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