blob: d07bf4cb893f878c2a2a7f40e5c5691304fbdbf5 [file] [log] [blame]
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001 /***************************************************************************
2 *
3 * Copyright (C) 2007-2008 SMSC
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
Jeff Kirsher9cb00072013-12-06 06:28:46 -080016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Steve Glendinning2f7ca802008-10-02 05:27:57 +000017 *
18 *****************************************************************************/
19
20#include <linux/module.h>
21#include <linux/kmod.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000022#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/ethtool.h>
25#include <linux/mii.h>
26#include <linux/usb.h>
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +000027#include <linux/bitrev.h>
28#include <linux/crc16.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000029#include <linux/crc32.h>
30#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000032#include "smsc95xx.h"
33
34#define SMSC_CHIPNAME "smsc95xx"
Steve Glendinningf7b29272008-11-20 04:19:21 -080035#define SMSC_DRIVER_VERSION "1.0.4"
Steve Glendinning2f7ca802008-10-02 05:27:57 +000036#define HS_USB_PKT_SIZE (512)
37#define FS_USB_PKT_SIZE (64)
38#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
39#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
40#define DEFAULT_BULK_IN_DELAY (0x00002000)
41#define MAX_SINGLE_PACKET_SIZE (2048)
42#define LAN95XX_EEPROM_MAGIC (0x9500)
43#define EEPROM_MAC_OFFSET (0x01)
Steve Glendinningf7b29272008-11-20 04:19:21 -080044#define DEFAULT_TX_CSUM_ENABLE (true)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000045#define DEFAULT_RX_CSUM_ENABLE (true)
46#define SMSC95XX_INTERNAL_PHY_ID (1)
47#define SMSC95XX_TX_OVERHEAD (8)
Steve Glendinningf7b29272008-11-20 04:19:21 -080048#define SMSC95XX_TX_OVERHEAD_CSUM (12)
Steve Glendinninge5e3af82012-11-22 08:05:24 +000049#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +000050 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000051
Steve Glendinning9ebca502012-11-22 08:05:23 +000052#define FEATURE_8_WAKEUP_FILTERS (0x01)
53#define FEATURE_PHY_NLP_CROSSOVER (0x02)
Ming Leieb970ff2013-02-22 03:05:05 +000054#define FEATURE_REMOTE_WAKEUP (0x04)
Steve Glendinning9ebca502012-11-22 08:05:23 +000055
Steve Glendinningb2d4b152013-01-03 03:00:16 +000056#define SUSPEND_SUSPEND0 (0x01)
57#define SUSPEND_SUSPEND1 (0x02)
58#define SUSPEND_SUSPEND2 (0x04)
59#define SUSPEND_SUSPEND3 (0x08)
60#define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
61 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
62
Steve Glendinning2f7ca802008-10-02 05:27:57 +000063struct smsc95xx_priv {
64 u32 mac_cr;
Marc Zyngier3c0f3c62011-03-18 03:53:58 +000065 u32 hash_hi;
66 u32 hash_lo;
Steve Glendinninge0e474a2012-09-28 00:07:12 +000067 u32 wolopts;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000068 spinlock_t mac_cr_lock;
Steve Glendinning9ebca502012-11-22 08:05:23 +000069 u8 features;
Steve Glendinningb2d4b152013-01-03 03:00:16 +000070 u8 suspend_flags;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000071};
72
Rusty Russelleb939922011-12-19 14:08:01 +000073static bool turbo_mode = true;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000074module_param(turbo_mode, bool, 0644);
75MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
76
Ming Leiec321152012-11-06 04:53:07 +000077static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
78 u32 *data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000079{
Ming Lei72108fd2012-10-24 19:47:04 +000080 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000081 int ret;
Ming Leiec321152012-11-06 04:53:07 +000082 int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000083
84 BUG_ON(!dev);
85
Ming Leiec321152012-11-06 04:53:07 +000086 if (!in_pm)
87 fn = usbnet_read_cmd;
88 else
89 fn = usbnet_read_cmd_nopm;
90
91 ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
92 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
93 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000094 if (unlikely(ret < 0))
Joe Perches1e1d7412012-11-24 01:27:49 +000095 netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
96 index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000097
Ming Lei72108fd2012-10-24 19:47:04 +000098 le32_to_cpus(&buf);
99 *data = buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000100
101 return ret;
102}
103
Ming Leiec321152012-11-06 04:53:07 +0000104static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
105 u32 data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000106{
Ming Lei72108fd2012-10-24 19:47:04 +0000107 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000108 int ret;
Ming Leiec321152012-11-06 04:53:07 +0000109 int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000110
111 BUG_ON(!dev);
112
Ming Leiec321152012-11-06 04:53:07 +0000113 if (!in_pm)
114 fn = usbnet_write_cmd;
115 else
116 fn = usbnet_write_cmd_nopm;
117
Ming Lei72108fd2012-10-24 19:47:04 +0000118 buf = data;
119 cpu_to_le32s(&buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000120
Ming Leiec321152012-11-06 04:53:07 +0000121 ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
122 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
123 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000124 if (unlikely(ret < 0))
Joe Perches1e1d7412012-11-24 01:27:49 +0000125 netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
126 index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000127
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000128 return ret;
129}
130
Ming Leiec321152012-11-06 04:53:07 +0000131static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
132 u32 *data)
133{
134 return __smsc95xx_read_reg(dev, index, data, 1);
135}
136
137static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
138 u32 data)
139{
140 return __smsc95xx_write_reg(dev, index, data, 1);
141}
142
143static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
144 u32 *data)
145{
146 return __smsc95xx_read_reg(dev, index, data, 0);
147}
148
149static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
150 u32 data)
151{
152 return __smsc95xx_write_reg(dev, index, data, 0);
153}
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000154
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000155/* Loop until the read is completed with timeout
156 * called with phy_mutex held */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000157static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
158 int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000159{
160 unsigned long start_time = jiffies;
161 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000162 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000163
164 do {
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000165 ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000166 if (ret < 0) {
167 netdev_warn(dev->net, "Error reading MII_ACCESS\n");
168 return ret;
169 }
170
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000171 if (!(val & MII_BUSY_))
172 return 0;
173 } while (!time_after(jiffies, start_time + HZ));
174
175 return -EIO;
176}
177
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000178static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
179 int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000180{
181 struct usbnet *dev = netdev_priv(netdev);
182 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000183 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000184
185 mutex_lock(&dev->phy_mutex);
186
187 /* confirm MII not busy */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000188 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000189 if (ret < 0) {
190 netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n");
191 goto done;
192 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000193
194 /* set the address, index & direction (read from PHY) */
195 phy_id &= dev->mii.phy_id_mask;
196 idx &= dev->mii.reg_num_mask;
Steve Glendinning80928802012-11-06 00:08:53 +0000197 addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000198 ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000199 if (ret < 0) {
200 netdev_warn(dev->net, "Error writing MII_ADDR\n");
201 goto done;
202 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000203
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000204 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000205 if (ret < 0) {
206 netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
207 goto done;
208 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000209
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000210 ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000211 if (ret < 0) {
212 netdev_warn(dev->net, "Error reading MII_DATA\n");
213 goto done;
214 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000215
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000216 ret = (u16)(val & 0xFFFF);
217
218done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000219 mutex_unlock(&dev->phy_mutex);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000220 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000221}
222
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000223static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,
224 int idx, int regval, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000225{
226 struct usbnet *dev = netdev_priv(netdev);
227 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000228 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000229
230 mutex_lock(&dev->phy_mutex);
231
232 /* confirm MII not busy */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000233 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000234 if (ret < 0) {
235 netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n");
236 goto done;
237 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000238
239 val = regval;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000240 ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000241 if (ret < 0) {
242 netdev_warn(dev->net, "Error writing MII_DATA\n");
243 goto done;
244 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000245
246 /* set the address, index & direction (write to PHY) */
247 phy_id &= dev->mii.phy_id_mask;
248 idx &= dev->mii.reg_num_mask;
Steve Glendinning80928802012-11-06 00:08:53 +0000249 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000250 ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000251 if (ret < 0) {
252 netdev_warn(dev->net, "Error writing MII_ADDR\n");
253 goto done;
254 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000255
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000256 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000257 if (ret < 0) {
258 netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
259 goto done;
260 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000261
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000262done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000263 mutex_unlock(&dev->phy_mutex);
264}
265
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000266static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
267 int idx)
268{
269 return __smsc95xx_mdio_read(netdev, phy_id, idx, 1);
270}
271
272static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
273 int idx, int regval)
274{
275 __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1);
276}
277
278static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
279{
280 return __smsc95xx_mdio_read(netdev, phy_id, idx, 0);
281}
282
283static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
284 int regval)
285{
286 __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0);
287}
288
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000289static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000290{
291 unsigned long start_time = jiffies;
292 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000293 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000294
295 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000296 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000297 if (ret < 0) {
298 netdev_warn(dev->net, "Error reading E2P_CMD\n");
299 return ret;
300 }
301
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000302 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
303 break;
304 udelay(40);
305 } while (!time_after(jiffies, start_time + HZ));
306
307 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
Joe Perches60b86752010-02-17 10:30:23 +0000308 netdev_warn(dev->net, "EEPROM read operation timeout\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000309 return -EIO;
310 }
311
312 return 0;
313}
314
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000315static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000316{
317 unsigned long start_time = jiffies;
318 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000319 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000320
321 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000322 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000323 if (ret < 0) {
324 netdev_warn(dev->net, "Error reading E2P_CMD\n");
325 return ret;
326 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000327
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000328 if (!(val & E2P_CMD_BUSY_))
329 return 0;
330
331 udelay(40);
332 } while (!time_after(jiffies, start_time + HZ));
333
Joe Perches60b86752010-02-17 10:30:23 +0000334 netdev_warn(dev->net, "EEPROM is busy\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000335 return -EIO;
336}
337
338static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
339 u8 *data)
340{
341 u32 val;
342 int i, ret;
343
344 BUG_ON(!dev);
345 BUG_ON(!data);
346
347 ret = smsc95xx_eeprom_confirm_not_busy(dev);
348 if (ret)
349 return ret;
350
351 for (i = 0; i < length; i++) {
352 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000353 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000354 if (ret < 0) {
355 netdev_warn(dev->net, "Error writing E2P_CMD\n");
356 return ret;
357 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000358
359 ret = smsc95xx_wait_eeprom(dev);
360 if (ret < 0)
361 return ret;
362
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000363 ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000364 if (ret < 0) {
365 netdev_warn(dev->net, "Error reading E2P_DATA\n");
366 return ret;
367 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000368
369 data[i] = val & 0xFF;
370 offset++;
371 }
372
373 return 0;
374}
375
376static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
377 u8 *data)
378{
379 u32 val;
380 int i, ret;
381
382 BUG_ON(!dev);
383 BUG_ON(!data);
384
385 ret = smsc95xx_eeprom_confirm_not_busy(dev);
386 if (ret)
387 return ret;
388
389 /* Issue write/erase enable command */
390 val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000391 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000392 if (ret < 0) {
393 netdev_warn(dev->net, "Error writing E2P_DATA\n");
394 return ret;
395 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000396
397 ret = smsc95xx_wait_eeprom(dev);
398 if (ret < 0)
399 return ret;
400
401 for (i = 0; i < length; i++) {
402
403 /* Fill data register */
404 val = data[i];
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000405 ret = smsc95xx_write_reg(dev, E2P_DATA, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000406 if (ret < 0) {
407 netdev_warn(dev->net, "Error writing E2P_DATA\n");
408 return ret;
409 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000410
411 /* Send "write" command */
412 val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000413 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000414 if (ret < 0) {
415 netdev_warn(dev->net, "Error writing E2P_CMD\n");
416 return ret;
417 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000418
419 ret = smsc95xx_wait_eeprom(dev);
420 if (ret < 0)
421 return ret;
422
423 offset++;
424 }
425
426 return 0;
427}
428
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000429static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000430 u32 data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000431{
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700432 const u16 size = 4;
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000433 u32 buf;
Ming Lei72108fd2012-10-24 19:47:04 +0000434 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000435
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000436 buf = data;
437 cpu_to_le32s(&buf);
438
Ming Lei72108fd2012-10-24 19:47:04 +0000439 ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
440 USB_DIR_OUT | USB_TYPE_VENDOR |
441 USB_RECIP_DEVICE,
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000442 0, index, &buf, size);
Ming Lei72108fd2012-10-24 19:47:04 +0000443 if (ret < 0)
444 netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
445 ret);
446 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000447}
448
449/* returns hash bit number for given MAC address
450 * example:
451 * 01 00 5E 00 00 01 -> returns bit number 31 */
452static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
453{
454 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
455}
456
457static void smsc95xx_set_multicast(struct net_device *netdev)
458{
459 struct usbnet *dev = netdev_priv(netdev);
460 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000461 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000462 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000463
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000464 pdata->hash_hi = 0;
465 pdata->hash_lo = 0;
466
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000467 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
468
469 if (dev->net->flags & IFF_PROMISC) {
Joe Perchesa475f602010-02-17 10:30:24 +0000470 netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000471 pdata->mac_cr |= MAC_CR_PRMS_;
472 pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
473 } else if (dev->net->flags & IFF_ALLMULTI) {
Joe Perchesa475f602010-02-17 10:30:24 +0000474 netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000475 pdata->mac_cr |= MAC_CR_MCPAS_;
476 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000477 } else if (!netdev_mc_empty(dev->net)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000478 struct netdev_hw_addr *ha;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000479
480 pdata->mac_cr |= MAC_CR_HPFILT_;
481 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
482
Jiri Pirko22bedad32010-04-01 21:22:57 +0000483 netdev_for_each_mc_addr(ha, netdev) {
484 u32 bitnum = smsc95xx_hash(ha->addr);
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000485 u32 mask = 0x01 << (bitnum & 0x1F);
486 if (bitnum & 0x20)
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000487 pdata->hash_hi |= mask;
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000488 else
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000489 pdata->hash_lo |= mask;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000490 }
491
Joe Perchesa475f602010-02-17 10:30:24 +0000492 netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000493 pdata->hash_hi, pdata->hash_lo);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000494 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000495 netif_dbg(dev, drv, dev->net, "receive own packets only\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000496 pdata->mac_cr &=
497 ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
498 }
499
500 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
501
502 /* Initiate async writes, as we can't wait for completion here */
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000503 ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi);
Steve Glendinningb052e072012-11-30 05:55:52 +0000504 if (ret < 0)
505 netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000506
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000507 ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo);
Steve Glendinningb052e072012-11-30 05:55:52 +0000508 if (ret < 0)
509 netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000510
Steve Glendinning7b9e7582012-12-10 01:03:08 +0000511 ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr);
Steve Glendinningb052e072012-11-30 05:55:52 +0000512 if (ret < 0)
513 netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000514}
515
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000516static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
517 u16 lcladv, u16 rmtadv)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000518{
519 u32 flow, afc_cfg = 0;
520
521 int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000522 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000523 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000524
525 if (duplex == DUPLEX_FULL) {
Steve Glendinningbc02ff92008-12-16 02:00:48 -0800526 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000527
528 if (cap & FLOW_CTRL_RX)
529 flow = 0xFFFF0002;
530 else
531 flow = 0;
532
533 if (cap & FLOW_CTRL_TX)
534 afc_cfg |= 0xF;
535 else
536 afc_cfg &= ~0xF;
537
Joe Perchesa475f602010-02-17 10:30:24 +0000538 netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
Joe Perches60b86752010-02-17 10:30:23 +0000539 cap & FLOW_CTRL_RX ? "enabled" : "disabled",
540 cap & FLOW_CTRL_TX ? "enabled" : "disabled");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000541 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000542 netif_dbg(dev, link, dev->net, "half duplex\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000543 flow = 0;
544 afc_cfg |= 0xF;
545 }
546
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000547 ret = smsc95xx_write_reg(dev, FLOW, flow);
Steve Glendinningb052e072012-11-30 05:55:52 +0000548 if (ret < 0)
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000549 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000550
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000551 return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000552}
553
554static int smsc95xx_link_reset(struct usbnet *dev)
555{
556 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
557 struct mii_if_info *mii = &dev->mii;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000558 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000559 unsigned long flags;
560 u16 lcladv, rmtadv;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000561 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000562
563 /* clear interrupt status */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000564 ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000565 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000566 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000567
568 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000569 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000570 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000571
572 mii_check_media(mii, 1, 1);
573 mii_ethtool_gset(&dev->mii, &ecmd);
574 lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
575 rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
576
David Decotigny8ae6dac2011-04-27 18:32:38 +0000577 netif_dbg(dev, link, dev->net,
578 "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
579 ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000580
581 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
582 if (ecmd.duplex != DUPLEX_FULL) {
583 pdata->mac_cr &= ~MAC_CR_FDPX_;
584 pdata->mac_cr |= MAC_CR_RCVOWN_;
585 } else {
586 pdata->mac_cr &= ~MAC_CR_RCVOWN_;
587 pdata->mac_cr |= MAC_CR_FDPX_;
588 }
589 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
590
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000591 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000592 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000593 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000594
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000595 ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
Steve Glendinningb052e072012-11-30 05:55:52 +0000596 if (ret < 0)
597 netdev_warn(dev->net, "Error updating PHY flow control\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000598
Steve Glendinningb052e072012-11-30 05:55:52 +0000599 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000600}
601
602static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
603{
604 u32 intdata;
605
606 if (urb->actual_length != 4) {
Joe Perches60b86752010-02-17 10:30:23 +0000607 netdev_warn(dev->net, "unexpected urb length %d\n",
608 urb->actual_length);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000609 return;
610 }
611
612 memcpy(&intdata, urb->transfer_buffer, 4);
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700613 le32_to_cpus(&intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000614
Joe Perchesa475f602010-02-17 10:30:24 +0000615 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000616
617 if (intdata & INT_ENP_PHY_INT_)
618 usbnet_defer_kevent(dev, EVENT_LINK_RESET);
619 else
Joe Perches60b86752010-02-17 10:30:23 +0000620 netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
621 intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000622}
623
Steve Glendinningf7b29272008-11-20 04:19:21 -0800624/* Enable or disable Tx & Rx checksum offload engines */
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000625static int smsc95xx_set_features(struct net_device *netdev,
626 netdev_features_t features)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000627{
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700628 struct usbnet *dev = netdev_priv(netdev);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000629 u32 read_buf;
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700630 int ret;
631
632 ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000633 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000634 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000635
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700636 if (features & NETIF_F_HW_CSUM)
Steve Glendinningf7b29272008-11-20 04:19:21 -0800637 read_buf |= Tx_COE_EN_;
638 else
639 read_buf &= ~Tx_COE_EN_;
640
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700641 if (features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000642 read_buf |= Rx_COE_EN_;
643 else
644 read_buf &= ~Rx_COE_EN_;
645
646 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000647 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000648 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000649
Joe Perchesa475f602010-02-17 10:30:24 +0000650 netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000651 return 0;
652}
653
654static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
655{
656 return MAX_EEPROM_SIZE;
657}
658
659static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
660 struct ethtool_eeprom *ee, u8 *data)
661{
662 struct usbnet *dev = netdev_priv(netdev);
663
664 ee->magic = LAN95XX_EEPROM_MAGIC;
665
666 return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
667}
668
669static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
670 struct ethtool_eeprom *ee, u8 *data)
671{
672 struct usbnet *dev = netdev_priv(netdev);
673
674 if (ee->magic != LAN95XX_EEPROM_MAGIC) {
Joe Perches60b86752010-02-17 10:30:23 +0000675 netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
676 ee->magic);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000677 return -EINVAL;
678 }
679
680 return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
681}
682
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400683static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
684{
685 /* all smsc95xx registers */
Steve Glendinning96245312012-12-10 01:03:07 +0000686 return COE_CR - ID_REV + sizeof(u32);
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400687}
688
689static void
690smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
691 void *buf)
692{
693 struct usbnet *dev = netdev_priv(netdev);
Dan Carpenterd3484462012-07-10 20:32:51 +0000694 unsigned int i, j;
695 int retval;
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400696 u32 *data = buf;
697
698 retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
699 if (retval < 0) {
700 netdev_warn(netdev, "REGS: cannot read ID_REV\n");
701 return;
702 }
703
704 for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
705 retval = smsc95xx_read_reg(dev, i, &data[j]);
706 if (retval < 0) {
707 netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
708 return;
709 }
710 }
711}
712
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000713static void smsc95xx_ethtool_get_wol(struct net_device *net,
714 struct ethtool_wolinfo *wolinfo)
715{
716 struct usbnet *dev = netdev_priv(net);
717 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
718
719 wolinfo->supported = SUPPORTED_WAKE;
720 wolinfo->wolopts = pdata->wolopts;
721}
722
723static int smsc95xx_ethtool_set_wol(struct net_device *net,
724 struct ethtool_wolinfo *wolinfo)
725{
726 struct usbnet *dev = netdev_priv(net);
727 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning3b146922012-11-30 05:55:50 +0000728 int ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000729
730 pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
Steve Glendinning3b146922012-11-30 05:55:50 +0000731
732 ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
Steve Glendinningb052e072012-11-30 05:55:52 +0000733 if (ret < 0)
734 netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
Steve Glendinning3b146922012-11-30 05:55:50 +0000735
Steve Glendinningb052e072012-11-30 05:55:52 +0000736 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000737}
738
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700739static const struct ethtool_ops smsc95xx_ethtool_ops = {
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000740 .get_link = usbnet_get_link,
741 .nway_reset = usbnet_nway_reset,
742 .get_drvinfo = usbnet_get_drvinfo,
743 .get_msglevel = usbnet_get_msglevel,
744 .set_msglevel = usbnet_set_msglevel,
745 .get_settings = usbnet_get_settings,
746 .set_settings = usbnet_set_settings,
747 .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
748 .get_eeprom = smsc95xx_ethtool_get_eeprom,
749 .set_eeprom = smsc95xx_ethtool_set_eeprom,
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400750 .get_regs_len = smsc95xx_ethtool_getregslen,
751 .get_regs = smsc95xx_ethtool_getregs,
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000752 .get_wol = smsc95xx_ethtool_get_wol,
753 .set_wol = smsc95xx_ethtool_set_wol,
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000754};
755
756static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
757{
758 struct usbnet *dev = netdev_priv(netdev);
759
760 if (!netif_running(netdev))
761 return -EINVAL;
762
763 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
764}
765
766static void smsc95xx_init_mac_address(struct usbnet *dev)
767{
768 /* try reading mac address from EEPROM */
769 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
770 dev->net->dev_addr) == 0) {
771 if (is_valid_ether_addr(dev->net->dev_addr)) {
772 /* eeprom values are valid so use them */
Joe Perchesa475f602010-02-17 10:30:24 +0000773 netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000774 return;
775 }
776 }
777
778 /* no eeprom, or eeprom values are invalid. generate random MAC */
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000779 eth_hw_addr_random(dev->net);
Joe Perchesc7e12ea2012-07-12 19:33:07 +0000780 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000781}
782
783static int smsc95xx_set_mac_address(struct usbnet *dev)
784{
785 u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
786 dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
787 u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
788 int ret;
789
790 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
Steve Glendinningb052e072012-11-30 05:55:52 +0000791 if (ret < 0)
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000792 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000793
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000794 return smsc95xx_write_reg(dev, ADDRH, addr_hi);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000795}
796
797/* starts the TX path */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000798static int smsc95xx_start_tx_path(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000799{
800 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
801 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000802 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000803
804 /* Enable Tx at MAC */
805 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
806 pdata->mac_cr |= MAC_CR_TXEN_;
807 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
808
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000809 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000810 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000811 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000812
813 /* Enable Tx at SCSRs */
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000814 return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000815}
816
817/* Starts the Receive path */
Ming Leiec321152012-11-06 04:53:07 +0000818static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000819{
820 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
821 unsigned long flags;
822
823 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
824 pdata->mac_cr |= MAC_CR_RXEN_;
825 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
826
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000827 return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000828}
829
830static int smsc95xx_phy_initialize(struct usbnet *dev)
831{
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000832 int bmcr, ret, timeout = 0;
Steve Glendinningdb443c42010-03-16 09:03:06 +0000833
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000834 /* Initialize MII structure */
835 dev->mii.dev = dev->net;
836 dev->mii.mdio_read = smsc95xx_mdio_read;
837 dev->mii.mdio_write = smsc95xx_mdio_write;
838 dev->mii.phy_id_mask = 0x1f;
839 dev->mii.reg_num_mask = 0x1f;
840 dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
841
Steve Glendinningdb443c42010-03-16 09:03:06 +0000842 /* reset phy and wait for reset to complete */
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000843 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
Steve Glendinningdb443c42010-03-16 09:03:06 +0000844
845 do {
846 msleep(10);
847 bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
848 timeout++;
Rabin Vincentd9460922011-04-30 08:29:27 +0000849 } while ((bmcr & BMCR_RESET) && (timeout < 100));
Steve Glendinningdb443c42010-03-16 09:03:06 +0000850
851 if (timeout >= 100) {
852 netdev_warn(dev->net, "timeout on PHY Reset");
853 return -EIO;
854 }
855
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000856 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
857 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
858 ADVERTISE_PAUSE_ASYM);
859
860 /* read to clear */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000861 ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
Steve Glendinningb052e072012-11-30 05:55:52 +0000862 if (ret < 0) {
863 netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n");
864 return ret;
865 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000866
867 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
868 PHY_INT_MASK_DEFAULT_);
869 mii_nway_restart(&dev->mii);
870
Joe Perchesa475f602010-02-17 10:30:24 +0000871 netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000872 return 0;
873}
874
875static int smsc95xx_reset(struct usbnet *dev)
876{
877 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
878 u32 read_buf, write_buf, burst_cap;
879 int ret = 0, timeout;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000880
Joe Perchesa475f602010-02-17 10:30:24 +0000881 netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000882
Steve Glendinning44367612012-09-28 00:07:08 +0000883 ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000884 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000885 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000886
887 timeout = 0;
888 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000889 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000890 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000891 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000892 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000893 timeout++;
894 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
895
896 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000897 netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000898 return ret;
899 }
900
Steve Glendinning44367612012-09-28 00:07:08 +0000901 ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000902 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000903 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000904
905 timeout = 0;
906 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000907 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000908 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000909 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000910 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000911 timeout++;
912 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
913
914 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000915 netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000916 return ret;
917 }
918
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000919 ret = smsc95xx_set_mac_address(dev);
920 if (ret < 0)
921 return ret;
922
Joe Perches1e1d7412012-11-24 01:27:49 +0000923 netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
924 dev->net->dev_addr);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000925
926 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000927 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000928 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000929
Joe Perches1e1d7412012-11-24 01:27:49 +0000930 netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
931 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000932
933 read_buf |= HW_CFG_BIR_;
934
935 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000936 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000937 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000938
939 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000940 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000941 return ret;
Steve Glendinningb052e072012-11-30 05:55:52 +0000942
Joe Perchesa475f602010-02-17 10:30:24 +0000943 netif_dbg(dev, ifup, dev->net,
944 "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
945 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000946
947 if (!turbo_mode) {
948 burst_cap = 0;
949 dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
950 } else if (dev->udev->speed == USB_SPEED_HIGH) {
951 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
952 dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
953 } else {
954 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
955 dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
956 }
957
Joe Perches1e1d7412012-11-24 01:27:49 +0000958 netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
959 (ulong)dev->rx_urb_size);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000960
961 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000962 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000963 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000964
965 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000966 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000967 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000968
Joe Perchesa475f602010-02-17 10:30:24 +0000969 netif_dbg(dev, ifup, dev->net,
970 "Read Value from BURST_CAP after writing: 0x%08x\n",
971 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000972
Steve Glendinning44367612012-09-28 00:07:08 +0000973 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000974 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000975 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000976
977 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000978 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000979 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000980
Joe Perchesa475f602010-02-17 10:30:24 +0000981 netif_dbg(dev, ifup, dev->net,
982 "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
983 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000984
985 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +0000986 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +0000987 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000988
Joe Perches1e1d7412012-11-24 01:27:49 +0000989 netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
990 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000991
992 if (turbo_mode)
993 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
994
995 read_buf &= ~HW_CFG_RXDOFF_;
996
997 /* set Rx data offset=2, Make IP header aligns on word boundary. */
998 read_buf |= NET_IP_ALIGN << 9;
999
1000 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001001 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001002 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001003
1004 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001005 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001006 return ret;
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001007
Joe Perchesa475f602010-02-17 10:30:24 +00001008 netif_dbg(dev, ifup, dev->net,
1009 "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001010
Steve Glendinning44367612012-09-28 00:07:08 +00001011 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001012 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001013 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001014
1015 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001016 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001017 return ret;
Joe Perchesa475f602010-02-17 10:30:24 +00001018 netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001019
Steve Glendinningf2935012009-05-01 05:46:51 +00001020 /* Configure GPIO pins as LED outputs */
1021 write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
1022 LED_GPIO_CFG_FDX_LED;
1023 ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001024 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001025 return ret;
Steve Glendinningf2935012009-05-01 05:46:51 +00001026
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001027 /* Init Tx */
Steve Glendinning44367612012-09-28 00:07:08 +00001028 ret = smsc95xx_write_reg(dev, FLOW, 0);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001029 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001030 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001031
Steve Glendinning44367612012-09-28 00:07:08 +00001032 ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001033 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001034 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001035
1036 /* Don't need mac_cr_lock during initialisation */
1037 ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001038 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001039 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001040
1041 /* Init Rx */
1042 /* Set Vlan */
Steve Glendinning44367612012-09-28 00:07:08 +00001043 ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001044 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001045 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001046
Steve Glendinningf7b29272008-11-20 04:19:21 -08001047 /* Enable or disable checksum offload engines */
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001048 ret = smsc95xx_set_features(dev->net, dev->net->features);
Steve Glendinningb052e072012-11-30 05:55:52 +00001049 if (ret < 0) {
1050 netdev_warn(dev->net, "Failed to set checksum offload features\n");
1051 return ret;
1052 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001053
1054 smsc95xx_set_multicast(dev->net);
1055
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001056 ret = smsc95xx_phy_initialize(dev);
Steve Glendinningb052e072012-11-30 05:55:52 +00001057 if (ret < 0) {
1058 netdev_warn(dev->net, "Failed to init PHY\n");
1059 return ret;
1060 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001061
1062 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001063 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001064 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001065
1066 /* enable PHY interrupts */
1067 read_buf |= INT_EP_CTL_PHY_INT_;
1068
1069 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001070 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001071 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001072
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001073 ret = smsc95xx_start_tx_path(dev);
Steve Glendinningb052e072012-11-30 05:55:52 +00001074 if (ret < 0) {
1075 netdev_warn(dev->net, "Failed to start TX path\n");
1076 return ret;
1077 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001078
Ming Leiec321152012-11-06 04:53:07 +00001079 ret = smsc95xx_start_rx_path(dev, 0);
Steve Glendinningb052e072012-11-30 05:55:52 +00001080 if (ret < 0) {
1081 netdev_warn(dev->net, "Failed to start RX path\n");
1082 return ret;
1083 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001084
Joe Perchesa475f602010-02-17 10:30:24 +00001085 netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001086 return 0;
1087}
1088
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001089static const struct net_device_ops smsc95xx_netdev_ops = {
1090 .ndo_open = usbnet_open,
1091 .ndo_stop = usbnet_stop,
1092 .ndo_start_xmit = usbnet_start_xmit,
1093 .ndo_tx_timeout = usbnet_tx_timeout,
1094 .ndo_change_mtu = usbnet_change_mtu,
1095 .ndo_set_mac_address = eth_mac_addr,
1096 .ndo_validate_addr = eth_validate_addr,
1097 .ndo_do_ioctl = smsc95xx_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001098 .ndo_set_rx_mode = smsc95xx_set_multicast,
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001099 .ndo_set_features = smsc95xx_set_features,
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001100};
1101
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001102static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
1103{
1104 struct smsc95xx_priv *pdata = NULL;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001105 u32 val;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001106 int ret;
1107
1108 printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
1109
1110 ret = usbnet_get_endpoints(dev, intf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001111 if (ret < 0) {
1112 netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
1113 return ret;
1114 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001115
1116 dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
Joe Perches38673c82013-02-03 17:28:11 +00001117 GFP_KERNEL);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001118
1119 pdata = (struct smsc95xx_priv *)(dev->data[0]);
Joe Perches38673c82013-02-03 17:28:11 +00001120 if (!pdata)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001121 return -ENOMEM;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001122
1123 spin_lock_init(&pdata->mac_cr_lock);
1124
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001125 if (DEFAULT_TX_CSUM_ENABLE)
1126 dev->net->features |= NETIF_F_HW_CSUM;
1127 if (DEFAULT_RX_CSUM_ENABLE)
1128 dev->net->features |= NETIF_F_RXCSUM;
1129
1130 dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001131
Bernard Blackhamf4e8ab72010-10-18 13:16:39 +00001132 smsc95xx_init_mac_address(dev);
1133
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001134 /* Init all registers */
1135 ret = smsc95xx_reset(dev);
1136
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001137 /* detect device revision as different features may be available */
1138 ret = smsc95xx_read_reg(dev, ID_REV, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001139 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001140 return ret;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001141 val >>= 16;
Steve Glendinning9ebca502012-11-22 08:05:23 +00001142
1143 if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
1144 (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
1145 pdata->features = (FEATURE_8_WAKEUP_FILTERS |
1146 FEATURE_PHY_NLP_CROSSOVER |
Ming Leieb970ff2013-02-22 03:05:05 +00001147 FEATURE_REMOTE_WAKEUP);
Steve Glendinning9ebca502012-11-22 08:05:23 +00001148 else if (val == ID_REV_CHIP_ID_9512_)
1149 pdata->features = FEATURE_8_WAKEUP_FILTERS;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001150
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001151 dev->net->netdev_ops = &smsc95xx_netdev_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001152 dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001153 dev->net->flags |= IFF_MULTICAST;
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001154 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
Stephane Fillod9bbf5662012-04-20 09:39:23 +00001155 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001156 return 0;
1157}
1158
1159static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
1160{
1161 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1162 if (pdata) {
Joe Perchesa475f602010-02-17 10:30:24 +00001163 netif_dbg(dev, ifdown, dev->net, "free pdata\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001164 kfree(pdata);
1165 pdata = NULL;
1166 dev->data[0] = 0;
1167 }
1168}
1169
Steve Glendinning068bb1a2012-11-30 05:55:51 +00001170static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001171{
Steve Glendinning068bb1a2012-11-30 05:55:51 +00001172 u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
1173 return crc << ((filter % 2) * 16);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001174}
1175
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001176static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
1177{
1178 struct mii_if_info *mii = &dev->mii;
1179 int ret;
1180
Joe Perches1e1d7412012-11-24 01:27:49 +00001181 netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001182
1183 /* read to clear */
1184 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001185 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001186 return ret;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001187
1188 /* enable interrupt source */
1189 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001190 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001191 return ret;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001192
1193 ret |= mask;
1194
1195 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
1196
1197 return 0;
1198}
1199
1200static int smsc95xx_link_ok_nopm(struct usbnet *dev)
1201{
1202 struct mii_if_info *mii = &dev->mii;
1203 int ret;
1204
1205 /* first, a dummy read, needed to latch some MII phys */
1206 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001207 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001208 return ret;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001209
1210 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001211 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001212 return ret;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001213
1214 return !!(ret & BMSR_LSTATUS);
1215}
1216
Steve Glendinning319b95b2012-11-22 08:05:25 +00001217static int smsc95xx_enter_suspend0(struct usbnet *dev)
1218{
1219 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1220 u32 val;
1221 int ret;
1222
1223 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001224 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001225 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001226
1227 val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
1228 val |= PM_CTL_SUS_MODE_0;
1229
1230 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001231 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001232 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001233
1234 /* clear wol status */
1235 val &= ~PM_CTL_WUPS_;
1236 val |= PM_CTL_WUPS_WOL_;
1237
1238 /* enable energy detection */
1239 if (pdata->wolopts & WAKE_PHY)
1240 val |= PM_CTL_WUPS_ED_;
1241
1242 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001243 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001244 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001245
1246 /* read back PM_CTRL */
1247 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Ming Lei76437212013-02-22 03:05:03 +00001248 if (ret < 0)
1249 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001250
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001251 pdata->suspend_flags |= SUSPEND_SUSPEND0;
1252
Ming Lei76437212013-02-22 03:05:03 +00001253 return 0;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001254}
1255
1256static int smsc95xx_enter_suspend1(struct usbnet *dev)
1257{
1258 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1259 struct mii_if_info *mii = &dev->mii;
1260 u32 val;
1261 int ret;
1262
1263 /* reconfigure link pulse detection timing for
1264 * compatibility with non-standard link partners
1265 */
1266 if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
1267 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG,
1268 PHY_EDPD_CONFIG_DEFAULT);
1269
1270 /* enable energy detect power-down mode */
1271 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001272 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001273 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001274
1275 ret |= MODE_CTRL_STS_EDPWRDOWN_;
1276
1277 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret);
1278
1279 /* enter SUSPEND1 mode */
1280 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001281 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001282 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001283
1284 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1285 val |= PM_CTL_SUS_MODE_1;
1286
1287 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001288 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001289 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001290
1291 /* clear wol status, enable energy detection */
1292 val &= ~PM_CTL_WUPS_;
1293 val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
1294
1295 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Ming Lei76437212013-02-22 03:05:03 +00001296 if (ret < 0)
1297 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001298
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001299 pdata->suspend_flags |= SUSPEND_SUSPEND1;
1300
Ming Lei76437212013-02-22 03:05:03 +00001301 return 0;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001302}
1303
1304static int smsc95xx_enter_suspend2(struct usbnet *dev)
1305{
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001306 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning319b95b2012-11-22 08:05:25 +00001307 u32 val;
1308 int ret;
1309
1310 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001311 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001312 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001313
1314 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1315 val |= PM_CTL_SUS_MODE_2;
1316
1317 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Ming Lei76437212013-02-22 03:05:03 +00001318 if (ret < 0)
1319 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001320
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001321 pdata->suspend_flags |= SUSPEND_SUSPEND2;
1322
Ming Lei76437212013-02-22 03:05:03 +00001323 return 0;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001324}
1325
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001326static int smsc95xx_enter_suspend3(struct usbnet *dev)
1327{
1328 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1329 u32 val;
1330 int ret;
1331
1332 ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val);
1333 if (ret < 0)
1334 return ret;
1335
1336 if (val & 0xFFFF) {
1337 netdev_info(dev->net, "rx fifo not empty in autosuspend\n");
1338 return -EBUSY;
1339 }
1340
1341 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
1342 if (ret < 0)
1343 return ret;
1344
1345 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1346 val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS;
1347
1348 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1349 if (ret < 0)
1350 return ret;
1351
1352 /* clear wol status */
1353 val &= ~PM_CTL_WUPS_;
1354 val |= PM_CTL_WUPS_WOL_;
1355
1356 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
1357 if (ret < 0)
1358 return ret;
1359
1360 pdata->suspend_flags |= SUSPEND_SUSPEND3;
1361
1362 return 0;
1363}
1364
1365static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
1366{
1367 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1368 int ret;
1369
1370 if (!netif_running(dev->net)) {
1371 /* interface is ifconfig down so fully power down hw */
1372 netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n");
1373 return smsc95xx_enter_suspend2(dev);
1374 }
1375
1376 if (!link_up) {
1377 /* link is down so enter EDPD mode, but only if device can
1378 * reliably resume from it. This check should be redundant
Ming Leieb970ff2013-02-22 03:05:05 +00001379 * as current FEATURE_REMOTE_WAKEUP parts also support
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001380 * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */
1381 if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) {
1382 netdev_warn(dev->net, "EDPD not supported\n");
1383 return -EBUSY;
1384 }
1385
1386 netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n");
1387
1388 /* enable PHY wakeup events for if cable is attached */
1389 ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1390 PHY_INT_MASK_ANEG_COMP_);
1391 if (ret < 0) {
1392 netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1393 return ret;
1394 }
1395
1396 netdev_info(dev->net, "entering SUSPEND1 mode\n");
1397 return smsc95xx_enter_suspend1(dev);
1398 }
1399
1400 /* enable PHY wakeup events so we remote wakeup if cable is pulled */
1401 ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1402 PHY_INT_MASK_LINK_DOWN_);
1403 if (ret < 0) {
1404 netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1405 return ret;
1406 }
1407
1408 netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n");
1409 return smsc95xx_enter_suspend3(dev);
1410}
1411
Steve Glendinningb5a04472012-09-28 00:07:11 +00001412static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1413{
1414 struct usbnet *dev = usb_get_intfdata(intf);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001415 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001416 u32 val, link_up;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001417 int ret;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001418
Steve Glendinningb5a04472012-09-28 00:07:11 +00001419 ret = usbnet_suspend(intf, message);
Steve Glendinningb052e072012-11-30 05:55:52 +00001420 if (ret < 0) {
1421 netdev_warn(dev->net, "usbnet_suspend error\n");
1422 return ret;
1423 }
Steve Glendinningb5a04472012-09-28 00:07:11 +00001424
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001425 if (pdata->suspend_flags) {
1426 netdev_warn(dev->net, "error during last resume\n");
1427 pdata->suspend_flags = 0;
1428 }
1429
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001430 /* determine if link is up using only _nopm functions */
1431 link_up = smsc95xx_link_ok_nopm(dev);
1432
Ming Lei42e21c02013-02-22 03:05:04 +00001433 if (message.event == PM_EVENT_AUTO_SUSPEND &&
Ming Leieb970ff2013-02-22 03:05:05 +00001434 (pdata->features & FEATURE_REMOTE_WAKEUP)) {
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001435 ret = smsc95xx_autosuspend(dev, link_up);
1436 goto done;
1437 }
1438
1439 /* if we get this far we're not autosuspending */
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001440 /* if no wol options set, or if link is down and we're not waking on
1441 * PHY activity, enter lowest power SUSPEND2 mode
1442 */
1443 if (!(pdata->wolopts & SUPPORTED_WAKE) ||
1444 !(link_up || (pdata->wolopts & WAKE_PHY))) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001445 netdev_info(dev->net, "entering SUSPEND2 mode\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001446
1447 /* disable energy detect (link up) & wake up events */
Ming Leiec321152012-11-06 04:53:07 +00001448 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001449 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001450 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001451
1452 val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
1453
Ming Leiec321152012-11-06 04:53:07 +00001454 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001455 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001456 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001457
Ming Leiec321152012-11-06 04:53:07 +00001458 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001459 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001460 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001461
1462 val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
1463
Ming Leiec321152012-11-06 04:53:07 +00001464 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001465 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001466 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001467
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001468 ret = smsc95xx_enter_suspend2(dev);
1469 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001470 }
1471
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001472 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 Glendinningb052e072012-11-30 05:55:52 +00001475 if (ret < 0) {
1476 netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1477 goto done;
1478 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001479
1480 /* if link is down then configure EDPD and enter SUSPEND1,
1481 * otherwise enter SUSPEND0 below
1482 */
1483 if (!link_up) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001484 netdev_info(dev->net, "entering SUSPEND1 mode\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001485 ret = smsc95xx_enter_suspend1(dev);
1486 goto done;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001487 }
1488 }
1489
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001490 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
Steve Glendinningeed9a722012-11-30 05:55:48 +00001491 u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL);
Ming Lei06a221b2012-11-06 04:53:06 +00001492 u32 command[2];
1493 u32 offset[2];
1494 u32 crc[4];
Steve Glendinning9ebca502012-11-22 08:05:23 +00001495 int wuff_filter_count =
1496 (pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
1497 LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001498 int i, filter = 0;
1499
Steve Glendinningeed9a722012-11-30 05:55:48 +00001500 if (!filter_mask) {
1501 netdev_warn(dev->net, "Unable to allocate filter_mask\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001502 ret = -ENOMEM;
1503 goto done;
Steve Glendinningeed9a722012-11-30 05:55:48 +00001504 }
1505
Ming Lei06a221b2012-11-06 04:53:06 +00001506 memset(command, 0, sizeof(command));
1507 memset(offset, 0, sizeof(offset));
1508 memset(crc, 0, sizeof(crc));
1509
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001510 if (pdata->wolopts & WAKE_BCAST) {
1511 const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Joe Perches1e1d7412012-11-24 01:27:49 +00001512 netdev_info(dev->net, "enabling broadcast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001513 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 Perches1e1d7412012-11-24 01:27:49 +00001525 netdev_info(dev->net, "enabling multicast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001526 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 Perches1e1d7412012-11-24 01:27:49 +00001538 netdev_info(dev->net, "enabling ARP detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001539 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 Perches1e1d7412012-11-24 01:27:49 +00001550 netdev_info(dev->net, "enabling unicast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001551 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 Glendinning9ebca502012-11-22 08:05:23 +00001561 for (i = 0; i < (wuff_filter_count * 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001562 ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
Steve Glendinningb052e072012-11-30 05:55:52 +00001563 if (ret < 0) {
Ming Lei06a221b2012-11-06 04:53:06 +00001564 kfree(filter_mask);
Steve Glendinningb052e072012-11-30 05:55:52 +00001565 goto done;
1566 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001567 }
Ming Lei06a221b2012-11-06 04:53:06 +00001568 kfree(filter_mask);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001569
Steve Glendinning9ebca502012-11-22 08:05:23 +00001570 for (i = 0; i < (wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001571 ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001572 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001573 goto done;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001574 }
1575
Steve Glendinning9ebca502012-11-22 08:05:23 +00001576 for (i = 0; i < (wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001577 ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001578 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001579 goto done;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001580 }
1581
Steve Glendinning9ebca502012-11-22 08:05:23 +00001582 for (i = 0; i < (wuff_filter_count / 2); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001583 ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001584 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001585 goto done;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001586 }
1587
1588 /* clear any pending pattern match packet status */
Ming Leiec321152012-11-06 04:53:07 +00001589 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001590 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001591 goto done;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001592
1593 val |= WUCSR_WUFR_;
1594
Ming Leiec321152012-11-06 04:53:07 +00001595 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001596 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001597 goto done;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001598 }
1599
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001600 if (pdata->wolopts & WAKE_MAGIC) {
1601 /* clear any pending magic packet status */
Ming Leiec321152012-11-06 04:53:07 +00001602 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001603 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001604 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001605
1606 val |= WUCSR_MPR_;
1607
Ming Leiec321152012-11-06 04:53:07 +00001608 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001609 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001610 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001611 }
1612
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001613 /* enable/disable wakeup sources */
Ming Leiec321152012-11-06 04:53:07 +00001614 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001615 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001616 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001617
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001618 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001619 netdev_info(dev->net, "enabling pattern match wakeup\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001620 val |= WUCSR_WAKE_EN_;
1621 } else {
Joe Perches1e1d7412012-11-24 01:27:49 +00001622 netdev_info(dev->net, "disabling pattern match wakeup\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001623 val &= ~WUCSR_WAKE_EN_;
1624 }
1625
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001626 if (pdata->wolopts & WAKE_MAGIC) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001627 netdev_info(dev->net, "enabling magic packet wakeup\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001628 val |= WUCSR_MPEN_;
1629 } else {
Joe Perches1e1d7412012-11-24 01:27:49 +00001630 netdev_info(dev->net, "disabling magic packet wakeup\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001631 val &= ~WUCSR_MPEN_;
1632 }
1633
Ming Leiec321152012-11-06 04:53:07 +00001634 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001635 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001636 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001637
1638 /* enable wol wakeup source */
Ming Leiec321152012-11-06 04:53:07 +00001639 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001640 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001641 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001642
1643 val |= PM_CTL_WOL_EN_;
1644
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001645 /* phy energy detect wakeup source */
1646 if (pdata->wolopts & WAKE_PHY)
1647 val |= PM_CTL_ED_EN_;
1648
Ming Leiec321152012-11-06 04:53:07 +00001649 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001650 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001651 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001652
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001653 /* enable receiver to enable frame reception */
Ming Leiec321152012-11-06 04:53:07 +00001654 smsc95xx_start_rx_path(dev, 1);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001655
1656 /* some wol options are enabled, so enter SUSPEND0 */
Joe Perches1e1d7412012-11-24 01:27:49 +00001657 netdev_info(dev->net, "entering SUSPEND0 mode\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001658 ret = smsc95xx_enter_suspend0(dev);
1659
1660done:
Ming Lei0d41be52013-03-15 12:08:58 +08001661 /*
1662 * TODO: resume() might need to handle the suspend failure
1663 * in system sleep
1664 */
1665 if (ret && PMSG_IS_AUTO(message))
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001666 usbnet_resume(intf);
1667 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001668}
1669
1670static int smsc95xx_resume(struct usb_interface *intf)
1671{
1672 struct usbnet *dev = usb_get_intfdata(intf);
1673 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001674 u8 suspend_flags = pdata->suspend_flags;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001675 int ret;
1676 u32 val;
1677
1678 BUG_ON(!dev);
1679
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001680 netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
1681
1682 /* do this first to ensure it's cleared even in error case */
1683 pdata->suspend_flags = 0;
1684
1685 if (suspend_flags & SUSPEND_ALLMODES) {
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001686 /* clear wake-up sources */
Ming Leiec321152012-11-06 04:53:07 +00001687 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001688 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001689 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001690
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001691 val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001692
Ming Leiec321152012-11-06 04:53:07 +00001693 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001694 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001695 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001696
1697 /* clear wake-up status */
Ming Leiec321152012-11-06 04:53:07 +00001698 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001699 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001700 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001701
1702 val &= ~PM_CTL_WOL_EN_;
1703 val |= PM_CTL_WUPS_;
1704
Ming Leiec321152012-11-06 04:53:07 +00001705 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge360a8b2013-01-03 03:00:15 +00001706 if (ret < 0)
Steve Glendinningb052e072012-11-30 05:55:52 +00001707 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001708 }
1709
Steve Glendinningaf3d7c12012-11-22 08:05:22 +00001710 ret = usbnet_resume(intf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001711 if (ret < 0)
1712 netdev_warn(dev->net, "usbnet_resume error\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001713
Steve Glendinningb052e072012-11-30 05:55:52 +00001714 return ret;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001715}
1716
Joonyoung Shimb4df4802014-07-10 11:49:42 +09001717static int smsc95xx_reset_resume(struct usb_interface *intf)
1718{
1719 struct usbnet *dev = usb_get_intfdata(intf);
1720 int ret;
1721
1722 ret = smsc95xx_reset(dev);
1723 if (ret < 0)
1724 return ret;
1725
1726 return smsc95xx_resume(intf);
1727}
1728
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001729static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
1730{
1731 skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
1732 skb->ip_summed = CHECKSUM_COMPLETE;
1733 skb_trim(skb, skb->len - 2);
1734}
1735
1736static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1737{
Emil Goodeeb855692014-02-13 17:50:19 +01001738 /* This check is no longer done by usbnet */
1739 if (skb->len < dev->net->hard_header_len)
1740 return 0;
1741
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001742 while (skb->len > 0) {
1743 u32 header, align_count;
1744 struct sk_buff *ax_skb;
1745 unsigned char *packet;
1746 u16 size;
1747
1748 memcpy(&header, skb->data, sizeof(header));
1749 le32_to_cpus(&header);
1750 skb_pull(skb, 4 + NET_IP_ALIGN);
1751 packet = skb->data;
1752
1753 /* get the packet length */
1754 size = (u16)((header & RX_STS_FL_) >> 16);
1755 align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
1756
1757 if (unlikely(header & RX_STS_ES_)) {
Joe Perchesa475f602010-02-17 10:30:24 +00001758 netif_dbg(dev, rx_err, dev->net,
1759 "Error header=0x%08x\n", header);
Herbert Xu80667ac2009-06-29 16:53:00 +00001760 dev->net->stats.rx_errors++;
1761 dev->net->stats.rx_dropped++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001762
1763 if (header & RX_STS_CRC_) {
Herbert Xu80667ac2009-06-29 16:53:00 +00001764 dev->net->stats.rx_crc_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001765 } else {
1766 if (header & (RX_STS_TL_ | RX_STS_RF_))
Herbert Xu80667ac2009-06-29 16:53:00 +00001767 dev->net->stats.rx_frame_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001768
1769 if ((header & RX_STS_LE_) &&
1770 (!(header & RX_STS_FT_)))
Herbert Xu80667ac2009-06-29 16:53:00 +00001771 dev->net->stats.rx_length_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001772 }
1773 } else {
1774 /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
1775 if (unlikely(size > (ETH_FRAME_LEN + 12))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001776 netif_dbg(dev, rx_err, dev->net,
1777 "size err header=0x%08x\n", header);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001778 return 0;
1779 }
1780
1781 /* last frame in this batch */
1782 if (skb->len == size) {
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001783 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001784 smsc95xx_rx_csum_offload(skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001785 skb_trim(skb, skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001786 skb->truesize = size + sizeof(struct sk_buff);
1787
1788 return 1;
1789 }
1790
1791 ax_skb = skb_clone(skb, GFP_ATOMIC);
1792 if (unlikely(!ax_skb)) {
Joe Perches60b86752010-02-17 10:30:23 +00001793 netdev_warn(dev->net, "Error allocating skb\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001794 return 0;
1795 }
1796
1797 ax_skb->len = size;
1798 ax_skb->data = packet;
1799 skb_set_tail_pointer(ax_skb, size);
1800
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001801 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001802 smsc95xx_rx_csum_offload(ax_skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001803 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001804 ax_skb->truesize = size + sizeof(struct sk_buff);
1805
1806 usbnet_skb_return(dev, ax_skb);
1807 }
1808
1809 skb_pull(skb, size);
1810
1811 /* padding bytes before the next frame starts */
1812 if (skb->len)
1813 skb_pull(skb, align_count);
1814 }
1815
1816 if (unlikely(skb->len < 0)) {
Joe Perches60b86752010-02-17 10:30:23 +00001817 netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001818 return 0;
1819 }
1820
1821 return 1;
1822}
1823
Steve Glendinningf7b29272008-11-20 04:19:21 -08001824static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1825{
Michał Mirosław55508d62010-12-14 15:24:08 +00001826 u16 low_16 = (u16)skb_checksum_start_offset(skb);
1827 u16 high_16 = low_16 + skb->csum_offset;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001828 return (high_16 << 16) | low_16;
1829}
1830
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001831static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
1832 struct sk_buff *skb, gfp_t flags)
1833{
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001834 bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001835 int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001836 u32 tx_cmd_a, tx_cmd_b;
1837
Steve Glendinningf7b29272008-11-20 04:19:21 -08001838 /* We do not advertise SG, so skbs should be already linearized */
1839 BUG_ON(skb_shinfo(skb)->nr_frags);
1840
1841 if (skb_headroom(skb) < overhead) {
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001842 struct sk_buff *skb2 = skb_copy_expand(skb,
Steve Glendinningf7b29272008-11-20 04:19:21 -08001843 overhead, 0, flags);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001844 dev_kfree_skb_any(skb);
1845 skb = skb2;
1846 if (!skb)
1847 return NULL;
1848 }
1849
Steve Glendinningf7b29272008-11-20 04:19:21 -08001850 if (csum) {
Steve Glendinning11bc3082010-03-18 22:18:41 -07001851 if (skb->len <= 45) {
1852 /* workaround - hardware tx checksum does not work
1853 * properly with extremely small packets */
Michał Mirosław55508d62010-12-14 15:24:08 +00001854 long csstart = skb_checksum_start_offset(skb);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001855 __wsum calc = csum_partial(skb->data + csstart,
1856 skb->len - csstart, 0);
1857 *((__sum16 *)(skb->data + csstart
1858 + skb->csum_offset)) = csum_fold(calc);
1859
1860 csum = false;
1861 } else {
1862 u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
1863 skb_push(skb, 4);
Steve Glendinning00acda62012-11-02 00:44:20 +00001864 cpu_to_le32s(&csum_preamble);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001865 memcpy(skb->data, &csum_preamble, 4);
1866 }
Steve Glendinningf7b29272008-11-20 04:19:21 -08001867 }
1868
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001869 skb_push(skb, 4);
1870 tx_cmd_b = (u32)(skb->len - 4);
Steve Glendinningf7b29272008-11-20 04:19:21 -08001871 if (csum)
1872 tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001873 cpu_to_le32s(&tx_cmd_b);
1874 memcpy(skb->data, &tx_cmd_b, 4);
1875
1876 skb_push(skb, 4);
1877 tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
1878 TX_CMD_A_LAST_SEG_;
1879 cpu_to_le32s(&tx_cmd_a);
1880 memcpy(skb->data, &tx_cmd_a, 4);
1881
1882 return skb;
1883}
1884
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001885static int smsc95xx_manage_power(struct usbnet *dev, int on)
1886{
1887 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1888
1889 dev->intf->needs_remote_wakeup = on;
1890
Ming Leieb970ff2013-02-22 03:05:05 +00001891 if (pdata->features & FEATURE_REMOTE_WAKEUP)
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001892 return 0;
1893
Ming Leieb970ff2013-02-22 03:05:05 +00001894 /* this chip revision isn't capable of remote wakeup */
1895 netdev_info(dev->net, "hardware isn't capable of remote wakeup\n");
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001896
1897 if (on)
1898 usb_autopm_get_interface_no_resume(dev->intf);
1899 else
1900 usb_autopm_put_interface(dev->intf);
1901
1902 return 0;
1903}
1904
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001905static const struct driver_info smsc95xx_info = {
1906 .description = "smsc95xx USB 2.0 Ethernet",
1907 .bind = smsc95xx_bind,
1908 .unbind = smsc95xx_unbind,
1909 .link_reset = smsc95xx_link_reset,
1910 .reset = smsc95xx_reset,
1911 .rx_fixup = smsc95xx_rx_fixup,
1912 .tx_fixup = smsc95xx_tx_fixup,
1913 .status = smsc95xx_status,
Steve Glendinningb2d4b152013-01-03 03:00:16 +00001914 .manage_power = smsc95xx_manage_power,
Paolo Pisati07d69d42012-04-23 04:05:20 +00001915 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001916};
1917
1918static const struct usb_device_id products[] = {
1919 {
1920 /* SMSC9500 USB Ethernet Device */
1921 USB_DEVICE(0x0424, 0x9500),
1922 .driver_info = (unsigned long) &smsc95xx_info,
1923 },
Steve Glendinning726474b2009-05-01 06:07:22 +00001924 {
Steve Glendinning6f41d122009-09-22 05:13:02 +00001925 /* SMSC9505 USB Ethernet Device */
1926 USB_DEVICE(0x0424, 0x9505),
1927 .driver_info = (unsigned long) &smsc95xx_info,
1928 },
1929 {
1930 /* SMSC9500A USB Ethernet Device */
1931 USB_DEVICE(0x0424, 0x9E00),
1932 .driver_info = (unsigned long) &smsc95xx_info,
1933 },
1934 {
1935 /* SMSC9505A USB Ethernet Device */
1936 USB_DEVICE(0x0424, 0x9E01),
1937 .driver_info = (unsigned long) &smsc95xx_info,
1938 },
1939 {
Steve Glendinning726474b2009-05-01 06:07:22 +00001940 /* SMSC9512/9514 USB Hub & Ethernet Device */
1941 USB_DEVICE(0x0424, 0xec00),
1942 .driver_info = (unsigned long) &smsc95xx_info,
1943 },
Steve Glendinning6f41d122009-09-22 05:13:02 +00001944 {
1945 /* SMSC9500 USB Ethernet Device (SAL10) */
1946 USB_DEVICE(0x0424, 0x9900),
1947 .driver_info = (unsigned long) &smsc95xx_info,
1948 },
1949 {
1950 /* SMSC9505 USB Ethernet Device (SAL10) */
1951 USB_DEVICE(0x0424, 0x9901),
1952 .driver_info = (unsigned long) &smsc95xx_info,
1953 },
1954 {
1955 /* SMSC9500A USB Ethernet Device (SAL10) */
1956 USB_DEVICE(0x0424, 0x9902),
1957 .driver_info = (unsigned long) &smsc95xx_info,
1958 },
1959 {
1960 /* SMSC9505A USB Ethernet Device (SAL10) */
1961 USB_DEVICE(0x0424, 0x9903),
1962 .driver_info = (unsigned long) &smsc95xx_info,
1963 },
1964 {
1965 /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
1966 USB_DEVICE(0x0424, 0x9904),
1967 .driver_info = (unsigned long) &smsc95xx_info,
1968 },
1969 {
1970 /* SMSC9500A USB Ethernet Device (HAL) */
1971 USB_DEVICE(0x0424, 0x9905),
1972 .driver_info = (unsigned long) &smsc95xx_info,
1973 },
1974 {
1975 /* SMSC9505A USB Ethernet Device (HAL) */
1976 USB_DEVICE(0x0424, 0x9906),
1977 .driver_info = (unsigned long) &smsc95xx_info,
1978 },
1979 {
1980 /* SMSC9500 USB Ethernet Device (Alternate ID) */
1981 USB_DEVICE(0x0424, 0x9907),
1982 .driver_info = (unsigned long) &smsc95xx_info,
1983 },
1984 {
1985 /* SMSC9500A USB Ethernet Device (Alternate ID) */
1986 USB_DEVICE(0x0424, 0x9908),
1987 .driver_info = (unsigned long) &smsc95xx_info,
1988 },
1989 {
1990 /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
1991 USB_DEVICE(0x0424, 0x9909),
1992 .driver_info = (unsigned long) &smsc95xx_info,
1993 },
Steve Glendinning88edaa42011-04-10 18:59:27 -07001994 {
1995 /* SMSC LAN9530 USB Ethernet Device */
1996 USB_DEVICE(0x0424, 0x9530),
1997 .driver_info = (unsigned long) &smsc95xx_info,
1998 },
1999 {
2000 /* SMSC LAN9730 USB Ethernet Device */
2001 USB_DEVICE(0x0424, 0x9730),
2002 .driver_info = (unsigned long) &smsc95xx_info,
2003 },
2004 {
2005 /* SMSC LAN89530 USB Ethernet Device */
2006 USB_DEVICE(0x0424, 0x9E08),
2007 .driver_info = (unsigned long) &smsc95xx_info,
2008 },
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002009 { }, /* END */
2010};
2011MODULE_DEVICE_TABLE(usb, products);
2012
2013static struct usb_driver smsc95xx_driver = {
2014 .name = "smsc95xx",
2015 .id_table = products,
2016 .probe = usbnet_probe,
Steve Glendinningb5a04472012-09-28 00:07:11 +00002017 .suspend = smsc95xx_suspend,
Steve Glendinninge0e474a2012-09-28 00:07:12 +00002018 .resume = smsc95xx_resume,
Joonyoung Shimb4df4802014-07-10 11:49:42 +09002019 .reset_resume = smsc95xx_reset_resume,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002020 .disconnect = usbnet_disconnect,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07002021 .disable_hub_initiated_lpm = 1,
Steve Glendinningb2d4b152013-01-03 03:00:16 +00002022 .supports_autosuspend = 1,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002023};
2024
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08002025module_usb_driver(smsc95xx_driver);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002026
2027MODULE_AUTHOR("Nancy Lin");
Steve Glendinning90b24cf2012-04-16 12:13:29 +01002028MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002029MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
2030MODULE_LICENSE("GPL");