Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2 | /*************************************************************************** |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 SMSC |
| 5 | * |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 6 | *****************************************************************************/ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kmod.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/etherdevice.h> |
| 12 | #include <linux/ethtool.h> |
| 13 | #include <linux/mii.h> |
| 14 | #include <linux/usb.h> |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 15 | #include <linux/bitrev.h> |
| 16 | #include <linux/crc16.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 17 | #include <linux/crc32.h> |
| 18 | #include <linux/usb/usbnet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 20 | #include <linux/of_net.h> |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 21 | #include <linux/mdio.h> |
| 22 | #include <linux/phy.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 23 | #include "smsc95xx.h" |
| 24 | |
| 25 | #define SMSC_CHIPNAME "smsc95xx" |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 26 | #define SMSC_DRIVER_VERSION "2.0.0" |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 27 | #define HS_USB_PKT_SIZE (512) |
| 28 | #define FS_USB_PKT_SIZE (64) |
| 29 | #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) |
| 30 | #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) |
| 31 | #define DEFAULT_BULK_IN_DELAY (0x00002000) |
| 32 | #define MAX_SINGLE_PACKET_SIZE (2048) |
| 33 | #define LAN95XX_EEPROM_MAGIC (0x9500) |
| 34 | #define EEPROM_MAC_OFFSET (0x01) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 35 | #define DEFAULT_TX_CSUM_ENABLE (true) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 36 | #define DEFAULT_RX_CSUM_ENABLE (true) |
| 37 | #define SMSC95XX_INTERNAL_PHY_ID (1) |
| 38 | #define SMSC95XX_TX_OVERHEAD (8) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 39 | #define SMSC95XX_TX_OVERHEAD_CSUM (12) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 40 | #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 41 | WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 42 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 43 | #define FEATURE_8_WAKEUP_FILTERS (0x01) |
| 44 | #define FEATURE_PHY_NLP_CROSSOVER (0x02) |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 45 | #define FEATURE_REMOTE_WAKEUP (0x04) |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 46 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 47 | #define SUSPEND_SUSPEND0 (0x01) |
| 48 | #define SUSPEND_SUSPEND1 (0x02) |
| 49 | #define SUSPEND_SUSPEND2 (0x04) |
| 50 | #define SUSPEND_SUSPEND3 (0x08) |
| 51 | #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ |
| 52 | SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) |
| 53 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 54 | struct smsc95xx_priv { |
| 55 | u32 mac_cr; |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 56 | u32 hash_hi; |
| 57 | u32 hash_lo; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 58 | u32 wolopts; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 59 | spinlock_t mac_cr_lock; |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 60 | u8 features; |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 61 | u8 suspend_flags; |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 62 | struct mii_bus *mdiobus; |
| 63 | struct phy_device *phydev; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 66 | static bool turbo_mode = true; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 67 | module_param(turbo_mode, bool, 0644); |
| 68 | MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); |
| 69 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 70 | static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, |
| 71 | u32 *data, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 72 | { |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 73 | u32 buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 74 | int ret; |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 75 | int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 76 | |
| 77 | BUG_ON(!dev); |
| 78 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 79 | if (!in_pm) |
| 80 | fn = usbnet_read_cmd; |
| 81 | else |
| 82 | fn = usbnet_read_cmd_nopm; |
| 83 | |
| 84 | ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN |
| 85 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 86 | 0, index, &buf, 4); |
Dan Carpenter | 5a36b68 | 2016-05-04 09:22:01 +0300 | [diff] [blame] | 87 | if (unlikely(ret < 0)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 88 | netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", |
| 89 | index, ret); |
Dan Carpenter | 5a36b68 | 2016-05-04 09:22:01 +0300 | [diff] [blame] | 90 | return ret; |
| 91 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 92 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 93 | le32_to_cpus(&buf); |
| 94 | *data = buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 99 | static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index, |
| 100 | u32 data, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 101 | { |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 102 | u32 buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 103 | int ret; |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 104 | int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 105 | |
| 106 | BUG_ON(!dev); |
| 107 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 108 | if (!in_pm) |
| 109 | fn = usbnet_write_cmd; |
| 110 | else |
| 111 | fn = usbnet_write_cmd_nopm; |
| 112 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 113 | buf = data; |
| 114 | cpu_to_le32s(&buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 115 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 116 | ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT |
| 117 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 118 | 0, index, &buf, 4); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 119 | if (unlikely(ret < 0)) |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 120 | netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", |
| 121 | index, ret); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 122 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 123 | return ret; |
| 124 | } |
| 125 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 126 | static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index, |
| 127 | u32 *data) |
| 128 | { |
| 129 | return __smsc95xx_read_reg(dev, index, data, 1); |
| 130 | } |
| 131 | |
| 132 | static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index, |
| 133 | u32 data) |
| 134 | { |
| 135 | return __smsc95xx_write_reg(dev, index, data, 1); |
| 136 | } |
| 137 | |
| 138 | static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, |
| 139 | u32 *data) |
| 140 | { |
| 141 | return __smsc95xx_read_reg(dev, index, data, 0); |
| 142 | } |
| 143 | |
| 144 | static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, |
| 145 | u32 data) |
| 146 | { |
| 147 | return __smsc95xx_write_reg(dev, index, data, 0); |
| 148 | } |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 149 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 150 | /* Loop until the read is completed with timeout |
| 151 | * called with phy_mutex held */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 152 | static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev, |
| 153 | int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 154 | { |
| 155 | unsigned long start_time = jiffies; |
| 156 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 157 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 158 | |
| 159 | do { |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 160 | ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 161 | if (ret < 0) { |
| 162 | netdev_warn(dev->net, "Error reading MII_ACCESS\n"); |
| 163 | return ret; |
| 164 | } |
| 165 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 166 | if (!(val & MII_BUSY_)) |
| 167 | return 0; |
| 168 | } while (!time_after(jiffies, start_time + HZ)); |
| 169 | |
| 170 | return -EIO; |
| 171 | } |
| 172 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 173 | static u32 mii_address_cmd(int phy_id, int idx, u16 op) |
| 174 | { |
| 175 | return (phy_id & 0x1f) << 11 | (idx & 0x1f) << 6 | op; |
| 176 | } |
| 177 | |
| 178 | static int __smsc95xx_mdio_read(struct usbnet *dev, int phy_id, int idx, |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 179 | int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 180 | { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 181 | u32 val, addr; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 182 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 183 | |
| 184 | mutex_lock(&dev->phy_mutex); |
| 185 | |
| 186 | /* confirm MII not busy */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 187 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 188 | if (ret < 0) { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 189 | netdev_warn(dev->net, "%s: MII is busy\n", __func__); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 190 | goto done; |
| 191 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 192 | |
| 193 | /* set the address, index & direction (read from PHY) */ |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 194 | addr = mii_address_cmd(phy_id, idx, MII_READ_ | MII_BUSY_); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 195 | ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 196 | if (ret < 0) { |
| 197 | netdev_warn(dev->net, "Error writing MII_ADDR\n"); |
| 198 | goto done; |
| 199 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 200 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 201 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 202 | if (ret < 0) { |
| 203 | netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); |
| 204 | goto done; |
| 205 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 206 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 207 | ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 208 | if (ret < 0) { |
| 209 | netdev_warn(dev->net, "Error reading MII_DATA\n"); |
| 210 | goto done; |
| 211 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 212 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 213 | ret = (u16)(val & 0xFFFF); |
| 214 | |
| 215 | done: |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 216 | mutex_unlock(&dev->phy_mutex); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 217 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 220 | static void __smsc95xx_mdio_write(struct usbnet *dev, int phy_id, |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 221 | int idx, int regval, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 222 | { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 223 | u32 val, addr; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 224 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 225 | |
| 226 | mutex_lock(&dev->phy_mutex); |
| 227 | |
| 228 | /* confirm MII not busy */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 229 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 230 | if (ret < 0) { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 231 | netdev_warn(dev->net, "%s: MII is busy\n", __func__); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 232 | goto done; |
| 233 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 234 | |
| 235 | val = regval; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 236 | ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 237 | if (ret < 0) { |
| 238 | netdev_warn(dev->net, "Error writing MII_DATA\n"); |
| 239 | goto done; |
| 240 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 241 | |
| 242 | /* set the address, index & direction (write to PHY) */ |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 243 | addr = mii_address_cmd(phy_id, idx, MII_WRITE_ | MII_BUSY_); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 244 | ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 245 | if (ret < 0) { |
| 246 | netdev_warn(dev->net, "Error writing MII_ADDR\n"); |
| 247 | goto done; |
| 248 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 249 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 250 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 251 | if (ret < 0) { |
| 252 | netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); |
| 253 | goto done; |
| 254 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 255 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 256 | done: |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 257 | mutex_unlock(&dev->phy_mutex); |
| 258 | } |
| 259 | |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 260 | static int smsc95xx_mdio_read_nopm(struct usbnet *dev, int idx) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 261 | { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 262 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 263 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 264 | return __smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, idx, 1); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 267 | static void smsc95xx_mdio_write_nopm(struct usbnet *dev, int idx, int regval) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 268 | { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 269 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 270 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 271 | __smsc95xx_mdio_write(dev, pdata->phydev->mdio.addr, idx, regval, 1); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 274 | static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 275 | { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 276 | struct usbnet *dev = bus->priv; |
| 277 | |
| 278 | return __smsc95xx_mdio_read(dev, phy_id, idx, 0); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 281 | static int smsc95xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx, |
| 282 | u16 regval) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 283 | { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 284 | struct usbnet *dev = bus->priv; |
| 285 | |
| 286 | __smsc95xx_mdio_write(dev, phy_id, idx, regval, 0); |
| 287 | return 0; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 290 | static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 291 | { |
| 292 | unsigned long start_time = jiffies; |
| 293 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 294 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 295 | |
| 296 | do { |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 297 | ret = smsc95xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 298 | if (ret < 0) { |
| 299 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 300 | return ret; |
| 301 | } |
| 302 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 303 | if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) |
| 304 | break; |
| 305 | udelay(40); |
| 306 | } while (!time_after(jiffies, start_time + HZ)); |
| 307 | |
| 308 | if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 309 | netdev_warn(dev->net, "EEPROM read operation timeout\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 310 | return -EIO; |
| 311 | } |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 316 | static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 317 | { |
| 318 | unsigned long start_time = jiffies; |
| 319 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 320 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 321 | |
| 322 | do { |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 323 | ret = smsc95xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 324 | if (ret < 0) { |
| 325 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 326 | return ret; |
| 327 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 328 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 329 | if (!(val & E2P_CMD_BUSY_)) |
| 330 | return 0; |
| 331 | |
| 332 | udelay(40); |
| 333 | } while (!time_after(jiffies, start_time + HZ)); |
| 334 | |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 335 | netdev_warn(dev->net, "EEPROM is busy\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 336 | return -EIO; |
| 337 | } |
| 338 | |
| 339 | static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 340 | u8 *data) |
| 341 | { |
| 342 | u32 val; |
| 343 | int i, ret; |
| 344 | |
| 345 | BUG_ON(!dev); |
| 346 | BUG_ON(!data); |
| 347 | |
| 348 | ret = smsc95xx_eeprom_confirm_not_busy(dev); |
| 349 | if (ret) |
| 350 | return ret; |
| 351 | |
| 352 | for (i = 0; i < length; i++) { |
| 353 | val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 354 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 355 | if (ret < 0) { |
| 356 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 357 | return ret; |
| 358 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 359 | |
| 360 | ret = smsc95xx_wait_eeprom(dev); |
| 361 | if (ret < 0) |
| 362 | return ret; |
| 363 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 364 | ret = smsc95xx_read_reg(dev, E2P_DATA, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 365 | if (ret < 0) { |
| 366 | netdev_warn(dev->net, "Error reading E2P_DATA\n"); |
| 367 | return ret; |
| 368 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 369 | |
| 370 | data[i] = val & 0xFF; |
| 371 | offset++; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 378 | u8 *data) |
| 379 | { |
| 380 | u32 val; |
| 381 | int i, ret; |
| 382 | |
| 383 | BUG_ON(!dev); |
| 384 | BUG_ON(!data); |
| 385 | |
| 386 | ret = smsc95xx_eeprom_confirm_not_busy(dev); |
| 387 | if (ret) |
| 388 | return ret; |
| 389 | |
| 390 | /* Issue write/erase enable command */ |
| 391 | val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 392 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 393 | if (ret < 0) { |
| 394 | netdev_warn(dev->net, "Error writing E2P_DATA\n"); |
| 395 | return ret; |
| 396 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 397 | |
| 398 | ret = smsc95xx_wait_eeprom(dev); |
| 399 | if (ret < 0) |
| 400 | return ret; |
| 401 | |
| 402 | for (i = 0; i < length; i++) { |
| 403 | |
| 404 | /* Fill data register */ |
| 405 | val = data[i]; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 406 | ret = smsc95xx_write_reg(dev, E2P_DATA, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 407 | if (ret < 0) { |
| 408 | netdev_warn(dev->net, "Error writing E2P_DATA\n"); |
| 409 | return ret; |
| 410 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 411 | |
| 412 | /* Send "write" command */ |
| 413 | val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 414 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 415 | if (ret < 0) { |
| 416 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 417 | return ret; |
| 418 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 419 | |
| 420 | ret = smsc95xx_wait_eeprom(dev); |
| 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
| 424 | offset++; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 430 | static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 431 | u32 data) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 432 | { |
Steve Glendinning | 1d74a6b | 2008-10-09 14:34:47 -0700 | [diff] [blame] | 433 | const u16 size = 4; |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 434 | u32 buf; |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 435 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 436 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 437 | buf = data; |
| 438 | cpu_to_le32s(&buf); |
| 439 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 440 | ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, |
| 441 | USB_DIR_OUT | USB_TYPE_VENDOR | |
| 442 | USB_RECIP_DEVICE, |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 443 | 0, index, &buf, size); |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 444 | if (ret < 0) |
| 445 | netdev_warn(dev->net, "Error write async cmd, sts=%d\n", |
| 446 | ret); |
| 447 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* returns hash bit number for given MAC address |
| 451 | * example: |
| 452 | * 01 00 5E 00 00 01 -> returns bit number 31 */ |
| 453 | static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) |
| 454 | { |
| 455 | return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; |
| 456 | } |
| 457 | |
| 458 | static void smsc95xx_set_multicast(struct net_device *netdev) |
| 459 | { |
| 460 | struct usbnet *dev = netdev_priv(netdev); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 461 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 462 | unsigned long flags; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 463 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 464 | |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 465 | pdata->hash_hi = 0; |
| 466 | pdata->hash_lo = 0; |
| 467 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 468 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 469 | |
| 470 | if (dev->net->flags & IFF_PROMISC) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 471 | netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 472 | pdata->mac_cr |= MAC_CR_PRMS_; |
| 473 | pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); |
| 474 | } else if (dev->net->flags & IFF_ALLMULTI) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 475 | netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 476 | pdata->mac_cr |= MAC_CR_MCPAS_; |
| 477 | pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 478 | } else if (!netdev_mc_empty(dev->net)) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 479 | struct netdev_hw_addr *ha; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 480 | |
| 481 | pdata->mac_cr |= MAC_CR_HPFILT_; |
| 482 | pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); |
| 483 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 484 | netdev_for_each_mc_addr(ha, netdev) { |
| 485 | u32 bitnum = smsc95xx_hash(ha->addr); |
Jiri Pirko | a92635d | 2010-02-18 04:02:26 +0000 | [diff] [blame] | 486 | u32 mask = 0x01 << (bitnum & 0x1F); |
| 487 | if (bitnum & 0x20) |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 488 | pdata->hash_hi |= mask; |
Jiri Pirko | a92635d | 2010-02-18 04:02:26 +0000 | [diff] [blame] | 489 | else |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 490 | pdata->hash_lo |= mask; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 493 | netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 494 | pdata->hash_hi, pdata->hash_lo); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 495 | } else { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 496 | netif_dbg(dev, drv, dev->net, "receive own packets only\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 497 | pdata->mac_cr &= |
| 498 | ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); |
| 499 | } |
| 500 | |
| 501 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 502 | |
| 503 | /* Initiate async writes, as we can't wait for completion here */ |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 504 | ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 505 | if (ret < 0) |
| 506 | netdev_warn(dev->net, "failed to initiate async write to HASHH\n"); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 507 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 508 | ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 509 | if (ret < 0) |
| 510 | netdev_warn(dev->net, "failed to initiate async write to HASHL\n"); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 511 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 512 | ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 513 | if (ret < 0) |
| 514 | netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 517 | static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 518 | { |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 519 | u32 flow = 0, afc_cfg; |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 520 | struct smsc95xx_priv *pdata = dev->driver_priv; |
| 521 | bool tx_pause, rx_pause; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 522 | |
| 523 | int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 524 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 525 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 526 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 527 | if (pdata->phydev->duplex == DUPLEX_FULL) { |
| 528 | phy_get_pause(pdata->phydev, &tx_pause, &rx_pause); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 529 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 530 | if (rx_pause) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 531 | flow = 0xFFFF0002; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 532 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 533 | if (tx_pause) { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 534 | afc_cfg |= 0xF; |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 535 | flow |= 0xFFFF0000; |
| 536 | } else { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 537 | afc_cfg &= ~0xF; |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 538 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 539 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 540 | netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 541 | rx_pause ? "enabled" : "disabled", |
| 542 | tx_pause ? "enabled" : "disabled"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 543 | } else { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 544 | netif_dbg(dev, link, dev->net, "half duplex\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 545 | afc_cfg |= 0xF; |
| 546 | } |
| 547 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 548 | ret = smsc95xx_write_reg(dev, FLOW, flow); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 549 | if (ret < 0) |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 550 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 551 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 552 | return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static int smsc95xx_link_reset(struct usbnet *dev) |
| 556 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 557 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 558 | unsigned long flags; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 559 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 560 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 561 | ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 562 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 563 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 564 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 565 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 566 | if (pdata->phydev->duplex != DUPLEX_FULL) { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 567 | pdata->mac_cr &= ~MAC_CR_FDPX_; |
| 568 | pdata->mac_cr |= MAC_CR_RCVOWN_; |
| 569 | } else { |
| 570 | pdata->mac_cr &= ~MAC_CR_RCVOWN_; |
| 571 | pdata->mac_cr |= MAC_CR_FDPX_; |
| 572 | } |
| 573 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 574 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 575 | ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 576 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 577 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 578 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 579 | ret = smsc95xx_phy_update_flowcontrol(dev); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 580 | if (ret < 0) |
| 581 | netdev_warn(dev->net, "Error updating PHY flow control\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 582 | |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 583 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void smsc95xx_status(struct usbnet *dev, struct urb *urb) |
| 587 | { |
| 588 | u32 intdata; |
| 589 | |
| 590 | if (urb->actual_length != 4) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 591 | netdev_warn(dev->net, "unexpected urb length %d\n", |
| 592 | urb->actual_length); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 593 | return; |
| 594 | } |
| 595 | |
Ben Dooks | 6809d21 | 2018-11-14 11:50:21 +0000 | [diff] [blame] | 596 | intdata = get_unaligned_le32(urb->transfer_buffer); |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 597 | netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 598 | |
| 599 | if (intdata & INT_ENP_PHY_INT_) |
| 600 | usbnet_defer_kevent(dev, EVENT_LINK_RESET); |
| 601 | else |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 602 | netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", |
| 603 | intdata); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 606 | /* Enable or disable Tx & Rx checksum offload engines */ |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 607 | static int smsc95xx_set_features(struct net_device *netdev, |
| 608 | netdev_features_t features) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 609 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 610 | struct usbnet *dev = netdev_priv(netdev); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 611 | u32 read_buf; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 612 | int ret; |
| 613 | |
| 614 | ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 615 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 616 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 617 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 618 | if (features & NETIF_F_IP_CSUM) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 619 | read_buf |= Tx_COE_EN_; |
| 620 | else |
| 621 | read_buf &= ~Tx_COE_EN_; |
| 622 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 623 | if (features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 624 | read_buf |= Rx_COE_EN_; |
| 625 | else |
| 626 | read_buf &= ~Rx_COE_EN_; |
| 627 | |
| 628 | ret = smsc95xx_write_reg(dev, COE_CR, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 629 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 630 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 631 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 632 | netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) |
| 637 | { |
| 638 | return MAX_EEPROM_SIZE; |
| 639 | } |
| 640 | |
| 641 | static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, |
| 642 | struct ethtool_eeprom *ee, u8 *data) |
| 643 | { |
| 644 | struct usbnet *dev = netdev_priv(netdev); |
| 645 | |
| 646 | ee->magic = LAN95XX_EEPROM_MAGIC; |
| 647 | |
| 648 | return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); |
| 649 | } |
| 650 | |
| 651 | static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, |
| 652 | struct ethtool_eeprom *ee, u8 *data) |
| 653 | { |
| 654 | struct usbnet *dev = netdev_priv(netdev); |
| 655 | |
| 656 | if (ee->magic != LAN95XX_EEPROM_MAGIC) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 657 | netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", |
| 658 | ee->magic); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 659 | return -EINVAL; |
| 660 | } |
| 661 | |
| 662 | return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); |
| 663 | } |
| 664 | |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 665 | static int smsc95xx_ethtool_getregslen(struct net_device *netdev) |
| 666 | { |
| 667 | /* all smsc95xx registers */ |
Steve Glendinning | 9624531 | 2012-12-10 01:03:07 +0000 | [diff] [blame] | 668 | return COE_CR - ID_REV + sizeof(u32); |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | static void |
| 672 | smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, |
| 673 | void *buf) |
| 674 | { |
| 675 | struct usbnet *dev = netdev_priv(netdev); |
Dan Carpenter | d348446 | 2012-07-10 20:32:51 +0000 | [diff] [blame] | 676 | unsigned int i, j; |
| 677 | int retval; |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 678 | u32 *data = buf; |
| 679 | |
| 680 | retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); |
| 681 | if (retval < 0) { |
| 682 | netdev_warn(netdev, "REGS: cannot read ID_REV\n"); |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { |
| 687 | retval = smsc95xx_read_reg(dev, i, &data[j]); |
| 688 | if (retval < 0) { |
| 689 | netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); |
| 690 | return; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 695 | static void smsc95xx_ethtool_get_wol(struct net_device *net, |
| 696 | struct ethtool_wolinfo *wolinfo) |
| 697 | { |
| 698 | struct usbnet *dev = netdev_priv(net); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 699 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 700 | |
| 701 | wolinfo->supported = SUPPORTED_WAKE; |
| 702 | wolinfo->wolopts = pdata->wolopts; |
| 703 | } |
| 704 | |
| 705 | static int smsc95xx_ethtool_set_wol(struct net_device *net, |
| 706 | struct ethtool_wolinfo *wolinfo) |
| 707 | { |
| 708 | struct usbnet *dev = netdev_priv(net); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 709 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 710 | int ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 711 | |
Florian Fainelli | c530c47 | 2018-09-28 16:18:56 -0700 | [diff] [blame] | 712 | if (wolinfo->wolopts & ~SUPPORTED_WAKE) |
| 713 | return -EINVAL; |
| 714 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 715 | pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 716 | |
| 717 | ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 718 | if (ret < 0) |
| 719 | netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 720 | |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 721 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 724 | static u32 smsc95xx_get_link(struct net_device *net) |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 725 | { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 726 | phy_read_status(net->phydev); |
| 727 | return net->phydev->link; |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 730 | static const struct ethtool_ops smsc95xx_ethtool_ops = { |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 731 | .get_link = smsc95xx_get_link, |
| 732 | .nway_reset = phy_ethtool_nway_reset, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 733 | .get_drvinfo = usbnet_get_drvinfo, |
| 734 | .get_msglevel = usbnet_get_msglevel, |
| 735 | .set_msglevel = usbnet_set_msglevel, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 736 | .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, |
| 737 | .get_eeprom = smsc95xx_ethtool_get_eeprom, |
| 738 | .set_eeprom = smsc95xx_ethtool_set_eeprom, |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 739 | .get_regs_len = smsc95xx_ethtool_getregslen, |
| 740 | .get_regs = smsc95xx_ethtool_getregs, |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 741 | .get_wol = smsc95xx_ethtool_get_wol, |
| 742 | .set_wol = smsc95xx_ethtool_set_wol, |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 743 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 744 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Petr Kulhavy | a8f5cb9 | 2017-07-13 19:40:57 +0200 | [diff] [blame] | 745 | .get_ts_info = ethtool_op_get_ts_info, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 746 | }; |
| 747 | |
| 748 | static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
| 749 | { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 750 | if (!netif_running(netdev)) |
| 751 | return -EINVAL; |
| 752 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 753 | return phy_mii_ioctl(netdev->phydev, rq, cmd); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | static void smsc95xx_init_mac_address(struct usbnet *dev) |
| 757 | { |
Jakub Kicinski | a7021af | 2021-10-21 06:12:04 -0700 | [diff] [blame] | 758 | u8 addr[ETH_ALEN]; |
| 759 | |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 760 | /* maybe the boot loader passed the MAC address in devicetree */ |
Jakub Kicinski | 4d04cdc | 2021-10-07 11:18:47 -0700 | [diff] [blame] | 761 | if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) { |
Łukasz Stelmach | 4f359b6 | 2020-09-30 16:25:25 +0200 | [diff] [blame] | 762 | if (is_valid_ether_addr(dev->net->dev_addr)) { |
| 763 | /* device tree values are valid so use them */ |
| 764 | netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n"); |
| 765 | return; |
| 766 | } |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 767 | } |
| 768 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 769 | /* try reading mac address from EEPROM */ |
Jakub Kicinski | a7021af | 2021-10-21 06:12:04 -0700 | [diff] [blame] | 770 | if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) { |
| 771 | eth_hw_addr_set(dev->net, addr); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 772 | if (is_valid_ether_addr(dev->net->dev_addr)) { |
| 773 | /* eeprom values are valid so use them */ |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 774 | netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | } |
| 778 | |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 779 | /* no useful static MAC address found. generate a random one */ |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 780 | eth_hw_addr_random(dev->net); |
Joe Perches | c7e12ea | 2012-07-12 19:33:07 +0000 | [diff] [blame] | 781 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static int smsc95xx_set_mac_address(struct usbnet *dev) |
| 785 | { |
| 786 | u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | |
| 787 | dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; |
| 788 | u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; |
| 789 | int ret; |
| 790 | |
| 791 | ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 792 | if (ret < 0) |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 793 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 794 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 795 | return smsc95xx_write_reg(dev, ADDRH, addr_hi); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* starts the TX path */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 799 | static int smsc95xx_start_tx_path(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 800 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 801 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 802 | unsigned long flags; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 803 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 804 | |
| 805 | /* Enable Tx at MAC */ |
| 806 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 807 | pdata->mac_cr |= MAC_CR_TXEN_; |
| 808 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 809 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 810 | ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 811 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 812 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 813 | |
| 814 | /* Enable Tx at SCSRs */ |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 815 | return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | /* Starts the Receive path */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 819 | static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 820 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 821 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 822 | unsigned long flags; |
| 823 | |
| 824 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 825 | pdata->mac_cr |= MAC_CR_RXEN_; |
| 826 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 827 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 828 | return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 831 | static int smsc95xx_reset(struct usbnet *dev) |
| 832 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 833 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 834 | u32 read_buf, write_buf, burst_cap; |
| 835 | int ret = 0, timeout; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 836 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 837 | netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 838 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 839 | ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 840 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 841 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 842 | |
| 843 | timeout = 0; |
| 844 | do { |
Steve Glendinning | cf2acec | 2012-09-28 00:07:07 +0000 | [diff] [blame] | 845 | msleep(10); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 846 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 847 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 848 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 849 | timeout++; |
| 850 | } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); |
| 851 | |
| 852 | if (timeout >= 100) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 853 | netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 854 | return ret; |
| 855 | } |
| 856 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 857 | ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 858 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 859 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 860 | |
| 861 | timeout = 0; |
| 862 | do { |
Steve Glendinning | cf2acec | 2012-09-28 00:07:07 +0000 | [diff] [blame] | 863 | msleep(10); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 864 | ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 865 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 866 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 867 | timeout++; |
| 868 | } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); |
| 869 | |
| 870 | if (timeout >= 100) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 871 | netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 872 | return ret; |
| 873 | } |
| 874 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 875 | ret = smsc95xx_set_mac_address(dev); |
| 876 | if (ret < 0) |
| 877 | return ret; |
| 878 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 879 | netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", |
| 880 | dev->net->dev_addr); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 881 | |
| 882 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 883 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 884 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 885 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 886 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", |
| 887 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 888 | |
| 889 | read_buf |= HW_CFG_BIR_; |
| 890 | |
| 891 | ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 892 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 893 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 894 | |
| 895 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 896 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 897 | return ret; |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 898 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 899 | netif_dbg(dev, ifup, dev->net, |
| 900 | "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", |
| 901 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 902 | |
| 903 | if (!turbo_mode) { |
| 904 | burst_cap = 0; |
| 905 | dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; |
| 906 | } else if (dev->udev->speed == USB_SPEED_HIGH) { |
| 907 | burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; |
| 908 | dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; |
| 909 | } else { |
| 910 | burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; |
| 911 | dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; |
| 912 | } |
| 913 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 914 | netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", |
| 915 | (ulong)dev->rx_urb_size); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 916 | |
| 917 | ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 918 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 919 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 920 | |
| 921 | ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 922 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 923 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 924 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 925 | netif_dbg(dev, ifup, dev->net, |
| 926 | "Read Value from BURST_CAP after writing: 0x%08x\n", |
| 927 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 928 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 929 | ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 930 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 931 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 932 | |
| 933 | ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 934 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 935 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 936 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 937 | netif_dbg(dev, ifup, dev->net, |
| 938 | "Read Value from BULK_IN_DLY after writing: 0x%08x\n", |
| 939 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 940 | |
| 941 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 942 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 943 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 944 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 945 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", |
| 946 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 947 | |
| 948 | if (turbo_mode) |
| 949 | read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); |
| 950 | |
| 951 | read_buf &= ~HW_CFG_RXDOFF_; |
| 952 | |
| 953 | /* set Rx data offset=2, Make IP header aligns on word boundary. */ |
| 954 | read_buf |= NET_IP_ALIGN << 9; |
| 955 | |
| 956 | ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 957 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 958 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 959 | |
| 960 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 961 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 962 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 963 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 964 | netif_dbg(dev, ifup, dev->net, |
| 965 | "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 966 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 967 | ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 968 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 969 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 970 | |
| 971 | ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 972 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 973 | return ret; |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 974 | netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 975 | |
Steve Glendinning | f293501 | 2009-05-01 05:46:51 +0000 | [diff] [blame] | 976 | /* Configure GPIO pins as LED outputs */ |
| 977 | write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | |
| 978 | LED_GPIO_CFG_FDX_LED; |
| 979 | ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 980 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 981 | return ret; |
Steve Glendinning | f293501 | 2009-05-01 05:46:51 +0000 | [diff] [blame] | 982 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 983 | /* Init Tx */ |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 984 | ret = smsc95xx_write_reg(dev, FLOW, 0); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 985 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 986 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 987 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 988 | ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 989 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 990 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 991 | |
| 992 | /* Don't need mac_cr_lock during initialisation */ |
| 993 | ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 994 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 995 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 996 | |
| 997 | /* Init Rx */ |
| 998 | /* Set Vlan */ |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 999 | ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1000 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1001 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1002 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1003 | /* Enable or disable checksum offload engines */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1004 | ret = smsc95xx_set_features(dev->net, dev->net->features); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1005 | if (ret < 0) { |
| 1006 | netdev_warn(dev->net, "Failed to set checksum offload features\n"); |
| 1007 | return ret; |
| 1008 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1009 | |
| 1010 | smsc95xx_set_multicast(dev->net); |
| 1011 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1012 | ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1013 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1014 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1015 | |
| 1016 | /* enable PHY interrupts */ |
| 1017 | read_buf |= INT_EP_CTL_PHY_INT_; |
| 1018 | |
| 1019 | ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1020 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1021 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1022 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1023 | ret = smsc95xx_start_tx_path(dev); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1024 | if (ret < 0) { |
| 1025 | netdev_warn(dev->net, "Failed to start TX path\n"); |
| 1026 | return ret; |
| 1027 | } |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1028 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1029 | ret = smsc95xx_start_rx_path(dev, 0); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1030 | if (ret < 0) { |
| 1031 | netdev_warn(dev->net, "Failed to start RX path\n"); |
| 1032 | return ret; |
| 1033 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1034 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1035 | netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1039 | static const struct net_device_ops smsc95xx_netdev_ops = { |
| 1040 | .ndo_open = usbnet_open, |
| 1041 | .ndo_stop = usbnet_stop, |
| 1042 | .ndo_start_xmit = usbnet_start_xmit, |
| 1043 | .ndo_tx_timeout = usbnet_tx_timeout, |
| 1044 | .ndo_change_mtu = usbnet_change_mtu, |
Heiner Kallweit | 323955a | 2020-11-10 20:51:03 +0100 | [diff] [blame] | 1045 | .ndo_get_stats64 = dev_get_tstats64, |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1046 | .ndo_set_mac_address = eth_mac_addr, |
| 1047 | .ndo_validate_addr = eth_validate_addr, |
Arnd Bergmann | a760537 | 2021-07-27 15:45:13 +0200 | [diff] [blame] | 1048 | .ndo_eth_ioctl = smsc95xx_ioctl, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1049 | .ndo_set_rx_mode = smsc95xx_set_multicast, |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1050 | .ndo_set_features = smsc95xx_set_features, |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1051 | }; |
| 1052 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1053 | static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) |
| 1054 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1055 | struct smsc95xx_priv *pdata; |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1056 | bool is_internal_phy; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1057 | u32 val; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1058 | int ret; |
| 1059 | |
| 1060 | printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); |
| 1061 | |
| 1062 | ret = usbnet_get_endpoints(dev, intf); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1063 | if (ret < 0) { |
| 1064 | netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); |
| 1065 | return ret; |
| 1066 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1067 | |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1068 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
Joe Perches | 38673c8 | 2013-02-03 17:28:11 +0000 | [diff] [blame] | 1069 | if (!pdata) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1070 | return -ENOMEM; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1071 | |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1072 | dev->driver_priv = pdata; |
| 1073 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1074 | spin_lock_init(&pdata->mac_cr_lock); |
| 1075 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1076 | /* LAN95xx devices do not alter the computed checksum of 0 to 0xffff. |
| 1077 | * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must |
| 1078 | * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero, |
| 1079 | * it is transmitted as all ones. The zero transmitted checksum means |
| 1080 | * transmitter generated no checksum. Hence, enable csum offload only |
| 1081 | * for ipv4 packets. |
| 1082 | */ |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1083 | if (DEFAULT_TX_CSUM_ENABLE) |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1084 | dev->net->features |= NETIF_F_IP_CSUM; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1085 | if (DEFAULT_RX_CSUM_ENABLE) |
| 1086 | dev->net->features |= NETIF_F_RXCSUM; |
| 1087 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1088 | dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
Ben Dooks | 810eeb1 | 2018-11-14 11:50:19 +0000 | [diff] [blame] | 1089 | set_bit(EVENT_NO_IP_ALIGN, &dev->flags); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1090 | |
Bernard Blackham | f4e8ab7 | 2010-10-18 13:16:39 +0000 | [diff] [blame] | 1091 | smsc95xx_init_mac_address(dev); |
| 1092 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1093 | /* Init all registers */ |
| 1094 | ret = smsc95xx_reset(dev); |
Andre Edich | 7c8b1e8 | 2020-07-06 10:39:34 +0200 | [diff] [blame] | 1095 | if (ret) |
| 1096 | goto free_pdata; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1097 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1098 | pdata->mdiobus = mdiobus_alloc(); |
| 1099 | if (!pdata->mdiobus) { |
| 1100 | ret = -ENOMEM; |
| 1101 | goto free_pdata; |
| 1102 | } |
| 1103 | |
| 1104 | ret = smsc95xx_read_reg(dev, HW_CFG, &val); |
| 1105 | if (ret < 0) |
| 1106 | goto free_mdio; |
| 1107 | |
| 1108 | is_internal_phy = !(val & HW_CFG_PSEL_); |
| 1109 | if (is_internal_phy) |
| 1110 | pdata->mdiobus->phy_mask = ~(1u << SMSC95XX_INTERNAL_PHY_ID); |
| 1111 | |
| 1112 | pdata->mdiobus->priv = dev; |
| 1113 | pdata->mdiobus->read = smsc95xx_mdiobus_read; |
| 1114 | pdata->mdiobus->write = smsc95xx_mdiobus_write; |
| 1115 | pdata->mdiobus->name = "smsc95xx-mdiobus"; |
| 1116 | pdata->mdiobus->parent = &dev->udev->dev; |
| 1117 | |
| 1118 | snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id), |
| 1119 | "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum); |
| 1120 | |
| 1121 | ret = mdiobus_register(pdata->mdiobus); |
| 1122 | if (ret) { |
| 1123 | netdev_err(dev->net, "Could not register MDIO bus\n"); |
| 1124 | goto free_mdio; |
| 1125 | } |
| 1126 | |
| 1127 | pdata->phydev = phy_find_first(pdata->mdiobus); |
| 1128 | if (!pdata->phydev) { |
| 1129 | netdev_err(dev->net, "no PHY found\n"); |
| 1130 | ret = -ENODEV; |
| 1131 | goto unregister_mdio; |
| 1132 | } |
| 1133 | |
| 1134 | pdata->phydev->is_internal = is_internal_phy; |
| 1135 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1136 | /* detect device revision as different features may be available */ |
| 1137 | ret = smsc95xx_read_reg(dev, ID_REV, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1138 | if (ret < 0) |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1139 | goto unregister_mdio; |
Andre Edich | 3ed58f9 | 2020-07-06 10:39:35 +0200 | [diff] [blame] | 1140 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1141 | val >>= 16; |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1142 | if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || |
| 1143 | (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) |
| 1144 | pdata->features = (FEATURE_8_WAKEUP_FILTERS | |
| 1145 | FEATURE_PHY_NLP_CROSSOVER | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1146 | FEATURE_REMOTE_WAKEUP); |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1147 | else if (val == ID_REV_CHIP_ID_9512_) |
| 1148 | pdata->features = FEATURE_8_WAKEUP_FILTERS; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1149 | |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1150 | dev->net->netdev_ops = &smsc95xx_netdev_ops; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1151 | dev->net->ethtool_ops = &smsc95xx_ethtool_ops; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1152 | dev->net->flags |= IFF_MULTICAST; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1153 | dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; |
Stefan Wahren | 85b18b0 | 2018-11-08 20:38:26 +0100 | [diff] [blame] | 1154 | dev->net->min_mtu = ETH_MIN_MTU; |
| 1155 | dev->net->max_mtu = ETH_DATA_LEN; |
Stephane Fillod | 9bbf566 | 2012-04-20 09:39:23 +0000 | [diff] [blame] | 1156 | dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1157 | return 0; |
Andre Edich | 7c8b1e8 | 2020-07-06 10:39:34 +0200 | [diff] [blame] | 1158 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1159 | unregister_mdio: |
| 1160 | mdiobus_unregister(pdata->mdiobus); |
| 1161 | |
| 1162 | free_mdio: |
| 1163 | mdiobus_free(pdata->mdiobus); |
| 1164 | |
Andre Edich | 7c8b1e8 | 2020-07-06 10:39:34 +0200 | [diff] [blame] | 1165 | free_pdata: |
| 1166 | kfree(pdata); |
| 1167 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 1171 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1172 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 1173 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1174 | mdiobus_unregister(pdata->mdiobus); |
| 1175 | mdiobus_free(pdata->mdiobus); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1176 | netif_dbg(dev, ifdown, dev->net, "free pdata\n"); |
| 1177 | kfree(pdata); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1180 | static void smsc95xx_handle_link_change(struct net_device *net) |
| 1181 | { |
Aaro Koskinen | 5ab8a44 | 2021-09-24 01:00:16 +0300 | [diff] [blame] | 1182 | struct usbnet *dev = netdev_priv(net); |
| 1183 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1184 | phy_print_status(net->phydev); |
Aaro Koskinen | 5ab8a44 | 2021-09-24 01:00:16 +0300 | [diff] [blame] | 1185 | usbnet_defer_kevent(dev, EVENT_LINK_CHANGE); |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | static int smsc95xx_start_phy(struct usbnet *dev) |
| 1189 | { |
| 1190 | struct smsc95xx_priv *pdata = dev->driver_priv; |
| 1191 | struct net_device *net = dev->net; |
| 1192 | int ret; |
| 1193 | |
| 1194 | ret = smsc95xx_reset(dev); |
| 1195 | if (ret < 0) |
| 1196 | return ret; |
| 1197 | |
| 1198 | ret = phy_connect_direct(net, pdata->phydev, |
| 1199 | &smsc95xx_handle_link_change, |
| 1200 | PHY_INTERFACE_MODE_MII); |
| 1201 | if (ret) { |
| 1202 | netdev_err(net, "can't attach PHY to %s\n", pdata->mdiobus->id); |
| 1203 | return ret; |
| 1204 | } |
| 1205 | |
| 1206 | phy_attached_info(net->phydev); |
| 1207 | phy_start(net->phydev); |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | static int smsc95xx_disconnect_phy(struct usbnet *dev) |
| 1212 | { |
| 1213 | phy_stop(dev->net->phydev); |
| 1214 | phy_disconnect(dev->net->phydev); |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Steve Glendinning | 068bb1a | 2012-11-30 05:55:51 +0000 | [diff] [blame] | 1218 | static u32 smsc_crc(const u8 *buffer, size_t len, int filter) |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1219 | { |
Steve Glendinning | 068bb1a | 2012-11-30 05:55:51 +0000 | [diff] [blame] | 1220 | u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); |
| 1221 | return crc << ((filter % 2) * 16); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1224 | static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) |
| 1225 | { |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1226 | int ret; |
| 1227 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1228 | netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1229 | |
| 1230 | /* read to clear */ |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1231 | ret = smsc95xx_mdio_read_nopm(dev, PHY_INT_SRC); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1232 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1233 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1234 | |
| 1235 | /* enable interrupt source */ |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1236 | ret = smsc95xx_mdio_read_nopm(dev, PHY_INT_MASK); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1237 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1238 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1239 | |
| 1240 | ret |= mask; |
| 1241 | |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1242 | smsc95xx_mdio_write_nopm(dev, PHY_INT_MASK, ret); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | static int smsc95xx_link_ok_nopm(struct usbnet *dev) |
| 1248 | { |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1249 | int ret; |
| 1250 | |
| 1251 | /* first, a dummy read, needed to latch some MII phys */ |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1252 | ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1253 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1254 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1255 | |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1256 | ret = smsc95xx_mdio_read_nopm(dev, MII_BMSR); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1257 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1258 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1259 | |
| 1260 | return !!(ret & BMSR_LSTATUS); |
| 1261 | } |
| 1262 | |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1263 | static int smsc95xx_enter_suspend0(struct usbnet *dev) |
| 1264 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1265 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1266 | u32 val; |
| 1267 | int ret; |
| 1268 | |
| 1269 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1270 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1271 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1272 | |
| 1273 | val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); |
| 1274 | val |= PM_CTL_SUS_MODE_0; |
| 1275 | |
| 1276 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1277 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1278 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1279 | |
| 1280 | /* clear wol status */ |
| 1281 | val &= ~PM_CTL_WUPS_; |
| 1282 | val |= PM_CTL_WUPS_WOL_; |
| 1283 | |
| 1284 | /* enable energy detection */ |
| 1285 | if (pdata->wolopts & WAKE_PHY) |
| 1286 | val |= PM_CTL_WUPS_ED_; |
| 1287 | |
| 1288 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1289 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1290 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1291 | |
| 1292 | /* read back PM_CTRL */ |
| 1293 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1294 | if (ret < 0) |
| 1295 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1296 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1297 | pdata->suspend_flags |= SUSPEND_SUSPEND0; |
| 1298 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1299 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | static int smsc95xx_enter_suspend1(struct usbnet *dev) |
| 1303 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1304 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1305 | u32 val; |
| 1306 | int ret; |
| 1307 | |
| 1308 | /* reconfigure link pulse detection timing for |
| 1309 | * compatibility with non-standard link partners |
| 1310 | */ |
| 1311 | if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1312 | smsc95xx_mdio_write_nopm(dev, PHY_EDPD_CONFIG, |
| 1313 | PHY_EDPD_CONFIG_DEFAULT); |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1314 | |
| 1315 | /* enable energy detect power-down mode */ |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1316 | ret = smsc95xx_mdio_read_nopm(dev, PHY_MODE_CTRL_STS); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1317 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1318 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1319 | |
| 1320 | ret |= MODE_CTRL_STS_EDPWRDOWN_; |
| 1321 | |
Andre Edich | 368be1c | 2020-08-26 13:17:15 +0200 | [diff] [blame] | 1322 | smsc95xx_mdio_write_nopm(dev, PHY_MODE_CTRL_STS, ret); |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1323 | |
| 1324 | /* enter SUSPEND1 mode */ |
| 1325 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1326 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1327 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1328 | |
| 1329 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1330 | val |= PM_CTL_SUS_MODE_1; |
| 1331 | |
| 1332 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1333 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1334 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1335 | |
| 1336 | /* clear wol status, enable energy detection */ |
| 1337 | val &= ~PM_CTL_WUPS_; |
| 1338 | val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); |
| 1339 | |
| 1340 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1341 | if (ret < 0) |
| 1342 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1343 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1344 | pdata->suspend_flags |= SUSPEND_SUSPEND1; |
| 1345 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1346 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static int smsc95xx_enter_suspend2(struct usbnet *dev) |
| 1350 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1351 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1352 | u32 val; |
| 1353 | int ret; |
| 1354 | |
| 1355 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1356 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1357 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1358 | |
| 1359 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1360 | val |= PM_CTL_SUS_MODE_2; |
| 1361 | |
| 1362 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1363 | if (ret < 0) |
| 1364 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1365 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1366 | pdata->suspend_flags |= SUSPEND_SUSPEND2; |
| 1367 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1368 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1371 | static int smsc95xx_enter_suspend3(struct usbnet *dev) |
| 1372 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1373 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1374 | u32 val; |
| 1375 | int ret; |
| 1376 | |
| 1377 | ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val); |
| 1378 | if (ret < 0) |
| 1379 | return ret; |
| 1380 | |
Martin Wetterwald | 53a759c | 2017-04-13 10:08:44 +0200 | [diff] [blame] | 1381 | if (val & RX_FIFO_INF_USED_) { |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1382 | netdev_info(dev->net, "rx fifo not empty in autosuspend\n"); |
| 1383 | return -EBUSY; |
| 1384 | } |
| 1385 | |
| 1386 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
| 1387 | if (ret < 0) |
| 1388 | return ret; |
| 1389 | |
| 1390 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1391 | val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS; |
| 1392 | |
| 1393 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
| 1394 | if (ret < 0) |
| 1395 | return ret; |
| 1396 | |
| 1397 | /* clear wol status */ |
| 1398 | val &= ~PM_CTL_WUPS_; |
| 1399 | val |= PM_CTL_WUPS_WOL_; |
| 1400 | |
| 1401 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
| 1402 | if (ret < 0) |
| 1403 | return ret; |
| 1404 | |
| 1405 | pdata->suspend_flags |= SUSPEND_SUSPEND3; |
| 1406 | |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up) |
| 1411 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1412 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1413 | int ret; |
| 1414 | |
| 1415 | if (!netif_running(dev->net)) { |
| 1416 | /* interface is ifconfig down so fully power down hw */ |
| 1417 | netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); |
| 1418 | return smsc95xx_enter_suspend2(dev); |
| 1419 | } |
| 1420 | |
| 1421 | if (!link_up) { |
| 1422 | /* link is down so enter EDPD mode, but only if device can |
| 1423 | * reliably resume from it. This check should be redundant |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1424 | * as current FEATURE_REMOTE_WAKEUP parts also support |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1425 | * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */ |
| 1426 | if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) { |
| 1427 | netdev_warn(dev->net, "EDPD not supported\n"); |
| 1428 | return -EBUSY; |
| 1429 | } |
| 1430 | |
| 1431 | netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); |
| 1432 | |
| 1433 | /* enable PHY wakeup events for if cable is attached */ |
| 1434 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1435 | PHY_INT_MASK_ANEG_COMP_); |
| 1436 | if (ret < 0) { |
| 1437 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1438 | return ret; |
| 1439 | } |
| 1440 | |
| 1441 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
| 1442 | return smsc95xx_enter_suspend1(dev); |
| 1443 | } |
| 1444 | |
| 1445 | /* enable PHY wakeup events so we remote wakeup if cable is pulled */ |
| 1446 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1447 | PHY_INT_MASK_LINK_DOWN_); |
| 1448 | if (ret < 0) { |
| 1449 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
| 1453 | netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); |
| 1454 | return smsc95xx_enter_suspend3(dev); |
| 1455 | } |
| 1456 | |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1457 | static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) |
| 1458 | { |
| 1459 | struct usbnet *dev = usb_get_intfdata(intf); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1460 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1461 | u32 val, link_up; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1462 | int ret; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1463 | |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1464 | ret = usbnet_suspend(intf, message); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1465 | if (ret < 0) { |
| 1466 | netdev_warn(dev->net, "usbnet_suspend error\n"); |
| 1467 | return ret; |
| 1468 | } |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1469 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1470 | if (pdata->suspend_flags) { |
| 1471 | netdev_warn(dev->net, "error during last resume\n"); |
| 1472 | pdata->suspend_flags = 0; |
| 1473 | } |
| 1474 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1475 | /* determine if link is up using only _nopm functions */ |
| 1476 | link_up = smsc95xx_link_ok_nopm(dev); |
| 1477 | |
Ming Lei | 42e21c0 | 2013-02-22 03:05:04 +0000 | [diff] [blame] | 1478 | if (message.event == PM_EVENT_AUTO_SUSPEND && |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1479 | (pdata->features & FEATURE_REMOTE_WAKEUP)) { |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1480 | ret = smsc95xx_autosuspend(dev, link_up); |
| 1481 | goto done; |
| 1482 | } |
| 1483 | |
| 1484 | /* if we get this far we're not autosuspending */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1485 | /* if no wol options set, or if link is down and we're not waking on |
| 1486 | * PHY activity, enter lowest power SUSPEND2 mode |
| 1487 | */ |
| 1488 | if (!(pdata->wolopts & SUPPORTED_WAKE) || |
| 1489 | !(link_up || (pdata->wolopts & WAKE_PHY))) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1490 | netdev_info(dev->net, "entering SUSPEND2 mode\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1491 | |
| 1492 | /* disable energy detect (link up) & wake up events */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1493 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1494 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1495 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1496 | |
| 1497 | val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); |
| 1498 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1499 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1500 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1501 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1502 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1503 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1504 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1505 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1506 | |
| 1507 | val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); |
| 1508 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1509 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1510 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1511 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1512 | |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1513 | ret = smsc95xx_enter_suspend2(dev); |
| 1514 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1517 | if (pdata->wolopts & WAKE_PHY) { |
| 1518 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1519 | (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1520 | if (ret < 0) { |
| 1521 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1522 | goto done; |
| 1523 | } |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1524 | |
| 1525 | /* if link is down then configure EDPD and enter SUSPEND1, |
| 1526 | * otherwise enter SUSPEND0 below |
| 1527 | */ |
| 1528 | if (!link_up) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1529 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1530 | ret = smsc95xx_enter_suspend1(dev); |
| 1531 | goto done; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1535 | if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1536 | u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL); |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1537 | u32 command[2]; |
| 1538 | u32 offset[2]; |
| 1539 | u32 crc[4]; |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1540 | int wuff_filter_count = |
| 1541 | (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? |
| 1542 | LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1543 | int i, filter = 0; |
| 1544 | |
Steve Glendinning | eed9a72 | 2012-11-30 05:55:48 +0000 | [diff] [blame] | 1545 | if (!filter_mask) { |
| 1546 | netdev_warn(dev->net, "Unable to allocate filter_mask\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1547 | ret = -ENOMEM; |
| 1548 | goto done; |
Steve Glendinning | eed9a72 | 2012-11-30 05:55:48 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1551 | memset(command, 0, sizeof(command)); |
| 1552 | memset(offset, 0, sizeof(offset)); |
| 1553 | memset(crc, 0, sizeof(crc)); |
| 1554 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1555 | if (pdata->wolopts & WAKE_BCAST) { |
| 1556 | const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1557 | netdev_info(dev->net, "enabling broadcast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1558 | filter_mask[filter * 4] = 0x003F; |
| 1559 | filter_mask[filter * 4 + 1] = 0x00; |
| 1560 | filter_mask[filter * 4 + 2] = 0x00; |
| 1561 | filter_mask[filter * 4 + 3] = 0x00; |
| 1562 | command[filter/4] |= 0x05UL << ((filter % 4) * 8); |
| 1563 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1564 | crc[filter/2] |= smsc_crc(bcast, 6, filter); |
| 1565 | filter++; |
| 1566 | } |
| 1567 | |
| 1568 | if (pdata->wolopts & WAKE_MCAST) { |
| 1569 | const u8 mcast[] = {0x01, 0x00, 0x5E}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1570 | netdev_info(dev->net, "enabling multicast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1571 | filter_mask[filter * 4] = 0x0007; |
| 1572 | filter_mask[filter * 4 + 1] = 0x00; |
| 1573 | filter_mask[filter * 4 + 2] = 0x00; |
| 1574 | filter_mask[filter * 4 + 3] = 0x00; |
| 1575 | command[filter/4] |= 0x09UL << ((filter % 4) * 8); |
| 1576 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1577 | crc[filter/2] |= smsc_crc(mcast, 3, filter); |
| 1578 | filter++; |
| 1579 | } |
| 1580 | |
| 1581 | if (pdata->wolopts & WAKE_ARP) { |
| 1582 | const u8 arp[] = {0x08, 0x06}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1583 | netdev_info(dev->net, "enabling ARP detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1584 | filter_mask[filter * 4] = 0x0003; |
| 1585 | filter_mask[filter * 4 + 1] = 0x00; |
| 1586 | filter_mask[filter * 4 + 2] = 0x00; |
| 1587 | filter_mask[filter * 4 + 3] = 0x00; |
| 1588 | command[filter/4] |= 0x05UL << ((filter % 4) * 8); |
| 1589 | offset[filter/4] |= 0x0C << ((filter % 4) * 8); |
| 1590 | crc[filter/2] |= smsc_crc(arp, 2, filter); |
| 1591 | filter++; |
| 1592 | } |
| 1593 | |
| 1594 | if (pdata->wolopts & WAKE_UCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1595 | netdev_info(dev->net, "enabling unicast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1596 | filter_mask[filter * 4] = 0x003F; |
| 1597 | filter_mask[filter * 4 + 1] = 0x00; |
| 1598 | filter_mask[filter * 4 + 2] = 0x00; |
| 1599 | filter_mask[filter * 4 + 3] = 0x00; |
| 1600 | command[filter/4] |= 0x01UL << ((filter % 4) * 8); |
| 1601 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1602 | crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); |
| 1603 | filter++; |
| 1604 | } |
| 1605 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1606 | for (i = 0; i < (wuff_filter_count * 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1607 | ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1608 | if (ret < 0) { |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1609 | kfree(filter_mask); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1610 | goto done; |
| 1611 | } |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1612 | } |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1613 | kfree(filter_mask); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1614 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1615 | for (i = 0; i < (wuff_filter_count / 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1616 | ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1617 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1618 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1621 | for (i = 0; i < (wuff_filter_count / 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1622 | ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1623 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1624 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1627 | for (i = 0; i < (wuff_filter_count / 2); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1628 | ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1629 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1630 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | /* clear any pending pattern match packet status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1634 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1635 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1636 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1637 | |
| 1638 | val |= WUCSR_WUFR_; |
| 1639 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1640 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1641 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1642 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1645 | if (pdata->wolopts & WAKE_MAGIC) { |
| 1646 | /* clear any pending magic packet status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1647 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1648 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1649 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1650 | |
| 1651 | val |= WUCSR_MPR_; |
| 1652 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1653 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1654 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1655 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1658 | /* enable/disable wakeup sources */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1659 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1660 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1661 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1662 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1663 | if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1664 | netdev_info(dev->net, "enabling pattern match wakeup\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1665 | val |= WUCSR_WAKE_EN_; |
| 1666 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1667 | netdev_info(dev->net, "disabling pattern match wakeup\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1668 | val &= ~WUCSR_WAKE_EN_; |
| 1669 | } |
| 1670 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1671 | if (pdata->wolopts & WAKE_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1672 | netdev_info(dev->net, "enabling magic packet wakeup\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1673 | val |= WUCSR_MPEN_; |
| 1674 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1675 | netdev_info(dev->net, "disabling magic packet wakeup\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1676 | val &= ~WUCSR_MPEN_; |
| 1677 | } |
| 1678 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1679 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1680 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1681 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1682 | |
| 1683 | /* enable wol wakeup source */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1684 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1685 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1686 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1687 | |
| 1688 | val |= PM_CTL_WOL_EN_; |
| 1689 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1690 | /* phy energy detect wakeup source */ |
| 1691 | if (pdata->wolopts & WAKE_PHY) |
| 1692 | val |= PM_CTL_ED_EN_; |
| 1693 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1694 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1695 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1696 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1697 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1698 | /* enable receiver to enable frame reception */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1699 | smsc95xx_start_rx_path(dev, 1); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1700 | |
| 1701 | /* some wol options are enabled, so enter SUSPEND0 */ |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1702 | netdev_info(dev->net, "entering SUSPEND0 mode\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1703 | ret = smsc95xx_enter_suspend0(dev); |
| 1704 | |
| 1705 | done: |
Ming Lei | 0d41be5 | 2013-03-15 12:08:58 +0800 | [diff] [blame] | 1706 | /* |
| 1707 | * TODO: resume() might need to handle the suspend failure |
| 1708 | * in system sleep |
| 1709 | */ |
| 1710 | if (ret && PMSG_IS_AUTO(message)) |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1711 | usbnet_resume(intf); |
Frieder Schrempf | 7b900ea | 2018-10-31 22:52:19 +0100 | [diff] [blame] | 1712 | |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1713 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | static int smsc95xx_resume(struct usb_interface *intf) |
| 1717 | { |
| 1718 | struct usbnet *dev = usb_get_intfdata(intf); |
Sudip Mukherjee | 8bca81d | 2014-11-11 14:10:47 +0530 | [diff] [blame] | 1719 | struct smsc95xx_priv *pdata; |
| 1720 | u8 suspend_flags; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1721 | int ret; |
| 1722 | u32 val; |
| 1723 | |
| 1724 | BUG_ON(!dev); |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1725 | pdata = dev->driver_priv; |
Sudip Mukherjee | 8bca81d | 2014-11-11 14:10:47 +0530 | [diff] [blame] | 1726 | suspend_flags = pdata->suspend_flags; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1727 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1728 | netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); |
| 1729 | |
| 1730 | /* do this first to ensure it's cleared even in error case */ |
| 1731 | pdata->suspend_flags = 0; |
| 1732 | |
| 1733 | if (suspend_flags & SUSPEND_ALLMODES) { |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1734 | /* clear wake-up sources */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1735 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1736 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1737 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1738 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1739 | val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1740 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1741 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1742 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1743 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1744 | |
| 1745 | /* clear wake-up status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1746 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1747 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1748 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1749 | |
| 1750 | val &= ~PM_CTL_WOL_EN_; |
| 1751 | val |= PM_CTL_WUPS_; |
| 1752 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1753 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1754 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1755 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
Steve Glendinning | af3d7c1 | 2012-11-22 08:05:22 +0000 | [diff] [blame] | 1758 | ret = usbnet_resume(intf); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1759 | if (ret < 0) |
| 1760 | netdev_warn(dev->net, "usbnet_resume error\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1761 | |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1762 | phy_init_hw(pdata->phydev); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1763 | return ret; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Joonyoung Shim | b4df480 | 2014-07-10 11:49:42 +0900 | [diff] [blame] | 1766 | static int smsc95xx_reset_resume(struct usb_interface *intf) |
| 1767 | { |
| 1768 | struct usbnet *dev = usb_get_intfdata(intf); |
| 1769 | int ret; |
| 1770 | |
| 1771 | ret = smsc95xx_reset(dev); |
| 1772 | if (ret < 0) |
| 1773 | return ret; |
| 1774 | |
| 1775 | return smsc95xx_resume(intf); |
| 1776 | } |
| 1777 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1778 | static void smsc95xx_rx_csum_offload(struct sk_buff *skb) |
| 1779 | { |
| 1780 | skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); |
| 1781 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1782 | skb_trim(skb, skb->len - 2); |
| 1783 | } |
| 1784 | |
| 1785 | static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
| 1786 | { |
Emil Goode | eb85569 | 2014-02-13 17:50:19 +0100 | [diff] [blame] | 1787 | /* This check is no longer done by usbnet */ |
| 1788 | if (skb->len < dev->net->hard_header_len) |
| 1789 | return 0; |
| 1790 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1791 | while (skb->len > 0) { |
| 1792 | u32 header, align_count; |
| 1793 | struct sk_buff *ax_skb; |
| 1794 | unsigned char *packet; |
| 1795 | u16 size; |
| 1796 | |
Ben Dooks | 6809d21 | 2018-11-14 11:50:21 +0000 | [diff] [blame] | 1797 | header = get_unaligned_le32(skb->data); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1798 | skb_pull(skb, 4 + NET_IP_ALIGN); |
| 1799 | packet = skb->data; |
| 1800 | |
| 1801 | /* get the packet length */ |
| 1802 | size = (u16)((header & RX_STS_FL_) >> 16); |
| 1803 | align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; |
| 1804 | |
| 1805 | if (unlikely(header & RX_STS_ES_)) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1806 | netif_dbg(dev, rx_err, dev->net, |
| 1807 | "Error header=0x%08x\n", header); |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1808 | dev->net->stats.rx_errors++; |
| 1809 | dev->net->stats.rx_dropped++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1810 | |
| 1811 | if (header & RX_STS_CRC_) { |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1812 | dev->net->stats.rx_crc_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1813 | } else { |
| 1814 | if (header & (RX_STS_TL_ | RX_STS_RF_)) |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1815 | dev->net->stats.rx_frame_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1816 | |
| 1817 | if ((header & RX_STS_LE_) && |
| 1818 | (!(header & RX_STS_FT_))) |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1819 | dev->net->stats.rx_length_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1820 | } |
| 1821 | } else { |
| 1822 | /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ |
| 1823 | if (unlikely(size > (ETH_FRAME_LEN + 12))) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1824 | netif_dbg(dev, rx_err, dev->net, |
| 1825 | "size err header=0x%08x\n", header); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | /* last frame in this batch */ |
| 1830 | if (skb->len == size) { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1831 | if (dev->net->features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1832 | smsc95xx_rx_csum_offload(skb); |
Peter Korsgaard | df18acc | 2009-05-13 10:10:41 +0000 | [diff] [blame] | 1833 | skb_trim(skb, skb->len - 4); /* remove fcs */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1834 | skb->truesize = size + sizeof(struct sk_buff); |
| 1835 | |
| 1836 | return 1; |
| 1837 | } |
| 1838 | |
| 1839 | ax_skb = skb_clone(skb, GFP_ATOMIC); |
| 1840 | if (unlikely(!ax_skb)) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 1841 | netdev_warn(dev->net, "Error allocating skb\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | ax_skb->len = size; |
| 1846 | ax_skb->data = packet; |
| 1847 | skb_set_tail_pointer(ax_skb, size); |
| 1848 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1849 | if (dev->net->features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1850 | smsc95xx_rx_csum_offload(ax_skb); |
Peter Korsgaard | df18acc | 2009-05-13 10:10:41 +0000 | [diff] [blame] | 1851 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1852 | ax_skb->truesize = size + sizeof(struct sk_buff); |
| 1853 | |
| 1854 | usbnet_skb_return(dev, ax_skb); |
| 1855 | } |
| 1856 | |
| 1857 | skb_pull(skb, size); |
| 1858 | |
| 1859 | /* padding bytes before the next frame starts */ |
| 1860 | if (skb->len) |
| 1861 | skb_pull(skb, align_count); |
| 1862 | } |
| 1863 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1864 | return 1; |
| 1865 | } |
| 1866 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1867 | static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) |
| 1868 | { |
Michał Mirosław | 55508d6 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 1869 | u16 low_16 = (u16)skb_checksum_start_offset(skb); |
| 1870 | u16 high_16 = low_16 + skb->csum_offset; |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1871 | return (high_16 << 16) | low_16; |
| 1872 | } |
| 1873 | |
Ben Dooks | 75938f7 | 2018-11-14 11:50:22 +0000 | [diff] [blame] | 1874 | /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the |
| 1875 | * transmission. This is fairly unlikely, only seems to trigger with some |
| 1876 | * short TCP ACK packets sent. |
| 1877 | * |
| 1878 | * Note, this calculation should probably check for the alignment of the |
| 1879 | * data as well, but a straight check for csum being in the last four bytes |
| 1880 | * of the packet should be ok for now. |
| 1881 | */ |
| 1882 | static bool smsc95xx_can_tx_checksum(struct sk_buff *skb) |
| 1883 | { |
| 1884 | unsigned int len = skb->len - skb_checksum_start_offset(skb); |
| 1885 | |
| 1886 | if (skb->len <= 45) |
| 1887 | return false; |
| 1888 | return skb->csum_offset < (len - (4 + 1)); |
| 1889 | } |
| 1890 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1891 | static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, |
| 1892 | struct sk_buff *skb, gfp_t flags) |
| 1893 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1894 | bool csum = skb->ip_summed == CHECKSUM_PARTIAL; |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1895 | int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1896 | u32 tx_cmd_a, tx_cmd_b; |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 1897 | void *ptr; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1898 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1899 | /* We do not advertise SG, so skbs should be already linearized */ |
| 1900 | BUG_ON(skb_shinfo(skb)->nr_frags); |
| 1901 | |
James Hughes | e9156cd | 2017-04-19 11:13:40 +0100 | [diff] [blame] | 1902 | /* Make writable and expand header space by overhead if required */ |
| 1903 | if (skb_cow_head(skb, overhead)) { |
| 1904 | /* Must deallocate here as returning NULL to indicate error |
| 1905 | * means the skb won't be deallocated in the caller. |
| 1906 | */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1907 | dev_kfree_skb_any(skb); |
James Hughes | e9156cd | 2017-04-19 11:13:40 +0100 | [diff] [blame] | 1908 | return NULL; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 1911 | tx_cmd_b = (u32)skb->len; |
| 1912 | tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; |
| 1913 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1914 | if (csum) { |
Ben Dooks | 75938f7 | 2018-11-14 11:50:22 +0000 | [diff] [blame] | 1915 | if (!smsc95xx_can_tx_checksum(skb)) { |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 1916 | /* workaround - hardware tx checksum does not work |
| 1917 | * properly with extremely small packets */ |
Michał Mirosław | 55508d6 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 1918 | long csstart = skb_checksum_start_offset(skb); |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 1919 | __wsum calc = csum_partial(skb->data + csstart, |
| 1920 | skb->len - csstart, 0); |
| 1921 | *((__sum16 *)(skb->data + csstart |
| 1922 | + skb->csum_offset)) = csum_fold(calc); |
| 1923 | |
| 1924 | csum = false; |
| 1925 | } else { |
| 1926 | u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 1927 | ptr = skb_push(skb, 4); |
| 1928 | put_unaligned_le32(csum_preamble, ptr); |
| 1929 | |
| 1930 | tx_cmd_a += 4; |
| 1931 | tx_cmd_b += 4; |
| 1932 | tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 1933 | } |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 1936 | ptr = skb_push(skb, 8); |
| 1937 | put_unaligned_le32(tx_cmd_a, ptr); |
| 1938 | put_unaligned_le32(tx_cmd_b, ptr+4); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1939 | |
| 1940 | return skb; |
| 1941 | } |
| 1942 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1943 | static int smsc95xx_manage_power(struct usbnet *dev, int on) |
| 1944 | { |
Andre Edich | ad90a73 | 2020-08-26 13:17:16 +0200 | [diff] [blame] | 1945 | struct smsc95xx_priv *pdata = dev->driver_priv; |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1946 | |
| 1947 | dev->intf->needs_remote_wakeup = on; |
| 1948 | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1949 | if (pdata->features & FEATURE_REMOTE_WAKEUP) |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1950 | return 0; |
| 1951 | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1952 | /* this chip revision isn't capable of remote wakeup */ |
| 1953 | netdev_info(dev->net, "hardware isn't capable of remote wakeup\n"); |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1954 | |
| 1955 | if (on) |
| 1956 | usb_autopm_get_interface_no_resume(dev->intf); |
| 1957 | else |
| 1958 | usb_autopm_put_interface(dev->intf); |
| 1959 | |
| 1960 | return 0; |
| 1961 | } |
| 1962 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1963 | static const struct driver_info smsc95xx_info = { |
| 1964 | .description = "smsc95xx USB 2.0 Ethernet", |
| 1965 | .bind = smsc95xx_bind, |
| 1966 | .unbind = smsc95xx_unbind, |
| 1967 | .link_reset = smsc95xx_link_reset, |
Andre Edich | 05b35e7 | 2020-08-26 13:17:17 +0200 | [diff] [blame] | 1968 | .reset = smsc95xx_start_phy, |
| 1969 | .stop = smsc95xx_disconnect_phy, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1970 | .rx_fixup = smsc95xx_rx_fixup, |
| 1971 | .tx_fixup = smsc95xx_tx_fixup, |
| 1972 | .status = smsc95xx_status, |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1973 | .manage_power = smsc95xx_manage_power, |
Paolo Pisati | 07d69d4 | 2012-04-23 04:05:20 +0000 | [diff] [blame] | 1974 | .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1975 | }; |
| 1976 | |
| 1977 | static const struct usb_device_id products[] = { |
| 1978 | { |
| 1979 | /* SMSC9500 USB Ethernet Device */ |
| 1980 | USB_DEVICE(0x0424, 0x9500), |
| 1981 | .driver_info = (unsigned long) &smsc95xx_info, |
| 1982 | }, |
Steve Glendinning | 726474b | 2009-05-01 06:07:22 +0000 | [diff] [blame] | 1983 | { |
Steve Glendinning | 6f41d12 | 2009-09-22 05:13:02 +0000 | [diff] [blame] | 1984 | /* SMSC9505 USB Ethernet Device */ |
| 1985 | USB_DEVICE(0x0424, 0x9505), |
| 1986 | .driver_info = (unsigned long) &smsc95xx_info, |
| 1987 | }, |
| 1988 | { |
| 1989 | /* SMSC9500A USB Ethernet Device */ |
| 1990 | USB_DEVICE(0x0424, 0x9E00), |
| 1991 | .driver_info = (unsigned long) &smsc95xx_info, |
| 1992 | }, |
| 1993 | { |
| 1994 | /* SMSC9505A USB Ethernet Device */ |
| 1995 | USB_DEVICE(0x0424, 0x9E01), |
| 1996 | .driver_info = (unsigned long) &smsc95xx_info, |
| 1997 | }, |
| 1998 | { |
Steve Glendinning | 726474b | 2009-05-01 06:07:22 +0000 | [diff] [blame] | 1999 | /* SMSC9512/9514 USB Hub & Ethernet Device */ |
| 2000 | USB_DEVICE(0x0424, 0xec00), |
| 2001 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2002 | }, |
Steve Glendinning | 6f41d12 | 2009-09-22 05:13:02 +0000 | [diff] [blame] | 2003 | { |
| 2004 | /* SMSC9500 USB Ethernet Device (SAL10) */ |
| 2005 | USB_DEVICE(0x0424, 0x9900), |
| 2006 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2007 | }, |
| 2008 | { |
| 2009 | /* SMSC9505 USB Ethernet Device (SAL10) */ |
| 2010 | USB_DEVICE(0x0424, 0x9901), |
| 2011 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2012 | }, |
| 2013 | { |
| 2014 | /* SMSC9500A USB Ethernet Device (SAL10) */ |
| 2015 | USB_DEVICE(0x0424, 0x9902), |
| 2016 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2017 | }, |
| 2018 | { |
| 2019 | /* SMSC9505A USB Ethernet Device (SAL10) */ |
| 2020 | USB_DEVICE(0x0424, 0x9903), |
| 2021 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2022 | }, |
| 2023 | { |
| 2024 | /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ |
| 2025 | USB_DEVICE(0x0424, 0x9904), |
| 2026 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2027 | }, |
| 2028 | { |
| 2029 | /* SMSC9500A USB Ethernet Device (HAL) */ |
| 2030 | USB_DEVICE(0x0424, 0x9905), |
| 2031 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2032 | }, |
| 2033 | { |
| 2034 | /* SMSC9505A USB Ethernet Device (HAL) */ |
| 2035 | USB_DEVICE(0x0424, 0x9906), |
| 2036 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2037 | }, |
| 2038 | { |
| 2039 | /* SMSC9500 USB Ethernet Device (Alternate ID) */ |
| 2040 | USB_DEVICE(0x0424, 0x9907), |
| 2041 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2042 | }, |
| 2043 | { |
| 2044 | /* SMSC9500A USB Ethernet Device (Alternate ID) */ |
| 2045 | USB_DEVICE(0x0424, 0x9908), |
| 2046 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2047 | }, |
| 2048 | { |
| 2049 | /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ |
| 2050 | USB_DEVICE(0x0424, 0x9909), |
| 2051 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2052 | }, |
Steve Glendinning | 88edaa4 | 2011-04-10 18:59:27 -0700 | [diff] [blame] | 2053 | { |
| 2054 | /* SMSC LAN9530 USB Ethernet Device */ |
| 2055 | USB_DEVICE(0x0424, 0x9530), |
| 2056 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2057 | }, |
| 2058 | { |
| 2059 | /* SMSC LAN9730 USB Ethernet Device */ |
| 2060 | USB_DEVICE(0x0424, 0x9730), |
| 2061 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2062 | }, |
| 2063 | { |
| 2064 | /* SMSC LAN89530 USB Ethernet Device */ |
| 2065 | USB_DEVICE(0x0424, 0x9E08), |
| 2066 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2067 | }, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2068 | { }, /* END */ |
| 2069 | }; |
| 2070 | MODULE_DEVICE_TABLE(usb, products); |
| 2071 | |
| 2072 | static struct usb_driver smsc95xx_driver = { |
| 2073 | .name = "smsc95xx", |
| 2074 | .id_table = products, |
| 2075 | .probe = usbnet_probe, |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 2076 | .suspend = smsc95xx_suspend, |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 2077 | .resume = smsc95xx_resume, |
Joonyoung Shim | b4df480 | 2014-07-10 11:49:42 +0900 | [diff] [blame] | 2078 | .reset_resume = smsc95xx_reset_resume, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2079 | .disconnect = usbnet_disconnect, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 2080 | .disable_hub_initiated_lpm = 1, |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2081 | .supports_autosuspend = 1, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2082 | }; |
| 2083 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 2084 | module_usb_driver(smsc95xx_driver); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2085 | |
| 2086 | MODULE_AUTHOR("Nancy Lin"); |
Steve Glendinning | 90b24cf | 2012-04-16 12:13:29 +0100 | [diff] [blame] | 2087 | MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2088 | MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); |
| 2089 | MODULE_LICENSE("GPL"); |