Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2007-2010 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 |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | *****************************************************************************/ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/kmod.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/ethtool.h> |
| 27 | #include <linux/mii.h> |
| 28 | #include <linux/usb.h> |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 29 | #include <linux/bitrev.h> |
| 30 | #include <linux/crc16.h> |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 31 | #include <linux/crc32.h> |
| 32 | #include <linux/usb/usbnet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 34 | #include "smsc75xx.h" |
| 35 | |
| 36 | #define SMSC_CHIPNAME "smsc75xx" |
| 37 | #define SMSC_DRIVER_VERSION "1.0.0" |
| 38 | #define HS_USB_PKT_SIZE (512) |
| 39 | #define FS_USB_PKT_SIZE (64) |
| 40 | #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) |
| 41 | #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) |
| 42 | #define DEFAULT_BULK_IN_DELAY (0x00002000) |
| 43 | #define MAX_SINGLE_PACKET_SIZE (9000) |
| 44 | #define LAN75XX_EEPROM_MAGIC (0x7500) |
| 45 | #define EEPROM_MAC_OFFSET (0x01) |
| 46 | #define DEFAULT_TX_CSUM_ENABLE (true) |
| 47 | #define DEFAULT_RX_CSUM_ENABLE (true) |
| 48 | #define DEFAULT_TSO_ENABLE (true) |
| 49 | #define SMSC75XX_INTERNAL_PHY_ID (1) |
| 50 | #define SMSC75XX_TX_OVERHEAD (8) |
| 51 | #define MAX_RX_FIFO_SIZE (20 * 1024) |
| 52 | #define MAX_TX_FIFO_SIZE (12 * 1024) |
| 53 | #define USB_VENDOR_ID_SMSC (0x0424) |
| 54 | #define USB_PRODUCT_ID_LAN7500 (0x7500) |
| 55 | #define USB_PRODUCT_ID_LAN7505 (0x7505) |
Nico Erfurth | ea1649d | 2011-11-08 07:30:40 +0000 | [diff] [blame] | 56 | #define RXW_PADDING 2 |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 57 | #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 58 | WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 59 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 60 | #define SUSPEND_SUSPEND0 (0x01) |
| 61 | #define SUSPEND_SUSPEND1 (0x02) |
| 62 | #define SUSPEND_SUSPEND2 (0x04) |
| 63 | #define SUSPEND_SUSPEND3 (0x08) |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 64 | #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ |
| 65 | SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) |
| 66 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 67 | struct smsc75xx_priv { |
| 68 | struct usbnet *dev; |
| 69 | u32 rfe_ctl; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 70 | u32 wolopts; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 71 | u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN]; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 72 | struct mutex dataport_mutex; |
| 73 | spinlock_t rfe_ctl_lock; |
| 74 | struct work_struct set_multicast; |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 75 | u8 suspend_flags; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | struct usb_context { |
| 79 | struct usb_ctrlrequest req; |
| 80 | struct usbnet *dev; |
| 81 | }; |
| 82 | |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 83 | static bool turbo_mode = true; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 84 | module_param(turbo_mode, bool, 0644); |
| 85 | MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); |
| 86 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 87 | static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index, |
| 88 | u32 *data, int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 89 | { |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 90 | u32 buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 91 | int ret; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 92 | int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 93 | |
| 94 | BUG_ON(!dev); |
| 95 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 96 | if (!in_pm) |
| 97 | fn = usbnet_read_cmd; |
| 98 | else |
| 99 | fn = usbnet_read_cmd_nopm; |
| 100 | |
| 101 | ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN |
| 102 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 103 | 0, index, &buf, 4); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 104 | if (unlikely(ret < 0)) |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 105 | netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", |
| 106 | index, ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 107 | |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 108 | le32_to_cpus(&buf); |
| 109 | *data = buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 114 | static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index, |
| 115 | u32 data, int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 116 | { |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 117 | u32 buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 118 | int ret; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 119 | int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 120 | |
| 121 | BUG_ON(!dev); |
| 122 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 123 | if (!in_pm) |
| 124 | fn = usbnet_write_cmd; |
| 125 | else |
| 126 | fn = usbnet_write_cmd_nopm; |
| 127 | |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 128 | buf = data; |
| 129 | cpu_to_le32s(&buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 130 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +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 | d0cad87 | 2010-03-16 08:46:46 +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 | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 137 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 138 | return ret; |
| 139 | } |
| 140 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 141 | static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index, |
| 142 | u32 *data) |
| 143 | { |
| 144 | return __smsc75xx_read_reg(dev, index, data, 1); |
| 145 | } |
| 146 | |
| 147 | static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index, |
| 148 | u32 data) |
| 149 | { |
| 150 | return __smsc75xx_write_reg(dev, index, data, 1); |
| 151 | } |
| 152 | |
| 153 | static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index, |
| 154 | u32 *data) |
| 155 | { |
| 156 | return __smsc75xx_read_reg(dev, index, data, 0); |
| 157 | } |
| 158 | |
| 159 | static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index, |
| 160 | u32 data) |
| 161 | { |
| 162 | return __smsc75xx_write_reg(dev, index, data, 0); |
| 163 | } |
| 164 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 165 | /* Loop until the read is completed with timeout |
| 166 | * called with phy_mutex held */ |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 167 | static __must_check int __smsc75xx_phy_wait_not_busy(struct usbnet *dev, |
| 168 | int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 169 | { |
| 170 | unsigned long start_time = jiffies; |
| 171 | u32 val; |
| 172 | int ret; |
| 173 | |
| 174 | do { |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 175 | ret = __smsc75xx_read_reg(dev, MII_ACCESS, &val, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 176 | if (ret < 0) { |
| 177 | netdev_warn(dev->net, "Error reading MII_ACCESS\n"); |
| 178 | return ret; |
| 179 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 180 | |
| 181 | if (!(val & MII_ACCESS_BUSY)) |
| 182 | return 0; |
| 183 | } while (!time_after(jiffies, start_time + HZ)); |
| 184 | |
| 185 | return -EIO; |
| 186 | } |
| 187 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 188 | static int __smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx, |
| 189 | int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 190 | { |
| 191 | struct usbnet *dev = netdev_priv(netdev); |
| 192 | u32 val, addr; |
| 193 | int ret; |
| 194 | |
| 195 | mutex_lock(&dev->phy_mutex); |
| 196 | |
| 197 | /* confirm MII not busy */ |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 198 | ret = __smsc75xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 199 | if (ret < 0) { |
| 200 | netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_read\n"); |
| 201 | goto done; |
| 202 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +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; |
| 207 | addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) |
| 208 | | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) |
Steve Glendinning | cb8722d | 2012-04-30 07:56:51 +0000 | [diff] [blame] | 209 | | MII_ACCESS_READ | MII_ACCESS_BUSY; |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 210 | ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 211 | if (ret < 0) { |
| 212 | netdev_warn(dev->net, "Error writing MII_ACCESS\n"); |
| 213 | goto done; |
| 214 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 215 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 216 | ret = __smsc75xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 217 | if (ret < 0) { |
| 218 | netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); |
| 219 | goto done; |
| 220 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 221 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 222 | ret = __smsc75xx_read_reg(dev, MII_DATA, &val, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 223 | if (ret < 0) { |
| 224 | netdev_warn(dev->net, "Error reading MII_DATA\n"); |
| 225 | goto done; |
| 226 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 227 | |
| 228 | ret = (u16)(val & 0xFFFF); |
| 229 | |
| 230 | done: |
| 231 | mutex_unlock(&dev->phy_mutex); |
| 232 | return ret; |
| 233 | } |
| 234 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 235 | static void __smsc75xx_mdio_write(struct net_device *netdev, int phy_id, |
| 236 | int idx, int regval, int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 237 | { |
| 238 | struct usbnet *dev = netdev_priv(netdev); |
| 239 | u32 val, addr; |
| 240 | int ret; |
| 241 | |
| 242 | mutex_lock(&dev->phy_mutex); |
| 243 | |
| 244 | /* confirm MII not busy */ |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 245 | ret = __smsc75xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 246 | if (ret < 0) { |
| 247 | netdev_warn(dev->net, "MII is busy in smsc75xx_mdio_write\n"); |
| 248 | goto done; |
| 249 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 250 | |
| 251 | val = regval; |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 252 | ret = __smsc75xx_write_reg(dev, MII_DATA, val, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 253 | if (ret < 0) { |
| 254 | netdev_warn(dev->net, "Error writing MII_DATA\n"); |
| 255 | goto done; |
| 256 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 257 | |
| 258 | /* set the address, index & direction (write to PHY) */ |
| 259 | phy_id &= dev->mii.phy_id_mask; |
| 260 | idx &= dev->mii.reg_num_mask; |
| 261 | addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) |
| 262 | | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) |
Steve Glendinning | cb8722d | 2012-04-30 07:56:51 +0000 | [diff] [blame] | 263 | | MII_ACCESS_WRITE | MII_ACCESS_BUSY; |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 264 | ret = __smsc75xx_write_reg(dev, MII_ACCESS, addr, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 265 | if (ret < 0) { |
| 266 | netdev_warn(dev->net, "Error writing MII_ACCESS\n"); |
| 267 | goto done; |
| 268 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 269 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 270 | ret = __smsc75xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 271 | if (ret < 0) { |
| 272 | netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); |
| 273 | goto done; |
| 274 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 275 | |
| 276 | done: |
| 277 | mutex_unlock(&dev->phy_mutex); |
| 278 | } |
| 279 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 280 | static int smsc75xx_mdio_read_nopm(struct net_device *netdev, int phy_id, |
| 281 | int idx) |
| 282 | { |
| 283 | return __smsc75xx_mdio_read(netdev, phy_id, idx, 1); |
| 284 | } |
| 285 | |
| 286 | static void smsc75xx_mdio_write_nopm(struct net_device *netdev, int phy_id, |
| 287 | int idx, int regval) |
| 288 | { |
| 289 | __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 1); |
| 290 | } |
| 291 | |
| 292 | static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx) |
| 293 | { |
| 294 | return __smsc75xx_mdio_read(netdev, phy_id, idx, 0); |
| 295 | } |
| 296 | |
| 297 | static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx, |
| 298 | int regval) |
| 299 | { |
| 300 | __smsc75xx_mdio_write(netdev, phy_id, idx, regval, 0); |
| 301 | } |
| 302 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 303 | static int smsc75xx_wait_eeprom(struct usbnet *dev) |
| 304 | { |
| 305 | unsigned long start_time = jiffies; |
| 306 | u32 val; |
| 307 | int ret; |
| 308 | |
| 309 | do { |
| 310 | ret = smsc75xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 311 | if (ret < 0) { |
| 312 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 313 | return ret; |
| 314 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 315 | |
| 316 | if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT)) |
| 317 | break; |
| 318 | udelay(40); |
| 319 | } while (!time_after(jiffies, start_time + HZ)); |
| 320 | |
| 321 | if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 322 | netdev_warn(dev->net, "EEPROM read operation timeout\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 323 | return -EIO; |
| 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev) |
| 330 | { |
| 331 | unsigned long start_time = jiffies; |
| 332 | u32 val; |
| 333 | int ret; |
| 334 | |
| 335 | do { |
| 336 | ret = smsc75xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 337 | if (ret < 0) { |
| 338 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 339 | return ret; |
| 340 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 341 | |
| 342 | if (!(val & E2P_CMD_BUSY)) |
| 343 | return 0; |
| 344 | |
| 345 | udelay(40); |
| 346 | } while (!time_after(jiffies, start_time + HZ)); |
| 347 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 348 | netdev_warn(dev->net, "EEPROM is busy\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 349 | return -EIO; |
| 350 | } |
| 351 | |
| 352 | static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 353 | u8 *data) |
| 354 | { |
| 355 | u32 val; |
| 356 | int i, ret; |
| 357 | |
| 358 | BUG_ON(!dev); |
| 359 | BUG_ON(!data); |
| 360 | |
| 361 | ret = smsc75xx_eeprom_confirm_not_busy(dev); |
| 362 | if (ret) |
| 363 | return ret; |
| 364 | |
| 365 | for (i = 0; i < length; i++) { |
| 366 | val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR); |
| 367 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 368 | if (ret < 0) { |
| 369 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 370 | return ret; |
| 371 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 372 | |
| 373 | ret = smsc75xx_wait_eeprom(dev); |
| 374 | if (ret < 0) |
| 375 | return ret; |
| 376 | |
| 377 | ret = smsc75xx_read_reg(dev, E2P_DATA, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 378 | if (ret < 0) { |
| 379 | netdev_warn(dev->net, "Error reading E2P_DATA\n"); |
| 380 | return ret; |
| 381 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 382 | |
| 383 | data[i] = val & 0xFF; |
| 384 | offset++; |
| 385 | } |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 391 | u8 *data) |
| 392 | { |
| 393 | u32 val; |
| 394 | int i, ret; |
| 395 | |
| 396 | BUG_ON(!dev); |
| 397 | BUG_ON(!data); |
| 398 | |
| 399 | ret = smsc75xx_eeprom_confirm_not_busy(dev); |
| 400 | if (ret) |
| 401 | return ret; |
| 402 | |
| 403 | /* Issue write/erase enable command */ |
| 404 | val = E2P_CMD_BUSY | E2P_CMD_EWEN; |
| 405 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 406 | if (ret < 0) { |
| 407 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 408 | return ret; |
| 409 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 410 | |
| 411 | ret = smsc75xx_wait_eeprom(dev); |
| 412 | if (ret < 0) |
| 413 | return ret; |
| 414 | |
| 415 | for (i = 0; i < length; i++) { |
| 416 | |
| 417 | /* Fill data register */ |
| 418 | val = data[i]; |
| 419 | ret = smsc75xx_write_reg(dev, E2P_DATA, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 420 | if (ret < 0) { |
| 421 | netdev_warn(dev->net, "Error writing E2P_DATA\n"); |
| 422 | return ret; |
| 423 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 424 | |
| 425 | /* Send "write" command */ |
| 426 | val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR); |
| 427 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 428 | if (ret < 0) { |
| 429 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 430 | return ret; |
| 431 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 432 | |
| 433 | ret = smsc75xx_wait_eeprom(dev); |
| 434 | if (ret < 0) |
| 435 | return ret; |
| 436 | |
| 437 | offset++; |
| 438 | } |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev) |
| 444 | { |
| 445 | int i, ret; |
| 446 | |
| 447 | for (i = 0; i < 100; i++) { |
| 448 | u32 dp_sel; |
| 449 | ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 450 | if (ret < 0) { |
| 451 | netdev_warn(dev->net, "Error reading DP_SEL\n"); |
| 452 | return ret; |
| 453 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 454 | |
| 455 | if (dp_sel & DP_SEL_DPRDY) |
| 456 | return 0; |
| 457 | |
| 458 | udelay(40); |
| 459 | } |
| 460 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 461 | netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 462 | |
| 463 | return -EIO; |
| 464 | } |
| 465 | |
| 466 | static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr, |
| 467 | u32 length, u32 *buf) |
| 468 | { |
| 469 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 470 | u32 dp_sel; |
| 471 | int i, ret; |
| 472 | |
| 473 | mutex_lock(&pdata->dataport_mutex); |
| 474 | |
| 475 | ret = smsc75xx_dataport_wait_not_busy(dev); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 476 | if (ret < 0) { |
| 477 | netdev_warn(dev->net, "smsc75xx_dataport_write busy on entry\n"); |
| 478 | goto done; |
| 479 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 480 | |
| 481 | ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 482 | if (ret < 0) { |
| 483 | netdev_warn(dev->net, "Error reading DP_SEL\n"); |
| 484 | goto done; |
| 485 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 486 | |
| 487 | dp_sel &= ~DP_SEL_RSEL; |
| 488 | dp_sel |= ram_select; |
| 489 | ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 490 | if (ret < 0) { |
| 491 | netdev_warn(dev->net, "Error writing DP_SEL\n"); |
| 492 | goto done; |
| 493 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 494 | |
| 495 | for (i = 0; i < length; i++) { |
| 496 | ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 497 | if (ret < 0) { |
| 498 | netdev_warn(dev->net, "Error writing DP_ADDR\n"); |
| 499 | goto done; |
| 500 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 501 | |
| 502 | ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 503 | if (ret < 0) { |
| 504 | netdev_warn(dev->net, "Error writing DP_DATA\n"); |
| 505 | goto done; |
| 506 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 507 | |
| 508 | ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 509 | if (ret < 0) { |
| 510 | netdev_warn(dev->net, "Error writing DP_CMD\n"); |
| 511 | goto done; |
| 512 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 513 | |
| 514 | ret = smsc75xx_dataport_wait_not_busy(dev); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 515 | if (ret < 0) { |
| 516 | netdev_warn(dev->net, "smsc75xx_dataport_write timeout\n"); |
| 517 | goto done; |
| 518 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | done: |
| 522 | mutex_unlock(&pdata->dataport_mutex); |
| 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | /* returns hash bit number for given MAC address */ |
| 527 | static u32 smsc75xx_hash(char addr[ETH_ALEN]) |
| 528 | { |
| 529 | return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff; |
| 530 | } |
| 531 | |
| 532 | static void smsc75xx_deferred_multicast_write(struct work_struct *param) |
| 533 | { |
| 534 | struct smsc75xx_priv *pdata = |
| 535 | container_of(param, struct smsc75xx_priv, set_multicast); |
| 536 | struct usbnet *dev = pdata->dev; |
| 537 | int ret; |
| 538 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 539 | netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n", |
| 540 | pdata->rfe_ctl); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 541 | |
| 542 | smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN, |
| 543 | DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table); |
| 544 | |
| 545 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 546 | if (ret < 0) |
| 547 | netdev_warn(dev->net, "Error writing RFE_CRL\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void smsc75xx_set_multicast(struct net_device *netdev) |
| 551 | { |
| 552 | struct usbnet *dev = netdev_priv(netdev); |
| 553 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 554 | unsigned long flags; |
| 555 | int i; |
| 556 | |
| 557 | spin_lock_irqsave(&pdata->rfe_ctl_lock, flags); |
| 558 | |
| 559 | pdata->rfe_ctl &= |
| 560 | ~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF); |
| 561 | pdata->rfe_ctl |= RFE_CTL_AB; |
| 562 | |
| 563 | for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++) |
| 564 | pdata->multicast_hash_table[i] = 0; |
| 565 | |
| 566 | if (dev->net->flags & IFF_PROMISC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 567 | netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 568 | pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU; |
| 569 | } else if (dev->net->flags & IFF_ALLMULTI) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 570 | netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 571 | pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF; |
| 572 | } else if (!netdev_mc_empty(dev->net)) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 573 | struct netdev_hw_addr *ha; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 574 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 575 | netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 576 | |
| 577 | pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF; |
| 578 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 579 | netdev_for_each_mc_addr(ha, netdev) { |
| 580 | u32 bitnum = smsc75xx_hash(ha->addr); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 581 | pdata->multicast_hash_table[bitnum / 32] |= |
| 582 | (1 << (bitnum % 32)); |
| 583 | } |
| 584 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 585 | netif_dbg(dev, drv, dev->net, "receive own packets only\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 586 | pdata->rfe_ctl |= RFE_CTL_DPF; |
| 587 | } |
| 588 | |
| 589 | spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags); |
| 590 | |
| 591 | /* defer register writes to a sleepable context */ |
| 592 | schedule_work(&pdata->set_multicast); |
| 593 | } |
| 594 | |
| 595 | static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex, |
| 596 | u16 lcladv, u16 rmtadv) |
| 597 | { |
| 598 | u32 flow = 0, fct_flow = 0; |
| 599 | int ret; |
| 600 | |
| 601 | if (duplex == DUPLEX_FULL) { |
| 602 | u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
| 603 | |
| 604 | if (cap & FLOW_CTRL_TX) { |
| 605 | flow = (FLOW_TX_FCEN | 0xFFFF); |
| 606 | /* set fct_flow thresholds to 20% and 80% */ |
| 607 | fct_flow = (8 << 8) | 32; |
| 608 | } |
| 609 | |
| 610 | if (cap & FLOW_CTRL_RX) |
| 611 | flow |= FLOW_RX_FCEN; |
| 612 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 613 | netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", |
| 614 | (cap & FLOW_CTRL_RX ? "enabled" : "disabled"), |
| 615 | (cap & FLOW_CTRL_TX ? "enabled" : "disabled")); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 616 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 617 | netif_dbg(dev, link, dev->net, "half duplex\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | ret = smsc75xx_write_reg(dev, FLOW, flow); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 621 | if (ret < 0) { |
| 622 | netdev_warn(dev->net, "Error writing FLOW\n"); |
| 623 | return ret; |
| 624 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 625 | |
| 626 | ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 627 | if (ret < 0) { |
| 628 | netdev_warn(dev->net, "Error writing FCT_FLOW\n"); |
| 629 | return ret; |
| 630 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 631 | |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static int smsc75xx_link_reset(struct usbnet *dev) |
| 636 | { |
| 637 | struct mii_if_info *mii = &dev->mii; |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 638 | struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 639 | u16 lcladv, rmtadv; |
| 640 | int ret; |
| 641 | |
Steve Glendinning | 4f94a92 | 2012-05-04 00:57:12 +0000 | [diff] [blame] | 642 | /* write to clear phy interrupt status */ |
Steve Glendinning | 7749622 | 2012-05-04 00:57:11 +0000 | [diff] [blame] | 643 | smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC, |
| 644 | PHY_INT_SRC_CLEAR_ALL); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 645 | |
| 646 | ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 647 | if (ret < 0) { |
| 648 | netdev_warn(dev->net, "Error writing INT_STS\n"); |
| 649 | return ret; |
| 650 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 651 | |
| 652 | mii_check_media(mii, 1, 1); |
| 653 | mii_ethtool_gset(&dev->mii, &ecmd); |
| 654 | lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); |
| 655 | rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA); |
| 656 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 657 | netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", |
| 658 | ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 659 | |
| 660 | return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); |
| 661 | } |
| 662 | |
| 663 | static void smsc75xx_status(struct usbnet *dev, struct urb *urb) |
| 664 | { |
| 665 | u32 intdata; |
| 666 | |
| 667 | if (urb->actual_length != 4) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 668 | netdev_warn(dev->net, "unexpected urb length %d\n", |
| 669 | urb->actual_length); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 670 | return; |
| 671 | } |
| 672 | |
| 673 | memcpy(&intdata, urb->transfer_buffer, 4); |
| 674 | le32_to_cpus(&intdata); |
| 675 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 676 | netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 677 | |
| 678 | if (intdata & INT_ENP_PHY_INT) |
| 679 | usbnet_defer_kevent(dev, EVENT_LINK_RESET); |
| 680 | else |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 681 | netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", |
| 682 | intdata); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 685 | static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net) |
| 686 | { |
| 687 | return MAX_EEPROM_SIZE; |
| 688 | } |
| 689 | |
| 690 | static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev, |
| 691 | struct ethtool_eeprom *ee, u8 *data) |
| 692 | { |
| 693 | struct usbnet *dev = netdev_priv(netdev); |
| 694 | |
| 695 | ee->magic = LAN75XX_EEPROM_MAGIC; |
| 696 | |
| 697 | return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data); |
| 698 | } |
| 699 | |
| 700 | static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev, |
| 701 | struct ethtool_eeprom *ee, u8 *data) |
| 702 | { |
| 703 | struct usbnet *dev = netdev_priv(netdev); |
| 704 | |
| 705 | if (ee->magic != LAN75XX_EEPROM_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 706 | netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n", |
| 707 | ee->magic); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data); |
| 712 | } |
| 713 | |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 714 | static void smsc75xx_ethtool_get_wol(struct net_device *net, |
| 715 | struct ethtool_wolinfo *wolinfo) |
| 716 | { |
| 717 | struct usbnet *dev = netdev_priv(net); |
| 718 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 719 | |
| 720 | wolinfo->supported = SUPPORTED_WAKE; |
| 721 | wolinfo->wolopts = pdata->wolopts; |
| 722 | } |
| 723 | |
| 724 | static int smsc75xx_ethtool_set_wol(struct net_device *net, |
| 725 | struct ethtool_wolinfo *wolinfo) |
| 726 | { |
| 727 | struct usbnet *dev = netdev_priv(net); |
| 728 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 729 | int ret; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 730 | |
| 731 | pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 732 | |
| 733 | ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 734 | if (ret < 0) |
| 735 | netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 736 | |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 737 | return ret; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 740 | static const struct ethtool_ops smsc75xx_ethtool_ops = { |
| 741 | .get_link = usbnet_get_link, |
| 742 | .nway_reset = usbnet_nway_reset, |
| 743 | .get_drvinfo = usbnet_get_drvinfo, |
| 744 | .get_msglevel = usbnet_get_msglevel, |
| 745 | .set_msglevel = usbnet_set_msglevel, |
| 746 | .get_settings = usbnet_get_settings, |
| 747 | .set_settings = usbnet_set_settings, |
| 748 | .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len, |
| 749 | .get_eeprom = smsc75xx_ethtool_get_eeprom, |
| 750 | .set_eeprom = smsc75xx_ethtool_set_eeprom, |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 751 | .get_wol = smsc75xx_ethtool_get_wol, |
| 752 | .set_wol = smsc75xx_ethtool_set_wol, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 753 | }; |
| 754 | |
| 755 | static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
| 756 | { |
| 757 | struct usbnet *dev = netdev_priv(netdev); |
| 758 | |
| 759 | if (!netif_running(netdev)) |
| 760 | return -EINVAL; |
| 761 | |
| 762 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); |
| 763 | } |
| 764 | |
| 765 | static void smsc75xx_init_mac_address(struct usbnet *dev) |
| 766 | { |
| 767 | /* try reading mac address from EEPROM */ |
| 768 | if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, |
| 769 | dev->net->dev_addr) == 0) { |
| 770 | if (is_valid_ether_addr(dev->net->dev_addr)) { |
| 771 | /* eeprom values are valid so use them */ |
| 772 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 773 | "MAC address read from EEPROM\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /* no eeprom, or eeprom values are invalid. generate random MAC */ |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 779 | eth_hw_addr_random(dev->net); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 780 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static int smsc75xx_set_mac_address(struct usbnet *dev) |
| 784 | { |
| 785 | u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | |
| 786 | dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; |
| 787 | u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; |
| 788 | |
| 789 | int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 790 | if (ret < 0) { |
| 791 | netdev_warn(dev->net, "Failed to write RX_ADDRH: %d\n", ret); |
| 792 | return ret; |
| 793 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 794 | |
| 795 | ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 796 | if (ret < 0) { |
| 797 | netdev_warn(dev->net, "Failed to write RX_ADDRL: %d\n", ret); |
| 798 | return ret; |
| 799 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 800 | |
| 801 | addr_hi |= ADDR_FILTX_FB_VALID; |
| 802 | ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 803 | if (ret < 0) { |
| 804 | netdev_warn(dev->net, "Failed to write ADDR_FILTX: %d\n", ret); |
| 805 | return ret; |
| 806 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 807 | |
| 808 | ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 809 | if (ret < 0) |
| 810 | netdev_warn(dev->net, "Failed to write ADDR_FILTX+4: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 811 | |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 812 | return ret; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static int smsc75xx_phy_initialize(struct usbnet *dev) |
| 816 | { |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 817 | int bmcr, ret, timeout = 0; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 818 | |
| 819 | /* Initialize MII structure */ |
| 820 | dev->mii.dev = dev->net; |
| 821 | dev->mii.mdio_read = smsc75xx_mdio_read; |
| 822 | dev->mii.mdio_write = smsc75xx_mdio_write; |
| 823 | dev->mii.phy_id_mask = 0x1f; |
| 824 | dev->mii.reg_num_mask = 0x1f; |
Steve Glendinning | c0b92e4 | 2012-04-30 07:56:55 +0000 | [diff] [blame] | 825 | dev->mii.supports_gmii = 1; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 826 | dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID; |
| 827 | |
| 828 | /* reset phy and wait for reset to complete */ |
| 829 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); |
| 830 | |
| 831 | do { |
| 832 | msleep(10); |
| 833 | bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 834 | if (bmcr < 0) { |
| 835 | netdev_warn(dev->net, "Error reading MII_BMCR\n"); |
| 836 | return bmcr; |
| 837 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 838 | timeout++; |
Steve Glendinning | 8a1d59d | 2012-04-30 07:56:53 +0000 | [diff] [blame] | 839 | } while ((bmcr & BMCR_RESET) && (timeout < 100)); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 840 | |
| 841 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 842 | netdev_warn(dev->net, "timeout on PHY Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 843 | return -EIO; |
| 844 | } |
| 845 | |
| 846 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, |
| 847 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | |
| 848 | ADVERTISE_PAUSE_ASYM); |
Steve Glendinning | c0b92e4 | 2012-04-30 07:56:55 +0000 | [diff] [blame] | 849 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000, |
| 850 | ADVERTISE_1000FULL); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 851 | |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 852 | /* read and write to clear phy interrupt status */ |
| 853 | ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 854 | if (ret < 0) { |
| 855 | netdev_warn(dev->net, "Error reading PHY_INT_SRC\n"); |
| 856 | return ret; |
| 857 | } |
| 858 | |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 859 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_SRC, 0xffff); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 860 | |
| 861 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, |
| 862 | PHY_INT_MASK_DEFAULT); |
| 863 | mii_nway_restart(&dev->mii); |
| 864 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 865 | netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size) |
| 870 | { |
| 871 | int ret = 0; |
| 872 | u32 buf; |
| 873 | bool rxenabled; |
| 874 | |
| 875 | ret = smsc75xx_read_reg(dev, MAC_RX, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 876 | if (ret < 0) { |
| 877 | netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret); |
| 878 | return ret; |
| 879 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 880 | |
| 881 | rxenabled = ((buf & MAC_RX_RXEN) != 0); |
| 882 | |
| 883 | if (rxenabled) { |
| 884 | buf &= ~MAC_RX_RXEN; |
| 885 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 886 | if (ret < 0) { |
| 887 | netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret); |
| 888 | return ret; |
| 889 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /* add 4 to size for FCS */ |
| 893 | buf &= ~MAC_RX_MAX_SIZE; |
| 894 | buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE); |
| 895 | |
| 896 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 897 | if (ret < 0) { |
| 898 | netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret); |
| 899 | return ret; |
| 900 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 901 | |
| 902 | if (rxenabled) { |
| 903 | buf |= MAC_RX_RXEN; |
| 904 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 905 | if (ret < 0) { |
| 906 | netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret); |
| 907 | return ret; |
| 908 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu) |
| 915 | { |
| 916 | struct usbnet *dev = netdev_priv(netdev); |
| 917 | |
| 918 | int ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 919 | if (ret < 0) { |
| 920 | netdev_warn(dev->net, "Failed to set mac rx frame length\n"); |
| 921 | return ret; |
| 922 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 923 | |
| 924 | return usbnet_change_mtu(netdev, new_mtu); |
| 925 | } |
| 926 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 927 | /* Enable or disable Rx checksum offload engine */ |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 928 | static int smsc75xx_set_features(struct net_device *netdev, |
| 929 | netdev_features_t features) |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 930 | { |
| 931 | struct usbnet *dev = netdev_priv(netdev); |
| 932 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 933 | unsigned long flags; |
| 934 | int ret; |
| 935 | |
| 936 | spin_lock_irqsave(&pdata->rfe_ctl_lock, flags); |
| 937 | |
| 938 | if (features & NETIF_F_RXCSUM) |
| 939 | pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM; |
| 940 | else |
| 941 | pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM); |
| 942 | |
| 943 | spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags); |
| 944 | /* it's racing here! */ |
| 945 | |
| 946 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 947 | if (ret < 0) |
| 948 | netdev_warn(dev->net, "Error writing RFE_CTL\n"); |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 949 | |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 950 | return ret; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 953 | static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm) |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 954 | { |
| 955 | int timeout = 0; |
| 956 | |
| 957 | do { |
| 958 | u32 buf; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 959 | int ret; |
| 960 | |
| 961 | ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm); |
| 962 | |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 963 | if (ret < 0) { |
| 964 | netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret); |
| 965 | return ret; |
| 966 | } |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 967 | |
| 968 | if (buf & PMT_CTL_DEV_RDY) |
| 969 | return 0; |
| 970 | |
| 971 | msleep(10); |
| 972 | timeout++; |
| 973 | } while (timeout < 100); |
| 974 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 975 | netdev_warn(dev->net, "timeout waiting for device ready\n"); |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 976 | return -EIO; |
| 977 | } |
| 978 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 979 | static int smsc75xx_reset(struct usbnet *dev) |
| 980 | { |
| 981 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 982 | u32 buf; |
| 983 | int ret = 0, timeout; |
| 984 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 985 | netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 986 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 987 | ret = smsc75xx_wait_ready(dev, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 988 | if (ret < 0) { |
| 989 | netdev_warn(dev->net, "device not ready in smsc75xx_reset\n"); |
| 990 | return ret; |
| 991 | } |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 992 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 993 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 994 | if (ret < 0) { |
| 995 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 996 | return ret; |
| 997 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 998 | |
| 999 | buf |= HW_CFG_LRST; |
| 1000 | |
| 1001 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1002 | if (ret < 0) { |
| 1003 | netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret); |
| 1004 | return ret; |
| 1005 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1006 | |
| 1007 | timeout = 0; |
| 1008 | do { |
| 1009 | msleep(10); |
| 1010 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1011 | if (ret < 0) { |
| 1012 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 1013 | return ret; |
| 1014 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1015 | timeout++; |
| 1016 | } while ((buf & HW_CFG_LRST) && (timeout < 100)); |
| 1017 | |
| 1018 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1019 | netdev_warn(dev->net, "timeout on completion of Lite Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1020 | return -EIO; |
| 1021 | } |
| 1022 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1023 | netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1024 | |
| 1025 | ret = smsc75xx_read_reg(dev, PMT_CTL, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1026 | if (ret < 0) { |
| 1027 | netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret); |
| 1028 | return ret; |
| 1029 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1030 | |
| 1031 | buf |= PMT_CTL_PHY_RST; |
| 1032 | |
| 1033 | ret = smsc75xx_write_reg(dev, PMT_CTL, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1034 | if (ret < 0) { |
| 1035 | netdev_warn(dev->net, "Failed to write PMT_CTL: %d\n", ret); |
| 1036 | return ret; |
| 1037 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1038 | |
| 1039 | timeout = 0; |
| 1040 | do { |
| 1041 | msleep(10); |
| 1042 | ret = smsc75xx_read_reg(dev, PMT_CTL, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1043 | if (ret < 0) { |
| 1044 | netdev_warn(dev->net, "Failed to read PMT_CTL: %d\n", ret); |
| 1045 | return ret; |
| 1046 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1047 | timeout++; |
| 1048 | } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100)); |
| 1049 | |
| 1050 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1051 | netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1052 | return -EIO; |
| 1053 | } |
| 1054 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1055 | netif_dbg(dev, ifup, dev->net, "PHY reset complete\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1056 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1057 | ret = smsc75xx_set_mac_address(dev); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1058 | if (ret < 0) { |
| 1059 | netdev_warn(dev->net, "Failed to set mac address\n"); |
| 1060 | return ret; |
| 1061 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1062 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1063 | netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", |
| 1064 | dev->net->dev_addr); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1065 | |
| 1066 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1067 | if (ret < 0) { |
| 1068 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 1069 | return ret; |
| 1070 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1071 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1072 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", |
| 1073 | buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1074 | |
| 1075 | buf |= HW_CFG_BIR; |
| 1076 | |
| 1077 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1078 | if (ret < 0) { |
| 1079 | netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret); |
| 1080 | return ret; |
| 1081 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1082 | |
| 1083 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1084 | if (ret < 0) { |
| 1085 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 1086 | return ret; |
| 1087 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1088 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1089 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n", |
| 1090 | buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1091 | |
| 1092 | if (!turbo_mode) { |
| 1093 | buf = 0; |
| 1094 | dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; |
| 1095 | } else if (dev->udev->speed == USB_SPEED_HIGH) { |
| 1096 | buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; |
| 1097 | dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; |
| 1098 | } else { |
| 1099 | buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; |
| 1100 | dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; |
| 1101 | } |
| 1102 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1103 | netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", |
| 1104 | (ulong)dev->rx_urb_size); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1105 | |
| 1106 | ret = smsc75xx_write_reg(dev, BURST_CAP, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1107 | if (ret < 0) { |
| 1108 | netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret); |
| 1109 | return ret; |
| 1110 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1111 | |
| 1112 | ret = smsc75xx_read_reg(dev, BURST_CAP, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1113 | if (ret < 0) { |
| 1114 | netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret); |
| 1115 | return ret; |
| 1116 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1117 | |
| 1118 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1119 | "Read Value from BURST_CAP after writing: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1120 | |
| 1121 | ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1122 | if (ret < 0) { |
| 1123 | netdev_warn(dev->net, "Failed to write BULK_IN_DLY: %d\n", ret); |
| 1124 | return ret; |
| 1125 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1126 | |
| 1127 | ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1128 | if (ret < 0) { |
| 1129 | netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret); |
| 1130 | return ret; |
| 1131 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1132 | |
| 1133 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1134 | "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1135 | |
| 1136 | if (turbo_mode) { |
| 1137 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1138 | if (ret < 0) { |
| 1139 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 1140 | return ret; |
| 1141 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1142 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1143 | netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1144 | |
| 1145 | buf |= (HW_CFG_MEF | HW_CFG_BCE); |
| 1146 | |
| 1147 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1148 | if (ret < 0) { |
| 1149 | netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret); |
| 1150 | return ret; |
| 1151 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1152 | |
| 1153 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1154 | if (ret < 0) { |
| 1155 | netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); |
| 1156 | return ret; |
| 1157 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1158 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1159 | netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* set FIFO sizes */ |
| 1163 | buf = (MAX_RX_FIFO_SIZE - 512) / 512; |
| 1164 | ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1165 | if (ret < 0) { |
| 1166 | netdev_warn(dev->net, "Failed to write FCT_RX_FIFO_END: %d\n", ret); |
| 1167 | return ret; |
| 1168 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1169 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1170 | netif_dbg(dev, ifup, dev->net, "FCT_RX_FIFO_END set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1171 | |
| 1172 | buf = (MAX_TX_FIFO_SIZE - 512) / 512; |
| 1173 | ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1174 | if (ret < 0) { |
| 1175 | netdev_warn(dev->net, "Failed to write FCT_TX_FIFO_END: %d\n", ret); |
| 1176 | return ret; |
| 1177 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1178 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1179 | netif_dbg(dev, ifup, dev->net, "FCT_TX_FIFO_END set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1180 | |
| 1181 | ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1182 | if (ret < 0) { |
| 1183 | netdev_warn(dev->net, "Failed to write INT_STS: %d\n", ret); |
| 1184 | return ret; |
| 1185 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1186 | |
| 1187 | ret = smsc75xx_read_reg(dev, ID_REV, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1188 | if (ret < 0) { |
| 1189 | netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret); |
| 1190 | return ret; |
| 1191 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1192 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1193 | netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1194 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1195 | ret = smsc75xx_read_reg(dev, E2P_CMD, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1196 | if (ret < 0) { |
| 1197 | netdev_warn(dev->net, "Failed to read E2P_CMD: %d\n", ret); |
| 1198 | return ret; |
| 1199 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1200 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1201 | /* only set default GPIO/LED settings if no EEPROM is detected */ |
| 1202 | if (!(buf & E2P_CMD_LOADED)) { |
| 1203 | ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1204 | if (ret < 0) { |
| 1205 | netdev_warn(dev->net, "Failed to read LED_GPIO_CFG: %d\n", ret); |
| 1206 | return ret; |
| 1207 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1208 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1209 | buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL); |
| 1210 | buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL; |
| 1211 | |
| 1212 | ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1213 | if (ret < 0) { |
| 1214 | netdev_warn(dev->net, "Failed to write LED_GPIO_CFG: %d\n", ret); |
| 1215 | return ret; |
| 1216 | } |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1217 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1218 | |
| 1219 | ret = smsc75xx_write_reg(dev, FLOW, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1220 | if (ret < 0) { |
| 1221 | netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret); |
| 1222 | return ret; |
| 1223 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1224 | |
| 1225 | ret = smsc75xx_write_reg(dev, FCT_FLOW, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1226 | if (ret < 0) { |
| 1227 | netdev_warn(dev->net, "Failed to write FCT_FLOW: %d\n", ret); |
| 1228 | return ret; |
| 1229 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1230 | |
| 1231 | /* Don't need rfe_ctl_lock during initialisation */ |
| 1232 | ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1233 | if (ret < 0) { |
| 1234 | netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret); |
| 1235 | return ret; |
| 1236 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1237 | |
| 1238 | pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF; |
| 1239 | |
| 1240 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1241 | if (ret < 0) { |
| 1242 | netdev_warn(dev->net, "Failed to write RFE_CTL: %d\n", ret); |
| 1243 | return ret; |
| 1244 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1245 | |
| 1246 | ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1247 | if (ret < 0) { |
| 1248 | netdev_warn(dev->net, "Failed to read RFE_CTL: %d\n", ret); |
| 1249 | return ret; |
| 1250 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1251 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1252 | netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n", |
| 1253 | pdata->rfe_ctl); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1254 | |
| 1255 | /* Enable or disable checksum offload engines */ |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1256 | smsc75xx_set_features(dev->net, dev->net->features); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1257 | |
| 1258 | smsc75xx_set_multicast(dev->net); |
| 1259 | |
| 1260 | ret = smsc75xx_phy_initialize(dev); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1261 | if (ret < 0) { |
| 1262 | netdev_warn(dev->net, "Failed to initialize PHY: %d\n", ret); |
| 1263 | return ret; |
| 1264 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1265 | |
| 1266 | ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1267 | if (ret < 0) { |
| 1268 | netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret); |
| 1269 | return ret; |
| 1270 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1271 | |
| 1272 | /* enable PHY interrupts */ |
| 1273 | buf |= INT_ENP_PHY_INT; |
| 1274 | |
| 1275 | ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1276 | if (ret < 0) { |
| 1277 | netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret); |
| 1278 | return ret; |
| 1279 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1280 | |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1281 | /* allow mac to detect speed and duplex from phy */ |
| 1282 | ret = smsc75xx_read_reg(dev, MAC_CR, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1283 | if (ret < 0) { |
| 1284 | netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret); |
| 1285 | return ret; |
| 1286 | } |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1287 | |
| 1288 | buf |= (MAC_CR_ADD | MAC_CR_ASD); |
| 1289 | ret = smsc75xx_write_reg(dev, MAC_CR, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1290 | if (ret < 0) { |
| 1291 | netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret); |
| 1292 | return ret; |
| 1293 | } |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1294 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1295 | ret = smsc75xx_read_reg(dev, MAC_TX, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1296 | if (ret < 0) { |
| 1297 | netdev_warn(dev->net, "Failed to read MAC_TX: %d\n", ret); |
| 1298 | return ret; |
| 1299 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1300 | |
| 1301 | buf |= MAC_TX_TXEN; |
| 1302 | |
| 1303 | ret = smsc75xx_write_reg(dev, MAC_TX, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1304 | if (ret < 0) { |
| 1305 | netdev_warn(dev->net, "Failed to write MAC_TX: %d\n", ret); |
| 1306 | return ret; |
| 1307 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1308 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1309 | netif_dbg(dev, ifup, dev->net, "MAC_TX set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1310 | |
| 1311 | ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1312 | if (ret < 0) { |
| 1313 | netdev_warn(dev->net, "Failed to read FCT_TX_CTL: %d\n", ret); |
| 1314 | return ret; |
| 1315 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1316 | |
| 1317 | buf |= FCT_TX_CTL_EN; |
| 1318 | |
| 1319 | ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1320 | if (ret < 0) { |
| 1321 | netdev_warn(dev->net, "Failed to write FCT_TX_CTL: %d\n", ret); |
| 1322 | return ret; |
| 1323 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1324 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1325 | netif_dbg(dev, ifup, dev->net, "FCT_TX_CTL set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1326 | |
| 1327 | ret = smsc75xx_set_rx_max_frame_length(dev, 1514); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1328 | if (ret < 0) { |
| 1329 | netdev_warn(dev->net, "Failed to set max rx frame length\n"); |
| 1330 | return ret; |
| 1331 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1332 | |
| 1333 | ret = smsc75xx_read_reg(dev, MAC_RX, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1334 | if (ret < 0) { |
| 1335 | netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret); |
| 1336 | return ret; |
| 1337 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1338 | |
| 1339 | buf |= MAC_RX_RXEN; |
| 1340 | |
| 1341 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1342 | if (ret < 0) { |
| 1343 | netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret); |
| 1344 | return ret; |
| 1345 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1346 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1347 | netif_dbg(dev, ifup, dev->net, "MAC_RX set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1348 | |
| 1349 | ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1350 | if (ret < 0) { |
| 1351 | netdev_warn(dev->net, "Failed to read FCT_RX_CTL: %d\n", ret); |
| 1352 | return ret; |
| 1353 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1354 | |
| 1355 | buf |= FCT_RX_CTL_EN; |
| 1356 | |
| 1357 | ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1358 | if (ret < 0) { |
| 1359 | netdev_warn(dev->net, "Failed to write FCT_RX_CTL: %d\n", ret); |
| 1360 | return ret; |
| 1361 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1362 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1363 | netif_dbg(dev, ifup, dev->net, "FCT_RX_CTL set to 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1364 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1365 | netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1366 | return 0; |
| 1367 | } |
| 1368 | |
| 1369 | static const struct net_device_ops smsc75xx_netdev_ops = { |
| 1370 | .ndo_open = usbnet_open, |
| 1371 | .ndo_stop = usbnet_stop, |
| 1372 | .ndo_start_xmit = usbnet_start_xmit, |
| 1373 | .ndo_tx_timeout = usbnet_tx_timeout, |
| 1374 | .ndo_change_mtu = smsc75xx_change_mtu, |
| 1375 | .ndo_set_mac_address = eth_mac_addr, |
| 1376 | .ndo_validate_addr = eth_validate_addr, |
| 1377 | .ndo_do_ioctl = smsc75xx_ioctl, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1378 | .ndo_set_rx_mode = smsc75xx_set_multicast, |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1379 | .ndo_set_features = smsc75xx_set_features, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1380 | }; |
| 1381 | |
| 1382 | static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) |
| 1383 | { |
| 1384 | struct smsc75xx_priv *pdata = NULL; |
| 1385 | int ret; |
| 1386 | |
| 1387 | printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); |
| 1388 | |
| 1389 | ret = usbnet_get_endpoints(dev, intf); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1390 | if (ret < 0) { |
| 1391 | netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); |
| 1392 | return ret; |
| 1393 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1394 | |
| 1395 | dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv), |
Joe Perches | 38673c8 | 2013-02-03 17:28:11 +0000 | [diff] [blame] | 1396 | GFP_KERNEL); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1397 | |
| 1398 | pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Joe Perches | 38673c8 | 2013-02-03 17:28:11 +0000 | [diff] [blame] | 1399 | if (!pdata) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1400 | return -ENOMEM; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1401 | |
| 1402 | pdata->dev = dev; |
| 1403 | |
| 1404 | spin_lock_init(&pdata->rfe_ctl_lock); |
| 1405 | mutex_init(&pdata->dataport_mutex); |
| 1406 | |
| 1407 | INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write); |
| 1408 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1409 | if (DEFAULT_TX_CSUM_ENABLE) { |
| 1410 | dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 1411 | if (DEFAULT_TSO_ENABLE) |
| 1412 | dev->net->features |= NETIF_F_SG | |
| 1413 | NETIF_F_TSO | NETIF_F_TSO6; |
| 1414 | } |
| 1415 | if (DEFAULT_RX_CSUM_ENABLE) |
| 1416 | dev->net->features |= NETIF_F_RXCSUM; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1417 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1418 | dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 1419 | NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_RXCSUM; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1420 | |
Steve Glendinning | 481705a | 2012-12-10 01:01:19 +0000 | [diff] [blame] | 1421 | ret = smsc75xx_wait_ready(dev, 0); |
| 1422 | if (ret < 0) { |
| 1423 | netdev_warn(dev->net, "device not ready in smsc75xx_bind\n"); |
| 1424 | return ret; |
| 1425 | } |
| 1426 | |
| 1427 | smsc75xx_init_mac_address(dev); |
| 1428 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1429 | /* Init all registers */ |
| 1430 | ret = smsc75xx_reset(dev); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1431 | if (ret < 0) { |
| 1432 | netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret); |
| 1433 | return ret; |
| 1434 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1435 | |
| 1436 | dev->net->netdev_ops = &smsc75xx_netdev_ops; |
| 1437 | dev->net->ethtool_ops = &smsc75xx_ethtool_ops; |
| 1438 | dev->net->flags |= IFF_MULTICAST; |
| 1439 | dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD; |
Stephane Fillod | a99ff7d | 2012-04-15 11:38:29 +0000 | [diff] [blame] | 1440 | dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1441 | return 0; |
| 1442 | } |
| 1443 | |
| 1444 | static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 1445 | { |
| 1446 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 1447 | if (pdata) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1448 | netif_dbg(dev, ifdown, dev->net, "free pdata\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1449 | kfree(pdata); |
| 1450 | pdata = NULL; |
| 1451 | dev->data[0] = 0; |
| 1452 | } |
| 1453 | } |
| 1454 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1455 | static u16 smsc_crc(const u8 *buffer, size_t len) |
| 1456 | { |
| 1457 | return bitrev16(crc16(0xFFFF, buffer, len)); |
| 1458 | } |
| 1459 | |
| 1460 | static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg, |
| 1461 | u32 wuf_mask1) |
| 1462 | { |
| 1463 | int cfg_base = WUF_CFGX + filter * 4; |
| 1464 | int mask_base = WUF_MASKX + filter * 16; |
| 1465 | int ret; |
| 1466 | |
| 1467 | ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1468 | if (ret < 0) { |
| 1469 | netdev_warn(dev->net, "Error writing WUF_CFGX\n"); |
| 1470 | return ret; |
| 1471 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1472 | |
| 1473 | ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1474 | if (ret < 0) { |
| 1475 | netdev_warn(dev->net, "Error writing WUF_MASKX\n"); |
| 1476 | return ret; |
| 1477 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1478 | |
| 1479 | ret = smsc75xx_write_reg(dev, mask_base + 4, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1480 | if (ret < 0) { |
| 1481 | netdev_warn(dev->net, "Error writing WUF_MASKX\n"); |
| 1482 | return ret; |
| 1483 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1484 | |
| 1485 | ret = smsc75xx_write_reg(dev, mask_base + 8, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1486 | if (ret < 0) { |
| 1487 | netdev_warn(dev->net, "Error writing WUF_MASKX\n"); |
| 1488 | return ret; |
| 1489 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1490 | |
| 1491 | ret = smsc75xx_write_reg(dev, mask_base + 12, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1492 | if (ret < 0) { |
| 1493 | netdev_warn(dev->net, "Error writing WUF_MASKX\n"); |
| 1494 | return ret; |
| 1495 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1500 | static int smsc75xx_enter_suspend0(struct usbnet *dev) |
| 1501 | { |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1502 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1503 | u32 val; |
| 1504 | int ret; |
| 1505 | |
| 1506 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1507 | if (ret < 0) { |
| 1508 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1509 | return ret; |
| 1510 | } |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1511 | |
| 1512 | val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST)); |
| 1513 | val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS; |
| 1514 | |
| 1515 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1516 | if (ret < 0) { |
| 1517 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1518 | return ret; |
| 1519 | } |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1520 | |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 1521 | pdata->suspend_flags |= SUSPEND_SUSPEND0; |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1522 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1523 | return 0; |
| 1524 | } |
| 1525 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1526 | static int smsc75xx_enter_suspend1(struct usbnet *dev) |
| 1527 | { |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1528 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1529 | u32 val; |
| 1530 | int ret; |
| 1531 | |
| 1532 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1533 | if (ret < 0) { |
| 1534 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1535 | return ret; |
| 1536 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1537 | |
| 1538 | val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST); |
| 1539 | val |= PMT_CTL_SUS_MODE_1; |
| 1540 | |
| 1541 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1542 | if (ret < 0) { |
| 1543 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1544 | return ret; |
| 1545 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1546 | |
| 1547 | /* clear wol status, enable energy detection */ |
| 1548 | val &= ~PMT_CTL_WUPS; |
| 1549 | val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN); |
| 1550 | |
| 1551 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1552 | if (ret < 0) { |
| 1553 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1554 | return ret; |
| 1555 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1556 | |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 1557 | pdata->suspend_flags |= SUSPEND_SUSPEND1; |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1558 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1559 | return 0; |
| 1560 | } |
| 1561 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1562 | static int smsc75xx_enter_suspend2(struct usbnet *dev) |
| 1563 | { |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1564 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1565 | u32 val; |
| 1566 | int ret; |
| 1567 | |
| 1568 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1569 | if (ret < 0) { |
| 1570 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1571 | return ret; |
| 1572 | } |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1573 | |
| 1574 | val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST); |
| 1575 | val |= PMT_CTL_SUS_MODE_2; |
| 1576 | |
| 1577 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1578 | if (ret < 0) { |
| 1579 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1580 | return ret; |
| 1581 | } |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1582 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1583 | pdata->suspend_flags |= SUSPEND_SUSPEND2; |
| 1584 | |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
| 1588 | static int smsc75xx_enter_suspend3(struct usbnet *dev) |
| 1589 | { |
| 1590 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 1591 | u32 val; |
| 1592 | int ret; |
| 1593 | |
| 1594 | ret = smsc75xx_read_reg_nopm(dev, FCT_RX_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1595 | if (ret < 0) { |
| 1596 | netdev_warn(dev->net, "Error reading FCT_RX_CTL\n"); |
| 1597 | return ret; |
| 1598 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1599 | |
| 1600 | if (val & FCT_RX_CTL_RXUSED) { |
| 1601 | netdev_dbg(dev->net, "rx fifo not empty in autosuspend\n"); |
| 1602 | return -EBUSY; |
| 1603 | } |
| 1604 | |
| 1605 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1606 | if (ret < 0) { |
| 1607 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1608 | return ret; |
| 1609 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1610 | |
| 1611 | val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST); |
| 1612 | val |= PMT_CTL_SUS_MODE_3 | PMT_CTL_RES_CLR_WKP_EN; |
| 1613 | |
| 1614 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1615 | if (ret < 0) { |
| 1616 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1617 | return ret; |
| 1618 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1619 | |
| 1620 | /* clear wol status */ |
| 1621 | val &= ~PMT_CTL_WUPS; |
| 1622 | val |= PMT_CTL_WUPS_WOL; |
| 1623 | |
| 1624 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1625 | if (ret < 0) { |
| 1626 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1627 | return ret; |
| 1628 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1629 | |
Steve Glendinning | 351f33d | 2012-11-28 05:59:50 +0000 | [diff] [blame] | 1630 | pdata->suspend_flags |= SUSPEND_SUSPEND3; |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1631 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame] | 1632 | return 0; |
| 1633 | } |
| 1634 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1635 | static int smsc75xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) |
| 1636 | { |
| 1637 | struct mii_if_info *mii = &dev->mii; |
| 1638 | int ret; |
| 1639 | |
| 1640 | netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); |
| 1641 | |
| 1642 | /* read to clear */ |
| 1643 | ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1644 | if (ret < 0) { |
| 1645 | netdev_warn(dev->net, "Error reading PHY_INT_SRC\n"); |
| 1646 | return ret; |
| 1647 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1648 | |
| 1649 | /* enable interrupt source */ |
| 1650 | ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1651 | if (ret < 0) { |
| 1652 | netdev_warn(dev->net, "Error reading PHY_INT_MASK\n"); |
| 1653 | return ret; |
| 1654 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1655 | |
| 1656 | ret |= mask; |
| 1657 | |
| 1658 | smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | static int smsc75xx_link_ok_nopm(struct usbnet *dev) |
| 1664 | { |
| 1665 | struct mii_if_info *mii = &dev->mii; |
| 1666 | int ret; |
| 1667 | |
| 1668 | /* first, a dummy read, needed to latch some MII phys */ |
| 1669 | ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1670 | if (ret < 0) { |
| 1671 | netdev_warn(dev->net, "Error reading MII_BMSR\n"); |
| 1672 | return ret; |
| 1673 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1674 | |
| 1675 | ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1676 | if (ret < 0) { |
| 1677 | netdev_warn(dev->net, "Error reading MII_BMSR\n"); |
| 1678 | return ret; |
| 1679 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1680 | |
| 1681 | return !!(ret & BMSR_LSTATUS); |
| 1682 | } |
| 1683 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1684 | static int smsc75xx_autosuspend(struct usbnet *dev, u32 link_up) |
| 1685 | { |
| 1686 | int ret; |
| 1687 | |
| 1688 | if (!netif_running(dev->net)) { |
| 1689 | /* interface is ifconfig down so fully power down hw */ |
| 1690 | netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); |
| 1691 | return smsc75xx_enter_suspend2(dev); |
| 1692 | } |
| 1693 | |
| 1694 | if (!link_up) { |
| 1695 | /* link is down so enter EDPD mode */ |
| 1696 | netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); |
| 1697 | |
| 1698 | /* enable PHY wakeup events for if cable is attached */ |
| 1699 | ret = smsc75xx_enable_phy_wakeup_interrupts(dev, |
| 1700 | PHY_INT_MASK_ANEG_COMP); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1701 | if (ret < 0) { |
| 1702 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1703 | return ret; |
| 1704 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1705 | |
| 1706 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
| 1707 | return smsc75xx_enter_suspend1(dev); |
| 1708 | } |
| 1709 | |
| 1710 | /* enable PHY wakeup events so we remote wakeup if cable is pulled */ |
| 1711 | ret = smsc75xx_enable_phy_wakeup_interrupts(dev, |
| 1712 | PHY_INT_MASK_LINK_DOWN); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1713 | if (ret < 0) { |
| 1714 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1715 | return ret; |
| 1716 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1717 | |
| 1718 | netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); |
| 1719 | return smsc75xx_enter_suspend3(dev); |
| 1720 | } |
| 1721 | |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1722 | static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message) |
| 1723 | { |
| 1724 | struct usbnet *dev = usb_get_intfdata(intf); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1725 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1726 | u32 val, link_up; |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1727 | int ret; |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1728 | |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1729 | ret = usbnet_suspend(intf, message); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1730 | if (ret < 0) { |
| 1731 | netdev_warn(dev->net, "usbnet_suspend error\n"); |
| 1732 | return ret; |
| 1733 | } |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1734 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1735 | if (pdata->suspend_flags) { |
| 1736 | netdev_warn(dev->net, "error during last resume\n"); |
| 1737 | pdata->suspend_flags = 0; |
| 1738 | } |
| 1739 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1740 | /* determine if link is up using only _nopm functions */ |
| 1741 | link_up = smsc75xx_link_ok_nopm(dev); |
| 1742 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 1743 | if (message.event == PM_EVENT_AUTO_SUSPEND) { |
| 1744 | ret = smsc75xx_autosuspend(dev, link_up); |
| 1745 | goto done; |
| 1746 | } |
| 1747 | |
| 1748 | /* if we get this far we're not autosuspending */ |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1749 | /* if no wol options set, or if link is down and we're not waking on |
| 1750 | * PHY activity, enter lowest power SUSPEND2 mode |
| 1751 | */ |
| 1752 | if (!(pdata->wolopts & SUPPORTED_WAKE) || |
| 1753 | !(link_up || (pdata->wolopts & WAKE_PHY))) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1754 | netdev_info(dev->net, "entering SUSPEND2 mode\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1755 | |
| 1756 | /* disable energy detect (link up) & wake up events */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1757 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1758 | if (ret < 0) { |
| 1759 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1760 | goto done; |
| 1761 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1762 | |
| 1763 | val &= ~(WUCSR_MPEN | WUCSR_WUEN); |
| 1764 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1765 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1766 | if (ret < 0) { |
| 1767 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1768 | goto done; |
| 1769 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1770 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1771 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1772 | if (ret < 0) { |
| 1773 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1774 | goto done; |
| 1775 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1776 | |
| 1777 | val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN); |
| 1778 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1779 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1780 | if (ret < 0) { |
| 1781 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1782 | goto done; |
| 1783 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1784 | |
Steve Glendinning | eacdd6c | 2012-11-28 05:59:48 +0000 | [diff] [blame] | 1785 | ret = smsc75xx_enter_suspend2(dev); |
| 1786 | goto done; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1789 | if (pdata->wolopts & WAKE_PHY) { |
| 1790 | ret = smsc75xx_enable_phy_wakeup_interrupts(dev, |
| 1791 | (PHY_INT_MASK_ANEG_COMP | PHY_INT_MASK_LINK_DOWN)); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1792 | if (ret < 0) { |
| 1793 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1794 | goto done; |
| 1795 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1796 | |
| 1797 | /* if link is down then configure EDPD and enter SUSPEND1, |
| 1798 | * otherwise enter SUSPEND0 below |
| 1799 | */ |
| 1800 | if (!link_up) { |
| 1801 | struct mii_if_info *mii = &dev->mii; |
| 1802 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
| 1803 | |
| 1804 | /* enable energy detect power-down mode */ |
| 1805 | ret = smsc75xx_mdio_read_nopm(dev->net, mii->phy_id, |
| 1806 | PHY_MODE_CTRL_STS); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1807 | if (ret < 0) { |
| 1808 | netdev_warn(dev->net, "Error reading PHY_MODE_CTRL_STS\n"); |
| 1809 | goto done; |
| 1810 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1811 | |
| 1812 | ret |= MODE_CTRL_STS_EDPWRDOWN; |
| 1813 | |
| 1814 | smsc75xx_mdio_write_nopm(dev->net, mii->phy_id, |
| 1815 | PHY_MODE_CTRL_STS, ret); |
| 1816 | |
| 1817 | /* enter SUSPEND1 mode */ |
Steve Glendinning | eacdd6c | 2012-11-28 05:59:48 +0000 | [diff] [blame] | 1818 | ret = smsc75xx_enter_suspend1(dev); |
| 1819 | goto done; |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1823 | if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) { |
| 1824 | int i, filter = 0; |
| 1825 | |
| 1826 | /* disable all filters */ |
| 1827 | for (i = 0; i < WUF_NUM; i++) { |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1828 | ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1829 | if (ret < 0) { |
| 1830 | netdev_warn(dev->net, "Error writing WUF_CFGX\n"); |
| 1831 | goto done; |
| 1832 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | if (pdata->wolopts & WAKE_MCAST) { |
| 1836 | const u8 mcast[] = {0x01, 0x00, 0x5E}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1837 | netdev_info(dev->net, "enabling multicast detection\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1838 | |
| 1839 | val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST |
| 1840 | | smsc_crc(mcast, 3); |
| 1841 | ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1842 | if (ret < 0) { |
| 1843 | netdev_warn(dev->net, "Error writing wakeup filter\n"); |
| 1844 | goto done; |
| 1845 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | if (pdata->wolopts & WAKE_ARP) { |
| 1849 | const u8 arp[] = {0x08, 0x06}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1850 | netdev_info(dev->net, "enabling ARP detection\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1851 | |
| 1852 | val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16) |
| 1853 | | smsc_crc(arp, 2); |
| 1854 | ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1855 | if (ret < 0) { |
| 1856 | netdev_warn(dev->net, "Error writing wakeup filter\n"); |
| 1857 | goto done; |
| 1858 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | /* clear any pending pattern match packet status */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1862 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1863 | if (ret < 0) { |
| 1864 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1865 | goto done; |
| 1866 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1867 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1868 | val |= WUCSR_WUFR; |
| 1869 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1870 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1871 | if (ret < 0) { |
| 1872 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1873 | goto done; |
| 1874 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1875 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1876 | netdev_info(dev->net, "enabling packet match detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1877 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1878 | if (ret < 0) { |
| 1879 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1880 | goto done; |
| 1881 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1882 | |
| 1883 | val |= WUCSR_WUEN; |
| 1884 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1885 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1886 | if (ret < 0) { |
| 1887 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1888 | goto done; |
| 1889 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1890 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1891 | netdev_info(dev->net, "disabling packet match detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1892 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1893 | if (ret < 0) { |
| 1894 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1895 | goto done; |
| 1896 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1897 | |
| 1898 | val &= ~WUCSR_WUEN; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1899 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1900 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1901 | if (ret < 0) { |
| 1902 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1903 | goto done; |
| 1904 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1907 | /* disable magic, bcast & unicast wakeup sources */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1908 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1909 | if (ret < 0) { |
| 1910 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1911 | goto done; |
| 1912 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1913 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1914 | val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1915 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1916 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1917 | if (ret < 0) { |
| 1918 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1919 | goto done; |
| 1920 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1921 | |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1922 | if (pdata->wolopts & WAKE_PHY) { |
| 1923 | netdev_info(dev->net, "enabling PHY wakeup\n"); |
| 1924 | |
| 1925 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1926 | if (ret < 0) { |
| 1927 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 1928 | goto done; |
| 1929 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1930 | |
| 1931 | /* clear wol status, enable energy detection */ |
| 1932 | val &= ~PMT_CTL_WUPS; |
| 1933 | val |= (PMT_CTL_WUPS_ED | PMT_CTL_ED_EN); |
| 1934 | |
| 1935 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1936 | if (ret < 0) { |
| 1937 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 1938 | goto done; |
| 1939 | } |
Steve Glendinning | f329ccd | 2012-11-28 05:59:47 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1942 | if (pdata->wolopts & WAKE_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1943 | netdev_info(dev->net, "enabling magic packet wakeup\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1944 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1945 | if (ret < 0) { |
| 1946 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1947 | goto done; |
| 1948 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1949 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1950 | /* clear any pending magic packet status */ |
| 1951 | val |= WUCSR_MPR | WUCSR_MPEN; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1952 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1953 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1954 | if (ret < 0) { |
| 1955 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1956 | goto done; |
| 1957 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1958 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1959 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1960 | if (pdata->wolopts & WAKE_BCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1961 | netdev_info(dev->net, "enabling broadcast detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1962 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1963 | if (ret < 0) { |
| 1964 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1965 | goto done; |
| 1966 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1967 | |
| 1968 | val |= WUCSR_BCAST_FR | WUCSR_BCST_EN; |
| 1969 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1970 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1971 | if (ret < 0) { |
| 1972 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1973 | goto done; |
| 1974 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | if (pdata->wolopts & WAKE_UCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1978 | netdev_info(dev->net, "enabling unicast detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1979 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1980 | if (ret < 0) { |
| 1981 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 1982 | goto done; |
| 1983 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1984 | |
| 1985 | val |= WUCSR_WUFR | WUCSR_PFDA_EN; |
| 1986 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1987 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1988 | if (ret < 0) { |
| 1989 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 1990 | goto done; |
| 1991 | } |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /* enable receiver to enable frame reception */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1995 | ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 1996 | if (ret < 0) { |
| 1997 | netdev_warn(dev->net, "Failed to read MAC_RX: %d\n", ret); |
| 1998 | goto done; |
| 1999 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2000 | |
| 2001 | val |= MAC_RX_RXEN; |
| 2002 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2003 | ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2004 | if (ret < 0) { |
| 2005 | netdev_warn(dev->net, "Failed to write MAC_RX: %d\n", ret); |
| 2006 | goto done; |
| 2007 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2008 | |
| 2009 | /* some wol options are enabled, so enter SUSPEND0 */ |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2010 | netdev_info(dev->net, "entering SUSPEND0 mode\n"); |
Steve Glendinning | eacdd6c | 2012-11-28 05:59:48 +0000 | [diff] [blame] | 2011 | ret = smsc75xx_enter_suspend0(dev); |
| 2012 | |
| 2013 | done: |
| 2014 | if (ret) |
| 2015 | usbnet_resume(intf); |
| 2016 | return ret; |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | static int smsc75xx_resume(struct usb_interface *intf) |
| 2020 | { |
| 2021 | struct usbnet *dev = usb_get_intfdata(intf); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2022 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2023 | u8 suspend_flags = pdata->suspend_flags; |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2024 | int ret; |
| 2025 | u32 val; |
| 2026 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2027 | netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2028 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2029 | /* do this first to ensure it's cleared even in error case */ |
| 2030 | pdata->suspend_flags = 0; |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2031 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2032 | if (suspend_flags & SUSPEND_ALLMODES) { |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 2033 | /* Disable wakeup sources */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2034 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2035 | if (ret < 0) { |
| 2036 | netdev_warn(dev->net, "Error reading WUCSR\n"); |
| 2037 | return ret; |
| 2038 | } |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2039 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 2040 | val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN |
| 2041 | | WUCSR_BCST_EN); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2042 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2043 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2044 | if (ret < 0) { |
| 2045 | netdev_warn(dev->net, "Error writing WUCSR\n"); |
| 2046 | return ret; |
| 2047 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2048 | |
| 2049 | /* clear wake-up status */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2050 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2051 | if (ret < 0) { |
| 2052 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 2053 | return ret; |
| 2054 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2055 | |
| 2056 | val &= ~PMT_CTL_WOL_EN; |
| 2057 | val |= PMT_CTL_WUPS; |
| 2058 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2059 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2060 | if (ret < 0) { |
| 2061 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 2062 | return ret; |
| 2063 | } |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | if (suspend_flags & SUSPEND_SUSPEND2) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2067 | netdev_info(dev->net, "resuming from SUSPEND2\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2068 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2069 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2070 | if (ret < 0) { |
| 2071 | netdev_warn(dev->net, "Error reading PMT_CTL\n"); |
| 2072 | return ret; |
| 2073 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2074 | |
| 2075 | val |= PMT_CTL_PHY_PWRUP; |
| 2076 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2077 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2078 | if (ret < 0) { |
| 2079 | netdev_warn(dev->net, "Error writing PMT_CTL\n"); |
| 2080 | return ret; |
| 2081 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 2082 | } |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2083 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 2084 | ret = smsc75xx_wait_ready(dev, 1); |
Steve Glendinning | e3c678e | 2012-11-30 04:52:44 +0000 | [diff] [blame] | 2085 | if (ret < 0) { |
| 2086 | netdev_warn(dev->net, "device not ready in smsc75xx_resume\n"); |
| 2087 | return ret; |
| 2088 | } |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2089 | |
| 2090 | return usbnet_resume(intf); |
| 2091 | } |
| 2092 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 2093 | static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb, |
| 2094 | u32 rx_cmd_a, u32 rx_cmd_b) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2095 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 2096 | if (!(dev->net->features & NETIF_F_RXCSUM) || |
| 2097 | unlikely(rx_cmd_a & RX_CMD_A_LCSM)) { |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2098 | skb->ip_summed = CHECKSUM_NONE; |
| 2099 | } else { |
| 2100 | skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT)); |
| 2101 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
| 2106 | { |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2107 | while (skb->len > 0) { |
| 2108 | u32 rx_cmd_a, rx_cmd_b, align_count, size; |
| 2109 | struct sk_buff *ax_skb; |
| 2110 | unsigned char *packet; |
| 2111 | |
| 2112 | memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a)); |
| 2113 | le32_to_cpus(&rx_cmd_a); |
| 2114 | skb_pull(skb, 4); |
| 2115 | |
| 2116 | memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b)); |
| 2117 | le32_to_cpus(&rx_cmd_b); |
Nico Erfurth | ea1649d | 2011-11-08 07:30:40 +0000 | [diff] [blame] | 2118 | skb_pull(skb, 4 + RXW_PADDING); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2119 | |
| 2120 | packet = skb->data; |
| 2121 | |
| 2122 | /* get the packet length */ |
Nico Erfurth | ea1649d | 2011-11-08 07:30:40 +0000 | [diff] [blame] | 2123 | size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING; |
| 2124 | align_count = (4 - ((size + RXW_PADDING) % 4)) % 4; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2125 | |
| 2126 | if (unlikely(rx_cmd_a & RX_CMD_A_RED)) { |
| 2127 | netif_dbg(dev, rx_err, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2128 | "Error rx_cmd_a=0x%08x\n", rx_cmd_a); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2129 | dev->net->stats.rx_errors++; |
| 2130 | dev->net->stats.rx_dropped++; |
| 2131 | |
| 2132 | if (rx_cmd_a & RX_CMD_A_FCS) |
| 2133 | dev->net->stats.rx_crc_errors++; |
| 2134 | else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT)) |
| 2135 | dev->net->stats.rx_frame_errors++; |
| 2136 | } else { |
| 2137 | /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ |
| 2138 | if (unlikely(size > (ETH_FRAME_LEN + 12))) { |
| 2139 | netif_dbg(dev, rx_err, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2140 | "size err rx_cmd_a=0x%08x\n", |
| 2141 | rx_cmd_a); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | /* last frame in this batch */ |
| 2146 | if (skb->len == size) { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 2147 | smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a, |
| 2148 | rx_cmd_b); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2149 | |
| 2150 | skb_trim(skb, skb->len - 4); /* remove fcs */ |
| 2151 | skb->truesize = size + sizeof(struct sk_buff); |
| 2152 | |
| 2153 | return 1; |
| 2154 | } |
| 2155 | |
| 2156 | ax_skb = skb_clone(skb, GFP_ATOMIC); |
| 2157 | if (unlikely(!ax_skb)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2158 | netdev_warn(dev->net, "Error allocating skb\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2159 | return 0; |
| 2160 | } |
| 2161 | |
| 2162 | ax_skb->len = size; |
| 2163 | ax_skb->data = packet; |
| 2164 | skb_set_tail_pointer(ax_skb, size); |
| 2165 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 2166 | smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a, |
| 2167 | rx_cmd_b); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2168 | |
| 2169 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ |
| 2170 | ax_skb->truesize = size + sizeof(struct sk_buff); |
| 2171 | |
| 2172 | usbnet_skb_return(dev, ax_skb); |
| 2173 | } |
| 2174 | |
| 2175 | skb_pull(skb, size); |
| 2176 | |
| 2177 | /* padding bytes before the next frame starts */ |
| 2178 | if (skb->len) |
| 2179 | skb_pull(skb, align_count); |
| 2180 | } |
| 2181 | |
| 2182 | if (unlikely(skb->len < 0)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 2183 | netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | return 1; |
| 2188 | } |
| 2189 | |
| 2190 | static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev, |
| 2191 | struct sk_buff *skb, gfp_t flags) |
| 2192 | { |
| 2193 | u32 tx_cmd_a, tx_cmd_b; |
| 2194 | |
| 2195 | skb_linearize(skb); |
| 2196 | |
| 2197 | if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) { |
| 2198 | struct sk_buff *skb2 = |
| 2199 | skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags); |
| 2200 | dev_kfree_skb_any(skb); |
| 2201 | skb = skb2; |
| 2202 | if (!skb) |
| 2203 | return NULL; |
| 2204 | } |
| 2205 | |
| 2206 | tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS; |
| 2207 | |
| 2208 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 2209 | tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE; |
| 2210 | |
| 2211 | if (skb_is_gso(skb)) { |
| 2212 | u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN); |
| 2213 | tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS; |
| 2214 | |
| 2215 | tx_cmd_a |= TX_CMD_A_LSO; |
| 2216 | } else { |
| 2217 | tx_cmd_b = 0; |
| 2218 | } |
| 2219 | |
| 2220 | skb_push(skb, 4); |
| 2221 | cpu_to_le32s(&tx_cmd_b); |
| 2222 | memcpy(skb->data, &tx_cmd_b, 4); |
| 2223 | |
| 2224 | skb_push(skb, 4); |
| 2225 | cpu_to_le32s(&tx_cmd_a); |
| 2226 | memcpy(skb->data, &tx_cmd_a, 4); |
| 2227 | |
| 2228 | return skb; |
| 2229 | } |
| 2230 | |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2231 | static int smsc75xx_manage_power(struct usbnet *dev, int on) |
| 2232 | { |
| 2233 | dev->intf->needs_remote_wakeup = on; |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2237 | static const struct driver_info smsc75xx_info = { |
| 2238 | .description = "smsc75xx USB 2.0 Gigabit Ethernet", |
| 2239 | .bind = smsc75xx_bind, |
| 2240 | .unbind = smsc75xx_unbind, |
| 2241 | .link_reset = smsc75xx_link_reset, |
| 2242 | .reset = smsc75xx_reset, |
| 2243 | .rx_fixup = smsc75xx_rx_fixup, |
| 2244 | .tx_fixup = smsc75xx_tx_fixup, |
| 2245 | .status = smsc75xx_status, |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2246 | .manage_power = smsc75xx_manage_power, |
Steve Glendinning | 7bdd305 | 2012-04-30 07:56:50 +0000 | [diff] [blame] | 2247 | .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2248 | }; |
| 2249 | |
| 2250 | static const struct usb_device_id products[] = { |
| 2251 | { |
| 2252 | /* SMSC7500 USB Gigabit Ethernet Device */ |
| 2253 | USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500), |
| 2254 | .driver_info = (unsigned long) &smsc75xx_info, |
| 2255 | }, |
| 2256 | { |
| 2257 | /* SMSC7500 USB Gigabit Ethernet Device */ |
| 2258 | USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505), |
| 2259 | .driver_info = (unsigned long) &smsc75xx_info, |
| 2260 | }, |
| 2261 | { }, /* END */ |
| 2262 | }; |
| 2263 | MODULE_DEVICE_TABLE(usb, products); |
| 2264 | |
| 2265 | static struct usb_driver smsc75xx_driver = { |
| 2266 | .name = SMSC_CHIPNAME, |
| 2267 | .id_table = products, |
| 2268 | .probe = usbnet_probe, |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 2269 | .suspend = smsc75xx_suspend, |
| 2270 | .resume = smsc75xx_resume, |
| 2271 | .reset_resume = smsc75xx_resume, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2272 | .disconnect = usbnet_disconnect, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 2273 | .disable_hub_initiated_lpm = 1, |
Steve Glendinning | b4cdea9 | 2012-11-28 05:59:49 +0000 | [diff] [blame] | 2274 | .supports_autosuspend = 1, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2275 | }; |
| 2276 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 2277 | module_usb_driver(smsc75xx_driver); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2278 | |
| 2279 | MODULE_AUTHOR("Nancy Lin"); |
Steve Glendinning | 90b24cf | 2012-04-16 12:13:29 +0100 | [diff] [blame] | 2280 | MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 2281 | MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices"); |
| 2282 | MODULE_LICENSE("GPL"); |