]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/usb/pegasus.c
Merge tag 'soc-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[karo-tx-linux.git] / drivers / net / usb / pegasus.c
1 /*
2  *  Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  *      ChangeLog:
9  *              ....    Most of the time spent on reading sources & docs.
10  *              v0.2.x  First official release for the Linux kernel.
11  *              v0.3.0  Beutified and structured, some bugs fixed.
12  *              v0.3.x  URBifying bulk requests and bugfixing. First relatively
13  *                      stable release. Still can touch device's registers only
14  *                      from top-halves.
15  *              v0.4.0  Control messages remained unurbified are now URBs.
16  *                      Now we can touch the HW at any time.
17  *              v0.4.9  Control urbs again use process context to wait. Argh...
18  *                      Some long standing bugs (enable_net_traffic) fixed.
19  *                      Also nasty trick about resubmiting control urb from
20  *                      interrupt context used. Please let me know how it
21  *                      behaves. Pegasus II support added since this version.
22  *                      TODO: suppressing HCD warnings spewage on disconnect.
23  *              v0.4.13 Ethernet address is now set at probe(), not at open()
24  *                      time as this seems to break dhcpd.
25  *              v0.5.0  branch to 2.5.x kernels
26  *              v0.5.1  ethtool support added
27  *              v0.5.5  rx socket buffers are in a pool and the their allocation
28  *                      is out of the interrupt routine.
29  *              ...
30  *              v0.9.3  simplified [get|set]_register(s), async update registers
31  *                      logic revisited, receive skb_pool removed.
32  */
33
34 #include <linux/sched.h>
35 #include <linux/slab.h>
36 #include <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/ethtool.h>
41 #include <linux/mii.h>
42 #include <linux/usb.h>
43 #include <linux/module.h>
44 #include <asm/byteorder.h>
45 #include <asm/uaccess.h>
46 #include "pegasus.h"
47
48 /*
49  * Version Information
50  */
51 #define DRIVER_VERSION "v0.9.3 (2013/04/25)"
52 #define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>"
53 #define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
54
55 static const char driver_name[] = "pegasus";
56
57 #undef  PEGASUS_WRITE_EEPROM
58 #define BMSR_MEDIA      (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
59                         BMSR_100FULL | BMSR_ANEGCAPABLE)
60
61 static bool loopback;
62 static bool mii_mode;
63 static char *devid;
64
65 static struct usb_eth_dev usb_dev_id[] = {
66 #define PEGASUS_DEV(pn, vid, pid, flags)        \
67         {.name = pn, .vendor = vid, .device = pid, .private = flags},
68 #define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
69         PEGASUS_DEV(pn, vid, pid, flags)
70 #include "pegasus.h"
71 #undef  PEGASUS_DEV
72 #undef  PEGASUS_DEV_CLASS
73         {NULL, 0, 0, 0},
74         {NULL, 0, 0, 0}
75 };
76
77 static struct usb_device_id pegasus_ids[] = {
78 #define PEGASUS_DEV(pn, vid, pid, flags) \
79         {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
80 /*
81  * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
82  * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
83  * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
84  * case anyway, seeing as the pegasus is for "Wired" adaptors.
85  */
86 #define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
87         {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
88         .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
89 #include "pegasus.h"
90 #undef  PEGASUS_DEV
91 #undef  PEGASUS_DEV_CLASS
92         {},
93         {}
94 };
95
96 MODULE_AUTHOR(DRIVER_AUTHOR);
97 MODULE_DESCRIPTION(DRIVER_DESC);
98 MODULE_LICENSE("GPL");
99 module_param(loopback, bool, 0);
100 module_param(mii_mode, bool, 0);
101 module_param(devid, charp, 0);
102 MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
103 MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
104 MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
105
106 /* use ethtool to change the level for any given device */
107 static int msg_level = -1;
108 module_param(msg_level, int, 0);
109 MODULE_PARM_DESC(msg_level, "Override default message level");
110
111 MODULE_DEVICE_TABLE(usb, pegasus_ids);
112 static const struct net_device_ops pegasus_netdev_ops;
113
114 /*****/
115
116 static void async_ctrl_callback(struct urb *urb)
117 {
118         struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
119         int status = urb->status;
120
121         if (status < 0)
122                 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
123         kfree(req);
124         usb_free_urb(urb);
125 }
126
127 static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
128 {
129         int ret;
130
131         ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0),
132                               PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0,
133                               indx, data, size, 1000);
134         if (ret < 0)
135                 netif_dbg(pegasus, drv, pegasus->net,
136                           "%s returned %d\n", __func__, ret);
137         return ret;
138 }
139
140 static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
141 {
142         int ret;
143
144         ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
145                               PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0,
146                               indx, data, size, 100);
147         if (ret < 0)
148                 netif_dbg(pegasus, drv, pegasus->net,
149                           "%s returned %d\n", __func__, ret);
150         return ret;
151 }
152
153 static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
154 {
155         int ret;
156
157         ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
158                               PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data,
159                               indx, &data, 1, 1000);
160         if (ret < 0)
161                 netif_dbg(pegasus, drv, pegasus->net,
162                           "%s returned %d\n", __func__, ret);
163         return ret;
164 }
165
166 static int update_eth_regs_async(pegasus_t *pegasus)
167 {
168         int ret = -ENOMEM;
169         struct urb *async_urb;
170         struct usb_ctrlrequest *req;
171
172         req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
173         if (req == NULL)
174                 return ret;
175
176         async_urb = usb_alloc_urb(0, GFP_ATOMIC);
177         if (async_urb == NULL) {
178                 kfree(req);
179                 return ret;
180         }
181         req->bRequestType = PEGASUS_REQT_WRITE;
182         req->bRequest = PEGASUS_REQ_SET_REGS;
183         req->wValue = cpu_to_le16(0);
184         req->wIndex = cpu_to_le16(EthCtrl0);
185         req->wLength = cpu_to_le16(3);
186
187         usb_fill_control_urb(async_urb, pegasus->usb,
188                              usb_sndctrlpipe(pegasus->usb, 0), (void *)req,
189                              pegasus->eth_regs, 3, async_ctrl_callback, req);
190
191         ret = usb_submit_urb(async_urb, GFP_ATOMIC);
192         if (ret) {
193                 if (ret == -ENODEV)
194                         netif_device_detach(pegasus->net);
195                 netif_err(pegasus, drv, pegasus->net,
196                           "%s returned %d\n", __func__, ret);
197         }
198         return ret;
199 }
200
201 static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd)
202 {
203         int i;
204         __u8 data[4] = { phy, 0, 0, indx };
205         __le16 regdi;
206         int ret = -ETIMEDOUT;
207
208         if (cmd & PHY_WRITE) {
209                 __le16 *t = (__le16 *) & data[1];
210                 *t = cpu_to_le16(*regd);
211         }
212         set_register(p, PhyCtrl, 0);
213         set_registers(p, PhyAddr, sizeof(data), data);
214         set_register(p, PhyCtrl, (indx | cmd));
215         for (i = 0; i < REG_TIMEOUT; i++) {
216                 ret = get_registers(p, PhyCtrl, 1, data);
217                 if (ret < 0)
218                         goto fail;
219                 if (data[0] & PHY_DONE)
220                         break;
221         }
222         if (i >= REG_TIMEOUT)
223                 goto fail;
224         if (cmd & PHY_READ) {
225                 ret = get_registers(p, PhyData, 2, &regdi);
226                 *regd = le16_to_cpu(regdi);
227                 return ret;
228         }
229         return 0;
230 fail:
231         netif_dbg(p, drv, p->net, "%s failed\n", __func__);
232         return ret;
233 }
234
235 /* Returns non-negative int on success, error on failure */
236 static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
237 {
238         return __mii_op(pegasus, phy, indx, regd, PHY_READ);
239 }
240
241 /* Returns zero on success, error on failure */
242 static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
243 {
244         return __mii_op(pegasus, phy, indx, regd, PHY_WRITE);
245 }
246
247 static int mdio_read(struct net_device *dev, int phy_id, int loc)
248 {
249         pegasus_t *pegasus = netdev_priv(dev);
250         u16 res;
251
252         read_mii_word(pegasus, phy_id, loc, &res);
253         return (int)res;
254 }
255
256 static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
257 {
258         pegasus_t *pegasus = netdev_priv(dev);
259
260         write_mii_word(pegasus, phy_id, loc, (__u16 *)&val);
261 }
262
263 static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata)
264 {
265         int i;
266         __u8 tmp;
267         __le16 retdatai;
268         int ret;
269
270         set_register(pegasus, EpromCtrl, 0);
271         set_register(pegasus, EpromOffset, index);
272         set_register(pegasus, EpromCtrl, EPROM_READ);
273
274         for (i = 0; i < REG_TIMEOUT; i++) {
275                 ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
276                 if (tmp & EPROM_DONE)
277                         break;
278                 if (ret == -ESHUTDOWN)
279                         goto fail;
280         }
281         if (i >= REG_TIMEOUT)
282                 goto fail;
283
284         ret = get_registers(pegasus, EpromData, 2, &retdatai);
285         *retdata = le16_to_cpu(retdatai);
286         return ret;
287
288 fail:
289         netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
290         return -ETIMEDOUT;
291 }
292
293 #ifdef  PEGASUS_WRITE_EEPROM
294 static inline void enable_eprom_write(pegasus_t *pegasus)
295 {
296         __u8 tmp;
297
298         get_registers(pegasus, EthCtrl2, 1, &tmp);
299         set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
300 }
301
302 static inline void disable_eprom_write(pegasus_t *pegasus)
303 {
304         __u8 tmp;
305
306         get_registers(pegasus, EthCtrl2, 1, &tmp);
307         set_register(pegasus, EpromCtrl, 0);
308         set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
309 }
310
311 static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data)
312 {
313         int i;
314         __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
315         int ret;
316         __le16 le_data = cpu_to_le16(data);
317
318         set_registers(pegasus, EpromOffset, 4, d);
319         enable_eprom_write(pegasus);
320         set_register(pegasus, EpromOffset, index);
321         set_registers(pegasus, EpromData, 2, &le_data);
322         set_register(pegasus, EpromCtrl, EPROM_WRITE);
323
324         for (i = 0; i < REG_TIMEOUT; i++) {
325                 ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
326                 if (ret == -ESHUTDOWN)
327                         goto fail;
328                 if (tmp & EPROM_DONE)
329                         break;
330         }
331         disable_eprom_write(pegasus);
332         if (i >= REG_TIMEOUT)
333                 goto fail;
334
335         return ret;
336
337 fail:
338         netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
339         return -ETIMEDOUT;
340 }
341 #endif                          /* PEGASUS_WRITE_EEPROM */
342
343 static inline void get_node_id(pegasus_t *pegasus, __u8 *id)
344 {
345         int i;
346         __u16 w16;
347
348         for (i = 0; i < 3; i++) {
349                 read_eprom_word(pegasus, i, &w16);
350                 ((__le16 *) id)[i] = cpu_to_le16(w16);
351         }
352 }
353
354 static void set_ethernet_addr(pegasus_t *pegasus)
355 {
356         __u8 node_id[6];
357
358         if (pegasus->features & PEGASUS_II) {
359                 get_registers(pegasus, 0x10, sizeof(node_id), node_id);
360         } else {
361                 get_node_id(pegasus, node_id);
362                 set_registers(pegasus, EthID, sizeof(node_id), node_id);
363         }
364         memcpy(pegasus->net->dev_addr, node_id, sizeof(node_id));
365 }
366
367 static inline int reset_mac(pegasus_t *pegasus)
368 {
369         __u8 data = 0x8;
370         int i;
371
372         set_register(pegasus, EthCtrl1, data);
373         for (i = 0; i < REG_TIMEOUT; i++) {
374                 get_registers(pegasus, EthCtrl1, 1, &data);
375                 if (~data & 0x08) {
376                         if (loopback)
377                                 break;
378                         if (mii_mode && (pegasus->features & HAS_HOME_PNA))
379                                 set_register(pegasus, Gpio1, 0x34);
380                         else
381                                 set_register(pegasus, Gpio1, 0x26);
382                         set_register(pegasus, Gpio0, pegasus->features);
383                         set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
384                         break;
385                 }
386         }
387         if (i == REG_TIMEOUT)
388                 return -ETIMEDOUT;
389
390         if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
391             usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
392                 set_register(pegasus, Gpio0, 0x24);
393                 set_register(pegasus, Gpio0, 0x26);
394         }
395         if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
396                 __u16 auxmode;
397                 read_mii_word(pegasus, 3, 0x1b, &auxmode);
398                 auxmode |= 4;
399                 write_mii_word(pegasus, 3, 0x1b, &auxmode);
400         }
401
402         return 0;
403 }
404
405 static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
406 {
407         __u16 linkpart;
408         __u8 data[4];
409         pegasus_t *pegasus = netdev_priv(dev);
410         int ret;
411
412         read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
413         data[0] = 0xc9;
414         data[1] = 0;
415         if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
416                 data[1] |= 0x20;        /* set full duplex */
417         if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
418                 data[1] |= 0x10;        /* set 100 Mbps */
419         if (mii_mode)
420                 data[1] = 0;
421         data[2] = loopback ? 0x09 : 0x01;
422
423         memcpy(pegasus->eth_regs, data, sizeof(data));
424         ret = set_registers(pegasus, EthCtrl0, 3, data);
425
426         if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
427             usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
428             usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
429                 u16 auxmode;
430                 read_mii_word(pegasus, 0, 0x1b, &auxmode);
431                 auxmode |= 4;
432                 write_mii_word(pegasus, 0, 0x1b, &auxmode);
433         }
434
435         return ret;
436 }
437
438 static void read_bulk_callback(struct urb *urb)
439 {
440         pegasus_t *pegasus = urb->context;
441         struct net_device *net;
442         int rx_status, count = urb->actual_length;
443         int status = urb->status;
444         u8 *buf = urb->transfer_buffer;
445         __u16 pkt_len;
446
447         if (!pegasus)
448                 return;
449
450         net = pegasus->net;
451         if (!netif_device_present(net) || !netif_running(net))
452                 return;
453
454         switch (status) {
455         case 0:
456                 break;
457         case -ETIME:
458                 netif_dbg(pegasus, rx_err, net, "reset MAC\n");
459                 pegasus->flags &= ~PEGASUS_RX_BUSY;
460                 break;
461         case -EPIPE:            /* stall, or disconnect from TT */
462                 /* FIXME schedule work to clear the halt */
463                 netif_warn(pegasus, rx_err, net, "no rx stall recovery\n");
464                 return;
465         case -ENOENT:
466         case -ECONNRESET:
467         case -ESHUTDOWN:
468                 netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status);
469                 return;
470         default:
471                 netif_dbg(pegasus, rx_err, net, "RX status %d\n", status);
472                 goto goon;
473         }
474
475         if (!count || count < 4)
476                 goto goon;
477
478         rx_status = buf[count - 2];
479         if (rx_status & 0x1e) {
480                 netif_dbg(pegasus, rx_err, net,
481                           "RX packet error %x\n", rx_status);
482                 pegasus->stats.rx_errors++;
483                 if (rx_status & 0x06)   /* long or runt */
484                         pegasus->stats.rx_length_errors++;
485                 if (rx_status & 0x08)
486                         pegasus->stats.rx_crc_errors++;
487                 if (rx_status & 0x10)   /* extra bits   */
488                         pegasus->stats.rx_frame_errors++;
489                 goto goon;
490         }
491         if (pegasus->chip == 0x8513) {
492                 pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
493                 pkt_len &= 0x0fff;
494                 pegasus->rx_skb->data += 2;
495         } else {
496                 pkt_len = buf[count - 3] << 8;
497                 pkt_len += buf[count - 4];
498                 pkt_len &= 0xfff;
499                 pkt_len -= 8;
500         }
501
502         /*
503          * If the packet is unreasonably long, quietly drop it rather than
504          * kernel panicing by calling skb_put.
505          */
506         if (pkt_len > PEGASUS_MTU)
507                 goto goon;
508
509         /*
510          * at this point we are sure pegasus->rx_skb != NULL
511          * so we go ahead and pass up the packet.
512          */
513         skb_put(pegasus->rx_skb, pkt_len);
514         pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
515         netif_rx(pegasus->rx_skb);
516         pegasus->stats.rx_packets++;
517         pegasus->stats.rx_bytes += pkt_len;
518
519         if (pegasus->flags & PEGASUS_UNPLUG)
520                 return;
521
522         pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU,
523                                                       GFP_ATOMIC);
524
525         if (pegasus->rx_skb == NULL)
526                 goto tl_sched;
527 goon:
528         usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
529                           usb_rcvbulkpipe(pegasus->usb, 1),
530                           pegasus->rx_skb->data, PEGASUS_MTU + 8,
531                           read_bulk_callback, pegasus);
532         rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
533         if (rx_status == -ENODEV)
534                 netif_device_detach(pegasus->net);
535         else if (rx_status) {
536                 pegasus->flags |= PEGASUS_RX_URB_FAIL;
537                 goto tl_sched;
538         } else {
539                 pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
540         }
541
542         return;
543
544 tl_sched:
545         tasklet_schedule(&pegasus->rx_tl);
546 }
547
548 static void rx_fixup(unsigned long data)
549 {
550         pegasus_t *pegasus;
551         int status;
552
553         pegasus = (pegasus_t *) data;
554         if (pegasus->flags & PEGASUS_UNPLUG)
555                 return;
556
557         if (pegasus->flags & PEGASUS_RX_URB_FAIL)
558                 if (pegasus->rx_skb)
559                         goto try_again;
560         if (pegasus->rx_skb == NULL)
561                 pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
562                                                               PEGASUS_MTU,
563                                                               GFP_ATOMIC);
564         if (pegasus->rx_skb == NULL) {
565                 netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n");
566                 tasklet_schedule(&pegasus->rx_tl);
567                 return;
568         }
569         usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
570                           usb_rcvbulkpipe(pegasus->usb, 1),
571                           pegasus->rx_skb->data, PEGASUS_MTU + 8,
572                           read_bulk_callback, pegasus);
573 try_again:
574         status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
575         if (status == -ENODEV)
576                 netif_device_detach(pegasus->net);
577         else if (status) {
578                 pegasus->flags |= PEGASUS_RX_URB_FAIL;
579                 tasklet_schedule(&pegasus->rx_tl);
580         } else {
581                 pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
582         }
583 }
584
585 static void write_bulk_callback(struct urb *urb)
586 {
587         pegasus_t *pegasus = urb->context;
588         struct net_device *net;
589         int status = urb->status;
590
591         if (!pegasus)
592                 return;
593
594         net = pegasus->net;
595
596         if (!netif_device_present(net) || !netif_running(net))
597                 return;
598
599         switch (status) {
600         case -EPIPE:
601                 /* FIXME schedule_work() to clear the tx halt */
602                 netif_stop_queue(net);
603                 netif_warn(pegasus, tx_err, net, "no tx stall recovery\n");
604                 return;
605         case -ENOENT:
606         case -ECONNRESET:
607         case -ESHUTDOWN:
608                 netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status);
609                 return;
610         default:
611                 netif_info(pegasus, tx_err, net, "TX status %d\n", status);
612                 /* FALL THROUGH */
613         case 0:
614                 break;
615         }
616
617         net->trans_start = jiffies; /* prevent tx timeout */
618         netif_wake_queue(net);
619 }
620
621 static void intr_callback(struct urb *urb)
622 {
623         pegasus_t *pegasus = urb->context;
624         struct net_device *net;
625         int res, status = urb->status;
626
627         if (!pegasus)
628                 return;
629         net = pegasus->net;
630
631         switch (status) {
632         case 0:
633                 break;
634         case -ECONNRESET:       /* unlink */
635         case -ENOENT:
636         case -ESHUTDOWN:
637                 return;
638         default:
639                 /* some Pegasus-I products report LOTS of data
640                  * toggle errors... avoid log spamming
641                  */
642                 netif_dbg(pegasus, timer, net, "intr status %d\n", status);
643         }
644
645         if (urb->actual_length >= 6) {
646                 u8 *d = urb->transfer_buffer;
647
648                 /* byte 0 == tx_status1, reg 2B */
649                 if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
650                                         |LATE_COL|JABBER_TIMEOUT)) {
651                         pegasus->stats.tx_errors++;
652                         if (d[0] & TX_UNDERRUN)
653                                 pegasus->stats.tx_fifo_errors++;
654                         if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
655                                 pegasus->stats.tx_aborted_errors++;
656                         if (d[0] & LATE_COL)
657                                 pegasus->stats.tx_window_errors++;
658                 }
659
660                 /* d[5].LINK_STATUS lies on some adapters.
661                  * d[0].NO_CARRIER kicks in only with failed TX.
662                  * ... so monitoring with MII may be safest.
663                  */
664
665                 /* bytes 3-4 == rx_lostpkt, reg 2E/2F */
666                 pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
667         }
668
669         res = usb_submit_urb(urb, GFP_ATOMIC);
670         if (res == -ENODEV)
671                 netif_device_detach(pegasus->net);
672         if (res)
673                 netif_err(pegasus, timer, net,
674                           "can't resubmit interrupt urb, %d\n", res);
675 }
676
677 static void pegasus_tx_timeout(struct net_device *net)
678 {
679         pegasus_t *pegasus = netdev_priv(net);
680         netif_warn(pegasus, timer, net, "tx timeout\n");
681         usb_unlink_urb(pegasus->tx_urb);
682         pegasus->stats.tx_errors++;
683 }
684
685 static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
686                                             struct net_device *net)
687 {
688         pegasus_t *pegasus = netdev_priv(net);
689         int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
690         int res;
691         __u16 l16 = skb->len;
692
693         netif_stop_queue(net);
694
695         ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
696         skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
697         usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
698                           usb_sndbulkpipe(pegasus->usb, 2),
699                           pegasus->tx_buff, count,
700                           write_bulk_callback, pegasus);
701         if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
702                 netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res);
703                 switch (res) {
704                 case -EPIPE:            /* stall, or disconnect from TT */
705                         /* cleanup should already have been scheduled */
706                         break;
707                 case -ENODEV:           /* disconnect() upcoming */
708                 case -EPERM:
709                         netif_device_detach(pegasus->net);
710                         break;
711                 default:
712                         pegasus->stats.tx_errors++;
713                         netif_start_queue(net);
714                 }
715         } else {
716                 pegasus->stats.tx_packets++;
717                 pegasus->stats.tx_bytes += skb->len;
718         }
719         dev_kfree_skb(skb);
720
721         return NETDEV_TX_OK;
722 }
723
724 static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
725 {
726         return &((pegasus_t *) netdev_priv(dev))->stats;
727 }
728
729 static inline void disable_net_traffic(pegasus_t *pegasus)
730 {
731         __le16 tmp = cpu_to_le16(0);
732
733         set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
734 }
735
736 static inline void get_interrupt_interval(pegasus_t *pegasus)
737 {
738         u16 data;
739         u8 interval;
740
741         read_eprom_word(pegasus, 4, &data);
742         interval = data >> 8;
743         if (pegasus->usb->speed != USB_SPEED_HIGH) {
744                 if (interval < 0x80) {
745                         netif_info(pegasus, timer, pegasus->net,
746                                    "intr interval changed from %ums to %ums\n",
747                                    interval, 0x80);
748                         interval = 0x80;
749                         data = (data & 0x00FF) | ((u16)interval << 8);
750 #ifdef PEGASUS_WRITE_EEPROM
751                         write_eprom_word(pegasus, 4, data);
752 #endif
753                 }
754         }
755         pegasus->intr_interval = interval;
756 }
757
758 static void set_carrier(struct net_device *net)
759 {
760         pegasus_t *pegasus = netdev_priv(net);
761         u16 tmp;
762
763         if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
764                 return;
765
766         if (tmp & BMSR_LSTATUS)
767                 netif_carrier_on(net);
768         else
769                 netif_carrier_off(net);
770 }
771
772 static void free_all_urbs(pegasus_t *pegasus)
773 {
774         usb_free_urb(pegasus->intr_urb);
775         usb_free_urb(pegasus->tx_urb);
776         usb_free_urb(pegasus->rx_urb);
777 }
778
779 static void unlink_all_urbs(pegasus_t *pegasus)
780 {
781         usb_kill_urb(pegasus->intr_urb);
782         usb_kill_urb(pegasus->tx_urb);
783         usb_kill_urb(pegasus->rx_urb);
784 }
785
786 static int alloc_urbs(pegasus_t *pegasus)
787 {
788         int res = -ENOMEM;
789
790         pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
791         if (!pegasus->rx_urb) {
792                 return res;
793         }
794         pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
795         if (!pegasus->tx_urb) {
796                 usb_free_urb(pegasus->rx_urb);
797                 return res;
798         }
799         pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
800         if (!pegasus->intr_urb) {
801                 usb_free_urb(pegasus->tx_urb);
802                 usb_free_urb(pegasus->rx_urb);
803                 return res;
804         }
805
806         return 0;
807 }
808
809 static int pegasus_open(struct net_device *net)
810 {
811         pegasus_t *pegasus = netdev_priv(net);
812         int res=-ENOMEM;
813
814         if (pegasus->rx_skb == NULL)
815                 pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
816                                                               PEGASUS_MTU,
817                                                               GFP_KERNEL);
818         if (!pegasus->rx_skb)
819                 goto exit;
820
821         res = set_registers(pegasus, EthID, 6, net->dev_addr);
822
823         usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
824                           usb_rcvbulkpipe(pegasus->usb, 1),
825                           pegasus->rx_skb->data, PEGASUS_MTU + 8,
826                           read_bulk_callback, pegasus);
827         if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
828                 if (res == -ENODEV)
829                         netif_device_detach(pegasus->net);
830                 netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res);
831                 goto exit;
832         }
833
834         usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
835                          usb_rcvintpipe(pegasus->usb, 3),
836                          pegasus->intr_buff, sizeof(pegasus->intr_buff),
837                          intr_callback, pegasus, pegasus->intr_interval);
838         if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
839                 if (res == -ENODEV)
840                         netif_device_detach(pegasus->net);
841                 netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res);
842                 usb_kill_urb(pegasus->rx_urb);
843                 goto exit;
844         }
845         res = enable_net_traffic(net, pegasus->usb);
846         if (res < 0) {
847                 netif_dbg(pegasus, ifup, net,
848                           "can't enable_net_traffic() - %d\n", res);
849                 res = -EIO;
850                 usb_kill_urb(pegasus->rx_urb);
851                 usb_kill_urb(pegasus->intr_urb);
852                 goto exit;
853         }
854         set_carrier(net);
855         netif_start_queue(net);
856         netif_dbg(pegasus, ifup, net, "open\n");
857         res = 0;
858 exit:
859         return res;
860 }
861
862 static int pegasus_close(struct net_device *net)
863 {
864         pegasus_t *pegasus = netdev_priv(net);
865
866         netif_stop_queue(net);
867         if (!(pegasus->flags & PEGASUS_UNPLUG))
868                 disable_net_traffic(pegasus);
869         tasklet_kill(&pegasus->rx_tl);
870         unlink_all_urbs(pegasus);
871
872         return 0;
873 }
874
875 static void pegasus_get_drvinfo(struct net_device *dev,
876                                 struct ethtool_drvinfo *info)
877 {
878         pegasus_t *pegasus = netdev_priv(dev);
879
880         strlcpy(info->driver, driver_name, sizeof(info->driver));
881         strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
882         usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info));
883 }
884
885 /* also handles three patterns of some kind in hardware */
886 #define WOL_SUPPORTED   (WAKE_MAGIC|WAKE_PHY)
887
888 static void
889 pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
890 {
891         pegasus_t       *pegasus = netdev_priv(dev);
892
893         wol->supported = WAKE_MAGIC | WAKE_PHY;
894         wol->wolopts = pegasus->wolopts;
895 }
896
897 static int
898 pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
899 {
900         pegasus_t       *pegasus = netdev_priv(dev);
901         u8              reg78 = 0x04;
902         int             ret;
903
904         if (wol->wolopts & ~WOL_SUPPORTED)
905                 return -EINVAL;
906
907         if (wol->wolopts & WAKE_MAGIC)
908                 reg78 |= 0x80;
909         if (wol->wolopts & WAKE_PHY)
910                 reg78 |= 0x40;
911         /* FIXME this 0x10 bit still needs to get set in the chip... */
912         if (wol->wolopts)
913                 pegasus->eth_regs[0] |= 0x10;
914         else
915                 pegasus->eth_regs[0] &= ~0x10;
916         pegasus->wolopts = wol->wolopts;
917
918         ret = set_register(pegasus, WakeupControl, reg78);
919         if (!ret)
920                 ret = device_set_wakeup_enable(&pegasus->usb->dev,
921                                                 wol->wolopts);
922         return ret;
923 }
924
925 static inline void pegasus_reset_wol(struct net_device *dev)
926 {
927         struct ethtool_wolinfo wol;
928
929         memset(&wol, 0, sizeof wol);
930         (void) pegasus_set_wol(dev, &wol);
931 }
932
933 static int
934 pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
935 {
936         pegasus_t *pegasus;
937
938         pegasus = netdev_priv(dev);
939         mii_ethtool_gset(&pegasus->mii, ecmd);
940         return 0;
941 }
942
943 static int
944 pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
945 {
946         pegasus_t *pegasus = netdev_priv(dev);
947         return mii_ethtool_sset(&pegasus->mii, ecmd);
948 }
949
950 static int pegasus_nway_reset(struct net_device *dev)
951 {
952         pegasus_t *pegasus = netdev_priv(dev);
953         return mii_nway_restart(&pegasus->mii);
954 }
955
956 static u32 pegasus_get_link(struct net_device *dev)
957 {
958         pegasus_t *pegasus = netdev_priv(dev);
959         return mii_link_ok(&pegasus->mii);
960 }
961
962 static u32 pegasus_get_msglevel(struct net_device *dev)
963 {
964         pegasus_t *pegasus = netdev_priv(dev);
965         return pegasus->msg_enable;
966 }
967
968 static void pegasus_set_msglevel(struct net_device *dev, u32 v)
969 {
970         pegasus_t *pegasus = netdev_priv(dev);
971         pegasus->msg_enable = v;
972 }
973
974 static const struct ethtool_ops ops = {
975         .get_drvinfo = pegasus_get_drvinfo,
976         .get_settings = pegasus_get_settings,
977         .set_settings = pegasus_set_settings,
978         .nway_reset = pegasus_nway_reset,
979         .get_link = pegasus_get_link,
980         .get_msglevel = pegasus_get_msglevel,
981         .set_msglevel = pegasus_set_msglevel,
982         .get_wol = pegasus_get_wol,
983         .set_wol = pegasus_set_wol,
984 };
985
986 static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
987 {
988         __u16 *data = (__u16 *) &rq->ifr_ifru;
989         pegasus_t *pegasus = netdev_priv(net);
990         int res;
991
992         switch (cmd) {
993         case SIOCDEVPRIVATE:
994                 data[0] = pegasus->phy;
995         case SIOCDEVPRIVATE + 1:
996                 read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
997                 res = 0;
998                 break;
999         case SIOCDEVPRIVATE + 2:
1000                 if (!capable(CAP_NET_ADMIN))
1001                         return -EPERM;
1002                 write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]);
1003                 res = 0;
1004                 break;
1005         default:
1006                 res = -EOPNOTSUPP;
1007         }
1008         return res;
1009 }
1010
1011 static void pegasus_set_multicast(struct net_device *net)
1012 {
1013         pegasus_t *pegasus = netdev_priv(net);
1014
1015         if (net->flags & IFF_PROMISC) {
1016                 pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
1017                 netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
1018         } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
1019                 pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
1020                 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
1021                 netif_dbg(pegasus, link, net, "set allmulti\n");
1022         } else {
1023                 pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
1024                 pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
1025         }
1026         update_eth_regs_async(pegasus);
1027 }
1028
1029 static __u8 mii_phy_probe(pegasus_t *pegasus)
1030 {
1031         int i;
1032         __u16 tmp;
1033
1034         for (i = 0; i < 32; i++) {
1035                 read_mii_word(pegasus, i, MII_BMSR, &tmp);
1036                 if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
1037                         continue;
1038                 else
1039                         return i;
1040         }
1041
1042         return 0xff;
1043 }
1044
1045 static inline void setup_pegasus_II(pegasus_t *pegasus)
1046 {
1047         __u8 data = 0xa5;
1048
1049         set_register(pegasus, Reg1d, 0);
1050         set_register(pegasus, Reg7b, 1);
1051         mdelay(100);
1052         if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
1053                 set_register(pegasus, Reg7b, 0);
1054         else
1055                 set_register(pegasus, Reg7b, 2);
1056
1057         set_register(pegasus, 0x83, data);
1058         get_registers(pegasus, 0x83, 1, &data);
1059
1060         if (data == 0xa5)
1061                 pegasus->chip = 0x8513;
1062         else
1063                 pegasus->chip = 0;
1064
1065         set_register(pegasus, 0x80, 0xc0);
1066         set_register(pegasus, 0x83, 0xff);
1067         set_register(pegasus, 0x84, 0x01);
1068
1069         if (pegasus->features & HAS_HOME_PNA && mii_mode)
1070                 set_register(pegasus, Reg81, 6);
1071         else
1072                 set_register(pegasus, Reg81, 2);
1073 }
1074
1075
1076 static int pegasus_count;
1077 static struct workqueue_struct *pegasus_workqueue;
1078 #define CARRIER_CHECK_DELAY (2 * HZ)
1079
1080 static void check_carrier(struct work_struct *work)
1081 {
1082         pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
1083         set_carrier(pegasus->net);
1084         if (!(pegasus->flags & PEGASUS_UNPLUG)) {
1085                 queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
1086                         CARRIER_CHECK_DELAY);
1087         }
1088 }
1089
1090 static int pegasus_blacklisted(struct usb_device *udev)
1091 {
1092         struct usb_device_descriptor *udd = &udev->descriptor;
1093
1094         /* Special quirk to keep the driver from handling the Belkin Bluetooth
1095          * dongle which happens to have the same ID.
1096          */
1097         if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
1098             (udd->idProduct == cpu_to_le16(0x0121)) &&
1099             (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
1100             (udd->bDeviceProtocol == 1))
1101                 return 1;
1102
1103         return 0;
1104 }
1105
1106 /* we rely on probe() and remove() being serialized so we
1107  * don't need extra locking on pegasus_count.
1108  */
1109 static void pegasus_dec_workqueue(void)
1110 {
1111         pegasus_count--;
1112         if (pegasus_count == 0) {
1113                 destroy_workqueue(pegasus_workqueue);
1114                 pegasus_workqueue = NULL;
1115         }
1116 }
1117
1118 static int pegasus_probe(struct usb_interface *intf,
1119                          const struct usb_device_id *id)
1120 {
1121         struct usb_device *dev = interface_to_usbdev(intf);
1122         struct net_device *net;
1123         pegasus_t *pegasus;
1124         int dev_index = id - pegasus_ids;
1125         int res = -ENOMEM;
1126
1127         if (pegasus_blacklisted(dev))
1128                 return -ENODEV;
1129
1130         if (pegasus_count == 0) {
1131                 pegasus_workqueue = create_singlethread_workqueue("pegasus");
1132                 if (!pegasus_workqueue)
1133                         return -ENOMEM;
1134         }
1135         pegasus_count++;
1136
1137         net = alloc_etherdev(sizeof(struct pegasus));
1138         if (!net)
1139                 goto out;
1140
1141         pegasus = netdev_priv(net);
1142         pegasus->dev_index = dev_index;
1143
1144         res = alloc_urbs(pegasus);
1145         if (res < 0) {
1146                 dev_err(&intf->dev, "can't allocate %s\n", "urbs");
1147                 goto out1;
1148         }
1149
1150         tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
1151
1152         INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
1153
1154         pegasus->intf = intf;
1155         pegasus->usb = dev;
1156         pegasus->net = net;
1157
1158
1159         net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
1160         net->netdev_ops = &pegasus_netdev_ops;
1161         SET_ETHTOOL_OPS(net, &ops);
1162         pegasus->mii.dev = net;
1163         pegasus->mii.mdio_read = mdio_read;
1164         pegasus->mii.mdio_write = mdio_write;
1165         pegasus->mii.phy_id_mask = 0x1f;
1166         pegasus->mii.reg_num_mask = 0x1f;
1167         pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV
1168                                 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1169
1170         pegasus->features = usb_dev_id[dev_index].private;
1171         get_interrupt_interval(pegasus);
1172         if (reset_mac(pegasus)) {
1173                 dev_err(&intf->dev, "can't reset MAC\n");
1174                 res = -EIO;
1175                 goto out2;
1176         }
1177         set_ethernet_addr(pegasus);
1178         if (pegasus->features & PEGASUS_II) {
1179                 dev_info(&intf->dev, "setup Pegasus II specific registers\n");
1180                 setup_pegasus_II(pegasus);
1181         }
1182         pegasus->phy = mii_phy_probe(pegasus);
1183         if (pegasus->phy == 0xff) {
1184                 dev_warn(&intf->dev, "can't locate MII phy, using default\n");
1185                 pegasus->phy = 1;
1186         }
1187         pegasus->mii.phy_id = pegasus->phy;
1188         usb_set_intfdata(intf, pegasus);
1189         SET_NETDEV_DEV(net, &intf->dev);
1190         pegasus_reset_wol(net);
1191         res = register_netdev(net);
1192         if (res)
1193                 goto out3;
1194         queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
1195                            CARRIER_CHECK_DELAY);
1196         dev_info(&intf->dev, "%s, %s, %pM\n", net->name,
1197                  usb_dev_id[dev_index].name, net->dev_addr);
1198         return 0;
1199
1200 out3:
1201         usb_set_intfdata(intf, NULL);
1202 out2:
1203         free_all_urbs(pegasus);
1204 out1:
1205         free_netdev(net);
1206 out:
1207         pegasus_dec_workqueue();
1208         return res;
1209 }
1210
1211 static void pegasus_disconnect(struct usb_interface *intf)
1212 {
1213         struct pegasus *pegasus = usb_get_intfdata(intf);
1214
1215         usb_set_intfdata(intf, NULL);
1216         if (!pegasus) {
1217                 dev_dbg(&intf->dev, "unregistering non-bound device?\n");
1218                 return;
1219         }
1220
1221         pegasus->flags |= PEGASUS_UNPLUG;
1222         cancel_delayed_work(&pegasus->carrier_check);
1223         unregister_netdev(pegasus->net);
1224         unlink_all_urbs(pegasus);
1225         free_all_urbs(pegasus);
1226         if (pegasus->rx_skb != NULL) {
1227                 dev_kfree_skb(pegasus->rx_skb);
1228                 pegasus->rx_skb = NULL;
1229         }
1230         free_netdev(pegasus->net);
1231         pegasus_dec_workqueue();
1232 }
1233
1234 static int pegasus_suspend(struct usb_interface *intf, pm_message_t message)
1235 {
1236         struct pegasus *pegasus = usb_get_intfdata(intf);
1237
1238         netif_device_detach(pegasus->net);
1239         cancel_delayed_work(&pegasus->carrier_check);
1240         if (netif_running(pegasus->net)) {
1241                 usb_kill_urb(pegasus->rx_urb);
1242                 usb_kill_urb(pegasus->intr_urb);
1243         }
1244         return 0;
1245 }
1246
1247 static int pegasus_resume(struct usb_interface *intf)
1248 {
1249         struct pegasus *pegasus = usb_get_intfdata(intf);
1250
1251         netif_device_attach(pegasus->net);
1252         if (netif_running(pegasus->net)) {
1253                 pegasus->rx_urb->status = 0;
1254                 pegasus->rx_urb->actual_length = 0;
1255                 read_bulk_callback(pegasus->rx_urb);
1256
1257                 pegasus->intr_urb->status = 0;
1258                 pegasus->intr_urb->actual_length = 0;
1259                 intr_callback(pegasus->intr_urb);
1260         }
1261         queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
1262                                 CARRIER_CHECK_DELAY);
1263         return 0;
1264 }
1265
1266 static const struct net_device_ops pegasus_netdev_ops = {
1267         .ndo_open =                     pegasus_open,
1268         .ndo_stop =                     pegasus_close,
1269         .ndo_do_ioctl =                 pegasus_ioctl,
1270         .ndo_start_xmit =               pegasus_start_xmit,
1271         .ndo_set_rx_mode =              pegasus_set_multicast,
1272         .ndo_get_stats =                pegasus_netdev_stats,
1273         .ndo_tx_timeout =               pegasus_tx_timeout,
1274         .ndo_change_mtu =               eth_change_mtu,
1275         .ndo_set_mac_address =          eth_mac_addr,
1276         .ndo_validate_addr =            eth_validate_addr,
1277 };
1278
1279 static struct usb_driver pegasus_driver = {
1280         .name = driver_name,
1281         .probe = pegasus_probe,
1282         .disconnect = pegasus_disconnect,
1283         .id_table = pegasus_ids,
1284         .suspend = pegasus_suspend,
1285         .resume = pegasus_resume,
1286         .disable_hub_initiated_lpm = 1,
1287 };
1288
1289 static void __init parse_id(char *id)
1290 {
1291         unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0;
1292         char *token, *name = NULL;
1293
1294         if ((token = strsep(&id, ":")) != NULL)
1295                 name = token;
1296         /* name now points to a null terminated string*/
1297         if ((token = strsep(&id, ":")) != NULL)
1298                 vendor_id = simple_strtoul(token, NULL, 16);
1299         if ((token = strsep(&id, ":")) != NULL)
1300                 device_id = simple_strtoul(token, NULL, 16);
1301         flags = simple_strtoul(id, NULL, 16);
1302         pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
1303                 driver_name, name, vendor_id, device_id, flags);
1304
1305         if (vendor_id > 0x10000 || vendor_id == 0)
1306                 return;
1307         if (device_id > 0x10000 || device_id == 0)
1308                 return;
1309
1310         for (i = 0; usb_dev_id[i].name; i++);
1311         usb_dev_id[i].name = name;
1312         usb_dev_id[i].vendor = vendor_id;
1313         usb_dev_id[i].device = device_id;
1314         usb_dev_id[i].private = flags;
1315         pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
1316         pegasus_ids[i].idVendor = vendor_id;
1317         pegasus_ids[i].idProduct = device_id;
1318 }
1319
1320 static int __init pegasus_init(void)
1321 {
1322         pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
1323         if (devid)
1324                 parse_id(devid);
1325         return usb_register(&pegasus_driver);
1326 }
1327
1328 static void __exit pegasus_exit(void)
1329 {
1330         usb_deregister(&pegasus_driver);
1331 }
1332
1333 module_init(pegasus_init);
1334 module_exit(pegasus_exit);