blob: c6d47d10590c6955f0d76bd72680a90fb9bdfd41 [file] [log] [blame]
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001/***************************************************************************
2 *
3 * Copyright (C) 2004-2008 SMSC
4 * Copyright (C) 2005-2008 ARM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 ***************************************************************************
21 * Rewritten, heavily based on smsc911x simple driver by SMSC.
22 * Partly uses io macros from smc91x.c by Nicolas Pitre
23 *
24 * Supported devices:
25 * LAN9115, LAN9116, LAN9117, LAN9118
26 * LAN9215, LAN9216, LAN9217, LAN9218
27 * LAN9210, LAN9211
28 * LAN9220, LAN9221
29 *
30 */
31
Joe Perchesdffc6b22011-03-25 14:21:22 +000032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Steve Glendinningfd9abb32008-11-05 00:35:37 +000034#include <linux/crc32.h>
35#include <linux/delay.h>
36#include <linux/errno.h>
37#include <linux/etherdevice.h>
38#include <linux/ethtool.h>
39#include <linux/init.h>
40#include <linux/ioport.h>
41#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/netdevice.h>
44#include <linux/platform_device.h>
45#include <linux/sched.h>
Steve Glendinningfd9abb32008-11-05 00:35:37 +000046#include <linux/timer.h>
Steve Glendinningfd9abb32008-11-05 00:35:37 +000047#include <linux/bug.h>
48#include <linux/bitops.h>
49#include <linux/irq.h>
50#include <linux/io.h>
Magnus Damm833cc672009-04-27 21:32:16 +000051#include <linux/swab.h>
Steve Glendinningfd9abb32008-11-05 00:35:37 +000052#include <linux/phy.h>
53#include <linux/smsc911x.h>
Daniel Mack6cb87822009-08-05 08:29:31 +000054#include <linux/device.h>
Steve Glendinningfd9abb32008-11-05 00:35:37 +000055#include "smsc911x.h"
56
57#define SMSC_CHIPNAME "smsc911x"
58#define SMSC_MDIONAME "smsc911x-mdio"
59#define SMSC_DRV_VERSION "2008-10-21"
60
61MODULE_LICENSE("GPL");
62MODULE_VERSION(SMSC_DRV_VERSION);
Vincent Stehlé62038e42010-09-26 18:50:05 -070063MODULE_ALIAS("platform:smsc911x");
Steve Glendinningfd9abb32008-11-05 00:35:37 +000064
65#if USE_DEBUG > 0
66static int debug = 16;
67#else
68static int debug = 3;
69#endif
70
71module_param(debug, int, 0);
72MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
73
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -070074struct smsc911x_data;
75
76struct smsc911x_ops {
77 u32 (*reg_read)(struct smsc911x_data *pdata, u32 reg);
78 void (*reg_write)(struct smsc911x_data *pdata, u32 reg, u32 val);
79 void (*rx_readfifo)(struct smsc911x_data *pdata,
80 unsigned int *buf, unsigned int wordcount);
81 void (*tx_writefifo)(struct smsc911x_data *pdata,
82 unsigned int *buf, unsigned int wordcount);
83};
84
Steve Glendinningfd9abb32008-11-05 00:35:37 +000085struct smsc911x_data {
86 void __iomem *ioaddr;
87
88 unsigned int idrev;
89
90 /* used to decide which workarounds apply */
91 unsigned int generation;
92
93 /* device configuration (copied from platform_data during probe) */
Steve Glendinning2107fb82008-11-05 00:35:38 +000094 struct smsc911x_platform_config config;
Steve Glendinningfd9abb32008-11-05 00:35:37 +000095
96 /* This needs to be acquired before calling any of below:
97 * smsc911x_mac_read(), smsc911x_mac_write()
98 */
99 spinlock_t mac_lock;
100
Catalin Marinas492c5d92010-07-19 13:36:21 -0700101 /* spinlock to ensure register accesses are serialised */
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000102 spinlock_t dev_lock;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000103
104 struct phy_device *phy_dev;
105 struct mii_bus *mii_bus;
106 int phy_irq[PHY_MAX_ADDR];
107 unsigned int using_extphy;
108 int last_duplex;
109 int last_carrier;
110
111 u32 msg_enable;
112 unsigned int gpio_setting;
113 unsigned int gpio_orig_setting;
114 struct net_device *dev;
115 struct napi_struct napi;
116
117 unsigned int software_irq_signal;
118
119#ifdef USE_PHY_WORK_AROUND
120#define MIN_PACKET_SIZE (64)
121 char loopback_tx_pkt[MIN_PACKET_SIZE];
122 char loopback_rx_pkt[MIN_PACKET_SIZE];
123 unsigned int resetcount;
124#endif
125
126 /* Members for Multicast filter workaround */
127 unsigned int multicast_update_pending;
128 unsigned int set_bits_mask;
129 unsigned int clear_bits_mask;
130 unsigned int hashhi;
131 unsigned int hashlo;
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700132
133 /* register access functions */
134 const struct smsc911x_ops *ops;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000135};
136
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700137/* Easy access to information */
138#define __smsc_shift(pdata, reg) ((reg) << ((pdata)->config.shift))
139
Catalin Marinas492c5d92010-07-19 13:36:21 -0700140static inline u32 __smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000141{
Steve Glendinning2107fb82008-11-05 00:35:38 +0000142 if (pdata->config.flags & SMSC911X_USE_32BIT)
143 return readl(pdata->ioaddr + reg);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000144
Catalin Marinas492c5d92010-07-19 13:36:21 -0700145 if (pdata->config.flags & SMSC911X_USE_16BIT)
146 return ((readw(pdata->ioaddr + reg) & 0xFFFF) |
Steve Glendinning2107fb82008-11-05 00:35:38 +0000147 ((readw(pdata->ioaddr + reg + 2) & 0xFFFF) << 16));
Steve Glendinning2107fb82008-11-05 00:35:38 +0000148
149 BUG();
Steve Glendinning702403a2009-01-11 00:14:27 -0800150 return 0;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000151}
152
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700153static inline u32
154__smsc911x_reg_read_shift(struct smsc911x_data *pdata, u32 reg)
155{
156 if (pdata->config.flags & SMSC911X_USE_32BIT)
157 return readl(pdata->ioaddr + __smsc_shift(pdata, reg));
158
159 if (pdata->config.flags & SMSC911X_USE_16BIT)
160 return (readw(pdata->ioaddr +
161 __smsc_shift(pdata, reg)) & 0xFFFF) |
162 ((readw(pdata->ioaddr +
163 __smsc_shift(pdata, reg + 2)) & 0xFFFF) << 16);
164
165 BUG();
166 return 0;
167}
168
Catalin Marinas492c5d92010-07-19 13:36:21 -0700169static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
170{
171 u32 data;
172 unsigned long flags;
173
174 spin_lock_irqsave(&pdata->dev_lock, flags);
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700175 data = pdata->ops->reg_read(pdata, reg);
Catalin Marinas492c5d92010-07-19 13:36:21 -0700176 spin_unlock_irqrestore(&pdata->dev_lock, flags);
177
178 return data;
179}
180
181static inline void __smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
182 u32 val)
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000183{
Steve Glendinning2107fb82008-11-05 00:35:38 +0000184 if (pdata->config.flags & SMSC911X_USE_32BIT) {
185 writel(val, pdata->ioaddr + reg);
186 return;
187 }
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000188
Steve Glendinning2107fb82008-11-05 00:35:38 +0000189 if (pdata->config.flags & SMSC911X_USE_16BIT) {
Steve Glendinning2107fb82008-11-05 00:35:38 +0000190 writew(val & 0xFFFF, pdata->ioaddr + reg);
191 writew((val >> 16) & 0xFFFF, pdata->ioaddr + reg + 2);
Steve Glendinning2107fb82008-11-05 00:35:38 +0000192 return;
193 }
194
195 BUG();
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000196}
197
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700198static inline void
199__smsc911x_reg_write_shift(struct smsc911x_data *pdata, u32 reg, u32 val)
200{
201 if (pdata->config.flags & SMSC911X_USE_32BIT) {
202 writel(val, pdata->ioaddr + __smsc_shift(pdata, reg));
203 return;
204 }
205
206 if (pdata->config.flags & SMSC911X_USE_16BIT) {
207 writew(val & 0xFFFF,
208 pdata->ioaddr + __smsc_shift(pdata, reg));
209 writew((val >> 16) & 0xFFFF,
210 pdata->ioaddr + __smsc_shift(pdata, reg + 2));
211 return;
212 }
213
214 BUG();
215}
216
Catalin Marinas492c5d92010-07-19 13:36:21 -0700217static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
218 u32 val)
219{
220 unsigned long flags;
221
222 spin_lock_irqsave(&pdata->dev_lock, flags);
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700223 pdata->ops->reg_write(pdata, reg, val);
Catalin Marinas492c5d92010-07-19 13:36:21 -0700224 spin_unlock_irqrestore(&pdata->dev_lock, flags);
225}
226
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000227/* Writes a packet to the TX_DATA_FIFO */
228static inline void
229smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf,
230 unsigned int wordcount)
231{
Catalin Marinas492c5d92010-07-19 13:36:21 -0700232 unsigned long flags;
233
234 spin_lock_irqsave(&pdata->dev_lock, flags);
235
Magnus Damm833cc672009-04-27 21:32:16 +0000236 if (pdata->config.flags & SMSC911X_SWAP_FIFO) {
237 while (wordcount--)
Catalin Marinas492c5d92010-07-19 13:36:21 -0700238 __smsc911x_reg_write(pdata, TX_DATA_FIFO,
239 swab32(*buf++));
240 goto out;
Magnus Damm833cc672009-04-27 21:32:16 +0000241 }
242
Steve Glendinning2107fb82008-11-05 00:35:38 +0000243 if (pdata->config.flags & SMSC911X_USE_32BIT) {
244 writesl(pdata->ioaddr + TX_DATA_FIFO, buf, wordcount);
Catalin Marinas492c5d92010-07-19 13:36:21 -0700245 goto out;
Steve Glendinning2107fb82008-11-05 00:35:38 +0000246 }
247
248 if (pdata->config.flags & SMSC911X_USE_16BIT) {
249 while (wordcount--)
Catalin Marinas492c5d92010-07-19 13:36:21 -0700250 __smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++);
251 goto out;
Steve Glendinning2107fb82008-11-05 00:35:38 +0000252 }
253
254 BUG();
Catalin Marinas492c5d92010-07-19 13:36:21 -0700255out:
256 spin_unlock_irqrestore(&pdata->dev_lock, flags);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000257}
258
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700259/* Writes a packet to the TX_DATA_FIFO - shifted version */
260static inline void
261smsc911x_tx_writefifo_shift(struct smsc911x_data *pdata, unsigned int *buf,
262 unsigned int wordcount)
263{
264 unsigned long flags;
265
266 spin_lock_irqsave(&pdata->dev_lock, flags);
267
268 if (pdata->config.flags & SMSC911X_SWAP_FIFO) {
269 while (wordcount--)
270 __smsc911x_reg_write_shift(pdata, TX_DATA_FIFO,
271 swab32(*buf++));
272 goto out;
273 }
274
275 if (pdata->config.flags & SMSC911X_USE_32BIT) {
276 writesl(pdata->ioaddr + __smsc_shift(pdata,
277 TX_DATA_FIFO), buf, wordcount);
278 goto out;
279 }
280
281 if (pdata->config.flags & SMSC911X_USE_16BIT) {
282 while (wordcount--)
283 __smsc911x_reg_write_shift(pdata,
284 TX_DATA_FIFO, *buf++);
285 goto out;
286 }
287
288 BUG();
289out:
290 spin_unlock_irqrestore(&pdata->dev_lock, flags);
291}
292
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000293/* Reads a packet out of the RX_DATA_FIFO */
294static inline void
295smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf,
296 unsigned int wordcount)
297{
Catalin Marinas492c5d92010-07-19 13:36:21 -0700298 unsigned long flags;
299
300 spin_lock_irqsave(&pdata->dev_lock, flags);
301
Magnus Damm833cc672009-04-27 21:32:16 +0000302 if (pdata->config.flags & SMSC911X_SWAP_FIFO) {
303 while (wordcount--)
Catalin Marinas492c5d92010-07-19 13:36:21 -0700304 *buf++ = swab32(__smsc911x_reg_read(pdata,
305 RX_DATA_FIFO));
306 goto out;
Magnus Damm833cc672009-04-27 21:32:16 +0000307 }
308
Steve Glendinning2107fb82008-11-05 00:35:38 +0000309 if (pdata->config.flags & SMSC911X_USE_32BIT) {
310 readsl(pdata->ioaddr + RX_DATA_FIFO, buf, wordcount);
Catalin Marinas492c5d92010-07-19 13:36:21 -0700311 goto out;
Steve Glendinning2107fb82008-11-05 00:35:38 +0000312 }
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000313
Steve Glendinning2107fb82008-11-05 00:35:38 +0000314 if (pdata->config.flags & SMSC911X_USE_16BIT) {
315 while (wordcount--)
Catalin Marinas492c5d92010-07-19 13:36:21 -0700316 *buf++ = __smsc911x_reg_read(pdata, RX_DATA_FIFO);
317 goto out;
Steve Glendinning2107fb82008-11-05 00:35:38 +0000318 }
319
320 BUG();
Catalin Marinas492c5d92010-07-19 13:36:21 -0700321out:
322 spin_unlock_irqrestore(&pdata->dev_lock, flags);
Steve Glendinning2107fb82008-11-05 00:35:38 +0000323}
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000324
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700325/* Reads a packet out of the RX_DATA_FIFO - shifted version */
326static inline void
327smsc911x_rx_readfifo_shift(struct smsc911x_data *pdata, unsigned int *buf,
328 unsigned int wordcount)
329{
330 unsigned long flags;
331
332 spin_lock_irqsave(&pdata->dev_lock, flags);
333
334 if (pdata->config.flags & SMSC911X_SWAP_FIFO) {
335 while (wordcount--)
336 *buf++ = swab32(__smsc911x_reg_read_shift(pdata,
337 RX_DATA_FIFO));
338 goto out;
339 }
340
341 if (pdata->config.flags & SMSC911X_USE_32BIT) {
342 readsl(pdata->ioaddr + __smsc_shift(pdata,
343 RX_DATA_FIFO), buf, wordcount);
344 goto out;
345 }
346
347 if (pdata->config.flags & SMSC911X_USE_16BIT) {
348 while (wordcount--)
349 *buf++ = __smsc911x_reg_read_shift(pdata,
350 RX_DATA_FIFO);
351 goto out;
352 }
353
354 BUG();
355out:
356 spin_unlock_irqrestore(&pdata->dev_lock, flags);
357}
358
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000359/* waits for MAC not busy, with timeout. Only called by smsc911x_mac_read
360 * and smsc911x_mac_write, so assumes mac_lock is held */
361static int smsc911x_mac_complete(struct smsc911x_data *pdata)
362{
363 int i;
364 u32 val;
365
366 SMSC_ASSERT_MAC_LOCK(pdata);
367
368 for (i = 0; i < 40; i++) {
369 val = smsc911x_reg_read(pdata, MAC_CSR_CMD);
370 if (!(val & MAC_CSR_CMD_CSR_BUSY_))
371 return 0;
372 }
Joe Perchesdffc6b22011-03-25 14:21:22 +0000373 SMSC_WARN(pdata, hw, "Timed out waiting for MAC not BUSY. "
374 "MAC_CSR_CMD: 0x%08X", val);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000375 return -EIO;
376}
377
378/* Fetches a MAC register value. Assumes mac_lock is acquired */
379static u32 smsc911x_mac_read(struct smsc911x_data *pdata, unsigned int offset)
380{
381 unsigned int temp;
382
383 SMSC_ASSERT_MAC_LOCK(pdata);
384
385 temp = smsc911x_reg_read(pdata, MAC_CSR_CMD);
386 if (unlikely(temp & MAC_CSR_CMD_CSR_BUSY_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000387 SMSC_WARN(pdata, hw, "MAC busy at entry");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000388 return 0xFFFFFFFF;
389 }
390
391 /* Send the MAC cmd */
392 smsc911x_reg_write(pdata, MAC_CSR_CMD, ((offset & 0xFF) |
393 MAC_CSR_CMD_CSR_BUSY_ | MAC_CSR_CMD_R_NOT_W_));
394
395 /* Workaround for hardware read-after-write restriction */
396 temp = smsc911x_reg_read(pdata, BYTE_TEST);
397
398 /* Wait for the read to complete */
399 if (likely(smsc911x_mac_complete(pdata) == 0))
400 return smsc911x_reg_read(pdata, MAC_CSR_DATA);
401
Joe Perchesdffc6b22011-03-25 14:21:22 +0000402 SMSC_WARN(pdata, hw, "MAC busy after read");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000403 return 0xFFFFFFFF;
404}
405
406/* Set a mac register, mac_lock must be acquired before calling */
407static void smsc911x_mac_write(struct smsc911x_data *pdata,
408 unsigned int offset, u32 val)
409{
410 unsigned int temp;
411
412 SMSC_ASSERT_MAC_LOCK(pdata);
413
414 temp = smsc911x_reg_read(pdata, MAC_CSR_CMD);
415 if (unlikely(temp & MAC_CSR_CMD_CSR_BUSY_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000416 SMSC_WARN(pdata, hw,
417 "smsc911x_mac_write failed, MAC busy at entry");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000418 return;
419 }
420
421 /* Send data to write */
422 smsc911x_reg_write(pdata, MAC_CSR_DATA, val);
423
424 /* Write the actual data */
425 smsc911x_reg_write(pdata, MAC_CSR_CMD, ((offset & 0xFF) |
426 MAC_CSR_CMD_CSR_BUSY_));
427
428 /* Workaround for hardware read-after-write restriction */
429 temp = smsc911x_reg_read(pdata, BYTE_TEST);
430
431 /* Wait for the write to complete */
432 if (likely(smsc911x_mac_complete(pdata) == 0))
433 return;
434
Joe Perchesdffc6b22011-03-25 14:21:22 +0000435 SMSC_WARN(pdata, hw, "smsc911x_mac_write failed, MAC busy after write");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000436}
437
438/* Get a phy register */
439static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
440{
441 struct smsc911x_data *pdata = (struct smsc911x_data *)bus->priv;
442 unsigned long flags;
443 unsigned int addr;
444 int i, reg;
445
446 spin_lock_irqsave(&pdata->mac_lock, flags);
447
448 /* Confirm MII not busy */
449 if (unlikely(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000450 SMSC_WARN(pdata, hw, "MII is busy in smsc911x_mii_read???");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000451 reg = -EIO;
452 goto out;
453 }
454
455 /* Set the address, index & direction (read from PHY) */
456 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6);
457 smsc911x_mac_write(pdata, MII_ACC, addr);
458
459 /* Wait for read to complete w/ timeout */
460 for (i = 0; i < 100; i++)
461 if (!(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
462 reg = smsc911x_mac_read(pdata, MII_DATA);
463 goto out;
464 }
465
Joe Perchesdffc6b22011-03-25 14:21:22 +0000466 SMSC_WARN(pdata, hw, "Timed out waiting for MII read to finish");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000467 reg = -EIO;
468
469out:
470 spin_unlock_irqrestore(&pdata->mac_lock, flags);
471 return reg;
472}
473
474/* Set a phy register */
475static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
476 u16 val)
477{
478 struct smsc911x_data *pdata = (struct smsc911x_data *)bus->priv;
479 unsigned long flags;
480 unsigned int addr;
481 int i, reg;
482
483 spin_lock_irqsave(&pdata->mac_lock, flags);
484
485 /* Confirm MII not busy */
486 if (unlikely(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000487 SMSC_WARN(pdata, hw, "MII is busy in smsc911x_mii_write???");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000488 reg = -EIO;
489 goto out;
490 }
491
492 /* Put the data to write in the MAC */
493 smsc911x_mac_write(pdata, MII_DATA, val);
494
495 /* Set the address, index & direction (write to PHY) */
496 addr = ((phyaddr & 0x1F) << 11) | ((regidx & 0x1F) << 6) |
497 MII_ACC_MII_WRITE_;
498 smsc911x_mac_write(pdata, MII_ACC, addr);
499
500 /* Wait for write to complete w/ timeout */
501 for (i = 0; i < 100; i++)
502 if (!(smsc911x_mac_read(pdata, MII_ACC) & MII_ACC_MII_BUSY_)) {
503 reg = 0;
504 goto out;
505 }
506
Joe Perchesdffc6b22011-03-25 14:21:22 +0000507 SMSC_WARN(pdata, hw, "Timed out waiting for MII write to finish");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000508 reg = -EIO;
509
510out:
511 spin_unlock_irqrestore(&pdata->mac_lock, flags);
512 return reg;
513}
514
Steve Glendinningd23f0282009-01-27 06:51:11 +0000515/* Switch to external phy. Assumes tx and rx are stopped. */
516static void smsc911x_phy_enable_external(struct smsc911x_data *pdata)
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000517{
518 unsigned int hwcfg = smsc911x_reg_read(pdata, HW_CFG);
519
Steve Glendinningd23f0282009-01-27 06:51:11 +0000520 /* Disable phy clocks to the MAC */
521 hwcfg &= (~HW_CFG_PHY_CLK_SEL_);
522 hwcfg |= HW_CFG_PHY_CLK_SEL_CLK_DIS_;
523 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
524 udelay(10); /* Enough time for clocks to stop */
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000525
Steve Glendinningd23f0282009-01-27 06:51:11 +0000526 /* Switch to external phy */
527 hwcfg |= HW_CFG_EXT_PHY_EN_;
528 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000529
Steve Glendinningd23f0282009-01-27 06:51:11 +0000530 /* Enable phy clocks to the MAC */
531 hwcfg &= (~HW_CFG_PHY_CLK_SEL_);
532 hwcfg |= HW_CFG_PHY_CLK_SEL_EXT_PHY_;
533 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
534 udelay(10); /* Enough time for clocks to restart */
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000535
Steve Glendinningd23f0282009-01-27 06:51:11 +0000536 hwcfg |= HW_CFG_SMI_SEL_;
537 smsc911x_reg_write(pdata, HW_CFG, hwcfg);
538}
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000539
Steve Glendinningd23f0282009-01-27 06:51:11 +0000540/* Autodetects and enables external phy if present on supported chips.
541 * autodetection can be overridden by specifying SMSC911X_FORCE_INTERNAL_PHY
542 * or SMSC911X_FORCE_EXTERNAL_PHY in the platform_data flags. */
543static void smsc911x_phy_initialise_external(struct smsc911x_data *pdata)
544{
545 unsigned int hwcfg = smsc911x_reg_read(pdata, HW_CFG);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000546
Steve Glendinningd23f0282009-01-27 06:51:11 +0000547 if (pdata->config.flags & SMSC911X_FORCE_INTERNAL_PHY) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000548 SMSC_TRACE(pdata, hw, "Forcing internal PHY");
Steve Glendinningd23f0282009-01-27 06:51:11 +0000549 pdata->using_extphy = 0;
550 } else if (pdata->config.flags & SMSC911X_FORCE_EXTERNAL_PHY) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000551 SMSC_TRACE(pdata, hw, "Forcing external PHY");
Steve Glendinningd23f0282009-01-27 06:51:11 +0000552 smsc911x_phy_enable_external(pdata);
553 pdata->using_extphy = 1;
554 } else if (hwcfg & HW_CFG_EXT_PHY_DET_) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000555 SMSC_TRACE(pdata, hw,
556 "HW_CFG EXT_PHY_DET set, using external PHY");
Steve Glendinningd23f0282009-01-27 06:51:11 +0000557 smsc911x_phy_enable_external(pdata);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000558 pdata->using_extphy = 1;
559 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000560 SMSC_TRACE(pdata, hw,
561 "HW_CFG EXT_PHY_DET clear, using internal PHY");
Steve Glendinningd23f0282009-01-27 06:51:11 +0000562 pdata->using_extphy = 0;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000563 }
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000564}
565
566/* Fetches a tx status out of the status fifo */
567static unsigned int smsc911x_tx_get_txstatus(struct smsc911x_data *pdata)
568{
569 unsigned int result =
570 smsc911x_reg_read(pdata, TX_FIFO_INF) & TX_FIFO_INF_TSUSED_;
571
572 if (result != 0)
573 result = smsc911x_reg_read(pdata, TX_STATUS_FIFO);
574
575 return result;
576}
577
578/* Fetches the next rx status */
579static unsigned int smsc911x_rx_get_rxstatus(struct smsc911x_data *pdata)
580{
581 unsigned int result =
582 smsc911x_reg_read(pdata, RX_FIFO_INF) & RX_FIFO_INF_RXSUSED_;
583
584 if (result != 0)
585 result = smsc911x_reg_read(pdata, RX_STATUS_FIFO);
586
587 return result;
588}
589
590#ifdef USE_PHY_WORK_AROUND
591static int smsc911x_phy_check_loopbackpkt(struct smsc911x_data *pdata)
592{
593 unsigned int tries;
594 u32 wrsz;
595 u32 rdsz;
596 ulong bufp;
597
598 for (tries = 0; tries < 10; tries++) {
599 unsigned int txcmd_a;
600 unsigned int txcmd_b;
601 unsigned int status;
602 unsigned int pktlength;
603 unsigned int i;
604
605 /* Zero-out rx packet memory */
606 memset(pdata->loopback_rx_pkt, 0, MIN_PACKET_SIZE);
607
608 /* Write tx packet to 118 */
609 txcmd_a = (u32)((ulong)pdata->loopback_tx_pkt & 0x03) << 16;
610 txcmd_a |= TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
611 txcmd_a |= MIN_PACKET_SIZE;
612
613 txcmd_b = MIN_PACKET_SIZE << 16 | MIN_PACKET_SIZE;
614
615 smsc911x_reg_write(pdata, TX_DATA_FIFO, txcmd_a);
616 smsc911x_reg_write(pdata, TX_DATA_FIFO, txcmd_b);
617
618 bufp = (ulong)pdata->loopback_tx_pkt & (~0x3);
619 wrsz = MIN_PACKET_SIZE + 3;
620 wrsz += (u32)((ulong)pdata->loopback_tx_pkt & 0x3);
621 wrsz >>= 2;
622
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700623 pdata->ops->tx_writefifo(pdata, (unsigned int *)bufp, wrsz);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000624
625 /* Wait till transmit is done */
626 i = 60;
627 do {
628 udelay(5);
629 status = smsc911x_tx_get_txstatus(pdata);
630 } while ((i--) && (!status));
631
632 if (!status) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000633 SMSC_WARN(pdata, hw,
634 "Failed to transmit during loopback test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000635 continue;
636 }
637 if (status & TX_STS_ES_) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000638 SMSC_WARN(pdata, hw,
639 "Transmit encountered errors during loopback test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000640 continue;
641 }
642
643 /* Wait till receive is done */
644 i = 60;
645 do {
646 udelay(5);
647 status = smsc911x_rx_get_rxstatus(pdata);
648 } while ((i--) && (!status));
649
650 if (!status) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000651 SMSC_WARN(pdata, hw,
652 "Failed to receive during loopback test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000653 continue;
654 }
655 if (status & RX_STS_ES_) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000656 SMSC_WARN(pdata, hw,
657 "Receive encountered errors during loopback test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000658 continue;
659 }
660
661 pktlength = ((status & 0x3FFF0000UL) >> 16);
662 bufp = (ulong)pdata->loopback_rx_pkt;
663 rdsz = pktlength + 3;
664 rdsz += (u32)((ulong)pdata->loopback_rx_pkt & 0x3);
665 rdsz >>= 2;
666
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -0700667 pdata->ops->rx_readfifo(pdata, (unsigned int *)bufp, rdsz);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000668
669 if (pktlength != (MIN_PACKET_SIZE + 4)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000670 SMSC_WARN(pdata, hw, "Unexpected packet size "
671 "during loop back test, size=%d, will retry",
672 pktlength);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000673 } else {
674 unsigned int j;
675 int mismatch = 0;
676 for (j = 0; j < MIN_PACKET_SIZE; j++) {
677 if (pdata->loopback_tx_pkt[j]
678 != pdata->loopback_rx_pkt[j]) {
679 mismatch = 1;
680 break;
681 }
682 }
683 if (!mismatch) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000684 SMSC_TRACE(pdata, hw, "Successfully verified "
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000685 "loopback packet");
686 return 0;
687 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000688 SMSC_WARN(pdata, hw, "Data mismatch "
689 "during loop back test, will retry");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000690 }
691 }
692 }
693
694 return -EIO;
695}
696
697static int smsc911x_phy_reset(struct smsc911x_data *pdata)
698{
699 struct phy_device *phy_dev = pdata->phy_dev;
700 unsigned int temp;
701 unsigned int i = 100000;
702
703 BUG_ON(!phy_dev);
704 BUG_ON(!phy_dev->bus);
705
Joe Perchesdffc6b22011-03-25 14:21:22 +0000706 SMSC_TRACE(pdata, hw, "Performing PHY BCR Reset");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000707 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR, BMCR_RESET);
708 do {
709 msleep(1);
710 temp = smsc911x_mii_read(phy_dev->bus, phy_dev->addr,
711 MII_BMCR);
712 } while ((i--) && (temp & BMCR_RESET));
713
714 if (temp & BMCR_RESET) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000715 SMSC_WARN(pdata, hw, "PHY reset failed to complete");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000716 return -EIO;
717 }
718 /* Extra delay required because the phy may not be completed with
719 * its reset when BMCR_RESET is cleared. Specs say 256 uS is
720 * enough delay but using 1ms here to be safe */
721 msleep(1);
722
723 return 0;
724}
725
726static int smsc911x_phy_loopbacktest(struct net_device *dev)
727{
728 struct smsc911x_data *pdata = netdev_priv(dev);
729 struct phy_device *phy_dev = pdata->phy_dev;
730 int result = -EIO;
731 unsigned int i, val;
732 unsigned long flags;
733
734 /* Initialise tx packet using broadcast destination address */
735 memset(pdata->loopback_tx_pkt, 0xff, ETH_ALEN);
736
737 /* Use incrementing source address */
738 for (i = 6; i < 12; i++)
739 pdata->loopback_tx_pkt[i] = (char)i;
740
741 /* Set length type field */
742 pdata->loopback_tx_pkt[12] = 0x00;
743 pdata->loopback_tx_pkt[13] = 0x00;
744
745 for (i = 14; i < MIN_PACKET_SIZE; i++)
746 pdata->loopback_tx_pkt[i] = (char)i;
747
748 val = smsc911x_reg_read(pdata, HW_CFG);
749 val &= HW_CFG_TX_FIF_SZ_;
750 val |= HW_CFG_SF_;
751 smsc911x_reg_write(pdata, HW_CFG, val);
752
753 smsc911x_reg_write(pdata, TX_CFG, TX_CFG_TX_ON_);
754 smsc911x_reg_write(pdata, RX_CFG,
755 (u32)((ulong)pdata->loopback_rx_pkt & 0x03) << 8);
756
757 for (i = 0; i < 10; i++) {
758 /* Set PHY to 10/FD, no ANEG, and loopback mode */
759 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR,
760 BMCR_LOOPBACK | BMCR_FULLDPLX);
761
762 /* Enable MAC tx/rx, FD */
763 spin_lock_irqsave(&pdata->mac_lock, flags);
764 smsc911x_mac_write(pdata, MAC_CR, MAC_CR_FDPX_
765 | MAC_CR_TXEN_ | MAC_CR_RXEN_);
766 spin_unlock_irqrestore(&pdata->mac_lock, flags);
767
768 if (smsc911x_phy_check_loopbackpkt(pdata) == 0) {
769 result = 0;
770 break;
771 }
772 pdata->resetcount++;
773
774 /* Disable MAC rx */
775 spin_lock_irqsave(&pdata->mac_lock, flags);
776 smsc911x_mac_write(pdata, MAC_CR, 0);
777 spin_unlock_irqrestore(&pdata->mac_lock, flags);
778
779 smsc911x_phy_reset(pdata);
780 }
781
782 /* Disable MAC */
783 spin_lock_irqsave(&pdata->mac_lock, flags);
784 smsc911x_mac_write(pdata, MAC_CR, 0);
785 spin_unlock_irqrestore(&pdata->mac_lock, flags);
786
787 /* Cancel PHY loopback mode */
788 smsc911x_mii_write(phy_dev->bus, phy_dev->addr, MII_BMCR, 0);
789
790 smsc911x_reg_write(pdata, TX_CFG, 0);
791 smsc911x_reg_write(pdata, RX_CFG, 0);
792
793 return result;
794}
795#endif /* USE_PHY_WORK_AROUND */
796
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000797static void smsc911x_phy_update_flowcontrol(struct smsc911x_data *pdata)
798{
799 struct phy_device *phy_dev = pdata->phy_dev;
800 u32 afc = smsc911x_reg_read(pdata, AFC_CFG);
801 u32 flow;
802 unsigned long flags;
803
804 if (phy_dev->duplex == DUPLEX_FULL) {
805 u16 lcladv = phy_read(phy_dev, MII_ADVERTISE);
806 u16 rmtadv = phy_read(phy_dev, MII_LPA);
Steve Glendinningbc02ff92008-12-16 02:00:48 -0800807 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000808
809 if (cap & FLOW_CTRL_RX)
810 flow = 0xFFFF0002;
811 else
812 flow = 0;
813
814 if (cap & FLOW_CTRL_TX)
815 afc |= 0xF;
816 else
817 afc &= ~0xF;
818
Joe Perchesdffc6b22011-03-25 14:21:22 +0000819 SMSC_TRACE(pdata, hw, "rx pause %s, tx pause %s",
820 (cap & FLOW_CTRL_RX ? "enabled" : "disabled"),
821 (cap & FLOW_CTRL_TX ? "enabled" : "disabled"));
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000822 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000823 SMSC_TRACE(pdata, hw, "half duplex");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000824 flow = 0;
825 afc |= 0xF;
826 }
827
828 spin_lock_irqsave(&pdata->mac_lock, flags);
829 smsc911x_mac_write(pdata, FLOW, flow);
830 spin_unlock_irqrestore(&pdata->mac_lock, flags);
831
832 smsc911x_reg_write(pdata, AFC_CFG, afc);
833}
834
835/* Update link mode if anything has changed. Called periodically when the
836 * PHY is in polling mode, even if nothing has changed. */
837static void smsc911x_phy_adjust_link(struct net_device *dev)
838{
839 struct smsc911x_data *pdata = netdev_priv(dev);
840 struct phy_device *phy_dev = pdata->phy_dev;
841 unsigned long flags;
842 int carrier;
843
844 if (phy_dev->duplex != pdata->last_duplex) {
845 unsigned int mac_cr;
Joe Perchesdffc6b22011-03-25 14:21:22 +0000846 SMSC_TRACE(pdata, hw, "duplex state has changed");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000847
848 spin_lock_irqsave(&pdata->mac_lock, flags);
849 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
850 if (phy_dev->duplex) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000851 SMSC_TRACE(pdata, hw,
852 "configuring for full duplex mode");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000853 mac_cr |= MAC_CR_FDPX_;
854 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000855 SMSC_TRACE(pdata, hw,
856 "configuring for half duplex mode");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000857 mac_cr &= ~MAC_CR_FDPX_;
858 }
859 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
860 spin_unlock_irqrestore(&pdata->mac_lock, flags);
861
862 smsc911x_phy_update_flowcontrol(pdata);
863 pdata->last_duplex = phy_dev->duplex;
864 }
865
866 carrier = netif_carrier_ok(dev);
867 if (carrier != pdata->last_carrier) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000868 SMSC_TRACE(pdata, hw, "carrier state has changed");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000869 if (carrier) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000870 SMSC_TRACE(pdata, hw, "configuring for carrier OK");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000871 if ((pdata->gpio_orig_setting & GPIO_CFG_LED1_EN_) &&
872 (!pdata->using_extphy)) {
Thomas Weber88393162010-03-16 11:47:56 +0100873 /* Restore original GPIO configuration */
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000874 pdata->gpio_setting = pdata->gpio_orig_setting;
875 smsc911x_reg_write(pdata, GPIO_CFG,
876 pdata->gpio_setting);
877 }
878 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000879 SMSC_TRACE(pdata, hw, "configuring for no carrier");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000880 /* Check global setting that LED1
881 * usage is 10/100 indicator */
882 pdata->gpio_setting = smsc911x_reg_read(pdata,
883 GPIO_CFG);
Joe Perches8e95a202009-12-03 07:58:21 +0000884 if ((pdata->gpio_setting & GPIO_CFG_LED1_EN_) &&
885 (!pdata->using_extphy)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000886 /* Force 10/100 LED off, after saving
Thomas Weber88393162010-03-16 11:47:56 +0100887 * original GPIO configuration */
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000888 pdata->gpio_orig_setting = pdata->gpio_setting;
889
890 pdata->gpio_setting &= ~GPIO_CFG_LED1_EN_;
891 pdata->gpio_setting |= (GPIO_CFG_GPIOBUF0_
892 | GPIO_CFG_GPIODIR0_
893 | GPIO_CFG_GPIOD0_);
894 smsc911x_reg_write(pdata, GPIO_CFG,
895 pdata->gpio_setting);
896 }
897 }
898 pdata->last_carrier = carrier;
899 }
900}
901
902static int smsc911x_mii_probe(struct net_device *dev)
903{
904 struct smsc911x_data *pdata = netdev_priv(dev);
905 struct phy_device *phydev = NULL;
kirjanov@gmail.come4a474f2010-02-16 21:54:58 +0000906 int ret;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000907
908 /* find the first phy */
kirjanov@gmail.come4a474f2010-02-16 21:54:58 +0000909 phydev = phy_find_first(pdata->mii_bus);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000910 if (!phydev) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000911 netdev_err(dev, "no PHY found\n");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000912 return -ENODEV;
913 }
914
Joe Perchesdffc6b22011-03-25 14:21:22 +0000915 SMSC_TRACE(pdata, probe, "PHY: addr %d, phy_id 0x%08X",
916 phydev->addr, phydev->phy_id);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000917
kirjanov@gmail.come4a474f2010-02-16 21:54:58 +0000918 ret = phy_connect_direct(dev, phydev,
919 &smsc911x_phy_adjust_link, 0,
920 pdata->config.phy_interface);
921
922 if (ret) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000923 netdev_err(dev, "Could not attach to PHY\n");
kirjanov@gmail.come4a474f2010-02-16 21:54:58 +0000924 return ret;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000925 }
926
Joe Perchesdffc6b22011-03-25 14:21:22 +0000927 netdev_info(dev,
928 "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
929 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000930
931 /* mask with MAC supported features */
932 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
933 SUPPORTED_Asym_Pause);
934 phydev->advertising = phydev->supported;
935
936 pdata->phy_dev = phydev;
937 pdata->last_duplex = -1;
938 pdata->last_carrier = -1;
939
940#ifdef USE_PHY_WORK_AROUND
941 if (smsc911x_phy_loopbacktest(dev) < 0) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000942 SMSC_WARN(pdata, hw, "Failed Loop Back Test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000943 return -ENODEV;
944 }
Joe Perchesdffc6b22011-03-25 14:21:22 +0000945 SMSC_TRACE(pdata, hw, "Passed Loop Back Test");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000946#endif /* USE_PHY_WORK_AROUND */
947
Joe Perchesdffc6b22011-03-25 14:21:22 +0000948 SMSC_TRACE(pdata, hw, "phy initialised successfully");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000949 return 0;
950}
951
952static int __devinit smsc911x_mii_init(struct platform_device *pdev,
953 struct net_device *dev)
954{
955 struct smsc911x_data *pdata = netdev_priv(dev);
956 int err = -ENXIO, i;
957
958 pdata->mii_bus = mdiobus_alloc();
959 if (!pdata->mii_bus) {
960 err = -ENOMEM;
961 goto err_out_1;
962 }
963
964 pdata->mii_bus->name = SMSC_MDIONAME;
965 snprintf(pdata->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id);
966 pdata->mii_bus->priv = pdata;
967 pdata->mii_bus->read = smsc911x_mii_read;
968 pdata->mii_bus->write = smsc911x_mii_write;
969 pdata->mii_bus->irq = pdata->phy_irq;
970 for (i = 0; i < PHY_MAX_ADDR; ++i)
971 pdata->mii_bus->irq[i] = PHY_POLL;
972
973 pdata->mii_bus->parent = &pdev->dev;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000974
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000975 switch (pdata->idrev & 0xFFFF0000) {
976 case 0x01170000:
977 case 0x01150000:
978 case 0x117A0000:
979 case 0x115A0000:
980 /* External PHY supported, try to autodetect */
Steve Glendinningd23f0282009-01-27 06:51:11 +0000981 smsc911x_phy_initialise_external(pdata);
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000982 break;
983 default:
Joe Perchesdffc6b22011-03-25 14:21:22 +0000984 SMSC_TRACE(pdata, hw, "External PHY is not supported, "
985 "using internal PHY");
Steve Glendinningd23f0282009-01-27 06:51:11 +0000986 pdata->using_extphy = 0;
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000987 break;
988 }
989
990 if (!pdata->using_extphy) {
991 /* Mask all PHYs except ID 1 (internal) */
992 pdata->mii_bus->phy_mask = ~(1 << 1);
993 }
994
995 if (mdiobus_register(pdata->mii_bus)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +0000996 SMSC_WARN(pdata, probe, "Error registering mii bus");
Steve Glendinningfd9abb32008-11-05 00:35:37 +0000997 goto err_out_free_bus_2;
998 }
999
1000 if (smsc911x_mii_probe(dev) < 0) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001001 SMSC_WARN(pdata, probe, "Error registering mii bus");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001002 goto err_out_unregister_bus_3;
1003 }
1004
1005 return 0;
1006
1007err_out_unregister_bus_3:
1008 mdiobus_unregister(pdata->mii_bus);
1009err_out_free_bus_2:
1010 mdiobus_free(pdata->mii_bus);
1011err_out_1:
1012 return err;
1013}
1014
1015/* Gets the number of tx statuses in the fifo */
1016static unsigned int smsc911x_tx_get_txstatcount(struct smsc911x_data *pdata)
1017{
1018 return (smsc911x_reg_read(pdata, TX_FIFO_INF)
1019 & TX_FIFO_INF_TSUSED_) >> 16;
1020}
1021
1022/* Reads tx statuses and increments counters where necessary */
1023static void smsc911x_tx_update_txcounters(struct net_device *dev)
1024{
1025 struct smsc911x_data *pdata = netdev_priv(dev);
1026 unsigned int tx_stat;
1027
1028 while ((tx_stat = smsc911x_tx_get_txstatus(pdata)) != 0) {
1029 if (unlikely(tx_stat & 0x80000000)) {
1030 /* In this driver the packet tag is used as the packet
1031 * length. Since a packet length can never reach the
1032 * size of 0x8000, this bit is reserved. It is worth
1033 * noting that the "reserved bit" in the warning above
1034 * does not reference a hardware defined reserved bit
1035 * but rather a driver defined one.
1036 */
Joe Perchesdffc6b22011-03-25 14:21:22 +00001037 SMSC_WARN(pdata, hw, "Packet tag reserved bit is high");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001038 } else {
Steve Glendinning785b6f92009-03-19 00:24:44 +00001039 if (unlikely(tx_stat & TX_STS_ES_)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001040 dev->stats.tx_errors++;
1041 } else {
1042 dev->stats.tx_packets++;
1043 dev->stats.tx_bytes += (tx_stat >> 16);
1044 }
Steve Glendinning785b6f92009-03-19 00:24:44 +00001045 if (unlikely(tx_stat & TX_STS_EXCESS_COL_)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001046 dev->stats.collisions += 16;
1047 dev->stats.tx_aborted_errors += 1;
1048 } else {
1049 dev->stats.collisions +=
1050 ((tx_stat >> 3) & 0xF);
1051 }
Steve Glendinning785b6f92009-03-19 00:24:44 +00001052 if (unlikely(tx_stat & TX_STS_LOST_CARRIER_))
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001053 dev->stats.tx_carrier_errors += 1;
Steve Glendinning785b6f92009-03-19 00:24:44 +00001054 if (unlikely(tx_stat & TX_STS_LATE_COL_)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001055 dev->stats.collisions++;
1056 dev->stats.tx_aborted_errors++;
1057 }
1058 }
1059 }
1060}
1061
1062/* Increments the Rx error counters */
1063static void
1064smsc911x_rx_counterrors(struct net_device *dev, unsigned int rxstat)
1065{
1066 int crc_err = 0;
1067
Steve Glendinning785b6f92009-03-19 00:24:44 +00001068 if (unlikely(rxstat & RX_STS_ES_)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001069 dev->stats.rx_errors++;
Steve Glendinning785b6f92009-03-19 00:24:44 +00001070 if (unlikely(rxstat & RX_STS_CRC_ERR_)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001071 dev->stats.rx_crc_errors++;
1072 crc_err = 1;
1073 }
1074 }
1075 if (likely(!crc_err)) {
Steve Glendinning785b6f92009-03-19 00:24:44 +00001076 if (unlikely((rxstat & RX_STS_FRAME_TYPE_) &&
1077 (rxstat & RX_STS_LENGTH_ERR_)))
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001078 dev->stats.rx_length_errors++;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001079 if (rxstat & RX_STS_MCAST_)
1080 dev->stats.multicast++;
1081 }
1082}
1083
1084/* Quickly dumps bad packets */
1085static void
1086smsc911x_rx_fastforward(struct smsc911x_data *pdata, unsigned int pktbytes)
1087{
1088 unsigned int pktwords = (pktbytes + NET_IP_ALIGN + 3) >> 2;
1089
1090 if (likely(pktwords >= 4)) {
1091 unsigned int timeout = 500;
1092 unsigned int val;
1093 smsc911x_reg_write(pdata, RX_DP_CTRL, RX_DP_CTRL_RX_FFWD_);
1094 do {
1095 udelay(1);
1096 val = smsc911x_reg_read(pdata, RX_DP_CTRL);
Steve Glendinning8dacd542009-03-04 07:33:24 +00001097 } while ((val & RX_DP_CTRL_RX_FFWD_) && --timeout);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001098
1099 if (unlikely(timeout == 0))
Joe Perchesdffc6b22011-03-25 14:21:22 +00001100 SMSC_WARN(pdata, hw, "Timed out waiting for "
1101 "RX FFWD to finish, RX_DP_CTRL: 0x%08X", val);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001102 } else {
1103 unsigned int temp;
1104 while (pktwords--)
1105 temp = smsc911x_reg_read(pdata, RX_DATA_FIFO);
1106 }
1107}
1108
1109/* NAPI poll function */
1110static int smsc911x_poll(struct napi_struct *napi, int budget)
1111{
1112 struct smsc911x_data *pdata =
1113 container_of(napi, struct smsc911x_data, napi);
1114 struct net_device *dev = pdata->dev;
1115 int npackets = 0;
1116
Sriramf88c5b92009-11-12 02:14:38 +00001117 while (npackets < budget) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001118 unsigned int pktlength;
1119 unsigned int pktwords;
1120 struct sk_buff *skb;
1121 unsigned int rxstat = smsc911x_rx_get_rxstatus(pdata);
1122
1123 if (!rxstat) {
1124 unsigned int temp;
1125 /* We processed all packets available. Tell NAPI it can
1126 * stop polling then re-enable rx interrupts */
1127 smsc911x_reg_write(pdata, INT_STS, INT_STS_RSFL_);
Ben Hutchings288379f2009-01-19 16:43:59 -08001128 napi_complete(napi);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001129 temp = smsc911x_reg_read(pdata, INT_EN);
1130 temp |= INT_EN_RSFL_EN_;
1131 smsc911x_reg_write(pdata, INT_EN, temp);
1132 break;
1133 }
1134
1135 /* Count packet for NAPI scheduling, even if it has an error.
1136 * Error packets still require cycles to discard */
1137 npackets++;
1138
1139 pktlength = ((rxstat & 0x3FFF0000) >> 16);
1140 pktwords = (pktlength + NET_IP_ALIGN + 3) >> 2;
1141 smsc911x_rx_counterrors(dev, rxstat);
1142
1143 if (unlikely(rxstat & RX_STS_ES_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001144 SMSC_WARN(pdata, rx_err,
1145 "Discarding packet with error bit set");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001146 /* Packet has an error, discard it and continue with
1147 * the next */
1148 smsc911x_rx_fastforward(pdata, pktwords);
1149 dev->stats.rx_dropped++;
1150 continue;
1151 }
1152
1153 skb = netdev_alloc_skb(dev, pktlength + NET_IP_ALIGN);
1154 if (unlikely(!skb)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001155 SMSC_WARN(pdata, rx_err,
1156 "Unable to allocate skb for rx packet");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001157 /* Drop the packet and stop this polling iteration */
1158 smsc911x_rx_fastforward(pdata, pktwords);
1159 dev->stats.rx_dropped++;
1160 break;
1161 }
1162
1163 skb->data = skb->head;
1164 skb_reset_tail_pointer(skb);
1165
1166 /* Align IP on 16B boundary */
1167 skb_reserve(skb, NET_IP_ALIGN);
1168 skb_put(skb, pktlength - 4);
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -07001169 pdata->ops->rx_readfifo(pdata,
1170 (unsigned int *)skb->head, pktwords);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001171 skb->protocol = eth_type_trans(skb, dev);
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001172 skb_checksum_none_assert(skb);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001173 netif_receive_skb(skb);
1174
1175 /* Update counters */
1176 dev->stats.rx_packets++;
1177 dev->stats.rx_bytes += (pktlength - 4);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001178 }
1179
1180 /* Return total received packets */
1181 return npackets;
1182}
1183
1184/* Returns hash bit number for given MAC address
1185 * Example:
1186 * 01 00 5E 00 00 01 -> returns bit number 31 */
1187static unsigned int smsc911x_hash(char addr[ETH_ALEN])
1188{
1189 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
1190}
1191
1192static void smsc911x_rx_multicast_update(struct smsc911x_data *pdata)
1193{
1194 /* Performs the multicast & mac_cr update. This is called when
1195 * safe on the current hardware, and with the mac_lock held */
1196 unsigned int mac_cr;
1197
1198 SMSC_ASSERT_MAC_LOCK(pdata);
1199
1200 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
1201 mac_cr |= pdata->set_bits_mask;
1202 mac_cr &= ~(pdata->clear_bits_mask);
1203 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
1204 smsc911x_mac_write(pdata, HASHH, pdata->hashhi);
1205 smsc911x_mac_write(pdata, HASHL, pdata->hashlo);
Joe Perchesdffc6b22011-03-25 14:21:22 +00001206 SMSC_TRACE(pdata, hw, "maccr 0x%08X, HASHH 0x%08X, HASHL 0x%08X",
1207 mac_cr, pdata->hashhi, pdata->hashlo);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001208}
1209
1210static void smsc911x_rx_multicast_update_workaround(struct smsc911x_data *pdata)
1211{
1212 unsigned int mac_cr;
1213
1214 /* This function is only called for older LAN911x devices
1215 * (revA or revB), where MAC_CR, HASHH and HASHL should not
1216 * be modified during Rx - newer devices immediately update the
1217 * registers.
1218 *
1219 * This is called from interrupt context */
1220
1221 spin_lock(&pdata->mac_lock);
1222
1223 /* Check Rx has stopped */
1224 if (smsc911x_mac_read(pdata, MAC_CR) & MAC_CR_RXEN_)
Joe Perchesdffc6b22011-03-25 14:21:22 +00001225 SMSC_WARN(pdata, drv, "Rx not stopped");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001226
1227 /* Perform the update - safe to do now Rx has stopped */
1228 smsc911x_rx_multicast_update(pdata);
1229
1230 /* Re-enable Rx */
1231 mac_cr = smsc911x_mac_read(pdata, MAC_CR);
1232 mac_cr |= MAC_CR_RXEN_;
1233 smsc911x_mac_write(pdata, MAC_CR, mac_cr);
1234
1235 pdata->multicast_update_pending = 0;
1236
1237 spin_unlock(&pdata->mac_lock);
1238}
1239
1240static int smsc911x_soft_reset(struct smsc911x_data *pdata)
1241{
1242 unsigned int timeout;
1243 unsigned int temp;
1244
1245 /* Reset the LAN911x */
1246 smsc911x_reg_write(pdata, HW_CFG, HW_CFG_SRST_);
1247 timeout = 10;
1248 do {
1249 udelay(10);
1250 temp = smsc911x_reg_read(pdata, HW_CFG);
1251 } while ((--timeout) && (temp & HW_CFG_SRST_));
1252
1253 if (unlikely(temp & HW_CFG_SRST_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001254 SMSC_WARN(pdata, drv, "Failed to complete reset");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001255 return -EIO;
1256 }
1257 return 0;
1258}
1259
1260/* Sets the device MAC address to dev_addr, called with mac_lock held */
1261static void
Steve Glendinning225ddf42009-03-19 00:24:46 +00001262smsc911x_set_hw_mac_address(struct smsc911x_data *pdata, u8 dev_addr[6])
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001263{
1264 u32 mac_high16 = (dev_addr[5] << 8) | dev_addr[4];
1265 u32 mac_low32 = (dev_addr[3] << 24) | (dev_addr[2] << 16) |
1266 (dev_addr[1] << 8) | dev_addr[0];
1267
1268 SMSC_ASSERT_MAC_LOCK(pdata);
1269
1270 smsc911x_mac_write(pdata, ADDRH, mac_high16);
1271 smsc911x_mac_write(pdata, ADDRL, mac_low32);
1272}
1273
1274static int smsc911x_open(struct net_device *dev)
1275{
1276 struct smsc911x_data *pdata = netdev_priv(dev);
1277 unsigned int timeout;
1278 unsigned int temp;
1279 unsigned int intcfg;
1280
1281 /* if the phy is not yet registered, retry later*/
1282 if (!pdata->phy_dev) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001283 SMSC_WARN(pdata, hw, "phy_dev is NULL");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001284 return -EAGAIN;
1285 }
1286
1287 if (!is_valid_ether_addr(dev->dev_addr)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001288 SMSC_WARN(pdata, hw, "dev_addr is not a valid MAC address");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001289 return -EADDRNOTAVAIL;
1290 }
1291
1292 /* Reset the LAN911x */
1293 if (smsc911x_soft_reset(pdata)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001294 SMSC_WARN(pdata, hw, "soft reset failed");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001295 return -EIO;
1296 }
1297
1298 smsc911x_reg_write(pdata, HW_CFG, 0x00050000);
1299 smsc911x_reg_write(pdata, AFC_CFG, 0x006E3740);
1300
Göran Weinholtf277e652011-03-02 04:07:21 +00001301 /* Increase the legal frame size of VLAN tagged frames to 1522 bytes */
1302 spin_lock_irq(&pdata->mac_lock);
1303 smsc911x_mac_write(pdata, VLAN1, ETH_P_8021Q);
1304 spin_unlock_irq(&pdata->mac_lock);
1305
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001306 /* Make sure EEPROM has finished loading before setting GPIO_CFG */
1307 timeout = 50;
Steve Glendinningf7efb6c2009-03-04 07:33:25 +00001308 while ((smsc911x_reg_read(pdata, E2P_CMD) & E2P_CMD_EPC_BUSY_) &&
1309 --timeout) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001310 udelay(10);
1311 }
1312
1313 if (unlikely(timeout == 0))
Joe Perchesdffc6b22011-03-25 14:21:22 +00001314 SMSC_WARN(pdata, ifup,
1315 "Timed out waiting for EEPROM busy bit to clear");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001316
1317 smsc911x_reg_write(pdata, GPIO_CFG, 0x70070000);
1318
1319 /* The soft reset above cleared the device's MAC address,
1320 * restore it from local copy (set in probe) */
1321 spin_lock_irq(&pdata->mac_lock);
Steve Glendinning225ddf42009-03-19 00:24:46 +00001322 smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001323 spin_unlock_irq(&pdata->mac_lock);
1324
1325 /* Initialise irqs, but leave all sources disabled */
1326 smsc911x_reg_write(pdata, INT_EN, 0);
1327 smsc911x_reg_write(pdata, INT_STS, 0xFFFFFFFF);
1328
1329 /* Set interrupt deassertion to 100uS */
1330 intcfg = ((10 << 24) | INT_CFG_IRQ_EN_);
1331
Steve Glendinning2107fb82008-11-05 00:35:38 +00001332 if (pdata->config.irq_polarity) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001333 SMSC_TRACE(pdata, ifup, "irq polarity: active high");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001334 intcfg |= INT_CFG_IRQ_POL_;
1335 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001336 SMSC_TRACE(pdata, ifup, "irq polarity: active low");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001337 }
1338
Steve Glendinning2107fb82008-11-05 00:35:38 +00001339 if (pdata->config.irq_type) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001340 SMSC_TRACE(pdata, ifup, "irq type: push-pull");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001341 intcfg |= INT_CFG_IRQ_TYPE_;
1342 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001343 SMSC_TRACE(pdata, ifup, "irq type: open drain");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001344 }
1345
1346 smsc911x_reg_write(pdata, INT_CFG, intcfg);
1347
Joe Perchesdffc6b22011-03-25 14:21:22 +00001348 SMSC_TRACE(pdata, ifup, "Testing irq handler using IRQ %d", dev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001349 pdata->software_irq_signal = 0;
1350 smp_wmb();
1351
1352 temp = smsc911x_reg_read(pdata, INT_EN);
1353 temp |= INT_EN_SW_INT_EN_;
1354 smsc911x_reg_write(pdata, INT_EN, temp);
1355
1356 timeout = 1000;
1357 while (timeout--) {
1358 if (pdata->software_irq_signal)
1359 break;
1360 msleep(1);
1361 }
1362
1363 if (!pdata->software_irq_signal) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001364 netdev_warn(dev, "ISR failed signaling test (IRQ %d)\n",
1365 dev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001366 return -ENODEV;
1367 }
Joe Perchesdffc6b22011-03-25 14:21:22 +00001368 SMSC_TRACE(pdata, ifup, "IRQ handler passed test using IRQ %d",
1369 dev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001370
Joe Perchesdffc6b22011-03-25 14:21:22 +00001371 netdev_info(dev, "SMSC911x/921x identified at %#08lx, IRQ: %d\n",
1372 (unsigned long)pdata->ioaddr, dev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001373
Steve Glendinning44c1d6f2009-03-18 23:37:18 -07001374 /* Reset the last known duplex and carrier */
1375 pdata->last_duplex = -1;
1376 pdata->last_carrier = -1;
1377
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001378 /* Bring the PHY up */
1379 phy_start(pdata->phy_dev);
1380
1381 temp = smsc911x_reg_read(pdata, HW_CFG);
1382 /* Preserve TX FIFO size and external PHY configuration */
1383 temp &= (HW_CFG_TX_FIF_SZ_|0x00000FFF);
1384 temp |= HW_CFG_SF_;
1385 smsc911x_reg_write(pdata, HW_CFG, temp);
1386
1387 temp = smsc911x_reg_read(pdata, FIFO_INT);
1388 temp |= FIFO_INT_TX_AVAIL_LEVEL_;
1389 temp &= ~(FIFO_INT_RX_STS_LEVEL_);
1390 smsc911x_reg_write(pdata, FIFO_INT, temp);
1391
1392 /* set RX Data offset to 2 bytes for alignment */
1393 smsc911x_reg_write(pdata, RX_CFG, (2 << 8));
1394
1395 /* enable NAPI polling before enabling RX interrupts */
1396 napi_enable(&pdata->napi);
1397
1398 temp = smsc911x_reg_read(pdata, INT_EN);
Steve Glendinning1373c0f2009-01-26 21:33:16 -08001399 temp |= (INT_EN_TDFA_EN_ | INT_EN_RSFL_EN_ | INT_EN_RXSTOP_INT_EN_);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001400 smsc911x_reg_write(pdata, INT_EN, temp);
1401
1402 spin_lock_irq(&pdata->mac_lock);
1403 temp = smsc911x_mac_read(pdata, MAC_CR);
1404 temp |= (MAC_CR_TXEN_ | MAC_CR_RXEN_ | MAC_CR_HBDIS_);
1405 smsc911x_mac_write(pdata, MAC_CR, temp);
1406 spin_unlock_irq(&pdata->mac_lock);
1407
1408 smsc911x_reg_write(pdata, TX_CFG, TX_CFG_TX_ON_);
1409
1410 netif_start_queue(dev);
1411 return 0;
1412}
1413
1414/* Entry point for stopping the interface */
1415static int smsc911x_stop(struct net_device *dev)
1416{
1417 struct smsc911x_data *pdata = netdev_priv(dev);
1418 unsigned int temp;
1419
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001420 /* Disable all device interrupts */
1421 temp = smsc911x_reg_read(pdata, INT_CFG);
1422 temp &= ~INT_CFG_IRQ_EN_;
1423 smsc911x_reg_write(pdata, INT_CFG, temp);
1424
1425 /* Stop Tx and Rx polling */
1426 netif_stop_queue(dev);
1427 napi_disable(&pdata->napi);
1428
1429 /* At this point all Rx and Tx activity is stopped */
1430 dev->stats.rx_dropped += smsc911x_reg_read(pdata, RX_DROP);
1431 smsc911x_tx_update_txcounters(dev);
1432
1433 /* Bring the PHY down */
Steve Glendinningdd045192008-12-25 16:40:19 -08001434 if (pdata->phy_dev)
1435 phy_stop(pdata->phy_dev);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001436
Joe Perchesdffc6b22011-03-25 14:21:22 +00001437 SMSC_TRACE(pdata, ifdown, "Interface stopped");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001438 return 0;
1439}
1440
1441/* Entry point for transmitting a packet */
1442static int smsc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1443{
1444 struct smsc911x_data *pdata = netdev_priv(dev);
1445 unsigned int freespace;
1446 unsigned int tx_cmd_a;
1447 unsigned int tx_cmd_b;
1448 unsigned int temp;
1449 u32 wrsz;
1450 ulong bufp;
1451
1452 freespace = smsc911x_reg_read(pdata, TX_FIFO_INF) & TX_FIFO_INF_TDFREE_;
1453
1454 if (unlikely(freespace < TX_FIFO_LOW_THRESHOLD))
Joe Perchesdffc6b22011-03-25 14:21:22 +00001455 SMSC_WARN(pdata, tx_err,
1456 "Tx data fifo low, space available: %d", freespace);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001457
1458 /* Word alignment adjustment */
1459 tx_cmd_a = (u32)((ulong)skb->data & 0x03) << 16;
1460 tx_cmd_a |= TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
1461 tx_cmd_a |= (unsigned int)skb->len;
1462
1463 tx_cmd_b = ((unsigned int)skb->len) << 16;
1464 tx_cmd_b |= (unsigned int)skb->len;
1465
1466 smsc911x_reg_write(pdata, TX_DATA_FIFO, tx_cmd_a);
1467 smsc911x_reg_write(pdata, TX_DATA_FIFO, tx_cmd_b);
1468
1469 bufp = (ulong)skb->data & (~0x3);
1470 wrsz = (u32)skb->len + 3;
1471 wrsz += (u32)((ulong)skb->data & 0x3);
1472 wrsz >>= 2;
1473
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -07001474 pdata->ops->tx_writefifo(pdata, (unsigned int *)bufp, wrsz);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001475 freespace -= (skb->len + 32);
1476 dev_kfree_skb(skb);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001477
1478 if (unlikely(smsc911x_tx_get_txstatcount(pdata) >= 30))
1479 smsc911x_tx_update_txcounters(dev);
1480
1481 if (freespace < TX_FIFO_LOW_THRESHOLD) {
1482 netif_stop_queue(dev);
1483 temp = smsc911x_reg_read(pdata, FIFO_INT);
1484 temp &= 0x00FFFFFF;
1485 temp |= 0x32000000;
1486 smsc911x_reg_write(pdata, FIFO_INT, temp);
1487 }
1488
1489 return NETDEV_TX_OK;
1490}
1491
1492/* Entry point for getting status counters */
1493static struct net_device_stats *smsc911x_get_stats(struct net_device *dev)
1494{
1495 struct smsc911x_data *pdata = netdev_priv(dev);
1496 smsc911x_tx_update_txcounters(dev);
1497 dev->stats.rx_dropped += smsc911x_reg_read(pdata, RX_DROP);
1498 return &dev->stats;
1499}
1500
1501/* Entry point for setting addressing modes */
1502static void smsc911x_set_multicast_list(struct net_device *dev)
1503{
1504 struct smsc911x_data *pdata = netdev_priv(dev);
1505 unsigned long flags;
1506
1507 if (dev->flags & IFF_PROMISC) {
1508 /* Enabling promiscuous mode */
1509 pdata->set_bits_mask = MAC_CR_PRMS_;
1510 pdata->clear_bits_mask = (MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
1511 pdata->hashhi = 0;
1512 pdata->hashlo = 0;
1513 } else if (dev->flags & IFF_ALLMULTI) {
1514 /* Enabling all multicast mode */
1515 pdata->set_bits_mask = MAC_CR_MCPAS_;
1516 pdata->clear_bits_mask = (MAC_CR_PRMS_ | MAC_CR_HPFILT_);
1517 pdata->hashhi = 0;
1518 pdata->hashlo = 0;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001519 } else if (!netdev_mc_empty(dev)) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001520 /* Enabling specific multicast addresses */
1521 unsigned int hash_high = 0;
1522 unsigned int hash_low = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001523 struct netdev_hw_addr *ha;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001524
1525 pdata->set_bits_mask = MAC_CR_HPFILT_;
1526 pdata->clear_bits_mask = (MAC_CR_PRMS_ | MAC_CR_MCPAS_);
1527
Jiri Pirko22bedad32010-04-01 21:22:57 +00001528 netdev_for_each_mc_addr(ha, dev) {
1529 unsigned int bitnum = smsc911x_hash(ha->addr);
Jiri Pirko2a0d18f2010-02-17 23:22:38 +00001530 unsigned int mask = 0x01 << (bitnum & 0x1F);
1531
1532 if (bitnum & 0x20)
1533 hash_high |= mask;
1534 else
1535 hash_low |= mask;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001536 }
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001537
1538 pdata->hashhi = hash_high;
1539 pdata->hashlo = hash_low;
1540 } else {
1541 /* Enabling local MAC address only */
1542 pdata->set_bits_mask = 0;
1543 pdata->clear_bits_mask =
1544 (MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
1545 pdata->hashhi = 0;
1546 pdata->hashlo = 0;
1547 }
1548
1549 spin_lock_irqsave(&pdata->mac_lock, flags);
1550
1551 if (pdata->generation <= 1) {
1552 /* Older hardware revision - cannot change these flags while
1553 * receiving data */
1554 if (!pdata->multicast_update_pending) {
1555 unsigned int temp;
Joe Perchesdffc6b22011-03-25 14:21:22 +00001556 SMSC_TRACE(pdata, hw, "scheduling mcast update");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001557 pdata->multicast_update_pending = 1;
1558
1559 /* Request the hardware to stop, then perform the
1560 * update when we get an RX_STOP interrupt */
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001561 temp = smsc911x_mac_read(pdata, MAC_CR);
1562 temp &= ~(MAC_CR_RXEN_);
1563 smsc911x_mac_write(pdata, MAC_CR, temp);
1564 } else {
1565 /* There is another update pending, this should now
1566 * use the newer values */
1567 }
1568 } else {
1569 /* Newer hardware revision - can write immediately */
1570 smsc911x_rx_multicast_update(pdata);
1571 }
1572
1573 spin_unlock_irqrestore(&pdata->mac_lock, flags);
1574}
1575
1576static irqreturn_t smsc911x_irqhandler(int irq, void *dev_id)
1577{
1578 struct net_device *dev = dev_id;
1579 struct smsc911x_data *pdata = netdev_priv(dev);
1580 u32 intsts = smsc911x_reg_read(pdata, INT_STS);
1581 u32 inten = smsc911x_reg_read(pdata, INT_EN);
1582 int serviced = IRQ_NONE;
1583 u32 temp;
1584
1585 if (unlikely(intsts & inten & INT_STS_SW_INT_)) {
1586 temp = smsc911x_reg_read(pdata, INT_EN);
1587 temp &= (~INT_EN_SW_INT_EN_);
1588 smsc911x_reg_write(pdata, INT_EN, temp);
1589 smsc911x_reg_write(pdata, INT_STS, INT_STS_SW_INT_);
1590 pdata->software_irq_signal = 1;
1591 smp_wmb();
1592 serviced = IRQ_HANDLED;
1593 }
1594
1595 if (unlikely(intsts & inten & INT_STS_RXSTOP_INT_)) {
1596 /* Called when there is a multicast update scheduled and
1597 * it is now safe to complete the update */
Joe Perchesdffc6b22011-03-25 14:21:22 +00001598 SMSC_TRACE(pdata, intr, "RX Stop interrupt");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001599 smsc911x_reg_write(pdata, INT_STS, INT_STS_RXSTOP_INT_);
Steve Glendinning1373c0f2009-01-26 21:33:16 -08001600 if (pdata->multicast_update_pending)
1601 smsc911x_rx_multicast_update_workaround(pdata);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001602 serviced = IRQ_HANDLED;
1603 }
1604
1605 if (intsts & inten & INT_STS_TDFA_) {
1606 temp = smsc911x_reg_read(pdata, FIFO_INT);
1607 temp |= FIFO_INT_TX_AVAIL_LEVEL_;
1608 smsc911x_reg_write(pdata, FIFO_INT, temp);
1609 smsc911x_reg_write(pdata, INT_STS, INT_STS_TDFA_);
1610 netif_wake_queue(dev);
1611 serviced = IRQ_HANDLED;
1612 }
1613
1614 if (unlikely(intsts & inten & INT_STS_RXE_)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001615 SMSC_TRACE(pdata, intr, "RX Error interrupt");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001616 smsc911x_reg_write(pdata, INT_STS, INT_STS_RXE_);
1617 serviced = IRQ_HANDLED;
1618 }
1619
1620 if (likely(intsts & inten & INT_STS_RSFL_)) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001621 if (likely(napi_schedule_prep(&pdata->napi))) {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001622 /* Disable Rx interrupts */
1623 temp = smsc911x_reg_read(pdata, INT_EN);
1624 temp &= (~INT_EN_RSFL_EN_);
1625 smsc911x_reg_write(pdata, INT_EN, temp);
1626 /* Schedule a NAPI poll */
Ben Hutchings288379f2009-01-19 16:43:59 -08001627 __napi_schedule(&pdata->napi);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001628 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001629 SMSC_WARN(pdata, rx_err, "napi_schedule_prep failed");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001630 }
1631 serviced = IRQ_HANDLED;
1632 }
1633
1634 return serviced;
1635}
1636
1637#ifdef CONFIG_NET_POLL_CONTROLLER
Steve Glendinning1757ab22008-12-12 22:31:16 -08001638static void smsc911x_poll_controller(struct net_device *dev)
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001639{
1640 disable_irq(dev->irq);
1641 smsc911x_irqhandler(0, dev);
1642 enable_irq(dev->irq);
1643}
1644#endif /* CONFIG_NET_POLL_CONTROLLER */
1645
Steve Glendinning225ddf42009-03-19 00:24:46 +00001646static int smsc911x_set_mac_address(struct net_device *dev, void *p)
1647{
1648 struct smsc911x_data *pdata = netdev_priv(dev);
1649 struct sockaddr *addr = p;
1650
1651 /* On older hardware revisions we cannot change the mac address
1652 * registers while receiving data. Newer devices can safely change
1653 * this at any time. */
1654 if (pdata->generation <= 1 && netif_running(dev))
1655 return -EBUSY;
1656
1657 if (!is_valid_ether_addr(addr->sa_data))
1658 return -EADDRNOTAVAIL;
1659
1660 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
1661
1662 spin_lock_irq(&pdata->mac_lock);
1663 smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
1664 spin_unlock_irq(&pdata->mac_lock);
1665
Joe Perchesdffc6b22011-03-25 14:21:22 +00001666 netdev_info(dev, "MAC Address: %pM\n", dev->dev_addr);
Steve Glendinning225ddf42009-03-19 00:24:46 +00001667
1668 return 0;
1669}
1670
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001671/* Standard ioctls for mii-tool */
1672static int smsc911x_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1673{
1674 struct smsc911x_data *pdata = netdev_priv(dev);
1675
1676 if (!netif_running(dev) || !pdata->phy_dev)
1677 return -EINVAL;
1678
Richard Cochran28b04112010-07-17 08:48:55 +00001679 return phy_mii_ioctl(pdata->phy_dev, ifr, cmd);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001680}
1681
1682static int
1683smsc911x_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1684{
1685 struct smsc911x_data *pdata = netdev_priv(dev);
1686
1687 cmd->maxtxpkt = 1;
1688 cmd->maxrxpkt = 1;
1689 return phy_ethtool_gset(pdata->phy_dev, cmd);
1690}
1691
1692static int
1693smsc911x_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1694{
1695 struct smsc911x_data *pdata = netdev_priv(dev);
1696
1697 return phy_ethtool_sset(pdata->phy_dev, cmd);
1698}
1699
1700static void smsc911x_ethtool_getdrvinfo(struct net_device *dev,
1701 struct ethtool_drvinfo *info)
1702{
1703 strlcpy(info->driver, SMSC_CHIPNAME, sizeof(info->driver));
1704 strlcpy(info->version, SMSC_DRV_VERSION, sizeof(info->version));
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08001705 strlcpy(info->bus_info, dev_name(dev->dev.parent),
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001706 sizeof(info->bus_info));
1707}
1708
1709static int smsc911x_ethtool_nwayreset(struct net_device *dev)
1710{
1711 struct smsc911x_data *pdata = netdev_priv(dev);
1712
1713 return phy_start_aneg(pdata->phy_dev);
1714}
1715
1716static u32 smsc911x_ethtool_getmsglevel(struct net_device *dev)
1717{
1718 struct smsc911x_data *pdata = netdev_priv(dev);
1719 return pdata->msg_enable;
1720}
1721
1722static void smsc911x_ethtool_setmsglevel(struct net_device *dev, u32 level)
1723{
1724 struct smsc911x_data *pdata = netdev_priv(dev);
1725 pdata->msg_enable = level;
1726}
1727
1728static int smsc911x_ethtool_getregslen(struct net_device *dev)
1729{
1730 return (((E2P_DATA - ID_REV) / 4 + 1) + (WUCSR - MAC_CR) + 1 + 32) *
1731 sizeof(u32);
1732}
1733
1734static void
1735smsc911x_ethtool_getregs(struct net_device *dev, struct ethtool_regs *regs,
1736 void *buf)
1737{
1738 struct smsc911x_data *pdata = netdev_priv(dev);
1739 struct phy_device *phy_dev = pdata->phy_dev;
1740 unsigned long flags;
1741 unsigned int i;
1742 unsigned int j = 0;
1743 u32 *data = buf;
1744
1745 regs->version = pdata->idrev;
1746 for (i = ID_REV; i <= E2P_DATA; i += (sizeof(u32)))
1747 data[j++] = smsc911x_reg_read(pdata, i);
1748
1749 for (i = MAC_CR; i <= WUCSR; i++) {
1750 spin_lock_irqsave(&pdata->mac_lock, flags);
1751 data[j++] = smsc911x_mac_read(pdata, i);
1752 spin_unlock_irqrestore(&pdata->mac_lock, flags);
1753 }
1754
1755 for (i = 0; i <= 31; i++)
1756 data[j++] = smsc911x_mii_read(phy_dev->bus, phy_dev->addr, i);
1757}
1758
1759static void smsc911x_eeprom_enable_access(struct smsc911x_data *pdata)
1760{
1761 unsigned int temp = smsc911x_reg_read(pdata, GPIO_CFG);
1762 temp &= ~GPIO_CFG_EEPR_EN_;
1763 smsc911x_reg_write(pdata, GPIO_CFG, temp);
1764 msleep(1);
1765}
1766
1767static int smsc911x_eeprom_send_cmd(struct smsc911x_data *pdata, u32 op)
1768{
1769 int timeout = 100;
1770 u32 e2cmd;
1771
Joe Perchesdffc6b22011-03-25 14:21:22 +00001772 SMSC_TRACE(pdata, drv, "op 0x%08x", op);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001773 if (smsc911x_reg_read(pdata, E2P_CMD) & E2P_CMD_EPC_BUSY_) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001774 SMSC_WARN(pdata, drv, "Busy at start");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001775 return -EBUSY;
1776 }
1777
1778 e2cmd = op | E2P_CMD_EPC_BUSY_;
1779 smsc911x_reg_write(pdata, E2P_CMD, e2cmd);
1780
1781 do {
1782 msleep(1);
1783 e2cmd = smsc911x_reg_read(pdata, E2P_CMD);
Roel Kluin2cf0dbe2009-02-20 00:52:19 -08001784 } while ((e2cmd & E2P_CMD_EPC_BUSY_) && (--timeout));
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001785
1786 if (!timeout) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001787 SMSC_TRACE(pdata, drv, "TIMED OUT");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001788 return -EAGAIN;
1789 }
1790
1791 if (e2cmd & E2P_CMD_EPC_TIMEOUT_) {
David S. Miller1c01a802011-04-11 13:44:25 -07001792 SMSC_TRACE(pdata, drv, "Error occurred during eeprom operation");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001793 return -EINVAL;
1794 }
1795
1796 return 0;
1797}
1798
1799static int smsc911x_eeprom_read_location(struct smsc911x_data *pdata,
1800 u8 address, u8 *data)
1801{
1802 u32 op = E2P_CMD_EPC_CMD_READ_ | address;
1803 int ret;
1804
Joe Perchesdffc6b22011-03-25 14:21:22 +00001805 SMSC_TRACE(pdata, drv, "address 0x%x", address);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001806 ret = smsc911x_eeprom_send_cmd(pdata, op);
1807
1808 if (!ret)
1809 data[address] = smsc911x_reg_read(pdata, E2P_DATA);
1810
1811 return ret;
1812}
1813
1814static int smsc911x_eeprom_write_location(struct smsc911x_data *pdata,
1815 u8 address, u8 data)
1816{
1817 u32 op = E2P_CMD_EPC_CMD_ERASE_ | address;
Steve Glendinning58add9f2009-03-26 07:14:36 +00001818 u32 temp;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001819 int ret;
1820
Joe Perchesdffc6b22011-03-25 14:21:22 +00001821 SMSC_TRACE(pdata, drv, "address 0x%x, data 0x%x", address, data);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001822 ret = smsc911x_eeprom_send_cmd(pdata, op);
1823
1824 if (!ret) {
1825 op = E2P_CMD_EPC_CMD_WRITE_ | address;
1826 smsc911x_reg_write(pdata, E2P_DATA, (u32)data);
Steve Glendinning58add9f2009-03-26 07:14:36 +00001827
1828 /* Workaround for hardware read-after-write restriction */
1829 temp = smsc911x_reg_read(pdata, BYTE_TEST);
1830
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001831 ret = smsc911x_eeprom_send_cmd(pdata, op);
1832 }
1833
1834 return ret;
1835}
1836
1837static int smsc911x_ethtool_get_eeprom_len(struct net_device *dev)
1838{
1839 return SMSC911X_EEPROM_SIZE;
1840}
1841
1842static int smsc911x_ethtool_get_eeprom(struct net_device *dev,
1843 struct ethtool_eeprom *eeprom, u8 *data)
1844{
1845 struct smsc911x_data *pdata = netdev_priv(dev);
1846 u8 eeprom_data[SMSC911X_EEPROM_SIZE];
1847 int len;
1848 int i;
1849
1850 smsc911x_eeprom_enable_access(pdata);
1851
1852 len = min(eeprom->len, SMSC911X_EEPROM_SIZE);
1853 for (i = 0; i < len; i++) {
1854 int ret = smsc911x_eeprom_read_location(pdata, i, eeprom_data);
1855 if (ret < 0) {
1856 eeprom->len = 0;
1857 return ret;
1858 }
1859 }
1860
1861 memcpy(data, &eeprom_data[eeprom->offset], len);
1862 eeprom->len = len;
1863 return 0;
1864}
1865
1866static int smsc911x_ethtool_set_eeprom(struct net_device *dev,
1867 struct ethtool_eeprom *eeprom, u8 *data)
1868{
1869 int ret;
1870 struct smsc911x_data *pdata = netdev_priv(dev);
1871
1872 smsc911x_eeprom_enable_access(pdata);
1873 smsc911x_eeprom_send_cmd(pdata, E2P_CMD_EPC_CMD_EWEN_);
1874 ret = smsc911x_eeprom_write_location(pdata, eeprom->offset, *data);
1875 smsc911x_eeprom_send_cmd(pdata, E2P_CMD_EPC_CMD_EWDS_);
1876
1877 /* Single byte write, according to man page */
1878 eeprom->len = 1;
1879
1880 return ret;
1881}
1882
Steve Glendinningcb5b04f2008-12-25 16:41:09 -08001883static const struct ethtool_ops smsc911x_ethtool_ops = {
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001884 .get_settings = smsc911x_ethtool_getsettings,
1885 .set_settings = smsc911x_ethtool_setsettings,
1886 .get_link = ethtool_op_get_link,
1887 .get_drvinfo = smsc911x_ethtool_getdrvinfo,
1888 .nway_reset = smsc911x_ethtool_nwayreset,
1889 .get_msglevel = smsc911x_ethtool_getmsglevel,
1890 .set_msglevel = smsc911x_ethtool_setmsglevel,
1891 .get_regs_len = smsc911x_ethtool_getregslen,
1892 .get_regs = smsc911x_ethtool_getregs,
1893 .get_eeprom_len = smsc911x_ethtool_get_eeprom_len,
1894 .get_eeprom = smsc911x_ethtool_get_eeprom,
1895 .set_eeprom = smsc911x_ethtool_set_eeprom,
1896};
1897
Steve Glendinning631b7562008-12-25 16:40:47 -08001898static const struct net_device_ops smsc911x_netdev_ops = {
1899 .ndo_open = smsc911x_open,
1900 .ndo_stop = smsc911x_stop,
1901 .ndo_start_xmit = smsc911x_hard_start_xmit,
1902 .ndo_get_stats = smsc911x_get_stats,
1903 .ndo_set_multicast_list = smsc911x_set_multicast_list,
1904 .ndo_do_ioctl = smsc911x_do_ioctl,
Ben Hutchings635ecaa2009-07-09 17:59:01 +00001905 .ndo_change_mtu = eth_change_mtu,
Steve Glendinning631b7562008-12-25 16:40:47 -08001906 .ndo_validate_addr = eth_validate_addr,
Steve Glendinning225ddf42009-03-19 00:24:46 +00001907 .ndo_set_mac_address = smsc911x_set_mac_address,
Steve Glendinning631b7562008-12-25 16:40:47 -08001908#ifdef CONFIG_NET_POLL_CONTROLLER
1909 .ndo_poll_controller = smsc911x_poll_controller,
1910#endif
1911};
1912
Steve Glendinning31f45742009-01-27 06:51:12 +00001913/* copies the current mac address from hardware to dev->dev_addr */
1914static void __devinit smsc911x_read_mac_address(struct net_device *dev)
1915{
1916 struct smsc911x_data *pdata = netdev_priv(dev);
1917 u32 mac_high16 = smsc911x_mac_read(pdata, ADDRH);
1918 u32 mac_low32 = smsc911x_mac_read(pdata, ADDRL);
1919
1920 dev->dev_addr[0] = (u8)(mac_low32);
1921 dev->dev_addr[1] = (u8)(mac_low32 >> 8);
1922 dev->dev_addr[2] = (u8)(mac_low32 >> 16);
1923 dev->dev_addr[3] = (u8)(mac_low32 >> 24);
1924 dev->dev_addr[4] = (u8)(mac_high16);
1925 dev->dev_addr[5] = (u8)(mac_high16 >> 8);
1926}
1927
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001928/* Initializing private device structures, only called from probe */
1929static int __devinit smsc911x_init(struct net_device *dev)
1930{
1931 struct smsc911x_data *pdata = netdev_priv(dev);
1932 unsigned int byte_test;
1933
Joe Perchesdffc6b22011-03-25 14:21:22 +00001934 SMSC_TRACE(pdata, probe, "Driver Parameters:");
1935 SMSC_TRACE(pdata, probe, "LAN base: 0x%08lX",
1936 (unsigned long)pdata->ioaddr);
1937 SMSC_TRACE(pdata, probe, "IRQ: %d", dev->irq);
1938 SMSC_TRACE(pdata, probe, "PHY will be autodetected.");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001939
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001940 spin_lock_init(&pdata->dev_lock);
Enric Balletbo i Serra35a67ed2011-04-05 06:52:49 +00001941 spin_lock_init(&pdata->mac_lock);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001942
1943 if (pdata->ioaddr == 0) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001944 SMSC_WARN(pdata, probe, "pdata->ioaddr: 0x00000000");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001945 return -ENODEV;
1946 }
1947
1948 /* Check byte ordering */
1949 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
Joe Perchesdffc6b22011-03-25 14:21:22 +00001950 SMSC_TRACE(pdata, probe, "BYTE_TEST: 0x%08X", byte_test);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001951 if (byte_test == 0x43218765) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001952 SMSC_TRACE(pdata, probe, "BYTE_TEST looks swapped, "
1953 "applying WORD_SWAP");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001954 smsc911x_reg_write(pdata, WORD_SWAP, 0xffffffff);
1955
1956 /* 1 dummy read of BYTE_TEST is needed after a write to
1957 * WORD_SWAP before its contents are valid */
1958 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1959
1960 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1961 }
1962
1963 if (byte_test != 0x87654321) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001964 SMSC_WARN(pdata, drv, "BYTE_TEST: 0x%08X", byte_test);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001965 if (((byte_test >> 16) & 0xFFFF) == (byte_test & 0xFFFF)) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00001966 SMSC_WARN(pdata, probe,
1967 "top 16 bits equal to bottom 16 bits");
1968 SMSC_TRACE(pdata, probe,
1969 "This may mean the chip is set "
1970 "for 32 bit while the bus is reading 16 bit");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00001971 }
1972 return -ENODEV;
1973 }
1974
1975 /* Default generation to zero (all workarounds apply) */
1976 pdata->generation = 0;
1977
1978 pdata->idrev = smsc911x_reg_read(pdata, ID_REV);
1979 switch (pdata->idrev & 0xFFFF0000) {
1980 case 0x01180000:
1981 case 0x01170000:
1982 case 0x01160000:
1983 case 0x01150000:
1984 /* LAN911[5678] family */
1985 pdata->generation = pdata->idrev & 0x0000FFFF;
1986 break;
1987
1988 case 0x118A0000:
1989 case 0x117A0000:
1990 case 0x116A0000:
1991 case 0x115A0000:
1992 /* LAN921[5678] family */
1993 pdata->generation = 3;
1994 break;
1995
1996 case 0x92100000:
1997 case 0x92110000:
1998 case 0x92200000:
1999 case 0x92210000:
2000 /* LAN9210/LAN9211/LAN9220/LAN9221 */
2001 pdata->generation = 4;
2002 break;
2003
2004 default:
Joe Perchesdffc6b22011-03-25 14:21:22 +00002005 SMSC_WARN(pdata, probe, "LAN911x not identified, idrev: 0x%08X",
2006 pdata->idrev);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002007 return -ENODEV;
2008 }
2009
Joe Perchesdffc6b22011-03-25 14:21:22 +00002010 SMSC_TRACE(pdata, probe,
2011 "LAN911x identified, idrev: 0x%08X, generation: %d",
2012 pdata->idrev, pdata->generation);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002013
2014 if (pdata->generation == 0)
Joe Perchesdffc6b22011-03-25 14:21:22 +00002015 SMSC_WARN(pdata, probe,
2016 "This driver is not intended for this chip revision");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002017
Steve Glendinning31f45742009-01-27 06:51:12 +00002018 /* workaround for platforms without an eeprom, where the mac address
2019 * is stored elsewhere and set by the bootloader. This saves the
2020 * mac address before resetting the device */
Enric Balletbo i Serra35a67ed2011-04-05 06:52:49 +00002021 if (pdata->config.flags & SMSC911X_SAVE_MAC_ADDRESS) {
2022 spin_lock_irq(&pdata->mac_lock);
Steve Glendinning31f45742009-01-27 06:51:12 +00002023 smsc911x_read_mac_address(dev);
Enric Balletbo i Serra35a67ed2011-04-05 06:52:49 +00002024 spin_unlock_irq(&pdata->mac_lock);
2025 }
Steve Glendinning31f45742009-01-27 06:51:12 +00002026
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002027 /* Reset the LAN911x */
2028 if (smsc911x_soft_reset(pdata))
2029 return -ENODEV;
2030
2031 /* Disable all interrupt sources until we bring the device up */
2032 smsc911x_reg_write(pdata, INT_EN, 0);
2033
2034 ether_setup(dev);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002035 dev->flags |= IFF_MULTICAST;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002036 netif_napi_add(dev, &pdata->napi, smsc911x_poll, SMSC_NAPI_WEIGHT);
Steve Glendinning631b7562008-12-25 16:40:47 -08002037 dev->netdev_ops = &smsc911x_netdev_ops;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002038 dev->ethtool_ops = &smsc911x_ethtool_ops;
2039
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002040 return 0;
2041}
2042
2043static int __devexit smsc911x_drv_remove(struct platform_device *pdev)
2044{
2045 struct net_device *dev;
2046 struct smsc911x_data *pdata;
2047 struct resource *res;
2048
2049 dev = platform_get_drvdata(pdev);
2050 BUG_ON(!dev);
2051 pdata = netdev_priv(dev);
2052 BUG_ON(!pdata);
2053 BUG_ON(!pdata->ioaddr);
2054 BUG_ON(!pdata->phy_dev);
2055
Joe Perchesdffc6b22011-03-25 14:21:22 +00002056 SMSC_TRACE(pdata, ifdown, "Stopping driver");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002057
2058 phy_disconnect(pdata->phy_dev);
2059 pdata->phy_dev = NULL;
2060 mdiobus_unregister(pdata->mii_bus);
2061 mdiobus_free(pdata->mii_bus);
2062
2063 platform_set_drvdata(pdev, NULL);
2064 unregister_netdev(dev);
2065 free_irq(dev->irq, dev);
2066 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2067 "smsc911x-memory");
2068 if (!res)
Steve Glendinningd4522732008-12-25 16:44:01 -08002069 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002070
Julia Lawall39424532009-07-04 11:31:47 +00002071 release_mem_region(res->start, resource_size(res));
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002072
2073 iounmap(pdata->ioaddr);
2074
2075 free_netdev(dev);
2076
2077 return 0;
2078}
2079
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -07002080/* standard register acces */
2081static const struct smsc911x_ops standard_smsc911x_ops = {
2082 .reg_read = __smsc911x_reg_read,
2083 .reg_write = __smsc911x_reg_write,
2084 .rx_readfifo = smsc911x_rx_readfifo,
2085 .tx_writefifo = smsc911x_tx_writefifo,
2086};
2087
2088/* shifted register access */
2089static const struct smsc911x_ops shifted_smsc911x_ops = {
2090 .reg_read = __smsc911x_reg_read_shift,
2091 .reg_write = __smsc911x_reg_write_shift,
2092 .rx_readfifo = smsc911x_rx_readfifo_shift,
2093 .tx_writefifo = smsc911x_tx_writefifo_shift,
2094};
2095
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002096static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
2097{
2098 struct net_device *dev;
2099 struct smsc911x_data *pdata;
Steve Glendinning2107fb82008-11-05 00:35:38 +00002100 struct smsc911x_platform_config *config = pdev->dev.platform_data;
Steve Glendinning61307ed2009-01-27 06:51:09 +00002101 struct resource *res, *irq_res;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002102 unsigned int intcfg = 0;
Steve Glendinning61307ed2009-01-27 06:51:09 +00002103 int res_size, irq_flags;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002104 int retval;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002105
Joe Perchesdffc6b22011-03-25 14:21:22 +00002106 pr_info("Driver version %s\n", SMSC_DRV_VERSION);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002107
Steve Glendinning2107fb82008-11-05 00:35:38 +00002108 /* platform data specifies irq & dynamic bus configuration */
2109 if (!pdev->dev.platform_data) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002110 pr_warn("platform_data not provided\n");
Steve Glendinning2107fb82008-11-05 00:35:38 +00002111 retval = -ENODEV;
2112 goto out_0;
2113 }
2114
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002115 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
2116 "smsc911x-memory");
2117 if (!res)
2118 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2119 if (!res) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002120 pr_warn("Could not allocate resource\n");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002121 retval = -ENODEV;
2122 goto out_0;
2123 }
Julia Lawall39424532009-07-04 11:31:47 +00002124 res_size = resource_size(res);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002125
Steve Glendinning61307ed2009-01-27 06:51:09 +00002126 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2127 if (!irq_res) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002128 pr_warn("Could not allocate irq resource\n");
Steve Glendinning61307ed2009-01-27 06:51:09 +00002129 retval = -ENODEV;
2130 goto out_0;
2131 }
2132
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002133 if (!request_mem_region(res->start, res_size, SMSC_CHIPNAME)) {
2134 retval = -EBUSY;
2135 goto out_0;
2136 }
2137
2138 dev = alloc_etherdev(sizeof(struct smsc911x_data));
2139 if (!dev) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002140 pr_warn("Could not allocate device\n");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002141 retval = -ENOMEM;
2142 goto out_release_io_1;
2143 }
2144
2145 SET_NETDEV_DEV(dev, &pdev->dev);
2146
2147 pdata = netdev_priv(dev);
2148
Steve Glendinning61307ed2009-01-27 06:51:09 +00002149 dev->irq = irq_res->start;
2150 irq_flags = irq_res->flags & IRQF_TRIGGER_MASK;
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002151 pdata->ioaddr = ioremap_nocache(res->start, res_size);
2152
Steve Glendinning2107fb82008-11-05 00:35:38 +00002153 /* copy config parameters across to pdata */
2154 memcpy(&pdata->config, config, sizeof(pdata->config));
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002155
2156 pdata->dev = dev;
2157 pdata->msg_enable = ((1 << debug) - 1);
2158
2159 if (pdata->ioaddr == NULL) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002160 SMSC_WARN(pdata, probe, "Error smsc911x base address invalid");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002161 retval = -ENOMEM;
2162 goto out_free_netdev_2;
2163 }
2164
Mathieu J. Poirierc326de88b2011-04-13 17:13:00 -07002165 /* assume standard, non-shifted, access to HW registers */
2166 pdata->ops = &standard_smsc911x_ops;
2167 /* apply the right access if shifting is needed */
2168 if (config->shift)
2169 pdata->ops = &shifted_smsc911x_ops;
2170
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002171 retval = smsc911x_init(dev);
2172 if (retval < 0)
2173 goto out_unmap_io_3;
2174
2175 /* configure irq polarity and type before connecting isr */
Steve Glendinning2107fb82008-11-05 00:35:38 +00002176 if (pdata->config.irq_polarity == SMSC911X_IRQ_POLARITY_ACTIVE_HIGH)
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002177 intcfg |= INT_CFG_IRQ_POL_;
2178
Steve Glendinning2107fb82008-11-05 00:35:38 +00002179 if (pdata->config.irq_type == SMSC911X_IRQ_TYPE_PUSH_PULL)
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002180 intcfg |= INT_CFG_IRQ_TYPE_;
2181
2182 smsc911x_reg_write(pdata, INT_CFG, intcfg);
2183
2184 /* Ensure interrupts are globally disabled before connecting ISR */
2185 smsc911x_reg_write(pdata, INT_EN, 0);
2186 smsc911x_reg_write(pdata, INT_STS, 0xFFFFFFFF);
2187
Steve Glendinning61307ed2009-01-27 06:51:09 +00002188 retval = request_irq(dev->irq, smsc911x_irqhandler,
Steve Glendinninge81259b2009-01-27 06:51:10 +00002189 irq_flags | IRQF_SHARED, dev->name, dev);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002190 if (retval) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002191 SMSC_WARN(pdata, probe,
2192 "Unable to claim requested irq: %d", dev->irq);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002193 goto out_unmap_io_3;
2194 }
2195
2196 platform_set_drvdata(pdev, dev);
2197
2198 retval = register_netdev(dev);
2199 if (retval) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002200 SMSC_WARN(pdata, probe, "Error %i registering device", retval);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002201 goto out_unset_drvdata_4;
2202 } else {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002203 SMSC_TRACE(pdata, probe,
2204 "Network interface: \"%s\"", dev->name);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002205 }
2206
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002207 retval = smsc911x_mii_init(pdev, dev);
2208 if (retval) {
Joe Perchesdffc6b22011-03-25 14:21:22 +00002209 SMSC_WARN(pdata, probe, "Error %i initialising mii", retval);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002210 goto out_unregister_netdev_5;
2211 }
2212
2213 spin_lock_irq(&pdata->mac_lock);
2214
2215 /* Check if mac address has been specified when bringing interface up */
2216 if (is_valid_ether_addr(dev->dev_addr)) {
Steve Glendinning225ddf42009-03-19 00:24:46 +00002217 smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
Joe Perchesdffc6b22011-03-25 14:21:22 +00002218 SMSC_TRACE(pdata, probe,
2219 "MAC Address is specified by configuration");
Manuel Laussaace4952009-10-13 07:25:49 +00002220 } else if (is_valid_ether_addr(pdata->config.mac)) {
2221 memcpy(dev->dev_addr, pdata->config.mac, 6);
Joe Perchesdffc6b22011-03-25 14:21:22 +00002222 SMSC_TRACE(pdata, probe,
2223 "MAC Address specified by platform data");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002224 } else {
2225 /* Try reading mac address from device. if EEPROM is present
2226 * it will already have been set */
Akira Takeuchi62747cd2010-10-27 17:28:58 +01002227 smsc_get_mac(dev);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002228
2229 if (is_valid_ether_addr(dev->dev_addr)) {
2230 /* eeprom values are valid so use them */
Joe Perchesdffc6b22011-03-25 14:21:22 +00002231 SMSC_TRACE(pdata, probe,
2232 "Mac Address is read from LAN911x EEPROM");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002233 } else {
2234 /* eeprom values are invalid, generate random MAC */
2235 random_ether_addr(dev->dev_addr);
Steve Glendinning225ddf42009-03-19 00:24:46 +00002236 smsc911x_set_hw_mac_address(pdata, dev->dev_addr);
Joe Perchesdffc6b22011-03-25 14:21:22 +00002237 SMSC_TRACE(pdata, probe,
2238 "MAC Address is set to random_ether_addr");
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002239 }
2240 }
2241
2242 spin_unlock_irq(&pdata->mac_lock);
2243
Joe Perchesdffc6b22011-03-25 14:21:22 +00002244 netdev_info(dev, "MAC Address: %pM\n", dev->dev_addr);
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002245
2246 return 0;
2247
2248out_unregister_netdev_5:
2249 unregister_netdev(dev);
2250out_unset_drvdata_4:
2251 platform_set_drvdata(pdev, NULL);
2252 free_irq(dev->irq, dev);
2253out_unmap_io_3:
2254 iounmap(pdata->ioaddr);
2255out_free_netdev_2:
2256 free_netdev(dev);
2257out_release_io_1:
Julia Lawall39424532009-07-04 11:31:47 +00002258 release_mem_region(res->start, resource_size(res));
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002259out_0:
2260 return retval;
2261}
2262
Daniel Mackb6907b02009-05-05 12:22:53 -07002263#ifdef CONFIG_PM
2264/* This implementation assumes the devices remains powered on its VDDVARIO
2265 * pins during suspend. */
2266
Daniel Mack6cb87822009-08-05 08:29:31 +00002267/* TODO: implement freeze/thaw callbacks for hibernation.*/
2268
2269static int smsc911x_suspend(struct device *dev)
Daniel Mackb6907b02009-05-05 12:22:53 -07002270{
Daniel Mack6cb87822009-08-05 08:29:31 +00002271 struct net_device *ndev = dev_get_drvdata(dev);
2272 struct smsc911x_data *pdata = netdev_priv(ndev);
Daniel Mackb6907b02009-05-05 12:22:53 -07002273
2274 /* enable wake on LAN, energy detection and the external PME
2275 * signal. */
2276 smsc911x_reg_write(pdata, PMT_CTRL,
2277 PMT_CTRL_PM_MODE_D1_ | PMT_CTRL_WOL_EN_ |
2278 PMT_CTRL_ED_EN_ | PMT_CTRL_PME_EN_);
2279
2280 return 0;
2281}
2282
Daniel Mack6cb87822009-08-05 08:29:31 +00002283static int smsc911x_resume(struct device *dev)
Daniel Mackb6907b02009-05-05 12:22:53 -07002284{
Daniel Mack6cb87822009-08-05 08:29:31 +00002285 struct net_device *ndev = dev_get_drvdata(dev);
2286 struct smsc911x_data *pdata = netdev_priv(ndev);
Daniel Mackb6907b02009-05-05 12:22:53 -07002287 unsigned int to = 100;
2288
2289 /* Note 3.11 from the datasheet:
2290 * "When the LAN9220 is in a power saving state, a write of any
2291 * data to the BYTE_TEST register will wake-up the device."
2292 */
2293 smsc911x_reg_write(pdata, BYTE_TEST, 0);
2294
2295 /* poll the READY bit in PMT_CTRL. Any other access to the device is
2296 * forbidden while this bit isn't set. Try for 100ms and return -EIO
2297 * if it failed. */
2298 while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && --to)
2299 udelay(1000);
2300
2301 return (to == 0) ? -EIO : 0;
2302}
2303
Alexey Dobriyan47145212009-12-14 18:00:08 -08002304static const struct dev_pm_ops smsc911x_pm_ops = {
Daniel Mack6cb87822009-08-05 08:29:31 +00002305 .suspend = smsc911x_suspend,
2306 .resume = smsc911x_resume,
2307};
2308
2309#define SMSC911X_PM_OPS (&smsc911x_pm_ops)
2310
Daniel Mackb6907b02009-05-05 12:22:53 -07002311#else
Daniel Mack6cb87822009-08-05 08:29:31 +00002312#define SMSC911X_PM_OPS NULL
Daniel Mackb6907b02009-05-05 12:22:53 -07002313#endif
2314
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002315static struct platform_driver smsc911x_driver = {
2316 .probe = smsc911x_drv_probe,
Mike Frysingerdf911e2d2009-06-05 14:37:20 +00002317 .remove = __devexit_p(smsc911x_drv_remove),
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002318 .driver = {
Daniel Mack6cb87822009-08-05 08:29:31 +00002319 .name = SMSC_CHIPNAME,
2320 .owner = THIS_MODULE,
2321 .pm = SMSC911X_PM_OPS,
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002322 },
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002323};
2324
2325/* Entry point for loading the module */
2326static int __init smsc911x_init_module(void)
2327{
Akira Takeuchi62747cd2010-10-27 17:28:58 +01002328 SMSC_INITIALIZE();
Steve Glendinningfd9abb32008-11-05 00:35:37 +00002329 return platform_driver_register(&smsc911x_driver);
2330}
2331
2332/* entry point for unloading the module */
2333static void __exit smsc911x_cleanup_module(void)
2334{
2335 platform_driver_unregister(&smsc911x_driver);
2336}
2337
2338module_init(smsc911x_init_module);
2339module_exit(smsc911x_cleanup_module);