1 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix_common.c backports-4.2.6-1/drivers/net/usb/asix_common.c
2 --- backports-4.2.6-1.org/drivers/net/usb/asix_common.c 1970-01-01 01:00:00.000000000 +0100
3 +++ backports-4.2.6-1/drivers/net/usb/asix_common.c 2016-06-28 14:35:17.965307221 +0200
6 + * ASIX AX8817X based USB 2.0 Ethernet Devices
7 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
8 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
9 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
10 + * Copyright (c) 2002-2003 TiVo Inc.
12 + * This program is free software; you can redistribute it and/or modify
13 + * it under the terms of the GNU General Public License as published by
14 + * the Free Software Foundation; either version 2 of the License, or
15 + * (at your option) any later version.
17 + * This program is distributed in the hope that it will be useful,
18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 + * GNU General Public License for more details.
22 + * You should have received a copy of the GNU General Public License
23 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 +int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
29 + u16 size, void *data)
32 + ret = usbnet_read_cmd(dev, cmd,
33 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
34 + value, index, data, size);
36 + if (ret != size && ret >= 0)
41 +int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
42 + u16 size, void *data)
44 + return usbnet_write_cmd(dev, cmd,
45 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
46 + value, index, data, size);
49 +void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
50 + u16 size, void *data)
52 + usbnet_write_cmd_async(dev, cmd,
53 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
54 + value, index, data, size);
57 +int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
58 + struct asix_rx_fixup_info *rx)
62 + while (offset + sizeof(u16) <= skb->len) {
64 + unsigned char *data;
67 + if ((skb->len - offset == sizeof(u16)) ||
69 + if(!rx->split_head) {
70 + rx->header = get_unaligned_le16(
71 + skb->data + offset);
72 + rx->split_head = true;
73 + offset += sizeof(u16);
76 + rx->header |= (get_unaligned_le16(
79 + rx->split_head = false;
80 + offset += sizeof(u16);
83 + rx->header = get_unaligned_le32(skb->data +
85 + offset += sizeof(u32);
88 + /* get the packet length */
89 + rx->size = (u16) (rx->header & 0x7ff);
90 + if (rx->size != ((~rx->header >> 16) & 0x7ff)) {
91 + netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n",
92 + rx->header, offset);
96 + rx->ax_skb = netdev_alloc_skb_ip_align(dev->net,
102 + if (rx->size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
103 + netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
105 + kfree_skb(rx->ax_skb);
112 + if (rx->size > skb->len - offset) {
113 + remaining = rx->size - (skb->len - offset);
114 + rx->size = skb->len - offset;
117 + data = skb_put(rx->ax_skb, rx->size);
118 + memcpy(data, skb->data + offset, rx->size);
120 + usbnet_skb_return(dev, rx->ax_skb);
122 + offset += (rx->size + 1) & 0xfffe;
123 + rx->size = remaining;
126 + if (skb->len != offset) {
127 + netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n",
135 +int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb)
137 + struct asix_common_private *dp = dev->driver_priv;
138 + struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
140 + return asix_rx_fixup_internal(dev, skb, rx);
143 +struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
147 + int headroom = skb_headroom(skb);
148 + int tailroom = skb_tailroom(skb);
150 + u32 padbytes = 0xffff0000;
152 + padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
154 + /* We need to push 4 bytes in front of frame (packet_len)
155 + * and maybe add 4 bytes after the end (if padlen is 4)
157 + * Avoid skb_copy_expand() expensive call, using following rules :
158 + * - We are allowed to push 4 bytes in headroom if skb_header_cloned()
159 + * is false (and if we have 4 bytes of headroom)
160 + * - We are allowed to put 4 bytes at tail if skb_cloned()
161 + * is false (and if we have 4 bytes of tailroom)
163 + * TCP packets for example are cloned, but skb_header_release()
164 + * was called in tcp stack, allowing us to use headroom for our needs.
166 + if (!skb_header_cloned(skb) &&
167 + !(padlen && skb_cloned(skb)) &&
168 + headroom + tailroom >= 4 + padlen) {
169 + /* following should not happen, but better be safe */
170 + if (headroom < 4 ||
171 + tailroom < padlen) {
172 + skb->data = memmove(skb->head + 4, skb->data, skb->len);
173 + skb_set_tail_pointer(skb, skb->len);
176 + struct sk_buff *skb2;
178 + skb2 = skb_copy_expand(skb, 4, padlen, flags);
179 + dev_kfree_skb_any(skb);
185 + packet_len = ((skb->len ^ 0x0000ffff) << 16) + skb->len;
187 + cpu_to_le32s(&packet_len);
188 + skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
191 + cpu_to_le32s(&padbytes);
192 + memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
193 + skb_put(skb, sizeof(padbytes));
196 + usbnet_set_skb_tx_stats(skb, 1, 0);
200 +int asix_set_sw_mii(struct usbnet *dev)
203 + ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
205 + netdev_err(dev->net, "Failed to enable software MII access\n");
209 +int asix_set_hw_mii(struct usbnet *dev)
212 + ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
214 + netdev_err(dev->net, "Failed to enable hardware MII access\n");
218 +int asix_read_phy_addr(struct usbnet *dev, int internal)
220 + int offset = (internal ? 1 : 0);
222 + int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
224 + netdev_dbg(dev->net, "asix_get_phy_addr()\n");
227 + netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
230 + netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
238 +int asix_get_phy_addr(struct usbnet *dev)
240 + /* return the address of the internal phy */
241 + return asix_read_phy_addr(dev, 1);
245 +int asix_sw_reset(struct usbnet *dev, u8 flags)
249 + ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
251 + netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
256 +u16 asix_read_rx_ctl(struct usbnet *dev)
259 + int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
262 + netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
265 + ret = le16_to_cpu(v);
270 +int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
274 + netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
275 + ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
277 + netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
283 +u16 asix_read_medium_status(struct usbnet *dev)
286 + int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
289 + netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
291 + return ret; /* TODO: callers not checking for error ret */
294 + return le16_to_cpu(v);
298 +int asix_write_medium_mode(struct usbnet *dev, u16 mode)
302 + netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
303 + ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
305 + netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
311 +int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
315 + netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
316 + ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
318 + netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
328 + * AX88772 & AX88178 have a 16-bit RX_CTL value
330 +void asix_set_multicast(struct net_device *net)
332 + struct usbnet *dev = netdev_priv(net);
333 + struct asix_data *data = (struct asix_data *)&dev->data;
334 + u16 rx_ctl = AX_DEFAULT_RX_CTL;
336 + if (net->flags & IFF_PROMISC) {
337 + rx_ctl |= AX_RX_CTL_PRO;
338 + } else if (net->flags & IFF_ALLMULTI ||
339 + netdev_mc_count(net) > AX_MAX_MCAST) {
340 + rx_ctl |= AX_RX_CTL_AMALL;
341 + } else if (netdev_mc_empty(net)) {
342 + /* just broadcast and directed */
344 + /* We use the 20 byte dev->data
345 + * for our 8 byte filter buffer
346 + * to avoid allocating memory that
347 + * is tricky to free later */
348 + struct netdev_hw_addr *ha;
351 + memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
353 + /* Build the multicast hash filter. */
354 + netdev_for_each_mc_addr(ha, net) {
355 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
356 + data->multi_filter[crc_bits >> 3] |=
357 + 1 << (crc_bits & 7);
360 + asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
361 + AX_MCAST_FILTER_SIZE, data->multi_filter);
363 + rx_ctl |= AX_RX_CTL_AM;
366 + asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
369 +int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
371 + struct usbnet *dev = netdev_priv(netdev);
374 + mutex_lock(&dev->phy_mutex);
375 + asix_set_sw_mii(dev);
376 + asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
377 + (__u16)loc, 2, &res);
378 + asix_set_hw_mii(dev);
379 + mutex_unlock(&dev->phy_mutex);
381 + netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
382 + phy_id, loc, le16_to_cpu(res));
384 + return le16_to_cpu(res);
387 +void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
389 + struct usbnet *dev = netdev_priv(netdev);
390 + __le16 res = cpu_to_le16(val);
392 + netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
394 + mutex_lock(&dev->phy_mutex);
395 + asix_set_sw_mii(dev);
396 + asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
397 + asix_set_hw_mii(dev);
398 + mutex_unlock(&dev->phy_mutex);
401 +void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
403 + struct usbnet *dev = netdev_priv(net);
406 + if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
407 + wolinfo->supported = 0;
408 + wolinfo->wolopts = 0;
411 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
412 + wolinfo->wolopts = 0;
413 + if (opt & AX_MONITOR_LINK)
414 + wolinfo->wolopts |= WAKE_PHY;
415 + if (opt & AX_MONITOR_MAGIC)
416 + wolinfo->wolopts |= WAKE_MAGIC;
419 +int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
421 + struct usbnet *dev = netdev_priv(net);
424 + if (wolinfo->wolopts & WAKE_PHY)
425 + opt |= AX_MONITOR_LINK;
426 + if (wolinfo->wolopts & WAKE_MAGIC)
427 + opt |= AX_MONITOR_MAGIC;
429 + if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
430 + opt, 0, 0, NULL) < 0)
436 +int asix_get_eeprom_len(struct net_device *net)
438 + return AX_EEPROM_LEN;
441 +int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
444 + struct usbnet *dev = netdev_priv(net);
446 + int first_word, last_word;
449 + if (eeprom->len == 0)
452 + eeprom->magic = AX_EEPROM_MAGIC;
454 + first_word = eeprom->offset >> 1;
455 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
457 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
462 + /* ax8817x returns 2 bytes from eeprom on read */
463 + for (i = first_word; i <= last_word; i++) {
464 + if (asix_read_cmd(dev, AX_CMD_READ_EEPROM, i, 0, 2,
465 + &(eeprom_buff[i - first_word])) < 0) {
466 + kfree(eeprom_buff);
471 + memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
472 + kfree(eeprom_buff);
476 +int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
479 + struct usbnet *dev = netdev_priv(net);
481 + int first_word, last_word;
485 + netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
486 + eeprom->len, eeprom->offset, eeprom->magic);
488 + if (eeprom->len == 0)
491 + if (eeprom->magic != AX_EEPROM_MAGIC)
494 + first_word = eeprom->offset >> 1;
495 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
497 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
502 + /* align data to 16 bit boundaries, read the missing data from
504 + if (eeprom->offset & 1) {
505 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, first_word, 0, 2,
506 + &(eeprom_buff[0]));
508 + netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", first_word);
513 + if ((eeprom->offset + eeprom->len) & 1) {
514 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, last_word, 0, 2,
515 + &(eeprom_buff[last_word - first_word]));
517 + netdev_err(net, "Failed to read EEPROM at offset 0x%02x.\n", last_word);
522 + memcpy((u8 *)eeprom_buff + (eeprom->offset & 1), data, eeprom->len);
524 + /* write data to EEPROM */
525 + ret = asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0x0000, 0, 0, NULL);
527 + netdev_err(net, "Failed to enable EEPROM write\n");
532 + for (i = first_word; i <= last_word; i++) {
533 + netdev_dbg(net, "write to EEPROM at offset 0x%02x, data 0x%04x\n",
534 + i, eeprom_buff[i - first_word]);
535 + ret = asix_write_cmd(dev, AX_CMD_WRITE_EEPROM, i,
536 + eeprom_buff[i - first_word], 0, NULL);
538 + netdev_err(net, "Failed to write EEPROM at offset 0x%02x.\n",
545 + ret = asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0x0000, 0, 0, NULL);
547 + netdev_err(net, "Failed to disable EEPROM write\n");
553 + kfree(eeprom_buff);
557 +void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
559 + /* Inherit standard device info */
560 + usbnet_get_drvinfo(net, info);
561 + strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
562 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
563 + info->eedump_len = AX_EEPROM_LEN;
566 +int asix_set_mac_address(struct net_device *net, void *p)
568 + struct usbnet *dev = netdev_priv(net);
569 + struct asix_data *data = (struct asix_data *)&dev->data;
570 + struct sockaddr *addr = p;
572 + if (netif_running(net))
574 + if (!is_valid_ether_addr(addr->sa_data))
575 + return -EADDRNOTAVAIL;
577 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
579 + /* We use the 20 byte dev->data
580 + * for our 6 byte mac buffer
581 + * to avoid allocating memory that
582 + * is tricky to free later */
583 + memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
584 + asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
589 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix_devices.c backports-4.2.6-1/drivers/net/usb/asix_devices.c
590 --- backports-4.2.6-1.org/drivers/net/usb/asix_devices.c 1970-01-01 01:00:00.000000000 +0100
591 +++ backports-4.2.6-1/drivers/net/usb/asix_devices.c 2016-06-28 14:35:17.965307221 +0200
594 + * ASIX AX8817X based USB 2.0 Ethernet Devices
595 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
596 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
597 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
598 + * Copyright (c) 2002-2003 TiVo Inc.
600 + * This program is free software; you can redistribute it and/or modify
601 + * it under the terms of the GNU General Public License as published by
602 + * the Free Software Foundation; either version 2 of the License, or
603 + * (at your option) any later version.
605 + * This program is distributed in the hope that it will be useful,
606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
608 + * GNU General Public License for more details.
610 + * You should have received a copy of the GNU General Public License
611 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
616 +#define PHY_MODE_MARVELL 0x0000
617 +#define MII_MARVELL_LED_CTRL 0x0018
618 +#define MII_MARVELL_STATUS 0x001b
619 +#define MII_MARVELL_CTRL 0x0014
621 +#define MARVELL_LED_MANUAL 0x0019
623 +#define MARVELL_STATUS_HWCFG 0x0004
625 +#define MARVELL_CTRL_TXDELAY 0x0002
626 +#define MARVELL_CTRL_RXDELAY 0x0080
628 +#define PHY_MODE_RTL8211CL 0x000C
630 +struct ax88172_int_data {
638 +static void asix_status(struct usbnet *dev, struct urb *urb)
640 + struct ax88172_int_data *event;
643 + if (urb->actual_length < 8)
646 + event = urb->transfer_buffer;
647 + link = event->link & 0x01;
648 + if (netif_carrier_ok(dev->net) != link) {
649 + usbnet_link_change(dev, link, 1);
650 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
654 +static void asix_set_netdev_dev_addr(struct usbnet *dev, u8 *addr)
656 + if (is_valid_ether_addr(addr)) {
657 + memcpy(dev->net->dev_addr, addr, ETH_ALEN);
659 + netdev_info(dev->net, "invalid hw address, using random\n");
660 + eth_hw_addr_random(dev->net);
664 +/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
665 +static u32 asix_get_phyid(struct usbnet *dev)
671 + /* Poll for the rare case the FW or phy isn't ready yet. */
672 + for (i = 0; i < 100; i++) {
673 + phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
674 + if (phy_reg != 0 && phy_reg != 0xFFFF)
679 + if (phy_reg <= 0 || phy_reg == 0xFFFF)
682 + phy_id = (phy_reg & 0xffff) << 16;
684 + phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
688 + phy_id |= (phy_reg & 0xffff);
693 +static u32 asix_get_link(struct net_device *net)
695 + struct usbnet *dev = netdev_priv(net);
697 + return mii_link_ok(&dev->mii);
700 +static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
702 + struct usbnet *dev = netdev_priv(net);
704 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
707 +/* We need to override some ethtool_ops so we require our
708 + own structure so we don't interfere with other usbnet
709 + devices that may be connected at the same time. */
710 +static const struct ethtool_ops ax88172_ethtool_ops = {
711 + .get_drvinfo = asix_get_drvinfo,
712 + .get_link = asix_get_link,
713 + .get_msglevel = usbnet_get_msglevel,
714 + .set_msglevel = usbnet_set_msglevel,
715 + .get_wol = asix_get_wol,
716 + .set_wol = asix_set_wol,
717 + .get_eeprom_len = asix_get_eeprom_len,
718 + .get_eeprom = asix_get_eeprom,
719 + .set_eeprom = asix_set_eeprom,
720 + .get_settings = usbnet_get_settings,
721 + .set_settings = usbnet_set_settings,
722 + .nway_reset = usbnet_nway_reset,
725 +static void ax88172_set_multicast(struct net_device *net)
727 + struct usbnet *dev = netdev_priv(net);
728 + struct asix_data *data = (struct asix_data *)&dev->data;
731 + if (net->flags & IFF_PROMISC) {
733 + } else if (net->flags & IFF_ALLMULTI ||
734 + netdev_mc_count(net) > AX_MAX_MCAST) {
736 + } else if (netdev_mc_empty(net)) {
737 + /* just broadcast and directed */
739 + /* We use the 20 byte dev->data
740 + * for our 8 byte filter buffer
741 + * to avoid allocating memory that
742 + * is tricky to free later */
743 + struct netdev_hw_addr *ha;
746 + memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
748 + /* Build the multicast hash filter. */
749 + netdev_for_each_mc_addr(ha, net) {
750 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
751 + data->multi_filter[crc_bits >> 3] |=
752 + 1 << (crc_bits & 7);
755 + asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
756 + AX_MCAST_FILTER_SIZE, data->multi_filter);
761 + asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
764 +static int ax88172_link_reset(struct usbnet *dev)
767 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
769 + mii_check_media(&dev->mii, 1, 1);
770 + mii_ethtool_gset(&dev->mii, &ecmd);
771 + mode = AX88172_MEDIUM_DEFAULT;
773 + if (ecmd.duplex != DUPLEX_FULL)
774 + mode |= ~AX88172_MEDIUM_FD;
776 + netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
777 + ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
779 + asix_write_medium_mode(dev, mode);
784 +static const struct net_device_ops ax88172_netdev_ops = {
785 + .ndo_open = usbnet_open,
786 + .ndo_stop = usbnet_stop,
787 + .ndo_start_xmit = usbnet_start_xmit,
788 + .ndo_tx_timeout = usbnet_tx_timeout,
789 + .ndo_change_mtu = usbnet_change_mtu,
790 + .ndo_set_mac_address = eth_mac_addr,
791 + .ndo_validate_addr = eth_validate_addr,
792 + .ndo_do_ioctl = asix_ioctl,
793 + .ndo_set_rx_mode = ax88172_set_multicast,
796 +static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
801 + unsigned long gpio_bits = dev->driver_info->data;
803 + usbnet_get_endpoints(dev,intf);
805 + /* Toggle the GPIOs in a manufacturer/model specific way */
806 + for (i = 2; i >= 0; i--) {
807 + ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
808 + (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL);
814 + ret = asix_write_rx_ctl(dev, 0x80);
818 + /* Get the MAC address */
819 + ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
821 + netdev_dbg(dev->net, "read AX_CMD_READ_NODE_ID failed: %d\n",
826 + asix_set_netdev_dev_addr(dev, buf);
828 + /* Initialize MII structure */
829 + dev->mii.dev = dev->net;
830 + dev->mii.mdio_read = asix_mdio_read;
831 + dev->mii.mdio_write = asix_mdio_write;
832 + dev->mii.phy_id_mask = 0x3f;
833 + dev->mii.reg_num_mask = 0x1f;
834 + dev->mii.phy_id = asix_get_phy_addr(dev);
836 + dev->net->netdev_ops = &ax88172_netdev_ops;
837 + dev->net->ethtool_ops = &ax88172_ethtool_ops;
838 + dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
839 + dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
841 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
842 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
843 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
844 + mii_nway_restart(&dev->mii);
852 +static const struct ethtool_ops ax88772_ethtool_ops = {
853 + .get_drvinfo = asix_get_drvinfo,
854 + .get_link = asix_get_link,
855 + .get_msglevel = usbnet_get_msglevel,
856 + .set_msglevel = usbnet_set_msglevel,
857 + .get_wol = asix_get_wol,
858 + .set_wol = asix_set_wol,
859 + .get_eeprom_len = asix_get_eeprom_len,
860 + .get_eeprom = asix_get_eeprom,
861 + .set_eeprom = asix_set_eeprom,
862 + .get_settings = usbnet_get_settings,
863 + .set_settings = usbnet_set_settings,
864 + .nway_reset = usbnet_nway_reset,
867 +static int ax88772_link_reset(struct usbnet *dev)
870 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
872 + mii_check_media(&dev->mii, 1, 1);
873 + mii_ethtool_gset(&dev->mii, &ecmd);
874 + mode = AX88772_MEDIUM_DEFAULT;
876 + if (ethtool_cmd_speed(&ecmd) != SPEED_100)
877 + mode &= ~AX_MEDIUM_PS;
879 + if (ecmd.duplex != DUPLEX_FULL)
880 + mode &= ~AX_MEDIUM_FD;
882 + netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
883 + ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
885 + asix_write_medium_mode(dev, mode);
890 +static int ax88772_reset(struct usbnet *dev)
892 + struct asix_data *data = (struct asix_data *)&dev->data;
896 + ret = asix_write_gpio(dev,
897 + AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5);
901 + embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
903 + ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
905 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
909 + ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
915 + ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
922 + ret = asix_sw_reset(dev, AX_SWRESET_IPRL);
926 + ret = asix_sw_reset(dev, AX_SWRESET_PRTE);
932 + rx_ctl = asix_read_rx_ctl(dev);
933 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
934 + ret = asix_write_rx_ctl(dev, 0x0000);
938 + rx_ctl = asix_read_rx_ctl(dev);
939 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
941 + ret = asix_sw_reset(dev, AX_SWRESET_PRL);
947 + ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL);
953 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
954 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
955 + ADVERTISE_ALL | ADVERTISE_CSMA);
956 + mii_nway_restart(&dev->mii);
958 + ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT);
962 + ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
963 + AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
964 + AX88772_IPG2_DEFAULT, 0, NULL);
966 + netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
970 + /* Rewrite MAC address */
971 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
972 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
977 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
978 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
982 + rx_ctl = asix_read_rx_ctl(dev);
983 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
986 + rx_ctl = asix_read_medium_status(dev);
987 + netdev_dbg(dev->net,
988 + "Medium Status is 0x%04x after all initializations\n",
998 +static const struct net_device_ops ax88772_netdev_ops = {
999 + .ndo_open = usbnet_open,
1000 + .ndo_stop = usbnet_stop,
1001 + .ndo_start_xmit = usbnet_start_xmit,
1002 + .ndo_tx_timeout = usbnet_tx_timeout,
1003 + .ndo_change_mtu = usbnet_change_mtu,
1004 + .ndo_set_mac_address = asix_set_mac_address,
1005 + .ndo_validate_addr = eth_validate_addr,
1006 + .ndo_do_ioctl = asix_ioctl,
1007 + .ndo_set_rx_mode = asix_set_multicast,
1010 +static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1012 + int ret, embd_phy, i;
1016 + usbnet_get_endpoints(dev,intf);
1018 + /* Get the MAC address */
1019 + if (dev->driver_info->data & FLAG_EEPROM_MAC) {
1020 + for (i = 0; i < (ETH_ALEN >> 1); i++) {
1021 + ret = asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x04 + i,
1022 + 0, 2, buf + i * 2);
1027 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
1028 + 0, 0, ETH_ALEN, buf);
1032 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
1036 + asix_set_netdev_dev_addr(dev, buf);
1038 + /* Initialize MII structure */
1039 + dev->mii.dev = dev->net;
1040 + dev->mii.mdio_read = asix_mdio_read;
1041 + dev->mii.mdio_write = asix_mdio_write;
1042 + dev->mii.phy_id_mask = 0x1f;
1043 + dev->mii.reg_num_mask = 0x1f;
1044 + dev->mii.phy_id = asix_get_phy_addr(dev);
1046 + dev->net->netdev_ops = &ax88772_netdev_ops;
1047 + dev->net->ethtool_ops = &ax88772_ethtool_ops;
1048 + dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
1049 + dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
1051 + embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
1053 + /* Reset the PHY to normal operation mode */
1054 + ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
1056 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
1060 + ax88772_reset(dev);
1062 + /* Read PHYID register *AFTER* the PHY was reset properly */
1063 + phyid = asix_get_phyid(dev);
1064 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
1066 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1067 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1068 + /* hard_mtu is still the default - the device does not support
1069 + jumbo eth frames */
1070 + dev->rx_urb_size = 2048;
1073 + dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
1074 + if (!dev->driver_priv)
1080 +static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
1082 + kfree(dev->driver_priv);
1085 +static const struct ethtool_ops ax88178_ethtool_ops = {
1086 + .get_drvinfo = asix_get_drvinfo,
1087 + .get_link = asix_get_link,
1088 + .get_msglevel = usbnet_get_msglevel,
1089 + .set_msglevel = usbnet_set_msglevel,
1090 + .get_wol = asix_get_wol,
1091 + .set_wol = asix_set_wol,
1092 + .get_eeprom_len = asix_get_eeprom_len,
1093 + .get_eeprom = asix_get_eeprom,
1094 + .set_eeprom = asix_set_eeprom,
1095 + .get_settings = usbnet_get_settings,
1096 + .set_settings = usbnet_set_settings,
1097 + .nway_reset = usbnet_nway_reset,
1100 +static int marvell_phy_init(struct usbnet *dev)
1102 + struct asix_data *data = (struct asix_data *)&dev->data;
1105 + netdev_dbg(dev->net, "marvell_phy_init()\n");
1107 + reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
1108 + netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
1110 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
1111 + MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
1113 + if (data->ledmode) {
1114 + reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1115 + MII_MARVELL_LED_CTRL);
1116 + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
1119 + reg |= (1 + 0x0100);
1120 + asix_mdio_write(dev->net, dev->mii.phy_id,
1121 + MII_MARVELL_LED_CTRL, reg);
1123 + reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1124 + MII_MARVELL_LED_CTRL);
1125 + netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
1132 +static int rtl8211cl_phy_init(struct usbnet *dev)
1134 + struct asix_data *data = (struct asix_data *)&dev->data;
1136 + netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
1138 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
1139 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
1140 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
1141 + asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
1142 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1144 + if (data->ledmode == 12) {
1145 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
1146 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
1147 + asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1153 +static int marvell_led_status(struct usbnet *dev, u16 speed)
1155 + u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
1157 + netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
1159 + /* Clear out the center LED bits - 0x03F0 */
1173 + netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
1174 + asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
1179 +static int ax88178_reset(struct usbnet *dev)
1181 + struct asix_data *data = (struct asix_data *)&dev->data;
1188 + asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
1189 + netdev_dbg(dev->net, "GPIO Status: 0x%04x\n", status);
1191 + asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
1192 + asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
1193 + asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
1195 + netdev_dbg(dev->net, "EEPROM index 0x17 is 0x%04x\n", eeprom);
1197 + if (eeprom == cpu_to_le16(0xffff)) {
1198 + data->phymode = PHY_MODE_MARVELL;
1199 + data->ledmode = 0;
1202 + data->phymode = le16_to_cpu(eeprom) & 0x7F;
1203 + data->ledmode = le16_to_cpu(eeprom) >> 8;
1204 + gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
1206 + netdev_dbg(dev->net, "GPIO0: %d, PhyMode: %d\n", gpio0, data->phymode);
1208 + /* Power up external GigaPHY through AX88178 GPIO pin */
1209 + asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
1210 + if ((le16_to_cpu(eeprom) >> 8) != 1) {
1211 + asix_write_gpio(dev, 0x003c, 30);
1212 + asix_write_gpio(dev, 0x001c, 300);
1213 + asix_write_gpio(dev, 0x003c, 30);
1215 + netdev_dbg(dev->net, "gpio phymode == 1 path\n");
1216 + asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
1217 + asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
1220 + /* Read PHYID register *AFTER* powering up PHY */
1221 + phyid = asix_get_phyid(dev);
1222 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
1224 + /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
1225 + asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
1227 + asix_sw_reset(dev, 0);
1230 + asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1233 + asix_write_rx_ctl(dev, 0);
1235 + if (data->phymode == PHY_MODE_MARVELL) {
1236 + marvell_phy_init(dev);
1238 + } else if (data->phymode == PHY_MODE_RTL8211CL)
1239 + rtl8211cl_phy_init(dev);
1241 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
1242 + BMCR_RESET | BMCR_ANENABLE);
1243 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1244 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1245 + asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
1246 + ADVERTISE_1000FULL);
1248 + mii_nway_restart(&dev->mii);
1250 + ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT);
1254 + /* Rewrite MAC address */
1255 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1256 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1261 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1268 +static int ax88178_link_reset(struct usbnet *dev)
1271 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
1272 + struct asix_data *data = (struct asix_data *)&dev->data;
1275 + netdev_dbg(dev->net, "ax88178_link_reset()\n");
1277 + mii_check_media(&dev->mii, 1, 1);
1278 + mii_ethtool_gset(&dev->mii, &ecmd);
1279 + mode = AX88178_MEDIUM_DEFAULT;
1280 + speed = ethtool_cmd_speed(&ecmd);
1282 + if (speed == SPEED_1000)
1283 + mode |= AX_MEDIUM_GM;
1284 + else if (speed == SPEED_100)
1285 + mode |= AX_MEDIUM_PS;
1287 + mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
1289 + mode |= AX_MEDIUM_ENCK;
1291 + if (ecmd.duplex == DUPLEX_FULL)
1292 + mode |= AX_MEDIUM_FD;
1294 + mode &= ~AX_MEDIUM_FD;
1296 + netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
1297 + speed, ecmd.duplex, mode);
1299 + asix_write_medium_mode(dev, mode);
1301 + if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
1302 + marvell_led_status(dev, speed);
1307 +static void ax88178_set_mfb(struct usbnet *dev)
1309 + u16 mfb = AX_RX_CTL_MFB_16384;
1312 + int old_rx_urb_size = dev->rx_urb_size;
1314 + if (dev->hard_mtu < 2048) {
1315 + dev->rx_urb_size = 2048;
1316 + mfb = AX_RX_CTL_MFB_2048;
1317 + } else if (dev->hard_mtu < 4096) {
1318 + dev->rx_urb_size = 4096;
1319 + mfb = AX_RX_CTL_MFB_4096;
1320 + } else if (dev->hard_mtu < 8192) {
1321 + dev->rx_urb_size = 8192;
1322 + mfb = AX_RX_CTL_MFB_8192;
1323 + } else if (dev->hard_mtu < 16384) {
1324 + dev->rx_urb_size = 16384;
1325 + mfb = AX_RX_CTL_MFB_16384;
1328 + rxctl = asix_read_rx_ctl(dev);
1329 + asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
1331 + medium = asix_read_medium_status(dev);
1332 + if (dev->net->mtu > 1500)
1333 + medium |= AX_MEDIUM_JFE;
1335 + medium &= ~AX_MEDIUM_JFE;
1336 + asix_write_medium_mode(dev, medium);
1338 + if (dev->rx_urb_size > old_rx_urb_size)
1339 + usbnet_unlink_rx_urbs(dev);
1342 +static int ax88178_change_mtu(struct net_device *net, int new_mtu)
1344 + struct usbnet *dev = netdev_priv(net);
1345 + int ll_mtu = new_mtu + net->hard_header_len + 4;
1347 + netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
1349 + if (new_mtu <= 0 || ll_mtu > 16384)
1352 + if ((ll_mtu % dev->maxpacket) == 0)
1355 + net->mtu = new_mtu;
1356 + dev->hard_mtu = net->mtu + net->hard_header_len;
1357 + ax88178_set_mfb(dev);
1359 + /* max qlen depend on hard_mtu and rx_urb_size */
1360 + usbnet_update_max_qlen(dev);
1365 +static const struct net_device_ops ax88178_netdev_ops = {
1366 + .ndo_open = usbnet_open,
1367 + .ndo_stop = usbnet_stop,
1368 + .ndo_start_xmit = usbnet_start_xmit,
1369 + .ndo_tx_timeout = usbnet_tx_timeout,
1370 + .ndo_set_mac_address = asix_set_mac_address,
1371 + .ndo_validate_addr = eth_validate_addr,
1372 + .ndo_set_rx_mode = asix_set_multicast,
1373 + .ndo_do_ioctl = asix_ioctl,
1374 + .ndo_change_mtu = ax88178_change_mtu,
1377 +static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1382 + usbnet_get_endpoints(dev,intf);
1384 + /* Get the MAC address */
1385 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
1387 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
1391 + asix_set_netdev_dev_addr(dev, buf);
1393 + /* Initialize MII structure */
1394 + dev->mii.dev = dev->net;
1395 + dev->mii.mdio_read = asix_mdio_read;
1396 + dev->mii.mdio_write = asix_mdio_write;
1397 + dev->mii.phy_id_mask = 0x1f;
1398 + dev->mii.reg_num_mask = 0xff;
1399 + dev->mii.supports_gmii = 1;
1400 + dev->mii.phy_id = asix_get_phy_addr(dev);
1402 + dev->net->netdev_ops = &ax88178_netdev_ops;
1403 + dev->net->ethtool_ops = &ax88178_ethtool_ops;
1405 + /* Blink LEDS so users know driver saw dongle */
1406 + asix_sw_reset(dev, 0);
1409 + asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1412 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1413 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1414 + /* hard_mtu is still the default - the device does not support
1415 + jumbo eth frames */
1416 + dev->rx_urb_size = 2048;
1419 + dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
1420 + if (!dev->driver_priv)
1426 +static const struct driver_info ax8817x_info = {
1427 + .description = "ASIX AX8817x USB 2.0 Ethernet",
1428 + .bind = ax88172_bind,
1429 + .status = asix_status,
1430 + .link_reset = ax88172_link_reset,
1431 + .reset = ax88172_link_reset,
1432 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1433 + .data = 0x00130103,
1436 +static const struct driver_info dlink_dub_e100_info = {
1437 + .description = "DLink DUB-E100 USB Ethernet",
1438 + .bind = ax88172_bind,
1439 + .status = asix_status,
1440 + .link_reset = ax88172_link_reset,
1441 + .reset = ax88172_link_reset,
1442 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1443 + .data = 0x009f9d9f,
1446 +static const struct driver_info netgear_fa120_info = {
1447 + .description = "Netgear FA-120 USB Ethernet",
1448 + .bind = ax88172_bind,
1449 + .status = asix_status,
1450 + .link_reset = ax88172_link_reset,
1451 + .reset = ax88172_link_reset,
1452 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1453 + .data = 0x00130103,
1456 +static const struct driver_info hawking_uf200_info = {
1457 + .description = "Hawking UF200 USB Ethernet",
1458 + .bind = ax88172_bind,
1459 + .status = asix_status,
1460 + .link_reset = ax88172_link_reset,
1461 + .reset = ax88172_link_reset,
1462 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
1463 + .data = 0x001f1d1f,
1466 +static const struct driver_info ax88772_info = {
1467 + .description = "ASIX AX88772 USB 2.0 Ethernet",
1468 + .bind = ax88772_bind,
1469 + .unbind = ax88772_unbind,
1470 + .status = asix_status,
1471 + .link_reset = ax88772_link_reset,
1472 + .reset = ax88772_link_reset,
1473 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
1474 + .rx_fixup = asix_rx_fixup_common,
1475 + .tx_fixup = asix_tx_fixup,
1478 +static const struct driver_info ax88772b_info = {
1479 + .description = "ASIX AX88772B USB 2.0 Ethernet",
1480 + .bind = ax88772_bind,
1481 + .unbind = ax88772_unbind,
1482 + .status = asix_status,
1483 + .link_reset = ax88772_link_reset,
1484 + .reset = ax88772_reset,
1485 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1486 + FLAG_MULTI_PACKET,
1487 + .rx_fixup = asix_rx_fixup_common,
1488 + .tx_fixup = asix_tx_fixup,
1489 + .data = FLAG_EEPROM_MAC,
1492 +static const struct driver_info ax88178_info = {
1493 + .description = "ASIX AX88178 USB 2.0 Ethernet",
1494 + .bind = ax88178_bind,
1495 + .unbind = ax88772_unbind,
1496 + .status = asix_status,
1497 + .link_reset = ax88178_link_reset,
1498 + .reset = ax88178_reset,
1499 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1500 + FLAG_MULTI_PACKET,
1501 + .rx_fixup = asix_rx_fixup_common,
1502 + .tx_fixup = asix_tx_fixup,
1506 + * USBLINK 20F9 "USB 2.0 LAN" USB ethernet adapter, typically found in
1507 + * no-name packaging.
1508 + * USB device strings are:
1509 + * 1: Manufacturer: USBLINK
1510 + * 2: Product: HG20F9 USB2.0
1511 + * 3: Serial: 000003
1512 + * Appears to be compatible with Asix 88772B.
1514 +static const struct driver_info hg20f9_info = {
1515 + .description = "HG20F9 USB 2.0 Ethernet",
1516 + .bind = ax88772_bind,
1517 + .unbind = ax88772_unbind,
1518 + .status = asix_status,
1519 + .link_reset = ax88772_link_reset,
1520 + .reset = ax88772_reset,
1521 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1522 + FLAG_MULTI_PACKET,
1523 + .rx_fixup = asix_rx_fixup_common,
1524 + .tx_fixup = asix_tx_fixup,
1525 + .data = FLAG_EEPROM_MAC,
1528 +static const struct usb_device_id products [] = {
1530 + // Linksys USB200M
1531 + USB_DEVICE (0x077b, 0x2226),
1532 + .driver_info = (unsigned long) &ax8817x_info,
1535 + USB_DEVICE (0x0846, 0x1040),
1536 + .driver_info = (unsigned long) &netgear_fa120_info,
1539 + USB_DEVICE (0x2001, 0x1a00),
1540 + .driver_info = (unsigned long) &dlink_dub_e100_info,
1542 + // Intellinet, ST Lab USB Ethernet
1543 + USB_DEVICE (0x0b95, 0x1720),
1544 + .driver_info = (unsigned long) &ax8817x_info,
1546 + // Hawking UF200, TrendNet TU2-ET100
1547 + USB_DEVICE (0x07b8, 0x420a),
1548 + .driver_info = (unsigned long) &hawking_uf200_info,
1550 + // Billionton Systems, USB2AR
1551 + USB_DEVICE (0x08dd, 0x90ff),
1552 + .driver_info = (unsigned long) &ax8817x_info,
1555 + USB_DEVICE (0x0557, 0x2009),
1556 + .driver_info = (unsigned long) &ax8817x_info,
1558 + // Buffalo LUA-U2-KTX
1559 + USB_DEVICE (0x0411, 0x003d),
1560 + .driver_info = (unsigned long) &ax8817x_info,
1562 + // Buffalo LUA-U2-GT 10/100/1000
1563 + USB_DEVICE (0x0411, 0x006e),
1564 + .driver_info = (unsigned long) &ax88178_info,
1566 + // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
1567 + USB_DEVICE (0x6189, 0x182d),
1568 + .driver_info = (unsigned long) &ax8817x_info,
1570 + // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
1571 + USB_DEVICE (0x0df6, 0x0056),
1572 + .driver_info = (unsigned long) &ax88178_info,
1574 + // Sitecom LN-028 "USB 2.0 10/100/1000 Ethernet adapter"
1575 + USB_DEVICE (0x0df6, 0x061c),
1576 + .driver_info = (unsigned long) &ax88178_info,
1578 + // corega FEther USB2-TX
1579 + USB_DEVICE (0x07aa, 0x0017),
1580 + .driver_info = (unsigned long) &ax8817x_info,
1582 + // Surecom EP-1427X-2
1583 + USB_DEVICE (0x1189, 0x0893),
1584 + .driver_info = (unsigned long) &ax8817x_info,
1586 + // goodway corp usb gwusb2e
1587 + USB_DEVICE (0x1631, 0x6200),
1588 + .driver_info = (unsigned long) &ax8817x_info,
1590 + // JVC MP-PRX1 Port Replicator
1591 + USB_DEVICE (0x04f1, 0x3008),
1592 + .driver_info = (unsigned long) &ax8817x_info,
1594 + // Lenovo U2L100P 10/100
1595 + USB_DEVICE (0x17ef, 0x7203),
1596 + .driver_info = (unsigned long) &ax88772_info,
1598 + // ASIX AX88772B 10/100
1599 + USB_DEVICE (0x0b95, 0x772b),
1600 + .driver_info = (unsigned long) &ax88772b_info,
1602 + // ASIX AX88772 10/100
1603 + USB_DEVICE (0x0b95, 0x7720),
1604 + .driver_info = (unsigned long) &ax88772_info,
1606 + // ASIX AX88178 10/100/1000
1607 + USB_DEVICE (0x0b95, 0x1780),
1608 + .driver_info = (unsigned long) &ax88178_info,
1610 + // Logitec LAN-GTJ/U2A
1611 + USB_DEVICE (0x0789, 0x0160),
1612 + .driver_info = (unsigned long) &ax88178_info,
1614 + // Linksys USB200M Rev 2
1615 + USB_DEVICE (0x13b1, 0x0018),
1616 + .driver_info = (unsigned long) &ax88772_info,
1618 + // 0Q0 cable ethernet
1619 + USB_DEVICE (0x1557, 0x7720),
1620 + .driver_info = (unsigned long) &ax88772_info,
1622 + // DLink DUB-E100 H/W Ver B1
1623 + USB_DEVICE (0x07d1, 0x3c05),
1624 + .driver_info = (unsigned long) &ax88772_info,
1626 + // DLink DUB-E100 H/W Ver B1 Alternate
1627 + USB_DEVICE (0x2001, 0x3c05),
1628 + .driver_info = (unsigned long) &ax88772_info,
1630 + // DLink DUB-E100 H/W Ver C1
1631 + USB_DEVICE (0x2001, 0x1a02),
1632 + .driver_info = (unsigned long) &ax88772_info,
1634 + // Linksys USB1000
1635 + USB_DEVICE (0x1737, 0x0039),
1636 + .driver_info = (unsigned long) &ax88178_info,
1638 + // IO-DATA ETG-US2
1639 + USB_DEVICE (0x04bb, 0x0930),
1640 + .driver_info = (unsigned long) &ax88178_info,
1643 + USB_DEVICE(0x050d, 0x5055),
1644 + .driver_info = (unsigned long) &ax88178_info,
1646 + // Apple USB Ethernet Adapter
1647 + USB_DEVICE(0x05ac, 0x1402),
1648 + .driver_info = (unsigned long) &ax88772_info,
1650 + // Cables-to-Go USB Ethernet Adapter
1651 + USB_DEVICE(0x0b95, 0x772a),
1652 + .driver_info = (unsigned long) &ax88772_info,
1655 + USB_DEVICE(0x14ea, 0xab11),
1656 + .driver_info = (unsigned long) &ax88178_info,
1659 + USB_DEVICE(0x0db0, 0xa877),
1660 + .driver_info = (unsigned long) &ax88772_info,
1662 + // Asus USB Ethernet Adapter
1663 + USB_DEVICE (0x0b95, 0x7e2b),
1664 + .driver_info = (unsigned long) &ax88772_info,
1666 + /* ASIX 88172a demo board */
1667 + USB_DEVICE(0x0b95, 0x172a),
1668 + .driver_info = (unsigned long) &ax88172a_info,
1671 + * USBLINK HG20F9 "USB 2.0 LAN"
1672 + * Appears to have gazumped Linksys's manufacturer ID but
1673 + * doesn't (yet) conflict with any known Linksys product.
1675 + USB_DEVICE(0x066b, 0x20f9),
1676 + .driver_info = (unsigned long) &hg20f9_info,
1680 +MODULE_DEVICE_TABLE(usb, products);
1682 +static struct usb_driver asix_driver = {
1683 + .name = DRIVER_NAME,
1684 + .id_table = products,
1685 + .probe = usbnet_probe,
1686 + .suspend = usbnet_suspend,
1687 + .resume = usbnet_resume,
1688 + .disconnect = usbnet_disconnect,
1689 + .supports_autosuspend = 1,
1690 + .disable_hub_initiated_lpm = 1,
1693 +module_usb_driver(asix_driver);
1695 +MODULE_AUTHOR("David Hollis");
1696 +MODULE_VERSION(DRIVER_VERSION);
1697 +MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1698 +MODULE_LICENSE("GPL");
1700 diff -Naur backports-4.2.6-1.org/drivers/net/usb/asix.h backports-4.2.6-1/drivers/net/usb/asix.h
1701 --- backports-4.2.6-1.org/drivers/net/usb/asix.h 1970-01-01 01:00:00.000000000 +0100
1702 +++ backports-4.2.6-1/drivers/net/usb/asix.h 2016-06-28 14:35:17.965307221 +0200
1705 + * ASIX AX8817X based USB 2.0 Ethernet Devices
1706 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
1707 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
1708 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
1709 + * Copyright (c) 2002-2003 TiVo Inc.
1711 + * This program is free software; you can redistribute it and/or modify
1712 + * it under the terms of the GNU General Public License as published by
1713 + * the Free Software Foundation; either version 2 of the License, or
1714 + * (at your option) any later version.
1716 + * This program is distributed in the hope that it will be useful,
1717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1719 + * GNU General Public License for more details.
1721 + * You should have received a copy of the GNU General Public License
1722 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
1728 +// #define DEBUG // error path messages, extra info
1729 +// #define VERBOSE // more; success messages
1731 +#include <linux/module.h>
1732 +#include <linux/kmod.h>
1733 +#include <linux/netdevice.h>
1734 +#include <linux/etherdevice.h>
1735 +#include <linux/ethtool.h>
1736 +#include <linux/workqueue.h>
1737 +#include <linux/mii.h>
1738 +#include <linux/usb.h>
1739 +#include <linux/crc32.h>
1740 +#include <linux/usb/usbnet.h>
1741 +#include <linux/slab.h>
1742 +#include <linux/if_vlan.h>
1744 +#define DRIVER_VERSION "22-Dec-2011"
1745 +#define DRIVER_NAME "asix"
1747 +/* ASIX AX8817X based USB 2.0 Ethernet Devices */
1749 +#define AX_CMD_SET_SW_MII 0x06
1750 +#define AX_CMD_READ_MII_REG 0x07
1751 +#define AX_CMD_WRITE_MII_REG 0x08
1752 +#define AX_CMD_SET_HW_MII 0x0a
1753 +#define AX_CMD_READ_EEPROM 0x0b
1754 +#define AX_CMD_WRITE_EEPROM 0x0c
1755 +#define AX_CMD_WRITE_ENABLE 0x0d
1756 +#define AX_CMD_WRITE_DISABLE 0x0e
1757 +#define AX_CMD_READ_RX_CTL 0x0f
1758 +#define AX_CMD_WRITE_RX_CTL 0x10
1759 +#define AX_CMD_READ_IPG012 0x11
1760 +#define AX_CMD_WRITE_IPG0 0x12
1761 +#define AX_CMD_WRITE_IPG1 0x13
1762 +#define AX_CMD_READ_NODE_ID 0x13
1763 +#define AX_CMD_WRITE_NODE_ID 0x14
1764 +#define AX_CMD_WRITE_IPG2 0x14
1765 +#define AX_CMD_WRITE_MULTI_FILTER 0x16
1766 +#define AX88172_CMD_READ_NODE_ID 0x17
1767 +#define AX_CMD_READ_PHY_ID 0x19
1768 +#define AX_CMD_READ_MEDIUM_STATUS 0x1a
1769 +#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
1770 +#define AX_CMD_READ_MONITOR_MODE 0x1c
1771 +#define AX_CMD_WRITE_MONITOR_MODE 0x1d
1772 +#define AX_CMD_READ_GPIOS 0x1e
1773 +#define AX_CMD_WRITE_GPIOS 0x1f
1774 +#define AX_CMD_SW_RESET 0x20
1775 +#define AX_CMD_SW_PHY_STATUS 0x21
1776 +#define AX_CMD_SW_PHY_SELECT 0x22
1778 +#define AX_PHY_SELECT_MASK (BIT(3) | BIT(2))
1779 +#define AX_PHY_SELECT_INTERNAL 0
1780 +#define AX_PHY_SELECT_EXTERNAL BIT(2)
1782 +#define AX_MONITOR_MODE 0x01
1783 +#define AX_MONITOR_LINK 0x02
1784 +#define AX_MONITOR_MAGIC 0x04
1785 +#define AX_MONITOR_HSFS 0x10
1787 +/* AX88172 Medium Status Register values */
1788 +#define AX88172_MEDIUM_FD 0x02
1789 +#define AX88172_MEDIUM_TX 0x04
1790 +#define AX88172_MEDIUM_FC 0x10
1791 +#define AX88172_MEDIUM_DEFAULT \
1792 + ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
1794 +#define AX_MCAST_FILTER_SIZE 8
1795 +#define AX_MAX_MCAST 64
1797 +#define AX_SWRESET_CLEAR 0x00
1798 +#define AX_SWRESET_RR 0x01
1799 +#define AX_SWRESET_RT 0x02
1800 +#define AX_SWRESET_PRTE 0x04
1801 +#define AX_SWRESET_PRL 0x08
1802 +#define AX_SWRESET_BZ 0x10
1803 +#define AX_SWRESET_IPRL 0x20
1804 +#define AX_SWRESET_IPPD 0x40
1806 +#define AX88772_IPG0_DEFAULT 0x15
1807 +#define AX88772_IPG1_DEFAULT 0x0c
1808 +#define AX88772_IPG2_DEFAULT 0x12
1810 +/* AX88772 & AX88178 Medium Mode Register */
1811 +#define AX_MEDIUM_PF 0x0080
1812 +#define AX_MEDIUM_JFE 0x0040
1813 +#define AX_MEDIUM_TFC 0x0020
1814 +#define AX_MEDIUM_RFC 0x0010
1815 +#define AX_MEDIUM_ENCK 0x0008
1816 +#define AX_MEDIUM_AC 0x0004
1817 +#define AX_MEDIUM_FD 0x0002
1818 +#define AX_MEDIUM_GM 0x0001
1819 +#define AX_MEDIUM_SM 0x1000
1820 +#define AX_MEDIUM_SBP 0x0800
1821 +#define AX_MEDIUM_PS 0x0200
1822 +#define AX_MEDIUM_RE 0x0100
1824 +#define AX88178_MEDIUM_DEFAULT \
1825 + (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
1826 + AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
1829 +#define AX88772_MEDIUM_DEFAULT \
1830 + (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
1831 + AX_MEDIUM_TFC | AX_MEDIUM_PS | \
1832 + AX_MEDIUM_AC | AX_MEDIUM_RE)
1834 +/* AX88772 & AX88178 RX_CTL values */
1835 +#define AX_RX_CTL_SO 0x0080
1836 +#define AX_RX_CTL_AP 0x0020
1837 +#define AX_RX_CTL_AM 0x0010
1838 +#define AX_RX_CTL_AB 0x0008
1839 +#define AX_RX_CTL_SEP 0x0004
1840 +#define AX_RX_CTL_AMALL 0x0002
1841 +#define AX_RX_CTL_PRO 0x0001
1842 +#define AX_RX_CTL_MFB_2048 0x0000
1843 +#define AX_RX_CTL_MFB_4096 0x0100
1844 +#define AX_RX_CTL_MFB_8192 0x0200
1845 +#define AX_RX_CTL_MFB_16384 0x0300
1847 +#define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
1849 +/* GPIO 0 .. 2 toggles */
1850 +#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
1851 +#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
1852 +#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
1853 +#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
1854 +#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
1855 +#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
1856 +#define AX_GPIO_RESERVED 0x40 /* Reserved */
1857 +#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
1859 +#define AX_EEPROM_MAGIC 0xdeadbeef
1860 +#define AX_EEPROM_LEN 0x200
1862 +/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
1864 + u8 multi_filter[AX_MCAST_FILTER_SIZE];
1865 + u8 mac_addr[ETH_ALEN];
1871 +struct asix_rx_fixup_info {
1872 + struct sk_buff *ax_skb;
1878 +struct asix_common_private {
1879 + struct asix_rx_fixup_info rx_fixup_info;
1882 +extern const struct driver_info ax88172a_info;
1884 +/* ASIX specific flags */
1885 +#define FLAG_EEPROM_MAC (1UL << 0) /* init device MAC from eeprom */
1887 +int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
1888 + u16 size, void *data);
1890 +int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
1891 + u16 size, void *data);
1893 +void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
1894 + u16 index, u16 size, void *data);
1896 +int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
1897 + struct asix_rx_fixup_info *rx);
1898 +int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb);
1900 +struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
1903 +int asix_set_sw_mii(struct usbnet *dev);
1904 +int asix_set_hw_mii(struct usbnet *dev);
1906 +int asix_read_phy_addr(struct usbnet *dev, int internal);
1907 +int asix_get_phy_addr(struct usbnet *dev);
1909 +int asix_sw_reset(struct usbnet *dev, u8 flags);
1911 +u16 asix_read_rx_ctl(struct usbnet *dev);
1912 +int asix_write_rx_ctl(struct usbnet *dev, u16 mode);
1914 +u16 asix_read_medium_status(struct usbnet *dev);
1915 +int asix_write_medium_mode(struct usbnet *dev, u16 mode);
1917 +int asix_write_gpio(struct usbnet *dev, u16 value, int sleep);
1919 +void asix_set_multicast(struct net_device *net);
1921 +int asix_mdio_read(struct net_device *netdev, int phy_id, int loc);
1922 +void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val);
1924 +void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
1925 +int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
1927 +int asix_get_eeprom_len(struct net_device *net);
1928 +int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
1930 +int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
1933 +void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info);
1935 +int asix_set_mac_address(struct net_device *net, void *p);
1937 +#endif /* _ASIX_H */
1938 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ax88172a.c backports-4.2.6-1/drivers/net/usb/ax88172a.c
1939 --- backports-4.2.6-1.org/drivers/net/usb/ax88172a.c 1970-01-01 01:00:00.000000000 +0100
1940 +++ backports-4.2.6-1/drivers/net/usb/ax88172a.c 2016-06-28 14:35:17.965307221 +0200
1943 + * ASIX AX88172A based USB 2.0 Ethernet Devices
1944 + * Copyright (C) 2012 OMICRON electronics GmbH
1946 + * Supports external PHYs via phylib. Based on the driver for the
1947 + * AX88772. Original copyrights follow:
1949 + * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
1950 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
1951 + * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
1952 + * Copyright (c) 2002-2003 TiVo Inc.
1954 + * This program is free software; you can redistribute it and/or modify
1955 + * it under the terms of the GNU General Public License as published by
1956 + * the Free Software Foundation; either version 2 of the License, or
1957 + * (at your option) any later version.
1959 + * This program is distributed in the hope that it will be useful,
1960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1962 + * GNU General Public License for more details.
1964 + * You should have received a copy of the GNU General Public License
1965 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
1969 +#include <linux/phy.h>
1971 +struct ax88172a_private {
1972 + struct mii_bus *mdio;
1973 + struct phy_device *phydev;
1974 + char phy_name[20];
1978 + struct asix_rx_fixup_info rx_fixup_info;
1981 +/* MDIO read and write wrappers for phylib */
1982 +static int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
1984 + return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
1988 +static int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum,
1991 + asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val);
1995 +static int ax88172a_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
1997 + if (!netif_running(net))
2003 + return phy_mii_ioctl(net->phydev, rq, cmd);
2006 +/* set MAC link settings according to information from phylib */
2007 +static void ax88172a_adjust_link(struct net_device *netdev)
2009 + struct phy_device *phydev = netdev->phydev;
2010 + struct usbnet *dev = netdev_priv(netdev);
2011 + struct ax88172a_private *priv = dev->driver_priv;
2014 + if (phydev->link) {
2015 + mode = AX88772_MEDIUM_DEFAULT;
2017 + if (phydev->duplex == DUPLEX_HALF)
2018 + mode &= ~AX_MEDIUM_FD;
2020 + if (phydev->speed != SPEED_100)
2021 + mode &= ~AX_MEDIUM_PS;
2024 + if (mode != priv->oldmode) {
2025 + asix_write_medium_mode(dev, mode);
2026 + priv->oldmode = mode;
2027 + netdev_dbg(netdev, "speed %u duplex %d, setting mode to 0x%04x\n",
2028 + phydev->speed, phydev->duplex, mode);
2029 + phy_print_status(phydev);
2033 +static void ax88172a_status(struct usbnet *dev, struct urb *urb)
2035 + /* link changes are detected by polling the phy */
2038 +/* use phylib infrastructure */
2039 +static int ax88172a_init_mdio(struct usbnet *dev)
2041 + struct ax88172a_private *priv = dev->driver_priv;
2044 + priv->mdio = mdiobus_alloc();
2045 + if (!priv->mdio) {
2046 + netdev_err(dev->net, "Could not allocate MDIO bus\n");
2050 + priv->mdio->priv = (void *)dev;
2051 + priv->mdio->read = &asix_mdio_bus_read;
2052 + priv->mdio->write = &asix_mdio_bus_write;
2053 + priv->mdio->name = "Asix MDIO Bus";
2054 + /* mii bus name is usb-<usb bus number>-<usb device number> */
2055 + snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
2056 + dev->udev->bus->busnum, dev->udev->devnum);
2058 + priv->mdio->irq = kzalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
2059 + if (!priv->mdio->irq) {
2063 + for (i = 0; i < PHY_MAX_ADDR; i++)
2064 + priv->mdio->irq[i] = PHY_POLL;
2066 + ret = mdiobus_register(priv->mdio);
2068 + netdev_err(dev->net, "Could not register MDIO bus\n");
2072 + netdev_info(dev->net, "registered mdio bus %s\n", priv->mdio->id);
2076 + kfree(priv->mdio->irq);
2078 + mdiobus_free(priv->mdio);
2082 +static void ax88172a_remove_mdio(struct usbnet *dev)
2084 + struct ax88172a_private *priv = dev->driver_priv;
2086 + netdev_info(dev->net, "deregistering mdio bus %s\n", priv->mdio->id);
2087 + mdiobus_unregister(priv->mdio);
2088 + kfree(priv->mdio->irq);
2089 + mdiobus_free(priv->mdio);
2092 +static const struct net_device_ops ax88172a_netdev_ops = {
2093 + .ndo_open = usbnet_open,
2094 + .ndo_stop = usbnet_stop,
2095 + .ndo_start_xmit = usbnet_start_xmit,
2096 + .ndo_tx_timeout = usbnet_tx_timeout,
2097 + .ndo_change_mtu = usbnet_change_mtu,
2098 + .ndo_set_mac_address = asix_set_mac_address,
2099 + .ndo_validate_addr = eth_validate_addr,
2100 + .ndo_do_ioctl = ax88172a_ioctl,
2101 + .ndo_set_rx_mode = asix_set_multicast,
2104 +static int ax88172a_get_settings(struct net_device *net,
2105 + struct ethtool_cmd *cmd)
2110 + return phy_ethtool_gset(net->phydev, cmd);
2113 +static int ax88172a_set_settings(struct net_device *net,
2114 + struct ethtool_cmd *cmd)
2119 + return phy_ethtool_sset(net->phydev, cmd);
2122 +static int ax88172a_nway_reset(struct net_device *net)
2127 + return phy_start_aneg(net->phydev);
2130 +static const struct ethtool_ops ax88172a_ethtool_ops = {
2131 + .get_drvinfo = asix_get_drvinfo,
2132 + .get_link = usbnet_get_link,
2133 + .get_msglevel = usbnet_get_msglevel,
2134 + .set_msglevel = usbnet_set_msglevel,
2135 + .get_wol = asix_get_wol,
2136 + .set_wol = asix_set_wol,
2137 + .get_eeprom_len = asix_get_eeprom_len,
2138 + .get_eeprom = asix_get_eeprom,
2139 + .set_eeprom = asix_set_eeprom,
2140 + .get_settings = ax88172a_get_settings,
2141 + .set_settings = ax88172a_set_settings,
2142 + .nway_reset = ax88172a_nway_reset,
2145 +static int ax88172a_reset_phy(struct usbnet *dev, int embd_phy)
2149 + ret = asix_sw_reset(dev, AX_SWRESET_IPPD);
2154 + ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
2160 + ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_IPPD);
2171 +static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf)
2175 + struct ax88172a_private *priv;
2177 + usbnet_get_endpoints(dev, intf);
2179 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
2183 + dev->driver_priv = priv;
2185 + /* Get the MAC address */
2186 + ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
2188 + netdev_err(dev->net, "Failed to read MAC address: %d\n", ret);
2191 + memcpy(dev->net->dev_addr, buf, ETH_ALEN);
2193 + dev->net->netdev_ops = &ax88172a_netdev_ops;
2194 + dev->net->ethtool_ops = &ax88172a_ethtool_ops;
2196 + /* are we using the internal or the external phy? */
2197 + ret = asix_read_cmd(dev, AX_CMD_SW_PHY_STATUS, 0, 0, 1, buf);
2199 + netdev_err(dev->net, "Failed to read software interface selection register: %d\n",
2204 + netdev_dbg(dev->net, "AX_CMD_SW_PHY_STATUS = 0x%02x\n", buf[0]);
2205 + switch (buf[0] & AX_PHY_SELECT_MASK) {
2206 + case AX_PHY_SELECT_INTERNAL:
2207 + netdev_dbg(dev->net, "use internal phy\n");
2208 + priv->use_embdphy = 1;
2210 + case AX_PHY_SELECT_EXTERNAL:
2211 + netdev_dbg(dev->net, "use external phy\n");
2212 + priv->use_embdphy = 0;
2215 + netdev_err(dev->net, "Interface mode not supported by driver\n");
2220 + priv->phy_addr = asix_read_phy_addr(dev, priv->use_embdphy);
2221 + ax88172a_reset_phy(dev, priv->use_embdphy);
2223 + /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
2224 + if (dev->driver_info->flags & FLAG_FRAMING_AX) {
2225 + /* hard_mtu is still the default - the device does not support
2226 + jumbo eth frames */
2227 + dev->rx_urb_size = 2048;
2230 + /* init MDIO bus */
2231 + ret = ax88172a_init_mdio(dev);
2242 +static int ax88172a_stop(struct usbnet *dev)
2244 + struct ax88172a_private *priv = dev->driver_priv;
2246 + netdev_dbg(dev->net, "Stopping interface\n");
2248 + if (priv->phydev) {
2249 + netdev_info(dev->net, "Disconnecting from phy %s\n",
2251 + phy_stop(priv->phydev);
2252 + phy_disconnect(priv->phydev);
2258 +static void ax88172a_unbind(struct usbnet *dev, struct usb_interface *intf)
2260 + struct ax88172a_private *priv = dev->driver_priv;
2262 + ax88172a_remove_mdio(dev);
2266 +static int ax88172a_reset(struct usbnet *dev)
2268 + struct asix_data *data = (struct asix_data *)&dev->data;
2269 + struct ax88172a_private *priv = dev->driver_priv;
2273 + ax88172a_reset_phy(dev, priv->use_embdphy);
2276 + rx_ctl = asix_read_rx_ctl(dev);
2277 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
2278 + ret = asix_write_rx_ctl(dev, 0x0000);
2282 + rx_ctl = asix_read_rx_ctl(dev);
2283 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
2287 + ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
2288 + AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
2289 + AX88772_IPG2_DEFAULT, 0, NULL);
2291 + netdev_err(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
2295 + /* Rewrite MAC address */
2296 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
2297 + ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
2302 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
2303 + ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
2307 + rx_ctl = asix_read_rx_ctl(dev);
2308 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
2311 + rx_ctl = asix_read_medium_status(dev);
2312 + netdev_dbg(dev->net, "Medium Status is 0x%04x after all initializations\n",
2315 + /* Connect to PHY */
2316 + snprintf(priv->phy_name, 20, PHY_ID_FMT,
2317 + priv->mdio->id, priv->phy_addr);
2319 + priv->phydev = phy_connect(dev->net, priv->phy_name,
2320 + &ax88172a_adjust_link,
2321 + PHY_INTERFACE_MODE_MII);
2322 + if (IS_ERR(priv->phydev)) {
2323 + netdev_err(dev->net, "Could not connect to PHY device %s\n",
2325 + ret = PTR_ERR(priv->phydev);
2329 + netdev_info(dev->net, "Connected to phy %s\n", priv->phy_name);
2331 + /* During power-up, the AX88172A set the power down (BMCR_PDOWN)
2332 + * bit of the PHY. Bring the PHY up again.
2334 + genphy_resume(priv->phydev);
2335 + phy_start(priv->phydev);
2344 +static int ax88172a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
2346 + struct ax88172a_private *dp = dev->driver_priv;
2347 + struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
2349 + return asix_rx_fixup_internal(dev, skb, rx);
2352 +const struct driver_info ax88172a_info = {
2353 + .description = "ASIX AX88172A USB 2.0 Ethernet",
2354 + .bind = ax88172a_bind,
2355 + .reset = ax88172a_reset,
2356 + .stop = ax88172a_stop,
2357 + .unbind = ax88172a_unbind,
2358 + .status = ax88172a_status,
2359 + .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
2360 + FLAG_MULTI_PACKET,
2361 + .rx_fixup = ax88172a_rx_fixup,
2362 + .tx_fixup = asix_tx_fixup,
2364 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ax88179_178a.c backports-4.2.6-1/drivers/net/usb/ax88179_178a.c
2365 --- backports-4.2.6-1.org/drivers/net/usb/ax88179_178a.c 1970-01-01 01:00:00.000000000 +0100
2366 +++ backports-4.2.6-1/drivers/net/usb/ax88179_178a.c 2016-06-28 14:35:17.968640554 +0200
2369 + * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices
2371 + * Copyright (C) 2011-2013 ASIX
2373 + * This program is free software; you can redistribute it and/or modify
2374 + * it under the terms of the GNU General Public License
2375 + * as published by the Free Software Foundation; either version 2
2376 + * of the License, or (at your option) any later version.
2378 + * This program is distributed in the hope that it will be useful,
2379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2381 + * GNU General Public License for more details.
2383 + * You should have received a copy of the GNU General Public License
2384 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
2387 +#include <linux/module.h>
2388 +#include <linux/etherdevice.h>
2389 +#include <linux/mii.h>
2390 +#include <linux/usb.h>
2391 +#include <linux/crc32.h>
2392 +#include <linux/usb/usbnet.h>
2393 +#include <uapi/linux/mdio.h>
2394 +#include <linux/mdio.h>
2396 +#define AX88179_PHY_ID 0x03
2397 +#define AX_EEPROM_LEN 0x100
2398 +#define AX88179_EEPROM_MAGIC 0x17900b95
2399 +#define AX_MCAST_FLTSIZE 8
2400 +#define AX_MAX_MCAST 64
2401 +#define AX_INT_PPLS_LINK ((u32)BIT(16))
2402 +#define AX_RXHDR_L4_TYPE_MASK 0x1c
2403 +#define AX_RXHDR_L4_TYPE_UDP 4
2404 +#define AX_RXHDR_L4_TYPE_TCP 16
2405 +#define AX_RXHDR_L3CSUM_ERR 2
2406 +#define AX_RXHDR_L4CSUM_ERR 1
2407 +#define AX_RXHDR_CRC_ERR ((u32)BIT(29))
2408 +#define AX_RXHDR_DROP_ERR ((u32)BIT(31))
2409 +#define AX_ACCESS_MAC 0x01
2410 +#define AX_ACCESS_PHY 0x02
2411 +#define AX_ACCESS_EEPROM 0x04
2412 +#define AX_ACCESS_EFUS 0x05
2413 +#define AX_PAUSE_WATERLVL_HIGH 0x54
2414 +#define AX_PAUSE_WATERLVL_LOW 0x55
2416 +#define PHYSICAL_LINK_STATUS 0x02
2417 + #define AX_USB_SS 0x04
2418 + #define AX_USB_HS 0x02
2420 +#define GENERAL_STATUS 0x03
2421 +/* Check AX88179 version. UA1:Bit2 = 0, UA2:Bit2 = 1 */
2422 + #define AX_SECLD 0x04
2424 +#define AX_SROM_ADDR 0x07
2425 +#define AX_SROM_CMD 0x0a
2426 + #define EEP_RD 0x04
2427 + #define EEP_BUSY 0x10
2429 +#define AX_SROM_DATA_LOW 0x08
2430 +#define AX_SROM_DATA_HIGH 0x09
2432 +#define AX_RX_CTL 0x0b
2433 + #define AX_RX_CTL_DROPCRCERR 0x0100
2434 + #define AX_RX_CTL_IPE 0x0200
2435 + #define AX_RX_CTL_START 0x0080
2436 + #define AX_RX_CTL_AP 0x0020
2437 + #define AX_RX_CTL_AM 0x0010
2438 + #define AX_RX_CTL_AB 0x0008
2439 + #define AX_RX_CTL_AMALL 0x0002
2440 + #define AX_RX_CTL_PRO 0x0001
2441 + #define AX_RX_CTL_STOP 0x0000
2443 +#define AX_NODE_ID 0x10
2444 +#define AX_MULFLTARY 0x16
2446 +#define AX_MEDIUM_STATUS_MODE 0x22
2447 + #define AX_MEDIUM_GIGAMODE 0x01
2448 + #define AX_MEDIUM_FULL_DUPLEX 0x02
2449 + #define AX_MEDIUM_EN_125MHZ 0x08
2450 + #define AX_MEDIUM_RXFLOW_CTRLEN 0x10
2451 + #define AX_MEDIUM_TXFLOW_CTRLEN 0x20
2452 + #define AX_MEDIUM_RECEIVE_EN 0x100
2453 + #define AX_MEDIUM_PS 0x200
2454 + #define AX_MEDIUM_JUMBO_EN 0x8040
2456 +#define AX_MONITOR_MOD 0x24
2457 + #define AX_MONITOR_MODE_RWLC 0x02
2458 + #define AX_MONITOR_MODE_RWMP 0x04
2459 + #define AX_MONITOR_MODE_PMEPOL 0x20
2460 + #define AX_MONITOR_MODE_PMETYPE 0x40
2462 +#define AX_GPIO_CTRL 0x25
2463 + #define AX_GPIO_CTRL_GPIO3EN 0x80
2464 + #define AX_GPIO_CTRL_GPIO2EN 0x40
2465 + #define AX_GPIO_CTRL_GPIO1EN 0x20
2467 +#define AX_PHYPWR_RSTCTL 0x26
2468 + #define AX_PHYPWR_RSTCTL_BZ 0x0010
2469 + #define AX_PHYPWR_RSTCTL_IPRL 0x0020
2470 + #define AX_PHYPWR_RSTCTL_AT 0x1000
2472 +#define AX_RX_BULKIN_QCTRL 0x2e
2473 +#define AX_CLK_SELECT 0x33
2474 + #define AX_CLK_SELECT_BCS 0x01
2475 + #define AX_CLK_SELECT_ACS 0x02
2476 + #define AX_CLK_SELECT_ULR 0x08
2478 +#define AX_RXCOE_CTL 0x34
2479 + #define AX_RXCOE_IP 0x01
2480 + #define AX_RXCOE_TCP 0x02
2481 + #define AX_RXCOE_UDP 0x04
2482 + #define AX_RXCOE_TCPV6 0x20
2483 + #define AX_RXCOE_UDPV6 0x40
2485 +#define AX_TXCOE_CTL 0x35
2486 + #define AX_TXCOE_IP 0x01
2487 + #define AX_TXCOE_TCP 0x02
2488 + #define AX_TXCOE_UDP 0x04
2489 + #define AX_TXCOE_TCPV6 0x20
2490 + #define AX_TXCOE_UDPV6 0x40
2492 +#define AX_LEDCTRL 0x73
2494 +#define GMII_PHY_PHYSR 0x11
2495 + #define GMII_PHY_PHYSR_SMASK 0xc000
2496 + #define GMII_PHY_PHYSR_GIGA 0x8000
2497 + #define GMII_PHY_PHYSR_100 0x4000
2498 + #define GMII_PHY_PHYSR_FULL 0x2000
2499 + #define GMII_PHY_PHYSR_LINK 0x400
2501 +#define GMII_LED_ACT 0x1a
2502 + #define GMII_LED_ACTIVE_MASK 0xff8f
2503 + #define GMII_LED0_ACTIVE BIT(4)
2504 + #define GMII_LED1_ACTIVE BIT(5)
2505 + #define GMII_LED2_ACTIVE BIT(6)
2507 +#define GMII_LED_LINK 0x1c
2508 + #define GMII_LED_LINK_MASK 0xf888
2509 + #define GMII_LED0_LINK_10 BIT(0)
2510 + #define GMII_LED0_LINK_100 BIT(1)
2511 + #define GMII_LED0_LINK_1000 BIT(2)
2512 + #define GMII_LED1_LINK_10 BIT(4)
2513 + #define GMII_LED1_LINK_100 BIT(5)
2514 + #define GMII_LED1_LINK_1000 BIT(6)
2515 + #define GMII_LED2_LINK_10 BIT(8)
2516 + #define GMII_LED2_LINK_100 BIT(9)
2517 + #define GMII_LED2_LINK_1000 BIT(10)
2518 + #define LED0_ACTIVE BIT(0)
2519 + #define LED0_LINK_10 BIT(1)
2520 + #define LED0_LINK_100 BIT(2)
2521 + #define LED0_LINK_1000 BIT(3)
2522 + #define LED0_FD BIT(4)
2523 + #define LED0_USB3_MASK 0x001f
2524 + #define LED1_ACTIVE BIT(5)
2525 + #define LED1_LINK_10 BIT(6)
2526 + #define LED1_LINK_100 BIT(7)
2527 + #define LED1_LINK_1000 BIT(8)
2528 + #define LED1_FD BIT(9)
2529 + #define LED1_USB3_MASK 0x03e0
2530 + #define LED2_ACTIVE BIT(10)
2531 + #define LED2_LINK_1000 BIT(13)
2532 + #define LED2_LINK_100 BIT(12)
2533 + #define LED2_LINK_10 BIT(11)
2534 + #define LED2_FD BIT(14)
2535 + #define LED_VALID BIT(15)
2536 + #define LED2_USB3_MASK 0x7c00
2538 +#define GMII_PHYPAGE 0x1e
2539 +#define GMII_PHY_PAGE_SELECT 0x1f
2540 + #define GMII_PHY_PGSEL_EXT 0x0007
2541 + #define GMII_PHY_PGSEL_PAGE0 0x0000
2542 + #define GMII_PHY_PGSEL_PAGE3 0x0003
2543 + #define GMII_PHY_PGSEL_PAGE5 0x0005
2545 +struct ax88179_data {
2552 +struct ax88179_int_data {
2557 +static const struct {
2558 + unsigned char ctrl, timer_l, timer_h, size, ifg;
2559 +} AX88179_BULKIN_SIZE[] = {
2560 + {7, 0x4f, 0, 0x12, 0xff},
2561 + {7, 0x20, 3, 0x16, 0xff},
2562 + {7, 0xae, 7, 0x18, 0xff},
2563 + {7, 0xcc, 0x4c, 0x18, 8},
2566 +static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2567 + u16 size, void *data, int in_pm)
2570 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
2575 + fn = usbnet_read_cmd;
2577 + fn = usbnet_read_cmd_nopm;
2579 + ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2580 + value, index, data, size);
2582 + if (unlikely(ret < 0))
2583 + netdev_warn(dev->net, "Failed to read reg index 0x%04x: %d\n",
2589 +static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2590 + u16 size, void *data, int in_pm)
2593 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
2598 + fn = usbnet_write_cmd;
2600 + fn = usbnet_write_cmd_nopm;
2602 + ret = fn(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2603 + value, index, data, size);
2605 + if (unlikely(ret < 0))
2606 + netdev_warn(dev->net, "Failed to write reg index 0x%04x: %d\n",
2612 +static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
2613 + u16 index, u16 size, void *data)
2618 + buf = *((u16 *)data);
2619 + cpu_to_le16s(&buf);
2620 + usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2621 + USB_RECIP_DEVICE, value, index, &buf,
2624 + usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
2625 + USB_RECIP_DEVICE, value, index, data,
2630 +static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2631 + u16 index, u16 size, void *data)
2637 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2638 + le16_to_cpus(&buf);
2639 + *((u16 *)data) = buf;
2640 + } else if (4 == size) {
2642 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1);
2643 + le32_to_cpus(&buf);
2644 + *((u32 *)data) = buf;
2646 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1);
2652 +static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
2653 + u16 index, u16 size, void *data)
2659 + buf = *((u16 *)data);
2660 + cpu_to_le16s(&buf);
2661 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2664 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2671 +static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2672 + u16 size, void *data)
2678 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
2679 + le16_to_cpus(&buf);
2680 + *((u16 *)data) = buf;
2681 + } else if (4 == size) {
2683 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0);
2684 + le32_to_cpus(&buf);
2685 + *((u32 *)data) = buf;
2687 + ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0);
2693 +static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
2694 + u16 size, void *data)
2700 + buf = *((u16 *)data);
2701 + cpu_to_le16s(&buf);
2702 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2705 + ret = __ax88179_write_cmd(dev, cmd, value, index,
2712 +static void ax88179_status(struct usbnet *dev, struct urb *urb)
2714 + struct ax88179_int_data *event;
2717 + if (urb->actual_length < 8)
2720 + event = urb->transfer_buffer;
2721 + le32_to_cpus((void *)&event->intdata1);
2723 + link = (((__force u32)event->intdata1) & AX_INT_PPLS_LINK) >> 16;
2725 + if (netif_carrier_ok(dev->net) != link) {
2726 + usbnet_link_change(dev, link, 1);
2727 + netdev_info(dev->net, "ax88179 - Link status is: %d\n", link);
2731 +static int ax88179_mdio_read(struct net_device *netdev, int phy_id, int loc)
2733 + struct usbnet *dev = netdev_priv(netdev);
2736 + ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
2740 +static void ax88179_mdio_write(struct net_device *netdev, int phy_id, int loc,
2743 + struct usbnet *dev = netdev_priv(netdev);
2744 + u16 res = (u16) val;
2746 + ax88179_write_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)loc, 2, &res);
2749 +static inline int ax88179_phy_mmd_indirect(struct usbnet *dev, u16 prtad,
2756 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2757 + MII_MMD_CTRL, 2, &tmp16);
2760 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2761 + MII_MMD_DATA, 2, &tmp16);
2763 + tmp16 = devad | MII_MMD_CTRL_NOINCR;
2764 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2765 + MII_MMD_CTRL, 2, &tmp16);
2771 +ax88179_phy_read_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad)
2776 + ax88179_phy_mmd_indirect(dev, prtad, devad);
2778 + ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2779 + MII_MMD_DATA, 2, &tmp16);
2787 +ax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad,
2792 + ax88179_phy_mmd_indirect(dev, prtad, devad);
2794 + ret = ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
2795 + MII_MMD_DATA, 2, &data);
2803 +static int ax88179_suspend(struct usb_interface *intf, pm_message_t message)
2805 + struct usbnet *dev = usb_get_intfdata(intf);
2809 + usbnet_suspend(intf, message);
2811 + /* Disable RX path */
2812 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2814 + tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
2815 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
2818 + /* Force bulk-in zero length */
2819 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2822 + tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL;
2823 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2826 + /* change clock */
2828 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2830 + /* Configure RX control register => stop operation */
2831 + tmp16 = AX_RX_CTL_STOP;
2832 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
2837 +/* This function is used to enable the autodetach function. */
2838 +/* This function is determined by offset 0x43 of EEPROM */
2839 +static int ax88179_auto_detach(struct usbnet *dev, int in_pm)
2843 + int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *);
2844 + int (*fnw)(struct usbnet *, u8, u16, u16, u16, void *);
2847 + fnr = ax88179_read_cmd;
2848 + fnw = ax88179_write_cmd;
2850 + fnr = ax88179_read_cmd_nopm;
2851 + fnw = ax88179_write_cmd_nopm;
2854 + if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0)
2857 + if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100)))
2860 + /* Enable Auto Detach bit */
2862 + fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2863 + tmp8 |= AX_CLK_SELECT_ULR;
2864 + fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2866 + fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
2867 + tmp16 |= AX_PHYPWR_RSTCTL_AT;
2868 + fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
2873 +static int ax88179_resume(struct usb_interface *intf)
2875 + struct usbnet *dev = usb_get_intfdata(intf);
2879 + usbnet_link_change(dev, 0, 0);
2881 + /* Power up ethernet PHY */
2883 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2887 + tmp16 = AX_PHYPWR_RSTCTL_IPRL;
2888 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL,
2892 + /* Ethernet PHY Auto Detach*/
2893 + ax88179_auto_detach(dev, 1);
2895 + /* Enable clock */
2896 + ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2897 + tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
2898 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8);
2901 + /* Configure RX control register => start operation */
2902 + tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
2903 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
2904 + ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
2906 + return usbnet_resume(intf);
2910 +ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
2912 + struct usbnet *dev = netdev_priv(net);
2915 + if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
2916 + 1, 1, &opt) < 0) {
2917 + wolinfo->supported = 0;
2918 + wolinfo->wolopts = 0;
2922 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
2923 + wolinfo->wolopts = 0;
2924 + if (opt & AX_MONITOR_MODE_RWLC)
2925 + wolinfo->wolopts |= WAKE_PHY;
2926 + if (opt & AX_MONITOR_MODE_RWMP)
2927 + wolinfo->wolopts |= WAKE_MAGIC;
2931 +ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
2933 + struct usbnet *dev = netdev_priv(net);
2936 + if (wolinfo->wolopts & WAKE_PHY)
2937 + opt |= AX_MONITOR_MODE_RWLC;
2938 + if (wolinfo->wolopts & WAKE_MAGIC)
2939 + opt |= AX_MONITOR_MODE_RWMP;
2941 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
2948 +static int ax88179_get_eeprom_len(struct net_device *net)
2950 + return AX_EEPROM_LEN;
2954 +ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
2957 + struct usbnet *dev = netdev_priv(net);
2959 + int first_word, last_word;
2962 + if (eeprom->len == 0)
2965 + eeprom->magic = AX88179_EEPROM_MAGIC;
2967 + first_word = eeprom->offset >> 1;
2968 + last_word = (eeprom->offset + eeprom->len - 1) >> 1;
2969 + eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
2974 + /* ax88179/178A returns 2 bytes from eeprom on read */
2975 + for (i = first_word; i <= last_word; i++) {
2976 + ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
2977 + &eeprom_buff[i - first_word],
2980 + kfree(eeprom_buff);
2985 + memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
2986 + kfree(eeprom_buff);
2990 +static int ax88179_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
2992 + struct usbnet *dev = netdev_priv(net);
2993 + return mii_ethtool_gset(&dev->mii, cmd);
2996 +static int ax88179_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
2998 + struct usbnet *dev = netdev_priv(net);
2999 + return mii_ethtool_sset(&dev->mii, cmd);
3003 +ax88179_ethtool_get_eee(struct usbnet *dev, struct ethtool_eee *data)
3007 + /* Get Supported EEE */
3008 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_PCS_EEE_ABLE,
3012 + data->supported = mmd_eee_cap_to_ethtool_sup_t(val);
3014 + /* Get advertisement EEE */
3015 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_ADV,
3019 + data->advertised = mmd_eee_adv_to_ethtool_adv_t(val);
3021 + /* Get LP advertisement EEE */
3022 + val = ax88179_phy_read_mmd_indirect(dev, MDIO_AN_EEE_LPABLE,
3026 + data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val);
3032 +ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data)
3034 + u16 tmp16 = ethtool_adv_to_mmd_eee_adv_t(data->advertised);
3036 + return ax88179_phy_write_mmd_indirect(dev, MDIO_AN_EEE_ADV,
3037 + MDIO_MMD_AN, tmp16);
3040 +static int ax88179_chk_eee(struct usbnet *dev)
3042 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
3043 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3045 + mii_ethtool_gset(&dev->mii, &ecmd);
3047 + if (ecmd.duplex & DUPLEX_FULL) {
3048 + int eee_lp, eee_cap, eee_adv;
3049 + u32 lp, cap, adv, supported = 0;
3051 + eee_cap = ax88179_phy_read_mmd_indirect(dev,
3052 + MDIO_PCS_EEE_ABLE,
3054 + if (eee_cap < 0) {
3055 + priv->eee_active = 0;
3059 + cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
3061 + priv->eee_active = 0;
3065 + eee_lp = ax88179_phy_read_mmd_indirect(dev,
3066 + MDIO_AN_EEE_LPABLE,
3069 + priv->eee_active = 0;
3073 + eee_adv = ax88179_phy_read_mmd_indirect(dev,
3077 + if (eee_adv < 0) {
3078 + priv->eee_active = 0;
3082 + adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
3083 + lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
3084 + supported = (ecmd.speed == SPEED_1000) ?
3085 + SUPPORTED_1000baseT_Full :
3086 + SUPPORTED_100baseT_Full;
3088 + if (!(lp & adv & supported)) {
3089 + priv->eee_active = 0;
3093 + priv->eee_active = 1;
3097 + priv->eee_active = 0;
3101 +static void ax88179_disable_eee(struct usbnet *dev)
3105 + tmp16 = GMII_PHY_PGSEL_PAGE3;
3106 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3107 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3110 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3111 + MII_PHYADDR, 2, &tmp16);
3113 + tmp16 = GMII_PHY_PGSEL_PAGE0;
3114 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3115 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3118 +static void ax88179_enable_eee(struct usbnet *dev)
3122 + tmp16 = GMII_PHY_PGSEL_PAGE3;
3123 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3124 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3127 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3128 + MII_PHYADDR, 2, &tmp16);
3130 + tmp16 = GMII_PHY_PGSEL_PAGE5;
3131 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3132 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3135 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3136 + MII_BMSR, 2, &tmp16);
3138 + tmp16 = GMII_PHY_PGSEL_PAGE0;
3139 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3140 + GMII_PHY_PAGE_SELECT, 2, &tmp16);
3143 +static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata)
3145 + struct usbnet *dev = netdev_priv(net);
3146 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3148 + edata->eee_enabled = priv->eee_enabled;
3149 + edata->eee_active = priv->eee_active;
3151 + return ax88179_ethtool_get_eee(dev, edata);
3154 +static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata)
3156 + struct usbnet *dev = netdev_priv(net);
3157 + struct ax88179_data *priv = (struct ax88179_data *)dev->data;
3158 + int ret = -EOPNOTSUPP;
3160 + priv->eee_enabled = edata->eee_enabled;
3161 + if (!priv->eee_enabled) {
3162 + ax88179_disable_eee(dev);
3164 + priv->eee_enabled = ax88179_chk_eee(dev);
3165 + if (!priv->eee_enabled)
3166 + return -EOPNOTSUPP;
3168 + ax88179_enable_eee(dev);
3171 + ret = ax88179_ethtool_set_eee(dev, edata);
3175 + mii_nway_restart(&dev->mii);
3177 + usbnet_link_change(dev, 0, 0);
3182 +static int ax88179_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
3184 + struct usbnet *dev = netdev_priv(net);
3185 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
3188 +static const struct ethtool_ops ax88179_ethtool_ops = {
3189 + .get_link = ethtool_op_get_link,
3190 + .get_msglevel = usbnet_get_msglevel,
3191 + .set_msglevel = usbnet_set_msglevel,
3192 + .get_wol = ax88179_get_wol,
3193 + .set_wol = ax88179_set_wol,
3194 + .get_eeprom_len = ax88179_get_eeprom_len,
3195 + .get_eeprom = ax88179_get_eeprom,
3196 + .get_settings = ax88179_get_settings,
3197 + .set_settings = ax88179_set_settings,
3198 + .get_eee = ax88179_get_eee,
3199 + .set_eee = ax88179_set_eee,
3200 + .nway_reset = usbnet_nway_reset,
3203 +static void ax88179_set_multicast(struct net_device *net)
3205 + struct usbnet *dev = netdev_priv(net);
3206 + struct ax88179_data *data = (struct ax88179_data *)dev->data;
3207 + u8 *m_filter = ((u8 *)dev->data) + 12;
3209 + data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
3211 + if (net->flags & IFF_PROMISC) {
3212 + data->rxctl |= AX_RX_CTL_PRO;
3213 + } else if (net->flags & IFF_ALLMULTI ||
3214 + netdev_mc_count(net) > AX_MAX_MCAST) {
3215 + data->rxctl |= AX_RX_CTL_AMALL;
3216 + } else if (netdev_mc_empty(net)) {
3217 + /* just broadcast and directed */
3219 + /* We use the 20 byte dev->data for our 8 byte filter buffer
3220 + * to avoid allocating memory that is tricky to free later
3223 + struct netdev_hw_addr *ha;
3225 + memset(m_filter, 0, AX_MCAST_FLTSIZE);
3227 + netdev_for_each_mc_addr(ha, net) {
3228 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
3229 + *(m_filter + (crc_bits >> 3)) |= (1 << (crc_bits & 7));
3232 + ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_MULFLTARY,
3233 + AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE,
3236 + data->rxctl |= AX_RX_CTL_AM;
3239 + ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
3240 + 2, 2, &data->rxctl);
3244 +ax88179_set_features(struct net_device *net, netdev_features_t features)
3247 + struct usbnet *dev = netdev_priv(net);
3248 + netdev_features_t changed = net->features ^ features;
3250 + if (changed & NETIF_F_IP_CSUM) {
3251 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3252 + tmp ^= AX_TXCOE_TCP | AX_TXCOE_UDP;
3253 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3256 + if (changed & NETIF_F_IPV6_CSUM) {
3257 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3258 + tmp ^= AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3259 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, &tmp);
3262 + if (changed & NETIF_F_RXCSUM) {
3263 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
3264 + tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3265 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3266 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
3272 +static int ax88179_change_mtu(struct net_device *net, int new_mtu)
3274 + struct usbnet *dev = netdev_priv(net);
3277 + if (new_mtu <= 0 || new_mtu > 4088)
3280 + net->mtu = new_mtu;
3281 + dev->hard_mtu = net->mtu + net->hard_header_len;
3283 + if (net->mtu > 1500) {
3284 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3286 + tmp16 |= AX_MEDIUM_JUMBO_EN;
3287 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3290 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3292 + tmp16 &= ~AX_MEDIUM_JUMBO_EN;
3293 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3297 + /* max qlen depend on hard_mtu and rx_urb_size */
3298 + usbnet_update_max_qlen(dev);
3303 +static int ax88179_set_mac_addr(struct net_device *net, void *p)
3305 + struct usbnet *dev = netdev_priv(net);
3306 + struct sockaddr *addr = p;
3309 + if (netif_running(net))
3311 + if (!is_valid_ether_addr(addr->sa_data))
3312 + return -EADDRNOTAVAIL;
3314 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
3316 + /* Set the MAC address */
3317 + ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
3318 + ETH_ALEN, net->dev_addr);
3325 +static const struct net_device_ops ax88179_netdev_ops = {
3326 + .ndo_open = usbnet_open,
3327 + .ndo_stop = usbnet_stop,
3328 + .ndo_start_xmit = usbnet_start_xmit,
3329 + .ndo_tx_timeout = usbnet_tx_timeout,
3330 + .ndo_change_mtu = ax88179_change_mtu,
3331 + .ndo_set_mac_address = ax88179_set_mac_addr,
3332 + .ndo_validate_addr = eth_validate_addr,
3333 + .ndo_do_ioctl = ax88179_ioctl,
3334 + .ndo_set_rx_mode = ax88179_set_multicast,
3335 + .ndo_set_features = ax88179_set_features,
3338 +static int ax88179_check_eeprom(struct usbnet *dev)
3340 + u8 i, buf, eeprom[20];
3341 + u16 csum, delay = HZ / 10;
3342 + unsigned long jtimeout;
3344 + /* Read EEPROM content */
3345 + for (i = 0; i < 6; i++) {
3347 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
3352 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3356 + jtimeout = jiffies + delay;
3358 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3361 + if (time_after(jiffies, jtimeout))
3364 + } while (buf & EEP_BUSY);
3366 + __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
3367 + 2, 2, &eeprom[i * 2], 0);
3369 + if ((i == 0) && (eeprom[0] == 0xFF))
3373 + csum = eeprom[6] + eeprom[7] + eeprom[8] + eeprom[9];
3374 + csum = (csum >> 8) + (csum & 0xff);
3375 + if ((csum + eeprom[10]) != 0xff)
3381 +static int ax88179_check_efuse(struct usbnet *dev, u16 *ledmode)
3387 + if (ax88179_read_cmd(dev, AX_ACCESS_EFUS, 0, 64, 64, efuse) < 0)
3390 + if (*efuse == 0xFF)
3393 + for (i = 0; i < 64; i++)
3394 + csum = csum + efuse[i];
3396 + while (csum > 255)
3397 + csum = (csum & 0x00FF) + ((csum >> 8) & 0x00FF);
3402 + *ledmode = (efuse[51] << 8) | efuse[52];
3407 +static int ax88179_convert_old_led(struct usbnet *dev, u16 *ledvalue)
3411 + /* Loaded the old eFuse LED Mode */
3412 + if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x3C, 1, 2, &led) < 0)
3418 + led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
3419 + LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
3420 + LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
3423 + led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 | LED_VALID;
3426 + led = LED0_ACTIVE | LED1_LINK_1000 | LED2_LINK_100 |
3427 + LED2_LINK_10 | LED_VALID;
3430 + led = LED0_ACTIVE | LED1_ACTIVE | LED1_LINK_1000 | LED2_ACTIVE |
3431 + LED2_LINK_100 | LED2_LINK_10 | LED_VALID;
3434 + led = LED0_ACTIVE | LED1_LINK_10 | LED1_LINK_100 |
3435 + LED1_LINK_1000 | LED2_ACTIVE | LED2_LINK_10 |
3436 + LED2_LINK_100 | LED2_LINK_1000 | LED_VALID;
3445 +static int ax88179_led_setting(struct usbnet *dev)
3447 + u8 ledfd, value = 0;
3448 + u16 tmp, ledact, ledlink, ledvalue = 0, delay = HZ / 10;
3449 + unsigned long jtimeout;
3451 + /* Check AX88179 version. UA1 or UA2*/
3452 + ax88179_read_cmd(dev, AX_ACCESS_MAC, GENERAL_STATUS, 1, 1, &value);
3454 + if (!(value & AX_SECLD)) { /* UA1 */
3455 + value = AX_GPIO_CTRL_GPIO3EN | AX_GPIO_CTRL_GPIO2EN |
3456 + AX_GPIO_CTRL_GPIO1EN;
3457 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_GPIO_CTRL,
3458 + 1, 1, &value) < 0)
3462 + /* Check EEPROM */
3463 + if (!ax88179_check_eeprom(dev)) {
3465 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_ADDR,
3466 + 1, 1, &value) < 0)
3470 + if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3471 + 1, 1, &value) < 0)
3474 + jtimeout = jiffies + delay;
3476 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_CMD,
3479 + if (time_after(jiffies, jtimeout))
3482 + } while (value & EEP_BUSY);
3484 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_HIGH,
3486 + ledvalue = (value << 8);
3488 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW,
3490 + ledvalue |= value;
3492 + /* load internal ROM for defaule setting */
3493 + if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
3494 + ax88179_convert_old_led(dev, &ledvalue);
3496 + } else if (!ax88179_check_efuse(dev, &ledvalue)) {
3497 + if ((ledvalue == 0xFFFF) || ((ledvalue & LED_VALID) == 0))
3498 + ax88179_convert_old_led(dev, &ledvalue);
3500 + ax88179_convert_old_led(dev, &ledvalue);
3503 + tmp = GMII_PHY_PGSEL_EXT;
3504 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3505 + GMII_PHY_PAGE_SELECT, 2, &tmp);
3508 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3509 + GMII_PHYPAGE, 2, &tmp);
3511 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3512 + GMII_LED_ACT, 2, &ledact);
3514 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3515 + GMII_LED_LINK, 2, &ledlink);
3517 + ledact &= GMII_LED_ACTIVE_MASK;
3518 + ledlink &= GMII_LED_LINK_MASK;
3520 + if (ledvalue & LED0_ACTIVE)
3521 + ledact |= GMII_LED0_ACTIVE;
3523 + if (ledvalue & LED1_ACTIVE)
3524 + ledact |= GMII_LED1_ACTIVE;
3526 + if (ledvalue & LED2_ACTIVE)
3527 + ledact |= GMII_LED2_ACTIVE;
3529 + if (ledvalue & LED0_LINK_10)
3530 + ledlink |= GMII_LED0_LINK_10;
3532 + if (ledvalue & LED1_LINK_10)
3533 + ledlink |= GMII_LED1_LINK_10;
3535 + if (ledvalue & LED2_LINK_10)
3536 + ledlink |= GMII_LED2_LINK_10;
3538 + if (ledvalue & LED0_LINK_100)
3539 + ledlink |= GMII_LED0_LINK_100;
3541 + if (ledvalue & LED1_LINK_100)
3542 + ledlink |= GMII_LED1_LINK_100;
3544 + if (ledvalue & LED2_LINK_100)
3545 + ledlink |= GMII_LED2_LINK_100;
3547 + if (ledvalue & LED0_LINK_1000)
3548 + ledlink |= GMII_LED0_LINK_1000;
3550 + if (ledvalue & LED1_LINK_1000)
3551 + ledlink |= GMII_LED1_LINK_1000;
3553 + if (ledvalue & LED2_LINK_1000)
3554 + ledlink |= GMII_LED2_LINK_1000;
3557 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3558 + GMII_LED_ACT, 2, &tmp);
3561 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3562 + GMII_LED_LINK, 2, &tmp);
3564 + tmp = GMII_PHY_PGSEL_PAGE0;
3565 + ax88179_write_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3566 + GMII_PHY_PAGE_SELECT, 2, &tmp);
3568 + /* LED full duplex setting */
3570 + if (ledvalue & LED0_FD)
3572 + else if ((ledvalue & LED0_USB3_MASK) == 0)
3575 + if (ledvalue & LED1_FD)
3577 + else if ((ledvalue & LED1_USB3_MASK) == 0)
3580 + if (ledvalue & LED2_FD)
3582 + else if ((ledvalue & LED2_USB3_MASK) == 0)
3585 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_LEDCTRL, 1, 1, &ledfd);
3590 +static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
3595 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3596 + struct ethtool_eee eee_data;
3598 + usbnet_get_endpoints(dev, intf);
3600 + tmp16 = (u16 *)buf;
3603 + memset(ax179_data, 0, sizeof(*ax179_data));
3605 + /* Power up ethernet PHY */
3607 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3608 + *tmp16 = AX_PHYPWR_RSTCTL_IPRL;
3609 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3612 + *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
3613 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
3616 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN,
3617 + ETH_ALEN, dev->net->dev_addr);
3618 + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
3620 + /* RX bulk configuration */
3621 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3622 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3624 + dev->rx_urb_size = 1024 * 20;
3627 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
3630 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
3633 + dev->net->netdev_ops = &ax88179_netdev_ops;
3634 + dev->net->ethtool_ops = &ax88179_ethtool_ops;
3635 + dev->net->needed_headroom = 8;
3637 + /* Initialize MII structure */
3638 + dev->mii.dev = dev->net;
3639 + dev->mii.mdio_read = ax88179_mdio_read;
3640 + dev->mii.mdio_write = ax88179_mdio_write;
3641 + dev->mii.phy_id_mask = 0xff;
3642 + dev->mii.reg_num_mask = 0xff;
3643 + dev->mii.phy_id = 0x03;
3644 + dev->mii.supports_gmii = 1;
3646 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3649 + dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3652 + /* Enable checksum offload */
3653 + *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3654 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3655 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
3657 + *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
3658 + AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3659 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
3661 + /* Configure RX control register => start operation */
3662 + *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
3663 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
3664 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
3666 + *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
3667 + AX_MONITOR_MODE_RWMP;
3668 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
3670 + /* Configure default medium type => giga */
3671 + *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3672 + AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
3673 + AX_MEDIUM_GIGAMODE;
3674 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3677 + ax88179_led_setting(dev);
3679 + ax179_data->eee_enabled = 0;
3680 + ax179_data->eee_active = 0;
3682 + ax88179_disable_eee(dev);
3684 + ax88179_ethtool_get_eee(dev, &eee_data);
3685 + eee_data.advertised = 0;
3686 + ax88179_ethtool_set_eee(dev, &eee_data);
3688 + /* Restart autoneg */
3689 + mii_nway_restart(&dev->mii);
3691 + usbnet_link_change(dev, 0, 0);
3696 +static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf)
3700 + /* Configure RX control register => stop operation */
3701 + tmp16 = AX_RX_CTL_STOP;
3702 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16);
3705 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp16);
3707 + /* Power down ethernet PHY */
3709 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16);
3713 +ax88179_rx_checksum(struct sk_buff *skb, u32 *pkt_hdr)
3715 + skb->ip_summed = CHECKSUM_NONE;
3717 + /* checksum error bit is set */
3718 + if ((*pkt_hdr & AX_RXHDR_L3CSUM_ERR) ||
3719 + (*pkt_hdr & AX_RXHDR_L4CSUM_ERR))
3722 + /* It must be a TCP or UDP packet with a valid checksum */
3723 + if (((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_TCP) ||
3724 + ((*pkt_hdr & AX_RXHDR_L4_TYPE_MASK) == AX_RXHDR_L4_TYPE_UDP))
3725 + skb->ip_summed = CHECKSUM_UNNECESSARY;
3728 +static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
3730 + struct sk_buff *ax_skb;
3736 + /* This check is no longer done by usbnet */
3737 + if (skb->len < dev->net->hard_header_len)
3740 + skb_trim(skb, skb->len - 4);
3741 + memcpy(&rx_hdr, skb_tail_pointer(skb), 4);
3742 + le32_to_cpus(&rx_hdr);
3744 + pkt_cnt = (u16)rx_hdr;
3745 + hdr_off = (u16)(rx_hdr >> 16);
3746 + pkt_hdr = (u32 *)(skb->data + hdr_off);
3748 + while (pkt_cnt--) {
3751 + le32_to_cpus(pkt_hdr);
3752 + pkt_len = (*pkt_hdr >> 16) & 0x1fff;
3754 + /* Check CRC or runt packet */
3755 + if ((*pkt_hdr & AX_RXHDR_CRC_ERR) ||
3756 + (*pkt_hdr & AX_RXHDR_DROP_ERR)) {
3757 + skb_pull(skb, (pkt_len + 7) & 0xFFF8);
3762 + if (pkt_cnt == 0) {
3763 + /* Skip IP alignment psudo header */
3765 + skb->len = pkt_len;
3766 + skb_set_tail_pointer(skb, pkt_len);
3767 + skb->truesize = pkt_len + sizeof(struct sk_buff);
3768 + ax88179_rx_checksum(skb, pkt_hdr);
3772 + ax_skb = skb_clone(skb, GFP_ATOMIC);
3774 + ax_skb->len = pkt_len;
3775 + ax_skb->data = skb->data + 2;
3776 + skb_set_tail_pointer(ax_skb, pkt_len);
3777 + ax_skb->truesize = pkt_len + sizeof(struct sk_buff);
3778 + ax88179_rx_checksum(ax_skb, pkt_hdr);
3779 + usbnet_skb_return(dev, ax_skb);
3784 + skb_pull(skb, (pkt_len + 7) & 0xFFF8);
3790 +static struct sk_buff *
3791 +ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
3793 + u32 tx_hdr1, tx_hdr2;
3794 + int frame_size = dev->maxpacket;
3795 + int mss = skb_shinfo(skb)->gso_size;
3798 + tx_hdr1 = skb->len;
3800 + if (((skb->len + 8) % frame_size) == 0)
3801 + tx_hdr2 |= 0x80008000; /* Enable padding */
3803 + headroom = skb_headroom(skb) - 8;
3805 + if ((skb_header_cloned(skb) || headroom < 0) &&
3806 + pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
3807 + dev_kfree_skb_any(skb);
3812 + cpu_to_le32s(&tx_hdr2);
3813 + skb_copy_to_linear_data(skb, &tx_hdr2, 4);
3816 + cpu_to_le32s(&tx_hdr1);
3817 + skb_copy_to_linear_data(skb, &tx_hdr1, 4);
3822 +static int ax88179_link_reset(struct usbnet *dev)
3824 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3825 + u8 tmp[5], link_sts;
3826 + u16 mode, tmp16, delay = HZ / 10;
3827 + u32 tmp32 = 0x40000000;
3828 + unsigned long jtimeout;
3830 + jtimeout = jiffies + delay;
3831 + while (tmp32 & 0x40000000) {
3833 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &mode);
3834 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2,
3835 + &ax179_data->rxctl);
3837 + /*link up, check the usb device control TX FIFO full or empty*/
3838 + ax88179_read_cmd(dev, 0x81, 0x8c, 0, 4, &tmp32);
3840 + if (time_after(jiffies, jtimeout))
3844 + mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3845 + AX_MEDIUM_RXFLOW_CTRLEN;
3847 + ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS,
3850 + ax88179_read_cmd(dev, AX_ACCESS_PHY, AX88179_PHY_ID,
3851 + GMII_PHY_PHYSR, 2, &tmp16);
3853 + if (!(tmp16 & GMII_PHY_PHYSR_LINK)) {
3855 + } else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
3856 + mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ;
3857 + if (dev->net->mtu > 1500)
3858 + mode |= AX_MEDIUM_JUMBO_EN;
3860 + if (link_sts & AX_USB_SS)
3861 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3862 + else if (link_sts & AX_USB_HS)
3863 + memcpy(tmp, &AX88179_BULKIN_SIZE[1], 5);
3865 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3866 + } else if (GMII_PHY_PHYSR_100 == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
3867 + mode |= AX_MEDIUM_PS;
3869 + if (link_sts & (AX_USB_SS | AX_USB_HS))
3870 + memcpy(tmp, &AX88179_BULKIN_SIZE[2], 5);
3872 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3874 + memcpy(tmp, &AX88179_BULKIN_SIZE[3], 5);
3877 + /* RX bulk configuration */
3878 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3880 + dev->rx_urb_size = (1024 * (tmp[3] + 2));
3882 + if (tmp16 & GMII_PHY_PHYSR_FULL)
3883 + mode |= AX_MEDIUM_FULL_DUPLEX;
3884 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3887 + ax179_data->eee_enabled = ax88179_chk_eee(dev);
3889 + netif_carrier_on(dev->net);
3894 +static int ax88179_reset(struct usbnet *dev)
3899 + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data;
3900 + struct ethtool_eee eee_data;
3902 + tmp16 = (u16 *)buf;
3905 + /* Power up ethernet PHY */
3907 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3909 + *tmp16 = AX_PHYPWR_RSTCTL_IPRL;
3910 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16);
3913 + *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS;
3914 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp);
3917 + /* Ethernet PHY Auto Detach*/
3918 + ax88179_auto_detach(dev, 0);
3920 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN,
3921 + dev->net->dev_addr);
3922 + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
3924 + /* RX bulk configuration */
3925 + memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5);
3926 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp);
3928 + dev->rx_urb_size = 1024 * 20;
3931 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp);
3934 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH,
3937 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3940 + dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3943 + /* Enable checksum offload */
3944 + *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
3945 + AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
3946 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp);
3948 + *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP |
3949 + AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
3950 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp);
3952 + /* Configure RX control register => start operation */
3953 + *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
3954 + AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
3955 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);
3957 + *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |
3958 + AX_MONITOR_MODE_RWMP;
3959 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
3961 + /* Configure default medium type => giga */
3962 + *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
3963 + AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
3964 + AX_MEDIUM_GIGAMODE;
3965 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3968 + ax88179_led_setting(dev);
3970 + ax179_data->eee_enabled = 0;
3971 + ax179_data->eee_active = 0;
3973 + ax88179_disable_eee(dev);
3975 + ax88179_ethtool_get_eee(dev, &eee_data);
3976 + eee_data.advertised = 0;
3977 + ax88179_ethtool_set_eee(dev, &eee_data);
3979 + /* Restart autoneg */
3980 + mii_nway_restart(&dev->mii);
3982 + usbnet_link_change(dev, 0, 0);
3987 +static int ax88179_stop(struct usbnet *dev)
3991 + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
3993 + tmp16 &= ~AX_MEDIUM_RECEIVE_EN;
3994 + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
4000 +static const struct driver_info ax88179_info = {
4001 + .description = "ASIX AX88179 USB 3.0 Gigabit Ethernet",
4002 + .bind = ax88179_bind,
4003 + .unbind = ax88179_unbind,
4004 + .status = ax88179_status,
4005 + .link_reset = ax88179_link_reset,
4006 + .reset = ax88179_reset,
4007 + .stop = ax88179_stop,
4008 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4009 + .rx_fixup = ax88179_rx_fixup,
4010 + .tx_fixup = ax88179_tx_fixup,
4013 +static const struct driver_info ax88178a_info = {
4014 + .description = "ASIX AX88178A USB 2.0 Gigabit Ethernet",
4015 + .bind = ax88179_bind,
4016 + .unbind = ax88179_unbind,
4017 + .status = ax88179_status,
4018 + .link_reset = ax88179_link_reset,
4019 + .reset = ax88179_reset,
4020 + .stop = ax88179_stop,
4021 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4022 + .rx_fixup = ax88179_rx_fixup,
4023 + .tx_fixup = ax88179_tx_fixup,
4026 +static const struct driver_info dlink_dub1312_info = {
4027 + .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
4028 + .bind = ax88179_bind,
4029 + .unbind = ax88179_unbind,
4030 + .status = ax88179_status,
4031 + .link_reset = ax88179_link_reset,
4032 + .reset = ax88179_reset,
4033 + .stop = ax88179_stop,
4034 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4035 + .rx_fixup = ax88179_rx_fixup,
4036 + .tx_fixup = ax88179_tx_fixup,
4039 +static const struct driver_info sitecom_info = {
4040 + .description = "Sitecom USB 3.0 to Gigabit Adapter",
4041 + .bind = ax88179_bind,
4042 + .unbind = ax88179_unbind,
4043 + .status = ax88179_status,
4044 + .link_reset = ax88179_link_reset,
4045 + .reset = ax88179_reset,
4046 + .stop = ax88179_stop,
4047 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4048 + .rx_fixup = ax88179_rx_fixup,
4049 + .tx_fixup = ax88179_tx_fixup,
4052 +static const struct driver_info samsung_info = {
4053 + .description = "Samsung USB Ethernet Adapter",
4054 + .bind = ax88179_bind,
4055 + .unbind = ax88179_unbind,
4056 + .status = ax88179_status,
4057 + .link_reset = ax88179_link_reset,
4058 + .reset = ax88179_reset,
4059 + .stop = ax88179_stop,
4060 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4061 + .rx_fixup = ax88179_rx_fixup,
4062 + .tx_fixup = ax88179_tx_fixup,
4065 +static const struct driver_info lenovo_info = {
4066 + .description = "Lenovo OneLinkDock Gigabit LAN",
4067 + .bind = ax88179_bind,
4068 + .unbind = ax88179_unbind,
4069 + .status = ax88179_status,
4070 + .link_reset = ax88179_link_reset,
4071 + .reset = ax88179_reset,
4072 + .stop = ax88179_stop,
4073 + .flags = FLAG_ETHER | FLAG_FRAMING_AX,
4074 + .rx_fixup = ax88179_rx_fixup,
4075 + .tx_fixup = ax88179_tx_fixup,
4078 +static const struct usb_device_id products[] = {
4080 + /* ASIX AX88179 10/100/1000 */
4081 + USB_DEVICE(0x0b95, 0x1790),
4082 + .driver_info = (unsigned long)&ax88179_info,
4084 + /* ASIX AX88178A 10/100/1000 */
4085 + USB_DEVICE(0x0b95, 0x178a),
4086 + .driver_info = (unsigned long)&ax88178a_info,
4088 + /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
4089 + USB_DEVICE(0x2001, 0x4a00),
4090 + .driver_info = (unsigned long)&dlink_dub1312_info,
4092 + /* Sitecom USB 3.0 to Gigabit Adapter */
4093 + USB_DEVICE(0x0df6, 0x0072),
4094 + .driver_info = (unsigned long)&sitecom_info,
4096 + /* Samsung USB Ethernet Adapter */
4097 + USB_DEVICE(0x04e8, 0xa100),
4098 + .driver_info = (unsigned long)&samsung_info,
4100 + /* Lenovo OneLinkDock Gigabit LAN */
4101 + USB_DEVICE(0x17ef, 0x304b),
4102 + .driver_info = (unsigned long)&lenovo_info,
4106 +MODULE_DEVICE_TABLE(usb, products);
4108 +static struct usb_driver ax88179_178a_driver = {
4109 + .name = "ax88179_178a",
4110 + .id_table = products,
4111 + .probe = usbnet_probe,
4112 + .suspend = ax88179_suspend,
4113 + .resume = ax88179_resume,
4114 + .reset_resume = ax88179_resume,
4115 + .disconnect = usbnet_disconnect,
4116 + .supports_autosuspend = 1,
4117 + .disable_hub_initiated_lpm = 1,
4120 +module_usb_driver(ax88179_178a_driver);
4122 +MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices");
4123 +MODULE_LICENSE("GPL");
4124 diff -Naur backports-4.2.6-1.org/drivers/net/usb/catc.c backports-4.2.6-1/drivers/net/usb/catc.c
4125 --- backports-4.2.6-1.org/drivers/net/usb/catc.c 1970-01-01 01:00:00.000000000 +0100
4126 +++ backports-4.2.6-1/drivers/net/usb/catc.c 2016-06-28 14:35:17.975307221 +0200
4129 + * Copyright (c) 2001 Vojtech Pavlik
4131 + * CATC EL1210A NetMate USB Ethernet driver
4133 + * Sponsored by SuSE
4135 + * Based on the work of
4138 + * Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
4139 + * - adds support for Belkin F5U011
4143 + * This program is free software; you can redistribute it and/or modify
4144 + * it under the terms of the GNU General Public License as published by
4145 + * the Free Software Foundation; either version 2 of the License, or
4146 + * (at your option) any later version.
4148 + * This program is distributed in the hope that it will be useful,
4149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4151 + * GNU General Public License for more details.
4153 + * You should have received a copy of the GNU General Public License
4154 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
4156 + * Should you need to contact me, the author, you can do so either by
4157 + * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
4158 + * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
4161 +#include <linux/module.h>
4162 +#include <linux/kernel.h>
4163 +#include <linux/string.h>
4164 +#include <linux/netdevice.h>
4165 +#include <linux/etherdevice.h>
4166 +#include <linux/skbuff.h>
4167 +#include <linux/spinlock.h>
4168 +#include <linux/ethtool.h>
4169 +#include <linux/crc32.h>
4170 +#include <linux/bitops.h>
4171 +#include <linux/gfp.h>
4172 +#include <asm/uaccess.h>
4176 +#include <linux/usb.h>
4179 + * Version information.
4182 +#define DRIVER_VERSION "v2.8"
4183 +#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
4184 +#define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
4185 +#define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
4187 +MODULE_AUTHOR(DRIVER_AUTHOR);
4188 +MODULE_DESCRIPTION(DRIVER_DESC);
4189 +MODULE_LICENSE("GPL");
4191 +static const char driver_name[] = "catc";
4197 +#define STATS_UPDATE (HZ) /* Time between stats updates */
4198 +#define TX_TIMEOUT (5*HZ) /* Max time the queue can be stopped */
4199 +#define PKT_SZ 1536 /* Max Ethernet packet size */
4200 +#define RX_MAX_BURST 15 /* Max packets per rx buffer (> 0, < 16) */
4201 +#define TX_MAX_BURST 15 /* Max full sized packets per tx buffer (> 0) */
4202 +#define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
4203 +#define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
4206 + * Control requests.
4209 +enum control_requests {
4214 + SetRxMode = 0xf5, /* F5U011 only */
4226 +enum register_offsets {
4227 + TxBufCount = 0x20,
4228 + RxBufCount = 0x21,
4235 + StationAddr0 = 0x67,
4241 + TxSingleColl = 0x00,
4242 + TxMultiColl = 0x02,
4243 + TxExcessColl = 0x04,
4247 +enum op_mode_bits {
4248 + Op3MemWaits = 0x03,
4249 + OpLenInclude = 0x08,
4252 + OpWin95bugfix = 0x40,
4253 + OpLoopback = 0x80,
4256 +enum rx_filter_bits {
4258 + RxPolarity = 0x02,
4260 + RxMultiCast = 0x08,
4262 + AltRxPromisc = 0x20, /* F5U011 uses different bit */
4280 + * The catc struct.
4283 +#define CTRL_RUNNING 0
4284 +#define RX_RUNNING 1
4285 +#define TX_RUNNING 2
4288 + struct net_device *netdev;
4289 + struct usb_device *usbdev;
4291 + unsigned long flags;
4293 + unsigned int tx_ptr, tx_idx;
4294 + unsigned int ctrl_head, ctrl_tail;
4295 + spinlock_t tx_lock, ctrl_lock;
4297 + u8 tx_buf[2][TX_MAX_BURST * (PKT_SZ + 2)];
4298 + u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
4301 + struct usb_ctrlrequest ctrl_dr;
4303 + struct timer_list timer;
4305 + u16 stats_vals[4];
4306 + unsigned long last_stats;
4310 + struct ctrl_queue {
4317 + void (*callback)(struct catc *catc, struct ctrl_queue *q);
4318 + } ctrl_queue[CTRL_QUEUE];
4320 + struct urb *tx_urb, *rx_urb, *irq_urb, *ctrl_urb;
4322 + u8 is_f5u011; /* Set if device is an F5U011 */
4323 + u8 rxmode[2]; /* Used for F5U011 */
4324 + atomic_t recq_sz; /* Used for F5U011 - counter of waiting rx packets */
4331 +#define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
4332 +#define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
4333 +#define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
4334 +#define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
4335 +#define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
4336 +#define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
4338 +#define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
4339 +#define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
4340 +#define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
4342 +#define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
4343 +#define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
4344 +#define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
4347 + * Receive routines.
4350 +static void catc_rx_done(struct urb *urb)
4352 + struct catc *catc = urb->context;
4353 + u8 *pkt_start = urb->transfer_buffer;
4354 + struct sk_buff *skb;
4355 + int pkt_len, pkt_offset = 0;
4356 + int status = urb->status;
4358 + if (!catc->is_f5u011) {
4359 + clear_bit(RX_RUNNING, &catc->flags);
4364 + dev_dbg(&urb->dev->dev, "rx_done, status %d, length %d\n",
4365 + status, urb->actual_length);
4370 + if(!catc->is_f5u011) {
4371 + pkt_len = le16_to_cpup((__le16*)pkt_start);
4372 + if (pkt_len > urb->actual_length) {
4373 + catc->netdev->stats.rx_length_errors++;
4374 + catc->netdev->stats.rx_errors++;
4378 + pkt_len = urb->actual_length;
4381 + if (!(skb = dev_alloc_skb(pkt_len)))
4384 + skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
4385 + skb_put(skb, pkt_len);
4387 + skb->protocol = eth_type_trans(skb, catc->netdev);
4390 + catc->netdev->stats.rx_packets++;
4391 + catc->netdev->stats.rx_bytes += pkt_len;
4393 + /* F5U011 only does one packet per RX */
4394 + if (catc->is_f5u011)
4396 + pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
4398 + } while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
4400 + if (catc->is_f5u011) {
4401 + if (atomic_read(&catc->recq_sz)) {
4403 + atomic_dec(&catc->recq_sz);
4404 + netdev_dbg(catc->netdev, "getting extra packet\n");
4405 + urb->dev = catc->usbdev;
4406 + if ((state = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
4407 + netdev_dbg(catc->netdev,
4408 + "submit(rx_urb) status %d\n", state);
4411 + clear_bit(RX_RUNNING, &catc->flags);
4416 +static void catc_irq_done(struct urb *urb)
4418 + struct catc *catc = urb->context;
4419 + u8 *data = urb->transfer_buffer;
4420 + int status = urb->status;
4421 + unsigned int hasdata = 0, linksts = LinkNoChange;
4424 + if (!catc->is_f5u011) {
4425 + hasdata = data[1] & 0x80;
4426 + if (data[1] & 0x40)
4427 + linksts = LinkGood;
4428 + else if (data[1] & 0x20)
4429 + linksts = LinkBad;
4431 + hasdata = (unsigned int)(be16_to_cpup((__be16*)data) & 0x0fff);
4432 + if (data[0] == 0x90)
4433 + linksts = LinkGood;
4434 + else if (data[0] == 0xA0)
4435 + linksts = LinkBad;
4439 + case 0: /* success */
4441 + case -ECONNRESET: /* unlink */
4445 + /* -EPIPE: should clear the halt */
4446 + default: /* error */
4447 + dev_dbg(&urb->dev->dev,
4448 + "irq_done, status %d, data %02x %02x.\n",
4449 + status, data[0], data[1]);
4453 + if (linksts == LinkGood) {
4454 + netif_carrier_on(catc->netdev);
4455 + netdev_dbg(catc->netdev, "link ok\n");
4458 + if (linksts == LinkBad) {
4459 + netif_carrier_off(catc->netdev);
4460 + netdev_dbg(catc->netdev, "link bad\n");
4464 + if (test_and_set_bit(RX_RUNNING, &catc->flags)) {
4465 + if (catc->is_f5u011)
4466 + atomic_inc(&catc->recq_sz);
4468 + catc->rx_urb->dev = catc->usbdev;
4469 + if ((res = usb_submit_urb(catc->rx_urb, GFP_ATOMIC)) < 0) {
4470 + dev_err(&catc->usbdev->dev,
4471 + "submit(rx_urb) status %d\n", res);
4476 + res = usb_submit_urb (urb, GFP_ATOMIC);
4478 + dev_err(&catc->usbdev->dev,
4479 + "can't resubmit intr, %s-%s, status %d\n",
4480 + catc->usbdev->bus->bus_name,
4481 + catc->usbdev->devpath, res);
4485 + * Transmit routines.
4488 +static int catc_tx_run(struct catc *catc)
4492 + if (catc->is_f5u011)
4493 + catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
4495 + catc->tx_urb->transfer_buffer_length = catc->tx_ptr;
4496 + catc->tx_urb->transfer_buffer = catc->tx_buf[catc->tx_idx];
4497 + catc->tx_urb->dev = catc->usbdev;
4499 + if ((status = usb_submit_urb(catc->tx_urb, GFP_ATOMIC)) < 0)
4500 + dev_err(&catc->usbdev->dev, "submit(tx_urb), status %d\n",
4503 + catc->tx_idx = !catc->tx_idx;
4506 + catc->netdev->trans_start = jiffies;
4510 +static void catc_tx_done(struct urb *urb)
4512 + struct catc *catc = urb->context;
4513 + unsigned long flags;
4514 + int r, status = urb->status;
4516 + if (status == -ECONNRESET) {
4517 + dev_dbg(&urb->dev->dev, "Tx Reset.\n");
4519 + catc->netdev->trans_start = jiffies;
4520 + catc->netdev->stats.tx_errors++;
4521 + clear_bit(TX_RUNNING, &catc->flags);
4522 + netif_wake_queue(catc->netdev);
4527 + dev_dbg(&urb->dev->dev, "tx_done, status %d, length %d\n",
4528 + status, urb->actual_length);
4532 + spin_lock_irqsave(&catc->tx_lock, flags);
4534 + if (catc->tx_ptr) {
4535 + r = catc_tx_run(catc);
4536 + if (unlikely(r < 0))
4537 + clear_bit(TX_RUNNING, &catc->flags);
4539 + clear_bit(TX_RUNNING, &catc->flags);
4542 + netif_wake_queue(catc->netdev);
4544 + spin_unlock_irqrestore(&catc->tx_lock, flags);
4547 +static netdev_tx_t catc_start_xmit(struct sk_buff *skb,
4548 + struct net_device *netdev)
4550 + struct catc *catc = netdev_priv(netdev);
4551 + unsigned long flags;
4555 + spin_lock_irqsave(&catc->tx_lock, flags);
4557 + catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
4558 + tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
4559 + if (catc->is_f5u011)
4560 + *(__be16 *)tx_buf = cpu_to_be16(skb->len);
4562 + *(__le16 *)tx_buf = cpu_to_le16(skb->len);
4563 + skb_copy_from_linear_data(skb, tx_buf + 2, skb->len);
4564 + catc->tx_ptr += skb->len + 2;
4566 + if (!test_and_set_bit(TX_RUNNING, &catc->flags)) {
4567 + r = catc_tx_run(catc);
4569 + clear_bit(TX_RUNNING, &catc->flags);
4572 + if ((catc->is_f5u011 && catc->tx_ptr) ||
4573 + (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2))))
4574 + netif_stop_queue(netdev);
4576 + spin_unlock_irqrestore(&catc->tx_lock, flags);
4579 + catc->netdev->stats.tx_bytes += skb->len;
4580 + catc->netdev->stats.tx_packets++;
4583 + dev_kfree_skb(skb);
4585 + return NETDEV_TX_OK;
4588 +static void catc_tx_timeout(struct net_device *netdev)
4590 + struct catc *catc = netdev_priv(netdev);
4592 + dev_warn(&netdev->dev, "Transmit timed out.\n");
4593 + usb_unlink_urb(catc->tx_urb);
4597 + * Control messages.
4600 +static int catc_ctrl_msg(struct catc *catc, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
4602 + int retval = usb_control_msg(catc->usbdev,
4603 + dir ? usb_rcvctrlpipe(catc->usbdev, 0) : usb_sndctrlpipe(catc->usbdev, 0),
4604 + request, 0x40 | dir, value, index, buf, len, 1000);
4605 + return retval < 0 ? retval : 0;
4608 +static void catc_ctrl_run(struct catc *catc)
4610 + struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
4611 + struct usb_device *usbdev = catc->usbdev;
4612 + struct urb *urb = catc->ctrl_urb;
4613 + struct usb_ctrlrequest *dr = &catc->ctrl_dr;
4616 + dr->bRequest = q->request;
4617 + dr->bRequestType = 0x40 | q->dir;
4618 + dr->wValue = cpu_to_le16(q->value);
4619 + dr->wIndex = cpu_to_le16(q->index);
4620 + dr->wLength = cpu_to_le16(q->len);
4622 + urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
4623 + urb->transfer_buffer_length = q->len;
4624 + urb->transfer_buffer = catc->ctrl_buf;
4625 + urb->setup_packet = (void *) dr;
4626 + urb->dev = usbdev;
4628 + if (!q->dir && q->buf && q->len)
4629 + memcpy(catc->ctrl_buf, q->buf, q->len);
4631 + if ((status = usb_submit_urb(catc->ctrl_urb, GFP_ATOMIC)))
4632 + dev_err(&catc->usbdev->dev, "submit(ctrl_urb) status %d\n",
4636 +static void catc_ctrl_done(struct urb *urb)
4638 + struct catc *catc = urb->context;
4639 + struct ctrl_queue *q;
4640 + unsigned long flags;
4641 + int status = urb->status;
4644 + dev_dbg(&urb->dev->dev, "ctrl_done, status %d, len %d.\n",
4645 + status, urb->actual_length);
4647 + spin_lock_irqsave(&catc->ctrl_lock, flags);
4649 + q = catc->ctrl_queue + catc->ctrl_tail;
4652 + if (q->buf && q->len)
4653 + memcpy(q->buf, catc->ctrl_buf, q->len);
4655 + q->buf = catc->ctrl_buf;
4659 + q->callback(catc, q);
4661 + catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
4663 + if (catc->ctrl_head != catc->ctrl_tail)
4664 + catc_ctrl_run(catc);
4666 + clear_bit(CTRL_RUNNING, &catc->flags);
4668 + spin_unlock_irqrestore(&catc->ctrl_lock, flags);
4671 +static int catc_ctrl_async(struct catc *catc, u8 dir, u8 request, u16 value,
4672 + u16 index, void *buf, int len, void (*callback)(struct catc *catc, struct ctrl_queue *q))
4674 + struct ctrl_queue *q;
4676 + unsigned long flags;
4678 + spin_lock_irqsave(&catc->ctrl_lock, flags);
4680 + q = catc->ctrl_queue + catc->ctrl_head;
4683 + q->request = request;
4688 + q->callback = callback;
4690 + catc->ctrl_head = (catc->ctrl_head + 1) & (CTRL_QUEUE - 1);
4692 + if (catc->ctrl_head == catc->ctrl_tail) {
4693 + dev_err(&catc->usbdev->dev, "ctrl queue full\n");
4694 + catc->ctrl_tail = (catc->ctrl_tail + 1) & (CTRL_QUEUE - 1);
4698 + if (!test_and_set_bit(CTRL_RUNNING, &catc->flags))
4699 + catc_ctrl_run(catc);
4701 + spin_unlock_irqrestore(&catc->ctrl_lock, flags);
4710 +static void catc_stats_done(struct catc *catc, struct ctrl_queue *q)
4712 + int index = q->index - EthStats;
4715 + catc->stats_buf[index] = *((char *)q->buf);
4720 + data = ((u16)catc->stats_buf[index] << 8) | catc->stats_buf[index + 1];
4721 + last = catc->stats_vals[index >> 1];
4724 + case TxSingleColl:
4726 + catc->netdev->stats.collisions += data - last;
4728 + case TxExcessColl:
4729 + catc->netdev->stats.tx_aborted_errors += data - last;
4730 + catc->netdev->stats.tx_errors += data - last;
4733 + catc->netdev->stats.rx_frame_errors += data - last;
4734 + catc->netdev->stats.rx_errors += data - last;
4738 + catc->stats_vals[index >> 1] = data;
4741 +static void catc_stats_timer(unsigned long data)
4743 + struct catc *catc = (void *) data;
4746 + for (i = 0; i < 8; i++)
4747 + catc_get_reg_async(catc, EthStats + 7 - i, catc_stats_done);
4749 + mod_timer(&catc->timer, jiffies + STATS_UPDATE);
4753 + * Receive modes. Broadcast, Multicast, Promisc.
4756 +static void catc_multicast(unsigned char *addr, u8 *multicast)
4760 + crc = ether_crc_le(6, addr);
4761 + multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
4764 +static void catc_set_multicast_list(struct net_device *netdev)
4766 + struct catc *catc = netdev_priv(netdev);
4767 + struct netdev_hw_addr *ha;
4768 + u8 broadcast[ETH_ALEN];
4769 + u8 rx = RxEnable | RxPolarity | RxMultiCast;
4771 + eth_broadcast_addr(broadcast);
4772 + memset(catc->multicast, 0, 64);
4774 + catc_multicast(broadcast, catc->multicast);
4775 + catc_multicast(netdev->dev_addr, catc->multicast);
4777 + if (netdev->flags & IFF_PROMISC) {
4778 + memset(catc->multicast, 0xff, 64);
4779 + rx |= (!catc->is_f5u011) ? RxPromisc : AltRxPromisc;
4782 + if (netdev->flags & IFF_ALLMULTI) {
4783 + memset(catc->multicast, 0xff, 64);
4785 + netdev_for_each_mc_addr(ha, netdev) {
4786 + u32 crc = ether_crc_le(6, ha->addr);
4787 + if (!catc->is_f5u011) {
4788 + catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
4790 + catc->multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
4794 + if (!catc->is_f5u011) {
4795 + catc_set_reg_async(catc, RxUnit, rx);
4796 + catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
4798 + f5u011_mchash_async(catc, catc->multicast);
4799 + if (catc->rxmode[0] != rx) {
4800 + catc->rxmode[0] = rx;
4801 + netdev_dbg(catc->netdev,
4802 + "Setting RX mode to %2.2X %2.2X\n",
4803 + catc->rxmode[0], catc->rxmode[1]);
4804 + f5u011_rxmode_async(catc, catc->rxmode);
4809 +static void catc_get_drvinfo(struct net_device *dev,
4810 + struct ethtool_drvinfo *info)
4812 + struct catc *catc = netdev_priv(dev);
4813 + strlcpy(info->driver, driver_name, sizeof(info->driver));
4814 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
4815 + usb_make_path(catc->usbdev, info->bus_info, sizeof(info->bus_info));
4818 +static int catc_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
4820 + struct catc *catc = netdev_priv(dev);
4821 + if (!catc->is_f5u011)
4822 + return -EOPNOTSUPP;
4824 + cmd->supported = SUPPORTED_10baseT_Half | SUPPORTED_TP;
4825 + cmd->advertising = ADVERTISED_10baseT_Half | ADVERTISED_TP;
4826 + ethtool_cmd_speed_set(cmd, SPEED_10);
4827 + cmd->duplex = DUPLEX_HALF;
4828 + cmd->port = PORT_TP;
4829 + cmd->phy_address = 0;
4830 + cmd->transceiver = XCVR_INTERNAL;
4831 + cmd->autoneg = AUTONEG_DISABLE;
4832 + cmd->maxtxpkt = 1;
4833 + cmd->maxrxpkt = 1;
4837 +static const struct ethtool_ops ops = {
4838 + .get_drvinfo = catc_get_drvinfo,
4839 + .get_settings = catc_get_settings,
4840 + .get_link = ethtool_op_get_link
4847 +static int catc_open(struct net_device *netdev)
4849 + struct catc *catc = netdev_priv(netdev);
4852 + catc->irq_urb->dev = catc->usbdev;
4853 + if ((status = usb_submit_urb(catc->irq_urb, GFP_KERNEL)) < 0) {
4854 + dev_err(&catc->usbdev->dev, "submit(irq_urb) status %d\n",
4859 + netif_start_queue(netdev);
4861 + if (!catc->is_f5u011)
4862 + mod_timer(&catc->timer, jiffies + STATS_UPDATE);
4867 +static int catc_stop(struct net_device *netdev)
4869 + struct catc *catc = netdev_priv(netdev);
4871 + netif_stop_queue(netdev);
4873 + if (!catc->is_f5u011)
4874 + del_timer_sync(&catc->timer);
4876 + usb_kill_urb(catc->rx_urb);
4877 + usb_kill_urb(catc->tx_urb);
4878 + usb_kill_urb(catc->irq_urb);
4879 + usb_kill_urb(catc->ctrl_urb);
4884 +static const struct net_device_ops catc_netdev_ops = {
4885 + .ndo_open = catc_open,
4886 + .ndo_stop = catc_stop,
4887 + .ndo_start_xmit = catc_start_xmit,
4889 + .ndo_tx_timeout = catc_tx_timeout,
4890 + .ndo_set_rx_mode = catc_set_multicast_list,
4891 + .ndo_change_mtu = eth_change_mtu,
4892 + .ndo_set_mac_address = eth_mac_addr,
4893 + .ndo_validate_addr = eth_validate_addr,
4897 + * USB probe, disconnect.
4900 +static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
4902 + struct device *dev = &intf->dev;
4903 + struct usb_device *usbdev = interface_to_usbdev(intf);
4904 + struct net_device *netdev;
4905 + struct catc *catc;
4906 + u8 broadcast[ETH_ALEN];
4909 + if (usb_set_interface(usbdev,
4910 + intf->altsetting->desc.bInterfaceNumber, 1)) {
4911 + dev_err(dev, "Can't set altsetting 1.\n");
4915 + netdev = alloc_etherdev(sizeof(struct catc));
4919 + catc = netdev_priv(netdev);
4921 + netdev->netdev_ops = &catc_netdev_ops;
4922 + netdev->watchdog_timeo = TX_TIMEOUT;
4923 + netdev->ethtool_ops = &ops;
4925 + catc->usbdev = usbdev;
4926 + catc->netdev = netdev;
4928 + spin_lock_init(&catc->tx_lock);
4929 + spin_lock_init(&catc->ctrl_lock);
4931 + init_timer(&catc->timer);
4932 + catc->timer.data = (long) catc;
4933 + catc->timer.function = catc_stats_timer;
4935 + catc->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
4936 + catc->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
4937 + catc->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
4938 + catc->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
4939 + if ((!catc->ctrl_urb) || (!catc->tx_urb) ||
4940 + (!catc->rx_urb) || (!catc->irq_urb)) {
4941 + dev_err(&intf->dev, "No free urbs available.\n");
4942 + usb_free_urb(catc->ctrl_urb);
4943 + usb_free_urb(catc->tx_urb);
4944 + usb_free_urb(catc->rx_urb);
4945 + usb_free_urb(catc->irq_urb);
4946 + free_netdev(netdev);
4950 + /* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
4951 + if (le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
4952 + le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
4953 + le16_to_cpu(catc->usbdev->descriptor.bcdDevice) == 0x0130) {
4954 + dev_dbg(dev, "Testing for f5u011\n");
4955 + catc->is_f5u011 = 1;
4956 + atomic_set(&catc->recq_sz, 0);
4957 + pktsz = RX_PKT_SZ;
4959 + pktsz = RX_MAX_BURST * (PKT_SZ + 2);
4962 + usb_fill_control_urb(catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
4963 + NULL, NULL, 0, catc_ctrl_done, catc);
4965 + usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
4966 + NULL, 0, catc_tx_done, catc);
4968 + usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
4969 + catc->rx_buf, pktsz, catc_rx_done, catc);
4971 + usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
4972 + catc->irq_buf, 2, catc_irq_done, catc, 1);
4974 + if (!catc->is_f5u011) {
4975 + dev_dbg(dev, "Checking memory size\n");
4978 + catc_write_mem(catc, 0x7a80, &i, 4);
4980 + catc_write_mem(catc, 0xfa80, &i, 4);
4981 + catc_read_mem(catc, 0x7a80, &i, 4);
4985 + catc_set_reg(catc, TxBufCount, 8);
4986 + catc_set_reg(catc, RxBufCount, 32);
4987 + dev_dbg(dev, "64k Memory\n");
4990 + dev_warn(&intf->dev,
4991 + "Couldn't detect memory size, assuming 32k\n");
4993 + catc_set_reg(catc, TxBufCount, 4);
4994 + catc_set_reg(catc, RxBufCount, 16);
4995 + dev_dbg(dev, "32k Memory\n");
4999 + dev_dbg(dev, "Getting MAC from SEEROM.\n");
5001 + catc_get_mac(catc, netdev->dev_addr);
5003 + dev_dbg(dev, "Setting MAC into registers.\n");
5005 + for (i = 0; i < 6; i++)
5006 + catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
5008 + dev_dbg(dev, "Filling the multicast list.\n");
5010 + eth_broadcast_addr(broadcast);
5011 + catc_multicast(broadcast, catc->multicast);
5012 + catc_multicast(netdev->dev_addr, catc->multicast);
5013 + catc_write_mem(catc, 0xfa80, catc->multicast, 64);
5015 + dev_dbg(dev, "Clearing error counters.\n");
5017 + for (i = 0; i < 8; i++)
5018 + catc_set_reg(catc, EthStats + i, 0);
5019 + catc->last_stats = jiffies;
5021 + dev_dbg(dev, "Enabling.\n");
5023 + catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
5024 + catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
5025 + catc_set_reg(catc, LEDCtrl, LEDLink);
5026 + catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
5028 + dev_dbg(dev, "Performing reset\n");
5030 + catc_get_mac(catc, netdev->dev_addr);
5032 + dev_dbg(dev, "Setting RX Mode\n");
5033 + catc->rxmode[0] = RxEnable | RxPolarity | RxMultiCast;
5034 + catc->rxmode[1] = 0;
5035 + f5u011_rxmode(catc, catc->rxmode);
5037 + dev_dbg(dev, "Init done.\n");
5038 + printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s, %pM.\n",
5039 + netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
5040 + usbdev->bus->bus_name, usbdev->devpath, netdev->dev_addr);
5041 + usb_set_intfdata(intf, catc);
5043 + SET_NETDEV_DEV(netdev, &intf->dev);
5044 + if (register_netdev(netdev) != 0) {
5045 + usb_set_intfdata(intf, NULL);
5046 + usb_free_urb(catc->ctrl_urb);
5047 + usb_free_urb(catc->tx_urb);
5048 + usb_free_urb(catc->rx_urb);
5049 + usb_free_urb(catc->irq_urb);
5050 + free_netdev(netdev);
5056 +static void catc_disconnect(struct usb_interface *intf)
5058 + struct catc *catc = usb_get_intfdata(intf);
5060 + usb_set_intfdata(intf, NULL);
5062 + unregister_netdev(catc->netdev);
5063 + usb_free_urb(catc->ctrl_urb);
5064 + usb_free_urb(catc->tx_urb);
5065 + usb_free_urb(catc->rx_urb);
5066 + usb_free_urb(catc->irq_urb);
5067 + free_netdev(catc->netdev);
5072 + * Module functions and tables.
5075 +static struct usb_device_id catc_id_table [] = {
5076 + { USB_DEVICE(0x0423, 0xa) }, /* CATC Netmate, Belkin F5U011 */
5077 + { USB_DEVICE(0x0423, 0xc) }, /* CATC Netmate II, Belkin F5U111 */
5078 + { USB_DEVICE(0x08d1, 0x1) }, /* smartBridges smartNIC */
5082 +MODULE_DEVICE_TABLE(usb, catc_id_table);
5084 +static struct usb_driver catc_driver = {
5085 + .name = driver_name,
5086 + .probe = catc_probe,
5087 + .disconnect = catc_disconnect,
5088 + .id_table = catc_id_table,
5089 + .disable_hub_initiated_lpm = 1,
5092 +module_usb_driver(catc_driver);
5093 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc_eem.c backports-4.2.6-1/drivers/net/usb/cdc_eem.c
5094 --- backports-4.2.6-1.org/drivers/net/usb/cdc_eem.c 1970-01-01 01:00:00.000000000 +0100
5095 +++ backports-4.2.6-1/drivers/net/usb/cdc_eem.c 2016-06-28 14:35:17.975307221 +0200
5098 + * USB CDC EEM network interface driver
5099 + * Copyright (C) 2009 Oberthur Technologies
5100 + * by Omar Laazimani, Olivier Condemine
5102 + * This program is free software; you can redistribute it and/or modify
5103 + * it under the terms of the GNU General Public License as published by
5104 + * the Free Software Foundation; either version 2 of the License, or
5105 + * (at your option) any later version.
5107 + * This program is distributed in the hope that it will be useful,
5108 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5109 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5110 + * GNU General Public License for more details.
5112 + * You should have received a copy of the GNU General Public License
5113 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
5116 +#include <linux/module.h>
5117 +#include <linux/netdevice.h>
5118 +#include <linux/etherdevice.h>
5119 +#include <linux/ctype.h>
5120 +#include <linux/ethtool.h>
5121 +#include <linux/workqueue.h>
5122 +#include <linux/mii.h>
5123 +#include <linux/usb.h>
5124 +#include <linux/crc32.h>
5125 +#include <linux/usb/cdc.h>
5126 +#include <linux/usb/usbnet.h>
5127 +#include <linux/gfp.h>
5128 +#include <linux/if_vlan.h>
5132 + * This driver is an implementation of the CDC "Ethernet Emulation
5133 + * Model" (EEM) specification, which encapsulates Ethernet frames
5134 + * for transport over USB using a simpler USB device model than the
5135 + * previous CDC "Ethernet Control Model" (ECM, or "CDC Ethernet").
5137 + * For details, see www.usb.org/developers/devclass_docs/CDC_EEM10.pdf
5139 + * This version has been tested with GIGAntIC WuaoW SIM Smart Card on 2.6.24,
5140 + * 2.6.27 and 2.6.30rc2 kernel.
5141 + * It has also been validated on Openmoko Om 2008.12 (based on 2.6.24 kernel).
5142 + * build on 23-April-2009
5145 +#define EEM_HEAD 2 /* 2 byte header */
5147 +/*-------------------------------------------------------------------------*/
5149 +static void eem_linkcmd_complete(struct urb *urb)
5151 + dev_kfree_skb(urb->context);
5152 + usb_free_urb(urb);
5155 +static void eem_linkcmd(struct usbnet *dev, struct sk_buff *skb)
5160 + urb = usb_alloc_urb(0, GFP_ATOMIC);
5164 + usb_fill_bulk_urb(urb, dev->udev, dev->out,
5165 + skb->data, skb->len, eem_linkcmd_complete, skb);
5167 + status = usb_submit_urb(urb, GFP_ATOMIC);
5169 + usb_free_urb(urb);
5171 + dev_kfree_skb(skb);
5172 + netdev_warn(dev->net, "link cmd failure\n");
5177 +static int eem_bind(struct usbnet *dev, struct usb_interface *intf)
5181 + status = usbnet_get_endpoints(dev, intf);
5183 + usb_set_intfdata(intf, NULL);
5184 + usb_driver_release_interface(driver_of(intf), intf);
5188 + /* no jumbogram (16K) support for now */
5190 + dev->net->hard_header_len += EEM_HEAD + ETH_FCS_LEN + VLAN_HLEN;
5191 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
5197 + * EEM permits packing multiple Ethernet frames into USB transfers
5198 + * (a "bundle"), but for TX we don't try to do that.
5200 +static struct sk_buff *eem_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
5203 + struct sk_buff *skb2 = NULL;
5204 + u16 len = skb->len;
5208 + /* When ((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket) is
5209 + * zero, stick two bytes of zero length EEM packet on the end.
5210 + * Else the framework would add invalid single byte padding,
5211 + * since it can't know whether ZLPs will be handled right by
5212 + * all the relevant hardware and software.
5214 + if (!((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket))
5217 + if (!skb_cloned(skb)) {
5218 + int headroom = skb_headroom(skb);
5219 + int tailroom = skb_tailroom(skb);
5221 + if ((tailroom >= ETH_FCS_LEN + padlen) &&
5222 + (headroom >= EEM_HEAD))
5225 + if ((headroom + tailroom)
5226 + > (EEM_HEAD + ETH_FCS_LEN + padlen)) {
5227 + skb->data = memmove(skb->head +
5231 + skb_set_tail_pointer(skb, len);
5236 + skb2 = skb_copy_expand(skb, EEM_HEAD, ETH_FCS_LEN + padlen, flags);
5240 + dev_kfree_skb_any(skb);
5244 + /* we don't use the "no Ethernet CRC" option */
5245 + crc = crc32_le(~0, skb->data, skb->len);
5248 + put_unaligned_le32(crc, skb_put(skb, 4));
5250 + /* EEM packet header format:
5251 + * b0..13: length of ethernet frame
5252 + * b14: bmCRC (1 == valid Ethernet CRC)
5253 + * b15: bmType (0 == data)
5256 + put_unaligned_le16(BIT(14) | len, skb_push(skb, 2));
5258 + /* Bundle a zero length EEM packet if needed */
5260 + put_unaligned_le16(0, skb_put(skb, 2));
5265 +static int eem_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
5268 + * Our task here is to strip off framing, leaving skb with one
5269 + * data frame for the usbnet framework code to process. But we
5270 + * may have received multiple EEM payloads, or command payloads.
5271 + * So we must process _everything_ as if it's a header, except
5272 + * maybe the last data payload
5274 + * REVISIT the framework needs updating so that when we consume
5275 + * all payloads (the last or only message was a command, or a
5276 + * zero length EEM packet) that is not accounted as an rx_error.
5279 + struct sk_buff *skb2 = NULL;
5283 + /* incomplete EEM header? */
5284 + if (skb->len < EEM_HEAD)
5288 + * EEM packet header format:
5289 + * b0..14: EEM type dependent (Data or Command)
5292 + header = get_unaligned_le16(skb->data);
5293 + skb_pull(skb, EEM_HEAD);
5296 + * The bmType bit helps to denote when EEM
5297 + * packet is data or command :
5298 + * bmType = 0 : EEM data payload
5299 + * bmType = 1 : EEM (link) command
5301 + if (header & BIT(15)) {
5305 + * EEM (link) command packet:
5306 + * b0..10: bmEEMCmdParam
5307 + * b11..13: bmEEMCmd
5308 + * b14: bmReserved (must be 0)
5309 + * b15: 1 (EEM command)
5311 + if (header & BIT(14)) {
5312 + netdev_dbg(dev->net, "reserved command %04x\n",
5317 + bmEEMCmd = (header >> 11) & 0x7;
5318 + switch (bmEEMCmd) {
5320 + /* Responding to echo requests is mandatory. */
5321 + case 0: /* Echo command */
5322 + len = header & 0x7FF;
5324 + /* bogus command? */
5325 + if (skb->len < len)
5328 + skb2 = skb_clone(skb, GFP_ATOMIC);
5329 + if (unlikely(!skb2))
5331 + skb_trim(skb2, len);
5332 + put_unaligned_le16(BIT(15) | (1 << 11) | len,
5333 + skb_push(skb2, 2));
5334 + eem_linkcmd(dev, skb2);
5338 + * Host may choose to ignore hints.
5339 + * - suspend: peripheral ready to suspend
5340 + * - response: suggest N millisec polling
5341 + * - response complete: suggest N sec polling
5343 + * Suspend is reported and maybe heeded.
5345 + case 2: /* Suspend hint */
5346 + usbnet_device_suggests_idle(dev);
5348 + case 3: /* Response hint */
5349 + case 4: /* Response complete hint */
5353 + * Hosts should never receive host-to-peripheral
5354 + * or reserved command codes; or responses to an
5355 + * echo command we didn't send.
5357 + case 1: /* Echo response */
5358 + case 5: /* Tickle */
5359 + default: /* reserved */
5360 + netdev_warn(dev->net,
5361 + "unexpected link command %d\n",
5370 + /* zero length EEM packet? */
5375 + * EEM data packet header :
5376 + * b0..13: length of ethernet frame
5378 + * b15: 0 (EEM data)
5380 + len = header & 0x3FFF;
5382 + /* bogus EEM payload? */
5383 + if (skb->len < len)
5386 + /* bogus ethernet frame? */
5387 + if (len < (ETH_HLEN + ETH_FCS_LEN))
5391 + * Treat the last payload differently: framework
5392 + * code expects our "fixup" to have stripped off
5393 + * headers, so "skb" is a data packet (or error).
5394 + * Else if it's not the last payload, keep "skb"
5395 + * for further processing.
5397 + is_last = (len == skb->len);
5401 + skb2 = skb_clone(skb, GFP_ATOMIC);
5402 + if (unlikely(!skb2))
5407 + * The bmCRC helps to denote when the CRC field in
5408 + * the Ethernet frame contains a calculated CRC:
5409 + * bmCRC = 1 : CRC is calculated
5410 + * bmCRC = 0 : CRC = 0xDEADBEEF
5412 + if (header & BIT(14)) {
5413 + crc = get_unaligned_le32(skb2->data
5414 + + len - ETH_FCS_LEN);
5415 + crc2 = ~crc32_le(~0, skb2->data, skb2->len
5418 + crc = get_unaligned_be32(skb2->data
5419 + + len - ETH_FCS_LEN);
5420 + crc2 = 0xdeadbeef;
5422 + skb_trim(skb2, len - ETH_FCS_LEN);
5425 + return crc == crc2;
5427 + if (unlikely(crc != crc2)) {
5428 + dev->net->stats.rx_errors++;
5429 + dev_kfree_skb_any(skb2);
5431 + usbnet_skb_return(dev, skb2);
5435 + skb_pull(skb, len);
5436 + } while (skb->len);
5441 +static const struct driver_info eem_info = {
5442 + .description = "CDC EEM Device",
5443 + .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
5445 + .rx_fixup = eem_rx_fixup,
5446 + .tx_fixup = eem_tx_fixup,
5449 +/*-------------------------------------------------------------------------*/
5451 +static const struct usb_device_id products[] = {
5453 + USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_EEM,
5454 + USB_CDC_PROTO_EEM),
5455 + .driver_info = (unsigned long) &eem_info,
5458 + /* EMPTY == end of list */
5461 +MODULE_DEVICE_TABLE(usb, products);
5463 +static struct usb_driver eem_driver = {
5464 + .name = "cdc_eem",
5465 + .id_table = products,
5466 + .probe = usbnet_probe,
5467 + .disconnect = usbnet_disconnect,
5468 + .suspend = usbnet_suspend,
5469 + .resume = usbnet_resume,
5470 + .disable_hub_initiated_lpm = 1,
5473 +module_usb_driver(eem_driver);
5475 +MODULE_AUTHOR("Omar Laazimani <omar.oberthur@gmail.com>");
5476 +MODULE_DESCRIPTION("USB CDC EEM");
5477 +MODULE_LICENSE("GPL");
5478 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc-phonet.c backports-4.2.6-1/drivers/net/usb/cdc-phonet.c
5479 --- backports-4.2.6-1.org/drivers/net/usb/cdc-phonet.c 1970-01-01 01:00:00.000000000 +0100
5480 +++ backports-4.2.6-1/drivers/net/usb/cdc-phonet.c 2016-06-28 14:35:17.975307221 +0200
5483 + * phonet.c -- USB CDC Phonet host driver
5485 + * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved.
5487 + * Author: Rémi Denis-Courmont
5489 + * This program is free software; you can redistribute it and/or
5490 + * modify it under the terms of the GNU General Public License
5491 + * version 2 as published by the Free Software Foundation.
5493 + * This program is distributed in the hope that it will be useful, but
5494 + * WITHOUT ANY WARRANTY; without even the implied warranty of
5495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Â See the GNU
5496 + * General Public License for more details.
5498 + * You should have received a copy of the GNU General Public License
5499 + * along with this program; if not, write to the Free Software
5500 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
5504 +#include <linux/kernel.h>
5505 +#include <linux/mm.h>
5506 +#include <linux/module.h>
5507 +#include <linux/gfp.h>
5508 +#include <linux/usb.h>
5509 +#include <linux/usb/cdc.h>
5510 +#include <linux/netdevice.h>
5511 +#include <linux/if_arp.h>
5512 +#include <linux/if_phonet.h>
5513 +#include <linux/phonet.h>
5515 +#define PN_MEDIA_USB 0x1B
5517 +static const unsigned rxq_size = 17;
5520 + struct net_device *dev;
5522 + struct usb_interface *intf, *data_intf;
5523 + struct usb_device *usb;
5524 + unsigned int tx_pipe, rx_pipe;
5525 + u8 active_setting;
5528 + unsigned tx_queue;
5529 + spinlock_t tx_lock;
5531 + spinlock_t rx_lock;
5532 + struct sk_buff *rx_skb;
5533 + struct urb *urbs[0];
5536 +static void tx_complete(struct urb *req);
5537 +static void rx_complete(struct urb *req);
5540 + * Network device callbacks
5542 +static netdev_tx_t usbpn_xmit(struct sk_buff *skb, struct net_device *dev)
5544 + struct usbpn_dev *pnd = netdev_priv(dev);
5545 + struct urb *req = NULL;
5546 + unsigned long flags;
5549 + if (skb->protocol != htons(ETH_P_PHONET))
5552 + req = usb_alloc_urb(0, GFP_ATOMIC);
5555 + usb_fill_bulk_urb(req, pnd->usb, pnd->tx_pipe, skb->data, skb->len,
5556 + tx_complete, skb);
5557 + req->transfer_flags = URB_ZERO_PACKET;
5558 + err = usb_submit_urb(req, GFP_ATOMIC);
5560 + usb_free_urb(req);
5564 + spin_lock_irqsave(&pnd->tx_lock, flags);
5566 + if (pnd->tx_queue >= dev->tx_queue_len)
5567 + netif_stop_queue(dev);
5568 + spin_unlock_irqrestore(&pnd->tx_lock, flags);
5569 + return NETDEV_TX_OK;
5572 + dev_kfree_skb(skb);
5573 + dev->stats.tx_dropped++;
5574 + return NETDEV_TX_OK;
5577 +static void tx_complete(struct urb *req)
5579 + struct sk_buff *skb = req->context;
5580 + struct net_device *dev = skb->dev;
5581 + struct usbpn_dev *pnd = netdev_priv(dev);
5582 + int status = req->status;
5586 + dev->stats.tx_bytes += skb->len;
5592 + dev->stats.tx_aborted_errors++;
5594 + dev->stats.tx_errors++;
5595 + dev_dbg(&dev->dev, "TX error (%d)\n", status);
5597 + dev->stats.tx_packets++;
5599 + spin_lock(&pnd->tx_lock);
5601 + netif_wake_queue(dev);
5602 + spin_unlock(&pnd->tx_lock);
5604 + dev_kfree_skb_any(skb);
5605 + usb_free_urb(req);
5608 +static int rx_submit(struct usbpn_dev *pnd, struct urb *req, gfp_t gfp_flags)
5610 + struct net_device *dev = pnd->dev;
5611 + struct page *page;
5614 + page = __dev_alloc_page(gfp_flags | __GFP_NOMEMALLOC);
5618 + usb_fill_bulk_urb(req, pnd->usb, pnd->rx_pipe, page_address(page),
5619 + PAGE_SIZE, rx_complete, dev);
5620 + req->transfer_flags = 0;
5621 + err = usb_submit_urb(req, gfp_flags);
5622 + if (unlikely(err)) {
5623 + dev_dbg(&dev->dev, "RX submit error (%d)\n", err);
5629 +static void rx_complete(struct urb *req)
5631 + struct net_device *dev = req->context;
5632 + struct usbpn_dev *pnd = netdev_priv(dev);
5633 + struct page *page = virt_to_page(req->transfer_buffer);
5634 + struct sk_buff *skb;
5635 + unsigned long flags;
5636 + int status = req->status;
5640 + spin_lock_irqsave(&pnd->rx_lock, flags);
5641 + skb = pnd->rx_skb;
5643 + skb = pnd->rx_skb = netdev_alloc_skb(dev, 12);
5644 + if (likely(skb)) {
5645 + /* Can't use pskb_pull() on page in IRQ */
5646 + memcpy(skb_put(skb, 1), page_address(page), 1);
5647 + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
5648 + page, 1, req->actual_length,
5653 + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
5654 + page, 0, req->actual_length,
5658 + if (req->actual_length < PAGE_SIZE)
5659 + pnd->rx_skb = NULL; /* Last fragment */
5662 + spin_unlock_irqrestore(&pnd->rx_lock, flags);
5664 + skb->protocol = htons(ETH_P_PHONET);
5665 + skb_reset_mac_header(skb);
5666 + __skb_pull(skb, 1);
5668 + dev->stats.rx_packets++;
5669 + dev->stats.rx_bytes += skb->len;
5682 + dev->stats.rx_over_errors++;
5683 + dev_dbg(&dev->dev, "RX overflow\n");
5687 + dev->stats.rx_crc_errors++;
5691 + dev->stats.rx_errors++;
5696 + rx_submit(pnd, req, GFP_ATOMIC);
5699 +static int usbpn_close(struct net_device *dev);
5701 +static int usbpn_open(struct net_device *dev)
5703 + struct usbpn_dev *pnd = netdev_priv(dev);
5706 + unsigned num = pnd->data_intf->cur_altsetting->desc.bInterfaceNumber;
5708 + err = usb_set_interface(pnd->usb, num, pnd->active_setting);
5712 + for (i = 0; i < rxq_size; i++) {
5713 + struct urb *req = usb_alloc_urb(0, GFP_KERNEL);
5715 + if (!req || rx_submit(pnd, req, GFP_KERNEL)) {
5716 + usb_free_urb(req);
5720 + pnd->urbs[i] = req;
5723 + netif_wake_queue(dev);
5727 +static int usbpn_close(struct net_device *dev)
5729 + struct usbpn_dev *pnd = netdev_priv(dev);
5731 + unsigned num = pnd->data_intf->cur_altsetting->desc.bInterfaceNumber;
5733 + netif_stop_queue(dev);
5735 + for (i = 0; i < rxq_size; i++) {
5736 + struct urb *req = pnd->urbs[i];
5740 + usb_kill_urb(req);
5741 + usb_free_urb(req);
5742 + pnd->urbs[i] = NULL;
5745 + return usb_set_interface(pnd->usb, num, !pnd->active_setting);
5748 +static int usbpn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5750 + struct if_phonet_req *req = (struct if_phonet_req *)ifr;
5753 + case SIOCPNGAUTOCONF:
5754 + req->ifr_phonet_autoconf.device = PN_DEV_PC;
5757 + return -ENOIOCTLCMD;
5760 +static int usbpn_set_mtu(struct net_device *dev, int new_mtu)
5762 + if ((new_mtu < PHONET_MIN_MTU) || (new_mtu > PHONET_MAX_MTU))
5765 + dev->mtu = new_mtu;
5769 +static const struct net_device_ops usbpn_ops = {
5770 + .ndo_open = usbpn_open,
5771 + .ndo_stop = usbpn_close,
5772 + .ndo_start_xmit = usbpn_xmit,
5773 + .ndo_do_ioctl = usbpn_ioctl,
5774 + .ndo_change_mtu = usbpn_set_mtu,
5777 +static void usbpn_setup(struct net_device *dev)
5779 + dev->features = 0;
5780 + dev->netdev_ops = &usbpn_ops,
5781 + dev->header_ops = &phonet_header_ops;
5782 + dev->type = ARPHRD_PHONET;
5783 + dev->flags = IFF_POINTOPOINT | IFF_NOARP;
5784 + dev->mtu = PHONET_MAX_MTU;
5785 + dev->hard_header_len = 1;
5786 + dev->dev_addr[0] = PN_MEDIA_USB;
5787 + dev->addr_len = 1;
5788 + dev->tx_queue_len = 3;
5790 + dev->destructor = free_netdev;
5794 + * USB driver callbacks
5796 +static struct usb_device_id usbpn_ids[] = {
5798 + .match_flags = USB_DEVICE_ID_MATCH_VENDOR
5799 + | USB_DEVICE_ID_MATCH_INT_CLASS
5800 + | USB_DEVICE_ID_MATCH_INT_SUBCLASS,
5801 + .idVendor = 0x0421, /* Nokia */
5802 + .bInterfaceClass = USB_CLASS_COMM,
5803 + .bInterfaceSubClass = 0xFE,
5808 +MODULE_DEVICE_TABLE(usb, usbpn_ids);
5810 +static struct usb_driver usbpn_driver;
5812 +static int usbpn_probe(struct usb_interface *intf, const struct usb_device_id *id)
5814 + static const char ifname[] = "usbpn%d";
5815 + const struct usb_cdc_union_desc *union_header = NULL;
5816 + const struct usb_host_interface *data_desc;
5817 + struct usb_interface *data_intf;
5818 + struct usb_device *usbdev = interface_to_usbdev(intf);
5819 + struct net_device *dev;
5820 + struct usbpn_dev *pnd;
5825 + data = intf->altsetting->extra;
5826 + len = intf->altsetting->extralen;
5827 + while (len >= 3) {
5828 + u8 dlen = data[0];
5832 + /* bDescriptorType */
5833 + if (data[1] == USB_DT_CS_INTERFACE) {
5834 + /* bDescriptorSubType */
5835 + switch (data[2]) {
5836 + case USB_CDC_UNION_TYPE:
5837 + if (union_header || dlen < 5)
5840 + (struct usb_cdc_union_desc *)data;
5851 + if (!union_header || !phonet)
5854 + data_intf = usb_ifnum_to_if(usbdev, union_header->bSlaveInterface0);
5855 + if (data_intf == NULL)
5857 + /* Data interface has one inactive and one active setting */
5858 + if (data_intf->num_altsetting != 2)
5860 + if (data_intf->altsetting[0].desc.bNumEndpoints == 0 &&
5861 + data_intf->altsetting[1].desc.bNumEndpoints == 2)
5862 + data_desc = data_intf->altsetting + 1;
5864 + if (data_intf->altsetting[0].desc.bNumEndpoints == 2 &&
5865 + data_intf->altsetting[1].desc.bNumEndpoints == 0)
5866 + data_desc = data_intf->altsetting;
5870 + dev = alloc_netdev(sizeof(*pnd) + sizeof(pnd->urbs[0]) * rxq_size,
5871 + ifname, NET_NAME_UNKNOWN, usbpn_setup);
5875 + pnd = netdev_priv(dev);
5876 + SET_NETDEV_DEV(dev, &intf->dev);
5879 + pnd->usb = usbdev;
5881 + pnd->data_intf = data_intf;
5882 + spin_lock_init(&pnd->tx_lock);
5883 + spin_lock_init(&pnd->rx_lock);
5885 + if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) {
5886 + pnd->rx_pipe = usb_rcvbulkpipe(usbdev,
5887 + data_desc->endpoint[0].desc.bEndpointAddress);
5888 + pnd->tx_pipe = usb_sndbulkpipe(usbdev,
5889 + data_desc->endpoint[1].desc.bEndpointAddress);
5891 + pnd->rx_pipe = usb_rcvbulkpipe(usbdev,
5892 + data_desc->endpoint[1].desc.bEndpointAddress);
5893 + pnd->tx_pipe = usb_sndbulkpipe(usbdev,
5894 + data_desc->endpoint[0].desc.bEndpointAddress);
5896 + pnd->active_setting = data_desc - data_intf->altsetting;
5898 + err = usb_driver_claim_interface(&usbpn_driver, data_intf, pnd);
5902 + /* Force inactive mode until the network device is brought UP */
5903 + usb_set_interface(usbdev, union_header->bSlaveInterface0,
5904 + !pnd->active_setting);
5905 + usb_set_intfdata(intf, pnd);
5907 + err = register_netdev(dev);
5909 + usb_driver_release_interface(&usbpn_driver, data_intf);
5913 + dev_dbg(&dev->dev, "USB CDC Phonet device found\n");
5917 + usb_set_intfdata(intf, NULL);
5922 +static void usbpn_disconnect(struct usb_interface *intf)
5924 + struct usbpn_dev *pnd = usb_get_intfdata(intf);
5926 + if (pnd->disconnected)
5929 + pnd->disconnected = 1;
5930 + usb_driver_release_interface(&usbpn_driver,
5931 + (pnd->intf == intf) ? pnd->data_intf : pnd->intf);
5932 + unregister_netdev(pnd->dev);
5935 +static struct usb_driver usbpn_driver = {
5936 + .name = "cdc_phonet",
5937 + .probe = usbpn_probe,
5938 + .disconnect = usbpn_disconnect,
5939 + .id_table = usbpn_ids,
5940 + .disable_hub_initiated_lpm = 1,
5943 +module_usb_driver(usbpn_driver);
5945 +MODULE_AUTHOR("Remi Denis-Courmont");
5946 +MODULE_DESCRIPTION("USB CDC Phonet host interface");
5947 +MODULE_LICENSE("GPL");
5948 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cdc_subset.c backports-4.2.6-1/drivers/net/usb/cdc_subset.c
5949 --- backports-4.2.6-1.org/drivers/net/usb/cdc_subset.c 1970-01-01 01:00:00.000000000 +0100
5950 +++ backports-4.2.6-1/drivers/net/usb/cdc_subset.c 2016-06-28 14:35:17.975307221 +0200
5953 + * Simple "CDC Subset" USB Networking Links
5954 + * Copyright (C) 2000-2005 by David Brownell
5956 + * This program is free software; you can redistribute it and/or modify
5957 + * it under the terms of the GNU General Public License as published by
5958 + * the Free Software Foundation; either version 2 of the License, or
5959 + * (at your option) any later version.
5961 + * This program is distributed in the hope that it will be useful,
5962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5964 + * GNU General Public License for more details.
5966 + * You should have received a copy of the GNU General Public License
5967 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
5970 +#include <linux/module.h>
5971 +#include <linux/kmod.h>
5972 +#include <linux/netdevice.h>
5973 +#include <linux/etherdevice.h>
5974 +#include <linux/ethtool.h>
5975 +#include <linux/workqueue.h>
5976 +#include <linux/mii.h>
5977 +#include <linux/usb.h>
5978 +#include <linux/usb/usbnet.h>
5982 + * This supports simple USB network links that don't require any special
5983 + * framing or hardware control operations. The protocol used here is a
5984 + * strict subset of CDC Ethernet, with three basic differences reflecting
5985 + * the goal that almost any hardware should run it:
5987 + * - Minimal runtime control: one interface, no altsettings, and
5988 + * no vendor or class specific control requests. If a device is
5989 + * configured, it is allowed to exchange packets with the host.
5990 + * Fancier models would mean not working on some hardware.
5992 + * - Minimal manufacturing control: no IEEE "Organizationally
5993 + * Unique ID" required, or an EEPROMs to store one. Each host uses
5994 + * one random "locally assigned" Ethernet address instead, which can
5995 + * of course be overridden using standard tools like "ifconfig".
5996 + * (With 2^46 such addresses, same-net collisions are quite rare.)
5998 + * - There is no additional framing data for USB. Packets are written
5999 + * exactly as in CDC Ethernet, starting with an Ethernet header and
6000 + * terminated by a short packet. However, the host will never send a
6001 + * zero length packet; some systems can't handle those robustly.
6003 + * Anything that can transmit and receive USB bulk packets can implement
6004 + * this protocol. That includes both smart peripherals and quite a lot
6005 + * of "host-to-host" USB cables (which embed two devices back-to-back).
6007 + * Note that although Linux may use many of those host-to-host links
6008 + * with this "cdc_subset" framing, that doesn't mean there may not be a
6009 + * better approach. Handling the "other end unplugs/replugs" scenario
6010 + * well tends to require chip-specific vendor requests. Also, Windows
6011 + * peers at the other end of host-to-host cables may expect their own
6012 + * framing to be used rather than this "cdc_subset" model.
6015 +#if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
6016 +/* PDA style devices are always connected if present */
6017 +static int always_connected (struct usbnet *dev)
6023 +#ifdef CONFIG_USB_ALI_M5632
6024 +#define HAVE_HARDWARE
6026 +/*-------------------------------------------------------------------------
6028 + * ALi M5632 driver ... does high speed
6030 + * NOTE that the MS-Windows drivers for this chip use some funky and
6031 + * (naturally) undocumented 7-byte prefix to each packet, so this is a
6032 + * case where we don't currently interoperate. Also, once you unplug
6033 + * one end of the cable, you need to replug the other end too ... since
6034 + * chip docs are unavailable, there's no way to reset the relevant state
6035 + * short of a power cycle.
6037 + *-------------------------------------------------------------------------*/
6039 +static void m5632_recover(struct usbnet *dev)
6041 + struct usb_device *udev = dev->udev;
6042 + struct usb_interface *intf = dev->intf;
6045 + r = usb_lock_device_for_reset(udev, intf);
6049 + usb_reset_device(udev);
6050 + usb_unlock_device(udev);
6053 +static const struct driver_info ali_m5632_info = {
6054 + .description = "ALi M5632",
6055 + .flags = FLAG_POINTTOPOINT,
6056 + .recover = m5632_recover,
6061 +#ifdef CONFIG_USB_AN2720
6062 +#define HAVE_HARDWARE
6064 +/*-------------------------------------------------------------------------
6066 + * AnchorChips 2720 driver ... http://www.cypress.com
6068 + * This doesn't seem to have a way to detect whether the peer is
6069 + * connected, or need any reset handshaking. It's got pretty big
6070 + * internal buffers (handles most of a frame's worth of data).
6071 + * Chip data sheets don't describe any vendor control messages.
6073 + *-------------------------------------------------------------------------*/
6075 +static const struct driver_info an2720_info = {
6076 + .description = "AnchorChips/Cypress 2720",
6077 + .flags = FLAG_POINTTOPOINT,
6078 + // no reset available!
6079 + // no check_connect available!
6081 + .in = 2, .out = 2, // direction distinguishes these
6084 +#endif /* CONFIG_USB_AN2720 */
6087 +#ifdef CONFIG_USB_BELKIN
6088 +#define HAVE_HARDWARE
6090 +/*-------------------------------------------------------------------------
6092 + * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
6094 + * ... also two eTEK designs, including one sold as "Advance USBNET"
6096 + *-------------------------------------------------------------------------*/
6098 +static const struct driver_info belkin_info = {
6099 + .description = "Belkin, eTEK, or compatible",
6100 + .flags = FLAG_POINTTOPOINT,
6103 +#endif /* CONFIG_USB_BELKIN */
6107 +#ifdef CONFIG_USB_EPSON2888
6108 +#define HAVE_HARDWARE
6110 +/*-------------------------------------------------------------------------
6112 + * EPSON USB clients
6114 + * This is the same idea as Linux PDAs (below) except the firmware in the
6115 + * device might not be Tux-powered. Epson provides reference firmware that
6116 + * implements this interface. Product developers can reuse or modify that
6117 + * code, such as by using their own product and vendor codes.
6119 + * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
6121 + *-------------------------------------------------------------------------*/
6123 +static const struct driver_info epson2888_info = {
6124 + .description = "Epson USB Device",
6125 + .check_connect = always_connected,
6126 + .flags = FLAG_POINTTOPOINT,
6128 + .in = 4, .out = 3,
6131 +#endif /* CONFIG_USB_EPSON2888 */
6134 +/*-------------------------------------------------------------------------
6136 + * info from Jonathan McDowell <noodles@earth.li>
6138 + *-------------------------------------------------------------------------*/
6139 +#ifdef CONFIG_USB_KC2190
6140 +#define HAVE_HARDWARE
6141 +static const struct driver_info kc2190_info = {
6142 + .description = "KC Technology KC-190",
6143 + .flags = FLAG_POINTTOPOINT,
6145 +#endif /* CONFIG_USB_KC2190 */
6148 +#ifdef CONFIG_USB_ARMLINUX
6149 +#define HAVE_HARDWARE
6151 +/*-------------------------------------------------------------------------
6153 + * Intel's SA-1100 chip integrates basic USB support, and is used
6154 + * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
6155 + * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
6156 + * network using minimal USB framing data.
6158 + * This describes the driver currently in standard ARM Linux kernels.
6159 + * The Zaurus uses a different driver (see later).
6161 + * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
6162 + * and different USB endpoint numbering than the SA1100 devices. The
6163 + * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
6164 + * so we rely on the endpoint descriptors.
6166 + *-------------------------------------------------------------------------*/
6168 +static const struct driver_info linuxdev_info = {
6169 + .description = "Linux Device",
6170 + .check_connect = always_connected,
6171 + .flags = FLAG_POINTTOPOINT,
6174 +static const struct driver_info yopy_info = {
6175 + .description = "Yopy",
6176 + .check_connect = always_connected,
6177 + .flags = FLAG_POINTTOPOINT,
6180 +static const struct driver_info blob_info = {
6181 + .description = "Boot Loader OBject",
6182 + .check_connect = always_connected,
6183 + .flags = FLAG_POINTTOPOINT,
6186 +#endif /* CONFIG_USB_ARMLINUX */
6189 +/*-------------------------------------------------------------------------*/
6191 +#ifndef HAVE_HARDWARE
6192 +#warning You need to configure some hardware for this driver
6196 + * chip vendor names won't normally be on the cables, and
6197 + * may not be on the device.
6200 +static const struct usb_device_id products [] = {
6202 +#ifdef CONFIG_USB_ALI_M5632
6204 + USB_DEVICE (0x0402, 0x5632), // ALi defaults
6205 + .driver_info = (unsigned long) &ali_m5632_info,
6208 + USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
6209 + .driver_info = (unsigned long) &ali_m5632_info,
6213 +#ifdef CONFIG_USB_AN2720
6215 + USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
6216 + .driver_info = (unsigned long) &an2720_info,
6218 + USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
6219 + .driver_info = (unsigned long) &an2720_info,
6223 +#ifdef CONFIG_USB_BELKIN
6225 + USB_DEVICE (0x050d, 0x0004), // Belkin
6226 + .driver_info = (unsigned long) &belkin_info,
6228 + USB_DEVICE (0x056c, 0x8100), // eTEK
6229 + .driver_info = (unsigned long) &belkin_info,
6231 + USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
6232 + .driver_info = (unsigned long) &belkin_info,
6236 +#ifdef CONFIG_USB_EPSON2888
6238 + USB_DEVICE (0x0525, 0x2888), // EPSON USB client
6239 + .driver_info = (unsigned long) &epson2888_info,
6243 +#ifdef CONFIG_USB_KC2190
6245 + USB_DEVICE (0x050f, 0x0190), // KC-190
6246 + .driver_info = (unsigned long) &kc2190_info,
6250 +#ifdef CONFIG_USB_ARMLINUX
6252 + * SA-1100 using standard ARM Linux kernels, or compatible.
6253 + * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
6254 + * The sa-1100 "usb-eth" driver handles the basic framing.
6256 + * PXA25x or PXA210 ... these use a "usb-eth" driver much like
6257 + * the sa1100 one, but hardware uses different endpoint numbers.
6259 + * Or the Linux "Ethernet" gadget on hardware that can't talk
6260 + * CDC Ethernet (e.g., no altsettings), in either of two modes:
6261 + * - acting just like the old "usb-eth" firmware, though
6262 + * the implementation is different
6263 + * - supporting RNDIS as the first/default configuration for
6264 + * MS-Windows interop; Linux needs to use the other config
6267 + // 1183 = 0x049F, both used as hex values?
6268 + // Compaq "Itsy" vendor/product id
6269 + USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
6270 + .driver_info = (unsigned long) &linuxdev_info,
6272 + USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
6273 + .driver_info = (unsigned long) &yopy_info,
6275 + USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
6276 + .driver_info = (unsigned long) &blob_info,
6278 + USB_DEVICE (0x1286, 0x8001), // "blob" bootloader
6279 + .driver_info = (unsigned long) &blob_info,
6281 + // Linux Ethernet/RNDIS gadget, mostly on PXA, second config
6282 + // e.g. Gumstix, current OpenZaurus, ... or anything else
6283 + // that just enables this gadget option.
6284 + USB_DEVICE (0x0525, 0xa4a2),
6285 + .driver_info = (unsigned long) &linuxdev_info,
6291 +MODULE_DEVICE_TABLE(usb, products);
6293 +/*-------------------------------------------------------------------------*/
6294 +static int dummy_prereset(struct usb_interface *intf)
6299 +static int dummy_postreset(struct usb_interface *intf)
6304 +static struct usb_driver cdc_subset_driver = {
6305 + .name = "cdc_subset",
6306 + .probe = usbnet_probe,
6307 + .suspend = usbnet_suspend,
6308 + .resume = usbnet_resume,
6309 + .pre_reset = dummy_prereset,
6310 + .post_reset = dummy_postreset,
6311 + .disconnect = usbnet_disconnect,
6312 + .id_table = products,
6313 + .disable_hub_initiated_lpm = 1,
6316 +module_usb_driver(cdc_subset_driver);
6318 +MODULE_AUTHOR("David Brownell");
6319 +MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
6320 +MODULE_LICENSE("GPL");
6321 diff -Naur backports-4.2.6-1.org/drivers/net/usb/cx82310_eth.c backports-4.2.6-1/drivers/net/usb/cx82310_eth.c
6322 --- backports-4.2.6-1.org/drivers/net/usb/cx82310_eth.c 1970-01-01 01:00:00.000000000 +0100
6323 +++ backports-4.2.6-1/drivers/net/usb/cx82310_eth.c 2016-06-28 14:35:17.978640554 +0200
6326 + * Driver for USB ethernet port of Conexant CX82310-based ADSL routers
6327 + * Copyright (C) 2010 by Ondrej Zary
6328 + * some parts inspired by the cxacru driver
6330 + * This program is free software; you can redistribute it and/or modify
6331 + * it under the terms of the GNU General Public License as published by
6332 + * the Free Software Foundation; either version 2 of the License, or
6333 + * (at your option) any later version.
6335 + * This program is distributed in the hope that it will be useful,
6336 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6337 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6338 + * GNU General Public License for more details.
6340 + * You should have received a copy of the GNU General Public License
6341 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
6344 +#include <linux/module.h>
6345 +#include <linux/netdevice.h>
6346 +#include <linux/etherdevice.h>
6347 +#include <linux/ethtool.h>
6348 +#include <linux/workqueue.h>
6349 +#include <linux/mii.h>
6350 +#include <linux/usb.h>
6351 +#include <linux/usb/usbnet.h>
6354 + CMD_START = 0x84, /* no effect? */
6355 + CMD_STOP = 0x85, /* no effect? */
6356 + CMD_GET_STATUS = 0x90, /* returns nothing? */
6357 + CMD_GET_MAC_ADDR = 0x91, /* read MAC address */
6358 + CMD_GET_LINK_STATUS = 0x92, /* not useful, link is always up */
6359 + CMD_ETHERNET_MODE = 0x99, /* unknown, needed during init */
6362 +enum cx82310_status {
6366 + STATUS_UNSUPPORTED,
6367 + STATUS_UNIMPLEMENTED,
6368 + STATUS_PARAMETER_ERROR,
6369 + STATUS_DBG_LOOPBACK,
6372 +#define CMD_PACKET_SIZE 64
6373 +#define CMD_TIMEOUT 100
6374 +#define CMD_REPLY_RETRY 5
6376 +#define CX82310_MTU 1514
6377 +#define CMD_EP 0x01
6380 + * execute control command
6381 + * - optionally send some data (command parameters)
6382 + * - optionally wait for the reply
6383 + * - optionally read some data from the reply
6385 +static int cx82310_cmd(struct usbnet *dev, enum cx82310_cmd cmd, bool reply,
6386 + u8 *wdata, int wlen, u8 *rdata, int rlen)
6388 + int actual_len, retries, ret;
6389 + struct usb_device *udev = dev->udev;
6390 + u8 *buf = kzalloc(CMD_PACKET_SIZE, GFP_KERNEL);
6395 + /* create command packet */
6398 + memcpy(buf + 4, wdata, min_t(int, wlen, CMD_PACKET_SIZE - 4));
6400 + /* send command packet */
6401 + ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, CMD_EP), buf,
6402 + CMD_PACKET_SIZE, &actual_len, CMD_TIMEOUT);
6404 + if (cmd != CMD_GET_LINK_STATUS)
6405 + dev_err(&dev->udev->dev, "send command %#x: error %d\n",
6411 + /* wait for reply, retry if it's empty */
6412 + for (retries = 0; retries < CMD_REPLY_RETRY; retries++) {
6413 + ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, CMD_EP),
6414 + buf, CMD_PACKET_SIZE, &actual_len,
6417 + if (cmd != CMD_GET_LINK_STATUS)
6418 + dev_err(&dev->udev->dev,
6419 + "reply receive error %d\n",
6423 + if (actual_len > 0)
6426 + if (actual_len == 0) {
6427 + dev_err(&dev->udev->dev, "no reply to command %#x\n",
6432 + if (buf[0] != cmd) {
6433 + dev_err(&dev->udev->dev,
6434 + "got reply to command %#x, expected: %#x\n",
6439 + if (buf[1] != STATUS_SUCCESS) {
6440 + dev_err(&dev->udev->dev, "command %#x failed: %#x\n",
6446 + memcpy(rdata, buf + 4,
6447 + min_t(int, rlen, CMD_PACKET_SIZE - 4));
6454 +#define partial_len data[0] /* length of partial packet data */
6455 +#define partial_rem data[1] /* remaining (missing) data length */
6456 +#define partial_data data[2] /* partial packet data */
6458 +static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
6462 + struct usb_device *udev = dev->udev;
6466 + /* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */
6467 + if (usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) > 0
6468 + && strcmp(buf, "USB NET CARD")) {
6469 + dev_info(&udev->dev, "ignoring: probably an ADSL modem\n");
6473 + ret = usbnet_get_endpoints(dev, intf);
6478 + * this must not include ethernet header as the device can send partial
6479 + * packets with no header (and sometimes even empty URBs)
6481 + dev->net->hard_header_len = 0;
6482 + /* we can send at most 1514 bytes of data (+ 2-byte header) per URB */
6483 + dev->hard_mtu = CX82310_MTU + 2;
6484 + /* we can receive URBs up to 4KB from the device */
6485 + dev->rx_urb_size = 4096;
6487 + dev->partial_data = (unsigned long) kmalloc(dev->hard_mtu, GFP_KERNEL);
6488 + if (!dev->partial_data)
6491 + /* wait for firmware to become ready (indicated by the link being up) */
6492 + while (--timeout) {
6493 + ret = cx82310_cmd(dev, CMD_GET_LINK_STATUS, true, NULL, 0,
6494 + link, sizeof(link));
6495 + /* the command can time out during boot - it's not an error */
6496 + if (!ret && link[0] == 1 && link[2] == 1)
6501 + dev_err(&udev->dev, "firmware not ready in time\n");
6502 + return -ETIMEDOUT;
6505 + /* enable ethernet mode (?) */
6506 + ret = cx82310_cmd(dev, CMD_ETHERNET_MODE, true, "\x01", 1, NULL, 0);
6508 + dev_err(&udev->dev, "unable to enable ethernet mode: %d\n",
6513 + /* get the MAC address */
6514 + ret = cx82310_cmd(dev, CMD_GET_MAC_ADDR, true, NULL, 0,
6515 + dev->net->dev_addr, ETH_ALEN);
6517 + dev_err(&udev->dev, "unable to read MAC address: %d\n", ret);
6521 + /* start (does not seem to have any effect?) */
6522 + ret = cx82310_cmd(dev, CMD_START, false, NULL, 0, NULL, 0);
6528 + kfree((void *)dev->partial_data);
6532 +static void cx82310_unbind(struct usbnet *dev, struct usb_interface *intf)
6534 + kfree((void *)dev->partial_data);
6538 + * RX is NOT easy - we can receive multiple packets per skb, each having 2-byte
6539 + * packet length at the beginning.
6540 + * The last packet might be incomplete (when it crosses the 4KB URB size),
6541 + * continuing in the next skb (without any headers).
6542 + * If a packet has odd length, there is one extra byte at the end (before next
6543 + * packet or at the end of the URB).
6545 +static int cx82310_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
6548 + struct sk_buff *skb2;
6551 + * If the last skb ended with an incomplete packet, this skb contains
6552 + * end of that packet at the beginning.
6554 + if (dev->partial_rem) {
6555 + len = dev->partial_len + dev->partial_rem;
6556 + skb2 = alloc_skb(len, GFP_ATOMIC);
6559 + skb_put(skb2, len);
6560 + memcpy(skb2->data, (void *)dev->partial_data,
6561 + dev->partial_len);
6562 + memcpy(skb2->data + dev->partial_len, skb->data,
6563 + dev->partial_rem);
6564 + usbnet_skb_return(dev, skb2);
6565 + skb_pull(skb, (dev->partial_rem + 1) & ~1);
6566 + dev->partial_rem = 0;
6571 + /* a skb can contain multiple packets */
6572 + while (skb->len > 1) {
6573 + /* first two bytes are packet length */
6574 + len = skb->data[0] | (skb->data[1] << 8);
6577 + /* if last packet in the skb, let usbnet to process it */
6578 + if (len == skb->len || len + 1 == skb->len) {
6579 + skb_trim(skb, len);
6583 + if (len > CX82310_MTU) {
6584 + dev_err(&dev->udev->dev, "RX packet too long: %d B\n",
6589 + /* incomplete packet, save it for the next skb */
6590 + if (len > skb->len) {
6591 + dev->partial_len = skb->len;
6592 + dev->partial_rem = len - skb->len;
6593 + memcpy((void *)dev->partial_data, skb->data,
6594 + dev->partial_len);
6595 + skb_pull(skb, skb->len);
6599 + skb2 = alloc_skb(len, GFP_ATOMIC);
6602 + skb_put(skb2, len);
6603 + memcpy(skb2->data, skb->data, len);
6604 + /* process the packet */
6605 + usbnet_skb_return(dev, skb2);
6607 + skb_pull(skb, (len + 1) & ~1);
6610 + /* let usbnet process the last packet */
6614 +/* TX is easy, just add 2 bytes of length at the beginning */
6615 +static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
6618 + int len = skb->len;
6620 + if (skb_headroom(skb) < 2) {
6621 + struct sk_buff *skb2 = skb_copy_expand(skb, 2, 0, flags);
6622 + dev_kfree_skb_any(skb);
6629 + skb->data[0] = len;
6630 + skb->data[1] = len >> 8;
6636 +static const struct driver_info cx82310_info = {
6637 + .description = "Conexant CX82310 USB ethernet",
6638 + .flags = FLAG_ETHER,
6639 + .bind = cx82310_bind,
6640 + .unbind = cx82310_unbind,
6641 + .rx_fixup = cx82310_rx_fixup,
6642 + .tx_fixup = cx82310_tx_fixup,
6645 +#define USB_DEVICE_CLASS(vend, prod, cl, sc, pr) \
6646 + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
6647 + USB_DEVICE_ID_MATCH_DEV_INFO, \
6648 + .idVendor = (vend), \
6649 + .idProduct = (prod), \
6650 + .bDeviceClass = (cl), \
6651 + .bDeviceSubClass = (sc), \
6652 + .bDeviceProtocol = (pr)
6654 +static const struct usb_device_id products[] = {
6656 + USB_DEVICE_CLASS(0x0572, 0xcb01, 0xff, 0, 0),
6657 + .driver_info = (unsigned long) &cx82310_info
6661 +MODULE_DEVICE_TABLE(usb, products);
6663 +static struct usb_driver cx82310_driver = {
6664 + .name = "cx82310_eth",
6665 + .id_table = products,
6666 + .probe = usbnet_probe,
6667 + .disconnect = usbnet_disconnect,
6668 + .suspend = usbnet_suspend,
6669 + .resume = usbnet_resume,
6670 + .disable_hub_initiated_lpm = 1,
6673 +module_usb_driver(cx82310_driver);
6675 +MODULE_AUTHOR("Ondrej Zary");
6676 +MODULE_DESCRIPTION("Conexant CX82310-based ADSL router USB ethernet driver");
6677 +MODULE_LICENSE("GPL");
6678 diff -Naur backports-4.2.6-1.org/drivers/net/usb/dm9601.c backports-4.2.6-1/drivers/net/usb/dm9601.c
6679 --- backports-4.2.6-1.org/drivers/net/usb/dm9601.c 1970-01-01 01:00:00.000000000 +0100
6680 +++ backports-4.2.6-1/drivers/net/usb/dm9601.c 2016-06-28 14:35:17.978640554 +0200
6683 + * Davicom DM96xx USB 10/100Mbps ethernet devices
6685 + * Peter Korsgaard <jacmet@sunsite.dk>
6687 + * This file is licensed under the terms of the GNU General Public License
6688 + * version 2. This program is licensed "as is" without any warranty of any
6689 + * kind, whether express or implied.
6694 +#include <linux/module.h>
6695 +#include <linux/sched.h>
6696 +#include <linux/stddef.h>
6697 +#include <linux/netdevice.h>
6698 +#include <linux/etherdevice.h>
6699 +#include <linux/ethtool.h>
6700 +#include <linux/mii.h>
6701 +#include <linux/usb.h>
6702 +#include <linux/crc32.h>
6703 +#include <linux/usb/usbnet.h>
6704 +#include <linux/slab.h>
6707 + http://ptm2.cc.utu.fi/ftp/network/cards/DM9601/From_NET/DM9601-DS-P01-930914.pdf
6710 +/* control requests */
6711 +#define DM_READ_REGS 0x00
6712 +#define DM_WRITE_REGS 0x01
6713 +#define DM_READ_MEMS 0x02
6714 +#define DM_WRITE_REG 0x03
6715 +#define DM_WRITE_MEMS 0x05
6716 +#define DM_WRITE_MEM 0x07
6719 +#define DM_NET_CTRL 0x00
6720 +#define DM_RX_CTRL 0x05
6721 +#define DM_SHARED_CTRL 0x0b
6722 +#define DM_SHARED_ADDR 0x0c
6723 +#define DM_SHARED_DATA 0x0d /* low + high */
6724 +#define DM_PHY_ADDR 0x10 /* 6 bytes */
6725 +#define DM_MCAST_ADDR 0x16 /* 8 bytes */
6726 +#define DM_GPR_CTRL 0x1e
6727 +#define DM_GPR_DATA 0x1f
6728 +#define DM_CHIP_ID 0x2c
6729 +#define DM_MODE_CTRL 0x91 /* only on dm9620 */
6731 +/* chip id values */
6732 +#define ID_DM9601 0
6733 +#define ID_DM9620 1
6735 +#define DM_MAX_MCAST 64
6736 +#define DM_MCAST_SIZE 8
6737 +#define DM_EEPROM_LEN 256
6738 +#define DM_TX_OVERHEAD 2 /* 2 byte header */
6739 +#define DM_RX_OVERHEAD 7 /* 3 byte header + 4 byte crc tail */
6740 +#define DM_TIMEOUT 1000
6742 +static int dm_read(struct usbnet *dev, u8 reg, u16 length, void *data)
6745 + err = usbnet_read_cmd(dev, DM_READ_REGS,
6746 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6747 + 0, reg, data, length);
6748 + if(err != length && err >= 0)
6753 +static int dm_read_reg(struct usbnet *dev, u8 reg, u8 *value)
6755 + return dm_read(dev, reg, 1, value);
6758 +static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
6761 + err = usbnet_write_cmd(dev, DM_WRITE_REGS,
6762 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6763 + 0, reg, data, length);
6765 + if (err >= 0 && err < length)
6770 +static int dm_write_reg(struct usbnet *dev, u8 reg, u8 value)
6772 + return usbnet_write_cmd(dev, DM_WRITE_REG,
6773 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6774 + value, reg, NULL, 0);
6777 +static void dm_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
6779 + usbnet_write_cmd_async(dev, DM_WRITE_REGS,
6780 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6781 + 0, reg, data, length);
6784 +static void dm_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
6786 + usbnet_write_cmd_async(dev, DM_WRITE_REG,
6787 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
6788 + value, reg, NULL, 0);
6791 +static int dm_read_shared_word(struct usbnet *dev, int phy, u8 reg, __le16 *value)
6795 + mutex_lock(&dev->phy_mutex);
6797 + dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
6798 + dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0xc : 0x4);
6800 + for (i = 0; i < DM_TIMEOUT; i++) {
6804 + ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
6809 + if ((tmp & 1) == 0)
6813 + if (i == DM_TIMEOUT) {
6814 + netdev_err(dev->net, "%s read timed out!\n", phy ? "phy" : "eeprom");
6819 + dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
6820 + ret = dm_read(dev, DM_SHARED_DATA, 2, value);
6822 + netdev_dbg(dev->net, "read shared %d 0x%02x returned 0x%04x, %d\n",
6823 + phy, reg, *value, ret);
6826 + mutex_unlock(&dev->phy_mutex);
6830 +static int dm_write_shared_word(struct usbnet *dev, int phy, u8 reg, __le16 value)
6834 + mutex_lock(&dev->phy_mutex);
6836 + ret = dm_write(dev, DM_SHARED_DATA, 2, &value);
6840 + dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
6841 + dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1a : 0x12);
6843 + for (i = 0; i < DM_TIMEOUT; i++) {
6847 + ret = dm_read_reg(dev, DM_SHARED_CTRL, &tmp);
6852 + if ((tmp & 1) == 0)
6856 + if (i == DM_TIMEOUT) {
6857 + netdev_err(dev->net, "%s write timed out!\n", phy ? "phy" : "eeprom");
6862 + dm_write_reg(dev, DM_SHARED_CTRL, 0x0);
6865 + mutex_unlock(&dev->phy_mutex);
6869 +static int dm_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
6871 + return dm_read_shared_word(dev, 0, offset, value);
6876 +static int dm9601_get_eeprom_len(struct net_device *dev)
6878 + return DM_EEPROM_LEN;
6881 +static int dm9601_get_eeprom(struct net_device *net,
6882 + struct ethtool_eeprom *eeprom, u8 * data)
6884 + struct usbnet *dev = netdev_priv(net);
6885 + __le16 *ebuf = (__le16 *) data;
6888 + /* access is 16bit */
6889 + if ((eeprom->offset % 2) || (eeprom->len % 2))
6892 + for (i = 0; i < eeprom->len / 2; i++) {
6893 + if (dm_read_eeprom_word(dev, eeprom->offset / 2 + i,
6900 +static int dm9601_mdio_read(struct net_device *netdev, int phy_id, int loc)
6902 + struct usbnet *dev = netdev_priv(netdev);
6907 + netdev_dbg(dev->net, "Only internal phy supported\n");
6911 + dm_read_shared_word(dev, 1, loc, &res);
6913 + netdev_dbg(dev->net,
6914 + "dm9601_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
6915 + phy_id, loc, le16_to_cpu(res));
6917 + return le16_to_cpu(res);
6920 +static void dm9601_mdio_write(struct net_device *netdev, int phy_id, int loc,
6923 + struct usbnet *dev = netdev_priv(netdev);
6924 + __le16 res = cpu_to_le16(val);
6927 + netdev_dbg(dev->net, "Only internal phy supported\n");
6931 + netdev_dbg(dev->net, "dm9601_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
6932 + phy_id, loc, val);
6934 + dm_write_shared_word(dev, 1, loc, res);
6937 +static void dm9601_get_drvinfo(struct net_device *net,
6938 + struct ethtool_drvinfo *info)
6940 + /* Inherit standard device info */
6941 + usbnet_get_drvinfo(net, info);
6942 + info->eedump_len = DM_EEPROM_LEN;
6945 +static u32 dm9601_get_link(struct net_device *net)
6947 + struct usbnet *dev = netdev_priv(net);
6949 + return mii_link_ok(&dev->mii);
6952 +static int dm9601_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
6954 + struct usbnet *dev = netdev_priv(net);
6956 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
6959 +static const struct ethtool_ops dm9601_ethtool_ops = {
6960 + .get_drvinfo = dm9601_get_drvinfo,
6961 + .get_link = dm9601_get_link,
6962 + .get_msglevel = usbnet_get_msglevel,
6963 + .set_msglevel = usbnet_set_msglevel,
6964 + .get_eeprom_len = dm9601_get_eeprom_len,
6965 + .get_eeprom = dm9601_get_eeprom,
6966 + .get_settings = usbnet_get_settings,
6967 + .set_settings = usbnet_set_settings,
6968 + .nway_reset = usbnet_nway_reset,
6971 +static void dm9601_set_multicast(struct net_device *net)
6973 + struct usbnet *dev = netdev_priv(net);
6974 + /* We use the 20 byte dev->data for our 8 byte filter buffer
6975 + * to avoid allocating memory that is tricky to free later */
6976 + u8 *hashes = (u8 *) & dev->data;
6979 + memset(hashes, 0x00, DM_MCAST_SIZE);
6980 + hashes[DM_MCAST_SIZE - 1] |= 0x80; /* broadcast address */
6982 + if (net->flags & IFF_PROMISC) {
6984 + } else if (net->flags & IFF_ALLMULTI ||
6985 + netdev_mc_count(net) > DM_MAX_MCAST) {
6987 + } else if (!netdev_mc_empty(net)) {
6988 + struct netdev_hw_addr *ha;
6990 + netdev_for_each_mc_addr(ha, net) {
6991 + u32 crc = ether_crc(ETH_ALEN, ha->addr) >> 26;
6992 + hashes[crc >> 3] |= 1 << (crc & 0x7);
6996 + dm_write_async(dev, DM_MCAST_ADDR, DM_MCAST_SIZE, hashes);
6997 + dm_write_reg_async(dev, DM_RX_CTRL, rx_ctl);
7000 +static void __dm9601_set_mac_address(struct usbnet *dev)
7002 + dm_write_async(dev, DM_PHY_ADDR, ETH_ALEN, dev->net->dev_addr);
7005 +static int dm9601_set_mac_address(struct net_device *net, void *p)
7007 + struct sockaddr *addr = p;
7008 + struct usbnet *dev = netdev_priv(net);
7010 + if (!is_valid_ether_addr(addr->sa_data)) {
7011 + dev_err(&net->dev, "not setting invalid mac address %pM\n",
7016 + memcpy(net->dev_addr, addr->sa_data, net->addr_len);
7017 + __dm9601_set_mac_address(dev);
7022 +static const struct net_device_ops dm9601_netdev_ops = {
7023 + .ndo_open = usbnet_open,
7024 + .ndo_stop = usbnet_stop,
7025 + .ndo_start_xmit = usbnet_start_xmit,
7026 + .ndo_tx_timeout = usbnet_tx_timeout,
7027 + .ndo_change_mtu = usbnet_change_mtu,
7028 + .ndo_validate_addr = eth_validate_addr,
7029 + .ndo_do_ioctl = dm9601_ioctl,
7030 + .ndo_set_rx_mode = dm9601_set_multicast,
7031 + .ndo_set_mac_address = dm9601_set_mac_address,
7034 +static int dm9601_bind(struct usbnet *dev, struct usb_interface *intf)
7037 + u8 mac[ETH_ALEN], id;
7039 + ret = usbnet_get_endpoints(dev, intf);
7043 + dev->net->netdev_ops = &dm9601_netdev_ops;
7044 + dev->net->ethtool_ops = &dm9601_ethtool_ops;
7045 + dev->net->hard_header_len += DM_TX_OVERHEAD;
7046 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
7048 + /* dm9620/21a require room for 4 byte padding, even in dm9601
7049 + * mode, so we need +1 to be able to receive full size
7050 + * ethernet frames.
7052 + dev->rx_urb_size = dev->net->mtu + ETH_HLEN + DM_RX_OVERHEAD + 1;
7054 + dev->mii.dev = dev->net;
7055 + dev->mii.mdio_read = dm9601_mdio_read;
7056 + dev->mii.mdio_write = dm9601_mdio_write;
7057 + dev->mii.phy_id_mask = 0x1f;
7058 + dev->mii.reg_num_mask = 0x1f;
7061 + dm_write_reg(dev, DM_NET_CTRL, 1);
7065 + if (dm_read(dev, DM_PHY_ADDR, ETH_ALEN, mac) < 0) {
7066 + printk(KERN_ERR "Error reading MAC address\n");
7072 + * Overwrite the auto-generated address only with good ones.
7074 + if (is_valid_ether_addr(mac))
7075 + memcpy(dev->net->dev_addr, mac, ETH_ALEN);
7077 + printk(KERN_WARNING
7078 + "dm9601: No valid MAC address in EEPROM, using %pM\n",
7079 + dev->net->dev_addr);
7080 + __dm9601_set_mac_address(dev);
7083 + if (dm_read_reg(dev, DM_CHIP_ID, &id) < 0) {
7084 + netdev_err(dev->net, "Error reading chip ID\n");
7089 + /* put dm9620 devices in dm9601 mode */
7090 + if (id == ID_DM9620) {
7093 + if (dm_read_reg(dev, DM_MODE_CTRL, &mode) < 0) {
7094 + netdev_err(dev->net, "Error reading MODE_CTRL\n");
7098 + dm_write_reg(dev, DM_MODE_CTRL, mode & 0x7f);
7101 + /* power up phy */
7102 + dm_write_reg(dev, DM_GPR_CTRL, 1);
7103 + dm_write_reg(dev, DM_GPR_DATA, 0);
7105 + /* receive broadcast packets */
7106 + dm9601_set_multicast(dev->net);
7108 + dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
7109 + dm9601_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
7110 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
7111 + mii_nway_restart(&dev->mii);
7117 +static int dm9601_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
7124 + b2: packet length (incl crc) low
7125 + b3: packet length (incl crc) high
7126 + b4..n-4: packet data
7127 + bn-3..bn: ethernet crc
7130 + if (unlikely(skb->len < DM_RX_OVERHEAD)) {
7131 + dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
7135 + status = skb->data[0];
7136 + len = (skb->data[1] | (skb->data[2] << 8)) - 4;
7138 + if (unlikely(status & 0xbf)) {
7139 + if (status & 0x01) dev->net->stats.rx_fifo_errors++;
7140 + if (status & 0x02) dev->net->stats.rx_crc_errors++;
7141 + if (status & 0x04) dev->net->stats.rx_frame_errors++;
7142 + if (status & 0x20) dev->net->stats.rx_missed_errors++;
7143 + if (status & 0x90) dev->net->stats.rx_length_errors++;
7148 + skb_trim(skb, len);
7153 +static struct sk_buff *dm9601_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
7159 + b1: packet length low
7160 + b2: packet length high
7161 + b3..n: packet data
7164 + len = skb->len + DM_TX_OVERHEAD;
7166 + /* workaround for dm962x errata with tx fifo getting out of
7167 + * sync if a USB bulk transfer retry happens right after a
7168 + * packet with odd / maxpacket length by adding up to 3 bytes
7171 + while ((len & 1) || !(len % dev->maxpacket))
7174 + len -= DM_TX_OVERHEAD; /* hw header doesn't count as part of length */
7175 + pad = len - skb->len;
7177 + if (skb_headroom(skb) < DM_TX_OVERHEAD || skb_tailroom(skb) < pad) {
7178 + struct sk_buff *skb2;
7180 + skb2 = skb_copy_expand(skb, DM_TX_OVERHEAD, pad, flags);
7181 + dev_kfree_skb_any(skb);
7187 + __skb_push(skb, DM_TX_OVERHEAD);
7190 + memset(skb->data + skb->len, 0, pad);
7191 + __skb_put(skb, pad);
7194 + skb->data[0] = len;
7195 + skb->data[1] = len >> 8;
7200 +static void dm9601_status(struct usbnet *dev, struct urb *urb)
7216 + if (urb->actual_length < 8)
7219 + buf = urb->transfer_buffer;
7221 + link = !!(buf[0] & 0x40);
7222 + if (netif_carrier_ok(dev->net) != link) {
7223 + usbnet_link_change(dev, link, 1);
7224 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
7228 +static int dm9601_link_reset(struct usbnet *dev)
7230 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
7232 + mii_check_media(&dev->mii, 1, 1);
7233 + mii_ethtool_gset(&dev->mii, &ecmd);
7235 + netdev_dbg(dev->net, "link_reset() speed: %u duplex: %d\n",
7236 + ethtool_cmd_speed(&ecmd), ecmd.duplex);
7241 +static const struct driver_info dm9601_info = {
7242 + .description = "Davicom DM96xx USB 10/100 Ethernet",
7243 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
7244 + .bind = dm9601_bind,
7245 + .rx_fixup = dm9601_rx_fixup,
7246 + .tx_fixup = dm9601_tx_fixup,
7247 + .status = dm9601_status,
7248 + .link_reset = dm9601_link_reset,
7249 + .reset = dm9601_link_reset,
7252 +static const struct usb_device_id products[] = {
7254 + USB_DEVICE(0x07aa, 0x9601), /* Corega FEther USB-TXC */
7255 + .driver_info = (unsigned long)&dm9601_info,
7258 + USB_DEVICE(0x0a46, 0x9601), /* Davicom USB-100 */
7259 + .driver_info = (unsigned long)&dm9601_info,
7262 + USB_DEVICE(0x0a46, 0x6688), /* ZT6688 USB NIC */
7263 + .driver_info = (unsigned long)&dm9601_info,
7266 + USB_DEVICE(0x0a46, 0x0268), /* ShanTou ST268 USB NIC */
7267 + .driver_info = (unsigned long)&dm9601_info,
7270 + USB_DEVICE(0x0a46, 0x8515), /* ADMtek ADM8515 USB NIC */
7271 + .driver_info = (unsigned long)&dm9601_info,
7274 + USB_DEVICE(0x0a47, 0x9601), /* Hirose USB-100 */
7275 + .driver_info = (unsigned long)&dm9601_info,
7278 + USB_DEVICE(0x0fe6, 0x8101), /* DM9601 USB to Fast Ethernet Adapter */
7279 + .driver_info = (unsigned long)&dm9601_info,
7282 + USB_DEVICE(0x0fe6, 0x9700), /* DM9601 USB to Fast Ethernet Adapter */
7283 + .driver_info = (unsigned long)&dm9601_info,
7286 + USB_DEVICE(0x0a46, 0x9000), /* DM9000E */
7287 + .driver_info = (unsigned long)&dm9601_info,
7290 + USB_DEVICE(0x0a46, 0x9620), /* DM9620 USB to Fast Ethernet Adapter */
7291 + .driver_info = (unsigned long)&dm9601_info,
7294 + USB_DEVICE(0x0a46, 0x9621), /* DM9621A USB to Fast Ethernet Adapter */
7295 + .driver_info = (unsigned long)&dm9601_info,
7298 + USB_DEVICE(0x0a46, 0x9622), /* DM9622 USB to Fast Ethernet Adapter */
7299 + .driver_info = (unsigned long)&dm9601_info,
7302 + USB_DEVICE(0x0a46, 0x0269), /* DM962OA USB to Fast Ethernet Adapter */
7303 + .driver_info = (unsigned long)&dm9601_info,
7306 + USB_DEVICE(0x0a46, 0x1269), /* DM9621A USB to Fast Ethernet Adapter */
7307 + .driver_info = (unsigned long)&dm9601_info,
7312 +MODULE_DEVICE_TABLE(usb, products);
7314 +static struct usb_driver dm9601_driver = {
7316 + .id_table = products,
7317 + .probe = usbnet_probe,
7318 + .disconnect = usbnet_disconnect,
7319 + .suspend = usbnet_suspend,
7320 + .resume = usbnet_resume,
7321 + .disable_hub_initiated_lpm = 1,
7324 +module_usb_driver(dm9601_driver);
7326 +MODULE_AUTHOR("Peter Korsgaard <jacmet@sunsite.dk>");
7327 +MODULE_DESCRIPTION("Davicom DM96xx USB 10/100 ethernet devices");
7328 +MODULE_LICENSE("GPL");
7329 diff -Naur backports-4.2.6-1.org/drivers/net/usb/gl620a.c backports-4.2.6-1/drivers/net/usb/gl620a.c
7330 --- backports-4.2.6-1.org/drivers/net/usb/gl620a.c 1970-01-01 01:00:00.000000000 +0100
7331 +++ backports-4.2.6-1/drivers/net/usb/gl620a.c 2016-06-28 14:35:17.978640554 +0200
7334 + * GeneSys GL620USB-A based links
7335 + * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
7336 + * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
7338 + * This program is free software; you can redistribute it and/or modify
7339 + * it under the terms of the GNU General Public License as published by
7340 + * the Free Software Foundation; either version 2 of the License, or
7341 + * (at your option) any later version.
7343 + * This program is distributed in the hope that it will be useful,
7344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7346 + * GNU General Public License for more details.
7348 + * You should have received a copy of the GNU General Public License
7349 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
7352 +// #define DEBUG // error path messages, extra info
7353 +// #define VERBOSE // more; success messages
7355 +#include <linux/module.h>
7356 +#include <linux/netdevice.h>
7357 +#include <linux/etherdevice.h>
7358 +#include <linux/ethtool.h>
7359 +#include <linux/workqueue.h>
7360 +#include <linux/mii.h>
7361 +#include <linux/usb.h>
7362 +#include <linux/usb/usbnet.h>
7363 +#include <linux/gfp.h>
7367 + * GeneSys GL620USB-A (www.genesyslogic.com.tw)
7369 + * ... should partially interop with the Win32 driver for this hardware.
7370 + * The GeneSys docs imply there's some NDIS issue motivating this framing.
7372 + * Some info from GeneSys:
7373 + * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
7374 + * (Some cables, like the BAFO-100c, use the half duplex version.)
7375 + * - For the full duplex model, the low bit of the version code says
7376 + * which side is which ("left/right").
7377 + * - For the half duplex type, a control/interrupt handshake settles
7378 + * the transfer direction. (That's disabled here, partially coded.)
7379 + * A control URB would block until other side writes an interrupt.
7381 + * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
7382 + * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
7385 +// control msg write command
7386 +#define GENELINK_CONNECT_WRITE 0xF0
7387 +// interrupt pipe index
7388 +#define GENELINK_INTERRUPT_PIPE 0x03
7389 +// interrupt read buffer size
7390 +#define INTERRUPT_BUFSIZE 0x08
7391 +// interrupt pipe interval value
7392 +#define GENELINK_INTERRUPT_INTERVAL 0x10
7393 +// max transmit packet number per transmit
7394 +#define GL_MAX_TRANSMIT_PACKETS 32
7395 +// max packet length
7396 +#define GL_MAX_PACKET_LEN 1514
7397 +// max receive buffer size
7398 +#define GL_RCV_BUF_SIZE \
7399 + (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
7402 + __le32 packet_length;
7403 + char packet_data [1];
7407 + __le32 packet_count;
7408 + struct gl_packet packets;
7411 +static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
7413 + struct gl_header *header;
7414 + struct gl_packet *packet;
7415 + struct sk_buff *gl_skb;
7419 + /* This check is no longer done by usbnet */
7420 + if (skb->len < dev->net->hard_header_len)
7423 + header = (struct gl_header *) skb->data;
7425 + // get the packet count of the received skb
7426 + count = le32_to_cpu(header->packet_count);
7427 + if (count > GL_MAX_TRANSMIT_PACKETS) {
7428 + netdev_dbg(dev->net,
7429 + "genelink: invalid received packet count %u\n",
7434 + // set the current packet pointer to the first packet
7435 + packet = &header->packets;
7437 + // decrement the length for the packet count size 4 bytes
7440 + while (count > 1) {
7441 + // get the packet length
7442 + size = le32_to_cpu(packet->packet_length);
7444 + // this may be a broken packet
7445 + if (size > GL_MAX_PACKET_LEN) {
7446 + netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
7451 + // allocate the skb for the individual packet
7452 + gl_skb = alloc_skb(size, GFP_ATOMIC);
7455 + // copy the packet data to the new skb
7456 + memcpy(skb_put(gl_skb, size),
7457 + packet->packet_data, size);
7458 + usbnet_skb_return(dev, gl_skb);
7461 + // advance to the next packet
7462 + packet = (struct gl_packet *)&packet->packet_data[size];
7465 + // shift the data pointer to the next gl_packet
7466 + skb_pull(skb, size + 4);
7469 + // skip the packet length field 4 bytes
7472 + if (skb->len > GL_MAX_PACKET_LEN) {
7473 + netdev_dbg(dev->net, "genelink: invalid rx length %d\n",
7480 +static struct sk_buff *
7481 +genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
7484 + int length = skb->len;
7485 + int headroom = skb_headroom(skb);
7486 + int tailroom = skb_tailroom(skb);
7487 + __le32 *packet_count;
7488 + __le32 *packet_len;
7490 + // FIXME: magic numbers, bleech
7491 + padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
7493 + if ((!skb_cloned(skb))
7494 + && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
7495 + if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
7496 + skb->data = memmove(skb->head + (4 + 4*1),
7497 + skb->data, skb->len);
7498 + skb_set_tail_pointer(skb, skb->len);
7501 + struct sk_buff *skb2;
7502 + skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
7503 + dev_kfree_skb_any(skb);
7509 + // attach the packet count to the header
7510 + packet_count = (__le32 *) skb_push(skb, (4 + 4*1));
7511 + packet_len = packet_count + 1;
7513 + *packet_count = cpu_to_le32(1);
7514 + *packet_len = cpu_to_le32(length);
7516 + // add padding byte
7517 + if ((skb->len % dev->maxpacket) == 0)
7523 +static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
7525 + dev->hard_mtu = GL_RCV_BUF_SIZE;
7526 + dev->net->hard_header_len += 4;
7527 + dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
7528 + dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
7532 +static const struct driver_info genelink_info = {
7533 + .description = "Genesys GeneLink",
7534 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_GL | FLAG_NO_SETINT,
7535 + .bind = genelink_bind,
7536 + .rx_fixup = genelink_rx_fixup,
7537 + .tx_fixup = genelink_tx_fixup,
7539 + .in = 1, .out = 2,
7541 +#ifdef GENELINK_ACK
7542 + .check_connect =genelink_check_connect,
7546 +static const struct usb_device_id products [] = {
7549 + USB_DEVICE(0x05e3, 0x0502), // GL620USB-A
7550 + .driver_info = (unsigned long) &genelink_info,
7552 + /* NOT: USB_DEVICE(0x05e3, 0x0501), // GL620USB
7553 + * that's half duplex, not currently supported
7557 +MODULE_DEVICE_TABLE(usb, products);
7559 +static struct usb_driver gl620a_driver = {
7561 + .id_table = products,
7562 + .probe = usbnet_probe,
7563 + .disconnect = usbnet_disconnect,
7564 + .suspend = usbnet_suspend,
7565 + .resume = usbnet_resume,
7566 + .disable_hub_initiated_lpm = 1,
7569 +module_usb_driver(gl620a_driver);
7571 +MODULE_AUTHOR("Jiun-Jie Huang");
7572 +MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
7573 +MODULE_LICENSE("GPL");
7575 diff -Naur backports-4.2.6-1.org/drivers/net/usb/hso.c backports-4.2.6-1/drivers/net/usb/hso.c
7576 --- backports-4.2.6-1.org/drivers/net/usb/hso.c 1970-01-01 01:00:00.000000000 +0100
7577 +++ backports-4.2.6-1/drivers/net/usb/hso.c 2016-06-28 14:35:17.981973887 +0200
7579 +/******************************************************************************
7581 + * Driver for Option High Speed Mobile Devices.
7583 + * Copyright (C) 2008 Option International
7584 + * Filip Aben <f.aben@option.com>
7585 + * Denis Joseph Barrow <d.barow@option.com>
7586 + * Jan Dumon <j.dumon@option.com>
7587 + * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
7588 + * <ajb@spheresystems.co.uk>
7589 + * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
7590 + * Copyright (C) 2008 Novell, Inc.
7592 + * This program is free software; you can redistribute it and/or modify
7593 + * it under the terms of the GNU General Public License version 2 as
7594 + * published by the Free Software Foundation.
7596 + * This program is distributed in the hope that it will be useful,
7597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7599 + * GNU General Public License for more details.
7601 + * You should have received a copy of the GNU General Public License
7602 + * along with this program; if not, write to the Free Software
7603 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
7607 + *****************************************************************************/
7609 +/******************************************************************************
7611 + * Description of the device:
7613 + * Interface 0: Contains the IP network interface on the bulk end points.
7614 + * The multiplexed serial ports are using the interrupt and
7615 + * control endpoints.
7616 + * Interrupt contains a bitmap telling which multiplexed
7617 + * serialport needs servicing.
7619 + * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the
7620 + * port is opened, as this have a huge impact on the network port
7623 + * Interface 2: Standard modem interface - circuit switched interface, this
7624 + * can be used to make a standard ppp connection however it
7625 + * should not be used in conjunction with the IP network interface
7626 + * enabled for USB performance reasons i.e. if using this set
7627 + * ideally disable_net=1.
7629 + *****************************************************************************/
7631 +#include <linux/sched.h>
7632 +#include <linux/slab.h>
7633 +#include <linux/init.h>
7634 +#include <linux/delay.h>
7635 +#include <linux/netdevice.h>
7636 +#include <linux/module.h>
7637 +#include <linux/ethtool.h>
7638 +#include <linux/usb.h>
7639 +#include <linux/tty.h>
7640 +#include <linux/tty_driver.h>
7641 +#include <linux/tty_flip.h>
7642 +#include <linux/kmod.h>
7643 +#include <linux/rfkill.h>
7644 +#include <linux/ip.h>
7645 +#include <linux/uaccess.h>
7646 +#include <linux/usb/cdc.h>
7647 +#include <net/arp.h>
7648 +#include <asm/byteorder.h>
7649 +#include <linux/serial_core.h>
7650 +#include <linux/serial.h>
7651 +#include <asm/local.h>
7653 +#define MOD_AUTHOR "Option Wireless"
7654 +#define MOD_DESCRIPTION "USB High Speed Option driver"
7655 +#define MOD_LICENSE "GPL"
7657 +#define HSO_MAX_NET_DEVICES 10
7658 +#define HSO__MAX_MTU 2048
7659 +#define DEFAULT_MTU 1500
7660 +#define DEFAULT_MRU 1500
7662 +#define CTRL_URB_RX_SIZE 1024
7663 +#define CTRL_URB_TX_SIZE 64
7665 +#define BULK_URB_RX_SIZE 4096
7666 +#define BULK_URB_TX_SIZE 8192
7668 +#define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
7669 +#define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
7670 +#define MUX_BULK_RX_BUF_COUNT 4
7671 +#define USB_TYPE_OPTION_VENDOR 0x20
7673 +/* These definitions are used with the struct hso_net flags element */
7674 +/* - use *_bit operations on it. (bit indices not values.) */
7675 +#define HSO_NET_RUNNING 0
7677 +#define HSO_NET_TX_TIMEOUT (HZ*10)
7679 +#define HSO_SERIAL_MAGIC 0x48534f31
7681 +/* Number of ttys to handle */
7682 +#define HSO_SERIAL_TTY_MINORS 256
7684 +#define MAX_RX_URBS 2
7686 +/*****************************************************************************/
7687 +/* Debugging functions */
7688 +/*****************************************************************************/
7689 +#define D__(lvl_, fmt, arg...) \
7691 + printk(lvl_ "[%d:%s]: " fmt "\n", \
7692 + __LINE__, __func__, ## arg); \
7695 +#define D_(lvl, args...) \
7697 + if (lvl & debug) \
7698 + D__(KERN_INFO, args); \
7701 +#define D1(args...) D_(0x01, ##args)
7702 +#define D2(args...) D_(0x02, ##args)
7703 +#define D3(args...) D_(0x04, ##args)
7704 +#define D4(args...) D_(0x08, ##args)
7705 +#define D5(args...) D_(0x10, ##args)
7707 +/*****************************************************************************/
7709 +/*****************************************************************************/
7710 +enum pkt_parse_state {
7716 +/*****************************************************************************/
7718 +/*****************************************************************************/
7720 +struct hso_shared_int {
7721 + struct usb_endpoint_descriptor *intr_endp;
7722 + void *shared_intr_buf;
7723 + struct urb *shared_intr_urb;
7724 + struct usb_device *usb;
7727 + struct mutex shared_int_lock;
7731 + struct hso_device *parent;
7732 + struct net_device *net;
7733 + struct rfkill *rfkill;
7736 + struct usb_endpoint_descriptor *in_endp;
7737 + struct usb_endpoint_descriptor *out_endp;
7739 + struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT];
7740 + struct urb *mux_bulk_tx_urb;
7741 + void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT];
7742 + void *mux_bulk_tx_buf;
7744 + struct sk_buff *skb_rx_buf;
7745 + struct sk_buff *skb_tx_buf;
7747 + enum pkt_parse_state rx_parse_state;
7748 + spinlock_t net_lock;
7750 + unsigned short rx_buf_size;
7751 + unsigned short rx_buf_missing;
7752 + struct iphdr rx_ip_hdr;
7754 + unsigned long flags;
7757 +enum rx_ctrl_state{
7763 +#define BM_REQUEST_TYPE (0xa1)
7764 +#define B_NOTIFICATION (0x20)
7765 +#define W_VALUE (0x0)
7766 +#define W_LENGTH (0x2)
7768 +#define B_OVERRUN (0x1<<6)
7769 +#define B_PARITY (0x1<<5)
7770 +#define B_FRAMING (0x1<<4)
7771 +#define B_RING_SIGNAL (0x1<<3)
7772 +#define B_BREAK (0x1<<2)
7773 +#define B_TX_CARRIER (0x1<<1)
7774 +#define B_RX_CARRIER (0x1<<0)
7776 +struct hso_serial_state_notification {
7782 + u16 UART_state_bitmap;
7785 +struct hso_tiocmget {
7786 + struct mutex mutex;
7787 + wait_queue_head_t waitq;
7788 + int intr_completed;
7789 + struct usb_endpoint_descriptor *endp;
7791 + struct hso_serial_state_notification serial_state_notification;
7792 + u16 prev_UART_state_bitmap;
7793 + struct uart_icount icount;
7797 +struct hso_serial {
7798 + struct hso_device *parent;
7802 + struct hso_shared_int *shared_int;
7804 + /* rx/tx urb could be either a bulk urb or a control urb depending
7805 + on which serial port it is used on. */
7806 + struct urb *rx_urb[MAX_RX_URBS];
7808 + u8 *rx_data[MAX_RX_URBS];
7809 + u16 rx_data_length; /* should contain allocated length */
7811 + struct urb *tx_urb;
7814 + u16 tx_data_length; /* should contain allocated length */
7815 + u16 tx_data_count;
7816 + u16 tx_buffer_count;
7817 + struct usb_ctrlrequest ctrl_req_tx;
7818 + struct usb_ctrlrequest ctrl_req_rx;
7820 + struct usb_endpoint_descriptor *in_endp;
7821 + struct usb_endpoint_descriptor *out_endp;
7823 + enum rx_ctrl_state rx_state;
7826 + unsigned tx_urb_used:1;
7828 + struct tty_port port;
7829 + /* from usb_serial_port */
7830 + spinlock_t serial_lock;
7832 + int (*write_data) (struct hso_serial *serial);
7833 + struct hso_tiocmget *tiocmget;
7834 + /* Hacks required to get flow control
7835 + * working on the serial receive buffers
7836 + * so as not to drop characters on the floor.
7838 + int curr_rx_urb_idx;
7839 + u8 rx_urb_filled[MAX_RX_URBS];
7840 + struct tasklet_struct unthrottle_tasklet;
7843 +struct hso_device {
7845 + struct hso_serial *dev_serial;
7846 + struct hso_net *dev_net;
7853 + struct work_struct async_get_intf;
7854 + struct work_struct async_put_intf;
7856 + struct usb_device *usb;
7857 + struct usb_interface *interface;
7859 + struct device *dev;
7861 + struct mutex mutex;
7864 +/* Type of interface */
7865 +#define HSO_INTF_MASK 0xFF00
7866 +#define HSO_INTF_MUX 0x0100
7867 +#define HSO_INTF_BULK 0x0200
7870 +#define HSO_PORT_MASK 0xFF
7871 +#define HSO_PORT_NO_PORT 0x0
7872 +#define HSO_PORT_CONTROL 0x1
7873 +#define HSO_PORT_APP 0x2
7874 +#define HSO_PORT_GPS 0x3
7875 +#define HSO_PORT_PCSC 0x4
7876 +#define HSO_PORT_APP2 0x5
7877 +#define HSO_PORT_GPS_CONTROL 0x6
7878 +#define HSO_PORT_MSD 0x7
7879 +#define HSO_PORT_VOICE 0x8
7880 +#define HSO_PORT_DIAG2 0x9
7881 +#define HSO_PORT_DIAG 0x10
7882 +#define HSO_PORT_MODEM 0x11
7883 +#define HSO_PORT_NETWORK 0x12
7885 +/* Additional device info */
7886 +#define HSO_INFO_MASK 0xFF000000
7887 +#define HSO_INFO_CRC_BUG 0x01000000
7889 +/*****************************************************************************/
7891 +/*****************************************************************************/
7892 +/* Serial driver functions */
7893 +static int hso_serial_tiocmset(struct tty_struct *tty,
7894 + unsigned int set, unsigned int clear);
7895 +static void ctrl_callback(struct urb *urb);
7896 +static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial);
7897 +static void hso_kick_transmit(struct hso_serial *serial);
7898 +/* Helper functions */
7899 +static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int,
7900 + struct usb_device *usb, gfp_t gfp);
7901 +static void handle_usb_error(int status, const char *function,
7902 + struct hso_device *hso_dev);
7903 +static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
7904 + int type, int dir);
7905 +static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports);
7906 +static void hso_free_interface(struct usb_interface *intf);
7907 +static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags);
7908 +static int hso_stop_serial_device(struct hso_device *hso_dev);
7909 +static int hso_start_net_device(struct hso_device *hso_dev);
7910 +static void hso_free_shared_int(struct hso_shared_int *shared_int);
7911 +static int hso_stop_net_device(struct hso_device *hso_dev);
7912 +static void hso_serial_ref_free(struct kref *ref);
7913 +static void hso_std_serial_read_bulk_callback(struct urb *urb);
7914 +static int hso_mux_serial_read(struct hso_serial *serial);
7915 +static void async_get_intf(struct work_struct *data);
7916 +static void async_put_intf(struct work_struct *data);
7917 +static int hso_put_activity(struct hso_device *hso_dev);
7918 +static int hso_get_activity(struct hso_device *hso_dev);
7919 +static void tiocmget_intr_callback(struct urb *urb);
7920 +/*****************************************************************************/
7921 +/* Helping functions */
7922 +/*****************************************************************************/
7924 +/* #define DEBUG */
7926 +static inline struct hso_net *dev2net(struct hso_device *hso_dev)
7928 + return hso_dev->port_data.dev_net;
7931 +static inline struct hso_serial *dev2ser(struct hso_device *hso_dev)
7933 + return hso_dev->port_data.dev_serial;
7936 +/* Debugging functions */
7938 +static void dbg_dump(int line_count, const char *func_name, unsigned char *buf,
7941 + static char name[255];
7943 + sprintf(name, "hso[%d:%s]", line_count, func_name);
7944 + print_hex_dump_bytes(name, DUMP_PREFIX_NONE, buf, len);
7947 +#define DUMP(buf_, len_) \
7948 + dbg_dump(__LINE__, __func__, (unsigned char *)buf_, len_)
7950 +#define DUMP1(buf_, len_) \
7952 + if (0x01 & debug) \
7953 + DUMP(buf_, len_); \
7956 +#define DUMP(buf_, len_)
7957 +#define DUMP1(buf_, len_)
7960 +/* module parameters */
7962 +static int tty_major;
7963 +static int disable_net;
7966 +static const char driver_name[] = "hso";
7967 +static const char tty_filename[] = "ttyHS";
7968 +static const char *version = __FILE__ ": " MOD_AUTHOR;
7969 +/* the usb driver itself (registered in hso_init) */
7970 +static struct usb_driver hso_driver;
7971 +/* serial structures */
7972 +static struct tty_driver *tty_drv;
7973 +static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS];
7974 +static struct hso_device *network_table[HSO_MAX_NET_DEVICES];
7975 +static spinlock_t serial_table_lock;
7977 +static const s32 default_port_spec[] = {
7978 + HSO_INTF_MUX | HSO_PORT_NETWORK,
7979 + HSO_INTF_BULK | HSO_PORT_DIAG,
7980 + HSO_INTF_BULK | HSO_PORT_MODEM,
7984 +static const s32 icon321_port_spec[] = {
7985 + HSO_INTF_MUX | HSO_PORT_NETWORK,
7986 + HSO_INTF_BULK | HSO_PORT_DIAG2,
7987 + HSO_INTF_BULK | HSO_PORT_MODEM,
7988 + HSO_INTF_BULK | HSO_PORT_DIAG,
7992 +#define default_port_device(vendor, product) \
7993 + USB_DEVICE(vendor, product), \
7994 + .driver_info = (kernel_ulong_t)default_port_spec
7996 +#define icon321_port_device(vendor, product) \
7997 + USB_DEVICE(vendor, product), \
7998 + .driver_info = (kernel_ulong_t)icon321_port_spec
8000 +/* list of devices we support */
8001 +static const struct usb_device_id hso_ids[] = {
8002 + {default_port_device(0x0af0, 0x6711)},
8003 + {default_port_device(0x0af0, 0x6731)},
8004 + {default_port_device(0x0af0, 0x6751)},
8005 + {default_port_device(0x0af0, 0x6771)},
8006 + {default_port_device(0x0af0, 0x6791)},
8007 + {default_port_device(0x0af0, 0x6811)},
8008 + {default_port_device(0x0af0, 0x6911)},
8009 + {default_port_device(0x0af0, 0x6951)},
8010 + {default_port_device(0x0af0, 0x6971)},
8011 + {default_port_device(0x0af0, 0x7011)},
8012 + {default_port_device(0x0af0, 0x7031)},
8013 + {default_port_device(0x0af0, 0x7051)},
8014 + {default_port_device(0x0af0, 0x7071)},
8015 + {default_port_device(0x0af0, 0x7111)},
8016 + {default_port_device(0x0af0, 0x7211)},
8017 + {default_port_device(0x0af0, 0x7251)},
8018 + {default_port_device(0x0af0, 0x7271)},
8019 + {default_port_device(0x0af0, 0x7311)},
8020 + {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
8021 + {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */
8022 + {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
8023 + {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */
8024 + {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */
8025 + {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */
8026 + {USB_DEVICE(0x0af0, 0x7381)}, /* GE40x */
8027 + {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */
8028 + {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */
8029 + {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */
8030 + {USB_DEVICE(0x0af0, 0x7701)},
8031 + {USB_DEVICE(0x0af0, 0x7706)},
8032 + {USB_DEVICE(0x0af0, 0x7801)},
8033 + {USB_DEVICE(0x0af0, 0x7901)},
8034 + {USB_DEVICE(0x0af0, 0x7A01)},
8035 + {USB_DEVICE(0x0af0, 0x7A05)},
8036 + {USB_DEVICE(0x0af0, 0x8200)},
8037 + {USB_DEVICE(0x0af0, 0x8201)},
8038 + {USB_DEVICE(0x0af0, 0x8300)},
8039 + {USB_DEVICE(0x0af0, 0x8302)},
8040 + {USB_DEVICE(0x0af0, 0x8304)},
8041 + {USB_DEVICE(0x0af0, 0x8400)},
8042 + {USB_DEVICE(0x0af0, 0x8600)},
8043 + {USB_DEVICE(0x0af0, 0x8800)},
8044 + {USB_DEVICE(0x0af0, 0x8900)},
8045 + {USB_DEVICE(0x0af0, 0x9000)},
8046 + {USB_DEVICE(0x0af0, 0x9200)}, /* Option GTM671WFS */
8047 + {USB_DEVICE(0x0af0, 0xd035)},
8048 + {USB_DEVICE(0x0af0, 0xd055)},
8049 + {USB_DEVICE(0x0af0, 0xd155)},
8050 + {USB_DEVICE(0x0af0, 0xd255)},
8051 + {USB_DEVICE(0x0af0, 0xd057)},
8052 + {USB_DEVICE(0x0af0, 0xd157)},
8053 + {USB_DEVICE(0x0af0, 0xd257)},
8054 + {USB_DEVICE(0x0af0, 0xd357)},
8055 + {USB_DEVICE(0x0af0, 0xd058)},
8056 + {USB_DEVICE(0x0af0, 0xc100)},
8059 +MODULE_DEVICE_TABLE(usb, hso_ids);
8061 +/* Sysfs attribute */
8062 +static ssize_t hso_sysfs_show_porttype(struct device *dev,
8063 + struct device_attribute *attr,
8066 + struct hso_device *hso_dev = dev_get_drvdata(dev);
8072 + switch (hso_dev->port_spec & HSO_PORT_MASK) {
8073 + case HSO_PORT_CONTROL:
8074 + port_name = "Control";
8076 + case HSO_PORT_APP:
8077 + port_name = "Application";
8079 + case HSO_PORT_APP2:
8080 + port_name = "Application2";
8082 + case HSO_PORT_GPS:
8083 + port_name = "GPS";
8085 + case HSO_PORT_GPS_CONTROL:
8086 + port_name = "GPS Control";
8088 + case HSO_PORT_PCSC:
8089 + port_name = "PCSC";
8091 + case HSO_PORT_DIAG:
8092 + port_name = "Diagnostic";
8094 + case HSO_PORT_DIAG2:
8095 + port_name = "Diagnostic2";
8097 + case HSO_PORT_MODEM:
8098 + port_name = "Modem";
8100 + case HSO_PORT_NETWORK:
8101 + port_name = "Network";
8104 + port_name = "Unknown";
8108 + return sprintf(buf, "%s\n", port_name);
8110 +static DEVICE_ATTR(hsotype, S_IRUGO, hso_sysfs_show_porttype, NULL);
8112 +static struct attribute *hso_serial_dev_attrs[] = {
8113 + &dev_attr_hsotype.attr,
8117 +ATTRIBUTE_GROUPS(hso_serial_dev);
8119 +static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb)
8123 + for (idx = 0; idx < serial->num_rx_urbs; idx++)
8124 + if (serial->rx_urb[idx] == urb)
8126 + dev_err(serial->parent->dev, "hso_urb_to_index failed\n");
8130 +/* converts mux value to a port spec value */
8131 +static u32 hso_mux_to_port(int mux)
8137 + result = HSO_PORT_CONTROL;
8140 + result = HSO_PORT_APP;
8143 + result = HSO_PORT_PCSC;
8146 + result = HSO_PORT_GPS;
8149 + result = HSO_PORT_APP2;
8152 + result = HSO_PORT_NO_PORT;
8157 +/* converts port spec value to a mux value */
8158 +static u32 hso_port_to_mux(int port)
8162 + switch (port & HSO_PORT_MASK) {
8163 + case HSO_PORT_CONTROL:
8166 + case HSO_PORT_APP:
8169 + case HSO_PORT_PCSC:
8172 + case HSO_PORT_GPS:
8175 + case HSO_PORT_APP2:
8184 +static struct hso_serial *get_serial_by_shared_int_and_type(
8185 + struct hso_shared_int *shared_int,
8190 + port = hso_mux_to_port(mux);
8192 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
8193 + if (serial_table[i] &&
8194 + (dev2ser(serial_table[i])->shared_int == shared_int) &&
8195 + ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) {
8196 + return dev2ser(serial_table[i]);
8203 +static struct hso_serial *get_serial_by_index(unsigned index)
8205 + struct hso_serial *serial = NULL;
8206 + unsigned long flags;
8208 + spin_lock_irqsave(&serial_table_lock, flags);
8209 + if (serial_table[index])
8210 + serial = dev2ser(serial_table[index]);
8211 + spin_unlock_irqrestore(&serial_table_lock, flags);
8216 +static int get_free_serial_index(void)
8219 + unsigned long flags;
8221 + spin_lock_irqsave(&serial_table_lock, flags);
8222 + for (index = 0; index < HSO_SERIAL_TTY_MINORS; index++) {
8223 + if (serial_table[index] == NULL) {
8224 + spin_unlock_irqrestore(&serial_table_lock, flags);
8228 + spin_unlock_irqrestore(&serial_table_lock, flags);
8230 + printk(KERN_ERR "%s: no free serial devices in table\n", __func__);
8234 +static void set_serial_by_index(unsigned index, struct hso_serial *serial)
8236 + unsigned long flags;
8238 + spin_lock_irqsave(&serial_table_lock, flags);
8240 + serial_table[index] = serial->parent;
8242 + serial_table[index] = NULL;
8243 + spin_unlock_irqrestore(&serial_table_lock, flags);
8246 +static void handle_usb_error(int status, const char *function,
8247 + struct hso_device *hso_dev)
8249 + char *explanation;
8253 + explanation = "no device";
8256 + explanation = "endpoint not enabled";
8259 + explanation = "endpoint stalled";
8262 + explanation = "not enough bandwidth";
8265 + explanation = "device disabled";
8267 + case -EHOSTUNREACH:
8268 + explanation = "device suspended";
8274 + explanation = "internal error";
8280 + explanation = "protocol error";
8282 + usb_queue_reset_device(hso_dev->interface);
8285 + explanation = "unknown status";
8289 + /* log a meaningful explanation of an USB status */
8290 + D1("%s: received USB status - %s (%d)", function, explanation, status);
8293 +/* Network interface functions */
8295 +/* called when net interface is brought up by ifconfig */
8296 +static int hso_net_open(struct net_device *net)
8298 + struct hso_net *odev = netdev_priv(net);
8299 + unsigned long flags = 0;
8302 + dev_err(&net->dev, "No net device !\n");
8306 + odev->skb_tx_buf = NULL;
8308 + /* setup environment */
8309 + spin_lock_irqsave(&odev->net_lock, flags);
8310 + odev->rx_parse_state = WAIT_IP;
8311 + odev->rx_buf_size = 0;
8312 + odev->rx_buf_missing = sizeof(struct iphdr);
8313 + spin_unlock_irqrestore(&odev->net_lock, flags);
8315 + /* We are up and running. */
8316 + set_bit(HSO_NET_RUNNING, &odev->flags);
8317 + hso_start_net_device(odev->parent);
8319 + /* Tell the kernel we are ready to start receiving from it */
8320 + netif_start_queue(net);
8325 +/* called when interface is brought down by ifconfig */
8326 +static int hso_net_close(struct net_device *net)
8328 + struct hso_net *odev = netdev_priv(net);
8330 + /* we don't need the queue anymore */
8331 + netif_stop_queue(net);
8332 + /* no longer running */
8333 + clear_bit(HSO_NET_RUNNING, &odev->flags);
8335 + hso_stop_net_device(odev->parent);
8341 +/* USB tells is xmit done, we should start the netqueue again */
8342 +static void write_bulk_callback(struct urb *urb)
8344 + struct hso_net *odev = urb->context;
8345 + int status = urb->status;
8347 + /* Sanity check */
8348 + if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
8349 + dev_err(&urb->dev->dev, "%s: device not running\n", __func__);
8353 + /* Do we still have a valid kernel network device? */
8354 + if (!netif_device_present(odev->net)) {
8355 + dev_err(&urb->dev->dev, "%s: net device not present\n",
8360 + /* log status, but don't act on it, we don't need to resubmit anything
8363 + handle_usb_error(status, __func__, odev->parent);
8365 + hso_put_activity(odev->parent);
8367 + /* Tell the network interface we are ready for another frame */
8368 + netif_wake_queue(odev->net);
8371 +/* called by kernel when we need to transmit a packet */
8372 +static netdev_tx_t hso_net_start_xmit(struct sk_buff *skb,
8373 + struct net_device *net)
8375 + struct hso_net *odev = netdev_priv(net);
8378 + /* Tell the kernel, "No more frames 'til we are done with this one." */
8379 + netif_stop_queue(net);
8380 + if (hso_get_activity(odev->parent) == -EAGAIN) {
8381 + odev->skb_tx_buf = skb;
8382 + return NETDEV_TX_OK;
8385 + /* log if asked */
8386 + DUMP1(skb->data, skb->len);
8387 + /* Copy it from kernel memory to OUR memory */
8388 + memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len);
8389 + D1("len: %d/%d", skb->len, MUX_BULK_TX_BUF_SIZE);
8391 + /* Fill in the URB for shipping it out. */
8392 + usb_fill_bulk_urb(odev->mux_bulk_tx_urb,
8393 + odev->parent->usb,
8394 + usb_sndbulkpipe(odev->parent->usb,
8396 + bEndpointAddress & 0x7F),
8397 + odev->mux_bulk_tx_buf, skb->len, write_bulk_callback,
8400 + /* Deal with the Zero Length packet problem, I hope */
8401 + odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET;
8403 + /* Send the URB on its merry way. */
8404 + result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC);
8406 + dev_warn(&odev->parent->interface->dev,
8407 + "failed mux_bulk_tx_urb %d\n", result);
8408 + net->stats.tx_errors++;
8409 + netif_start_queue(net);
8411 + net->stats.tx_packets++;
8412 + net->stats.tx_bytes += skb->len;
8414 + dev_kfree_skb(skb);
8416 + return NETDEV_TX_OK;
8419 +static const struct ethtool_ops ops = {
8420 + .get_link = ethtool_op_get_link
8423 +/* called when a packet did not ack after watchdogtimeout */
8424 +static void hso_net_tx_timeout(struct net_device *net)
8426 + struct hso_net *odev = netdev_priv(net);
8431 + /* Tell syslog we are hosed. */
8432 + dev_warn(&net->dev, "Tx timed out.\n");
8434 + /* Tear the waiting frame off the list */
8435 + if (odev->mux_bulk_tx_urb &&
8436 + (odev->mux_bulk_tx_urb->status == -EINPROGRESS))
8437 + usb_unlink_urb(odev->mux_bulk_tx_urb);
8439 + /* Update statistics */
8440 + net->stats.tx_errors++;
8443 +/* make a real packet from the received USB buffer */
8444 +static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt,
8445 + unsigned int count, unsigned char is_eop)
8447 + unsigned short temp_bytes;
8448 + unsigned short buffer_offset = 0;
8449 + unsigned short frame_len;
8450 + unsigned char *tmp_rx_buf;
8452 + /* log if needed */
8453 + D1("Rx %d bytes", count);
8454 + DUMP(ip_pkt, min(128, (int)count));
8457 + switch (odev->rx_parse_state) {
8459 + /* waiting for IP header. */
8460 + /* wanted bytes - size of ip header */
8463 + odev->rx_buf_missing) ? count : odev->
8466 + memcpy(((unsigned char *)(&odev->rx_ip_hdr)) +
8467 + odev->rx_buf_size, ip_pkt + buffer_offset,
8470 + odev->rx_buf_size += temp_bytes;
8471 + buffer_offset += temp_bytes;
8472 + odev->rx_buf_missing -= temp_bytes;
8473 + count -= temp_bytes;
8475 + if (!odev->rx_buf_missing) {
8476 + /* header is complete allocate an sk_buffer and
8477 + * continue to WAIT_DATA */
8478 + frame_len = ntohs(odev->rx_ip_hdr.tot_len);
8480 + if ((frame_len > DEFAULT_MRU) ||
8481 + (frame_len < sizeof(struct iphdr))) {
8482 + dev_err(&odev->net->dev,
8483 + "Invalid frame (%d) length\n",
8485 + odev->rx_parse_state = WAIT_SYNC;
8488 + /* Allocate an sk_buff */
8489 + odev->skb_rx_buf = netdev_alloc_skb(odev->net,
8491 + if (!odev->skb_rx_buf) {
8492 + /* We got no receive buffer. */
8493 + D1("could not allocate memory");
8494 + odev->rx_parse_state = WAIT_SYNC;
8498 + /* Copy what we got so far. make room for iphdr
8501 + skb_put(odev->skb_rx_buf,
8502 + sizeof(struct iphdr));
8503 + memcpy(tmp_rx_buf, (char *)&(odev->rx_ip_hdr),
8504 + sizeof(struct iphdr));
8507 + odev->rx_buf_size = sizeof(struct iphdr);
8509 + /* Filip actually use .tot_len */
8510 + odev->rx_buf_missing =
8511 + frame_len - sizeof(struct iphdr);
8512 + odev->rx_parse_state = WAIT_DATA;
8517 + temp_bytes = (count < odev->rx_buf_missing)
8518 + ? count : odev->rx_buf_missing;
8520 + /* Copy the rest of the bytes that are left in the
8521 + * buffer into the waiting sk_buf. */
8522 + /* Make room for temp_bytes after tail. */
8523 + tmp_rx_buf = skb_put(odev->skb_rx_buf, temp_bytes);
8524 + memcpy(tmp_rx_buf, ip_pkt + buffer_offset, temp_bytes);
8526 + odev->rx_buf_missing -= temp_bytes;
8527 + count -= temp_bytes;
8528 + buffer_offset += temp_bytes;
8529 + odev->rx_buf_size += temp_bytes;
8530 + if (!odev->rx_buf_missing) {
8531 + /* Packet is complete. Inject into stack. */
8532 + /* We have IP packet here */
8533 + odev->skb_rx_buf->protocol = cpu_to_be16(ETH_P_IP);
8534 + skb_reset_mac_header(odev->skb_rx_buf);
8536 + /* Ship it off to the kernel */
8537 + netif_rx(odev->skb_rx_buf);
8538 + /* No longer our buffer. */
8539 + odev->skb_rx_buf = NULL;
8541 + /* update out statistics */
8542 + odev->net->stats.rx_packets++;
8544 + odev->net->stats.rx_bytes += odev->rx_buf_size;
8546 + odev->rx_buf_size = 0;
8547 + odev->rx_buf_missing = sizeof(struct iphdr);
8548 + odev->rx_parse_state = WAIT_IP;
8563 + /* Recovery mechanism for WAIT_SYNC state. */
8565 + if (odev->rx_parse_state == WAIT_SYNC) {
8566 + odev->rx_parse_state = WAIT_IP;
8567 + odev->rx_buf_size = 0;
8568 + odev->rx_buf_missing = sizeof(struct iphdr);
8573 +static void fix_crc_bug(struct urb *urb, __le16 max_packet_size)
8575 + static const u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
8576 + u32 rest = urb->actual_length % le16_to_cpu(max_packet_size);
8578 + if (((rest == 5) || (rest == 6)) &&
8579 + !memcmp(((u8 *)urb->transfer_buffer) + urb->actual_length - 4,
8581 + urb->actual_length -= 4;
8585 +/* Moving data from usb to kernel (in interrupt state) */
8586 +static void read_bulk_callback(struct urb *urb)
8588 + struct hso_net *odev = urb->context;
8589 + struct net_device *net;
8591 + int status = urb->status;
8593 + /* is al ok? (Filip: Who's Al ?) */
8595 + handle_usb_error(status, __func__, odev->parent);
8599 + /* Sanity check */
8600 + if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) {
8601 + D1("BULK IN callback but driver is not active!");
8604 + usb_mark_last_busy(urb->dev);
8608 + if (!netif_device_present(net)) {
8609 + /* Somebody killed our network interface... */
8613 + if (odev->parent->port_spec & HSO_INFO_CRC_BUG)
8614 + fix_crc_bug(urb, odev->in_endp->wMaxPacketSize);
8616 + /* do we even have a packet? */
8617 + if (urb->actual_length) {
8618 + /* Handle the IP stream, add header and push it onto network
8619 + * stack if the packet is complete. */
8620 + spin_lock(&odev->net_lock);
8621 + packetizeRx(odev, urb->transfer_buffer, urb->actual_length,
8622 + (urb->transfer_buffer_length >
8623 + urb->actual_length) ? 1 : 0);
8624 + spin_unlock(&odev->net_lock);
8627 + /* We are done with this URB, resubmit it. Prep the USB to wait for
8628 + * another frame. Reuse same as received. */
8629 + usb_fill_bulk_urb(urb,
8630 + odev->parent->usb,
8631 + usb_rcvbulkpipe(odev->parent->usb,
8633 + bEndpointAddress & 0x7F),
8634 + urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE,
8635 + read_bulk_callback, odev);
8637 + /* Give this to the USB subsystem so it can tell us when more data
8639 + result = usb_submit_urb(urb, GFP_ATOMIC);
8641 + dev_warn(&odev->parent->interface->dev,
8642 + "%s failed submit mux_bulk_rx_urb %d\n", __func__,
8646 +/* Serial driver functions */
8648 +static void hso_init_termios(struct ktermios *termios)
8651 + * The default requirements for this device are:
8653 + termios->c_iflag &=
8654 + ~(IGNBRK /* disable ignore break */
8655 + | BRKINT /* disable break causes interrupt */
8656 + | PARMRK /* disable mark parity errors */
8657 + | ISTRIP /* disable clear high bit of input characters */
8658 + | INLCR /* disable translate NL to CR */
8659 + | IGNCR /* disable ignore CR */
8660 + | ICRNL /* disable translate CR to NL */
8661 + | IXON); /* disable enable XON/XOFF flow control */
8663 + /* disable postprocess output characters */
8664 + termios->c_oflag &= ~OPOST;
8666 + termios->c_lflag &=
8667 + ~(ECHO /* disable echo input characters */
8668 + | ECHONL /* disable echo new line */
8669 + | ICANON /* disable erase, kill, werase, and rprnt
8670 + special characters */
8671 + | ISIG /* disable interrupt, quit, and suspend special
8673 + | IEXTEN); /* disable non-POSIX special characters */
8675 + termios->c_cflag &=
8676 + ~(CSIZE /* no size */
8677 + | PARENB /* disable parity bit */
8678 + | CBAUD /* clear current baud rate */
8679 + | CBAUDEX); /* clear current buad rate */
8681 + termios->c_cflag |= CS8; /* character size 8 bits */
8683 + /* baud rate 115200 */
8684 + tty_termios_encode_baud_rate(termios, 115200, 115200);
8687 +static void _hso_serial_set_termios(struct tty_struct *tty,
8688 + struct ktermios *old)
8690 + struct hso_serial *serial = tty->driver_data;
8693 + printk(KERN_ERR "%s: no tty structures", __func__);
8697 + D4("port %d", serial->minor);
8700 + * Fix up unsupported bits
8702 + tty->termios.c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */
8704 + tty->termios.c_cflag &=
8705 + ~(CSIZE /* no size */
8706 + | PARENB /* disable parity bit */
8707 + | CBAUD /* clear current baud rate */
8708 + | CBAUDEX); /* clear current buad rate */
8710 + tty->termios.c_cflag |= CS8; /* character size 8 bits */
8712 + /* baud rate 115200 */
8713 + tty_encode_baud_rate(tty, 115200, 115200);
8716 +static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb)
8719 + /* We are done with this URB, resubmit it. Prep the USB to wait for
8720 + * another frame */
8721 + usb_fill_bulk_urb(urb, serial->parent->usb,
8722 + usb_rcvbulkpipe(serial->parent->usb,
8724 + bEndpointAddress & 0x7F),
8725 + urb->transfer_buffer, serial->rx_data_length,
8726 + hso_std_serial_read_bulk_callback, serial);
8727 + /* Give this to the USB subsystem so it can tell us when more data
8729 + result = usb_submit_urb(urb, GFP_ATOMIC);
8731 + dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n",
8732 + __func__, result);
8739 +static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial)
8742 + struct urb *curr_urb;
8744 + while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) {
8745 + curr_urb = serial->rx_urb[serial->curr_rx_urb_idx];
8746 + count = put_rxbuf_data(curr_urb, serial);
8750 + serial->curr_rx_urb_idx++;
8751 + if (serial->curr_rx_urb_idx >= serial->num_rx_urbs)
8752 + serial->curr_rx_urb_idx = 0;
8753 + hso_resubmit_rx_bulk_urb(serial, curr_urb);
8758 +static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
8763 + urb = serial->rx_urb[0];
8764 + if (atomic_read(&serial->port.count) > 0) {
8765 + count = put_rxbuf_data(urb, serial);
8769 + /* Re issue a read as long as we receive data. */
8771 + if (count == 0 && ((urb->actual_length != 0) ||
8772 + (serial->rx_state == RX_PENDING))) {
8773 + serial->rx_state = RX_SENT;
8774 + hso_mux_serial_read(serial);
8776 + serial->rx_state = RX_IDLE;
8780 +/* read callback for Diag and CS port */
8781 +static void hso_std_serial_read_bulk_callback(struct urb *urb)
8783 + struct hso_serial *serial = urb->context;
8784 + int status = urb->status;
8786 + D4("\n--- Got serial_read_bulk callback %02x ---", status);
8788 + /* sanity check */
8790 + D1("serial == NULL");
8794 + handle_usb_error(status, __func__, serial->parent);
8798 + D1("Actual length = %d\n", urb->actual_length);
8799 + DUMP1(urb->transfer_buffer, urb->actual_length);
8801 + /* Anyone listening? */
8802 + if (atomic_read(&serial->port.count) == 0)
8805 + if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
8806 + fix_crc_bug(urb, serial->in_endp->wMaxPacketSize);
8807 + /* Valid data, handle RX data */
8808 + spin_lock(&serial->serial_lock);
8809 + serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1;
8810 + put_rxbuf_data_and_resubmit_bulk_urb(serial);
8811 + spin_unlock(&serial->serial_lock);
8815 + * This needs to be a tasklet otherwise we will
8816 + * end up recursively calling this function.
8818 +static void hso_unthrottle_tasklet(struct hso_serial *serial)
8820 + unsigned long flags;
8822 + spin_lock_irqsave(&serial->serial_lock, flags);
8823 + if ((serial->parent->port_spec & HSO_INTF_MUX))
8824 + put_rxbuf_data_and_resubmit_ctrl_urb(serial);
8826 + put_rxbuf_data_and_resubmit_bulk_urb(serial);
8827 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8830 +static void hso_unthrottle(struct tty_struct *tty)
8832 + struct hso_serial *serial = tty->driver_data;
8834 + tasklet_hi_schedule(&serial->unthrottle_tasklet);
8837 +/* open the requested serial port */
8838 +static int hso_serial_open(struct tty_struct *tty, struct file *filp)
8840 + struct hso_serial *serial = get_serial_by_index(tty->index);
8843 + /* sanity check */
8844 + if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
8846 + tty->driver_data = NULL;
8847 + D1("Failed to open port");
8851 + mutex_lock(&serial->parent->mutex);
8852 + result = usb_autopm_get_interface(serial->parent->interface);
8856 + D1("Opening %d", serial->minor);
8859 + tty->driver_data = serial;
8860 + tty_port_tty_set(&serial->port, tty);
8862 + /* check for port already opened, if not set the termios */
8863 + if (atomic_inc_return(&serial->port.count) == 1) {
8864 + serial->rx_state = RX_IDLE;
8865 + /* Force default termio settings */
8866 + _hso_serial_set_termios(tty, NULL);
8867 + tasklet_init(&serial->unthrottle_tasklet,
8868 + (void (*)(unsigned long))hso_unthrottle_tasklet,
8869 + (unsigned long)serial);
8870 + result = hso_start_serial_device(serial->parent, GFP_KERNEL);
8872 + hso_stop_serial_device(serial->parent);
8873 + atomic_dec(&serial->port.count);
8875 + kref_get(&serial->parent->ref);
8878 + D1("Port was already open");
8881 + usb_autopm_put_interface(serial->parent->interface);
8885 + hso_serial_tiocmset(tty, TIOCM_RTS | TIOCM_DTR, 0);
8887 + mutex_unlock(&serial->parent->mutex);
8891 +/* close the requested serial port */
8892 +static void hso_serial_close(struct tty_struct *tty, struct file *filp)
8894 + struct hso_serial *serial = tty->driver_data;
8897 + D1("Closing serial port");
8899 + /* Open failed, no close cleanup required */
8900 + if (serial == NULL)
8903 + mutex_lock(&serial->parent->mutex);
8904 + usb_gone = serial->parent->usb_gone;
8907 + usb_autopm_get_interface(serial->parent->interface);
8909 + /* reset the rts and dtr */
8910 + /* do the actual close */
8911 + atomic_dec(&serial->port.count);
8913 + if (atomic_read(&serial->port.count) <= 0) {
8914 + atomic_set(&serial->port.count, 0);
8915 + tty_port_tty_set(&serial->port, NULL);
8917 + hso_stop_serial_device(serial->parent);
8918 + tasklet_kill(&serial->unthrottle_tasklet);
8922 + usb_autopm_put_interface(serial->parent->interface);
8924 + mutex_unlock(&serial->parent->mutex);
8927 +/* close the requested serial port */
8928 +static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
8931 + struct hso_serial *serial = tty->driver_data;
8932 + int space, tx_bytes;
8933 + unsigned long flags;
8935 + /* sanity check */
8936 + if (serial == NULL) {
8937 + printk(KERN_ERR "%s: serial is NULL\n", __func__);
8941 + spin_lock_irqsave(&serial->serial_lock, flags);
8943 + space = serial->tx_data_length - serial->tx_buffer_count;
8944 + tx_bytes = (count < space) ? count : space;
8949 + memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes);
8950 + serial->tx_buffer_count += tx_bytes;
8953 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8955 + hso_kick_transmit(serial);
8960 +/* how much room is there for writing */
8961 +static int hso_serial_write_room(struct tty_struct *tty)
8963 + struct hso_serial *serial = tty->driver_data;
8965 + unsigned long flags;
8967 + spin_lock_irqsave(&serial->serial_lock, flags);
8968 + room = serial->tx_data_length - serial->tx_buffer_count;
8969 + spin_unlock_irqrestore(&serial->serial_lock, flags);
8971 + /* return free room */
8975 +static void hso_serial_cleanup(struct tty_struct *tty)
8977 + struct hso_serial *serial = tty->driver_data;
8982 + kref_put(&serial->parent->ref, hso_serial_ref_free);
8985 +/* setup the term */
8986 +static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
8988 + struct hso_serial *serial = tty->driver_data;
8989 + unsigned long flags;
8992 + D5("Termios called with: cflags new[%d] - old[%d]",
8993 + tty->termios.c_cflag, old->c_cflag);
8995 + /* the actual setup */
8996 + spin_lock_irqsave(&serial->serial_lock, flags);
8997 + if (atomic_read(&serial->port.count))
8998 + _hso_serial_set_termios(tty, old);
9000 + tty->termios = *old;
9001 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9006 +/* how many characters in the buffer */
9007 +static int hso_serial_chars_in_buffer(struct tty_struct *tty)
9009 + struct hso_serial *serial = tty->driver_data;
9011 + unsigned long flags;
9013 + /* sanity check */
9014 + if (serial == NULL)
9017 + spin_lock_irqsave(&serial->serial_lock, flags);
9018 + chars = serial->tx_buffer_count;
9019 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9023 +static int tiocmget_submit_urb(struct hso_serial *serial,
9024 + struct hso_tiocmget *tiocmget,
9025 + struct usb_device *usb)
9029 + if (serial->parent->usb_gone)
9031 + usb_fill_int_urb(tiocmget->urb, usb,
9032 + usb_rcvintpipe(usb,
9034 + bEndpointAddress & 0x7F),
9035 + &tiocmget->serial_state_notification,
9036 + sizeof(struct hso_serial_state_notification),
9037 + tiocmget_intr_callback, serial,
9038 + tiocmget->endp->bInterval);
9039 + result = usb_submit_urb(tiocmget->urb, GFP_ATOMIC);
9041 + dev_warn(&usb->dev, "%s usb_submit_urb failed %d\n", __func__,
9048 +static void tiocmget_intr_callback(struct urb *urb)
9050 + struct hso_serial *serial = urb->context;
9051 + struct hso_tiocmget *tiocmget;
9052 + int status = urb->status;
9053 + u16 UART_state_bitmap, prev_UART_state_bitmap;
9054 + struct uart_icount *icount;
9055 + struct hso_serial_state_notification *serial_state_notification;
9056 + struct usb_device *usb;
9057 + struct usb_interface *interface;
9060 + /* Sanity checks */
9064 + handle_usb_error(status, __func__, serial->parent);
9068 + /* tiocmget is only supported on HSO_PORT_MODEM */
9069 + tiocmget = serial->tiocmget;
9072 + BUG_ON((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM);
9074 + usb = serial->parent->usb;
9075 + interface = serial->parent->interface;
9077 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
9079 + /* wIndex should be the USB interface number of the port to which the
9080 + * notification applies, which should always be the Modem port.
9082 + serial_state_notification = &tiocmget->serial_state_notification;
9083 + if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
9084 + serial_state_notification->bNotification != B_NOTIFICATION ||
9085 + le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
9086 + le16_to_cpu(serial_state_notification->wIndex) != if_num ||
9087 + le16_to_cpu(serial_state_notification->wLength) != W_LENGTH) {
9088 + dev_warn(&usb->dev,
9089 + "hso received invalid serial state notification\n");
9090 + DUMP(serial_state_notification,
9091 + sizeof(struct hso_serial_state_notification));
9094 + UART_state_bitmap = le16_to_cpu(serial_state_notification->
9095 + UART_state_bitmap);
9096 + prev_UART_state_bitmap = tiocmget->prev_UART_state_bitmap;
9097 + icount = &tiocmget->icount;
9098 + spin_lock(&serial->serial_lock);
9099 + if ((UART_state_bitmap & B_OVERRUN) !=
9100 + (prev_UART_state_bitmap & B_OVERRUN))
9102 + if ((UART_state_bitmap & B_PARITY) !=
9103 + (prev_UART_state_bitmap & B_PARITY))
9105 + if ((UART_state_bitmap & B_FRAMING) !=
9106 + (prev_UART_state_bitmap & B_FRAMING))
9108 + if ((UART_state_bitmap & B_RING_SIGNAL) &&
9109 + !(prev_UART_state_bitmap & B_RING_SIGNAL))
9111 + if ((UART_state_bitmap & B_BREAK) !=
9112 + (prev_UART_state_bitmap & B_BREAK))
9114 + if ((UART_state_bitmap & B_TX_CARRIER) !=
9115 + (prev_UART_state_bitmap & B_TX_CARRIER))
9117 + if ((UART_state_bitmap & B_RX_CARRIER) !=
9118 + (prev_UART_state_bitmap & B_RX_CARRIER))
9120 + tiocmget->prev_UART_state_bitmap = UART_state_bitmap;
9121 + spin_unlock(&serial->serial_lock);
9122 + tiocmget->intr_completed = 1;
9123 + wake_up_interruptible(&tiocmget->waitq);
9125 + memset(serial_state_notification, 0,
9126 + sizeof(struct hso_serial_state_notification));
9127 + tiocmget_submit_urb(serial,
9129 + serial->parent->usb);
9133 + * next few functions largely stolen from drivers/serial/serial_core.c
9135 +/* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
9136 + * - mask passed in arg for lines of interest
9137 + * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
9138 + * Caller should use TIOCGICOUNT to see which one it was
9141 +hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
9143 + DECLARE_WAITQUEUE(wait, current);
9144 + struct uart_icount cprev, cnow;
9145 + struct hso_tiocmget *tiocmget;
9148 + tiocmget = serial->tiocmget;
9152 + * note the counters on entry
9154 + spin_lock_irq(&serial->serial_lock);
9155 + memcpy(&cprev, &tiocmget->icount, sizeof(struct uart_icount));
9156 + spin_unlock_irq(&serial->serial_lock);
9157 + add_wait_queue(&tiocmget->waitq, &wait);
9159 + spin_lock_irq(&serial->serial_lock);
9160 + memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
9161 + spin_unlock_irq(&serial->serial_lock);
9162 + set_current_state(TASK_INTERRUPTIBLE);
9163 + if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
9164 + ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
9165 + ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd))) {
9170 + /* see if a signal did it */
9171 + if (signal_pending(current)) {
9172 + ret = -ERESTARTSYS;
9177 + __set_current_state(TASK_RUNNING);
9178 + remove_wait_queue(&tiocmget->waitq, &wait);
9184 + * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
9185 + * Return: write counters to the user passed counter struct
9186 + * NB: both 1->0 and 0->1 transitions are counted except for
9187 + * RI where only 0->1 is counted.
9189 +static int hso_get_count(struct tty_struct *tty,
9190 + struct serial_icounter_struct *icount)
9192 + struct uart_icount cnow;
9193 + struct hso_serial *serial = tty->driver_data;
9194 + struct hso_tiocmget *tiocmget = serial->tiocmget;
9196 + memset(icount, 0, sizeof(struct serial_icounter_struct));
9200 + spin_lock_irq(&serial->serial_lock);
9201 + memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
9202 + spin_unlock_irq(&serial->serial_lock);
9204 + icount->cts = cnow.cts;
9205 + icount->dsr = cnow.dsr;
9206 + icount->rng = cnow.rng;
9207 + icount->dcd = cnow.dcd;
9208 + icount->rx = cnow.rx;
9209 + icount->tx = cnow.tx;
9210 + icount->frame = cnow.frame;
9211 + icount->overrun = cnow.overrun;
9212 + icount->parity = cnow.parity;
9213 + icount->brk = cnow.brk;
9214 + icount->buf_overrun = cnow.buf_overrun;
9220 +static int hso_serial_tiocmget(struct tty_struct *tty)
9223 + struct hso_serial *serial = tty->driver_data;
9224 + struct hso_tiocmget *tiocmget;
9225 + u16 UART_state_bitmap;
9227 + /* sanity check */
9229 + D1("no tty structures");
9232 + spin_lock_irq(&serial->serial_lock);
9233 + retval = ((serial->rts_state) ? TIOCM_RTS : 0) |
9234 + ((serial->dtr_state) ? TIOCM_DTR : 0);
9235 + tiocmget = serial->tiocmget;
9238 + UART_state_bitmap = le16_to_cpu(
9239 + tiocmget->prev_UART_state_bitmap);
9240 + if (UART_state_bitmap & B_RING_SIGNAL)
9241 + retval |= TIOCM_RNG;
9242 + if (UART_state_bitmap & B_RX_CARRIER)
9243 + retval |= TIOCM_CD;
9244 + if (UART_state_bitmap & B_TX_CARRIER)
9245 + retval |= TIOCM_DSR;
9247 + spin_unlock_irq(&serial->serial_lock);
9251 +static int hso_serial_tiocmset(struct tty_struct *tty,
9252 + unsigned int set, unsigned int clear)
9255 + unsigned long flags;
9257 + struct hso_serial *serial = tty->driver_data;
9258 + struct usb_interface *interface;
9260 + /* sanity check */
9262 + D1("no tty structures");
9266 + if ((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM)
9269 + interface = serial->parent->interface;
9270 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
9272 + spin_lock_irqsave(&serial->serial_lock, flags);
9273 + if (set & TIOCM_RTS)
9274 + serial->rts_state = 1;
9275 + if (set & TIOCM_DTR)
9276 + serial->dtr_state = 1;
9278 + if (clear & TIOCM_RTS)
9279 + serial->rts_state = 0;
9280 + if (clear & TIOCM_DTR)
9281 + serial->dtr_state = 0;
9283 + if (serial->dtr_state)
9285 + if (serial->rts_state)
9288 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9290 + return usb_control_msg(serial->parent->usb,
9291 + usb_rcvctrlpipe(serial->parent->usb, 0), 0x22,
9292 + 0x21, val, if_num, NULL, 0,
9293 + USB_CTRL_SET_TIMEOUT);
9296 +static int hso_serial_ioctl(struct tty_struct *tty,
9297 + unsigned int cmd, unsigned long arg)
9299 + struct hso_serial *serial = tty->driver_data;
9301 + D4("IOCTL cmd: %d, arg: %ld", cmd, arg);
9307 + ret = hso_wait_modem_status(serial, arg);
9310 + ret = -ENOIOCTLCMD;
9317 +/* starts a transmit */
9318 +static void hso_kick_transmit(struct hso_serial *serial)
9321 + unsigned long flags;
9324 + spin_lock_irqsave(&serial->serial_lock, flags);
9325 + if (!serial->tx_buffer_count)
9328 + if (serial->tx_urb_used)
9331 + /* Wakeup USB interface if necessary */
9332 + if (hso_get_activity(serial->parent) == -EAGAIN)
9335 + /* Switch pointers around to avoid memcpy */
9336 + temp = serial->tx_buffer;
9337 + serial->tx_buffer = serial->tx_data;
9338 + serial->tx_data = temp;
9339 + serial->tx_data_count = serial->tx_buffer_count;
9340 + serial->tx_buffer_count = 0;
9342 + /* If temp is set, it means we switched buffers */
9343 + if (temp && serial->write_data) {
9344 + res = serial->write_data(serial);
9346 + serial->tx_urb_used = 1;
9349 + spin_unlock_irqrestore(&serial->serial_lock, flags);
9352 +/* make a request (for reading and writing data to muxed serial port) */
9353 +static int mux_device_request(struct hso_serial *serial, u8 type, u16 port,
9354 + struct urb *ctrl_urb,
9355 + struct usb_ctrlrequest *ctrl_req,
9356 + u8 *ctrl_urb_data, u32 size)
9361 + /* Sanity check */
9362 + if (!serial || !ctrl_urb || !ctrl_req) {
9363 + printk(KERN_ERR "%s: Wrong arguments\n", __func__);
9368 + ctrl_req->wValue = 0;
9369 + ctrl_req->wIndex = cpu_to_le16(hso_port_to_mux(port));
9370 + ctrl_req->wLength = cpu_to_le16(size);
9372 + if (type == USB_CDC_GET_ENCAPSULATED_RESPONSE) {
9373 + /* Reading command */
9374 + ctrl_req->bRequestType = USB_DIR_IN |
9375 + USB_TYPE_OPTION_VENDOR |
9376 + USB_RECIP_INTERFACE;
9377 + ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
9378 + pipe = usb_rcvctrlpipe(serial->parent->usb, 0);
9380 + /* Writing command */
9381 + ctrl_req->bRequestType = USB_DIR_OUT |
9382 + USB_TYPE_OPTION_VENDOR |
9383 + USB_RECIP_INTERFACE;
9384 + ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
9385 + pipe = usb_sndctrlpipe(serial->parent->usb, 0);
9388 + D2("%s command (%02x) len: %d, port: %d",
9389 + type == USB_CDC_GET_ENCAPSULATED_RESPONSE ? "Read" : "Write",
9390 + ctrl_req->bRequestType, ctrl_req->wLength, port);
9392 + /* Load ctrl urb */
9393 + ctrl_urb->transfer_flags = 0;
9394 + usb_fill_control_urb(ctrl_urb,
9395 + serial->parent->usb,
9398 + ctrl_urb_data, size, ctrl_callback, serial);
9399 + /* Send it on merry way */
9400 + result = usb_submit_urb(ctrl_urb, GFP_ATOMIC);
9402 + dev_err(&ctrl_urb->dev->dev,
9403 + "%s failed submit ctrl_urb %d type %d\n", __func__,
9412 +/* called by intr_callback when read occurs */
9413 +static int hso_mux_serial_read(struct hso_serial *serial)
9419 + memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE);
9420 + /* make the request */
9422 + if (serial->num_rx_urbs != 1) {
9423 + dev_err(&serial->parent->interface->dev,
9424 + "ERROR: mux'd reads with multiple buffers "
9425 + "not possible\n");
9428 + return mux_device_request(serial,
9429 + USB_CDC_GET_ENCAPSULATED_RESPONSE,
9430 + serial->parent->port_spec & HSO_PORT_MASK,
9431 + serial->rx_urb[0],
9432 + &serial->ctrl_req_rx,
9433 + serial->rx_data[0], serial->rx_data_length);
9436 +/* used for muxed serial port callback (muxed serial read) */
9437 +static void intr_callback(struct urb *urb)
9439 + struct hso_shared_int *shared_int = urb->context;
9440 + struct hso_serial *serial;
9441 + unsigned char *port_req;
9442 + int status = urb->status;
9445 + usb_mark_last_busy(urb->dev);
9447 + /* sanity check */
9451 + /* status check */
9453 + handle_usb_error(status, __func__, NULL);
9456 + D4("\n--- Got intr callback 0x%02X ---", status);
9458 + /* what request? */
9459 + port_req = urb->transfer_buffer;
9460 + D4(" port_req = 0x%.2X\n", *port_req);
9461 + /* loop over all muxed ports to find the one sending this */
9462 + for (i = 0; i < 8; i++) {
9463 + /* max 8 channels on MUX */
9464 + if (*port_req & (1 << i)) {
9465 + serial = get_serial_by_shared_int_and_type(shared_int,
9467 + if (serial != NULL) {
9468 + D1("Pending read interrupt on port %d\n", i);
9469 + spin_lock(&serial->serial_lock);
9470 + if (serial->rx_state == RX_IDLE &&
9471 + atomic_read(&serial->port.count) > 0) {
9472 + /* Setup and send a ctrl req read on
9474 + if (!serial->rx_urb_filled[0]) {
9475 + serial->rx_state = RX_SENT;
9476 + hso_mux_serial_read(serial);
9478 + serial->rx_state = RX_PENDING;
9480 + D1("Already a read pending on "
9481 + "port %d or port not open\n", i);
9483 + spin_unlock(&serial->serial_lock);
9487 + /* Resubmit interrupt urb */
9488 + hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC);
9491 +/* called for writing to muxed serial port */
9492 +static int hso_mux_serial_write_data(struct hso_serial *serial)
9494 + if (NULL == serial)
9497 + return mux_device_request(serial,
9498 + USB_CDC_SEND_ENCAPSULATED_COMMAND,
9499 + serial->parent->port_spec & HSO_PORT_MASK,
9501 + &serial->ctrl_req_tx,
9502 + serial->tx_data, serial->tx_data_count);
9505 +/* write callback for Diag and CS port */
9506 +static void hso_std_serial_write_bulk_callback(struct urb *urb)
9508 + struct hso_serial *serial = urb->context;
9509 + int status = urb->status;
9511 + /* sanity check */
9513 + D1("serial == NULL");
9517 + spin_lock(&serial->serial_lock);
9518 + serial->tx_urb_used = 0;
9519 + spin_unlock(&serial->serial_lock);
9521 + handle_usb_error(status, __func__, serial->parent);
9524 + hso_put_activity(serial->parent);
9525 + tty_port_tty_wakeup(&serial->port);
9526 + hso_kick_transmit(serial);
9531 +/* called for writing diag or CS serial port */
9532 +static int hso_std_serial_write_data(struct hso_serial *serial)
9534 + int count = serial->tx_data_count;
9537 + usb_fill_bulk_urb(serial->tx_urb,
9538 + serial->parent->usb,
9539 + usb_sndbulkpipe(serial->parent->usb,
9540 + serial->out_endp->
9541 + bEndpointAddress & 0x7F),
9542 + serial->tx_data, serial->tx_data_count,
9543 + hso_std_serial_write_bulk_callback, serial);
9545 + result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC);
9547 + dev_warn(&serial->parent->usb->dev,
9548 + "Failed to submit urb - res %d\n", result);
9555 +/* callback after read or write on muxed serial port */
9556 +static void ctrl_callback(struct urb *urb)
9558 + struct hso_serial *serial = urb->context;
9559 + struct usb_ctrlrequest *req;
9560 + int status = urb->status;
9562 + /* sanity check */
9566 + spin_lock(&serial->serial_lock);
9567 + serial->tx_urb_used = 0;
9568 + spin_unlock(&serial->serial_lock);
9570 + handle_usb_error(status, __func__, serial->parent);
9574 + /* what request? */
9575 + req = (struct usb_ctrlrequest *)(urb->setup_packet);
9576 + D4("\n--- Got muxed ctrl callback 0x%02X ---", status);
9577 + D4("Actual length of urb = %d\n", urb->actual_length);
9578 + DUMP1(urb->transfer_buffer, urb->actual_length);
9580 + if (req->bRequestType ==
9581 + (USB_DIR_IN | USB_TYPE_OPTION_VENDOR | USB_RECIP_INTERFACE)) {
9582 + /* response to a read command */
9583 + serial->rx_urb_filled[0] = 1;
9584 + spin_lock(&serial->serial_lock);
9585 + put_rxbuf_data_and_resubmit_ctrl_urb(serial);
9586 + spin_unlock(&serial->serial_lock);
9588 + hso_put_activity(serial->parent);
9589 + tty_port_tty_wakeup(&serial->port);
9590 + /* response to a write command */
9591 + hso_kick_transmit(serial);
9595 +/* handle RX data for serial port */
9596 +static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
9598 + struct tty_struct *tty;
9601 + /* Sanity check */
9602 + if (urb == NULL || serial == NULL) {
9603 + D1("serial = NULL");
9607 + tty = tty_port_tty_get(&serial->port);
9609 + if (tty && test_bit(TTY_THROTTLED, &tty->flags)) {
9610 + tty_kref_put(tty);
9614 + /* Push data to tty */
9615 + D1("data to push to tty");
9616 + count = tty_buffer_request_room(&serial->port, urb->actual_length);
9617 + if (count >= urb->actual_length) {
9618 + tty_insert_flip_string(&serial->port, urb->transfer_buffer,
9619 + urb->actual_length);
9620 + tty_flip_buffer_push(&serial->port);
9622 + dev_warn(&serial->parent->usb->dev,
9623 + "dropping data, %d bytes lost\n", urb->actual_length);
9626 + tty_kref_put(tty);
9628 + serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
9634 +/* Base driver functions */
9636 +static void hso_log_port(struct hso_device *hso_dev)
9639 + char port_dev[20];
9641 + switch (hso_dev->port_spec & HSO_PORT_MASK) {
9642 + case HSO_PORT_CONTROL:
9643 + port_type = "Control";
9645 + case HSO_PORT_APP:
9646 + port_type = "Application";
9648 + case HSO_PORT_GPS:
9649 + port_type = "GPS";
9651 + case HSO_PORT_GPS_CONTROL:
9652 + port_type = "GPS control";
9654 + case HSO_PORT_APP2:
9655 + port_type = "Application2";
9657 + case HSO_PORT_PCSC:
9658 + port_type = "PCSC";
9660 + case HSO_PORT_DIAG:
9661 + port_type = "Diagnostic";
9663 + case HSO_PORT_DIAG2:
9664 + port_type = "Diagnostic2";
9666 + case HSO_PORT_MODEM:
9667 + port_type = "Modem";
9669 + case HSO_PORT_NETWORK:
9670 + port_type = "Network";
9673 + port_type = "Unknown";
9676 + if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
9677 + sprintf(port_dev, "%s", dev2net(hso_dev)->net->name);
9679 + sprintf(port_dev, "/dev/%s%d", tty_filename,
9680 + dev2ser(hso_dev)->minor);
9682 + dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n",
9683 + port_type, port_dev);
9686 +static int hso_start_net_device(struct hso_device *hso_dev)
9688 + int i, result = 0;
9689 + struct hso_net *hso_net = dev2net(hso_dev);
9694 + /* send URBs for all read buffers */
9695 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9697 + /* Prep a receive URB */
9698 + usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i],
9700 + usb_rcvbulkpipe(hso_dev->usb,
9701 + hso_net->in_endp->
9702 + bEndpointAddress & 0x7F),
9703 + hso_net->mux_bulk_rx_buf_pool[i],
9704 + MUX_BULK_RX_BUF_SIZE, read_bulk_callback,
9707 + /* Put it out there so the device can send us stuff */
9708 + result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i],
9711 + dev_warn(&hso_dev->usb->dev,
9712 + "%s failed mux_bulk_rx_urb[%d] %d\n", __func__,
9719 +static int hso_stop_net_device(struct hso_device *hso_dev)
9722 + struct hso_net *hso_net = dev2net(hso_dev);
9727 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9728 + if (hso_net->mux_bulk_rx_urb_pool[i])
9729 + usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]);
9732 + if (hso_net->mux_bulk_tx_urb)
9733 + usb_kill_urb(hso_net->mux_bulk_tx_urb);
9738 +static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags)
9740 + int i, result = 0;
9741 + struct hso_serial *serial = dev2ser(hso_dev);
9746 + /* If it is not the MUX port fill in and submit a bulk urb (already
9747 + * allocated in hso_serial_start) */
9748 + if (!(serial->parent->port_spec & HSO_INTF_MUX)) {
9749 + for (i = 0; i < serial->num_rx_urbs; i++) {
9750 + usb_fill_bulk_urb(serial->rx_urb[i],
9751 + serial->parent->usb,
9752 + usb_rcvbulkpipe(serial->parent->usb,
9754 + bEndpointAddress &
9756 + serial->rx_data[i],
9757 + serial->rx_data_length,
9758 + hso_std_serial_read_bulk_callback,
9760 + result = usb_submit_urb(serial->rx_urb[i], flags);
9762 + dev_warn(&serial->parent->usb->dev,
9763 + "Failed to submit urb - res %d\n",
9769 + mutex_lock(&serial->shared_int->shared_int_lock);
9770 + if (!serial->shared_int->use_count) {
9772 + hso_mux_submit_intr_urb(serial->shared_int,
9773 + hso_dev->usb, flags);
9775 + serial->shared_int->use_count++;
9776 + mutex_unlock(&serial->shared_int->shared_int_lock);
9778 + if (serial->tiocmget)
9779 + tiocmget_submit_urb(serial,
9781 + serial->parent->usb);
9785 +static int hso_stop_serial_device(struct hso_device *hso_dev)
9788 + struct hso_serial *serial = dev2ser(hso_dev);
9789 + struct hso_tiocmget *tiocmget;
9794 + for (i = 0; i < serial->num_rx_urbs; i++) {
9795 + if (serial->rx_urb[i]) {
9796 + usb_kill_urb(serial->rx_urb[i]);
9797 + serial->rx_urb_filled[i] = 0;
9800 + serial->curr_rx_urb_idx = 0;
9802 + if (serial->tx_urb)
9803 + usb_kill_urb(serial->tx_urb);
9805 + if (serial->shared_int) {
9806 + mutex_lock(&serial->shared_int->shared_int_lock);
9807 + if (serial->shared_int->use_count &&
9808 + (--serial->shared_int->use_count == 0)) {
9811 + urb = serial->shared_int->shared_intr_urb;
9813 + usb_kill_urb(urb);
9815 + mutex_unlock(&serial->shared_int->shared_int_lock);
9817 + tiocmget = serial->tiocmget;
9819 + wake_up_interruptible(&tiocmget->waitq);
9820 + usb_kill_urb(tiocmget->urb);
9826 +static void hso_serial_tty_unregister(struct hso_serial *serial)
9828 + tty_unregister_device(tty_drv, serial->minor);
9831 +static void hso_serial_common_free(struct hso_serial *serial)
9835 + for (i = 0; i < serial->num_rx_urbs; i++) {
9836 + /* unlink and free RX URB */
9837 + usb_free_urb(serial->rx_urb[i]);
9838 + /* free the RX buffer */
9839 + kfree(serial->rx_data[i]);
9842 + /* unlink and free TX URB */
9843 + usb_free_urb(serial->tx_urb);
9844 + kfree(serial->tx_buffer);
9845 + kfree(serial->tx_data);
9846 + tty_port_destroy(&serial->port);
9849 +static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
9850 + int rx_size, int tx_size)
9852 + struct device *dev;
9856 + tty_port_init(&serial->port);
9858 + minor = get_free_serial_index();
9862 + /* register our minor number */
9863 + serial->parent->dev = tty_port_register_device_attr(&serial->port,
9864 + tty_drv, minor, &serial->parent->interface->dev,
9865 + serial->parent, hso_serial_dev_groups);
9866 + dev = serial->parent->dev;
9868 + /* fill in specific data for later use */
9869 + serial->minor = minor;
9870 + serial->magic = HSO_SERIAL_MAGIC;
9871 + spin_lock_init(&serial->serial_lock);
9872 + serial->num_rx_urbs = num_urbs;
9874 + /* RX, allocate urb and initialize */
9876 + /* prepare our RX buffer */
9877 + serial->rx_data_length = rx_size;
9878 + for (i = 0; i < serial->num_rx_urbs; i++) {
9879 + serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
9880 + if (!serial->rx_urb[i]) {
9881 + dev_err(dev, "Could not allocate urb?\n");
9884 + serial->rx_urb[i]->transfer_buffer = NULL;
9885 + serial->rx_urb[i]->transfer_buffer_length = 0;
9886 + serial->rx_data[i] = kzalloc(serial->rx_data_length,
9888 + if (!serial->rx_data[i])
9892 + /* TX, allocate urb and initialize */
9893 + serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
9894 + if (!serial->tx_urb) {
9895 + dev_err(dev, "Could not allocate urb?\n");
9898 + serial->tx_urb->transfer_buffer = NULL;
9899 + serial->tx_urb->transfer_buffer_length = 0;
9900 + /* prepare our TX buffer */
9901 + serial->tx_data_count = 0;
9902 + serial->tx_buffer_count = 0;
9903 + serial->tx_data_length = tx_size;
9904 + serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL);
9905 + if (!serial->tx_data)
9908 + serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL);
9909 + if (!serial->tx_buffer)
9914 + hso_serial_tty_unregister(serial);
9915 + hso_serial_common_free(serial);
9919 +/* Creates a general hso device */
9920 +static struct hso_device *hso_create_device(struct usb_interface *intf,
9923 + struct hso_device *hso_dev;
9925 + hso_dev = kzalloc(sizeof(*hso_dev), GFP_ATOMIC);
9929 + hso_dev->port_spec = port_spec;
9930 + hso_dev->usb = interface_to_usbdev(intf);
9931 + hso_dev->interface = intf;
9932 + kref_init(&hso_dev->ref);
9933 + mutex_init(&hso_dev->mutex);
9935 + INIT_WORK(&hso_dev->async_get_intf, async_get_intf);
9936 + INIT_WORK(&hso_dev->async_put_intf, async_put_intf);
9941 +/* Removes a network device in the network device table */
9942 +static int remove_net_device(struct hso_device *hso_dev)
9946 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
9947 + if (network_table[i] == hso_dev) {
9948 + network_table[i] = NULL;
9952 + if (i == HSO_MAX_NET_DEVICES)
9957 +/* Frees our network device */
9958 +static void hso_free_net_device(struct hso_device *hso_dev)
9961 + struct hso_net *hso_net = dev2net(hso_dev);
9966 + remove_net_device(hso_net->parent);
9969 + unregister_netdev(hso_net->net);
9971 + /* start freeing */
9972 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
9973 + usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]);
9974 + kfree(hso_net->mux_bulk_rx_buf_pool[i]);
9975 + hso_net->mux_bulk_rx_buf_pool[i] = NULL;
9977 + usb_free_urb(hso_net->mux_bulk_tx_urb);
9978 + kfree(hso_net->mux_bulk_tx_buf);
9979 + hso_net->mux_bulk_tx_buf = NULL;
9982 + free_netdev(hso_net->net);
9987 +static const struct net_device_ops hso_netdev_ops = {
9988 + .ndo_open = hso_net_open,
9989 + .ndo_stop = hso_net_close,
9990 + .ndo_start_xmit = hso_net_start_xmit,
9991 + .ndo_tx_timeout = hso_net_tx_timeout,
9994 +/* initialize the network interface */
9995 +static void hso_net_init(struct net_device *net)
9997 + struct hso_net *hso_net = netdev_priv(net);
9999 + D1("sizeof hso_net is %d", (int)sizeof(*hso_net));
10001 + /* fill in the other fields */
10002 + net->netdev_ops = &hso_netdev_ops;
10003 + net->watchdog_timeo = HSO_NET_TX_TIMEOUT;
10004 + net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
10005 + net->type = ARPHRD_NONE;
10006 + net->mtu = DEFAULT_MTU - 14;
10007 + net->tx_queue_len = 10;
10008 + net->ethtool_ops = &ops;
10010 + /* and initialize the semaphore */
10011 + spin_lock_init(&hso_net->net_lock);
10014 +/* Adds a network device in the network device table */
10015 +static int add_net_device(struct hso_device *hso_dev)
10019 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10020 + if (network_table[i] == NULL) {
10021 + network_table[i] = hso_dev;
10025 + if (i == HSO_MAX_NET_DEVICES)
10030 +static int hso_rfkill_set_block(void *data, bool blocked)
10032 + struct hso_device *hso_dev = data;
10033 + int enabled = !blocked;
10036 + mutex_lock(&hso_dev->mutex);
10037 + if (hso_dev->usb_gone)
10040 + rv = usb_control_msg(hso_dev->usb, usb_rcvctrlpipe(hso_dev->usb, 0),
10041 + enabled ? 0x82 : 0x81, 0x40, 0, 0, NULL, 0,
10042 + USB_CTRL_SET_TIMEOUT);
10043 + mutex_unlock(&hso_dev->mutex);
10047 +static const struct rfkill_ops hso_rfkill_ops = {
10048 + .set_block = hso_rfkill_set_block,
10051 +/* Creates and sets up everything for rfkill */
10052 +static void hso_create_rfkill(struct hso_device *hso_dev,
10053 + struct usb_interface *interface)
10055 + struct hso_net *hso_net = dev2net(hso_dev);
10056 + struct device *dev = &hso_net->net->dev;
10057 + static u32 rfkill_counter;
10059 + snprintf(hso_net->name, sizeof(hso_net->name), "hso-%d",
10060 + rfkill_counter++);
10062 + hso_net->rfkill = rfkill_alloc(hso_net->name,
10063 + &interface_to_usbdev(interface)->dev,
10064 + RFKILL_TYPE_WWAN,
10065 + &hso_rfkill_ops, hso_dev);
10066 + if (!hso_net->rfkill) {
10067 + dev_err(dev, "%s - Out of memory\n", __func__);
10070 + if (rfkill_register(hso_net->rfkill) < 0) {
10071 + rfkill_destroy(hso_net->rfkill);
10072 + hso_net->rfkill = NULL;
10073 + dev_err(dev, "%s - Failed to register rfkill\n", __func__);
10078 +static struct device_type hso_type = {
10082 +/* Creates our network device */
10083 +static struct hso_device *hso_create_net_device(struct usb_interface *interface,
10087 + struct net_device *net;
10088 + struct hso_net *hso_net;
10089 + struct hso_device *hso_dev;
10091 + hso_dev = hso_create_device(interface, port_spec);
10095 + /* allocate our network device, then we can put in our private data */
10096 + /* call hso_net_init to do the basic initialization */
10097 + net = alloc_netdev(sizeof(struct hso_net), "hso%d", NET_NAME_UNKNOWN,
10100 + dev_err(&interface->dev, "Unable to create ethernet device\n");
10104 + hso_net = netdev_priv(net);
10106 + hso_dev->port_data.dev_net = hso_net;
10107 + hso_net->net = net;
10108 + hso_net->parent = hso_dev;
10110 + hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10112 + if (!hso_net->in_endp) {
10113 + dev_err(&interface->dev, "Can't find BULK IN endpoint\n");
10116 + hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10118 + if (!hso_net->out_endp) {
10119 + dev_err(&interface->dev, "Can't find BULK OUT endpoint\n");
10122 + SET_NETDEV_DEV(net, &interface->dev);
10123 + SET_NETDEV_DEVTYPE(net, &hso_type);
10125 + /* registering our net device */
10126 + result = register_netdev(net);
10128 + dev_err(&interface->dev, "Failed to register device\n");
10132 + /* start allocating */
10133 + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) {
10134 + hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL);
10135 + if (!hso_net->mux_bulk_rx_urb_pool[i]) {
10136 + dev_err(&interface->dev, "Could not allocate rx urb\n");
10139 + hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE,
10141 + if (!hso_net->mux_bulk_rx_buf_pool[i])
10144 + hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL);
10145 + if (!hso_net->mux_bulk_tx_urb) {
10146 + dev_err(&interface->dev, "Could not allocate tx urb\n");
10149 + hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL);
10150 + if (!hso_net->mux_bulk_tx_buf)
10153 + add_net_device(hso_dev);
10155 + hso_log_port(hso_dev);
10157 + hso_create_rfkill(hso_dev, interface);
10161 + hso_free_net_device(hso_dev);
10165 +static void hso_free_tiomget(struct hso_serial *serial)
10167 + struct hso_tiocmget *tiocmget;
10170 + tiocmget = serial->tiocmget;
10172 + usb_free_urb(tiocmget->urb);
10173 + tiocmget->urb = NULL;
10174 + serial->tiocmget = NULL;
10179 +/* Frees an AT channel ( goes for both mux and non-mux ) */
10180 +static void hso_free_serial_device(struct hso_device *hso_dev)
10182 + struct hso_serial *serial = dev2ser(hso_dev);
10187 + hso_serial_common_free(serial);
10189 + if (serial->shared_int) {
10190 + mutex_lock(&serial->shared_int->shared_int_lock);
10191 + if (--serial->shared_int->ref_count == 0)
10192 + hso_free_shared_int(serial->shared_int);
10194 + mutex_unlock(&serial->shared_int->shared_int_lock);
10196 + hso_free_tiomget(serial);
10201 +/* Creates a bulk AT channel */
10202 +static struct hso_device *hso_create_bulk_serial_device(
10203 + struct usb_interface *interface, int port)
10205 + struct hso_device *hso_dev;
10206 + struct hso_serial *serial;
10208 + struct hso_tiocmget *tiocmget;
10210 + hso_dev = hso_create_device(interface, port);
10214 + serial = kzalloc(sizeof(*serial), GFP_KERNEL);
10218 + serial->parent = hso_dev;
10219 + hso_dev->port_data.dev_serial = serial;
10221 + if ((port & HSO_PORT_MASK) == HSO_PORT_MODEM) {
10223 + serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
10225 + /* it isn't going to break our heart if serial->tiocmget
10226 + * allocation fails don't bother checking this.
10228 + if (serial->tiocmget) {
10229 + tiocmget = serial->tiocmget;
10230 + tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
10231 + if (tiocmget->urb) {
10232 + mutex_init(&tiocmget->mutex);
10233 + init_waitqueue_head(&tiocmget->waitq);
10234 + tiocmget->endp = hso_get_ep(
10236 + USB_ENDPOINT_XFER_INT,
10239 + hso_free_tiomget(serial);
10245 + if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE,
10246 + BULK_URB_TX_SIZE))
10249 + serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK,
10251 + if (!serial->in_endp) {
10252 + dev_err(&interface->dev, "Failed to find BULK IN ep\n");
10257 + (serial->out_endp =
10258 + hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) {
10259 + dev_err(&interface->dev, "Failed to find BULK IN ep\n");
10263 + serial->write_data = hso_std_serial_write_data;
10265 + /* and record this serial */
10266 + set_serial_by_index(serial->minor, serial);
10268 + /* setup the proc dirs and files if needed */
10269 + hso_log_port(hso_dev);
10271 + /* done, return it */
10275 + hso_serial_tty_unregister(serial);
10276 + hso_serial_common_free(serial);
10278 + hso_free_tiomget(serial);
10284 +/* Creates a multiplexed AT channel */
10286 +struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface,
10288 + struct hso_shared_int *mux)
10290 + struct hso_device *hso_dev;
10291 + struct hso_serial *serial;
10294 + port_spec = HSO_INTF_MUX;
10295 + port_spec &= ~HSO_PORT_MASK;
10297 + port_spec |= hso_mux_to_port(port);
10298 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NO_PORT)
10301 + hso_dev = hso_create_device(interface, port_spec);
10305 + serial = kzalloc(sizeof(*serial), GFP_KERNEL);
10309 + hso_dev->port_data.dev_serial = serial;
10310 + serial->parent = hso_dev;
10312 + if (hso_serial_common_create
10313 + (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE))
10316 + serial->tx_data_length--;
10317 + serial->write_data = hso_mux_serial_write_data;
10319 + serial->shared_int = mux;
10320 + mutex_lock(&serial->shared_int->shared_int_lock);
10321 + serial->shared_int->ref_count++;
10322 + mutex_unlock(&serial->shared_int->shared_int_lock);
10324 + /* and record this serial */
10325 + set_serial_by_index(serial->minor, serial);
10327 + /* setup the proc dirs and files if needed */
10328 + hso_log_port(hso_dev);
10330 + /* done, return it */
10335 + tty_unregister_device(tty_drv, serial->minor);
10343 +static void hso_free_shared_int(struct hso_shared_int *mux)
10345 + usb_free_urb(mux->shared_intr_urb);
10346 + kfree(mux->shared_intr_buf);
10347 + mutex_unlock(&mux->shared_int_lock);
10352 +struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface)
10354 + struct hso_shared_int *mux = kzalloc(sizeof(*mux), GFP_KERNEL);
10359 + mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT,
10361 + if (!mux->intr_endp) {
10362 + dev_err(&interface->dev, "Can't find INT IN endpoint\n");
10366 + mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL);
10367 + if (!mux->shared_intr_urb) {
10368 + dev_err(&interface->dev, "Could not allocate intr urb?\n");
10371 + mux->shared_intr_buf =
10372 + kzalloc(le16_to_cpu(mux->intr_endp->wMaxPacketSize),
10374 + if (!mux->shared_intr_buf)
10377 + mutex_init(&mux->shared_int_lock);
10382 + kfree(mux->shared_intr_buf);
10383 + usb_free_urb(mux->shared_intr_urb);
10388 +/* Gets the port spec for a certain interface */
10389 +static int hso_get_config_data(struct usb_interface *interface)
10391 + struct usb_device *usbdev = interface_to_usbdev(interface);
10392 + u8 *config_data = kmalloc(17, GFP_KERNEL);
10393 + u32 if_num = interface->cur_altsetting->desc.bInterfaceNumber;
10396 + if (!config_data)
10398 + if (usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
10399 + 0x86, 0xC0, 0, 0, config_data, 17,
10400 + USB_CTRL_SET_TIMEOUT) != 0x11) {
10401 + kfree(config_data);
10405 + switch (config_data[if_num]) {
10410 + result = HSO_PORT_DIAG;
10413 + result = HSO_PORT_GPS;
10416 + result = HSO_PORT_GPS_CONTROL;
10419 + result = HSO_PORT_APP;
10422 + result = HSO_PORT_APP2;
10425 + result = HSO_PORT_CONTROL;
10428 + result = HSO_PORT_NETWORK;
10431 + result = HSO_PORT_MODEM;
10434 + result = HSO_PORT_MSD;
10437 + result = HSO_PORT_PCSC;
10440 + result = HSO_PORT_VOICE;
10447 + result |= HSO_INTF_BULK;
10449 + if (config_data[16] & 0x1)
10450 + result |= HSO_INFO_CRC_BUG;
10452 + kfree(config_data);
10456 +/* called once for each interface upon device insertion */
10457 +static int hso_probe(struct usb_interface *interface,
10458 + const struct usb_device_id *id)
10460 + int mux, i, if_num, port_spec;
10461 + unsigned char port_mask;
10462 + struct hso_device *hso_dev = NULL;
10463 + struct hso_shared_int *shared_int;
10464 + struct hso_device *tmp_dev = NULL;
10466 + if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) {
10467 + dev_err(&interface->dev, "Not our interface\n");
10471 + if_num = interface->cur_altsetting->desc.bInterfaceNumber;
10473 + /* Get the interface/port specification from either driver_info or from
10474 + * the device itself */
10475 + if (id->driver_info)
10476 + port_spec = ((u32 *)(id->driver_info))[if_num];
10478 + port_spec = hso_get_config_data(interface);
10480 + /* Check if we need to switch to alt interfaces prior to port
10481 + * configuration */
10482 + if (interface->num_altsetting > 1)
10483 + usb_set_interface(interface_to_usbdev(interface), if_num, 1);
10484 + interface->needs_remote_wakeup = 1;
10486 + /* Allocate new hso device(s) */
10487 + switch (port_spec & HSO_INTF_MASK) {
10488 + case HSO_INTF_MUX:
10489 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
10490 + /* Create the network device */
10491 + if (!disable_net) {
10492 + hso_dev = hso_create_net_device(interface,
10496 + tmp_dev = hso_dev;
10500 + if (hso_get_mux_ports(interface, &port_mask))
10501 + /* TODO: de-allocate everything */
10504 + shared_int = hso_create_shared_int(interface);
10508 + for (i = 1, mux = 0; i < 0x100; i = i << 1, mux++) {
10509 + if (port_mask & i) {
10510 + hso_dev = hso_create_mux_serial_device(
10511 + interface, i, shared_int);
10518 + hso_dev = tmp_dev;
10521 + case HSO_INTF_BULK:
10522 + /* It's a regular bulk interface */
10523 + if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) {
10524 + if (!disable_net)
10526 + hso_create_net_device(interface, port_spec);
10529 + hso_create_bulk_serial_device(interface, port_spec);
10538 + /* save our data pointer in this device */
10539 + usb_set_intfdata(interface, hso_dev);
10544 + hso_free_interface(interface);
10548 +/* device removed, cleaning up */
10549 +static void hso_disconnect(struct usb_interface *interface)
10551 + hso_free_interface(interface);
10553 + /* remove reference of our private data */
10554 + usb_set_intfdata(interface, NULL);
10557 +static void async_get_intf(struct work_struct *data)
10559 + struct hso_device *hso_dev =
10560 + container_of(data, struct hso_device, async_get_intf);
10561 + usb_autopm_get_interface(hso_dev->interface);
10564 +static void async_put_intf(struct work_struct *data)
10566 + struct hso_device *hso_dev =
10567 + container_of(data, struct hso_device, async_put_intf);
10568 + usb_autopm_put_interface(hso_dev->interface);
10571 +static int hso_get_activity(struct hso_device *hso_dev)
10573 + if (hso_dev->usb->state == USB_STATE_SUSPENDED) {
10574 + if (!hso_dev->is_active) {
10575 + hso_dev->is_active = 1;
10576 + schedule_work(&hso_dev->async_get_intf);
10580 + if (hso_dev->usb->state != USB_STATE_CONFIGURED)
10583 + usb_mark_last_busy(hso_dev->usb);
10588 +static int hso_put_activity(struct hso_device *hso_dev)
10590 + if (hso_dev->usb->state != USB_STATE_SUSPENDED) {
10591 + if (hso_dev->is_active) {
10592 + hso_dev->is_active = 0;
10593 + schedule_work(&hso_dev->async_put_intf);
10597 + hso_dev->is_active = 0;
10601 +/* called by kernel when we need to suspend device */
10602 +static int hso_suspend(struct usb_interface *iface, pm_message_t message)
10606 + /* Stop all serial ports */
10607 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10608 + if (serial_table[i] && (serial_table[i]->interface == iface)) {
10609 + result = hso_stop_serial_device(serial_table[i]);
10615 + /* Stop all network ports */
10616 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10617 + if (network_table[i] &&
10618 + (network_table[i]->interface == iface)) {
10619 + result = hso_stop_net_device(network_table[i]);
10629 +/* called by kernel when we need to resume device */
10630 +static int hso_resume(struct usb_interface *iface)
10632 + int i, result = 0;
10633 + struct hso_net *hso_net;
10635 + /* Start all serial ports */
10636 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10637 + if (serial_table[i] && (serial_table[i]->interface == iface)) {
10638 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
10640 + hso_start_serial_device(serial_table[i], GFP_NOIO);
10641 + hso_kick_transmit(dev2ser(serial_table[i]));
10648 + /* Start all network ports */
10649 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10650 + if (network_table[i] &&
10651 + (network_table[i]->interface == iface)) {
10652 + hso_net = dev2net(network_table[i]);
10653 + if (hso_net->flags & IFF_UP) {
10654 + /* First transmit any lingering data,
10655 + then restart the device. */
10656 + if (hso_net->skb_tx_buf) {
10657 + dev_dbg(&iface->dev,
10659 + " lingering data\n");
10660 + hso_net_start_xmit(hso_net->skb_tx_buf,
10662 + hso_net->skb_tx_buf = NULL;
10664 + result = hso_start_net_device(network_table[i]);
10675 +static void hso_serial_ref_free(struct kref *ref)
10677 + struct hso_device *hso_dev = container_of(ref, struct hso_device, ref);
10679 + hso_free_serial_device(hso_dev);
10682 +static void hso_free_interface(struct usb_interface *interface)
10684 + struct hso_serial *serial;
10687 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
10688 + if (serial_table[i] &&
10689 + (serial_table[i]->interface == interface)) {
10690 + serial = dev2ser(serial_table[i]);
10691 + tty_port_tty_hangup(&serial->port, false);
10692 + mutex_lock(&serial->parent->mutex);
10693 + serial->parent->usb_gone = 1;
10694 + mutex_unlock(&serial->parent->mutex);
10695 + cancel_work_sync(&serial_table[i]->async_put_intf);
10696 + cancel_work_sync(&serial_table[i]->async_get_intf);
10697 + hso_serial_tty_unregister(serial);
10698 + kref_put(&serial_table[i]->ref, hso_serial_ref_free);
10699 + set_serial_by_index(i, NULL);
10703 + for (i = 0; i < HSO_MAX_NET_DEVICES; i++) {
10704 + if (network_table[i] &&
10705 + (network_table[i]->interface == interface)) {
10706 + struct rfkill *rfk = dev2net(network_table[i])->rfkill;
10707 + /* hso_stop_net_device doesn't stop the net queue since
10708 + * traffic needs to start it again when suspended */
10709 + netif_stop_queue(dev2net(network_table[i])->net);
10710 + hso_stop_net_device(network_table[i]);
10711 + cancel_work_sync(&network_table[i]->async_put_intf);
10712 + cancel_work_sync(&network_table[i]->async_get_intf);
10714 + rfkill_unregister(rfk);
10715 + rfkill_destroy(rfk);
10717 + hso_free_net_device(network_table[i]);
10722 +/* Helper functions */
10724 +/* Get the endpoint ! */
10725 +static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf,
10726 + int type, int dir)
10729 + struct usb_host_interface *iface = intf->cur_altsetting;
10730 + struct usb_endpoint_descriptor *endp;
10732 + for (i = 0; i < iface->desc.bNumEndpoints; i++) {
10733 + endp = &iface->endpoint[i].desc;
10734 + if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) &&
10735 + (usb_endpoint_type(endp) == type))
10742 +/* Get the byte that describes which ports are enabled */
10743 +static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports)
10746 + struct usb_host_interface *iface = intf->cur_altsetting;
10748 + if (iface->extralen == 3) {
10749 + *ports = iface->extra[2];
10753 + for (i = 0; i < iface->desc.bNumEndpoints; i++) {
10754 + if (iface->endpoint[i].extralen == 3) {
10755 + *ports = iface->endpoint[i].extra[2];
10763 +/* interrupt urb needs to be submitted, used for serial read of muxed port */
10764 +static int hso_mux_submit_intr_urb(struct hso_shared_int *shared_int,
10765 + struct usb_device *usb, gfp_t gfp)
10769 + usb_fill_int_urb(shared_int->shared_intr_urb, usb,
10770 + usb_rcvintpipe(usb,
10771 + shared_int->intr_endp->bEndpointAddress & 0x7F),
10772 + shared_int->shared_intr_buf,
10774 + intr_callback, shared_int,
10775 + shared_int->intr_endp->bInterval);
10777 + result = usb_submit_urb(shared_int->shared_intr_urb, gfp);
10779 + dev_warn(&usb->dev, "%s failed mux_intr_urb %d\n", __func__,
10785 +/* operations setup of the serial interface */
10786 +static const struct tty_operations hso_serial_ops = {
10787 + .open = hso_serial_open,
10788 + .close = hso_serial_close,
10789 + .write = hso_serial_write,
10790 + .write_room = hso_serial_write_room,
10791 + .cleanup = hso_serial_cleanup,
10792 + .ioctl = hso_serial_ioctl,
10793 + .set_termios = hso_serial_set_termios,
10794 + .chars_in_buffer = hso_serial_chars_in_buffer,
10795 + .tiocmget = hso_serial_tiocmget,
10796 + .tiocmset = hso_serial_tiocmset,
10797 + .get_icount = hso_get_count,
10798 + .unthrottle = hso_unthrottle
10801 +static struct usb_driver hso_driver = {
10802 + .name = driver_name,
10803 + .probe = hso_probe,
10804 + .disconnect = hso_disconnect,
10805 + .id_table = hso_ids,
10806 + .suspend = hso_suspend,
10807 + .resume = hso_resume,
10808 + .reset_resume = hso_resume,
10809 + .supports_autosuspend = 1,
10810 + .disable_hub_initiated_lpm = 1,
10813 +static int __init hso_init(void)
10818 + /* put it in the log */
10819 + printk(KERN_INFO "hso: %s\n", version);
10821 + /* Initialise the serial table semaphore and table */
10822 + spin_lock_init(&serial_table_lock);
10823 + for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++)
10824 + serial_table[i] = NULL;
10826 + /* allocate our driver using the proper amount of supported minors */
10827 + tty_drv = alloc_tty_driver(HSO_SERIAL_TTY_MINORS);
10831 + /* fill in all needed values */
10832 + tty_drv->driver_name = driver_name;
10833 + tty_drv->name = tty_filename;
10835 + /* if major number is provided as parameter, use that one */
10837 + tty_drv->major = tty_major;
10839 + tty_drv->minor_start = 0;
10840 + tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
10841 + tty_drv->subtype = SERIAL_TYPE_NORMAL;
10842 + tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
10843 + tty_drv->init_termios = tty_std_termios;
10844 + hso_init_termios(&tty_drv->init_termios);
10845 + tty_set_operations(tty_drv, &hso_serial_ops);
10847 + /* register the tty driver */
10848 + result = tty_register_driver(tty_drv);
10850 + printk(KERN_ERR "%s - tty_register_driver failed(%d)\n",
10851 + __func__, result);
10852 + goto err_free_tty;
10855 + /* register this module as an usb driver */
10856 + result = usb_register(&hso_driver);
10858 + printk(KERN_ERR "Could not register hso driver? error: %d\n",
10860 + goto err_unreg_tty;
10866 + tty_unregister_driver(tty_drv);
10868 + put_tty_driver(tty_drv);
10872 +static void __exit hso_exit(void)
10874 + printk(KERN_INFO "hso: unloaded\n");
10876 + tty_unregister_driver(tty_drv);
10877 + put_tty_driver(tty_drv);
10878 + /* deregister the usb driver */
10879 + usb_deregister(&hso_driver);
10882 +/* Module definitions */
10883 +module_init(hso_init);
10884 +module_exit(hso_exit);
10886 +MODULE_AUTHOR(MOD_AUTHOR);
10887 +MODULE_DESCRIPTION(MOD_DESCRIPTION);
10888 +MODULE_LICENSE(MOD_LICENSE);
10890 +/* change the debug level (eg: insmod hso.ko debug=0x04) */
10891 +MODULE_PARM_DESC(debug, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]");
10892 +module_param(debug, int, S_IRUGO | S_IWUSR);
10894 +/* set the major tty number (eg: insmod hso.ko tty_major=245) */
10895 +MODULE_PARM_DESC(tty_major, "Set the major tty number");
10896 +module_param(tty_major, int, S_IRUGO | S_IWUSR);
10898 +/* disable network interface (eg: insmod hso.ko disable_net=1) */
10899 +MODULE_PARM_DESC(disable_net, "Disable the network interface");
10900 +module_param(disable_net, int, S_IRUGO | S_IWUSR);
10901 diff -Naur backports-4.2.6-1.org/drivers/net/usb/huawei_cdc_ncm.c backports-4.2.6-1/drivers/net/usb/huawei_cdc_ncm.c
10902 --- backports-4.2.6-1.org/drivers/net/usb/huawei_cdc_ncm.c 1970-01-01 01:00:00.000000000 +0100
10903 +++ backports-4.2.6-1/drivers/net/usb/huawei_cdc_ncm.c 2016-06-28 14:35:17.981973887 +0200
10905 +/* huawei_cdc_ncm.c - handles Huawei devices using the CDC NCM protocol as
10906 + * transport layer.
10907 + * Copyright (C) 2013 Enrico Mioso <mrkiko.rs@gmail.com>
10911 + * This driver handles devices resembling the CDC NCM standard, but
10912 + * encapsulating another protocol inside it. An example are some Huawei 3G
10913 + * devices, exposing an embedded AT channel where you can set up the NCM
10915 + * This code has been heavily inspired by the cdc_mbim.c driver, which is
10916 + * Copyright (c) 2012 Smith Micro Software, Inc.
10917 + * Copyright (c) 2012 Bjørn Mork <bjorn@mork.no>
10919 + * This program is free software; you can redistribute it and/or
10920 + * modify it under the terms of the GNU General Public License
10921 + * version 2 as published by the Free Software Foundation.
10924 +#include <linux/module.h>
10925 +#include <linux/netdevice.h>
10926 +#include <linux/ethtool.h>
10927 +#include <linux/if_vlan.h>
10928 +#include <linux/ip.h>
10929 +#include <linux/mii.h>
10930 +#include <linux/usb.h>
10931 +#include <linux/usb/cdc.h>
10932 +#include <linux/usb/usbnet.h>
10933 +#include <linux/usb/cdc-wdm.h>
10934 +#include <linux/usb/cdc_ncm.h>
10937 +struct huawei_cdc_ncm_state {
10938 + struct cdc_ncm_ctx *ctx;
10939 + atomic_t pmcount;
10940 + struct usb_driver *subdriver;
10941 + struct usb_interface *control;
10942 + struct usb_interface *data;
10945 +static int huawei_cdc_ncm_manage_power(struct usbnet *usbnet_dev, int on)
10947 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
10950 + if ((on && atomic_add_return(1, &drvstate->pmcount) == 1) ||
10951 + (!on && atomic_dec_and_test(&drvstate->pmcount))) {
10952 + rv = usb_autopm_get_interface(usbnet_dev->intf);
10953 + usbnet_dev->intf->needs_remote_wakeup = on;
10955 + usb_autopm_put_interface(usbnet_dev->intf);
10960 +static int huawei_cdc_ncm_wdm_manage_power(struct usb_interface *intf,
10963 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
10965 + /* can be called while disconnecting */
10969 + return huawei_cdc_ncm_manage_power(usbnet_dev, status);
10973 +static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev,
10974 + struct usb_interface *intf)
10976 + struct cdc_ncm_ctx *ctx;
10977 + struct usb_driver *subdriver = ERR_PTR(-ENODEV);
10978 + int ret = -ENODEV;
10979 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
10980 + int drvflags = 0;
10982 + /* altsetting should always be 1 for NCM devices - so we hard-coded
10983 + * it here. Some huawei devices will need the NDP part of the NCM package to
10984 + * be at the end of the frame.
10986 + drvflags |= CDC_NCM_FLAG_NDP_TO_END;
10987 + ret = cdc_ncm_bind_common(usbnet_dev, intf, 1, drvflags);
10991 + ctx = drvstate->ctx;
10993 + if (usbnet_dev->status)
10994 + /* The wMaxCommand buffer must be big enough to hold
10995 + * any message from the modem. Experience has shown
10996 + * that some replies are more than 256 bytes long
10998 + subdriver = usb_cdc_wdm_register(ctx->control,
10999 + &usbnet_dev->status->desc,
11000 + 1024, /* wMaxCommand */
11001 + huawei_cdc_ncm_wdm_manage_power);
11002 + if (IS_ERR(subdriver)) {
11003 + ret = PTR_ERR(subdriver);
11004 + cdc_ncm_unbind(usbnet_dev, intf);
11008 + /* Prevent usbnet from using the status descriptor */
11009 + usbnet_dev->status = NULL;
11011 + drvstate->subdriver = subdriver;
11017 +static void huawei_cdc_ncm_unbind(struct usbnet *usbnet_dev,
11018 + struct usb_interface *intf)
11020 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11021 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11023 + if (drvstate->subdriver && drvstate->subdriver->disconnect)
11024 + drvstate->subdriver->disconnect(ctx->control);
11025 + drvstate->subdriver = NULL;
11027 + cdc_ncm_unbind(usbnet_dev, intf);
11030 +static int huawei_cdc_ncm_suspend(struct usb_interface *intf,
11031 + pm_message_t message)
11034 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
11035 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11036 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11038 + if (ctx == NULL) {
11043 + ret = usbnet_suspend(intf, message);
11047 + if (intf == ctx->control &&
11048 + drvstate->subdriver &&
11049 + drvstate->subdriver->suspend)
11050 + ret = drvstate->subdriver->suspend(intf, message);
11052 + usbnet_resume(intf);
11058 +static int huawei_cdc_ncm_resume(struct usb_interface *intf)
11061 + struct usbnet *usbnet_dev = usb_get_intfdata(intf);
11062 + struct huawei_cdc_ncm_state *drvstate = (void *)&usbnet_dev->data;
11064 + struct cdc_ncm_ctx *ctx = drvstate->ctx;
11066 + /* should we call subdriver's resume function? */
11068 + (intf == ctx->control &&
11069 + drvstate->subdriver &&
11070 + drvstate->subdriver->resume);
11073 + ret = drvstate->subdriver->resume(intf);
11076 + ret = usbnet_resume(intf);
11077 + if (ret < 0 && callsub)
11078 + drvstate->subdriver->suspend(intf, PMSG_SUSPEND);
11083 +static const struct driver_info huawei_cdc_ncm_info = {
11084 + .description = "Huawei CDC NCM device",
11085 + .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
11086 + .bind = huawei_cdc_ncm_bind,
11087 + .unbind = huawei_cdc_ncm_unbind,
11088 + .manage_power = huawei_cdc_ncm_manage_power,
11089 + .rx_fixup = cdc_ncm_rx_fixup,
11090 + .tx_fixup = cdc_ncm_tx_fixup,
11093 +static const struct usb_device_id huawei_cdc_ncm_devs[] = {
11094 + /* Huawei NCM devices disguised as vendor specific */
11095 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16),
11096 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11098 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46),
11099 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11101 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x76),
11102 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11104 + { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x03, 0x16),
11105 + .driver_info = (unsigned long)&huawei_cdc_ncm_info,
11108 + /* Terminating entry */
11112 +MODULE_DEVICE_TABLE(usb, huawei_cdc_ncm_devs);
11114 +static struct usb_driver huawei_cdc_ncm_driver = {
11115 + .name = "huawei_cdc_ncm",
11116 + .id_table = huawei_cdc_ncm_devs,
11117 + .probe = usbnet_probe,
11118 + .disconnect = usbnet_disconnect,
11119 + .suspend = huawei_cdc_ncm_suspend,
11120 + .resume = huawei_cdc_ncm_resume,
11121 + .reset_resume = huawei_cdc_ncm_resume,
11122 + .supports_autosuspend = 1,
11123 + .disable_hub_initiated_lpm = 1,
11125 +module_usb_driver(huawei_cdc_ncm_driver);
11126 +MODULE_AUTHOR("Enrico Mioso <mrkiko.rs@gmail.com>");
11127 +MODULE_DESCRIPTION("USB CDC NCM host driver with encapsulated protocol support");
11128 +MODULE_LICENSE("GPL");
11129 diff -Naur backports-4.2.6-1.org/drivers/net/usb/int51x1.c backports-4.2.6-1/drivers/net/usb/int51x1.c
11130 --- backports-4.2.6-1.org/drivers/net/usb/int51x1.c 1970-01-01 01:00:00.000000000 +0100
11131 +++ backports-4.2.6-1/drivers/net/usb/int51x1.c 2016-06-28 14:35:17.985307220 +0200
11134 + * Copyright (c) 2009 Peter Holik
11136 + * Intellon usb PLC (Powerline Communications) usb net driver
11138 + * http://www.tandel.be/downloads/INT51X1_Datasheet.pdf
11140 + * Based on the work of Jan 'RedBully' Seiffert
11144 + * This program is free software; you can redistribute it and/or modify
11145 + * it under the terms of the GNU General Public License as published by
11146 + * the Free Software Foundation; either version 2 of the License, or.
11147 + * (at your option) any later version.
11149 + * This program is distributed in the hope that it will be useful,
11150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11152 + * GNU General Public License for more details.
11154 + * You should have received a copy of the GNU General Public License
11155 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
11158 +#include <linux/module.h>
11159 +#include <linux/ctype.h>
11160 +#include <linux/netdevice.h>
11161 +#include <linux/etherdevice.h>
11162 +#include <linux/ethtool.h>
11163 +#include <linux/slab.h>
11164 +#include <linux/mii.h>
11165 +#include <linux/usb.h>
11166 +#include <linux/usb/usbnet.h>
11168 +#define INT51X1_VENDOR_ID 0x09e1
11169 +#define INT51X1_PRODUCT_ID 0x5121
11171 +#define INT51X1_HEADER_SIZE 2 /* 2 byte header */
11173 +#define PACKET_TYPE_PROMISCUOUS (1 << 0)
11174 +#define PACKET_TYPE_ALL_MULTICAST (1 << 1) /* no filter */
11175 +#define PACKET_TYPE_DIRECTED (1 << 2)
11176 +#define PACKET_TYPE_BROADCAST (1 << 3)
11177 +#define PACKET_TYPE_MULTICAST (1 << 4) /* filtered */
11179 +#define SET_ETHERNET_PACKET_FILTER 0x43
11181 +static int int51x1_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
11185 + if (!(pskb_may_pull(skb, INT51X1_HEADER_SIZE))) {
11186 + netdev_err(dev->net, "unexpected tiny rx frame\n");
11190 + len = le16_to_cpu(*(__le16 *)&skb->data[skb->len - 2]);
11192 + skb_trim(skb, len);
11197 +static struct sk_buff *int51x1_tx_fixup(struct usbnet *dev,
11198 + struct sk_buff *skb, gfp_t flags)
11200 + int pack_len = skb->len;
11201 + int pack_with_header_len = pack_len + INT51X1_HEADER_SIZE;
11202 + int headroom = skb_headroom(skb);
11203 + int tailroom = skb_tailroom(skb);
11204 + int need_tail = 0;
11207 + /* if packet and our header is smaler than 64 pad to 64 (+ ZLP) */
11208 + if ((pack_with_header_len) < dev->maxpacket)
11209 + need_tail = dev->maxpacket - pack_with_header_len + 1;
11211 + * usbnet would send a ZLP if packetlength mod urbsize == 0 for us,
11212 + * but we need to know ourself, because this would add to the length
11213 + * we send down to the device...
11215 + else if (!(pack_with_header_len % dev->maxpacket))
11218 + if (!skb_cloned(skb) &&
11219 + (headroom + tailroom >= need_tail + INT51X1_HEADER_SIZE)) {
11220 + if (headroom < INT51X1_HEADER_SIZE || tailroom < need_tail) {
11221 + skb->data = memmove(skb->head + INT51X1_HEADER_SIZE,
11222 + skb->data, skb->len);
11223 + skb_set_tail_pointer(skb, skb->len);
11226 + struct sk_buff *skb2;
11228 + skb2 = skb_copy_expand(skb,
11229 + INT51X1_HEADER_SIZE,
11232 + dev_kfree_skb_any(skb);
11238 + pack_len += need_tail;
11239 + pack_len &= 0x07ff;
11241 + len = (__le16 *) __skb_push(skb, INT51X1_HEADER_SIZE);
11242 + *len = cpu_to_le16(pack_len);
11245 + memset(__skb_put(skb, need_tail), 0, need_tail);
11250 +static void int51x1_set_multicast(struct net_device *netdev)
11252 + struct usbnet *dev = netdev_priv(netdev);
11253 + u16 filter = PACKET_TYPE_DIRECTED | PACKET_TYPE_BROADCAST;
11255 + if (netdev->flags & IFF_PROMISC) {
11256 + /* do not expect to see traffic of other PLCs */
11257 + filter |= PACKET_TYPE_PROMISCUOUS;
11258 + netdev_info(dev->net, "promiscuous mode enabled\n");
11259 + } else if (!netdev_mc_empty(netdev) ||
11260 + (netdev->flags & IFF_ALLMULTI)) {
11261 + filter |= PACKET_TYPE_ALL_MULTICAST;
11262 + netdev_dbg(dev->net, "receive all multicast enabled\n");
11264 + /* ~PROMISCUOUS, ~MULTICAST */
11265 + netdev_dbg(dev->net, "receive own packets only\n");
11268 + usbnet_write_cmd_async(dev, SET_ETHERNET_PACKET_FILTER,
11269 + USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
11270 + filter, 0, NULL, 0);
11273 +static const struct net_device_ops int51x1_netdev_ops = {
11274 + .ndo_open = usbnet_open,
11275 + .ndo_stop = usbnet_stop,
11276 + .ndo_start_xmit = usbnet_start_xmit,
11277 + .ndo_tx_timeout = usbnet_tx_timeout,
11278 + .ndo_change_mtu = usbnet_change_mtu,
11279 + .ndo_set_mac_address = eth_mac_addr,
11280 + .ndo_validate_addr = eth_validate_addr,
11281 + .ndo_set_rx_mode = int51x1_set_multicast,
11284 +static int int51x1_bind(struct usbnet *dev, struct usb_interface *intf)
11286 + int status = usbnet_get_ethernet_addr(dev, 3);
11291 + dev->net->hard_header_len += INT51X1_HEADER_SIZE;
11292 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
11293 + dev->net->netdev_ops = &int51x1_netdev_ops;
11295 + return usbnet_get_endpoints(dev, intf);
11298 +static const struct driver_info int51x1_info = {
11299 + .description = "Intellon usb powerline adapter",
11300 + .bind = int51x1_bind,
11301 + .rx_fixup = int51x1_rx_fixup,
11302 + .tx_fixup = int51x1_tx_fixup,
11305 + .flags = FLAG_ETHER,
11308 +static const struct usb_device_id products[] = {
11310 + USB_DEVICE(INT51X1_VENDOR_ID, INT51X1_PRODUCT_ID),
11311 + .driver_info = (unsigned long) &int51x1_info,
11315 +MODULE_DEVICE_TABLE(usb, products);
11317 +static struct usb_driver int51x1_driver = {
11318 + .name = "int51x1",
11319 + .id_table = products,
11320 + .probe = usbnet_probe,
11321 + .disconnect = usbnet_disconnect,
11322 + .suspend = usbnet_suspend,
11323 + .resume = usbnet_resume,
11324 + .disable_hub_initiated_lpm = 1,
11327 +module_usb_driver(int51x1_driver);
11329 +MODULE_AUTHOR("Peter Holik");
11330 +MODULE_DESCRIPTION("Intellon usb powerline adapter");
11331 +MODULE_LICENSE("GPL");
11332 diff -Naur backports-4.2.6-1.org/drivers/net/usb/ipheth.c backports-4.2.6-1/drivers/net/usb/ipheth.c
11333 --- backports-4.2.6-1.org/drivers/net/usb/ipheth.c 1970-01-01 01:00:00.000000000 +0100
11334 +++ backports-4.2.6-1/drivers/net/usb/ipheth.c 2016-06-28 14:35:17.985307220 +0200
11337 + * ipheth.c - Apple iPhone USB Ethernet driver
11339 + * Copyright (c) 2009 Diego Giagio <diego@giagio.com>
11340 + * All rights reserved.
11342 + * Redistribution and use in source and binary forms, with or without
11343 + * modification, are permitted provided that the following conditions
11345 + * 1. Redistributions of source code must retain the above copyright
11346 + * notice, this list of conditions and the following disclaimer.
11347 + * 2. Redistributions in binary form must reproduce the above copyright
11348 + * notice, this list of conditions and the following disclaimer in the
11349 + * documentation and/or other materials provided with the distribution.
11350 + * 3. Neither the name of GIAGIO.COM nor the names of its contributors
11351 + * may be used to endorse or promote products derived from this software
11352 + * without specific prior written permission.
11354 + * Alternatively, provided that this notice is retained in full, this
11355 + * software may be distributed under the terms of the GNU General
11356 + * Public License ("GPL") version 2, in which case the provisions of the
11357 + * GPL apply INSTEAD OF those given above.
11359 + * The provided data structures and external interfaces from this code
11360 + * are not restricted to be used by modules with a GPL compatible license.
11362 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11363 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11364 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11365 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11366 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11367 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11368 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11369 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11370 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11371 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
11372 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
11376 + * Attention: iPhone device must be paired, otherwise it won't respond to our
11377 + * driver. For more info: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
11381 +#include <linux/kernel.h>
11382 +#include <linux/errno.h>
11383 +#include <linux/slab.h>
11384 +#include <linux/module.h>
11385 +#include <linux/netdevice.h>
11386 +#include <linux/etherdevice.h>
11387 +#include <linux/ethtool.h>
11388 +#include <linux/usb.h>
11389 +#include <linux/workqueue.h>
11391 +#define USB_VENDOR_APPLE 0x05ac
11392 +#define USB_PRODUCT_IPHONE 0x1290
11393 +#define USB_PRODUCT_IPHONE_3G 0x1292
11394 +#define USB_PRODUCT_IPHONE_3GS 0x1294
11395 +#define USB_PRODUCT_IPHONE_4 0x1297
11396 +#define USB_PRODUCT_IPAD 0x129a
11397 +#define USB_PRODUCT_IPAD_2 0x12a2
11398 +#define USB_PRODUCT_IPAD_3 0x12a6
11399 +#define USB_PRODUCT_IPAD_MINI 0x12ab
11400 +#define USB_PRODUCT_IPHONE_4_VZW 0x129c
11401 +#define USB_PRODUCT_IPHONE_4S 0x12a0
11402 +#define USB_PRODUCT_IPHONE_5 0x12a8
11404 +#define IPHETH_USBINTF_CLASS 255
11405 +#define IPHETH_USBINTF_SUBCLASS 253
11406 +#define IPHETH_USBINTF_PROTO 1
11408 +#define IPHETH_BUF_SIZE 1516
11409 +#define IPHETH_IP_ALIGN 2 /* padding at front of URB */
11410 +#define IPHETH_TX_TIMEOUT (5 * HZ)
11412 +#define IPHETH_INTFNUM 2
11413 +#define IPHETH_ALT_INTFNUM 1
11415 +#define IPHETH_CTRL_ENDP 0x00
11416 +#define IPHETH_CTRL_BUF_SIZE 0x40
11417 +#define IPHETH_CTRL_TIMEOUT (5 * HZ)
11419 +#define IPHETH_CMD_GET_MACADDR 0x00
11420 +#define IPHETH_CMD_CARRIER_CHECK 0x45
11422 +#define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
11423 +#define IPHETH_CARRIER_ON 0x04
11425 +static struct usb_device_id ipheth_table[] = {
11426 + { USB_DEVICE_AND_INTERFACE_INFO(
11427 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
11428 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11429 + IPHETH_USBINTF_PROTO) },
11430 + { USB_DEVICE_AND_INTERFACE_INFO(
11431 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3G,
11432 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11433 + IPHETH_USBINTF_PROTO) },
11434 + { USB_DEVICE_AND_INTERFACE_INFO(
11435 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3GS,
11436 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11437 + IPHETH_USBINTF_PROTO) },
11438 + { USB_DEVICE_AND_INTERFACE_INFO(
11439 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4,
11440 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11441 + IPHETH_USBINTF_PROTO) },
11442 + { USB_DEVICE_AND_INTERFACE_INFO(
11443 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD,
11444 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11445 + IPHETH_USBINTF_PROTO) },
11446 + { USB_DEVICE_AND_INTERFACE_INFO(
11447 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_2,
11448 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11449 + IPHETH_USBINTF_PROTO) },
11450 + { USB_DEVICE_AND_INTERFACE_INFO(
11451 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_3,
11452 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11453 + IPHETH_USBINTF_PROTO) },
11454 + { USB_DEVICE_AND_INTERFACE_INFO(
11455 + USB_VENDOR_APPLE, USB_PRODUCT_IPAD_MINI,
11456 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11457 + IPHETH_USBINTF_PROTO) },
11458 + { USB_DEVICE_AND_INTERFACE_INFO(
11459 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4_VZW,
11460 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11461 + IPHETH_USBINTF_PROTO) },
11462 + { USB_DEVICE_AND_INTERFACE_INFO(
11463 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_4S,
11464 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11465 + IPHETH_USBINTF_PROTO) },
11466 + { USB_DEVICE_AND_INTERFACE_INFO(
11467 + USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_5,
11468 + IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
11469 + IPHETH_USBINTF_PROTO) },
11472 +MODULE_DEVICE_TABLE(usb, ipheth_table);
11474 +struct ipheth_device {
11475 + struct usb_device *udev;
11476 + struct usb_interface *intf;
11477 + struct net_device *net;
11478 + struct sk_buff *tx_skb;
11479 + struct urb *tx_urb;
11480 + struct urb *rx_urb;
11481 + unsigned char *tx_buf;
11482 + unsigned char *rx_buf;
11483 + unsigned char *ctrl_buf;
11486 + struct delayed_work carrier_work;
11489 +static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
11491 +static int ipheth_alloc_urbs(struct ipheth_device *iphone)
11493 + struct urb *tx_urb = NULL;
11494 + struct urb *rx_urb = NULL;
11495 + u8 *tx_buf = NULL;
11496 + u8 *rx_buf = NULL;
11498 + tx_urb = usb_alloc_urb(0, GFP_KERNEL);
11499 + if (tx_urb == NULL)
11500 + goto error_nomem;
11502 + rx_urb = usb_alloc_urb(0, GFP_KERNEL);
11503 + if (rx_urb == NULL)
11504 + goto free_tx_urb;
11506 + tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
11507 + GFP_KERNEL, &tx_urb->transfer_dma);
11508 + if (tx_buf == NULL)
11509 + goto free_rx_urb;
11511 + rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
11512 + GFP_KERNEL, &rx_urb->transfer_dma);
11513 + if (rx_buf == NULL)
11514 + goto free_tx_buf;
11517 + iphone->tx_urb = tx_urb;
11518 + iphone->rx_urb = rx_urb;
11519 + iphone->tx_buf = tx_buf;
11520 + iphone->rx_buf = rx_buf;
11524 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
11525 + tx_urb->transfer_dma);
11527 + usb_free_urb(rx_urb);
11529 + usb_free_urb(tx_urb);
11534 +static void ipheth_free_urbs(struct ipheth_device *iphone)
11536 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
11537 + iphone->rx_urb->transfer_dma);
11538 + usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
11539 + iphone->tx_urb->transfer_dma);
11540 + usb_free_urb(iphone->rx_urb);
11541 + usb_free_urb(iphone->tx_urb);
11544 +static void ipheth_kill_urbs(struct ipheth_device *dev)
11546 + usb_kill_urb(dev->tx_urb);
11547 + usb_kill_urb(dev->rx_urb);
11550 +static void ipheth_rcvbulk_callback(struct urb *urb)
11552 + struct ipheth_device *dev;
11553 + struct sk_buff *skb;
11558 + dev = urb->context;
11562 + status = urb->status;
11563 + switch (status) {
11565 + case -ECONNRESET:
11571 + dev_err(&dev->intf->dev, "%s: urb status: %d\n",
11572 + __func__, status);
11576 + if (urb->actual_length <= IPHETH_IP_ALIGN) {
11577 + dev->net->stats.rx_length_errors++;
11580 + len = urb->actual_length - IPHETH_IP_ALIGN;
11581 + buf = urb->transfer_buffer + IPHETH_IP_ALIGN;
11583 + skb = dev_alloc_skb(len);
11585 + dev_err(&dev->intf->dev, "%s: dev_alloc_skb: -ENOMEM\n",
11587 + dev->net->stats.rx_dropped++;
11591 + memcpy(skb_put(skb, len), buf, len);
11592 + skb->dev = dev->net;
11593 + skb->protocol = eth_type_trans(skb, dev->net);
11595 + dev->net->stats.rx_packets++;
11596 + dev->net->stats.rx_bytes += len;
11599 + ipheth_rx_submit(dev, GFP_ATOMIC);
11602 +static void ipheth_sndbulk_callback(struct urb *urb)
11604 + struct ipheth_device *dev;
11605 + int status = urb->status;
11607 + dev = urb->context;
11611 + if (status != 0 &&
11612 + status != -ENOENT &&
11613 + status != -ECONNRESET &&
11614 + status != -ESHUTDOWN)
11615 + dev_err(&dev->intf->dev, "%s: urb status: %d\n",
11616 + __func__, status);
11618 + dev_kfree_skb_irq(dev->tx_skb);
11619 + netif_wake_queue(dev->net);
11622 +static int ipheth_carrier_set(struct ipheth_device *dev)
11624 + struct usb_device *udev = dev->udev;
11627 + retval = usb_control_msg(udev,
11628 + usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
11629 + IPHETH_CMD_CARRIER_CHECK, /* request */
11630 + 0xc0, /* request type */
11631 + 0x00, /* value */
11632 + 0x02, /* index */
11633 + dev->ctrl_buf, IPHETH_CTRL_BUF_SIZE,
11634 + IPHETH_CTRL_TIMEOUT);
11635 + if (retval < 0) {
11636 + dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
11637 + __func__, retval);
11641 + if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
11642 + netif_carrier_on(dev->net);
11644 + netif_carrier_off(dev->net);
11649 +static void ipheth_carrier_check_work(struct work_struct *work)
11651 + struct ipheth_device *dev = container_of(work, struct ipheth_device,
11652 + carrier_work.work);
11654 + ipheth_carrier_set(dev);
11655 + schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
11658 +static int ipheth_get_macaddr(struct ipheth_device *dev)
11660 + struct usb_device *udev = dev->udev;
11661 + struct net_device *net = dev->net;
11664 + retval = usb_control_msg(udev,
11665 + usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
11666 + IPHETH_CMD_GET_MACADDR, /* request */
11667 + 0xc0, /* request type */
11668 + 0x00, /* value */
11669 + 0x02, /* index */
11671 + IPHETH_CTRL_BUF_SIZE,
11672 + IPHETH_CTRL_TIMEOUT);
11673 + if (retval < 0) {
11674 + dev_err(&dev->intf->dev, "%s: usb_control_msg: %d\n",
11675 + __func__, retval);
11676 + } else if (retval < ETH_ALEN) {
11677 + dev_err(&dev->intf->dev,
11678 + "%s: usb_control_msg: short packet: %d bytes\n",
11679 + __func__, retval);
11680 + retval = -EINVAL;
11682 + memcpy(net->dev_addr, dev->ctrl_buf, ETH_ALEN);
11689 +static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags)
11691 + struct usb_device *udev = dev->udev;
11694 + usb_fill_bulk_urb(dev->rx_urb, udev,
11695 + usb_rcvbulkpipe(udev, dev->bulk_in),
11696 + dev->rx_buf, IPHETH_BUF_SIZE,
11697 + ipheth_rcvbulk_callback,
11699 + dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
11701 + retval = usb_submit_urb(dev->rx_urb, mem_flags);
11703 + dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
11704 + __func__, retval);
11708 +static int ipheth_open(struct net_device *net)
11710 + struct ipheth_device *dev = netdev_priv(net);
11711 + struct usb_device *udev = dev->udev;
11714 + usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
11716 + retval = ipheth_carrier_set(dev);
11720 + retval = ipheth_rx_submit(dev, GFP_KERNEL);
11724 + schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
11725 + netif_start_queue(net);
11729 +static int ipheth_close(struct net_device *net)
11731 + struct ipheth_device *dev = netdev_priv(net);
11733 + cancel_delayed_work_sync(&dev->carrier_work);
11734 + netif_stop_queue(net);
11738 +static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
11740 + struct ipheth_device *dev = netdev_priv(net);
11741 + struct usb_device *udev = dev->udev;
11745 + if (skb->len > IPHETH_BUF_SIZE) {
11746 + WARN(1, "%s: skb too large: %d bytes\n", __func__, skb->len);
11747 + dev->net->stats.tx_dropped++;
11748 + dev_kfree_skb_irq(skb);
11749 + return NETDEV_TX_OK;
11752 + memcpy(dev->tx_buf, skb->data, skb->len);
11753 + if (skb->len < IPHETH_BUF_SIZE)
11754 + memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len);
11756 + usb_fill_bulk_urb(dev->tx_urb, udev,
11757 + usb_sndbulkpipe(udev, dev->bulk_out),
11758 + dev->tx_buf, IPHETH_BUF_SIZE,
11759 + ipheth_sndbulk_callback,
11761 + dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
11763 + retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
11765 + dev_err(&dev->intf->dev, "%s: usb_submit_urb: %d\n",
11766 + __func__, retval);
11767 + dev->net->stats.tx_errors++;
11768 + dev_kfree_skb_irq(skb);
11770 + dev->tx_skb = skb;
11772 + dev->net->stats.tx_packets++;
11773 + dev->net->stats.tx_bytes += skb->len;
11774 + netif_stop_queue(net);
11777 + return NETDEV_TX_OK;
11780 +static void ipheth_tx_timeout(struct net_device *net)
11782 + struct ipheth_device *dev = netdev_priv(net);
11784 + dev_err(&dev->intf->dev, "%s: TX timeout\n", __func__);
11785 + dev->net->stats.tx_errors++;
11786 + usb_unlink_urb(dev->tx_urb);
11789 +static u32 ipheth_ethtool_op_get_link(struct net_device *net)
11791 + struct ipheth_device *dev = netdev_priv(net);
11792 + return netif_carrier_ok(dev->net);
11795 +static const struct ethtool_ops ops = {
11796 + .get_link = ipheth_ethtool_op_get_link
11799 +static const struct net_device_ops ipheth_netdev_ops = {
11800 + .ndo_open = ipheth_open,
11801 + .ndo_stop = ipheth_close,
11802 + .ndo_start_xmit = ipheth_tx,
11803 + .ndo_tx_timeout = ipheth_tx_timeout,
11806 +static int ipheth_probe(struct usb_interface *intf,
11807 + const struct usb_device_id *id)
11809 + struct usb_device *udev = interface_to_usbdev(intf);
11810 + struct usb_host_interface *hintf;
11811 + struct usb_endpoint_descriptor *endp;
11812 + struct ipheth_device *dev;
11813 + struct net_device *netdev;
11817 + netdev = alloc_etherdev(sizeof(struct ipheth_device));
11821 + netdev->netdev_ops = &ipheth_netdev_ops;
11822 + netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
11823 + strcpy(netdev->name, "eth%d");
11825 + dev = netdev_priv(netdev);
11826 + dev->udev = udev;
11827 + dev->net = netdev;
11828 + dev->intf = intf;
11830 + /* Set up endpoints */
11831 + hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
11832 + if (hintf == NULL) {
11833 + retval = -ENODEV;
11834 + dev_err(&intf->dev, "Unable to find alternate settings interface\n");
11835 + goto err_endpoints;
11838 + for (i = 0; i < hintf->desc.bNumEndpoints; i++) {
11839 + endp = &hintf->endpoint[i].desc;
11840 + if (usb_endpoint_is_bulk_in(endp))
11841 + dev->bulk_in = endp->bEndpointAddress;
11842 + else if (usb_endpoint_is_bulk_out(endp))
11843 + dev->bulk_out = endp->bEndpointAddress;
11845 + if (!(dev->bulk_in && dev->bulk_out)) {
11846 + retval = -ENODEV;
11847 + dev_err(&intf->dev, "Unable to find endpoints\n");
11848 + goto err_endpoints;
11851 + dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
11852 + if (dev->ctrl_buf == NULL) {
11853 + retval = -ENOMEM;
11854 + goto err_alloc_ctrl_buf;
11857 + retval = ipheth_get_macaddr(dev);
11859 + goto err_get_macaddr;
11861 + INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
11863 + retval = ipheth_alloc_urbs(dev);
11865 + dev_err(&intf->dev, "error allocating urbs: %d\n", retval);
11866 + goto err_alloc_urbs;
11869 + usb_set_intfdata(intf, dev);
11871 + SET_NETDEV_DEV(netdev, &intf->dev);
11872 + netdev->ethtool_ops = &ops;
11874 + retval = register_netdev(netdev);
11876 + dev_err(&intf->dev, "error registering netdev: %d\n", retval);
11878 + goto err_register_netdev;
11881 + dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
11884 +err_register_netdev:
11885 + ipheth_free_urbs(dev);
11888 +err_alloc_ctrl_buf:
11889 + kfree(dev->ctrl_buf);
11891 + free_netdev(netdev);
11895 +static void ipheth_disconnect(struct usb_interface *intf)
11897 + struct ipheth_device *dev;
11899 + dev = usb_get_intfdata(intf);
11900 + if (dev != NULL) {
11901 + unregister_netdev(dev->net);
11902 + ipheth_kill_urbs(dev);
11903 + ipheth_free_urbs(dev);
11904 + kfree(dev->ctrl_buf);
11905 + free_netdev(dev->net);
11907 + usb_set_intfdata(intf, NULL);
11908 + dev_info(&intf->dev, "Apple iPhone USB Ethernet now disconnected\n");
11911 +static struct usb_driver ipheth_driver = {
11912 + .name = "ipheth",
11913 + .probe = ipheth_probe,
11914 + .disconnect = ipheth_disconnect,
11915 + .id_table = ipheth_table,
11916 + .disable_hub_initiated_lpm = 1,
11919 +module_usb_driver(ipheth_driver);
11921 +MODULE_AUTHOR("Diego Giagio <diego@giagio.com>");
11922 +MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
11923 +MODULE_LICENSE("Dual BSD/GPL");
11924 diff -Naur backports-4.2.6-1.org/drivers/net/usb/kalmia.c backports-4.2.6-1/drivers/net/usb/kalmia.c
11925 --- backports-4.2.6-1.org/drivers/net/usb/kalmia.c 1970-01-01 01:00:00.000000000 +0100
11926 +++ backports-4.2.6-1/drivers/net/usb/kalmia.c 2016-06-28 14:35:17.985307220 +0200
11929 + * USB network interface driver for Samsung Kalmia based LTE USB modem like the
11930 + * Samsung GT-B3730 and GT-B3710.
11932 + * Copyright (C) 2011 Marius Bjoernstad Kotsbak <marius@kotsbak.com>
11934 + * Sponsored by Quicklink Video Distribution Services Ltd.
11936 + * Based on the cdc_eem module.
11938 + * This program is free software; you can redistribute it and/or modify
11939 + * it under the terms of the GNU General Public License as published by
11940 + * the Free Software Foundation; either version 2 of the License, or
11941 + * (at your option) any later version.
11944 +#include <linux/module.h>
11945 +#include <linux/netdevice.h>
11946 +#include <linux/etherdevice.h>
11947 +#include <linux/ctype.h>
11948 +#include <linux/ethtool.h>
11949 +#include <linux/workqueue.h>
11950 +#include <linux/mii.h>
11951 +#include <linux/usb.h>
11952 +#include <linux/crc32.h>
11953 +#include <linux/usb/cdc.h>
11954 +#include <linux/usb/usbnet.h>
11955 +#include <linux/gfp.h>
11958 + * The Samsung Kalmia based LTE USB modems have a CDC ACM port for modem control
11959 + * handled by the "option" module and an ethernet data port handled by this
11962 + * The stick must first be switched into modem mode by usb_modeswitch
11963 + * or similar tool. Then the modem gets sent two initialization packets by
11964 + * this module, which gives the MAC address of the device. User space can then
11965 + * connect the modem using AT commands through the ACM port and then use
11966 + * DHCP on the network interface exposed by this module. Network packets are
11967 + * sent to and from the modem in a proprietary format discovered after watching
11968 + * the behavior of the windows driver for the modem.
11970 + * More information about the use of the modem is available in usb_modeswitch
11971 + * forum and the project page:
11973 + * http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?t=465
11974 + * https://github.com/mkotsbak/Samsung-GT-B3730-linux-driver
11977 +/* #define DEBUG */
11978 +/* #define VERBOSE */
11980 +#define KALMIA_HEADER_LENGTH 6
11981 +#define KALMIA_ALIGN_SIZE 4
11982 +#define KALMIA_USB_TIMEOUT 10000
11984 +/*-------------------------------------------------------------------------*/
11987 +kalmia_send_init_packet(struct usbnet *dev, u8 *init_msg, u8 init_msg_len,
11988 + u8 *buffer, u8 expected_len)
11993 + netdev_dbg(dev->net, "Sending init packet");
11995 + status = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 0x02),
11996 + init_msg, init_msg_len, &act_len, KALMIA_USB_TIMEOUT);
11997 + if (status != 0) {
11998 + netdev_err(dev->net,
11999 + "Error sending init packet. Status %i, length %i\n",
12000 + status, act_len);
12003 + else if (act_len != init_msg_len) {
12004 + netdev_err(dev->net,
12005 + "Did not send all of init packet. Bytes sent: %i",
12009 + netdev_dbg(dev->net, "Successfully sent init packet.");
12012 + status = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, 0x81),
12013 + buffer, expected_len, &act_len, KALMIA_USB_TIMEOUT);
12016 + netdev_err(dev->net,
12017 + "Error receiving init result. Status %i, length %i\n",
12018 + status, act_len);
12019 + else if (act_len != expected_len)
12020 + netdev_err(dev->net, "Unexpected init result length: %i\n",
12027 +kalmia_init_and_get_ethernet_addr(struct usbnet *dev, u8 *ethernet_addr)
12029 + static const char init_msg_1[] =
12030 + { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
12032 + static const char init_msg_2[] =
12033 + { 0x57, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xf4,
12035 + static const int buflen = 28;
12039 + usb_buf = kmalloc(buflen, GFP_DMA | GFP_KERNEL);
12043 + memcpy(usb_buf, init_msg_1, 12);
12044 + status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_1)
12045 + / sizeof(init_msg_1[0]), usb_buf, 24);
12049 + memcpy(usb_buf, init_msg_2, 12);
12050 + status = kalmia_send_init_packet(dev, usb_buf, sizeof(init_msg_2)
12051 + / sizeof(init_msg_2[0]), usb_buf, 28);
12055 + memcpy(ethernet_addr, usb_buf + 10, ETH_ALEN);
12062 +kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
12065 + u8 ethernet_addr[ETH_ALEN];
12067 + /* Don't bind to AT command interface */
12068 + if (intf->cur_altsetting->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
12071 + dev->in = usb_rcvbulkpipe(dev->udev, 0x81 & USB_ENDPOINT_NUMBER_MASK);
12072 + dev->out = usb_sndbulkpipe(dev->udev, 0x02 & USB_ENDPOINT_NUMBER_MASK);
12073 + dev->status = NULL;
12075 + dev->net->hard_header_len += KALMIA_HEADER_LENGTH;
12076 + dev->hard_mtu = 1400;
12077 + dev->rx_urb_size = dev->hard_mtu * 10; // Found as optimal after testing
12079 + status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
12081 + if (status < 0) {
12082 + usb_set_intfdata(intf, NULL);
12083 + usb_driver_release_interface(driver_of(intf), intf);
12087 + memcpy(dev->net->dev_addr, ethernet_addr, ETH_ALEN);
12092 +static struct sk_buff *
12093 +kalmia_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
12095 + struct sk_buff *skb2 = NULL;
12097 + unsigned char *header_start;
12098 + unsigned char ether_type_1, ether_type_2;
12099 + u8 remainder, padlen = 0;
12101 + if (!skb_cloned(skb)) {
12102 + int headroom = skb_headroom(skb);
12103 + int tailroom = skb_tailroom(skb);
12105 + if ((tailroom >= KALMIA_ALIGN_SIZE) && (headroom
12106 + >= KALMIA_HEADER_LENGTH))
12109 + if ((headroom + tailroom) > (KALMIA_HEADER_LENGTH
12110 + + KALMIA_ALIGN_SIZE)) {
12111 + skb->data = memmove(skb->head + KALMIA_HEADER_LENGTH,
12112 + skb->data, skb->len);
12113 + skb_set_tail_pointer(skb, skb->len);
12118 + skb2 = skb_copy_expand(skb, KALMIA_HEADER_LENGTH,
12119 + KALMIA_ALIGN_SIZE, flags);
12123 + dev_kfree_skb_any(skb);
12127 + header_start = skb_push(skb, KALMIA_HEADER_LENGTH);
12128 + ether_type_1 = header_start[KALMIA_HEADER_LENGTH + 12];
12129 + ether_type_2 = header_start[KALMIA_HEADER_LENGTH + 13];
12131 + netdev_dbg(dev->net, "Sending etherType: %02x%02x", ether_type_1,
12134 + /* According to empiric data for data packages */
12135 + header_start[0] = 0x57;
12136 + header_start[1] = 0x44;
12137 + content_len = skb->len - KALMIA_HEADER_LENGTH;
12139 + put_unaligned_le16(content_len, &header_start[2]);
12140 + header_start[4] = ether_type_1;
12141 + header_start[5] = ether_type_2;
12143 + /* Align to 4 bytes by padding with zeros */
12144 + remainder = skb->len % KALMIA_ALIGN_SIZE;
12145 + if (remainder > 0) {
12146 + padlen = KALMIA_ALIGN_SIZE - remainder;
12147 + memset(skb_put(skb, padlen), 0, padlen);
12150 + netdev_dbg(dev->net,
12151 + "Sending package with length %i and padding %i. Header: %6phC.",
12152 + content_len, padlen, header_start);
12158 +kalmia_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
12161 + * Our task here is to strip off framing, leaving skb with one
12162 + * data frame for the usbnet framework code to process.
12164 + static const u8 HEADER_END_OF_USB_PACKET[] =
12165 + { 0x57, 0x5a, 0x00, 0x00, 0x08, 0x00 };
12166 + static const u8 EXPECTED_UNKNOWN_HEADER_1[] =
12167 + { 0x57, 0x43, 0x1e, 0x00, 0x15, 0x02 };
12168 + static const u8 EXPECTED_UNKNOWN_HEADER_2[] =
12169 + { 0x57, 0x50, 0x0e, 0x00, 0x00, 0x00 };
12172 + /* incomplete header? */
12173 + if (skb->len < KALMIA_HEADER_LENGTH)
12177 + struct sk_buff *skb2 = NULL;
12178 + u8 *header_start;
12179 + u16 usb_packet_length, ether_packet_length;
12182 + header_start = skb->data;
12184 + if (unlikely(header_start[0] != 0x57 || header_start[1] != 0x44)) {
12185 + if (!memcmp(header_start, EXPECTED_UNKNOWN_HEADER_1,
12186 + sizeof(EXPECTED_UNKNOWN_HEADER_1)) || !memcmp(
12187 + header_start, EXPECTED_UNKNOWN_HEADER_2,
12188 + sizeof(EXPECTED_UNKNOWN_HEADER_2))) {
12189 + netdev_dbg(dev->net,
12190 + "Received expected unknown frame header: %6phC. Package length: %i\n",
12192 + skb->len - KALMIA_HEADER_LENGTH);
12195 + netdev_err(dev->net,
12196 + "Received unknown frame header: %6phC. Package length: %i\n",
12198 + skb->len - KALMIA_HEADER_LENGTH);
12203 + netdev_dbg(dev->net,
12204 + "Received header: %6phC. Package length: %i\n",
12205 + header_start, skb->len - KALMIA_HEADER_LENGTH);
12207 + /* subtract start header and end header */
12208 + usb_packet_length = skb->len - (2 * KALMIA_HEADER_LENGTH);
12209 + ether_packet_length = get_unaligned_le16(&header_start[2]);
12210 + skb_pull(skb, KALMIA_HEADER_LENGTH);
12212 + /* Some small packets misses end marker */
12213 + if (usb_packet_length < ether_packet_length) {
12214 + ether_packet_length = usb_packet_length
12215 + + KALMIA_HEADER_LENGTH;
12219 + netdev_dbg(dev->net, "Correct package length #%i", i
12222 + is_last = (memcmp(skb->data + ether_packet_length,
12223 + HEADER_END_OF_USB_PACKET,
12224 + sizeof(HEADER_END_OF_USB_PACKET)) == 0);
12226 + header_start = skb->data + ether_packet_length;
12227 + netdev_dbg(dev->net,
12228 + "End header: %6phC. Package length: %i\n",
12230 + skb->len - KALMIA_HEADER_LENGTH);
12238 + skb2 = skb_clone(skb, GFP_ATOMIC);
12239 + if (unlikely(!skb2))
12243 + skb_trim(skb2, ether_packet_length);
12249 + usbnet_skb_return(dev, skb2);
12250 + skb_pull(skb, ether_packet_length);
12255 + while (skb->len);
12260 +static const struct driver_info kalmia_info = {
12261 + .description = "Samsung Kalmia LTE USB dongle",
12262 + .flags = FLAG_WWAN,
12263 + .bind = kalmia_bind,
12264 + .rx_fixup = kalmia_rx_fixup,
12265 + .tx_fixup = kalmia_tx_fixup
12268 +/*-------------------------------------------------------------------------*/
12270 +static const struct usb_device_id products[] = {
12271 + /* The unswitched USB ID, to get the module auto loaded: */
12272 + { USB_DEVICE(0x04e8, 0x689a) },
12273 + /* The stick swithed into modem (by e.g. usb_modeswitch): */
12274 + { USB_DEVICE(0x04e8, 0x6889),
12275 + .driver_info = (unsigned long) &kalmia_info, },
12276 + { /* EMPTY == end of list */} };
12277 +MODULE_DEVICE_TABLE( usb, products);
12279 +static struct usb_driver kalmia_driver = {
12280 + .name = "kalmia",
12281 + .id_table = products,
12282 + .probe = usbnet_probe,
12283 + .disconnect = usbnet_disconnect,
12284 + .suspend = usbnet_suspend,
12285 + .resume = usbnet_resume,
12286 + .disable_hub_initiated_lpm = 1,
12289 +module_usb_driver(kalmia_driver);
12291 +MODULE_AUTHOR("Marius Bjoernstad Kotsbak <marius@kotsbak.com>");
12292 +MODULE_DESCRIPTION("Samsung Kalmia USB network driver");
12293 +MODULE_LICENSE("GPL");
12294 diff -Naur backports-4.2.6-1.org/drivers/net/usb/kaweth.c backports-4.2.6-1/drivers/net/usb/kaweth.c
12295 --- backports-4.2.6-1.org/drivers/net/usb/kaweth.c 1970-01-01 01:00:00.000000000 +0100
12296 +++ backports-4.2.6-1/drivers/net/usb/kaweth.c 2016-06-28 14:35:17.988640553 +0200
12298 +/****************************************************************
12300 + * kaweth.c - driver for KL5KUSB101 based USB->Ethernet
12302 + * (c) 2000 Interlan Communications
12303 + * (c) 2000 Stephane Alnet
12304 + * (C) 2001 Brad Hards
12305 + * (C) 2002 Oliver Neukum
12307 + * Original author: The Zapman <zapman@interlan.net>
12308 + * Inspired by, and much credit goes to Michael Rothwell
12309 + * <rothwell@interlan.net> for the test equipment, help, and patience
12310 + * Based off of (and with thanks to) Petko Manolov's pegaus.c driver.
12311 + * Also many thanks to Joel Silverman and Ed Surprenant at Kawasaki
12312 + * for providing the firmware and driver resources.
12314 + * This program is free software; you can redistribute it and/or
12315 + * modify it under the terms of the GNU General Public License as
12316 + * published by the Free Software Foundation; either version 2, or
12317 + * (at your option) any later version.
12319 + * This program is distributed in the hope that it will be useful,
12320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12322 + * GNU General Public License for more details.
12324 + * You should have received a copy of the GNU General Public License
12325 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
12327 + ****************************************************************/
12330 + * Develop test procedures for USB net interfaces
12331 + * Run test procedures
12332 + * Fix bugs from previous two steps
12333 + * Snoop other OSs for any tricks we're not doing
12334 + * Reduce arbitrary timeouts
12335 + * Smart multicast support
12336 + * Temporary MAC change support
12337 + * Tunable SOFs parameter - ioctl()?
12338 + * Ethernet stats collection
12339 + * Code formatting improvements
12342 +#include <linux/module.h>
12343 +#include <linux/slab.h>
12344 +#include <linux/string.h>
12345 +#include <linux/delay.h>
12346 +#include <linux/netdevice.h>
12347 +#include <linux/etherdevice.h>
12348 +#include <linux/usb.h>
12349 +#include <linux/types.h>
12350 +#include <linux/ethtool.h>
12351 +#include <linux/dma-mapping.h>
12352 +#include <linux/wait.h>
12353 +#include <linux/firmware.h>
12354 +#include <asm/uaccess.h>
12355 +#include <asm/byteorder.h>
12359 +#define KAWETH_MTU 1514
12360 +#define KAWETH_BUF_SIZE 1664
12361 +#define KAWETH_TX_TIMEOUT (5 * HZ)
12362 +#define KAWETH_SCRATCH_SIZE 32
12363 +#define KAWETH_FIRMWARE_BUF_SIZE 4096
12364 +#define KAWETH_CONTROL_TIMEOUT (30000)
12366 +#define KAWETH_STATUS_BROKEN 0x0000001
12367 +#define KAWETH_STATUS_CLOSING 0x0000002
12368 +#define KAWETH_STATUS_SUSPENDING 0x0000004
12370 +#define KAWETH_STATUS_BLOCKED (KAWETH_STATUS_CLOSING | KAWETH_STATUS_SUSPENDING)
12372 +#define KAWETH_PACKET_FILTER_PROMISCUOUS 0x01
12373 +#define KAWETH_PACKET_FILTER_ALL_MULTICAST 0x02
12374 +#define KAWETH_PACKET_FILTER_DIRECTED 0x04
12375 +#define KAWETH_PACKET_FILTER_BROADCAST 0x08
12376 +#define KAWETH_PACKET_FILTER_MULTICAST 0x10
12379 +#define KAWETH_COMMAND_GET_ETHERNET_DESC 0x00
12380 +#define KAWETH_COMMAND_MULTICAST_FILTERS 0x01
12381 +#define KAWETH_COMMAND_SET_PACKET_FILTER 0x02
12382 +#define KAWETH_COMMAND_STATISTICS 0x03
12383 +#define KAWETH_COMMAND_SET_TEMP_MAC 0x06
12384 +#define KAWETH_COMMAND_GET_TEMP_MAC 0x07
12385 +#define KAWETH_COMMAND_SET_URB_SIZE 0x08
12386 +#define KAWETH_COMMAND_SET_SOFS_WAIT 0x09
12387 +#define KAWETH_COMMAND_SCAN 0xFF
12389 +#define KAWETH_SOFS_TO_WAIT 0x05
12391 +#define INTBUFFERSIZE 4
12393 +#define STATE_OFFSET 0
12394 +#define STATE_MASK 0x40
12395 +#define STATE_SHIFT 5
12397 +#define IS_BLOCKED(s) (s & KAWETH_STATUS_BLOCKED)
12400 +MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-picardie.fr>, Brad Hards <bhards@bigpond.net.au> and Oliver Neukum <oliver@neukum.org>");
12401 +MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver");
12402 +MODULE_LICENSE("GPL");
12403 +MODULE_FIRMWARE("kaweth/new_code.bin");
12404 +MODULE_FIRMWARE("kaweth/new_code_fix.bin");
12405 +MODULE_FIRMWARE("kaweth/trigger_code.bin");
12406 +MODULE_FIRMWARE("kaweth/trigger_code_fix.bin");
12408 +static const char driver_name[] = "kaweth";
12410 +static int kaweth_probe(
12411 + struct usb_interface *intf,
12412 + const struct usb_device_id *id /* from id_table */
12414 +static void kaweth_disconnect(struct usb_interface *intf);
12415 +static int kaweth_internal_control_msg(struct usb_device *usb_dev,
12416 + unsigned int pipe,
12417 + struct usb_ctrlrequest *cmd, void *data,
12418 + int len, int timeout);
12419 +static int kaweth_suspend(struct usb_interface *intf, pm_message_t message);
12420 +static int kaweth_resume(struct usb_interface *intf);
12422 +/****************************************************************
12424 + ****************************************************************/
12425 +static struct usb_device_id usb_klsi_table[] = {
12426 + { USB_DEVICE(0x03e8, 0x0008) }, /* AOX Endpoints USB Ethernet */
12427 + { USB_DEVICE(0x04bb, 0x0901) }, /* I-O DATA USB-ET/T */
12428 + { USB_DEVICE(0x0506, 0x03e8) }, /* 3Com 3C19250 */
12429 + { USB_DEVICE(0x0506, 0x11f8) }, /* 3Com 3C460 */
12430 + { USB_DEVICE(0x0557, 0x2002) }, /* ATEN USB Ethernet */
12431 + { USB_DEVICE(0x0557, 0x4000) }, /* D-Link DSB-650C */
12432 + { USB_DEVICE(0x0565, 0x0002) }, /* Peracom Enet */
12433 + { USB_DEVICE(0x0565, 0x0003) }, /* Optus@Home UEP1045A */
12434 + { USB_DEVICE(0x0565, 0x0005) }, /* Peracom Enet2 */
12435 + { USB_DEVICE(0x05e9, 0x0008) }, /* KLSI KL5KUSB101B */
12436 + { USB_DEVICE(0x05e9, 0x0009) }, /* KLSI KL5KUSB101B (Board change) */
12437 + { USB_DEVICE(0x066b, 0x2202) }, /* Linksys USB10T */
12438 + { USB_DEVICE(0x06e1, 0x0008) }, /* ADS USB-10BT */
12439 + { USB_DEVICE(0x06e1, 0x0009) }, /* ADS USB-10BT */
12440 + { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2202USB */
12441 + { USB_DEVICE(0x07aa, 0x0001) }, /* Correga K.K. */
12442 + { USB_DEVICE(0x07b8, 0x4000) }, /* D-Link DU-E10 */
12443 + { USB_DEVICE(0x07c9, 0xb010) }, /* Allied Telesyn AT-USB10 USB Ethernet Adapter */
12444 + { USB_DEVICE(0x0846, 0x1001) }, /* NetGear EA-101 */
12445 + { USB_DEVICE(0x0846, 0x1002) }, /* NetGear EA-101 */
12446 + { USB_DEVICE(0x085a, 0x0008) }, /* PortGear Ethernet Adapter */
12447 + { USB_DEVICE(0x085a, 0x0009) }, /* PortGear Ethernet Adapter */
12448 + { USB_DEVICE(0x087d, 0x5704) }, /* Jaton USB Ethernet Device Adapter */
12449 + { USB_DEVICE(0x0951, 0x0008) }, /* Kingston Technology USB Ethernet Adapter */
12450 + { USB_DEVICE(0x095a, 0x3003) }, /* Portsmith Express Ethernet Adapter */
12451 + { USB_DEVICE(0x10bd, 0x1427) }, /* ASANTE USB To Ethernet Adapter */
12452 + { USB_DEVICE(0x1342, 0x0204) }, /* Mobility USB-Ethernet Adapter */
12453 + { USB_DEVICE(0x13d2, 0x0400) }, /* Shark Pocket Adapter */
12454 + { USB_DEVICE(0x1485, 0x0001) }, /* Silicom U2E */
12455 + { USB_DEVICE(0x1485, 0x0002) }, /* Psion Dacom Gold Port Ethernet */
12456 + { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */
12457 + { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */
12458 + { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */
12459 + { USB_DEVICE(0x1668, 0x0323) }, /* Actiontec USB Ethernet */
12460 + { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */
12461 + {} /* Null terminator */
12464 +MODULE_DEVICE_TABLE (usb, usb_klsi_table);
12466 +/****************************************************************
12468 + ****************************************************************/
12469 +static struct usb_driver kaweth_driver = {
12470 + .name = driver_name,
12471 + .probe = kaweth_probe,
12472 + .disconnect = kaweth_disconnect,
12473 + .suspend = kaweth_suspend,
12474 + .resume = kaweth_resume,
12475 + .id_table = usb_klsi_table,
12476 + .supports_autosuspend = 1,
12477 + .disable_hub_initiated_lpm = 1,
12480 +typedef __u8 eth_addr_t[6];
12482 +/****************************************************************
12484 + ****************************************************************/
12485 +struct usb_eth_dev {
12492 +/****************************************************************
12493 + * kaweth_ethernet_configuration
12495 + ****************************************************************/
12496 +struct kaweth_ethernet_configuration
12501 + eth_addr_t hw_addr;
12502 + __u32 statistics_mask;
12503 + __le16 segment_size;
12504 + __u16 max_multicast_filters;
12508 +/****************************************************************
12510 + ****************************************************************/
12511 +struct kaweth_device
12513 + spinlock_t device_lock;
12517 + int suspend_lowmem_rx;
12518 + int suspend_lowmem_ctrl;
12521 + struct delayed_work lowmem_work;
12523 + struct usb_device *dev;
12524 + struct usb_interface *intf;
12525 + struct net_device *net;
12526 + wait_queue_head_t term_wait;
12528 + struct urb *rx_urb;
12529 + struct urb *tx_urb;
12530 + struct urb *irq_urb;
12532 + dma_addr_t intbufferhandle;
12534 + dma_addr_t rxbufferhandle;
12538 + struct sk_buff *tx_skb;
12540 + __u8 *firmware_buf;
12541 + __u8 scratch[KAWETH_SCRATCH_SIZE];
12542 + __u16 packet_filter_bitmap;
12544 + struct kaweth_ethernet_configuration configuration;
12546 + struct net_device_stats stats;
12549 +/****************************************************************
12551 + ****************************************************************/
12552 +static int kaweth_control(struct kaweth_device *kaweth,
12553 + unsigned int pipe,
12555 + __u8 requesttype,
12562 + struct usb_ctrlrequest *dr;
12565 + netdev_dbg(kaweth->net, "kaweth_control()\n");
12567 + if(in_interrupt()) {
12568 + netdev_dbg(kaweth->net, "in_interrupt()\n");
12572 + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
12576 + dr->bRequestType = requesttype;
12577 + dr->bRequest = request;
12578 + dr->wValue = cpu_to_le16(value);
12579 + dr->wIndex = cpu_to_le16(index);
12580 + dr->wLength = cpu_to_le16(size);
12582 + retval = kaweth_internal_control_msg(kaweth->dev,
12593 +/****************************************************************
12594 + * kaweth_read_configuration
12595 + ****************************************************************/
12596 +static int kaweth_read_configuration(struct kaweth_device *kaweth)
12600 + netdev_dbg(kaweth->net, "Reading kaweth configuration\n");
12602 + retval = kaweth_control(kaweth,
12603 + usb_rcvctrlpipe(kaweth->dev, 0),
12604 + KAWETH_COMMAND_GET_ETHERNET_DESC,
12605 + USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
12608 + (void *)&kaweth->configuration,
12609 + sizeof(kaweth->configuration),
12610 + KAWETH_CONTROL_TIMEOUT);
12615 +/****************************************************************
12616 + * kaweth_set_urb_size
12617 + ****************************************************************/
12618 +static int kaweth_set_urb_size(struct kaweth_device *kaweth, __u16 urb_size)
12622 + netdev_dbg(kaweth->net, "Setting URB size to %d\n", (unsigned)urb_size);
12624 + retval = kaweth_control(kaweth,
12625 + usb_sndctrlpipe(kaweth->dev, 0),
12626 + KAWETH_COMMAND_SET_URB_SIZE,
12627 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12630 + (void *)&kaweth->scratch,
12632 + KAWETH_CONTROL_TIMEOUT);
12637 +/****************************************************************
12638 + * kaweth_set_sofs_wait
12639 + ****************************************************************/
12640 +static int kaweth_set_sofs_wait(struct kaweth_device *kaweth, __u16 sofs_wait)
12644 + netdev_dbg(kaweth->net, "Set SOFS wait to %d\n", (unsigned)sofs_wait);
12646 + retval = kaweth_control(kaweth,
12647 + usb_sndctrlpipe(kaweth->dev, 0),
12648 + KAWETH_COMMAND_SET_SOFS_WAIT,
12649 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12652 + (void *)&kaweth->scratch,
12654 + KAWETH_CONTROL_TIMEOUT);
12659 +/****************************************************************
12660 + * kaweth_set_receive_filter
12661 + ****************************************************************/
12662 +static int kaweth_set_receive_filter(struct kaweth_device *kaweth,
12663 + __u16 receive_filter)
12667 + netdev_dbg(kaweth->net, "Set receive filter to %d\n",
12668 + (unsigned)receive_filter);
12670 + retval = kaweth_control(kaweth,
12671 + usb_sndctrlpipe(kaweth->dev, 0),
12672 + KAWETH_COMMAND_SET_PACKET_FILTER,
12673 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12676 + (void *)&kaweth->scratch,
12678 + KAWETH_CONTROL_TIMEOUT);
12683 +/****************************************************************
12684 + * kaweth_download_firmware
12685 + ****************************************************************/
12686 +static int kaweth_download_firmware(struct kaweth_device *kaweth,
12687 + const char *fwname,
12691 + const struct firmware *fw;
12695 + ret = request_firmware(&fw, fwname, &kaweth->dev->dev);
12697 + dev_err(&kaweth->intf->dev, "Firmware request failed\n");
12701 + if (fw->size > KAWETH_FIRMWARE_BUF_SIZE) {
12702 + dev_err(&kaweth->intf->dev, "Firmware too big: %zu\n",
12704 + release_firmware(fw);
12707 + data_len = fw->size;
12708 + memcpy(kaweth->firmware_buf, fw->data, fw->size);
12710 + release_firmware(fw);
12712 + kaweth->firmware_buf[2] = (data_len & 0xFF) - 7;
12713 + kaweth->firmware_buf[3] = data_len >> 8;
12714 + kaweth->firmware_buf[4] = type;
12715 + kaweth->firmware_buf[5] = interrupt;
12717 + netdev_dbg(kaweth->net, "High: %i, Low:%i\n", kaweth->firmware_buf[3],
12718 + kaweth->firmware_buf[2]);
12720 + netdev_dbg(kaweth->net,
12721 + "Downloading firmware at %p to kaweth device at %p\n",
12722 + kaweth->firmware_buf, kaweth);
12723 + netdev_dbg(kaweth->net, "Firmware length: %d\n", data_len);
12725 + return kaweth_control(kaweth,
12726 + usb_sndctrlpipe(kaweth->dev, 0),
12727 + KAWETH_COMMAND_SCAN,
12728 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12731 + (void *)kaweth->firmware_buf,
12733 + KAWETH_CONTROL_TIMEOUT);
12736 +/****************************************************************
12737 + * kaweth_trigger_firmware
12738 + ****************************************************************/
12739 +static int kaweth_trigger_firmware(struct kaweth_device *kaweth,
12742 + kaweth->firmware_buf[0] = 0xB6;
12743 + kaweth->firmware_buf[1] = 0xC3;
12744 + kaweth->firmware_buf[2] = 0x01;
12745 + kaweth->firmware_buf[3] = 0x00;
12746 + kaweth->firmware_buf[4] = 0x06;
12747 + kaweth->firmware_buf[5] = interrupt;
12748 + kaweth->firmware_buf[6] = 0x00;
12749 + kaweth->firmware_buf[7] = 0x00;
12751 + netdev_dbg(kaweth->net, "Triggering firmware\n");
12753 + return kaweth_control(kaweth,
12754 + usb_sndctrlpipe(kaweth->dev, 0),
12755 + KAWETH_COMMAND_SCAN,
12756 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
12759 + (void *)kaweth->firmware_buf,
12761 + KAWETH_CONTROL_TIMEOUT);
12764 +/****************************************************************
12766 + ****************************************************************/
12767 +static int kaweth_reset(struct kaweth_device *kaweth)
12771 + netdev_dbg(kaweth->net, "kaweth_reset(%p)\n", kaweth);
12772 + result = usb_reset_configuration(kaweth->dev);
12775 + netdev_dbg(kaweth->net, "kaweth_reset() returns %d.\n", result);
12780 +static void kaweth_usb_receive(struct urb *);
12781 +static int kaweth_resubmit_rx_urb(struct kaweth_device *, gfp_t);
12783 +/****************************************************************
12785 +*****************************************************************/
12787 +static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, gfp_t mf)
12791 + status = usb_submit_urb (kaweth->irq_urb, mf);
12792 + if (unlikely(status == -ENOMEM)) {
12793 + kaweth->suspend_lowmem_ctrl = 1;
12794 + schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
12796 + kaweth->suspend_lowmem_ctrl = 0;
12800 + dev_err(&kaweth->intf->dev,
12801 + "can't resubmit intr, %s-%s, status %d\n",
12802 + kaweth->dev->bus->bus_name,
12803 + kaweth->dev->devpath, status);
12806 +static void int_callback(struct urb *u)
12808 + struct kaweth_device *kaweth = u->context;
12810 + int status = u->status;
12812 + switch (status) {
12813 + case 0: /* success */
12815 + case -ECONNRESET: /* unlink */
12819 + /* -EPIPE: should clear the halt */
12820 + default: /* error */
12824 + /* we check the link state to report changes */
12825 + if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) {
12827 + netif_carrier_on(kaweth->net);
12829 + netif_carrier_off(kaweth->net);
12831 + kaweth->linkstate = act_state;
12834 + kaweth_resubmit_int_urb(kaweth, GFP_ATOMIC);
12837 +static void kaweth_resubmit_tl(struct work_struct *work)
12839 + struct kaweth_device *kaweth =
12840 + container_of(work, struct kaweth_device, lowmem_work.work);
12842 + if (IS_BLOCKED(kaweth->status))
12845 + if (kaweth->suspend_lowmem_rx)
12846 + kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
12848 + if (kaweth->suspend_lowmem_ctrl)
12849 + kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
12853 +/****************************************************************
12854 + * kaweth_resubmit_rx_urb
12855 + ****************************************************************/
12856 +static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
12861 + usb_fill_bulk_urb(kaweth->rx_urb,
12863 + usb_rcvbulkpipe(kaweth->dev, 1),
12866 + kaweth_usb_receive,
12868 + kaweth->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
12869 + kaweth->rx_urb->transfer_dma = kaweth->rxbufferhandle;
12871 + if((result = usb_submit_urb(kaweth->rx_urb, mem_flags))) {
12872 + if (result == -ENOMEM) {
12873 + kaweth->suspend_lowmem_rx = 1;
12874 + schedule_delayed_work(&kaweth->lowmem_work, HZ/4);
12876 + dev_err(&kaweth->intf->dev, "resubmitting rx_urb %d failed\n",
12879 + kaweth->suspend_lowmem_rx = 0;
12885 +static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth);
12887 +/****************************************************************
12888 + * kaweth_usb_receive
12889 + ****************************************************************/
12890 +static void kaweth_usb_receive(struct urb *urb)
12892 + struct device *dev = &urb->dev->dev;
12893 + struct kaweth_device *kaweth = urb->context;
12894 + struct net_device *net = kaweth->net;
12895 + int status = urb->status;
12897 + int count = urb->actual_length;
12898 + int count2 = urb->transfer_buffer_length;
12900 + __u16 pkt_len = le16_to_cpup((__le16 *)kaweth->rx_buf);
12902 + struct sk_buff *skb;
12904 + if (unlikely(status == -EPIPE)) {
12905 + kaweth->stats.rx_errors++;
12907 + wake_up(&kaweth->term_wait);
12908 + dev_dbg(dev, "Status was -EPIPE.\n");
12911 + if (unlikely(status == -ECONNRESET || status == -ESHUTDOWN)) {
12912 + /* we are killed - set a flag and wake the disconnect handler */
12914 + wake_up(&kaweth->term_wait);
12915 + dev_dbg(dev, "Status was -ECONNRESET or -ESHUTDOWN.\n");
12918 + if (unlikely(status == -EPROTO || status == -ETIME ||
12919 + status == -EILSEQ)) {
12920 + kaweth->stats.rx_errors++;
12921 + dev_dbg(dev, "Status was -EPROTO, -ETIME, or -EILSEQ.\n");
12924 + if (unlikely(status == -EOVERFLOW)) {
12925 + kaweth->stats.rx_errors++;
12926 + dev_dbg(dev, "Status was -EOVERFLOW.\n");
12928 + spin_lock(&kaweth->device_lock);
12929 + if (IS_BLOCKED(kaweth->status)) {
12930 + spin_unlock(&kaweth->device_lock);
12933 + spin_unlock(&kaweth->device_lock);
12935 + if(status && status != -EREMOTEIO && count != 1) {
12936 + dev_err(&kaweth->intf->dev,
12937 + "%s RX status: %d count: %d packet_len: %d\n",
12938 + net->name, status, count, (int)pkt_len);
12939 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12943 + if(kaweth->net && (count > 2)) {
12944 + if(pkt_len > (count - 2)) {
12945 + dev_err(&kaweth->intf->dev,
12946 + "Packet length too long for USB frame (pkt_len: %x, count: %x)\n",
12948 + dev_err(&kaweth->intf->dev, "Packet len & 2047: %x\n",
12950 + dev_err(&kaweth->intf->dev, "Count 2: %x\n", count2);
12951 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12955 + if(!(skb = dev_alloc_skb(pkt_len+2))) {
12956 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12960 + skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
12962 + skb_copy_to_linear_data(skb, kaweth->rx_buf + 2, pkt_len);
12964 + skb_put(skb, pkt_len);
12966 + skb->protocol = eth_type_trans(skb, net);
12970 + kaweth->stats.rx_packets++;
12971 + kaweth->stats.rx_bytes += pkt_len;
12974 + kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
12977 +/****************************************************************
12979 + ****************************************************************/
12980 +static int kaweth_open(struct net_device *net)
12982 + struct kaweth_device *kaweth = netdev_priv(net);
12985 + netdev_dbg(kaweth->net, "Opening network device.\n");
12987 + res = usb_autopm_get_interface(kaweth->intf);
12989 + dev_err(&kaweth->intf->dev, "Interface cannot be resumed.\n");
12992 + res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
12996 + usb_fill_int_urb(
12999 + usb_rcvintpipe(kaweth->dev, 3),
13000 + kaweth->intbuffer,
13004 + 250); /* overriding the descriptor */
13005 + kaweth->irq_urb->transfer_dma = kaweth->intbufferhandle;
13006 + kaweth->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
13008 + res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
13010 + usb_kill_urb(kaweth->rx_urb);
13013 + kaweth->opened = 1;
13015 + netif_start_queue(net);
13017 + kaweth_async_set_rx_mode(kaweth);
13021 + usb_autopm_put_interface(kaweth->intf);
13025 +/****************************************************************
13026 + * kaweth_kill_urbs
13027 + ****************************************************************/
13028 +static void kaweth_kill_urbs(struct kaweth_device *kaweth)
13030 + usb_kill_urb(kaweth->irq_urb);
13031 + usb_kill_urb(kaweth->rx_urb);
13032 + usb_kill_urb(kaweth->tx_urb);
13034 + cancel_delayed_work_sync(&kaweth->lowmem_work);
13036 + /* a scheduled work may have resubmitted,
13037 + we hit them again */
13038 + usb_kill_urb(kaweth->irq_urb);
13039 + usb_kill_urb(kaweth->rx_urb);
13042 +/****************************************************************
13044 + ****************************************************************/
13045 +static int kaweth_close(struct net_device *net)
13047 + struct kaweth_device *kaweth = netdev_priv(net);
13049 + netif_stop_queue(net);
13050 + kaweth->opened = 0;
13052 + kaweth->status |= KAWETH_STATUS_CLOSING;
13054 + kaweth_kill_urbs(kaweth);
13056 + kaweth->status &= ~KAWETH_STATUS_CLOSING;
13058 + usb_autopm_put_interface(kaweth->intf);
13063 +static u32 kaweth_get_link(struct net_device *dev)
13065 + struct kaweth_device *kaweth = netdev_priv(dev);
13067 + return kaweth->linkstate;
13070 +static const struct ethtool_ops ops = {
13071 + .get_link = kaweth_get_link
13074 +/****************************************************************
13075 + * kaweth_usb_transmit_complete
13076 + ****************************************************************/
13077 +static void kaweth_usb_transmit_complete(struct urb *urb)
13079 + struct kaweth_device *kaweth = urb->context;
13080 + struct sk_buff *skb = kaweth->tx_skb;
13081 + int status = urb->status;
13083 + if (unlikely(status != 0))
13084 + if (status != -ENOENT)
13085 + dev_dbg(&urb->dev->dev, "%s: TX status %d.\n",
13086 + kaweth->net->name, status);
13088 + netif_wake_queue(kaweth->net);
13089 + dev_kfree_skb_irq(skb);
13092 +/****************************************************************
13093 + * kaweth_start_xmit
13094 + ****************************************************************/
13095 +static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
13096 + struct net_device *net)
13098 + struct kaweth_device *kaweth = netdev_priv(net);
13099 + __le16 *private_header;
13103 + spin_lock_irq(&kaweth->device_lock);
13105 + kaweth_async_set_rx_mode(kaweth);
13106 + netif_stop_queue(net);
13107 + if (IS_BLOCKED(kaweth->status)) {
13111 + /* We now decide whether we can put our special header into the sk_buff */
13112 + if (skb_cloned(skb) || skb_headroom(skb) < 2) {
13113 + /* no such luck - we make our own */
13114 + struct sk_buff *copied_skb;
13115 + copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC);
13116 + dev_kfree_skb_irq(skb);
13117 + skb = copied_skb;
13118 + if (!copied_skb) {
13119 + kaweth->stats.tx_errors++;
13120 + netif_start_queue(net);
13121 + spin_unlock_irq(&kaweth->device_lock);
13122 + return NETDEV_TX_OK;
13126 + private_header = (__le16 *)__skb_push(skb, 2);
13127 + *private_header = cpu_to_le16(skb->len-2);
13128 + kaweth->tx_skb = skb;
13130 + usb_fill_bulk_urb(kaweth->tx_urb,
13132 + usb_sndbulkpipe(kaweth->dev, 2),
13135 + kaweth_usb_transmit_complete,
13139 + if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC)))
13141 + dev_warn(&net->dev, "kaweth failed tx_urb %d\n", res);
13143 + kaweth->stats.tx_errors++;
13145 + netif_start_queue(net);
13146 + dev_kfree_skb_irq(skb);
13150 + kaweth->stats.tx_packets++;
13151 + kaweth->stats.tx_bytes += skb->len;
13154 + spin_unlock_irq(&kaweth->device_lock);
13156 + return NETDEV_TX_OK;
13159 +/****************************************************************
13160 + * kaweth_set_rx_mode
13161 + ****************************************************************/
13162 +static void kaweth_set_rx_mode(struct net_device *net)
13164 + struct kaweth_device *kaweth = netdev_priv(net);
13166 + __u16 packet_filter_bitmap = KAWETH_PACKET_FILTER_DIRECTED |
13167 + KAWETH_PACKET_FILTER_BROADCAST |
13168 + KAWETH_PACKET_FILTER_MULTICAST;
13170 + netdev_dbg(net, "Setting Rx mode to %d\n", packet_filter_bitmap);
13172 + netif_stop_queue(net);
13174 + if (net->flags & IFF_PROMISC) {
13175 + packet_filter_bitmap |= KAWETH_PACKET_FILTER_PROMISCUOUS;
13177 + else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
13178 + packet_filter_bitmap |= KAWETH_PACKET_FILTER_ALL_MULTICAST;
13181 + kaweth->packet_filter_bitmap = packet_filter_bitmap;
13182 + netif_wake_queue(net);
13185 +/****************************************************************
13186 + * kaweth_async_set_rx_mode
13187 + ****************************************************************/
13188 +static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth)
13191 + __u16 packet_filter_bitmap = kaweth->packet_filter_bitmap;
13193 + kaweth->packet_filter_bitmap = 0;
13194 + if (packet_filter_bitmap == 0)
13197 + if (in_interrupt())
13200 + result = kaweth_control(kaweth,
13201 + usb_sndctrlpipe(kaweth->dev, 0),
13202 + KAWETH_COMMAND_SET_PACKET_FILTER,
13203 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
13204 + packet_filter_bitmap,
13206 + (void *)&kaweth->scratch,
13208 + KAWETH_CONTROL_TIMEOUT);
13211 + dev_err(&kaweth->intf->dev, "Failed to set Rx mode: %d\n",
13215 + netdev_dbg(kaweth->net, "Set Rx mode to %d\n",
13216 + packet_filter_bitmap);
13220 +/****************************************************************
13221 + * kaweth_netdev_stats
13222 + ****************************************************************/
13223 +static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
13225 + struct kaweth_device *kaweth = netdev_priv(dev);
13226 + return &kaweth->stats;
13229 +/****************************************************************
13230 + * kaweth_tx_timeout
13231 + ****************************************************************/
13232 +static void kaweth_tx_timeout(struct net_device *net)
13234 + struct kaweth_device *kaweth = netdev_priv(net);
13236 + dev_warn(&net->dev, "%s: Tx timed out. Resetting.\n", net->name);
13237 + kaweth->stats.tx_errors++;
13238 + net->trans_start = jiffies;
13240 + usb_unlink_urb(kaweth->tx_urb);
13243 +/****************************************************************
13245 + ****************************************************************/
13246 +static int kaweth_suspend(struct usb_interface *intf, pm_message_t message)
13248 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13249 + unsigned long flags;
13251 + dev_dbg(&intf->dev, "Suspending device\n");
13252 + spin_lock_irqsave(&kaweth->device_lock, flags);
13253 + kaweth->status |= KAWETH_STATUS_SUSPENDING;
13254 + spin_unlock_irqrestore(&kaweth->device_lock, flags);
13256 + kaweth_kill_urbs(kaweth);
13260 +/****************************************************************
13262 + ****************************************************************/
13263 +static int kaweth_resume(struct usb_interface *intf)
13265 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13266 + unsigned long flags;
13268 + dev_dbg(&intf->dev, "Resuming device\n");
13269 + spin_lock_irqsave(&kaweth->device_lock, flags);
13270 + kaweth->status &= ~KAWETH_STATUS_SUSPENDING;
13271 + spin_unlock_irqrestore(&kaweth->device_lock, flags);
13273 + if (!kaweth->opened)
13275 + kaweth_resubmit_rx_urb(kaweth, GFP_NOIO);
13276 + kaweth_resubmit_int_urb(kaweth, GFP_NOIO);
13281 +/****************************************************************
13283 + ****************************************************************/
13286 +static const struct net_device_ops kaweth_netdev_ops = {
13287 + .ndo_open = kaweth_open,
13288 + .ndo_stop = kaweth_close,
13289 + .ndo_start_xmit = kaweth_start_xmit,
13290 + .ndo_tx_timeout = kaweth_tx_timeout,
13291 + .ndo_set_rx_mode = kaweth_set_rx_mode,
13292 + .ndo_get_stats = kaweth_netdev_stats,
13293 + .ndo_change_mtu = eth_change_mtu,
13294 + .ndo_set_mac_address = eth_mac_addr,
13295 + .ndo_validate_addr = eth_validate_addr,
13298 +static int kaweth_probe(
13299 + struct usb_interface *intf,
13300 + const struct usb_device_id *id /* from id_table */
13303 + struct device *dev = &intf->dev;
13304 + struct usb_device *udev = interface_to_usbdev(intf);
13305 + struct kaweth_device *kaweth;
13306 + struct net_device *netdev;
13307 + const eth_addr_t bcast_addr = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13311 + "Kawasaki Device Probe (Device number:%d): 0x%4.4x:0x%4.4x:0x%4.4x\n",
13312 + udev->devnum, le16_to_cpu(udev->descriptor.idVendor),
13313 + le16_to_cpu(udev->descriptor.idProduct),
13314 + le16_to_cpu(udev->descriptor.bcdDevice));
13316 + dev_dbg(dev, "Device at %p\n", udev);
13318 + dev_dbg(dev, "Descriptor length: %x type: %x\n",
13319 + (int)udev->descriptor.bLength,
13320 + (int)udev->descriptor.bDescriptorType);
13322 + netdev = alloc_etherdev(sizeof(*kaweth));
13326 + kaweth = netdev_priv(netdev);
13327 + kaweth->dev = udev;
13328 + kaweth->net = netdev;
13330 + spin_lock_init(&kaweth->device_lock);
13331 + init_waitqueue_head(&kaweth->term_wait);
13333 + dev_dbg(dev, "Resetting.\n");
13335 + kaweth_reset(kaweth);
13338 + * If high byte of bcdDevice is nonzero, firmware is already
13339 + * downloaded. Don't try to do it again, or we'll hang the device.
13342 + if (le16_to_cpu(udev->descriptor.bcdDevice) >> 8) {
13343 + dev_info(dev, "Firmware present in device.\n");
13345 + /* Download the firmware */
13346 + dev_info(dev, "Downloading firmware...\n");
13347 + kaweth->firmware_buf = (__u8 *)__get_free_page(GFP_KERNEL);
13348 + if ((result = kaweth_download_firmware(kaweth,
13349 + "kaweth/new_code.bin",
13352 + dev_err(dev, "Error downloading firmware (%d)\n",
13357 + if ((result = kaweth_download_firmware(kaweth,
13358 + "kaweth/new_code_fix.bin",
13361 + dev_err(dev, "Error downloading firmware fix (%d)\n",
13366 + if ((result = kaweth_download_firmware(kaweth,
13367 + "kaweth/trigger_code.bin",
13370 + dev_err(dev, "Error downloading trigger code (%d)\n",
13376 + if ((result = kaweth_download_firmware(kaweth,
13377 + "kaweth/trigger_code_fix.bin",
13380 + dev_err(dev, "Error downloading trigger code fix (%d)\n", result);
13385 + if ((result = kaweth_trigger_firmware(kaweth, 126)) < 0) {
13386 + dev_err(dev, "Error triggering firmware (%d)\n", result);
13390 + /* Device will now disappear for a moment... */
13391 + dev_info(dev, "Firmware loaded. I'll be back...\n");
13393 + free_page((unsigned long)kaweth->firmware_buf);
13394 + free_netdev(netdev);
13398 + result = kaweth_read_configuration(kaweth);
13401 + dev_err(dev, "Error reading configuration (%d), no net device created\n", result);
13402 + goto err_free_netdev;
13405 + dev_info(dev, "Statistics collection: %x\n", kaweth->configuration.statistics_mask);
13406 + dev_info(dev, "Multicast filter limit: %x\n", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1));
13407 + dev_info(dev, "MTU: %d\n", le16_to_cpu(kaweth->configuration.segment_size));
13408 + dev_info(dev, "Read MAC address %pM\n", kaweth->configuration.hw_addr);
13410 + if(!memcmp(&kaweth->configuration.hw_addr,
13412 + sizeof(bcast_addr))) {
13413 + dev_err(dev, "Firmware not functioning properly, no net device created\n");
13414 + goto err_free_netdev;
13417 + if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
13418 + dev_dbg(dev, "Error setting URB size\n");
13419 + goto err_free_netdev;
13422 + if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
13423 + dev_err(dev, "Error setting SOFS wait\n");
13424 + goto err_free_netdev;
13427 + result = kaweth_set_receive_filter(kaweth,
13428 + KAWETH_PACKET_FILTER_DIRECTED |
13429 + KAWETH_PACKET_FILTER_BROADCAST |
13430 + KAWETH_PACKET_FILTER_MULTICAST);
13433 + dev_err(dev, "Error setting receive filter\n");
13434 + goto err_free_netdev;
13437 + dev_dbg(dev, "Initializing net device.\n");
13439 + kaweth->intf = intf;
13441 + kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
13442 + if (!kaweth->tx_urb)
13443 + goto err_free_netdev;
13444 + kaweth->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
13445 + if (!kaweth->rx_urb)
13446 + goto err_only_tx;
13447 + kaweth->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
13448 + if (!kaweth->irq_urb)
13449 + goto err_tx_and_rx;
13451 + kaweth->intbuffer = usb_alloc_coherent( kaweth->dev,
13454 + &kaweth->intbufferhandle);
13455 + if (!kaweth->intbuffer)
13456 + goto err_tx_and_rx_and_irq;
13457 + kaweth->rx_buf = usb_alloc_coherent( kaweth->dev,
13460 + &kaweth->rxbufferhandle);
13461 + if (!kaweth->rx_buf)
13462 + goto err_all_but_rxbuf;
13464 + memcpy(netdev->broadcast, &bcast_addr, sizeof(bcast_addr));
13465 + memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
13466 + sizeof(kaweth->configuration.hw_addr));
13468 + netdev->netdev_ops = &kaweth_netdev_ops;
13469 + netdev->watchdog_timeo = KAWETH_TX_TIMEOUT;
13470 + netdev->mtu = le16_to_cpu(kaweth->configuration.segment_size);
13471 + netdev->ethtool_ops = &ops;
13473 + /* kaweth is zeroed as part of alloc_netdev */
13474 + INIT_DELAYED_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl);
13475 + usb_set_intfdata(intf, kaweth);
13478 +// dma_supported() is deeply broken on almost all architectures
13479 + if (dma_supported (dev, 0xffffffffffffffffULL))
13480 + kaweth->net->features |= NETIF_F_HIGHDMA;
13483 + SET_NETDEV_DEV(netdev, dev);
13484 + if (register_netdev(netdev) != 0) {
13485 + dev_err(dev, "Error registering netdev.\n");
13486 + goto err_intfdata;
13489 + dev_info(dev, "kaweth interface created at %s\n",
13490 + kaweth->net->name);
13492 + dev_dbg(dev, "Kaweth probe returning.\n");
13497 + usb_set_intfdata(intf, NULL);
13498 + usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
13499 +err_all_but_rxbuf:
13500 + usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
13501 +err_tx_and_rx_and_irq:
13502 + usb_free_urb(kaweth->irq_urb);
13504 + usb_free_urb(kaweth->rx_urb);
13506 + usb_free_urb(kaweth->tx_urb);
13508 + free_netdev(netdev);
13513 +/****************************************************************
13514 + * kaweth_disconnect
13515 + ****************************************************************/
13516 +static void kaweth_disconnect(struct usb_interface *intf)
13518 + struct kaweth_device *kaweth = usb_get_intfdata(intf);
13519 + struct net_device *netdev;
13521 + dev_info(&intf->dev, "Unregistering\n");
13523 + usb_set_intfdata(intf, NULL);
13525 + dev_warn(&intf->dev, "unregistering non-existent device\n");
13528 + netdev = kaweth->net;
13530 + netdev_dbg(kaweth->net, "Unregistering net device\n");
13531 + unregister_netdev(netdev);
13533 + usb_free_urb(kaweth->rx_urb);
13534 + usb_free_urb(kaweth->tx_urb);
13535 + usb_free_urb(kaweth->irq_urb);
13537 + usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
13538 + usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
13540 + free_netdev(netdev);
13544 +// FIXME this completion stuff is a modified clone of
13545 +// an OLD version of some stuff in usb.c ...
13546 +struct usb_api_data {
13547 + wait_queue_head_t wqh;
13551 +/*-------------------------------------------------------------------*
13552 + * completion handler for compatibility wrappers (sync control/bulk) *
13553 + *-------------------------------------------------------------------*/
13554 +static void usb_api_blocking_completion(struct urb *urb)
13556 + struct usb_api_data *awd = (struct usb_api_data *)urb->context;
13559 + wake_up(&awd->wqh);
13562 +/*-------------------------------------------------------------------*
13563 + * COMPATIBILITY STUFF *
13564 + *-------------------------------------------------------------------*/
13566 +// Starts urb and waits for completion or timeout
13567 +static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
13569 + struct usb_api_data awd;
13572 + init_waitqueue_head(&awd.wqh);
13575 + urb->context = &awd;
13576 + status = usb_submit_urb(urb, GFP_ATOMIC);
13578 + // something went wrong
13579 + usb_free_urb(urb);
13583 + if (!wait_event_timeout(awd.wqh, awd.done, timeout)) {
13585 + dev_warn(&urb->dev->dev, "usb_control/bulk_msg: timeout\n");
13586 + usb_kill_urb(urb); // remove urb safely
13587 + status = -ETIMEDOUT;
13590 + status = urb->status;
13593 + if (actual_length) {
13594 + *actual_length = urb->actual_length;
13597 + usb_free_urb(urb);
13601 +/*-------------------------------------------------------------------*/
13602 +// returns status (negative) or length (positive)
13603 +static int kaweth_internal_control_msg(struct usb_device *usb_dev,
13604 + unsigned int pipe,
13605 + struct usb_ctrlrequest *cmd, void *data,
13606 + int len, int timeout)
13610 + int length = 0; /* shut up GCC */
13612 + urb = usb_alloc_urb(0, GFP_ATOMIC);
13616 + usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char*)cmd, data,
13617 + len, usb_api_blocking_completion, NULL);
13619 + retv = usb_start_wait_urb(urb, timeout, &length);
13628 +module_usb_driver(kaweth_driver);
13629 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Kconfig backports-4.2.6-1/drivers/net/usb/Kconfig
13630 --- backports-4.2.6-1.org/drivers/net/usb/Kconfig 2015-11-15 22:19:40.000000000 +0100
13631 +++ backports-4.2.6-1/drivers/net/usb/Kconfig 2016-06-28 14:35:17.991973886 +0200
13637 tristate "USB CATC NetMate-based Ethernet device support"
13641 module will be called catc.
13645 tristate "USB KLSI KL5USB101-based ethernet device support"
13649 module will be called kaweth.
13653 tristate "USB Pegasus/Pegasus-II based ethernet device support"
13657 module will be called pegasus.
13661 tristate "USB RTL8150 based ethernet device support"
13664 @@ -105,7 +101,6 @@
13665 module will be called rtl8150.
13669 tristate "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
13672 @@ -153,7 +148,6 @@
13673 module will be called usbnet.
13675 config USB_NET_AX8817X
13677 tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
13679 depends on USB_USBNET
13680 @@ -184,7 +178,6 @@
13681 what other networking devices you have in use.
13683 config USB_NET_AX88179_178A
13685 tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
13687 depends on USB_USBNET
13688 @@ -233,7 +226,6 @@
13689 name is used instead.
13691 config USB_NET_CDC_EEM
13693 tristate "CDC EEM support"
13695 depends on USB_USBNET
13696 @@ -269,7 +261,6 @@
13697 * Ericsson F5521gw Mobile Broadband Module
13699 config USB_NET_HUAWEI_CDC_NCM
13701 tristate "Huawei NCM embedded AT channel support"
13703 depends on USB_USBNET
13704 @@ -305,7 +296,6 @@
13705 module will be called cdc_mbim.
13707 config USB_NET_DM9601
13709 tristate "Davicom DM96xx based USB 10/100 ethernet devices"
13711 depends on USB_USBNET
13712 @@ -315,7 +305,6 @@
13713 based USB 10/100 Ethernet adapters.
13715 config USB_NET_SR9700
13717 tristate "CoreChip-sz SR9700 based USB 1.1 10/100 ethernet devices"
13719 depends on USB_USBNET
13720 @@ -325,7 +314,6 @@
13721 10/100 Ethernet adapters.
13723 config USB_NET_SR9800
13725 tristate "CoreChip-sz SR9800 based USB 2.0 10/100 ethernet devices"
13727 depends on USB_USBNET
13728 @@ -342,7 +330,6 @@
13729 module will be called sr9800.
13731 config USB_NET_SMSC75XX
13733 tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"
13735 depends on USB_USBNET
13736 @@ -354,7 +341,6 @@
13737 Gigabit Ethernet adapters.
13739 config USB_NET_SMSC95XX
13741 tristate "SMSC LAN95XX based USB 2.0 10/100 ethernet devices"
13743 depends on USB_USBNET
13744 @@ -366,7 +352,6 @@
13745 10/100 Ethernet adapters.
13747 config USB_NET_GL620A
13749 tristate "GeneSys GL620USB-A based cables"
13751 depends on USB_USBNET
13752 @@ -377,7 +362,6 @@
13753 Note that the half-duplex "GL620USB" is not supported.
13755 config USB_NET_NET1080
13757 tristate "NetChip 1080 based cables (Laplink, ...)"
13760 @@ -388,7 +372,6 @@
13761 optionally with LEDs that indicate traffic
13763 config USB_NET_PLUSB
13765 tristate "Prolific PL-2301/2302/25A1 based cables"
13767 # if the handshake/init/reset problems, from original 'plusb',
13768 @@ -399,7 +382,6 @@
13769 with one of these chips.
13771 config USB_NET_MCS7830
13773 tristate "MosChip MCS7830 based Ethernet adapters"
13775 depends on USB_USBNET
13776 @@ -425,7 +407,6 @@
13777 (and for) Microsoft; it isn't an "Open" ecosystem or market.
13779 config USB_NET_CDC_SUBSET
13781 tristate "Simple USB Network Links (CDC Ethernet subset)"
13783 depends on USB_USBNET
13784 @@ -497,7 +478,6 @@
13785 with one of these chips.
13787 config USB_NET_ZAURUS
13789 tristate "Sharp Zaurus (stock ROMs) and compatible"
13791 depends on USB_USBNET
13792 @@ -517,7 +497,6 @@
13793 some cases CDC MDLM) protocol, not "g_ether".
13795 config USB_NET_CX82310_ETH
13797 tristate "Conexant CX82310 USB ethernet port"
13799 depends on USB_USBNET
13800 @@ -527,7 +506,6 @@
13801 it will not work with ADSL modems (use cxacru driver instead).
13803 config USB_NET_KALMIA
13805 tristate "Samsung Kalmia based LTE USB modem"
13807 depends on USB_USBNET
13808 @@ -562,7 +540,6 @@
13809 module will be called qmi_wwan.
13813 tristate "Option USB High Speed Mobile Devices"
13815 depends on USB && RFKILL && TTY
13816 @@ -575,7 +552,6 @@
13817 module will be called hso.
13819 config USB_NET_INT51X1
13821 tristate "Intellon PLC based usb adapter"
13823 depends on USB_USBNET
13824 @@ -585,7 +561,6 @@
13825 INT51x1/INT5200 chip, like the "devolo dLan duo".
13827 config USB_CDC_PHONET
13829 tristate "CDC Phonet support"
13832 @@ -595,7 +570,6 @@
13833 "PC suite" USB profile.
13837 tristate "Apple iPhone USB Ethernet driver"
13840 @@ -619,11 +593,10 @@
13841 module will be called sierra_net.
13845 tristate "LG VL600 modem dongle"
13847 depends on USB_NET_CDCETHER && TTY
13849 +# depends on USB_ACM
13851 Select this if you want to use an LG Electronics 4G/LTE usb modem
13852 called VL600. This driver only handles the ethernet
13853 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Kconfig.orig backports-4.2.6-1/drivers/net/usb/Kconfig.orig
13854 --- backports-4.2.6-1.org/drivers/net/usb/Kconfig.orig 1970-01-01 01:00:00.000000000 +0100
13855 +++ backports-4.2.6-1/drivers/net/usb/Kconfig.orig 2016-06-28 14:35:17.991973886 +0200
13858 +# USB Network devices configuration
13860 +comment "Host-side USB support is needed for USB Network Adapter support"
13861 + depends on !USB && NET
13863 +menuconfig USB_NET_DRIVERS
13864 + tristate "USB Network Adapters"
13866 + default USB if USB
13867 + depends on USB && NET
13869 +if USB_NET_DRIVERS
13873 + tristate "USB CATC NetMate-based Ethernet device support"
13877 + Say Y if you want to use one of the following 10Mbps USB Ethernet
13878 + device based on the EL1210A chip. Supported devices are:
13883 + smartBridges smartNIC
13885 + This driver makes the adapter appear as a normal Ethernet interface,
13886 + typically on eth0, if it is the only ethernet device, or perhaps on
13887 + eth1, if you have a PCI or ISA ethernet card installed.
13889 + To compile this driver as a module, choose M here: the
13890 + module will be called catc.
13894 + tristate "USB KLSI KL5USB101-based ethernet device support"
13897 + Say Y here if you want to use one of the following 10Mbps only
13898 + USB Ethernet adapters based on the KLSI KL5KUSB101B chipset:
13901 + ATEN USB Ethernet
13902 + ASANTE USB To Ethernet Adapter
13903 + AOX Endpoints USB Ethernet
13905 + D-Link DSB-650C and DU-E10
13906 + Entrega / Portgear E45
13907 + I-O DATA USB-ET/T
13908 + Jaton USB Ethernet Device Adapter
13909 + Kingston Technology USB Ethernet Adapter
13911 + Mobility USB-Ethernet Adapter
13913 + Peracom Enet and Enet2
13914 + Portsmith Express Ethernet Adapter
13915 + Shark Pocket Adapter
13917 + Sony Vaio port extender
13919 + This driver is likely to work with most 10Mbps only USB Ethernet
13920 + adapters, including some "no brand" devices. It does NOT work on
13921 + SmartBridges smartNIC or on Belkin F5U111 devices - you should use
13922 + the CATC NetMate driver for those. If you are not sure which one
13923 + you need, select both, and the correct one should be selected for
13926 + This driver makes the adapter appear as a normal Ethernet interface,
13927 + typically on eth0, if it is the only ethernet device, or perhaps on
13928 + eth1, if you have a PCI or ISA ethernet card installed.
13930 + To compile this driver as a module, choose M here: the
13931 + module will be called kaweth.
13933 +config USB_PEGASUS
13935 + tristate "USB Pegasus/Pegasus-II based ethernet device support"
13937 + select BPAUTO_MII
13939 + Say Y here if you know you have Pegasus or Pegasus-II based adapter.
13940 + If in doubt then look at <file:drivers/net/usb/pegasus.h> for the
13941 + complete list of supported devices.
13943 + If your particular adapter is not in the list and you are _sure_ it
13944 + is Pegasus or Pegasus II based then send me
13945 + <petkan@users.sourceforge.net> vendor and device IDs.
13947 + To compile this driver as a module, choose M here: the
13948 + module will be called pegasus.
13950 +config USB_RTL8150
13952 + tristate "USB RTL8150 based ethernet device support"
13954 + select BPAUTO_MII
13956 + Say Y here if you have RTL8150 based usb-ethernet adapter.
13957 + Send me <petkan@users.sourceforge.net> any comments you may have.
13958 + You can also check for updates at <http://pegasus2.sourceforge.net/>.
13960 + To compile this driver as a module, choose M here: the
13961 + module will be called rtl8150.
13963 +config USB_RTL8152
13965 + tristate "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
13967 + select BPAUTO_MII
13969 + This option adds support for Realtek RTL8152 based USB 2.0
13970 + 10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
13971 + Ethernet adapters.
13973 + To compile this driver as a module, choose M here: the
13974 + module will be called r8152.
13977 + tristate "Multi-purpose USB Networking Framework"
13979 + select BPAUTO_MII
13981 + This driver supports several kinds of network links over USB,
13982 + with "minidrivers" built around a common network driver core
13983 + that supports deep queues for efficient transfers. (This gives
13984 + better performance with small packets and at high speeds).
13986 + The USB host runs "usbnet", and the other end of the link might be:
13988 + - Another USB host, when using USB "network" or "data transfer"
13989 + cables. These are often used to network laptops to PCs, like
13990 + "Laplink" parallel cables or some motherboards. These rely
13991 + on specialized chips from many suppliers.
13993 + - An intelligent USB gadget, perhaps embedding a Linux system.
13994 + These include PDAs running Linux (iPaq, Yopy, Zaurus, and
13995 + others), and devices that interoperate using the standard
13996 + CDC-Ethernet specification (including many cable modems).
13998 + - Network adapter hardware (like those for 10/100 Ethernet) which
13999 + uses this driver framework.
14001 + The link will appear with a name like "usb0", when the link is
14002 + a two-node link, or "eth0" for most CDC-Ethernet devices. Those
14003 + two-node links are most easily managed with Ethernet Bridging
14004 + (CONFIG_BRIDGE) instead of routing.
14006 + For more information see <http://www.linux-usb.org/usbnet/>.
14008 + To compile this driver as a module, choose M here: the
14009 + module will be called usbnet.
14011 +config USB_NET_AX8817X
14013 + tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
14015 + depends on USB_USBNET
14017 + depends on PHYLIB
14020 + This option adds support for ASIX AX88xxx based USB 2.0
14021 + 10/100 Ethernet adapters.
14023 + This driver should work with at least the following devices:
14026 + * Billionton Systems, USB2AR
14027 + * Buffalo LUA-U2-KTX
14028 + * Corega FEther USB2-TX
14029 + * D-Link DUB-E100
14031 + * Linksys USB200M
14035 + * Intellinet USB 2.0 Ethernet
14036 + * ST Lab USB 2.0 Ethernet
14037 + * TrendNet TU2-ET100
14039 + This driver creates an interface named "ethX", where X depends on
14040 + what other networking devices you have in use.
14042 +config USB_NET_AX88179_178A
14044 + tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
14046 + depends on USB_USBNET
14048 + depends on PHYLIB
14051 + This option adds support for ASIX AX88179 based USB 3.0/2.0
14052 + to Gigabit Ethernet adapters.
14054 + This driver should work with at least the following devices:
14059 + This driver creates an interface named "ethX", where X depends on
14060 + what other networking devices you have in use.
14062 +config USB_NET_CDCETHER
14063 + tristate "CDC Ethernet support (smart devices such as cable modems)"
14065 + depends on USB_USBNET
14068 + This option supports devices conforming to the Communication Device
14069 + Class (CDC) Ethernet Control Model, a specification that's easy to
14070 + implement in device firmware. The CDC specifications are available
14071 + from <http://www.usb.org/>.
14073 + CDC Ethernet is an implementation option for DOCSIS cable modems
14074 + that support USB connectivity, used for non-Microsoft USB hosts.
14075 + The Linux-USB CDC Ethernet Gadget driver is an open implementation.
14076 + This driver should work with at least the following devices:
14078 + * Dell Wireless 5530 HSPA
14079 + * Ericsson PipeRider (all variants)
14080 + * Ericsson Mobile Broadband Module (all variants)
14081 + * Motorola (DM100 and SB4100)
14082 + * Broadcom Cable Modem (reference design)
14083 + * Toshiba (PCX1100U and F3507g/F3607gw)
14086 + This driver creates an interface named "ethX", where X depends on
14087 + what other networking devices you have in use. However, if the
14088 + IEEE 802 "local assignment" bit is set in the address, a "usbX"
14089 + name is used instead.
14091 +config USB_NET_CDC_EEM
14093 + tristate "CDC EEM support"
14095 + depends on USB_USBNET
14097 + This option supports devices conforming to the Communication Device
14098 + Class (CDC) Ethernet Emulation Model, a specification that's easy to
14099 + implement in device firmware. The CDC EEM specifications are available
14100 + from <http://www.usb.org/>.
14102 + This driver creates an interface named "ethX", where X depends on
14103 + what other networking devices you have in use. However, if the
14104 + IEEE 802 "local assignment" bit is set in the address, a "usbX"
14105 + name is used instead.
14107 +config USB_NET_CDC_NCM
14108 + tristate "CDC NCM support"
14110 + depends on USB_USBNET
14113 + This driver provides support for CDC NCM (Network Control Model
14114 + Device USB Class Specification). The CDC NCM specification is
14115 + available from <http://www.usb.org/>.
14117 + Say "y" to link the driver statically, or "m" to build a
14118 + dynamically linked module.
14120 + This driver should work with at least the following devices:
14121 + * ST-Ericsson M700 LTE FDD/TDD Mobile Broadband Modem (ref. design)
14122 + * ST-Ericsson M5730 HSPA+ Mobile Broadband Modem (reference design)
14123 + * ST-Ericsson M570 HSPA+ Mobile Broadband Modem (reference design)
14124 + * ST-Ericsson M343 HSPA Mobile Broadband Modem (reference design)
14125 + * Ericsson F5521gw Mobile Broadband Module
14127 +config USB_NET_HUAWEI_CDC_NCM
14129 + tristate "Huawei NCM embedded AT channel support"
14131 + depends on USB_USBNET
14133 + select USB_NET_CDC_NCM
14135 + This driver supports huawei-style NCM devices, that use NCM as a
14136 + transport for other protocols, usually an embedded AT channel.
14137 + Good examples are:
14141 + To compile this driver as a module, choose M here: the module will be
14142 + called huawei_cdc_ncm.ko.
14144 +config USB_NET_CDC_MBIM
14145 + tristate "CDC MBIM support"
14147 + depends on USB_USBNET
14149 + select USB_NET_CDC_NCM
14151 + This driver provides support for CDC MBIM (Mobile Broadband
14152 + Interface Model) devices. The CDC MBIM specification is
14153 + available from <http://www.usb.org/>.
14155 + MBIM devices require configuration using the management
14156 + protocol defined by the MBIM specification. This driver
14157 + provides unfiltered access to the MBIM control channel
14158 + through the associated /dev/cdc-wdmx character device.
14160 + To compile this driver as a module, choose M here: the
14161 + module will be called cdc_mbim.
14163 +config USB_NET_DM9601
14165 + tristate "Davicom DM96xx based USB 10/100 ethernet devices"
14167 + depends on USB_USBNET
14170 + This option adds support for Davicom DM9601/DM9620/DM9621A
14171 + based USB 10/100 Ethernet adapters.
14173 +config USB_NET_SR9700
14175 + tristate "CoreChip-sz SR9700 based USB 1.1 10/100 ethernet devices"
14177 + depends on USB_USBNET
14180 + This option adds support for CoreChip-sz SR9700 based USB 1.1
14181 + 10/100 Ethernet adapters.
14183 +config USB_NET_SR9800
14185 + tristate "CoreChip-sz SR9800 based USB 2.0 10/100 ethernet devices"
14187 + depends on USB_USBNET
14190 + Say Y if you want to use one of the following 100Mbps USB Ethernet
14191 + device based on the CoreChip-sz SR9800 chip.
14193 + This driver makes the adapter appear as a normal Ethernet interface,
14194 + typically on eth0, if it is the only ethernet device, or perhaps on
14195 + eth1, if you have a PCI or ISA ethernet card installed.
14197 + To compile this driver as a module, choose M here: the
14198 + module will be called sr9800.
14200 +config USB_NET_SMSC75XX
14202 + tristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"
14204 + depends on USB_USBNET
14205 + depends on BITREVERSE
14209 + This option adds support for SMSC LAN75XX based USB 2.0
14210 + Gigabit Ethernet adapters.
14212 +config USB_NET_SMSC95XX
14214 + tristate "SMSC LAN95XX based USB 2.0 10/100 ethernet devices"
14216 + depends on USB_USBNET
14217 + depends on BITREVERSE
14221 + This option adds support for SMSC LAN95XX based USB 2.0
14222 + 10/100 Ethernet adapters.
14224 +config USB_NET_GL620A
14226 + tristate "GeneSys GL620USB-A based cables"
14228 + depends on USB_USBNET
14230 + Choose this option if you're using a host-to-host cable,
14231 + or PC2PC motherboard, with this chip.
14233 + Note that the half-duplex "GL620USB" is not supported.
14235 +config USB_NET_NET1080
14237 + tristate "NetChip 1080 based cables (Laplink, ...)"
14240 + depends on USB_USBNET
14242 + Choose this option if you're using a host-to-host cable based
14243 + on this design: one NetChip 1080 chip and supporting logic,
14244 + optionally with LEDs that indicate traffic
14246 +config USB_NET_PLUSB
14248 + tristate "Prolific PL-2301/2302/25A1 based cables"
14250 + # if the handshake/init/reset problems, from original 'plusb',
14251 + # are ever resolved ... then remove "experimental"
14252 + depends on USB_USBNET
14254 + Choose this option if you're using a host-to-host cable
14255 + with one of these chips.
14257 +config USB_NET_MCS7830
14259 + tristate "MosChip MCS7830 based Ethernet adapters"
14261 + depends on USB_USBNET
14263 + Choose this option if you're using a 10/100 Ethernet USB2
14264 + adapter based on the MosChip 7830 controller. This includes
14265 + adapters marketed under the DeLOCK brand.
14267 +config USB_NET_RNDIS_HOST
14268 + tristate "Host for RNDIS and ActiveSync devices"
14270 + depends on USB_USBNET
14271 + select USB_NET_CDCETHER
14273 + This option enables hosting "Remote NDIS" USB networking links,
14274 + as encouraged by Microsoft (instead of CDC Ethernet!) for use in
14275 + various devices that may only support this protocol. A variant
14276 + of this protocol (with even less public documentation) seems to
14277 + be at the root of Microsoft's "ActiveSync" too.
14279 + Avoid using this protocol unless you have no better options.
14280 + The protocol specification is incomplete, and is controlled by
14281 + (and for) Microsoft; it isn't an "Open" ecosystem or market.
14283 +config USB_NET_CDC_SUBSET
14285 + tristate "Simple USB Network Links (CDC Ethernet subset)"
14287 + depends on USB_USBNET
14290 + This driver module supports USB network devices that can work
14291 + without any device-specific information. Select it if you have
14292 + one of these drivers.
14294 + Note that while many USB host-to-host cables can work in this mode,
14295 + that may mean not being able to talk to Win32 systems or more
14296 + commonly not being able to handle certain events (like replugging
14297 + the host on the other end) very well. Also, these devices will
14298 + not generally have permanently assigned Ethernet addresses.
14300 +config USB_ALI_M5632
14301 + bool "ALi M5632 based 'USB 2.0 Data Link' cables"
14302 + depends on USB_NET_CDC_SUBSET
14304 + Choose this option if you're using a host-to-host cable
14305 + based on this design, which supports USB 2.0 high speed.
14308 + bool "AnchorChips 2720 based cables (Xircom PGUNET, ...)"
14309 + depends on USB_NET_CDC_SUBSET
14311 + Choose this option if you're using a host-to-host cable
14312 + based on this design. Note that AnchorChips is now a
14316 + bool "eTEK based host-to-host cables (Advance, Belkin, ...)"
14317 + depends on USB_NET_CDC_SUBSET
14320 + Choose this option if you're using a host-to-host cable
14321 + based on this design: two NetChip 2890 chips and an Atmel
14322 + microcontroller, with LEDs that indicate traffic.
14324 +config USB_ARMLINUX
14325 + bool "Embedded ARM Linux links (iPaq, ...)"
14326 + depends on USB_NET_CDC_SUBSET
14329 + Choose this option to support the "usb-eth" networking driver
14330 + used by most of the ARM Linux community with device controllers
14331 + such as the SA-11x0 and PXA-25x UDCs, or the tftp capabilities
14332 + in some PXA versions of the "blob" boot loader.
14334 + Linux-based "Gumstix" PXA-25x based systems use this protocol
14335 + to talk with other Linux systems.
14337 + Although the ROMs shipped with Sharp Zaurus products use a
14338 + different link level framing protocol, you can have them use
14339 + this simpler protocol by installing a different kernel.
14341 +config USB_EPSON2888
14342 + bool "Epson 2888 based firmware (DEVELOPMENT)"
14343 + depends on USB_NET_CDC_SUBSET
14345 + Choose this option to support the usb networking links used
14346 + by some sample firmware from Epson.
14349 + bool "KT Technology KC2190 based cables (InstaNet)"
14350 + depends on USB_NET_CDC_SUBSET
14352 + Choose this option if you're using a host-to-host cable
14353 + with one of these chips.
14355 +config USB_NET_ZAURUS
14357 + tristate "Sharp Zaurus (stock ROMs) and compatible"
14359 + depends on USB_USBNET
14360 + select USB_NET_CDCETHER
14364 + Choose this option to support the usb networking links used by
14365 + Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
14366 + This also supports some related device firmware, as used in some
14367 + PDAs from Olympus and some cell phones from Motorola.
14369 + If you install an alternate image, such as the Linux 2.6 based
14370 + versions of OpenZaurus, you should no longer need to support this
14371 + protocol. Only the "eth-fd" or "net_fd" drivers in these devices
14372 + really need this non-conformant variant of CDC Ethernet (or in
14373 + some cases CDC MDLM) protocol, not "g_ether".
14375 +config USB_NET_CX82310_ETH
14377 + tristate "Conexant CX82310 USB ethernet port"
14379 + depends on USB_USBNET
14381 + Choose this option if you're using a Conexant CX82310-based ADSL
14382 + router with USB ethernet port. This driver is for routers only,
14383 + it will not work with ADSL modems (use cxacru driver instead).
14385 +config USB_NET_KALMIA
14387 + tristate "Samsung Kalmia based LTE USB modem"
14389 + depends on USB_USBNET
14391 + Choose this option if you have a Samsung Kalmia based USB modem
14392 + as Samsung GT-B3730.
14394 + To compile this driver as a module, choose M here: the
14395 + module will be called kalmia.
14397 +config USB_NET_QMI_WWAN
14398 + tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"
14400 + depends on USB_USBNET
14403 + Support WWAN LTE/3G devices based on Qualcomm Mobile Data Modem
14404 + (MDM) chipsets. Examples of such devices are
14405 + * Huawei E392/E398
14407 + This driver will only drive the ethernet part of the chips.
14408 + The devices require additional configuration to be usable.
14409 + Multiple management interfaces with linux drivers are
14412 + * option: AT commands on /dev/ttyUSBx
14413 + * cdc-wdm: Qualcomm MSM Interface (QMI) protocol on /dev/cdc-wdmx
14415 + A modem manager with support for QMI is recommended.
14417 + To compile this driver as a module, choose M here: the
14418 + module will be called qmi_wwan.
14422 + tristate "Option USB High Speed Mobile Devices"
14424 + depends on USB && RFKILL && TTY
14427 + Choose this option if you have an Option HSDPA/HSUPA card.
14428 + These cards support downlink speeds of 7.2Mbps or greater.
14430 + To compile this driver as a module, choose M here: the
14431 + module will be called hso.
14433 +config USB_NET_INT51X1
14435 + tristate "Intellon PLC based usb adapter"
14437 + depends on USB_USBNET
14439 + Choose this option if you're using a 14Mb USB-based PLC
14440 + (Powerline Communications) solution with an Intellon
14441 + INT51x1/INT5200 chip, like the "devolo dLan duo".
14443 +config USB_CDC_PHONET
14445 + tristate "CDC Phonet support"
14447 + depends on PHONET
14449 + Choose this option to support the Phonet interface to a Nokia
14450 + cellular modem, as found on most Nokia handsets with the
14451 + "PC suite" USB profile.
14455 + tristate "Apple iPhone USB Ethernet driver"
14459 + Module used to share Internet connection (tethering) from your
14460 + iPhone (Original, 3G and 3GS) to your system.
14461 + Note that you need userspace libraries and programs that are needed
14462 + to pair your device with your system and that understand the iPhone
14465 + For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
14467 +config USB_SIERRA_NET
14468 + tristate "USB-to-WWAN Driver for Sierra Wireless modems"
14470 + depends on USB_USBNET
14472 + Choose this option if you have a Sierra Wireless USB-to-WWAN device.
14474 + To compile this driver as a module, choose M here: the
14475 + module will be called sierra_net.
14479 + tristate "LG VL600 modem dongle"
14481 + depends on USB_NET_CDCETHER && TTY
14484 + Select this if you want to use an LG Electronics 4G/LTE usb modem
14485 + called VL600. This driver only handles the ethernet
14486 + interface exposed by the modem firmware. To establish a connection
14487 + you will first need a userspace program that sends the right
14488 + command to the modem through its CDC ACM port, and most
14489 + likely also a DHCP client. See this thread about using the
14490 + 4G modem from Verizon:
14492 + http://ubuntuforums.org/showpost.php?p=10589647&postcount=17
14494 +endif # USB_NET_DRIVERS
14495 diff -Naur backports-4.2.6-1.org/drivers/net/usb/lg-vl600.c backports-4.2.6-1/drivers/net/usb/lg-vl600.c
14496 --- backports-4.2.6-1.org/drivers/net/usb/lg-vl600.c 1970-01-01 01:00:00.000000000 +0100
14497 +++ backports-4.2.6-1/drivers/net/usb/lg-vl600.c 2016-06-28 14:35:17.991973886 +0200
14500 + * Ethernet interface part of the LG VL600 LTE modem (4G dongle)
14502 + * Copyright (C) 2011 Intel Corporation
14503 + * Author: Andrzej Zaborowski <balrogg@gmail.com>
14505 + * This program is free software; you can redistribute it and/or modify
14506 + * it under the terms of the GNU General Public License as published by
14507 + * the Free Software Foundation; either version 2 of the License, or
14508 + * (at your option) any later version.
14510 + * This program is distributed in the hope that it will be useful,
14511 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14512 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14513 + * GNU General Public License for more details.
14515 + * You should have received a copy of the GNU General Public License
14516 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
14518 +#include <linux/etherdevice.h>
14519 +#include <linux/ethtool.h>
14520 +#include <linux/mii.h>
14521 +#include <linux/usb.h>
14522 +#include <linux/usb/cdc.h>
14523 +#include <linux/usb/usbnet.h>
14524 +#include <linux/if_ether.h>
14525 +#include <linux/if_arp.h>
14526 +#include <linux/inetdevice.h>
14527 +#include <linux/module.h>
14530 + * The device has a CDC ACM port for modem control (it claims to be
14531 + * CDC ACM anyway) and a CDC Ethernet port for actual network data.
14532 + * It will however ignore data on both ports that is not encapsulated
14533 + * in a specific way, any data returned is also encapsulated the same
14534 + * way. The headers don't seem to follow any popular standard.
14536 + * This driver adds and strips these headers from the ethernet frames
14537 + * sent/received from the CDC Ethernet port. The proprietary header
14538 + * replaces the standard ethernet header in a packet so only actual
14539 + * ethernet frames are allowed. The headers allow some form of
14540 + * multiplexing by using non standard values of the .h_proto field.
14541 + * Windows/Mac drivers do send a couple of such frames to the device
14542 + * during initialisation, with protocol set to 0x0906 or 0x0b06 and (what
14543 + * seems to be) a flag in the .dummy_flags. This doesn't seem necessary
14544 + * for modem operation but can possibly be used for GPS or other funcitons.
14547 +struct vl600_frame_hdr {
14551 + __le32 dummy_flags;
14554 +} __attribute__((packed));
14556 +struct vl600_pkt_hdr {
14560 +} __attribute__((packed));
14562 +struct vl600_state {
14563 + struct sk_buff *current_rx_buf;
14566 +static int vl600_bind(struct usbnet *dev, struct usb_interface *intf)
14569 + struct vl600_state *s = kzalloc(sizeof(struct vl600_state), GFP_KERNEL);
14574 + ret = usbnet_cdc_bind(dev, intf);
14580 + dev->driver_priv = s;
14582 + /* ARP packets don't go through, but they're also of no use. The
14583 + * subnet has only two hosts anyway: us and the gateway / DHCP
14584 + * server (probably simulated by modem firmware or network operator)
14585 + * whose address changes everytime we connect to the intarwebz and
14586 + * who doesn't bother answering ARP requests either. So hardware
14587 + * addresses have no meaning, the destination and the source of every
14588 + * packet depend only on whether it is on the IN or OUT endpoint. */
14589 + dev->net->flags |= IFF_NOARP;
14590 + /* IPv6 NDP relies on multicast. Enable it by default. */
14591 + dev->net->flags |= IFF_MULTICAST;
14596 +static void vl600_unbind(struct usbnet *dev, struct usb_interface *intf)
14598 + struct vl600_state *s = dev->driver_priv;
14600 + if (s->current_rx_buf)
14601 + dev_kfree_skb(s->current_rx_buf);
14605 + return usbnet_cdc_unbind(dev, intf);
14608 +static int vl600_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
14610 + struct vl600_frame_hdr *frame;
14611 + struct vl600_pkt_hdr *packet;
14612 + struct ethhdr *ethhdr;
14613 + int packet_len, count;
14614 + struct sk_buff *buf = skb;
14615 + struct sk_buff *clone;
14616 + struct vl600_state *s = dev->driver_priv;
14618 + /* Frame lengths are generally 4B multiplies but every couple of
14619 + * hours there's an odd number of bytes sized yet correct frame,
14620 + * so don't require this. */
14622 + /* Allow a packet (or multiple packets batched together) to be
14623 + * split across many frames. We don't allow a new batch to
14624 + * begin in the same frame another one is ending however, and no
14625 + * leading or trailing pad bytes. */
14626 + if (s->current_rx_buf) {
14627 + frame = (struct vl600_frame_hdr *) s->current_rx_buf->data;
14628 + if (skb->len + s->current_rx_buf->len >
14629 + le32_to_cpup(&frame->len)) {
14630 + netif_err(dev, ifup, dev->net, "Fragment too long\n");
14631 + dev->net->stats.rx_length_errors++;
14635 + buf = s->current_rx_buf;
14636 + memcpy(skb_put(buf, skb->len), skb->data, skb->len);
14637 + } else if (skb->len < 4) {
14638 + netif_err(dev, ifup, dev->net, "Frame too short\n");
14639 + dev->net->stats.rx_length_errors++;
14643 + frame = (struct vl600_frame_hdr *) buf->data;
14644 + /* Yes, check that frame->magic == 0x53544448 (or 0x44544d48),
14645 + * otherwise we may run out of memory w/a bad packet */
14646 + if (ntohl(frame->magic) != 0x53544448 &&
14647 + ntohl(frame->magic) != 0x44544d48)
14650 + if (buf->len < sizeof(*frame) ||
14651 + buf->len != le32_to_cpup(&frame->len)) {
14652 + /* Save this fragment for later assembly */
14653 + if (s->current_rx_buf)
14656 + s->current_rx_buf = skb_copy_expand(skb, 0,
14657 + le32_to_cpup(&frame->len), GFP_ATOMIC);
14658 + if (!s->current_rx_buf) {
14659 + netif_err(dev, ifup, dev->net, "Reserving %i bytes "
14660 + "for packet assembly failed.\n",
14661 + le32_to_cpup(&frame->len));
14662 + dev->net->stats.rx_errors++;
14668 + count = le32_to_cpup(&frame->pkt_cnt);
14670 + skb_pull(buf, sizeof(*frame));
14672 + while (count--) {
14673 + if (buf->len < sizeof(*packet)) {
14674 + netif_err(dev, ifup, dev->net, "Packet too short\n");
14678 + packet = (struct vl600_pkt_hdr *) buf->data;
14679 + packet_len = sizeof(*packet) + le32_to_cpup(&packet->len);
14680 + if (packet_len > buf->len) {
14681 + netif_err(dev, ifup, dev->net,
14682 + "Bad packet length stored in header\n");
14686 + /* Packet header is same size as the ethernet header
14687 + * (sizeof(*packet) == sizeof(*ethhdr)), additionally
14688 + * the h_proto field is in the same place so we just leave it
14689 + * alone and fill in the remaining fields.
14691 + ethhdr = (struct ethhdr *) skb->data;
14692 + if (be16_to_cpup(ðhdr->h_proto) == ETH_P_ARP &&
14693 + buf->len > 0x26) {
14694 + /* Copy the addresses from packet contents */
14695 + memcpy(ethhdr->h_source,
14696 + &buf->data[sizeof(*ethhdr) + 0x8],
14698 + memcpy(ethhdr->h_dest,
14699 + &buf->data[sizeof(*ethhdr) + 0x12],
14702 + eth_zero_addr(ethhdr->h_source);
14703 + memcpy(ethhdr->h_dest, dev->net->dev_addr, ETH_ALEN);
14705 + /* Inbound IPv6 packets have an IPv4 ethertype (0x800)
14706 + * for some reason. Peek at the L3 header to check
14707 + * for IPv6 packets, and set the ethertype to IPv6
14708 + * (0x86dd) so Linux can understand it.
14710 + if ((buf->data[sizeof(*ethhdr)] & 0xf0) == 0x60)
14711 + ethhdr->h_proto = htons(ETH_P_IPV6);
14715 + /* Not the last packet in this batch */
14716 + clone = skb_clone(buf, GFP_ATOMIC);
14720 + skb_trim(clone, packet_len);
14721 + usbnet_skb_return(dev, clone);
14723 + skb_pull(buf, (packet_len + 3) & ~3);
14725 + skb_trim(buf, packet_len);
14727 + if (s->current_rx_buf) {
14728 + usbnet_skb_return(dev, buf);
14729 + s->current_rx_buf = NULL;
14738 + if (s->current_rx_buf) {
14739 + dev_kfree_skb_any(s->current_rx_buf);
14740 + s->current_rx_buf = NULL;
14742 + dev->net->stats.rx_errors++;
14746 +static struct sk_buff *vl600_tx_fixup(struct usbnet *dev,
14747 + struct sk_buff *skb, gfp_t flags)
14749 + struct sk_buff *ret;
14750 + struct vl600_frame_hdr *frame;
14751 + struct vl600_pkt_hdr *packet;
14752 + static uint32_t serial = 1;
14753 + int orig_len = skb->len - sizeof(struct ethhdr);
14754 + int full_len = (skb->len + sizeof(struct vl600_frame_hdr) + 3) & ~3;
14756 + frame = (struct vl600_frame_hdr *) skb->data;
14757 + if (skb->len > sizeof(*frame) && skb->len == le32_to_cpup(&frame->len))
14758 + return skb; /* Already encapsulated? */
14760 + if (skb->len < sizeof(struct ethhdr))
14761 + /* Drop, device can only deal with ethernet packets */
14764 + if (!skb_cloned(skb)) {
14765 + int headroom = skb_headroom(skb);
14766 + int tailroom = skb_tailroom(skb);
14768 + if (tailroom >= full_len - skb->len - sizeof(*frame) &&
14769 + headroom >= sizeof(*frame))
14770 + /* There's enough head and tail room */
14771 + goto encapsulate;
14773 + if (headroom + tailroom + skb->len >= full_len) {
14774 + /* There's enough total room, just readjust */
14775 + skb->data = memmove(skb->head + sizeof(*frame),
14776 + skb->data, skb->len);
14777 + skb_set_tail_pointer(skb, skb->len);
14778 + goto encapsulate;
14782 + /* Alloc a new skb with the required size */
14783 + ret = skb_copy_expand(skb, sizeof(struct vl600_frame_hdr), full_len -
14784 + skb->len - sizeof(struct vl600_frame_hdr), flags);
14785 + dev_kfree_skb_any(skb);
14791 + /* Packet header is same size as ethernet packet header
14792 + * (sizeof(*packet) == sizeof(struct ethhdr)), additionally the
14793 + * h_proto field is in the same place so we just leave it alone and
14794 + * overwrite the remaining fields.
14796 + packet = (struct vl600_pkt_hdr *) skb->data;
14797 + /* The VL600 wants IPv6 packets to have an IPv4 ethertype
14798 + * Since this modem only supports IPv4 and IPv6, just set all
14799 + * frames to 0x0800 (ETH_P_IP)
14801 + packet->h_proto = htons(ETH_P_IP);
14802 + memset(&packet->dummy, 0, sizeof(packet->dummy));
14803 + packet->len = cpu_to_le32(orig_len);
14805 + frame = (struct vl600_frame_hdr *) skb_push(skb, sizeof(*frame));
14806 + memset(frame, 0, sizeof(*frame));
14807 + frame->len = cpu_to_le32(full_len);
14808 + frame->serial = cpu_to_le32(serial++);
14809 + frame->pkt_cnt = cpu_to_le32(1);
14811 + if (skb->len < full_len) /* Pad */
14812 + skb_put(skb, full_len - skb->len);
14817 +static const struct driver_info vl600_info = {
14818 + .description = "LG VL600 modem",
14819 + .flags = FLAG_RX_ASSEMBLE | FLAG_WWAN,
14820 + .bind = vl600_bind,
14821 + .unbind = vl600_unbind,
14822 + .status = usbnet_cdc_status,
14823 + .rx_fixup = vl600_rx_fixup,
14824 + .tx_fixup = vl600_tx_fixup,
14827 +static const struct usb_device_id products[] = {
14829 + USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
14830 + USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
14831 + .driver_info = (unsigned long) &vl600_info,
14835 +MODULE_DEVICE_TABLE(usb, products);
14837 +static struct usb_driver lg_vl600_driver = {
14838 + .name = "lg-vl600",
14839 + .id_table = products,
14840 + .probe = usbnet_probe,
14841 + .disconnect = usbnet_disconnect,
14842 + .suspend = usbnet_suspend,
14843 + .resume = usbnet_resume,
14844 + .disable_hub_initiated_lpm = 1,
14847 +module_usb_driver(lg_vl600_driver);
14849 +MODULE_AUTHOR("Anrzej Zaborowski");
14850 +MODULE_DESCRIPTION("LG-VL600 modem's ethernet link");
14851 +MODULE_LICENSE("GPL");
14852 diff -Naur backports-4.2.6-1.org/drivers/net/usb/Makefile backports-4.2.6-1/drivers/net/usb/Makefile
14853 --- backports-4.2.6-1.org/drivers/net/usb/Makefile 2015-11-15 22:19:40.000000000 +0100
14854 +++ backports-4.2.6-1/drivers/net/usb/Makefile 2016-06-28 14:35:17.991973886 +0200
14857 # Makefile for USB Network drivers
14860 -#obj-$(CPTCFG_USB_CATC) += catc.o
14861 -#obj-$(CPTCFG_USB_KAWETH) += kaweth.o
14862 -#obj-$(CPTCFG_USB_PEGASUS) += pegasus.o
14863 -#obj-$(CPTCFG_USB_RTL8150) += rtl8150.o
14864 -#obj-$(CPTCFG_USB_RTL8152) += r8152.o
14865 -#obj-$(CPTCFG_USB_HSO) += hso.o
14866 -#obj-$(CPTCFG_USB_NET_AX8817X) += asix.o
14867 -#obj-$(CPTCFG_USB_NET_AX88179_178A) += ax88179_178a.o
14869 +obj-$(CPTCFG_USB_CATC) += catc.o
14870 +obj-$(CPTCFG_USB_KAWETH) += kaweth.o
14871 +obj-$(CPTCFG_USB_PEGASUS) += pegasus.o
14872 +obj-$(CPTCFG_USB_RTL8150) += rtl8150.o
14873 +obj-$(CPTCFG_USB_RTL8152) += r8152.o
14874 +obj-$(CPTCFG_USB_HSO) += hso.o
14875 +obj-$(CPTCFG_USB_NET_AX8817X) += asix.o
14876 +asix-y := asix_devices.o asix_common.o ax88172a.o
14877 +obj-$(CPTCFG_USB_NET_AX88179_178A) += ax88179_178a.o
14878 obj-$(CPTCFG_USB_NET_CDCETHER) += cdc_ether.o
14879 -#obj-$(CPTCFG_USB_NET_CDC_EEM) += cdc_eem.o
14880 -#obj-$(CPTCFG_USB_NET_DM9601) += dm9601.o
14881 -#obj-$(CPTCFG_USB_NET_SR9700) += sr9700.o
14882 -#obj-$(CPTCFG_USB_NET_SR9800) += sr9800.o
14883 -#obj-$(CPTCFG_USB_NET_SMSC75XX) += smsc75xx.o
14884 -#obj-$(CPTCFG_USB_NET_SMSC95XX) += smsc95xx.o
14885 -#obj-$(CPTCFG_USB_NET_GL620A) += gl620a.o
14886 -#obj-$(CPTCFG_USB_NET_NET1080) += net1080.o
14887 -#obj-$(CPTCFG_USB_NET_PLUSB) += plusb.o
14888 +obj-$(CPTCFG_USB_NET_CDC_EEM) += cdc_eem.o
14889 +obj-$(CPTCFG_USB_NET_DM9601) += dm9601.o
14890 +obj-$(CPTCFG_USB_NET_SR9700) += sr9700.o
14891 +obj-$(CPTCFG_USB_NET_SR9800) += sr9800.o
14892 +obj-$(CPTCFG_USB_NET_SMSC75XX) += smsc75xx.o
14893 +obj-$(CPTCFG_USB_NET_SMSC95XX) += smsc95xx.o
14894 +obj-$(CPTCFG_USB_NET_GL620A) += gl620a.o
14895 +obj-$(CPTCFG_USB_NET_NET1080) += net1080.o
14896 +obj-$(CPTCFG_USB_NET_PLUSB) += plusb.o
14897 obj-$(CPTCFG_USB_NET_RNDIS_HOST) += rndis_host.o
14898 -#obj-$(CPTCFG_USB_NET_CDC_SUBSET) += cdc_subset.o
14899 -#obj-$(CPTCFG_USB_NET_ZAURUS) += zaurus.o
14900 -#obj-$(CPTCFG_USB_NET_MCS7830) += mcs7830.o
14901 +obj-$(CPTCFG_USB_NET_CDC_SUBSET) += cdc_subset.o
14902 +obj-$(CPTCFG_USB_NET_ZAURUS) += zaurus.o
14903 +obj-$(CPTCFG_USB_NET_MCS7830) += mcs7830.o
14904 obj-$(CPTCFG_USB_USBNET) += usbnet.o
14905 -#obj-$(CPTCFG_USB_NET_INT51X1) += int51x1.o
14906 -#obj-$(CPTCFG_USB_CDC_PHONET) += cdc-phonet.o
14907 -#obj-$(CPTCFG_USB_NET_KALMIA) += kalmia.o
14908 -#obj-$(CPTCFG_USB_IPHETH) += ipheth.o
14909 +obj-$(CPTCFG_USB_NET_INT51X1) += int51x1.o
14910 +obj-$(CPTCFG_USB_CDC_PHONET) += cdc-phonet.o
14911 +obj-$(CPTCFG_USB_NET_KALMIA) += kalmia.o
14912 +obj-$(CPTCFG_USB_IPHETH) += ipheth.o
14913 obj-$(CPTCFG_USB_SIERRA_NET) += sierra_net.o
14914 -#obj-$(CPTCFG_USB_NET_CX82310_ETH) += cx82310_eth.o
14915 +obj-$(CPTCFG_USB_NET_CX82310_ETH) += cx82310_eth.o
14916 obj-$(CPTCFG_USB_NET_CDC_NCM) += cdc_ncm.o
14917 -#obj-$(CPTCFG_USB_NET_HUAWEI_CDC_NCM) += huawei_cdc_ncm.o
14918 -#obj-$(CPTCFG_USB_VL600) += lg-vl600.o
14919 +obj-$(CPTCFG_USB_NET_HUAWEI_CDC_NCM) += huawei_cdc_ncm.o
14920 +obj-$(CPTCFG_USB_VL600) += lg-vl600.o
14921 obj-$(CPTCFG_USB_NET_QMI_WWAN) += qmi_wwan.o
14922 obj-$(CPTCFG_USB_NET_CDC_MBIM) += cdc_mbim.o
14924 diff -Naur backports-4.2.6-1.org/drivers/net/usb/mcs7830.c backports-4.2.6-1/drivers/net/usb/mcs7830.c
14925 --- backports-4.2.6-1.org/drivers/net/usb/mcs7830.c 1970-01-01 01:00:00.000000000 +0100
14926 +++ backports-4.2.6-1/drivers/net/usb/mcs7830.c 2016-06-28 14:35:17.995307218 +0200
14929 + * MOSCHIP MCS7830 based (7730/7830/7832) USB 2.0 Ethernet Devices
14931 + * based on usbnet.c, asix.c and the vendor provided mcs7830 driver
14933 + * Copyright (C) 2010 Andreas Mohr <andi@lisas.de>
14934 + * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>
14935 + * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
14936 + * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
14937 + * Copyright (c) 2002-2003 TiVo Inc.
14939 + * Definitions gathered from MOSCHIP, Data Sheet_7830DA.pdf (thanks!).
14941 + * 2010-12-19: add 7832 USB PID ("functionality same as MCS7830"),
14942 + * per active notification by manufacturer
14945 + * - support HIF_REG_CONFIG_SLEEPMODE/HIF_REG_CONFIG_TXENABLE (via autopm?)
14946 + * - implement ethtool_ops get_pauseparam/set_pauseparam
14947 + * via HIF_REG_PAUSE_THRESHOLD (>= revision C only!)
14948 + * - implement get_eeprom/[set_eeprom]
14949 + * - switch PHY on/off on ifup/ifdown (perhaps in usbnet.c, via MII)
14950 + * - mcs7830_get_regs() handling is weird: for rev 2 we return 32 regs,
14951 + * can access only ~ 24, remaining user buffer is uninitialized garbage
14952 + * - anything else?
14955 + * This program is free software; you can redistribute it and/or modify
14956 + * it under the terms of the GNU General Public License as published by
14957 + * the Free Software Foundation; either version 2 of the License, or
14958 + * (at your option) any later version.
14960 + * This program is distributed in the hope that it will be useful,
14961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14963 + * GNU General Public License for more details.
14965 + * You should have received a copy of the GNU General Public License
14966 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
14969 +#include <linux/crc32.h>
14970 +#include <linux/etherdevice.h>
14971 +#include <linux/ethtool.h>
14972 +#include <linux/mii.h>
14973 +#include <linux/module.h>
14974 +#include <linux/netdevice.h>
14975 +#include <linux/slab.h>
14976 +#include <linux/usb.h>
14977 +#include <linux/usb/usbnet.h>
14980 +#define MCS7830_RD_BMREQ (USB_DIR_IN | USB_TYPE_VENDOR | \
14981 + USB_RECIP_DEVICE)
14982 +#define MCS7830_WR_BMREQ (USB_DIR_OUT | USB_TYPE_VENDOR | \
14983 + USB_RECIP_DEVICE)
14984 +#define MCS7830_RD_BREQ 0x0E
14985 +#define MCS7830_WR_BREQ 0x0D
14987 +#define MCS7830_CTRL_TIMEOUT 1000
14988 +#define MCS7830_MAX_MCAST 64
14990 +#define MCS7830_VENDOR_ID 0x9710
14991 +#define MCS7832_PRODUCT_ID 0x7832
14992 +#define MCS7830_PRODUCT_ID 0x7830
14993 +#define MCS7730_PRODUCT_ID 0x7730
14995 +#define SITECOM_VENDOR_ID 0x0DF6
14996 +#define LN_030_PRODUCT_ID 0x0021
14998 +#define MCS7830_MII_ADVERTISE (ADVERTISE_PAUSE_CAP | ADVERTISE_100FULL | \
14999 + ADVERTISE_100HALF | ADVERTISE_10FULL | \
15000 + ADVERTISE_10HALF | ADVERTISE_CSMA)
15002 +/* HIF_REG_XX corresponding index value */
15004 + HIF_REG_MULTICAST_HASH = 0x00,
15005 + HIF_REG_PACKET_GAP1 = 0x08,
15006 + HIF_REG_PACKET_GAP2 = 0x09,
15007 + HIF_REG_PHY_DATA = 0x0a,
15008 + HIF_REG_PHY_CMD1 = 0x0c,
15009 + HIF_REG_PHY_CMD1_READ = 0x40,
15010 + HIF_REG_PHY_CMD1_WRITE = 0x20,
15011 + HIF_REG_PHY_CMD1_PHYADDR = 0x01,
15012 + HIF_REG_PHY_CMD2 = 0x0d,
15013 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT = 0x80,
15014 + HIF_REG_PHY_CMD2_READY_FLAG_BIT = 0x40,
15015 + HIF_REG_CONFIG = 0x0e,
15016 + /* hmm, spec sez: "R/W", "Except bit 3" (likely TXENABLE). */
15017 + HIF_REG_CONFIG_CFG = 0x80,
15018 + HIF_REG_CONFIG_SPEED100 = 0x40,
15019 + HIF_REG_CONFIG_FULLDUPLEX_ENABLE = 0x20,
15020 + HIF_REG_CONFIG_RXENABLE = 0x10,
15021 + HIF_REG_CONFIG_TXENABLE = 0x08,
15022 + HIF_REG_CONFIG_SLEEPMODE = 0x04,
15023 + HIF_REG_CONFIG_ALLMULTICAST = 0x02,
15024 + HIF_REG_CONFIG_PROMISCUOUS = 0x01,
15025 + HIF_REG_ETHERNET_ADDR = 0x0f,
15026 + HIF_REG_FRAME_DROP_COUNTER = 0x15, /* 0..ff; reset: 0 */
15027 + HIF_REG_PAUSE_THRESHOLD = 0x16,
15028 + HIF_REG_PAUSE_THRESHOLD_DEFAULT = 0,
15031 +/* Trailing status byte in Ethernet Rx frame */
15033 + MCS7830_RX_SHORT_FRAME = 0x01, /* < 64 bytes */
15034 + MCS7830_RX_LENGTH_ERROR = 0x02, /* framelen != Ethernet length field */
15035 + MCS7830_RX_ALIGNMENT_ERROR = 0x04, /* non-even number of nibbles */
15036 + MCS7830_RX_CRC_ERROR = 0x08,
15037 + MCS7830_RX_LARGE_FRAME = 0x10, /* > 1518 bytes */
15038 + MCS7830_RX_FRAME_CORRECT = 0x20, /* frame is correct */
15039 + /* [7:6] reserved */
15042 +struct mcs7830_data {
15043 + u8 multi_filter[8];
15047 +static const char driver_name[] = "MOSCHIP usb-ethernet driver";
15049 +static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data)
15051 + return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ,
15052 + 0x0000, index, data, size);
15055 +static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data)
15057 + return usbnet_write_cmd(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
15058 + 0x0000, index, data, size);
15061 +static void mcs7830_set_reg_async(struct usbnet *dev, u16 index, u16 size, void *data)
15063 + usbnet_write_cmd_async(dev, MCS7830_WR_BREQ, MCS7830_WR_BMREQ,
15064 + 0x0000, index, data, size);
15067 +static int mcs7830_hif_get_mac_address(struct usbnet *dev, unsigned char *addr)
15069 + int ret = mcs7830_get_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
15075 +static int mcs7830_hif_set_mac_address(struct usbnet *dev, unsigned char *addr)
15077 + int ret = mcs7830_set_reg(dev, HIF_REG_ETHERNET_ADDR, ETH_ALEN, addr);
15084 +static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
15087 + struct usbnet *dev = netdev_priv(netdev);
15088 + struct sockaddr *addr = p;
15090 + if (netif_running(netdev))
15093 + if (!is_valid_ether_addr(addr->sa_data))
15094 + return -EADDRNOTAVAIL;
15096 + ret = mcs7830_hif_set_mac_address(dev, addr->sa_data);
15101 + /* it worked --> adopt it on netdev side */
15102 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
15107 +static int mcs7830_read_phy(struct usbnet *dev, u8 index)
15114 + HIF_REG_PHY_CMD1_READ | HIF_REG_PHY_CMD1_PHYADDR,
15115 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
15118 + mutex_lock(&dev->phy_mutex);
15119 + /* write the MII command */
15120 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15124 + /* wait for the data to become valid, should be within < 1ms */
15125 + for (i = 0; i < 10; i++) {
15126 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15127 + if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
15135 + /* read actual register contents */
15136 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_DATA, 2, &val);
15139 + ret = le16_to_cpu(val);
15140 + dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
15143 + mutex_unlock(&dev->phy_mutex);
15147 +static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
15154 + HIF_REG_PHY_CMD1_WRITE | HIF_REG_PHY_CMD1_PHYADDR,
15155 + HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
15158 + mutex_lock(&dev->phy_mutex);
15160 + /* write the new register contents */
15161 + le_val = cpu_to_le16(val);
15162 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
15166 + /* write the MII command */
15167 + ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15171 + /* wait for the command to be accepted by the PHY */
15172 + for (i = 0; i < 10; i++) {
15173 + ret = mcs7830_get_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
15174 + if ((ret < 0) || (cmd[1] & HIF_REG_PHY_CMD2_READY_FLAG_BIT))
15183 + dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
15186 + mutex_unlock(&dev->phy_mutex);
15191 + * This algorithm comes from the original mcs7830 version 1.4 driver,
15192 + * not sure if it is needed.
15194 +static int mcs7830_set_autoneg(struct usbnet *dev, int ptrUserPhyMode)
15197 + /* Enable all media types */
15198 + ret = mcs7830_write_phy(dev, MII_ADVERTISE, MCS7830_MII_ADVERTISE);
15200 + /* First reset BMCR */
15202 + ret = mcs7830_write_phy(dev, MII_BMCR, 0x0000);
15203 + /* Enable Auto Neg */
15205 + ret = mcs7830_write_phy(dev, MII_BMCR, BMCR_ANENABLE);
15206 + /* Restart Auto Neg (Keep the Enable Auto Neg Bit Set) */
15208 + ret = mcs7830_write_phy(dev, MII_BMCR,
15209 + BMCR_ANENABLE | BMCR_ANRESTART );
15215 + * if we can read register 22, the chip revision is C or higher
15217 +static int mcs7830_get_rev(struct usbnet *dev)
15221 + ret = mcs7830_get_reg(dev, HIF_REG_FRAME_DROP_COUNTER, 2, dummy);
15223 + return 2; /* Rev C or later */
15224 + return 1; /* earlier revision */
15228 + * On rev. C we need to set the pause threshold
15230 +static void mcs7830_rev_C_fixup(struct usbnet *dev)
15232 + u8 pause_threshold = HIF_REG_PAUSE_THRESHOLD_DEFAULT;
15235 + for (retry = 0; retry < 2; retry++) {
15236 + if (mcs7830_get_rev(dev) == 2) {
15237 + dev_info(&dev->udev->dev, "applying rev.C fixup\n");
15238 + mcs7830_set_reg(dev, HIF_REG_PAUSE_THRESHOLD,
15239 + 1, &pause_threshold);
15245 +static int mcs7830_mdio_read(struct net_device *netdev, int phy_id,
15248 + struct usbnet *dev = netdev_priv(netdev);
15249 + return mcs7830_read_phy(dev, location);
15252 +static void mcs7830_mdio_write(struct net_device *netdev, int phy_id,
15253 + int location, int val)
15255 + struct usbnet *dev = netdev_priv(netdev);
15256 + mcs7830_write_phy(dev, location, val);
15259 +static int mcs7830_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
15261 + struct usbnet *dev = netdev_priv(net);
15262 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
15265 +static inline struct mcs7830_data *mcs7830_get_data(struct usbnet *dev)
15267 + return (struct mcs7830_data *)&dev->data;
15270 +static void mcs7830_hif_update_multicast_hash(struct usbnet *dev)
15272 + struct mcs7830_data *data = mcs7830_get_data(dev);
15273 + mcs7830_set_reg_async(dev, HIF_REG_MULTICAST_HASH,
15274 + sizeof data->multi_filter,
15275 + data->multi_filter);
15278 +static void mcs7830_hif_update_config(struct usbnet *dev)
15280 + /* implementation specific to data->config
15281 + (argument needs to be heap-based anyway - USB DMA!) */
15282 + struct mcs7830_data *data = mcs7830_get_data(dev);
15283 + mcs7830_set_reg_async(dev, HIF_REG_CONFIG, 1, &data->config);
15286 +static void mcs7830_data_set_multicast(struct net_device *net)
15288 + struct usbnet *dev = netdev_priv(net);
15289 + struct mcs7830_data *data = mcs7830_get_data(dev);
15291 + memset(data->multi_filter, 0, sizeof data->multi_filter);
15293 + data->config = HIF_REG_CONFIG_TXENABLE;
15295 + /* this should not be needed, but it doesn't work otherwise */
15296 + data->config |= HIF_REG_CONFIG_ALLMULTICAST;
15298 + if (net->flags & IFF_PROMISC) {
15299 + data->config |= HIF_REG_CONFIG_PROMISCUOUS;
15300 + } else if (net->flags & IFF_ALLMULTI ||
15301 + netdev_mc_count(net) > MCS7830_MAX_MCAST) {
15302 + data->config |= HIF_REG_CONFIG_ALLMULTICAST;
15303 + } else if (netdev_mc_empty(net)) {
15304 + /* just broadcast and directed */
15306 + /* We use the 20 byte dev->data
15307 + * for our 8 byte filter buffer
15308 + * to avoid allocating memory that
15309 + * is tricky to free later */
15310 + struct netdev_hw_addr *ha;
15313 + /* Build the multicast hash filter. */
15314 + netdev_for_each_mc_addr(ha, net) {
15315 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
15316 + data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
15321 +static int mcs7830_apply_base_config(struct usbnet *dev)
15325 + /* re-configure known MAC (suspend case etc.) */
15326 + ret = mcs7830_hif_set_mac_address(dev, dev->net->dev_addr);
15328 + dev_info(&dev->udev->dev, "Cannot set MAC address\n");
15333 + ret = mcs7830_set_autoneg(dev, 0);
15335 + dev_info(&dev->udev->dev, "Cannot set autoneg\n");
15339 + mcs7830_hif_update_multicast_hash(dev);
15340 + mcs7830_hif_update_config(dev);
15342 + mcs7830_rev_C_fixup(dev);
15348 +/* credits go to asix_set_multicast */
15349 +static void mcs7830_set_multicast(struct net_device *net)
15351 + struct usbnet *dev = netdev_priv(net);
15353 + mcs7830_data_set_multicast(net);
15355 + mcs7830_hif_update_multicast_hash(dev);
15356 + mcs7830_hif_update_config(dev);
15359 +static int mcs7830_get_regs_len(struct net_device *net)
15361 + struct usbnet *dev = netdev_priv(net);
15363 + switch (mcs7830_get_rev(dev)) {
15372 +static void mcs7830_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *drvinfo)
15374 + usbnet_get_drvinfo(net, drvinfo);
15375 + drvinfo->regdump_len = mcs7830_get_regs_len(net);
15378 +static void mcs7830_get_regs(struct net_device *net, struct ethtool_regs *regs, void *data)
15380 + struct usbnet *dev = netdev_priv(net);
15382 + regs->version = mcs7830_get_rev(dev);
15383 + mcs7830_get_reg(dev, 0, regs->len, data);
15386 +static const struct ethtool_ops mcs7830_ethtool_ops = {
15387 + .get_drvinfo = mcs7830_get_drvinfo,
15388 + .get_regs_len = mcs7830_get_regs_len,
15389 + .get_regs = mcs7830_get_regs,
15391 + /* common usbnet calls */
15392 + .get_link = usbnet_get_link,
15393 + .get_msglevel = usbnet_get_msglevel,
15394 + .set_msglevel = usbnet_set_msglevel,
15395 + .get_settings = usbnet_get_settings,
15396 + .set_settings = usbnet_set_settings,
15397 + .nway_reset = usbnet_nway_reset,
15400 +static const struct net_device_ops mcs7830_netdev_ops = {
15401 + .ndo_open = usbnet_open,
15402 + .ndo_stop = usbnet_stop,
15403 + .ndo_start_xmit = usbnet_start_xmit,
15404 + .ndo_tx_timeout = usbnet_tx_timeout,
15405 + .ndo_change_mtu = usbnet_change_mtu,
15406 + .ndo_validate_addr = eth_validate_addr,
15407 + .ndo_do_ioctl = mcs7830_ioctl,
15408 + .ndo_set_rx_mode = mcs7830_set_multicast,
15409 + .ndo_set_mac_address = mcs7830_set_mac_address,
15412 +static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
15414 + struct net_device *net = dev->net;
15418 + /* Initial startup: Gather MAC address setting from EEPROM */
15420 + for (retry = 0; retry < 5 && ret; retry++)
15421 + ret = mcs7830_hif_get_mac_address(dev, net->dev_addr);
15423 + dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
15427 + mcs7830_data_set_multicast(net);
15429 + ret = mcs7830_apply_base_config(dev);
15433 + net->ethtool_ops = &mcs7830_ethtool_ops;
15434 + net->netdev_ops = &mcs7830_netdev_ops;
15436 + /* reserve space for the status byte on rx */
15437 + dev->rx_urb_size = ETH_FRAME_LEN + 1;
15439 + dev->mii.mdio_read = mcs7830_mdio_read;
15440 + dev->mii.mdio_write = mcs7830_mdio_write;
15441 + dev->mii.dev = net;
15442 + dev->mii.phy_id_mask = 0x3f;
15443 + dev->mii.reg_num_mask = 0x1f;
15444 + dev->mii.phy_id = *((u8 *) net->dev_addr + 1);
15446 + ret = usbnet_get_endpoints(dev, udev);
15451 +/* The chip always appends a status byte that we need to strip */
15452 +static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
15456 + /* This check is no longer done by usbnet */
15457 + if (skb->len < dev->net->hard_header_len) {
15458 + dev_err(&dev->udev->dev, "unexpected tiny rx frame\n");
15462 + skb_trim(skb, skb->len - 1);
15463 + status = skb->data[skb->len];
15465 + if (status != MCS7830_RX_FRAME_CORRECT) {
15466 + dev_dbg(&dev->udev->dev, "rx fixup status %x\n", status);
15468 + /* hmm, perhaps usbnet.c already sees a globally visible
15469 + frame error and increments rx_errors on its own already? */
15470 + dev->net->stats.rx_errors++;
15472 + if (status & (MCS7830_RX_SHORT_FRAME
15473 + |MCS7830_RX_LENGTH_ERROR
15474 + |MCS7830_RX_LARGE_FRAME))
15475 + dev->net->stats.rx_length_errors++;
15476 + if (status & MCS7830_RX_ALIGNMENT_ERROR)
15477 + dev->net->stats.rx_frame_errors++;
15478 + if (status & MCS7830_RX_CRC_ERROR)
15479 + dev->net->stats.rx_crc_errors++;
15482 + return skb->len > 0;
15485 +static void mcs7830_status(struct usbnet *dev, struct urb *urb)
15487 + u8 *buf = urb->transfer_buffer;
15488 + bool link, link_changed;
15490 + if (urb->actual_length < 16)
15493 + link = !(buf[1] == 0x20);
15494 + link_changed = netif_carrier_ok(dev->net) != link;
15495 + if (link_changed) {
15496 + usbnet_link_change(dev, link, 0);
15497 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
15501 +static const struct driver_info moschip_info = {
15502 + .description = "MOSCHIP 7830/7832/7730 usb-NET adapter",
15503 + .bind = mcs7830_bind,
15504 + .rx_fixup = mcs7830_rx_fixup,
15505 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
15506 + .status = mcs7830_status,
15511 +static const struct driver_info sitecom_info = {
15512 + .description = "Sitecom LN-30 usb-NET adapter",
15513 + .bind = mcs7830_bind,
15514 + .rx_fixup = mcs7830_rx_fixup,
15515 + .flags = FLAG_ETHER | FLAG_LINK_INTR,
15516 + .status = mcs7830_status,
15521 +static const struct usb_device_id products[] = {
15523 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7832_PRODUCT_ID),
15524 + .driver_info = (unsigned long) &moschip_info,
15527 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7830_PRODUCT_ID),
15528 + .driver_info = (unsigned long) &moschip_info,
15531 + USB_DEVICE(MCS7830_VENDOR_ID, MCS7730_PRODUCT_ID),
15532 + .driver_info = (unsigned long) &moschip_info,
15535 + USB_DEVICE(SITECOM_VENDOR_ID, LN_030_PRODUCT_ID),
15536 + .driver_info = (unsigned long) &sitecom_info,
15540 +MODULE_DEVICE_TABLE(usb, products);
15542 +static int mcs7830_reset_resume (struct usb_interface *intf)
15544 + /* YES, this function is successful enough that ethtool -d
15545 + does show same output pre-/post-suspend */
15547 + struct usbnet *dev = usb_get_intfdata(intf);
15549 + mcs7830_apply_base_config(dev);
15551 + usbnet_resume(intf);
15556 +static struct usb_driver mcs7830_driver = {
15557 + .name = driver_name,
15558 + .id_table = products,
15559 + .probe = usbnet_probe,
15560 + .disconnect = usbnet_disconnect,
15561 + .suspend = usbnet_suspend,
15562 + .resume = usbnet_resume,
15563 + .reset_resume = mcs7830_reset_resume,
15564 + .disable_hub_initiated_lpm = 1,
15567 +module_usb_driver(mcs7830_driver);
15569 +MODULE_DESCRIPTION("USB to network adapter MCS7830)");
15570 +MODULE_LICENSE("GPL");
15571 diff -Naur backports-4.2.6-1.org/drivers/net/usb/net1080.c backports-4.2.6-1/drivers/net/usb/net1080.c
15572 --- backports-4.2.6-1.org/drivers/net/usb/net1080.c 1970-01-01 01:00:00.000000000 +0100
15573 +++ backports-4.2.6-1/drivers/net/usb/net1080.c 2016-06-28 14:35:17.995307218 +0200
15576 + * Net1080 based USB host-to-host cables
15577 + * Copyright (C) 2000-2005 by David Brownell
15579 + * This program is free software; you can redistribute it and/or modify
15580 + * it under the terms of the GNU General Public License as published by
15581 + * the Free Software Foundation; either version 2 of the License, or
15582 + * (at your option) any later version.
15584 + * This program is distributed in the hope that it will be useful,
15585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15587 + * GNU General Public License for more details.
15589 + * You should have received a copy of the GNU General Public License
15590 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
15593 +// #define DEBUG // error path messages, extra info
15594 +// #define VERBOSE // more; success messages
15596 +#include <linux/module.h>
15597 +#include <linux/netdevice.h>
15598 +#include <linux/etherdevice.h>
15599 +#include <linux/ethtool.h>
15600 +#include <linux/workqueue.h>
15601 +#include <linux/mii.h>
15602 +#include <linux/usb.h>
15603 +#include <linux/usb/usbnet.h>
15604 +#include <linux/slab.h>
15606 +#include <asm/unaligned.h>
15610 + * Netchip 1080 driver ... http://www.netchip.com
15611 + * (Sept 2004: End-of-life announcement has been sent.)
15612 + * Used in (some) LapLink cables
15615 +#define frame_errors data[1]
15618 + * NetChip framing of ethernet packets, supporting additional error
15619 + * checks for links that may drop bulk packets from inside messages.
15620 + * Odd USB length == always short read for last usb packet.
15622 + * - Ethernet header (14 bytes)
15624 + * - (optional padding byte, if needed so length becomes odd)
15627 + * This framing is to be avoided for non-NetChip devices.
15630 +struct nc_header { // packed:
15631 + __le16 hdr_len; // sizeof nc_header (LE, all)
15632 + __le16 packet_len; // payload size (including ethhdr)
15633 + __le16 packet_id; // detects dropped packets
15634 +#define MIN_HEADER 6
15636 + // all else is optional, and must start with:
15637 + // __le16 vendorId; // from usb-if
15638 + // __le16 productId;
15641 +#define PAD_BYTE ((unsigned char)0xAC)
15643 +struct nc_trailer {
15644 + __le16 packet_id;
15647 +// packets may use FLAG_FRAMING_NC and optional pad
15648 +#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
15649 + + sizeof (struct ethhdr) \
15652 + + sizeof (struct nc_trailer))
15654 +#define MIN_FRAMED FRAMED_SIZE(0)
15656 +/* packets _could_ be up to 64KB... */
15657 +#define NC_MAX_PACKET 32767
15661 + * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
15662 + * before the hardware drops it. If that's done, the driver will need to
15663 + * frame network packets to guard against the dropped USB packets. The win32
15664 + * driver sets this for both sides of the link.
15666 +#define NC_READ_TTL_MS ((u8)255) // ms
15669 + * We ignore most registers and EEPROM contents.
15671 +#define REG_USBCTL ((u8)0x04)
15672 +#define REG_TTL ((u8)0x10)
15673 +#define REG_STATUS ((u8)0x11)
15676 + * Vendor specific requests to read/write data
15678 +#define REQUEST_REGISTER ((u8)0x10)
15679 +#define REQUEST_EEPROM ((u8)0x11)
15682 +nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
15684 + int status = usbnet_read_cmd(dev, req,
15685 + USB_DIR_IN | USB_TYPE_VENDOR |
15686 + USB_RECIP_DEVICE,
15687 + 0, regnum, retval_ptr,
15688 + sizeof *retval_ptr);
15692 + le16_to_cpus(retval_ptr);
15697 +nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr)
15699 + return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);
15702 +// no retval ... can become async, usable in_interrupt()
15704 +nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value)
15706 + usbnet_write_cmd(dev, req,
15707 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
15708 + value, regnum, NULL, 0);
15711 +static inline void
15712 +nc_register_write(struct usbnet *dev, u8 regnum, u16 value)
15714 + nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);
15719 +static void nc_dump_registers(struct usbnet *dev)
15722 + u16 *vp = kmalloc(sizeof (u16));
15727 + netdev_dbg(dev->net, "registers:\n");
15728 + for (reg = 0; reg < 0x20; reg++) {
15731 + // reading some registers is trouble
15732 + if (reg >= 0x08 && reg <= 0xf)
15734 + if (reg >= 0x12 && reg <= 0x1e)
15737 + retval = nc_register_read(dev, reg, vp);
15739 + netdev_dbg(dev->net, "reg [0x%x] ==> error %d\n",
15742 + netdev_dbg(dev->net, "reg [0x%x] = 0x%x\n", reg, *vp);
15749 +/*-------------------------------------------------------------------------*/
15752 + * Control register
15755 +#define USBCTL_WRITABLE_MASK 0x1f0f
15756 +// bits 15-13 reserved, r/o
15757 +#define USBCTL_ENABLE_LANG (1 << 12)
15758 +#define USBCTL_ENABLE_MFGR (1 << 11)
15759 +#define USBCTL_ENABLE_PROD (1 << 10)
15760 +#define USBCTL_ENABLE_SERIAL (1 << 9)
15761 +#define USBCTL_ENABLE_DEFAULTS (1 << 8)
15762 +// bits 7-4 reserved, r/o
15763 +#define USBCTL_FLUSH_OTHER (1 << 3)
15764 +#define USBCTL_FLUSH_THIS (1 << 2)
15765 +#define USBCTL_DISCONN_OTHER (1 << 1)
15766 +#define USBCTL_DISCONN_THIS (1 << 0)
15768 +static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl)
15770 + netif_dbg(dev, link, dev->net,
15771 + "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s; this%s%s; other%s%s; r/o 0x%x\n",
15772 + dev->udev->bus->bus_name, dev->udev->devpath,
15774 + (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
15775 + (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
15776 + (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
15777 + (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
15778 + (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
15780 + (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
15781 + (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
15783 + (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
15784 + (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
15786 + usbctl & ~USBCTL_WRITABLE_MASK);
15789 +/*-------------------------------------------------------------------------*/
15792 + * Status register
15795 +#define STATUS_PORT_A (1 << 15)
15797 +#define STATUS_CONN_OTHER (1 << 14)
15798 +#define STATUS_SUSPEND_OTHER (1 << 13)
15799 +#define STATUS_MAILBOX_OTHER (1 << 12)
15800 +#define STATUS_PACKETS_OTHER(n) (((n) >> 8) & 0x03)
15802 +#define STATUS_CONN_THIS (1 << 6)
15803 +#define STATUS_SUSPEND_THIS (1 << 5)
15804 +#define STATUS_MAILBOX_THIS (1 << 4)
15805 +#define STATUS_PACKETS_THIS(n) (((n) >> 0) & 0x03)
15807 +#define STATUS_UNSPEC_MASK 0x0c8c
15808 +#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
15811 +static inline void nc_dump_status(struct usbnet *dev, u16 status)
15813 + netif_dbg(dev, link, dev->net,
15814 + "net1080 %s-%s status 0x%x: this (%c) PKT=%d%s%s%s; other PKT=%d%s%s%s; unspec 0x%x\n",
15815 + dev->udev->bus->bus_name, dev->udev->devpath,
15818 + // XXX the packet counts don't seem right
15819 + // (1 at reset, not 0); maybe UNSPEC too
15821 + (status & STATUS_PORT_A) ? 'A' : 'B',
15822 + STATUS_PACKETS_THIS(status),
15823 + (status & STATUS_CONN_THIS) ? " CON" : "",
15824 + (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
15825 + (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
15827 + STATUS_PACKETS_OTHER(status),
15828 + (status & STATUS_CONN_OTHER) ? " CON" : "",
15829 + (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
15830 + (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
15832 + status & STATUS_UNSPEC_MASK);
15835 +/*-------------------------------------------------------------------------*/
15841 +#define TTL_THIS(ttl) (0x00ff & ttl)
15842 +#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
15843 +#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
15845 +static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl)
15847 + netif_dbg(dev, link, dev->net, "net1080 %s-%s ttl 0x%x this = %d, other = %d\n",
15848 + dev->udev->bus->bus_name, dev->udev->devpath,
15849 + ttl, TTL_THIS(ttl), TTL_OTHER(ttl));
15852 +/*-------------------------------------------------------------------------*/
15854 +static int net1080_reset(struct usbnet *dev)
15856 + u16 usbctl, status, ttl;
15860 + // nc_dump_registers(dev);
15862 + if ((retval = nc_register_read(dev, REG_STATUS, &vp)) < 0) {
15863 + netdev_dbg(dev->net, "can't read %s-%s status: %d\n",
15864 + dev->udev->bus->bus_name, dev->udev->devpath, retval);
15868 + nc_dump_status(dev, status);
15870 + if ((retval = nc_register_read(dev, REG_USBCTL, &vp)) < 0) {
15871 + netdev_dbg(dev->net, "can't read USBCTL, %d\n", retval);
15875 + nc_dump_usbctl(dev, usbctl);
15877 + nc_register_write(dev, REG_USBCTL,
15878 + USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
15880 + if ((retval = nc_register_read(dev, REG_TTL, &vp)) < 0) {
15881 + netdev_dbg(dev->net, "can't read TTL, %d\n", retval);
15885 + // nc_dump_ttl(dev, ttl);
15887 + nc_register_write(dev, REG_TTL,
15888 + MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) );
15889 + netdev_dbg(dev->net, "assigned TTL, %d ms\n", NC_READ_TTL_MS);
15891 + netif_info(dev, link, dev->net, "port %c, peer %sconnected\n",
15892 + (status & STATUS_PORT_A) ? 'A' : 'B',
15893 + (status & STATUS_CONN_OTHER) ? "" : "dis");
15900 +static int net1080_check_connect(struct usbnet *dev)
15906 + retval = nc_register_read(dev, REG_STATUS, &vp);
15908 + if (retval != 0) {
15909 + netdev_dbg(dev->net, "net1080_check_conn read - %d\n", retval);
15912 + if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
15917 +static void nc_ensure_sync(struct usbnet *dev)
15919 + if (++dev->frame_errors <= 5)
15922 + if (usbnet_write_cmd_async(dev, REQUEST_REGISTER,
15923 + USB_DIR_OUT | USB_TYPE_VENDOR |
15924 + USB_RECIP_DEVICE,
15925 + USBCTL_FLUSH_THIS |
15926 + USBCTL_FLUSH_OTHER,
15927 + REG_USBCTL, NULL, 0))
15930 + netif_dbg(dev, rx_err, dev->net,
15931 + "flush net1080; too many framing errors\n");
15932 + dev->frame_errors = 0;
15935 +static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
15937 + struct nc_header *header;
15938 + struct nc_trailer *trailer;
15939 + u16 hdr_len, packet_len;
15941 + /* This check is no longer done by usbnet */
15942 + if (skb->len < dev->net->hard_header_len)
15945 + if (!(skb->len & 0x01)) {
15946 + netdev_dbg(dev->net, "rx framesize %d range %d..%d mtu %d\n",
15947 + skb->len, dev->net->hard_header_len, dev->hard_mtu,
15949 + dev->net->stats.rx_frame_errors++;
15950 + nc_ensure_sync(dev);
15954 + header = (struct nc_header *) skb->data;
15955 + hdr_len = le16_to_cpup(&header->hdr_len);
15956 + packet_len = le16_to_cpup(&header->packet_len);
15957 + if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) {
15958 + dev->net->stats.rx_frame_errors++;
15959 + netdev_dbg(dev->net, "packet too big, %d\n", packet_len);
15960 + nc_ensure_sync(dev);
15962 + } else if (hdr_len < MIN_HEADER) {
15963 + dev->net->stats.rx_frame_errors++;
15964 + netdev_dbg(dev->net, "header too short, %d\n", hdr_len);
15965 + nc_ensure_sync(dev);
15967 + } else if (hdr_len > MIN_HEADER) {
15968 + // out of band data for us?
15969 + netdev_dbg(dev->net, "header OOB, %d bytes\n", hdr_len - MIN_HEADER);
15970 + nc_ensure_sync(dev);
15971 + // switch (vendor/product ids) { ... }
15973 + skb_pull(skb, hdr_len);
15975 + trailer = (struct nc_trailer *)
15976 + (skb->data + skb->len - sizeof *trailer);
15977 + skb_trim(skb, skb->len - sizeof *trailer);
15979 + if ((packet_len & 0x01) == 0) {
15980 + if (skb->data [packet_len] != PAD_BYTE) {
15981 + dev->net->stats.rx_frame_errors++;
15982 + netdev_dbg(dev->net, "bad pad\n");
15985 + skb_trim(skb, skb->len - 1);
15987 + if (skb->len != packet_len) {
15988 + dev->net->stats.rx_frame_errors++;
15989 + netdev_dbg(dev->net, "bad packet len %d (expected %d)\n",
15990 + skb->len, packet_len);
15991 + nc_ensure_sync(dev);
15994 + if (header->packet_id != get_unaligned(&trailer->packet_id)) {
15995 + dev->net->stats.rx_fifo_errors++;
15996 + netdev_dbg(dev->net, "(2+ dropped) rx packet_id mismatch 0x%x 0x%x\n",
15997 + le16_to_cpu(header->packet_id),
15998 + le16_to_cpu(trailer->packet_id));
16002 + netdev_dbg(dev->net, "frame <rx h %d p %d id %d\n", header->hdr_len,
16003 + header->packet_len, header->packet_id);
16005 + dev->frame_errors = 0;
16009 +static struct sk_buff *
16010 +net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
16012 + struct sk_buff *skb2;
16013 + struct nc_header *header = NULL;
16014 + struct nc_trailer *trailer = NULL;
16015 + int padlen = sizeof (struct nc_trailer);
16016 + int len = skb->len;
16018 + if (!((len + padlen + sizeof (struct nc_header)) & 0x01))
16020 + if (!skb_cloned(skb)) {
16021 + int headroom = skb_headroom(skb);
16022 + int tailroom = skb_tailroom(skb);
16024 + if (padlen <= tailroom &&
16025 + sizeof(struct nc_header) <= headroom)
16026 + /* There's enough head and tail room */
16027 + goto encapsulate;
16029 + if ((sizeof (struct nc_header) + padlen) <
16030 + (headroom + tailroom)) {
16031 + /* There's enough total room, so just readjust */
16032 + skb->data = memmove(skb->head
16033 + + sizeof (struct nc_header),
16034 + skb->data, skb->len);
16035 + skb_set_tail_pointer(skb, len);
16036 + goto encapsulate;
16040 + /* Create a new skb to use with the correct size */
16041 + skb2 = skb_copy_expand(skb,
16042 + sizeof (struct nc_header),
16045 + dev_kfree_skb_any(skb);
16051 + /* header first */
16052 + header = (struct nc_header *) skb_push(skb, sizeof *header);
16053 + header->hdr_len = cpu_to_le16(sizeof (*header));
16054 + header->packet_len = cpu_to_le16(len);
16055 + header->packet_id = cpu_to_le16((u16)dev->xid++);
16057 + /* maybe pad; then trailer */
16058 + if (!((skb->len + sizeof *trailer) & 0x01))
16059 + *skb_put(skb, 1) = PAD_BYTE;
16060 + trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer);
16061 + put_unaligned(header->packet_id, &trailer->packet_id);
16063 + netdev_dbg(dev->net, "frame >tx h %d p %d id %d\n",
16064 + header->hdr_len, header->packet_len,
16065 + header->packet_id);
16070 +static int net1080_bind(struct usbnet *dev, struct usb_interface *intf)
16072 + unsigned extra = sizeof (struct nc_header)
16074 + + sizeof (struct nc_trailer);
16076 + dev->net->hard_header_len += extra;
16077 + dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
16078 + dev->hard_mtu = NC_MAX_PACKET;
16079 + return usbnet_get_endpoints (dev, intf);
16082 +static const struct driver_info net1080_info = {
16083 + .description = "NetChip TurboCONNECT",
16084 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_NC,
16085 + .bind = net1080_bind,
16086 + .reset = net1080_reset,
16087 + .check_connect = net1080_check_connect,
16088 + .rx_fixup = net1080_rx_fixup,
16089 + .tx_fixup = net1080_tx_fixup,
16092 +static const struct usb_device_id products [] = {
16094 + USB_DEVICE(0x0525, 0x1080), // NetChip ref design
16095 + .driver_info = (unsigned long) &net1080_info,
16097 + USB_DEVICE(0x06D0, 0x0622), // Laplink Gold
16098 + .driver_info = (unsigned long) &net1080_info,
16102 +MODULE_DEVICE_TABLE(usb, products);
16104 +static struct usb_driver net1080_driver = {
16105 + .name = "net1080",
16106 + .id_table = products,
16107 + .probe = usbnet_probe,
16108 + .disconnect = usbnet_disconnect,
16109 + .suspend = usbnet_suspend,
16110 + .resume = usbnet_resume,
16111 + .disable_hub_initiated_lpm = 1,
16114 +module_usb_driver(net1080_driver);
16116 +MODULE_AUTHOR("David Brownell");
16117 +MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links");
16118 +MODULE_LICENSE("GPL");
16119 diff -Naur backports-4.2.6-1.org/drivers/net/usb/pegasus.c backports-4.2.6-1/drivers/net/usb/pegasus.c
16120 --- backports-4.2.6-1.org/drivers/net/usb/pegasus.c 1970-01-01 01:00:00.000000000 +0100
16121 +++ backports-4.2.6-1/drivers/net/usb/pegasus.c 2016-06-28 14:35:17.995307218 +0200
16124 + * Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
16126 + * This program is free software; you can redistribute it and/or modify
16127 + * it under the terms of the GNU General Public License version 2 as
16128 + * published by the Free Software Foundation.
16131 + * .... Most of the time spent on reading sources & docs.
16132 + * v0.2.x First official release for the Linux kernel.
16133 + * v0.3.0 Beutified and structured, some bugs fixed.
16134 + * v0.3.x URBifying bulk requests and bugfixing. First relatively
16135 + * stable release. Still can touch device's registers only
16136 + * from top-halves.
16137 + * v0.4.0 Control messages remained unurbified are now URBs.
16138 + * Now we can touch the HW at any time.
16139 + * v0.4.9 Control urbs again use process context to wait. Argh...
16140 + * Some long standing bugs (enable_net_traffic) fixed.
16141 + * Also nasty trick about resubmiting control urb from
16142 + * interrupt context used. Please let me know how it
16143 + * behaves. Pegasus II support added since this version.
16144 + * TODO: suppressing HCD warnings spewage on disconnect.
16145 + * v0.4.13 Ethernet address is now set at probe(), not at open()
16146 + * time as this seems to break dhcpd.
16147 + * v0.5.0 branch to 2.5.x kernels
16148 + * v0.5.1 ethtool support added
16149 + * v0.5.5 rx socket buffers are in a pool and the their allocation
16150 + * is out of the interrupt routine.
16152 + * v0.9.3 simplified [get|set]_register(s), async update registers
16153 + * logic revisited, receive skb_pool removed.
16156 +#include <linux/sched.h>
16157 +#include <linux/slab.h>
16158 +#include <linux/init.h>
16159 +#include <linux/delay.h>
16160 +#include <linux/netdevice.h>
16161 +#include <linux/etherdevice.h>
16162 +#include <linux/ethtool.h>
16163 +#include <linux/mii.h>
16164 +#include <linux/usb.h>
16165 +#include <linux/module.h>
16166 +#include <asm/byteorder.h>
16167 +#include <asm/uaccess.h>
16168 +#include "pegasus.h"
16171 + * Version Information
16173 +#define DRIVER_VERSION "v0.9.3 (2013/04/25)"
16174 +#define DRIVER_AUTHOR "Petko Manolov <petkan@nucleusys.com>"
16175 +#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
16177 +static const char driver_name[] = "pegasus";
16179 +#undef PEGASUS_WRITE_EEPROM
16180 +#define BMSR_MEDIA (BMSR_10HALF | BMSR_10FULL | BMSR_100HALF | \
16181 + BMSR_100FULL | BMSR_ANEGCAPABLE)
16183 +static bool loopback;
16184 +static bool mii_mode;
16185 +static char *devid;
16187 +static struct usb_eth_dev usb_dev_id[] = {
16188 +#define PEGASUS_DEV(pn, vid, pid, flags) \
16189 + {.name = pn, .vendor = vid, .device = pid, .private = flags},
16190 +#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
16191 + PEGASUS_DEV(pn, vid, pid, flags)
16192 +#include "pegasus.h"
16193 +#undef PEGASUS_DEV
16194 +#undef PEGASUS_DEV_CLASS
16199 +static struct usb_device_id pegasus_ids[] = {
16200 +#define PEGASUS_DEV(pn, vid, pid, flags) \
16201 + {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
16203 + * The Belkin F8T012xx1 bluetooth adaptor has the same vendor and product
16204 + * IDs as the Belkin F5D5050, so we need to teach the pegasus driver to
16205 + * ignore adaptors belonging to the "Wireless" class 0xE0. For this one
16206 + * case anyway, seeing as the pegasus is for "Wired" adaptors.
16208 +#define PEGASUS_DEV_CLASS(pn, vid, pid, dclass, flags) \
16209 + {.match_flags = (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_CLASS), \
16210 + .idVendor = vid, .idProduct = pid, .bDeviceClass = dclass},
16211 +#include "pegasus.h"
16212 +#undef PEGASUS_DEV
16213 +#undef PEGASUS_DEV_CLASS
16218 +MODULE_AUTHOR(DRIVER_AUTHOR);
16219 +MODULE_DESCRIPTION(DRIVER_DESC);
16220 +MODULE_LICENSE("GPL");
16221 +module_param(loopback, bool, 0);
16222 +module_param(mii_mode, bool, 0);
16223 +module_param(devid, charp, 0);
16224 +MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
16225 +MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
16226 +MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
16228 +/* use ethtool to change the level for any given device */
16229 +static int msg_level = -1;
16230 +module_param(msg_level, int, 0);
16231 +MODULE_PARM_DESC(msg_level, "Override default message level");
16233 +MODULE_DEVICE_TABLE(usb, pegasus_ids);
16234 +static const struct net_device_ops pegasus_netdev_ops;
16238 +static void async_ctrl_callback(struct urb *urb)
16240 + struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
16241 + int status = urb->status;
16244 + dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
16246 + usb_free_urb(urb);
16249 +static int get_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
16253 + ret = usb_control_msg(pegasus->usb, usb_rcvctrlpipe(pegasus->usb, 0),
16254 + PEGASUS_REQ_GET_REGS, PEGASUS_REQT_READ, 0,
16255 + indx, data, size, 1000);
16257 + netif_dbg(pegasus, drv, pegasus->net,
16258 + "%s returned %d\n", __func__, ret);
16262 +static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data)
16266 + ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
16267 + PEGASUS_REQ_SET_REGS, PEGASUS_REQT_WRITE, 0,
16268 + indx, data, size, 100);
16270 + netif_dbg(pegasus, drv, pegasus->net,
16271 + "%s returned %d\n", __func__, ret);
16275 +static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data)
16279 + ret = usb_control_msg(pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0),
16280 + PEGASUS_REQ_SET_REG, PEGASUS_REQT_WRITE, data,
16281 + indx, &data, 1, 1000);
16283 + netif_dbg(pegasus, drv, pegasus->net,
16284 + "%s returned %d\n", __func__, ret);
16288 +static int update_eth_regs_async(pegasus_t *pegasus)
16290 + int ret = -ENOMEM;
16291 + struct urb *async_urb;
16292 + struct usb_ctrlrequest *req;
16294 + req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
16298 + async_urb = usb_alloc_urb(0, GFP_ATOMIC);
16299 + if (async_urb == NULL) {
16303 + req->bRequestType = PEGASUS_REQT_WRITE;
16304 + req->bRequest = PEGASUS_REQ_SET_REGS;
16305 + req->wValue = cpu_to_le16(0);
16306 + req->wIndex = cpu_to_le16(EthCtrl0);
16307 + req->wLength = cpu_to_le16(3);
16309 + usb_fill_control_urb(async_urb, pegasus->usb,
16310 + usb_sndctrlpipe(pegasus->usb, 0), (void *)req,
16311 + pegasus->eth_regs, 3, async_ctrl_callback, req);
16313 + ret = usb_submit_urb(async_urb, GFP_ATOMIC);
16315 + if (ret == -ENODEV)
16316 + netif_device_detach(pegasus->net);
16317 + netif_err(pegasus, drv, pegasus->net,
16318 + "%s returned %d\n", __func__, ret);
16323 +static int __mii_op(pegasus_t *p, __u8 phy, __u8 indx, __u16 *regd, __u8 cmd)
16326 + __u8 data[4] = { phy, 0, 0, indx };
16328 + int ret = -ETIMEDOUT;
16330 + if (cmd & PHY_WRITE) {
16331 + __le16 *t = (__le16 *) & data[1];
16332 + *t = cpu_to_le16(*regd);
16334 + set_register(p, PhyCtrl, 0);
16335 + set_registers(p, PhyAddr, sizeof(data), data);
16336 + set_register(p, PhyCtrl, (indx | cmd));
16337 + for (i = 0; i < REG_TIMEOUT; i++) {
16338 + ret = get_registers(p, PhyCtrl, 1, data);
16341 + if (data[0] & PHY_DONE)
16344 + if (i >= REG_TIMEOUT)
16346 + if (cmd & PHY_READ) {
16347 + ret = get_registers(p, PhyData, 2, ®di);
16348 + *regd = le16_to_cpu(regdi);
16353 + netif_dbg(p, drv, p->net, "%s failed\n", __func__);
16357 +/* Returns non-negative int on success, error on failure */
16358 +static int read_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
16360 + return __mii_op(pegasus, phy, indx, regd, PHY_READ);
16363 +/* Returns zero on success, error on failure */
16364 +static int write_mii_word(pegasus_t *pegasus, __u8 phy, __u8 indx, __u16 *regd)
16366 + return __mii_op(pegasus, phy, indx, regd, PHY_WRITE);
16369 +static int mdio_read(struct net_device *dev, int phy_id, int loc)
16371 + pegasus_t *pegasus = netdev_priv(dev);
16374 + read_mii_word(pegasus, phy_id, loc, &res);
16378 +static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
16380 + pegasus_t *pegasus = netdev_priv(dev);
16383 + write_mii_word(pegasus, phy_id, loc, &data);
16386 +static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata)
16393 + set_register(pegasus, EpromCtrl, 0);
16394 + set_register(pegasus, EpromOffset, index);
16395 + set_register(pegasus, EpromCtrl, EPROM_READ);
16397 + for (i = 0; i < REG_TIMEOUT; i++) {
16398 + ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
16399 + if (tmp & EPROM_DONE)
16401 + if (ret == -ESHUTDOWN)
16404 + if (i >= REG_TIMEOUT)
16407 + ret = get_registers(pegasus, EpromData, 2, &retdatai);
16408 + *retdata = le16_to_cpu(retdatai);
16412 + netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
16413 + return -ETIMEDOUT;
16416 +#ifdef PEGASUS_WRITE_EEPROM
16417 +static inline void enable_eprom_write(pegasus_t *pegasus)
16421 + get_registers(pegasus, EthCtrl2, 1, &tmp);
16422 + set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
16425 +static inline void disable_eprom_write(pegasus_t *pegasus)
16429 + get_registers(pegasus, EthCtrl2, 1, &tmp);
16430 + set_register(pegasus, EpromCtrl, 0);
16431 + set_register(pegasus, EthCtrl2, tmp & ~EPROM_WR_ENABLE);
16434 +static int write_eprom_word(pegasus_t *pegasus, __u8 index, __u16 data)
16437 + __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
16439 + __le16 le_data = cpu_to_le16(data);
16441 + set_registers(pegasus, EpromOffset, 4, d);
16442 + enable_eprom_write(pegasus);
16443 + set_register(pegasus, EpromOffset, index);
16444 + set_registers(pegasus, EpromData, 2, &le_data);
16445 + set_register(pegasus, EpromCtrl, EPROM_WRITE);
16447 + for (i = 0; i < REG_TIMEOUT; i++) {
16448 + ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
16449 + if (ret == -ESHUTDOWN)
16451 + if (tmp & EPROM_DONE)
16454 + disable_eprom_write(pegasus);
16455 + if (i >= REG_TIMEOUT)
16461 + netif_warn(pegasus, drv, pegasus->net, "%s failed\n", __func__);
16462 + return -ETIMEDOUT;
16464 +#endif /* PEGASUS_WRITE_EEPROM */
16466 +static inline void get_node_id(pegasus_t *pegasus, __u8 *id)
16471 + for (i = 0; i < 3; i++) {
16472 + read_eprom_word(pegasus, i, &w16);
16473 + ((__le16 *) id)[i] = cpu_to_le16(w16);
16477 +static void set_ethernet_addr(pegasus_t *pegasus)
16481 + if (pegasus->features & PEGASUS_II) {
16482 + get_registers(pegasus, 0x10, sizeof(node_id), node_id);
16484 + get_node_id(pegasus, node_id);
16485 + set_registers(pegasus, EthID, sizeof(node_id), node_id);
16487 + memcpy(pegasus->net->dev_addr, node_id, sizeof(node_id));
16490 +static inline int reset_mac(pegasus_t *pegasus)
16495 + set_register(pegasus, EthCtrl1, data);
16496 + for (i = 0; i < REG_TIMEOUT; i++) {
16497 + get_registers(pegasus, EthCtrl1, 1, &data);
16498 + if (~data & 0x08) {
16501 + if (mii_mode && (pegasus->features & HAS_HOME_PNA))
16502 + set_register(pegasus, Gpio1, 0x34);
16504 + set_register(pegasus, Gpio1, 0x26);
16505 + set_register(pegasus, Gpio0, pegasus->features);
16506 + set_register(pegasus, Gpio0, DEFAULT_GPIO_SET);
16510 + if (i == REG_TIMEOUT)
16511 + return -ETIMEDOUT;
16513 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
16514 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
16515 + set_register(pegasus, Gpio0, 0x24);
16516 + set_register(pegasus, Gpio0, 0x26);
16518 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_ELCON) {
16520 + read_mii_word(pegasus, 3, 0x1b, &auxmode);
16522 + write_mii_word(pegasus, 3, 0x1b, &auxmode);
16528 +static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
16532 + pegasus_t *pegasus = netdev_priv(dev);
16535 + read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
16538 + if (linkpart & (ADVERTISE_100FULL | ADVERTISE_10FULL))
16539 + data[1] |= 0x20; /* set full duplex */
16540 + if (linkpart & (ADVERTISE_100FULL | ADVERTISE_100HALF))
16541 + data[1] |= 0x10; /* set 100 Mbps */
16544 + data[2] = loopback ? 0x09 : 0x01;
16546 + memcpy(pegasus->eth_regs, data, sizeof(data));
16547 + ret = set_registers(pegasus, EthCtrl0, 3, data);
16549 + if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
16550 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
16551 + usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
16553 + read_mii_word(pegasus, 0, 0x1b, &auxmode);
16555 + write_mii_word(pegasus, 0, 0x1b, &auxmode);
16561 +static void read_bulk_callback(struct urb *urb)
16563 + pegasus_t *pegasus = urb->context;
16564 + struct net_device *net;
16565 + int rx_status, count = urb->actual_length;
16566 + int status = urb->status;
16567 + u8 *buf = urb->transfer_buffer;
16573 + net = pegasus->net;
16574 + if (!netif_device_present(net) || !netif_running(net))
16577 + switch (status) {
16581 + netif_dbg(pegasus, rx_err, net, "reset MAC\n");
16582 + pegasus->flags &= ~PEGASUS_RX_BUSY;
16584 + case -EPIPE: /* stall, or disconnect from TT */
16585 + /* FIXME schedule work to clear the halt */
16586 + netif_warn(pegasus, rx_err, net, "no rx stall recovery\n");
16589 + case -ECONNRESET:
16591 + netif_dbg(pegasus, ifdown, net, "rx unlink, %d\n", status);
16594 + netif_dbg(pegasus, rx_err, net, "RX status %d\n", status);
16598 + if (!count || count < 4)
16601 + rx_status = buf[count - 2];
16602 + if (rx_status & 0x1e) {
16603 + netif_dbg(pegasus, rx_err, net,
16604 + "RX packet error %x\n", rx_status);
16605 + pegasus->stats.rx_errors++;
16606 + if (rx_status & 0x06) /* long or runt */
16607 + pegasus->stats.rx_length_errors++;
16608 + if (rx_status & 0x08)
16609 + pegasus->stats.rx_crc_errors++;
16610 + if (rx_status & 0x10) /* extra bits */
16611 + pegasus->stats.rx_frame_errors++;
16614 + if (pegasus->chip == 0x8513) {
16615 + pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
16616 + pkt_len &= 0x0fff;
16617 + pegasus->rx_skb->data += 2;
16619 + pkt_len = buf[count - 3] << 8;
16620 + pkt_len += buf[count - 4];
16621 + pkt_len &= 0xfff;
16626 + * If the packet is unreasonably long, quietly drop it rather than
16627 + * kernel panicing by calling skb_put.
16629 + if (pkt_len > PEGASUS_MTU)
16633 + * at this point we are sure pegasus->rx_skb != NULL
16634 + * so we go ahead and pass up the packet.
16636 + skb_put(pegasus->rx_skb, pkt_len);
16637 + pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
16638 + netif_rx(pegasus->rx_skb);
16639 + pegasus->stats.rx_packets++;
16640 + pegasus->stats.rx_bytes += pkt_len;
16642 + if (pegasus->flags & PEGASUS_UNPLUG)
16645 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net, PEGASUS_MTU,
16648 + if (pegasus->rx_skb == NULL)
16651 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16652 + usb_rcvbulkpipe(pegasus->usb, 1),
16653 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16654 + read_bulk_callback, pegasus);
16655 + rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
16656 + if (rx_status == -ENODEV)
16657 + netif_device_detach(pegasus->net);
16658 + else if (rx_status) {
16659 + pegasus->flags |= PEGASUS_RX_URB_FAIL;
16662 + pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
16668 + tasklet_schedule(&pegasus->rx_tl);
16671 +static void rx_fixup(unsigned long data)
16673 + pegasus_t *pegasus;
16676 + pegasus = (pegasus_t *) data;
16677 + if (pegasus->flags & PEGASUS_UNPLUG)
16680 + if (pegasus->flags & PEGASUS_RX_URB_FAIL)
16681 + if (pegasus->rx_skb)
16683 + if (pegasus->rx_skb == NULL)
16684 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
16687 + if (pegasus->rx_skb == NULL) {
16688 + netif_warn(pegasus, rx_err, pegasus->net, "low on memory\n");
16689 + tasklet_schedule(&pegasus->rx_tl);
16692 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16693 + usb_rcvbulkpipe(pegasus->usb, 1),
16694 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16695 + read_bulk_callback, pegasus);
16697 + status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
16698 + if (status == -ENODEV)
16699 + netif_device_detach(pegasus->net);
16700 + else if (status) {
16701 + pegasus->flags |= PEGASUS_RX_URB_FAIL;
16702 + tasklet_schedule(&pegasus->rx_tl);
16704 + pegasus->flags &= ~PEGASUS_RX_URB_FAIL;
16708 +static void write_bulk_callback(struct urb *urb)
16710 + pegasus_t *pegasus = urb->context;
16711 + struct net_device *net;
16712 + int status = urb->status;
16717 + net = pegasus->net;
16719 + if (!netif_device_present(net) || !netif_running(net))
16722 + switch (status) {
16724 + /* FIXME schedule_work() to clear the tx halt */
16725 + netif_stop_queue(net);
16726 + netif_warn(pegasus, tx_err, net, "no tx stall recovery\n");
16729 + case -ECONNRESET:
16731 + netif_dbg(pegasus, ifdown, net, "tx unlink, %d\n", status);
16734 + netif_info(pegasus, tx_err, net, "TX status %d\n", status);
16735 + /* FALL THROUGH */
16740 + net->trans_start = jiffies; /* prevent tx timeout */
16741 + netif_wake_queue(net);
16744 +static void intr_callback(struct urb *urb)
16746 + pegasus_t *pegasus = urb->context;
16747 + struct net_device *net;
16748 + int res, status = urb->status;
16752 + net = pegasus->net;
16754 + switch (status) {
16757 + case -ECONNRESET: /* unlink */
16762 + /* some Pegasus-I products report LOTS of data
16763 + * toggle errors... avoid log spamming
16765 + netif_dbg(pegasus, timer, net, "intr status %d\n", status);
16768 + if (urb->actual_length >= 6) {
16769 + u8 *d = urb->transfer_buffer;
16771 + /* byte 0 == tx_status1, reg 2B */
16772 + if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
16773 + |LATE_COL|JABBER_TIMEOUT)) {
16774 + pegasus->stats.tx_errors++;
16775 + if (d[0] & TX_UNDERRUN)
16776 + pegasus->stats.tx_fifo_errors++;
16777 + if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
16778 + pegasus->stats.tx_aborted_errors++;
16779 + if (d[0] & LATE_COL)
16780 + pegasus->stats.tx_window_errors++;
16783 + /* d[5].LINK_STATUS lies on some adapters.
16784 + * d[0].NO_CARRIER kicks in only with failed TX.
16785 + * ... so monitoring with MII may be safest.
16788 + /* bytes 3-4 == rx_lostpkt, reg 2E/2F */
16789 + pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
16792 + res = usb_submit_urb(urb, GFP_ATOMIC);
16793 + if (res == -ENODEV)
16794 + netif_device_detach(pegasus->net);
16796 + netif_err(pegasus, timer, net,
16797 + "can't resubmit interrupt urb, %d\n", res);
16800 +static void pegasus_tx_timeout(struct net_device *net)
16802 + pegasus_t *pegasus = netdev_priv(net);
16803 + netif_warn(pegasus, timer, net, "tx timeout\n");
16804 + usb_unlink_urb(pegasus->tx_urb);
16805 + pegasus->stats.tx_errors++;
16808 +static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
16809 + struct net_device *net)
16811 + pegasus_t *pegasus = netdev_priv(net);
16812 + int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
16814 + __u16 l16 = skb->len;
16816 + netif_stop_queue(net);
16818 + ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
16819 + skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
16820 + usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
16821 + usb_sndbulkpipe(pegasus->usb, 2),
16822 + pegasus->tx_buff, count,
16823 + write_bulk_callback, pegasus);
16824 + if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
16825 + netif_warn(pegasus, tx_err, net, "fail tx, %d\n", res);
16827 + case -EPIPE: /* stall, or disconnect from TT */
16828 + /* cleanup should already have been scheduled */
16830 + case -ENODEV: /* disconnect() upcoming */
16832 + netif_device_detach(pegasus->net);
16835 + pegasus->stats.tx_errors++;
16836 + netif_start_queue(net);
16839 + pegasus->stats.tx_packets++;
16840 + pegasus->stats.tx_bytes += skb->len;
16842 + dev_kfree_skb(skb);
16844 + return NETDEV_TX_OK;
16847 +static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
16849 + return &((pegasus_t *) netdev_priv(dev))->stats;
16852 +static inline void disable_net_traffic(pegasus_t *pegasus)
16854 + __le16 tmp = cpu_to_le16(0);
16856 + set_registers(pegasus, EthCtrl0, sizeof(tmp), &tmp);
16859 +static inline void get_interrupt_interval(pegasus_t *pegasus)
16864 + read_eprom_word(pegasus, 4, &data);
16865 + interval = data >> 8;
16866 + if (pegasus->usb->speed != USB_SPEED_HIGH) {
16867 + if (interval < 0x80) {
16868 + netif_info(pegasus, timer, pegasus->net,
16869 + "intr interval changed from %ums to %ums\n",
16872 + data = (data & 0x00FF) | ((u16)interval << 8);
16873 +#ifdef PEGASUS_WRITE_EEPROM
16874 + write_eprom_word(pegasus, 4, data);
16878 + pegasus->intr_interval = interval;
16881 +static void set_carrier(struct net_device *net)
16883 + pegasus_t *pegasus = netdev_priv(net);
16886 + if (read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
16889 + if (tmp & BMSR_LSTATUS)
16890 + netif_carrier_on(net);
16892 + netif_carrier_off(net);
16895 +static void free_all_urbs(pegasus_t *pegasus)
16897 + usb_free_urb(pegasus->intr_urb);
16898 + usb_free_urb(pegasus->tx_urb);
16899 + usb_free_urb(pegasus->rx_urb);
16902 +static void unlink_all_urbs(pegasus_t *pegasus)
16904 + usb_kill_urb(pegasus->intr_urb);
16905 + usb_kill_urb(pegasus->tx_urb);
16906 + usb_kill_urb(pegasus->rx_urb);
16909 +static int alloc_urbs(pegasus_t *pegasus)
16911 + int res = -ENOMEM;
16913 + pegasus->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
16914 + if (!pegasus->rx_urb) {
16917 + pegasus->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
16918 + if (!pegasus->tx_urb) {
16919 + usb_free_urb(pegasus->rx_urb);
16922 + pegasus->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
16923 + if (!pegasus->intr_urb) {
16924 + usb_free_urb(pegasus->tx_urb);
16925 + usb_free_urb(pegasus->rx_urb);
16932 +static int pegasus_open(struct net_device *net)
16934 + pegasus_t *pegasus = netdev_priv(net);
16937 + if (pegasus->rx_skb == NULL)
16938 + pegasus->rx_skb = __netdev_alloc_skb_ip_align(pegasus->net,
16941 + if (!pegasus->rx_skb)
16944 + res = set_registers(pegasus, EthID, 6, net->dev_addr);
16946 + usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
16947 + usb_rcvbulkpipe(pegasus->usb, 1),
16948 + pegasus->rx_skb->data, PEGASUS_MTU + 8,
16949 + read_bulk_callback, pegasus);
16950 + if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
16951 + if (res == -ENODEV)
16952 + netif_device_detach(pegasus->net);
16953 + netif_dbg(pegasus, ifup, net, "failed rx_urb, %d\n", res);
16957 + usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
16958 + usb_rcvintpipe(pegasus->usb, 3),
16959 + pegasus->intr_buff, sizeof(pegasus->intr_buff),
16960 + intr_callback, pegasus, pegasus->intr_interval);
16961 + if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
16962 + if (res == -ENODEV)
16963 + netif_device_detach(pegasus->net);
16964 + netif_dbg(pegasus, ifup, net, "failed intr_urb, %d\n", res);
16965 + usb_kill_urb(pegasus->rx_urb);
16968 + res = enable_net_traffic(net, pegasus->usb);
16970 + netif_dbg(pegasus, ifup, net,
16971 + "can't enable_net_traffic() - %d\n", res);
16973 + usb_kill_urb(pegasus->rx_urb);
16974 + usb_kill_urb(pegasus->intr_urb);
16977 + set_carrier(net);
16978 + netif_start_queue(net);
16979 + netif_dbg(pegasus, ifup, net, "open\n");
16985 +static int pegasus_close(struct net_device *net)
16987 + pegasus_t *pegasus = netdev_priv(net);
16989 + netif_stop_queue(net);
16990 + if (!(pegasus->flags & PEGASUS_UNPLUG))
16991 + disable_net_traffic(pegasus);
16992 + tasklet_kill(&pegasus->rx_tl);
16993 + unlink_all_urbs(pegasus);
16998 +static void pegasus_get_drvinfo(struct net_device *dev,
16999 + struct ethtool_drvinfo *info)
17001 + pegasus_t *pegasus = netdev_priv(dev);
17003 + strlcpy(info->driver, driver_name, sizeof(info->driver));
17004 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
17005 + usb_make_path(pegasus->usb, info->bus_info, sizeof(info->bus_info));
17008 +/* also handles three patterns of some kind in hardware */
17009 +#define WOL_SUPPORTED (WAKE_MAGIC|WAKE_PHY)
17012 +pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
17014 + pegasus_t *pegasus = netdev_priv(dev);
17016 + wol->supported = WAKE_MAGIC | WAKE_PHY;
17017 + wol->wolopts = pegasus->wolopts;
17021 +pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
17023 + pegasus_t *pegasus = netdev_priv(dev);
17027 + if (wol->wolopts & ~WOL_SUPPORTED)
17030 + if (wol->wolopts & WAKE_MAGIC)
17032 + if (wol->wolopts & WAKE_PHY)
17034 + /* FIXME this 0x10 bit still needs to get set in the chip... */
17035 + if (wol->wolopts)
17036 + pegasus->eth_regs[0] |= 0x10;
17038 + pegasus->eth_regs[0] &= ~0x10;
17039 + pegasus->wolopts = wol->wolopts;
17041 + ret = set_register(pegasus, WakeupControl, reg78);
17043 + ret = device_set_wakeup_enable(&pegasus->usb->dev,
17048 +static inline void pegasus_reset_wol(struct net_device *dev)
17050 + struct ethtool_wolinfo wol;
17052 + memset(&wol, 0, sizeof wol);
17053 + (void) pegasus_set_wol(dev, &wol);
17057 +pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
17059 + pegasus_t *pegasus;
17061 + pegasus = netdev_priv(dev);
17062 + mii_ethtool_gset(&pegasus->mii, ecmd);
17067 +pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
17069 + pegasus_t *pegasus = netdev_priv(dev);
17070 + return mii_ethtool_sset(&pegasus->mii, ecmd);
17073 +static int pegasus_nway_reset(struct net_device *dev)
17075 + pegasus_t *pegasus = netdev_priv(dev);
17076 + return mii_nway_restart(&pegasus->mii);
17079 +static u32 pegasus_get_link(struct net_device *dev)
17081 + pegasus_t *pegasus = netdev_priv(dev);
17082 + return mii_link_ok(&pegasus->mii);
17085 +static u32 pegasus_get_msglevel(struct net_device *dev)
17087 + pegasus_t *pegasus = netdev_priv(dev);
17088 + return pegasus->msg_enable;
17091 +static void pegasus_set_msglevel(struct net_device *dev, u32 v)
17093 + pegasus_t *pegasus = netdev_priv(dev);
17094 + pegasus->msg_enable = v;
17097 +static const struct ethtool_ops ops = {
17098 + .get_drvinfo = pegasus_get_drvinfo,
17099 + .get_settings = pegasus_get_settings,
17100 + .set_settings = pegasus_set_settings,
17101 + .nway_reset = pegasus_nway_reset,
17102 + .get_link = pegasus_get_link,
17103 + .get_msglevel = pegasus_get_msglevel,
17104 + .set_msglevel = pegasus_set_msglevel,
17105 + .get_wol = pegasus_get_wol,
17106 + .set_wol = pegasus_set_wol,
17109 +static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
17111 + __u16 *data = (__u16 *) &rq->ifr_ifru;
17112 + pegasus_t *pegasus = netdev_priv(net);
17116 + case SIOCDEVPRIVATE:
17117 + data[0] = pegasus->phy;
17118 + case SIOCDEVPRIVATE + 1:
17119 + read_mii_word(pegasus, data[0], data[1] & 0x1f, &data[3]);
17122 + case SIOCDEVPRIVATE + 2:
17123 + if (!capable(CAP_NET_ADMIN))
17125 + write_mii_word(pegasus, pegasus->phy, data[1] & 0x1f, &data[2]);
17129 + res = -EOPNOTSUPP;
17134 +static void pegasus_set_multicast(struct net_device *net)
17136 + pegasus_t *pegasus = netdev_priv(net);
17138 + if (net->flags & IFF_PROMISC) {
17139 + pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
17140 + netif_info(pegasus, link, net, "Promiscuous mode enabled\n");
17141 + } else if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI)) {
17142 + pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
17143 + pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
17144 + netif_dbg(pegasus, link, net, "set allmulti\n");
17146 + pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
17147 + pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
17149 + update_eth_regs_async(pegasus);
17152 +static __u8 mii_phy_probe(pegasus_t *pegasus)
17157 + for (i = 0; i < 32; i++) {
17158 + read_mii_word(pegasus, i, MII_BMSR, &tmp);
17159 + if (tmp == 0 || tmp == 0xffff || (tmp & BMSR_MEDIA) == 0)
17168 +static inline void setup_pegasus_II(pegasus_t *pegasus)
17170 + __u8 data = 0xa5;
17172 + set_register(pegasus, Reg1d, 0);
17173 + set_register(pegasus, Reg7b, 1);
17175 + if ((pegasus->features & HAS_HOME_PNA) && mii_mode)
17176 + set_register(pegasus, Reg7b, 0);
17178 + set_register(pegasus, Reg7b, 2);
17180 + set_register(pegasus, 0x83, data);
17181 + get_registers(pegasus, 0x83, 1, &data);
17183 + if (data == 0xa5)
17184 + pegasus->chip = 0x8513;
17186 + pegasus->chip = 0;
17188 + set_register(pegasus, 0x80, 0xc0);
17189 + set_register(pegasus, 0x83, 0xff);
17190 + set_register(pegasus, 0x84, 0x01);
17192 + if (pegasus->features & HAS_HOME_PNA && mii_mode)
17193 + set_register(pegasus, Reg81, 6);
17195 + set_register(pegasus, Reg81, 2);
17199 +static int pegasus_count;
17200 +static struct workqueue_struct *pegasus_workqueue;
17201 +#define CARRIER_CHECK_DELAY (2 * HZ)
17203 +static void check_carrier(struct work_struct *work)
17205 + pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
17206 + set_carrier(pegasus->net);
17207 + if (!(pegasus->flags & PEGASUS_UNPLUG)) {
17208 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17209 + CARRIER_CHECK_DELAY);
17213 +static int pegasus_blacklisted(struct usb_device *udev)
17215 + struct usb_device_descriptor *udd = &udev->descriptor;
17217 + /* Special quirk to keep the driver from handling the Belkin Bluetooth
17218 + * dongle which happens to have the same ID.
17220 + if ((udd->idVendor == cpu_to_le16(VENDOR_BELKIN)) &&
17221 + (udd->idProduct == cpu_to_le16(0x0121)) &&
17222 + (udd->bDeviceClass == USB_CLASS_WIRELESS_CONTROLLER) &&
17223 + (udd->bDeviceProtocol == 1))
17229 +/* we rely on probe() and remove() being serialized so we
17230 + * don't need extra locking on pegasus_count.
17232 +static void pegasus_dec_workqueue(void)
17235 + if (pegasus_count == 0) {
17236 + destroy_workqueue(pegasus_workqueue);
17237 + pegasus_workqueue = NULL;
17241 +static int pegasus_probe(struct usb_interface *intf,
17242 + const struct usb_device_id *id)
17244 + struct usb_device *dev = interface_to_usbdev(intf);
17245 + struct net_device *net;
17246 + pegasus_t *pegasus;
17247 + int dev_index = id - pegasus_ids;
17248 + int res = -ENOMEM;
17250 + if (pegasus_blacklisted(dev))
17253 + if (pegasus_count == 0) {
17254 + pegasus_workqueue = create_singlethread_workqueue("pegasus");
17255 + if (!pegasus_workqueue)
17260 + net = alloc_etherdev(sizeof(struct pegasus));
17264 + pegasus = netdev_priv(net);
17265 + pegasus->dev_index = dev_index;
17267 + res = alloc_urbs(pegasus);
17269 + dev_err(&intf->dev, "can't allocate %s\n", "urbs");
17273 + tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
17275 + INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
17277 + pegasus->intf = intf;
17278 + pegasus->usb = dev;
17279 + pegasus->net = net;
17282 + net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
17283 + net->netdev_ops = &pegasus_netdev_ops;
17284 + net->ethtool_ops = &ops;
17285 + pegasus->mii.dev = net;
17286 + pegasus->mii.mdio_read = mdio_read;
17287 + pegasus->mii.mdio_write = mdio_write;
17288 + pegasus->mii.phy_id_mask = 0x1f;
17289 + pegasus->mii.reg_num_mask = 0x1f;
17290 + pegasus->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV
17291 + | NETIF_MSG_PROBE | NETIF_MSG_LINK);
17293 + pegasus->features = usb_dev_id[dev_index].private;
17294 + get_interrupt_interval(pegasus);
17295 + if (reset_mac(pegasus)) {
17296 + dev_err(&intf->dev, "can't reset MAC\n");
17300 + set_ethernet_addr(pegasus);
17301 + if (pegasus->features & PEGASUS_II) {
17302 + dev_info(&intf->dev, "setup Pegasus II specific registers\n");
17303 + setup_pegasus_II(pegasus);
17305 + pegasus->phy = mii_phy_probe(pegasus);
17306 + if (pegasus->phy == 0xff) {
17307 + dev_warn(&intf->dev, "can't locate MII phy, using default\n");
17308 + pegasus->phy = 1;
17310 + pegasus->mii.phy_id = pegasus->phy;
17311 + usb_set_intfdata(intf, pegasus);
17312 + SET_NETDEV_DEV(net, &intf->dev);
17313 + pegasus_reset_wol(net);
17314 + res = register_netdev(net);
17317 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17318 + CARRIER_CHECK_DELAY);
17319 + dev_info(&intf->dev, "%s, %s, %pM\n", net->name,
17320 + usb_dev_id[dev_index].name, net->dev_addr);
17324 + usb_set_intfdata(intf, NULL);
17326 + free_all_urbs(pegasus);
17328 + free_netdev(net);
17330 + pegasus_dec_workqueue();
17334 +static void pegasus_disconnect(struct usb_interface *intf)
17336 + struct pegasus *pegasus = usb_get_intfdata(intf);
17338 + usb_set_intfdata(intf, NULL);
17340 + dev_dbg(&intf->dev, "unregistering non-bound device?\n");
17344 + pegasus->flags |= PEGASUS_UNPLUG;
17345 + cancel_delayed_work(&pegasus->carrier_check);
17346 + unregister_netdev(pegasus->net);
17347 + unlink_all_urbs(pegasus);
17348 + free_all_urbs(pegasus);
17349 + if (pegasus->rx_skb != NULL) {
17350 + dev_kfree_skb(pegasus->rx_skb);
17351 + pegasus->rx_skb = NULL;
17353 + free_netdev(pegasus->net);
17354 + pegasus_dec_workqueue();
17357 +static int pegasus_suspend(struct usb_interface *intf, pm_message_t message)
17359 + struct pegasus *pegasus = usb_get_intfdata(intf);
17361 + netif_device_detach(pegasus->net);
17362 + cancel_delayed_work(&pegasus->carrier_check);
17363 + if (netif_running(pegasus->net)) {
17364 + usb_kill_urb(pegasus->rx_urb);
17365 + usb_kill_urb(pegasus->intr_urb);
17370 +static int pegasus_resume(struct usb_interface *intf)
17372 + struct pegasus *pegasus = usb_get_intfdata(intf);
17374 + netif_device_attach(pegasus->net);
17375 + if (netif_running(pegasus->net)) {
17376 + pegasus->rx_urb->status = 0;
17377 + pegasus->rx_urb->actual_length = 0;
17378 + read_bulk_callback(pegasus->rx_urb);
17380 + pegasus->intr_urb->status = 0;
17381 + pegasus->intr_urb->actual_length = 0;
17382 + intr_callback(pegasus->intr_urb);
17384 + queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
17385 + CARRIER_CHECK_DELAY);
17389 +static const struct net_device_ops pegasus_netdev_ops = {
17390 + .ndo_open = pegasus_open,
17391 + .ndo_stop = pegasus_close,
17392 + .ndo_do_ioctl = pegasus_ioctl,
17393 + .ndo_start_xmit = pegasus_start_xmit,
17394 + .ndo_set_rx_mode = pegasus_set_multicast,
17395 + .ndo_get_stats = pegasus_netdev_stats,
17396 + .ndo_tx_timeout = pegasus_tx_timeout,
17397 + .ndo_change_mtu = eth_change_mtu,
17398 + .ndo_set_mac_address = eth_mac_addr,
17399 + .ndo_validate_addr = eth_validate_addr,
17402 +static struct usb_driver pegasus_driver = {
17403 + .name = driver_name,
17404 + .probe = pegasus_probe,
17405 + .disconnect = pegasus_disconnect,
17406 + .id_table = pegasus_ids,
17407 + .suspend = pegasus_suspend,
17408 + .resume = pegasus_resume,
17409 + .disable_hub_initiated_lpm = 1,
17412 +static void __init parse_id(char *id)
17414 + unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0;
17415 + char *token, *name = NULL;
17417 + if ((token = strsep(&id, ":")) != NULL)
17419 + /* name now points to a null terminated string*/
17420 + if ((token = strsep(&id, ":")) != NULL)
17421 + vendor_id = simple_strtoul(token, NULL, 16);
17422 + if ((token = strsep(&id, ":")) != NULL)
17423 + device_id = simple_strtoul(token, NULL, 16);
17424 + flags = simple_strtoul(id, NULL, 16);
17425 + pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
17426 + driver_name, name, vendor_id, device_id, flags);
17428 + if (vendor_id > 0x10000 || vendor_id == 0)
17430 + if (device_id > 0x10000 || device_id == 0)
17433 + for (i = 0; usb_dev_id[i].name; i++);
17434 + usb_dev_id[i].name = name;
17435 + usb_dev_id[i].vendor = vendor_id;
17436 + usb_dev_id[i].device = device_id;
17437 + usb_dev_id[i].private = flags;
17438 + pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
17439 + pegasus_ids[i].idVendor = vendor_id;
17440 + pegasus_ids[i].idProduct = device_id;
17443 +static int __init pegasus_init(void)
17445 + pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
17448 + return usb_register(&pegasus_driver);
17451 +static void __exit pegasus_exit(void)
17453 + usb_deregister(&pegasus_driver);
17456 +module_init(pegasus_init);
17457 +module_exit(pegasus_exit);
17458 diff -Naur backports-4.2.6-1.org/drivers/net/usb/pegasus.h backports-4.2.6-1/drivers/net/usb/pegasus.h
17459 --- backports-4.2.6-1.org/drivers/net/usb/pegasus.h 1970-01-01 01:00:00.000000000 +0100
17460 +++ backports-4.2.6-1/drivers/net/usb/pegasus.h 2016-06-28 14:35:17.998640551 +0200
17463 + * Copyright (c) 1999-2013 Petko Manolov (petkan@nucleusys.com)
17465 + * This program is free software; you can redistribute it and/or modify
17466 + * it under the terms of the GNU General Public License version 2 as published
17467 + * by the Free Software Foundation.
17471 +#ifndef PEGASUS_DEV
17473 +#define PEGASUS_II 0x80000000
17474 +#define HAS_HOME_PNA 0x40000000
17476 +#define PEGASUS_MTU 1536
17478 +#define EPROM_WRITE 0x01
17479 +#define EPROM_READ 0x02
17480 +#define EPROM_DONE 0x04
17481 +#define EPROM_WR_ENABLE 0x10
17482 +#define EPROM_LOAD 0x20
17484 +#define PHY_DONE 0x80
17485 +#define PHY_READ 0x40
17486 +#define PHY_WRITE 0x20
17487 +#define DEFAULT_GPIO_RESET 0x24
17488 +#define DEFAULT_GPIO_SET 0x26
17490 +#define PEGASUS_PRESENT 0x00000001
17491 +#define PEGASUS_TX_BUSY 0x00000004
17492 +#define PEGASUS_RX_BUSY 0x00000008
17493 +#define CTRL_URB_RUNNING 0x00000010
17494 +#define CTRL_URB_SLEEP 0x00000020
17495 +#define PEGASUS_UNPLUG 0x00000040
17496 +#define PEGASUS_RX_URB_FAIL 0x00000080
17498 +#define RX_MULTICAST 2
17499 +#define RX_PROMISCUOUS 4
17501 +#define REG_TIMEOUT (HZ)
17502 +#define PEGASUS_TX_TIMEOUT (HZ*10)
17504 +#define TX_UNDERRUN 0x80
17505 +#define EXCESSIVE_COL 0x40
17506 +#define LATE_COL 0x20
17507 +#define NO_CARRIER 0x10
17508 +#define LOSS_CARRIER 0x08
17509 +#define JABBER_TIMEOUT 0x04
17511 +#define LINK_STATUS 0x01
17513 +#define PEGASUS_REQT_READ 0xc0
17514 +#define PEGASUS_REQT_WRITE 0x40
17515 +#define PEGASUS_REQ_GET_REGS 0xf0
17516 +#define PEGASUS_REQ_SET_REGS 0xf1
17517 +#define PEGASUS_REQ_SET_REG PEGASUS_REQ_SET_REGS
17519 +enum pegasus_registers {
17525 + EpromOffset = 0x20,
17526 + EpromData = 0x21, /* 0x21 low, 0x22 high byte */
17527 + EpromCtrl = 0x23,
17529 + PhyData = 0x26, /* 0x26 low, 0x27 high byte */
17532 + EthTxStat0 = 0x2b,
17533 + EthTxStat1 = 0x2c,
17534 + EthRxStat = 0x2d,
17535 + WakeupControl = 0x78,
17543 +typedef struct pegasus {
17544 + struct usb_device *usb;
17545 + struct usb_interface *intf;
17546 + struct net_device *net;
17547 + struct net_device_stats stats;
17548 + struct mii_if_info mii;
17550 + unsigned features;
17554 + int intr_interval;
17555 + struct tasklet_struct rx_tl;
17556 + struct delayed_work carrier_check;
17557 + struct urb *rx_urb, *tx_urb, *intr_urb;
17558 + struct sk_buff *rx_skb;
17560 + unsigned char intr_buff[8];
17561 + __u8 tx_buff[PEGASUS_MTU];
17562 + __u8 eth_regs[4];
17568 +struct usb_eth_dev {
17572 + __u32 private; /* LSB is gpio reset value */
17575 +#define VENDOR_3COM 0x0506
17576 +#define VENDOR_ABOCOM 0x07b8
17577 +#define VENDOR_ACCTON 0x083a
17578 +#define VENDOR_ADMTEK 0x07a6
17579 +#define VENDOR_AEILAB 0x3334
17580 +#define VENDOR_ALLIEDTEL 0x07c9
17581 +#define VENDOR_ATEN 0x0557
17582 +#define VENDOR_BELKIN 0x050d
17583 +#define VENDOR_BILLIONTON 0x08dd
17584 +#define VENDOR_COMPAQ 0x049f
17585 +#define VENDOR_COREGA 0x07aa
17586 +#define VENDOR_DLINK 0x2001
17587 +#define VENDOR_ELCON 0x0db7
17588 +#define VENDOR_ELECOM 0x056e
17589 +#define VENDOR_ELSA 0x05cc
17590 +#define VENDOR_GIGABYTE 0x1044
17591 +#define VENDOR_HAWKING 0x0e66
17592 +#define VENDOR_HP 0x03f0
17593 +#define VENDOR_IODATA 0x04bb
17594 +#define VENDOR_KINGSTON 0x0951
17595 +#define VENDOR_LANEED 0x056e
17596 +#define VENDOR_LINKSYS 0x066b
17597 +#define VENDOR_LINKSYS2 0x077b
17598 +#define VENDOR_MELCO 0x0411
17599 +#define VENDOR_MICROSOFT 0x045e
17600 +#define VENDOR_MOBILITY 0x1342
17601 +#define VENDOR_NETGEAR 0x0846
17602 +#define VENDOR_OCT 0x0b39
17603 +#define VENDOR_SMARTBRIDGES 0x08d1
17604 +#define VENDOR_SMC 0x0707
17605 +#define VENDOR_SOHOWARE 0x15e8
17606 +#define VENDOR_SIEMENS 0x067c
17609 +#else /* PEGASUS_DEV */
17611 +PEGASUS_DEV("3Com USB Ethernet 3C460B", VENDOR_3COM, 0x4601,
17612 + DEFAULT_GPIO_RESET | PEGASUS_II)
17613 +PEGASUS_DEV("ATEN USB Ethernet UC-110T", VENDOR_ATEN, 0x2007,
17614 + DEFAULT_GPIO_RESET | PEGASUS_II)
17615 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x110c,
17616 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17617 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4104,
17618 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17619 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4004,
17620 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17621 +PEGASUS_DEV("USB HPNA/Ethernet", VENDOR_ABOCOM, 0x4007,
17622 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17623 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4102,
17624 + DEFAULT_GPIO_RESET | PEGASUS_II)
17625 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x4002,
17626 + DEFAULT_GPIO_RESET)
17627 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400b,
17628 + DEFAULT_GPIO_RESET | PEGASUS_II)
17629 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x400c,
17630 + DEFAULT_GPIO_RESET | PEGASUS_II)
17631 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0xabc1,
17632 + DEFAULT_GPIO_RESET)
17633 +PEGASUS_DEV("USB 10/100 Fast Ethernet", VENDOR_ABOCOM, 0x200c,
17634 + DEFAULT_GPIO_RESET | PEGASUS_II)
17635 +PEGASUS_DEV("Accton USB 10/100 Ethernet Adapter", VENDOR_ACCTON, 0x1046,
17636 + DEFAULT_GPIO_RESET)
17637 +PEGASUS_DEV("SpeedStream USB 10/100 Ethernet", VENDOR_ACCTON, 0x5046,
17638 + DEFAULT_GPIO_RESET | PEGASUS_II)
17639 +PEGASUS_DEV("Philips USB 10/100 Ethernet", VENDOR_ACCTON, 0xb004,
17640 + DEFAULT_GPIO_RESET | PEGASUS_II)
17641 +PEGASUS_DEV("ADMtek ADM8511 \"Pegasus II\" USB Ethernet",
17642 + VENDOR_ADMTEK, 0x8511,
17643 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17644 +PEGASUS_DEV("ADMtek ADM8513 \"Pegasus II\" USB Ethernet",
17645 + VENDOR_ADMTEK, 0x8513,
17646 + DEFAULT_GPIO_RESET | PEGASUS_II)
17647 +PEGASUS_DEV("ADMtek ADM8515 \"Pegasus II\" USB-2.0 Ethernet",
17648 + VENDOR_ADMTEK, 0x8515,
17649 + DEFAULT_GPIO_RESET | PEGASUS_II)
17650 +PEGASUS_DEV("ADMtek AN986 \"Pegasus\" USB Ethernet (evaluation board)",
17651 + VENDOR_ADMTEK, 0x0986,
17652 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17653 +PEGASUS_DEV("AN986A USB MAC", VENDOR_ADMTEK, 1986,
17654 + DEFAULT_GPIO_RESET | PEGASUS_II)
17655 +PEGASUS_DEV("AEI USB Fast Ethernet Adapter", VENDOR_AEILAB, 0x1701,
17656 + DEFAULT_GPIO_RESET | PEGASUS_II)
17657 +PEGASUS_DEV("Allied Telesyn Int. AT-USB100", VENDOR_ALLIEDTEL, 0xb100,
17658 + DEFAULT_GPIO_RESET | PEGASUS_II)
17660 + * Distinguish between this Belkin adaptor and the Belkin bluetooth adaptors
17661 + * with the same product IDs by checking the device class too.
17663 +PEGASUS_DEV_CLASS("Belkin F5D5050 USB Ethernet", VENDOR_BELKIN, 0x0121, 0x00,
17664 + DEFAULT_GPIO_RESET | PEGASUS_II)
17665 +PEGASUS_DEV("Belkin F5U122 10/100 USB Ethernet", VENDOR_BELKIN, 0x0122,
17666 + DEFAULT_GPIO_RESET | PEGASUS_II)
17667 +PEGASUS_DEV("Billionton USB-100", VENDOR_BILLIONTON, 0x0986,
17668 + DEFAULT_GPIO_RESET)
17669 +PEGASUS_DEV("Billionton USBLP-100", VENDOR_BILLIONTON, 0x0987,
17670 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17671 +PEGASUS_DEV("iPAQ Networking 10/100 USB", VENDOR_COMPAQ, 0x8511,
17672 + DEFAULT_GPIO_RESET | PEGASUS_II)
17673 +PEGASUS_DEV("Billionton USBEL-100", VENDOR_BILLIONTON, 0x0988,
17674 + DEFAULT_GPIO_RESET)
17675 +PEGASUS_DEV("Billionton USBE-100", VENDOR_BILLIONTON, 0x8511,
17676 + DEFAULT_GPIO_RESET | PEGASUS_II)
17677 +PEGASUS_DEV("Corega FEther USB-TX", VENDOR_COREGA, 0x0004,
17678 + DEFAULT_GPIO_RESET)
17679 +PEGASUS_DEV("Corega FEther USB-TXS", VENDOR_COREGA, 0x000d,
17680 + DEFAULT_GPIO_RESET | PEGASUS_II)
17681 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4001,
17682 + DEFAULT_GPIO_RESET)
17683 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4002,
17684 + DEFAULT_GPIO_RESET)
17685 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x4102,
17686 + DEFAULT_GPIO_RESET | PEGASUS_II)
17687 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x400b,
17688 + DEFAULT_GPIO_RESET | PEGASUS_II)
17689 +PEGASUS_DEV("D-Link DSB-650TX", VENDOR_DLINK, 0x200c,
17690 + DEFAULT_GPIO_RESET | PEGASUS_II)
17691 +PEGASUS_DEV("D-Link DSB-650TX(PNA)", VENDOR_DLINK, 0x4003,
17692 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17693 +PEGASUS_DEV("D-Link DSB-650", VENDOR_DLINK, 0xabc1,
17694 + DEFAULT_GPIO_RESET)
17695 +PEGASUS_DEV("GOLDPFEIL USB Adapter", VENDOR_ELCON, 0x0002,
17696 + DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA)
17697 +PEGASUS_DEV("ELECOM USB Ethernet LD-USB20", VENDOR_ELECOM, 0x4010,
17698 + DEFAULT_GPIO_RESET | PEGASUS_II)
17699 +PEGASUS_DEV("EasiDock Ethernet", VENDOR_MOBILITY, 0x0304,
17700 + DEFAULT_GPIO_RESET)
17701 +PEGASUS_DEV("Elsa Micolink USB2Ethernet", VENDOR_ELSA, 0x3000,
17702 + DEFAULT_GPIO_RESET)
17703 +PEGASUS_DEV("GIGABYTE GN-BR402W Wireless Router", VENDOR_GIGABYTE, 0x8002,
17704 + DEFAULT_GPIO_RESET)
17705 +PEGASUS_DEV("Hawking UF100 10/100 Ethernet", VENDOR_HAWKING, 0x400c,
17706 + DEFAULT_GPIO_RESET | PEGASUS_II)
17707 +PEGASUS_DEV("HP hn210c Ethernet USB", VENDOR_HP, 0x811c,
17708 + DEFAULT_GPIO_RESET | PEGASUS_II)
17709 +PEGASUS_DEV("IO DATA USB ET/TX", VENDOR_IODATA, 0x0904,
17710 + DEFAULT_GPIO_RESET)
17711 +PEGASUS_DEV("IO DATA USB ET/TX-S", VENDOR_IODATA, 0x0913,
17712 + DEFAULT_GPIO_RESET | PEGASUS_II)
17713 +PEGASUS_DEV("IO DATA USB ETX-US2", VENDOR_IODATA, 0x093a,
17714 + DEFAULT_GPIO_RESET | PEGASUS_II)
17715 +PEGASUS_DEV("Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
17716 + DEFAULT_GPIO_RESET)
17717 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x4002,
17718 + DEFAULT_GPIO_RESET)
17719 +PEGASUS_DEV("LANEED USB Ethernet LD-USBL/TX", VENDOR_LANEED, 0x4005,
17720 + DEFAULT_GPIO_RESET | PEGASUS_II)
17721 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x400b,
17722 + DEFAULT_GPIO_RESET | PEGASUS_II)
17723 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/T", VENDOR_LANEED, 0xabc1,
17724 + DEFAULT_GPIO_RESET)
17725 +PEGASUS_DEV("LANEED USB Ethernet LD-USB/TX", VENDOR_LANEED, 0x200c,
17726 + DEFAULT_GPIO_RESET | PEGASUS_II)
17727 +PEGASUS_DEV("Linksys USB10TX", VENDOR_LINKSYS, 0x2202,
17728 + DEFAULT_GPIO_RESET)
17729 +PEGASUS_DEV("Linksys USB100TX", VENDOR_LINKSYS, 0x2203,
17730 + DEFAULT_GPIO_RESET)
17731 +PEGASUS_DEV("Linksys USB100TX", VENDOR_LINKSYS, 0x2204,
17732 + DEFAULT_GPIO_RESET | HAS_HOME_PNA)
17733 +PEGASUS_DEV("Linksys USB10T Ethernet Adapter", VENDOR_LINKSYS, 0x2206,
17734 + DEFAULT_GPIO_RESET | PEGASUS_II)
17735 +PEGASUS_DEV("Linksys USBVPN1", VENDOR_LINKSYS2, 0x08b4,
17736 + DEFAULT_GPIO_RESET)
17737 +PEGASUS_DEV("Linksys USB USB100TX", VENDOR_LINKSYS, 0x400b,
17738 + DEFAULT_GPIO_RESET | PEGASUS_II)
17739 +PEGASUS_DEV("Linksys USB10TX", VENDOR_LINKSYS, 0x200c,
17740 + DEFAULT_GPIO_RESET | PEGASUS_II)
17741 +PEGASUS_DEV("MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0001,
17742 + DEFAULT_GPIO_RESET)
17743 +PEGASUS_DEV("MELCO/BUFFALO LUA-TX", VENDOR_MELCO, 0x0005,
17744 + DEFAULT_GPIO_RESET)
17745 +PEGASUS_DEV("MELCO/BUFFALO LUA2-TX", VENDOR_MELCO, 0x0009,
17746 + DEFAULT_GPIO_RESET | PEGASUS_II)
17747 +PEGASUS_DEV("Microsoft MN-110", VENDOR_MICROSOFT, 0x007a,
17748 + DEFAULT_GPIO_RESET | PEGASUS_II)
17749 +PEGASUS_DEV("NETGEAR FA101", VENDOR_NETGEAR, 0x1020,
17750 + DEFAULT_GPIO_RESET | PEGASUS_II)
17751 +PEGASUS_DEV("OCT Inc.", VENDOR_OCT, 0x0109,
17752 + DEFAULT_GPIO_RESET | PEGASUS_II)
17753 +PEGASUS_DEV("OCT USB TO Ethernet", VENDOR_OCT, 0x0901,
17754 + DEFAULT_GPIO_RESET | PEGASUS_II)
17755 +PEGASUS_DEV("smartNIC 2 PnP Adapter", VENDOR_SMARTBRIDGES, 0x0003,
17756 + DEFAULT_GPIO_RESET | PEGASUS_II)
17757 +PEGASUS_DEV("SMC 202 USB Ethernet", VENDOR_SMC, 0x0200,
17758 + DEFAULT_GPIO_RESET)
17759 +PEGASUS_DEV("SMC 2206 USB Ethernet", VENDOR_SMC, 0x0201,
17760 + DEFAULT_GPIO_RESET | PEGASUS_II)
17761 +PEGASUS_DEV("SOHOware NUB100 Ethernet", VENDOR_SOHOWARE, 0x9100,
17762 + DEFAULT_GPIO_RESET)
17763 +PEGASUS_DEV("SOHOware NUB110 Ethernet", VENDOR_SOHOWARE, 0x9110,
17764 + DEFAULT_GPIO_RESET | PEGASUS_II)
17765 +PEGASUS_DEV("SpeedStream USB 10/100 Ethernet", VENDOR_SIEMENS, 0x1001,
17766 + DEFAULT_GPIO_RESET | PEGASUS_II)
17769 +#endif /* PEGASUS_DEV */
17770 diff -Naur backports-4.2.6-1.org/drivers/net/usb/plusb.c backports-4.2.6-1/drivers/net/usb/plusb.c
17771 --- backports-4.2.6-1.org/drivers/net/usb/plusb.c 1970-01-01 01:00:00.000000000 +0100
17772 +++ backports-4.2.6-1/drivers/net/usb/plusb.c 2016-06-28 14:35:17.998640551 +0200
17775 + * PL-2301/2302 USB host-to-host link cables
17776 + * Copyright (C) 2000-2005 by David Brownell
17778 + * This program is free software; you can redistribute it and/or modify
17779 + * it under the terms of the GNU General Public License as published by
17780 + * the Free Software Foundation; either version 2 of the License, or
17781 + * (at your option) any later version.
17783 + * This program is distributed in the hope that it will be useful,
17784 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17785 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17786 + * GNU General Public License for more details.
17788 + * You should have received a copy of the GNU General Public License
17789 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
17792 +// #define DEBUG // error path messages, extra info
17793 +// #define VERBOSE // more; success messages
17795 +#include <linux/module.h>
17796 +#include <linux/netdevice.h>
17797 +#include <linux/etherdevice.h>
17798 +#include <linux/ethtool.h>
17799 +#include <linux/workqueue.h>
17800 +#include <linux/mii.h>
17801 +#include <linux/usb.h>
17802 +#include <linux/usb/usbnet.h>
17806 + * Prolific PL-2301/PL-2302 driver ... http://www.prolific.com.tw/
17808 + * The protocol and handshaking used here should be bug-compatible
17809 + * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
17811 + * HEADS UP: this handshaking isn't all that robust. This driver
17812 + * gets confused easily if you unplug one end of the cable then
17813 + * try to connect it again; you'll need to restart both ends. The
17814 + * "naplink" software (used by some PlayStation/2 deveopers) does
17815 + * the handshaking much better! Also, sometimes this hardware
17816 + * seems to get wedged under load. Prolific docs are weak, and
17817 + * don't identify differences between PL2301 and PL2302, much less
17818 + * anything to explain the different PL2302 versions observed.
17820 + * NOTE: pl2501 has several modes, including pl2301 and pl2302
17821 + * compatibility. Some docs suggest the difference between 2301
17822 + * and 2302 is only to make MS-Windows use a different driver...
17824 + * pl25a1 glue based on patch from Tony Gibbs. Prolific "docs" on
17825 + * this chip are as usual incomplete about what control messages
17830 + * Bits 0-4 can be used for software handshaking; they're set from
17831 + * one end, cleared from the other, "read" with the interrupt byte.
17833 +#define PL_S_EN (1<<7) /* (feature only) suspend enable */
17834 +/* reserved bit -- rx ready (6) ? */
17835 +#define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
17836 +#define PL_RESET_OUT (1<<4) /* reset output pipe */
17837 +#define PL_RESET_IN (1<<3) /* reset input pipe */
17838 +#define PL_TX_C (1<<2) /* transmission complete */
17839 +#define PL_TX_REQ (1<<1) /* transmission received */
17840 +#define PL_PEER_E (1<<0) /* peer exists */
17843 +pl_vendor_req(struct usbnet *dev, u8 req, u8 val, u8 index)
17845 + return usbnet_read_cmd(dev, req,
17846 + USB_DIR_IN | USB_TYPE_VENDOR |
17847 + USB_RECIP_DEVICE,
17848 + val, index, NULL, 0);
17852 +pl_clear_QuickLink_features(struct usbnet *dev, int val)
17854 + return pl_vendor_req(dev, 1, (u8) val, 0);
17858 +pl_set_QuickLink_features(struct usbnet *dev, int val)
17860 + return pl_vendor_req(dev, 3, (u8) val, 0);
17863 +static int pl_reset(struct usbnet *dev)
17867 + /* some units seem to need this reset, others reject it utterly.
17868 + * FIXME be more like "naplink" or windows drivers.
17870 + status = pl_set_QuickLink_features(dev,
17871 + PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
17872 + if (status != 0 && netif_msg_probe(dev))
17873 + netif_dbg(dev, link, dev->net, "pl_reset --> %d\n", status);
17877 +static const struct driver_info prolific_info = {
17878 + .description = "Prolific PL-2301/PL-2302/PL-25A1",
17879 + .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT,
17880 + /* some PL-2302 versions seem to fail usb_set_interface() */
17881 + .reset = pl_reset,
17885 +/*-------------------------------------------------------------------------*/
17888 + * Proilific's name won't normally be on the cables, and
17889 + * may not be on the device.
17892 +static const struct usb_device_id products [] = {
17894 +/* full speed cables */
17896 + USB_DEVICE(0x067b, 0x0000), // PL-2301
17897 + .driver_info = (unsigned long) &prolific_info,
17899 + USB_DEVICE(0x067b, 0x0001), // PL-2302
17900 + .driver_info = (unsigned long) &prolific_info,
17903 +/* high speed cables */
17905 + USB_DEVICE(0x067b, 0x25a1), /* PL-25A1, no eeprom */
17906 + .driver_info = (unsigned long) &prolific_info,
17908 + USB_DEVICE(0x050d, 0x258a), /* Belkin F5U258/F5U279 (PL-25A1) */
17909 + .driver_info = (unsigned long) &prolific_info,
17911 + USB_DEVICE(0x3923, 0x7825), /* National Instruments USB
17912 + * Host-to-Host Cable
17914 + .driver_info = (unsigned long) &prolific_info,
17919 +MODULE_DEVICE_TABLE(usb, products);
17921 +static struct usb_driver plusb_driver = {
17923 + .id_table = products,
17924 + .probe = usbnet_probe,
17925 + .disconnect = usbnet_disconnect,
17926 + .suspend = usbnet_suspend,
17927 + .resume = usbnet_resume,
17928 + .disable_hub_initiated_lpm = 1,
17931 +module_usb_driver(plusb_driver);
17933 +MODULE_AUTHOR("David Brownell");
17934 +MODULE_DESCRIPTION("Prolific PL-2301/2302/25A1 USB Host to Host Link Driver");
17935 +MODULE_LICENSE("GPL");
17936 diff -Naur backports-4.2.6-1.org/drivers/net/usb/r8152.c backports-4.2.6-1/drivers/net/usb/r8152.c
17937 --- backports-4.2.6-1.org/drivers/net/usb/r8152.c 1970-01-01 01:00:00.000000000 +0100
17938 +++ backports-4.2.6-1/drivers/net/usb/r8152.c 2016-06-28 14:45:32.005250978 +0200
17941 + * Copyright (c) 2014 Realtek Semiconductor Corp. All rights reserved.
17943 + * This program is free software; you can redistribute it and/or
17944 + * modify it under the terms of the GNU General Public License
17945 + * version 2 as published by the Free Software Foundation.
17949 +#include <linux/signal.h>
17950 +#include <linux/slab.h>
17951 +#include <linux/module.h>
17952 +#include <linux/netdevice.h>
17953 +#include <linux/etherdevice.h>
17954 +#include <linux/mii.h>
17955 +#include <linux/ethtool.h>
17956 +#include <linux/usb.h>
17957 +#include <linux/crc32.h>
17958 +#include <linux/if_vlan.h>
17959 +#include <linux/uaccess.h>
17960 +#include <linux/list.h>
17961 +#include <linux/ip.h>
17962 +#include <linux/ipv6.h>
17964 +/* Version Information */
17965 +#define DRIVER_VERSION "v1.04.0 (2014/01/15)"
17966 +#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
17967 +#define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
17968 +#define MODULENAME "r8152"
17970 +#define R8152_PHY_ID 32
17972 +#define PLA_IDR 0xc000
17973 +#define PLA_RCR 0xc010
17974 +#define PLA_RMS 0xc016
17975 +#define PLA_RXFIFO_CTRL0 0xc0a0
17976 +#define PLA_RXFIFO_CTRL1 0xc0a4
17977 +#define PLA_RXFIFO_CTRL2 0xc0a8
17978 +#define PLA_FMC 0xc0b4
17979 +#define PLA_CFG_WOL 0xc0b6
17980 +#define PLA_TEREDO_CFG 0xc0bc
17981 +#define PLA_MAR 0xcd00
17982 +#define PLA_BACKUP 0xd000
17983 +#define PAL_BDC_CR 0xd1a0
17984 +#define PLA_TEREDO_TIMER 0xd2cc
17985 +#define PLA_REALWOW_TIMER 0xd2e8
17986 +#define PLA_LEDSEL 0xdd90
17987 +#define PLA_LED_FEATURE 0xdd92
17988 +#define PLA_PHYAR 0xde00
17989 +#define PLA_BOOT_CTRL 0xe004
17990 +#define PLA_GPHY_INTR_IMR 0xe022
17991 +#define PLA_EEE_CR 0xe040
17992 +#define PLA_EEEP_CR 0xe080
17993 +#define PLA_MAC_PWR_CTRL 0xe0c0
17994 +#define PLA_MAC_PWR_CTRL2 0xe0ca
17995 +#define PLA_MAC_PWR_CTRL3 0xe0cc
17996 +#define PLA_MAC_PWR_CTRL4 0xe0ce
17997 +#define PLA_WDT6_CTRL 0xe428
17998 +#define PLA_TCR0 0xe610
17999 +#define PLA_TCR1 0xe612
18000 +#define PLA_TXFIFO_CTRL 0xe618
18001 +#define PLA_RSTTELLY 0xe800
18002 +#define PLA_CR 0xe813
18003 +#define PLA_CRWECR 0xe81c
18004 +#define PLA_CONFIG5 0xe822
18005 +#define PLA_PHY_PWR 0xe84c
18006 +#define PLA_OOB_CTRL 0xe84f
18007 +#define PLA_CPCR 0xe854
18008 +#define PLA_MISC_0 0xe858
18009 +#define PLA_MISC_1 0xe85a
18010 +#define PLA_OCP_GPHY_BASE 0xe86c
18011 +#define PLA_TELLYCNT 0xe890
18012 +#define PLA_SFF_STS_7 0xe8de
18013 +#define PLA_PHYSTATUS 0xe908
18014 +#define PLA_BP_BA 0xfc26
18015 +#define PLA_BP_0 0xfc28
18016 +#define PLA_BP_1 0xfc2a
18017 +#define PLA_BP_2 0xfc2c
18018 +#define PLA_BP_3 0xfc2e
18019 +#define PLA_BP_4 0xfc30
18020 +#define PLA_BP_5 0xfc32
18021 +#define PLA_BP_6 0xfc34
18022 +#define PLA_BP_7 0xfc36
18023 +#define PLA_BP_EN 0xfc38
18025 +#define USB_U2P3_CTRL 0xb460
18026 +#define USB_DEV_STAT 0xb808
18027 +#define USB_USB_CTRL 0xd406
18028 +#define USB_PHY_CTRL 0xd408
18029 +#define USB_TX_AGG 0xd40a
18030 +#define USB_RX_BUF_TH 0xd40c
18031 +#define USB_USB_TIMER 0xd428
18032 +#define USB_RX_EARLY_AGG 0xd42c
18033 +#define USB_PM_CTRL_STATUS 0xd432
18034 +#define USB_TX_DMA 0xd434
18035 +#define USB_TOLERANCE 0xd490
18036 +#define USB_LPM_CTRL 0xd41a
18037 +#define USB_UPS_CTRL 0xd800
18038 +#define USB_MISC_0 0xd81a
18039 +#define USB_POWER_CUT 0xd80a
18040 +#define USB_AFE_CTRL2 0xd824
18041 +#define USB_WDT11_CTRL 0xe43c
18042 +#define USB_BP_BA 0xfc26
18043 +#define USB_BP_0 0xfc28
18044 +#define USB_BP_1 0xfc2a
18045 +#define USB_BP_2 0xfc2c
18046 +#define USB_BP_3 0xfc2e
18047 +#define USB_BP_4 0xfc30
18048 +#define USB_BP_5 0xfc32
18049 +#define USB_BP_6 0xfc34
18050 +#define USB_BP_7 0xfc36
18051 +#define USB_BP_EN 0xfc38
18053 +/* OCP Registers */
18054 +#define OCP_ALDPS_CONFIG 0x2010
18055 +#define OCP_EEE_CONFIG1 0x2080
18056 +#define OCP_EEE_CONFIG2 0x2092
18057 +#define OCP_EEE_CONFIG3 0x2094
18058 +#define OCP_BASE_MII 0xa400
18059 +#define OCP_EEE_AR 0xa41a
18060 +#define OCP_EEE_DATA 0xa41c
18061 +#define OCP_PHY_STATUS 0xa420
18062 +#define OCP_POWER_CFG 0xa430
18063 +#define OCP_EEE_CFG 0xa432
18064 +#define OCP_SRAM_ADDR 0xa436
18065 +#define OCP_SRAM_DATA 0xa438
18066 +#define OCP_DOWN_SPEED 0xa442
18067 +#define OCP_EEE_CFG2 0xa5d0
18068 +#define OCP_ADC_CFG 0xbc06
18070 +/* SRAM Register */
18071 +#define SRAM_LPF_CFG 0x8012
18072 +#define SRAM_10M_AMP1 0x8080
18073 +#define SRAM_10M_AMP2 0x8082
18074 +#define SRAM_IMPEDANCE 0x8084
18077 +#define RCR_AAP 0x00000001
18078 +#define RCR_APM 0x00000002
18079 +#define RCR_AM 0x00000004
18080 +#define RCR_AB 0x00000008
18081 +#define RCR_ACPT_ALL (RCR_AAP | RCR_APM | RCR_AM | RCR_AB)
18083 +/* PLA_RXFIFO_CTRL0 */
18084 +#define RXFIFO_THR1_NORMAL 0x00080002
18085 +#define RXFIFO_THR1_OOB 0x01800003
18087 +/* PLA_RXFIFO_CTRL1 */
18088 +#define RXFIFO_THR2_FULL 0x00000060
18089 +#define RXFIFO_THR2_HIGH 0x00000038
18090 +#define RXFIFO_THR2_OOB 0x0000004a
18091 +#define RXFIFO_THR2_NORMAL 0x00a0
18093 +/* PLA_RXFIFO_CTRL2 */
18094 +#define RXFIFO_THR3_FULL 0x00000078
18095 +#define RXFIFO_THR3_HIGH 0x00000048
18096 +#define RXFIFO_THR3_OOB 0x0000005a
18097 +#define RXFIFO_THR3_NORMAL 0x0110
18099 +/* PLA_TXFIFO_CTRL */
18100 +#define TXFIFO_THR_NORMAL 0x00400008
18101 +#define TXFIFO_THR_NORMAL2 0x01000008
18104 +#define FMC_FCR_MCU_EN 0x0001
18107 +#define EEEP_CR_EEEP_TX 0x0002
18109 +/* PLA_WDT6_CTRL */
18110 +#define WDT6_SET_MODE 0x0010
18113 +#define TCR0_TX_EMPTY 0x0800
18114 +#define TCR0_AUTO_FIFO 0x0080
18117 +#define VERSION_MASK 0x7cf0
18120 +#define CR_RST 0x10
18121 +#define CR_RE 0x08
18122 +#define CR_TE 0x04
18125 +#define CRWECR_NORAML 0x00
18126 +#define CRWECR_CONFIG 0xc0
18128 +/* PLA_OOB_CTRL */
18129 +#define NOW_IS_OOB 0x80
18130 +#define TXFIFO_EMPTY 0x20
18131 +#define RXFIFO_EMPTY 0x10
18132 +#define LINK_LIST_READY 0x02
18133 +#define DIS_MCU_CLROOB 0x01
18134 +#define FIFO_EMPTY (TXFIFO_EMPTY | RXFIFO_EMPTY)
18137 +#define RXDY_GATED_EN 0x0008
18139 +/* PLA_SFF_STS_7 */
18140 +#define RE_INIT_LL 0x8000
18141 +#define MCU_BORW_EN 0x4000
18144 +#define CPCR_RX_VLAN 0x0040
18147 +#define MAGIC_EN 0x0001
18149 +/* PLA_TEREDO_CFG */
18150 +#define TEREDO_SEL 0x8000
18151 +#define TEREDO_WAKE_MASK 0x7f00
18152 +#define TEREDO_RS_EVENT_MASK 0x00fe
18153 +#define OOB_TEREDO_EN 0x0001
18156 +#define ALDPS_PROXY_MODE 0x0001
18159 +#define LAN_WAKE_EN 0x0002
18161 +/* PLA_LED_FEATURE */
18162 +#define LED_MODE_MASK 0x0700
18165 +#define TX_10M_IDLE_EN 0x0080
18166 +#define PFM_PWM_SWITCH 0x0040
18168 +/* PLA_MAC_PWR_CTRL */
18169 +#define D3_CLK_GATED_EN 0x00004000
18170 +#define MCU_CLK_RATIO 0x07010f07
18171 +#define MCU_CLK_RATIO_MASK 0x0f0f0f0f
18172 +#define ALDPS_SPDWN_RATIO 0x0f87
18174 +/* PLA_MAC_PWR_CTRL2 */
18175 +#define EEE_SPDWN_RATIO 0x8007
18177 +/* PLA_MAC_PWR_CTRL3 */
18178 +#define PKT_AVAIL_SPDWN_EN 0x0100
18179 +#define SUSPEND_SPDWN_EN 0x0004
18180 +#define U1U2_SPDWN_EN 0x0002
18181 +#define L1_SPDWN_EN 0x0001
18183 +/* PLA_MAC_PWR_CTRL4 */
18184 +#define PWRSAVE_SPDWN_EN 0x1000
18185 +#define RXDV_SPDWN_EN 0x0800
18186 +#define TX10MIDLE_EN 0x0100
18187 +#define TP100_SPDWN_EN 0x0020
18188 +#define TP500_SPDWN_EN 0x0010
18189 +#define TP1000_SPDWN_EN 0x0008
18190 +#define EEE_SPDWN_EN 0x0001
18192 +/* PLA_GPHY_INTR_IMR */
18193 +#define GPHY_STS_MSK 0x0001
18194 +#define SPEED_DOWN_MSK 0x0002
18195 +#define SPDWN_RXDV_MSK 0x0004
18196 +#define SPDWN_LINKCHG_MSK 0x0008
18199 +#define PHYAR_FLAG 0x80000000
18202 +#define EEE_RX_EN 0x0001
18203 +#define EEE_TX_EN 0x0002
18205 +/* PLA_BOOT_CTRL */
18206 +#define AUTOLOAD_DONE 0x0002
18208 +/* USB_DEV_STAT */
18209 +#define STAT_SPEED_MASK 0x0006
18210 +#define STAT_SPEED_HIGH 0x0000
18211 +#define STAT_SPEED_FULL 0x0001
18214 +#define TX_AGG_MAX_THRESHOLD 0x03
18216 +/* USB_RX_BUF_TH */
18217 +#define RX_THR_SUPPER 0x0c350180
18218 +#define RX_THR_HIGH 0x7a120180
18219 +#define RX_THR_SLOW 0xffff0180
18222 +#define TEST_MODE_DISABLE 0x00000001
18223 +#define TX_SIZE_ADJUST1 0x00000100
18225 +/* USB_UPS_CTRL */
18226 +#define POWER_CUT 0x0100
18228 +/* USB_PM_CTRL_STATUS */
18229 +#define RESUME_INDICATE 0x0001
18231 +/* USB_USB_CTRL */
18232 +#define RX_AGG_DISABLE 0x0010
18234 +/* USB_U2P3_CTRL */
18235 +#define U2P3_ENABLE 0x0001
18237 +/* USB_POWER_CUT */
18238 +#define PWR_EN 0x0001
18239 +#define PHASE2_EN 0x0008
18242 +#define PCUT_STATUS 0x0001
18244 +/* USB_RX_EARLY_AGG */
18245 +#define EARLY_AGG_SUPPER 0x0e832981
18246 +#define EARLY_AGG_HIGH 0x0e837a12
18247 +#define EARLY_AGG_SLOW 0x0e83ffff
18249 +/* USB_WDT11_CTRL */
18250 +#define TIMER11_EN 0x0001
18252 +/* USB_LPM_CTRL */
18253 +#define LPM_TIMER_MASK 0x0c
18254 +#define LPM_TIMER_500MS 0x04 /* 500 ms */
18255 +#define LPM_TIMER_500US 0x0c /* 500 us */
18257 +/* USB_AFE_CTRL2 */
18258 +#define SEN_VAL_MASK 0xf800
18259 +#define SEN_VAL_NORMAL 0xa000
18260 +#define SEL_RXIDLE 0x0100
18262 +/* OCP_ALDPS_CONFIG */
18263 +#define ENPWRSAVE 0x8000
18264 +#define ENPDNPS 0x0200
18265 +#define LINKENA 0x0100
18266 +#define DIS_SDSAVE 0x0010
18268 +/* OCP_PHY_STATUS */
18269 +#define PHY_STAT_MASK 0x0007
18270 +#define PHY_STAT_LAN_ON 3
18271 +#define PHY_STAT_PWRDN 5
18273 +/* OCP_POWER_CFG */
18274 +#define EEE_CLKDIV_EN 0x8000
18275 +#define EN_ALDPS 0x0004
18276 +#define EN_10M_PLLOFF 0x0001
18278 +/* OCP_EEE_CONFIG1 */
18279 +#define RG_TXLPI_MSK_HFDUP 0x8000
18280 +#define RG_MATCLR_EN 0x4000
18281 +#define EEE_10_CAP 0x2000
18282 +#define EEE_NWAY_EN 0x1000
18283 +#define TX_QUIET_EN 0x0200
18284 +#define RX_QUIET_EN 0x0100
18285 +#define SDRISETIME 0x0010 /* bit 4 ~ 6 */
18286 +#define RG_RXLPI_MSK_HFDUP 0x0008
18287 +#define SDFALLTIME 0x0007 /* bit 0 ~ 2 */
18289 +/* OCP_EEE_CONFIG2 */
18290 +#define RG_LPIHYS_NUM 0x7000 /* bit 12 ~ 15 */
18291 +#define RG_DACQUIET_EN 0x0400
18292 +#define RG_LDVQUIET_EN 0x0200
18293 +#define RG_CKRSEL 0x0020
18294 +#define RG_EEEPRG_EN 0x0010
18296 +/* OCP_EEE_CONFIG3 */
18297 +#define FST_SNR_EYE_R 0x1500 /* bit 7 ~ 15 */
18298 +#define RG_LFS_SEL 0x0060 /* bit 6 ~ 5 */
18299 +#define MSK_PH 0x0006 /* bit 0 ~ 3 */
18302 +/* bit[15:14] function */
18303 +#define FUN_ADDR 0x0000
18304 +#define FUN_DATA 0x4000
18305 +/* bit[4:0] device addr */
18306 +#define DEVICE_ADDR 0x0007
18308 +/* OCP_EEE_DATA */
18309 +#define EEE_ADDR 0x003C
18310 +#define EEE_DATA 0x0002
18313 +#define CTAP_SHORT_EN 0x0040
18314 +#define EEE10_EN 0x0010
18316 +/* OCP_DOWN_SPEED */
18317 +#define EN_10M_BGOFF 0x0080
18319 +/* OCP_EEE_CFG2 */
18320 +#define MY1000_EEE 0x0004
18321 +#define MY100_EEE 0x0002
18324 +#define CKADSEL_L 0x0100
18325 +#define ADC_EN 0x0080
18326 +#define EN_EMI_L 0x0040
18328 +/* SRAM_LPF_CFG */
18329 +#define LPF_AUTO_TUNE 0x8000
18331 +/* SRAM_10M_AMP1 */
18332 +#define GDAC_IB_UPALL 0x0008
18334 +/* SRAM_10M_AMP2 */
18335 +#define AMP_DN 0x0200
18337 +/* SRAM_IMPEDANCE */
18338 +#define RX_DRIVING_MASK 0x6000
18340 +enum rtl_register_content {
18344 + LINK_STATUS = 0x02,
18348 +#define RTL8152_MAX_TX 10
18349 +#define RTL8152_MAX_RX 10
18350 +#define INTBUFSIZE 2
18351 +#define CRC_SIZE 4
18352 +#define TX_ALIGN 4
18353 +#define RX_ALIGN 8
18355 +#define INTR_LINK 0x0004
18357 +#define RTL8152_REQT_READ 0xc0
18358 +#define RTL8152_REQT_WRITE 0x40
18359 +#define RTL8152_REQ_GET_REGS 0x05
18360 +#define RTL8152_REQ_SET_REGS 0x05
18362 +#define BYTE_EN_DWORD 0xff
18363 +#define BYTE_EN_WORD 0x33
18364 +#define BYTE_EN_BYTE 0x11
18365 +#define BYTE_EN_SIX_BYTES 0x3f
18366 +#define BYTE_EN_START_MASK 0x0f
18367 +#define BYTE_EN_END_MASK 0xf0
18369 +#define RTL8152_RMS (VLAN_ETH_FRAME_LEN + VLAN_HLEN)
18370 +#define RTL8152_TX_TIMEOUT (HZ)
18372 +/* rtl8152 flags */
18373 +enum rtl8152_flags {
18374 + RTL8152_UNPLUG = 0,
18375 + RTL8152_SET_RX_MODE,
18377 + RTL8152_LINK_CHG,
18380 +/* Define these values to match your device */
18381 +#define VENDOR_ID_REALTEK 0x0bda
18382 +#define PRODUCT_ID_RTL8152 0x8152
18383 +#define PRODUCT_ID_RTL8153 0x8153
18385 +#define VENDOR_ID_SAMSUNG 0x04e8
18386 +#define PRODUCT_ID_SAMSUNG 0xa101
18388 +#define VENDOR_ID_LENOVO 0x17ef
18389 +#define PRODUCT_ID_LENOVO 0x7205
18391 +#define VENDOR_ID_NVIDIA 0x0955
18392 +#define PRODUCT_ID_NVIDIA 0x09ff
18395 +#define MCU_TYPE_PLA 0x0100
18396 +#define MCU_TYPE_USB 0x0000
18400 +#define RX_LEN_MASK 0x7fff
18410 +#define TX_FS (1 << 31) /* First segment of a packet */
18411 +#define TX_LS (1 << 30) /* Final segment of a packet */
18412 +#define TX_LEN_MASK 0x3ffff
18415 +#define UDP_CS (1 << 31) /* Calculate UDP/IP checksum */
18416 +#define TCP_CS (1 << 30) /* Calculate TCP/IP checksum */
18417 +#define IPV4_CS (1 << 29) /* Calculate IPv4 checksum */
18418 +#define IPV6_CS (1 << 28) /* Calculate IPv6 checksum */
18424 + struct list_head list;
18426 + struct r8152 *context;
18432 + struct list_head list;
18434 + struct r8152 *context;
18442 + unsigned long flags;
18443 + struct usb_device *udev;
18444 + struct tasklet_struct tl;
18445 + struct usb_interface *intf;
18446 + struct net_device *netdev;
18447 + struct urb *intr_urb;
18448 + struct tx_agg tx_info[RTL8152_MAX_TX];
18449 + struct rx_agg rx_info[RTL8152_MAX_RX];
18450 + struct list_head rx_done, tx_free;
18451 + struct sk_buff_head tx_queue;
18452 + spinlock_t rx_lock, tx_lock;
18453 + struct delayed_work schedule;
18454 + struct mii_if_info mii;
18457 + void (*init)(struct r8152 *);
18458 + int (*enable)(struct r8152 *);
18459 + void (*disable)(struct r8152 *);
18460 + void (*down)(struct r8152 *);
18461 + void (*unload)(struct r8152 *);
18462 + } __no_const rtl_ops;
18464 + int intr_interval;
18473 +enum rtl_version {
18474 + RTL_VER_UNKNOWN = 0,
18483 +/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
18484 + * The RTL chips use a 64 element hash table based on the Ethernet CRC.
18486 +static const int multicast_filter_limit = 32;
18487 +static unsigned int rx_buf_sz = 16384;
18490 +int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
18495 + tmp = kmalloc(size, GFP_KERNEL);
18499 + ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
18500 + RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
18501 + value, index, tmp, size, 500);
18503 + memcpy(data, tmp, size);
18510 +int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
18515 + tmp = kmalloc(size, GFP_KERNEL);
18519 + memcpy(tmp, data, size);
18521 + ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
18522 + RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE,
18523 + value, index, tmp, size, 500);
18529 +static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
18530 + void *data, u16 type)
18535 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18538 + /* both size and indix must be 4 bytes align */
18539 + if ((size & 3) || !size || (index & 3) || !data)
18542 + if ((u32)index + (u32)size > 0xffff)
18546 + if (size > limit) {
18547 + ret = get_registers(tp, index, type, limit, data);
18555 + ret = get_registers(tp, index, type, size, data);
18569 +static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
18570 + u16 size, void *data, u16 type)
18573 + u16 byteen_start, byteen_end, byen;
18576 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18579 + /* both size and indix must be 4 bytes align */
18580 + if ((size & 3) || !size || (index & 3) || !data)
18583 + if ((u32)index + (u32)size > 0xffff)
18586 + byteen_start = byteen & BYTE_EN_START_MASK;
18587 + byteen_end = byteen & BYTE_EN_END_MASK;
18589 + byen = byteen_start | (byteen_start << 4);
18590 + ret = set_registers(tp, index, type | byen, 4, data);
18602 + if (size > limit) {
18603 + ret = set_registers(tp, index,
18604 + type | BYTE_EN_DWORD,
18613 + ret = set_registers(tp, index,
18614 + type | BYTE_EN_DWORD,
18626 + byen = byteen_end | (byteen_end >> 4);
18627 + ret = set_registers(tp, index, type | byen, 4, data);
18637 +int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
18639 + return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA);
18643 +int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
18645 + return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA);
18649 +int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
18651 + return generic_ocp_read(tp, index, size, data, MCU_TYPE_USB);
18655 +int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
18657 + return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB);
18660 +static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
18664 + generic_ocp_read(tp, index, sizeof(data), &data, type);
18666 + return __le32_to_cpu(data);
18669 +static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
18671 + __le32 tmp = __cpu_to_le32(data);
18673 + generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type);
18676 +static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
18680 + u8 shift = index & 2;
18684 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18686 + data = __le32_to_cpu(tmp);
18687 + data >>= (shift * 8);
18690 + return (u16)data;
18693 +static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
18695 + u32 mask = 0xffff;
18697 + u16 byen = BYTE_EN_WORD;
18698 + u8 shift = index & 2;
18704 + mask <<= (shift * 8);
18705 + data <<= (shift * 8);
18709 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18711 + data |= __le32_to_cpu(tmp) & ~mask;
18712 + tmp = __cpu_to_le32(data);
18714 + generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
18717 +static u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index)
18721 + u8 shift = index & 3;
18725 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18727 + data = __le32_to_cpu(tmp);
18728 + data >>= (shift * 8);
18734 +static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
18738 + u16 byen = BYTE_EN_BYTE;
18739 + u8 shift = index & 3;
18745 + mask <<= (shift * 8);
18746 + data <<= (shift * 8);
18750 + generic_ocp_read(tp, index, sizeof(tmp), &tmp, type);
18752 + data |= __le32_to_cpu(tmp) & ~mask;
18753 + tmp = __cpu_to_le32(data);
18755 + generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
18758 +static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
18760 + u16 ocp_base, ocp_index;
18762 + ocp_base = addr & 0xf000;
18763 + if (ocp_base != tp->ocp_base) {
18764 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
18765 + tp->ocp_base = ocp_base;
18768 + ocp_index = (addr & 0x0fff) | 0xb000;
18769 + return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
18772 +static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
18774 + u16 ocp_base, ocp_index;
18776 + ocp_base = addr & 0xf000;
18777 + if (ocp_base != tp->ocp_base) {
18778 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
18779 + tp->ocp_base = ocp_base;
18782 + ocp_index = (addr & 0x0fff) | 0xb000;
18783 + ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
18786 +static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
18788 + ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
18791 +static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
18793 + return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
18796 +static void sram_write(struct r8152 *tp, u16 addr, u16 data)
18798 + ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
18799 + ocp_reg_write(tp, OCP_SRAM_DATA, data);
18802 +static u16 sram_read(struct r8152 *tp, u16 addr)
18804 + ocp_reg_write(tp, OCP_SRAM_ADDR, addr);
18805 + return ocp_reg_read(tp, OCP_SRAM_DATA);
18808 +static int read_mii_word(struct net_device *netdev, int phy_id, int reg)
18810 + struct r8152 *tp = netdev_priv(netdev);
18812 + if (phy_id != R8152_PHY_ID)
18815 + return r8152_mdio_read(tp, reg);
18819 +void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val)
18821 + struct r8152 *tp = netdev_priv(netdev);
18823 + if (phy_id != R8152_PHY_ID)
18826 + r8152_mdio_write(tp, reg, val);
18830 +int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags);
18832 +static inline void set_ethernet_addr(struct r8152 *tp)
18834 + struct net_device *dev = tp->netdev;
18835 + u8 node_id[8] = {0};
18837 + if (pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id) < 0)
18838 + netif_notice(tp, probe, dev, "inet addr fail\n");
18840 + memcpy(dev->dev_addr, node_id, dev->addr_len);
18841 + memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
18845 +static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
18847 + struct r8152 *tp = netdev_priv(netdev);
18848 + struct sockaddr *addr = p;
18850 + if (!is_valid_ether_addr(addr->sa_data))
18851 + return -EADDRNOTAVAIL;
18853 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
18855 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
18856 + pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data);
18857 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
18862 +static struct net_device_stats *rtl8152_get_stats(struct net_device *dev)
18864 + return &dev->stats;
18867 +static void read_bulk_callback(struct urb *urb)
18869 + struct net_device *netdev;
18870 + unsigned long flags;
18871 + int status = urb->status;
18872 + struct rx_agg *agg;
18873 + struct r8152 *tp;
18876 + agg = urb->context;
18880 + tp = agg->context;
18884 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18887 + if (!test_bit(WORK_ENABLE, &tp->flags))
18890 + netdev = tp->netdev;
18892 + /* When link down, the driver would cancel all bulks. */
18893 + /* This avoid the re-submitting bulk */
18894 + if (!netif_carrier_ok(netdev))
18897 + switch (status) {
18899 + if (urb->actual_length < ETH_ZLEN)
18902 + spin_lock_irqsave(&tp->rx_lock, flags);
18903 + list_add_tail(&agg->list, &tp->rx_done);
18904 + spin_unlock_irqrestore(&tp->rx_lock, flags);
18905 + tasklet_schedule(&tp->tl);
18908 + set_bit(RTL8152_UNPLUG, &tp->flags);
18909 + netif_device_detach(tp->netdev);
18912 + return; /* the urb is in unlink state */
18914 + if (net_ratelimit())
18915 + netdev_warn(netdev, "maybe reset is needed?\n");
18918 + if (net_ratelimit())
18919 + netdev_warn(netdev, "Rx status %d\n", status);
18923 + result = r8152_submit_rx(tp, agg, GFP_ATOMIC);
18924 + if (result == -ENODEV) {
18925 + netif_device_detach(tp->netdev);
18926 + } else if (result) {
18927 + spin_lock_irqsave(&tp->rx_lock, flags);
18928 + list_add_tail(&agg->list, &tp->rx_done);
18929 + spin_unlock_irqrestore(&tp->rx_lock, flags);
18930 + tasklet_schedule(&tp->tl);
18934 +static void write_bulk_callback(struct urb *urb)
18936 + struct net_device_stats *stats;
18937 + unsigned long flags;
18938 + struct tx_agg *agg;
18939 + struct r8152 *tp;
18940 + int status = urb->status;
18942 + agg = urb->context;
18946 + tp = agg->context;
18950 + stats = rtl8152_get_stats(tp->netdev);
18952 + if (net_ratelimit())
18953 + netdev_warn(tp->netdev, "Tx status %d\n", status);
18954 + stats->tx_errors += agg->skb_num;
18956 + stats->tx_packets += agg->skb_num;
18957 + stats->tx_bytes += agg->skb_len;
18960 + spin_lock_irqsave(&tp->tx_lock, flags);
18961 + list_add_tail(&agg->list, &tp->tx_free);
18962 + spin_unlock_irqrestore(&tp->tx_lock, flags);
18964 + if (!netif_carrier_ok(tp->netdev))
18967 + if (!test_bit(WORK_ENABLE, &tp->flags))
18970 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18973 + if (!skb_queue_empty(&tp->tx_queue))
18974 + tasklet_schedule(&tp->tl);
18977 +static void intr_callback(struct urb *urb)
18979 + struct r8152 *tp;
18981 + int status = urb->status;
18984 + tp = urb->context;
18988 + if (!test_bit(WORK_ENABLE, &tp->flags))
18991 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
18994 + switch (status) {
18995 + case 0: /* success */
18997 + case -ECONNRESET: /* unlink */
18999 + netif_device_detach(tp->netdev);
19003 + netif_info(tp, intr, tp->netdev, "intr status -EOVERFLOW\n");
19005 + /* -EPIPE: should clear the halt */
19007 + netif_info(tp, intr, tp->netdev, "intr status %d\n", status);
19011 + d = urb->transfer_buffer;
19012 + if (INTR_LINK & __le16_to_cpu(d[0])) {
19013 + if (!(tp->speed & LINK_STATUS)) {
19014 + set_bit(RTL8152_LINK_CHG, &tp->flags);
19015 + schedule_delayed_work(&tp->schedule, 0);
19018 + if (tp->speed & LINK_STATUS) {
19019 + set_bit(RTL8152_LINK_CHG, &tp->flags);
19020 + schedule_delayed_work(&tp->schedule, 0);
19025 + res = usb_submit_urb(urb, GFP_ATOMIC);
19026 + if (res == -ENODEV)
19027 + netif_device_detach(tp->netdev);
19029 + netif_err(tp, intr, tp->netdev,
19030 + "can't resubmit intr, status %d\n", res);
19033 +static inline void *rx_agg_align(void *data)
19035 + return (void *)ALIGN((uintptr_t)data, RX_ALIGN);
19038 +static inline void *tx_agg_align(void *data)
19040 + return (void *)ALIGN((uintptr_t)data, TX_ALIGN);
19043 +static void free_all_mem(struct r8152 *tp)
19047 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19048 + usb_free_urb(tp->rx_info[i].urb);
19049 + tp->rx_info[i].urb = NULL;
19051 + kfree(tp->rx_info[i].buffer);
19052 + tp->rx_info[i].buffer = NULL;
19053 + tp->rx_info[i].head = NULL;
19056 + for (i = 0; i < RTL8152_MAX_TX; i++) {
19057 + usb_free_urb(tp->tx_info[i].urb);
19058 + tp->tx_info[i].urb = NULL;
19060 + kfree(tp->tx_info[i].buffer);
19061 + tp->tx_info[i].buffer = NULL;
19062 + tp->tx_info[i].head = NULL;
19065 + usb_free_urb(tp->intr_urb);
19066 + tp->intr_urb = NULL;
19068 + kfree(tp->intr_buff);
19069 + tp->intr_buff = NULL;
19072 +static int alloc_all_mem(struct r8152 *tp)
19074 + struct net_device *netdev = tp->netdev;
19075 + struct usb_interface *intf = tp->intf;
19076 + struct usb_host_interface *alt = intf->cur_altsetting;
19077 + struct usb_host_endpoint *ep_intr = alt->endpoint + 2;
19082 + node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1;
19084 + spin_lock_init(&tp->rx_lock);
19085 + spin_lock_init(&tp->tx_lock);
19086 + INIT_LIST_HEAD(&tp->rx_done);
19087 + INIT_LIST_HEAD(&tp->tx_free);
19088 + skb_queue_head_init(&tp->tx_queue);
19090 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19091 + buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
19095 + if (buf != rx_agg_align(buf)) {
19097 + buf = kmalloc_node(rx_buf_sz + RX_ALIGN, GFP_KERNEL,
19103 + urb = usb_alloc_urb(0, GFP_KERNEL);
19109 + INIT_LIST_HEAD(&tp->rx_info[i].list);
19110 + tp->rx_info[i].context = tp;
19111 + tp->rx_info[i].urb = urb;
19112 + tp->rx_info[i].buffer = buf;
19113 + tp->rx_info[i].head = rx_agg_align(buf);
19116 + for (i = 0; i < RTL8152_MAX_TX; i++) {
19117 + buf = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
19121 + if (buf != tx_agg_align(buf)) {
19123 + buf = kmalloc_node(rx_buf_sz + TX_ALIGN, GFP_KERNEL,
19129 + urb = usb_alloc_urb(0, GFP_KERNEL);
19135 + INIT_LIST_HEAD(&tp->tx_info[i].list);
19136 + tp->tx_info[i].context = tp;
19137 + tp->tx_info[i].urb = urb;
19138 + tp->tx_info[i].buffer = buf;
19139 + tp->tx_info[i].head = tx_agg_align(buf);
19141 + list_add_tail(&tp->tx_info[i].list, &tp->tx_free);
19144 + tp->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
19145 + if (!tp->intr_urb)
19148 + tp->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
19149 + if (!tp->intr_buff)
19152 + tp->intr_interval = (int)ep_intr->desc.bInterval;
19153 + usb_fill_int_urb(tp->intr_urb, tp->udev, usb_rcvintpipe(tp->udev, 3),
19154 + tp->intr_buff, INTBUFSIZE, intr_callback,
19155 + tp, tp->intr_interval);
19160 + free_all_mem(tp);
19164 +static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
19166 + struct tx_agg *agg = NULL;
19167 + unsigned long flags;
19169 + spin_lock_irqsave(&tp->tx_lock, flags);
19170 + if (!list_empty(&tp->tx_free)) {
19171 + struct list_head *cursor;
19173 + cursor = tp->tx_free.next;
19174 + list_del_init(cursor);
19175 + agg = list_entry(cursor, struct tx_agg, list);
19177 + spin_unlock_irqrestore(&tp->tx_lock, flags);
19183 +r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
19185 + memset(desc, 0, sizeof(*desc));
19187 + desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS);
19189 + if (skb->ip_summed == CHECKSUM_PARTIAL) {
19194 + if (skb->protocol == htons(ETH_P_8021Q))
19195 + protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
19197 + protocol = skb->protocol;
19199 + switch (protocol) {
19200 + case htons(ETH_P_IP):
19201 + opts2 |= IPV4_CS;
19202 + ip_protocol = ip_hdr(skb)->protocol;
19205 + case htons(ETH_P_IPV6):
19206 + opts2 |= IPV6_CS;
19207 + ip_protocol = ipv6_hdr(skb)->nexthdr;
19211 + ip_protocol = IPPROTO_RAW;
19215 + if (ip_protocol == IPPROTO_TCP) {
19217 + opts2 |= (skb_transport_offset(skb) & 0x7fff) << 17;
19218 + } else if (ip_protocol == IPPROTO_UDP) {
19224 + desc->opts2 = cpu_to_le32(opts2);
19228 +static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
19233 + tx_data = agg->head;
19234 + agg->skb_num = agg->skb_len = 0;
19235 + remain = rx_buf_sz;
19237 + while (remain >= ETH_ZLEN + sizeof(struct tx_desc)) {
19238 + struct tx_desc *tx_desc;
19239 + struct sk_buff *skb;
19240 + unsigned int len;
19242 + skb = skb_dequeue(&tp->tx_queue);
19246 + remain -= sizeof(*tx_desc);
19248 + if (remain < len) {
19249 + skb_queue_head(&tp->tx_queue, skb);
19253 + tx_data = tx_agg_align(tx_data);
19254 + tx_desc = (struct tx_desc *)tx_data;
19255 + tx_data += sizeof(*tx_desc);
19257 + r8152_tx_csum(tp, tx_desc, skb);
19258 + memcpy(tx_data, skb->data, len);
19260 + agg->skb_len += len;
19261 + dev_kfree_skb_any(skb);
19264 + remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head);
19267 + netif_tx_lock(tp->netdev);
19269 + if (netif_queue_stopped(tp->netdev) &&
19270 + skb_queue_len(&tp->tx_queue) < tp->tx_qlen)
19271 + netif_wake_queue(tp->netdev);
19273 + netif_tx_unlock(tp->netdev);
19275 + usb_fill_bulk_urb(agg->urb, tp->udev, usb_sndbulkpipe(tp->udev, 2),
19276 + agg->head, (int)(tx_data - (u8 *)agg->head),
19277 + (usb_complete_t)write_bulk_callback, agg);
19279 + return usb_submit_urb(agg->urb, GFP_ATOMIC);
19282 +static void rx_bottom(struct r8152 *tp)
19284 + unsigned long flags;
19285 + struct list_head *cursor, *next;
19287 + spin_lock_irqsave(&tp->rx_lock, flags);
19288 + list_for_each_safe(cursor, next, &tp->rx_done) {
19289 + struct rx_desc *rx_desc;
19290 + struct rx_agg *agg;
19291 + int len_used = 0;
19296 + list_del_init(cursor);
19297 + spin_unlock_irqrestore(&tp->rx_lock, flags);
19299 + agg = list_entry(cursor, struct rx_agg, list);
19301 + if (urb->actual_length < ETH_ZLEN)
19304 + rx_desc = agg->head;
19305 + rx_data = agg->head;
19306 + len_used += sizeof(struct rx_desc);
19308 + while (urb->actual_length > len_used) {
19309 + struct net_device *netdev = tp->netdev;
19310 + struct net_device_stats *stats;
19311 + unsigned int pkt_len;
19312 + struct sk_buff *skb;
19314 + pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
19315 + if (pkt_len < ETH_ZLEN)
19318 + len_used += pkt_len;
19319 + if (urb->actual_length < len_used)
19322 + stats = rtl8152_get_stats(netdev);
19324 + pkt_len -= CRC_SIZE;
19325 + rx_data += sizeof(struct rx_desc);
19327 + skb = netdev_alloc_skb_ip_align(netdev, pkt_len);
19329 + stats->rx_dropped++;
19332 + memcpy(skb->data, rx_data, pkt_len);
19333 + skb_put(skb, pkt_len);
19334 + skb->protocol = eth_type_trans(skb, netdev);
19336 + stats->rx_packets++;
19337 + stats->rx_bytes += pkt_len;
19339 + rx_data = rx_agg_align(rx_data + pkt_len + CRC_SIZE);
19340 + rx_desc = (struct rx_desc *)rx_data;
19341 + len_used = (int)(rx_data - (u8 *)agg->head);
19342 + len_used += sizeof(struct rx_desc);
19346 + ret = r8152_submit_rx(tp, agg, GFP_ATOMIC);
19347 + spin_lock_irqsave(&tp->rx_lock, flags);
19348 + if (ret && ret != -ENODEV) {
19349 + list_add_tail(&agg->list, next);
19350 + tasklet_schedule(&tp->tl);
19353 + spin_unlock_irqrestore(&tp->rx_lock, flags);
19356 +static void tx_bottom(struct r8152 *tp)
19361 + struct tx_agg *agg;
19363 + if (skb_queue_empty(&tp->tx_queue))
19366 + agg = r8152_get_tx_agg(tp);
19370 + res = r8152_tx_agg_fill(tp, agg);
19372 + struct net_device_stats *stats;
19373 + struct net_device *netdev;
19374 + unsigned long flags;
19376 + netdev = tp->netdev;
19377 + stats = rtl8152_get_stats(netdev);
19379 + if (res == -ENODEV) {
19380 + netif_device_detach(netdev);
19382 + netif_warn(tp, tx_err, netdev,
19383 + "failed tx_urb %d\n", res);
19384 + stats->tx_dropped += agg->skb_num;
19385 + spin_lock_irqsave(&tp->tx_lock, flags);
19386 + list_add_tail(&agg->list, &tp->tx_free);
19387 + spin_unlock_irqrestore(&tp->tx_lock, flags);
19390 + } while (res == 0);
19393 +static void bottom_half(unsigned long data)
19395 + struct r8152 *tp;
19397 + tp = (struct r8152 *)data;
19399 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
19402 + if (!test_bit(WORK_ENABLE, &tp->flags))
19405 + /* When link down, the driver would cancel all bulks. */
19406 + /* This avoid the re-submitting bulk */
19407 + if (!netif_carrier_ok(tp->netdev))
19415 +int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
19417 + usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
19418 + agg->head, rx_buf_sz,
19419 + (usb_complete_t)read_bulk_callback, agg);
19421 + return usb_submit_urb(agg->urb, mem_flags);
19424 +static void rtl8152_tx_timeout(struct net_device *netdev)
19426 + struct r8152 *tp = netdev_priv(netdev);
19429 + netif_warn(tp, tx_err, netdev, "Tx timeout\n");
19430 + for (i = 0; i < RTL8152_MAX_TX; i++)
19431 + usb_unlink_urb(tp->tx_info[i].urb);
19434 +static void rtl8152_set_rx_mode(struct net_device *netdev)
19436 + struct r8152 *tp = netdev_priv(netdev);
19438 + if (tp->speed & LINK_STATUS) {
19439 + set_bit(RTL8152_SET_RX_MODE, &tp->flags);
19440 + schedule_delayed_work(&tp->schedule, 0);
19444 +static void _rtl8152_set_rx_mode(struct net_device *netdev)
19446 + struct r8152 *tp = netdev_priv(netdev);
19447 + u32 mc_filter[2]; /* Multicast hash filter */
19451 + clear_bit(RTL8152_SET_RX_MODE, &tp->flags);
19452 + netif_stop_queue(netdev);
19453 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19454 + ocp_data &= ~RCR_ACPT_ALL;
19455 + ocp_data |= RCR_AB | RCR_APM;
19457 + if (netdev->flags & IFF_PROMISC) {
19458 + /* Unconditionally log net taps. */
19459 + netif_notice(tp, link, netdev, "Promiscuous mode enabled\n");
19460 + ocp_data |= RCR_AM | RCR_AAP;
19461 + mc_filter[1] = mc_filter[0] = 0xffffffff;
19462 + } else if ((netdev_mc_count(netdev) > multicast_filter_limit) ||
19463 + (netdev->flags & IFF_ALLMULTI)) {
19464 + /* Too many to filter perfectly -- accept all multicasts. */
19465 + ocp_data |= RCR_AM;
19466 + mc_filter[1] = mc_filter[0] = 0xffffffff;
19468 + struct netdev_hw_addr *ha;
19470 + mc_filter[1] = mc_filter[0] = 0;
19471 + netdev_for_each_mc_addr(ha, netdev) {
19472 + int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
19473 + mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
19474 + ocp_data |= RCR_AM;
19478 + tmp[0] = __cpu_to_le32(swab32(mc_filter[1]));
19479 + tmp[1] = __cpu_to_le32(swab32(mc_filter[0]));
19481 + pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp);
19482 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19483 + netif_wake_queue(netdev);
19486 +static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
19487 + struct net_device *netdev)
19489 + struct r8152 *tp = netdev_priv(netdev);
19491 + skb_tx_timestamp(skb);
19493 + skb_queue_tail(&tp->tx_queue, skb);
19495 + if (list_empty(&tp->tx_free) &&
19496 + skb_queue_len(&tp->tx_queue) > tp->tx_qlen)
19497 + netif_stop_queue(netdev);
19499 + if (!list_empty(&tp->tx_free))
19500 + tasklet_schedule(&tp->tl);
19502 + return NETDEV_TX_OK;
19505 +static void r8152b_reset_packet_filter(struct r8152 *tp)
19509 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_FMC);
19510 + ocp_data &= ~FMC_FCR_MCU_EN;
19511 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
19512 + ocp_data |= FMC_FCR_MCU_EN;
19513 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_FMC, ocp_data);
19516 +static void rtl8152_nic_reset(struct r8152 *tp)
19520 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, CR_RST);
19522 + for (i = 0; i < 1000; i++) {
19523 + if (!(ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR) & CR_RST))
19529 +static void set_tx_qlen(struct r8152 *tp)
19531 + struct net_device *netdev = tp->netdev;
19533 + tp->tx_qlen = rx_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + VLAN_HLEN +
19534 + sizeof(struct tx_desc));
19537 +static inline u8 rtl8152_get_speed(struct r8152 *tp)
19539 + return ocp_read_byte(tp, MCU_TYPE_PLA, PLA_PHYSTATUS);
19542 +static void rtl_set_eee_plus(struct r8152 *tp)
19547 + speed = rtl8152_get_speed(tp);
19548 + if (speed & _10bps) {
19549 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR);
19550 + ocp_data |= EEEP_CR_EEEP_TX;
19551 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data);
19553 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR);
19554 + ocp_data &= ~EEEP_CR_EEEP_TX;
19555 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEEP_CR, ocp_data);
19559 +static int rtl_enable(struct r8152 *tp)
19564 + r8152b_reset_packet_filter(tp);
19566 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CR);
19567 + ocp_data |= CR_RE | CR_TE;
19568 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, ocp_data);
19570 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19571 + ocp_data &= ~RXDY_GATED_EN;
19572 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19574 + INIT_LIST_HEAD(&tp->rx_done);
19576 + for (i = 0; i < RTL8152_MAX_RX; i++) {
19577 + INIT_LIST_HEAD(&tp->rx_info[i].list);
19578 + ret |= r8152_submit_rx(tp, &tp->rx_info[i], GFP_KERNEL);
19584 +static int rtl8152_enable(struct r8152 *tp)
19587 + rtl_set_eee_plus(tp);
19589 + return rtl_enable(tp);
19592 +static void r8153_set_rx_agg(struct r8152 *tp)
19596 + speed = rtl8152_get_speed(tp);
19597 + if (speed & _1000bps) {
19598 + if (tp->udev->speed == USB_SPEED_SUPER) {
19599 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH,
19601 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19602 + EARLY_AGG_SUPPER);
19604 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH,
19606 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19610 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_SLOW);
19611 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_EARLY_AGG,
19616 +static int rtl8153_enable(struct r8152 *tp)
19619 + rtl_set_eee_plus(tp);
19620 + r8153_set_rx_agg(tp);
19622 + return rtl_enable(tp);
19625 +static void rtl8152_disable(struct r8152 *tp)
19627 + struct net_device_stats *stats = rtl8152_get_stats(tp->netdev);
19628 + struct sk_buff *skb;
19632 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19633 + ocp_data &= ~RCR_ACPT_ALL;
19634 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19636 + while ((skb = skb_dequeue(&tp->tx_queue))) {
19637 + dev_kfree_skb(skb);
19638 + stats->tx_dropped++;
19641 + for (i = 0; i < RTL8152_MAX_TX; i++)
19642 + usb_kill_urb(tp->tx_info[i].urb);
19644 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19645 + ocp_data |= RXDY_GATED_EN;
19646 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19648 + for (i = 0; i < 1000; i++) {
19649 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19650 + if ((ocp_data & FIFO_EMPTY) == FIFO_EMPTY)
19655 + for (i = 0; i < 1000; i++) {
19656 + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0) & TCR0_TX_EMPTY)
19661 + for (i = 0; i < RTL8152_MAX_RX; i++)
19662 + usb_kill_urb(tp->rx_info[i].urb);
19664 + rtl8152_nic_reset(tp);
19667 +static void r8152b_exit_oob(struct r8152 *tp)
19672 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19673 + ocp_data &= ~RCR_ACPT_ALL;
19674 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19676 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19677 + ocp_data |= RXDY_GATED_EN;
19678 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19680 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
19681 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CR, 0x00);
19683 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19684 + ocp_data &= ~NOW_IS_OOB;
19685 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19687 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19688 + ocp_data &= ~MCU_BORW_EN;
19689 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19691 + for (i = 0; i < 1000; i++) {
19692 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19693 + if (ocp_data & LINK_LIST_READY)
19698 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19699 + ocp_data |= RE_INIT_LL;
19700 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19702 + for (i = 0; i < 1000; i++) {
19703 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19704 + if (ocp_data & LINK_LIST_READY)
19709 + rtl8152_nic_reset(tp);
19711 + /* rx share fifo credit full threshold */
19712 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
19714 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_DEV_STAT);
19715 + ocp_data &= STAT_SPEED_MASK;
19716 + if (ocp_data == STAT_SPEED_FULL) {
19717 + /* rx share fifo credit near full threshold */
19718 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
19719 + RXFIFO_THR2_FULL);
19720 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
19721 + RXFIFO_THR3_FULL);
19723 + /* rx share fifo credit near full threshold */
19724 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1,
19725 + RXFIFO_THR2_HIGH);
19726 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2,
19727 + RXFIFO_THR3_HIGH);
19730 + /* TX share fifo free credit full threshold */
19731 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL);
19733 + ocp_write_byte(tp, MCU_TYPE_USB, USB_TX_AGG, TX_AGG_MAX_THRESHOLD);
19734 + ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_HIGH);
19735 + ocp_write_dword(tp, MCU_TYPE_USB, USB_TX_DMA,
19736 + TEST_MODE_DISABLE | TX_SIZE_ADJUST1);
19738 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19739 + ocp_data &= ~CPCR_RX_VLAN;
19740 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19742 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19744 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
19745 + ocp_data |= TCR0_AUTO_FIFO;
19746 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
19749 +static void r8152b_enter_oob(struct r8152 *tp)
19754 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19755 + ocp_data &= ~NOW_IS_OOB;
19756 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19758 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_OOB);
19759 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_OOB);
19760 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_OOB);
19762 + rtl8152_disable(tp);
19764 + for (i = 0; i < 1000; i++) {
19765 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19766 + if (ocp_data & LINK_LIST_READY)
19771 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19772 + ocp_data |= RE_INIT_LL;
19773 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19775 + for (i = 0; i < 1000; i++) {
19776 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19777 + if (ocp_data & LINK_LIST_READY)
19782 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19784 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
19785 + ocp_data |= MAGIC_EN;
19786 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
19788 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19789 + ocp_data |= CPCR_RX_VLAN;
19790 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19792 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
19793 + ocp_data |= ALDPS_PROXY_MODE;
19794 + ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
19796 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19797 + ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
19798 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19800 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN);
19802 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19803 + ocp_data &= ~RXDY_GATED_EN;
19804 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19806 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19807 + ocp_data |= RCR_APM | RCR_AM | RCR_AB;
19808 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19811 +static void r8152b_disable_aldps(struct r8152 *tp)
19813 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPDNPS | LINKENA | DIS_SDSAVE);
19817 +static inline void r8152b_enable_aldps(struct r8152 *tp)
19819 + ocp_reg_write(tp, OCP_ALDPS_CONFIG, ENPWRSAVE | ENPDNPS |
19820 + LINKENA | DIS_SDSAVE);
19823 +static void r8153_hw_phy_cfg(struct r8152 *tp)
19828 + ocp_reg_write(tp, OCP_ADC_CFG, CKADSEL_L | ADC_EN | EN_EMI_L);
19829 + r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE);
19831 + if (tp->version == RTL_VER_03) {
19832 + data = ocp_reg_read(tp, OCP_EEE_CFG);
19833 + data &= ~CTAP_SHORT_EN;
19834 + ocp_reg_write(tp, OCP_EEE_CFG, data);
19837 + data = ocp_reg_read(tp, OCP_POWER_CFG);
19838 + data |= EEE_CLKDIV_EN;
19839 + ocp_reg_write(tp, OCP_POWER_CFG, data);
19841 + data = ocp_reg_read(tp, OCP_DOWN_SPEED);
19842 + data |= EN_10M_BGOFF;
19843 + ocp_reg_write(tp, OCP_DOWN_SPEED, data);
19844 + data = ocp_reg_read(tp, OCP_POWER_CFG);
19845 + data |= EN_10M_PLLOFF;
19846 + ocp_reg_write(tp, OCP_POWER_CFG, data);
19847 + data = sram_read(tp, SRAM_IMPEDANCE);
19848 + data &= ~RX_DRIVING_MASK;
19849 + sram_write(tp, SRAM_IMPEDANCE, data);
19851 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
19852 + ocp_data |= PFM_PWM_SWITCH;
19853 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
19855 + data = sram_read(tp, SRAM_LPF_CFG);
19856 + data |= LPF_AUTO_TUNE;
19857 + sram_write(tp, SRAM_LPF_CFG, data);
19859 + data = sram_read(tp, SRAM_10M_AMP1);
19860 + data |= GDAC_IB_UPALL;
19861 + sram_write(tp, SRAM_10M_AMP1, data);
19862 + data = sram_read(tp, SRAM_10M_AMP2);
19864 + sram_write(tp, SRAM_10M_AMP2, data);
19867 +static void r8153_u1u2en(struct r8152 *tp, int enable)
19872 + memset(u1u2, 0xff, sizeof(u1u2));
19874 + memset(u1u2, 0x00, sizeof(u1u2));
19876 + usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
19879 +static void r8153_u2p3en(struct r8152 *tp, int enable)
19883 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL);
19885 + ocp_data |= U2P3_ENABLE;
19887 + ocp_data &= ~U2P3_ENABLE;
19888 + ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
19891 +static void r8153_power_cut_en(struct r8152 *tp, int enable)
19895 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT);
19897 + ocp_data |= PWR_EN | PHASE2_EN;
19899 + ocp_data &= ~(PWR_EN | PHASE2_EN);
19900 + ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data);
19902 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
19903 + ocp_data &= ~PCUT_STATUS;
19904 + ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
19907 +static void r8153_teredo_off(struct r8152 *tp)
19911 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
19912 + ocp_data &= ~(TEREDO_SEL | TEREDO_RS_EVENT_MASK | OOB_TEREDO_EN);
19913 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
19915 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_WDT6_CTRL, WDT6_SET_MODE);
19916 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_REALWOW_TIMER, 0);
19917 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TEREDO_TIMER, 0);
19920 +static void r8153_first_init(struct r8152 *tp)
19925 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
19926 + ocp_data |= RXDY_GATED_EN;
19927 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
19929 + r8153_teredo_off(tp);
19931 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
19932 + ocp_data &= ~RCR_ACPT_ALL;
19933 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
19935 + r8153_hw_phy_cfg(tp);
19937 + rtl8152_nic_reset(tp);
19939 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19940 + ocp_data &= ~NOW_IS_OOB;
19941 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19943 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19944 + ocp_data &= ~MCU_BORW_EN;
19945 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19947 + for (i = 0; i < 1000; i++) {
19948 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19949 + if (ocp_data & LINK_LIST_READY)
19954 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
19955 + ocp_data |= RE_INIT_LL;
19956 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
19958 + for (i = 0; i < 1000; i++) {
19959 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19960 + if (ocp_data & LINK_LIST_READY)
19965 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
19966 + ocp_data &= ~CPCR_RX_VLAN;
19967 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
19969 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
19971 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
19972 + ocp_data |= TCR0_AUTO_FIFO;
19973 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR0, ocp_data);
19975 + rtl8152_nic_reset(tp);
19977 + /* rx share fifo credit full threshold */
19978 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL0, RXFIFO_THR1_NORMAL);
19979 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL1, RXFIFO_THR2_NORMAL);
19980 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL);
19981 + /* TX share fifo free credit full threshold */
19982 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2);
19984 + /* rx aggregation */
19985 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
19986 + ocp_data &= ~RX_AGG_DISABLE;
19987 + ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
19990 +static void r8153_enter_oob(struct r8152 *tp)
19995 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
19996 + ocp_data &= ~NOW_IS_OOB;
19997 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
19999 + rtl8152_disable(tp);
20001 + for (i = 0; i < 1000; i++) {
20002 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20003 + if (ocp_data & LINK_LIST_READY)
20008 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
20009 + ocp_data |= RE_INIT_LL;
20010 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
20012 + for (i = 0; i < 1000; i++) {
20013 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20014 + if (ocp_data & LINK_LIST_READY)
20019 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
20021 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL);
20022 + ocp_data |= MAGIC_EN;
20023 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CFG_WOL, ocp_data);
20025 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG);
20026 + ocp_data &= ~TEREDO_WAKE_MASK;
20027 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TEREDO_CFG, ocp_data);
20029 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_CPCR);
20030 + ocp_data |= CPCR_RX_VLAN;
20031 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_CPCR, ocp_data);
20033 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PAL_BDC_CR);
20034 + ocp_data |= ALDPS_PROXY_MODE;
20035 + ocp_write_word(tp, MCU_TYPE_PLA, PAL_BDC_CR, ocp_data);
20037 + ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
20038 + ocp_data |= NOW_IS_OOB | DIS_MCU_CLROOB;
20039 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
20041 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG5, LAN_WAKE_EN);
20043 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MISC_1);
20044 + ocp_data &= ~RXDY_GATED_EN;
20045 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MISC_1, ocp_data);
20047 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
20048 + ocp_data |= RCR_APM | RCR_AM | RCR_AB;
20049 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
20052 +static void r8153_disable_aldps(struct r8152 *tp)
20056 + data = ocp_reg_read(tp, OCP_POWER_CFG);
20057 + data &= ~EN_ALDPS;
20058 + ocp_reg_write(tp, OCP_POWER_CFG, data);
20062 +static void r8153_enable_aldps(struct r8152 *tp)
20066 + data = ocp_reg_read(tp, OCP_POWER_CFG);
20067 + data |= EN_ALDPS;
20068 + ocp_reg_write(tp, OCP_POWER_CFG, data);
20071 +static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
20073 + u16 bmcr, anar, gbcr;
20076 + cancel_delayed_work_sync(&tp->schedule);
20077 + anar = r8152_mdio_read(tp, MII_ADVERTISE);
20078 + anar &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
20079 + ADVERTISE_100HALF | ADVERTISE_100FULL);
20080 + if (tp->mii.supports_gmii) {
20081 + gbcr = r8152_mdio_read(tp, MII_CTRL1000);
20082 + gbcr &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
20087 + if (autoneg == AUTONEG_DISABLE) {
20088 + if (speed == SPEED_10) {
20090 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20091 + } else if (speed == SPEED_100) {
20092 + bmcr = BMCR_SPEED100;
20093 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20094 + } else if (speed == SPEED_1000 && tp->mii.supports_gmii) {
20095 + bmcr = BMCR_SPEED1000;
20096 + gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
20102 + if (duplex == DUPLEX_FULL)
20103 + bmcr |= BMCR_FULLDPLX;
20105 + if (speed == SPEED_10) {
20106 + if (duplex == DUPLEX_FULL)
20107 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20109 + anar |= ADVERTISE_10HALF;
20110 + } else if (speed == SPEED_100) {
20111 + if (duplex == DUPLEX_FULL) {
20112 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20113 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20115 + anar |= ADVERTISE_10HALF;
20116 + anar |= ADVERTISE_100HALF;
20118 + } else if (speed == SPEED_1000 && tp->mii.supports_gmii) {
20119 + if (duplex == DUPLEX_FULL) {
20120 + anar |= ADVERTISE_10HALF | ADVERTISE_10FULL;
20121 + anar |= ADVERTISE_100HALF | ADVERTISE_100FULL;
20122 + gbcr |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
20124 + anar |= ADVERTISE_10HALF;
20125 + anar |= ADVERTISE_100HALF;
20126 + gbcr |= ADVERTISE_1000HALF;
20133 + bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
20136 + if (tp->mii.supports_gmii)
20137 + r8152_mdio_write(tp, MII_CTRL1000, gbcr);
20139 + r8152_mdio_write(tp, MII_ADVERTISE, anar);
20140 + r8152_mdio_write(tp, MII_BMCR, bmcr);
20147 +static void rtl8152_down(struct r8152 *tp)
20151 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20152 + ocp_data &= ~POWER_CUT;
20153 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20155 + r8152b_disable_aldps(tp);
20156 + r8152b_enter_oob(tp);
20157 + r8152b_enable_aldps(tp);
20160 +static void rtl8153_down(struct r8152 *tp)
20162 + r8153_u1u2en(tp, 0);
20163 + r8153_power_cut_en(tp, 0);
20164 + r8153_disable_aldps(tp);
20165 + r8153_enter_oob(tp);
20166 + r8153_enable_aldps(tp);
20169 +static void set_carrier(struct r8152 *tp)
20171 + struct net_device *netdev = tp->netdev;
20174 + clear_bit(RTL8152_LINK_CHG, &tp->flags);
20175 + speed = rtl8152_get_speed(tp);
20177 + if (speed & LINK_STATUS) {
20178 + if (!(tp->speed & LINK_STATUS)) {
20179 + tp->rtl_ops.enable(tp);
20180 + set_bit(RTL8152_SET_RX_MODE, &tp->flags);
20181 + netif_carrier_on(netdev);
20184 + if (tp->speed & LINK_STATUS) {
20185 + netif_carrier_off(netdev);
20186 + tasklet_disable(&tp->tl);
20187 + tp->rtl_ops.disable(tp);
20188 + tasklet_enable(&tp->tl);
20191 + tp->speed = speed;
20194 +static void rtl_work_func_t(struct work_struct *work)
20196 + struct r8152 *tp = container_of(work, struct r8152, schedule.work);
20198 + if (!test_bit(WORK_ENABLE, &tp->flags))
20201 + if (test_bit(RTL8152_UNPLUG, &tp->flags))
20204 + if (test_bit(RTL8152_LINK_CHG, &tp->flags))
20207 + if (test_bit(RTL8152_SET_RX_MODE, &tp->flags))
20208 + _rtl8152_set_rx_mode(tp->netdev);
20214 +static int rtl8152_open(struct net_device *netdev)
20216 + struct r8152 *tp = netdev_priv(netdev);
20219 + rtl8152_set_speed(tp, AUTONEG_ENABLE,
20220 + tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
20223 + netif_carrier_off(netdev);
20224 + netif_start_queue(netdev);
20225 + set_bit(WORK_ENABLE, &tp->flags);
20226 + res = usb_submit_urb(tp->intr_urb, GFP_KERNEL);
20228 + if (res == -ENODEV)
20229 + netif_device_detach(tp->netdev);
20230 + netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n",
20238 +static int rtl8152_close(struct net_device *netdev)
20240 + struct r8152 *tp = netdev_priv(netdev);
20243 + clear_bit(WORK_ENABLE, &tp->flags);
20244 + usb_kill_urb(tp->intr_urb);
20245 + cancel_delayed_work_sync(&tp->schedule);
20246 + netif_stop_queue(netdev);
20247 + tasklet_disable(&tp->tl);
20248 + tp->rtl_ops.disable(tp);
20249 + tasklet_enable(&tp->tl);
20254 +static void rtl_clear_bp(struct r8152 *tp)
20256 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_0, 0);
20257 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_2, 0);
20258 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_4, 0);
20259 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_BP_6, 0);
20260 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_0, 0);
20261 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_2, 0);
20262 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_4, 0);
20263 + ocp_write_dword(tp, MCU_TYPE_USB, USB_BP_6, 0);
20265 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_BP_BA, 0);
20266 + ocp_write_word(tp, MCU_TYPE_USB, USB_BP_BA, 0);
20269 +static void r8153_clear_bp(struct r8152 *tp)
20271 + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
20272 + ocp_write_byte(tp, MCU_TYPE_USB, USB_BP_EN, 0);
20273 + rtl_clear_bp(tp);
20276 +static void r8152b_enable_eee(struct r8152 *tp)
20280 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR);
20281 + ocp_data |= EEE_RX_EN | EEE_TX_EN;
20282 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data);
20283 + ocp_reg_write(tp, OCP_EEE_CONFIG1, RG_TXLPI_MSK_HFDUP | RG_MATCLR_EN |
20284 + EEE_10_CAP | EEE_NWAY_EN |
20285 + TX_QUIET_EN | RX_QUIET_EN |
20286 + SDRISETIME | RG_RXLPI_MSK_HFDUP |
20288 + ocp_reg_write(tp, OCP_EEE_CONFIG2, RG_LPIHYS_NUM | RG_DACQUIET_EN |
20289 + RG_LDVQUIET_EN | RG_CKRSEL |
20291 + ocp_reg_write(tp, OCP_EEE_CONFIG3, FST_SNR_EYE_R | RG_LFS_SEL | MSK_PH);
20292 + ocp_reg_write(tp, OCP_EEE_AR, FUN_ADDR | DEVICE_ADDR);
20293 + ocp_reg_write(tp, OCP_EEE_DATA, EEE_ADDR);
20294 + ocp_reg_write(tp, OCP_EEE_AR, FUN_DATA | DEVICE_ADDR);
20295 + ocp_reg_write(tp, OCP_EEE_DATA, EEE_DATA);
20296 + ocp_reg_write(tp, OCP_EEE_AR, 0x0000);
20299 +static void r8153_enable_eee(struct r8152 *tp)
20304 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EEE_CR);
20305 + ocp_data |= EEE_RX_EN | EEE_TX_EN;
20306 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_EEE_CR, ocp_data);
20307 + data = ocp_reg_read(tp, OCP_EEE_CFG);
20308 + data |= EEE10_EN;
20309 + ocp_reg_write(tp, OCP_EEE_CFG, data);
20310 + data = ocp_reg_read(tp, OCP_EEE_CFG2);
20311 + data |= MY1000_EEE | MY100_EEE;
20312 + ocp_reg_write(tp, OCP_EEE_CFG2, data);
20315 +static void r8152b_enable_fc(struct r8152 *tp)
20319 + anar = r8152_mdio_read(tp, MII_ADVERTISE);
20320 + anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
20321 + r8152_mdio_write(tp, MII_ADVERTISE, anar);
20324 +static void r8152b_hw_phy_cfg(struct r8152 *tp)
20326 + r8152_mdio_write(tp, MII_BMCR, BMCR_ANENABLE);
20327 + r8152b_disable_aldps(tp);
20330 +static void r8152b_init(struct r8152 *tp)
20335 + rtl_clear_bp(tp);
20337 + if (tp->version == RTL_VER_01) {
20338 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
20339 + ocp_data &= ~LED_MODE_MASK;
20340 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
20343 + r8152b_hw_phy_cfg(tp);
20345 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20346 + ocp_data &= ~POWER_CUT;
20347 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20349 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
20350 + ocp_data &= ~RESUME_INDICATE;
20351 + ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
20353 + r8152b_exit_oob(tp);
20355 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
20356 + ocp_data |= TX_10M_IDLE_EN | PFM_PWM_SWITCH;
20357 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
20358 + ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL);
20359 + ocp_data &= ~MCU_CLK_RATIO_MASK;
20360 + ocp_data |= MCU_CLK_RATIO | D3_CLK_GATED_EN;
20361 + ocp_write_dword(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ocp_data);
20362 + ocp_data = GPHY_STS_MSK | SPEED_DOWN_MSK |
20363 + SPDWN_RXDV_MSK | SPDWN_LINKCHG_MSK;
20364 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_GPHY_INTR_IMR, ocp_data);
20366 + r8152b_enable_eee(tp);
20367 + r8152b_enable_aldps(tp);
20368 + r8152b_enable_fc(tp);
20370 + r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
20372 + for (i = 0; i < 100; i++) {
20374 + if (!(r8152_mdio_read(tp, MII_BMCR) & BMCR_RESET))
20378 + /* enable rx aggregation */
20379 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
20380 + ocp_data &= ~RX_AGG_DISABLE;
20381 + ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
20384 +static void r8153_init(struct r8152 *tp)
20389 + r8153_u1u2en(tp, 0);
20391 + for (i = 0; i < 500; i++) {
20392 + if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) &
20398 + for (i = 0; i < 500; i++) {
20399 + ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
20400 + if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
20405 + r8153_u2p3en(tp, 0);
20407 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL);
20408 + ocp_data &= ~TIMER11_EN;
20409 + ocp_write_word(tp, MCU_TYPE_USB, USB_WDT11_CTRL, ocp_data);
20411 + r8153_clear_bp(tp);
20413 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE);
20414 + ocp_data &= ~LED_MODE_MASK;
20415 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_LED_FEATURE, ocp_data);
20417 + ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL);
20418 + ocp_data &= ~LPM_TIMER_MASK;
20419 + if (tp->udev->speed == USB_SPEED_SUPER)
20420 + ocp_data |= LPM_TIMER_500US;
20422 + ocp_data |= LPM_TIMER_500MS;
20423 + ocp_write_byte(tp, MCU_TYPE_USB, USB_LPM_CTRL, ocp_data);
20425 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2);
20426 + ocp_data &= ~SEN_VAL_MASK;
20427 + ocp_data |= SEN_VAL_NORMAL | SEL_RXIDLE;
20428 + ocp_write_word(tp, MCU_TYPE_USB, USB_AFE_CTRL2, ocp_data);
20430 + r8153_power_cut_en(tp, 0);
20431 + r8153_u1u2en(tp, 1);
20433 + r8153_first_init(tp);
20435 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, ALDPS_SPDWN_RATIO);
20436 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, EEE_SPDWN_RATIO);
20437 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
20438 + PKT_AVAIL_SPDWN_EN | SUSPEND_SPDWN_EN |
20439 + U1U2_SPDWN_EN | L1_SPDWN_EN);
20440 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
20441 + PWRSAVE_SPDWN_EN | RXDV_SPDWN_EN | TX10MIDLE_EN |
20442 + TP100_SPDWN_EN | TP500_SPDWN_EN | TP1000_SPDWN_EN |
20445 + r8153_enable_eee(tp);
20446 + r8153_enable_aldps(tp);
20447 + r8152b_enable_fc(tp);
20449 + r8152_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE |
20453 +static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
20455 + struct r8152 *tp = usb_get_intfdata(intf);
20457 + netif_device_detach(tp->netdev);
20459 + if (netif_running(tp->netdev)) {
20460 + clear_bit(WORK_ENABLE, &tp->flags);
20461 + usb_kill_urb(tp->intr_urb);
20462 + cancel_delayed_work_sync(&tp->schedule);
20463 + tasklet_disable(&tp->tl);
20466 + tp->rtl_ops.down(tp);
20471 +static int rtl8152_resume(struct usb_interface *intf)
20473 + struct r8152 *tp = usb_get_intfdata(intf);
20475 + tp->rtl_ops.init(tp);
20476 + netif_device_attach(tp->netdev);
20477 + if (netif_running(tp->netdev)) {
20478 + rtl8152_set_speed(tp, AUTONEG_ENABLE,
20479 + tp->mii.supports_gmii ? SPEED_1000 : SPEED_100,
20482 + netif_carrier_off(tp->netdev);
20483 + set_bit(WORK_ENABLE, &tp->flags);
20484 + usb_submit_urb(tp->intr_urb, GFP_KERNEL);
20485 + tasklet_enable(&tp->tl);
20491 +static void rtl8152_get_drvinfo(struct net_device *netdev,
20492 + struct ethtool_drvinfo *info)
20494 + struct r8152 *tp = netdev_priv(netdev);
20496 + strncpy(info->driver, MODULENAME, ETHTOOL_BUSINFO_LEN);
20497 + strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
20498 + usb_make_path(tp->udev, info->bus_info, sizeof(info->bus_info));
20502 +int rtl8152_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
20504 + struct r8152 *tp = netdev_priv(netdev);
20506 + if (!tp->mii.mdio_read)
20507 + return -EOPNOTSUPP;
20509 + return mii_ethtool_gset(&tp->mii, cmd);
20512 +static int rtl8152_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
20514 + struct r8152 *tp = netdev_priv(dev);
20516 + return rtl8152_set_speed(tp, cmd->autoneg, cmd->speed, cmd->duplex);
20519 +static struct ethtool_ops ops = {
20520 + .get_drvinfo = rtl8152_get_drvinfo,
20521 + .get_settings = rtl8152_get_settings,
20522 + .set_settings = rtl8152_set_settings,
20523 + .get_link = ethtool_op_get_link,
20526 +static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
20528 + struct r8152 *tp = netdev_priv(netdev);
20529 + struct mii_ioctl_data *data = if_mii(rq);
20533 + case SIOCGMIIPHY:
20534 + data->phy_id = R8152_PHY_ID; /* Internal PHY */
20537 + case SIOCGMIIREG:
20538 + data->val_out = r8152_mdio_read(tp, data->reg_num);
20541 + case SIOCSMIIREG:
20542 + if (!capable(CAP_NET_ADMIN)) {
20546 + r8152_mdio_write(tp, data->reg_num, data->val_in);
20550 + res = -EOPNOTSUPP;
20556 +static const struct net_device_ops rtl8152_netdev_ops = {
20557 + .ndo_open = rtl8152_open,
20558 + .ndo_stop = rtl8152_close,
20559 + .ndo_do_ioctl = rtl8152_ioctl,
20560 + .ndo_start_xmit = rtl8152_start_xmit,
20561 + .ndo_tx_timeout = rtl8152_tx_timeout,
20562 + .ndo_set_rx_mode = rtl8152_set_rx_mode,
20563 + .ndo_set_mac_address = rtl8152_set_mac_address,
20565 + .ndo_change_mtu = eth_change_mtu,
20566 + .ndo_validate_addr = eth_validate_addr,
20569 +static void r8152b_get_version(struct r8152 *tp)
20574 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1);
20575 + version = (u16)(ocp_data & VERSION_MASK);
20577 + switch (version) {
20579 + tp->version = RTL_VER_01;
20582 + tp->version = RTL_VER_02;
20585 + tp->version = RTL_VER_03;
20586 + tp->mii.supports_gmii = 1;
20589 + tp->version = RTL_VER_04;
20590 + tp->mii.supports_gmii = 1;
20593 + tp->version = RTL_VER_05;
20594 + tp->mii.supports_gmii = 1;
20597 + netif_info(tp, probe, tp->netdev,
20598 + "Unknown version 0x%04x\n", version);
20603 +static void rtl8152_unload(struct r8152 *tp)
20607 + if (tp->version != RTL_VER_01) {
20608 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_UPS_CTRL);
20609 + ocp_data |= POWER_CUT;
20610 + ocp_write_word(tp, MCU_TYPE_USB, USB_UPS_CTRL, ocp_data);
20613 + ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS);
20614 + ocp_data &= ~RESUME_INDICATE;
20615 + ocp_write_word(tp, MCU_TYPE_USB, USB_PM_CTRL_STATUS, ocp_data);
20618 +static void rtl8153_unload(struct r8152 *tp)
20620 + r8153_power_cut_en(tp, 1);
20623 +static int rtl_ops_init(struct r8152 *tp, const struct usb_device_id *id)
20625 + struct rtl_ops *ops = &tp->rtl_ops;
20626 + int ret = -ENODEV;
20628 + switch (id->idVendor) {
20629 + case VENDOR_ID_REALTEK:
20630 + switch (id->idProduct) {
20631 + case PRODUCT_ID_RTL8152:
20632 + ops->init = r8152b_init;
20633 + ops->enable = rtl8152_enable;
20634 + ops->disable = rtl8152_disable;
20635 + ops->down = rtl8152_down;
20636 + ops->unload = rtl8152_unload;
20639 + case PRODUCT_ID_RTL8153:
20640 + ops->init = r8153_init;
20641 + ops->enable = rtl8153_enable;
20642 + ops->disable = rtl8152_disable;
20643 + ops->down = rtl8153_down;
20644 + ops->unload = rtl8153_unload;
20652 + case VENDOR_ID_SAMSUNG:
20653 + switch (id->idProduct) {
20654 + case PRODUCT_ID_SAMSUNG:
20655 + ops->init = r8153_init;
20656 + ops->enable = rtl8153_enable;
20657 + ops->disable = rtl8152_disable;
20658 + ops->down = rtl8153_down;
20659 + ops->unload = rtl8153_unload;
20672 + netif_err(tp, probe, tp->netdev, "Unknown Device\n");
20677 +static int rtl8152_probe(struct usb_interface *intf,
20678 + const struct usb_device_id *id)
20680 + struct usb_device *udev = interface_to_usbdev(intf);
20681 + struct r8152 *tp;
20682 + struct net_device *netdev;
20685 + if (udev->actconfig->desc.bConfigurationValue != 1) {
20686 + usb_driver_set_configuration(udev, 1);
20690 + usb_reset_device(udev);
20691 + netdev = alloc_etherdev(sizeof(struct r8152));
20693 + dev_err(&intf->dev, "Out of memory\n");
20697 + SET_NETDEV_DEV(netdev, &intf->dev);
20698 + tp = netdev_priv(netdev);
20699 + tp->msg_enable = 0x7FFF;
20702 + tp->netdev = netdev;
20705 + ret = rtl_ops_init(tp, id);
20709 + tasklet_init(&tp->tl, bottom_half, (unsigned long)tp);
20710 + INIT_DELAYED_WORK(&tp->schedule, rtl_work_func_t);
20712 + netdev->netdev_ops = &rtl8152_netdev_ops;
20713 + netdev->watchdog_timeo = RTL8152_TX_TIMEOUT;
20715 + netdev->features |= NETIF_F_IP_CSUM;
20716 + netdev->hw_features = NETIF_F_IP_CSUM;
20717 + SET_ETHTOOL_OPS(netdev, &ops);
20719 + tp->mii.dev = netdev;
20720 + tp->mii.mdio_read = read_mii_word;
20721 + tp->mii.mdio_write = write_mii_word;
20722 + tp->mii.phy_id_mask = 0x3f;
20723 + tp->mii.reg_num_mask = 0x1f;
20724 + tp->mii.phy_id = R8152_PHY_ID;
20725 + tp->mii.supports_gmii = 0;
20727 + r8152b_get_version(tp);
20728 + tp->rtl_ops.init(tp);
20729 + set_ethernet_addr(tp);
20731 + ret = alloc_all_mem(tp);
20735 + usb_set_intfdata(intf, tp);
20737 + ret = register_netdev(netdev);
20739 + netif_err(tp, probe, netdev, "couldn't register the device\n");
20743 + netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION);
20748 + usb_set_intfdata(intf, NULL);
20750 + free_netdev(netdev);
20754 +static void rtl8152_disconnect(struct usb_interface *intf)
20756 + struct r8152 *tp = usb_get_intfdata(intf);
20758 + usb_set_intfdata(intf, NULL);
20760 + set_bit(RTL8152_UNPLUG, &tp->flags);
20761 + tasklet_kill(&tp->tl);
20762 + unregister_netdev(tp->netdev);
20763 + tp->rtl_ops.unload(tp);
20764 + free_all_mem(tp);
20765 + free_netdev(tp->netdev);
20769 +/* table of devices that work with this driver */
20770 +static struct usb_device_id rtl8152_table[] = {
20771 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)},
20772 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)},
20773 + {USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)},
20774 + {USB_DEVICE(VENDOR_ID_LENOVO, PRODUCT_ID_LENOVO)},
20775 + {USB_DEVICE(VENDOR_ID_NVIDIA, PRODUCT_ID_NVIDIA)},
20779 +MODULE_DEVICE_TABLE(usb, rtl8152_table);
20781 +static struct usb_driver rtl8152_driver = {
20782 + .name = MODULENAME,
20783 + .id_table = rtl8152_table,
20784 + .probe = rtl8152_probe,
20785 + .disconnect = rtl8152_disconnect,
20786 + .suspend = rtl8152_suspend,
20787 + .resume = rtl8152_resume,
20788 + .reset_resume = rtl8152_resume,
20791 +module_usb_driver(rtl8152_driver);
20793 +MODULE_AUTHOR(DRIVER_AUTHOR);
20794 +MODULE_DESCRIPTION(DRIVER_DESC);
20795 +MODULE_LICENSE("GPL");
20796 diff -Naur backports-4.2.6-1.org/drivers/net/usb/rtl8150.c backports-4.2.6-1/drivers/net/usb/rtl8150.c
20797 --- backports-4.2.6-1.org/drivers/net/usb/rtl8150.c 1970-01-01 01:00:00.000000000 +0100
20798 +++ backports-4.2.6-1/drivers/net/usb/rtl8150.c 2016-06-28 14:35:18.001973885 +0200
20801 + * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
20803 + * This program is free software; you can redistribute it and/or
20804 + * modify it under the terms of the GNU General Public License
20805 + * version 2 as published by the Free Software Foundation.
20808 +#include <linux/signal.h>
20809 +#include <linux/slab.h>
20810 +#include <linux/module.h>
20811 +#include <linux/netdevice.h>
20812 +#include <linux/etherdevice.h>
20813 +#include <linux/mii.h>
20814 +#include <linux/ethtool.h>
20815 +#include <linux/usb.h>
20816 +#include <asm/uaccess.h>
20818 +/* Version Information */
20819 +#define DRIVER_VERSION "v0.6.2 (2004/08/27)"
20820 +#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
20821 +#define DRIVER_DESC "rtl8150 based usb-ethernet driver"
20823 +#define IDR 0x0120
20824 +#define MAR 0x0126
20826 +#define TCR 0x012f
20827 +#define RCR 0x0130
20828 +#define TSR 0x0132
20829 +#define RSR 0x0133
20830 +#define CON0 0x0135
20831 +#define CON1 0x0136
20832 +#define MSR 0x0137
20833 +#define PHYADD 0x0138
20834 +#define PHYDAT 0x0139
20835 +#define PHYCNT 0x013b
20836 +#define GPPC 0x013d
20837 +#define BMCR 0x0140
20838 +#define BMSR 0x0142
20839 +#define ANAR 0x0144
20840 +#define ANLP 0x0146
20841 +#define AER 0x0148
20842 +#define CSCR 0x014C /* This one has the link status */
20843 +#define CSCR_LINK_STATUS (1 << 3)
20845 +#define IDR_EEPROM 0x1202
20847 +#define PHY_READ 0
20848 +#define PHY_WRITE 0x20
20849 +#define PHY_GO 0x40
20851 +#define MII_TIMEOUT 10
20852 +#define INTBUFSIZE 8
20854 +#define RTL8150_REQT_READ 0xc0
20855 +#define RTL8150_REQT_WRITE 0x40
20856 +#define RTL8150_REQ_GET_REGS 0x05
20857 +#define RTL8150_REQ_SET_REGS 0x05
20860 +/* Transmit status register errors */
20861 +#define TSR_ECOL (1<<5)
20862 +#define TSR_LCOL (1<<4)
20863 +#define TSR_LOSS_CRS (1<<3)
20864 +#define TSR_JBR (1<<2)
20865 +#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
20866 +/* Receive status register errors */
20867 +#define RSR_CRC (1<<2)
20868 +#define RSR_FAE (1<<1)
20869 +#define RSR_ERRORS (RSR_CRC | RSR_FAE)
20871 +/* Media status register definitions */
20872 +#define MSR_DUPLEX (1<<4)
20873 +#define MSR_SPEED (1<<3)
20874 +#define MSR_LINK (1<<2)
20876 +/* Interrupt pipe data */
20877 +#define INT_TSR 0x00
20878 +#define INT_RSR 0x01
20879 +#define INT_MSR 0x02
20880 +#define INT_WAKSR 0x03
20881 +#define INT_TXOK_CNT 0x04
20882 +#define INT_RXLOST_CNT 0x05
20883 +#define INT_CRERR_CNT 0x06
20884 +#define INT_COL_CNT 0x07
20887 +#define RTL8150_MTU 1540
20888 +#define RTL8150_TX_TIMEOUT (HZ)
20889 +#define RX_SKB_POOL_SIZE 4
20891 +/* rtl8150 flags */
20892 +#define RTL8150_HW_CRC 0
20893 +#define RX_REG_SET 1
20894 +#define RTL8150_UNPLUG 2
20895 +#define RX_URB_FAIL 3
20897 +/* Define these values to match your device */
20898 +#define VENDOR_ID_REALTEK 0x0bda
20899 +#define VENDOR_ID_MELCO 0x0411
20900 +#define VENDOR_ID_MICRONET 0x3980
20901 +#define VENDOR_ID_LONGSHINE 0x07b8
20902 +#define VENDOR_ID_OQO 0x1557
20903 +#define VENDOR_ID_ZYXEL 0x0586
20905 +#define PRODUCT_ID_RTL8150 0x8150
20906 +#define PRODUCT_ID_LUAKTX 0x0012
20907 +#define PRODUCT_ID_LCS8138TX 0x401a
20908 +#define PRODUCT_ID_SP128AR 0x0003
20909 +#define PRODUCT_ID_PRESTIGE 0x401a
20911 +#undef EEPROM_WRITE
20913 +/* table of devices that work with this driver */
20914 +static struct usb_device_id rtl8150_table[] = {
20915 + {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
20916 + {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
20917 + {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
20918 + {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
20919 + {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
20920 + {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
20924 +MODULE_DEVICE_TABLE(usb, rtl8150_table);
20927 + unsigned long flags;
20928 + struct usb_device *udev;
20929 + struct tasklet_struct tl;
20930 + struct net_device *netdev;
20931 + struct urb *rx_urb, *tx_urb, *intr_urb;
20932 + struct sk_buff *tx_skb, *rx_skb;
20933 + struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
20934 + spinlock_t rx_pool_lock;
20935 + struct usb_ctrlrequest dr;
20936 + int intr_interval;
20941 +typedef struct rtl8150 rtl8150_t;
20943 +struct async_req {
20944 + struct usb_ctrlrequest dr;
20948 +static const char driver_name [] = "rtl8150";
20952 +** device related part of the code
20955 +static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
20957 + return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
20958 + RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
20959 + indx, 0, data, size, 500);
20962 +static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
20964 + return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
20965 + RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
20966 + indx, 0, data, size, 500);
20969 +static void async_set_reg_cb(struct urb *urb)
20971 + struct async_req *req = (struct async_req *)urb->context;
20972 + int status = urb->status;
20975 + dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
20977 + usb_free_urb(urb);
20980 +static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
20982 + int res = -ENOMEM;
20983 + struct urb *async_urb;
20984 + struct async_req *req;
20986 + req = kmalloc(sizeof(struct async_req), GFP_ATOMIC);
20989 + async_urb = usb_alloc_urb(0, GFP_ATOMIC);
20990 + if (async_urb == NULL) {
20994 + req->rx_creg = cpu_to_le16(reg);
20995 + req->dr.bRequestType = RTL8150_REQT_WRITE;
20996 + req->dr.bRequest = RTL8150_REQ_SET_REGS;
20997 + req->dr.wIndex = 0;
20998 + req->dr.wValue = cpu_to_le16(indx);
20999 + req->dr.wLength = cpu_to_le16(size);
21000 + usb_fill_control_urb(async_urb, dev->udev,
21001 + usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr,
21002 + &req->rx_creg, size, async_set_reg_cb, req);
21003 + res = usb_submit_urb(async_urb, GFP_ATOMIC);
21005 + if (res == -ENODEV)
21006 + netif_device_detach(dev->netdev);
21007 + dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
21012 +static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
21018 + data[1] = data[2] = 0;
21019 + tmp = indx | PHY_READ | PHY_GO;
21022 + set_registers(dev, PHYADD, sizeof(data), data);
21023 + set_registers(dev, PHYCNT, 1, &tmp);
21025 + get_registers(dev, PHYCNT, 1, data);
21026 + } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
21028 + if (i <= MII_TIMEOUT) {
21029 + get_registers(dev, PHYDAT, 2, data);
21030 + *reg = data[0] | (data[1] << 8);
21036 +static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
21042 + data[1] = reg & 0xff;
21043 + data[2] = (reg >> 8) & 0xff;
21044 + tmp = indx | PHY_WRITE | PHY_GO;
21047 + set_registers(dev, PHYADD, sizeof(data), data);
21048 + set_registers(dev, PHYCNT, 1, &tmp);
21050 + get_registers(dev, PHYCNT, 1, data);
21051 + } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
21053 + if (i <= MII_TIMEOUT)
21059 +static inline void set_ethernet_addr(rtl8150_t * dev)
21063 + get_registers(dev, IDR, sizeof(node_id), node_id);
21064 + memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
21067 +static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
21069 + struct sockaddr *addr = p;
21070 + rtl8150_t *dev = netdev_priv(netdev);
21072 + if (netif_running(netdev))
21075 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
21076 + netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr);
21077 + /* Set the IDR registers. */
21078 + set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
21079 +#ifdef EEPROM_WRITE
21083 + /* Get the CR contents. */
21084 + get_registers(dev, CR, 1, &cr);
21085 + /* Set the WEPROM bit (eeprom write enable). */
21087 + set_registers(dev, CR, 1, &cr);
21088 + /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
21089 + so we need to split them up. */
21090 + for (i = 0; i * 2 < netdev->addr_len; i++) {
21091 + set_registers(dev, IDR_EEPROM + (i * 2), 2,
21092 + netdev->dev_addr + (i * 2));
21094 + /* Clear the WEPROM bit (preventing accidental eeprom writes). */
21096 + set_registers(dev, CR, 1, &cr);
21102 +static int rtl8150_reset(rtl8150_t * dev)
21107 + set_registers(dev, CR, 1, &data);
21109 + get_registers(dev, CR, 1, &data);
21110 + } while ((data & 0x10) && --i);
21112 + return (i > 0) ? 1 : 0;
21115 +static int alloc_all_urbs(rtl8150_t * dev)
21117 + dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
21118 + if (!dev->rx_urb)
21120 + dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
21121 + if (!dev->tx_urb) {
21122 + usb_free_urb(dev->rx_urb);
21125 + dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
21126 + if (!dev->intr_urb) {
21127 + usb_free_urb(dev->rx_urb);
21128 + usb_free_urb(dev->tx_urb);
21135 +static void free_all_urbs(rtl8150_t * dev)
21137 + usb_free_urb(dev->rx_urb);
21138 + usb_free_urb(dev->tx_urb);
21139 + usb_free_urb(dev->intr_urb);
21142 +static void unlink_all_urbs(rtl8150_t * dev)
21144 + usb_kill_urb(dev->rx_urb);
21145 + usb_kill_urb(dev->tx_urb);
21146 + usb_kill_urb(dev->intr_urb);
21149 +static inline struct sk_buff *pull_skb(rtl8150_t *dev)
21151 + struct sk_buff *skb;
21154 + for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
21155 + if (dev->rx_skb_pool[i]) {
21156 + skb = dev->rx_skb_pool[i];
21157 + dev->rx_skb_pool[i] = NULL;
21164 +static void read_bulk_callback(struct urb *urb)
21167 + unsigned pkt_len, res;
21168 + struct sk_buff *skb;
21169 + struct net_device *netdev;
21171 + int status = urb->status;
21174 + dev = urb->context;
21177 + if (test_bit(RTL8150_UNPLUG, &dev->flags))
21179 + netdev = dev->netdev;
21180 + if (!netif_device_present(netdev))
21183 + switch (status) {
21187 + return; /* the urb is in unlink state */
21189 + if (printk_ratelimit())
21190 + dev_warn(&urb->dev->dev, "may be reset is needed?..\n");
21193 + if (printk_ratelimit())
21194 + dev_warn(&urb->dev->dev, "Rx status %d\n", status);
21198 + if (!dev->rx_skb)
21200 + /* protect against short packets (tell me why we got some?!?) */
21201 + if (urb->actual_length < 4)
21204 + res = urb->actual_length;
21205 + rx_stat = le16_to_cpu(*(__le16 *)(urb->transfer_buffer + res - 4));
21206 + pkt_len = res - 4;
21208 + skb_put(dev->rx_skb, pkt_len);
21209 + dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
21210 + netif_rx(dev->rx_skb);
21211 + netdev->stats.rx_packets++;
21212 + netdev->stats.rx_bytes += pkt_len;
21214 + spin_lock(&dev->rx_pool_lock);
21215 + skb = pull_skb(dev);
21216 + spin_unlock(&dev->rx_pool_lock);
21220 + dev->rx_skb = skb;
21222 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21223 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21224 + result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
21225 + if (result == -ENODEV)
21226 + netif_device_detach(dev->netdev);
21227 + else if (result) {
21228 + set_bit(RX_URB_FAIL, &dev->flags);
21231 + clear_bit(RX_URB_FAIL, &dev->flags);
21236 + tasklet_schedule(&dev->tl);
21239 +static void write_bulk_callback(struct urb *urb)
21242 + int status = urb->status;
21244 + dev = urb->context;
21247 + dev_kfree_skb_irq(dev->tx_skb);
21248 + if (!netif_device_present(dev->netdev))
21251 + dev_info(&urb->dev->dev, "%s: Tx status %d\n",
21252 + dev->netdev->name, status);
21253 + dev->netdev->trans_start = jiffies;
21254 + netif_wake_queue(dev->netdev);
21257 +static void intr_callback(struct urb *urb)
21261 + int status = urb->status;
21264 + dev = urb->context;
21267 + switch (status) {
21268 + case 0: /* success */
21270 + case -ECONNRESET: /* unlink */
21274 + /* -EPIPE: should clear the halt */
21276 + dev_info(&urb->dev->dev, "%s: intr status %d\n",
21277 + dev->netdev->name, status);
21281 + d = urb->transfer_buffer;
21282 + if (d[0] & TSR_ERRORS) {
21283 + dev->netdev->stats.tx_errors++;
21284 + if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
21285 + dev->netdev->stats.tx_aborted_errors++;
21286 + if (d[INT_TSR] & TSR_LCOL)
21287 + dev->netdev->stats.tx_window_errors++;
21288 + if (d[INT_TSR] & TSR_LOSS_CRS)
21289 + dev->netdev->stats.tx_carrier_errors++;
21291 + /* Report link status changes to the network stack */
21292 + if ((d[INT_MSR] & MSR_LINK) == 0) {
21293 + if (netif_carrier_ok(dev->netdev)) {
21294 + netif_carrier_off(dev->netdev);
21295 + netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__);
21298 + if (!netif_carrier_ok(dev->netdev)) {
21299 + netif_carrier_on(dev->netdev);
21300 + netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__);
21305 + res = usb_submit_urb (urb, GFP_ATOMIC);
21306 + if (res == -ENODEV)
21307 + netif_device_detach(dev->netdev);
21309 + dev_err(&dev->udev->dev,
21310 + "can't resubmit intr, %s-%s/input0, status %d\n",
21311 + dev->udev->bus->bus_name, dev->udev->devpath, res);
21314 +static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
21316 + rtl8150_t *dev = usb_get_intfdata(intf);
21318 + netif_device_detach(dev->netdev);
21320 + if (netif_running(dev->netdev)) {
21321 + usb_kill_urb(dev->rx_urb);
21322 + usb_kill_urb(dev->intr_urb);
21327 +static int rtl8150_resume(struct usb_interface *intf)
21329 + rtl8150_t *dev = usb_get_intfdata(intf);
21331 + netif_device_attach(dev->netdev);
21332 + if (netif_running(dev->netdev)) {
21333 + dev->rx_urb->status = 0;
21334 + dev->rx_urb->actual_length = 0;
21335 + read_bulk_callback(dev->rx_urb);
21337 + dev->intr_urb->status = 0;
21338 + dev->intr_urb->actual_length = 0;
21339 + intr_callback(dev->intr_urb);
21346 +** network related part of the code
21350 +static void fill_skb_pool(rtl8150_t *dev)
21352 + struct sk_buff *skb;
21355 + for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
21356 + if (dev->rx_skb_pool[i])
21358 + skb = dev_alloc_skb(RTL8150_MTU + 2);
21362 + skb_reserve(skb, 2);
21363 + dev->rx_skb_pool[i] = skb;
21367 +static void free_skb_pool(rtl8150_t *dev)
21371 + for (i = 0; i < RX_SKB_POOL_SIZE; i++)
21372 + if (dev->rx_skb_pool[i])
21373 + dev_kfree_skb(dev->rx_skb_pool[i]);
21376 +static void rx_fixup(unsigned long data)
21378 + struct rtl8150 *dev = (struct rtl8150 *)data;
21379 + struct sk_buff *skb;
21382 + spin_lock_irq(&dev->rx_pool_lock);
21383 + fill_skb_pool(dev);
21384 + spin_unlock_irq(&dev->rx_pool_lock);
21385 + if (test_bit(RX_URB_FAIL, &dev->flags))
21388 + spin_lock_irq(&dev->rx_pool_lock);
21389 + skb = pull_skb(dev);
21390 + spin_unlock_irq(&dev->rx_pool_lock);
21393 + dev->rx_skb = skb;
21394 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21395 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21397 + status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
21398 + if (status == -ENODEV) {
21399 + netif_device_detach(dev->netdev);
21400 + } else if (status) {
21401 + set_bit(RX_URB_FAIL, &dev->flags);
21404 + clear_bit(RX_URB_FAIL, &dev->flags);
21409 + tasklet_schedule(&dev->tl);
21412 +static int enable_net_traffic(rtl8150_t * dev)
21414 + u8 cr, tcr, rcr, msr;
21416 + if (!rtl8150_reset(dev)) {
21417 + dev_warn(&dev->udev->dev, "device reset failed\n");
21419 + /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
21423 + if (!(rcr & 0x80))
21424 + set_bit(RTL8150_HW_CRC, &dev->flags);
21425 + set_registers(dev, RCR, 1, &rcr);
21426 + set_registers(dev, TCR, 1, &tcr);
21427 + set_registers(dev, CR, 1, &cr);
21428 + get_registers(dev, MSR, 1, &msr);
21433 +static void disable_net_traffic(rtl8150_t * dev)
21437 + get_registers(dev, CR, 1, &cr);
21439 + set_registers(dev, CR, 1, &cr);
21442 +static void rtl8150_tx_timeout(struct net_device *netdev)
21444 + rtl8150_t *dev = netdev_priv(netdev);
21445 + dev_warn(&netdev->dev, "Tx timeout.\n");
21446 + usb_unlink_urb(dev->tx_urb);
21447 + netdev->stats.tx_errors++;
21450 +static void rtl8150_set_multicast(struct net_device *netdev)
21452 + rtl8150_t *dev = netdev_priv(netdev);
21453 + u16 rx_creg = 0x9e;
21455 + netif_stop_queue(netdev);
21456 + if (netdev->flags & IFF_PROMISC) {
21457 + rx_creg |= 0x0001;
21458 + dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name);
21459 + } else if (!netdev_mc_empty(netdev) ||
21460 + (netdev->flags & IFF_ALLMULTI)) {
21461 + rx_creg &= 0xfffe;
21462 + rx_creg |= 0x0002;
21463 + dev_info(&netdev->dev, "%s: allmulti set\n", netdev->name);
21465 + /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
21466 + rx_creg &= 0x00fc;
21468 + async_set_registers(dev, RCR, sizeof(rx_creg), rx_creg);
21469 + netif_wake_queue(netdev);
21472 +static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
21473 + struct net_device *netdev)
21475 + rtl8150_t *dev = netdev_priv(netdev);
21478 + netif_stop_queue(netdev);
21479 + count = (skb->len < 60) ? 60 : skb->len;
21480 + count = (count & 0x3f) ? count : count + 1;
21481 + dev->tx_skb = skb;
21482 + usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
21483 + skb->data, count, write_bulk_callback, dev);
21484 + if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
21485 + /* Can we get/handle EPIPE here? */
21486 + if (res == -ENODEV)
21487 + netif_device_detach(dev->netdev);
21489 + dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
21490 + netdev->stats.tx_errors++;
21491 + netif_start_queue(netdev);
21494 + netdev->stats.tx_packets++;
21495 + netdev->stats.tx_bytes += skb->len;
21496 + netdev->trans_start = jiffies;
21499 + return NETDEV_TX_OK;
21503 +static void set_carrier(struct net_device *netdev)
21505 + rtl8150_t *dev = netdev_priv(netdev);
21508 + get_registers(dev, CSCR, 2, &tmp);
21509 + if (tmp & CSCR_LINK_STATUS)
21510 + netif_carrier_on(netdev);
21512 + netif_carrier_off(netdev);
21515 +static int rtl8150_open(struct net_device *netdev)
21517 + rtl8150_t *dev = netdev_priv(netdev);
21520 + if (dev->rx_skb == NULL)
21521 + dev->rx_skb = pull_skb(dev);
21522 + if (!dev->rx_skb)
21525 + set_registers(dev, IDR, 6, netdev->dev_addr);
21527 + usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
21528 + dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
21529 + if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
21530 + if (res == -ENODEV)
21531 + netif_device_detach(dev->netdev);
21532 + dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
21535 + usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
21536 + dev->intr_buff, INTBUFSIZE, intr_callback,
21537 + dev, dev->intr_interval);
21538 + if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
21539 + if (res == -ENODEV)
21540 + netif_device_detach(dev->netdev);
21541 + dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
21542 + usb_kill_urb(dev->rx_urb);
21545 + enable_net_traffic(dev);
21546 + set_carrier(netdev);
21547 + netif_start_queue(netdev);
21552 +static int rtl8150_close(struct net_device *netdev)
21554 + rtl8150_t *dev = netdev_priv(netdev);
21556 + netif_stop_queue(netdev);
21557 + if (!test_bit(RTL8150_UNPLUG, &dev->flags))
21558 + disable_net_traffic(dev);
21559 + unlink_all_urbs(dev);
21564 +static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
21566 + rtl8150_t *dev = netdev_priv(netdev);
21568 + strlcpy(info->driver, driver_name, sizeof(info->driver));
21569 + strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
21570 + usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
21573 +static int rtl8150_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
21575 + rtl8150_t *dev = netdev_priv(netdev);
21578 + ecmd->supported = (SUPPORTED_10baseT_Half |
21579 + SUPPORTED_10baseT_Full |
21580 + SUPPORTED_100baseT_Half |
21581 + SUPPORTED_100baseT_Full |
21582 + SUPPORTED_Autoneg |
21583 + SUPPORTED_TP | SUPPORTED_MII);
21584 + ecmd->port = PORT_TP;
21585 + ecmd->transceiver = XCVR_INTERNAL;
21586 + ecmd->phy_address = dev->phy;
21587 + get_registers(dev, BMCR, 2, &bmcr);
21588 + get_registers(dev, ANLP, 2, &lpa);
21589 + if (bmcr & BMCR_ANENABLE) {
21590 + u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ?
21591 + SPEED_100 : SPEED_10);
21592 + ethtool_cmd_speed_set(ecmd, speed);
21593 + ecmd->autoneg = AUTONEG_ENABLE;
21594 + if (speed == SPEED_100)
21595 + ecmd->duplex = (lpa & LPA_100FULL) ?
21596 + DUPLEX_FULL : DUPLEX_HALF;
21598 + ecmd->duplex = (lpa & LPA_10FULL) ?
21599 + DUPLEX_FULL : DUPLEX_HALF;
21601 + ecmd->autoneg = AUTONEG_DISABLE;
21602 + ethtool_cmd_speed_set(ecmd, ((bmcr & BMCR_SPEED100) ?
21603 + SPEED_100 : SPEED_10));
21604 + ecmd->duplex = (bmcr & BMCR_FULLDPLX) ?
21605 + DUPLEX_FULL : DUPLEX_HALF;
21610 +static const struct ethtool_ops ops = {
21611 + .get_drvinfo = rtl8150_get_drvinfo,
21612 + .get_settings = rtl8150_get_settings,
21613 + .get_link = ethtool_op_get_link
21616 +static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
21618 + rtl8150_t *dev = netdev_priv(netdev);
21619 + u16 *data = (u16 *) & rq->ifr_ifru;
21623 + case SIOCDEVPRIVATE:
21624 + data[0] = dev->phy;
21625 + case SIOCDEVPRIVATE + 1:
21626 + read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
21628 + case SIOCDEVPRIVATE + 2:
21629 + if (!capable(CAP_NET_ADMIN))
21631 + write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
21634 + res = -EOPNOTSUPP;
21640 +static const struct net_device_ops rtl8150_netdev_ops = {
21641 + .ndo_open = rtl8150_open,
21642 + .ndo_stop = rtl8150_close,
21643 + .ndo_do_ioctl = rtl8150_ioctl,
21644 + .ndo_start_xmit = rtl8150_start_xmit,
21645 + .ndo_tx_timeout = rtl8150_tx_timeout,
21646 + .ndo_set_rx_mode = rtl8150_set_multicast,
21647 + .ndo_set_mac_address = rtl8150_set_mac_address,
21649 + .ndo_change_mtu = eth_change_mtu,
21650 + .ndo_validate_addr = eth_validate_addr,
21653 +static int rtl8150_probe(struct usb_interface *intf,
21654 + const struct usb_device_id *id)
21656 + struct usb_device *udev = interface_to_usbdev(intf);
21658 + struct net_device *netdev;
21660 + netdev = alloc_etherdev(sizeof(rtl8150_t));
21664 + dev = netdev_priv(netdev);
21666 + dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
21667 + if (!dev->intr_buff) {
21668 + free_netdev(netdev);
21672 + tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
21673 + spin_lock_init(&dev->rx_pool_lock);
21675 + dev->udev = udev;
21676 + dev->netdev = netdev;
21677 + netdev->netdev_ops = &rtl8150_netdev_ops;
21678 + netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
21679 + netdev->ethtool_ops = &ops;
21680 + dev->intr_interval = 100; /* 100ms */
21682 + if (!alloc_all_urbs(dev)) {
21683 + dev_err(&intf->dev, "out of memory\n");
21686 + if (!rtl8150_reset(dev)) {
21687 + dev_err(&intf->dev, "couldn't reset the device\n");
21690 + fill_skb_pool(dev);
21691 + set_ethernet_addr(dev);
21693 + usb_set_intfdata(intf, dev);
21694 + SET_NETDEV_DEV(netdev, &intf->dev);
21695 + if (register_netdev(netdev) != 0) {
21696 + dev_err(&intf->dev, "couldn't register the device\n");
21700 + dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name);
21705 + usb_set_intfdata(intf, NULL);
21706 + free_skb_pool(dev);
21708 + free_all_urbs(dev);
21710 + kfree(dev->intr_buff);
21711 + free_netdev(netdev);
21715 +static void rtl8150_disconnect(struct usb_interface *intf)
21717 + rtl8150_t *dev = usb_get_intfdata(intf);
21719 + usb_set_intfdata(intf, NULL);
21721 + set_bit(RTL8150_UNPLUG, &dev->flags);
21722 + tasklet_kill(&dev->tl);
21723 + unregister_netdev(dev->netdev);
21724 + unlink_all_urbs(dev);
21725 + free_all_urbs(dev);
21726 + free_skb_pool(dev);
21728 + dev_kfree_skb(dev->rx_skb);
21729 + kfree(dev->intr_buff);
21730 + free_netdev(dev->netdev);
21734 +static struct usb_driver rtl8150_driver = {
21735 + .name = driver_name,
21736 + .probe = rtl8150_probe,
21737 + .disconnect = rtl8150_disconnect,
21738 + .id_table = rtl8150_table,
21739 + .suspend = rtl8150_suspend,
21740 + .resume = rtl8150_resume,
21741 + .disable_hub_initiated_lpm = 1,
21744 +module_usb_driver(rtl8150_driver);
21746 +MODULE_AUTHOR(DRIVER_AUTHOR);
21747 +MODULE_DESCRIPTION(DRIVER_DESC);
21748 +MODULE_LICENSE("GPL");
21749 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc75xx.c backports-4.2.6-1/drivers/net/usb/smsc75xx.c
21750 --- backports-4.2.6-1.org/drivers/net/usb/smsc75xx.c 1970-01-01 01:00:00.000000000 +0100
21751 +++ backports-4.2.6-1/drivers/net/usb/smsc75xx.c 2016-06-28 14:35:18.008640551 +0200
21753 + /***************************************************************************
21755 + * Copyright (C) 2007-2010 SMSC
21757 + * This program is free software; you can redistribute it and/or
21758 + * modify it under the terms of the GNU General Public License
21759 + * as published by the Free Software Foundation; either version 2
21760 + * of the License, or (at your option) any later version.
21762 + * This program is distributed in the hope that it will be useful,
21763 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21764 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21765 + * GNU General Public License for more details.
21767 + * You should have received a copy of the GNU General Public License
21768 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
21770 + *****************************************************************************/
21772 +#include <linux/module.h>
21773 +#include <linux/kmod.h>
21774 +#include <linux/netdevice.h>
21775 +#include <linux/etherdevice.h>
21776 +#include <linux/ethtool.h>
21777 +#include <linux/mii.h>
21778 +#include <linux/usb.h>
21779 +#include <linux/bitrev.h>
21780 +#include <linux/crc16.h>
21781 +#include <linux/crc32.h>
21782 +#include <linux/usb/usbnet.h>
21783 +#include <linux/slab.h>
21784 +#include "smsc75xx.h"
21786 +#define SMSC_CHIPNAME "smsc75xx"
21787 +#define SMSC_DRIVER_VERSION "1.0.0"
21788 +#define HS_USB_PKT_SIZE (512)
21789 +#define FS_USB_PKT_SIZE (64)
21790 +#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
21791 +#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
21792 +#define DEFAULT_BULK_IN_DELAY (0x00002000)
21793 +#define MAX_SINGLE_PACKET_SIZE (9000)
21794 +#define LAN75XX_EEPROM_MAGIC (0x7500)
21795 +#define EEPROM_MAC_OFFSET (0x01)
21796 +#define DEFAULT_TX_CSUM_ENABLE (true)
21797 +#define DEFAULT_RX_CSUM_ENABLE (true)
21798 +#define SMSC75XX_INTERNAL_PHY_ID (1)
21799 +#define SMSC75XX_TX_OVERHEAD (8)
21800 +#define MAX_RX_FIFO_SIZE (20 * 1024)
21801 +#define MAX_TX_FIFO_SIZE (12 * 1024)
21802 +#define USB_VENDOR_ID_SMSC (0x0424)
21803 +#define USB_PRODUCT_ID_LAN7500 (0x7500)
21804 +#define USB_PRODUCT_ID_LAN7505 (0x7505)
21805 +#define RXW_PADDING 2
21806 +#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
21807 + WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
21809 +#define SUSPEND_SUSPEND0 (0x01)
21810 +#define SUSPEND_SUSPEND1 (0x02)
21811 +#define SUSPEND_SUSPEND2 (0x04)
21812 +#define SUSPEND_SUSPEND3 (0x08)
21813 +#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
21814 + SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
21816 +struct smsc75xx_priv {
21817 + struct usbnet *dev;
21820 + u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN];
21821 + struct mutex dataport_mutex;
21822 + spinlock_t rfe_ctl_lock;
21823 + struct work_struct set_multicast;
21824 + u8 suspend_flags;
21827 +struct usb_context {
21828 + struct usb_ctrlrequest req;
21829 + struct usbnet *dev;
21832 +static bool turbo_mode = true;
21833 +module_param(turbo_mode, bool, 0644);
21834 +MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
21836 +static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index,
21837 + u32 *data, int in_pm)
21841 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
21846 + fn = usbnet_read_cmd;
21848 + fn = usbnet_read_cmd_nopm;
21850 + ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
21851 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
21852 + 0, index, &buf, 4);
21853 + if (unlikely(ret < 0))
21854 + netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
21857 + le32_to_cpus(&buf);
21863 +static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index,
21864 + u32 data, int in_pm)
21868 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
21873 + fn = usbnet_write_cmd;
21875 + fn = usbnet_write_cmd_nopm;
21878 + cpu_to_le32s(&buf);
21880 + ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
21881 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
21882 + 0, index, &buf, 4);
21883 + if (unlikely(ret < 0))
21884 + netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
21890 +static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index,
21893 + return __smsc75xx_read_reg(dev, index, data, 1);
21896 +static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index,
21899 + return __smsc75xx_write_reg(dev, index, data, 1);
21902 +static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index,
21905 + return __smsc75xx_read_reg(dev, index, data, 0);
21908 +static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index,
21911 + return __smsc75xx_write_reg(dev, index, data, 0);
21914 +/* Loop until the read is completed with timeout
21915 + * called with phy_mutex held */
21916 +static __must_check int __smsc75xx_phy_wait_not_busy(struct usbnet *dev,
21919 + unsigned long start_time = jiffies;
21924 + ret = __smsc75xx_read_reg(dev, MII_ACCESS, &val, in_pm);
21926 + netdev_warn(dev->net, "Error reading MII_ACCESS\n");
21930 + if (!(val & MII_ACCESS_BUSY))
21932 + } while (!time_after(jiffies, start_time + HZ));
21937 +static int __smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
21940 + struct usbnet *dev = netdev_priv(netdev);
21944 + mutex_lock(&dev->phy_mutex);
21946 + /* confirm MII not busy */
21947 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21949 + netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_read\n");
21953 + /* set the address, index & direction (read from PHY) */
21954 + phy_id &= dev->mii.phy_id_mask;
21955 + idx &= dev->mii.reg_num_mask;
21956 + addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
21957 + | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
21958 + | MII_ACCESS_READ | MII_ACCESS_BUSY;
21959 + ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
21961 + netdev_warn(dev->net, "Error writing MII_ACCESS\n");
21965 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21967 + netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
21971 + ret = __smsc75xx_read_reg(dev, MII_DATA, &val, in_pm);
21973 + netdev_warn(dev->net, "Error reading MII_DATA\n");
21977 + ret = (u16)(val & 0xFFFF);
21980 + mutex_unlock(&dev->phy_mutex);
21984 +static void __smsc75xx_mdio_write(struct net_device *netdev, int phy_id,
21985 + int idx, int regval, int in_pm)
21987 + struct usbnet *dev = netdev_priv(netdev);
21991 + mutex_lock(&dev->phy_mutex);
21993 + /* confirm MII not busy */
21994 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
21996 + netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_write\n");
22001 + ret = __smsc75xx_write_reg(dev, MII_DATA, val, in_pm);
22003 + netdev_warn(dev->net, "Error writing MII_DATA\n");
22007 + /* set the address, index & direction (write to PHY) */
22008 + phy_id &= dev->mii.phy_id_mask;
22009 + idx &= dev->mii.reg_num_mask;
22010 + addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR)
22011 + | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR)
22012 + | MII_ACCESS_WRITE | MII_ACCESS_BUSY;
22013 + ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm);
22015 + netdev_warn(dev->net, "Error writing MII_ACCESS\n");
22019 + ret = __smsc75xx_phy_wait_not_busy(dev, in_pm);
22021 + netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
22026 + mutex_unlock(&dev->phy_mutex);
22029 +static int smsc75xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
22032 + return __smsc75xx_mdio_read(netdev, phy_id, idx, 1);
22035 +static void smsc75xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
22036 + int idx, int regval)
22038 + __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 1);
22041 +static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
22043 + return __smsc75xx_mdio_read(netdev, phy_id, idx, 0);
22046 +static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
22049 + __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 0);
22052 +static int smsc75xx_wait_eeprom(struct usbnet *dev)
22054 + unsigned long start_time = jiffies;
22059 + ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
22061 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
22065 + if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT))
22068 + } while (!time_after(jiffies, start_time + HZ));
22070 + if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) {
22071 + netdev_warn(dev->net, "EEPROM read operation timeout\n");
22078 +static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev)
22080 + unsigned long start_time = jiffies;
22085 + ret = smsc75xx_read_reg(dev, E2P_CMD, &val);
22087 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
22091 + if (!(val & E2P_CMD_BUSY))
22095 + } while (!time_after(jiffies, start_time + HZ));
22097 + netdev_warn(dev->net, "EEPROM is busy\n");
22101 +static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
22110 + ret = smsc75xx_eeprom_confirm_not_busy(dev);
22114 + for (i = 0; i < length; i++) {
22115 + val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR);
22116 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22118 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22122 + ret = smsc75xx_wait_eeprom(dev);
22126 + ret = smsc75xx_read_reg(dev, E2P_DATA, &val);
22128 + netdev_warn(dev->net, "Error reading E2P_DATA\n");
22132 + data[i] = val & 0xFF;
22139 +static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
22148 + ret = smsc75xx_eeprom_confirm_not_busy(dev);
22152 + /* Issue write/erase enable command */
22153 + val = E2P_CMD_BUSY | E2P_CMD_EWEN;
22154 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22156 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22160 + ret = smsc75xx_wait_eeprom(dev);
22164 + for (i = 0; i < length; i++) {
22166 + /* Fill data register */
22168 + ret = smsc75xx_write_reg(dev, E2P_DATA, val);
22170 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
22174 + /* Send "write" command */
22175 + val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR);
22176 + ret = smsc75xx_write_reg(dev, E2P_CMD, val);
22178 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
22182 + ret = smsc75xx_wait_eeprom(dev);
22192 +static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev)
22196 + for (i = 0; i < 100; i++) {
22198 + ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
22200 + netdev_warn(dev->net, "Error reading DP_SEL\n");
22204 + if (dp_sel & DP_SEL_DPRDY)
22210 + netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n");
22215 +static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr,
22216 + u32 length, u32 *buf)
22218 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22222 + mutex_lock(&pdata->dataport_mutex);
22224 + ret = smsc75xx_dataport_wait_not_busy(dev);
22226 + netdev_warn(dev->net, "smsc75xx_dataport_write busy on entry\n");
22230 + ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel);
22232 + netdev_warn(dev->net, "Error reading DP_SEL\n");
22236 + dp_sel &= ~DP_SEL_RSEL;
22237 + dp_sel |= ram_select;
22238 + ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel);
22240 + netdev_warn(dev->net, "Error writing DP_SEL\n");
22244 + for (i = 0; i < length; i++) {
22245 + ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i);
22247 + netdev_warn(dev->net, "Error writing DP_ADDR\n");
22251 + ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]);
22253 + netdev_warn(dev->net, "Error writing DP_DATA\n");
22257 + ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE);
22259 + netdev_warn(dev->net, "Error writing DP_CMD\n");
22263 + ret = smsc75xx_dataport_wait_not_busy(dev);
22265 + netdev_warn(dev->net, "smsc75xx_dataport_write timeout\n");
22271 + mutex_unlock(&pdata->dataport_mutex);
22275 +/* returns hash bit number for given MAC address */
22276 +static u32 smsc75xx_hash(char addr[ETH_ALEN])
22278 + return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff;
22281 +static void smsc75xx_deferred_multicast_write(struct work_struct *param)
22283 + struct smsc75xx_priv *pdata =
22284 + container_of(param, struct smsc75xx_priv, set_multicast);
22285 + struct usbnet *dev = pdata->dev;
22288 + netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n",
22291 + smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN,
22292 + DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table);
22294 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22296 + netdev_warn(dev->net, "Error writing RFE_CRL\n");
22299 +static void smsc75xx_set_multicast(struct net_device *netdev)
22301 + struct usbnet *dev = netdev_priv(netdev);
22302 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22303 + unsigned long flags;
22306 + spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
22308 + pdata->rfe_ctl &=
22309 + ~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF);
22310 + pdata->rfe_ctl |= RFE_CTL_AB;
22312 + for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++)
22313 + pdata->multicast_hash_table[i] = 0;
22315 + if (dev->net->flags & IFF_PROMISC) {
22316 + netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
22317 + pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU;
22318 + } else if (dev->net->flags & IFF_ALLMULTI) {
22319 + netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
22320 + pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF;
22321 + } else if (!netdev_mc_empty(dev->net)) {
22322 + struct netdev_hw_addr *ha;
22324 + netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n");
22326 + pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF;
22328 + netdev_for_each_mc_addr(ha, netdev) {
22329 + u32 bitnum = smsc75xx_hash(ha->addr);
22330 + pdata->multicast_hash_table[bitnum / 32] |=
22331 + (1 << (bitnum % 32));
22334 + netif_dbg(dev, drv, dev->net, "receive own packets only\n");
22335 + pdata->rfe_ctl |= RFE_CTL_DPF;
22338 + spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
22340 + /* defer register writes to a sleepable context */
22341 + schedule_work(&pdata->set_multicast);
22344 +static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex,
22345 + u16 lcladv, u16 rmtadv)
22347 + u32 flow = 0, fct_flow = 0;
22350 + if (duplex == DUPLEX_FULL) {
22351 + u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
22353 + if (cap & FLOW_CTRL_TX) {
22354 + flow = (FLOW_TX_FCEN | 0xFFFF);
22355 + /* set fct_flow thresholds to 20% and 80% */
22356 + fct_flow = (8 << 8) | 32;
22359 + if (cap & FLOW_CTRL_RX)
22360 + flow |= FLOW_RX_FCEN;
22362 + netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
22363 + (cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
22364 + (cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
22366 + netif_dbg(dev, link, dev->net, "half duplex\n");
22369 + ret = smsc75xx_write_reg(dev, FLOW, flow);
22371 + netdev_warn(dev->net, "Error writing FLOW\n");
22375 + ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow);
22377 + netdev_warn(dev->net, "Error writing FCT_FLOW\n");
22384 +static int smsc75xx_link_reset(struct usbnet *dev)
22386 + struct mii_if_info *mii = &dev->mii;
22387 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
22388 + u16 lcladv, rmtadv;
22391 + /* write to clear phy interrupt status */
22392 + smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC,
22393 + PHY_INT_SRC_CLEAR_ALL);
22395 + ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
22397 + netdev_warn(dev->net, "Error writing INT_STS\n");
22401 + mii_check_media(mii, 1, 1);
22402 + mii_ethtool_gset(&dev->mii, &ecmd);
22403 + lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
22404 + rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
22406 + netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
22407 + ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
22409 + return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
22412 +static void smsc75xx_status(struct usbnet *dev, struct urb *urb)
22416 + if (urb->actual_length != 4) {
22417 + netdev_warn(dev->net, "unexpected urb length %d\n",
22418 + urb->actual_length);
22422 + memcpy(&intdata, urb->transfer_buffer, 4);
22423 + le32_to_cpus(&intdata);
22425 + netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
22427 + if (intdata & INT_ENP_PHY_INT)
22428 + usbnet_defer_kevent(dev, EVENT_LINK_RESET);
22430 + netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
22434 +static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net)
22436 + return MAX_EEPROM_SIZE;
22439 +static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev,
22440 + struct ethtool_eeprom *ee, u8 *data)
22442 + struct usbnet *dev = netdev_priv(netdev);
22444 + ee->magic = LAN75XX_EEPROM_MAGIC;
22446 + return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data);
22449 +static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev,
22450 + struct ethtool_eeprom *ee, u8 *data)
22452 + struct usbnet *dev = netdev_priv(netdev);
22454 + if (ee->magic != LAN75XX_EEPROM_MAGIC) {
22455 + netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n",
22460 + return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data);
22463 +static void smsc75xx_ethtool_get_wol(struct net_device *net,
22464 + struct ethtool_wolinfo *wolinfo)
22466 + struct usbnet *dev = netdev_priv(net);
22467 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22469 + wolinfo->supported = SUPPORTED_WAKE;
22470 + wolinfo->wolopts = pdata->wolopts;
22473 +static int smsc75xx_ethtool_set_wol(struct net_device *net,
22474 + struct ethtool_wolinfo *wolinfo)
22476 + struct usbnet *dev = netdev_priv(net);
22477 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22480 + pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
22482 + ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
22484 + netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
22489 +static const struct ethtool_ops smsc75xx_ethtool_ops = {
22490 + .get_link = usbnet_get_link,
22491 + .nway_reset = usbnet_nway_reset,
22492 + .get_drvinfo = usbnet_get_drvinfo,
22493 + .get_msglevel = usbnet_get_msglevel,
22494 + .set_msglevel = usbnet_set_msglevel,
22495 + .get_settings = usbnet_get_settings,
22496 + .set_settings = usbnet_set_settings,
22497 + .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
22498 + .get_eeprom = smsc75xx_ethtool_get_eeprom,
22499 + .set_eeprom = smsc75xx_ethtool_set_eeprom,
22500 + .get_wol = smsc75xx_ethtool_get_wol,
22501 + .set_wol = smsc75xx_ethtool_set_wol,
22504 +static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
22506 + struct usbnet *dev = netdev_priv(netdev);
22508 + if (!netif_running(netdev))
22511 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
22514 +static void smsc75xx_init_mac_address(struct usbnet *dev)
22516 + /* try reading mac address from EEPROM */
22517 + if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
22518 + dev->net->dev_addr) == 0) {
22519 + if (is_valid_ether_addr(dev->net->dev_addr)) {
22520 + /* eeprom values are valid so use them */
22521 + netif_dbg(dev, ifup, dev->net,
22522 + "MAC address read from EEPROM\n");
22527 + /* no eeprom, or eeprom values are invalid. generate random MAC */
22528 + eth_hw_addr_random(dev->net);
22529 + netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
22532 +static int smsc75xx_set_mac_address(struct usbnet *dev)
22534 + u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
22535 + dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
22536 + u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
22538 + int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi);
22540 + netdev_warn(dev->net, "Failed to write RX_ADDRH: %d\n", ret);
22544 + ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo);
22546 + netdev_warn(dev->net, "Failed to write RX_ADDRL: %d\n", ret);
22550 + addr_hi |= ADDR_FILTX_FB_VALID;
22551 + ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi);
22553 + netdev_warn(dev->net, "Failed to write ADDR_FILTX: %d\n", ret);
22557 + ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo);
22559 + netdev_warn(dev->net, "Failed to write ADDR_FILTX+4: %d\n", ret);
22564 +static int smsc75xx_phy_initialize(struct usbnet *dev)
22566 + int bmcr, ret, timeout = 0;
22568 + /* Initialize MII structure */
22569 + dev->mii.dev = dev->net;
22570 + dev->mii.mdio_read = smsc75xx_mdio_read;
22571 + dev->mii.mdio_write = smsc75xx_mdio_write;
22572 + dev->mii.phy_id_mask = 0x1f;
22573 + dev->mii.reg_num_mask = 0x1f;
22574 + dev->mii.supports_gmii = 1;
22575 + dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID;
22577 + /* reset phy and wait for reset to complete */
22578 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
22582 + bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
22584 + netdev_warn(dev->net, "Error reading MII_BMCR\n");
22588 + } while ((bmcr & BMCR_RESET) && (timeout < 100));
22590 + if (timeout >= 100) {
22591 + netdev_warn(dev->net, "timeout on PHY Reset\n");
22595 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
22596 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
22597 + ADVERTISE_PAUSE_ASYM);
22598 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
22599 + ADVERTISE_1000FULL);
22601 + /* read and write to clear phy interrupt status */
22602 + ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
22604 + netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
22608 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff);
22610 + smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
22611 + PHY_INT_MASK_DEFAULT);
22612 + mii_nway_restart(&dev->mii);
22614 + netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
22618 +static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size)
22624 + ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
22626 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
22630 + rxenabled = ((buf & MAC_RX_RXEN) != 0);
22633 + buf &= ~MAC_RX_RXEN;
22634 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22636 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22641 + /* add 4 to size for FCS */
22642 + buf &= ~MAC_RX_MAX_SIZE;
22643 + buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE);
22645 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22647 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22652 + buf |= MAC_RX_RXEN;
22653 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
22655 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
22663 +static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu)
22665 + struct usbnet *dev = netdev_priv(netdev);
22668 + if (new_mtu > MAX_SINGLE_PACKET_SIZE)
22671 + ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu + ETH_HLEN);
22673 + netdev_warn(dev->net, "Failed to set mac rx frame length\n");
22677 + return usbnet_change_mtu(netdev, new_mtu);
22680 +/* Enable or disable Rx checksum offload engine */
22681 +static int smsc75xx_set_features(struct net_device *netdev,
22682 + netdev_features_t features)
22684 + struct usbnet *dev = netdev_priv(netdev);
22685 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22686 + unsigned long flags;
22689 + spin_lock_irqsave(&pdata->rfe_ctl_lock, flags);
22691 + if (features & NETIF_F_RXCSUM)
22692 + pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM;
22694 + pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM);
22696 + spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags);
22697 + /* it's racing here! */
22699 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22701 + netdev_warn(dev->net, "Error writing RFE_CTL\n");
22706 +static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm)
22714 + ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm);
22717 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22721 + if (buf & PMT_CTL_DEV_RDY)
22726 + } while (timeout < 100);
22728 + netdev_warn(dev->net, "timeout waiting for device ready\n");
22732 +static int smsc75xx_reset(struct usbnet *dev)
22734 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
22736 + int ret = 0, timeout;
22738 + netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n");
22740 + ret = smsc75xx_wait_ready(dev, 0);
22742 + netdev_warn(dev->net, "device not ready in smsc75xx_reset\n");
22746 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22748 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22752 + buf |= HW_CFG_LRST;
22754 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22756 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22763 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22765 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22769 + } while ((buf & HW_CFG_LRST) && (timeout < 100));
22771 + if (timeout >= 100) {
22772 + netdev_warn(dev->net, "timeout on completion of Lite Reset\n");
22776 + netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n");
22778 + ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
22780 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22784 + buf |= PMT_CTL_PHY_RST;
22786 + ret = smsc75xx_write_reg(dev, PMT_CTL, buf);
22788 + netdev_warn(dev->net, "Failed to write PMT_CTL: %d\n", ret);
22795 + ret = smsc75xx_read_reg(dev, PMT_CTL, &buf);
22797 + netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret);
22801 + } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100));
22803 + if (timeout >= 100) {
22804 + netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
22808 + netif_dbg(dev, ifup, dev->net, "PHY reset complete\n");
22810 + ret = smsc75xx_set_mac_address(dev);
22812 + netdev_warn(dev->net, "Failed to set mac address\n");
22816 + netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
22817 + dev->net->dev_addr);
22819 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22821 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22825 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
22828 + buf |= HW_CFG_BIR;
22830 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22832 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22836 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22838 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22842 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n",
22845 + if (!turbo_mode) {
22847 + dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
22848 + } else if (dev->udev->speed == USB_SPEED_HIGH) {
22849 + buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
22850 + dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
22852 + buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
22853 + dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
22856 + netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
22857 + (ulong)dev->rx_urb_size);
22859 + ret = smsc75xx_write_reg(dev, BURST_CAP, buf);
22861 + netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
22865 + ret = smsc75xx_read_reg(dev, BURST_CAP, &buf);
22867 + netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
22871 + netif_dbg(dev, ifup, dev->net,
22872 + "Read Value from BURST_CAP after writing: 0x%08x\n", buf);
22874 + ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
22876 + netdev_warn(dev->net, "Failed to write BULK_IN_DLY: %d\n", ret);
22880 + ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf);
22882 + netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
22886 + netif_dbg(dev, ifup, dev->net,
22887 + "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf);
22889 + if (turbo_mode) {
22890 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22892 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22896 + netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
22898 + buf |= (HW_CFG_MEF | HW_CFG_BCE);
22900 + ret = smsc75xx_write_reg(dev, HW_CFG, buf);
22902 + netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
22906 + ret = smsc75xx_read_reg(dev, HW_CFG, &buf);
22908 + netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
22912 + netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf);
22915 + /* set FIFO sizes */
22916 + buf = (MAX_RX_FIFO_SIZE - 512) / 512;
22917 + ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf);
22919 + netdev_warn(dev->net, "Failed to write FCT_RX_FIFO_END: %d\n", ret);
22923 + netif_dbg(dev, ifup, dev->net, "FCT_RX_FIFO_END set to 0x%08x\n", buf);
22925 + buf = (MAX_TX_FIFO_SIZE - 512) / 512;
22926 + ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf);
22928 + netdev_warn(dev->net, "Failed to write FCT_TX_FIFO_END: %d\n", ret);
22932 + netif_dbg(dev, ifup, dev->net, "FCT_TX_FIFO_END set to 0x%08x\n", buf);
22934 + ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL);
22936 + netdev_warn(dev->net, "Failed to write INT_STS: %d\n", ret);
22940 + ret = smsc75xx_read_reg(dev, ID_REV, &buf);
22942 + netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
22946 + netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf);
22948 + ret = smsc75xx_read_reg(dev, E2P_CMD, &buf);
22950 + netdev_warn(dev->net, "Failed to read E2P_CMD: %d\n", ret);
22954 + /* only set default GPIO/LED settings if no EEPROM is detected */
22955 + if (!(buf & E2P_CMD_LOADED)) {
22956 + ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf);
22958 + netdev_warn(dev->net, "Failed to read LED_GPIO_CFG: %d\n", ret);
22962 + buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL);
22963 + buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL;
22965 + ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf);
22967 + netdev_warn(dev->net, "Failed to write LED_GPIO_CFG: %d\n", ret);
22972 + ret = smsc75xx_write_reg(dev, FLOW, 0);
22974 + netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
22978 + ret = smsc75xx_write_reg(dev, FCT_FLOW, 0);
22980 + netdev_warn(dev->net, "Failed to write FCT_FLOW: %d\n", ret);
22984 + /* Don't need rfe_ctl_lock during initialisation */
22985 + ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
22987 + netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
22991 + pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF;
22993 + ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl);
22995 + netdev_warn(dev->net, "Failed to write RFE_CTL: %d\n", ret);
22999 + ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl);
23001 + netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret);
23005 + netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n",
23008 + /* Enable or disable checksum offload engines */
23009 + smsc75xx_set_features(dev->net, dev->net->features);
23011 + smsc75xx_set_multicast(dev->net);
23013 + ret = smsc75xx_phy_initialize(dev);
23015 + netdev_warn(dev->net, "Failed to initialize PHY: %d\n", ret);
23019 + ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf);
23021 + netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
23025 + /* enable PHY interrupts */
23026 + buf |= INT_ENP_PHY_INT;
23028 + ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf);
23030 + netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
23034 + /* allow mac to detect speed and duplex from phy */
23035 + ret = smsc75xx_read_reg(dev, MAC_CR, &buf);
23037 + netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
23041 + buf |= (MAC_CR_ADD | MAC_CR_ASD);
23042 + ret = smsc75xx_write_reg(dev, MAC_CR, buf);
23044 + netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret);
23048 + ret = smsc75xx_read_reg(dev, MAC_TX, &buf);
23050 + netdev_warn(dev->net, "Failed to read MAC_TX: %d\n", ret);
23054 + buf |= MAC_TX_TXEN;
23056 + ret = smsc75xx_write_reg(dev, MAC_TX, buf);
23058 + netdev_warn(dev->net, "Failed to write MAC_TX: %d\n", ret);
23062 + netif_dbg(dev, ifup, dev->net, "MAC_TX set to 0x%08x\n", buf);
23064 + ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf);
23066 + netdev_warn(dev->net, "Failed to read FCT_TX_CTL: %d\n", ret);
23070 + buf |= FCT_TX_CTL_EN;
23072 + ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf);
23074 + netdev_warn(dev->net, "Failed to write FCT_TX_CTL: %d\n", ret);
23078 + netif_dbg(dev, ifup, dev->net, "FCT_TX_CTL set to 0x%08x\n", buf);
23080 + ret = smsc75xx_set_rx_max_frame_length(dev, dev->net->mtu + ETH_HLEN);
23082 + netdev_warn(dev->net, "Failed to set max rx frame length\n");
23086 + ret = smsc75xx_read_reg(dev, MAC_RX, &buf);
23088 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
23092 + buf |= MAC_RX_RXEN;
23094 + ret = smsc75xx_write_reg(dev, MAC_RX, buf);
23096 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
23100 + netif_dbg(dev, ifup, dev->net, "MAC_RX set to 0x%08x\n", buf);
23102 + ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf);
23104 + netdev_warn(dev->net, "Failed to read FCT_RX_CTL: %d\n", ret);
23108 + buf |= FCT_RX_CTL_EN;
23110 + ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf);
23112 + netdev_warn(dev->net, "Failed to write FCT_RX_CTL: %d\n", ret);
23116 + netif_dbg(dev, ifup, dev->net, "FCT_RX_CTL set to 0x%08x\n", buf);
23118 + netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n");
23122 +static const struct net_device_ops smsc75xx_netdev_ops = {
23123 + .ndo_open = usbnet_open,
23124 + .ndo_stop = usbnet_stop,
23125 + .ndo_start_xmit = usbnet_start_xmit,
23126 + .ndo_tx_timeout = usbnet_tx_timeout,
23127 + .ndo_change_mtu = smsc75xx_change_mtu,
23128 + .ndo_set_mac_address = eth_mac_addr,
23129 + .ndo_validate_addr = eth_validate_addr,
23130 + .ndo_do_ioctl = smsc75xx_ioctl,
23131 + .ndo_set_rx_mode = smsc75xx_set_multicast,
23132 + .ndo_set_features = smsc75xx_set_features,
23135 +static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
23137 + struct smsc75xx_priv *pdata = NULL;
23140 + printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
23142 + ret = usbnet_get_endpoints(dev, intf);
23144 + netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
23148 + dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv),
23151 + pdata = (struct smsc75xx_priv *)(dev->data[0]);
23155 + pdata->dev = dev;
23157 + spin_lock_init(&pdata->rfe_ctl_lock);
23158 + mutex_init(&pdata->dataport_mutex);
23160 + INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write);
23162 + if (DEFAULT_TX_CSUM_ENABLE)
23163 + dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
23165 + if (DEFAULT_RX_CSUM_ENABLE)
23166 + dev->net->features |= NETIF_F_RXCSUM;
23168 + dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
23171 + ret = smsc75xx_wait_ready(dev, 0);
23173 + netdev_warn(dev->net, "device not ready in smsc75xx_bind\n");
23177 + smsc75xx_init_mac_address(dev);
23179 + /* Init all registers */
23180 + ret = smsc75xx_reset(dev);
23182 + netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret);
23186 + dev->net->netdev_ops = &smsc75xx_netdev_ops;
23187 + dev->net->ethtool_ops = &smsc75xx_ethtool_ops;
23188 + dev->net->flags |= IFF_MULTICAST;
23189 + dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD;
23190 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
23194 +static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
23196 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23198 + netif_dbg(dev, ifdown, dev->net, "free pdata\n");
23201 + dev->data[0] = 0;
23205 +static u16 smsc_crc(const u8 *buffer, size_t len)
23207 + return bitrev16(crc16(0xFFFF, buffer, len));
23210 +static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg,
23213 + int cfg_base = WUF_CFGX + filter * 4;
23214 + int mask_base = WUF_MASKX + filter * 16;
23217 + ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg);
23219 + netdev_warn(dev->net, "Error writing WUF_CFGX\n");
23223 + ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1);
23225 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23229 + ret = smsc75xx_write_reg(dev, mask_base + 4, 0);
23231 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23235 + ret = smsc75xx_write_reg(dev, mask_base + 8, 0);
23237 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23241 + ret = smsc75xx_write_reg(dev, mask_base + 12, 0);
23243 + netdev_warn(dev->net, "Error writing WUF_MASKX\n");
23250 +static int smsc75xx_enter_suspend0(struct usbnet *dev)
23252 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23256 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23258 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23262 + val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST));
23263 + val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS;
23265 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23267 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23271 + pdata->suspend_flags |= SUSPEND_SUSPEND0;
23276 +static int smsc75xx_enter_suspend1(struct usbnet *dev)
23278 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23282 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23284 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23288 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23289 + val |= PMT_CTL_SUS_MODE_1;
23291 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23293 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23297 + /* clear wol status, enable energy detection */
23298 + val &= ~PMT_CTL_WUPS;
23299 + val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
23301 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23303 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23307 + pdata->suspend_flags |= SUSPEND_SUSPEND1;
23312 +static int smsc75xx_enter_suspend2(struct usbnet *dev)
23314 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23318 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23320 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23324 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23325 + val |= PMT_CTL_SUS_MODE_2;
23327 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23329 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23333 + pdata->suspend_flags |= SUSPEND_SUSPEND2;
23338 +static int smsc75xx_enter_suspend3(struct usbnet *dev)
23340 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23344 + ret = smsc75xx_read_reg_nopm(dev, FCT_RX_CTL, &val);
23346 + netdev_warn(dev->net, "Error reading FCT_RX_CTL\n");
23350 + if (val & FCT_RX_CTL_RXUSED) {
23351 + netdev_dbg(dev->net, "rx fifo not empty in autosuspend\n");
23355 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23357 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23361 + val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST);
23362 + val |= PMT_CTL_SUS_MODE_3 | PMT_CTL_RES_CLR_WKP_EN;
23364 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23366 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23370 + /* clear wol status */
23371 + val &= ~PMT_CTL_WUPS;
23372 + val |= PMT_CTL_WUPS_WOL;
23374 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23376 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23380 + pdata->suspend_flags |= SUSPEND_SUSPEND3;
23385 +static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
23387 + struct mii_if_info *mii = &dev->mii;
23390 + netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
23392 + /* read to clear */
23393 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
23395 + netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
23399 + /* enable interrupt source */
23400 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
23402 + netdev_warn(dev->net, "Error reading PHY_INT_MASK\n");
23408 + smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
23413 +static int smsc75xx_link_ok_nopm(struct usbnet *dev)
23415 + struct mii_if_info *mii = &dev->mii;
23418 + /* first, a dummy read, needed to latch some MII phys */
23419 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
23421 + netdev_warn(dev->net, "Error reading MII_BMSR\n");
23425 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
23427 + netdev_warn(dev->net, "Error reading MII_BMSR\n");
23431 + return !!(ret & BMSR_LSTATUS);
23434 +static int smsc75xx_autosuspend(struct usbnet *dev, u32 link_up)
23438 + if (!netif_running(dev->net)) {
23439 + /* interface is ifconfig down so fully power down hw */
23440 + netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
23441 + return smsc75xx_enter_suspend2(dev);
23445 + /* link is down so enter EDPD mode */
23446 + netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
23448 + /* enable PHY wakeup events for if cable is attached */
23449 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23450 + PHY_INT_MASK_ANEG_COMP);
23452 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23456 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
23457 + return smsc75xx_enter_suspend1(dev);
23460 + /* enable PHY wakeup events so we remote wakeup if cable is pulled */
23461 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23462 + PHY_INT_MASK_LINK_DOWN);
23464 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23468 + netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
23469 + return smsc75xx_enter_suspend3(dev);
23472 +static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
23474 + struct usbnet *dev = usb_get_intfdata(intf);
23475 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23476 + u32 val, link_up;
23479 + ret = usbnet_suspend(intf, message);
23481 + netdev_warn(dev->net, "usbnet_suspend error\n");
23485 + if (pdata->suspend_flags) {
23486 + netdev_warn(dev->net, "error during last resume\n");
23487 + pdata->suspend_flags = 0;
23490 + /* determine if link is up using only _nopm functions */
23491 + link_up = smsc75xx_link_ok_nopm(dev);
23493 + if (message.event == PM_EVENT_AUTO_SUSPEND) {
23494 + ret = smsc75xx_autosuspend(dev, link_up);
23498 + /* if we get this far we're not autosuspending */
23499 + /* if no wol options set, or if link is down and we're not waking on
23500 + * PHY activity, enter lowest power SUSPEND2 mode
23502 + if (!(pdata->wolopts & SUPPORTED_WAKE) ||
23503 + !(link_up || (pdata->wolopts & WAKE_PHY))) {
23504 + netdev_info(dev->net, "entering SUSPEND2 mode\n");
23506 + /* disable energy detect (link up) & wake up events */
23507 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23509 + netdev_warn(dev->net, "Error reading WUCSR\n");
23513 + val &= ~(WUCSR_MPEN | WUCSR_WUEN);
23515 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23517 + netdev_warn(dev->net, "Error writing WUCSR\n");
23521 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23523 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23527 + val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN);
23529 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23531 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23535 + ret = smsc75xx_enter_suspend2(dev);
23539 + if (pdata->wolopts & WAKE_PHY) {
23540 + ret = smsc75xx_enable_phy_wakeup_interrupts(dev,
23541 + (PHY_INT_MASK_ANEG_COMP | PHY_INT_MASK_LINK_DOWN));
23543 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
23547 + /* if link is down then configure EDPD and enter SUSPEND1,
23548 + * otherwise enter SUSPEND0 below
23551 + struct mii_if_info *mii = &dev->mii;
23552 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
23554 + /* enable energy detect power-down mode */
23555 + ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id,
23556 + PHY_MODE_CTRL_STS);
23558 + netdev_warn(dev->net, "Error reading PHY_MODE_CTRL_STS\n");
23562 + ret |= MODE_CTRL_STS_EDPWRDOWN;
23564 + smsc75xx_mdio_write_nopm(dev->net, mii->phy_id,
23565 + PHY_MODE_CTRL_STS, ret);
23567 + /* enter SUSPEND1 mode */
23568 + ret = smsc75xx_enter_suspend1(dev);
23573 + if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) {
23574 + int i, filter = 0;
23576 + /* disable all filters */
23577 + for (i = 0; i < WUF_NUM; i++) {
23578 + ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0);
23580 + netdev_warn(dev->net, "Error writing WUF_CFGX\n");
23585 + if (pdata->wolopts & WAKE_MCAST) {
23586 + const u8 mcast[] = {0x01, 0x00, 0x5E};
23587 + netdev_info(dev->net, "enabling multicast detection\n");
23589 + val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST
23590 + | smsc_crc(mcast, 3);
23591 + ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007);
23593 + netdev_warn(dev->net, "Error writing wakeup filter\n");
23598 + if (pdata->wolopts & WAKE_ARP) {
23599 + const u8 arp[] = {0x08, 0x06};
23600 + netdev_info(dev->net, "enabling ARP detection\n");
23602 + val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16)
23603 + | smsc_crc(arp, 2);
23604 + ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003);
23606 + netdev_warn(dev->net, "Error writing wakeup filter\n");
23611 + /* clear any pending pattern match packet status */
23612 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23614 + netdev_warn(dev->net, "Error reading WUCSR\n");
23618 + val |= WUCSR_WUFR;
23620 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23622 + netdev_warn(dev->net, "Error writing WUCSR\n");
23626 + netdev_info(dev->net, "enabling packet match detection\n");
23627 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23629 + netdev_warn(dev->net, "Error reading WUCSR\n");
23633 + val |= WUCSR_WUEN;
23635 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23637 + netdev_warn(dev->net, "Error writing WUCSR\n");
23641 + netdev_info(dev->net, "disabling packet match detection\n");
23642 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23644 + netdev_warn(dev->net, "Error reading WUCSR\n");
23648 + val &= ~WUCSR_WUEN;
23650 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23652 + netdev_warn(dev->net, "Error writing WUCSR\n");
23657 + /* disable magic, bcast & unicast wakeup sources */
23658 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23660 + netdev_warn(dev->net, "Error reading WUCSR\n");
23664 + val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN);
23666 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23668 + netdev_warn(dev->net, "Error writing WUCSR\n");
23672 + if (pdata->wolopts & WAKE_PHY) {
23673 + netdev_info(dev->net, "enabling PHY wakeup\n");
23675 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23677 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23681 + /* clear wol status, enable energy detection */
23682 + val &= ~PMT_CTL_WUPS;
23683 + val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN);
23685 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23687 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23692 + if (pdata->wolopts & WAKE_MAGIC) {
23693 + netdev_info(dev->net, "enabling magic packet wakeup\n");
23694 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23696 + netdev_warn(dev->net, "Error reading WUCSR\n");
23700 + /* clear any pending magic packet status */
23701 + val |= WUCSR_MPR | WUCSR_MPEN;
23703 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23705 + netdev_warn(dev->net, "Error writing WUCSR\n");
23710 + if (pdata->wolopts & WAKE_BCAST) {
23711 + netdev_info(dev->net, "enabling broadcast detection\n");
23712 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23714 + netdev_warn(dev->net, "Error reading WUCSR\n");
23718 + val |= WUCSR_BCAST_FR | WUCSR_BCST_EN;
23720 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23722 + netdev_warn(dev->net, "Error writing WUCSR\n");
23727 + if (pdata->wolopts & WAKE_UCAST) {
23728 + netdev_info(dev->net, "enabling unicast detection\n");
23729 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23731 + netdev_warn(dev->net, "Error reading WUCSR\n");
23735 + val |= WUCSR_WUFR | WUCSR_PFDA_EN;
23737 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23739 + netdev_warn(dev->net, "Error writing WUCSR\n");
23744 + /* enable receiver to enable frame reception */
23745 + ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val);
23747 + netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret);
23751 + val |= MAC_RX_RXEN;
23753 + ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val);
23755 + netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret);
23759 + /* some wol options are enabled, so enter SUSPEND0 */
23760 + netdev_info(dev->net, "entering SUSPEND0 mode\n");
23761 + ret = smsc75xx_enter_suspend0(dev);
23765 + * TODO: resume() might need to handle the suspend failure
23766 + * in system sleep
23768 + if (ret && PMSG_IS_AUTO(message))
23769 + usbnet_resume(intf);
23773 +static int smsc75xx_resume(struct usb_interface *intf)
23775 + struct usbnet *dev = usb_get_intfdata(intf);
23776 + struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]);
23777 + u8 suspend_flags = pdata->suspend_flags;
23781 + netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
23783 + /* do this first to ensure it's cleared even in error case */
23784 + pdata->suspend_flags = 0;
23786 + if (suspend_flags & SUSPEND_ALLMODES) {
23787 + /* Disable wakeup sources */
23788 + ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val);
23790 + netdev_warn(dev->net, "Error reading WUCSR\n");
23794 + val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN
23795 + | WUCSR_BCST_EN);
23797 + ret = smsc75xx_write_reg_nopm(dev, WUCSR, val);
23799 + netdev_warn(dev->net, "Error writing WUCSR\n");
23803 + /* clear wake-up status */
23804 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23806 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23810 + val &= ~PMT_CTL_WOL_EN;
23811 + val |= PMT_CTL_WUPS;
23813 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23815 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23820 + if (suspend_flags & SUSPEND_SUSPEND2) {
23821 + netdev_info(dev->net, "resuming from SUSPEND2\n");
23823 + ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val);
23825 + netdev_warn(dev->net, "Error reading PMT_CTL\n");
23829 + val |= PMT_CTL_PHY_PWRUP;
23831 + ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val);
23833 + netdev_warn(dev->net, "Error writing PMT_CTL\n");
23838 + ret = smsc75xx_wait_ready(dev, 1);
23840 + netdev_warn(dev->net, "device not ready in smsc75xx_resume\n");
23844 + return usbnet_resume(intf);
23847 +static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,
23848 + u32 rx_cmd_a, u32 rx_cmd_b)
23850 + if (!(dev->net->features & NETIF_F_RXCSUM) ||
23851 + unlikely(rx_cmd_a & RX_CMD_A_LCSM)) {
23852 + skb->ip_summed = CHECKSUM_NONE;
23854 + skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT));
23855 + skb->ip_summed = CHECKSUM_COMPLETE;
23859 +static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
23861 + /* This check is no longer done by usbnet */
23862 + if (skb->len < dev->net->hard_header_len)
23865 + while (skb->len > 0) {
23866 + u32 rx_cmd_a, rx_cmd_b, align_count, size;
23867 + struct sk_buff *ax_skb;
23868 + unsigned char *packet;
23870 + memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
23871 + le32_to_cpus(&rx_cmd_a);
23872 + skb_pull(skb, 4);
23874 + memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
23875 + le32_to_cpus(&rx_cmd_b);
23876 + skb_pull(skb, 4 + RXW_PADDING);
23878 + packet = skb->data;
23880 + /* get the packet length */
23881 + size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
23882 + align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
23884 + if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
23885 + netif_dbg(dev, rx_err, dev->net,
23886 + "Error rx_cmd_a=0x%08x\n", rx_cmd_a);
23887 + dev->net->stats.rx_errors++;
23888 + dev->net->stats.rx_dropped++;
23890 + if (rx_cmd_a & RX_CMD_A_FCS)
23891 + dev->net->stats.rx_crc_errors++;
23892 + else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT))
23893 + dev->net->stats.rx_frame_errors++;
23895 + /* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
23896 + if (unlikely(size > (MAX_SINGLE_PACKET_SIZE + ETH_HLEN + 12))) {
23897 + netif_dbg(dev, rx_err, dev->net,
23898 + "size err rx_cmd_a=0x%08x\n",
23903 + /* last frame in this batch */
23904 + if (skb->len == size) {
23905 + smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
23908 + skb_trim(skb, skb->len - 4); /* remove fcs */
23909 + skb->truesize = size + sizeof(struct sk_buff);
23914 + ax_skb = skb_clone(skb, GFP_ATOMIC);
23915 + if (unlikely(!ax_skb)) {
23916 + netdev_warn(dev->net, "Error allocating skb\n");
23920 + ax_skb->len = size;
23921 + ax_skb->data = packet;
23922 + skb_set_tail_pointer(ax_skb, size);
23924 + smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
23927 + skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
23928 + ax_skb->truesize = size + sizeof(struct sk_buff);
23930 + usbnet_skb_return(dev, ax_skb);
23933 + skb_pull(skb, size);
23935 + /* padding bytes before the next frame starts */
23937 + skb_pull(skb, align_count);
23940 + if (unlikely(skb->len < 0)) {
23941 + netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
23948 +static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
23949 + struct sk_buff *skb, gfp_t flags)
23951 + u32 tx_cmd_a, tx_cmd_b;
23953 + if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) {
23954 + struct sk_buff *skb2 =
23955 + skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags);
23956 + dev_kfree_skb_any(skb);
23962 + tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
23964 + if (skb->ip_summed == CHECKSUM_PARTIAL)
23965 + tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE;
23967 + if (skb_is_gso(skb)) {
23968 + u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN);
23969 + tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS;
23971 + tx_cmd_a |= TX_CMD_A_LSO;
23976 + skb_push(skb, 4);
23977 + cpu_to_le32s(&tx_cmd_b);
23978 + memcpy(skb->data, &tx_cmd_b, 4);
23980 + skb_push(skb, 4);
23981 + cpu_to_le32s(&tx_cmd_a);
23982 + memcpy(skb->data, &tx_cmd_a, 4);
23987 +static int smsc75xx_manage_power(struct usbnet *dev, int on)
23989 + dev->intf->needs_remote_wakeup = on;
23993 +static const struct driver_info smsc75xx_info = {
23994 + .description = "smsc75xx USB 2.0 Gigabit Ethernet",
23995 + .bind = smsc75xx_bind,
23996 + .unbind = smsc75xx_unbind,
23997 + .link_reset = smsc75xx_link_reset,
23998 + .reset = smsc75xx_reset,
23999 + .rx_fixup = smsc75xx_rx_fixup,
24000 + .tx_fixup = smsc75xx_tx_fixup,
24001 + .status = smsc75xx_status,
24002 + .manage_power = smsc75xx_manage_power,
24003 + .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
24006 +static const struct usb_device_id products[] = {
24008 + /* SMSC7500 USB Gigabit Ethernet Device */
24009 + USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500),
24010 + .driver_info = (unsigned long) &smsc75xx_info,
24013 + /* SMSC7500 USB Gigabit Ethernet Device */
24014 + USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505),
24015 + .driver_info = (unsigned long) &smsc75xx_info,
24019 +MODULE_DEVICE_TABLE(usb, products);
24021 +static struct usb_driver smsc75xx_driver = {
24022 + .name = SMSC_CHIPNAME,
24023 + .id_table = products,
24024 + .probe = usbnet_probe,
24025 + .suspend = smsc75xx_suspend,
24026 + .resume = smsc75xx_resume,
24027 + .reset_resume = smsc75xx_resume,
24028 + .disconnect = usbnet_disconnect,
24029 + .disable_hub_initiated_lpm = 1,
24030 + .supports_autosuspend = 1,
24033 +module_usb_driver(smsc75xx_driver);
24035 +MODULE_AUTHOR("Nancy Lin");
24036 +MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
24037 +MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices");
24038 +MODULE_LICENSE("GPL");
24039 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc75xx.h backports-4.2.6-1/drivers/net/usb/smsc75xx.h
24040 --- backports-4.2.6-1.org/drivers/net/usb/smsc75xx.h 1970-01-01 01:00:00.000000000 +0100
24041 +++ backports-4.2.6-1/drivers/net/usb/smsc75xx.h 2016-06-28 14:35:18.008640551 +0200
24043 + /***************************************************************************
24045 + * Copyright (C) 2007-2010 SMSC
24047 + * This program is free software; you can redistribute it and/or
24048 + * modify it under the terms of the GNU General Public License
24049 + * as published by the Free Software Foundation; either version 2
24050 + * of the License, or (at your option) any later version.
24052 + * This program is distributed in the hope that it will be useful,
24053 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24054 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24055 + * GNU General Public License for more details.
24057 + * You should have received a copy of the GNU General Public License
24058 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
24060 + *****************************************************************************/
24062 +#ifndef _SMSC75XX_H
24063 +#define _SMSC75XX_H
24065 +/* Tx command words */
24066 +#define TX_CMD_A_LSO (0x08000000)
24067 +#define TX_CMD_A_IPE (0x04000000)
24068 +#define TX_CMD_A_TPE (0x02000000)
24069 +#define TX_CMD_A_IVTG (0x01000000)
24070 +#define TX_CMD_A_RVTG (0x00800000)
24071 +#define TX_CMD_A_FCS (0x00400000)
24072 +#define TX_CMD_A_LEN (0x000FFFFF)
24074 +#define TX_CMD_B_MSS (0x3FFF0000)
24075 +#define TX_CMD_B_MSS_SHIFT (16)
24076 +#define TX_MSS_MIN ((u16)8)
24077 +#define TX_CMD_B_VTAG (0x0000FFFF)
24079 +/* Rx command words */
24080 +#define RX_CMD_A_ICE (0x80000000)
24081 +#define RX_CMD_A_TCE (0x40000000)
24082 +#define RX_CMD_A_IPV (0x20000000)
24083 +#define RX_CMD_A_PID (0x18000000)
24084 +#define RX_CMD_A_PID_NIP (0x00000000)
24085 +#define RX_CMD_A_PID_TCP (0x08000000)
24086 +#define RX_CMD_A_PID_UDP (0x10000000)
24087 +#define RX_CMD_A_PID_PP (0x18000000)
24088 +#define RX_CMD_A_PFF (0x04000000)
24089 +#define RX_CMD_A_BAM (0x02000000)
24090 +#define RX_CMD_A_MAM (0x01000000)
24091 +#define RX_CMD_A_FVTG (0x00800000)
24092 +#define RX_CMD_A_RED (0x00400000)
24093 +#define RX_CMD_A_RWT (0x00200000)
24094 +#define RX_CMD_A_RUNT (0x00100000)
24095 +#define RX_CMD_A_LONG (0x00080000)
24096 +#define RX_CMD_A_RXE (0x00040000)
24097 +#define RX_CMD_A_DRB (0x00020000)
24098 +#define RX_CMD_A_FCS (0x00010000)
24099 +#define RX_CMD_A_UAM (0x00008000)
24100 +#define RX_CMD_A_LCSM (0x00004000)
24101 +#define RX_CMD_A_LEN (0x00003FFF)
24103 +#define RX_CMD_B_CSUM (0xFFFF0000)
24104 +#define RX_CMD_B_CSUM_SHIFT (16)
24105 +#define RX_CMD_B_VTAG (0x0000FFFF)
24108 +#define ID_REV (0x0000)
24110 +#define FPGA_REV (0x0004)
24112 +#define BOND_CTL (0x0008)
24114 +#define INT_STS (0x000C)
24115 +#define INT_STS_RDFO_INT (0x00400000)
24116 +#define INT_STS_TXE_INT (0x00200000)
24117 +#define INT_STS_MACRTO_INT (0x00100000)
24118 +#define INT_STS_TX_DIS_INT (0x00080000)
24119 +#define INT_STS_RX_DIS_INT (0x00040000)
24120 +#define INT_STS_PHY_INT_ (0x00020000)
24121 +#define INT_STS_MAC_ERR_INT (0x00008000)
24122 +#define INT_STS_TDFU (0x00004000)
24123 +#define INT_STS_TDFO (0x00002000)
24124 +#define INT_STS_GPIOS (0x00000FFF)
24125 +#define INT_STS_CLEAR_ALL (0xFFFFFFFF)
24127 +#define HW_CFG (0x0010)
24128 +#define HW_CFG_SMDET_STS (0x00008000)
24129 +#define HW_CFG_SMDET_EN (0x00004000)
24130 +#define HW_CFG_EEM (0x00002000)
24131 +#define HW_CFG_RST_PROTECT (0x00001000)
24132 +#define HW_CFG_PORT_SWAP (0x00000800)
24133 +#define HW_CFG_PHY_BOOST (0x00000600)
24134 +#define HW_CFG_PHY_BOOST_NORMAL (0x00000000)
24135 +#define HW_CFG_PHY_BOOST_4 (0x00002000)
24136 +#define HW_CFG_PHY_BOOST_8 (0x00004000)
24137 +#define HW_CFG_PHY_BOOST_12 (0x00006000)
24138 +#define HW_CFG_LEDB (0x00000100)
24139 +#define HW_CFG_BIR (0x00000080)
24140 +#define HW_CFG_SBP (0x00000040)
24141 +#define HW_CFG_IME (0x00000020)
24142 +#define HW_CFG_MEF (0x00000010)
24143 +#define HW_CFG_ETC (0x00000008)
24144 +#define HW_CFG_BCE (0x00000004)
24145 +#define HW_CFG_LRST (0x00000002)
24146 +#define HW_CFG_SRST (0x00000001)
24148 +#define PMT_CTL (0x0014)
24149 +#define PMT_CTL_PHY_PWRUP (0x00000400)
24150 +#define PMT_CTL_RES_CLR_WKP_EN (0x00000100)
24151 +#define PMT_CTL_DEV_RDY (0x00000080)
24152 +#define PMT_CTL_SUS_MODE (0x00000060)
24153 +#define PMT_CTL_SUS_MODE_0 (0x00000000)
24154 +#define PMT_CTL_SUS_MODE_1 (0x00000020)
24155 +#define PMT_CTL_SUS_MODE_2 (0x00000040)
24156 +#define PMT_CTL_SUS_MODE_3 (0x00000060)
24157 +#define PMT_CTL_PHY_RST (0x00000010)
24158 +#define PMT_CTL_WOL_EN (0x00000008)
24159 +#define PMT_CTL_ED_EN (0x00000004)
24160 +#define PMT_CTL_WUPS (0x00000003)
24161 +#define PMT_CTL_WUPS_NO (0x00000000)
24162 +#define PMT_CTL_WUPS_ED (0x00000001)
24163 +#define PMT_CTL_WUPS_WOL (0x00000002)
24164 +#define PMT_CTL_WUPS_MULTI (0x00000003)
24166 +#define LED_GPIO_CFG (0x0018)
24167 +#define LED_GPIO_CFG_LED2_FUN_SEL (0x80000000)
24168 +#define LED_GPIO_CFG_LED10_FUN_SEL (0x40000000)
24169 +#define LED_GPIO_CFG_LEDGPIO_EN (0x0000F000)
24170 +#define LED_GPIO_CFG_LEDGPIO_EN_0 (0x00001000)
24171 +#define LED_GPIO_CFG_LEDGPIO_EN_1 (0x00002000)
24172 +#define LED_GPIO_CFG_LEDGPIO_EN_2 (0x00004000)
24173 +#define LED_GPIO_CFG_LEDGPIO_EN_3 (0x00008000)
24174 +#define LED_GPIO_CFG_GPBUF (0x00000F00)
24175 +#define LED_GPIO_CFG_GPBUF_0 (0x00000100)
24176 +#define LED_GPIO_CFG_GPBUF_1 (0x00000200)
24177 +#define LED_GPIO_CFG_GPBUF_2 (0x00000400)
24178 +#define LED_GPIO_CFG_GPBUF_3 (0x00000800)
24179 +#define LED_GPIO_CFG_GPDIR (0x000000F0)
24180 +#define LED_GPIO_CFG_GPDIR_0 (0x00000010)
24181 +#define LED_GPIO_CFG_GPDIR_1 (0x00000020)
24182 +#define LED_GPIO_CFG_GPDIR_2 (0x00000040)
24183 +#define LED_GPIO_CFG_GPDIR_3 (0x00000080)
24184 +#define LED_GPIO_CFG_GPDATA (0x0000000F)
24185 +#define LED_GPIO_CFG_GPDATA_0 (0x00000001)
24186 +#define LED_GPIO_CFG_GPDATA_1 (0x00000002)
24187 +#define LED_GPIO_CFG_GPDATA_2 (0x00000004)
24188 +#define LED_GPIO_CFG_GPDATA_3 (0x00000008)
24190 +#define GPIO_CFG (0x001C)
24191 +#define GPIO_CFG_SHIFT (24)
24192 +#define GPIO_CFG_GPEN (0xFF000000)
24193 +#define GPIO_CFG_GPBUF (0x00FF0000)
24194 +#define GPIO_CFG_GPDIR (0x0000FF00)
24195 +#define GPIO_CFG_GPDATA (0x000000FF)
24197 +#define GPIO_WAKE (0x0020)
24198 +#define GPIO_WAKE_PHY_LINKUP_EN (0x80000000)
24199 +#define GPIO_WAKE_POL (0x0FFF0000)
24200 +#define GPIO_WAKE_POL_SHIFT (16)
24201 +#define GPIO_WAKE_WK (0x00000FFF)
24203 +#define DP_SEL (0x0024)
24204 +#define DP_SEL_DPRDY (0x80000000)
24205 +#define DP_SEL_RSEL (0x0000000F)
24206 +#define DP_SEL_URX (0x00000000)
24207 +#define DP_SEL_VHF (0x00000001)
24208 +#define DP_SEL_VHF_HASH_LEN (16)
24209 +#define DP_SEL_VHF_VLAN_LEN (128)
24210 +#define DP_SEL_LSO_HEAD (0x00000002)
24211 +#define DP_SEL_FCT_RX (0x00000003)
24212 +#define DP_SEL_FCT_TX (0x00000004)
24213 +#define DP_SEL_DESCRIPTOR (0x00000005)
24214 +#define DP_SEL_WOL (0x00000006)
24216 +#define DP_CMD (0x0028)
24217 +#define DP_CMD_WRITE (0x01)
24218 +#define DP_CMD_READ (0x00)
24220 +#define DP_ADDR (0x002C)
24222 +#define DP_DATA (0x0030)
24224 +#define BURST_CAP (0x0034)
24225 +#define BURST_CAP_MASK (0x0000000F)
24227 +#define INT_EP_CTL (0x0038)
24228 +#define INT_EP_CTL_INTEP_ON (0x80000000)
24229 +#define INT_EP_CTL_RDFO_EN (0x00400000)
24230 +#define INT_EP_CTL_TXE_EN (0x00200000)
24231 +#define INT_EP_CTL_MACROTO_EN (0x00100000)
24232 +#define INT_EP_CTL_TX_DIS_EN (0x00080000)
24233 +#define INT_EP_CTL_RX_DIS_EN (0x00040000)
24234 +#define INT_EP_CTL_PHY_EN_ (0x00020000)
24235 +#define INT_EP_CTL_MAC_ERR_EN (0x00008000)
24236 +#define INT_EP_CTL_TDFU_EN (0x00004000)
24237 +#define INT_EP_CTL_TDFO_EN (0x00002000)
24238 +#define INT_EP_CTL_RX_FIFO_EN (0x00001000)
24239 +#define INT_EP_CTL_GPIOX_EN (0x00000FFF)
24241 +#define BULK_IN_DLY (0x003C)
24242 +#define BULK_IN_DLY_MASK (0xFFFF)
24244 +#define E2P_CMD (0x0040)
24245 +#define E2P_CMD_BUSY (0x80000000)
24246 +#define E2P_CMD_MASK (0x70000000)
24247 +#define E2P_CMD_READ (0x00000000)
24248 +#define E2P_CMD_EWDS (0x10000000)
24249 +#define E2P_CMD_EWEN (0x20000000)
24250 +#define E2P_CMD_WRITE (0x30000000)
24251 +#define E2P_CMD_WRAL (0x40000000)
24252 +#define E2P_CMD_ERASE (0x50000000)
24253 +#define E2P_CMD_ERAL (0x60000000)
24254 +#define E2P_CMD_RELOAD (0x70000000)
24255 +#define E2P_CMD_TIMEOUT (0x00000400)
24256 +#define E2P_CMD_LOADED (0x00000200)
24257 +#define E2P_CMD_ADDR (0x000001FF)
24259 +#define MAX_EEPROM_SIZE (512)
24261 +#define E2P_DATA (0x0044)
24262 +#define E2P_DATA_MASK_ (0x000000FF)
24264 +#define RFE_CTL (0x0060)
24265 +#define RFE_CTL_TCPUDP_CKM (0x00001000)
24266 +#define RFE_CTL_IP_CKM (0x00000800)
24267 +#define RFE_CTL_AB (0x00000400)
24268 +#define RFE_CTL_AM (0x00000200)
24269 +#define RFE_CTL_AU (0x00000100)
24270 +#define RFE_CTL_VS (0x00000080)
24271 +#define RFE_CTL_UF (0x00000040)
24272 +#define RFE_CTL_VF (0x00000020)
24273 +#define RFE_CTL_SPF (0x00000010)
24274 +#define RFE_CTL_MHF (0x00000008)
24275 +#define RFE_CTL_DHF (0x00000004)
24276 +#define RFE_CTL_DPF (0x00000002)
24277 +#define RFE_CTL_RST_RF (0x00000001)
24279 +#define VLAN_TYPE (0x0064)
24280 +#define VLAN_TYPE_MASK (0x0000FFFF)
24282 +#define FCT_RX_CTL (0x0090)
24283 +#define FCT_RX_CTL_EN (0x80000000)
24284 +#define FCT_RX_CTL_RST (0x40000000)
24285 +#define FCT_RX_CTL_SBF (0x02000000)
24286 +#define FCT_RX_CTL_OVERFLOW (0x01000000)
24287 +#define FCT_RX_CTL_FRM_DROP (0x00800000)
24288 +#define FCT_RX_CTL_RX_NOT_EMPTY (0x00400000)
24289 +#define FCT_RX_CTL_RX_EMPTY (0x00200000)
24290 +#define FCT_RX_CTL_RX_DISABLED (0x00100000)
24291 +#define FCT_RX_CTL_RXUSED (0x0000FFFF)
24293 +#define FCT_TX_CTL (0x0094)
24294 +#define FCT_TX_CTL_EN (0x80000000)
24295 +#define FCT_TX_CTL_RST (0x40000000)
24296 +#define FCT_TX_CTL_TX_NOT_EMPTY (0x00400000)
24297 +#define FCT_TX_CTL_TX_EMPTY (0x00200000)
24298 +#define FCT_TX_CTL_TX_DISABLED (0x00100000)
24299 +#define FCT_TX_CTL_TXUSED (0x0000FFFF)
24301 +#define FCT_RX_FIFO_END (0x0098)
24302 +#define FCT_RX_FIFO_END_MASK (0x0000007F)
24304 +#define FCT_TX_FIFO_END (0x009C)
24305 +#define FCT_TX_FIFO_END_MASK (0x0000003F)
24307 +#define FCT_FLOW (0x00A0)
24308 +#define FCT_FLOW_THRESHOLD_OFF (0x00007F00)
24309 +#define FCT_FLOW_THRESHOLD_OFF_SHIFT (8)
24310 +#define FCT_FLOW_THRESHOLD_ON (0x0000007F)
24313 +#define MAC_CR (0x100)
24314 +#define MAC_CR_ADP (0x00002000)
24315 +#define MAC_CR_ADD (0x00001000)
24316 +#define MAC_CR_ASD (0x00000800)
24317 +#define MAC_CR_INT_LOOP (0x00000400)
24318 +#define MAC_CR_BOLMT (0x000000C0)
24319 +#define MAC_CR_FDPX (0x00000008)
24320 +#define MAC_CR_CFG (0x00000006)
24321 +#define MAC_CR_CFG_10 (0x00000000)
24322 +#define MAC_CR_CFG_100 (0x00000002)
24323 +#define MAC_CR_CFG_1000 (0x00000004)
24324 +#define MAC_CR_RST (0x00000001)
24326 +#define MAC_RX (0x104)
24327 +#define MAC_RX_MAX_SIZE (0x3FFF0000)
24328 +#define MAC_RX_MAX_SIZE_SHIFT (16)
24329 +#define MAC_RX_FCS_STRIP (0x00000010)
24330 +#define MAC_RX_FSE (0x00000004)
24331 +#define MAC_RX_RXD (0x00000002)
24332 +#define MAC_RX_RXEN (0x00000001)
24334 +#define MAC_TX (0x108)
24335 +#define MAC_TX_BFCS (0x00000004)
24336 +#define MAC_TX_TXD (0x00000002)
24337 +#define MAC_TX_TXEN (0x00000001)
24339 +#define FLOW (0x10C)
24340 +#define FLOW_FORCE_FC (0x80000000)
24341 +#define FLOW_TX_FCEN (0x40000000)
24342 +#define FLOW_RX_FCEN (0x20000000)
24343 +#define FLOW_FPF (0x10000000)
24344 +#define FLOW_PAUSE_TIME (0x0000FFFF)
24346 +#define RAND_SEED (0x110)
24347 +#define RAND_SEED_MASK (0x0000FFFF)
24349 +#define ERR_STS (0x114)
24350 +#define ERR_STS_FCS_ERR (0x00000100)
24351 +#define ERR_STS_LFRM_ERR (0x00000080)
24352 +#define ERR_STS_RUNT_ERR (0x00000040)
24353 +#define ERR_STS_COLLISION_ERR (0x00000010)
24354 +#define ERR_STS_ALIGN_ERR (0x00000008)
24355 +#define ERR_STS_URUN_ERR (0x00000004)
24357 +#define RX_ADDRH (0x118)
24358 +#define RX_ADDRH_MASK (0x0000FFFF)
24360 +#define RX_ADDRL (0x11C)
24362 +#define MII_ACCESS (0x120)
24363 +#define MII_ACCESS_PHY_ADDR (0x0000F800)
24364 +#define MII_ACCESS_PHY_ADDR_SHIFT (11)
24365 +#define MII_ACCESS_REG_ADDR (0x000007C0)
24366 +#define MII_ACCESS_REG_ADDR_SHIFT (6)
24367 +#define MII_ACCESS_READ (0x00000000)
24368 +#define MII_ACCESS_WRITE (0x00000002)
24369 +#define MII_ACCESS_BUSY (0x00000001)
24371 +#define MII_DATA (0x124)
24372 +#define MII_DATA_MASK (0x0000FFFF)
24374 +#define WUCSR (0x140)
24375 +#define WUCSR_PFDA_FR (0x00000080)
24376 +#define WUCSR_WUFR (0x00000040)
24377 +#define WUCSR_MPR (0x00000020)
24378 +#define WUCSR_BCAST_FR (0x00000010)
24379 +#define WUCSR_PFDA_EN (0x00000008)
24380 +#define WUCSR_WUEN (0x00000004)
24381 +#define WUCSR_MPEN (0x00000002)
24382 +#define WUCSR_BCST_EN (0x00000001)
24384 +#define WUF_CFGX (0x144)
24385 +#define WUF_CFGX_EN (0x80000000)
24386 +#define WUF_CFGX_ATYPE (0x03000000)
24387 +#define WUF_CFGX_ATYPE_UNICAST (0x00000000)
24388 +#define WUF_CFGX_ATYPE_MULTICAST (0x02000000)
24389 +#define WUF_CFGX_ATYPE_ALL (0x03000000)
24390 +#define WUF_CFGX_PATTERN_OFFSET (0x007F0000)
24391 +#define WUF_CFGX_PATTERN_OFFSET_SHIFT (16)
24392 +#define WUF_CFGX_CRC16 (0x0000FFFF)
24393 +#define WUF_NUM (8)
24395 +#define WUF_MASKX (0x170)
24396 +#define WUF_MASKX_AVALID (0x80000000)
24397 +#define WUF_MASKX_ATYPE (0x40000000)
24399 +#define ADDR_FILTX (0x300)
24400 +#define ADDR_FILTX_FB_VALID (0x80000000)
24401 +#define ADDR_FILTX_FB_TYPE (0x40000000)
24402 +#define ADDR_FILTX_FB_ADDRHI (0x0000FFFF)
24403 +#define ADDR_FILTX_SB_ADDRLO (0xFFFFFFFF)
24405 +#define WUCSR2 (0x500)
24406 +#define WUCSR2_NS_RCD (0x00000040)
24407 +#define WUCSR2_ARP_RCD (0x00000020)
24408 +#define WUCSR2_TCPSYN_RCD (0x00000010)
24409 +#define WUCSR2_NS_OFFLOAD (0x00000004)
24410 +#define WUCSR2_ARP_OFFLOAD (0x00000002)
24411 +#define WUCSR2_TCPSYN_OFFLOAD (0x00000001)
24413 +#define WOL_FIFO_STS (0x504)
24415 +#define IPV6_ADDRX (0x510)
24417 +#define IPV4_ADDRX (0x590)
24420 +/* Vendor-specific PHY Definitions */
24422 +/* Mode Control/Status Register */
24423 +#define PHY_MODE_CTRL_STS (17)
24424 +#define MODE_CTRL_STS_EDPWRDOWN ((u16)0x2000)
24425 +#define MODE_CTRL_STS_ENERGYON ((u16)0x0002)
24427 +#define PHY_INT_SRC (29)
24428 +#define PHY_INT_SRC_ENERGY_ON ((u16)0x0080)
24429 +#define PHY_INT_SRC_ANEG_COMP ((u16)0x0040)
24430 +#define PHY_INT_SRC_REMOTE_FAULT ((u16)0x0020)
24431 +#define PHY_INT_SRC_LINK_DOWN ((u16)0x0010)
24432 +#define PHY_INT_SRC_CLEAR_ALL ((u16)0xffff)
24434 +#define PHY_INT_MASK (30)
24435 +#define PHY_INT_MASK_ENERGY_ON ((u16)0x0080)
24436 +#define PHY_INT_MASK_ANEG_COMP ((u16)0x0040)
24437 +#define PHY_INT_MASK_REMOTE_FAULT ((u16)0x0020)
24438 +#define PHY_INT_MASK_LINK_DOWN ((u16)0x0010)
24439 +#define PHY_INT_MASK_DEFAULT (PHY_INT_MASK_ANEG_COMP | \
24440 + PHY_INT_MASK_LINK_DOWN)
24442 +#define PHY_SPECIAL (31)
24443 +#define PHY_SPECIAL_SPD ((u16)0x001C)
24444 +#define PHY_SPECIAL_SPD_10HALF ((u16)0x0004)
24445 +#define PHY_SPECIAL_SPD_10FULL ((u16)0x0014)
24446 +#define PHY_SPECIAL_SPD_100HALF ((u16)0x0008)
24447 +#define PHY_SPECIAL_SPD_100FULL ((u16)0x0018)
24449 +/* USB Vendor Requests */
24450 +#define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
24451 +#define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
24452 +#define USB_VENDOR_REQUEST_GET_STATS 0xA2
24454 +/* Interrupt Endpoint status word bitfields */
24455 +#define INT_ENP_RDFO_INT ((u32)BIT(22))
24456 +#define INT_ENP_TXE_INT ((u32)BIT(21))
24457 +#define INT_ENP_TX_DIS_INT ((u32)BIT(19))
24458 +#define INT_ENP_RX_DIS_INT ((u32)BIT(18))
24459 +#define INT_ENP_PHY_INT ((u32)BIT(17))
24460 +#define INT_ENP_MAC_ERR_INT ((u32)BIT(15))
24461 +#define INT_ENP_RX_FIFO_DATA_INT ((u32)BIT(12))
24463 +#endif /* _SMSC75XX_H */
24464 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc95xx.c backports-4.2.6-1/drivers/net/usb/smsc95xx.c
24465 --- backports-4.2.6-1.org/drivers/net/usb/smsc95xx.c 1970-01-01 01:00:00.000000000 +0100
24466 +++ backports-4.2.6-1/drivers/net/usb/smsc95xx.c 2016-06-28 14:35:18.011973884 +0200
24468 + /***************************************************************************
24470 + * Copyright (C) 2007-2008 SMSC
24472 + * This program is free software; you can redistribute it and/or
24473 + * modify it under the terms of the GNU General Public License
24474 + * as published by the Free Software Foundation; either version 2
24475 + * of the License, or (at your option) any later version.
24477 + * This program is distributed in the hope that it will be useful,
24478 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24480 + * GNU General Public License for more details.
24482 + * You should have received a copy of the GNU General Public License
24483 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
24485 + *****************************************************************************/
24487 +#include <linux/module.h>
24488 +#include <linux/kmod.h>
24489 +#include <linux/netdevice.h>
24490 +#include <linux/etherdevice.h>
24491 +#include <linux/ethtool.h>
24492 +#include <linux/mii.h>
24493 +#include <linux/usb.h>
24494 +#include <linux/bitrev.h>
24495 +#include <linux/crc16.h>
24496 +#include <linux/crc32.h>
24497 +#include <linux/usb/usbnet.h>
24498 +#include <linux/slab.h>
24499 +#include "smsc95xx.h"
24501 +#define SMSC_CHIPNAME "smsc95xx"
24502 +#define SMSC_DRIVER_VERSION "1.0.4"
24503 +#define HS_USB_PKT_SIZE (512)
24504 +#define FS_USB_PKT_SIZE (64)
24505 +#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
24506 +#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
24507 +#define DEFAULT_BULK_IN_DELAY (0x00002000)
24508 +#define MAX_SINGLE_PACKET_SIZE (2048)
24509 +#define LAN95XX_EEPROM_MAGIC (0x9500)
24510 +#define EEPROM_MAC_OFFSET (0x01)
24511 +#define DEFAULT_TX_CSUM_ENABLE (true)
24512 +#define DEFAULT_RX_CSUM_ENABLE (true)
24513 +#define SMSC95XX_INTERNAL_PHY_ID (1)
24514 +#define SMSC95XX_TX_OVERHEAD (8)
24515 +#define SMSC95XX_TX_OVERHEAD_CSUM (12)
24516 +#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
24517 + WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
24519 +#define FEATURE_8_WAKEUP_FILTERS (0x01)
24520 +#define FEATURE_PHY_NLP_CROSSOVER (0x02)
24521 +#define FEATURE_REMOTE_WAKEUP (0x04)
24523 +#define SUSPEND_SUSPEND0 (0x01)
24524 +#define SUSPEND_SUSPEND1 (0x02)
24525 +#define SUSPEND_SUSPEND2 (0x04)
24526 +#define SUSPEND_SUSPEND3 (0x08)
24527 +#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
24528 + SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
24530 +struct smsc95xx_priv {
24535 + spinlock_t mac_cr_lock;
24537 + u8 suspend_flags;
24540 +static bool turbo_mode = true;
24541 +module_param(turbo_mode, bool, 0644);
24542 +MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
24544 +static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
24545 + u32 *data, int in_pm)
24549 + int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
24554 + fn = usbnet_read_cmd;
24556 + fn = usbnet_read_cmd_nopm;
24558 + ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
24559 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
24560 + 0, index, &buf, 4);
24561 + if (unlikely(ret < 0))
24562 + netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
24565 + le32_to_cpus(&buf);
24571 +static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
24572 + u32 data, int in_pm)
24576 + int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
24581 + fn = usbnet_write_cmd;
24583 + fn = usbnet_write_cmd_nopm;
24586 + cpu_to_le32s(&buf);
24588 + ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
24589 + | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
24590 + 0, index, &buf, 4);
24591 + if (unlikely(ret < 0))
24592 + netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
24598 +static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
24601 + return __smsc95xx_read_reg(dev, index, data, 1);
24604 +static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
24607 + return __smsc95xx_write_reg(dev, index, data, 1);
24610 +static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
24613 + return __smsc95xx_read_reg(dev, index, data, 0);
24616 +static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
24619 + return __smsc95xx_write_reg(dev, index, data, 0);
24622 +/* Loop until the read is completed with timeout
24623 + * called with phy_mutex held */
24624 +static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
24627 + unsigned long start_time = jiffies;
24632 + ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
24634 + netdev_warn(dev->net, "Error reading MII_ACCESS\n");
24638 + if (!(val & MII_BUSY_))
24640 + } while (!time_after(jiffies, start_time + HZ));
24645 +static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
24648 + struct usbnet *dev = netdev_priv(netdev);
24652 + mutex_lock(&dev->phy_mutex);
24654 + /* confirm MII not busy */
24655 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24657 + netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n");
24661 + /* set the address, index & direction (read from PHY) */
24662 + phy_id &= dev->mii.phy_id_mask;
24663 + idx &= dev->mii.reg_num_mask;
24664 + addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_;
24665 + ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
24667 + netdev_warn(dev->net, "Error writing MII_ADDR\n");
24671 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24673 + netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
24677 + ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
24679 + netdev_warn(dev->net, "Error reading MII_DATA\n");
24683 + ret = (u16)(val & 0xFFFF);
24686 + mutex_unlock(&dev->phy_mutex);
24690 +static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,
24691 + int idx, int regval, int in_pm)
24693 + struct usbnet *dev = netdev_priv(netdev);
24697 + mutex_lock(&dev->phy_mutex);
24699 + /* confirm MII not busy */
24700 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24702 + netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n");
24707 + ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
24709 + netdev_warn(dev->net, "Error writing MII_DATA\n");
24713 + /* set the address, index & direction (write to PHY) */
24714 + phy_id &= dev->mii.phy_id_mask;
24715 + idx &= dev->mii.reg_num_mask;
24716 + addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_;
24717 + ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
24719 + netdev_warn(dev->net, "Error writing MII_ADDR\n");
24723 + ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
24725 + netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
24730 + mutex_unlock(&dev->phy_mutex);
24733 +static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
24736 + return __smsc95xx_mdio_read(netdev, phy_id, idx, 1);
24739 +static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
24740 + int idx, int regval)
24742 + __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1);
24745 +static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
24747 + return __smsc95xx_mdio_read(netdev, phy_id, idx, 0);
24750 +static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
24753 + __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0);
24756 +static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
24758 + unsigned long start_time = jiffies;
24763 + ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
24765 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
24769 + if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
24772 + } while (!time_after(jiffies, start_time + HZ));
24774 + if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
24775 + netdev_warn(dev->net, "EEPROM read operation timeout\n");
24782 +static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
24784 + unsigned long start_time = jiffies;
24789 + ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
24791 + netdev_warn(dev->net, "Error reading E2P_CMD\n");
24795 + if (!(val & E2P_CMD_BUSY_))
24799 + } while (!time_after(jiffies, start_time + HZ));
24801 + netdev_warn(dev->net, "EEPROM is busy\n");
24805 +static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
24814 + ret = smsc95xx_eeprom_confirm_not_busy(dev);
24818 + for (i = 0; i < length; i++) {
24819 + val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
24820 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24822 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
24826 + ret = smsc95xx_wait_eeprom(dev);
24830 + ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
24832 + netdev_warn(dev->net, "Error reading E2P_DATA\n");
24836 + data[i] = val & 0xFF;
24843 +static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
24852 + ret = smsc95xx_eeprom_confirm_not_busy(dev);
24856 + /* Issue write/erase enable command */
24857 + val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
24858 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24860 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
24864 + ret = smsc95xx_wait_eeprom(dev);
24868 + for (i = 0; i < length; i++) {
24870 + /* Fill data register */
24872 + ret = smsc95xx_write_reg(dev, E2P_DATA, val);
24874 + netdev_warn(dev->net, "Error writing E2P_DATA\n");
24878 + /* Send "write" command */
24879 + val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
24880 + ret = smsc95xx_write_reg(dev, E2P_CMD, val);
24882 + netdev_warn(dev->net, "Error writing E2P_CMD\n");
24886 + ret = smsc95xx_wait_eeprom(dev);
24896 +static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
24899 + const u16 size = 4;
24904 + cpu_to_le32s(&buf);
24906 + ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
24907 + USB_DIR_OUT | USB_TYPE_VENDOR |
24908 + USB_RECIP_DEVICE,
24909 + 0, index, &buf, size);
24911 + netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
24916 +/* returns hash bit number for given MAC address
24918 + * 01 00 5E 00 00 01 -> returns bit number 31 */
24919 +static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
24921 + return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
24924 +static void smsc95xx_set_multicast(struct net_device *netdev)
24926 + struct usbnet *dev = netdev_priv(netdev);
24927 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
24928 + unsigned long flags;
24931 + pdata->hash_hi = 0;
24932 + pdata->hash_lo = 0;
24934 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
24936 + if (dev->net->flags & IFF_PROMISC) {
24937 + netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
24938 + pdata->mac_cr |= MAC_CR_PRMS_;
24939 + pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
24940 + } else if (dev->net->flags & IFF_ALLMULTI) {
24941 + netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
24942 + pdata->mac_cr |= MAC_CR_MCPAS_;
24943 + pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
24944 + } else if (!netdev_mc_empty(dev->net)) {
24945 + struct netdev_hw_addr *ha;
24947 + pdata->mac_cr |= MAC_CR_HPFILT_;
24948 + pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
24950 + netdev_for_each_mc_addr(ha, netdev) {
24951 + u32 bitnum = smsc95xx_hash(ha->addr);
24952 + u32 mask = 0x01 << (bitnum & 0x1F);
24953 + if (bitnum & 0x20)
24954 + pdata->hash_hi |= mask;
24956 + pdata->hash_lo |= mask;
24959 + netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
24960 + pdata->hash_hi, pdata->hash_lo);
24962 + netif_dbg(dev, drv, dev->net, "receive own packets only\n");
24964 + ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
24967 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
24969 + /* Initiate async writes, as we can't wait for completion here */
24970 + ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi);
24972 + netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
24974 + ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo);
24976 + netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
24978 + ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr);
24980 + netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
24983 +static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
24984 + u16 lcladv, u16 rmtadv)
24986 + u32 flow, afc_cfg = 0;
24988 + int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
24992 + if (duplex == DUPLEX_FULL) {
24993 + u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
24995 + if (cap & FLOW_CTRL_RX)
24996 + flow = 0xFFFF0002;
25000 + if (cap & FLOW_CTRL_TX)
25005 + netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
25006 + cap & FLOW_CTRL_RX ? "enabled" : "disabled",
25007 + cap & FLOW_CTRL_TX ? "enabled" : "disabled");
25009 + netif_dbg(dev, link, dev->net, "half duplex\n");
25014 + ret = smsc95xx_write_reg(dev, FLOW, flow);
25018 + return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
25021 +static int smsc95xx_link_reset(struct usbnet *dev)
25023 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25024 + struct mii_if_info *mii = &dev->mii;
25025 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
25026 + unsigned long flags;
25027 + u16 lcladv, rmtadv;
25030 + /* clear interrupt status */
25031 + ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
25035 + ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
25039 + mii_check_media(mii, 1, 1);
25040 + mii_ethtool_gset(&dev->mii, &ecmd);
25041 + lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
25042 + rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
25044 + netif_dbg(dev, link, dev->net,
25045 + "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
25046 + ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
25048 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25049 + if (ecmd.duplex != DUPLEX_FULL) {
25050 + pdata->mac_cr &= ~MAC_CR_FDPX_;
25051 + pdata->mac_cr |= MAC_CR_RCVOWN_;
25053 + pdata->mac_cr &= ~MAC_CR_RCVOWN_;
25054 + pdata->mac_cr |= MAC_CR_FDPX_;
25056 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25058 + ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
25062 + ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
25064 + netdev_warn(dev->net, "Error updating PHY flow control\n");
25069 +static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
25073 + if (urb->actual_length != 4) {
25074 + netdev_warn(dev->net, "unexpected urb length %d\n",
25075 + urb->actual_length);
25079 + memcpy(&intdata, urb->transfer_buffer, 4);
25080 + le32_to_cpus(&intdata);
25082 + netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
25084 + if (intdata & INT_ENP_PHY_INT_)
25085 + usbnet_defer_kevent(dev, EVENT_LINK_RESET);
25087 + netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
25091 +/* Enable or disable Tx & Rx checksum offload engines */
25092 +static int smsc95xx_set_features(struct net_device *netdev,
25093 + netdev_features_t features)
25095 + struct usbnet *dev = netdev_priv(netdev);
25099 + ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
25103 + if (features & NETIF_F_HW_CSUM)
25104 + read_buf |= Tx_COE_EN_;
25106 + read_buf &= ~Tx_COE_EN_;
25108 + if (features & NETIF_F_RXCSUM)
25109 + read_buf |= Rx_COE_EN_;
25111 + read_buf &= ~Rx_COE_EN_;
25113 + ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
25117 + netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
25121 +static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
25123 + return MAX_EEPROM_SIZE;
25126 +static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
25127 + struct ethtool_eeprom *ee, u8 *data)
25129 + struct usbnet *dev = netdev_priv(netdev);
25131 + ee->magic = LAN95XX_EEPROM_MAGIC;
25133 + return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
25136 +static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
25137 + struct ethtool_eeprom *ee, u8 *data)
25139 + struct usbnet *dev = netdev_priv(netdev);
25141 + if (ee->magic != LAN95XX_EEPROM_MAGIC) {
25142 + netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
25147 + return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
25150 +static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
25152 + /* all smsc95xx registers */
25153 + return COE_CR - ID_REV + sizeof(u32);
25157 +smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
25160 + struct usbnet *dev = netdev_priv(netdev);
25161 + unsigned int i, j;
25165 + retval = smsc95xx_read_reg(dev, ID_REV, ®s->version);
25166 + if (retval < 0) {
25167 + netdev_warn(netdev, "REGS: cannot read ID_REV\n");
25171 + for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
25172 + retval = smsc95xx_read_reg(dev, i, &data[j]);
25173 + if (retval < 0) {
25174 + netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
25180 +static void smsc95xx_ethtool_get_wol(struct net_device *net,
25181 + struct ethtool_wolinfo *wolinfo)
25183 + struct usbnet *dev = netdev_priv(net);
25184 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25186 + wolinfo->supported = SUPPORTED_WAKE;
25187 + wolinfo->wolopts = pdata->wolopts;
25190 +static int smsc95xx_ethtool_set_wol(struct net_device *net,
25191 + struct ethtool_wolinfo *wolinfo)
25193 + struct usbnet *dev = netdev_priv(net);
25194 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25197 + pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
25199 + ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
25201 + netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
25206 +static const struct ethtool_ops smsc95xx_ethtool_ops = {
25207 + .get_link = usbnet_get_link,
25208 + .nway_reset = usbnet_nway_reset,
25209 + .get_drvinfo = usbnet_get_drvinfo,
25210 + .get_msglevel = usbnet_get_msglevel,
25211 + .set_msglevel = usbnet_set_msglevel,
25212 + .get_settings = usbnet_get_settings,
25213 + .set_settings = usbnet_set_settings,
25214 + .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
25215 + .get_eeprom = smsc95xx_ethtool_get_eeprom,
25216 + .set_eeprom = smsc95xx_ethtool_set_eeprom,
25217 + .get_regs_len = smsc95xx_ethtool_getregslen,
25218 + .get_regs = smsc95xx_ethtool_getregs,
25219 + .get_wol = smsc95xx_ethtool_get_wol,
25220 + .set_wol = smsc95xx_ethtool_set_wol,
25223 +static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
25225 + struct usbnet *dev = netdev_priv(netdev);
25227 + if (!netif_running(netdev))
25230 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
25233 +static void smsc95xx_init_mac_address(struct usbnet *dev)
25235 + /* try reading mac address from EEPROM */
25236 + if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
25237 + dev->net->dev_addr) == 0) {
25238 + if (is_valid_ether_addr(dev->net->dev_addr)) {
25239 + /* eeprom values are valid so use them */
25240 + netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
25245 + /* no eeprom, or eeprom values are invalid. generate random MAC */
25246 + eth_hw_addr_random(dev->net);
25247 + netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
25250 +static int smsc95xx_set_mac_address(struct usbnet *dev)
25252 + u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
25253 + dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
25254 + u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
25257 + ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
25261 + return smsc95xx_write_reg(dev, ADDRH, addr_hi);
25264 +/* starts the TX path */
25265 +static int smsc95xx_start_tx_path(struct usbnet *dev)
25267 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25268 + unsigned long flags;
25271 + /* Enable Tx at MAC */
25272 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25273 + pdata->mac_cr |= MAC_CR_TXEN_;
25274 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25276 + ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
25280 + /* Enable Tx at SCSRs */
25281 + return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
25284 +/* Starts the Receive path */
25285 +static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
25287 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25288 + unsigned long flags;
25290 + spin_lock_irqsave(&pdata->mac_cr_lock, flags);
25291 + pdata->mac_cr |= MAC_CR_RXEN_;
25292 + spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
25294 + return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
25297 +static int smsc95xx_phy_initialize(struct usbnet *dev)
25299 + int bmcr, ret, timeout = 0;
25301 + /* Initialize MII structure */
25302 + dev->mii.dev = dev->net;
25303 + dev->mii.mdio_read = smsc95xx_mdio_read;
25304 + dev->mii.mdio_write = smsc95xx_mdio_write;
25305 + dev->mii.phy_id_mask = 0x1f;
25306 + dev->mii.reg_num_mask = 0x1f;
25307 + dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
25309 + /* reset phy and wait for reset to complete */
25310 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
25314 + bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
25316 + } while ((bmcr & BMCR_RESET) && (timeout < 100));
25318 + if (timeout >= 100) {
25319 + netdev_warn(dev->net, "timeout on PHY Reset");
25323 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
25324 + ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
25325 + ADVERTISE_PAUSE_ASYM);
25327 + /* read to clear */
25328 + ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
25330 + netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n");
25334 + smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
25335 + PHY_INT_MASK_DEFAULT_);
25336 + mii_nway_restart(&dev->mii);
25338 + netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
25342 +static int smsc95xx_reset(struct usbnet *dev)
25344 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25345 + u32 read_buf, write_buf, burst_cap;
25346 + int ret = 0, timeout;
25348 + netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
25350 + ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
25357 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25361 + } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
25363 + if (timeout >= 100) {
25364 + netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
25368 + ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
25375 + ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
25379 + } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
25381 + if (timeout >= 100) {
25382 + netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
25386 + ret = smsc95xx_set_mac_address(dev);
25390 + netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
25391 + dev->net->dev_addr);
25393 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25397 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
25400 + read_buf |= HW_CFG_BIR_;
25402 + ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
25406 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25410 + netif_dbg(dev, ifup, dev->net,
25411 + "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
25414 + if (!turbo_mode) {
25416 + dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
25417 + } else if (dev->udev->speed == USB_SPEED_HIGH) {
25418 + burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
25419 + dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
25421 + burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
25422 + dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
25425 + netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
25426 + (ulong)dev->rx_urb_size);
25428 + ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
25432 + ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
25436 + netif_dbg(dev, ifup, dev->net,
25437 + "Read Value from BURST_CAP after writing: 0x%08x\n",
25440 + ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
25444 + ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
25448 + netif_dbg(dev, ifup, dev->net,
25449 + "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
25452 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25456 + netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
25460 + read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
25462 + read_buf &= ~HW_CFG_RXDOFF_;
25464 + /* set Rx data offset=2, Make IP header aligns on word boundary. */
25465 + read_buf |= NET_IP_ALIGN << 9;
25467 + ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
25471 + ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
25475 + netif_dbg(dev, ifup, dev->net,
25476 + "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
25478 + ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
25482 + ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
25485 + netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
25487 + /* Configure GPIO pins as LED outputs */
25488 + write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
25489 + LED_GPIO_CFG_FDX_LED;
25490 + ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
25495 + ret = smsc95xx_write_reg(dev, FLOW, 0);
25499 + ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
25503 + /* Don't need mac_cr_lock during initialisation */
25504 + ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
25510 + ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
25514 + /* Enable or disable checksum offload engines */
25515 + ret = smsc95xx_set_features(dev->net, dev->net->features);
25517 + netdev_warn(dev->net, "Failed to set checksum offload features\n");
25521 + smsc95xx_set_multicast(dev->net);
25523 + ret = smsc95xx_phy_initialize(dev);
25525 + netdev_warn(dev->net, "Failed to init PHY\n");
25529 + ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
25533 + /* enable PHY interrupts */
25534 + read_buf |= INT_EP_CTL_PHY_INT_;
25536 + ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
25540 + ret = smsc95xx_start_tx_path(dev);
25542 + netdev_warn(dev->net, "Failed to start TX path\n");
25546 + ret = smsc95xx_start_rx_path(dev, 0);
25548 + netdev_warn(dev->net, "Failed to start RX path\n");
25552 + netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
25556 +static const struct net_device_ops smsc95xx_netdev_ops = {
25557 + .ndo_open = usbnet_open,
25558 + .ndo_stop = usbnet_stop,
25559 + .ndo_start_xmit = usbnet_start_xmit,
25560 + .ndo_tx_timeout = usbnet_tx_timeout,
25561 + .ndo_change_mtu = usbnet_change_mtu,
25562 + .ndo_set_mac_address = eth_mac_addr,
25563 + .ndo_validate_addr = eth_validate_addr,
25564 + .ndo_do_ioctl = smsc95xx_ioctl,
25565 + .ndo_set_rx_mode = smsc95xx_set_multicast,
25566 + .ndo_set_features = smsc95xx_set_features,
25569 +static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
25571 + struct smsc95xx_priv *pdata = NULL;
25575 + printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
25577 + ret = usbnet_get_endpoints(dev, intf);
25579 + netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
25583 + dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
25586 + pdata = (struct smsc95xx_priv *)(dev->data[0]);
25590 + spin_lock_init(&pdata->mac_cr_lock);
25592 + if (DEFAULT_TX_CSUM_ENABLE)
25593 + dev->net->features |= NETIF_F_HW_CSUM;
25594 + if (DEFAULT_RX_CSUM_ENABLE)
25595 + dev->net->features |= NETIF_F_RXCSUM;
25597 + dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
25599 + smsc95xx_init_mac_address(dev);
25601 + /* Init all registers */
25602 + ret = smsc95xx_reset(dev);
25604 + /* detect device revision as different features may be available */
25605 + ret = smsc95xx_read_reg(dev, ID_REV, &val);
25610 + if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
25611 + (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
25612 + pdata->features = (FEATURE_8_WAKEUP_FILTERS |
25613 + FEATURE_PHY_NLP_CROSSOVER |
25614 + FEATURE_REMOTE_WAKEUP);
25615 + else if (val == ID_REV_CHIP_ID_9512_)
25616 + pdata->features = FEATURE_8_WAKEUP_FILTERS;
25618 + dev->net->netdev_ops = &smsc95xx_netdev_ops;
25619 + dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
25620 + dev->net->flags |= IFF_MULTICAST;
25621 + dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
25622 + dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
25626 +static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
25628 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25630 + netif_dbg(dev, ifdown, dev->net, "free pdata\n");
25633 + dev->data[0] = 0;
25637 +static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
25639 + u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
25640 + return crc << ((filter % 2) * 16);
25643 +static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
25645 + struct mii_if_info *mii = &dev->mii;
25648 + netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
25650 + /* read to clear */
25651 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
25655 + /* enable interrupt source */
25656 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
25662 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
25667 +static int smsc95xx_link_ok_nopm(struct usbnet *dev)
25669 + struct mii_if_info *mii = &dev->mii;
25672 + /* first, a dummy read, needed to latch some MII phys */
25673 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
25677 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
25681 + return !!(ret & BMSR_LSTATUS);
25684 +static int smsc95xx_enter_suspend0(struct usbnet *dev)
25686 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25690 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25694 + val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
25695 + val |= PM_CTL_SUS_MODE_0;
25697 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25701 + /* clear wol status */
25702 + val &= ~PM_CTL_WUPS_;
25703 + val |= PM_CTL_WUPS_WOL_;
25705 + /* enable energy detection */
25706 + if (pdata->wolopts & WAKE_PHY)
25707 + val |= PM_CTL_WUPS_ED_;
25709 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25713 + /* read back PM_CTRL */
25714 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25718 + pdata->suspend_flags |= SUSPEND_SUSPEND0;
25723 +static int smsc95xx_enter_suspend1(struct usbnet *dev)
25725 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25726 + struct mii_if_info *mii = &dev->mii;
25730 + /* reconfigure link pulse detection timing for
25731 + * compatibility with non-standard link partners
25733 + if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
25734 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG,
25735 + PHY_EDPD_CONFIG_DEFAULT);
25737 + /* enable energy detect power-down mode */
25738 + ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS);
25742 + ret |= MODE_CTRL_STS_EDPWRDOWN_;
25744 + smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret);
25746 + /* enter SUSPEND1 mode */
25747 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25751 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25752 + val |= PM_CTL_SUS_MODE_1;
25754 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25758 + /* clear wol status, enable energy detection */
25759 + val &= ~PM_CTL_WUPS_;
25760 + val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
25762 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25766 + pdata->suspend_flags |= SUSPEND_SUSPEND1;
25771 +static int smsc95xx_enter_suspend2(struct usbnet *dev)
25773 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25777 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25781 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25782 + val |= PM_CTL_SUS_MODE_2;
25784 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25788 + pdata->suspend_flags |= SUSPEND_SUSPEND2;
25793 +static int smsc95xx_enter_suspend3(struct usbnet *dev)
25795 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25799 + ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val);
25803 + if (val & 0xFFFF) {
25804 + netdev_info(dev->net, "rx fifo not empty in autosuspend\n");
25808 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25812 + val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
25813 + val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS;
25815 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25819 + /* clear wol status */
25820 + val &= ~PM_CTL_WUPS_;
25821 + val |= PM_CTL_WUPS_WOL_;
25823 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25827 + pdata->suspend_flags |= SUSPEND_SUSPEND3;
25832 +static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
25834 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25837 + if (!netif_running(dev->net)) {
25838 + /* interface is ifconfig down so fully power down hw */
25839 + netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
25840 + return smsc95xx_enter_suspend2(dev);
25844 + /* link is down so enter EDPD mode, but only if device can
25845 + * reliably resume from it. This check should be redundant
25846 + * as current FEATURE_REMOTE_WAKEUP parts also support
25847 + * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */
25848 + if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) {
25849 + netdev_warn(dev->net, "EDPD not supported\n");
25853 + netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
25855 + /* enable PHY wakeup events for if cable is attached */
25856 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25857 + PHY_INT_MASK_ANEG_COMP_);
25859 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25863 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
25864 + return smsc95xx_enter_suspend1(dev);
25867 + /* enable PHY wakeup events so we remote wakeup if cable is pulled */
25868 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25869 + PHY_INT_MASK_LINK_DOWN_);
25871 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25875 + netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
25876 + return smsc95xx_enter_suspend3(dev);
25879 +static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
25881 + struct usbnet *dev = usb_get_intfdata(intf);
25882 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
25883 + u32 val, link_up;
25886 + ret = usbnet_suspend(intf, message);
25888 + netdev_warn(dev->net, "usbnet_suspend error\n");
25892 + if (pdata->suspend_flags) {
25893 + netdev_warn(dev->net, "error during last resume\n");
25894 + pdata->suspend_flags = 0;
25897 + /* determine if link is up using only _nopm functions */
25898 + link_up = smsc95xx_link_ok_nopm(dev);
25900 + if (message.event == PM_EVENT_AUTO_SUSPEND &&
25901 + (pdata->features & FEATURE_REMOTE_WAKEUP)) {
25902 + ret = smsc95xx_autosuspend(dev, link_up);
25906 + /* if we get this far we're not autosuspending */
25907 + /* if no wol options set, or if link is down and we're not waking on
25908 + * PHY activity, enter lowest power SUSPEND2 mode
25910 + if (!(pdata->wolopts & SUPPORTED_WAKE) ||
25911 + !(link_up || (pdata->wolopts & WAKE_PHY))) {
25912 + netdev_info(dev->net, "entering SUSPEND2 mode\n");
25914 + /* disable energy detect (link up) & wake up events */
25915 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
25919 + val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
25921 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
25925 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
25929 + val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
25931 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
25935 + ret = smsc95xx_enter_suspend2(dev);
25939 + if (pdata->wolopts & WAKE_PHY) {
25940 + ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
25941 + (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_));
25943 + netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
25947 + /* if link is down then configure EDPD and enter SUSPEND1,
25948 + * otherwise enter SUSPEND0 below
25951 + netdev_info(dev->net, "entering SUSPEND1 mode\n");
25952 + ret = smsc95xx_enter_suspend1(dev);
25957 + if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
25958 + u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL);
25962 + int wuff_filter_count =
25963 + (pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
25964 + LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
25965 + int i, filter = 0;
25967 + if (!filter_mask) {
25968 + netdev_warn(dev->net, "Unable to allocate filter_mask\n");
25973 + memset(command, 0, sizeof(command));
25974 + memset(offset, 0, sizeof(offset));
25975 + memset(crc, 0, sizeof(crc));
25977 + if (pdata->wolopts & WAKE_BCAST) {
25978 + const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
25979 + netdev_info(dev->net, "enabling broadcast detection\n");
25980 + filter_mask[filter * 4] = 0x003F;
25981 + filter_mask[filter * 4 + 1] = 0x00;
25982 + filter_mask[filter * 4 + 2] = 0x00;
25983 + filter_mask[filter * 4 + 3] = 0x00;
25984 + command[filter/4] |= 0x05UL << ((filter % 4) * 8);
25985 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
25986 + crc[filter/2] |= smsc_crc(bcast, 6, filter);
25990 + if (pdata->wolopts & WAKE_MCAST) {
25991 + const u8 mcast[] = {0x01, 0x00, 0x5E};
25992 + netdev_info(dev->net, "enabling multicast detection\n");
25993 + filter_mask[filter * 4] = 0x0007;
25994 + filter_mask[filter * 4 + 1] = 0x00;
25995 + filter_mask[filter * 4 + 2] = 0x00;
25996 + filter_mask[filter * 4 + 3] = 0x00;
25997 + command[filter/4] |= 0x09UL << ((filter % 4) * 8);
25998 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
25999 + crc[filter/2] |= smsc_crc(mcast, 3, filter);
26003 + if (pdata->wolopts & WAKE_ARP) {
26004 + const u8 arp[] = {0x08, 0x06};
26005 + netdev_info(dev->net, "enabling ARP detection\n");
26006 + filter_mask[filter * 4] = 0x0003;
26007 + filter_mask[filter * 4 + 1] = 0x00;
26008 + filter_mask[filter * 4 + 2] = 0x00;
26009 + filter_mask[filter * 4 + 3] = 0x00;
26010 + command[filter/4] |= 0x05UL << ((filter % 4) * 8);
26011 + offset[filter/4] |= 0x0C << ((filter % 4) * 8);
26012 + crc[filter/2] |= smsc_crc(arp, 2, filter);
26016 + if (pdata->wolopts & WAKE_UCAST) {
26017 + netdev_info(dev->net, "enabling unicast detection\n");
26018 + filter_mask[filter * 4] = 0x003F;
26019 + filter_mask[filter * 4 + 1] = 0x00;
26020 + filter_mask[filter * 4 + 2] = 0x00;
26021 + filter_mask[filter * 4 + 3] = 0x00;
26022 + command[filter/4] |= 0x01UL << ((filter % 4) * 8);
26023 + offset[filter/4] |= 0x00 << ((filter % 4) * 8);
26024 + crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
26028 + for (i = 0; i < (wuff_filter_count * 4); i++) {
26029 + ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
26031 + kfree(filter_mask);
26035 + kfree(filter_mask);
26037 + for (i = 0; i < (wuff_filter_count / 4); i++) {
26038 + ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
26043 + for (i = 0; i < (wuff_filter_count / 4); i++) {
26044 + ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
26049 + for (i = 0; i < (wuff_filter_count / 2); i++) {
26050 + ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
26055 + /* clear any pending pattern match packet status */
26056 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26060 + val |= WUCSR_WUFR_;
26062 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26067 + if (pdata->wolopts & WAKE_MAGIC) {
26068 + /* clear any pending magic packet status */
26069 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26073 + val |= WUCSR_MPR_;
26075 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26080 + /* enable/disable wakeup sources */
26081 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26085 + if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
26086 + netdev_info(dev->net, "enabling pattern match wakeup\n");
26087 + val |= WUCSR_WAKE_EN_;
26089 + netdev_info(dev->net, "disabling pattern match wakeup\n");
26090 + val &= ~WUCSR_WAKE_EN_;
26093 + if (pdata->wolopts & WAKE_MAGIC) {
26094 + netdev_info(dev->net, "enabling magic packet wakeup\n");
26095 + val |= WUCSR_MPEN_;
26097 + netdev_info(dev->net, "disabling magic packet wakeup\n");
26098 + val &= ~WUCSR_MPEN_;
26101 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26105 + /* enable wol wakeup source */
26106 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
26110 + val |= PM_CTL_WOL_EN_;
26112 + /* phy energy detect wakeup source */
26113 + if (pdata->wolopts & WAKE_PHY)
26114 + val |= PM_CTL_ED_EN_;
26116 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
26120 + /* enable receiver to enable frame reception */
26121 + smsc95xx_start_rx_path(dev, 1);
26123 + /* some wol options are enabled, so enter SUSPEND0 */
26124 + netdev_info(dev->net, "entering SUSPEND0 mode\n");
26125 + ret = smsc95xx_enter_suspend0(dev);
26129 + * TODO: resume() might need to handle the suspend failure
26130 + * in system sleep
26132 + if (ret && PMSG_IS_AUTO(message))
26133 + usbnet_resume(intf);
26137 +static int smsc95xx_resume(struct usb_interface *intf)
26139 + struct usbnet *dev = usb_get_intfdata(intf);
26140 + struct smsc95xx_priv *pdata;
26141 + u8 suspend_flags;
26146 + pdata = (struct smsc95xx_priv *)(dev->data[0]);
26147 + suspend_flags = pdata->suspend_flags;
26149 + netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
26151 + /* do this first to ensure it's cleared even in error case */
26152 + pdata->suspend_flags = 0;
26154 + if (suspend_flags & SUSPEND_ALLMODES) {
26155 + /* clear wake-up sources */
26156 + ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
26160 + val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
26162 + ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
26166 + /* clear wake-up status */
26167 + ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
26171 + val &= ~PM_CTL_WOL_EN_;
26172 + val |= PM_CTL_WUPS_;
26174 + ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
26179 + ret = usbnet_resume(intf);
26181 + netdev_warn(dev->net, "usbnet_resume error\n");
26186 +static int smsc95xx_reset_resume(struct usb_interface *intf)
26188 + struct usbnet *dev = usb_get_intfdata(intf);
26191 + ret = smsc95xx_reset(dev);
26195 + return smsc95xx_resume(intf);
26198 +static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
26200 + skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
26201 + skb->ip_summed = CHECKSUM_COMPLETE;
26202 + skb_trim(skb, skb->len - 2);
26205 +static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
26207 + /* This check is no longer done by usbnet */
26208 + if (skb->len < dev->net->hard_header_len)
26211 + while (skb->len > 0) {
26212 + u32 header, align_count;
26213 + struct sk_buff *ax_skb;
26214 + unsigned char *packet;
26217 + memcpy(&header, skb->data, sizeof(header));
26218 + le32_to_cpus(&header);
26219 + skb_pull(skb, 4 + NET_IP_ALIGN);
26220 + packet = skb->data;
26222 + /* get the packet length */
26223 + size = (u16)((header & RX_STS_FL_) >> 16);
26224 + align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
26226 + if (unlikely(header & RX_STS_ES_)) {
26227 + netif_dbg(dev, rx_err, dev->net,
26228 + "Error header=0x%08x\n", header);
26229 + dev->net->stats.rx_errors++;
26230 + dev->net->stats.rx_dropped++;
26232 + if (header & RX_STS_CRC_) {
26233 + dev->net->stats.rx_crc_errors++;
26235 + if (header & (RX_STS_TL_ | RX_STS_RF_))
26236 + dev->net->stats.rx_frame_errors++;
26238 + if ((header & RX_STS_LE_) &&
26239 + (!(header & RX_STS_FT_)))
26240 + dev->net->stats.rx_length_errors++;
26243 + /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
26244 + if (unlikely(size > (ETH_FRAME_LEN + 12))) {
26245 + netif_dbg(dev, rx_err, dev->net,
26246 + "size err header=0x%08x\n", header);
26250 + /* last frame in this batch */
26251 + if (skb->len == size) {
26252 + if (dev->net->features & NETIF_F_RXCSUM)
26253 + smsc95xx_rx_csum_offload(skb);
26254 + skb_trim(skb, skb->len - 4); /* remove fcs */
26255 + skb->truesize = size + sizeof(struct sk_buff);
26260 + ax_skb = skb_clone(skb, GFP_ATOMIC);
26261 + if (unlikely(!ax_skb)) {
26262 + netdev_warn(dev->net, "Error allocating skb\n");
26266 + ax_skb->len = size;
26267 + ax_skb->data = packet;
26268 + skb_set_tail_pointer(ax_skb, size);
26270 + if (dev->net->features & NETIF_F_RXCSUM)
26271 + smsc95xx_rx_csum_offload(ax_skb);
26272 + skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
26273 + ax_skb->truesize = size + sizeof(struct sk_buff);
26275 + usbnet_skb_return(dev, ax_skb);
26278 + skb_pull(skb, size);
26280 + /* padding bytes before the next frame starts */
26282 + skb_pull(skb, align_count);
26285 + if (unlikely(skb->len < 0)) {
26286 + netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
26293 +static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
26295 + u16 low_16 = (u16)skb_checksum_start_offset(skb);
26296 + u16 high_16 = low_16 + skb->csum_offset;
26297 + return (high_16 << 16) | low_16;
26300 +static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
26301 + struct sk_buff *skb, gfp_t flags)
26303 + bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
26304 + int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
26305 + u32 tx_cmd_a, tx_cmd_b;
26307 + /* We do not advertise SG, so skbs should be already linearized */
26308 + BUG_ON(skb_shinfo(skb)->nr_frags);
26310 + if (skb_headroom(skb) < overhead) {
26311 + struct sk_buff *skb2 = skb_copy_expand(skb,
26312 + overhead, 0, flags);
26313 + dev_kfree_skb_any(skb);
26320 + if (skb->len <= 45) {
26321 + /* workaround - hardware tx checksum does not work
26322 + * properly with extremely small packets */
26323 + long csstart = skb_checksum_start_offset(skb);
26324 + __wsum calc = csum_partial(skb->data + csstart,
26325 + skb->len - csstart, 0);
26326 + *((__sum16 *)(skb->data + csstart
26327 + + skb->csum_offset)) = csum_fold(calc);
26331 + u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
26332 + skb_push(skb, 4);
26333 + cpu_to_le32s(&csum_preamble);
26334 + memcpy(skb->data, &csum_preamble, 4);
26338 + skb_push(skb, 4);
26339 + tx_cmd_b = (u32)(skb->len - 4);
26341 + tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
26342 + cpu_to_le32s(&tx_cmd_b);
26343 + memcpy(skb->data, &tx_cmd_b, 4);
26345 + skb_push(skb, 4);
26346 + tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
26347 + TX_CMD_A_LAST_SEG_;
26348 + cpu_to_le32s(&tx_cmd_a);
26349 + memcpy(skb->data, &tx_cmd_a, 4);
26354 +static int smsc95xx_manage_power(struct usbnet *dev, int on)
26356 + struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
26358 + dev->intf->needs_remote_wakeup = on;
26360 + if (pdata->features & FEATURE_REMOTE_WAKEUP)
26363 + /* this chip revision isn't capable of remote wakeup */
26364 + netdev_info(dev->net, "hardware isn't capable of remote wakeup\n");
26367 + usb_autopm_get_interface_no_resume(dev->intf);
26369 + usb_autopm_put_interface(dev->intf);
26374 +static const struct driver_info smsc95xx_info = {
26375 + .description = "smsc95xx USB 2.0 Ethernet",
26376 + .bind = smsc95xx_bind,
26377 + .unbind = smsc95xx_unbind,
26378 + .link_reset = smsc95xx_link_reset,
26379 + .reset = smsc95xx_reset,
26380 + .rx_fixup = smsc95xx_rx_fixup,
26381 + .tx_fixup = smsc95xx_tx_fixup,
26382 + .status = smsc95xx_status,
26383 + .manage_power = smsc95xx_manage_power,
26384 + .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
26387 +static const struct usb_device_id products[] = {
26389 + /* SMSC9500 USB Ethernet Device */
26390 + USB_DEVICE(0x0424, 0x9500),
26391 + .driver_info = (unsigned long) &smsc95xx_info,
26394 + /* SMSC9505 USB Ethernet Device */
26395 + USB_DEVICE(0x0424, 0x9505),
26396 + .driver_info = (unsigned long) &smsc95xx_info,
26399 + /* SMSC9500A USB Ethernet Device */
26400 + USB_DEVICE(0x0424, 0x9E00),
26401 + .driver_info = (unsigned long) &smsc95xx_info,
26404 + /* SMSC9505A USB Ethernet Device */
26405 + USB_DEVICE(0x0424, 0x9E01),
26406 + .driver_info = (unsigned long) &smsc95xx_info,
26409 + /* SMSC9512/9514 USB Hub & Ethernet Device */
26410 + USB_DEVICE(0x0424, 0xec00),
26411 + .driver_info = (unsigned long) &smsc95xx_info,
26414 + /* SMSC9500 USB Ethernet Device (SAL10) */
26415 + USB_DEVICE(0x0424, 0x9900),
26416 + .driver_info = (unsigned long) &smsc95xx_info,
26419 + /* SMSC9505 USB Ethernet Device (SAL10) */
26420 + USB_DEVICE(0x0424, 0x9901),
26421 + .driver_info = (unsigned long) &smsc95xx_info,
26424 + /* SMSC9500A USB Ethernet Device (SAL10) */
26425 + USB_DEVICE(0x0424, 0x9902),
26426 + .driver_info = (unsigned long) &smsc95xx_info,
26429 + /* SMSC9505A USB Ethernet Device (SAL10) */
26430 + USB_DEVICE(0x0424, 0x9903),
26431 + .driver_info = (unsigned long) &smsc95xx_info,
26434 + /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
26435 + USB_DEVICE(0x0424, 0x9904),
26436 + .driver_info = (unsigned long) &smsc95xx_info,
26439 + /* SMSC9500A USB Ethernet Device (HAL) */
26440 + USB_DEVICE(0x0424, 0x9905),
26441 + .driver_info = (unsigned long) &smsc95xx_info,
26444 + /* SMSC9505A USB Ethernet Device (HAL) */
26445 + USB_DEVICE(0x0424, 0x9906),
26446 + .driver_info = (unsigned long) &smsc95xx_info,
26449 + /* SMSC9500 USB Ethernet Device (Alternate ID) */
26450 + USB_DEVICE(0x0424, 0x9907),
26451 + .driver_info = (unsigned long) &smsc95xx_info,
26454 + /* SMSC9500A USB Ethernet Device (Alternate ID) */
26455 + USB_DEVICE(0x0424, 0x9908),
26456 + .driver_info = (unsigned long) &smsc95xx_info,
26459 + /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
26460 + USB_DEVICE(0x0424, 0x9909),
26461 + .driver_info = (unsigned long) &smsc95xx_info,
26464 + /* SMSC LAN9530 USB Ethernet Device */
26465 + USB_DEVICE(0x0424, 0x9530),
26466 + .driver_info = (unsigned long) &smsc95xx_info,
26469 + /* SMSC LAN9730 USB Ethernet Device */
26470 + USB_DEVICE(0x0424, 0x9730),
26471 + .driver_info = (unsigned long) &smsc95xx_info,
26474 + /* SMSC LAN89530 USB Ethernet Device */
26475 + USB_DEVICE(0x0424, 0x9E08),
26476 + .driver_info = (unsigned long) &smsc95xx_info,
26480 +MODULE_DEVICE_TABLE(usb, products);
26482 +static struct usb_driver smsc95xx_driver = {
26483 + .name = "smsc95xx",
26484 + .id_table = products,
26485 + .probe = usbnet_probe,
26486 + .suspend = smsc95xx_suspend,
26487 + .resume = smsc95xx_resume,
26488 + .reset_resume = smsc95xx_reset_resume,
26489 + .disconnect = usbnet_disconnect,
26490 + .disable_hub_initiated_lpm = 1,
26491 + .supports_autosuspend = 1,
26494 +module_usb_driver(smsc95xx_driver);
26496 +MODULE_AUTHOR("Nancy Lin");
26497 +MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
26498 +MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
26499 +MODULE_LICENSE("GPL");
26500 diff -Naur backports-4.2.6-1.org/drivers/net/usb/smsc95xx.h backports-4.2.6-1/drivers/net/usb/smsc95xx.h
26501 --- backports-4.2.6-1.org/drivers/net/usb/smsc95xx.h 1970-01-01 01:00:00.000000000 +0100
26502 +++ backports-4.2.6-1/drivers/net/usb/smsc95xx.h 2016-06-28 14:35:18.011973884 +0200
26504 + /***************************************************************************
26506 + * Copyright (C) 2007-2008 SMSC
26508 + * This program is free software; you can redistribute it and/or
26509 + * modify it under the terms of the GNU General Public License
26510 + * as published by the Free Software Foundation; either version 2
26511 + * of the License, or (at your option) any later version.
26513 + * This program is distributed in the hope that it will be useful,
26514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26516 + * GNU General Public License for more details.
26518 + * You should have received a copy of the GNU General Public License
26519 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
26521 + *****************************************************************************/
26523 +#ifndef _SMSC95XX_H
26524 +#define _SMSC95XX_H
26526 +/* Tx command words */
26527 +#define TX_CMD_A_DATA_OFFSET_ (0x001F0000)
26528 +#define TX_CMD_A_FIRST_SEG_ (0x00002000)
26529 +#define TX_CMD_A_LAST_SEG_ (0x00001000)
26530 +#define TX_CMD_A_BUF_SIZE_ (0x000007FF)
26532 +#define TX_CMD_B_CSUM_ENABLE (0x00004000)
26533 +#define TX_CMD_B_ADD_CRC_DISABLE_ (0x00002000)
26534 +#define TX_CMD_B_DISABLE_PADDING_ (0x00001000)
26535 +#define TX_CMD_B_PKT_BYTE_LENGTH_ (0x000007FF)
26537 +/* Rx status word */
26538 +#define RX_STS_FF_ (0x40000000) /* Filter Fail */
26539 +#define RX_STS_FL_ (0x3FFF0000) /* Frame Length */
26540 +#define RX_STS_ES_ (0x00008000) /* Error Summary */
26541 +#define RX_STS_BF_ (0x00002000) /* Broadcast Frame */
26542 +#define RX_STS_LE_ (0x00001000) /* Length Error */
26543 +#define RX_STS_RF_ (0x00000800) /* Runt Frame */
26544 +#define RX_STS_MF_ (0x00000400) /* Multicast Frame */
26545 +#define RX_STS_TL_ (0x00000080) /* Frame too long */
26546 +#define RX_STS_CS_ (0x00000040) /* Collision Seen */
26547 +#define RX_STS_FT_ (0x00000020) /* Frame Type */
26548 +#define RX_STS_RW_ (0x00000010) /* Receive Watchdog */
26549 +#define RX_STS_ME_ (0x00000008) /* Mii Error */
26550 +#define RX_STS_DB_ (0x00000004) /* Dribbling */
26551 +#define RX_STS_CRC_ (0x00000002) /* CRC Error */
26554 +#define ID_REV (0x00)
26555 +#define ID_REV_CHIP_ID_MASK_ (0xFFFF0000)
26556 +#define ID_REV_CHIP_REV_MASK_ (0x0000FFFF)
26557 +#define ID_REV_CHIP_ID_9500_ (0x9500)
26558 +#define ID_REV_CHIP_ID_9500A_ (0x9E00)
26559 +#define ID_REV_CHIP_ID_9512_ (0xEC00)
26560 +#define ID_REV_CHIP_ID_9530_ (0x9530)
26561 +#define ID_REV_CHIP_ID_89530_ (0x9E08)
26562 +#define ID_REV_CHIP_ID_9730_ (0x9730)
26564 +#define INT_STS (0x08)
26565 +#define INT_STS_TX_STOP_ (0x00020000)
26566 +#define INT_STS_RX_STOP_ (0x00010000)
26567 +#define INT_STS_PHY_INT_ (0x00008000)
26568 +#define INT_STS_TXE_ (0x00004000)
26569 +#define INT_STS_TDFU_ (0x00002000)
26570 +#define INT_STS_TDFO_ (0x00001000)
26571 +#define INT_STS_RXDF_ (0x00000800)
26572 +#define INT_STS_GPIOS_ (0x000007FF)
26573 +#define INT_STS_CLEAR_ALL_ (0xFFFFFFFF)
26575 +#define RX_CFG (0x0C)
26576 +#define RX_FIFO_FLUSH_ (0x00000001)
26578 +#define TX_CFG (0x10)
26579 +#define TX_CFG_ON_ (0x00000004)
26580 +#define TX_CFG_STOP_ (0x00000002)
26581 +#define TX_CFG_FIFO_FLUSH_ (0x00000001)
26583 +#define HW_CFG (0x14)
26584 +#define HW_CFG_BIR_ (0x00001000)
26585 +#define HW_CFG_LEDB_ (0x00000800)
26586 +#define HW_CFG_RXDOFF_ (0x00000600)
26587 +#define HW_CFG_DRP_ (0x00000040)
26588 +#define HW_CFG_MEF_ (0x00000020)
26589 +#define HW_CFG_LRST_ (0x00000008)
26590 +#define HW_CFG_PSEL_ (0x00000004)
26591 +#define HW_CFG_BCE_ (0x00000002)
26592 +#define HW_CFG_SRST_ (0x00000001)
26594 +#define RX_FIFO_INF (0x18)
26596 +#define PM_CTRL (0x20)
26597 +#define PM_CTL_RES_CLR_WKP_STS (0x00000200)
26598 +#define PM_CTL_DEV_RDY_ (0x00000080)
26599 +#define PM_CTL_SUS_MODE_ (0x00000060)
26600 +#define PM_CTL_SUS_MODE_0 (0x00000000)
26601 +#define PM_CTL_SUS_MODE_1 (0x00000020)
26602 +#define PM_CTL_SUS_MODE_2 (0x00000040)
26603 +#define PM_CTL_SUS_MODE_3 (0x00000060)
26604 +#define PM_CTL_PHY_RST_ (0x00000010)
26605 +#define PM_CTL_WOL_EN_ (0x00000008)
26606 +#define PM_CTL_ED_EN_ (0x00000004)
26607 +#define PM_CTL_WUPS_ (0x00000003)
26608 +#define PM_CTL_WUPS_NO_ (0x00000000)
26609 +#define PM_CTL_WUPS_ED_ (0x00000001)
26610 +#define PM_CTL_WUPS_WOL_ (0x00000002)
26611 +#define PM_CTL_WUPS_MULTI_ (0x00000003)
26613 +#define LED_GPIO_CFG (0x24)
26614 +#define LED_GPIO_CFG_SPD_LED (0x01000000)
26615 +#define LED_GPIO_CFG_LNK_LED (0x00100000)
26616 +#define LED_GPIO_CFG_FDX_LED (0x00010000)
26618 +#define GPIO_CFG (0x28)
26620 +#define AFC_CFG (0x2C)
26622 +/* Hi watermark = 15.5Kb (~10 mtu pkts) */
26623 +/* low watermark = 3k (~2 mtu pkts) */
26624 +/* backpressure duration = ~ 350us */
26625 +/* Apply FC on any frame. */
26626 +#define AFC_CFG_DEFAULT (0x00F830A1)
26628 +#define E2P_CMD (0x30)
26629 +#define E2P_CMD_BUSY_ (0x80000000)
26630 +#define E2P_CMD_MASK_ (0x70000000)
26631 +#define E2P_CMD_READ_ (0x00000000)
26632 +#define E2P_CMD_EWDS_ (0x10000000)
26633 +#define E2P_CMD_EWEN_ (0x20000000)
26634 +#define E2P_CMD_WRITE_ (0x30000000)
26635 +#define E2P_CMD_WRAL_ (0x40000000)
26636 +#define E2P_CMD_ERASE_ (0x50000000)
26637 +#define E2P_CMD_ERAL_ (0x60000000)
26638 +#define E2P_CMD_RELOAD_ (0x70000000)
26639 +#define E2P_CMD_TIMEOUT_ (0x00000400)
26640 +#define E2P_CMD_LOADED_ (0x00000200)
26641 +#define E2P_CMD_ADDR_ (0x000001FF)
26643 +#define MAX_EEPROM_SIZE (512)
26645 +#define E2P_DATA (0x34)
26646 +#define E2P_DATA_MASK_ (0x000000FF)
26648 +#define BURST_CAP (0x38)
26650 +#define GPIO_WAKE (0x64)
26652 +#define INT_EP_CTL (0x68)
26653 +#define INT_EP_CTL_INTEP_ (0x80000000)
26654 +#define INT_EP_CTL_MACRTO_ (0x00080000)
26655 +#define INT_EP_CTL_TX_STOP_ (0x00020000)
26656 +#define INT_EP_CTL_RX_STOP_ (0x00010000)
26657 +#define INT_EP_CTL_PHY_INT_ (0x00008000)
26658 +#define INT_EP_CTL_TXE_ (0x00004000)
26659 +#define INT_EP_CTL_TDFU_ (0x00002000)
26660 +#define INT_EP_CTL_TDFO_ (0x00001000)
26661 +#define INT_EP_CTL_RXDF_ (0x00000800)
26662 +#define INT_EP_CTL_GPIOS_ (0x000007FF)
26664 +#define BULK_IN_DLY (0x6C)
26667 +#define MAC_CR (0x100)
26668 +#define MAC_CR_RXALL_ (0x80000000)
26669 +#define MAC_CR_RCVOWN_ (0x00800000)
26670 +#define MAC_CR_LOOPBK_ (0x00200000)
26671 +#define MAC_CR_FDPX_ (0x00100000)
26672 +#define MAC_CR_MCPAS_ (0x00080000)
26673 +#define MAC_CR_PRMS_ (0x00040000)
26674 +#define MAC_CR_INVFILT_ (0x00020000)
26675 +#define MAC_CR_PASSBAD_ (0x00010000)
26676 +#define MAC_CR_HFILT_ (0x00008000)
26677 +#define MAC_CR_HPFILT_ (0x00002000)
26678 +#define MAC_CR_LCOLL_ (0x00001000)
26679 +#define MAC_CR_BCAST_ (0x00000800)
26680 +#define MAC_CR_DISRTY_ (0x00000400)
26681 +#define MAC_CR_PADSTR_ (0x00000100)
26682 +#define MAC_CR_BOLMT_MASK (0x000000C0)
26683 +#define MAC_CR_DFCHK_ (0x00000020)
26684 +#define MAC_CR_TXEN_ (0x00000008)
26685 +#define MAC_CR_RXEN_ (0x00000004)
26687 +#define ADDRH (0x104)
26689 +#define ADDRL (0x108)
26691 +#define HASHH (0x10C)
26693 +#define HASHL (0x110)
26695 +#define MII_ADDR (0x114)
26696 +#define MII_WRITE_ (0x02)
26697 +#define MII_BUSY_ (0x01)
26698 +#define MII_READ_ (0x00) /* ~of MII Write bit */
26700 +#define MII_DATA (0x118)
26702 +#define FLOW (0x11C)
26703 +#define FLOW_FCPT_ (0xFFFF0000)
26704 +#define FLOW_FCPASS_ (0x00000004)
26705 +#define FLOW_FCEN_ (0x00000002)
26706 +#define FLOW_FCBSY_ (0x00000001)
26708 +#define VLAN1 (0x120)
26710 +#define VLAN2 (0x124)
26712 +#define WUFF (0x128)
26713 +#define LAN9500_WUFF_NUM (4)
26714 +#define LAN9500A_WUFF_NUM (8)
26716 +#define WUCSR (0x12C)
26717 +#define WUCSR_WFF_PTR_RST_ (0x80000000)
26718 +#define WUCSR_GUE_ (0x00000200)
26719 +#define WUCSR_WUFR_ (0x00000040)
26720 +#define WUCSR_MPR_ (0x00000020)
26721 +#define WUCSR_WAKE_EN_ (0x00000004)
26722 +#define WUCSR_MPEN_ (0x00000002)
26724 +#define COE_CR (0x130)
26725 +#define Tx_COE_EN_ (0x00010000)
26726 +#define Rx_COE_MODE_ (0x00000002)
26727 +#define Rx_COE_EN_ (0x00000001)
26729 +/* Vendor-specific PHY Definitions */
26731 +/* EDPD NLP / crossover time configuration (LAN9500A only) */
26732 +#define PHY_EDPD_CONFIG (16)
26733 +#define PHY_EDPD_CONFIG_TX_NLP_EN_ ((u16)0x8000)
26734 +#define PHY_EDPD_CONFIG_TX_NLP_1000_ ((u16)0x0000)
26735 +#define PHY_EDPD_CONFIG_TX_NLP_768_ ((u16)0x2000)
26736 +#define PHY_EDPD_CONFIG_TX_NLP_512_ ((u16)0x4000)
26737 +#define PHY_EDPD_CONFIG_TX_NLP_256_ ((u16)0x6000)
26738 +#define PHY_EDPD_CONFIG_RX_1_NLP_ ((u16)0x1000)
26739 +#define PHY_EDPD_CONFIG_RX_NLP_64_ ((u16)0x0000)
26740 +#define PHY_EDPD_CONFIG_RX_NLP_256_ ((u16)0x0400)
26741 +#define PHY_EDPD_CONFIG_RX_NLP_512_ ((u16)0x0800)
26742 +#define PHY_EDPD_CONFIG_RX_NLP_1000_ ((u16)0x0C00)
26743 +#define PHY_EDPD_CONFIG_EXT_CROSSOVER_ ((u16)0x0001)
26744 +#define PHY_EDPD_CONFIG_DEFAULT (PHY_EDPD_CONFIG_TX_NLP_EN_ | \
26745 + PHY_EDPD_CONFIG_TX_NLP_768_ | \
26746 + PHY_EDPD_CONFIG_RX_1_NLP_)
26748 +/* Mode Control/Status Register */
26749 +#define PHY_MODE_CTRL_STS (17)
26750 +#define MODE_CTRL_STS_EDPWRDOWN_ ((u16)0x2000)
26751 +#define MODE_CTRL_STS_ENERGYON_ ((u16)0x0002)
26753 +#define SPECIAL_CTRL_STS (27)
26754 +#define SPECIAL_CTRL_STS_OVRRD_AMDIX_ ((u16)0x8000)
26755 +#define SPECIAL_CTRL_STS_AMDIX_ENABLE_ ((u16)0x4000)
26756 +#define SPECIAL_CTRL_STS_AMDIX_STATE_ ((u16)0x2000)
26758 +#define PHY_INT_SRC (29)
26759 +#define PHY_INT_SRC_ENERGY_ON_ ((u16)0x0080)
26760 +#define PHY_INT_SRC_ANEG_COMP_ ((u16)0x0040)
26761 +#define PHY_INT_SRC_REMOTE_FAULT_ ((u16)0x0020)
26762 +#define PHY_INT_SRC_LINK_DOWN_ ((u16)0x0010)
26764 +#define PHY_INT_MASK (30)
26765 +#define PHY_INT_MASK_ENERGY_ON_ ((u16)0x0080)
26766 +#define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
26767 +#define PHY_INT_MASK_REMOTE_FAULT_ ((u16)0x0020)
26768 +#define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
26769 +#define PHY_INT_MASK_DEFAULT_ (PHY_INT_MASK_ANEG_COMP_ | \
26770 + PHY_INT_MASK_LINK_DOWN_)
26772 +#define PHY_SPECIAL (31)
26773 +#define PHY_SPECIAL_SPD_ ((u16)0x001C)
26774 +#define PHY_SPECIAL_SPD_10HALF_ ((u16)0x0004)
26775 +#define PHY_SPECIAL_SPD_10FULL_ ((u16)0x0014)
26776 +#define PHY_SPECIAL_SPD_100HALF_ ((u16)0x0008)
26777 +#define PHY_SPECIAL_SPD_100FULL_ ((u16)0x0018)
26779 +/* USB Vendor Requests */
26780 +#define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
26781 +#define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
26782 +#define USB_VENDOR_REQUEST_GET_STATS 0xA2
26784 +/* Interrupt Endpoint status word bitfields */
26785 +#define INT_ENP_TX_STOP_ ((u32)BIT(17))
26786 +#define INT_ENP_RX_STOP_ ((u32)BIT(16))
26787 +#define INT_ENP_PHY_INT_ ((u32)BIT(15))
26788 +#define INT_ENP_TXE_ ((u32)BIT(14))
26789 +#define INT_ENP_TDFU_ ((u32)BIT(13))
26790 +#define INT_ENP_TDFO_ ((u32)BIT(12))
26791 +#define INT_ENP_RXDF_ ((u32)BIT(11))
26793 +#endif /* _SMSC95XX_H */
26794 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9700.c backports-4.2.6-1/drivers/net/usb/sr9700.c
26795 --- backports-4.2.6-1.org/drivers/net/usb/sr9700.c 1970-01-01 01:00:00.000000000 +0100
26796 +++ backports-4.2.6-1/drivers/net/usb/sr9700.c 2016-06-28 14:35:18.011973884 +0200
26799 + * CoreChip-sz SR9700 one chip USB 1.1 Ethernet Devices
26801 + * Author : Liu Junliang <liujunliang_ljl@163.com>
26803 + * Based on dm9601.c
26805 + * This file is licensed under the terms of the GNU General Public License
26806 + * version 2. This program is licensed "as is" without any warranty of any
26807 + * kind, whether express or implied.
26810 +#include <linux/module.h>
26811 +#include <linux/sched.h>
26812 +#include <linux/stddef.h>
26813 +#include <linux/netdevice.h>
26814 +#include <linux/etherdevice.h>
26815 +#include <linux/ethtool.h>
26816 +#include <linux/mii.h>
26817 +#include <linux/usb.h>
26818 +#include <linux/crc32.h>
26819 +#include <linux/usb/usbnet.h>
26821 +#include "sr9700.h"
26823 +static int sr_read(struct usbnet *dev, u8 reg, u16 length, void *data)
26827 + err = usbnet_read_cmd(dev, SR_RD_REGS, SR_REQ_RD_REG, 0, reg, data,
26829 + if ((err != length) && (err >= 0))
26834 +static int sr_write(struct usbnet *dev, u8 reg, u16 length, void *data)
26838 + err = usbnet_write_cmd(dev, SR_WR_REGS, SR_REQ_WR_REG, 0, reg, data,
26840 + if ((err >= 0) && (err < length))
26845 +static int sr_read_reg(struct usbnet *dev, u8 reg, u8 *value)
26847 + return sr_read(dev, reg, 1, value);
26850 +static int sr_write_reg(struct usbnet *dev, u8 reg, u8 value)
26852 + return usbnet_write_cmd(dev, SR_WR_REGS, SR_REQ_WR_REG,
26853 + value, reg, NULL, 0);
26856 +static void sr_write_async(struct usbnet *dev, u8 reg, u16 length, void *data)
26858 + usbnet_write_cmd_async(dev, SR_WR_REGS, SR_REQ_WR_REG,
26859 + 0, reg, data, length);
26862 +static void sr_write_reg_async(struct usbnet *dev, u8 reg, u8 value)
26864 + usbnet_write_cmd_async(dev, SR_WR_REGS, SR_REQ_WR_REG,
26865 + value, reg, NULL, 0);
26868 +static int wait_phy_eeprom_ready(struct usbnet *dev, int phy)
26872 + for (i = 0; i < SR_SHARE_TIMEOUT; i++) {
26877 + ret = sr_read_reg(dev, SR_EPCR, &tmp);
26882 + if (!(tmp & EPCR_ERRE))
26886 + netdev_err(dev->net, "%s write timed out!\n", phy ? "phy" : "eeprom");
26891 +static int sr_share_read_word(struct usbnet *dev, int phy, u8 reg,
26896 + mutex_lock(&dev->phy_mutex);
26898 + sr_write_reg(dev, SR_EPAR, phy ? (reg | EPAR_PHY_ADR) : reg);
26899 + sr_write_reg(dev, SR_EPCR, phy ? (EPCR_EPOS | EPCR_ERPRR) : EPCR_ERPRR);
26901 + ret = wait_phy_eeprom_ready(dev, phy);
26905 + sr_write_reg(dev, SR_EPCR, 0x0);
26906 + ret = sr_read(dev, SR_EPDR, 2, value);
26908 + netdev_dbg(dev->net, "read shared %d 0x%02x returned 0x%04x, %d\n",
26909 + phy, reg, *value, ret);
26912 + mutex_unlock(&dev->phy_mutex);
26916 +static int sr_share_write_word(struct usbnet *dev, int phy, u8 reg,
26921 + mutex_lock(&dev->phy_mutex);
26923 + ret = sr_write(dev, SR_EPDR, 2, &value);
26927 + sr_write_reg(dev, SR_EPAR, phy ? (reg | EPAR_PHY_ADR) : reg);
26928 + sr_write_reg(dev, SR_EPCR, phy ? (EPCR_WEP | EPCR_EPOS | EPCR_ERPRW) :
26929 + (EPCR_WEP | EPCR_ERPRW));
26931 + ret = wait_phy_eeprom_ready(dev, phy);
26935 + sr_write_reg(dev, SR_EPCR, 0x0);
26938 + mutex_unlock(&dev->phy_mutex);
26942 +static int sr_read_eeprom_word(struct usbnet *dev, u8 offset, void *value)
26944 + return sr_share_read_word(dev, 0, offset, value);
26947 +static int sr9700_get_eeprom_len(struct net_device *netdev)
26949 + return SR_EEPROM_LEN;
26952 +static int sr9700_get_eeprom(struct net_device *netdev,
26953 + struct ethtool_eeprom *eeprom, u8 *data)
26955 + struct usbnet *dev = netdev_priv(netdev);
26956 + __le16 *buf = (__le16 *)data;
26960 + /* access is 16bit */
26961 + if ((eeprom->offset & 0x01) || (eeprom->len & 0x01))
26964 + for (i = 0; i < eeprom->len / 2; i++) {
26965 + ret = sr_read_eeprom_word(dev, eeprom->offset / 2 + i, buf + i);
26973 +static int sr_mdio_read(struct net_device *netdev, int phy_id, int loc)
26975 + struct usbnet *dev = netdev_priv(netdev);
26980 + netdev_dbg(netdev, "Only internal phy supported\n");
26984 + /* Access NSR_LINKST bit for link status instead of MII_BMSR */
26985 + if (loc == MII_BMSR) {
26988 + sr_read_reg(dev, SR_NSR, &value);
26989 + if (value & NSR_LINKST)
26992 + sr_share_read_word(dev, 1, loc, &res);
26994 + res = le16_to_cpu(res) | BMSR_LSTATUS;
26996 + res = le16_to_cpu(res) & ~BMSR_LSTATUS;
26998 + netdev_dbg(netdev, "sr_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
26999 + phy_id, loc, res);
27004 +static void sr_mdio_write(struct net_device *netdev, int phy_id, int loc,
27007 + struct usbnet *dev = netdev_priv(netdev);
27008 + __le16 res = cpu_to_le16(val);
27011 + netdev_dbg(netdev, "Only internal phy supported\n");
27015 + netdev_dbg(netdev, "sr_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
27016 + phy_id, loc, val);
27018 + sr_share_write_word(dev, 1, loc, res);
27021 +static u32 sr9700_get_link(struct net_device *netdev)
27023 + struct usbnet *dev = netdev_priv(netdev);
27027 + /* Get the Link Status directly */
27028 + sr_read_reg(dev, SR_NSR, &value);
27029 + if (value & NSR_LINKST)
27035 +static int sr9700_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
27037 + struct usbnet *dev = netdev_priv(netdev);
27039 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
27042 +static const struct ethtool_ops sr9700_ethtool_ops = {
27043 + .get_drvinfo = usbnet_get_drvinfo,
27044 + .get_link = sr9700_get_link,
27045 + .get_msglevel = usbnet_get_msglevel,
27046 + .set_msglevel = usbnet_set_msglevel,
27047 + .get_eeprom_len = sr9700_get_eeprom_len,
27048 + .get_eeprom = sr9700_get_eeprom,
27049 + .get_settings = usbnet_get_settings,
27050 + .set_settings = usbnet_set_settings,
27051 + .nway_reset = usbnet_nway_reset,
27054 +static void sr9700_set_multicast(struct net_device *netdev)
27056 + struct usbnet *dev = netdev_priv(netdev);
27057 + /* We use the 20 byte dev->data for our 8 byte filter buffer
27058 + * to avoid allocating memory that is tricky to free later
27060 + u8 *hashes = (u8 *)&dev->data;
27061 + /* rx_ctl setting : enable, disable_long, disable_crc */
27062 + u8 rx_ctl = RCR_RXEN | RCR_DIS_CRC | RCR_DIS_LONG;
27064 + memset(hashes, 0x00, SR_MCAST_SIZE);
27065 + /* broadcast address */
27066 + hashes[SR_MCAST_SIZE - 1] |= SR_MCAST_ADDR_FLAG;
27067 + if (netdev->flags & IFF_PROMISC) {
27068 + rx_ctl |= RCR_PRMSC;
27069 + } else if (netdev->flags & IFF_ALLMULTI ||
27070 + netdev_mc_count(netdev) > SR_MCAST_MAX) {
27071 + rx_ctl |= RCR_RUNT;
27072 + } else if (!netdev_mc_empty(netdev)) {
27073 + struct netdev_hw_addr *ha;
27075 + netdev_for_each_mc_addr(ha, netdev) {
27076 + u32 crc = ether_crc(ETH_ALEN, ha->addr) >> 26;
27077 + hashes[crc >> 3] |= 1 << (crc & 0x7);
27081 + sr_write_async(dev, SR_MAR, SR_MCAST_SIZE, hashes);
27082 + sr_write_reg_async(dev, SR_RCR, rx_ctl);
27085 +static int sr9700_set_mac_address(struct net_device *netdev, void *p)
27087 + struct usbnet *dev = netdev_priv(netdev);
27088 + struct sockaddr *addr = p;
27090 + if (!is_valid_ether_addr(addr->sa_data)) {
27091 + netdev_err(netdev, "not setting invalid mac address %pM\n",
27096 + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
27097 + sr_write_async(dev, SR_PAR, 6, netdev->dev_addr);
27102 +static const struct net_device_ops sr9700_netdev_ops = {
27103 + .ndo_open = usbnet_open,
27104 + .ndo_stop = usbnet_stop,
27105 + .ndo_start_xmit = usbnet_start_xmit,
27106 + .ndo_tx_timeout = usbnet_tx_timeout,
27107 + .ndo_change_mtu = usbnet_change_mtu,
27108 + .ndo_validate_addr = eth_validate_addr,
27109 + .ndo_do_ioctl = sr9700_ioctl,
27110 + .ndo_set_rx_mode = sr9700_set_multicast,
27111 + .ndo_set_mac_address = sr9700_set_mac_address,
27114 +static int sr9700_bind(struct usbnet *dev, struct usb_interface *intf)
27116 + struct net_device *netdev;
27117 + struct mii_if_info *mii;
27120 + ret = usbnet_get_endpoints(dev, intf);
27124 + netdev = dev->net;
27126 + netdev->netdev_ops = &sr9700_netdev_ops;
27127 + netdev->ethtool_ops = &sr9700_ethtool_ops;
27128 + netdev->hard_header_len += SR_TX_OVERHEAD;
27129 + dev->hard_mtu = netdev->mtu + netdev->hard_header_len;
27130 + /* bulkin buffer is preferably not less than 3K */
27131 + dev->rx_urb_size = 3072;
27134 + mii->dev = netdev;
27135 + mii->mdio_read = sr_mdio_read;
27136 + mii->mdio_write = sr_mdio_write;
27137 + mii->phy_id_mask = 0x1f;
27138 + mii->reg_num_mask = 0x1f;
27140 + sr_write_reg(dev, SR_NCR, NCR_RST);
27144 + * After Chip Power on, the Chip will reload the MAC from
27145 + * EEPROM automatically to PAR. In case there is no EEPROM externally,
27146 + * a default MAC address is stored in PAR for making chip work properly.
27148 + if (sr_read(dev, SR_PAR, ETH_ALEN, netdev->dev_addr) < 0) {
27149 + netdev_err(netdev, "Error reading MAC address\n");
27154 + /* power up and reset phy */
27155 + sr_write_reg(dev, SR_PRR, PRR_PHY_RST);
27156 + /* at least 10ms, here 20ms for safe */
27158 + sr_write_reg(dev, SR_PRR, 0);
27159 + /* at least 1ms, here 2ms for reading right register */
27160 + udelay(2 * 1000);
27162 + /* receive broadcast packets */
27163 + sr9700_set_multicast(netdev);
27165 + sr_mdio_write(netdev, mii->phy_id, MII_BMCR, BMCR_RESET);
27166 + sr_mdio_write(netdev, mii->phy_id, MII_ADVERTISE, ADVERTISE_ALL |
27167 + ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
27168 + mii_nway_restart(mii);
27174 +static int sr9700_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
27176 + struct sk_buff *sr_skb;
27179 + /* skb content (packets) format :
27180 + * p0 p1 p2 ...... pm
27185 + * p0b0 p0b1 p0b2 p0b3 ...... p0b(n-4) p0b(n-3)...p0bn
27188 + * p0b0 : packet 0 byte 0
27191 + * b1: packet length (incl crc) low
27192 + * b2: packet length (incl crc) high
27193 + * b3..n-4: packet data
27194 + * bn-3..bn: ethernet packet crc
27196 + if (unlikely(skb->len < SR_RX_OVERHEAD)) {
27197 + netdev_err(dev->net, "unexpected tiny rx frame\n");
27201 + /* one skb may contains multiple packets */
27202 + while (skb->len > SR_RX_OVERHEAD) {
27203 + if (skb->data[0] != 0x40)
27206 + /* ignore the CRC length */
27207 + len = (skb->data[1] | (skb->data[2] << 8)) - 4;
27209 + if (len > ETH_FRAME_LEN)
27212 + /* the last packet of current skb */
27213 + if (skb->len == (len + SR_RX_OVERHEAD)) {
27214 + skb_pull(skb, 3);
27216 + skb_set_tail_pointer(skb, len);
27217 + skb->truesize = len + sizeof(struct sk_buff);
27221 + /* skb_clone is used for address align */
27222 + sr_skb = skb_clone(skb, GFP_ATOMIC);
27226 + sr_skb->len = len;
27227 + sr_skb->data = skb->data + 3;
27228 + skb_set_tail_pointer(sr_skb, len);
27229 + sr_skb->truesize = len + sizeof(struct sk_buff);
27230 + usbnet_skb_return(dev, sr_skb);
27232 + skb_pull(skb, len + SR_RX_OVERHEAD);
27238 +static struct sk_buff *sr9700_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
27243 + /* SR9700 can only send out one ethernet packet at once.
27245 + * b0 b1 b2 b3 ...... b(n-4) b(n-3)...bn
27248 + * b1: packet length (incl crc) low
27249 + * b2: packet length (incl crc) high
27250 + * b3..n-4: packet data
27251 + * bn-3..bn: ethernet packet crc
27256 + if (skb_headroom(skb) < SR_TX_OVERHEAD) {
27257 + struct sk_buff *skb2;
27259 + skb2 = skb_copy_expand(skb, SR_TX_OVERHEAD, 0, flags);
27260 + dev_kfree_skb_any(skb);
27266 + __skb_push(skb, SR_TX_OVERHEAD);
27268 + /* usbnet adds padding if length is a multiple of packet size
27269 + * if so, adjust length value in header
27271 + if ((skb->len % dev->maxpacket) == 0)
27274 + skb->data[0] = len;
27275 + skb->data[1] = len >> 8;
27280 +static void sr9700_status(struct usbnet *dev, struct urb *urb)
27296 + if (urb->actual_length < 8)
27299 + buf = urb->transfer_buffer;
27301 + link = !!(buf[0] & 0x40);
27302 + if (netif_carrier_ok(dev->net) != link) {
27303 + usbnet_link_change(dev, link, 1);
27304 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
27308 +static int sr9700_link_reset(struct usbnet *dev)
27310 + struct ethtool_cmd ecmd;
27312 + mii_check_media(&dev->mii, 1, 1);
27313 + mii_ethtool_gset(&dev->mii, &ecmd);
27315 + netdev_dbg(dev->net, "link_reset() speed: %d duplex: %d\n",
27316 + ecmd.speed, ecmd.duplex);
27321 +static const struct driver_info sr9700_driver_info = {
27322 + .description = "CoreChip SR9700 USB Ethernet",
27323 + .flags = FLAG_ETHER,
27324 + .bind = sr9700_bind,
27325 + .rx_fixup = sr9700_rx_fixup,
27326 + .tx_fixup = sr9700_tx_fixup,
27327 + .status = sr9700_status,
27328 + .link_reset = sr9700_link_reset,
27329 + .reset = sr9700_link_reset,
27332 +static const struct usb_device_id products[] = {
27334 + USB_DEVICE(0x0fe6, 0x9700), /* SR9700 device */
27335 + .driver_info = (unsigned long)&sr9700_driver_info,
27340 +MODULE_DEVICE_TABLE(usb, products);
27342 +static struct usb_driver sr9700_usb_driver = {
27343 + .name = "sr9700",
27344 + .id_table = products,
27345 + .probe = usbnet_probe,
27346 + .disconnect = usbnet_disconnect,
27347 + .suspend = usbnet_suspend,
27348 + .resume = usbnet_resume,
27349 + .disable_hub_initiated_lpm = 1,
27352 +module_usb_driver(sr9700_usb_driver);
27354 +MODULE_AUTHOR("liujl <liujunliang_ljl@163.com>");
27355 +MODULE_DESCRIPTION("SR9700 one chip USB 1.1 USB to Ethernet device from http://www.corechip-sz.com/");
27356 +MODULE_LICENSE("GPL");
27357 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9700.h backports-4.2.6-1/drivers/net/usb/sr9700.h
27358 --- backports-4.2.6-1.org/drivers/net/usb/sr9700.h 1970-01-01 01:00:00.000000000 +0100
27359 +++ backports-4.2.6-1/drivers/net/usb/sr9700.h 2016-06-28 14:35:18.011973884 +0200
27362 + * CoreChip-sz SR9700 one chip USB 1.1 Ethernet Devices
27364 + * Author : Liu Junliang <liujunliang_ljl@163.com>
27366 + * This program is free software; you can redistribute it and/or
27367 + * modify it under the terms of the GNU General Public License
27368 + * version 2 as published by the Free Software Foundation.
27374 +/* sr9700 spec. register table on Linux platform */
27376 +/* Network Control Reg */
27377 +#define SR_NCR 0x00
27378 +#define NCR_RST (1 << 0)
27379 +#define NCR_LBK (3 << 1)
27380 +#define NCR_FDX (1 << 3)
27381 +#define NCR_WAKEEN (1 << 6)
27382 +/* Network Status Reg */
27383 +#define SR_NSR 0x01
27384 +#define NSR_RXRDY (1 << 0)
27385 +#define NSR_RXOV (1 << 1)
27386 +#define NSR_TX1END (1 << 2)
27387 +#define NSR_TX2END (1 << 3)
27388 +#define NSR_TXFULL (1 << 4)
27389 +#define NSR_WAKEST (1 << 5)
27390 +#define NSR_LINKST (1 << 6)
27391 +#define NSR_SPEED (1 << 7)
27392 +/* Tx Control Reg */
27393 +#define SR_TCR 0x02
27394 +#define TCR_CRC_DIS (1 << 1)
27395 +#define TCR_PAD_DIS (1 << 2)
27396 +#define TCR_LC_CARE (1 << 3)
27397 +#define TCR_CRS_CARE (1 << 4)
27398 +#define TCR_EXCECM (1 << 5)
27399 +#define TCR_LF_EN (1 << 6)
27400 +/* Tx Status Reg for Packet Index 1 */
27401 +#define SR_TSR1 0x03
27402 +#define TSR1_EC (1 << 2)
27403 +#define TSR1_COL (1 << 3)
27404 +#define TSR1_LC (1 << 4)
27405 +#define TSR1_NC (1 << 5)
27406 +#define TSR1_LOC (1 << 6)
27407 +#define TSR1_TLF (1 << 7)
27408 +/* Tx Status Reg for Packet Index 2 */
27409 +#define SR_TSR2 0x04
27410 +#define TSR2_EC (1 << 2)
27411 +#define TSR2_COL (1 << 3)
27412 +#define TSR2_LC (1 << 4)
27413 +#define TSR2_NC (1 << 5)
27414 +#define TSR2_LOC (1 << 6)
27415 +#define TSR2_TLF (1 << 7)
27416 +/* Rx Control Reg*/
27417 +#define SR_RCR 0x05
27418 +#define RCR_RXEN (1 << 0)
27419 +#define RCR_PRMSC (1 << 1)
27420 +#define RCR_RUNT (1 << 2)
27421 +#define RCR_ALL (1 << 3)
27422 +#define RCR_DIS_CRC (1 << 4)
27423 +#define RCR_DIS_LONG (1 << 5)
27424 +/* Rx Status Reg */
27425 +#define SR_RSR 0x06
27426 +#define RSR_AE (1 << 2)
27427 +#define RSR_MF (1 << 6)
27428 +#define RSR_RF (1 << 7)
27429 +/* Rx Overflow Counter Reg */
27430 +#define SR_ROCR 0x07
27431 +#define ROCR_ROC (0x7F << 0)
27432 +#define ROCR_RXFU (1 << 7)
27433 +/* Back Pressure Threshold Reg */
27434 +#define SR_BPTR 0x08
27435 +#define BPTR_JPT (0x0F << 0)
27436 +#define BPTR_BPHW (0x0F << 4)
27437 +/* Flow Control Threshold Reg */
27438 +#define SR_FCTR 0x09
27439 +#define FCTR_LWOT (0x0F << 0)
27440 +#define FCTR_HWOT (0x0F << 4)
27441 +/* rx/tx Flow Control Reg */
27442 +#define SR_FCR 0x0A
27443 +#define FCR_FLCE (1 << 0)
27444 +#define FCR_BKPA (1 << 4)
27445 +#define FCR_TXPEN (1 << 5)
27446 +#define FCR_TXPF (1 << 6)
27447 +#define FCR_TXP0 (1 << 7)
27448 +/* Eeprom & Phy Control Reg */
27449 +#define SR_EPCR 0x0B
27450 +#define EPCR_ERRE (1 << 0)
27451 +#define EPCR_ERPRW (1 << 1)
27452 +#define EPCR_ERPRR (1 << 2)
27453 +#define EPCR_EPOS (1 << 3)
27454 +#define EPCR_WEP (1 << 4)
27455 +/* Eeprom & Phy Address Reg */
27456 +#define SR_EPAR 0x0C
27457 +#define EPAR_EROA (0x3F << 0)
27458 +#define EPAR_PHY_ADR_MASK (0x03 << 6)
27459 +#define EPAR_PHY_ADR (0x01 << 6)
27460 +/* Eeprom & Phy Data Reg */
27461 +#define SR_EPDR 0x0D /* 0x0D ~ 0x0E for Data Reg Low & High */
27462 +/* Wakeup Control Reg */
27463 +#define SR_WCR 0x0F
27464 +#define WCR_MAGICST (1 << 0)
27465 +#define WCR_LINKST (1 << 2)
27466 +#define WCR_MAGICEN (1 << 3)
27467 +#define WCR_LINKEN (1 << 5)
27468 +/* Physical Address Reg */
27469 +#define SR_PAR 0x10 /* 0x10 ~ 0x15 6 bytes for PAR */
27470 +/* Multicast Address Reg */
27471 +#define SR_MAR 0x16 /* 0x16 ~ 0x1D 8 bytes for MAR */
27473 +/* Phy Reset Reg */
27474 +#define SR_PRR 0x1F
27475 +#define PRR_PHY_RST (1 << 0)
27476 +/* Tx sdram Write Pointer Address Low */
27477 +#define SR_TWPAL 0x20
27478 +/* Tx sdram Write Pointer Address High */
27479 +#define SR_TWPAH 0x21
27480 +/* Tx sdram Read Pointer Address Low */
27481 +#define SR_TRPAL 0x22
27482 +/* Tx sdram Read Pointer Address High */
27483 +#define SR_TRPAH 0x23
27484 +/* Rx sdram Write Pointer Address Low */
27485 +#define SR_RWPAL 0x24
27486 +/* Rx sdram Write Pointer Address High */
27487 +#define SR_RWPAH 0x25
27488 +/* Rx sdram Read Pointer Address Low */
27489 +#define SR_RRPAL 0x26
27490 +/* Rx sdram Read Pointer Address High */
27491 +#define SR_RRPAH 0x27
27492 +/* Vendor ID register */
27493 +#define SR_VID 0x28 /* 0x28 ~ 0x29 2 bytes for VID */
27494 +/* Product ID register */
27495 +#define SR_PID 0x2A /* 0x2A ~ 0x2B 2 bytes for PID */
27496 +/* CHIP Revision register */
27497 +#define SR_CHIPR 0x2C
27498 +/* 0x2D --> 0xEF unused */
27499 +/* USB Device Address */
27500 +#define SR_USBDA 0xF0
27501 +#define USBDA_USBFA (0x7F << 0)
27502 +/* RX packet Counter Reg */
27503 +#define SR_RXC 0xF1
27504 +/* Tx packet Counter & USB Status Reg */
27505 +#define SR_TXC_USBS 0xF2
27506 +#define TXC_USBS_TXC0 (1 << 0)
27507 +#define TXC_USBS_TXC1 (1 << 1)
27508 +#define TXC_USBS_TXC2 (1 << 2)
27509 +#define TXC_USBS_EP1RDY (1 << 5)
27510 +#define TXC_USBS_SUSFLAG (1 << 6)
27511 +#define TXC_USBS_RXFAULT (1 << 7)
27512 +/* USB Control register */
27513 +#define SR_USBC 0xF4
27514 +#define USBC_EP3NAK (1 << 4)
27515 +#define USBC_EP3ACK (1 << 5)
27517 +/* Register access commands and flags */
27518 +#define SR_RD_REGS 0x00
27519 +#define SR_WR_REGS 0x01
27520 +#define SR_WR_REG 0x03
27521 +#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
27522 +#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
27525 +#define SR_SHARE_TIMEOUT 1000
27526 +#define SR_EEPROM_LEN 256
27527 +#define SR_MCAST_SIZE 8
27528 +#define SR_MCAST_ADDR_FLAG 0x80
27529 +#define SR_MCAST_MAX 64
27530 +#define SR_TX_OVERHEAD 2 /* 2bytes header */
27531 +#define SR_RX_OVERHEAD 7 /* 3bytes header + 4crc tail */
27533 +#endif /* _SR9700_H */
27534 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9800.c backports-4.2.6-1/drivers/net/usb/sr9800.c
27535 --- backports-4.2.6-1.org/drivers/net/usb/sr9800.c 1970-01-01 01:00:00.000000000 +0100
27536 +++ backports-4.2.6-1/drivers/net/usb/sr9800.c 2016-06-28 14:35:18.015307217 +0200
27538 +/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
27540 + * Author : Liu Junliang <liujunliang_ljl@163.com>
27542 + * Based on asix_common.c, asix_devices.c
27544 + * This file is licensed under the terms of the GNU General Public License
27545 + * version 2. This program is licensed "as is" without any warranty of any
27546 + * kind, whether express or implied.*
27549 +#include <linux/module.h>
27550 +#include <linux/kmod.h>
27551 +#include <linux/init.h>
27552 +#include <linux/netdevice.h>
27553 +#include <linux/etherdevice.h>
27554 +#include <linux/ethtool.h>
27555 +#include <linux/workqueue.h>
27556 +#include <linux/mii.h>
27557 +#include <linux/usb.h>
27558 +#include <linux/crc32.h>
27559 +#include <linux/usb/usbnet.h>
27560 +#include <linux/slab.h>
27561 +#include <linux/if_vlan.h>
27563 +#include "sr9800.h"
27565 +static int sr_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27566 + u16 size, void *data)
27570 + err = usbnet_read_cmd(dev, cmd, SR_REQ_RD_REG, value, index,
27572 + if ((err != size) && (err >= 0))
27578 +static int sr_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27579 + u16 size, void *data)
27583 + err = usbnet_write_cmd(dev, cmd, SR_REQ_WR_REG, value, index,
27585 + if ((err != size) && (err >= 0))
27592 +sr_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
27593 + u16 size, void *data)
27595 + usbnet_write_cmd_async(dev, cmd, SR_REQ_WR_REG, value, index, data,
27599 +static int sr_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
27603 + /* This check is no longer done by usbnet */
27604 + if (skb->len < dev->net->hard_header_len)
27607 + while (offset + sizeof(u32) < skb->len) {
27608 + struct sk_buff *sr_skb;
27610 + u32 header = get_unaligned_le32(skb->data + offset);
27612 + offset += sizeof(u32);
27613 + /* get the packet length */
27614 + size = (u16) (header & 0x7ff);
27615 + if (size != ((~header >> 16) & 0x07ff)) {
27616 + netdev_err(dev->net, "%s : Bad Header Length\n",
27621 + if ((size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) ||
27622 + (size + offset > skb->len)) {
27623 + netdev_err(dev->net, "%s : Bad RX Length %d\n",
27627 + sr_skb = netdev_alloc_skb_ip_align(dev->net, size);
27631 + skb_put(sr_skb, size);
27632 + memcpy(sr_skb->data, skb->data + offset, size);
27633 + usbnet_skb_return(dev, sr_skb);
27635 + offset += (size + 1) & 0xfffe;
27638 + if (skb->len != offset) {
27639 + netdev_err(dev->net, "%s : Bad SKB Length %d\n", __func__,
27647 +static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
27650 + int headroom = skb_headroom(skb);
27651 + int tailroom = skb_tailroom(skb);
27652 + u32 padbytes = 0xffff0000;
27656 + padlen = ((skb->len + 4) % (dev->maxpacket - 1)) ? 0 : 4;
27658 + if ((!skb_cloned(skb)) && ((headroom + tailroom) >= (4 + padlen))) {
27659 + if ((headroom < 4) || (tailroom < padlen)) {
27660 + skb->data = memmove(skb->head + 4, skb->data,
27662 + skb_set_tail_pointer(skb, skb->len);
27665 + struct sk_buff *skb2;
27666 + skb2 = skb_copy_expand(skb, 4, padlen, flags);
27667 + dev_kfree_skb_any(skb);
27673 + skb_push(skb, 4);
27674 + packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
27675 + cpu_to_le32s(&packet_len);
27676 + skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
27679 + cpu_to_le32s(&padbytes);
27680 + memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
27681 + skb_put(skb, sizeof(padbytes));
27684 + usbnet_set_skb_tx_stats(skb, 1, 0);
27688 +static void sr_status(struct usbnet *dev, struct urb *urb)
27690 + struct sr9800_int_data *event;
27693 + if (urb->actual_length < 8)
27696 + event = urb->transfer_buffer;
27697 + link = event->link & 0x01;
27698 + if (netif_carrier_ok(dev->net) != link) {
27699 + usbnet_link_change(dev, link, 1);
27700 + netdev_dbg(dev->net, "Link Status is: %d\n", link);
27706 +static inline int sr_set_sw_mii(struct usbnet *dev)
27710 + ret = sr_write_cmd(dev, SR_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
27712 + netdev_err(dev->net, "Failed to enable software MII access\n");
27716 +static inline int sr_set_hw_mii(struct usbnet *dev)
27720 + ret = sr_write_cmd(dev, SR_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
27722 + netdev_err(dev->net, "Failed to enable hardware MII access\n");
27726 +static inline int sr_get_phy_addr(struct usbnet *dev)
27731 + ret = sr_read_cmd(dev, SR_CMD_READ_PHY_ID, 0, 0, 2, buf);
27733 + netdev_err(dev->net, "%s : Error reading PHYID register:%02x\n",
27737 + netdev_dbg(dev->net, "%s : returning 0x%04x\n", __func__,
27738 + *((__le16 *)buf));
27746 +static int sr_sw_reset(struct usbnet *dev, u8 flags)
27750 + ret = sr_write_cmd(dev, SR_CMD_SW_RESET, flags, 0, 0, NULL);
27752 + netdev_err(dev->net, "Failed to send software reset:%02x\n",
27758 +static u16 sr_read_rx_ctl(struct usbnet *dev)
27763 + ret = sr_read_cmd(dev, SR_CMD_READ_RX_CTL, 0, 0, 2, &v);
27765 + netdev_err(dev->net, "Error reading RX_CTL register:%02x\n",
27770 + ret = le16_to_cpu(v);
27775 +static int sr_write_rx_ctl(struct usbnet *dev, u16 mode)
27779 + netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
27780 + ret = sr_write_cmd(dev, SR_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
27782 + netdev_err(dev->net,
27783 + "Failed to write RX_CTL mode to 0x%04x:%02x\n",
27789 +static u16 sr_read_medium_status(struct usbnet *dev)
27794 + ret = sr_read_cmd(dev, SR_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
27796 + netdev_err(dev->net,
27797 + "Error reading Medium Status register:%02x\n", ret);
27798 + return ret; /* TODO: callers not checking for error ret */
27801 + return le16_to_cpu(v);
27804 +static int sr_write_medium_mode(struct usbnet *dev, u16 mode)
27808 + netdev_dbg(dev->net, "%s : mode = 0x%04x\n", __func__, mode);
27809 + ret = sr_write_cmd(dev, SR_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
27811 + netdev_err(dev->net,
27812 + "Failed to write Medium Mode mode to 0x%04x:%02x\n",
27817 +static int sr_write_gpio(struct usbnet *dev, u16 value, int sleep)
27821 + netdev_dbg(dev->net, "%s : value = 0x%04x\n", __func__, value);
27822 + ret = sr_write_cmd(dev, SR_CMD_WRITE_GPIOS, value, 0, 0, NULL);
27824 + netdev_err(dev->net, "Failed to write GPIO value 0x%04x:%02x\n",
27832 +/* SR9800 have a 16-bit RX_CTL value */
27833 +static void sr_set_multicast(struct net_device *net)
27835 + struct usbnet *dev = netdev_priv(net);
27836 + struct sr_data *data = (struct sr_data *)&dev->data;
27837 + u16 rx_ctl = SR_DEFAULT_RX_CTL;
27839 + if (net->flags & IFF_PROMISC) {
27840 + rx_ctl |= SR_RX_CTL_PRO;
27841 + } else if (net->flags & IFF_ALLMULTI ||
27842 + netdev_mc_count(net) > SR_MAX_MCAST) {
27843 + rx_ctl |= SR_RX_CTL_AMALL;
27844 + } else if (netdev_mc_empty(net)) {
27845 + /* just broadcast and directed */
27847 + /* We use the 20 byte dev->data
27848 + * for our 8 byte filter buffer
27849 + * to avoid allocating memory that
27850 + * is tricky to free later
27852 + struct netdev_hw_addr *ha;
27855 + memset(data->multi_filter, 0, SR_MCAST_FILTER_SIZE);
27857 + /* Build the multicast hash filter. */
27858 + netdev_for_each_mc_addr(ha, net) {
27859 + crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
27860 + data->multi_filter[crc_bits >> 3] |=
27861 + 1 << (crc_bits & 7);
27864 + sr_write_cmd_async(dev, SR_CMD_WRITE_MULTI_FILTER, 0, 0,
27865 + SR_MCAST_FILTER_SIZE, data->multi_filter);
27867 + rx_ctl |= SR_RX_CTL_AM;
27870 + sr_write_cmd_async(dev, SR_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
27873 +static int sr_mdio_read(struct net_device *net, int phy_id, int loc)
27875 + struct usbnet *dev = netdev_priv(net);
27878 + mutex_lock(&dev->phy_mutex);
27879 + sr_set_sw_mii(dev);
27880 + sr_read_cmd(dev, SR_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, &res);
27881 + sr_set_hw_mii(dev);
27882 + mutex_unlock(&dev->phy_mutex);
27884 + netdev_dbg(dev->net,
27885 + "%s : phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n", __func__,
27886 + phy_id, loc, le16_to_cpu(res));
27888 + return le16_to_cpu(res);
27892 +sr_mdio_write(struct net_device *net, int phy_id, int loc, int val)
27894 + struct usbnet *dev = netdev_priv(net);
27895 + __le16 res = cpu_to_le16(val);
27897 + netdev_dbg(dev->net,
27898 + "%s : phy_id=0x%02x, loc=0x%02x, val=0x%04x\n", __func__,
27899 + phy_id, loc, val);
27900 + mutex_lock(&dev->phy_mutex);
27901 + sr_set_sw_mii(dev);
27902 + sr_write_cmd(dev, SR_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
27903 + sr_set_hw_mii(dev);
27904 + mutex_unlock(&dev->phy_mutex);
27907 +/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
27908 +static u32 sr_get_phyid(struct usbnet *dev)
27914 + /* Poll for the rare case the FW or phy isn't ready yet. */
27915 + for (i = 0; i < 100; i++) {
27916 + phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
27917 + if (phy_reg != 0 && phy_reg != 0xFFFF)
27922 + if (phy_reg <= 0 || phy_reg == 0xFFFF)
27925 + phy_id = (phy_reg & 0xffff) << 16;
27927 + phy_reg = sr_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
27931 + phy_id |= (phy_reg & 0xffff);
27937 +sr_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
27939 + struct usbnet *dev = netdev_priv(net);
27942 + if (sr_read_cmd(dev, SR_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
27943 + wolinfo->supported = 0;
27944 + wolinfo->wolopts = 0;
27947 + wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
27948 + wolinfo->wolopts = 0;
27949 + if (opt & SR_MONITOR_LINK)
27950 + wolinfo->wolopts |= WAKE_PHY;
27951 + if (opt & SR_MONITOR_MAGIC)
27952 + wolinfo->wolopts |= WAKE_MAGIC;
27956 +sr_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
27958 + struct usbnet *dev = netdev_priv(net);
27961 + if (wolinfo->wolopts & WAKE_PHY)
27962 + opt |= SR_MONITOR_LINK;
27963 + if (wolinfo->wolopts & WAKE_MAGIC)
27964 + opt |= SR_MONITOR_MAGIC;
27966 + if (sr_write_cmd(dev, SR_CMD_WRITE_MONITOR_MODE,
27967 + opt, 0, 0, NULL) < 0)
27973 +static int sr_get_eeprom_len(struct net_device *net)
27975 + struct usbnet *dev = netdev_priv(net);
27976 + struct sr_data *data = (struct sr_data *)&dev->data;
27978 + return data->eeprom_len;
27981 +static int sr_get_eeprom(struct net_device *net,
27982 + struct ethtool_eeprom *eeprom, u8 *data)
27984 + struct usbnet *dev = netdev_priv(net);
27985 + __le16 *ebuf = (__le16 *)data;
27989 + /* Crude hack to ensure that we don't overwrite memory
27990 + * if an odd length is supplied
27992 + if (eeprom->len % 2)
27995 + eeprom->magic = SR_EEPROM_MAGIC;
27997 + /* sr9800 returns 2 bytes from eeprom on read */
27998 + for (i = 0; i < eeprom->len / 2; i++) {
27999 + ret = sr_read_cmd(dev, SR_CMD_READ_EEPROM, eeprom->offset + i,
28007 +static void sr_get_drvinfo(struct net_device *net,
28008 + struct ethtool_drvinfo *info)
28010 + struct usbnet *dev = netdev_priv(net);
28011 + struct sr_data *data = (struct sr_data *)&dev->data;
28013 + /* Inherit standard device info */
28014 + usbnet_get_drvinfo(net, info);
28015 + strncpy(info->driver, DRIVER_NAME, sizeof(info->driver));
28016 + strncpy(info->version, DRIVER_VERSION, sizeof(info->version));
28017 + info->eedump_len = data->eeprom_len;
28020 +static u32 sr_get_link(struct net_device *net)
28022 + struct usbnet *dev = netdev_priv(net);
28024 + return mii_link_ok(&dev->mii);
28027 +static int sr_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
28029 + struct usbnet *dev = netdev_priv(net);
28031 + return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
28034 +static int sr_set_mac_address(struct net_device *net, void *p)
28036 + struct usbnet *dev = netdev_priv(net);
28037 + struct sr_data *data = (struct sr_data *)&dev->data;
28038 + struct sockaddr *addr = p;
28040 + if (netif_running(net))
28042 + if (!is_valid_ether_addr(addr->sa_data))
28043 + return -EADDRNOTAVAIL;
28045 + memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
28047 + /* We use the 20 byte dev->data
28048 + * for our 6 byte mac buffer
28049 + * to avoid allocating memory that
28050 + * is tricky to free later
28052 + memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
28053 + sr_write_cmd_async(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
28059 +static const struct ethtool_ops sr9800_ethtool_ops = {
28060 + .get_drvinfo = sr_get_drvinfo,
28061 + .get_link = sr_get_link,
28062 + .get_msglevel = usbnet_get_msglevel,
28063 + .set_msglevel = usbnet_set_msglevel,
28064 + .get_wol = sr_get_wol,
28065 + .set_wol = sr_set_wol,
28066 + .get_eeprom_len = sr_get_eeprom_len,
28067 + .get_eeprom = sr_get_eeprom,
28068 + .get_settings = usbnet_get_settings,
28069 + .set_settings = usbnet_set_settings,
28070 + .nway_reset = usbnet_nway_reset,
28073 +static int sr9800_link_reset(struct usbnet *dev)
28075 + struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
28078 + mii_check_media(&dev->mii, 1, 1);
28079 + mii_ethtool_gset(&dev->mii, &ecmd);
28080 + mode = SR9800_MEDIUM_DEFAULT;
28082 + if (ethtool_cmd_speed(&ecmd) != SPEED_100)
28083 + mode &= ~SR_MEDIUM_PS;
28085 + if (ecmd.duplex != DUPLEX_FULL)
28086 + mode &= ~SR_MEDIUM_FD;
28088 + netdev_dbg(dev->net, "%s : speed: %u duplex: %d mode: 0x%04x\n",
28089 + __func__, ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
28091 + sr_write_medium_mode(dev, mode);
28097 +static int sr9800_set_default_mode(struct usbnet *dev)
28102 + sr_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
28103 + sr_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
28104 + ADVERTISE_ALL | ADVERTISE_CSMA);
28105 + mii_nway_restart(&dev->mii);
28107 + ret = sr_write_medium_mode(dev, SR9800_MEDIUM_DEFAULT);
28111 + ret = sr_write_cmd(dev, SR_CMD_WRITE_IPG012,
28112 + SR9800_IPG0_DEFAULT | SR9800_IPG1_DEFAULT,
28113 + SR9800_IPG2_DEFAULT, 0, NULL);
28115 + netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
28119 + /* Set RX_CTL to default values with 2k buffer, and enable cactus */
28120 + ret = sr_write_rx_ctl(dev, SR_DEFAULT_RX_CTL);
28124 + rx_ctl = sr_read_rx_ctl(dev);
28125 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
28128 + rx_ctl = sr_read_medium_status(dev);
28129 + netdev_dbg(dev->net, "Medium Status:0x%04x after all initializations\n",
28137 +static int sr9800_reset(struct usbnet *dev)
28139 + struct sr_data *data = (struct sr_data *)&dev->data;
28140 + int ret, embd_phy;
28143 + ret = sr_write_gpio(dev,
28144 + SR_GPIO_RSE | SR_GPIO_GPO_2 | SR_GPIO_GPO2EN, 5);
28148 + embd_phy = ((sr_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
28150 + ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
28152 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
28156 + ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_PRL);
28162 + ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
28169 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28173 + ret = sr_sw_reset(dev, SR_SWRESET_PRTE);
28179 + rx_ctl = sr_read_rx_ctl(dev);
28180 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
28181 + ret = sr_write_rx_ctl(dev, 0x0000);
28185 + rx_ctl = sr_read_rx_ctl(dev);
28186 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
28188 + ret = sr_sw_reset(dev, SR_SWRESET_PRL);
28194 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL | SR_SWRESET_PRL);
28200 + ret = sr9800_set_default_mode(dev);
28204 + /* Rewrite MAC address */
28205 + memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
28206 + ret = sr_write_cmd(dev, SR_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
28217 +static const struct net_device_ops sr9800_netdev_ops = {
28218 + .ndo_open = usbnet_open,
28219 + .ndo_stop = usbnet_stop,
28220 + .ndo_start_xmit = usbnet_start_xmit,
28221 + .ndo_tx_timeout = usbnet_tx_timeout,
28222 + .ndo_change_mtu = usbnet_change_mtu,
28223 + .ndo_set_mac_address = sr_set_mac_address,
28224 + .ndo_validate_addr = eth_validate_addr,
28225 + .ndo_do_ioctl = sr_ioctl,
28226 + .ndo_set_rx_mode = sr_set_multicast,
28229 +static int sr9800_phy_powerup(struct usbnet *dev)
28233 + /* set the embedded Ethernet PHY in power-down state */
28234 + ret = sr_sw_reset(dev, SR_SWRESET_IPPD | SR_SWRESET_IPRL);
28236 + netdev_err(dev->net, "Failed to power down PHY : %d\n", ret);
28241 + /* set the embedded Ethernet PHY in power-up state */
28242 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28244 + netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
28249 + /* set the embedded Ethernet PHY in reset state */
28250 + ret = sr_sw_reset(dev, SR_SWRESET_CLEAR);
28252 + netdev_err(dev->net, "Failed to power up PHY: %d\n", ret);
28257 + /* set the embedded Ethernet PHY in power-up state */
28258 + ret = sr_sw_reset(dev, SR_SWRESET_IPRL);
28260 + netdev_err(dev->net, "Failed to reset PHY: %d\n", ret);
28267 +static int sr9800_bind(struct usbnet *dev, struct usb_interface *intf)
28269 + struct sr_data *data = (struct sr_data *)&dev->data;
28270 + u16 led01_mux, led23_mux;
28271 + int ret, embd_phy;
28275 + data->eeprom_len = SR9800_EEPROM_LEN;
28277 + usbnet_get_endpoints(dev, intf);
28279 + /* LED Setting Rule :
28281 + * AA : MFA0(LED0)
28282 + * BB : MFA1(LED1)
28283 + * CC : MFA2(LED2), Reserved for SR9800
28284 + * DD : MFA3(LED3), Reserved for SR9800
28286 + led01_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_LINK;
28287 + led23_mux = (SR_LED_MUX_LINK_ACTIVE << 8) | SR_LED_MUX_TX_ACTIVE;
28288 + ret = sr_write_cmd(dev, SR_CMD_LED_MUX, led01_mux, led23_mux, 0, NULL);
28290 + netdev_err(dev->net, "set LINK LED failed : %d\n", ret);
28294 + /* Get the MAC address */
28295 + ret = sr_read_cmd(dev, SR_CMD_READ_NODE_ID, 0, 0, ETH_ALEN,
28296 + dev->net->dev_addr);
28298 + netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
28301 + netdev_dbg(dev->net, "mac addr : %pM\n", dev->net->dev_addr);
28303 + /* Initialize MII structure */
28304 + dev->mii.dev = dev->net;
28305 + dev->mii.mdio_read = sr_mdio_read;
28306 + dev->mii.mdio_write = sr_mdio_write;
28307 + dev->mii.phy_id_mask = 0x1f;
28308 + dev->mii.reg_num_mask = 0x1f;
28309 + dev->mii.phy_id = sr_get_phy_addr(dev);
28311 + dev->net->netdev_ops = &sr9800_netdev_ops;
28312 + dev->net->ethtool_ops = &sr9800_ethtool_ops;
28314 + embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
28315 + /* Reset the PHY to normal operation mode */
28316 + ret = sr_write_cmd(dev, SR_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
28318 + netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
28322 + /* Init PHY routine */
28323 + ret = sr9800_phy_powerup(dev);
28327 + rx_ctl = sr_read_rx_ctl(dev);
28328 + netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
28329 + ret = sr_write_rx_ctl(dev, 0x0000);
28333 + rx_ctl = sr_read_rx_ctl(dev);
28334 + netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
28336 + /* Read PHYID register *AFTER* the PHY was reset properly */
28337 + phyid = sr_get_phyid(dev);
28338 + netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
28340 + /* medium mode setting */
28341 + ret = sr9800_set_default_mode(dev);
28345 + if (dev->udev->speed == USB_SPEED_HIGH) {
28346 + ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
28347 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].byte_cnt,
28348 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].threshold,
28351 + netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
28354 + dev->rx_urb_size =
28355 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_4K].size;
28357 + ret = sr_write_cmd(dev, SR_CMD_BULKIN_SIZE,
28358 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].byte_cnt,
28359 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].threshold,
28362 + netdev_err(dev->net, "Reset RX_CTL failed: %d\n", ret);
28365 + dev->rx_urb_size =
28366 + SR9800_BULKIN_SIZE[SR9800_MAX_BULKIN_2K].size;
28368 + netdev_dbg(dev->net, "%s : setting rx_urb_size with : %zu\n", __func__,
28369 + dev->rx_urb_size);
28376 +static const struct driver_info sr9800_driver_info = {
28377 + .description = "CoreChip SR9800 USB 2.0 Ethernet",
28378 + .bind = sr9800_bind,
28379 + .status = sr_status,
28380 + .link_reset = sr9800_link_reset,
28381 + .reset = sr9800_reset,
28382 + .flags = DRIVER_FLAG,
28383 + .rx_fixup = sr_rx_fixup,
28384 + .tx_fixup = sr_tx_fixup,
28387 +static const struct usb_device_id products[] = {
28389 + USB_DEVICE(0x0fe6, 0x9800), /* SR9800 Device */
28390 + .driver_info = (unsigned long) &sr9800_driver_info,
28395 +MODULE_DEVICE_TABLE(usb, products);
28397 +static struct usb_driver sr_driver = {
28398 + .name = DRIVER_NAME,
28399 + .id_table = products,
28400 + .probe = usbnet_probe,
28401 + .suspend = usbnet_suspend,
28402 + .resume = usbnet_resume,
28403 + .disconnect = usbnet_disconnect,
28404 + .supports_autosuspend = 1,
28407 +module_usb_driver(sr_driver);
28409 +MODULE_AUTHOR("Liu Junliang <liujunliang_ljl@163.com");
28410 +MODULE_VERSION(DRIVER_VERSION);
28411 +MODULE_DESCRIPTION("SR9800 USB 2.0 USB2NET Dev : http://www.corechip-sz.com");
28412 +MODULE_LICENSE("GPL");
28413 diff -Naur backports-4.2.6-1.org/drivers/net/usb/sr9800.h backports-4.2.6-1/drivers/net/usb/sr9800.h
28414 --- backports-4.2.6-1.org/drivers/net/usb/sr9800.h 1970-01-01 01:00:00.000000000 +0100
28415 +++ backports-4.2.6-1/drivers/net/usb/sr9800.h 2016-06-28 14:35:18.015307217 +0200
28417 +/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices
28419 + * Author : Liu Junliang <liujunliang_ljl@163.com>
28421 + * This file is licensed under the terms of the GNU General Public License
28422 + * version 2. This program is licensed "as is" without any warranty of any
28423 + * kind, whether express or implied.
28429 +/* SR9800 spec. command table on Linux Platform */
28431 +/* command : Software Station Management Control Reg */
28432 +#define SR_CMD_SET_SW_MII 0x06
28433 +/* command : PHY Read Reg */
28434 +#define SR_CMD_READ_MII_REG 0x07
28435 +/* command : PHY Write Reg */
28436 +#define SR_CMD_WRITE_MII_REG 0x08
28437 +/* command : Hardware Station Management Control Reg */
28438 +#define SR_CMD_SET_HW_MII 0x0a
28439 +/* command : SROM Read Reg */
28440 +#define SR_CMD_READ_EEPROM 0x0b
28441 +/* command : SROM Write Reg */
28442 +#define SR_CMD_WRITE_EEPROM 0x0c
28443 +/* command : SROM Write Enable Reg */
28444 +#define SR_CMD_WRITE_ENABLE 0x0d
28445 +/* command : SROM Write Disable Reg */
28446 +#define SR_CMD_WRITE_DISABLE 0x0e
28447 +/* command : RX Control Read Reg */
28448 +#define SR_CMD_READ_RX_CTL 0x0f
28449 +#define SR_RX_CTL_PRO (1 << 0)
28450 +#define SR_RX_CTL_AMALL (1 << 1)
28451 +#define SR_RX_CTL_SEP (1 << 2)
28452 +#define SR_RX_CTL_AB (1 << 3)
28453 +#define SR_RX_CTL_AM (1 << 4)
28454 +#define SR_RX_CTL_AP (1 << 5)
28455 +#define SR_RX_CTL_ARP (1 << 6)
28456 +#define SR_RX_CTL_SO (1 << 7)
28457 +#define SR_RX_CTL_RH1M (1 << 8)
28458 +#define SR_RX_CTL_RH2M (1 << 9)
28459 +#define SR_RX_CTL_RH3M (1 << 10)
28460 +/* command : RX Control Write Reg */
28461 +#define SR_CMD_WRITE_RX_CTL 0x10
28462 +/* command : IPG0/IPG1/IPG2 Control Read Reg */
28463 +#define SR_CMD_READ_IPG012 0x11
28464 +/* command : IPG0/IPG1/IPG2 Control Write Reg */
28465 +#define SR_CMD_WRITE_IPG012 0x12
28466 +/* command : Node ID Read Reg */
28467 +#define SR_CMD_READ_NODE_ID 0x13
28468 +/* command : Node ID Write Reg */
28469 +#define SR_CMD_WRITE_NODE_ID 0x14
28470 +/* command : Multicast Filter Array Read Reg */
28471 +#define SR_CMD_READ_MULTI_FILTER 0x15
28472 +/* command : Multicast Filter Array Write Reg */
28473 +#define SR_CMD_WRITE_MULTI_FILTER 0x16
28474 +/* command : Eth/HomePNA PHY Address Reg */
28475 +#define SR_CMD_READ_PHY_ID 0x19
28476 +/* command : Medium Status Read Reg */
28477 +#define SR_CMD_READ_MEDIUM_STATUS 0x1a
28478 +#define SR_MONITOR_LINK (1 << 1)
28479 +#define SR_MONITOR_MAGIC (1 << 2)
28480 +#define SR_MONITOR_HSFS (1 << 4)
28481 +/* command : Medium Status Write Reg */
28482 +#define SR_CMD_WRITE_MEDIUM_MODE 0x1b
28483 +#define SR_MEDIUM_GM (1 << 0)
28484 +#define SR_MEDIUM_FD (1 << 1)
28485 +#define SR_MEDIUM_AC (1 << 2)
28486 +#define SR_MEDIUM_ENCK (1 << 3)
28487 +#define SR_MEDIUM_RFC (1 << 4)
28488 +#define SR_MEDIUM_TFC (1 << 5)
28489 +#define SR_MEDIUM_JFE (1 << 6)
28490 +#define SR_MEDIUM_PF (1 << 7)
28491 +#define SR_MEDIUM_RE (1 << 8)
28492 +#define SR_MEDIUM_PS (1 << 9)
28493 +#define SR_MEDIUM_RSV (1 << 10)
28494 +#define SR_MEDIUM_SBP (1 << 11)
28495 +#define SR_MEDIUM_SM (1 << 12)
28496 +/* command : Monitor Mode Status Read Reg */
28497 +#define SR_CMD_READ_MONITOR_MODE 0x1c
28498 +/* command : Monitor Mode Status Write Reg */
28499 +#define SR_CMD_WRITE_MONITOR_MODE 0x1d
28500 +/* command : GPIO Status Read Reg */
28501 +#define SR_CMD_READ_GPIOS 0x1e
28502 +#define SR_GPIO_GPO0EN (1 << 0) /* GPIO0 Output enable */
28503 +#define SR_GPIO_GPO_0 (1 << 1) /* GPIO0 Output value */
28504 +#define SR_GPIO_GPO1EN (1 << 2) /* GPIO1 Output enable */
28505 +#define SR_GPIO_GPO_1 (1 << 3) /* GPIO1 Output value */
28506 +#define SR_GPIO_GPO2EN (1 << 4) /* GPIO2 Output enable */
28507 +#define SR_GPIO_GPO_2 (1 << 5) /* GPIO2 Output value */
28508 +#define SR_GPIO_RESERVED (1 << 6) /* Reserved */
28509 +#define SR_GPIO_RSE (1 << 7) /* Reload serial EEPROM */
28510 +/* command : GPIO Status Write Reg */
28511 +#define SR_CMD_WRITE_GPIOS 0x1f
28512 +/* command : Eth PHY Power and Reset Control Reg */
28513 +#define SR_CMD_SW_RESET 0x20
28514 +#define SR_SWRESET_CLEAR 0x00
28515 +#define SR_SWRESET_RR (1 << 0)
28516 +#define SR_SWRESET_RT (1 << 1)
28517 +#define SR_SWRESET_PRTE (1 << 2)
28518 +#define SR_SWRESET_PRL (1 << 3)
28519 +#define SR_SWRESET_BZ (1 << 4)
28520 +#define SR_SWRESET_IPRL (1 << 5)
28521 +#define SR_SWRESET_IPPD (1 << 6)
28522 +/* command : Software Interface Selection Status Read Reg */
28523 +#define SR_CMD_SW_PHY_STATUS 0x21
28524 +/* command : Software Interface Selection Status Write Reg */
28525 +#define SR_CMD_SW_PHY_SELECT 0x22
28526 +/* command : BULK in Buffer Size Reg */
28527 +#define SR_CMD_BULKIN_SIZE 0x2A
28528 +/* command : LED_MUX Control Reg */
28529 +#define SR_CMD_LED_MUX 0x70
28530 +#define SR_LED_MUX_TX_ACTIVE (1 << 0)
28531 +#define SR_LED_MUX_RX_ACTIVE (1 << 1)
28532 +#define SR_LED_MUX_COLLISION (1 << 2)
28533 +#define SR_LED_MUX_DUP_COL (1 << 3)
28534 +#define SR_LED_MUX_DUP (1 << 4)
28535 +#define SR_LED_MUX_SPEED (1 << 5)
28536 +#define SR_LED_MUX_LINK_ACTIVE (1 << 6)
28537 +#define SR_LED_MUX_LINK (1 << 7)
28539 +/* Register Access Flags */
28540 +#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
28541 +#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
28543 +/* Multicast Filter Array size & Max Number */
28544 +#define SR_MCAST_FILTER_SIZE 8
28545 +#define SR_MAX_MCAST 64
28547 +/* IPG0/1/2 Default Value */
28548 +#define SR9800_IPG0_DEFAULT 0x15
28549 +#define SR9800_IPG1_DEFAULT 0x0c
28550 +#define SR9800_IPG2_DEFAULT 0x12
28552 +/* Medium Status Default Mode */
28553 +#define SR9800_MEDIUM_DEFAULT \
28554 + (SR_MEDIUM_FD | SR_MEDIUM_RFC | \
28555 + SR_MEDIUM_TFC | SR_MEDIUM_PS | \
28556 + SR_MEDIUM_AC | SR_MEDIUM_RE)
28558 +/* RX Control Default Setting */
28559 +#define SR_DEFAULT_RX_CTL \
28560 + (SR_RX_CTL_SO | SR_RX_CTL_AB | SR_RX_CTL_RH1M)
28562 +/* EEPROM Magic Number & EEPROM Size */
28563 +#define SR_EEPROM_MAGIC 0xdeadbeef
28564 +#define SR9800_EEPROM_LEN 0xff
28566 +/* SR9800 Driver Version and Driver Name */
28567 +#define DRIVER_VERSION "11-Nov-2013"
28568 +#define DRIVER_NAME "CoreChips"
28569 +#define DRIVER_FLAG \
28570 + (FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET)
28572 +/* SR9800 BULKIN Buffer Size */
28573 +#define SR9800_MAX_BULKIN_2K 0
28574 +#define SR9800_MAX_BULKIN_4K 1
28575 +#define SR9800_MAX_BULKIN_6K 2
28576 +#define SR9800_MAX_BULKIN_8K 3
28577 +#define SR9800_MAX_BULKIN_16K 4
28578 +#define SR9800_MAX_BULKIN_20K 5
28579 +#define SR9800_MAX_BULKIN_24K 6
28580 +#define SR9800_MAX_BULKIN_32K 7
28582 +struct {unsigned short size, byte_cnt, threshold; } SR9800_BULKIN_SIZE[] = {
28584 + {2048, 0x8000, 0x8001},
28586 + {4096, 0x8100, 0x8147},
28588 + {6144, 0x8200, 0x81EB},
28590 + {8192, 0x8300, 0x83D7},
28592 + {16384, 0x8400, 0x851E},
28594 + {20480, 0x8500, 0x8666},
28596 + {24576, 0x8600, 0x87AE},
28598 + {32768, 0x8700, 0x8A3D},
28601 +/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
28603 + u8 multi_filter[SR_MCAST_FILTER_SIZE];
28604 + u8 mac_addr[ETH_ALEN];
28610 +struct sr9800_int_data {
28618 +#endif /* _SR9800_H */
28619 diff -Naur backports-4.2.6-1.org/drivers/net/usb/zaurus.c backports-4.2.6-1/drivers/net/usb/zaurus.c
28620 --- backports-4.2.6-1.org/drivers/net/usb/zaurus.c 1970-01-01 01:00:00.000000000 +0100
28621 +++ backports-4.2.6-1/drivers/net/usb/zaurus.c 2016-06-28 14:35:18.015307217 +0200
28624 + * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
28625 + * Copyright (C) 2002-2005 by David Brownell
28627 + * This program is free software; you can redistribute it and/or modify
28628 + * it under the terms of the GNU General Public License as published by
28629 + * the Free Software Foundation; either version 2 of the License, or
28630 + * (at your option) any later version.
28632 + * This program is distributed in the hope that it will be useful,
28633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28635 + * GNU General Public License for more details.
28637 + * You should have received a copy of the GNU General Public License
28638 + * along with this program; if not, see <http://www.gnu.org/licenses/>.
28641 +// #define DEBUG // error path messages, extra info
28642 +// #define VERBOSE // more; success messages
28644 +#include <linux/module.h>
28645 +#include <linux/netdevice.h>
28646 +#include <linux/ethtool.h>
28647 +#include <linux/workqueue.h>
28648 +#include <linux/mii.h>
28649 +#include <linux/crc32.h>
28650 +#include <linux/usb.h>
28651 +#include <linux/usb/cdc.h>
28652 +#include <linux/usb/usbnet.h>
28656 + * All known Zaurii lie about their standards conformance. At least
28657 + * the earliest SA-1100 models lie by saying they support CDC Ethernet.
28658 + * Some later models (especially PXA-25x and PXA-27x based ones) lie
28659 + * and say they support CDC MDLM (for access to cell phone modems).
28661 + * There are non-Zaurus products that use these same protocols too.
28663 + * The annoying thing is that at the same time Sharp was developing
28664 + * that annoying standards-breaking software, the Linux community had
28665 + * a simple "CDC Subset" working reliably on the same SA-1100 hardware.
28666 + * That is, the same functionality but not violating standards.
28668 + * The CDC Ethernet nonconformance points are troublesome to hosts
28669 + * with a true CDC Ethernet implementation:
28670 + * - Framing appends a CRC, which the spec says drivers "must not" do;
28671 + * - Transfers data in altsetting zero, instead of altsetting 1;
28672 + * - All these peripherals use the same ethernet address.
28674 + * The CDC MDLM nonconformance is less immediately troublesome, since all
28675 + * MDLM implementations are quasi-proprietary anyway.
28678 +static struct sk_buff *
28679 +zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
28682 + struct sk_buff *skb2;
28685 + if (!skb_cloned(skb)) {
28686 + int tailroom = skb_tailroom(skb);
28687 + if ((padlen + 4) <= tailroom)
28690 + skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
28691 + dev_kfree_skb_any(skb);
28696 + fcs = crc32_le(~0, skb->data, skb->len);
28699 + *skb_put (skb, 1) = fcs & 0xff;
28700 + *skb_put (skb, 1) = (fcs>> 8) & 0xff;
28701 + *skb_put (skb, 1) = (fcs>>16) & 0xff;
28702 + *skb_put (skb, 1) = (fcs>>24) & 0xff;
28707 +static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
28709 + /* Belcarra's funky framing has other options; mostly
28710 + * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
28712 + dev->net->hard_header_len += 6;
28713 + dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
28714 + return usbnet_generic_cdc_bind(dev, intf);
28717 +/* PDA style devices are always connected if present */
28718 +static int always_connected (struct usbnet *dev)
28723 +static const struct driver_info zaurus_sl5x00_info = {
28724 + .description = "Sharp Zaurus SL-5x00",
28725 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28726 + .check_connect = always_connected,
28727 + .bind = zaurus_bind,
28728 + .unbind = usbnet_cdc_unbind,
28729 + .tx_fixup = zaurus_tx_fixup,
28731 +#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
28733 +static const struct driver_info zaurus_pxa_info = {
28734 + .description = "Sharp Zaurus, PXA-2xx based",
28735 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28736 + .check_connect = always_connected,
28737 + .bind = zaurus_bind,
28738 + .unbind = usbnet_cdc_unbind,
28739 + .tx_fixup = zaurus_tx_fixup,
28741 +#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
28743 +static const struct driver_info olympus_mxl_info = {
28744 + .description = "Olympus R1000",
28745 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28746 + .check_connect = always_connected,
28747 + .bind = zaurus_bind,
28748 + .unbind = usbnet_cdc_unbind,
28749 + .tx_fixup = zaurus_tx_fixup,
28751 +#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
28754 +/* Some more recent products using Lineo/Belcarra code will wrongly claim
28755 + * CDC MDLM conformance. They aren't conformant: data endpoints live
28756 + * in the control interface, there's no data interface, and it's not used
28757 + * to talk to a cell phone radio. But at least we can detect these two
28758 + * pseudo-classes, rather than growing this product list with entries for
28759 + * each new nonconformant product (sigh).
28761 +static const u8 safe_guid[16] = {
28762 + 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
28763 + 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
28765 +static const u8 blan_guid[16] = {
28766 + 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
28767 + 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
28770 +static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
28772 + u8 *buf = intf->cur_altsetting->extra;
28773 + int len = intf->cur_altsetting->extralen;
28774 + struct usb_cdc_mdlm_desc *desc = NULL;
28775 + struct usb_cdc_mdlm_detail_desc *detail = NULL;
28777 + while (len > 3) {
28778 + if (buf [1] != USB_DT_CS_INTERFACE)
28781 + /* use bDescriptorSubType, and just verify that we get a
28782 + * "BLAN" (or "SAFE") descriptor.
28784 + switch (buf [2]) {
28785 + case USB_CDC_MDLM_TYPE:
28787 + dev_dbg(&intf->dev, "extra MDLM\n");
28790 + desc = (void *) buf;
28791 + if (desc->bLength != sizeof *desc) {
28792 + dev_dbg(&intf->dev, "MDLM len %u\n",
28796 + /* expect bcdVersion 1.0, ignore */
28797 + if (memcmp(&desc->bGUID, blan_guid, 16) &&
28798 + memcmp(&desc->bGUID, safe_guid, 16)) {
28799 + /* hey, this one might _really_ be MDLM! */
28800 + dev_dbg(&intf->dev, "MDLM guid\n");
28804 + case USB_CDC_MDLM_DETAIL_TYPE:
28806 + dev_dbg(&intf->dev, "extra MDLM detail\n");
28809 + detail = (void *) buf;
28810 + switch (detail->bGuidDescriptorType) {
28811 + case 0: /* "SAFE" */
28812 + if (detail->bLength != (sizeof *detail + 2))
28815 + case 1: /* "BLAN" */
28816 + if (detail->bLength != (sizeof *detail + 3))
28823 + /* assuming we either noticed BLAN already, or will
28824 + * find it soon, there are some data bytes here:
28825 + * - bmNetworkCapabilities (unused)
28826 + * - bmDataCapabilities (bits, see below)
28827 + * - bPad (ignored, for PADAFTER -- BLAN-only)
28829 + * - 0x01 -- Zaurus framing (add CRC)
28830 + * - 0x02 -- PADBEFORE (CRC includes some padding)
28831 + * - 0x04 -- PADAFTER (some padding after CRC)
28832 + * - 0x08 -- "fermat" packet mangling (for hw bugs)
28833 + * the PADBEFORE appears not to matter; we interop
28834 + * with devices that use it and those that don't.
28836 + if ((detail->bDetailData[1] & ~0x02) != 0x01) {
28837 + /* bmDataCapabilities == 0 would be fine too,
28838 + * but framing is minidriver-coupled for now.
28841 + dev_dbg(&intf->dev,
28842 + "bad MDLM detail, %d %d %d\n",
28844 + detail->bDetailData[0],
28845 + detail->bDetailData[2]);
28849 + /* same extra framing as for non-BLAN mode */
28850 + dev->net->hard_header_len += 6;
28851 + dev->rx_urb_size = dev->net->hard_header_len
28856 + len -= buf [0]; /* bLength */
28860 + if (!desc || !detail) {
28861 + dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
28862 + desc ? "" : "func ",
28863 + detail ? "" : "detail ");
28867 + /* There's probably a CDC Ethernet descriptor there, but we can't
28868 + * rely on the Ethernet address it provides since not all vendors
28869 + * bother to make it unique. Likewise there's no point in tracking
28870 + * of the CDC event notifications.
28872 + return usbnet_get_endpoints(dev, intf);
28875 + dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n");
28879 +static const struct driver_info bogus_mdlm_info = {
28880 + .description = "pseudo-MDLM (BLAN) device",
28881 + .flags = FLAG_POINTTOPOINT | FLAG_FRAMING_Z,
28882 + .check_connect = always_connected,
28883 + .tx_fixup = zaurus_tx_fixup,
28884 + .bind = blan_mdlm_bind,
28887 +static const struct usb_device_id products [] = {
28888 +#define ZAURUS_MASTER_INTERFACE \
28889 + .bInterfaceClass = USB_CLASS_COMM, \
28890 + .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
28891 + .bInterfaceProtocol = USB_CDC_PROTO_NONE
28893 +/* SA-1100 based Sharp Zaurus ("collie"), or compatible. */
28895 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28896 + | USB_DEVICE_ID_MATCH_DEVICE,
28897 + .idVendor = 0x04DD,
28898 + .idProduct = 0x8004,
28899 + ZAURUS_MASTER_INTERFACE,
28900 + .driver_info = ZAURUS_STRONGARM_INFO,
28903 +/* PXA-2xx based models are also lying-about-cdc. If you add any
28904 + * more devices that claim to be CDC Ethernet, make sure they get
28905 + * added to the blacklist in cdc_ether too.
28907 + * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
28908 + * unlike the older ones with 2.4 "embedix" kernels.
28911 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28912 + | USB_DEVICE_ID_MATCH_DEVICE,
28913 + .idVendor = 0x04DD,
28914 + .idProduct = 0x8005, /* A-300 */
28915 + ZAURUS_MASTER_INTERFACE,
28916 + .driver_info = ZAURUS_PXA_INFO,
28918 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28919 + | USB_DEVICE_ID_MATCH_DEVICE,
28920 + .idVendor = 0x04DD,
28921 + .idProduct = 0x8006, /* B-500/SL-5600 */
28922 + ZAURUS_MASTER_INTERFACE,
28923 + .driver_info = ZAURUS_PXA_INFO,
28925 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28926 + | USB_DEVICE_ID_MATCH_DEVICE,
28927 + .idVendor = 0x04DD,
28928 + .idProduct = 0x8007, /* C-700 */
28929 + ZAURUS_MASTER_INTERFACE,
28930 + .driver_info = ZAURUS_PXA_INFO,
28932 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28933 + | USB_DEVICE_ID_MATCH_DEVICE,
28934 + .idVendor = 0x04DD,
28935 + .idProduct = 0x9031, /* C-750 C-760 */
28936 + ZAURUS_MASTER_INTERFACE,
28937 + .driver_info = ZAURUS_PXA_INFO,
28939 + /* C-750/C-760/C-860/SL-C3000 PDA in MDLM mode */
28940 + USB_DEVICE_AND_INTERFACE_INFO(0x04DD, 0x9031, USB_CLASS_COMM,
28941 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28942 + .driver_info = (unsigned long) &bogus_mdlm_info,
28944 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28945 + | USB_DEVICE_ID_MATCH_DEVICE,
28946 + .idVendor = 0x04DD,
28947 + .idProduct = 0x9032, /* SL-6000 */
28948 + ZAURUS_MASTER_INTERFACE,
28949 + .driver_info = ZAURUS_PXA_INFO,
28951 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28952 + | USB_DEVICE_ID_MATCH_DEVICE,
28953 + .idVendor = 0x04DD,
28954 + /* reported with some C860 units */
28955 + .idProduct = 0x9050, /* C-860 */
28956 + ZAURUS_MASTER_INTERFACE,
28957 + .driver_info = ZAURUS_PXA_INFO,
28960 + /* Motorola Rokr E6 */
28961 + USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6027, USB_CLASS_COMM,
28962 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28963 + .driver_info = (unsigned long) &bogus_mdlm_info,
28965 + /* Motorola MOTOMAGX phones */
28966 + USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM,
28967 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28968 + .driver_info = (unsigned long) &bogus_mdlm_info,
28971 +/* Olympus has some models with a Zaurus-compatible option.
28972 + * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
28975 + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
28976 + | USB_DEVICE_ID_MATCH_DEVICE,
28977 + .idVendor = 0x07B4,
28978 + .idProduct = 0x0F02, /* R-1000 */
28979 + ZAURUS_MASTER_INTERFACE,
28980 + .driver_info = OLYMPUS_MXL_INFO,
28983 +/* Logitech Harmony 900 - uses the pseudo-MDLM (BLAN) driver */
28985 + USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM,
28986 + USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
28987 + .driver_info = (unsigned long) &bogus_mdlm_info,
28991 +MODULE_DEVICE_TABLE(usb, products);
28993 +static struct usb_driver zaurus_driver = {
28994 + .name = "zaurus",
28995 + .id_table = products,
28996 + .probe = usbnet_probe,
28997 + .disconnect = usbnet_disconnect,
28998 + .suspend = usbnet_suspend,
28999 + .resume = usbnet_resume,
29000 + .disable_hub_initiated_lpm = 1,
29003 +module_usb_driver(zaurus_driver);
29005 +MODULE_AUTHOR("Pavel Machek, David Brownell");
29006 +MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
29007 +MODULE_LICENSE("GPL");