net: use netdev_mc_count and netdev_mc_empty when appropriate
[safe/jmp/linux-2.6] / drivers / net / usb / pegasus.c
index d9241f1..44ae8f6 100644 (file)
@@ -62,8 +62,11 @@ static char *devid=NULL;
 static struct usb_eth_dev usb_dev_id[] = {
 #define        PEGASUS_DEV(pn, vid, pid, flags)        \
        {.name = pn, .vendor = vid, .device = pid, .private = flags},
+#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
+       PEGASUS_DEV(pn, vid, pid, flags)
 #include "pegasus.h"
 #undef PEGASUS_DEV
+#undef PEGASUS_DEV_CLASS
        {NULL, 0, 0, 0},
        {NULL, 0, 0, 0}
 };
@@ -71,8 +74,18 @@ static struct usb_eth_dev usb_dev_id[] = {
 static struct usb_device_id pegasus_ids[] = {
 #define        PEGASUS_DEV(pn, vid, pid, flags) \
        {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
+/*
+ * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
+ * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
+ * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
+ * case anyway, seeing as the pegasus is for "Wired" adaptors.
+ */
+#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
+       {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
+       .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
 #include "pegasus.h"
 #undef PEGASUS_DEV
+#undef PEGASUS_DEV_CLASS
        {},
        {}
 };
@@ -93,6 +106,7 @@ module_param (msg_level, int, 0);
 MODULE_PARM_DESC (msg_level, "Override default message level");
 
 MODULE_DEVICE_TABLE(usb, pegasus_ids);
+static const struct net_device_ops pegasus_netdev_ops;
 
 static int update_eth_regs_async(pegasus_t *);
 /* Aargh!!! I _really_ hate such tweaks */
@@ -296,7 +310,7 @@ static int update_eth_regs_async(pegasus_t * pegasus)
 
        pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
        pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
-       pegasus->dr.wValue = 0;
+       pegasus->dr.wValue = cpu_to_le16(0);
        pegasus->dr.wIndex = cpu_to_le16(EthCtrl0);
        pegasus->dr.wLength = cpu_to_le16(3);
        pegasus->ctrl_urb->transfer_buffer_length = 3;
@@ -445,11 +459,12 @@ static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
        int i;
        __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
        int ret;
+       __le16 le_data = cpu_to_le16(data);
 
        set_registers(pegasus, EpromOffset, 4, d);
        enable_eprom_write(pegasus);
        set_register(pegasus, EpromOffset, index);
-       set_registers(pegasus, EpromData, 2, &data);
+       set_registers(pegasus, EpromData, 2, &le_data);
        set_register(pegasus, EpromCtrl, EPROM_WRITE);
 
        for (i = 0; i < REG_TIMEOUT; i++) {
@@ -874,7 +889,8 @@ static void pegasus_tx_timeout(struct net_device *net)
        pegasus->stats.tx_errors++;
 }
 
-static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
+static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
+                                           struct net_device *net)
 {
        pegasus_t *pegasus = netdev_priv(net);
        int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
@@ -898,6 +914,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
                        /* cleanup should already have been scheduled */
                        break;
                case -ENODEV:           /* disconnect() upcoming */
+               case -EPERM:
                        netif_device_detach(pegasus->net);
                        break;
                default:
@@ -911,7 +928,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
        }
        dev_kfree_skb(skb);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
@@ -921,29 +938,32 @@ static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
 
 static inline void disable_net_traffic(pegasus_t * pegasus)
 {
-       int tmp = 0;
+       __le16 tmp = cpu_to_le16(0);
 
-       set_registers(pegasus, EthCtrl0, 2, &tmp);
+       set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
 }
 
 static inline void get_interrupt_interval(pegasus_t * pegasus)
 {
-       __u8 data[2];
+       u16 data;
+       u8 interval;
 
-       read_eprom_word(pegasus, 4, (__u16 *) data);
+       read_eprom_word(pegasus, 4, &data);
+       interval = data >> 8;
        if (pegasus->usb->speed != USB_SPEED_HIGH) {
-               if (data[1] < 0x80) {
+               if (interval < 0x80) {
                        if (netif_msg_timer(pegasus))
                                dev_info(&pegasus->intf->dev, "intr interval "
                                        "changed from %ums to %ums\n",
-                                       data[1], 0x80);
-                       data[1] = 0x80;
+                                       interval, 0x80);
+                       interval = 0x80;
+                       data = (data & 0x00FF) | ((u16)interval << 8);
 #ifdef PEGASUS_WRITE_EEPROM
-                       write_eprom_word(pegasus, 4, *(__u16 *) data);
+                       write_eprom_word(pegasus, 4, data);
 #endif
                }
        }
-       pegasus->intr_interval = data[1];
+       pegasus->intr_interval = interval;
 }
 
 static void set_carrier(struct net_device *net)
@@ -1167,7 +1187,7 @@ static void pegasus_set_msglevel(struct net_device *dev, u32 v)
        pegasus->msg_enable = v;
 }
 
-static struct ethtool_ops ops = {
+static const struct ethtool_ops ops = {
        .get_drvinfo = pegasus_get_drvinfo,
        .get_settings = pegasus_get_settings,
        .set_settings = pegasus_set_settings,
@@ -1212,7 +1232,7 @@ static void pegasus_set_multicast(struct net_device *net)
                pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
                if (netif_msg_link(pegasus))
                        pr_info("%s: Promiscuous mode enabled.\n", net->name);
-       } else if (net->mc_count || (net->flags & IFF_ALLMULTI)) {
+       } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
                pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
                pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
                if (netif_msg_link(pegasus))
@@ -1297,7 +1317,8 @@ static int pegasus_blacklisted(struct usb_device *udev)
        /* Special quirk to keep the driver from handling the Belkin Bluetooth
         * dongle which happens to have the same ID.
         */
-       if ((udd->idVendor == VENDOR_BELKIN && udd->idProduct == 0x0121) &&
+       if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
+           (udd->idProduct == cpu_to_le16(0x0121)) &&
            (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
            (udd->bDeviceProtocol == 1))
                return 1;
@@ -1360,14 +1381,10 @@ static int pegasus_probe(struct usb_interface *intf,
        pegasus->intf = intf;
        pegasus->usb = dev;
        pegasus->net = net;
-       net->open = pegasus_open;
-       net->stop = pegasus_close;
+
+
        net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
-       net->tx_timeout = pegasus_tx_timeout;
-       net->do_ioctl = pegasus_ioctl;
-       net->hard_start_xmit = pegasus_start_xmit;
-       net->set_multicast_list = pegasus_set_multicast;
-       net->get_stats = pegasus_netdev_stats;
+       net->netdev_ops = &pegasus_netdev_ops;
        SET_ETHTOOL_OPS(net, &ops);
        pegasus->mii.dev = net;
        pegasus->mii.mdio_read = mdio_read;
@@ -1482,6 +1499,19 @@ static int pegasus_resume (struct usb_interface *intf)
        return 0;
 }
 
+static const struct net_device_ops pegasus_netdev_ops = {
+       .ndo_open =                     pegasus_open,
+       .ndo_stop =                     pegasus_close,
+       .ndo_do_ioctl =                 pegasus_ioctl,
+       .ndo_start_xmit =               pegasus_start_xmit,
+       .ndo_set_multicast_list =       pegasus_set_multicast,
+       .ndo_get_stats =                pegasus_netdev_stats,
+       .ndo_tx_timeout =               pegasus_tx_timeout,
+       .ndo_change_mtu =               eth_change_mtu,
+       .ndo_set_mac_address =          eth_mac_addr,
+       .ndo_validate_addr =            eth_validate_addr,
+};
+
 static struct usb_driver pegasus_driver = {
        .name = driver_name,
        .probe = pegasus_probe,