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