21 #include <linux/module.h>
24 #include <linux/netdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/mii.h>
31 #include <linux/slab.h>
34 #define SMSC_CHIPNAME "smsc75xx"
35 #define SMSC_DRIVER_VERSION "1.0.0"
36 #define HS_USB_PKT_SIZE (512)
37 #define FS_USB_PKT_SIZE (64)
38 #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
39 #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
40 #define DEFAULT_BULK_IN_DELAY (0x00002000)
41 #define MAX_SINGLE_PACKET_SIZE (9000)
42 #define LAN75XX_EEPROM_MAGIC (0x7500)
43 #define EEPROM_MAC_OFFSET (0x01)
44 #define DEFAULT_TX_CSUM_ENABLE (true)
45 #define DEFAULT_RX_CSUM_ENABLE (true)
46 #define DEFAULT_TSO_ENABLE (true)
47 #define SMSC75XX_INTERNAL_PHY_ID (1)
48 #define SMSC75XX_TX_OVERHEAD (8)
49 #define MAX_RX_FIFO_SIZE (20 * 1024)
50 #define MAX_TX_FIFO_SIZE (12 * 1024)
51 #define USB_VENDOR_ID_SMSC (0x0424)
52 #define USB_PRODUCT_ID_LAN7500 (0x7500)
53 #define USB_PRODUCT_ID_LAN7505 (0x7505)
55 #define SUPPORTED_WAKE (WAKE_MAGIC)
57 #define check_warn(ret, fmt, args...) \
58 ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
60 #define check_warn_return(ret, fmt, args...) \
61 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } })
63 #define check_warn_goto_done(ret, fmt, args...) \
64 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } })
81 static bool turbo_mode =
true;
99 00, index, buf, 4, USB_CTRL_GET_TIMEOUT);
102 netdev_warn(dev->
net,
103 "Failed to read reg index 0x%08x: %d", index, ret);
129 00, index, buf, 4, USB_CTRL_SET_TIMEOUT);
132 netdev_warn(dev->
net,
133 "Failed to write reg index 0x%08x: %d", index, ret);
149 USB_CTRL_SET_TIMEOUT);
152 static int smsc75xx_clear_feature(
struct usbnet *dev,
u32 feature)
161 USB_CTRL_SET_TIMEOUT);
166 static int smsc75xx_phy_wait_not_busy(
struct usbnet *dev)
173 ret = smsc75xx_read_reg(dev,
MII_ACCESS, &val);
185 struct usbnet *dev = netdev_priv(netdev);
192 ret = smsc75xx_phy_wait_not_busy(dev);
196 phy_id &= dev->
mii.phy_id_mask;
197 idx &= dev->
mii.reg_num_mask;
201 ret = smsc75xx_write_reg(dev,
MII_ACCESS, addr);
204 ret = smsc75xx_phy_wait_not_busy(dev);
207 ret = smsc75xx_read_reg(dev,
MII_DATA, &val);
210 ret = (
u16)(val & 0xFFFF);
217 static void smsc75xx_mdio_write(
struct net_device *netdev,
int phy_id,
int idx,
220 struct usbnet *dev = netdev_priv(netdev);
227 ret = smsc75xx_phy_wait_not_busy(dev);
231 ret = smsc75xx_write_reg(dev,
MII_DATA, val);
235 phy_id &= dev->
mii.phy_id_mask;
236 idx &= dev->
mii.reg_num_mask;
240 ret = smsc75xx_write_reg(dev,
MII_ACCESS, addr);
243 ret = smsc75xx_phy_wait_not_busy(dev);
250 static int smsc75xx_wait_eeprom(
struct usbnet *dev)
252 unsigned long start_time =
jiffies;
257 ret = smsc75xx_read_reg(dev,
E2P_CMD, &val);
266 netdev_warn(dev->
net,
"EEPROM read operation timeout");
273 static int smsc75xx_eeprom_confirm_not_busy(
struct usbnet *dev)
275 unsigned long start_time =
jiffies;
280 ret = smsc75xx_read_reg(dev,
E2P_CMD, &val);
283 if (!(val & E2P_CMD_BUSY))
289 netdev_warn(dev->
net,
"EEPROM is busy");
302 ret = smsc75xx_eeprom_confirm_not_busy(dev);
306 for (i = 0; i <
length; i++) {
308 ret = smsc75xx_write_reg(dev,
E2P_CMD, val);
311 ret = smsc75xx_wait_eeprom(dev);
315 ret = smsc75xx_read_reg(dev,
E2P_DATA, &val);
318 data[
i] = val & 0xFF;
325 static int smsc75xx_write_eeprom(
struct usbnet *dev,
u32 offset,
u32 length,
334 ret = smsc75xx_eeprom_confirm_not_busy(dev);
340 ret = smsc75xx_write_reg(dev,
E2P_CMD, val);
343 ret = smsc75xx_wait_eeprom(dev);
347 for (i = 0; i <
length; i++) {
351 ret = smsc75xx_write_reg(dev,
E2P_DATA, val);
356 ret = smsc75xx_write_reg(dev,
E2P_CMD, val);
359 ret = smsc75xx_wait_eeprom(dev);
369 static int smsc75xx_dataport_wait_not_busy(
struct usbnet *dev)
373 for (i = 0; i < 100; i++) {
375 ret = smsc75xx_read_reg(dev,
DP_SEL, &dp_sel);
384 netdev_warn(dev->
net,
"smsc75xx_dataport_wait_not_busy timed out");
389 static int smsc75xx_dataport_write(
struct usbnet *dev,
u32 ram_select,
u32 addr,
398 ret = smsc75xx_dataport_wait_not_busy(dev);
401 ret = smsc75xx_read_reg(dev,
DP_SEL, &dp_sel);
405 dp_sel |= ram_select;
406 ret = smsc75xx_write_reg(dev,
DP_SEL, dp_sel);
409 for (i = 0; i <
length; i++) {
410 ret = smsc75xx_write_reg(dev,
DP_ADDR, addr + i);
413 ret = smsc75xx_write_reg(dev,
DP_DATA, buf[i]);
419 ret = smsc75xx_dataport_wait_not_busy(dev);
431 return (
ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff;
441 netif_dbg(dev, drv, dev->
net,
"deferred multicast write 0x%08x",
451 static void smsc75xx_set_multicast(
struct net_device *netdev)
453 struct usbnet *dev = netdev_priv(netdev);
468 netif_dbg(dev, drv, dev->
net,
"promiscuous mode enabled");
471 netif_dbg(dev, drv, dev->
net,
"receive all multicast enabled");
476 netif_dbg(dev, drv, dev->
net,
"receive multicast hash filter");
481 u32 bitnum = smsc75xx_hash(ha->
addr);
483 (1 << (bitnum % 32));
486 netif_dbg(dev, drv, dev->
net,
"receive own packets only");
496 static int smsc75xx_update_flowcontrol(
struct usbnet *dev,
u8 duplex,
499 u32 flow = 0, fct_flow = 0;
503 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
508 fct_flow = (8 << 8) | 32;
515 (cap & FLOW_CTRL_RX ?
"enabled" :
"disabled"),
516 (cap & FLOW_CTRL_TX ?
"enabled" :
"disabled"));
521 ret = smsc75xx_write_reg(dev,
FLOW, flow);
524 ret = smsc75xx_write_reg(dev,
FCT_FLOW, fct_flow);
530 static int smsc75xx_link_reset(
struct usbnet *dev)
550 " rmtadv: %04x", ethtool_cmd_speed(&ecmd),
551 ecmd.
duplex, lcladv, rmtadv);
553 return smsc75xx_update_flowcontrol(dev, ecmd.
duplex, lcladv, rmtadv);
556 static void smsc75xx_status(
struct usbnet *dev,
struct urb *
urb)
560 if (urb->actual_length != 4) {
561 netdev_warn(dev->
net,
562 "unexpected urb length %d", urb->actual_length);
566 memcpy(&intdata, urb->transfer_buffer, 4);
574 netdev_warn(dev->
net,
575 "unexpected interrupt, intdata=0x%08X", intdata);
578 static int smsc75xx_ethtool_get_eeprom_len(
struct net_device *
net)
583 static int smsc75xx_ethtool_get_eeprom(
struct net_device *netdev,
586 struct usbnet *dev = netdev_priv(netdev);
590 return smsc75xx_read_eeprom(dev, ee->
offset, ee->
len, data);
593 static int smsc75xx_ethtool_set_eeprom(
struct net_device *netdev,
596 struct usbnet *dev = netdev_priv(netdev);
599 netdev_warn(dev->
net,
600 "EEPROM: magic value mismatch: 0x%x", ee->
magic);
604 return smsc75xx_write_eeprom(dev, ee->
offset, ee->
len, data);
610 struct usbnet *dev = netdev_priv(net);
617 static int smsc75xx_ethtool_set_wol(
struct net_device *net,
620 struct usbnet *dev = netdev_priv(net);
627 static const struct ethtool_ops smsc75xx_ethtool_ops = {
635 .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len,
636 .get_eeprom = smsc75xx_ethtool_get_eeprom,
637 .set_eeprom = smsc75xx_ethtool_set_eeprom,
638 .get_wol = smsc75xx_ethtool_get_wol,
639 .set_wol = smsc75xx_ethtool_set_wol,
644 struct usbnet *dev = netdev_priv(netdev);
646 if (!netif_running(netdev))
652 static void smsc75xx_init_mac_address(
struct usbnet *dev)
656 dev->
net->dev_addr) == 0) {
657 if (is_valid_ether_addr(dev->
net->dev_addr)) {
660 "MAC address read from EEPROM");
666 eth_hw_addr_random(dev->
net);
667 netif_dbg(dev, ifup, dev->
net,
"MAC address set to eth_random_addr");
670 static int smsc75xx_set_mac_address(
struct usbnet *dev)
672 u32 addr_lo = dev->
net->dev_addr[0] | dev->
net->dev_addr[1] << 8 |
673 dev->
net->dev_addr[2] << 16 | dev->
net->dev_addr[3] << 24;
674 u32 addr_hi = dev->
net->dev_addr[4] | dev->
net->dev_addr[5] << 8;
676 int ret = smsc75xx_write_reg(dev,
RX_ADDRH, addr_hi);
679 ret = smsc75xx_write_reg(dev,
RX_ADDRL, addr_lo);
683 ret = smsc75xx_write_reg(dev,
ADDR_FILTX, addr_hi);
686 ret = smsc75xx_write_reg(dev,
ADDR_FILTX + 4, addr_lo);
692 static int smsc75xx_phy_initialize(
struct usbnet *dev)
698 dev->
mii.mdio_read = smsc75xx_mdio_read;
699 dev->
mii.mdio_write = smsc75xx_mdio_write;
700 dev->
mii.phy_id_mask = 0x1f;
701 dev->
mii.reg_num_mask = 0x1f;
702 dev->
mii.supports_gmii = 1;
713 }
while ((bmcr &
BMCR_RESET) && (timeout < 100));
715 if (timeout >= 100) {
716 netdev_warn(dev->
net,
"timeout on PHY Reset");
735 netif_dbg(dev, ifup, dev->
net,
"phy initialised successfully");
739 static int smsc75xx_set_rx_max_frame_length(
struct usbnet *dev,
int size)
745 ret = smsc75xx_read_reg(dev,
MAC_RX, &buf);
752 ret = smsc75xx_write_reg(dev,
MAC_RX, buf);
760 ret = smsc75xx_write_reg(dev,
MAC_RX, buf);
765 ret = smsc75xx_write_reg(dev,
MAC_RX, buf);
772 static int smsc75xx_change_mtu(
struct net_device *netdev,
int new_mtu)
774 struct usbnet *dev = netdev_priv(netdev);
776 int ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu);
783 static int smsc75xx_set_features(
struct net_device *netdev,
786 struct usbnet *dev = netdev_priv(netdev);
807 static int smsc75xx_wait_ready(
struct usbnet *dev)
813 int ret = smsc75xx_read_reg(dev,
PMT_CTL, &buf);
821 }
while (timeout < 100);
823 netdev_warn(dev->
net,
"timeout waiting for device ready");
827 static int smsc75xx_reset(
struct usbnet *dev)
831 int ret = 0, timeout;
833 netif_dbg(dev, ifup, dev->
net,
"entering smsc75xx_reset");
835 ret = smsc75xx_wait_ready(dev);
838 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
843 ret = smsc75xx_write_reg(dev,
HW_CFG, buf);
849 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
854 if (timeout >= 100) {
855 netdev_warn(dev->
net,
"timeout on completion of Lite Reset");
859 netif_dbg(dev, ifup, dev->
net,
"Lite reset complete, resetting PHY");
861 ret = smsc75xx_read_reg(dev,
PMT_CTL, &buf);
866 ret = smsc75xx_write_reg(dev,
PMT_CTL, buf);
872 ret = smsc75xx_read_reg(dev,
PMT_CTL, &buf);
877 if (timeout >= 100) {
878 netdev_warn(dev->
net,
"timeout waiting for PHY Reset");
884 smsc75xx_init_mac_address(dev);
886 ret = smsc75xx_set_mac_address(dev);
889 netif_dbg(dev, ifup, dev->
net,
"MAC Address: %pM", dev->
net->dev_addr);
891 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
894 netif_dbg(dev, ifup, dev->
net,
"Read Value from HW_CFG : 0x%08x", buf);
898 ret = smsc75xx_write_reg(dev,
HW_CFG, buf);
901 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
904 netif_dbg(dev, ifup, dev->
net,
"Read Value from HW_CFG after "
905 "writing HW_CFG_BIR: 0x%08x", buf);
921 ret = smsc75xx_write_reg(dev,
BURST_CAP, buf);
924 ret = smsc75xx_read_reg(dev,
BURST_CAP, &buf);
928 "Read Value from BURST_CAP after writing: 0x%08x", buf);
937 "Read Value from BULK_IN_DLY after writing: 0x%08x", buf);
940 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
947 ret = smsc75xx_write_reg(dev,
HW_CFG, buf);
950 ret = smsc75xx_read_reg(dev,
HW_CFG, &buf);
961 netif_dbg(dev, ifup, dev->
net,
"FCT_RX_FIFO_END set to 0x%08x", buf);
967 netif_dbg(dev, ifup, dev->
net,
"FCT_TX_FIFO_END set to 0x%08x", buf);
972 ret = smsc75xx_read_reg(dev,
ID_REV, &buf);
977 ret = smsc75xx_read_reg(dev,
E2P_CMD, &buf);
992 ret = smsc75xx_write_reg(dev,
FLOW, 0);
995 ret = smsc75xx_write_reg(dev,
FCT_FLOW, 0);
1013 smsc75xx_set_features(dev->
net, dev->
net->features);
1015 smsc75xx_set_multicast(dev->
net);
1017 ret = smsc75xx_phy_initialize(dev);
1020 ret = smsc75xx_read_reg(dev,
INT_EP_CTL, &buf);
1026 ret = smsc75xx_write_reg(dev,
INT_EP_CTL, buf);
1030 ret = smsc75xx_read_reg(dev,
MAC_CR, &buf);
1034 ret = smsc75xx_write_reg(dev,
MAC_CR, buf);
1037 ret = smsc75xx_read_reg(dev,
MAC_TX, &buf);
1042 ret = smsc75xx_write_reg(dev,
MAC_TX, buf);
1045 netif_dbg(dev, ifup, dev->
net,
"MAC_TX set to 0x%08x", buf);
1047 ret = smsc75xx_read_reg(dev,
FCT_TX_CTL, &buf);
1052 ret = smsc75xx_write_reg(dev,
FCT_TX_CTL, buf);
1055 netif_dbg(dev, ifup, dev->
net,
"FCT_TX_CTL set to 0x%08x", buf);
1057 ret = smsc75xx_set_rx_max_frame_length(dev, 1514);
1060 ret = smsc75xx_read_reg(dev,
MAC_RX, &buf);
1065 ret = smsc75xx_write_reg(dev,
MAC_RX, buf);
1068 netif_dbg(dev, ifup, dev->
net,
"MAC_RX set to 0x%08x", buf);
1070 ret = smsc75xx_read_reg(dev,
FCT_RX_CTL, &buf);
1075 ret = smsc75xx_write_reg(dev,
FCT_RX_CTL, buf);
1078 netif_dbg(dev, ifup, dev->
net,
"FCT_RX_CTL set to 0x%08x", buf);
1080 netif_dbg(dev, ifup, dev->
net,
"smsc75xx_reset, return 0");
1089 .ndo_change_mtu = smsc75xx_change_mtu,
1092 .ndo_do_ioctl = smsc75xx_ioctl,
1093 .ndo_set_rx_mode = smsc75xx_set_multicast,
1094 .ndo_set_features = smsc75xx_set_features,
1112 netdev_warn(dev->
net,
"Unable to allocate smsc75xx_priv");
1136 ret = smsc75xx_reset(dev);
1138 dev->
net->netdev_ops = &smsc75xx_netdev_ops;
1139 dev->
net->ethtool_ops = &smsc75xx_ethtool_ops;
1159 struct usbnet *dev = usb_get_intfdata(intf);
1169 netdev_info(dev->
net,
"entering SUSPEND2 mode");
1172 ret = smsc75xx_read_reg(dev,
WUCSR, &val);
1177 ret = smsc75xx_write_reg(dev,
WUCSR, val);
1180 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1185 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1189 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1195 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1203 ret = smsc75xx_read_reg(dev,
WUCSR, &val);
1208 ret = smsc75xx_write_reg(dev,
WUCSR, val);
1213 ret = smsc75xx_read_reg(dev,
WUCSR, &val);
1217 netdev_info(dev->
net,
"enabling magic packet wakeup");
1220 netdev_info(dev->
net,
"disabling magic packet wakeup");
1224 ret = smsc75xx_write_reg(dev,
WUCSR, val);
1228 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1233 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1237 ret = smsc75xx_read_reg(dev,
MAC_RX, &val);
1242 ret = smsc75xx_write_reg(dev,
MAC_RX, val);
1246 netdev_info(dev->
net,
"entering SUSPEND0 mode");
1248 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1254 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1260 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1264 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1274 struct usbnet *dev = usb_get_intfdata(intf);
1280 netdev_info(dev->
net,
"resuming from SUSPEND0");
1285 ret = smsc75xx_read_reg(dev,
WUCSR, &val);
1290 ret = smsc75xx_write_reg(dev,
WUCSR, val);
1294 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1300 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1303 netdev_info(dev->
net,
"resuming from SUSPEND2");
1305 ret = smsc75xx_read_reg(dev,
PMT_CTL, &val);
1310 ret = smsc75xx_write_reg(dev,
PMT_CTL, val);
1314 ret = smsc75xx_wait_ready(dev);
1320 static void smsc75xx_rx_csum_offload(
struct usbnet *dev,
struct sk_buff *
skb,
1321 u32 rx_cmd_a,
u32 rx_cmd_b)
1332 static int smsc75xx_rx_fixup(
struct usbnet *dev,
struct sk_buff *skb)
1334 while (skb->
len > 0) {
1335 u32 rx_cmd_a, rx_cmd_b, align_count,
size;
1339 memcpy(&rx_cmd_a, skb->
data,
sizeof(rx_cmd_a));
1343 memcpy(&rx_cmd_b, skb->
data,
sizeof(rx_cmd_b));
1351 align_count = (4 - ((size +
RXW_PADDING) % 4)) % 4;
1355 "Error rx_cmd_a=0x%08x", rx_cmd_a);
1356 dev->
net->stats.rx_errors++;
1357 dev->
net->stats.rx_dropped++;
1360 dev->
net->stats.rx_crc_errors++;
1362 dev->
net->stats.rx_frame_errors++;
1367 "size err rx_cmd_a=0x%08x", rx_cmd_a);
1372 if (skb->
len == size) {
1373 smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a,
1384 netdev_warn(dev->
net,
"Error allocating skb");
1389 ax_skb->
data = packet;
1390 skb_set_tail_pointer(ax_skb, size);
1392 smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a,
1409 netdev_warn(dev->
net,
"invalid rx length<0 %d", skb->
len);
1416 static struct sk_buff *smsc75xx_tx_fixup(
struct usbnet *dev,
1419 u32 tx_cmd_a, tx_cmd_b;
1437 if (skb_is_gso(skb)) {
1458 .description =
"smsc75xx USB 2.0 Gigabit Ethernet",
1459 .bind = smsc75xx_bind,
1460 .unbind = smsc75xx_unbind,
1461 .link_reset = smsc75xx_link_reset,
1462 .reset = smsc75xx_reset,
1463 .rx_fixup = smsc75xx_rx_fixup,
1464 .tx_fixup = smsc75xx_tx_fixup,
1465 .status = smsc75xx_status,
1473 .driver_info = (
unsigned long) &smsc75xx_info,
1478 .driver_info = (
unsigned long) &smsc75xx_info,
1484 static struct usb_driver smsc75xx_driver = {
1486 .id_table = products,
1488 .suspend = smsc75xx_suspend,
1489 .resume = smsc75xx_resume,
1490 .reset_resume = smsc75xx_resume,
1492 .disable_hub_initiated_lpm = 1,