1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Aquantia Corp. Aquantia AQtion USB to 5GbE Controller
3 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
5 * Copyright (C) 2002-2003 TiVo Inc.
6 * Copyright (C) 2017-2018 ASIX
7 * Copyright (C) 2018 Aquantia Corp.
10 #include <linux/module.h>
11 #include <linux/netdevice.h>
12 #include <linux/ethtool.h>
13 #include <linux/mii.h>
14 #include <linux/usb.h>
15 #include <linux/crc32.h>
16 #include <linux/if_vlan.h>
17 #include <linux/usb/cdc.h>
18 #include <linux/usb/usbnet.h>
19 #include <linux/linkmode.h>
23 #define DRIVER_NAME "aqc111"
25 static int aqc111_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
26 u16 index, u16 size, void *data)
30 ret = usbnet_read_cmd_nopm(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR |
31 USB_RECIP_DEVICE, value, index, data, size);
33 if (unlikely(ret < 0))
35 "Failed to read(0x%x) reg index 0x%04x: %d\n",
41 static int aqc111_read_cmd(struct usbnet *dev, u8 cmd, u16 value,
42 u16 index, u16 size, void *data)
46 ret = usbnet_read_cmd(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR |
47 USB_RECIP_DEVICE, value, index, data, size);
49 if (unlikely(ret < 0))
51 "Failed to read(0x%x) reg index 0x%04x: %d\n",
57 static int aqc111_read16_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
62 ret = aqc111_read_cmd_nopm(dev, cmd, value, index, sizeof(*data), data);
68 static int aqc111_read16_cmd(struct usbnet *dev, u8 cmd, u16 value,
73 ret = aqc111_read_cmd(dev, cmd, value, index, sizeof(*data), data);
79 static int __aqc111_write_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
80 u16 value, u16 index, u16 size, const void *data)
86 "%s cmd=%#x reqtype=%#x value=%#x index=%#x size=%d\n",
87 __func__, cmd, reqtype, value, index, size);
90 buf = kmemdup(data, size, GFP_KERNEL);
95 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
96 cmd, reqtype, value, index, buf, size,
97 (cmd == AQ_PHY_POWER) ? AQ_USB_PHY_SET_TIMEOUT :
100 if (unlikely(err < 0))
101 netdev_warn(dev->net,
102 "Failed to write(0x%x) reg index 0x%04x: %d\n",
110 static int aqc111_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
111 u16 index, u16 size, void *data)
115 ret = __aqc111_write_cmd(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
116 USB_RECIP_DEVICE, value, index, size, data);
121 static int aqc111_write_cmd(struct usbnet *dev, u8 cmd, u16 value,
122 u16 index, u16 size, void *data)
126 if (usb_autopm_get_interface(dev->intf) < 0)
129 ret = __aqc111_write_cmd(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
130 USB_RECIP_DEVICE, value, index, size, data);
132 usb_autopm_put_interface(dev->intf);
137 static int aqc111_write16_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
138 u16 index, u16 *data)
144 return aqc111_write_cmd_nopm(dev, cmd, value, index, sizeof(tmp), &tmp);
147 static int aqc111_write16_cmd(struct usbnet *dev, u8 cmd, u16 value,
148 u16 index, u16 *data)
154 return aqc111_write_cmd(dev, cmd, value, index, sizeof(tmp), &tmp);
157 static int aqc111_write32_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value,
158 u16 index, u32 *data)
164 return aqc111_write_cmd_nopm(dev, cmd, value, index, sizeof(tmp), &tmp);
167 static int aqc111_write32_cmd(struct usbnet *dev, u8 cmd, u16 value,
168 u16 index, u32 *data)
174 return aqc111_write_cmd(dev, cmd, value, index, sizeof(tmp), &tmp);
177 static int aqc111_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
178 u16 index, u16 size, void *data)
180 return usbnet_write_cmd_async(dev, cmd, USB_DIR_OUT | USB_TYPE_VENDOR |
181 USB_RECIP_DEVICE, value, index, data,
185 static int aqc111_write16_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
186 u16 index, u16 *data)
192 return aqc111_write_cmd_async(dev, cmd, value, index,
196 static void aqc111_get_drvinfo(struct net_device *net,
197 struct ethtool_drvinfo *info)
199 struct usbnet *dev = netdev_priv(net);
200 struct aqc111_data *aqc111_data = dev->driver_priv;
202 /* Inherit standard device info */
203 usbnet_get_drvinfo(net, info);
204 strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
205 snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u",
206 aqc111_data->fw_ver.major,
207 aqc111_data->fw_ver.minor,
208 aqc111_data->fw_ver.rev);
209 info->eedump_len = 0x00;
210 info->regdump_len = 0x00;
213 static void aqc111_get_wol(struct net_device *net,
214 struct ethtool_wolinfo *wolinfo)
216 struct usbnet *dev = netdev_priv(net);
217 struct aqc111_data *aqc111_data = dev->driver_priv;
219 wolinfo->supported = WAKE_MAGIC;
220 wolinfo->wolopts = 0;
222 if (aqc111_data->wol_flags & AQ_WOL_FLAG_MP)
223 wolinfo->wolopts |= WAKE_MAGIC;
226 static int aqc111_set_wol(struct net_device *net,
227 struct ethtool_wolinfo *wolinfo)
229 struct usbnet *dev = netdev_priv(net);
230 struct aqc111_data *aqc111_data = dev->driver_priv;
232 if (wolinfo->wolopts & ~WAKE_MAGIC)
235 aqc111_data->wol_flags = 0;
236 if (wolinfo->wolopts & WAKE_MAGIC)
237 aqc111_data->wol_flags |= AQ_WOL_FLAG_MP;
242 static void aqc111_speed_to_link_mode(u32 speed,
243 struct ethtool_link_ksettings *elk)
247 ethtool_link_ksettings_add_link_mode(elk, advertising,
251 ethtool_link_ksettings_add_link_mode(elk, advertising,
255 ethtool_link_ksettings_add_link_mode(elk, advertising,
259 ethtool_link_ksettings_add_link_mode(elk, advertising,
265 static int aqc111_get_link_ksettings(struct net_device *net,
266 struct ethtool_link_ksettings *elk)
268 struct usbnet *dev = netdev_priv(net);
269 struct aqc111_data *aqc111_data = dev->driver_priv;
270 enum usb_device_speed usb_speed = dev->udev->speed;
271 u32 speed = SPEED_UNKNOWN;
273 ethtool_link_ksettings_zero_link_mode(elk, supported);
274 ethtool_link_ksettings_add_link_mode(elk, supported,
276 ethtool_link_ksettings_add_link_mode(elk, supported,
278 if (usb_speed == USB_SPEED_SUPER) {
279 ethtool_link_ksettings_add_link_mode(elk, supported,
281 ethtool_link_ksettings_add_link_mode(elk, supported,
284 ethtool_link_ksettings_add_link_mode(elk, supported, TP);
285 ethtool_link_ksettings_add_link_mode(elk, supported, Autoneg);
287 elk->base.port = PORT_TP;
288 elk->base.transceiver = XCVR_INTERNAL;
290 elk->base.mdio_support = 0x00; /*Not supported*/
292 if (aqc111_data->autoneg)
293 linkmode_copy(elk->link_modes.advertising,
294 elk->link_modes.supported);
296 aqc111_speed_to_link_mode(aqc111_data->advertised_speed, elk);
298 elk->base.autoneg = aqc111_data->autoneg;
300 switch (aqc111_data->link_speed) {
301 case AQ_INT_SPEED_5G:
304 case AQ_INT_SPEED_2_5G:
307 case AQ_INT_SPEED_1G:
310 case AQ_INT_SPEED_100M:
314 elk->base.duplex = DUPLEX_FULL;
315 elk->base.speed = speed;
320 static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed)
322 struct aqc111_data *aqc111_data = dev->driver_priv;
324 aqc111_data->phy_cfg &= ~AQ_ADV_MASK;
325 aqc111_data->phy_cfg |= AQ_PAUSE;
326 aqc111_data->phy_cfg |= AQ_ASYM_PAUSE;
327 aqc111_data->phy_cfg |= AQ_DOWNSHIFT;
328 aqc111_data->phy_cfg &= ~AQ_DSH_RETRIES_MASK;
329 aqc111_data->phy_cfg |= (3 << AQ_DSH_RETRIES_SHIFT) &
332 if (autoneg == AUTONEG_ENABLE) {
335 aqc111_data->phy_cfg |= AQ_ADV_5G;
338 aqc111_data->phy_cfg |= AQ_ADV_2G5;
341 aqc111_data->phy_cfg |= AQ_ADV_1G;
344 aqc111_data->phy_cfg |= AQ_ADV_100M;
350 aqc111_data->phy_cfg |= AQ_ADV_5G;
353 aqc111_data->phy_cfg |= AQ_ADV_2G5;
356 aqc111_data->phy_cfg |= AQ_ADV_1G;
359 aqc111_data->phy_cfg |= AQ_ADV_100M;
364 aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, &aqc111_data->phy_cfg);
367 static int aqc111_set_link_ksettings(struct net_device *net,
368 const struct ethtool_link_ksettings *elk)
370 struct usbnet *dev = netdev_priv(net);
371 struct aqc111_data *aqc111_data = dev->driver_priv;
372 enum usb_device_speed usb_speed = dev->udev->speed;
373 u8 autoneg = elk->base.autoneg;
374 u32 speed = elk->base.speed;
376 if (autoneg == AUTONEG_ENABLE) {
377 if (aqc111_data->autoneg != AUTONEG_ENABLE) {
378 aqc111_data->autoneg = AUTONEG_ENABLE;
379 aqc111_data->advertised_speed =
380 (usb_speed == USB_SPEED_SUPER) ?
381 SPEED_5000 : SPEED_1000;
382 aqc111_set_phy_speed(dev, aqc111_data->autoneg,
383 aqc111_data->advertised_speed);
386 if (speed != SPEED_100 &&
387 speed != SPEED_1000 &&
388 speed != SPEED_2500 &&
389 speed != SPEED_5000 &&
390 speed != SPEED_UNKNOWN)
393 if (elk->base.duplex != DUPLEX_FULL)
396 if (usb_speed != USB_SPEED_SUPER && speed > SPEED_1000)
399 aqc111_data->autoneg = AUTONEG_DISABLE;
400 if (speed != SPEED_UNKNOWN)
401 aqc111_data->advertised_speed = speed;
403 aqc111_set_phy_speed(dev, aqc111_data->autoneg,
404 aqc111_data->advertised_speed);
410 static const struct ethtool_ops aqc111_ethtool_ops = {
411 .get_drvinfo = aqc111_get_drvinfo,
412 .get_wol = aqc111_get_wol,
413 .set_wol = aqc111_set_wol,
414 .get_msglevel = usbnet_get_msglevel,
415 .set_msglevel = usbnet_set_msglevel,
416 .get_link = ethtool_op_get_link,
417 .get_link_ksettings = aqc111_get_link_ksettings,
418 .set_link_ksettings = aqc111_set_link_ksettings
421 static int aqc111_change_mtu(struct net_device *net, int new_mtu)
423 struct usbnet *dev = netdev_priv(net);
428 dev->hard_mtu = net->mtu + net->hard_header_len;
430 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
433 reg16 |= SFR_MEDIUM_JUMBO_EN;
435 reg16 &= ~SFR_MEDIUM_JUMBO_EN;
437 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
440 if (dev->net->mtu > 12500 && dev->net->mtu <= 16334) {
441 memcpy(buf, &AQC111_BULKIN_SIZE[2], 5);
442 /* RX bulk configuration */
443 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QCTRL,
447 /* Set high low water level */
448 if (dev->net->mtu <= 4500)
450 else if (dev->net->mtu <= 9500)
452 else if (dev->net->mtu <= 12500)
454 else if (dev->net->mtu <= 16334)
459 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_PAUSE_WATERLVL_LOW,
465 static int aqc111_set_mac_addr(struct net_device *net, void *p)
467 struct usbnet *dev = netdev_priv(net);
470 ret = eth_mac_addr(net, p);
474 /* Set the MAC address */
475 return aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN,
476 ETH_ALEN, net->dev_addr);
479 static int aqc111_vlan_rx_kill_vid(struct net_device *net,
480 __be16 proto, u16 vid)
482 struct usbnet *dev = netdev_priv(net);
487 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
492 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_ADDRESS, 1, 1, ®8);
494 reg8 = vlan_ctrl | SFR_VLAN_CONTROL_RD;
495 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
496 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, ®16);
497 reg16 &= ~(1 << (vid % 16));
498 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, ®16);
499 reg8 = vlan_ctrl | SFR_VLAN_CONTROL_WE;
500 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
505 static int aqc111_vlan_rx_add_vid(struct net_device *net, __be16 proto, u16 vid)
507 struct usbnet *dev = netdev_priv(net);
512 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
517 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_ADDRESS, 1, 1, ®8);
519 reg8 = vlan_ctrl | SFR_VLAN_CONTROL_RD;
520 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
521 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, ®16);
522 reg16 |= (1 << (vid % 16));
523 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_DATA0, 2, ®16);
524 reg8 = vlan_ctrl | SFR_VLAN_CONTROL_WE;
525 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL, 1, 1, ®8);
530 static void aqc111_set_rx_mode(struct net_device *net)
532 struct usbnet *dev = netdev_priv(net);
533 struct aqc111_data *aqc111_data = dev->driver_priv;
536 mc_count = netdev_mc_count(net);
538 aqc111_data->rxctl &= ~(SFR_RX_CTL_PRO | SFR_RX_CTL_AMALL |
541 if (net->flags & IFF_PROMISC) {
542 aqc111_data->rxctl |= SFR_RX_CTL_PRO;
543 } else if ((net->flags & IFF_ALLMULTI) || mc_count > AQ_MAX_MCAST) {
544 aqc111_data->rxctl |= SFR_RX_CTL_AMALL;
545 } else if (!netdev_mc_empty(net)) {
546 u8 m_filter[AQ_MCAST_FILTER_SIZE] = { 0 };
547 struct netdev_hw_addr *ha = NULL;
550 netdev_for_each_mc_addr(ha, net) {
551 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
552 m_filter[crc_bits >> 3] |= BIT(crc_bits & 7);
555 aqc111_write_cmd_async(dev, AQ_ACCESS_MAC,
556 SFR_MULTI_FILTER_ARRY,
557 AQ_MCAST_FILTER_SIZE,
558 AQ_MCAST_FILTER_SIZE, m_filter);
560 aqc111_data->rxctl |= SFR_RX_CTL_AM;
563 aqc111_write16_cmd_async(dev, AQ_ACCESS_MAC, SFR_RX_CTL,
564 2, &aqc111_data->rxctl);
567 static int aqc111_set_features(struct net_device *net,
568 netdev_features_t features)
570 struct usbnet *dev = netdev_priv(net);
571 struct aqc111_data *aqc111_data = dev->driver_priv;
572 netdev_features_t changed = net->features ^ features;
576 if (changed & NETIF_F_IP_CSUM) {
577 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL, 1, 1, ®8);
578 reg8 ^= SFR_TXCOE_TCP | SFR_TXCOE_UDP;
579 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL,
583 if (changed & NETIF_F_IPV6_CSUM) {
584 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL, 1, 1, ®8);
585 reg8 ^= SFR_TXCOE_TCPV6 | SFR_TXCOE_UDPV6;
586 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL,
590 if (changed & NETIF_F_RXCSUM) {
591 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_RXCOE_CTL, 1, 1, ®8);
592 if (features & NETIF_F_RXCSUM) {
593 aqc111_data->rx_checksum = 1;
594 reg8 &= ~(SFR_RXCOE_IP | SFR_RXCOE_TCP | SFR_RXCOE_UDP |
595 SFR_RXCOE_TCPV6 | SFR_RXCOE_UDPV6);
597 aqc111_data->rx_checksum = 0;
598 reg8 |= SFR_RXCOE_IP | SFR_RXCOE_TCP | SFR_RXCOE_UDP |
599 SFR_RXCOE_TCPV6 | SFR_RXCOE_UDPV6;
602 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RXCOE_CTL,
605 if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
606 if (features & NETIF_F_HW_VLAN_CTAG_FILTER) {
609 for (i = 0; i < 256; i++) {
612 aqc111_write_cmd(dev, AQ_ACCESS_MAC,
616 aqc111_write16_cmd(dev, AQ_ACCESS_MAC,
619 reg8 = SFR_VLAN_CONTROL_WE;
620 aqc111_write_cmd(dev, AQ_ACCESS_MAC,
624 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL,
626 reg8 |= SFR_VLAN_CONTROL_VFE;
627 aqc111_write_cmd(dev, AQ_ACCESS_MAC,
628 SFR_VLAN_ID_CONTROL, 1, 1, ®8);
630 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL,
632 reg8 &= ~SFR_VLAN_CONTROL_VFE;
633 aqc111_write_cmd(dev, AQ_ACCESS_MAC,
634 SFR_VLAN_ID_CONTROL, 1, 1, ®8);
641 static const struct net_device_ops aqc111_netdev_ops = {
642 .ndo_open = usbnet_open,
643 .ndo_stop = usbnet_stop,
644 .ndo_start_xmit = usbnet_start_xmit,
645 .ndo_tx_timeout = usbnet_tx_timeout,
646 .ndo_get_stats64 = usbnet_get_stats64,
647 .ndo_change_mtu = aqc111_change_mtu,
648 .ndo_set_mac_address = aqc111_set_mac_addr,
649 .ndo_validate_addr = eth_validate_addr,
650 .ndo_vlan_rx_add_vid = aqc111_vlan_rx_add_vid,
651 .ndo_vlan_rx_kill_vid = aqc111_vlan_rx_kill_vid,
652 .ndo_set_rx_mode = aqc111_set_rx_mode,
653 .ndo_set_features = aqc111_set_features,
656 static int aqc111_read_perm_mac(struct usbnet *dev)
661 ret = aqc111_read_cmd(dev, AQ_FLASH_PARAMETERS, 0, 0, ETH_ALEN, buf);
665 ether_addr_copy(dev->net->perm_addr, buf);
672 static void aqc111_read_fw_version(struct usbnet *dev,
673 struct aqc111_data *aqc111_data)
675 aqc111_read_cmd(dev, AQ_ACCESS_MAC, AQ_FW_VER_MAJOR,
676 1, 1, &aqc111_data->fw_ver.major);
677 aqc111_read_cmd(dev, AQ_ACCESS_MAC, AQ_FW_VER_MINOR,
678 1, 1, &aqc111_data->fw_ver.minor);
679 aqc111_read_cmd(dev, AQ_ACCESS_MAC, AQ_FW_VER_REV,
680 1, 1, &aqc111_data->fw_ver.rev);
682 if (aqc111_data->fw_ver.major & 0x80)
683 aqc111_data->fw_ver.major &= ~0x80;
686 static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf)
688 struct usb_device *udev = interface_to_usbdev(intf);
689 enum usb_device_speed usb_speed = udev->speed;
690 struct aqc111_data *aqc111_data;
693 /* Check if vendor configuration */
694 if (udev->actconfig->desc.bConfigurationValue != 1) {
695 usb_driver_set_configuration(udev, 1);
699 usb_reset_configuration(dev->udev);
701 ret = usbnet_get_endpoints(dev, intf);
703 netdev_dbg(dev->net, "usbnet_get_endpoints failed");
707 aqc111_data = kzalloc(sizeof(*aqc111_data), GFP_KERNEL);
711 /* store aqc111_data pointer in device data field */
712 dev->driver_priv = aqc111_data;
714 /* Init the MAC address */
715 ret = aqc111_read_perm_mac(dev);
719 ether_addr_copy(dev->net->dev_addr, dev->net->perm_addr);
721 /* Set Rx urb size */
722 dev->rx_urb_size = URB_SIZE;
724 /* Set TX needed headroom & tailroom */
725 dev->net->needed_headroom += sizeof(u64);
726 dev->net->needed_tailroom += sizeof(u64);
728 dev->net->max_mtu = 16334;
730 dev->net->netdev_ops = &aqc111_netdev_ops;
731 dev->net->ethtool_ops = &aqc111_ethtool_ops;
733 if (usb_device_no_sg_constraint(dev->udev))
736 dev->net->hw_features |= AQ_SUPPORT_HW_FEATURE;
737 dev->net->features |= AQ_SUPPORT_FEATURE;
738 dev->net->vlan_features |= AQ_SUPPORT_VLAN_FEATURE;
740 netif_set_gso_max_size(dev->net, 65535);
742 aqc111_read_fw_version(dev, aqc111_data);
743 aqc111_data->autoneg = AUTONEG_ENABLE;
744 aqc111_data->advertised_speed = (usb_speed == USB_SPEED_SUPER) ?
745 SPEED_5000 : SPEED_1000;
754 static void aqc111_unbind(struct usbnet *dev, struct usb_interface *intf)
756 struct aqc111_data *aqc111_data = dev->driver_priv;
760 reg16 = SFR_PHYPWR_RSTCTL_BZ;
761 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL,
764 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL,
767 /* Power down ethernet PHY */
768 aqc111_data->phy_cfg &= ~AQ_ADV_MASK;
769 aqc111_data->phy_cfg |= AQ_LOW_POWER;
770 aqc111_data->phy_cfg &= ~AQ_PHY_POWER_EN;
771 aqc111_write32_cmd_nopm(dev, AQ_PHY_OPS, 0, 0,
772 &aqc111_data->phy_cfg);
777 static void aqc111_status(struct usbnet *dev, struct urb *urb)
779 struct aqc111_data *aqc111_data = dev->driver_priv;
780 u64 *event_data = NULL;
783 if (urb->actual_length < sizeof(*event_data))
786 event_data = urb->transfer_buffer;
787 le64_to_cpus(event_data);
789 if (*event_data & AQ_LS_MASK)
794 aqc111_data->link_speed = (*event_data & AQ_SPEED_MASK) >>
796 aqc111_data->link = link;
798 if (netif_carrier_ok(dev->net) != link)
799 usbnet_defer_kevent(dev, EVENT_LINK_RESET);
802 static void aqc111_configure_rx(struct usbnet *dev,
803 struct aqc111_data *aqc111_data)
805 enum usb_device_speed usb_speed = dev->udev->speed;
806 u16 link_speed = 0, usb_host = 0;
815 switch (aqc111_data->link_speed) {
816 case AQ_INT_SPEED_5G:
821 case AQ_INT_SPEED_2_5G:
825 case AQ_INT_SPEED_1G:
829 case AQ_INT_SPEED_100M:
838 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_INTER_PACKET_GAP_0,
841 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_TX_PAUSE_RESEND_T, 3, 3, buf);
844 case USB_SPEED_SUPER:
860 if (dev->net->mtu > 12500 && dev->net->mtu <= 16334)
861 queue_num = 2; /* For Jumbo packet 16KB */
863 memcpy(buf, &AQC111_BULKIN_SIZE[queue_num], 5);
864 /* RX bulk configuration */
865 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QCTRL, 5, 5, buf);
867 /* Set high low water level */
868 if (dev->net->mtu <= 4500)
870 else if (dev->net->mtu <= 9500)
872 else if (dev->net->mtu <= 12500)
874 else if (dev->net->mtu <= 16334)
877 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_PAUSE_WATERLVL_LOW,
879 netdev_info(dev->net, "Link Speed %d, USB %d", link_speed, usb_host);
882 static void aqc111_configure_csum_offload(struct usbnet *dev)
886 if (dev->net->features & NETIF_F_RXCSUM) {
887 reg8 |= SFR_RXCOE_IP | SFR_RXCOE_TCP | SFR_RXCOE_UDP |
888 SFR_RXCOE_TCPV6 | SFR_RXCOE_UDPV6;
890 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RXCOE_CTL, 1, 1, ®8);
893 if (dev->net->features & NETIF_F_IP_CSUM)
894 reg8 |= SFR_TXCOE_IP | SFR_TXCOE_TCP | SFR_TXCOE_UDP;
896 if (dev->net->features & NETIF_F_IPV6_CSUM)
897 reg8 |= SFR_TXCOE_TCPV6 | SFR_TXCOE_UDPV6;
899 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL, 1, 1, ®8);
902 static int aqc111_link_reset(struct usbnet *dev)
904 struct aqc111_data *aqc111_data = dev->driver_priv;
908 if (aqc111_data->link == 1) { /* Link up */
909 aqc111_configure_rx(dev, aqc111_data);
911 /* Vlan Tag Filter */
912 reg8 = SFR_VLAN_CONTROL_VSO;
913 if (dev->net->features & NETIF_F_HW_VLAN_CTAG_FILTER)
914 reg8 |= SFR_VLAN_CONTROL_VFE;
916 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_VLAN_ID_CONTROL,
920 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BMRX_DMA_CONTROL,
923 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BMTX_DMA_CONTROL,
926 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_ARC_CTRL, 1, 1, ®8);
928 reg16 = SFR_RX_CTL_IPE | SFR_RX_CTL_AB;
929 aqc111_data->rxctl = reg16;
930 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
932 reg8 = SFR_RX_PATH_READY;
933 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH,
936 reg8 = SFR_BULK_OUT_EFF_EN;
937 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BULK_OUT_CTRL,
941 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
944 reg16 = SFR_MEDIUM_XGMIIMODE | SFR_MEDIUM_FULL_DUPLEX;
945 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
948 aqc111_configure_csum_offload(dev);
950 aqc111_set_rx_mode(dev->net);
952 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
955 if (dev->net->mtu > 1500)
956 reg16 |= SFR_MEDIUM_JUMBO_EN;
958 reg16 |= SFR_MEDIUM_RECEIVE_EN | SFR_MEDIUM_RXFLOW_CTRLEN |
959 SFR_MEDIUM_TXFLOW_CTRLEN;
960 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
963 aqc111_data->rxctl |= SFR_RX_CTL_START;
964 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_RX_CTL,
965 2, &aqc111_data->rxctl);
967 netif_carrier_on(dev->net);
969 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
971 reg16 &= ~SFR_MEDIUM_RECEIVE_EN;
972 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
975 aqc111_data->rxctl &= ~SFR_RX_CTL_START;
976 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_RX_CTL,
977 2, &aqc111_data->rxctl);
979 reg8 = SFR_BULK_OUT_FLUSH_EN | SFR_BULK_OUT_EFF_EN;
980 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BULK_OUT_CTRL,
982 reg8 = SFR_BULK_OUT_EFF_EN;
983 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BULK_OUT_CTRL,
986 netif_carrier_off(dev->net);
991 static int aqc111_reset(struct usbnet *dev)
993 struct aqc111_data *aqc111_data = dev->driver_priv;
996 dev->rx_urb_size = URB_SIZE;
998 if (usb_device_no_sg_constraint(dev->udev))
1001 dev->net->hw_features |= AQ_SUPPORT_HW_FEATURE;
1002 dev->net->features |= AQ_SUPPORT_FEATURE;
1003 dev->net->vlan_features |= AQ_SUPPORT_VLAN_FEATURE;
1005 /* Power up ethernet PHY */
1006 aqc111_data->phy_cfg = AQ_PHY_POWER_EN;
1007 aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0,
1008 &aqc111_data->phy_cfg);
1010 /* Set the MAC address */
1011 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN,
1012 ETH_ALEN, dev->net->dev_addr);
1015 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK, 1, 1, ®8);
1018 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_SWP_CTRL, 1, 1, ®8);
1020 aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_MONITOR_MODE, 1, 1, ®8);
1021 reg8 &= ~(SFR_MONITOR_MODE_EPHYRW | SFR_MONITOR_MODE_RWLC |
1022 SFR_MONITOR_MODE_RWMP | SFR_MONITOR_MODE_RWWF |
1023 SFR_MONITOR_MODE_RW_FLAG);
1024 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_MONITOR_MODE, 1, 1, ®8);
1026 netif_carrier_off(dev->net);
1029 aqc111_set_phy_speed(dev, aqc111_data->autoneg,
1030 aqc111_data->advertised_speed);
1035 static int aqc111_stop(struct usbnet *dev)
1037 struct aqc111_data *aqc111_data = dev->driver_priv;
1040 aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
1042 reg16 &= ~SFR_MEDIUM_RECEIVE_EN;
1043 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
1046 aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
1048 /* Put PHY to low power*/
1049 aqc111_data->phy_cfg |= AQ_LOW_POWER;
1050 aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0,
1051 &aqc111_data->phy_cfg);
1053 netif_carrier_off(dev->net);
1058 static void aqc111_rx_checksum(struct sk_buff *skb, u64 pkt_desc)
1062 skb->ip_summed = CHECKSUM_NONE;
1063 /* checksum error bit is set */
1064 if (pkt_desc & AQ_RX_PD_L4_ERR || pkt_desc & AQ_RX_PD_L3_ERR)
1067 pkt_type = pkt_desc & AQ_RX_PD_L4_TYPE_MASK;
1068 /* It must be a TCP or UDP packet with a valid checksum */
1069 if (pkt_type == AQ_RX_PD_L4_TCP || pkt_type == AQ_RX_PD_L4_UDP)
1070 skb->ip_summed = CHECKSUM_UNNECESSARY;
1073 static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1075 struct aqc111_data *aqc111_data = dev->driver_priv;
1076 struct sk_buff *new_skb = NULL;
1077 u32 pkt_total_offset = 0;
1078 u64 *pkt_desc_ptr = NULL;
1079 u32 start_of_descs = 0;
1080 u32 desc_offset = 0; /*RX Header Offset*/
1093 /* RX Descriptor Header */
1094 skb_trim(skb, skb->len - sizeof(desc_hdr));
1095 desc_hdr = le64_to_cpup((u64 *)skb_tail_pointer(skb));
1097 /* Check these packets */
1098 desc_offset = (desc_hdr & AQ_RX_DH_DESC_OFFSET_MASK) >>
1099 AQ_RX_DH_DESC_OFFSET_SHIFT;
1100 pkt_count = desc_hdr & AQ_RX_DH_PKT_CNT_MASK;
1101 start_of_descs = skb_len - ((pkt_count + 1) * sizeof(desc_hdr));
1103 /* self check descs position */
1104 if (start_of_descs != desc_offset)
1107 /* self check desc_offset from header*/
1108 if (desc_offset >= skb_len)
1114 /* Get the first RX packet descriptor */
1115 pkt_desc_ptr = (u64 *)(skb->data + desc_offset);
1117 while (pkt_count--) {
1118 u64 pkt_desc = le64_to_cpup(pkt_desc_ptr);
1119 u32 pkt_len_with_padd = 0;
1122 pkt_len = (u32)((pkt_desc & AQ_RX_PD_LEN_MASK) >>
1123 AQ_RX_PD_LEN_SHIFT);
1124 pkt_len_with_padd = ((pkt_len + 7) & 0x7FFF8);
1126 pkt_total_offset += pkt_len_with_padd;
1127 if (pkt_total_offset > desc_offset ||
1128 (pkt_count == 0 && pkt_total_offset != desc_offset)) {
1132 if (pkt_desc & AQ_RX_PD_DROP ||
1133 !(pkt_desc & AQ_RX_PD_RX_OK) ||
1134 pkt_len > (dev->hard_mtu + AQ_RX_HW_PAD)) {
1135 skb_pull(skb, pkt_len_with_padd);
1136 /* Next RX Packet Descriptor */
1142 new_skb = skb_clone(skb, GFP_ATOMIC);
1147 new_skb->len = pkt_len;
1148 skb_pull(new_skb, AQ_RX_HW_PAD);
1149 skb_set_tail_pointer(new_skb, new_skb->len);
1151 new_skb->truesize = SKB_TRUESIZE(new_skb->len);
1152 if (aqc111_data->rx_checksum)
1153 aqc111_rx_checksum(new_skb, pkt_desc);
1155 if (pkt_desc & AQ_RX_PD_VLAN) {
1156 vlan_tag = pkt_desc >> AQ_RX_PD_VLAN_SHIFT;
1157 __vlan_hwaccel_put_tag(new_skb, htons(ETH_P_8021Q),
1158 vlan_tag & VLAN_VID_MASK);
1161 usbnet_skb_return(dev, new_skb);
1165 skb_pull(skb, pkt_len_with_padd);
1167 /* Next RX Packet Header */
1179 static struct sk_buff *aqc111_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
1182 int frame_size = dev->maxpacket;
1183 struct sk_buff *new_skb = NULL;
1184 u64 *tx_desc_ptr = NULL;
1185 int padding_size = 0;
1191 /*Length of actual data*/
1192 tx_desc |= skb->len & AQ_TX_DESC_LEN_MASK;
1195 tx_desc |= ((u64)(skb_shinfo(skb)->gso_size & AQ_TX_DESC_MSS_MASK)) <<
1196 AQ_TX_DESC_MSS_SHIFT;
1198 headroom = (skb->len + sizeof(tx_desc)) % 8;
1200 padding_size = 8 - headroom;
1202 if (((skb->len + sizeof(tx_desc) + padding_size) % frame_size) == 0) {
1204 tx_desc |= AQ_TX_DESC_DROP_PADD;
1208 if (vlan_get_tag(skb, &tci) >= 0) {
1209 tx_desc |= AQ_TX_DESC_VLAN;
1210 tx_desc |= ((u64)tci & AQ_TX_DESC_VLAN_MASK) <<
1211 AQ_TX_DESC_VLAN_SHIFT;
1214 if (!dev->can_dma_sg && (dev->net->features & NETIF_F_SG) &&
1218 headroom = skb_headroom(skb);
1219 tailroom = skb_tailroom(skb);
1221 if (!(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) {
1222 new_skb = skb_copy_expand(skb, sizeof(tx_desc),
1223 padding_size, flags);
1224 dev_kfree_skb_any(skb);
1229 if (padding_size != 0)
1230 skb_put_zero(skb, padding_size);
1231 /* Copy TX header */
1232 tx_desc_ptr = skb_push(skb, sizeof(tx_desc));
1233 *tx_desc_ptr = cpu_to_le64(tx_desc);
1235 usbnet_set_skb_tx_stats(skb, 1, 0);
1240 static const struct driver_info aqc111_info = {
1241 .description = "Aquantia AQtion USB to 5GbE Controller",
1242 .bind = aqc111_bind,
1243 .unbind = aqc111_unbind,
1244 .status = aqc111_status,
1245 .link_reset = aqc111_link_reset,
1246 .reset = aqc111_reset,
1247 .stop = aqc111_stop,
1248 .flags = FLAG_ETHER | FLAG_FRAMING_AX |
1249 FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET,
1250 .rx_fixup = aqc111_rx_fixup,
1251 .tx_fixup = aqc111_tx_fixup,
1254 #define ASIX111_DESC \
1255 "ASIX USB 3.1 Gen1 to 5G Multi-Gigabit Ethernet Adapter"
1257 static const struct driver_info asix111_info = {
1258 .description = ASIX111_DESC,
1259 .bind = aqc111_bind,
1260 .unbind = aqc111_unbind,
1261 .status = aqc111_status,
1262 .link_reset = aqc111_link_reset,
1263 .reset = aqc111_reset,
1264 .stop = aqc111_stop,
1265 .flags = FLAG_ETHER | FLAG_FRAMING_AX |
1266 FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET,
1267 .rx_fixup = aqc111_rx_fixup,
1268 .tx_fixup = aqc111_tx_fixup,
1273 #define ASIX112_DESC \
1274 "ASIX USB 3.1 Gen1 to 2.5G Multi-Gigabit Ethernet Adapter"
1276 static const struct driver_info asix112_info = {
1277 .description = ASIX112_DESC,
1278 .bind = aqc111_bind,
1279 .unbind = aqc111_unbind,
1280 .status = aqc111_status,
1281 .link_reset = aqc111_link_reset,
1282 .reset = aqc111_reset,
1283 .stop = aqc111_stop,
1284 .flags = FLAG_ETHER | FLAG_FRAMING_AX |
1285 FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET,
1286 .rx_fixup = aqc111_rx_fixup,
1287 .tx_fixup = aqc111_tx_fixup,
1292 static const struct driver_info trendnet_info = {
1293 .description = "USB-C 3.1 to 5GBASE-T Ethernet Adapter",
1294 .bind = aqc111_bind,
1295 .unbind = aqc111_unbind,
1296 .status = aqc111_status,
1297 .link_reset = aqc111_link_reset,
1298 .reset = aqc111_reset,
1299 .stop = aqc111_stop,
1300 .flags = FLAG_ETHER | FLAG_FRAMING_AX |
1301 FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET,
1302 .rx_fixup = aqc111_rx_fixup,
1303 .tx_fixup = aqc111_tx_fixup,
1306 static const struct driver_info qnap_info = {
1307 .description = "QNAP QNA-UC5G1T USB to 5GbE Adapter",
1308 .bind = aqc111_bind,
1309 .unbind = aqc111_unbind,
1310 .status = aqc111_status,
1311 .link_reset = aqc111_link_reset,
1312 .reset = aqc111_reset,
1313 .stop = aqc111_stop,
1314 .flags = FLAG_ETHER | FLAG_FRAMING_AX |
1315 FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET,
1316 .rx_fixup = aqc111_rx_fixup,
1317 .tx_fixup = aqc111_tx_fixup,
1320 static int aqc111_suspend(struct usb_interface *intf, pm_message_t message)
1322 struct usbnet *dev = usb_get_intfdata(intf);
1323 struct aqc111_data *aqc111_data = dev->driver_priv;
1324 u16 temp_rx_ctrl = 0x00;
1328 usbnet_suspend(intf, message);
1330 aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
1331 temp_rx_ctrl = reg16;
1332 /* Stop RX operations*/
1333 reg16 &= ~SFR_RX_CTL_START;
1334 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
1336 aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL,
1338 reg16 |= SFR_PHYPWR_RSTCTL_BZ;
1339 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_PHYPWR_RSTCTL,
1342 reg8 = SFR_BULK_OUT_EFF_EN;
1343 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BULK_OUT_CTRL,
1346 temp_rx_ctrl &= ~(SFR_RX_CTL_START | SFR_RX_CTL_RF_WAK |
1347 SFR_RX_CTL_AP | SFR_RX_CTL_AM);
1348 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL,
1352 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH,
1355 if (aqc111_data->wol_flags) {
1356 struct aqc111_wol_cfg wol_cfg;
1358 memset(&wol_cfg, 0, sizeof(struct aqc111_wol_cfg));
1360 aqc111_data->phy_cfg |= AQ_WOL;
1361 ether_addr_copy(wol_cfg.hw_addr, dev->net->dev_addr);
1362 wol_cfg.flags = aqc111_data->wol_flags;
1364 temp_rx_ctrl |= (SFR_RX_CTL_AB | SFR_RX_CTL_START);
1365 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL,
1368 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK,
1370 reg8 = SFR_BMRX_DMA_EN;
1371 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BMRX_DMA_CONTROL,
1373 reg8 = SFR_RX_PATH_READY;
1374 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH,
1377 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QCTRL,
1380 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC,
1381 SFR_RX_BULKIN_QTIMR_LOW, 1, 1, ®8);
1382 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC,
1383 SFR_RX_BULKIN_QTIMR_HIGH, 1, 1, ®8);
1385 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QSIZE,
1387 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_BULKIN_QIFG,
1390 aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC,
1391 SFR_MEDIUM_STATUS_MODE, 2, ®16);
1392 reg16 |= SFR_MEDIUM_RECEIVE_EN;
1393 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC,
1394 SFR_MEDIUM_STATUS_MODE, 2, ®16);
1396 aqc111_write_cmd(dev, AQ_WOL_CFG, 0, 0,
1397 WOL_CFG_SIZE, &wol_cfg);
1398 aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0,
1399 &aqc111_data->phy_cfg);
1401 aqc111_data->phy_cfg |= AQ_LOW_POWER;
1402 aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0,
1403 &aqc111_data->phy_cfg);
1405 /* Disable RX path */
1406 aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC,
1407 SFR_MEDIUM_STATUS_MODE, 2, ®16);
1408 reg16 &= ~SFR_MEDIUM_RECEIVE_EN;
1409 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC,
1410 SFR_MEDIUM_STATUS_MODE, 2, ®16);
1416 static int aqc111_resume(struct usb_interface *intf)
1418 struct usbnet *dev = usb_get_intfdata(intf);
1419 struct aqc111_data *aqc111_data = dev->driver_priv;
1423 netif_carrier_off(dev->net);
1425 /* Power up ethernet PHY */
1426 aqc111_data->phy_cfg |= AQ_PHY_POWER_EN;
1427 aqc111_data->phy_cfg &= ~AQ_LOW_POWER;
1428 aqc111_data->phy_cfg &= ~AQ_WOL;
1431 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK,
1433 /* Configure RX control register => start operation */
1434 reg16 = aqc111_data->rxctl;
1435 reg16 &= ~SFR_RX_CTL_START;
1436 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
1438 reg16 |= SFR_RX_CTL_START;
1439 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_RX_CTL, 2, ®16);
1441 aqc111_set_phy_speed(dev, aqc111_data->autoneg,
1442 aqc111_data->advertised_speed);
1444 aqc111_read16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
1446 reg16 |= SFR_MEDIUM_RECEIVE_EN;
1447 aqc111_write16_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE,
1449 reg8 = SFR_RX_PATH_READY;
1450 aqc111_write_cmd_nopm(dev, AQ_ACCESS_MAC, SFR_ETH_MAC_PATH,
1453 aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BMRX_DMA_CONTROL, 1, 1, ®8);
1455 return usbnet_resume(intf);
1458 #define AQC111_USB_ETH_DEV(vid, pid, table) \
1459 USB_DEVICE_INTERFACE_CLASS((vid), (pid), USB_CLASS_VENDOR_SPEC), \
1460 .driver_info = (unsigned long)&(table) \
1463 USB_DEVICE_AND_INTERFACE_INFO((vid), (pid), \
1465 USB_CDC_SUBCLASS_ETHERNET, \
1466 USB_CDC_PROTO_NONE), \
1467 .driver_info = (unsigned long)&(table),
1469 static const struct usb_device_id products[] = {
1470 {AQC111_USB_ETH_DEV(0x2eca, 0xc101, aqc111_info)},
1471 {AQC111_USB_ETH_DEV(0x0b95, 0x2790, asix111_info)},
1472 {AQC111_USB_ETH_DEV(0x0b95, 0x2791, asix112_info)},
1473 {AQC111_USB_ETH_DEV(0x20f4, 0xe05a, trendnet_info)},
1474 {AQC111_USB_ETH_DEV(0x1c04, 0x0015, qnap_info)},
1477 MODULE_DEVICE_TABLE(usb, products);
1479 static struct usb_driver aq_driver = {
1481 .id_table = products,
1482 .probe = usbnet_probe,
1483 .suspend = aqc111_suspend,
1484 .resume = aqc111_resume,
1485 .disconnect = usbnet_disconnect,
1488 module_usb_driver(aq_driver);
1490 MODULE_DESCRIPTION("Aquantia AQtion USB to 5/2.5GbE Controllers");
1491 MODULE_LICENSE("GPL");