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 | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 57 | #define SUPPORTED_WAKE (WAKE_UCAST | WAKE_BCAST | \ |
| 58 | WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 59 | |
| 60 | #define check_warn(ret, fmt, args...) \ |
| 61 | ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); }) |
| 62 | |
| 63 | #define check_warn_return(ret, fmt, args...) \ |
| 64 | ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } }) |
| 65 | |
| 66 | #define check_warn_goto_done(ret, fmt, args...) \ |
| 67 | ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } }) |
| 68 | |
| 69 | struct smsc75xx_priv { |
| 70 | struct usbnet *dev; |
| 71 | u32 rfe_ctl; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 72 | u32 wolopts; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 73 | u32 multicast_hash_table[DP_SEL_VHF_HASH_LEN]; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 74 | struct mutex dataport_mutex; |
| 75 | spinlock_t rfe_ctl_lock; |
| 76 | struct work_struct set_multicast; |
| 77 | }; |
| 78 | |
| 79 | struct usb_context { |
| 80 | struct usb_ctrlrequest req; |
| 81 | struct usbnet *dev; |
| 82 | }; |
| 83 | |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 84 | static bool turbo_mode = true; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 85 | module_param(turbo_mode, bool, 0644); |
| 86 | MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); |
| 87 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 88 | static int __must_check __smsc75xx_read_reg(struct usbnet *dev, u32 index, |
| 89 | u32 *data, int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 90 | { |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 91 | u32 buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 92 | int ret; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 93 | int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 94 | |
| 95 | BUG_ON(!dev); |
| 96 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 97 | if (!in_pm) |
| 98 | fn = usbnet_read_cmd; |
| 99 | else |
| 100 | fn = usbnet_read_cmd_nopm; |
| 101 | |
| 102 | ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN |
| 103 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 104 | 0, index, &buf, 4); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 105 | if (unlikely(ret < 0)) |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 106 | netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", |
| 107 | index, ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 108 | |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 109 | le32_to_cpus(&buf); |
| 110 | *data = buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 115 | static int __must_check __smsc75xx_write_reg(struct usbnet *dev, u32 index, |
| 116 | u32 data, int in_pm) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 117 | { |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 118 | u32 buf; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 119 | int ret; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 120 | int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 121 | |
| 122 | BUG_ON(!dev); |
| 123 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 124 | if (!in_pm) |
| 125 | fn = usbnet_write_cmd; |
| 126 | else |
| 127 | fn = usbnet_write_cmd_nopm; |
| 128 | |
Ming Lei | 2b2e41e | 2012-10-24 19:47:03 +0000 | [diff] [blame] | 129 | buf = data; |
| 130 | cpu_to_le32s(&buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 131 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 132 | ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT |
| 133 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 134 | 0, index, &buf, 4); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 135 | if (unlikely(ret < 0)) |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 136 | netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", |
| 137 | index, ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 138 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 139 | return ret; |
| 140 | } |
| 141 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 142 | static int __must_check smsc75xx_read_reg_nopm(struct usbnet *dev, u32 index, |
| 143 | u32 *data) |
| 144 | { |
| 145 | return __smsc75xx_read_reg(dev, index, data, 1); |
| 146 | } |
| 147 | |
| 148 | static int __must_check smsc75xx_write_reg_nopm(struct usbnet *dev, u32 index, |
| 149 | u32 data) |
| 150 | { |
| 151 | return __smsc75xx_write_reg(dev, index, data, 1); |
| 152 | } |
| 153 | |
| 154 | static int __must_check smsc75xx_read_reg(struct usbnet *dev, u32 index, |
| 155 | u32 *data) |
| 156 | { |
| 157 | return __smsc75xx_read_reg(dev, index, data, 0); |
| 158 | } |
| 159 | |
| 160 | static int __must_check smsc75xx_write_reg(struct usbnet *dev, u32 index, |
| 161 | u32 data) |
| 162 | { |
| 163 | return __smsc75xx_write_reg(dev, index, data, 0); |
| 164 | } |
| 165 | |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 166 | static int smsc75xx_set_feature(struct usbnet *dev, u32 feature) |
| 167 | { |
| 168 | if (WARN_ON_ONCE(!dev)) |
| 169 | return -EINVAL; |
| 170 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 171 | return usbnet_write_cmd_nopm(dev, USB_REQ_SET_FEATURE, |
| 172 | USB_DIR_OUT | USB_RECIP_DEVICE, |
| 173 | feature, 0, NULL, 0); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int smsc75xx_clear_feature(struct usbnet *dev, u32 feature) |
| 177 | { |
| 178 | if (WARN_ON_ONCE(!dev)) |
| 179 | return -EINVAL; |
| 180 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 181 | return usbnet_write_cmd_nopm(dev, USB_REQ_CLEAR_FEATURE, |
| 182 | USB_DIR_OUT | USB_RECIP_DEVICE, |
| 183 | feature, 0, NULL, 0); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 186 | /* Loop until the read is completed with timeout |
| 187 | * called with phy_mutex held */ |
| 188 | static int smsc75xx_phy_wait_not_busy(struct usbnet *dev) |
| 189 | { |
| 190 | unsigned long start_time = jiffies; |
| 191 | u32 val; |
| 192 | int ret; |
| 193 | |
| 194 | do { |
| 195 | ret = smsc75xx_read_reg(dev, MII_ACCESS, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 196 | check_warn_return(ret, "Error reading MII_ACCESS\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 197 | |
| 198 | if (!(val & MII_ACCESS_BUSY)) |
| 199 | return 0; |
| 200 | } while (!time_after(jiffies, start_time + HZ)); |
| 201 | |
| 202 | return -EIO; |
| 203 | } |
| 204 | |
| 205 | static int smsc75xx_mdio_read(struct net_device *netdev, int phy_id, int idx) |
| 206 | { |
| 207 | struct usbnet *dev = netdev_priv(netdev); |
| 208 | u32 val, addr; |
| 209 | int ret; |
| 210 | |
| 211 | mutex_lock(&dev->phy_mutex); |
| 212 | |
| 213 | /* confirm MII not busy */ |
| 214 | ret = smsc75xx_phy_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 215 | check_warn_goto_done(ret, "MII is busy in smsc75xx_mdio_read\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 216 | |
| 217 | /* set the address, index & direction (read from PHY) */ |
| 218 | phy_id &= dev->mii.phy_id_mask; |
| 219 | idx &= dev->mii.reg_num_mask; |
| 220 | addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) |
| 221 | | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) |
Steve Glendinning | cb8722d | 2012-04-30 07:56:51 +0000 | [diff] [blame] | 222 | | MII_ACCESS_READ | MII_ACCESS_BUSY; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 223 | ret = smsc75xx_write_reg(dev, MII_ACCESS, addr); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 224 | check_warn_goto_done(ret, "Error writing MII_ACCESS\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 225 | |
| 226 | ret = smsc75xx_phy_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 227 | check_warn_goto_done(ret, "Timed out reading MII reg %02X\n", idx); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 228 | |
| 229 | ret = smsc75xx_read_reg(dev, MII_DATA, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 230 | check_warn_goto_done(ret, "Error reading MII_DATA\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 231 | |
| 232 | ret = (u16)(val & 0xFFFF); |
| 233 | |
| 234 | done: |
| 235 | mutex_unlock(&dev->phy_mutex); |
| 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | static void smsc75xx_mdio_write(struct net_device *netdev, int phy_id, int idx, |
| 240 | int regval) |
| 241 | { |
| 242 | struct usbnet *dev = netdev_priv(netdev); |
| 243 | u32 val, addr; |
| 244 | int ret; |
| 245 | |
| 246 | mutex_lock(&dev->phy_mutex); |
| 247 | |
| 248 | /* confirm MII not busy */ |
| 249 | ret = smsc75xx_phy_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 250 | check_warn_goto_done(ret, "MII is busy in smsc75xx_mdio_write\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 251 | |
| 252 | val = regval; |
| 253 | ret = smsc75xx_write_reg(dev, MII_DATA, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 254 | check_warn_goto_done(ret, "Error writing MII_DATA\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 255 | |
| 256 | /* set the address, index & direction (write to PHY) */ |
| 257 | phy_id &= dev->mii.phy_id_mask; |
| 258 | idx &= dev->mii.reg_num_mask; |
| 259 | addr = ((phy_id << MII_ACCESS_PHY_ADDR_SHIFT) & MII_ACCESS_PHY_ADDR) |
| 260 | | ((idx << MII_ACCESS_REG_ADDR_SHIFT) & MII_ACCESS_REG_ADDR) |
Steve Glendinning | cb8722d | 2012-04-30 07:56:51 +0000 | [diff] [blame] | 261 | | MII_ACCESS_WRITE | MII_ACCESS_BUSY; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 262 | ret = smsc75xx_write_reg(dev, MII_ACCESS, addr); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 263 | check_warn_goto_done(ret, "Error writing MII_ACCESS\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 264 | |
| 265 | ret = smsc75xx_phy_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 266 | check_warn_goto_done(ret, "Timed out writing MII reg %02X\n", idx); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 267 | |
| 268 | done: |
| 269 | mutex_unlock(&dev->phy_mutex); |
| 270 | } |
| 271 | |
| 272 | static int smsc75xx_wait_eeprom(struct usbnet *dev) |
| 273 | { |
| 274 | unsigned long start_time = jiffies; |
| 275 | u32 val; |
| 276 | int ret; |
| 277 | |
| 278 | do { |
| 279 | ret = smsc75xx_read_reg(dev, E2P_CMD, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 280 | check_warn_return(ret, "Error reading E2P_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 281 | |
| 282 | if (!(val & E2P_CMD_BUSY) || (val & E2P_CMD_TIMEOUT)) |
| 283 | break; |
| 284 | udelay(40); |
| 285 | } while (!time_after(jiffies, start_time + HZ)); |
| 286 | |
| 287 | if (val & (E2P_CMD_TIMEOUT | E2P_CMD_BUSY)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 288 | netdev_warn(dev->net, "EEPROM read operation timeout\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 289 | return -EIO; |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static int smsc75xx_eeprom_confirm_not_busy(struct usbnet *dev) |
| 296 | { |
| 297 | unsigned long start_time = jiffies; |
| 298 | u32 val; |
| 299 | int ret; |
| 300 | |
| 301 | do { |
| 302 | ret = smsc75xx_read_reg(dev, E2P_CMD, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 303 | check_warn_return(ret, "Error reading E2P_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 304 | |
| 305 | if (!(val & E2P_CMD_BUSY)) |
| 306 | return 0; |
| 307 | |
| 308 | udelay(40); |
| 309 | } while (!time_after(jiffies, start_time + HZ)); |
| 310 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 311 | netdev_warn(dev->net, "EEPROM is busy\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 312 | return -EIO; |
| 313 | } |
| 314 | |
| 315 | static int smsc75xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 316 | u8 *data) |
| 317 | { |
| 318 | u32 val; |
| 319 | int i, ret; |
| 320 | |
| 321 | BUG_ON(!dev); |
| 322 | BUG_ON(!data); |
| 323 | |
| 324 | ret = smsc75xx_eeprom_confirm_not_busy(dev); |
| 325 | if (ret) |
| 326 | return ret; |
| 327 | |
| 328 | for (i = 0; i < length; i++) { |
| 329 | val = E2P_CMD_BUSY | E2P_CMD_READ | (offset & E2P_CMD_ADDR); |
| 330 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 331 | check_warn_return(ret, "Error writing E2P_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 332 | |
| 333 | ret = smsc75xx_wait_eeprom(dev); |
| 334 | if (ret < 0) |
| 335 | return ret; |
| 336 | |
| 337 | ret = smsc75xx_read_reg(dev, E2P_DATA, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 338 | check_warn_return(ret, "Error reading E2P_DATA\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 339 | |
| 340 | data[i] = val & 0xFF; |
| 341 | offset++; |
| 342 | } |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int smsc75xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 348 | u8 *data) |
| 349 | { |
| 350 | u32 val; |
| 351 | int i, ret; |
| 352 | |
| 353 | BUG_ON(!dev); |
| 354 | BUG_ON(!data); |
| 355 | |
| 356 | ret = smsc75xx_eeprom_confirm_not_busy(dev); |
| 357 | if (ret) |
| 358 | return ret; |
| 359 | |
| 360 | /* Issue write/erase enable command */ |
| 361 | val = E2P_CMD_BUSY | E2P_CMD_EWEN; |
| 362 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 363 | check_warn_return(ret, "Error writing E2P_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 364 | |
| 365 | ret = smsc75xx_wait_eeprom(dev); |
| 366 | if (ret < 0) |
| 367 | return ret; |
| 368 | |
| 369 | for (i = 0; i < length; i++) { |
| 370 | |
| 371 | /* Fill data register */ |
| 372 | val = data[i]; |
| 373 | ret = smsc75xx_write_reg(dev, E2P_DATA, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 374 | check_warn_return(ret, "Error writing E2P_DATA\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 375 | |
| 376 | /* Send "write" command */ |
| 377 | val = E2P_CMD_BUSY | E2P_CMD_WRITE | (offset & E2P_CMD_ADDR); |
| 378 | ret = smsc75xx_write_reg(dev, E2P_CMD, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 379 | check_warn_return(ret, "Error writing E2P_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 380 | |
| 381 | ret = smsc75xx_wait_eeprom(dev); |
| 382 | if (ret < 0) |
| 383 | return ret; |
| 384 | |
| 385 | offset++; |
| 386 | } |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static int smsc75xx_dataport_wait_not_busy(struct usbnet *dev) |
| 392 | { |
| 393 | int i, ret; |
| 394 | |
| 395 | for (i = 0; i < 100; i++) { |
| 396 | u32 dp_sel; |
| 397 | ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 398 | check_warn_return(ret, "Error reading DP_SEL\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 399 | |
| 400 | if (dp_sel & DP_SEL_DPRDY) |
| 401 | return 0; |
| 402 | |
| 403 | udelay(40); |
| 404 | } |
| 405 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 406 | netdev_warn(dev->net, "smsc75xx_dataport_wait_not_busy timed out\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 407 | |
| 408 | return -EIO; |
| 409 | } |
| 410 | |
| 411 | static int smsc75xx_dataport_write(struct usbnet *dev, u32 ram_select, u32 addr, |
| 412 | u32 length, u32 *buf) |
| 413 | { |
| 414 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 415 | u32 dp_sel; |
| 416 | int i, ret; |
| 417 | |
| 418 | mutex_lock(&pdata->dataport_mutex); |
| 419 | |
| 420 | ret = smsc75xx_dataport_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 421 | check_warn_goto_done(ret, "smsc75xx_dataport_write busy on entry\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 422 | |
| 423 | ret = smsc75xx_read_reg(dev, DP_SEL, &dp_sel); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 424 | check_warn_goto_done(ret, "Error reading DP_SEL\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 425 | |
| 426 | dp_sel &= ~DP_SEL_RSEL; |
| 427 | dp_sel |= ram_select; |
| 428 | ret = smsc75xx_write_reg(dev, DP_SEL, dp_sel); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 429 | check_warn_goto_done(ret, "Error writing DP_SEL\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 430 | |
| 431 | for (i = 0; i < length; i++) { |
| 432 | ret = smsc75xx_write_reg(dev, DP_ADDR, addr + i); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 433 | check_warn_goto_done(ret, "Error writing DP_ADDR\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 434 | |
| 435 | ret = smsc75xx_write_reg(dev, DP_DATA, buf[i]); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 436 | check_warn_goto_done(ret, "Error writing DP_DATA\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 437 | |
| 438 | ret = smsc75xx_write_reg(dev, DP_CMD, DP_CMD_WRITE); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 439 | check_warn_goto_done(ret, "Error writing DP_CMD\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 440 | |
| 441 | ret = smsc75xx_dataport_wait_not_busy(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 442 | check_warn_goto_done(ret, "smsc75xx_dataport_write timeout\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | done: |
| 446 | mutex_unlock(&pdata->dataport_mutex); |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | /* returns hash bit number for given MAC address */ |
| 451 | static u32 smsc75xx_hash(char addr[ETH_ALEN]) |
| 452 | { |
| 453 | return (ether_crc(ETH_ALEN, addr) >> 23) & 0x1ff; |
| 454 | } |
| 455 | |
| 456 | static void smsc75xx_deferred_multicast_write(struct work_struct *param) |
| 457 | { |
| 458 | struct smsc75xx_priv *pdata = |
| 459 | container_of(param, struct smsc75xx_priv, set_multicast); |
| 460 | struct usbnet *dev = pdata->dev; |
| 461 | int ret; |
| 462 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 463 | netif_dbg(dev, drv, dev->net, "deferred multicast write 0x%08x\n", |
| 464 | pdata->rfe_ctl); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 465 | |
| 466 | smsc75xx_dataport_write(dev, DP_SEL_VHF, DP_SEL_VHF_VLAN_LEN, |
| 467 | DP_SEL_VHF_HASH_LEN, pdata->multicast_hash_table); |
| 468 | |
| 469 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 470 | check_warn(ret, "Error writing RFE_CRL\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void smsc75xx_set_multicast(struct net_device *netdev) |
| 474 | { |
| 475 | struct usbnet *dev = netdev_priv(netdev); |
| 476 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 477 | unsigned long flags; |
| 478 | int i; |
| 479 | |
| 480 | spin_lock_irqsave(&pdata->rfe_ctl_lock, flags); |
| 481 | |
| 482 | pdata->rfe_ctl &= |
| 483 | ~(RFE_CTL_AU | RFE_CTL_AM | RFE_CTL_DPF | RFE_CTL_MHF); |
| 484 | pdata->rfe_ctl |= RFE_CTL_AB; |
| 485 | |
| 486 | for (i = 0; i < DP_SEL_VHF_HASH_LEN; i++) |
| 487 | pdata->multicast_hash_table[i] = 0; |
| 488 | |
| 489 | if (dev->net->flags & IFF_PROMISC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 490 | netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 491 | pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_AU; |
| 492 | } else if (dev->net->flags & IFF_ALLMULTI) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 493 | netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 494 | pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF; |
| 495 | } else if (!netdev_mc_empty(dev->net)) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 496 | struct netdev_hw_addr *ha; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 497 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 498 | netif_dbg(dev, drv, dev->net, "receive multicast hash filter\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 499 | |
| 500 | pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF; |
| 501 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 502 | netdev_for_each_mc_addr(ha, netdev) { |
| 503 | u32 bitnum = smsc75xx_hash(ha->addr); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 504 | pdata->multicast_hash_table[bitnum / 32] |= |
| 505 | (1 << (bitnum % 32)); |
| 506 | } |
| 507 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 508 | netif_dbg(dev, drv, dev->net, "receive own packets only\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 509 | pdata->rfe_ctl |= RFE_CTL_DPF; |
| 510 | } |
| 511 | |
| 512 | spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags); |
| 513 | |
| 514 | /* defer register writes to a sleepable context */ |
| 515 | schedule_work(&pdata->set_multicast); |
| 516 | } |
| 517 | |
| 518 | static int smsc75xx_update_flowcontrol(struct usbnet *dev, u8 duplex, |
| 519 | u16 lcladv, u16 rmtadv) |
| 520 | { |
| 521 | u32 flow = 0, fct_flow = 0; |
| 522 | int ret; |
| 523 | |
| 524 | if (duplex == DUPLEX_FULL) { |
| 525 | u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
| 526 | |
| 527 | if (cap & FLOW_CTRL_TX) { |
| 528 | flow = (FLOW_TX_FCEN | 0xFFFF); |
| 529 | /* set fct_flow thresholds to 20% and 80% */ |
| 530 | fct_flow = (8 << 8) | 32; |
| 531 | } |
| 532 | |
| 533 | if (cap & FLOW_CTRL_RX) |
| 534 | flow |= FLOW_RX_FCEN; |
| 535 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 536 | netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", |
| 537 | (cap & FLOW_CTRL_RX ? "enabled" : "disabled"), |
| 538 | (cap & FLOW_CTRL_TX ? "enabled" : "disabled")); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 539 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 540 | netif_dbg(dev, link, dev->net, "half duplex\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | ret = smsc75xx_write_reg(dev, FLOW, flow); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 544 | check_warn_return(ret, "Error writing FLOW\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 545 | |
| 546 | ret = smsc75xx_write_reg(dev, FCT_FLOW, fct_flow); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 547 | check_warn_return(ret, "Error writing FCT_FLOW\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | static int smsc75xx_link_reset(struct usbnet *dev) |
| 553 | { |
| 554 | struct mii_if_info *mii = &dev->mii; |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 555 | struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 556 | u16 lcladv, rmtadv; |
| 557 | int ret; |
| 558 | |
Steve Glendinning | 4f94a92 | 2012-05-04 00:57:12 +0000 | [diff] [blame] | 559 | /* write to clear phy interrupt status */ |
Steve Glendinning | 7749622 | 2012-05-04 00:57:11 +0000 | [diff] [blame] | 560 | smsc75xx_mdio_write(dev->net, mii->phy_id, PHY_INT_SRC, |
| 561 | PHY_INT_SRC_CLEAR_ALL); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 562 | |
| 563 | ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 564 | check_warn_return(ret, "Error writing INT_STS\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 565 | |
| 566 | mii_check_media(mii, 1, 1); |
| 567 | mii_ethtool_gset(&dev->mii, &ecmd); |
| 568 | lcladv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); |
| 569 | rmtadv = smsc75xx_mdio_read(dev->net, mii->phy_id, MII_LPA); |
| 570 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 571 | netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", |
| 572 | ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 573 | |
| 574 | return smsc75xx_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); |
| 575 | } |
| 576 | |
| 577 | static void smsc75xx_status(struct usbnet *dev, struct urb *urb) |
| 578 | { |
| 579 | u32 intdata; |
| 580 | |
| 581 | if (urb->actual_length != 4) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 582 | netdev_warn(dev->net, "unexpected urb length %d\n", |
| 583 | urb->actual_length); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 584 | return; |
| 585 | } |
| 586 | |
| 587 | memcpy(&intdata, urb->transfer_buffer, 4); |
| 588 | le32_to_cpus(&intdata); |
| 589 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 590 | netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 591 | |
| 592 | if (intdata & INT_ENP_PHY_INT) |
| 593 | usbnet_defer_kevent(dev, EVENT_LINK_RESET); |
| 594 | else |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 595 | netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", |
| 596 | intdata); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 599 | static int smsc75xx_ethtool_get_eeprom_len(struct net_device *net) |
| 600 | { |
| 601 | return MAX_EEPROM_SIZE; |
| 602 | } |
| 603 | |
| 604 | static int smsc75xx_ethtool_get_eeprom(struct net_device *netdev, |
| 605 | struct ethtool_eeprom *ee, u8 *data) |
| 606 | { |
| 607 | struct usbnet *dev = netdev_priv(netdev); |
| 608 | |
| 609 | ee->magic = LAN75XX_EEPROM_MAGIC; |
| 610 | |
| 611 | return smsc75xx_read_eeprom(dev, ee->offset, ee->len, data); |
| 612 | } |
| 613 | |
| 614 | static int smsc75xx_ethtool_set_eeprom(struct net_device *netdev, |
| 615 | struct ethtool_eeprom *ee, u8 *data) |
| 616 | { |
| 617 | struct usbnet *dev = netdev_priv(netdev); |
| 618 | |
| 619 | if (ee->magic != LAN75XX_EEPROM_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 620 | netdev_warn(dev->net, "EEPROM: magic value mismatch: 0x%x\n", |
| 621 | ee->magic); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 622 | return -EINVAL; |
| 623 | } |
| 624 | |
| 625 | return smsc75xx_write_eeprom(dev, ee->offset, ee->len, data); |
| 626 | } |
| 627 | |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 628 | static void smsc75xx_ethtool_get_wol(struct net_device *net, |
| 629 | struct ethtool_wolinfo *wolinfo) |
| 630 | { |
| 631 | struct usbnet *dev = netdev_priv(net); |
| 632 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 633 | |
| 634 | wolinfo->supported = SUPPORTED_WAKE; |
| 635 | wolinfo->wolopts = pdata->wolopts; |
| 636 | } |
| 637 | |
| 638 | static int smsc75xx_ethtool_set_wol(struct net_device *net, |
| 639 | struct ethtool_wolinfo *wolinfo) |
| 640 | { |
| 641 | struct usbnet *dev = netdev_priv(net); |
| 642 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 643 | |
| 644 | pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; |
| 645 | return 0; |
| 646 | } |
| 647 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 648 | static const struct ethtool_ops smsc75xx_ethtool_ops = { |
| 649 | .get_link = usbnet_get_link, |
| 650 | .nway_reset = usbnet_nway_reset, |
| 651 | .get_drvinfo = usbnet_get_drvinfo, |
| 652 | .get_msglevel = usbnet_get_msglevel, |
| 653 | .set_msglevel = usbnet_set_msglevel, |
| 654 | .get_settings = usbnet_get_settings, |
| 655 | .set_settings = usbnet_set_settings, |
| 656 | .get_eeprom_len = smsc75xx_ethtool_get_eeprom_len, |
| 657 | .get_eeprom = smsc75xx_ethtool_get_eeprom, |
| 658 | .set_eeprom = smsc75xx_ethtool_set_eeprom, |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 659 | .get_wol = smsc75xx_ethtool_get_wol, |
| 660 | .set_wol = smsc75xx_ethtool_set_wol, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
| 664 | { |
| 665 | struct usbnet *dev = netdev_priv(netdev); |
| 666 | |
| 667 | if (!netif_running(netdev)) |
| 668 | return -EINVAL; |
| 669 | |
| 670 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); |
| 671 | } |
| 672 | |
| 673 | static void smsc75xx_init_mac_address(struct usbnet *dev) |
| 674 | { |
| 675 | /* try reading mac address from EEPROM */ |
| 676 | if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, |
| 677 | dev->net->dev_addr) == 0) { |
| 678 | if (is_valid_ether_addr(dev->net->dev_addr)) { |
| 679 | /* eeprom values are valid so use them */ |
| 680 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 681 | "MAC address read from EEPROM\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 682 | return; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /* no eeprom, or eeprom values are invalid. generate random MAC */ |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 687 | eth_hw_addr_random(dev->net); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 688 | 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] | 689 | } |
| 690 | |
| 691 | static int smsc75xx_set_mac_address(struct usbnet *dev) |
| 692 | { |
| 693 | u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | |
| 694 | dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; |
| 695 | u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; |
| 696 | |
| 697 | int ret = smsc75xx_write_reg(dev, RX_ADDRH, addr_hi); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 698 | check_warn_return(ret, "Failed to write RX_ADDRH: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 699 | |
| 700 | ret = smsc75xx_write_reg(dev, RX_ADDRL, addr_lo); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 701 | check_warn_return(ret, "Failed to write RX_ADDRL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 702 | |
| 703 | addr_hi |= ADDR_FILTX_FB_VALID; |
| 704 | ret = smsc75xx_write_reg(dev, ADDR_FILTX, addr_hi); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 705 | check_warn_return(ret, "Failed to write ADDR_FILTX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 706 | |
| 707 | ret = smsc75xx_write_reg(dev, ADDR_FILTX + 4, addr_lo); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 708 | check_warn_return(ret, "Failed to write ADDR_FILTX+4: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int smsc75xx_phy_initialize(struct usbnet *dev) |
| 714 | { |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 715 | int bmcr, ret, timeout = 0; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 716 | |
| 717 | /* Initialize MII structure */ |
| 718 | dev->mii.dev = dev->net; |
| 719 | dev->mii.mdio_read = smsc75xx_mdio_read; |
| 720 | dev->mii.mdio_write = smsc75xx_mdio_write; |
| 721 | dev->mii.phy_id_mask = 0x1f; |
| 722 | dev->mii.reg_num_mask = 0x1f; |
Steve Glendinning | c0b92e4 | 2012-04-30 07:56:55 +0000 | [diff] [blame] | 723 | dev->mii.supports_gmii = 1; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 724 | dev->mii.phy_id = SMSC75XX_INTERNAL_PHY_ID; |
| 725 | |
| 726 | /* reset phy and wait for reset to complete */ |
| 727 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); |
| 728 | |
| 729 | do { |
| 730 | msleep(10); |
| 731 | bmcr = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 732 | check_warn_return(bmcr, "Error reading MII_BMCR\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 733 | timeout++; |
Steve Glendinning | 8a1d59d | 2012-04-30 07:56:53 +0000 | [diff] [blame] | 734 | } while ((bmcr & BMCR_RESET) && (timeout < 100)); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 735 | |
| 736 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 737 | netdev_warn(dev->net, "timeout on PHY Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 738 | return -EIO; |
| 739 | } |
| 740 | |
| 741 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, |
| 742 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | |
| 743 | ADVERTISE_PAUSE_ASYM); |
Steve Glendinning | c0b92e4 | 2012-04-30 07:56:55 +0000 | [diff] [blame] | 744 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000, |
| 745 | ADVERTISE_1000FULL); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 746 | |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 747 | /* read and write to clear phy interrupt status */ |
| 748 | ret = smsc75xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 749 | check_warn_return(ret, "Error reading PHY_INT_SRC\n"); |
Steve Glendinning | b140504 | 2012-04-30 07:56:54 +0000 | [diff] [blame] | 750 | 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] | 751 | |
| 752 | smsc75xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, |
| 753 | PHY_INT_MASK_DEFAULT); |
| 754 | mii_nway_restart(&dev->mii); |
| 755 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 756 | netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | static int smsc75xx_set_rx_max_frame_length(struct usbnet *dev, int size) |
| 761 | { |
| 762 | int ret = 0; |
| 763 | u32 buf; |
| 764 | bool rxenabled; |
| 765 | |
| 766 | ret = smsc75xx_read_reg(dev, MAC_RX, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 767 | check_warn_return(ret, "Failed to read MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 768 | |
| 769 | rxenabled = ((buf & MAC_RX_RXEN) != 0); |
| 770 | |
| 771 | if (rxenabled) { |
| 772 | buf &= ~MAC_RX_RXEN; |
| 773 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 774 | check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /* add 4 to size for FCS */ |
| 778 | buf &= ~MAC_RX_MAX_SIZE; |
| 779 | buf |= (((size + 4) << MAC_RX_MAX_SIZE_SHIFT) & MAC_RX_MAX_SIZE); |
| 780 | |
| 781 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 782 | check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 783 | |
| 784 | if (rxenabled) { |
| 785 | buf |= MAC_RX_RXEN; |
| 786 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 787 | check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | static int smsc75xx_change_mtu(struct net_device *netdev, int new_mtu) |
| 794 | { |
| 795 | struct usbnet *dev = netdev_priv(netdev); |
| 796 | |
| 797 | int ret = smsc75xx_set_rx_max_frame_length(dev, new_mtu); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 798 | check_warn_return(ret, "Failed to set mac rx frame length\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 799 | |
| 800 | return usbnet_change_mtu(netdev, new_mtu); |
| 801 | } |
| 802 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 803 | /* Enable or disable Rx checksum offload engine */ |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 804 | static int smsc75xx_set_features(struct net_device *netdev, |
| 805 | netdev_features_t features) |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 806 | { |
| 807 | struct usbnet *dev = netdev_priv(netdev); |
| 808 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 809 | unsigned long flags; |
| 810 | int ret; |
| 811 | |
| 812 | spin_lock_irqsave(&pdata->rfe_ctl_lock, flags); |
| 813 | |
| 814 | if (features & NETIF_F_RXCSUM) |
| 815 | pdata->rfe_ctl |= RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM; |
| 816 | else |
| 817 | pdata->rfe_ctl &= ~(RFE_CTL_TCPUDP_CKM | RFE_CTL_IP_CKM); |
| 818 | |
| 819 | spin_unlock_irqrestore(&pdata->rfe_ctl_lock, flags); |
| 820 | /* it's racing here! */ |
| 821 | |
| 822 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 823 | check_warn_return(ret, "Error writing RFE_CTL\n"); |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 828 | static int smsc75xx_wait_ready(struct usbnet *dev, int in_pm) |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 829 | { |
| 830 | int timeout = 0; |
| 831 | |
| 832 | do { |
| 833 | u32 buf; |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 834 | int ret; |
| 835 | |
| 836 | ret = __smsc75xx_read_reg(dev, PMT_CTL, &buf, in_pm); |
| 837 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 838 | check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret); |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 839 | |
| 840 | if (buf & PMT_CTL_DEV_RDY) |
| 841 | return 0; |
| 842 | |
| 843 | msleep(10); |
| 844 | timeout++; |
| 845 | } while (timeout < 100); |
| 846 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 847 | netdev_warn(dev->net, "timeout waiting for device ready\n"); |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 848 | return -EIO; |
| 849 | } |
| 850 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 851 | static int smsc75xx_reset(struct usbnet *dev) |
| 852 | { |
| 853 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 854 | u32 buf; |
| 855 | int ret = 0, timeout; |
| 856 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 857 | netif_dbg(dev, ifup, dev->net, "entering smsc75xx_reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 858 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 859 | ret = smsc75xx_wait_ready(dev, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 860 | check_warn_return(ret, "device not ready in smsc75xx_reset\n"); |
Steve Glendinning | 8762cec | 2012-09-28 00:57:51 +0000 | [diff] [blame] | 861 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 862 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 863 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 864 | |
| 865 | buf |= HW_CFG_LRST; |
| 866 | |
| 867 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 868 | check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 869 | |
| 870 | timeout = 0; |
| 871 | do { |
| 872 | msleep(10); |
| 873 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 874 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 875 | timeout++; |
| 876 | } while ((buf & HW_CFG_LRST) && (timeout < 100)); |
| 877 | |
| 878 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 879 | netdev_warn(dev->net, "timeout on completion of Lite Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 880 | return -EIO; |
| 881 | } |
| 882 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 883 | netif_dbg(dev, ifup, dev->net, "Lite reset complete, resetting PHY\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 884 | |
| 885 | ret = smsc75xx_read_reg(dev, PMT_CTL, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 886 | check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 887 | |
| 888 | buf |= PMT_CTL_PHY_RST; |
| 889 | |
| 890 | ret = smsc75xx_write_reg(dev, PMT_CTL, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 891 | check_warn_return(ret, "Failed to write PMT_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 892 | |
| 893 | timeout = 0; |
| 894 | do { |
| 895 | msleep(10); |
| 896 | ret = smsc75xx_read_reg(dev, PMT_CTL, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 897 | check_warn_return(ret, "Failed to read PMT_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 898 | timeout++; |
| 899 | } while ((buf & PMT_CTL_PHY_RST) && (timeout < 100)); |
| 900 | |
| 901 | if (timeout >= 100) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 902 | netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 903 | return -EIO; |
| 904 | } |
| 905 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 906 | netif_dbg(dev, ifup, dev->net, "PHY reset complete\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 907 | |
| 908 | smsc75xx_init_mac_address(dev); |
| 909 | |
| 910 | ret = smsc75xx_set_mac_address(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 911 | check_warn_return(ret, "Failed to set mac address\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 912 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 913 | netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", |
| 914 | dev->net->dev_addr); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 915 | |
| 916 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 917 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 918 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 919 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", |
| 920 | buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 921 | |
| 922 | buf |= HW_CFG_BIR; |
| 923 | |
| 924 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 925 | check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 926 | |
| 927 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 928 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 929 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 930 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG after writing HW_CFG_BIR: 0x%08x\n", |
| 931 | buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 932 | |
| 933 | if (!turbo_mode) { |
| 934 | buf = 0; |
| 935 | dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; |
| 936 | } else if (dev->udev->speed == USB_SPEED_HIGH) { |
| 937 | buf = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; |
| 938 | dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; |
| 939 | } else { |
| 940 | buf = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; |
| 941 | dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; |
| 942 | } |
| 943 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 944 | netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", |
| 945 | (ulong)dev->rx_urb_size); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 946 | |
| 947 | ret = smsc75xx_write_reg(dev, BURST_CAP, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 948 | check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 949 | |
| 950 | ret = smsc75xx_read_reg(dev, BURST_CAP, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 951 | check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 952 | |
| 953 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 954 | "Read Value from BURST_CAP after writing: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 955 | |
| 956 | ret = smsc75xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 957 | check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 958 | |
| 959 | ret = smsc75xx_read_reg(dev, BULK_IN_DLY, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 960 | check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 961 | |
| 962 | netif_dbg(dev, ifup, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 963 | "Read Value from BULK_IN_DLY after writing: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 964 | |
| 965 | if (turbo_mode) { |
| 966 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 967 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 968 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 969 | netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 970 | |
| 971 | buf |= (HW_CFG_MEF | HW_CFG_BCE); |
| 972 | |
| 973 | ret = smsc75xx_write_reg(dev, HW_CFG, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 974 | check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 975 | |
| 976 | ret = smsc75xx_read_reg(dev, HW_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 977 | check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 978 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 979 | netif_dbg(dev, ifup, dev->net, "HW_CFG: 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* set FIFO sizes */ |
| 983 | buf = (MAX_RX_FIFO_SIZE - 512) / 512; |
| 984 | ret = smsc75xx_write_reg(dev, FCT_RX_FIFO_END, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 985 | check_warn_return(ret, "Failed to write FCT_RX_FIFO_END: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 986 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 987 | 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] | 988 | |
| 989 | buf = (MAX_TX_FIFO_SIZE - 512) / 512; |
| 990 | ret = smsc75xx_write_reg(dev, FCT_TX_FIFO_END, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 991 | check_warn_return(ret, "Failed to write FCT_TX_FIFO_END: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 992 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 993 | 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] | 994 | |
| 995 | ret = smsc75xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 996 | check_warn_return(ret, "Failed to write INT_STS: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 997 | |
| 998 | ret = smsc75xx_read_reg(dev, ID_REV, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 999 | check_warn_return(ret, "Failed to read ID_REV: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1000 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1001 | netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", buf); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1002 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1003 | ret = smsc75xx_read_reg(dev, E2P_CMD, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1004 | check_warn_return(ret, "Failed to read E2P_CMD: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1005 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1006 | /* only set default GPIO/LED settings if no EEPROM is detected */ |
| 1007 | if (!(buf & E2P_CMD_LOADED)) { |
| 1008 | ret = smsc75xx_read_reg(dev, LED_GPIO_CFG, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1009 | check_warn_return(ret, "Failed to read LED_GPIO_CFG: %d\n", |
| 1010 | ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1011 | |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1012 | buf &= ~(LED_GPIO_CFG_LED2_FUN_SEL | LED_GPIO_CFG_LED10_FUN_SEL); |
| 1013 | buf |= LED_GPIO_CFG_LEDGPIO_EN | LED_GPIO_CFG_LED2_FUN_SEL; |
| 1014 | |
| 1015 | ret = smsc75xx_write_reg(dev, LED_GPIO_CFG, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1016 | check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", |
| 1017 | ret); |
Steve Glendinning | 97138a1 | 2012-05-04 00:57:13 +0000 | [diff] [blame] | 1018 | } |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1019 | |
| 1020 | ret = smsc75xx_write_reg(dev, FLOW, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1021 | check_warn_return(ret, "Failed to write FLOW: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1022 | |
| 1023 | ret = smsc75xx_write_reg(dev, FCT_FLOW, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1024 | check_warn_return(ret, "Failed to write FCT_FLOW: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* Don't need rfe_ctl_lock during initialisation */ |
| 1027 | ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1028 | check_warn_return(ret, "Failed to read RFE_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1029 | |
| 1030 | pdata->rfe_ctl |= RFE_CTL_AB | RFE_CTL_DPF; |
| 1031 | |
| 1032 | ret = smsc75xx_write_reg(dev, RFE_CTL, pdata->rfe_ctl); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1033 | check_warn_return(ret, "Failed to write RFE_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1034 | |
| 1035 | ret = smsc75xx_read_reg(dev, RFE_CTL, &pdata->rfe_ctl); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1036 | check_warn_return(ret, "Failed to read RFE_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1037 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1038 | netif_dbg(dev, ifup, dev->net, "RFE_CTL set to 0x%08x\n", |
| 1039 | pdata->rfe_ctl); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* Enable or disable checksum offload engines */ |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1042 | smsc75xx_set_features(dev->net, dev->net->features); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1043 | |
| 1044 | smsc75xx_set_multicast(dev->net); |
| 1045 | |
| 1046 | ret = smsc75xx_phy_initialize(dev); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1047 | check_warn_return(ret, "Failed to initialize PHY: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1048 | |
| 1049 | ret = smsc75xx_read_reg(dev, INT_EP_CTL, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1050 | check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1051 | |
| 1052 | /* enable PHY interrupts */ |
| 1053 | buf |= INT_ENP_PHY_INT; |
| 1054 | |
| 1055 | ret = smsc75xx_write_reg(dev, INT_EP_CTL, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1056 | check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1057 | |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1058 | /* allow mac to detect speed and duplex from phy */ |
| 1059 | ret = smsc75xx_read_reg(dev, MAC_CR, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1060 | check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret); |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1061 | |
| 1062 | buf |= (MAC_CR_ADD | MAC_CR_ASD); |
| 1063 | ret = smsc75xx_write_reg(dev, MAC_CR, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1064 | check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret); |
Steve Glendinning | 2f3a081 | 2012-04-30 07:56:56 +0000 | [diff] [blame] | 1065 | |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1066 | ret = smsc75xx_read_reg(dev, MAC_TX, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1067 | check_warn_return(ret, "Failed to read MAC_TX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1068 | |
| 1069 | buf |= MAC_TX_TXEN; |
| 1070 | |
| 1071 | ret = smsc75xx_write_reg(dev, MAC_TX, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1072 | check_warn_return(ret, "Failed to write MAC_TX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1073 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1074 | 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] | 1075 | |
| 1076 | ret = smsc75xx_read_reg(dev, FCT_TX_CTL, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1077 | check_warn_return(ret, "Failed to read FCT_TX_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1078 | |
| 1079 | buf |= FCT_TX_CTL_EN; |
| 1080 | |
| 1081 | ret = smsc75xx_write_reg(dev, FCT_TX_CTL, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1082 | check_warn_return(ret, "Failed to write FCT_TX_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1083 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1084 | 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] | 1085 | |
| 1086 | ret = smsc75xx_set_rx_max_frame_length(dev, 1514); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1087 | check_warn_return(ret, "Failed to set max rx frame length\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1088 | |
| 1089 | ret = smsc75xx_read_reg(dev, MAC_RX, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1090 | check_warn_return(ret, "Failed to read MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1091 | |
| 1092 | buf |= MAC_RX_RXEN; |
| 1093 | |
| 1094 | ret = smsc75xx_write_reg(dev, MAC_RX, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1095 | check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1096 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1097 | 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] | 1098 | |
| 1099 | ret = smsc75xx_read_reg(dev, FCT_RX_CTL, &buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1100 | check_warn_return(ret, "Failed to read FCT_RX_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1101 | |
| 1102 | buf |= FCT_RX_CTL_EN; |
| 1103 | |
| 1104 | ret = smsc75xx_write_reg(dev, FCT_RX_CTL, buf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1105 | check_warn_return(ret, "Failed to write FCT_RX_CTL: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1106 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1107 | 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] | 1108 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1109 | netif_dbg(dev, ifup, dev->net, "smsc75xx_reset, return 0\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | static const struct net_device_ops smsc75xx_netdev_ops = { |
| 1114 | .ndo_open = usbnet_open, |
| 1115 | .ndo_stop = usbnet_stop, |
| 1116 | .ndo_start_xmit = usbnet_start_xmit, |
| 1117 | .ndo_tx_timeout = usbnet_tx_timeout, |
| 1118 | .ndo_change_mtu = smsc75xx_change_mtu, |
| 1119 | .ndo_set_mac_address = eth_mac_addr, |
| 1120 | .ndo_validate_addr = eth_validate_addr, |
| 1121 | .ndo_do_ioctl = smsc75xx_ioctl, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1122 | .ndo_set_rx_mode = smsc75xx_set_multicast, |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1123 | .ndo_set_features = smsc75xx_set_features, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1124 | }; |
| 1125 | |
| 1126 | static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) |
| 1127 | { |
| 1128 | struct smsc75xx_priv *pdata = NULL; |
| 1129 | int ret; |
| 1130 | |
| 1131 | printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); |
| 1132 | |
| 1133 | ret = usbnet_get_endpoints(dev, intf); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1134 | check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1135 | |
| 1136 | dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc75xx_priv), |
| 1137 | GFP_KERNEL); |
| 1138 | |
| 1139 | pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 1140 | if (!pdata) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1141 | netdev_warn(dev->net, "Unable to allocate smsc75xx_priv\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1142 | return -ENOMEM; |
| 1143 | } |
| 1144 | |
| 1145 | pdata->dev = dev; |
| 1146 | |
| 1147 | spin_lock_init(&pdata->rfe_ctl_lock); |
| 1148 | mutex_init(&pdata->dataport_mutex); |
| 1149 | |
| 1150 | INIT_WORK(&pdata->set_multicast, smsc75xx_deferred_multicast_write); |
| 1151 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1152 | if (DEFAULT_TX_CSUM_ENABLE) { |
| 1153 | dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 1154 | if (DEFAULT_TSO_ENABLE) |
| 1155 | dev->net->features |= NETIF_F_SG | |
| 1156 | NETIF_F_TSO | NETIF_F_TSO6; |
| 1157 | } |
| 1158 | if (DEFAULT_RX_CSUM_ENABLE) |
| 1159 | dev->net->features |= NETIF_F_RXCSUM; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1160 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1161 | dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 1162 | NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_RXCSUM; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1163 | |
| 1164 | /* Init all registers */ |
| 1165 | ret = smsc75xx_reset(dev); |
Steve Glendinning | 33763b7 | 2012-11-28 05:59:45 +0000 | [diff] [blame] | 1166 | check_warn_return(ret, "smsc75xx_reset error %d\n", ret); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1167 | |
| 1168 | dev->net->netdev_ops = &smsc75xx_netdev_ops; |
| 1169 | dev->net->ethtool_ops = &smsc75xx_ethtool_ops; |
| 1170 | dev->net->flags |= IFF_MULTICAST; |
| 1171 | dev->net->hard_header_len += SMSC75XX_TX_OVERHEAD; |
Stephane Fillod | a99ff7d | 2012-04-15 11:38:29 +0000 | [diff] [blame] | 1172 | dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 1177 | { |
| 1178 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
| 1179 | if (pdata) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1180 | netif_dbg(dev, ifdown, dev->net, "free pdata\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1181 | kfree(pdata); |
| 1182 | pdata = NULL; |
| 1183 | dev->data[0] = 0; |
| 1184 | } |
| 1185 | } |
| 1186 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1187 | static u16 smsc_crc(const u8 *buffer, size_t len) |
| 1188 | { |
| 1189 | return bitrev16(crc16(0xFFFF, buffer, len)); |
| 1190 | } |
| 1191 | |
| 1192 | static int smsc75xx_write_wuff(struct usbnet *dev, int filter, u32 wuf_cfg, |
| 1193 | u32 wuf_mask1) |
| 1194 | { |
| 1195 | int cfg_base = WUF_CFGX + filter * 4; |
| 1196 | int mask_base = WUF_MASKX + filter * 16; |
| 1197 | int ret; |
| 1198 | |
| 1199 | ret = smsc75xx_write_reg(dev, cfg_base, wuf_cfg); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1200 | check_warn_return(ret, "Error writing WUF_CFGX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1201 | |
| 1202 | ret = smsc75xx_write_reg(dev, mask_base, wuf_mask1); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1203 | check_warn_return(ret, "Error writing WUF_MASKX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1204 | |
| 1205 | ret = smsc75xx_write_reg(dev, mask_base + 4, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1206 | check_warn_return(ret, "Error writing WUF_MASKX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1207 | |
| 1208 | ret = smsc75xx_write_reg(dev, mask_base + 8, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1209 | check_warn_return(ret, "Error writing WUF_MASKX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1210 | |
| 1211 | ret = smsc75xx_write_reg(dev, mask_base + 12, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1212 | check_warn_return(ret, "Error writing WUF_MASKX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame^] | 1217 | static int smsc75xx_enter_suspend0(struct usbnet *dev) |
| 1218 | { |
| 1219 | u32 val; |
| 1220 | int ret; |
| 1221 | |
| 1222 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
| 1223 | check_warn_return(ret, "Error reading PMT_CTL\n"); |
| 1224 | |
| 1225 | val &= (~(PMT_CTL_SUS_MODE | PMT_CTL_PHY_RST)); |
| 1226 | val |= PMT_CTL_SUS_MODE_0 | PMT_CTL_WOL_EN | PMT_CTL_WUPS; |
| 1227 | |
| 1228 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
| 1229 | check_warn_return(ret, "Error writing PMT_CTL\n"); |
| 1230 | |
| 1231 | smsc75xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); |
| 1232 | |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | static int smsc75xx_enter_suspend2(struct usbnet *dev) |
| 1237 | { |
| 1238 | u32 val; |
| 1239 | int ret; |
| 1240 | |
| 1241 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
| 1242 | check_warn_return(ret, "Error reading PMT_CTL\n"); |
| 1243 | |
| 1244 | val &= ~(PMT_CTL_SUS_MODE | PMT_CTL_WUPS | PMT_CTL_PHY_RST); |
| 1245 | val |= PMT_CTL_SUS_MODE_2; |
| 1246 | |
| 1247 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
| 1248 | check_warn_return(ret, "Error writing PMT_CTL\n"); |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1253 | static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message) |
| 1254 | { |
| 1255 | struct usbnet *dev = usb_get_intfdata(intf); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1256 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1257 | int ret; |
| 1258 | u32 val; |
| 1259 | |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1260 | ret = usbnet_suspend(intf, message); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1261 | check_warn_return(ret, "usbnet_suspend error\n"); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1262 | |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1263 | /* if no wol options set, enter lowest power SUSPEND2 mode */ |
| 1264 | if (!(pdata->wolopts & SUPPORTED_WAKE)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1265 | netdev_info(dev->net, "entering SUSPEND2 mode\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1266 | |
| 1267 | /* disable energy detect (link up) & wake up events */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1268 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1269 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1270 | |
| 1271 | val &= ~(WUCSR_MPEN | WUCSR_WUEN); |
| 1272 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1273 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1274 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1275 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1276 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1277 | check_warn_return(ret, "Error reading PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1278 | |
| 1279 | val &= ~(PMT_CTL_ED_EN | PMT_CTL_WOL_EN); |
| 1280 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1281 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1282 | check_warn_return(ret, "Error writing PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1283 | |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame^] | 1284 | return smsc75xx_enter_suspend2(dev); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1287 | if (pdata->wolopts & (WAKE_MCAST | WAKE_ARP)) { |
| 1288 | int i, filter = 0; |
| 1289 | |
| 1290 | /* disable all filters */ |
| 1291 | for (i = 0; i < WUF_NUM; i++) { |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1292 | ret = smsc75xx_write_reg_nopm(dev, WUF_CFGX + i * 4, 0); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1293 | check_warn_return(ret, "Error writing WUF_CFGX\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (pdata->wolopts & WAKE_MCAST) { |
| 1297 | const u8 mcast[] = {0x01, 0x00, 0x5E}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1298 | netdev_info(dev->net, "enabling multicast detection\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1299 | |
| 1300 | val = WUF_CFGX_EN | WUF_CFGX_ATYPE_MULTICAST |
| 1301 | | smsc_crc(mcast, 3); |
| 1302 | ret = smsc75xx_write_wuff(dev, filter++, val, 0x0007); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1303 | check_warn_return(ret, "Error writing wakeup filter\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | if (pdata->wolopts & WAKE_ARP) { |
| 1307 | const u8 arp[] = {0x08, 0x06}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1308 | netdev_info(dev->net, "enabling ARP detection\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1309 | |
| 1310 | val = WUF_CFGX_EN | WUF_CFGX_ATYPE_ALL | (0x0C << 16) |
| 1311 | | smsc_crc(arp, 2); |
| 1312 | ret = smsc75xx_write_wuff(dev, filter++, val, 0x0003); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1313 | check_warn_return(ret, "Error writing wakeup filter\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /* clear any pending pattern match packet status */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1317 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1318 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1319 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1320 | val |= WUCSR_WUFR; |
| 1321 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1322 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1323 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1324 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1325 | netdev_info(dev->net, "enabling packet match detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1326 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1327 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1328 | |
| 1329 | val |= WUCSR_WUEN; |
| 1330 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1331 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1332 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1333 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1334 | netdev_info(dev->net, "disabling packet match detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1335 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1336 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1337 | |
| 1338 | val &= ~WUCSR_WUEN; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1339 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1340 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1341 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1344 | /* disable magic, bcast & unicast wakeup sources */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1345 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1346 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1347 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1348 | val &= ~(WUCSR_MPEN | WUCSR_BCST_EN | WUCSR_PFDA_EN); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1349 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1350 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1351 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1352 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1353 | if (pdata->wolopts & WAKE_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1354 | netdev_info(dev->net, "enabling magic packet wakeup\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1355 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1356 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1357 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1358 | /* clear any pending magic packet status */ |
| 1359 | val |= WUCSR_MPR | WUCSR_MPEN; |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1360 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1361 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1362 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1363 | } |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1364 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1365 | if (pdata->wolopts & WAKE_BCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1366 | netdev_info(dev->net, "enabling broadcast detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1367 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1368 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1369 | |
| 1370 | val |= WUCSR_BCAST_FR | WUCSR_BCST_EN; |
| 1371 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1372 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1373 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | if (pdata->wolopts & WAKE_UCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1377 | netdev_info(dev->net, "enabling unicast detection\n"); |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1378 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1379 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1380 | |
| 1381 | val |= WUCSR_WUFR | WUCSR_PFDA_EN; |
| 1382 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1383 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1384 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /* enable receiver to enable frame reception */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1388 | ret = smsc75xx_read_reg_nopm(dev, MAC_RX, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1389 | check_warn_return(ret, "Failed to read MAC_RX: %d\n", ret); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1390 | |
| 1391 | val |= MAC_RX_RXEN; |
| 1392 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1393 | ret = smsc75xx_write_reg_nopm(dev, MAC_RX, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1394 | check_warn_return(ret, "Failed to write MAC_RX: %d\n", ret); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1395 | |
| 1396 | /* some wol options are enabled, so enter SUSPEND0 */ |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1397 | netdev_info(dev->net, "entering SUSPEND0 mode\n"); |
Steve Glendinning | 9deb275 | 2012-11-28 05:59:46 +0000 | [diff] [blame^] | 1398 | return smsc75xx_enter_suspend0(dev); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | static int smsc75xx_resume(struct usb_interface *intf) |
| 1402 | { |
| 1403 | struct usbnet *dev = usb_get_intfdata(intf); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1404 | struct smsc75xx_priv *pdata = (struct smsc75xx_priv *)(dev->data[0]); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1405 | int ret; |
| 1406 | u32 val; |
| 1407 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1408 | if (pdata->wolopts) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1409 | netdev_info(dev->net, "resuming from SUSPEND0\n"); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1410 | |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1411 | smsc75xx_clear_feature(dev, USB_DEVICE_REMOTE_WAKEUP); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1412 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1413 | /* Disable wakeup sources */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1414 | ret = smsc75xx_read_reg_nopm(dev, WUCSR, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1415 | check_warn_return(ret, "Error reading WUCSR\n"); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1416 | |
Steve Glendinning | 899a391 | 2012-10-30 07:46:32 +0000 | [diff] [blame] | 1417 | val &= ~(WUCSR_WUEN | WUCSR_MPEN | WUCSR_PFDA_EN |
| 1418 | | WUCSR_BCST_EN); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1419 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1420 | ret = smsc75xx_write_reg_nopm(dev, WUCSR, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1421 | check_warn_return(ret, "Error writing WUCSR\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1422 | |
| 1423 | /* clear wake-up status */ |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1424 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1425 | check_warn_return(ret, "Error reading PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1426 | |
| 1427 | val &= ~PMT_CTL_WOL_EN; |
| 1428 | val |= PMT_CTL_WUPS; |
| 1429 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1430 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1431 | check_warn_return(ret, "Error writing PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1432 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1433 | netdev_info(dev->net, "resuming from SUSPEND2\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1434 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1435 | ret = smsc75xx_read_reg_nopm(dev, PMT_CTL, &val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1436 | check_warn_return(ret, "Error reading PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1437 | |
| 1438 | val |= PMT_CTL_PHY_PWRUP; |
| 1439 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1440 | ret = smsc75xx_write_reg_nopm(dev, PMT_CTL, val); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1441 | check_warn_return(ret, "Error writing PMT_CTL\n"); |
Steve Glendinning | 6c63650 | 2012-09-28 00:57:53 +0000 | [diff] [blame] | 1442 | } |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1443 | |
Ming Lei | 47bbea4 | 2012-11-06 04:53:05 +0000 | [diff] [blame] | 1444 | ret = smsc75xx_wait_ready(dev, 1); |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1445 | check_warn_return(ret, "device not ready in smsc75xx_resume\n"); |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1446 | |
| 1447 | return usbnet_resume(intf); |
| 1448 | } |
| 1449 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1450 | static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb, |
| 1451 | u32 rx_cmd_a, u32 rx_cmd_b) |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1452 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1453 | if (!(dev->net->features & NETIF_F_RXCSUM) || |
| 1454 | unlikely(rx_cmd_a & RX_CMD_A_LCSM)) { |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1455 | skb->ip_summed = CHECKSUM_NONE; |
| 1456 | } else { |
| 1457 | skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT)); |
| 1458 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
| 1463 | { |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1464 | while (skb->len > 0) { |
| 1465 | u32 rx_cmd_a, rx_cmd_b, align_count, size; |
| 1466 | struct sk_buff *ax_skb; |
| 1467 | unsigned char *packet; |
| 1468 | |
| 1469 | memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a)); |
| 1470 | le32_to_cpus(&rx_cmd_a); |
| 1471 | skb_pull(skb, 4); |
| 1472 | |
| 1473 | memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b)); |
| 1474 | le32_to_cpus(&rx_cmd_b); |
Nico Erfurth | ea1649d | 2011-11-08 07:30:40 +0000 | [diff] [blame] | 1475 | skb_pull(skb, 4 + RXW_PADDING); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1476 | |
| 1477 | packet = skb->data; |
| 1478 | |
| 1479 | /* get the packet length */ |
Nico Erfurth | ea1649d | 2011-11-08 07:30:40 +0000 | [diff] [blame] | 1480 | size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING; |
| 1481 | align_count = (4 - ((size + RXW_PADDING) % 4)) % 4; |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (unlikely(rx_cmd_a & RX_CMD_A_RED)) { |
| 1484 | netif_dbg(dev, rx_err, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1485 | "Error rx_cmd_a=0x%08x\n", rx_cmd_a); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1486 | dev->net->stats.rx_errors++; |
| 1487 | dev->net->stats.rx_dropped++; |
| 1488 | |
| 1489 | if (rx_cmd_a & RX_CMD_A_FCS) |
| 1490 | dev->net->stats.rx_crc_errors++; |
| 1491 | else if (rx_cmd_a & (RX_CMD_A_LONG | RX_CMD_A_RUNT)) |
| 1492 | dev->net->stats.rx_frame_errors++; |
| 1493 | } else { |
| 1494 | /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ |
| 1495 | if (unlikely(size > (ETH_FRAME_LEN + 12))) { |
| 1496 | netif_dbg(dev, rx_err, dev->net, |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1497 | "size err rx_cmd_a=0x%08x\n", |
| 1498 | rx_cmd_a); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | |
| 1502 | /* last frame in this batch */ |
| 1503 | if (skb->len == size) { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1504 | smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a, |
| 1505 | rx_cmd_b); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1506 | |
| 1507 | skb_trim(skb, skb->len - 4); /* remove fcs */ |
| 1508 | skb->truesize = size + sizeof(struct sk_buff); |
| 1509 | |
| 1510 | return 1; |
| 1511 | } |
| 1512 | |
| 1513 | ax_skb = skb_clone(skb, GFP_ATOMIC); |
| 1514 | if (unlikely(!ax_skb)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1515 | netdev_warn(dev->net, "Error allocating skb\n"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | ax_skb->len = size; |
| 1520 | ax_skb->data = packet; |
| 1521 | skb_set_tail_pointer(ax_skb, size); |
| 1522 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1523 | smsc75xx_rx_csum_offload(dev, ax_skb, rx_cmd_a, |
| 1524 | rx_cmd_b); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1525 | |
| 1526 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ |
| 1527 | ax_skb->truesize = size + sizeof(struct sk_buff); |
| 1528 | |
| 1529 | usbnet_skb_return(dev, ax_skb); |
| 1530 | } |
| 1531 | |
| 1532 | skb_pull(skb, size); |
| 1533 | |
| 1534 | /* padding bytes before the next frame starts */ |
| 1535 | if (skb->len) |
| 1536 | skb_pull(skb, align_count); |
| 1537 | } |
| 1538 | |
| 1539 | if (unlikely(skb->len < 0)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1540 | netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | return 1; |
| 1545 | } |
| 1546 | |
| 1547 | static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev, |
| 1548 | struct sk_buff *skb, gfp_t flags) |
| 1549 | { |
| 1550 | u32 tx_cmd_a, tx_cmd_b; |
| 1551 | |
| 1552 | skb_linearize(skb); |
| 1553 | |
| 1554 | if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) { |
| 1555 | struct sk_buff *skb2 = |
| 1556 | skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags); |
| 1557 | dev_kfree_skb_any(skb); |
| 1558 | skb = skb2; |
| 1559 | if (!skb) |
| 1560 | return NULL; |
| 1561 | } |
| 1562 | |
| 1563 | tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS; |
| 1564 | |
| 1565 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 1566 | tx_cmd_a |= TX_CMD_A_IPE | TX_CMD_A_TPE; |
| 1567 | |
| 1568 | if (skb_is_gso(skb)) { |
| 1569 | u16 mss = max(skb_shinfo(skb)->gso_size, TX_MSS_MIN); |
| 1570 | tx_cmd_b = (mss << TX_CMD_B_MSS_SHIFT) & TX_CMD_B_MSS; |
| 1571 | |
| 1572 | tx_cmd_a |= TX_CMD_A_LSO; |
| 1573 | } else { |
| 1574 | tx_cmd_b = 0; |
| 1575 | } |
| 1576 | |
| 1577 | skb_push(skb, 4); |
| 1578 | cpu_to_le32s(&tx_cmd_b); |
| 1579 | memcpy(skb->data, &tx_cmd_b, 4); |
| 1580 | |
| 1581 | skb_push(skb, 4); |
| 1582 | cpu_to_le32s(&tx_cmd_a); |
| 1583 | memcpy(skb->data, &tx_cmd_a, 4); |
| 1584 | |
| 1585 | return skb; |
| 1586 | } |
| 1587 | |
| 1588 | static const struct driver_info smsc75xx_info = { |
| 1589 | .description = "smsc75xx USB 2.0 Gigabit Ethernet", |
| 1590 | .bind = smsc75xx_bind, |
| 1591 | .unbind = smsc75xx_unbind, |
| 1592 | .link_reset = smsc75xx_link_reset, |
| 1593 | .reset = smsc75xx_reset, |
| 1594 | .rx_fixup = smsc75xx_rx_fixup, |
| 1595 | .tx_fixup = smsc75xx_tx_fixup, |
| 1596 | .status = smsc75xx_status, |
Steve Glendinning | 7bdd305 | 2012-04-30 07:56:50 +0000 | [diff] [blame] | 1597 | .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1598 | }; |
| 1599 | |
| 1600 | static const struct usb_device_id products[] = { |
| 1601 | { |
| 1602 | /* SMSC7500 USB Gigabit Ethernet Device */ |
| 1603 | USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7500), |
| 1604 | .driver_info = (unsigned long) &smsc75xx_info, |
| 1605 | }, |
| 1606 | { |
| 1607 | /* SMSC7500 USB Gigabit Ethernet Device */ |
| 1608 | USB_DEVICE(USB_VENDOR_ID_SMSC, USB_PRODUCT_ID_LAN7505), |
| 1609 | .driver_info = (unsigned long) &smsc75xx_info, |
| 1610 | }, |
| 1611 | { }, /* END */ |
| 1612 | }; |
| 1613 | MODULE_DEVICE_TABLE(usb, products); |
| 1614 | |
| 1615 | static struct usb_driver smsc75xx_driver = { |
| 1616 | .name = SMSC_CHIPNAME, |
| 1617 | .id_table = products, |
| 1618 | .probe = usbnet_probe, |
Steve Glendinning | 16c79a0 | 2012-09-28 00:57:52 +0000 | [diff] [blame] | 1619 | .suspend = smsc75xx_suspend, |
| 1620 | .resume = smsc75xx_resume, |
| 1621 | .reset_resume = smsc75xx_resume, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1622 | .disconnect = usbnet_disconnect, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 1623 | .disable_hub_initiated_lpm = 1, |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1624 | }; |
| 1625 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 1626 | module_usb_driver(smsc75xx_driver); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1627 | |
| 1628 | MODULE_AUTHOR("Nancy Lin"); |
Steve Glendinning | 90b24cf | 2012-04-16 12:13:29 +0100 | [diff] [blame] | 1629 | MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); |
Steve Glendinning | d0cad87 | 2010-03-16 08:46:46 +0000 | [diff] [blame] | 1630 | MODULE_DESCRIPTION("SMSC75XX USB 2.0 Gigabit Ethernet Devices"); |
| 1631 | MODULE_LICENSE("GPL"); |