1 /***************************************************************************
3 * Copyright (C) 2007-2010 SMSC
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *****************************************************************************/
20 #include <linux/module.h>
21 #include <linux/kmod.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/ethtool.h>
25 #include <linux/mii.h>
26 #include <linux/usb.h>
27 #include <linux/bitrev.h>
28 #include <linux/crc16.h>
29 #include <linux/crc32.h>
30 #include <linux/usb/usbnet.h>
31 #include <linux/slab.h>
32 #include <linux/of_net.h>
35 #define SMSC_CHIPNAME "smsc75xx"
36 #define SMSC_DRIVER_VERSION "1.0.0"
37 #define HS_USB_PKT_SIZE (512)
38 #define FS_USB_PKT_SIZE (64)
39 #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
40 #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
41 #define DEFAULT_BULK_IN_DELAY (0x00002000)
42 #define MAX_SINGLE_PACKET_SIZE (9000)
43 #define LAN75XX_EEPROM_MAGIC (0x7500)
44 #define EEPROM_MAC_OFFSET (0x01)
45 #define DEFAULT_TX_CSUM_ENABLE (true)
46 #define DEFAULT_RX_CSUM_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_PHY | WAKE_UCAST | WAKE_BCAST | \
56 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
58 #define SUSPEND_SUSPEND0 (0x01)
59 #define SUSPEND_SUSPEND1 (0x02)
60 #define SUSPEND_SUSPEND2 (0x04)
61 #define SUSPEND_SUSPEND3 (0x08)
62 #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
63 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
65 struct smsc75xx_priv
{
69 u32 multicast_hash_table
[DP_SEL_VHF_HASH_LEN
];
70 struct mutex dataport_mutex
;
71 spinlock_t rfe_ctl_lock
;
72 struct work_struct set_multicast
;
77 struct usb_ctrlrequest req
;
81 static bool turbo_mode
= true;
82 module_param(turbo_mode
, bool, 0644);
83 MODULE_PARM_DESC(turbo_mode
, "Enable multiple frames per Rx transaction");
85 static int smsc75xx_link_ok_nopm(struct usbnet
*dev
);
86 static int smsc75xx_phy_gig_workaround(struct usbnet
*dev
);
88 static int __must_check
__smsc75xx_read_reg(struct usbnet
*dev
, u32 index
,
93 int (*fn
)(struct usbnet
*, u8
, u8
, u16
, u16
, void *, u16
);
100 fn
= usbnet_read_cmd_nopm
;
102 ret
= fn(dev
, USB_VENDOR_REQUEST_READ_REGISTER
, USB_DIR_IN
103 | USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
105 if (unlikely(ret
< 0)) {
106 netdev_warn(dev
->net
, "Failed to read reg index 0x%08x: %d\n",
117 static int __must_check
__smsc75xx_write_reg(struct usbnet
*dev
, u32 index
,
122 int (*fn
)(struct usbnet
*, u8
, u8
, u16
, u16
, const void *, u16
);
127 fn
= usbnet_write_cmd
;
129 fn
= usbnet_write_cmd_nopm
;
134 ret
= fn(dev
, USB_VENDOR_REQUEST_WRITE_REGISTER
, USB_DIR_OUT
135 | USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
137 if (unlikely(ret
< 0))
138 netdev_warn(dev
->net
, "Failed to write reg index 0x%08x: %d\n",
144 static int __must_check
smsc75xx_read_reg_nopm(struct usbnet
*dev
, u32 index
,
147 return __smsc75xx_read_reg(dev
, index
, data
, 1);
150 static int __must_check
smsc75xx_write_reg_nopm(struct usbnet
*dev
, u32 index
,
153 return __smsc75xx_write_reg(dev
, index
, data
, 1);
156 static int __must_check
smsc75xx_read_reg(struct usbnet
*dev
, u32 index
,
159 return __smsc75xx_read_reg(dev
, index
, data
, 0);
162 static int __must_check
smsc75xx_write_reg(struct usbnet
*dev
, u32 index
,
165 return __smsc75xx_write_reg(dev
, index
, data
, 0);
168 /* Loop until the read is completed with timeout
169 * called with phy_mutex held */
170 static __must_check
int __smsc75xx_phy_wait_not_busy(struct usbnet
*dev
,
173 unsigned long start_time
= jiffies
;
178 ret
= __smsc75xx_read_reg(dev
, MII_ACCESS
, &val
, in_pm
);
180 netdev_warn(dev
->net
, "Error reading MII_ACCESS\n");
184 if (!(val
& MII_ACCESS_BUSY
))
186 } while (!time_after(jiffies
, start_time
+ HZ
));
191 static int __smsc75xx_mdio_read(struct net_device
*netdev
, int phy_id
, int idx
,
194 struct usbnet
*dev
= netdev_priv(netdev
);
198 mutex_lock(&dev
->phy_mutex
);
200 /* confirm MII not busy */
201 ret
= __smsc75xx_phy_wait_not_busy(dev
, in_pm
);
203 netdev_warn(dev
->net
, "MII is busy in smsc75xx_mdio_read\n");
207 /* set the address, index & direction (read from PHY) */
208 phy_id
&= dev
->mii
.phy_id_mask
;
209 idx
&= dev
->mii
.reg_num_mask
;
210 addr
= ((phy_id
<< MII_ACCESS_PHY_ADDR_SHIFT
) & MII_ACCESS_PHY_ADDR
)
211 | ((idx
<< MII_ACCESS_REG_ADDR_SHIFT
) & MII_ACCESS_REG_ADDR
)
212 | MII_ACCESS_READ
| MII_ACCESS_BUSY
;
213 ret
= __smsc75xx_write_reg(dev
, MII_ACCESS
, addr
, in_pm
);
215 netdev_warn(dev
->net
, "Error writing MII_ACCESS\n");
219 ret
= __smsc75xx_phy_wait_not_busy(dev
, in_pm
);
221 netdev_warn(dev
->net
, "Timed out reading MII reg %02X\n", idx
);
225 ret
= __smsc75xx_read_reg(dev
, MII_DATA
, &val
, in_pm
);
227 netdev_warn(dev
->net
, "Error reading MII_DATA\n");
231 ret
= (u16
)(val
& 0xFFFF);
234 mutex_unlock(&dev
->phy_mutex
);
238 static void __smsc75xx_mdio_write(struct net_device
*netdev
, int phy_id
,
239 int idx
, int regval
, int in_pm
)
241 struct usbnet
*dev
= netdev_priv(netdev
);
245 mutex_lock(&dev
->phy_mutex
);
247 /* confirm MII not busy */
248 ret
= __smsc75xx_phy_wait_not_busy(dev
, in_pm
);
250 netdev_warn(dev
->net
, "MII is busy in smsc75xx_mdio_write\n");
255 ret
= __smsc75xx_write_reg(dev
, MII_DATA
, val
, in_pm
);
257 netdev_warn(dev
->net
, "Error writing MII_DATA\n");
261 /* set the address, index & direction (write to PHY) */
262 phy_id
&= dev
->mii
.phy_id_mask
;
263 idx
&= dev
->mii
.reg_num_mask
;
264 addr
= ((phy_id
<< MII_ACCESS_PHY_ADDR_SHIFT
) & MII_ACCESS_PHY_ADDR
)
265 | ((idx
<< MII_ACCESS_REG_ADDR_SHIFT
) & MII_ACCESS_REG_ADDR
)
266 | MII_ACCESS_WRITE
| MII_ACCESS_BUSY
;
267 ret
= __smsc75xx_write_reg(dev
, MII_ACCESS
, addr
, in_pm
);
269 netdev_warn(dev
->net
, "Error writing MII_ACCESS\n");
273 ret
= __smsc75xx_phy_wait_not_busy(dev
, in_pm
);
275 netdev_warn(dev
->net
, "Timed out writing MII reg %02X\n", idx
);
280 mutex_unlock(&dev
->phy_mutex
);
283 static int smsc75xx_mdio_read_nopm(struct net_device
*netdev
, int phy_id
,
286 return __smsc75xx_mdio_read(netdev
, phy_id
, idx
, 1);
289 static void smsc75xx_mdio_write_nopm(struct net_device
*netdev
, int phy_id
,
292 __smsc75xx_mdio_write(netdev
, phy_id
, idx
, regval
, 1);
295 static int smsc75xx_mdio_read(struct net_device
*netdev
, int phy_id
, int idx
)
297 return __smsc75xx_mdio_read(netdev
, phy_id
, idx
, 0);
300 static void smsc75xx_mdio_write(struct net_device
*netdev
, int phy_id
, int idx
,
303 __smsc75xx_mdio_write(netdev
, phy_id
, idx
, regval
, 0);
306 static int smsc75xx_wait_eeprom(struct usbnet
*dev
)
308 unsigned long start_time
= jiffies
;
313 ret
= smsc75xx_read_reg(dev
, E2P_CMD
, &val
);
315 netdev_warn(dev
->net
, "Error reading E2P_CMD\n");
319 if (!(val
& E2P_CMD_BUSY
) || (val
& E2P_CMD_TIMEOUT
))
322 } while (!time_after(jiffies
, start_time
+ HZ
));
324 if (val
& (E2P_CMD_TIMEOUT
| E2P_CMD_BUSY
)) {
325 netdev_warn(dev
->net
, "EEPROM read operation timeout\n");
332 static int smsc75xx_eeprom_confirm_not_busy(struct usbnet
*dev
)
334 unsigned long start_time
= jiffies
;
339 ret
= smsc75xx_read_reg(dev
, E2P_CMD
, &val
);
341 netdev_warn(dev
->net
, "Error reading E2P_CMD\n");
345 if (!(val
& E2P_CMD_BUSY
))
349 } while (!time_after(jiffies
, start_time
+ HZ
));
351 netdev_warn(dev
->net
, "EEPROM is busy\n");
355 static int smsc75xx_read_eeprom(struct usbnet
*dev
, u32 offset
, u32 length
,
364 ret
= smsc75xx_eeprom_confirm_not_busy(dev
);
368 for (i
= 0; i
< length
; i
++) {
369 val
= E2P_CMD_BUSY
| E2P_CMD_READ
| (offset
& E2P_CMD_ADDR
);
370 ret
= smsc75xx_write_reg(dev
, E2P_CMD
, val
);
372 netdev_warn(dev
->net
, "Error writing E2P_CMD\n");
376 ret
= smsc75xx_wait_eeprom(dev
);
380 ret
= smsc75xx_read_reg(dev
, E2P_DATA
, &val
);
382 netdev_warn(dev
->net
, "Error reading E2P_DATA\n");
386 data
[i
] = val
& 0xFF;
393 static int smsc75xx_write_eeprom(struct usbnet
*dev
, u32 offset
, u32 length
,
402 ret
= smsc75xx_eeprom_confirm_not_busy(dev
);
406 /* Issue write/erase enable command */
407 val
= E2P_CMD_BUSY
| E2P_CMD_EWEN
;
408 ret
= smsc75xx_write_reg(dev
, E2P_CMD
, val
);
410 netdev_warn(dev
->net
, "Error writing E2P_CMD\n");
414 ret
= smsc75xx_wait_eeprom(dev
);
418 for (i
= 0; i
< length
; i
++) {
420 /* Fill data register */
422 ret
= smsc75xx_write_reg(dev
, E2P_DATA
, val
);
424 netdev_warn(dev
->net
, "Error writing E2P_DATA\n");
428 /* Send "write" command */
429 val
= E2P_CMD_BUSY
| E2P_CMD_WRITE
| (offset
& E2P_CMD_ADDR
);
430 ret
= smsc75xx_write_reg(dev
, E2P_CMD
, val
);
432 netdev_warn(dev
->net
, "Error writing E2P_CMD\n");
436 ret
= smsc75xx_wait_eeprom(dev
);
446 static int smsc75xx_dataport_wait_not_busy(struct usbnet
*dev
)
450 for (i
= 0; i
< 100; i
++) {
452 ret
= smsc75xx_read_reg(dev
, DP_SEL
, &dp_sel
);
454 netdev_warn(dev
->net
, "Error reading DP_SEL\n");
458 if (dp_sel
& DP_SEL_DPRDY
)
464 netdev_warn(dev
->net
, "smsc75xx_dataport_wait_not_busy timed out\n");
469 static int smsc75xx_dataport_write(struct usbnet
*dev
, u32 ram_select
, u32 addr
,
470 u32 length
, u32
*buf
)
472 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
476 mutex_lock(&pdata
->dataport_mutex
);
478 ret
= smsc75xx_dataport_wait_not_busy(dev
);
480 netdev_warn(dev
->net
, "smsc75xx_dataport_write busy on entry\n");
484 ret
= smsc75xx_read_reg(dev
, DP_SEL
, &dp_sel
);
486 netdev_warn(dev
->net
, "Error reading DP_SEL\n");
490 dp_sel
&= ~DP_SEL_RSEL
;
491 dp_sel
|= ram_select
;
492 ret
= smsc75xx_write_reg(dev
, DP_SEL
, dp_sel
);
494 netdev_warn(dev
->net
, "Error writing DP_SEL\n");
498 for (i
= 0; i
< length
; i
++) {
499 ret
= smsc75xx_write_reg(dev
, DP_ADDR
, addr
+ i
);
501 netdev_warn(dev
->net
, "Error writing DP_ADDR\n");
505 ret
= smsc75xx_write_reg(dev
, DP_DATA
, buf
[i
]);
507 netdev_warn(dev
->net
, "Error writing DP_DATA\n");
511 ret
= smsc75xx_write_reg(dev
, DP_CMD
, DP_CMD_WRITE
);
513 netdev_warn(dev
->net
, "Error writing DP_CMD\n");
517 ret
= smsc75xx_dataport_wait_not_busy(dev
);
519 netdev_warn(dev
->net
, "smsc75xx_dataport_write timeout\n");
525 mutex_unlock(&pdata
->dataport_mutex
);
529 /* returns hash bit number for given MAC address */
530 static u32
smsc75xx_hash(char addr
[ETH_ALEN
])
532 return (ether_crc(ETH_ALEN
, addr
) >> 23) & 0x1ff;
535 static void smsc75xx_deferred_multicast_write(struct work_struct
*param
)
537 struct smsc75xx_priv
*pdata
=
538 container_of(param
, struct smsc75xx_priv
, set_multicast
);
539 struct usbnet
*dev
= pdata
->dev
;
542 netif_dbg(dev
, drv
, dev
->net
, "deferred multicast write 0x%08x\n",
545 smsc75xx_dataport_write(dev
, DP_SEL_VHF
, DP_SEL_VHF_VLAN_LEN
,
546 DP_SEL_VHF_HASH_LEN
, pdata
->multicast_hash_table
);
548 ret
= smsc75xx_write_reg(dev
, RFE_CTL
, pdata
->rfe_ctl
);
550 netdev_warn(dev
->net
, "Error writing RFE_CRL\n");
553 static void smsc75xx_set_multicast(struct net_device
*netdev
)
555 struct usbnet
*dev
= netdev_priv(netdev
);
556 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
560 spin_lock_irqsave(&pdata
->rfe_ctl_lock
, flags
);
563 ~(RFE_CTL_AU
| RFE_CTL_AM
| RFE_CTL_DPF
| RFE_CTL_MHF
);
564 pdata
->rfe_ctl
|= RFE_CTL_AB
;
566 for (i
= 0; i
< DP_SEL_VHF_HASH_LEN
; i
++)
567 pdata
->multicast_hash_table
[i
] = 0;
569 if (dev
->net
->flags
& IFF_PROMISC
) {
570 netif_dbg(dev
, drv
, dev
->net
, "promiscuous mode enabled\n");
571 pdata
->rfe_ctl
|= RFE_CTL_AM
| RFE_CTL_AU
;
572 } else if (dev
->net
->flags
& IFF_ALLMULTI
) {
573 netif_dbg(dev
, drv
, dev
->net
, "receive all multicast enabled\n");
574 pdata
->rfe_ctl
|= RFE_CTL_AM
| RFE_CTL_DPF
;
575 } else if (!netdev_mc_empty(dev
->net
)) {
576 struct netdev_hw_addr
*ha
;
578 netif_dbg(dev
, drv
, dev
->net
, "receive multicast hash filter\n");
580 pdata
->rfe_ctl
|= RFE_CTL_MHF
| RFE_CTL_DPF
;
582 netdev_for_each_mc_addr(ha
, netdev
) {
583 u32 bitnum
= smsc75xx_hash(ha
->addr
);
584 pdata
->multicast_hash_table
[bitnum
/ 32] |=
585 (1 << (bitnum
% 32));
588 netif_dbg(dev
, drv
, dev
->net
, "receive own packets only\n");
589 pdata
->rfe_ctl
|= RFE_CTL_DPF
;
592 spin_unlock_irqrestore(&pdata
->rfe_ctl_lock
, flags
);
594 /* defer register writes to a sleepable context */
595 schedule_work(&pdata
->set_multicast
);
598 static int smsc75xx_update_flowcontrol(struct usbnet
*dev
, u8 duplex
,
599 u16 lcladv
, u16 rmtadv
)
601 u32 flow
= 0, fct_flow
= 0;
604 if (duplex
== DUPLEX_FULL
) {
605 u8 cap
= mii_resolve_flowctrl_fdx(lcladv
, rmtadv
);
607 if (cap
& FLOW_CTRL_TX
) {
608 flow
= (FLOW_TX_FCEN
| 0xFFFF);
609 /* set fct_flow thresholds to 20% and 80% */
610 fct_flow
= (8 << 8) | 32;
613 if (cap
& FLOW_CTRL_RX
)
614 flow
|= FLOW_RX_FCEN
;
616 netif_dbg(dev
, link
, dev
->net
, "rx pause %s, tx pause %s\n",
617 (cap
& FLOW_CTRL_RX
? "enabled" : "disabled"),
618 (cap
& FLOW_CTRL_TX
? "enabled" : "disabled"));
620 netif_dbg(dev
, link
, dev
->net
, "half duplex\n");
623 ret
= smsc75xx_write_reg(dev
, FLOW
, flow
);
625 netdev_warn(dev
->net
, "Error writing FLOW\n");
629 ret
= smsc75xx_write_reg(dev
, FCT_FLOW
, fct_flow
);
631 netdev_warn(dev
->net
, "Error writing FCT_FLOW\n");
638 static int smsc75xx_link_reset(struct usbnet
*dev
)
640 struct mii_if_info
*mii
= &dev
->mii
;
641 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
645 /* write to clear phy interrupt status */
646 smsc75xx_mdio_write(dev
->net
, mii
->phy_id
, PHY_INT_SRC
,
647 PHY_INT_SRC_CLEAR_ALL
);
649 ret
= smsc75xx_write_reg(dev
, INT_STS
, INT_STS_CLEAR_ALL
);
651 netdev_warn(dev
->net
, "Error writing INT_STS\n");
655 mii_check_media(mii
, 1, 1);
656 mii_ethtool_gset(&dev
->mii
, &ecmd
);
657 lcladv
= smsc75xx_mdio_read(dev
->net
, mii
->phy_id
, MII_ADVERTISE
);
658 rmtadv
= smsc75xx_mdio_read(dev
->net
, mii
->phy_id
, MII_LPA
);
660 netif_dbg(dev
, link
, dev
->net
, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
661 ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, lcladv
, rmtadv
);
663 return smsc75xx_update_flowcontrol(dev
, ecmd
.duplex
, lcladv
, rmtadv
);
666 static void smsc75xx_status(struct usbnet
*dev
, struct urb
*urb
)
670 if (urb
->actual_length
!= 4) {
671 netdev_warn(dev
->net
, "unexpected urb length %d\n",
676 memcpy(&intdata
, urb
->transfer_buffer
, 4);
677 le32_to_cpus(&intdata
);
679 netif_dbg(dev
, link
, dev
->net
, "intdata: 0x%08X\n", intdata
);
681 if (intdata
& INT_ENP_PHY_INT
)
682 usbnet_defer_kevent(dev
, EVENT_LINK_RESET
);
684 netdev_warn(dev
->net
, "unexpected interrupt, intdata=0x%08X\n",
688 static int smsc75xx_ethtool_get_eeprom_len(struct net_device
*net
)
690 return MAX_EEPROM_SIZE
;
693 static int smsc75xx_ethtool_get_eeprom(struct net_device
*netdev
,
694 struct ethtool_eeprom
*ee
, u8
*data
)
696 struct usbnet
*dev
= netdev_priv(netdev
);
698 ee
->magic
= LAN75XX_EEPROM_MAGIC
;
700 return smsc75xx_read_eeprom(dev
, ee
->offset
, ee
->len
, data
);
703 static int smsc75xx_ethtool_set_eeprom(struct net_device
*netdev
,
704 struct ethtool_eeprom
*ee
, u8
*data
)
706 struct usbnet
*dev
= netdev_priv(netdev
);
708 if (ee
->magic
!= LAN75XX_EEPROM_MAGIC
) {
709 netdev_warn(dev
->net
, "EEPROM: magic value mismatch: 0x%x\n",
714 return smsc75xx_write_eeprom(dev
, ee
->offset
, ee
->len
, data
);
717 static void smsc75xx_ethtool_get_wol(struct net_device
*net
,
718 struct ethtool_wolinfo
*wolinfo
)
720 struct usbnet
*dev
= netdev_priv(net
);
721 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
723 wolinfo
->supported
= SUPPORTED_WAKE
;
724 wolinfo
->wolopts
= pdata
->wolopts
;
727 static int smsc75xx_ethtool_set_wol(struct net_device
*net
,
728 struct ethtool_wolinfo
*wolinfo
)
730 struct usbnet
*dev
= netdev_priv(net
);
731 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
734 if (wolinfo
->wolopts
& ~SUPPORTED_WAKE
)
737 pdata
->wolopts
= wolinfo
->wolopts
& SUPPORTED_WAKE
;
739 ret
= device_set_wakeup_enable(&dev
->udev
->dev
, pdata
->wolopts
);
741 netdev_warn(dev
->net
, "device_set_wakeup_enable error %d\n", ret
);
746 static const struct ethtool_ops smsc75xx_ethtool_ops
= {
747 .get_link
= usbnet_get_link
,
748 .nway_reset
= usbnet_nway_reset
,
749 .get_drvinfo
= usbnet_get_drvinfo
,
750 .get_msglevel
= usbnet_get_msglevel
,
751 .set_msglevel
= usbnet_set_msglevel
,
752 .get_eeprom_len
= smsc75xx_ethtool_get_eeprom_len
,
753 .get_eeprom
= smsc75xx_ethtool_get_eeprom
,
754 .set_eeprom
= smsc75xx_ethtool_set_eeprom
,
755 .get_wol
= smsc75xx_ethtool_get_wol
,
756 .set_wol
= smsc75xx_ethtool_set_wol
,
757 .get_link_ksettings
= usbnet_get_link_ksettings
,
758 .set_link_ksettings
= usbnet_set_link_ksettings
,
761 static int smsc75xx_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
763 struct usbnet
*dev
= netdev_priv(netdev
);
765 if (!netif_running(netdev
))
768 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
771 static void smsc75xx_init_mac_address(struct usbnet
*dev
)
775 /* maybe the boot loader passed the MAC address in devicetree */
776 mac_addr
= of_get_mac_address(dev
->udev
->dev
.of_node
);
778 memcpy(dev
->net
->dev_addr
, mac_addr
, ETH_ALEN
);
782 /* try reading mac address from EEPROM */
783 if (smsc75xx_read_eeprom(dev
, EEPROM_MAC_OFFSET
, ETH_ALEN
,
784 dev
->net
->dev_addr
) == 0) {
785 if (is_valid_ether_addr(dev
->net
->dev_addr
)) {
786 /* eeprom values are valid so use them */
787 netif_dbg(dev
, ifup
, dev
->net
,
788 "MAC address read from EEPROM\n");
793 /* no useful static MAC address found. generate a random one */
794 eth_hw_addr_random(dev
->net
);
795 netif_dbg(dev
, ifup
, dev
->net
, "MAC address set to eth_random_addr\n");
798 static int smsc75xx_set_mac_address(struct usbnet
*dev
)
800 u32 addr_lo
= dev
->net
->dev_addr
[0] | dev
->net
->dev_addr
[1] << 8 |
801 dev
->net
->dev_addr
[2] << 16 | dev
->net
->dev_addr
[3] << 24;
802 u32 addr_hi
= dev
->net
->dev_addr
[4] | dev
->net
->dev_addr
[5] << 8;
804 int ret
= smsc75xx_write_reg(dev
, RX_ADDRH
, addr_hi
);
806 netdev_warn(dev
->net
, "Failed to write RX_ADDRH: %d\n", ret
);
810 ret
= smsc75xx_write_reg(dev
, RX_ADDRL
, addr_lo
);
812 netdev_warn(dev
->net
, "Failed to write RX_ADDRL: %d\n", ret
);
816 addr_hi
|= ADDR_FILTX_FB_VALID
;
817 ret
= smsc75xx_write_reg(dev
, ADDR_FILTX
, addr_hi
);
819 netdev_warn(dev
->net
, "Failed to write ADDR_FILTX: %d\n", ret
);
823 ret
= smsc75xx_write_reg(dev
, ADDR_FILTX
+ 4, addr_lo
);
825 netdev_warn(dev
->net
, "Failed to write ADDR_FILTX+4: %d\n", ret
);
830 static int smsc75xx_phy_initialize(struct usbnet
*dev
)
832 int bmcr
, ret
, timeout
= 0;
834 /* Initialize MII structure */
835 dev
->mii
.dev
= dev
->net
;
836 dev
->mii
.mdio_read
= smsc75xx_mdio_read
;
837 dev
->mii
.mdio_write
= smsc75xx_mdio_write
;
838 dev
->mii
.phy_id_mask
= 0x1f;
839 dev
->mii
.reg_num_mask
= 0x1f;
840 dev
->mii
.supports_gmii
= 1;
841 dev
->mii
.phy_id
= SMSC75XX_INTERNAL_PHY_ID
;
843 /* reset phy and wait for reset to complete */
844 smsc75xx_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
848 bmcr
= smsc75xx_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
);
850 netdev_warn(dev
->net
, "Error reading MII_BMCR\n");
854 } while ((bmcr
& BMCR_RESET
) && (timeout
< 100));
856 if (timeout
>= 100) {
857 netdev_warn(dev
->net
, "timeout on PHY Reset\n");
861 /* phy workaround for gig link */
862 smsc75xx_phy_gig_workaround(dev
);
864 smsc75xx_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
865 ADVERTISE_ALL
| ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
|
866 ADVERTISE_PAUSE_ASYM
);
867 smsc75xx_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_CTRL1000
,
870 /* read and write to clear phy interrupt status */
871 ret
= smsc75xx_mdio_read(dev
->net
, dev
->mii
.phy_id
, PHY_INT_SRC
);
873 netdev_warn(dev
->net
, "Error reading PHY_INT_SRC\n");
877 smsc75xx_mdio_write(dev
->net
, dev
->mii
.phy_id
, PHY_INT_SRC
, 0xffff);
879 smsc75xx_mdio_write(dev
->net
, dev
->mii
.phy_id
, PHY_INT_MASK
,
880 PHY_INT_MASK_DEFAULT
);
881 mii_nway_restart(&dev
->mii
);
883 netif_dbg(dev
, ifup
, dev
->net
, "phy initialised successfully\n");
887 static int smsc75xx_set_rx_max_frame_length(struct usbnet
*dev
, int size
)
893 ret
= smsc75xx_read_reg(dev
, MAC_RX
, &buf
);
895 netdev_warn(dev
->net
, "Failed to read MAC_RX: %d\n", ret
);
899 rxenabled
= ((buf
& MAC_RX_RXEN
) != 0);
903 ret
= smsc75xx_write_reg(dev
, MAC_RX
, buf
);
905 netdev_warn(dev
->net
, "Failed to write MAC_RX: %d\n", ret
);
910 /* add 4 to size for FCS */
911 buf
&= ~MAC_RX_MAX_SIZE
;
912 buf
|= (((size
+ 4) << MAC_RX_MAX_SIZE_SHIFT
) & MAC_RX_MAX_SIZE
);
914 ret
= smsc75xx_write_reg(dev
, MAC_RX
, buf
);
916 netdev_warn(dev
->net
, "Failed to write MAC_RX: %d\n", ret
);
922 ret
= smsc75xx_write_reg(dev
, MAC_RX
, buf
);
924 netdev_warn(dev
->net
, "Failed to write MAC_RX: %d\n", ret
);
932 static int smsc75xx_change_mtu(struct net_device
*netdev
, int new_mtu
)
934 struct usbnet
*dev
= netdev_priv(netdev
);
937 ret
= smsc75xx_set_rx_max_frame_length(dev
, new_mtu
+ ETH_HLEN
);
939 netdev_warn(dev
->net
, "Failed to set mac rx frame length\n");
943 return usbnet_change_mtu(netdev
, new_mtu
);
946 /* Enable or disable Rx checksum offload engine */
947 static int smsc75xx_set_features(struct net_device
*netdev
,
948 netdev_features_t features
)
950 struct usbnet
*dev
= netdev_priv(netdev
);
951 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
955 spin_lock_irqsave(&pdata
->rfe_ctl_lock
, flags
);
957 if (features
& NETIF_F_RXCSUM
)
958 pdata
->rfe_ctl
|= RFE_CTL_TCPUDP_CKM
| RFE_CTL_IP_CKM
;
960 pdata
->rfe_ctl
&= ~(RFE_CTL_TCPUDP_CKM
| RFE_CTL_IP_CKM
);
962 spin_unlock_irqrestore(&pdata
->rfe_ctl_lock
, flags
);
963 /* it's racing here! */
965 ret
= smsc75xx_write_reg(dev
, RFE_CTL
, pdata
->rfe_ctl
);
967 netdev_warn(dev
->net
, "Error writing RFE_CTL\n");
973 static int smsc75xx_wait_ready(struct usbnet
*dev
, int in_pm
)
981 ret
= __smsc75xx_read_reg(dev
, PMT_CTL
, &buf
, in_pm
);
984 netdev_warn(dev
->net
, "Failed to read PMT_CTL: %d\n", ret
);
988 if (buf
& PMT_CTL_DEV_RDY
)
993 } while (timeout
< 100);
995 netdev_warn(dev
->net
, "timeout waiting for device ready\n");
999 static int smsc75xx_phy_gig_workaround(struct usbnet
*dev
)
1001 struct mii_if_info
*mii
= &dev
->mii
;
1002 int ret
= 0, timeout
= 0;
1003 u32 buf
, link_up
= 0;
1005 /* Set the phy in Gig loopback */
1006 smsc75xx_mdio_write(dev
->net
, mii
->phy_id
, MII_BMCR
, 0x4040);
1008 /* Wait for the link up */
1010 link_up
= smsc75xx_link_ok_nopm(dev
);
1011 usleep_range(10000, 20000);
1013 } while ((!link_up
) && (timeout
< 1000));
1015 if (timeout
>= 1000) {
1016 netdev_warn(dev
->net
, "Timeout waiting for PHY link up\n");
1021 ret
= smsc75xx_read_reg(dev
, PMT_CTL
, &buf
);
1023 netdev_warn(dev
->net
, "Failed to read PMT_CTL: %d\n", ret
);
1027 buf
|= PMT_CTL_PHY_RST
;
1029 ret
= smsc75xx_write_reg(dev
, PMT_CTL
, buf
);
1031 netdev_warn(dev
->net
, "Failed to write PMT_CTL: %d\n", ret
);
1037 usleep_range(10000, 20000);
1038 ret
= smsc75xx_read_reg(dev
, PMT_CTL
, &buf
);
1040 netdev_warn(dev
->net
, "Failed to read PMT_CTL: %d\n",
1045 } while ((buf
& PMT_CTL_PHY_RST
) && (timeout
< 100));
1047 if (timeout
>= 100) {
1048 netdev_warn(dev
->net
, "timeout waiting for PHY Reset\n");
1055 static int smsc75xx_reset(struct usbnet
*dev
)
1057 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1059 int ret
= 0, timeout
;
1061 netif_dbg(dev
, ifup
, dev
->net
, "entering smsc75xx_reset\n");
1063 ret
= smsc75xx_wait_ready(dev
, 0);
1065 netdev_warn(dev
->net
, "device not ready in smsc75xx_reset\n");
1069 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1071 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1077 ret
= smsc75xx_write_reg(dev
, HW_CFG
, buf
);
1079 netdev_warn(dev
->net
, "Failed to write HW_CFG: %d\n", ret
);
1086 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1088 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1092 } while ((buf
& HW_CFG_LRST
) && (timeout
< 100));
1094 if (timeout
>= 100) {
1095 netdev_warn(dev
->net
, "timeout on completion of Lite Reset\n");
1099 netif_dbg(dev
, ifup
, dev
->net
, "Lite reset complete, resetting PHY\n");
1101 ret
= smsc75xx_read_reg(dev
, PMT_CTL
, &buf
);
1103 netdev_warn(dev
->net
, "Failed to read PMT_CTL: %d\n", ret
);
1107 buf
|= PMT_CTL_PHY_RST
;
1109 ret
= smsc75xx_write_reg(dev
, PMT_CTL
, buf
);
1111 netdev_warn(dev
->net
, "Failed to write PMT_CTL: %d\n", ret
);
1118 ret
= smsc75xx_read_reg(dev
, PMT_CTL
, &buf
);
1120 netdev_warn(dev
->net
, "Failed to read PMT_CTL: %d\n", ret
);
1124 } while ((buf
& PMT_CTL_PHY_RST
) && (timeout
< 100));
1126 if (timeout
>= 100) {
1127 netdev_warn(dev
->net
, "timeout waiting for PHY Reset\n");
1131 netif_dbg(dev
, ifup
, dev
->net
, "PHY reset complete\n");
1133 ret
= smsc75xx_set_mac_address(dev
);
1135 netdev_warn(dev
->net
, "Failed to set mac address\n");
1139 netif_dbg(dev
, ifup
, dev
->net
, "MAC Address: %pM\n",
1140 dev
->net
->dev_addr
);
1142 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1144 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1148 netif_dbg(dev
, ifup
, dev
->net
, "Read Value from HW_CFG : 0x%08x\n",
1153 ret
= smsc75xx_write_reg(dev
, HW_CFG
, buf
);
1155 netdev_warn(dev
->net
, "Failed to write HW_CFG: %d\n", ret
);
1159 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1161 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1165 netif_dbg(dev
, ifup
, dev
->net
, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n",
1170 dev
->rx_urb_size
= MAX_SINGLE_PACKET_SIZE
;
1171 } else if (dev
->udev
->speed
== USB_SPEED_HIGH
) {
1172 buf
= DEFAULT_HS_BURST_CAP_SIZE
/ HS_USB_PKT_SIZE
;
1173 dev
->rx_urb_size
= DEFAULT_HS_BURST_CAP_SIZE
;
1175 buf
= DEFAULT_FS_BURST_CAP_SIZE
/ FS_USB_PKT_SIZE
;
1176 dev
->rx_urb_size
= DEFAULT_FS_BURST_CAP_SIZE
;
1179 netif_dbg(dev
, ifup
, dev
->net
, "rx_urb_size=%ld\n",
1180 (ulong
)dev
->rx_urb_size
);
1182 ret
= smsc75xx_write_reg(dev
, BURST_CAP
, buf
);
1184 netdev_warn(dev
->net
, "Failed to write BURST_CAP: %d\n", ret
);
1188 ret
= smsc75xx_read_reg(dev
, BURST_CAP
, &buf
);
1190 netdev_warn(dev
->net
, "Failed to read BURST_CAP: %d\n", ret
);
1194 netif_dbg(dev
, ifup
, dev
->net
,
1195 "Read Value from BURST_CAP after writing: 0x%08x\n", buf
);
1197 ret
= smsc75xx_write_reg(dev
, BULK_IN_DLY
, DEFAULT_BULK_IN_DELAY
);
1199 netdev_warn(dev
->net
, "Failed to write BULK_IN_DLY: %d\n", ret
);
1203 ret
= smsc75xx_read_reg(dev
, BULK_IN_DLY
, &buf
);
1205 netdev_warn(dev
->net
, "Failed to read BULK_IN_DLY: %d\n", ret
);
1209 netif_dbg(dev
, ifup
, dev
->net
,
1210 "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf
);
1213 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1215 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1219 netif_dbg(dev
, ifup
, dev
->net
, "HW_CFG: 0x%08x\n", buf
);
1221 buf
|= (HW_CFG_MEF
| HW_CFG_BCE
);
1223 ret
= smsc75xx_write_reg(dev
, HW_CFG
, buf
);
1225 netdev_warn(dev
->net
, "Failed to write HW_CFG: %d\n", ret
);
1229 ret
= smsc75xx_read_reg(dev
, HW_CFG
, &buf
);
1231 netdev_warn(dev
->net
, "Failed to read HW_CFG: %d\n", ret
);
1235 netif_dbg(dev
, ifup
, dev
->net
, "HW_CFG: 0x%08x\n", buf
);
1238 /* set FIFO sizes */
1239 buf
= (MAX_RX_FIFO_SIZE
- 512) / 512;
1240 ret
= smsc75xx_write_reg(dev
, FCT_RX_FIFO_END
, buf
);
1242 netdev_warn(dev
->net
, "Failed to write FCT_RX_FIFO_END: %d\n", ret
);
1246 netif_dbg(dev
, ifup
, dev
->net
, "FCT_RX_FIFO_END set to 0x%08x\n", buf
);
1248 buf
= (MAX_TX_FIFO_SIZE
- 512) / 512;
1249 ret
= smsc75xx_write_reg(dev
, FCT_TX_FIFO_END
, buf
);
1251 netdev_warn(dev
->net
, "Failed to write FCT_TX_FIFO_END: %d\n", ret
);
1255 netif_dbg(dev
, ifup
, dev
->net
, "FCT_TX_FIFO_END set to 0x%08x\n", buf
);
1257 ret
= smsc75xx_write_reg(dev
, INT_STS
, INT_STS_CLEAR_ALL
);
1259 netdev_warn(dev
->net
, "Failed to write INT_STS: %d\n", ret
);
1263 ret
= smsc75xx_read_reg(dev
, ID_REV
, &buf
);
1265 netdev_warn(dev
->net
, "Failed to read ID_REV: %d\n", ret
);
1269 netif_dbg(dev
, ifup
, dev
->net
, "ID_REV = 0x%08x\n", buf
);
1271 ret
= smsc75xx_read_reg(dev
, E2P_CMD
, &buf
);
1273 netdev_warn(dev
->net
, "Failed to read E2P_CMD: %d\n", ret
);
1277 /* only set default GPIO/LED settings if no EEPROM is detected */
1278 if (!(buf
& E2P_CMD_LOADED
)) {
1279 ret
= smsc75xx_read_reg(dev
, LED_GPIO_CFG
, &buf
);
1281 netdev_warn(dev
->net
, "Failed to read LED_GPIO_CFG: %d\n", ret
);
1285 buf
&= ~(LED_GPIO_CFG_LED2_FUN_SEL
| LED_GPIO_CFG_LED10_FUN_SEL
);
1286 buf
|= LED_GPIO_CFG_LEDGPIO_EN
| LED_GPIO_CFG_LED2_FUN_SEL
;
1288 ret
= smsc75xx_write_reg(dev
, LED_GPIO_CFG
, buf
);
1290 netdev_warn(dev
->net
, "Failed to write LED_GPIO_CFG: %d\n", ret
);
1295 ret
= smsc75xx_write_reg(dev
, FLOW
, 0);
1297 netdev_warn(dev
->net
, "Failed to write FLOW: %d\n", ret
);
1301 ret
= smsc75xx_write_reg(dev
, FCT_FLOW
, 0);
1303 netdev_warn(dev
->net
, "Failed to write FCT_FLOW: %d\n", ret
);
1307 /* Don't need rfe_ctl_lock during initialisation */
1308 ret
= smsc75xx_read_reg(dev
, RFE_CTL
, &pdata
->rfe_ctl
);
1310 netdev_warn(dev
->net
, "Failed to read RFE_CTL: %d\n", ret
);
1314 pdata
->rfe_ctl
|= RFE_CTL_AB
| RFE_CTL_DPF
;
1316 ret
= smsc75xx_write_reg(dev
, RFE_CTL
, pdata
->rfe_ctl
);
1318 netdev_warn(dev
->net
, "Failed to write RFE_CTL: %d\n", ret
);
1322 ret
= smsc75xx_read_reg(dev
, RFE_CTL
, &pdata
->rfe_ctl
);
1324 netdev_warn(dev
->net
, "Failed to read RFE_CTL: %d\n", ret
);
1328 netif_dbg(dev
, ifup
, dev
->net
, "RFE_CTL set to 0x%08x\n",
1331 /* Enable or disable checksum offload engines */
1332 smsc75xx_set_features(dev
->net
, dev
->net
->features
);
1334 smsc75xx_set_multicast(dev
->net
);
1336 ret
= smsc75xx_phy_initialize(dev
);
1338 netdev_warn(dev
->net
, "Failed to initialize PHY: %d\n", ret
);
1342 ret
= smsc75xx_read_reg(dev
, INT_EP_CTL
, &buf
);
1344 netdev_warn(dev
->net
, "Failed to read INT_EP_CTL: %d\n", ret
);
1348 /* enable PHY interrupts */
1349 buf
|= INT_ENP_PHY_INT
;
1351 ret
= smsc75xx_write_reg(dev
, INT_EP_CTL
, buf
);
1353 netdev_warn(dev
->net
, "Failed to write INT_EP_CTL: %d\n", ret
);
1357 /* allow mac to detect speed and duplex from phy */
1358 ret
= smsc75xx_read_reg(dev
, MAC_CR
, &buf
);
1360 netdev_warn(dev
->net
, "Failed to read MAC_CR: %d\n", ret
);
1364 buf
|= (MAC_CR_ADD
| MAC_CR_ASD
);
1365 ret
= smsc75xx_write_reg(dev
, MAC_CR
, buf
);
1367 netdev_warn(dev
->net
, "Failed to write MAC_CR: %d\n", ret
);
1371 ret
= smsc75xx_read_reg(dev
, MAC_TX
, &buf
);
1373 netdev_warn(dev
->net
, "Failed to read MAC_TX: %d\n", ret
);
1379 ret
= smsc75xx_write_reg(dev
, MAC_TX
, buf
);
1381 netdev_warn(dev
->net
, "Failed to write MAC_TX: %d\n", ret
);
1385 netif_dbg(dev
, ifup
, dev
->net
, "MAC_TX set to 0x%08x\n", buf
);
1387 ret
= smsc75xx_read_reg(dev
, FCT_TX_CTL
, &buf
);
1389 netdev_warn(dev
->net
, "Failed to read FCT_TX_CTL: %d\n", ret
);
1393 buf
|= FCT_TX_CTL_EN
;
1395 ret
= smsc75xx_write_reg(dev
, FCT_TX_CTL
, buf
);
1397 netdev_warn(dev
->net
, "Failed to write FCT_TX_CTL: %d\n", ret
);
1401 netif_dbg(dev
, ifup
, dev
->net
, "FCT_TX_CTL set to 0x%08x\n", buf
);
1403 ret
= smsc75xx_set_rx_max_frame_length(dev
, dev
->net
->mtu
+ ETH_HLEN
);
1405 netdev_warn(dev
->net
, "Failed to set max rx frame length\n");
1409 ret
= smsc75xx_read_reg(dev
, MAC_RX
, &buf
);
1411 netdev_warn(dev
->net
, "Failed to read MAC_RX: %d\n", ret
);
1417 ret
= smsc75xx_write_reg(dev
, MAC_RX
, buf
);
1419 netdev_warn(dev
->net
, "Failed to write MAC_RX: %d\n", ret
);
1423 netif_dbg(dev
, ifup
, dev
->net
, "MAC_RX set to 0x%08x\n", buf
);
1425 ret
= smsc75xx_read_reg(dev
, FCT_RX_CTL
, &buf
);
1427 netdev_warn(dev
->net
, "Failed to read FCT_RX_CTL: %d\n", ret
);
1431 buf
|= FCT_RX_CTL_EN
;
1433 ret
= smsc75xx_write_reg(dev
, FCT_RX_CTL
, buf
);
1435 netdev_warn(dev
->net
, "Failed to write FCT_RX_CTL: %d\n", ret
);
1439 netif_dbg(dev
, ifup
, dev
->net
, "FCT_RX_CTL set to 0x%08x\n", buf
);
1441 netif_dbg(dev
, ifup
, dev
->net
, "smsc75xx_reset, return 0\n");
1445 static const struct net_device_ops smsc75xx_netdev_ops
= {
1446 .ndo_open
= usbnet_open
,
1447 .ndo_stop
= usbnet_stop
,
1448 .ndo_start_xmit
= usbnet_start_xmit
,
1449 .ndo_tx_timeout
= usbnet_tx_timeout
,
1450 .ndo_get_stats64
= usbnet_get_stats64
,
1451 .ndo_change_mtu
= smsc75xx_change_mtu
,
1452 .ndo_set_mac_address
= eth_mac_addr
,
1453 .ndo_validate_addr
= eth_validate_addr
,
1454 .ndo_do_ioctl
= smsc75xx_ioctl
,
1455 .ndo_set_rx_mode
= smsc75xx_set_multicast
,
1456 .ndo_set_features
= smsc75xx_set_features
,
1459 static int smsc75xx_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
1461 struct smsc75xx_priv
*pdata
= NULL
;
1464 printk(KERN_INFO SMSC_CHIPNAME
" v" SMSC_DRIVER_VERSION
"\n");
1466 ret
= usbnet_get_endpoints(dev
, intf
);
1468 netdev_warn(dev
->net
, "usbnet_get_endpoints failed: %d\n", ret
);
1472 dev
->data
[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv
),
1475 pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1481 spin_lock_init(&pdata
->rfe_ctl_lock
);
1482 mutex_init(&pdata
->dataport_mutex
);
1484 INIT_WORK(&pdata
->set_multicast
, smsc75xx_deferred_multicast_write
);
1486 if (DEFAULT_TX_CSUM_ENABLE
)
1487 dev
->net
->features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
1489 if (DEFAULT_RX_CSUM_ENABLE
)
1490 dev
->net
->features
|= NETIF_F_RXCSUM
;
1492 dev
->net
->hw_features
= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1495 ret
= smsc75xx_wait_ready(dev
, 0);
1497 netdev_warn(dev
->net
, "device not ready in smsc75xx_bind\n");
1501 smsc75xx_init_mac_address(dev
);
1503 /* Init all registers */
1504 ret
= smsc75xx_reset(dev
);
1506 netdev_warn(dev
->net
, "smsc75xx_reset error %d\n", ret
);
1510 dev
->net
->netdev_ops
= &smsc75xx_netdev_ops
;
1511 dev
->net
->ethtool_ops
= &smsc75xx_ethtool_ops
;
1512 dev
->net
->flags
|= IFF_MULTICAST
;
1513 dev
->net
->hard_header_len
+= SMSC75XX_TX_OVERHEAD
;
1514 dev
->hard_mtu
= dev
->net
->mtu
+ dev
->net
->hard_header_len
;
1515 dev
->net
->max_mtu
= MAX_SINGLE_PACKET_SIZE
;
1519 static void smsc75xx_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
1521 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1523 cancel_work_sync(&pdata
->set_multicast
);
1524 netif_dbg(dev
, ifdown
, dev
->net
, "free pdata\n");
1531 static u16
smsc_crc(const u8
*buffer
, size_t len
)
1533 return bitrev16(crc16(0xFFFF, buffer
, len
));
1536 static int smsc75xx_write_wuff(struct usbnet
*dev
, int filter
, u32 wuf_cfg
,
1539 int cfg_base
= WUF_CFGX
+ filter
* 4;
1540 int mask_base
= WUF_MASKX
+ filter
* 16;
1543 ret
= smsc75xx_write_reg(dev
, cfg_base
, wuf_cfg
);
1545 netdev_warn(dev
->net
, "Error writing WUF_CFGX\n");
1549 ret
= smsc75xx_write_reg(dev
, mask_base
, wuf_mask1
);
1551 netdev_warn(dev
->net
, "Error writing WUF_MASKX\n");
1555 ret
= smsc75xx_write_reg(dev
, mask_base
+ 4, 0);
1557 netdev_warn(dev
->net
, "Error writing WUF_MASKX\n");
1561 ret
= smsc75xx_write_reg(dev
, mask_base
+ 8, 0);
1563 netdev_warn(dev
->net
, "Error writing WUF_MASKX\n");
1567 ret
= smsc75xx_write_reg(dev
, mask_base
+ 12, 0);
1569 netdev_warn(dev
->net
, "Error writing WUF_MASKX\n");
1576 static int smsc75xx_enter_suspend0(struct usbnet
*dev
)
1578 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1582 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
1584 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
1588 val
&= (~(PMT_CTL_SUS_MODE
| PMT_CTL_PHY_RST
));
1589 val
|= PMT_CTL_SUS_MODE_0
| PMT_CTL_WOL_EN
| PMT_CTL_WUPS
;
1591 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1593 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1597 pdata
->suspend_flags
|= SUSPEND_SUSPEND0
;
1602 static int smsc75xx_enter_suspend1(struct usbnet
*dev
)
1604 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1608 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
1610 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
1614 val
&= ~(PMT_CTL_SUS_MODE
| PMT_CTL_WUPS
| PMT_CTL_PHY_RST
);
1615 val
|= PMT_CTL_SUS_MODE_1
;
1617 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1619 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1623 /* clear wol status, enable energy detection */
1624 val
&= ~PMT_CTL_WUPS
;
1625 val
|= (PMT_CTL_WUPS_ED
| PMT_CTL_ED_EN
);
1627 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1629 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1633 pdata
->suspend_flags
|= SUSPEND_SUSPEND1
;
1638 static int smsc75xx_enter_suspend2(struct usbnet
*dev
)
1640 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1644 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
1646 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
1650 val
&= ~(PMT_CTL_SUS_MODE
| PMT_CTL_WUPS
| PMT_CTL_PHY_RST
);
1651 val
|= PMT_CTL_SUS_MODE_2
;
1653 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1655 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1659 pdata
->suspend_flags
|= SUSPEND_SUSPEND2
;
1664 static int smsc75xx_enter_suspend3(struct usbnet
*dev
)
1666 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1670 ret
= smsc75xx_read_reg_nopm(dev
, FCT_RX_CTL
, &val
);
1672 netdev_warn(dev
->net
, "Error reading FCT_RX_CTL\n");
1676 if (val
& FCT_RX_CTL_RXUSED
) {
1677 netdev_dbg(dev
->net
, "rx fifo not empty in autosuspend\n");
1681 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
1683 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
1687 val
&= ~(PMT_CTL_SUS_MODE
| PMT_CTL_WUPS
| PMT_CTL_PHY_RST
);
1688 val
|= PMT_CTL_SUS_MODE_3
| PMT_CTL_RES_CLR_WKP_EN
;
1690 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1692 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1696 /* clear wol status */
1697 val
&= ~PMT_CTL_WUPS
;
1698 val
|= PMT_CTL_WUPS_WOL
;
1700 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1702 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1706 pdata
->suspend_flags
|= SUSPEND_SUSPEND3
;
1711 static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet
*dev
, u16 mask
)
1713 struct mii_if_info
*mii
= &dev
->mii
;
1716 netdev_dbg(dev
->net
, "enabling PHY wakeup interrupts\n");
1719 ret
= smsc75xx_mdio_read_nopm(dev
->net
, mii
->phy_id
, PHY_INT_SRC
);
1721 netdev_warn(dev
->net
, "Error reading PHY_INT_SRC\n");
1725 /* enable interrupt source */
1726 ret
= smsc75xx_mdio_read_nopm(dev
->net
, mii
->phy_id
, PHY_INT_MASK
);
1728 netdev_warn(dev
->net
, "Error reading PHY_INT_MASK\n");
1734 smsc75xx_mdio_write_nopm(dev
->net
, mii
->phy_id
, PHY_INT_MASK
, ret
);
1739 static int smsc75xx_link_ok_nopm(struct usbnet
*dev
)
1741 struct mii_if_info
*mii
= &dev
->mii
;
1744 /* first, a dummy read, needed to latch some MII phys */
1745 ret
= smsc75xx_mdio_read_nopm(dev
->net
, mii
->phy_id
, MII_BMSR
);
1747 netdev_warn(dev
->net
, "Error reading MII_BMSR\n");
1751 ret
= smsc75xx_mdio_read_nopm(dev
->net
, mii
->phy_id
, MII_BMSR
);
1753 netdev_warn(dev
->net
, "Error reading MII_BMSR\n");
1757 return !!(ret
& BMSR_LSTATUS
);
1760 static int smsc75xx_autosuspend(struct usbnet
*dev
, u32 link_up
)
1764 if (!netif_running(dev
->net
)) {
1765 /* interface is ifconfig down so fully power down hw */
1766 netdev_dbg(dev
->net
, "autosuspend entering SUSPEND2\n");
1767 return smsc75xx_enter_suspend2(dev
);
1771 /* link is down so enter EDPD mode */
1772 netdev_dbg(dev
->net
, "autosuspend entering SUSPEND1\n");
1774 /* enable PHY wakeup events for if cable is attached */
1775 ret
= smsc75xx_enable_phy_wakeup_interrupts(dev
,
1776 PHY_INT_MASK_ANEG_COMP
);
1778 netdev_warn(dev
->net
, "error enabling PHY wakeup ints\n");
1782 netdev_info(dev
->net
, "entering SUSPEND1 mode\n");
1783 return smsc75xx_enter_suspend1(dev
);
1786 /* enable PHY wakeup events so we remote wakeup if cable is pulled */
1787 ret
= smsc75xx_enable_phy_wakeup_interrupts(dev
,
1788 PHY_INT_MASK_LINK_DOWN
);
1790 netdev_warn(dev
->net
, "error enabling PHY wakeup ints\n");
1794 netdev_dbg(dev
->net
, "autosuspend entering SUSPEND3\n");
1795 return smsc75xx_enter_suspend3(dev
);
1798 static int smsc75xx_suspend(struct usb_interface
*intf
, pm_message_t message
)
1800 struct usbnet
*dev
= usb_get_intfdata(intf
);
1801 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
1805 ret
= usbnet_suspend(intf
, message
);
1807 netdev_warn(dev
->net
, "usbnet_suspend error\n");
1811 if (pdata
->suspend_flags
) {
1812 netdev_warn(dev
->net
, "error during last resume\n");
1813 pdata
->suspend_flags
= 0;
1816 /* determine if link is up using only _nopm functions */
1817 link_up
= smsc75xx_link_ok_nopm(dev
);
1819 if (message
.event
== PM_EVENT_AUTO_SUSPEND
) {
1820 ret
= smsc75xx_autosuspend(dev
, link_up
);
1824 /* if we get this far we're not autosuspending */
1825 /* if no wol options set, or if link is down and we're not waking on
1826 * PHY activity, enter lowest power SUSPEND2 mode
1828 if (!(pdata
->wolopts
& SUPPORTED_WAKE
) ||
1829 !(link_up
|| (pdata
->wolopts
& WAKE_PHY
))) {
1830 netdev_info(dev
->net
, "entering SUSPEND2 mode\n");
1832 /* disable energy detect (link up) & wake up events */
1833 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
1835 netdev_warn(dev
->net
, "Error reading WUCSR\n");
1839 val
&= ~(WUCSR_MPEN
| WUCSR_WUEN
);
1841 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
1843 netdev_warn(dev
->net
, "Error writing WUCSR\n");
1847 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
1849 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
1853 val
&= ~(PMT_CTL_ED_EN
| PMT_CTL_WOL_EN
);
1855 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
1857 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
1861 ret
= smsc75xx_enter_suspend2(dev
);
1865 if (pdata
->wolopts
& WAKE_PHY
) {
1866 ret
= smsc75xx_enable_phy_wakeup_interrupts(dev
,
1867 (PHY_INT_MASK_ANEG_COMP
| PHY_INT_MASK_LINK_DOWN
));
1869 netdev_warn(dev
->net
, "error enabling PHY wakeup ints\n");
1873 /* if link is down then configure EDPD and enter SUSPEND1,
1874 * otherwise enter SUSPEND0 below
1877 struct mii_if_info
*mii
= &dev
->mii
;
1878 netdev_info(dev
->net
, "entering SUSPEND1 mode\n");
1880 /* enable energy detect power-down mode */
1881 ret
= smsc75xx_mdio_read_nopm(dev
->net
, mii
->phy_id
,
1884 netdev_warn(dev
->net
, "Error reading PHY_MODE_CTRL_STS\n");
1888 ret
|= MODE_CTRL_STS_EDPWRDOWN
;
1890 smsc75xx_mdio_write_nopm(dev
->net
, mii
->phy_id
,
1891 PHY_MODE_CTRL_STS
, ret
);
1893 /* enter SUSPEND1 mode */
1894 ret
= smsc75xx_enter_suspend1(dev
);
1899 if (pdata
->wolopts
& (WAKE_MCAST
| WAKE_ARP
)) {
1902 /* disable all filters */
1903 for (i
= 0; i
< WUF_NUM
; i
++) {
1904 ret
= smsc75xx_write_reg_nopm(dev
, WUF_CFGX
+ i
* 4, 0);
1906 netdev_warn(dev
->net
, "Error writing WUF_CFGX\n");
1911 if (pdata
->wolopts
& WAKE_MCAST
) {
1912 const u8 mcast
[] = {0x01, 0x00, 0x5E};
1913 netdev_info(dev
->net
, "enabling multicast detection\n");
1915 val
= WUF_CFGX_EN
| WUF_CFGX_ATYPE_MULTICAST
1916 | smsc_crc(mcast
, 3);
1917 ret
= smsc75xx_write_wuff(dev
, filter
++, val
, 0x0007);
1919 netdev_warn(dev
->net
, "Error writing wakeup filter\n");
1924 if (pdata
->wolopts
& WAKE_ARP
) {
1925 const u8 arp
[] = {0x08, 0x06};
1926 netdev_info(dev
->net
, "enabling ARP detection\n");
1928 val
= WUF_CFGX_EN
| WUF_CFGX_ATYPE_ALL
| (0x0C << 16)
1930 ret
= smsc75xx_write_wuff(dev
, filter
++, val
, 0x0003);
1932 netdev_warn(dev
->net
, "Error writing wakeup filter\n");
1937 /* clear any pending pattern match packet status */
1938 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
1940 netdev_warn(dev
->net
, "Error reading WUCSR\n");
1946 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
1948 netdev_warn(dev
->net
, "Error writing WUCSR\n");
1952 netdev_info(dev
->net
, "enabling packet match detection\n");
1953 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
1955 netdev_warn(dev
->net
, "Error reading WUCSR\n");
1961 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
1963 netdev_warn(dev
->net
, "Error writing WUCSR\n");
1967 netdev_info(dev
->net
, "disabling packet match detection\n");
1968 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
1970 netdev_warn(dev
->net
, "Error reading WUCSR\n");
1976 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
1978 netdev_warn(dev
->net
, "Error writing WUCSR\n");
1983 /* disable magic, bcast & unicast wakeup sources */
1984 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
1986 netdev_warn(dev
->net
, "Error reading WUCSR\n");
1990 val
&= ~(WUCSR_MPEN
| WUCSR_BCST_EN
| WUCSR_PFDA_EN
);
1992 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
1994 netdev_warn(dev
->net
, "Error writing WUCSR\n");
1998 if (pdata
->wolopts
& WAKE_PHY
) {
1999 netdev_info(dev
->net
, "enabling PHY wakeup\n");
2001 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
2003 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
2007 /* clear wol status, enable energy detection */
2008 val
&= ~PMT_CTL_WUPS
;
2009 val
|= (PMT_CTL_WUPS_ED
| PMT_CTL_ED_EN
);
2011 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
2013 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
2018 if (pdata
->wolopts
& WAKE_MAGIC
) {
2019 netdev_info(dev
->net
, "enabling magic packet wakeup\n");
2020 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
2022 netdev_warn(dev
->net
, "Error reading WUCSR\n");
2026 /* clear any pending magic packet status */
2027 val
|= WUCSR_MPR
| WUCSR_MPEN
;
2029 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
2031 netdev_warn(dev
->net
, "Error writing WUCSR\n");
2036 if (pdata
->wolopts
& WAKE_BCAST
) {
2037 netdev_info(dev
->net
, "enabling broadcast detection\n");
2038 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
2040 netdev_warn(dev
->net
, "Error reading WUCSR\n");
2044 val
|= WUCSR_BCAST_FR
| WUCSR_BCST_EN
;
2046 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
2048 netdev_warn(dev
->net
, "Error writing WUCSR\n");
2053 if (pdata
->wolopts
& WAKE_UCAST
) {
2054 netdev_info(dev
->net
, "enabling unicast detection\n");
2055 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
2057 netdev_warn(dev
->net
, "Error reading WUCSR\n");
2061 val
|= WUCSR_WUFR
| WUCSR_PFDA_EN
;
2063 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
2065 netdev_warn(dev
->net
, "Error writing WUCSR\n");
2070 /* enable receiver to enable frame reception */
2071 ret
= smsc75xx_read_reg_nopm(dev
, MAC_RX
, &val
);
2073 netdev_warn(dev
->net
, "Failed to read MAC_RX: %d\n", ret
);
2079 ret
= smsc75xx_write_reg_nopm(dev
, MAC_RX
, val
);
2081 netdev_warn(dev
->net
, "Failed to write MAC_RX: %d\n", ret
);
2085 /* some wol options are enabled, so enter SUSPEND0 */
2086 netdev_info(dev
->net
, "entering SUSPEND0 mode\n");
2087 ret
= smsc75xx_enter_suspend0(dev
);
2091 * TODO: resume() might need to handle the suspend failure
2094 if (ret
&& PMSG_IS_AUTO(message
))
2095 usbnet_resume(intf
);
2099 static int smsc75xx_resume(struct usb_interface
*intf
)
2101 struct usbnet
*dev
= usb_get_intfdata(intf
);
2102 struct smsc75xx_priv
*pdata
= (struct smsc75xx_priv
*)(dev
->data
[0]);
2103 u8 suspend_flags
= pdata
->suspend_flags
;
2107 netdev_dbg(dev
->net
, "resume suspend_flags=0x%02x\n", suspend_flags
);
2109 /* do this first to ensure it's cleared even in error case */
2110 pdata
->suspend_flags
= 0;
2112 if (suspend_flags
& SUSPEND_ALLMODES
) {
2113 /* Disable wakeup sources */
2114 ret
= smsc75xx_read_reg_nopm(dev
, WUCSR
, &val
);
2116 netdev_warn(dev
->net
, "Error reading WUCSR\n");
2120 val
&= ~(WUCSR_WUEN
| WUCSR_MPEN
| WUCSR_PFDA_EN
2123 ret
= smsc75xx_write_reg_nopm(dev
, WUCSR
, val
);
2125 netdev_warn(dev
->net
, "Error writing WUCSR\n");
2129 /* clear wake-up status */
2130 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
2132 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
2136 val
&= ~PMT_CTL_WOL_EN
;
2137 val
|= PMT_CTL_WUPS
;
2139 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
2141 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
2146 if (suspend_flags
& SUSPEND_SUSPEND2
) {
2147 netdev_info(dev
->net
, "resuming from SUSPEND2\n");
2149 ret
= smsc75xx_read_reg_nopm(dev
, PMT_CTL
, &val
);
2151 netdev_warn(dev
->net
, "Error reading PMT_CTL\n");
2155 val
|= PMT_CTL_PHY_PWRUP
;
2157 ret
= smsc75xx_write_reg_nopm(dev
, PMT_CTL
, val
);
2159 netdev_warn(dev
->net
, "Error writing PMT_CTL\n");
2164 ret
= smsc75xx_wait_ready(dev
, 1);
2166 netdev_warn(dev
->net
, "device not ready in smsc75xx_resume\n");
2170 return usbnet_resume(intf
);
2173 static void smsc75xx_rx_csum_offload(struct usbnet
*dev
, struct sk_buff
*skb
,
2174 u32 rx_cmd_a
, u32 rx_cmd_b
)
2176 if (!(dev
->net
->features
& NETIF_F_RXCSUM
) ||
2177 unlikely(rx_cmd_a
& RX_CMD_A_LCSM
)) {
2178 skb
->ip_summed
= CHECKSUM_NONE
;
2180 skb
->csum
= ntohs((u16
)(rx_cmd_b
>> RX_CMD_B_CSUM_SHIFT
));
2181 skb
->ip_summed
= CHECKSUM_COMPLETE
;
2185 static int smsc75xx_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
)
2187 /* This check is no longer done by usbnet */
2188 if (skb
->len
< dev
->net
->hard_header_len
)
2191 while (skb
->len
> 0) {
2192 u32 rx_cmd_a
, rx_cmd_b
, align_count
, size
;
2193 struct sk_buff
*ax_skb
;
2194 unsigned char *packet
;
2196 memcpy(&rx_cmd_a
, skb
->data
, sizeof(rx_cmd_a
));
2197 le32_to_cpus(&rx_cmd_a
);
2200 memcpy(&rx_cmd_b
, skb
->data
, sizeof(rx_cmd_b
));
2201 le32_to_cpus(&rx_cmd_b
);
2202 skb_pull(skb
, 4 + RXW_PADDING
);
2206 /* get the packet length */
2207 size
= (rx_cmd_a
& RX_CMD_A_LEN
) - RXW_PADDING
;
2208 align_count
= (4 - ((size
+ RXW_PADDING
) % 4)) % 4;
2210 if (unlikely(rx_cmd_a
& RX_CMD_A_RED
)) {
2211 netif_dbg(dev
, rx_err
, dev
->net
,
2212 "Error rx_cmd_a=0x%08x\n", rx_cmd_a
);
2213 dev
->net
->stats
.rx_errors
++;
2214 dev
->net
->stats
.rx_dropped
++;
2216 if (rx_cmd_a
& RX_CMD_A_FCS
)
2217 dev
->net
->stats
.rx_crc_errors
++;
2218 else if (rx_cmd_a
& (RX_CMD_A_LONG
| RX_CMD_A_RUNT
))
2219 dev
->net
->stats
.rx_frame_errors
++;
2221 /* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
2222 if (unlikely(size
> (MAX_SINGLE_PACKET_SIZE
+ ETH_HLEN
+ 12))) {
2223 netif_dbg(dev
, rx_err
, dev
->net
,
2224 "size err rx_cmd_a=0x%08x\n",
2229 /* last frame in this batch */
2230 if (skb
->len
== size
) {
2231 smsc75xx_rx_csum_offload(dev
, skb
, rx_cmd_a
,
2234 skb_trim(skb
, skb
->len
- 4); /* remove fcs */
2235 skb
->truesize
= size
+ sizeof(struct sk_buff
);
2240 ax_skb
= skb_clone(skb
, GFP_ATOMIC
);
2241 if (unlikely(!ax_skb
)) {
2242 netdev_warn(dev
->net
, "Error allocating skb\n");
2247 ax_skb
->data
= packet
;
2248 skb_set_tail_pointer(ax_skb
, size
);
2250 smsc75xx_rx_csum_offload(dev
, ax_skb
, rx_cmd_a
,
2253 skb_trim(ax_skb
, ax_skb
->len
- 4); /* remove fcs */
2254 ax_skb
->truesize
= size
+ sizeof(struct sk_buff
);
2256 usbnet_skb_return(dev
, ax_skb
);
2259 skb_pull(skb
, size
);
2261 /* padding bytes before the next frame starts */
2263 skb_pull(skb
, align_count
);
2269 static struct sk_buff
*smsc75xx_tx_fixup(struct usbnet
*dev
,
2270 struct sk_buff
*skb
, gfp_t flags
)
2272 u32 tx_cmd_a
, tx_cmd_b
;
2274 if (skb_cow_head(skb
, SMSC75XX_TX_OVERHEAD
)) {
2275 dev_kfree_skb_any(skb
);
2279 tx_cmd_a
= (u32
)(skb
->len
& TX_CMD_A_LEN
) | TX_CMD_A_FCS
;
2281 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2282 tx_cmd_a
|= TX_CMD_A_IPE
| TX_CMD_A_TPE
;
2284 if (skb_is_gso(skb
)) {
2285 u16 mss
= max(skb_shinfo(skb
)->gso_size
, TX_MSS_MIN
);
2286 tx_cmd_b
= (mss
<< TX_CMD_B_MSS_SHIFT
) & TX_CMD_B_MSS
;
2288 tx_cmd_a
|= TX_CMD_A_LSO
;
2294 cpu_to_le32s(&tx_cmd_b
);
2295 memcpy(skb
->data
, &tx_cmd_b
, 4);
2298 cpu_to_le32s(&tx_cmd_a
);
2299 memcpy(skb
->data
, &tx_cmd_a
, 4);
2304 static int smsc75xx_manage_power(struct usbnet
*dev
, int on
)
2306 dev
->intf
->needs_remote_wakeup
= on
;
2310 static const struct driver_info smsc75xx_info
= {
2311 .description
= "smsc75xx USB 2.0 Gigabit Ethernet",
2312 .bind
= smsc75xx_bind
,
2313 .unbind
= smsc75xx_unbind
,
2314 .link_reset
= smsc75xx_link_reset
,
2315 .reset
= smsc75xx_reset
,
2316 .rx_fixup
= smsc75xx_rx_fixup
,
2317 .tx_fixup
= smsc75xx_tx_fixup
,
2318 .status
= smsc75xx_status
,
2319 .manage_power
= smsc75xx_manage_power
,
2320 .flags
= FLAG_ETHER
| FLAG_SEND_ZLP
| FLAG_LINK_INTR
,
2323 static const struct usb_device_id products
[] = {
2325 /* SMSC7500 USB Gigabit Ethernet Device */
2326 USB_DEVICE(USB_VENDOR_ID_SMSC
, USB_PRODUCT_ID_LAN7500
),
2327 .driver_info
= (unsigned long) &smsc75xx_info
,
2330 /* SMSC7500 USB Gigabit Ethernet Device */
2331 USB_DEVICE(USB_VENDOR_ID_SMSC
, USB_PRODUCT_ID_LAN7505
),
2332 .driver_info
= (unsigned long) &smsc75xx_info
,
2336 MODULE_DEVICE_TABLE(usb
, products
);
2338 static struct usb_driver smsc75xx_driver
= {
2339 .name
= SMSC_CHIPNAME
,
2340 .id_table
= products
,
2341 .probe
= usbnet_probe
,
2342 .suspend
= smsc75xx_suspend
,
2343 .resume
= smsc75xx_resume
,
2344 .reset_resume
= smsc75xx_resume
,
2345 .disconnect
= usbnet_disconnect
,
2346 .disable_hub_initiated_lpm
= 1,
2347 .supports_autosuspend
= 1,
2350 module_usb_driver(smsc75xx_driver
);
2352 MODULE_AUTHOR("Nancy Lin");
2353 MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
2354 MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices");
2355 MODULE_LICENSE("GPL");