2 * ASIX AX8817X based USB 2.0 Ethernet Devices
3 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
5 * Copyright (c) 2002-2003 TiVo Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 // #define DEBUG // error path messages, extra info
23 // #define VERBOSE // more; success messages
25 #include <linux/module.h>
26 #include <linux/kmod.h>
27 #include <linux/sched.h>
28 #include <linux/init.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/ethtool.h>
32 #include <linux/workqueue.h>
33 #include <linux/mii.h>
34 #include <linux/usb.h>
35 #include <linux/crc32.h>
39 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
41 #define AX_CMD_SET_SW_MII 0x06
42 #define AX_CMD_READ_MII_REG 0x07
43 #define AX_CMD_WRITE_MII_REG 0x08
44 #define AX_CMD_SET_HW_MII 0x0a
45 #define AX_CMD_READ_EEPROM 0x0b
46 #define AX_CMD_WRITE_EEPROM 0x0c
47 #define AX_CMD_WRITE_ENABLE 0x0d
48 #define AX_CMD_WRITE_DISABLE 0x0e
49 #define AX_CMD_WRITE_RX_CTL 0x10
50 #define AX_CMD_READ_IPG012 0x11
51 #define AX_CMD_WRITE_IPG0 0x12
52 #define AX_CMD_WRITE_IPG1 0x13
53 #define AX_CMD_WRITE_IPG2 0x14
54 #define AX_CMD_WRITE_MULTI_FILTER 0x16
55 #define AX_CMD_READ_NODE_ID 0x17
56 #define AX_CMD_READ_PHY_ID 0x19
57 #define AX_CMD_READ_MEDIUM_STATUS 0x1a
58 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
59 #define AX_CMD_READ_MONITOR_MODE 0x1c
60 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
61 #define AX_CMD_WRITE_GPIOS 0x1f
62 #define AX_CMD_SW_RESET 0x20
63 #define AX_CMD_SW_PHY_STATUS 0x21
64 #define AX_CMD_SW_PHY_SELECT 0x22
65 #define AX88772_CMD_READ_NODE_ID 0x13
67 #define AX_MONITOR_MODE 0x01
68 #define AX_MONITOR_LINK 0x02
69 #define AX_MONITOR_MAGIC 0x04
70 #define AX_MONITOR_HSFS 0x10
72 /* AX88172 Medium Status Register values */
73 #define AX_MEDIUM_FULL_DUPLEX 0x02
74 #define AX_MEDIUM_TX_ABORT_ALLOW 0x04
75 #define AX_MEDIUM_FLOW_CONTROL_EN 0x10
77 #define AX_MCAST_FILTER_SIZE 8
78 #define AX_MAX_MCAST 64
80 #define AX_EEPROM_LEN 0x40
82 #define AX_SWRESET_CLEAR 0x00
83 #define AX_SWRESET_RR 0x01
84 #define AX_SWRESET_RT 0x02
85 #define AX_SWRESET_PRTE 0x04
86 #define AX_SWRESET_PRL 0x08
87 #define AX_SWRESET_BZ 0x10
88 #define AX_SWRESET_IPRL 0x20
89 #define AX_SWRESET_IPPD 0x40
91 #define AX88772_IPG0_DEFAULT 0x15
92 #define AX88772_IPG1_DEFAULT 0x0c
93 #define AX88772_IPG2_DEFAULT 0x12
95 #define AX88772_MEDIUM_FULL_DUPLEX 0x0002
96 #define AX88772_MEDIUM_RESERVED 0x0004
97 #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
98 #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
99 #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
100 #define AX88772_MEDIUM_RX_ENABLE 0x0100
101 #define AX88772_MEDIUM_100MB 0x0200
102 #define AX88772_MEDIUM_DEFAULT \
103 (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
104 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
105 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
107 #define AX_EEPROM_MAGIC 0xdeadbeef
109 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
111 u8 multi_filter[AX_MCAST_FILTER_SIZE];
114 struct ax88172_int_data {
120 } __attribute__ ((packed));
122 static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
123 u16 size, void *data)
125 return usb_control_msg(
127 usb_rcvctrlpipe(dev->udev, 0),
129 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
134 USB_CTRL_GET_TIMEOUT);
137 static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
138 u16 size, void *data)
140 return usb_control_msg(
142 usb_sndctrlpipe(dev->udev, 0),
144 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
149 USB_CTRL_SET_TIMEOUT);
152 static void asix_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
154 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
157 printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
164 static inline int asix_set_sw_mii(struct usbnet *dev)
167 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
169 devdbg(dev, "Failed to enable software MII access");
173 static inline int asix_set_hw_mii(struct usbnet *dev)
176 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
178 devdbg(dev, "Failed to enable hardware MII access");
182 static inline int asix_get_phyid(struct usbnet *dev)
187 buf = kmalloc(2, GFP_KERNEL);
191 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID,
192 0, 0, 2, buf)) < 2) {
193 devdbg(dev, "Error reading PHYID register: %02x", ret);
196 ret = *((u8 *)buf + 1);
203 static int asix_sw_reset(struct usbnet *dev, u8 flags)
207 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
209 devdbg(dev,"Failed to send software reset: %02x", ret);
214 static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
218 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
220 devdbg(dev, "Failed to write RX_CTL mode: %02x", ret);
225 static void asix_status(struct usbnet *dev, struct urb *urb)
227 struct ax88172_int_data *event;
230 if (urb->actual_length < 8)
233 event = urb->transfer_buffer;
234 link = event->link & 0x01;
235 if (netif_carrier_ok(dev->net) != link) {
237 netif_carrier_on(dev->net);
238 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
240 netif_carrier_off(dev->net);
241 devdbg(dev, "Link Status is: %d", link);
246 asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
247 u16 size, void *data)
249 struct usb_ctrlrequest *req;
253 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
254 devdbg(dev, "Error allocating URB in write_cmd_async!");
258 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
259 deverr(dev, "Failed to allocate memory for control request");
264 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
266 req->wValue = cpu_to_le16(value);
267 req->wIndex = cpu_to_le16(index);
268 req->wLength = cpu_to_le16(size);
270 usb_fill_control_urb(urb, dev->udev,
271 usb_sndctrlpipe(dev->udev, 0),
272 (void *)req, data, size,
273 asix_async_cmd_callback, req);
275 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
276 deverr(dev, "Error submitting the control message: status=%d",
283 static void asix_set_multicast(struct net_device *net)
285 struct usbnet *dev = netdev_priv(net);
286 struct asix_data *data = (struct asix_data *)&dev->data;
289 if (net->flags & IFF_PROMISC) {
291 } else if (net->flags & IFF_ALLMULTI
292 || net->mc_count > AX_MAX_MCAST) {
294 } else if (net->mc_count == 0) {
295 /* just broadcast and directed */
297 /* We use the 20 byte dev->data
298 * for our 8 byte filter buffer
299 * to avoid allocating memory that
300 * is tricky to free later */
301 struct dev_mc_list *mc_list = net->mc_list;
305 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
307 /* Build the multicast hash filter. */
308 for (i = 0; i < net->mc_count; i++) {
311 mc_list->dmi_addr) >> 26;
312 data->multi_filter[crc_bits >> 3] |=
314 mc_list = mc_list->next;
317 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
318 AX_MCAST_FILTER_SIZE, data->multi_filter);
323 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
326 static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
328 struct usbnet *dev = netdev_priv(netdev);
331 asix_set_sw_mii(dev);
332 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
333 (__u16)loc, 2, (u16 *)&res);
334 asix_set_hw_mii(dev);
339 /* same as above, but converts resulting value to cpu byte order */
340 static int asix_mdio_read_le(struct net_device *netdev, int phy_id, int loc)
342 return le16_to_cpu(asix_mdio_read(netdev,phy_id, loc));
346 asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
348 struct usbnet *dev = netdev_priv(netdev);
351 asix_set_sw_mii(dev);
352 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
353 (__u16)loc, 2, (u16 *)&res);
354 asix_set_hw_mii(dev);
357 /* same as above, but converts new value to le16 byte order before writing */
359 asix_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val)
361 asix_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) );
364 static int ax88172_link_reset(struct usbnet *dev)
371 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
372 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
373 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
374 res = mii_nway_result(lpa|adv);
375 if (res & LPA_DUPLEX)
376 mode |= AX_MEDIUM_FULL_DUPLEX;
377 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
383 asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
385 struct usbnet *dev = netdev_priv(net);
388 if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
389 wolinfo->supported = 0;
390 wolinfo->wolopts = 0;
393 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
394 wolinfo->wolopts = 0;
395 if (opt & AX_MONITOR_MODE) {
396 if (opt & AX_MONITOR_LINK)
397 wolinfo->wolopts |= WAKE_PHY;
398 if (opt & AX_MONITOR_MAGIC)
399 wolinfo->wolopts |= WAKE_MAGIC;
404 asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
406 struct usbnet *dev = netdev_priv(net);
410 if (wolinfo->wolopts & WAKE_PHY)
411 opt |= AX_MONITOR_LINK;
412 if (wolinfo->wolopts & WAKE_MAGIC)
413 opt |= AX_MONITOR_MAGIC;
415 opt |= AX_MONITOR_MODE;
417 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
418 opt, 0, 0, &buf) < 0)
424 static int asix_get_eeprom_len(struct net_device *net)
426 return AX_EEPROM_LEN;
429 static int asix_get_eeprom(struct net_device *net,
430 struct ethtool_eeprom *eeprom, u8 *data)
432 struct usbnet *dev = netdev_priv(net);
433 u16 *ebuf = (u16 *)data;
436 /* Crude hack to ensure that we don't overwrite memory
437 * if an odd length is supplied
442 eeprom->magic = AX_EEPROM_MAGIC;
444 /* ax8817x returns 2 bytes from eeprom on read */
445 for (i=0; i < eeprom->len / 2; i++) {
446 if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
447 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
453 static void asix_get_drvinfo (struct net_device *net,
454 struct ethtool_drvinfo *info)
456 /* Inherit standard device info */
457 usbnet_get_drvinfo(net, info);
458 info->eedump_len = 0x3e;
461 static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
463 struct usbnet *dev = netdev_priv(net);
465 return mii_ethtool_gset(&dev->mii,cmd);
468 static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
470 struct usbnet *dev = netdev_priv(net);
472 return mii_ethtool_sset(&dev->mii,cmd);
475 /* We need to override some ethtool_ops so we require our
476 own structure so we don't interfere with other usbnet
477 devices that may be connected at the same time. */
478 static struct ethtool_ops ax88172_ethtool_ops = {
479 .get_drvinfo = asix_get_drvinfo,
480 .get_link = ethtool_op_get_link,
481 .get_msglevel = usbnet_get_msglevel,
482 .set_msglevel = usbnet_set_msglevel,
483 .get_wol = asix_get_wol,
484 .set_wol = asix_set_wol,
485 .get_eeprom_len = asix_get_eeprom_len,
486 .get_eeprom = asix_get_eeprom,
487 .get_settings = asix_get_settings,
488 .set_settings = asix_set_settings,
491 static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
493 struct usbnet *dev = netdev_priv(net);
495 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
498 static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
503 unsigned long gpio_bits = dev->driver_info->data;
505 usbnet_get_endpoints(dev,intf);
507 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
513 /* Toggle the GPIOs in a manufacturer/model specific way */
514 for (i = 2; i >= 0; i--) {
515 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
516 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
522 if ((ret = asix_write_rx_ctl(dev,0x80)) < 0)
525 /* Get the MAC address */
526 memset(buf, 0, ETH_ALEN);
527 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
528 0, 0, 6, buf)) < 0) {
529 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
532 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
534 /* Initialize MII structure */
535 dev->mii.dev = dev->net;
536 dev->mii.mdio_read = asix_mdio_read;
537 dev->mii.mdio_write = asix_mdio_write;
538 dev->mii.phy_id_mask = 0x3f;
539 dev->mii.reg_num_mask = 0x1f;
540 dev->mii.phy_id = asix_get_phyid(dev);
541 dev->net->do_ioctl = asix_ioctl;
543 dev->net->set_multicast_list = asix_set_multicast;
544 dev->net->ethtool_ops = &ax88172_ethtool_ops;
546 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
547 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
548 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
549 mii_nway_restart(&dev->mii);
558 static struct ethtool_ops ax88772_ethtool_ops = {
559 .get_drvinfo = asix_get_drvinfo,
560 .get_link = ethtool_op_get_link,
561 .get_msglevel = usbnet_get_msglevel,
562 .set_msglevel = usbnet_set_msglevel,
563 .get_wol = asix_get_wol,
564 .set_wol = asix_set_wol,
565 .get_eeprom_len = asix_get_eeprom_len,
566 .get_eeprom = asix_get_eeprom,
567 .get_settings = asix_get_settings,
568 .set_settings = asix_set_settings,
571 static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
576 usbnet_get_endpoints(dev,intf);
578 buf = kmalloc(6, GFP_KERNEL);
580 dbg ("Cannot allocate memory for buffer");
585 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
586 0x00B0, 0, 0, buf)) < 0)
590 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
591 0x0001, 0, 0, buf)) < 0) {
592 dbg("Select PHY #1 failed: %d", ret);
596 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD)) < 0)
600 if ((ret = asix_sw_reset(dev, AX_SWRESET_CLEAR)) < 0)
604 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
608 if ((ret = asix_write_rx_ctl(dev, 0x00)) < 0)
611 /* Get the MAC address */
612 memset(buf, 0, ETH_ALEN);
613 if ((ret = asix_read_cmd(dev, AX88772_CMD_READ_NODE_ID,
614 0, 0, ETH_ALEN, buf)) < 0) {
615 dbg("Failed to read MAC address: %d", ret);
618 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
620 if ((ret = asix_set_sw_mii(dev)) < 0)
623 if (((ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG,
624 0x0010, 2, 2, buf)) < 0)
625 || (*((u16 *)buf) != 0x003b)) {
626 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
630 /* Initialize MII structure */
631 dev->mii.dev = dev->net;
632 dev->mii.mdio_read = asix_mdio_read;
633 dev->mii.mdio_write = asix_mdio_write;
634 dev->mii.phy_id_mask = 0xff;
635 dev->mii.reg_num_mask = 0xff;
636 dev->net->do_ioctl = asix_ioctl;
637 dev->mii.phy_id = asix_get_phyid(dev);
639 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0)
644 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
649 dev->net->set_multicast_list = asix_set_multicast;
650 dev->net->ethtool_ops = &ax88772_ethtool_ops;
652 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
653 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
654 ADVERTISE_ALL | ADVERTISE_CSMA);
655 mii_nway_restart(&dev->mii);
657 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE,
658 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
659 dbg("Write medium mode register: %d", ret);
663 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
664 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
665 AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
666 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
669 if ((ret = asix_set_hw_mii(dev)) < 0)
672 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
673 if ((ret = asix_write_rx_ctl(dev, 0x0088)) < 0)
678 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
679 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
680 /* hard_mtu is still the default - the device does not support
682 dev->rx_urb_size = 2048;
693 static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
698 struct sk_buff *ax_skb;
701 head = (u8 *) skb->data;
702 memcpy(&header, head, sizeof(header));
703 le32_to_cpus(&header);
704 packet = head + sizeof(header);
708 while (skb->len > 0) {
709 if ((short)(header & 0x0000ffff) !=
710 ~((short)((header & 0xffff0000) >> 16))) {
711 devdbg(dev,"header length data is error");
713 /* get the packet length */
714 size = (u16) (header & 0x0000ffff);
716 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
718 if (size > ETH_FRAME_LEN) {
719 devdbg(dev,"invalid rx length %d", size);
722 ax_skb = skb_clone(skb, GFP_ATOMIC);
725 ax_skb->data = packet;
726 ax_skb->tail = packet + size;
727 usbnet_skb_return(dev, ax_skb);
732 skb_pull(skb, (size + 1) & 0xfffe);
737 head = (u8 *) skb->data;
738 memcpy(&header, head, sizeof(header));
739 le32_to_cpus(&header);
740 packet = head + sizeof(header);
745 devdbg(dev,"invalid rx length %d", skb->len);
751 static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
755 int headroom = skb_headroom(skb);
756 int tailroom = skb_tailroom(skb);
758 u32 padbytes = 0xffff0000;
760 padlen = ((skb->len + 4) % 512) ? 0 : 4;
762 if ((!skb_cloned(skb))
763 && ((headroom + tailroom) >= (4 + padlen))) {
764 if ((headroom < 4) || (tailroom < padlen)) {
765 skb->data = memmove(skb->head + 4, skb->data, skb->len);
766 skb->tail = skb->data + skb->len;
769 struct sk_buff *skb2;
770 skb2 = skb_copy_expand(skb, 4, padlen, flags);
771 dev_kfree_skb_any(skb);
778 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
779 memcpy(skb->data, &packet_len, sizeof(packet_len));
781 if ((skb->len % 512) == 0) {
782 memcpy( skb->tail, &padbytes, sizeof(padbytes));
783 skb_put(skb, sizeof(padbytes));
788 static int ax88772_link_reset(struct usbnet *dev)
795 mode = AX88772_MEDIUM_DEFAULT;
796 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
797 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
798 res = mii_nway_result(lpa|adv);
800 if ((res & LPA_DUPLEX) == 0)
801 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
802 if ((res & LPA_100) == 0)
803 mode &= ~AX88772_MEDIUM_100MB;
804 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
809 static const struct driver_info ax8817x_info = {
810 .description = "ASIX AX8817x USB 2.0 Ethernet",
811 .bind = ax88172_bind,
812 .status = asix_status,
813 .link_reset = ax88172_link_reset,
814 .reset = ax88172_link_reset,
819 static const struct driver_info dlink_dub_e100_info = {
820 .description = "DLink DUB-E100 USB Ethernet",
821 .bind = ax88172_bind,
822 .status = asix_status,
823 .link_reset = ax88172_link_reset,
824 .reset = ax88172_link_reset,
829 static const struct driver_info netgear_fa120_info = {
830 .description = "Netgear FA-120 USB Ethernet",
831 .bind = ax88172_bind,
832 .status = asix_status,
833 .link_reset = ax88172_link_reset,
834 .reset = ax88172_link_reset,
839 static const struct driver_info hawking_uf200_info = {
840 .description = "Hawking UF200 USB Ethernet",
841 .bind = ax88172_bind,
842 .status = asix_status,
843 .link_reset = ax88172_link_reset,
844 .reset = ax88172_link_reset,
849 static const struct driver_info ax88772_info = {
850 .description = "ASIX AX88772 USB 2.0 Ethernet",
851 .bind = ax88772_bind,
852 .status = asix_status,
853 .link_reset = ax88772_link_reset,
854 .reset = ax88772_link_reset,
855 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
856 .rx_fixup = ax88772_rx_fixup,
857 .tx_fixup = ax88772_tx_fixup,
860 static const struct usb_device_id products [] = {
863 USB_DEVICE (0x077b, 0x2226),
864 .driver_info = (unsigned long) &ax8817x_info,
867 USB_DEVICE (0x0846, 0x1040),
868 .driver_info = (unsigned long) &netgear_fa120_info,
871 USB_DEVICE (0x2001, 0x1a00),
872 .driver_info = (unsigned long) &dlink_dub_e100_info,
874 // Intellinet, ST Lab USB Ethernet
875 USB_DEVICE (0x0b95, 0x1720),
876 .driver_info = (unsigned long) &ax8817x_info,
878 // Hawking UF200, TrendNet TU2-ET100
879 USB_DEVICE (0x07b8, 0x420a),
880 .driver_info = (unsigned long) &hawking_uf200_info,
882 // Billionton Systems, USB2AR
883 USB_DEVICE (0x08dd, 0x90ff),
884 .driver_info = (unsigned long) &ax8817x_info,
887 USB_DEVICE (0x0557, 0x2009),
888 .driver_info = (unsigned long) &ax8817x_info,
890 // Buffalo LUA-U2-KTX
891 USB_DEVICE (0x0411, 0x003d),
892 .driver_info = (unsigned long) &ax8817x_info,
894 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
895 USB_DEVICE (0x6189, 0x182d),
896 .driver_info = (unsigned long) &ax8817x_info,
898 // corega FEther USB2-TX
899 USB_DEVICE (0x07aa, 0x0017),
900 .driver_info = (unsigned long) &ax8817x_info,
902 // Surecom EP-1427X-2
903 USB_DEVICE (0x1189, 0x0893),
904 .driver_info = (unsigned long) &ax8817x_info,
906 // goodway corp usb gwusb2e
907 USB_DEVICE (0x1631, 0x6200),
908 .driver_info = (unsigned long) &ax8817x_info,
910 // ASIX AX88772 10/100
911 USB_DEVICE (0x0b95, 0x7720),
912 .driver_info = (unsigned long) &ax88772_info,
914 // ASIX AX88178 10/100/1000
915 USB_DEVICE (0x0b95, 0x1780),
916 .driver_info = (unsigned long) &ax88772_info,
918 // Linksys USB200M Rev 2
919 USB_DEVICE (0x13b1, 0x0018),
920 .driver_info = (unsigned long) &ax88772_info,
922 // 0Q0 cable ethernet
923 USB_DEVICE (0x1557, 0x7720),
924 .driver_info = (unsigned long) &ax88772_info,
928 MODULE_DEVICE_TABLE(usb, products);
930 static struct usb_driver asix_driver = {
932 .id_table = products,
933 .probe = usbnet_probe,
934 .suspend = usbnet_suspend,
935 .resume = usbnet_resume,
936 .disconnect = usbnet_disconnect,
939 static int __init asix_init(void)
941 return usb_register(&asix_driver);
943 module_init(asix_init);
945 static void __exit asix_exit(void)
947 usb_deregister(&asix_driver);
949 module_exit(asix_exit);
951 MODULE_AUTHOR("David Hollis");
952 MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
953 MODULE_LICENSE("GPL");