diff options
Diffstat (limited to 'drivers/usb/net/usbnet.c')
-rw-r--r-- | drivers/usb/net/usbnet.c | 936 |
1 files changed, 47 insertions, 889 deletions
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index 57b41fbd3bb8..99a488140140 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -3,8 +3,6 @@ | |||
3 | * Copyright (C) 2000-2005 by David Brownell | 3 | * Copyright (C) 2000-2005 by David Brownell |
4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> | 4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> |
5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | 5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> |
6 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> | ||
7 | * Copyright (c) 2002-2003 TiVo Inc. | ||
8 | * | 6 | * |
9 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -156,9 +154,6 @@ | |||
156 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 154 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
157 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 155 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
158 | 156 | ||
159 | /* packets are always ethernet, sometimes wrapped in other framing */ | ||
160 | #define MIN_PACKET sizeof(struct ethhdr) | ||
161 | |||
162 | // reawaken network queue this soon after stopping; else watchdog barks | 157 | // reawaken network queue this soon after stopping; else watchdog barks |
163 | #define TX_TIMEOUT_JIFFIES (5*HZ) | 158 | #define TX_TIMEOUT_JIFFIES (5*HZ) |
164 | 159 | ||
@@ -186,11 +181,7 @@ MODULE_PARM_DESC (msg_level, "Override default message level"); | |||
186 | 181 | ||
187 | /*-------------------------------------------------------------------------*/ | 182 | /*-------------------------------------------------------------------------*/ |
188 | 183 | ||
189 | static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); | ||
190 | static u32 usbnet_get_link (struct net_device *); | 184 | static u32 usbnet_get_link (struct net_device *); |
191 | static u32 usbnet_get_msglevel (struct net_device *); | ||
192 | static void usbnet_set_msglevel (struct net_device *, u32); | ||
193 | static void defer_kevent (struct usbnet *, int); | ||
194 | 185 | ||
195 | /* mostly for PDA style devices, which are always connected if present */ | 186 | /* mostly for PDA style devices, which are always connected if present */ |
196 | static int always_connected (struct usbnet *dev) | 187 | static int always_connected (struct usbnet *dev) |
@@ -199,8 +190,7 @@ static int always_connected (struct usbnet *dev) | |||
199 | } | 190 | } |
200 | 191 | ||
201 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ | 192 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ |
202 | static int | 193 | int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) |
203 | get_endpoints (struct usbnet *dev, struct usb_interface *intf) | ||
204 | { | 194 | { |
205 | int tmp; | 195 | int tmp; |
206 | struct usb_host_interface *alt = NULL; | 196 | struct usb_host_interface *alt = NULL; |
@@ -264,6 +254,7 @@ get_endpoints (struct usbnet *dev, struct usb_interface *intf) | |||
264 | dev->status = status; | 254 | dev->status = status; |
265 | return 0; | 255 | return 0; |
266 | } | 256 | } |
257 | EXPORT_SYMBOL_GPL(usbnet_get_endpoints); | ||
267 | 258 | ||
268 | static void intr_complete (struct urb *urb, struct pt_regs *regs); | 259 | static void intr_complete (struct urb *urb, struct pt_regs *regs); |
269 | 260 | ||
@@ -303,7 +294,11 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf) | |||
303 | return 0; | 294 | return 0; |
304 | } | 295 | } |
305 | 296 | ||
306 | static void skb_return (struct usbnet *dev, struct sk_buff *skb) | 297 | /* Passes this packet up the stack, updating its accounting. |
298 | * Some link protocols batch packets, so their rx_fixup paths | ||
299 | * can return clones as well as just modify the original skb. | ||
300 | */ | ||
301 | void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) | ||
307 | { | 302 | { |
308 | int status; | 303 | int status; |
309 | 304 | ||
@@ -320,784 +315,7 @@ static void skb_return (struct usbnet *dev, struct sk_buff *skb) | |||
320 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) | 315 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) |
321 | devdbg (dev, "netif_rx status %d", status); | 316 | devdbg (dev, "netif_rx status %d", status); |
322 | } | 317 | } |
323 | 318 | EXPORT_SYMBOL_GPL(usbnet_skb_return); | |
324 | |||
325 | #ifdef CONFIG_USB_AX8817X | ||
326 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ | ||
327 | |||
328 | #define HAVE_HARDWARE | ||
329 | #define NEED_MII | ||
330 | |||
331 | #include <linux/crc32.h> | ||
332 | |||
333 | #define AX_CMD_SET_SW_MII 0x06 | ||
334 | #define AX_CMD_READ_MII_REG 0x07 | ||
335 | #define AX_CMD_WRITE_MII_REG 0x08 | ||
336 | #define AX_CMD_SET_HW_MII 0x0a | ||
337 | #define AX_CMD_READ_EEPROM 0x0b | ||
338 | #define AX_CMD_WRITE_EEPROM 0x0c | ||
339 | #define AX_CMD_WRITE_ENABLE 0x0d | ||
340 | #define AX_CMD_WRITE_DISABLE 0x0e | ||
341 | #define AX_CMD_WRITE_RX_CTL 0x10 | ||
342 | #define AX_CMD_READ_IPG012 0x11 | ||
343 | #define AX_CMD_WRITE_IPG0 0x12 | ||
344 | #define AX_CMD_WRITE_IPG1 0x13 | ||
345 | #define AX_CMD_WRITE_IPG2 0x14 | ||
346 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 | ||
347 | #define AX_CMD_READ_NODE_ID 0x17 | ||
348 | #define AX_CMD_READ_PHY_ID 0x19 | ||
349 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a | ||
350 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b | ||
351 | #define AX_CMD_READ_MONITOR_MODE 0x1c | ||
352 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d | ||
353 | #define AX_CMD_WRITE_GPIOS 0x1f | ||
354 | #define AX_CMD_SW_RESET 0x20 | ||
355 | #define AX_CMD_SW_PHY_STATUS 0x21 | ||
356 | #define AX_CMD_SW_PHY_SELECT 0x22 | ||
357 | #define AX88772_CMD_READ_NODE_ID 0x13 | ||
358 | |||
359 | #define AX_MONITOR_MODE 0x01 | ||
360 | #define AX_MONITOR_LINK 0x02 | ||
361 | #define AX_MONITOR_MAGIC 0x04 | ||
362 | #define AX_MONITOR_HSFS 0x10 | ||
363 | |||
364 | /* AX88172 Medium Status Register values */ | ||
365 | #define AX_MEDIUM_FULL_DUPLEX 0x02 | ||
366 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 | ||
367 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 | ||
368 | |||
369 | #define AX_MCAST_FILTER_SIZE 8 | ||
370 | #define AX_MAX_MCAST 64 | ||
371 | |||
372 | #define AX_EEPROM_LEN 0x40 | ||
373 | |||
374 | #define AX_SWRESET_CLEAR 0x00 | ||
375 | #define AX_SWRESET_RR 0x01 | ||
376 | #define AX_SWRESET_RT 0x02 | ||
377 | #define AX_SWRESET_PRTE 0x04 | ||
378 | #define AX_SWRESET_PRL 0x08 | ||
379 | #define AX_SWRESET_BZ 0x10 | ||
380 | #define AX_SWRESET_IPRL 0x20 | ||
381 | #define AX_SWRESET_IPPD 0x40 | ||
382 | |||
383 | #define AX88772_IPG0_DEFAULT 0x15 | ||
384 | #define AX88772_IPG1_DEFAULT 0x0c | ||
385 | #define AX88772_IPG2_DEFAULT 0x12 | ||
386 | |||
387 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 | ||
388 | #define AX88772_MEDIUM_RESERVED 0x0004 | ||
389 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 | ||
390 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 | ||
391 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 | ||
392 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 | ||
393 | #define AX88772_MEDIUM_100MB 0x0200 | ||
394 | #define AX88772_MEDIUM_DEFAULT \ | ||
395 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ | ||
396 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ | ||
397 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) | ||
398 | |||
399 | #define AX_EEPROM_MAGIC 0xdeadbeef | ||
400 | |||
401 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ | ||
402 | struct ax8817x_data { | ||
403 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; | ||
404 | }; | ||
405 | |||
406 | struct ax88172_int_data { | ||
407 | u16 res1; | ||
408 | u8 link; | ||
409 | u16 res2; | ||
410 | u8 status; | ||
411 | u16 res3; | ||
412 | } __attribute__ ((packed)); | ||
413 | |||
414 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
415 | u16 size, void *data) | ||
416 | { | ||
417 | return usb_control_msg( | ||
418 | dev->udev, | ||
419 | usb_rcvctrlpipe(dev->udev, 0), | ||
420 | cmd, | ||
421 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
422 | value, | ||
423 | index, | ||
424 | data, | ||
425 | size, | ||
426 | CONTROL_TIMEOUT_MS); | ||
427 | } | ||
428 | |||
429 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
430 | u16 size, void *data) | ||
431 | { | ||
432 | return usb_control_msg( | ||
433 | dev->udev, | ||
434 | usb_sndctrlpipe(dev->udev, 0), | ||
435 | cmd, | ||
436 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
437 | value, | ||
438 | index, | ||
439 | data, | ||
440 | size, | ||
441 | CONTROL_TIMEOUT_MS); | ||
442 | } | ||
443 | |||
444 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) | ||
445 | { | ||
446 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
447 | |||
448 | if (urb->status < 0) | ||
449 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", | ||
450 | urb->status); | ||
451 | |||
452 | kfree(req); | ||
453 | usb_free_urb(urb); | ||
454 | } | ||
455 | |||
456 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) | ||
457 | { | ||
458 | struct ax88172_int_data *event; | ||
459 | int link; | ||
460 | |||
461 | if (urb->actual_length < 8) | ||
462 | return; | ||
463 | |||
464 | event = urb->transfer_buffer; | ||
465 | link = event->link & 0x01; | ||
466 | if (netif_carrier_ok(dev->net) != link) { | ||
467 | if (link) { | ||
468 | netif_carrier_on(dev->net); | ||
469 | defer_kevent (dev, EVENT_LINK_RESET ); | ||
470 | } else | ||
471 | netif_carrier_off(dev->net); | ||
472 | devdbg(dev, "ax8817x - Link Status is: %d", link); | ||
473 | } | ||
474 | } | ||
475 | |||
476 | static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
477 | u16 size, void *data) | ||
478 | { | ||
479 | struct usb_ctrlrequest *req; | ||
480 | int status; | ||
481 | struct urb *urb; | ||
482 | |||
483 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { | ||
484 | devdbg(dev, "Error allocating URB in write_cmd_async!"); | ||
485 | return; | ||
486 | } | ||
487 | |||
488 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { | ||
489 | deverr(dev, "Failed to allocate memory for control request"); | ||
490 | usb_free_urb(urb); | ||
491 | return; | ||
492 | } | ||
493 | |||
494 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
495 | req->bRequest = cmd; | ||
496 | req->wValue = cpu_to_le16(value); | ||
497 | req->wIndex = cpu_to_le16(index); | ||
498 | req->wLength = cpu_to_le16(size); | ||
499 | |||
500 | usb_fill_control_urb(urb, dev->udev, | ||
501 | usb_sndctrlpipe(dev->udev, 0), | ||
502 | (void *)req, data, size, | ||
503 | ax8817x_async_cmd_callback, req); | ||
504 | |||
505 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
506 | deverr(dev, "Error submitting the control message: status=%d", status); | ||
507 | kfree(req); | ||
508 | usb_free_urb(urb); | ||
509 | } | ||
510 | } | ||
511 | |||
512 | static void ax8817x_set_multicast(struct net_device *net) | ||
513 | { | ||
514 | struct usbnet *dev = netdev_priv(net); | ||
515 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; | ||
516 | u8 rx_ctl = 0x8c; | ||
517 | |||
518 | if (net->flags & IFF_PROMISC) { | ||
519 | rx_ctl |= 0x01; | ||
520 | } else if (net->flags & IFF_ALLMULTI | ||
521 | || net->mc_count > AX_MAX_MCAST) { | ||
522 | rx_ctl |= 0x02; | ||
523 | } else if (net->mc_count == 0) { | ||
524 | /* just broadcast and directed */ | ||
525 | } else { | ||
526 | /* We use the 20 byte dev->data | ||
527 | * for our 8 byte filter buffer | ||
528 | * to avoid allocating memory that | ||
529 | * is tricky to free later */ | ||
530 | struct dev_mc_list *mc_list = net->mc_list; | ||
531 | u32 crc_bits; | ||
532 | int i; | ||
533 | |||
534 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); | ||
535 | |||
536 | /* Build the multicast hash filter. */ | ||
537 | for (i = 0; i < net->mc_count; i++) { | ||
538 | crc_bits = | ||
539 | ether_crc(ETH_ALEN, | ||
540 | mc_list->dmi_addr) >> 26; | ||
541 | data->multi_filter[crc_bits >> 3] |= | ||
542 | 1 << (crc_bits & 7); | ||
543 | mc_list = mc_list->next; | ||
544 | } | ||
545 | |||
546 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, | ||
547 | AX_MCAST_FILTER_SIZE, data->multi_filter); | ||
548 | |||
549 | rx_ctl |= 0x10; | ||
550 | } | ||
551 | |||
552 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); | ||
553 | } | ||
554 | |||
555 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
556 | { | ||
557 | struct usbnet *dev = netdev_priv(netdev); | ||
558 | u16 res; | ||
559 | u8 buf[1]; | ||
560 | |||
561 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
562 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
563 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
564 | |||
565 | return res & 0xffff; | ||
566 | } | ||
567 | |||
568 | static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | ||
569 | { | ||
570 | struct usbnet *dev = netdev_priv(netdev); | ||
571 | u16 res = val; | ||
572 | u8 buf[1]; | ||
573 | |||
574 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
575 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
576 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
577 | } | ||
578 | |||
579 | static int ax88172_link_reset(struct usbnet *dev) | ||
580 | { | ||
581 | u16 lpa; | ||
582 | u8 mode; | ||
583 | |||
584 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; | ||
585 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
586 | if (lpa & LPA_DUPLEX) | ||
587 | mode |= AX_MEDIUM_FULL_DUPLEX; | ||
588 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
589 | |||
590 | return 0; | ||
591 | } | ||
592 | |||
593 | static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
594 | { | ||
595 | struct usbnet *dev = netdev_priv(net); | ||
596 | u8 opt; | ||
597 | |||
598 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { | ||
599 | wolinfo->supported = 0; | ||
600 | wolinfo->wolopts = 0; | ||
601 | return; | ||
602 | } | ||
603 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; | ||
604 | wolinfo->wolopts = 0; | ||
605 | if (opt & AX_MONITOR_MODE) { | ||
606 | if (opt & AX_MONITOR_LINK) | ||
607 | wolinfo->wolopts |= WAKE_PHY; | ||
608 | if (opt & AX_MONITOR_MAGIC) | ||
609 | wolinfo->wolopts |= WAKE_MAGIC; | ||
610 | } | ||
611 | } | ||
612 | |||
613 | static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
614 | { | ||
615 | struct usbnet *dev = netdev_priv(net); | ||
616 | u8 opt = 0; | ||
617 | u8 buf[1]; | ||
618 | |||
619 | if (wolinfo->wolopts & WAKE_PHY) | ||
620 | opt |= AX_MONITOR_LINK; | ||
621 | if (wolinfo->wolopts & WAKE_MAGIC) | ||
622 | opt |= AX_MONITOR_MAGIC; | ||
623 | if (opt != 0) | ||
624 | opt |= AX_MONITOR_MODE; | ||
625 | |||
626 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, | ||
627 | opt, 0, 0, &buf) < 0) | ||
628 | return -EINVAL; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static int ax8817x_get_eeprom_len(struct net_device *net) | ||
634 | { | ||
635 | return AX_EEPROM_LEN; | ||
636 | } | ||
637 | |||
638 | static int ax8817x_get_eeprom(struct net_device *net, | ||
639 | struct ethtool_eeprom *eeprom, u8 *data) | ||
640 | { | ||
641 | struct usbnet *dev = netdev_priv(net); | ||
642 | u16 *ebuf = (u16 *)data; | ||
643 | int i; | ||
644 | |||
645 | /* Crude hack to ensure that we don't overwrite memory | ||
646 | * if an odd length is supplied | ||
647 | */ | ||
648 | if (eeprom->len % 2) | ||
649 | return -EINVAL; | ||
650 | |||
651 | eeprom->magic = AX_EEPROM_MAGIC; | ||
652 | |||
653 | /* ax8817x returns 2 bytes from eeprom on read */ | ||
654 | for (i=0; i < eeprom->len / 2; i++) { | ||
655 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, | ||
656 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) | ||
657 | return -EINVAL; | ||
658 | } | ||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | static void ax8817x_get_drvinfo (struct net_device *net, | ||
663 | struct ethtool_drvinfo *info) | ||
664 | { | ||
665 | /* Inherit standard device info */ | ||
666 | usbnet_get_drvinfo(net, info); | ||
667 | info->eedump_len = 0x3e; | ||
668 | } | ||
669 | |||
670 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
671 | { | ||
672 | struct usbnet *dev = netdev_priv(net); | ||
673 | |||
674 | return mii_ethtool_gset(&dev->mii,cmd); | ||
675 | } | ||
676 | |||
677 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
678 | { | ||
679 | struct usbnet *dev = netdev_priv(net); | ||
680 | |||
681 | return mii_ethtool_sset(&dev->mii,cmd); | ||
682 | } | ||
683 | |||
684 | /* We need to override some ethtool_ops so we require our | ||
685 | own structure so we don't interfere with other usbnet | ||
686 | devices that may be connected at the same time. */ | ||
687 | static struct ethtool_ops ax8817x_ethtool_ops = { | ||
688 | .get_drvinfo = ax8817x_get_drvinfo, | ||
689 | .get_link = ethtool_op_get_link, | ||
690 | .get_msglevel = usbnet_get_msglevel, | ||
691 | .set_msglevel = usbnet_set_msglevel, | ||
692 | .get_wol = ax8817x_get_wol, | ||
693 | .set_wol = ax8817x_set_wol, | ||
694 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
695 | .get_eeprom = ax8817x_get_eeprom, | ||
696 | .get_settings = ax8817x_get_settings, | ||
697 | .set_settings = ax8817x_set_settings, | ||
698 | }; | ||
699 | |||
700 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) | ||
701 | { | ||
702 | int ret = 0; | ||
703 | void *buf; | ||
704 | int i; | ||
705 | unsigned long gpio_bits = dev->driver_info->data; | ||
706 | |||
707 | get_endpoints(dev,intf); | ||
708 | |||
709 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); | ||
710 | if(!buf) { | ||
711 | ret = -ENOMEM; | ||
712 | goto out1; | ||
713 | } | ||
714 | |||
715 | /* Toggle the GPIOs in a manufacturer/model specific way */ | ||
716 | for (i = 2; i >= 0; i--) { | ||
717 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
718 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, | ||
719 | buf)) < 0) | ||
720 | goto out2; | ||
721 | msleep(5); | ||
722 | } | ||
723 | |||
724 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) { | ||
725 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); | ||
726 | goto out2; | ||
727 | } | ||
728 | |||
729 | /* Get the MAC address */ | ||
730 | memset(buf, 0, ETH_ALEN); | ||
731 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) { | ||
732 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); | ||
733 | goto out2; | ||
734 | } | ||
735 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
736 | |||
737 | /* Get the PHY id */ | ||
738 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
739 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); | ||
740 | goto out2; | ||
741 | } else if (ret < 2) { | ||
742 | /* this should always return 2 bytes */ | ||
743 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret); | ||
744 | ret = -EIO; | ||
745 | goto out2; | ||
746 | } | ||
747 | |||
748 | /* Initialize MII structure */ | ||
749 | dev->mii.dev = dev->net; | ||
750 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
751 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
752 | dev->mii.phy_id_mask = 0x3f; | ||
753 | dev->mii.reg_num_mask = 0x1f; | ||
754 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
755 | |||
756 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
757 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; | ||
758 | |||
759 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
760 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
761 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
762 | mii_nway_restart(&dev->mii); | ||
763 | |||
764 | if (dev->driver_info->flags & FLAG_FRAMING_AX) { | ||
765 | /* REVISIT: adjust hard_header_len too */ | ||
766 | dev->hard_mtu = 2048; | ||
767 | } | ||
768 | |||
769 | return 0; | ||
770 | out2: | ||
771 | kfree(buf); | ||
772 | out1: | ||
773 | return ret; | ||
774 | } | ||
775 | |||
776 | static struct ethtool_ops ax88772_ethtool_ops = { | ||
777 | .get_drvinfo = ax8817x_get_drvinfo, | ||
778 | .get_link = ethtool_op_get_link, | ||
779 | .get_msglevel = usbnet_get_msglevel, | ||
780 | .set_msglevel = usbnet_set_msglevel, | ||
781 | .get_wol = ax8817x_get_wol, | ||
782 | .set_wol = ax8817x_set_wol, | ||
783 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
784 | .get_eeprom = ax8817x_get_eeprom, | ||
785 | .get_settings = ax8817x_get_settings, | ||
786 | .set_settings = ax8817x_set_settings, | ||
787 | }; | ||
788 | |||
789 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
790 | { | ||
791 | int ret; | ||
792 | void *buf; | ||
793 | |||
794 | get_endpoints(dev,intf); | ||
795 | |||
796 | buf = kmalloc(6, GFP_KERNEL); | ||
797 | if(!buf) { | ||
798 | dbg ("Cannot allocate memory for buffer"); | ||
799 | ret = -ENOMEM; | ||
800 | goto out1; | ||
801 | } | ||
802 | |||
803 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
804 | 0x00B0, 0, 0, buf)) < 0) | ||
805 | goto out2; | ||
806 | |||
807 | msleep(5); | ||
808 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) { | ||
809 | dbg("Select PHY #1 failed: %d", ret); | ||
810 | goto out2; | ||
811 | } | ||
812 | |||
813 | if ((ret = | ||
814 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) { | ||
815 | dbg("Failed to power down internal PHY: %d", ret); | ||
816 | goto out2; | ||
817 | } | ||
818 | |||
819 | msleep(150); | ||
820 | if ((ret = | ||
821 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) { | ||
822 | dbg("Failed to perform software reset: %d", ret); | ||
823 | goto out2; | ||
824 | } | ||
825 | |||
826 | msleep(150); | ||
827 | if ((ret = | ||
828 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
829 | dbg("Failed to set Internal/External PHY reset control: %d", ret); | ||
830 | goto out2; | ||
831 | } | ||
832 | |||
833 | msleep(150); | ||
834 | if ((ret = | ||
835 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0, | ||
836 | buf)) < 0) { | ||
837 | dbg("Failed to reset RX_CTL: %d", ret); | ||
838 | goto out2; | ||
839 | } | ||
840 | |||
841 | /* Get the MAC address */ | ||
842 | memset(buf, 0, ETH_ALEN); | ||
843 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) { | ||
844 | dbg("Failed to read MAC address: %d", ret); | ||
845 | goto out2; | ||
846 | } | ||
847 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
848 | |||
849 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) { | ||
850 | dbg("Enabling software MII failed: %d", ret); | ||
851 | goto out2; | ||
852 | } | ||
853 | |||
854 | if (((ret = | ||
855 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0) | ||
856 | || (*((u16 *)buf) != 0x003b)) { | ||
857 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); | ||
858 | goto out2; | ||
859 | } | ||
860 | |||
861 | /* Initialize MII structure */ | ||
862 | dev->mii.dev = dev->net; | ||
863 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
864 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
865 | dev->mii.phy_id_mask = 0xff; | ||
866 | dev->mii.reg_num_mask = 0xff; | ||
867 | |||
868 | /* Get the PHY id */ | ||
869 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
870 | dbg("Error reading PHY ID: %02x", ret); | ||
871 | goto out2; | ||
872 | } else if (ret < 2) { | ||
873 | /* this should always return 2 bytes */ | ||
874 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
875 | ret); | ||
876 | ret = -EIO; | ||
877 | goto out2; | ||
878 | } | ||
879 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
880 | |||
881 | if ((ret = | ||
882 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
883 | dbg("Set external PHY reset pin level: %d", ret); | ||
884 | goto out2; | ||
885 | } | ||
886 | msleep(150); | ||
887 | if ((ret = | ||
888 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
889 | dbg("Set Internal/External PHY reset control: %d", ret); | ||
890 | goto out2; | ||
891 | } | ||
892 | msleep(150); | ||
893 | |||
894 | |||
895 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
896 | dev->net->ethtool_ops = &ax88772_ethtool_ops; | ||
897 | |||
898 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
899 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
900 | ADVERTISE_ALL | ADVERTISE_CSMA); | ||
901 | mii_nway_restart(&dev->mii); | ||
902 | |||
903 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { | ||
904 | dbg("Write medium mode register: %d", ret); | ||
905 | goto out2; | ||
906 | } | ||
907 | |||
908 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) { | ||
909 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); | ||
910 | goto out2; | ||
911 | } | ||
912 | if ((ret = | ||
913 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { | ||
914 | dbg("Failed to set hardware MII: %02x", ret); | ||
915 | goto out2; | ||
916 | } | ||
917 | |||
918 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ | ||
919 | if ((ret = | ||
920 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, | ||
921 | buf)) < 0) { | ||
922 | dbg("Reset RX_CTL failed: %d", ret); | ||
923 | goto out2; | ||
924 | } | ||
925 | |||
926 | kfree(buf); | ||
927 | |||
928 | return 0; | ||
929 | |||
930 | out2: | ||
931 | kfree(buf); | ||
932 | out1: | ||
933 | return ret; | ||
934 | } | ||
935 | |||
936 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
937 | { | ||
938 | u32 *header; | ||
939 | char *packet; | ||
940 | struct sk_buff *ax_skb; | ||
941 | u16 size; | ||
942 | |||
943 | header = (u32 *) skb->data; | ||
944 | le32_to_cpus(header); | ||
945 | packet = (char *)(header + 1); | ||
946 | |||
947 | skb_pull(skb, 4); | ||
948 | |||
949 | while (skb->len > 0) { | ||
950 | if ((short)(*header & 0x0000ffff) != | ||
951 | ~((short)((*header & 0xffff0000) >> 16))) { | ||
952 | devdbg(dev,"header length data is error"); | ||
953 | } | ||
954 | /* get the packet length */ | ||
955 | size = (u16) (*header & 0x0000ffff); | ||
956 | |||
957 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) | ||
958 | return 2; | ||
959 | if (size > ETH_FRAME_LEN) { | ||
960 | devdbg(dev,"invalid rx length %d", size); | ||
961 | return 0; | ||
962 | } | ||
963 | ax_skb = skb_clone(skb, GFP_ATOMIC); | ||
964 | if (ax_skb) { | ||
965 | ax_skb->len = size; | ||
966 | ax_skb->data = packet; | ||
967 | ax_skb->tail = packet + size; | ||
968 | skb_return(dev, ax_skb); | ||
969 | } else { | ||
970 | return 0; | ||
971 | } | ||
972 | |||
973 | skb_pull(skb, (size + 1) & 0xfffe); | ||
974 | |||
975 | if (skb->len == 0) | ||
976 | break; | ||
977 | |||
978 | header = (u32 *) skb->data; | ||
979 | le32_to_cpus(header); | ||
980 | packet = (char *)(header + 1); | ||
981 | skb_pull(skb, 4); | ||
982 | } | ||
983 | |||
984 | if (skb->len < 0) { | ||
985 | devdbg(dev,"invalid rx length %d", skb->len); | ||
986 | return 0; | ||
987 | } | ||
988 | return 1; | ||
989 | } | ||
990 | |||
991 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
992 | unsigned flags) | ||
993 | { | ||
994 | int padlen; | ||
995 | int headroom = skb_headroom(skb); | ||
996 | int tailroom = skb_tailroom(skb); | ||
997 | u32 *packet_len; | ||
998 | u32 *padbytes_ptr; | ||
999 | |||
1000 | padlen = ((skb->len + 4) % 512) ? 0 : 4; | ||
1001 | |||
1002 | if ((!skb_cloned(skb)) | ||
1003 | && ((headroom + tailroom) >= (4 + padlen))) { | ||
1004 | if ((headroom < 4) || (tailroom < padlen)) { | ||
1005 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | ||
1006 | skb->tail = skb->data + skb->len; | ||
1007 | } | ||
1008 | } else { | ||
1009 | struct sk_buff *skb2; | ||
1010 | skb2 = skb_copy_expand(skb, 4, padlen, flags); | ||
1011 | dev_kfree_skb_any(skb); | ||
1012 | skb = skb2; | ||
1013 | if (!skb) | ||
1014 | return NULL; | ||
1015 | } | ||
1016 | |||
1017 | packet_len = (u32 *) skb_push(skb, 4); | ||
1018 | |||
1019 | packet_len = (u32 *) skb->data; | ||
1020 | *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | ||
1021 | |||
1022 | if ((skb->len % 512) == 0) { | ||
1023 | padbytes_ptr = (u32 *) skb->tail; | ||
1024 | *padbytes_ptr = 0xffff0000; | ||
1025 | skb_put(skb, padlen); | ||
1026 | } | ||
1027 | return skb; | ||
1028 | } | ||
1029 | |||
1030 | static int ax88772_link_reset(struct usbnet *dev) | ||
1031 | { | ||
1032 | u16 lpa; | ||
1033 | u16 mode; | ||
1034 | |||
1035 | mode = AX88772_MEDIUM_DEFAULT; | ||
1036 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
1037 | |||
1038 | if ((lpa & LPA_DUPLEX) == 0) | ||
1039 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; | ||
1040 | if ((lpa & LPA_100) == 0) | ||
1041 | mode &= ~AX88772_MEDIUM_100MB; | ||
1042 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
1043 | |||
1044 | return 0; | ||
1045 | } | ||
1046 | |||
1047 | static const struct driver_info ax8817x_info = { | ||
1048 | .description = "ASIX AX8817x USB 2.0 Ethernet", | ||
1049 | .bind = ax8817x_bind, | ||
1050 | .status = ax8817x_status, | ||
1051 | .link_reset = ax88172_link_reset, | ||
1052 | .reset = ax88172_link_reset, | ||
1053 | .flags = FLAG_ETHER, | ||
1054 | .data = 0x00130103, | ||
1055 | }; | ||
1056 | |||
1057 | static const struct driver_info dlink_dub_e100_info = { | ||
1058 | .description = "DLink DUB-E100 USB Ethernet", | ||
1059 | .bind = ax8817x_bind, | ||
1060 | .status = ax8817x_status, | ||
1061 | .link_reset = ax88172_link_reset, | ||
1062 | .reset = ax88172_link_reset, | ||
1063 | .flags = FLAG_ETHER, | ||
1064 | .data = 0x009f9d9f, | ||
1065 | }; | ||
1066 | |||
1067 | static const struct driver_info netgear_fa120_info = { | ||
1068 | .description = "Netgear FA-120 USB Ethernet", | ||
1069 | .bind = ax8817x_bind, | ||
1070 | .status = ax8817x_status, | ||
1071 | .link_reset = ax88172_link_reset, | ||
1072 | .reset = ax88172_link_reset, | ||
1073 | .flags = FLAG_ETHER, | ||
1074 | .data = 0x00130103, | ||
1075 | }; | ||
1076 | |||
1077 | static const struct driver_info hawking_uf200_info = { | ||
1078 | .description = "Hawking UF200 USB Ethernet", | ||
1079 | .bind = ax8817x_bind, | ||
1080 | .status = ax8817x_status, | ||
1081 | .link_reset = ax88172_link_reset, | ||
1082 | .reset = ax88172_link_reset, | ||
1083 | .flags = FLAG_ETHER, | ||
1084 | .data = 0x001f1d1f, | ||
1085 | }; | ||
1086 | |||
1087 | static const struct driver_info ax88772_info = { | ||
1088 | .description = "ASIX AX88772 USB 2.0 Ethernet", | ||
1089 | .bind = ax88772_bind, | ||
1090 | .status = ax8817x_status, | ||
1091 | .link_reset = ax88772_link_reset, | ||
1092 | .reset = ax88772_link_reset, | ||
1093 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, | ||
1094 | .rx_fixup = ax88772_rx_fixup, | ||
1095 | .tx_fixup = ax88772_tx_fixup, | ||
1096 | .data = 0x00130103, | ||
1097 | }; | ||
1098 | |||
1099 | #endif /* CONFIG_USB_AX8817X */ | ||
1100 | |||
1101 | 319 | ||
1102 | 320 | ||
1103 | /*------------------------------------------------------------------------- | 321 | /*------------------------------------------------------------------------- |
@@ -1284,7 +502,7 @@ next_desc: | |||
1284 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); | 502 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); |
1285 | if (status < 0) | 503 | if (status < 0) |
1286 | return status; | 504 | return status; |
1287 | status = get_endpoints (dev, info->data); | 505 | status = usbnet_get_endpoints (dev, info->data); |
1288 | if (status < 0) { | 506 | if (status < 0) { |
1289 | /* ensure immediate exit from usbnet_disconnect */ | 507 | /* ensure immediate exit from usbnet_disconnect */ |
1290 | usb_set_intfdata(info->data, NULL); | 508 | usb_set_intfdata(info->data, NULL); |
@@ -1721,7 +939,7 @@ static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb) | |||
1721 | 939 | ||
1722 | // copy the packet data to the new skb | 940 | // copy the packet data to the new skb |
1723 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); | 941 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); |
1724 | skb_return (dev, gl_skb); | 942 | usbnet_skb_return (dev, gl_skb); |
1725 | } | 943 | } |
1726 | 944 | ||
1727 | // advance to the next packet | 945 | // advance to the next packet |
@@ -2616,7 +1834,7 @@ next_desc: | |||
2616 | * bother to make it unique. Likewise there's no point in tracking | 1834 | * bother to make it unique. Likewise there's no point in tracking |
2617 | * of the CDC event notifications. | 1835 | * of the CDC event notifications. |
2618 | */ | 1836 | */ |
2619 | return get_endpoints (dev, intf); | 1837 | return usbnet_get_endpoints (dev, intf); |
2620 | 1838 | ||
2621 | bad_desc: | 1839 | bad_desc: |
2622 | dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n"); | 1840 | dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n"); |
@@ -2694,7 +1912,7 @@ static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_hea | |||
2694 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, | 1912 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, |
2695 | * but tasklet_schedule() doesn't. hope the failure is rare. | 1913 | * but tasklet_schedule() doesn't. hope the failure is rare. |
2696 | */ | 1914 | */ |
2697 | static void defer_kevent (struct usbnet *dev, int work) | 1915 | void usbnet_defer_kevent (struct usbnet *dev, int work) |
2698 | { | 1916 | { |
2699 | set_bit (work, &dev->flags); | 1917 | set_bit (work, &dev->flags); |
2700 | if (!schedule_work (&dev->kevent)) | 1918 | if (!schedule_work (&dev->kevent)) |
@@ -2702,6 +1920,7 @@ static void defer_kevent (struct usbnet *dev, int work) | |||
2702 | else | 1920 | else |
2703 | devdbg (dev, "kevent %d scheduled", work); | 1921 | devdbg (dev, "kevent %d scheduled", work); |
2704 | } | 1922 | } |
1923 | EXPORT_SYMBOL_GPL(usbnet_defer_kevent); | ||
2705 | 1924 | ||
2706 | /*-------------------------------------------------------------------------*/ | 1925 | /*-------------------------------------------------------------------------*/ |
2707 | 1926 | ||
@@ -2713,14 +1932,12 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) | |||
2713 | struct skb_data *entry; | 1932 | struct skb_data *entry; |
2714 | int retval = 0; | 1933 | int retval = 0; |
2715 | unsigned long lockflags; | 1934 | unsigned long lockflags; |
2716 | size_t size; | 1935 | size_t size = dev->rx_urb_size; |
2717 | 1936 | ||
2718 | size = max(dev->net->hard_header_len + dev->net->mtu, | ||
2719 | (unsigned)ETH_FRAME_LEN); | ||
2720 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { | 1937 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { |
2721 | if (netif_msg_rx_err (dev)) | 1938 | if (netif_msg_rx_err (dev)) |
2722 | devdbg (dev, "no rx skb"); | 1939 | devdbg (dev, "no rx skb"); |
2723 | defer_kevent (dev, EVENT_RX_MEMORY); | 1940 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
2724 | usb_free_urb (urb); | 1941 | usb_free_urb (urb); |
2725 | return; | 1942 | return; |
2726 | } | 1943 | } |
@@ -2742,10 +1959,10 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) | |||
2742 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 1959 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
2743 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ | 1960 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ |
2744 | case -EPIPE: | 1961 | case -EPIPE: |
2745 | defer_kevent (dev, EVENT_RX_HALT); | 1962 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
2746 | break; | 1963 | break; |
2747 | case -ENOMEM: | 1964 | case -ENOMEM: |
2748 | defer_kevent (dev, EVENT_RX_MEMORY); | 1965 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
2749 | break; | 1966 | break; |
2750 | case -ENODEV: | 1967 | case -ENODEV: |
2751 | if (netif_msg_ifdown (dev)) | 1968 | if (netif_msg_ifdown (dev)) |
@@ -2783,7 +2000,7 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) | |||
2783 | // else network stack removes extra byte if we forced a short packet | 2000 | // else network stack removes extra byte if we forced a short packet |
2784 | 2001 | ||
2785 | if (skb->len) | 2002 | if (skb->len) |
2786 | skb_return (dev, skb); | 2003 | usbnet_skb_return (dev, skb); |
2787 | else { | 2004 | else { |
2788 | if (netif_msg_rx_err (dev)) | 2005 | if (netif_msg_rx_err (dev)) |
2789 | devdbg (dev, "drop"); | 2006 | devdbg (dev, "drop"); |
@@ -2824,7 +2041,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs) | |||
2824 | // storm, recovering as needed. | 2041 | // storm, recovering as needed. |
2825 | case -EPIPE: | 2042 | case -EPIPE: |
2826 | dev->stats.rx_errors++; | 2043 | dev->stats.rx_errors++; |
2827 | defer_kevent (dev, EVENT_RX_HALT); | 2044 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
2828 | // FALLTHROUGH | 2045 | // FALLTHROUGH |
2829 | 2046 | ||
2830 | // software-driven interface shutdown | 2047 | // software-driven interface shutdown |
@@ -3066,16 +2283,22 @@ done: | |||
3066 | 2283 | ||
3067 | /*-------------------------------------------------------------------------*/ | 2284 | /*-------------------------------------------------------------------------*/ |
3068 | 2285 | ||
3069 | static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | 2286 | /* ethtool methods; minidrivers may need to add some more, but |
2287 | * they'll probably want to use this base set. | ||
2288 | */ | ||
2289 | |||
2290 | void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | ||
3070 | { | 2291 | { |
3071 | struct usbnet *dev = netdev_priv(net); | 2292 | struct usbnet *dev = netdev_priv(net); |
3072 | 2293 | ||
2294 | /* REVISIT don't always return "usbnet" */ | ||
3073 | strncpy (info->driver, driver_name, sizeof info->driver); | 2295 | strncpy (info->driver, driver_name, sizeof info->driver); |
3074 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); | 2296 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); |
3075 | strncpy (info->fw_version, dev->driver_info->description, | 2297 | strncpy (info->fw_version, dev->driver_info->description, |
3076 | sizeof info->fw_version); | 2298 | sizeof info->fw_version); |
3077 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); | 2299 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); |
3078 | } | 2300 | } |
2301 | EXPORT_SYMBOL_GPL(usbnet_get_drvinfo); | ||
3079 | 2302 | ||
3080 | static u32 usbnet_get_link (struct net_device *net) | 2303 | static u32 usbnet_get_link (struct net_device *net) |
3081 | { | 2304 | { |
@@ -3089,32 +2312,29 @@ static u32 usbnet_get_link (struct net_device *net) | |||
3089 | return 1; | 2312 | return 1; |
3090 | } | 2313 | } |
3091 | 2314 | ||
3092 | static u32 usbnet_get_msglevel (struct net_device *net) | 2315 | u32 usbnet_get_msglevel (struct net_device *net) |
3093 | { | 2316 | { |
3094 | struct usbnet *dev = netdev_priv(net); | 2317 | struct usbnet *dev = netdev_priv(net); |
3095 | 2318 | ||
3096 | return dev->msg_enable; | 2319 | return dev->msg_enable; |
3097 | } | 2320 | } |
2321 | EXPORT_SYMBOL_GPL(usbnet_get_msglevel); | ||
3098 | 2322 | ||
3099 | static void usbnet_set_msglevel (struct net_device *net, u32 level) | 2323 | void usbnet_set_msglevel (struct net_device *net, u32 level) |
3100 | { | 2324 | { |
3101 | struct usbnet *dev = netdev_priv(net); | 2325 | struct usbnet *dev = netdev_priv(net); |
3102 | 2326 | ||
3103 | dev->msg_enable = level; | 2327 | dev->msg_enable = level; |
3104 | } | 2328 | } |
2329 | EXPORT_SYMBOL_GPL(usbnet_set_msglevel); | ||
3105 | 2330 | ||
3106 | static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) | 2331 | /* drivers may override default ethtool_ops in their bind() routine */ |
3107 | { | 2332 | static struct ethtool_ops usbnet_ethtool_ops = { |
3108 | #ifdef NEED_MII | 2333 | .get_drvinfo = usbnet_get_drvinfo, |
3109 | { | 2334 | .get_link = usbnet_get_link, |
3110 | struct usbnet *dev = netdev_priv(net); | 2335 | .get_msglevel = usbnet_get_msglevel, |
3111 | 2336 | .set_msglevel = usbnet_set_msglevel, | |
3112 | if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) | 2337 | }; |
3113 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
3114 | } | ||
3115 | #endif | ||
3116 | return -EOPNOTSUPP; | ||
3117 | } | ||
3118 | 2338 | ||
3119 | /*-------------------------------------------------------------------------*/ | 2339 | /*-------------------------------------------------------------------------*/ |
3120 | 2340 | ||
@@ -3209,7 +2429,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs) | |||
3209 | 2429 | ||
3210 | switch (urb->status) { | 2430 | switch (urb->status) { |
3211 | case -EPIPE: | 2431 | case -EPIPE: |
3212 | defer_kevent (dev, EVENT_TX_HALT); | 2432 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3213 | break; | 2433 | break; |
3214 | 2434 | ||
3215 | /* software-driven interface shutdown */ | 2435 | /* software-driven interface shutdown */ |
@@ -3339,7 +2559,7 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
3339 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { | 2559 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { |
3340 | case -EPIPE: | 2560 | case -EPIPE: |
3341 | netif_stop_queue (net); | 2561 | netif_stop_queue (net); |
3342 | defer_kevent (dev, EVENT_TX_HALT); | 2562 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3343 | break; | 2563 | break; |
3344 | default: | 2564 | default: |
3345 | if (netif_msg_tx_err (dev)) | 2565 | if (netif_msg_tx_err (dev)) |
@@ -3478,8 +2698,6 @@ EXPORT_SYMBOL_GPL(usbnet_disconnect); | |||
3478 | 2698 | ||
3479 | /*-------------------------------------------------------------------------*/ | 2699 | /*-------------------------------------------------------------------------*/ |
3480 | 2700 | ||
3481 | static struct ethtool_ops usbnet_ethtool_ops; | ||
3482 | |||
3483 | // precondition: never called in_interrupt | 2701 | // precondition: never called in_interrupt |
3484 | 2702 | ||
3485 | int | 2703 | int |
@@ -3530,8 +2748,11 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3530 | dev->net = net; | 2748 | dev->net = net; |
3531 | strcpy (net->name, "usb%d"); | 2749 | strcpy (net->name, "usb%d"); |
3532 | memcpy (net->dev_addr, node_id, sizeof node_id); | 2750 | memcpy (net->dev_addr, node_id, sizeof node_id); |
3533 | dev->hard_mtu = net->mtu + net->hard_header_len; | ||
3534 | 2751 | ||
2752 | /* rx and tx sides can use different message sizes; | ||
2753 | * bind() should set rx_urb_size in that case. | ||
2754 | */ | ||
2755 | dev->hard_mtu = net->mtu + net->hard_header_len; | ||
3535 | #if 0 | 2756 | #if 0 |
3536 | // dma_supported() is deeply broken on almost all architectures | 2757 | // dma_supported() is deeply broken on almost all architectures |
3537 | // possible with some EHCI controllers | 2758 | // possible with some EHCI controllers |
@@ -3546,7 +2767,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3546 | net->stop = usbnet_stop; | 2767 | net->stop = usbnet_stop; |
3547 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; | 2768 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; |
3548 | net->tx_timeout = usbnet_tx_timeout; | 2769 | net->tx_timeout = usbnet_tx_timeout; |
3549 | net->do_ioctl = usbnet_ioctl; | ||
3550 | net->ethtool_ops = &usbnet_ethtool_ops; | 2770 | net->ethtool_ops = &usbnet_ethtool_ops; |
3551 | 2771 | ||
3552 | // allow device-specific bind/init procedures | 2772 | // allow device-specific bind/init procedures |
@@ -3563,8 +2783,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3563 | /* maybe the remote can't receive an Ethernet MTU */ | 2783 | /* maybe the remote can't receive an Ethernet MTU */ |
3564 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) | 2784 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) |
3565 | net->mtu = dev->hard_mtu - net->hard_header_len; | 2785 | net->mtu = dev->hard_mtu - net->hard_header_len; |
3566 | } else if (!info->in || info->out) | 2786 | } else if (!info->in || !info->out) |
3567 | status = get_endpoints (dev, udev); | 2787 | status = usbnet_get_endpoints (dev, udev); |
3568 | else { | 2788 | else { |
3569 | dev->in = usb_rcvbulkpipe (xdev, info->in); | 2789 | dev->in = usb_rcvbulkpipe (xdev, info->in); |
3570 | dev->out = usb_sndbulkpipe (xdev, info->out); | 2790 | dev->out = usb_sndbulkpipe (xdev, info->out); |
@@ -3581,6 +2801,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3581 | if (status < 0) | 2801 | if (status < 0) |
3582 | goto out1; | 2802 | goto out1; |
3583 | 2803 | ||
2804 | if (!dev->rx_urb_size) | ||
2805 | dev->rx_urb_size = dev->hard_mtu; | ||
3584 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); | 2806 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); |
3585 | 2807 | ||
3586 | SET_NETDEV_DEV(net, &udev->dev); | 2808 | SET_NETDEV_DEV(net, &udev->dev); |
@@ -3662,62 +2884,6 @@ EXPORT_SYMBOL_GPL(usbnet_resume); | |||
3662 | 2884 | ||
3663 | static const struct usb_device_id products [] = { | 2885 | static const struct usb_device_id products [] = { |
3664 | 2886 | ||
3665 | #ifdef CONFIG_USB_AX8817X | ||
3666 | { | ||
3667 | // Linksys USB200M | ||
3668 | USB_DEVICE (0x077b, 0x2226), | ||
3669 | .driver_info = (unsigned long) &ax8817x_info, | ||
3670 | }, { | ||
3671 | // Netgear FA120 | ||
3672 | USB_DEVICE (0x0846, 0x1040), | ||
3673 | .driver_info = (unsigned long) &netgear_fa120_info, | ||
3674 | }, { | ||
3675 | // DLink DUB-E100 | ||
3676 | USB_DEVICE (0x2001, 0x1a00), | ||
3677 | .driver_info = (unsigned long) &dlink_dub_e100_info, | ||
3678 | }, { | ||
3679 | // Intellinet, ST Lab USB Ethernet | ||
3680 | USB_DEVICE (0x0b95, 0x1720), | ||
3681 | .driver_info = (unsigned long) &ax8817x_info, | ||
3682 | }, { | ||
3683 | // Hawking UF200, TrendNet TU2-ET100 | ||
3684 | USB_DEVICE (0x07b8, 0x420a), | ||
3685 | .driver_info = (unsigned long) &hawking_uf200_info, | ||
3686 | }, { | ||
3687 | // Billionton Systems, USB2AR | ||
3688 | USB_DEVICE (0x08dd, 0x90ff), | ||
3689 | .driver_info = (unsigned long) &ax8817x_info, | ||
3690 | }, { | ||
3691 | // ATEN UC210T | ||
3692 | USB_DEVICE (0x0557, 0x2009), | ||
3693 | .driver_info = (unsigned long) &ax8817x_info, | ||
3694 | }, { | ||
3695 | // Buffalo LUA-U2-KTX | ||
3696 | USB_DEVICE (0x0411, 0x003d), | ||
3697 | .driver_info = (unsigned long) &ax8817x_info, | ||
3698 | }, { | ||
3699 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" | ||
3700 | USB_DEVICE (0x6189, 0x182d), | ||
3701 | .driver_info = (unsigned long) &ax8817x_info, | ||
3702 | }, { | ||
3703 | // corega FEther USB2-TX | ||
3704 | USB_DEVICE (0x07aa, 0x0017), | ||
3705 | .driver_info = (unsigned long) &ax8817x_info, | ||
3706 | }, { | ||
3707 | // Surecom EP-1427X-2 | ||
3708 | USB_DEVICE (0x1189, 0x0893), | ||
3709 | .driver_info = (unsigned long) &ax8817x_info, | ||
3710 | }, { | ||
3711 | // goodway corp usb gwusb2e | ||
3712 | USB_DEVICE (0x1631, 0x6200), | ||
3713 | .driver_info = (unsigned long) &ax8817x_info, | ||
3714 | }, { | ||
3715 | // ASIX AX88772 10/100 | ||
3716 | USB_DEVICE (0x0b95, 0x7720), | ||
3717 | .driver_info = (unsigned long) &ax88772_info, | ||
3718 | }, | ||
3719 | #endif | ||
3720 | |||
3721 | #ifdef CONFIG_USB_GENESYS | 2887 | #ifdef CONFIG_USB_GENESYS |
3722 | { | 2888 | { |
3723 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A | 2889 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A |
@@ -3881,14 +3047,6 @@ static struct usb_driver usbnet_driver = { | |||
3881 | .resume = usbnet_resume, | 3047 | .resume = usbnet_resume, |
3882 | }; | 3048 | }; |
3883 | 3049 | ||
3884 | /* Default ethtool_ops assigned. Devices can override in their bind() routine */ | ||
3885 | static struct ethtool_ops usbnet_ethtool_ops = { | ||
3886 | .get_drvinfo = usbnet_get_drvinfo, | ||
3887 | .get_link = usbnet_get_link, | ||
3888 | .get_msglevel = usbnet_get_msglevel, | ||
3889 | .set_msglevel = usbnet_set_msglevel, | ||
3890 | }; | ||
3891 | |||
3892 | /*-------------------------------------------------------------------------*/ | 3050 | /*-------------------------------------------------------------------------*/ |
3893 | 3051 | ||
3894 | static int __init usbnet_init(void) | 3052 | static int __init usbnet_init(void) |