1 /***************************************************************************
3 * Copyright (C) 2004-2008 SMSC
4 * Copyright (C) 2005-2008 ARM
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.
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.
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.
20 ***************************************************************************
21 * Rewritten, heavily based on smsc911x simple driver by SMSC.
22 * Partly uses io macros from smc91x.c by Nicolas Pitre
25 * LAN9115, LAN9116, LAN9117, LAN9118
26 * LAN9215, LAN9216, LAN9217, LAN9218
32 #include <linux/crc32.h>
33 #include <linux/delay.h>
34 #include <linux/errno.h>
35 #include <linux/etherdevice.h>
36 #include <linux/ethtool.h>
37 #include <linux/init.h>
38 #include <linux/ioport.h>
39 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/netdevice.h>
42 #include <linux/platform_device.h>
43 #include <linux/sched.h>
44 #include <linux/slab.h>
45 #include <linux/timer.h>
46 #include <linux/bug.h>
47 #include <linux/bitops.h>
48 #include <linux/irq.h>
50 #include <linux/swab.h>
51 #include <linux/phy.h>
52 #include <linux/smsc911x.h>
53 #include <linux/device.h>
56 #define SMSC_CHIPNAME "smsc911x"
57 #define SMSC_MDIONAME "smsc911x-mdio"
58 #define SMSC_DRV_VERSION "2008-10-21"
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(SMSC_DRV_VERSION
);
64 static int debug
= 16;
69 module_param(debug
, int, 0);
70 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
72 struct smsc911x_data
{
77 /* used to decide which workarounds apply */
78 unsigned int generation
;
80 /* device configuration (copied from platform_data during probe) */
81 struct smsc911x_platform_config config
;
83 /* This needs to be acquired before calling any of below:
84 * smsc911x_mac_read(), smsc911x_mac_write()
88 /* spinlock to ensure 16-bit accesses are serialised.
89 * unused with a 32-bit bus */
92 struct phy_device
*phy_dev
;
93 struct mii_bus
*mii_bus
;
94 int phy_irq
[PHY_MAX_ADDR
];
95 unsigned int using_extphy
;
100 unsigned int gpio_setting
;
101 unsigned int gpio_orig_setting
;
102 struct net_device
*dev
;
103 struct napi_struct napi
;
105 unsigned int software_irq_signal
;
107 #ifdef USE_PHY_WORK_AROUND
108 #define MIN_PACKET_SIZE (64)
109 char loopback_tx_pkt
[MIN_PACKET_SIZE
];
110 char loopback_rx_pkt
[MIN_PACKET_SIZE
];
111 unsigned int resetcount
;
114 /* Members for Multicast filter workaround */
115 unsigned int multicast_update_pending
;
116 unsigned int set_bits_mask
;
117 unsigned int clear_bits_mask
;
122 /* The 16-bit access functions are significantly slower, due to the locking
123 * necessary. If your bus hardware can be configured to do this for you
124 * (in response to a single 32-bit operation from software), you should use
125 * the 32-bit access functions instead. */
127 static inline u32
smsc911x_reg_read(struct smsc911x_data
*pdata
, u32 reg
)
129 if (pdata
->config
.flags
& SMSC911X_USE_32BIT
)
130 return readl(pdata
->ioaddr
+ reg
);
132 if (pdata
->config
.flags
& SMSC911X_USE_16BIT
) {
136 /* these two 16-bit reads must be performed consecutively, so
137 * must not be interrupted by our own ISR (which would start
138 * another read operation) */
139 spin_lock_irqsave(&pdata
->dev_lock
, flags
);
140 data
= ((readw(pdata
->ioaddr
+ reg
) & 0xFFFF) |
141 ((readw(pdata
->ioaddr
+ reg
+ 2) & 0xFFFF) << 16));
142 spin_unlock_irqrestore(&pdata
->dev_lock
, flags
);
151 static inline void smsc911x_reg_write(struct smsc911x_data
*pdata
, u32 reg
,
154 if (pdata
->config
.flags
& SMSC911X_USE_32BIT
) {
155 writel(val
, pdata
->ioaddr
+ reg
);
159 if (pdata
->config
.flags
& SMSC911X_USE_16BIT
) {
162 /* these two 16-bit writes must be performed consecutively, so
163 * must not be interrupted by our own ISR (which would start
164 * another read operation) */
165 spin_lock_irqsave(&pdata
->dev_lock
, flags
);
166 writew(val
& 0xFFFF, pdata
->ioaddr
+ reg
);
167 writew((val
>> 16) & 0xFFFF, pdata
->ioaddr
+ reg
+ 2);
168 spin_unlock_irqrestore(&pdata
->dev_lock
, flags
);
175 /* Writes a packet to the TX_DATA_FIFO */
177 smsc911x_tx_writefifo(struct smsc911x_data
*pdata
, unsigned int *buf
,
178 unsigned int wordcount
)
180 if (pdata
->config
.flags
& SMSC911X_SWAP_FIFO
) {
182 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, swab32(*buf
++));
186 if (pdata
->config
.flags
& SMSC911X_USE_32BIT
) {
187 writesl(pdata
->ioaddr
+ TX_DATA_FIFO
, buf
, wordcount
);
191 if (pdata
->config
.flags
& SMSC911X_USE_16BIT
) {
193 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, *buf
++);
200 /* Reads a packet out of the RX_DATA_FIFO */
202 smsc911x_rx_readfifo(struct smsc911x_data
*pdata
, unsigned int *buf
,
203 unsigned int wordcount
)
205 if (pdata
->config
.flags
& SMSC911X_SWAP_FIFO
) {
207 *buf
++ = swab32(smsc911x_reg_read(pdata
, RX_DATA_FIFO
));
211 if (pdata
->config
.flags
& SMSC911X_USE_32BIT
) {
212 readsl(pdata
->ioaddr
+ RX_DATA_FIFO
, buf
, wordcount
);
216 if (pdata
->config
.flags
& SMSC911X_USE_16BIT
) {
218 *buf
++ = smsc911x_reg_read(pdata
, RX_DATA_FIFO
);
225 /* waits for MAC not busy, with timeout. Only called by smsc911x_mac_read
226 * and smsc911x_mac_write, so assumes mac_lock is held */
227 static int smsc911x_mac_complete(struct smsc911x_data
*pdata
)
232 SMSC_ASSERT_MAC_LOCK(pdata
);
234 for (i
= 0; i
< 40; i
++) {
235 val
= smsc911x_reg_read(pdata
, MAC_CSR_CMD
);
236 if (!(val
& MAC_CSR_CMD_CSR_BUSY_
))
239 SMSC_WARNING(HW
, "Timed out waiting for MAC not BUSY. "
240 "MAC_CSR_CMD: 0x%08X", val
);
244 /* Fetches a MAC register value. Assumes mac_lock is acquired */
245 static u32
smsc911x_mac_read(struct smsc911x_data
*pdata
, unsigned int offset
)
249 SMSC_ASSERT_MAC_LOCK(pdata
);
251 temp
= smsc911x_reg_read(pdata
, MAC_CSR_CMD
);
252 if (unlikely(temp
& MAC_CSR_CMD_CSR_BUSY_
)) {
253 SMSC_WARNING(HW
, "MAC busy at entry");
257 /* Send the MAC cmd */
258 smsc911x_reg_write(pdata
, MAC_CSR_CMD
, ((offset
& 0xFF) |
259 MAC_CSR_CMD_CSR_BUSY_
| MAC_CSR_CMD_R_NOT_W_
));
261 /* Workaround for hardware read-after-write restriction */
262 temp
= smsc911x_reg_read(pdata
, BYTE_TEST
);
264 /* Wait for the read to complete */
265 if (likely(smsc911x_mac_complete(pdata
) == 0))
266 return smsc911x_reg_read(pdata
, MAC_CSR_DATA
);
268 SMSC_WARNING(HW
, "MAC busy after read");
272 /* Set a mac register, mac_lock must be acquired before calling */
273 static void smsc911x_mac_write(struct smsc911x_data
*pdata
,
274 unsigned int offset
, u32 val
)
278 SMSC_ASSERT_MAC_LOCK(pdata
);
280 temp
= smsc911x_reg_read(pdata
, MAC_CSR_CMD
);
281 if (unlikely(temp
& MAC_CSR_CMD_CSR_BUSY_
)) {
283 "smsc911x_mac_write failed, MAC busy at entry");
287 /* Send data to write */
288 smsc911x_reg_write(pdata
, MAC_CSR_DATA
, val
);
290 /* Write the actual data */
291 smsc911x_reg_write(pdata
, MAC_CSR_CMD
, ((offset
& 0xFF) |
292 MAC_CSR_CMD_CSR_BUSY_
));
294 /* Workaround for hardware read-after-write restriction */
295 temp
= smsc911x_reg_read(pdata
, BYTE_TEST
);
297 /* Wait for the write to complete */
298 if (likely(smsc911x_mac_complete(pdata
) == 0))
302 "smsc911x_mac_write failed, MAC busy after write");
305 /* Get a phy register */
306 static int smsc911x_mii_read(struct mii_bus
*bus
, int phyaddr
, int regidx
)
308 struct smsc911x_data
*pdata
= (struct smsc911x_data
*)bus
->priv
;
313 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
315 /* Confirm MII not busy */
316 if (unlikely(smsc911x_mac_read(pdata
, MII_ACC
) & MII_ACC_MII_BUSY_
)) {
318 "MII is busy in smsc911x_mii_read???");
323 /* Set the address, index & direction (read from PHY) */
324 addr
= ((phyaddr
& 0x1F) << 11) | ((regidx
& 0x1F) << 6);
325 smsc911x_mac_write(pdata
, MII_ACC
, addr
);
327 /* Wait for read to complete w/ timeout */
328 for (i
= 0; i
< 100; i
++)
329 if (!(smsc911x_mac_read(pdata
, MII_ACC
) & MII_ACC_MII_BUSY_
)) {
330 reg
= smsc911x_mac_read(pdata
, MII_DATA
);
334 SMSC_WARNING(HW
, "Timed out waiting for MII read to finish");
338 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
342 /* Set a phy register */
343 static int smsc911x_mii_write(struct mii_bus
*bus
, int phyaddr
, int regidx
,
346 struct smsc911x_data
*pdata
= (struct smsc911x_data
*)bus
->priv
;
351 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
353 /* Confirm MII not busy */
354 if (unlikely(smsc911x_mac_read(pdata
, MII_ACC
) & MII_ACC_MII_BUSY_
)) {
356 "MII is busy in smsc911x_mii_write???");
361 /* Put the data to write in the MAC */
362 smsc911x_mac_write(pdata
, MII_DATA
, val
);
364 /* Set the address, index & direction (write to PHY) */
365 addr
= ((phyaddr
& 0x1F) << 11) | ((regidx
& 0x1F) << 6) |
367 smsc911x_mac_write(pdata
, MII_ACC
, addr
);
369 /* Wait for write to complete w/ timeout */
370 for (i
= 0; i
< 100; i
++)
371 if (!(smsc911x_mac_read(pdata
, MII_ACC
) & MII_ACC_MII_BUSY_
)) {
376 SMSC_WARNING(HW
, "Timed out waiting for MII write to finish");
380 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
384 /* Switch to external phy. Assumes tx and rx are stopped. */
385 static void smsc911x_phy_enable_external(struct smsc911x_data
*pdata
)
387 unsigned int hwcfg
= smsc911x_reg_read(pdata
, HW_CFG
);
389 /* Disable phy clocks to the MAC */
390 hwcfg
&= (~HW_CFG_PHY_CLK_SEL_
);
391 hwcfg
|= HW_CFG_PHY_CLK_SEL_CLK_DIS_
;
392 smsc911x_reg_write(pdata
, HW_CFG
, hwcfg
);
393 udelay(10); /* Enough time for clocks to stop */
395 /* Switch to external phy */
396 hwcfg
|= HW_CFG_EXT_PHY_EN_
;
397 smsc911x_reg_write(pdata
, HW_CFG
, hwcfg
);
399 /* Enable phy clocks to the MAC */
400 hwcfg
&= (~HW_CFG_PHY_CLK_SEL_
);
401 hwcfg
|= HW_CFG_PHY_CLK_SEL_EXT_PHY_
;
402 smsc911x_reg_write(pdata
, HW_CFG
, hwcfg
);
403 udelay(10); /* Enough time for clocks to restart */
405 hwcfg
|= HW_CFG_SMI_SEL_
;
406 smsc911x_reg_write(pdata
, HW_CFG
, hwcfg
);
409 /* Autodetects and enables external phy if present on supported chips.
410 * autodetection can be overridden by specifying SMSC911X_FORCE_INTERNAL_PHY
411 * or SMSC911X_FORCE_EXTERNAL_PHY in the platform_data flags. */
412 static void smsc911x_phy_initialise_external(struct smsc911x_data
*pdata
)
414 unsigned int hwcfg
= smsc911x_reg_read(pdata
, HW_CFG
);
416 if (pdata
->config
.flags
& SMSC911X_FORCE_INTERNAL_PHY
) {
417 SMSC_TRACE(HW
, "Forcing internal PHY");
418 pdata
->using_extphy
= 0;
419 } else if (pdata
->config
.flags
& SMSC911X_FORCE_EXTERNAL_PHY
) {
420 SMSC_TRACE(HW
, "Forcing external PHY");
421 smsc911x_phy_enable_external(pdata
);
422 pdata
->using_extphy
= 1;
423 } else if (hwcfg
& HW_CFG_EXT_PHY_DET_
) {
424 SMSC_TRACE(HW
, "HW_CFG EXT_PHY_DET set, using external PHY");
425 smsc911x_phy_enable_external(pdata
);
426 pdata
->using_extphy
= 1;
428 SMSC_TRACE(HW
, "HW_CFG EXT_PHY_DET clear, using internal PHY");
429 pdata
->using_extphy
= 0;
433 /* Fetches a tx status out of the status fifo */
434 static unsigned int smsc911x_tx_get_txstatus(struct smsc911x_data
*pdata
)
436 unsigned int result
=
437 smsc911x_reg_read(pdata
, TX_FIFO_INF
) & TX_FIFO_INF_TSUSED_
;
440 result
= smsc911x_reg_read(pdata
, TX_STATUS_FIFO
);
445 /* Fetches the next rx status */
446 static unsigned int smsc911x_rx_get_rxstatus(struct smsc911x_data
*pdata
)
448 unsigned int result
=
449 smsc911x_reg_read(pdata
, RX_FIFO_INF
) & RX_FIFO_INF_RXSUSED_
;
452 result
= smsc911x_reg_read(pdata
, RX_STATUS_FIFO
);
457 #ifdef USE_PHY_WORK_AROUND
458 static int smsc911x_phy_check_loopbackpkt(struct smsc911x_data
*pdata
)
465 for (tries
= 0; tries
< 10; tries
++) {
466 unsigned int txcmd_a
;
467 unsigned int txcmd_b
;
469 unsigned int pktlength
;
472 /* Zero-out rx packet memory */
473 memset(pdata
->loopback_rx_pkt
, 0, MIN_PACKET_SIZE
);
475 /* Write tx packet to 118 */
476 txcmd_a
= (u32
)((ulong
)pdata
->loopback_tx_pkt
& 0x03) << 16;
477 txcmd_a
|= TX_CMD_A_FIRST_SEG_
| TX_CMD_A_LAST_SEG_
;
478 txcmd_a
|= MIN_PACKET_SIZE
;
480 txcmd_b
= MIN_PACKET_SIZE
<< 16 | MIN_PACKET_SIZE
;
482 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, txcmd_a
);
483 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, txcmd_b
);
485 bufp
= (ulong
)pdata
->loopback_tx_pkt
& (~0x3);
486 wrsz
= MIN_PACKET_SIZE
+ 3;
487 wrsz
+= (u32
)((ulong
)pdata
->loopback_tx_pkt
& 0x3);
490 smsc911x_tx_writefifo(pdata
, (unsigned int *)bufp
, wrsz
);
492 /* Wait till transmit is done */
496 status
= smsc911x_tx_get_txstatus(pdata
);
497 } while ((i
--) && (!status
));
500 SMSC_WARNING(HW
, "Failed to transmit "
501 "during loopback test");
504 if (status
& TX_STS_ES_
) {
505 SMSC_WARNING(HW
, "Transmit encountered "
506 "errors during loopback test");
510 /* Wait till receive is done */
514 status
= smsc911x_rx_get_rxstatus(pdata
);
515 } while ((i
--) && (!status
));
519 "Failed to receive during loopback test");
522 if (status
& RX_STS_ES_
) {
523 SMSC_WARNING(HW
, "Receive encountered "
524 "errors during loopback test");
528 pktlength
= ((status
& 0x3FFF0000UL
) >> 16);
529 bufp
= (ulong
)pdata
->loopback_rx_pkt
;
530 rdsz
= pktlength
+ 3;
531 rdsz
+= (u32
)((ulong
)pdata
->loopback_rx_pkt
& 0x3);
534 smsc911x_rx_readfifo(pdata
, (unsigned int *)bufp
, rdsz
);
536 if (pktlength
!= (MIN_PACKET_SIZE
+ 4)) {
537 SMSC_WARNING(HW
, "Unexpected packet size "
538 "during loop back test, size=%d, will retry",
543 for (j
= 0; j
< MIN_PACKET_SIZE
; j
++) {
544 if (pdata
->loopback_tx_pkt
[j
]
545 != pdata
->loopback_rx_pkt
[j
]) {
551 SMSC_TRACE(HW
, "Successfully verified "
555 SMSC_WARNING(HW
, "Data mismatch "
556 "during loop back test, will retry");
564 static int smsc911x_phy_reset(struct smsc911x_data
*pdata
)
566 struct phy_device
*phy_dev
= pdata
->phy_dev
;
568 unsigned int i
= 100000;
571 BUG_ON(!phy_dev
->bus
);
573 SMSC_TRACE(HW
, "Performing PHY BCR Reset");
574 smsc911x_mii_write(phy_dev
->bus
, phy_dev
->addr
, MII_BMCR
, BMCR_RESET
);
577 temp
= smsc911x_mii_read(phy_dev
->bus
, phy_dev
->addr
,
579 } while ((i
--) && (temp
& BMCR_RESET
));
581 if (temp
& BMCR_RESET
) {
582 SMSC_WARNING(HW
, "PHY reset failed to complete.");
585 /* Extra delay required because the phy may not be completed with
586 * its reset when BMCR_RESET is cleared. Specs say 256 uS is
587 * enough delay but using 1ms here to be safe */
593 static int smsc911x_phy_loopbacktest(struct net_device
*dev
)
595 struct smsc911x_data
*pdata
= netdev_priv(dev
);
596 struct phy_device
*phy_dev
= pdata
->phy_dev
;
601 /* Initialise tx packet using broadcast destination address */
602 memset(pdata
->loopback_tx_pkt
, 0xff, ETH_ALEN
);
604 /* Use incrementing source address */
605 for (i
= 6; i
< 12; i
++)
606 pdata
->loopback_tx_pkt
[i
] = (char)i
;
608 /* Set length type field */
609 pdata
->loopback_tx_pkt
[12] = 0x00;
610 pdata
->loopback_tx_pkt
[13] = 0x00;
612 for (i
= 14; i
< MIN_PACKET_SIZE
; i
++)
613 pdata
->loopback_tx_pkt
[i
] = (char)i
;
615 val
= smsc911x_reg_read(pdata
, HW_CFG
);
616 val
&= HW_CFG_TX_FIF_SZ_
;
618 smsc911x_reg_write(pdata
, HW_CFG
, val
);
620 smsc911x_reg_write(pdata
, TX_CFG
, TX_CFG_TX_ON_
);
621 smsc911x_reg_write(pdata
, RX_CFG
,
622 (u32
)((ulong
)pdata
->loopback_rx_pkt
& 0x03) << 8);
624 for (i
= 0; i
< 10; i
++) {
625 /* Set PHY to 10/FD, no ANEG, and loopback mode */
626 smsc911x_mii_write(phy_dev
->bus
, phy_dev
->addr
, MII_BMCR
,
627 BMCR_LOOPBACK
| BMCR_FULLDPLX
);
629 /* Enable MAC tx/rx, FD */
630 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
631 smsc911x_mac_write(pdata
, MAC_CR
, MAC_CR_FDPX_
632 | MAC_CR_TXEN_
| MAC_CR_RXEN_
);
633 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
635 if (smsc911x_phy_check_loopbackpkt(pdata
) == 0) {
642 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
643 smsc911x_mac_write(pdata
, MAC_CR
, 0);
644 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
646 smsc911x_phy_reset(pdata
);
650 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
651 smsc911x_mac_write(pdata
, MAC_CR
, 0);
652 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
654 /* Cancel PHY loopback mode */
655 smsc911x_mii_write(phy_dev
->bus
, phy_dev
->addr
, MII_BMCR
, 0);
657 smsc911x_reg_write(pdata
, TX_CFG
, 0);
658 smsc911x_reg_write(pdata
, RX_CFG
, 0);
662 #endif /* USE_PHY_WORK_AROUND */
664 static void smsc911x_phy_update_flowcontrol(struct smsc911x_data
*pdata
)
666 struct phy_device
*phy_dev
= pdata
->phy_dev
;
667 u32 afc
= smsc911x_reg_read(pdata
, AFC_CFG
);
671 if (phy_dev
->duplex
== DUPLEX_FULL
) {
672 u16 lcladv
= phy_read(phy_dev
, MII_ADVERTISE
);
673 u16 rmtadv
= phy_read(phy_dev
, MII_LPA
);
674 u8 cap
= mii_resolve_flowctrl_fdx(lcladv
, rmtadv
);
676 if (cap
& FLOW_CTRL_RX
)
681 if (cap
& FLOW_CTRL_TX
)
686 SMSC_TRACE(HW
, "rx pause %s, tx pause %s",
687 (cap
& FLOW_CTRL_RX
? "enabled" : "disabled"),
688 (cap
& FLOW_CTRL_TX
? "enabled" : "disabled"));
690 SMSC_TRACE(HW
, "half duplex");
695 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
696 smsc911x_mac_write(pdata
, FLOW
, flow
);
697 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
699 smsc911x_reg_write(pdata
, AFC_CFG
, afc
);
702 /* Update link mode if anything has changed. Called periodically when the
703 * PHY is in polling mode, even if nothing has changed. */
704 static void smsc911x_phy_adjust_link(struct net_device
*dev
)
706 struct smsc911x_data
*pdata
= netdev_priv(dev
);
707 struct phy_device
*phy_dev
= pdata
->phy_dev
;
711 if (phy_dev
->duplex
!= pdata
->last_duplex
) {
713 SMSC_TRACE(HW
, "duplex state has changed");
715 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
716 mac_cr
= smsc911x_mac_read(pdata
, MAC_CR
);
717 if (phy_dev
->duplex
) {
719 "configuring for full duplex mode");
720 mac_cr
|= MAC_CR_FDPX_
;
723 "configuring for half duplex mode");
724 mac_cr
&= ~MAC_CR_FDPX_
;
726 smsc911x_mac_write(pdata
, MAC_CR
, mac_cr
);
727 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
729 smsc911x_phy_update_flowcontrol(pdata
);
730 pdata
->last_duplex
= phy_dev
->duplex
;
733 carrier
= netif_carrier_ok(dev
);
734 if (carrier
!= pdata
->last_carrier
) {
735 SMSC_TRACE(HW
, "carrier state has changed");
737 SMSC_TRACE(HW
, "configuring for carrier OK");
738 if ((pdata
->gpio_orig_setting
& GPIO_CFG_LED1_EN_
) &&
739 (!pdata
->using_extphy
)) {
740 /* Restore orginal GPIO configuration */
741 pdata
->gpio_setting
= pdata
->gpio_orig_setting
;
742 smsc911x_reg_write(pdata
, GPIO_CFG
,
743 pdata
->gpio_setting
);
746 SMSC_TRACE(HW
, "configuring for no carrier");
747 /* Check global setting that LED1
748 * usage is 10/100 indicator */
749 pdata
->gpio_setting
= smsc911x_reg_read(pdata
,
751 if ((pdata
->gpio_setting
& GPIO_CFG_LED1_EN_
)
752 && (!pdata
->using_extphy
)) {
753 /* Force 10/100 LED off, after saving
754 * orginal GPIO configuration */
755 pdata
->gpio_orig_setting
= pdata
->gpio_setting
;
757 pdata
->gpio_setting
&= ~GPIO_CFG_LED1_EN_
;
758 pdata
->gpio_setting
|= (GPIO_CFG_GPIOBUF0_
761 smsc911x_reg_write(pdata
, GPIO_CFG
,
762 pdata
->gpio_setting
);
765 pdata
->last_carrier
= carrier
;
769 static int smsc911x_mii_probe(struct net_device
*dev
)
771 struct smsc911x_data
*pdata
= netdev_priv(dev
);
772 struct phy_device
*phydev
= NULL
;
775 /* find the first phy */
776 for (phy_addr
= 0; phy_addr
< PHY_MAX_ADDR
; phy_addr
++) {
777 if (pdata
->mii_bus
->phy_map
[phy_addr
]) {
778 phydev
= pdata
->mii_bus
->phy_map
[phy_addr
];
779 SMSC_TRACE(PROBE
, "PHY %d: addr %d, phy_id 0x%08X",
780 phy_addr
, phydev
->addr
, phydev
->phy_id
);
786 pr_err("%s: no PHY found\n", dev
->name
);
790 phydev
= phy_connect(dev
, dev_name(&phydev
->dev
),
791 &smsc911x_phy_adjust_link
, 0, pdata
->config
.phy_interface
);
793 if (IS_ERR(phydev
)) {
794 pr_err("%s: Could not attach to PHY\n", dev
->name
);
795 return PTR_ERR(phydev
);
798 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
799 dev
->name
, phydev
->drv
->name
,
800 dev_name(&phydev
->dev
), phydev
->irq
);
802 /* mask with MAC supported features */
803 phydev
->supported
&= (PHY_BASIC_FEATURES
| SUPPORTED_Pause
|
804 SUPPORTED_Asym_Pause
);
805 phydev
->advertising
= phydev
->supported
;
807 pdata
->phy_dev
= phydev
;
808 pdata
->last_duplex
= -1;
809 pdata
->last_carrier
= -1;
811 #ifdef USE_PHY_WORK_AROUND
812 if (smsc911x_phy_loopbacktest(dev
) < 0) {
813 SMSC_WARNING(HW
, "Failed Loop Back Test");
816 SMSC_TRACE(HW
, "Passed Loop Back Test");
817 #endif /* USE_PHY_WORK_AROUND */
819 SMSC_TRACE(HW
, "phy initialised succesfully");
823 static int __devinit
smsc911x_mii_init(struct platform_device
*pdev
,
824 struct net_device
*dev
)
826 struct smsc911x_data
*pdata
= netdev_priv(dev
);
829 pdata
->mii_bus
= mdiobus_alloc();
830 if (!pdata
->mii_bus
) {
835 pdata
->mii_bus
->name
= SMSC_MDIONAME
;
836 snprintf(pdata
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%x", pdev
->id
);
837 pdata
->mii_bus
->priv
= pdata
;
838 pdata
->mii_bus
->read
= smsc911x_mii_read
;
839 pdata
->mii_bus
->write
= smsc911x_mii_write
;
840 pdata
->mii_bus
->irq
= pdata
->phy_irq
;
841 for (i
= 0; i
< PHY_MAX_ADDR
; ++i
)
842 pdata
->mii_bus
->irq
[i
] = PHY_POLL
;
844 pdata
->mii_bus
->parent
= &pdev
->dev
;
846 switch (pdata
->idrev
& 0xFFFF0000) {
851 /* External PHY supported, try to autodetect */
852 smsc911x_phy_initialise_external(pdata
);
855 SMSC_TRACE(HW
, "External PHY is not supported, "
856 "using internal PHY");
857 pdata
->using_extphy
= 0;
861 if (!pdata
->using_extphy
) {
862 /* Mask all PHYs except ID 1 (internal) */
863 pdata
->mii_bus
->phy_mask
= ~(1 << 1);
866 if (mdiobus_register(pdata
->mii_bus
)) {
867 SMSC_WARNING(PROBE
, "Error registering mii bus");
868 goto err_out_free_bus_2
;
871 if (smsc911x_mii_probe(dev
) < 0) {
872 SMSC_WARNING(PROBE
, "Error registering mii bus");
873 goto err_out_unregister_bus_3
;
878 err_out_unregister_bus_3
:
879 mdiobus_unregister(pdata
->mii_bus
);
881 mdiobus_free(pdata
->mii_bus
);
886 /* Gets the number of tx statuses in the fifo */
887 static unsigned int smsc911x_tx_get_txstatcount(struct smsc911x_data
*pdata
)
889 return (smsc911x_reg_read(pdata
, TX_FIFO_INF
)
890 & TX_FIFO_INF_TSUSED_
) >> 16;
893 /* Reads tx statuses and increments counters where necessary */
894 static void smsc911x_tx_update_txcounters(struct net_device
*dev
)
896 struct smsc911x_data
*pdata
= netdev_priv(dev
);
897 unsigned int tx_stat
;
899 while ((tx_stat
= smsc911x_tx_get_txstatus(pdata
)) != 0) {
900 if (unlikely(tx_stat
& 0x80000000)) {
901 /* In this driver the packet tag is used as the packet
902 * length. Since a packet length can never reach the
903 * size of 0x8000, this bit is reserved. It is worth
904 * noting that the "reserved bit" in the warning above
905 * does not reference a hardware defined reserved bit
906 * but rather a driver defined one.
909 "Packet tag reserved bit is high");
911 if (unlikely(tx_stat
& TX_STS_ES_
)) {
912 dev
->stats
.tx_errors
++;
914 dev
->stats
.tx_packets
++;
915 dev
->stats
.tx_bytes
+= (tx_stat
>> 16);
917 if (unlikely(tx_stat
& TX_STS_EXCESS_COL_
)) {
918 dev
->stats
.collisions
+= 16;
919 dev
->stats
.tx_aborted_errors
+= 1;
921 dev
->stats
.collisions
+=
922 ((tx_stat
>> 3) & 0xF);
924 if (unlikely(tx_stat
& TX_STS_LOST_CARRIER_
))
925 dev
->stats
.tx_carrier_errors
+= 1;
926 if (unlikely(tx_stat
& TX_STS_LATE_COL_
)) {
927 dev
->stats
.collisions
++;
928 dev
->stats
.tx_aborted_errors
++;
934 /* Increments the Rx error counters */
936 smsc911x_rx_counterrors(struct net_device
*dev
, unsigned int rxstat
)
940 if (unlikely(rxstat
& RX_STS_ES_
)) {
941 dev
->stats
.rx_errors
++;
942 if (unlikely(rxstat
& RX_STS_CRC_ERR_
)) {
943 dev
->stats
.rx_crc_errors
++;
947 if (likely(!crc_err
)) {
948 if (unlikely((rxstat
& RX_STS_FRAME_TYPE_
) &&
949 (rxstat
& RX_STS_LENGTH_ERR_
)))
950 dev
->stats
.rx_length_errors
++;
951 if (rxstat
& RX_STS_MCAST_
)
952 dev
->stats
.multicast
++;
956 /* Quickly dumps bad packets */
958 smsc911x_rx_fastforward(struct smsc911x_data
*pdata
, unsigned int pktbytes
)
960 unsigned int pktwords
= (pktbytes
+ NET_IP_ALIGN
+ 3) >> 2;
962 if (likely(pktwords
>= 4)) {
963 unsigned int timeout
= 500;
965 smsc911x_reg_write(pdata
, RX_DP_CTRL
, RX_DP_CTRL_RX_FFWD_
);
968 val
= smsc911x_reg_read(pdata
, RX_DP_CTRL
);
969 } while ((val
& RX_DP_CTRL_RX_FFWD_
) && --timeout
);
971 if (unlikely(timeout
== 0))
972 SMSC_WARNING(HW
, "Timed out waiting for "
973 "RX FFWD to finish, RX_DP_CTRL: 0x%08X", val
);
977 temp
= smsc911x_reg_read(pdata
, RX_DATA_FIFO
);
981 /* NAPI poll function */
982 static int smsc911x_poll(struct napi_struct
*napi
, int budget
)
984 struct smsc911x_data
*pdata
=
985 container_of(napi
, struct smsc911x_data
, napi
);
986 struct net_device
*dev
= pdata
->dev
;
989 while (likely(netif_running(dev
)) && (npackets
< budget
)) {
990 unsigned int pktlength
;
991 unsigned int pktwords
;
993 unsigned int rxstat
= smsc911x_rx_get_rxstatus(pdata
);
997 /* We processed all packets available. Tell NAPI it can
998 * stop polling then re-enable rx interrupts */
999 smsc911x_reg_write(pdata
, INT_STS
, INT_STS_RSFL_
);
1000 napi_complete(napi
);
1001 temp
= smsc911x_reg_read(pdata
, INT_EN
);
1002 temp
|= INT_EN_RSFL_EN_
;
1003 smsc911x_reg_write(pdata
, INT_EN
, temp
);
1007 /* Count packet for NAPI scheduling, even if it has an error.
1008 * Error packets still require cycles to discard */
1011 pktlength
= ((rxstat
& 0x3FFF0000) >> 16);
1012 pktwords
= (pktlength
+ NET_IP_ALIGN
+ 3) >> 2;
1013 smsc911x_rx_counterrors(dev
, rxstat
);
1015 if (unlikely(rxstat
& RX_STS_ES_
)) {
1016 SMSC_WARNING(RX_ERR
,
1017 "Discarding packet with error bit set");
1018 /* Packet has an error, discard it and continue with
1020 smsc911x_rx_fastforward(pdata
, pktwords
);
1021 dev
->stats
.rx_dropped
++;
1025 skb
= netdev_alloc_skb(dev
, pktlength
+ NET_IP_ALIGN
);
1026 if (unlikely(!skb
)) {
1027 SMSC_WARNING(RX_ERR
,
1028 "Unable to allocate skb for rx packet");
1029 /* Drop the packet and stop this polling iteration */
1030 smsc911x_rx_fastforward(pdata
, pktwords
);
1031 dev
->stats
.rx_dropped
++;
1035 skb
->data
= skb
->head
;
1036 skb_reset_tail_pointer(skb
);
1038 /* Align IP on 16B boundary */
1039 skb_reserve(skb
, NET_IP_ALIGN
);
1040 skb_put(skb
, pktlength
- 4);
1041 smsc911x_rx_readfifo(pdata
, (unsigned int *)skb
->head
,
1043 skb
->protocol
= eth_type_trans(skb
, dev
);
1044 skb
->ip_summed
= CHECKSUM_NONE
;
1045 netif_receive_skb(skb
);
1047 /* Update counters */
1048 dev
->stats
.rx_packets
++;
1049 dev
->stats
.rx_bytes
+= (pktlength
- 4);
1050 dev
->last_rx
= jiffies
;
1053 /* Return total received packets */
1057 /* Returns hash bit number for given MAC address
1059 * 01 00 5E 00 00 01 -> returns bit number 31 */
1060 static unsigned int smsc911x_hash(char addr
[ETH_ALEN
])
1062 return (ether_crc(ETH_ALEN
, addr
) >> 26) & 0x3f;
1065 static void smsc911x_rx_multicast_update(struct smsc911x_data
*pdata
)
1067 /* Performs the multicast & mac_cr update. This is called when
1068 * safe on the current hardware, and with the mac_lock held */
1069 unsigned int mac_cr
;
1071 SMSC_ASSERT_MAC_LOCK(pdata
);
1073 mac_cr
= smsc911x_mac_read(pdata
, MAC_CR
);
1074 mac_cr
|= pdata
->set_bits_mask
;
1075 mac_cr
&= ~(pdata
->clear_bits_mask
);
1076 smsc911x_mac_write(pdata
, MAC_CR
, mac_cr
);
1077 smsc911x_mac_write(pdata
, HASHH
, pdata
->hashhi
);
1078 smsc911x_mac_write(pdata
, HASHL
, pdata
->hashlo
);
1079 SMSC_TRACE(HW
, "maccr 0x%08X, HASHH 0x%08X, HASHL 0x%08X",
1080 mac_cr
, pdata
->hashhi
, pdata
->hashlo
);
1083 static void smsc911x_rx_multicast_update_workaround(struct smsc911x_data
*pdata
)
1085 unsigned int mac_cr
;
1087 /* This function is only called for older LAN911x devices
1088 * (revA or revB), where MAC_CR, HASHH and HASHL should not
1089 * be modified during Rx - newer devices immediately update the
1092 * This is called from interrupt context */
1094 spin_lock(&pdata
->mac_lock
);
1096 /* Check Rx has stopped */
1097 if (smsc911x_mac_read(pdata
, MAC_CR
) & MAC_CR_RXEN_
)
1098 SMSC_WARNING(DRV
, "Rx not stopped");
1100 /* Perform the update - safe to do now Rx has stopped */
1101 smsc911x_rx_multicast_update(pdata
);
1104 mac_cr
= smsc911x_mac_read(pdata
, MAC_CR
);
1105 mac_cr
|= MAC_CR_RXEN_
;
1106 smsc911x_mac_write(pdata
, MAC_CR
, mac_cr
);
1108 pdata
->multicast_update_pending
= 0;
1110 spin_unlock(&pdata
->mac_lock
);
1113 static int smsc911x_soft_reset(struct smsc911x_data
*pdata
)
1115 unsigned int timeout
;
1118 /* Reset the LAN911x */
1119 smsc911x_reg_write(pdata
, HW_CFG
, HW_CFG_SRST_
);
1123 temp
= smsc911x_reg_read(pdata
, HW_CFG
);
1124 } while ((--timeout
) && (temp
& HW_CFG_SRST_
));
1126 if (unlikely(temp
& HW_CFG_SRST_
)) {
1127 SMSC_WARNING(DRV
, "Failed to complete reset");
1133 /* Sets the device MAC address to dev_addr, called with mac_lock held */
1135 smsc911x_set_hw_mac_address(struct smsc911x_data
*pdata
, u8 dev_addr
[6])
1137 u32 mac_high16
= (dev_addr
[5] << 8) | dev_addr
[4];
1138 u32 mac_low32
= (dev_addr
[3] << 24) | (dev_addr
[2] << 16) |
1139 (dev_addr
[1] << 8) | dev_addr
[0];
1141 SMSC_ASSERT_MAC_LOCK(pdata
);
1143 smsc911x_mac_write(pdata
, ADDRH
, mac_high16
);
1144 smsc911x_mac_write(pdata
, ADDRL
, mac_low32
);
1147 static int smsc911x_open(struct net_device
*dev
)
1149 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1150 unsigned int timeout
;
1152 unsigned int intcfg
;
1154 /* if the phy is not yet registered, retry later*/
1155 if (!pdata
->phy_dev
) {
1156 SMSC_WARNING(HW
, "phy_dev is NULL");
1160 if (!is_valid_ether_addr(dev
->dev_addr
)) {
1161 SMSC_WARNING(HW
, "dev_addr is not a valid MAC address");
1162 return -EADDRNOTAVAIL
;
1165 /* Reset the LAN911x */
1166 if (smsc911x_soft_reset(pdata
)) {
1167 SMSC_WARNING(HW
, "soft reset failed");
1171 smsc911x_reg_write(pdata
, HW_CFG
, 0x00050000);
1172 smsc911x_reg_write(pdata
, AFC_CFG
, 0x006E3740);
1174 /* Make sure EEPROM has finished loading before setting GPIO_CFG */
1176 while ((smsc911x_reg_read(pdata
, E2P_CMD
) & E2P_CMD_EPC_BUSY_
) &&
1181 if (unlikely(timeout
== 0))
1183 "Timed out waiting for EEPROM busy bit to clear");
1185 smsc911x_reg_write(pdata
, GPIO_CFG
, 0x70070000);
1187 /* The soft reset above cleared the device's MAC address,
1188 * restore it from local copy (set in probe) */
1189 spin_lock_irq(&pdata
->mac_lock
);
1190 smsc911x_set_hw_mac_address(pdata
, dev
->dev_addr
);
1191 spin_unlock_irq(&pdata
->mac_lock
);
1193 /* Initialise irqs, but leave all sources disabled */
1194 smsc911x_reg_write(pdata
, INT_EN
, 0);
1195 smsc911x_reg_write(pdata
, INT_STS
, 0xFFFFFFFF);
1197 /* Set interrupt deassertion to 100uS */
1198 intcfg
= ((10 << 24) | INT_CFG_IRQ_EN_
);
1200 if (pdata
->config
.irq_polarity
) {
1201 SMSC_TRACE(IFUP
, "irq polarity: active high");
1202 intcfg
|= INT_CFG_IRQ_POL_
;
1204 SMSC_TRACE(IFUP
, "irq polarity: active low");
1207 if (pdata
->config
.irq_type
) {
1208 SMSC_TRACE(IFUP
, "irq type: push-pull");
1209 intcfg
|= INT_CFG_IRQ_TYPE_
;
1211 SMSC_TRACE(IFUP
, "irq type: open drain");
1214 smsc911x_reg_write(pdata
, INT_CFG
, intcfg
);
1216 SMSC_TRACE(IFUP
, "Testing irq handler using IRQ %d", dev
->irq
);
1217 pdata
->software_irq_signal
= 0;
1220 temp
= smsc911x_reg_read(pdata
, INT_EN
);
1221 temp
|= INT_EN_SW_INT_EN_
;
1222 smsc911x_reg_write(pdata
, INT_EN
, temp
);
1226 if (pdata
->software_irq_signal
)
1231 if (!pdata
->software_irq_signal
) {
1232 dev_warn(&dev
->dev
, "ISR failed signaling test (IRQ %d)\n",
1236 SMSC_TRACE(IFUP
, "IRQ handler passed test using IRQ %d", dev
->irq
);
1238 dev_info(&dev
->dev
, "SMSC911x/921x identified at %#08lx, IRQ: %d\n",
1239 (unsigned long)pdata
->ioaddr
, dev
->irq
);
1241 /* Reset the last known duplex and carrier */
1242 pdata
->last_duplex
= -1;
1243 pdata
->last_carrier
= -1;
1245 /* Bring the PHY up */
1246 phy_start(pdata
->phy_dev
);
1248 temp
= smsc911x_reg_read(pdata
, HW_CFG
);
1249 /* Preserve TX FIFO size and external PHY configuration */
1250 temp
&= (HW_CFG_TX_FIF_SZ_
|0x00000FFF);
1252 smsc911x_reg_write(pdata
, HW_CFG
, temp
);
1254 temp
= smsc911x_reg_read(pdata
, FIFO_INT
);
1255 temp
|= FIFO_INT_TX_AVAIL_LEVEL_
;
1256 temp
&= ~(FIFO_INT_RX_STS_LEVEL_
);
1257 smsc911x_reg_write(pdata
, FIFO_INT
, temp
);
1259 /* set RX Data offset to 2 bytes for alignment */
1260 smsc911x_reg_write(pdata
, RX_CFG
, (2 << 8));
1262 /* enable NAPI polling before enabling RX interrupts */
1263 napi_enable(&pdata
->napi
);
1265 temp
= smsc911x_reg_read(pdata
, INT_EN
);
1266 temp
|= (INT_EN_TDFA_EN_
| INT_EN_RSFL_EN_
| INT_EN_RXSTOP_INT_EN_
);
1267 smsc911x_reg_write(pdata
, INT_EN
, temp
);
1269 spin_lock_irq(&pdata
->mac_lock
);
1270 temp
= smsc911x_mac_read(pdata
, MAC_CR
);
1271 temp
|= (MAC_CR_TXEN_
| MAC_CR_RXEN_
| MAC_CR_HBDIS_
);
1272 smsc911x_mac_write(pdata
, MAC_CR
, temp
);
1273 spin_unlock_irq(&pdata
->mac_lock
);
1275 smsc911x_reg_write(pdata
, TX_CFG
, TX_CFG_TX_ON_
);
1277 netif_start_queue(dev
);
1281 /* Entry point for stopping the interface */
1282 static int smsc911x_stop(struct net_device
*dev
)
1284 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1287 /* Disable all device interrupts */
1288 temp
= smsc911x_reg_read(pdata
, INT_CFG
);
1289 temp
&= ~INT_CFG_IRQ_EN_
;
1290 smsc911x_reg_write(pdata
, INT_CFG
, temp
);
1292 /* Stop Tx and Rx polling */
1293 netif_stop_queue(dev
);
1294 napi_disable(&pdata
->napi
);
1296 /* At this point all Rx and Tx activity is stopped */
1297 dev
->stats
.rx_dropped
+= smsc911x_reg_read(pdata
, RX_DROP
);
1298 smsc911x_tx_update_txcounters(dev
);
1300 /* Bring the PHY down */
1302 phy_stop(pdata
->phy_dev
);
1304 SMSC_TRACE(IFDOWN
, "Interface stopped");
1308 /* Entry point for transmitting a packet */
1309 static int smsc911x_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1311 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1312 unsigned int freespace
;
1313 unsigned int tx_cmd_a
;
1314 unsigned int tx_cmd_b
;
1319 freespace
= smsc911x_reg_read(pdata
, TX_FIFO_INF
) & TX_FIFO_INF_TDFREE_
;
1321 if (unlikely(freespace
< TX_FIFO_LOW_THRESHOLD
))
1322 SMSC_WARNING(TX_ERR
,
1323 "Tx data fifo low, space available: %d", freespace
);
1325 /* Word alignment adjustment */
1326 tx_cmd_a
= (u32
)((ulong
)skb
->data
& 0x03) << 16;
1327 tx_cmd_a
|= TX_CMD_A_FIRST_SEG_
| TX_CMD_A_LAST_SEG_
;
1328 tx_cmd_a
|= (unsigned int)skb
->len
;
1330 tx_cmd_b
= ((unsigned int)skb
->len
) << 16;
1331 tx_cmd_b
|= (unsigned int)skb
->len
;
1333 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, tx_cmd_a
);
1334 smsc911x_reg_write(pdata
, TX_DATA_FIFO
, tx_cmd_b
);
1336 bufp
= (ulong
)skb
->data
& (~0x3);
1337 wrsz
= (u32
)skb
->len
+ 3;
1338 wrsz
+= (u32
)((ulong
)skb
->data
& 0x3);
1341 smsc911x_tx_writefifo(pdata
, (unsigned int *)bufp
, wrsz
);
1342 freespace
-= (skb
->len
+ 32);
1344 dev
->trans_start
= jiffies
;
1346 if (unlikely(smsc911x_tx_get_txstatcount(pdata
) >= 30))
1347 smsc911x_tx_update_txcounters(dev
);
1349 if (freespace
< TX_FIFO_LOW_THRESHOLD
) {
1350 netif_stop_queue(dev
);
1351 temp
= smsc911x_reg_read(pdata
, FIFO_INT
);
1354 smsc911x_reg_write(pdata
, FIFO_INT
, temp
);
1357 return NETDEV_TX_OK
;
1360 /* Entry point for getting status counters */
1361 static struct net_device_stats
*smsc911x_get_stats(struct net_device
*dev
)
1363 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1364 smsc911x_tx_update_txcounters(dev
);
1365 dev
->stats
.rx_dropped
+= smsc911x_reg_read(pdata
, RX_DROP
);
1369 /* Entry point for setting addressing modes */
1370 static void smsc911x_set_multicast_list(struct net_device
*dev
)
1372 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1373 unsigned long flags
;
1375 if (dev
->flags
& IFF_PROMISC
) {
1376 /* Enabling promiscuous mode */
1377 pdata
->set_bits_mask
= MAC_CR_PRMS_
;
1378 pdata
->clear_bits_mask
= (MAC_CR_MCPAS_
| MAC_CR_HPFILT_
);
1381 } else if (dev
->flags
& IFF_ALLMULTI
) {
1382 /* Enabling all multicast mode */
1383 pdata
->set_bits_mask
= MAC_CR_MCPAS_
;
1384 pdata
->clear_bits_mask
= (MAC_CR_PRMS_
| MAC_CR_HPFILT_
);
1387 } else if (dev
->mc_count
> 0) {
1388 /* Enabling specific multicast addresses */
1389 unsigned int hash_high
= 0;
1390 unsigned int hash_low
= 0;
1391 unsigned int count
= 0;
1392 struct dev_mc_list
*mc_list
= dev
->mc_list
;
1394 pdata
->set_bits_mask
= MAC_CR_HPFILT_
;
1395 pdata
->clear_bits_mask
= (MAC_CR_PRMS_
| MAC_CR_MCPAS_
);
1399 if ((mc_list
->dmi_addrlen
) == ETH_ALEN
) {
1400 unsigned int bitnum
=
1401 smsc911x_hash(mc_list
->dmi_addr
);
1402 unsigned int mask
= 0x01 << (bitnum
& 0x1F);
1408 SMSC_WARNING(DRV
, "dmi_addrlen != 6");
1410 mc_list
= mc_list
->next
;
1412 if (count
!= (unsigned int)dev
->mc_count
)
1413 SMSC_WARNING(DRV
, "mc_count != dev->mc_count");
1415 pdata
->hashhi
= hash_high
;
1416 pdata
->hashlo
= hash_low
;
1418 /* Enabling local MAC address only */
1419 pdata
->set_bits_mask
= 0;
1420 pdata
->clear_bits_mask
=
1421 (MAC_CR_PRMS_
| MAC_CR_MCPAS_
| MAC_CR_HPFILT_
);
1426 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
1428 if (pdata
->generation
<= 1) {
1429 /* Older hardware revision - cannot change these flags while
1431 if (!pdata
->multicast_update_pending
) {
1433 SMSC_TRACE(HW
, "scheduling mcast update");
1434 pdata
->multicast_update_pending
= 1;
1436 /* Request the hardware to stop, then perform the
1437 * update when we get an RX_STOP interrupt */
1438 temp
= smsc911x_mac_read(pdata
, MAC_CR
);
1439 temp
&= ~(MAC_CR_RXEN_
);
1440 smsc911x_mac_write(pdata
, MAC_CR
, temp
);
1442 /* There is another update pending, this should now
1443 * use the newer values */
1446 /* Newer hardware revision - can write immediately */
1447 smsc911x_rx_multicast_update(pdata
);
1450 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
1453 static irqreturn_t
smsc911x_irqhandler(int irq
, void *dev_id
)
1455 struct net_device
*dev
= dev_id
;
1456 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1457 u32 intsts
= smsc911x_reg_read(pdata
, INT_STS
);
1458 u32 inten
= smsc911x_reg_read(pdata
, INT_EN
);
1459 int serviced
= IRQ_NONE
;
1462 if (unlikely(intsts
& inten
& INT_STS_SW_INT_
)) {
1463 temp
= smsc911x_reg_read(pdata
, INT_EN
);
1464 temp
&= (~INT_EN_SW_INT_EN_
);
1465 smsc911x_reg_write(pdata
, INT_EN
, temp
);
1466 smsc911x_reg_write(pdata
, INT_STS
, INT_STS_SW_INT_
);
1467 pdata
->software_irq_signal
= 1;
1469 serviced
= IRQ_HANDLED
;
1472 if (unlikely(intsts
& inten
& INT_STS_RXSTOP_INT_
)) {
1473 /* Called when there is a multicast update scheduled and
1474 * it is now safe to complete the update */
1475 SMSC_TRACE(INTR
, "RX Stop interrupt");
1476 smsc911x_reg_write(pdata
, INT_STS
, INT_STS_RXSTOP_INT_
);
1477 if (pdata
->multicast_update_pending
)
1478 smsc911x_rx_multicast_update_workaround(pdata
);
1479 serviced
= IRQ_HANDLED
;
1482 if (intsts
& inten
& INT_STS_TDFA_
) {
1483 temp
= smsc911x_reg_read(pdata
, FIFO_INT
);
1484 temp
|= FIFO_INT_TX_AVAIL_LEVEL_
;
1485 smsc911x_reg_write(pdata
, FIFO_INT
, temp
);
1486 smsc911x_reg_write(pdata
, INT_STS
, INT_STS_TDFA_
);
1487 netif_wake_queue(dev
);
1488 serviced
= IRQ_HANDLED
;
1491 if (unlikely(intsts
& inten
& INT_STS_RXE_
)) {
1492 SMSC_TRACE(INTR
, "RX Error interrupt");
1493 smsc911x_reg_write(pdata
, INT_STS
, INT_STS_RXE_
);
1494 serviced
= IRQ_HANDLED
;
1497 if (likely(intsts
& inten
& INT_STS_RSFL_
)) {
1498 if (likely(napi_schedule_prep(&pdata
->napi
))) {
1499 /* Disable Rx interrupts */
1500 temp
= smsc911x_reg_read(pdata
, INT_EN
);
1501 temp
&= (~INT_EN_RSFL_EN_
);
1502 smsc911x_reg_write(pdata
, INT_EN
, temp
);
1503 /* Schedule a NAPI poll */
1504 __napi_schedule(&pdata
->napi
);
1506 SMSC_WARNING(RX_ERR
,
1507 "napi_schedule_prep failed");
1509 serviced
= IRQ_HANDLED
;
1515 #ifdef CONFIG_NET_POLL_CONTROLLER
1516 static void smsc911x_poll_controller(struct net_device
*dev
)
1518 disable_irq(dev
->irq
);
1519 smsc911x_irqhandler(0, dev
);
1520 enable_irq(dev
->irq
);
1522 #endif /* CONFIG_NET_POLL_CONTROLLER */
1524 static int smsc911x_set_mac_address(struct net_device
*dev
, void *p
)
1526 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1527 struct sockaddr
*addr
= p
;
1529 /* On older hardware revisions we cannot change the mac address
1530 * registers while receiving data. Newer devices can safely change
1531 * this at any time. */
1532 if (pdata
->generation
<= 1 && netif_running(dev
))
1535 if (!is_valid_ether_addr(addr
->sa_data
))
1536 return -EADDRNOTAVAIL
;
1538 memcpy(dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
1540 spin_lock_irq(&pdata
->mac_lock
);
1541 smsc911x_set_hw_mac_address(pdata
, dev
->dev_addr
);
1542 spin_unlock_irq(&pdata
->mac_lock
);
1544 dev_info(&dev
->dev
, "MAC Address: %pM\n", dev
->dev_addr
);
1549 /* Standard ioctls for mii-tool */
1550 static int smsc911x_do_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
1552 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1554 if (!netif_running(dev
) || !pdata
->phy_dev
)
1557 return phy_mii_ioctl(pdata
->phy_dev
, if_mii(ifr
), cmd
);
1561 smsc911x_ethtool_getsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1563 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1567 return phy_ethtool_gset(pdata
->phy_dev
, cmd
);
1571 smsc911x_ethtool_setsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1573 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1575 return phy_ethtool_sset(pdata
->phy_dev
, cmd
);
1578 static void smsc911x_ethtool_getdrvinfo(struct net_device
*dev
,
1579 struct ethtool_drvinfo
*info
)
1581 strlcpy(info
->driver
, SMSC_CHIPNAME
, sizeof(info
->driver
));
1582 strlcpy(info
->version
, SMSC_DRV_VERSION
, sizeof(info
->version
));
1583 strlcpy(info
->bus_info
, dev_name(dev
->dev
.parent
),
1584 sizeof(info
->bus_info
));
1587 static int smsc911x_ethtool_nwayreset(struct net_device
*dev
)
1589 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1591 return phy_start_aneg(pdata
->phy_dev
);
1594 static u32
smsc911x_ethtool_getmsglevel(struct net_device
*dev
)
1596 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1597 return pdata
->msg_enable
;
1600 static void smsc911x_ethtool_setmsglevel(struct net_device
*dev
, u32 level
)
1602 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1603 pdata
->msg_enable
= level
;
1606 static int smsc911x_ethtool_getregslen(struct net_device
*dev
)
1608 return (((E2P_DATA
- ID_REV
) / 4 + 1) + (WUCSR
- MAC_CR
) + 1 + 32) *
1613 smsc911x_ethtool_getregs(struct net_device
*dev
, struct ethtool_regs
*regs
,
1616 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1617 struct phy_device
*phy_dev
= pdata
->phy_dev
;
1618 unsigned long flags
;
1623 regs
->version
= pdata
->idrev
;
1624 for (i
= ID_REV
; i
<= E2P_DATA
; i
+= (sizeof(u32
)))
1625 data
[j
++] = smsc911x_reg_read(pdata
, i
);
1627 for (i
= MAC_CR
; i
<= WUCSR
; i
++) {
1628 spin_lock_irqsave(&pdata
->mac_lock
, flags
);
1629 data
[j
++] = smsc911x_mac_read(pdata
, i
);
1630 spin_unlock_irqrestore(&pdata
->mac_lock
, flags
);
1633 for (i
= 0; i
<= 31; i
++)
1634 data
[j
++] = smsc911x_mii_read(phy_dev
->bus
, phy_dev
->addr
, i
);
1637 static void smsc911x_eeprom_enable_access(struct smsc911x_data
*pdata
)
1639 unsigned int temp
= smsc911x_reg_read(pdata
, GPIO_CFG
);
1640 temp
&= ~GPIO_CFG_EEPR_EN_
;
1641 smsc911x_reg_write(pdata
, GPIO_CFG
, temp
);
1645 static int smsc911x_eeprom_send_cmd(struct smsc911x_data
*pdata
, u32 op
)
1650 SMSC_TRACE(DRV
, "op 0x%08x", op
);
1651 if (smsc911x_reg_read(pdata
, E2P_CMD
) & E2P_CMD_EPC_BUSY_
) {
1652 SMSC_WARNING(DRV
, "Busy at start");
1656 e2cmd
= op
| E2P_CMD_EPC_BUSY_
;
1657 smsc911x_reg_write(pdata
, E2P_CMD
, e2cmd
);
1661 e2cmd
= smsc911x_reg_read(pdata
, E2P_CMD
);
1662 } while ((e2cmd
& E2P_CMD_EPC_BUSY_
) && (--timeout
));
1665 SMSC_TRACE(DRV
, "TIMED OUT");
1669 if (e2cmd
& E2P_CMD_EPC_TIMEOUT_
) {
1670 SMSC_TRACE(DRV
, "Error occured during eeprom operation");
1677 static int smsc911x_eeprom_read_location(struct smsc911x_data
*pdata
,
1678 u8 address
, u8
*data
)
1680 u32 op
= E2P_CMD_EPC_CMD_READ_
| address
;
1683 SMSC_TRACE(DRV
, "address 0x%x", address
);
1684 ret
= smsc911x_eeprom_send_cmd(pdata
, op
);
1687 data
[address
] = smsc911x_reg_read(pdata
, E2P_DATA
);
1692 static int smsc911x_eeprom_write_location(struct smsc911x_data
*pdata
,
1693 u8 address
, u8 data
)
1695 u32 op
= E2P_CMD_EPC_CMD_ERASE_
| address
;
1699 SMSC_TRACE(DRV
, "address 0x%x, data 0x%x", address
, data
);
1700 ret
= smsc911x_eeprom_send_cmd(pdata
, op
);
1703 op
= E2P_CMD_EPC_CMD_WRITE_
| address
;
1704 smsc911x_reg_write(pdata
, E2P_DATA
, (u32
)data
);
1706 /* Workaround for hardware read-after-write restriction */
1707 temp
= smsc911x_reg_read(pdata
, BYTE_TEST
);
1709 ret
= smsc911x_eeprom_send_cmd(pdata
, op
);
1715 static int smsc911x_ethtool_get_eeprom_len(struct net_device
*dev
)
1717 return SMSC911X_EEPROM_SIZE
;
1720 static int smsc911x_ethtool_get_eeprom(struct net_device
*dev
,
1721 struct ethtool_eeprom
*eeprom
, u8
*data
)
1723 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1724 u8 eeprom_data
[SMSC911X_EEPROM_SIZE
];
1728 smsc911x_eeprom_enable_access(pdata
);
1730 len
= min(eeprom
->len
, SMSC911X_EEPROM_SIZE
);
1731 for (i
= 0; i
< len
; i
++) {
1732 int ret
= smsc911x_eeprom_read_location(pdata
, i
, eeprom_data
);
1739 memcpy(data
, &eeprom_data
[eeprom
->offset
], len
);
1744 static int smsc911x_ethtool_set_eeprom(struct net_device
*dev
,
1745 struct ethtool_eeprom
*eeprom
, u8
*data
)
1748 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1750 smsc911x_eeprom_enable_access(pdata
);
1751 smsc911x_eeprom_send_cmd(pdata
, E2P_CMD_EPC_CMD_EWEN_
);
1752 ret
= smsc911x_eeprom_write_location(pdata
, eeprom
->offset
, *data
);
1753 smsc911x_eeprom_send_cmd(pdata
, E2P_CMD_EPC_CMD_EWDS_
);
1755 /* Single byte write, according to man page */
1761 static const struct ethtool_ops smsc911x_ethtool_ops
= {
1762 .get_settings
= smsc911x_ethtool_getsettings
,
1763 .set_settings
= smsc911x_ethtool_setsettings
,
1764 .get_link
= ethtool_op_get_link
,
1765 .get_drvinfo
= smsc911x_ethtool_getdrvinfo
,
1766 .nway_reset
= smsc911x_ethtool_nwayreset
,
1767 .get_msglevel
= smsc911x_ethtool_getmsglevel
,
1768 .set_msglevel
= smsc911x_ethtool_setmsglevel
,
1769 .get_regs_len
= smsc911x_ethtool_getregslen
,
1770 .get_regs
= smsc911x_ethtool_getregs
,
1771 .get_eeprom_len
= smsc911x_ethtool_get_eeprom_len
,
1772 .get_eeprom
= smsc911x_ethtool_get_eeprom
,
1773 .set_eeprom
= smsc911x_ethtool_set_eeprom
,
1776 static const struct net_device_ops smsc911x_netdev_ops
= {
1777 .ndo_open
= smsc911x_open
,
1778 .ndo_stop
= smsc911x_stop
,
1779 .ndo_start_xmit
= smsc911x_hard_start_xmit
,
1780 .ndo_get_stats
= smsc911x_get_stats
,
1781 .ndo_set_multicast_list
= smsc911x_set_multicast_list
,
1782 .ndo_do_ioctl
= smsc911x_do_ioctl
,
1783 .ndo_change_mtu
= eth_change_mtu
,
1784 .ndo_validate_addr
= eth_validate_addr
,
1785 .ndo_set_mac_address
= smsc911x_set_mac_address
,
1786 #ifdef CONFIG_NET_POLL_CONTROLLER
1787 .ndo_poll_controller
= smsc911x_poll_controller
,
1791 /* copies the current mac address from hardware to dev->dev_addr */
1792 static void __devinit
smsc911x_read_mac_address(struct net_device
*dev
)
1794 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1795 u32 mac_high16
= smsc911x_mac_read(pdata
, ADDRH
);
1796 u32 mac_low32
= smsc911x_mac_read(pdata
, ADDRL
);
1798 dev
->dev_addr
[0] = (u8
)(mac_low32
);
1799 dev
->dev_addr
[1] = (u8
)(mac_low32
>> 8);
1800 dev
->dev_addr
[2] = (u8
)(mac_low32
>> 16);
1801 dev
->dev_addr
[3] = (u8
)(mac_low32
>> 24);
1802 dev
->dev_addr
[4] = (u8
)(mac_high16
);
1803 dev
->dev_addr
[5] = (u8
)(mac_high16
>> 8);
1806 /* Initializing private device structures, only called from probe */
1807 static int __devinit
smsc911x_init(struct net_device
*dev
)
1809 struct smsc911x_data
*pdata
= netdev_priv(dev
);
1810 unsigned int byte_test
;
1812 SMSC_TRACE(PROBE
, "Driver Parameters:");
1813 SMSC_TRACE(PROBE
, "LAN base: 0x%08lX",
1814 (unsigned long)pdata
->ioaddr
);
1815 SMSC_TRACE(PROBE
, "IRQ: %d", dev
->irq
);
1816 SMSC_TRACE(PROBE
, "PHY will be autodetected.");
1818 spin_lock_init(&pdata
->dev_lock
);
1820 if (pdata
->ioaddr
== 0) {
1821 SMSC_WARNING(PROBE
, "pdata->ioaddr: 0x00000000");
1825 /* Check byte ordering */
1826 byte_test
= smsc911x_reg_read(pdata
, BYTE_TEST
);
1827 SMSC_TRACE(PROBE
, "BYTE_TEST: 0x%08X", byte_test
);
1828 if (byte_test
== 0x43218765) {
1829 SMSC_TRACE(PROBE
, "BYTE_TEST looks swapped, "
1830 "applying WORD_SWAP");
1831 smsc911x_reg_write(pdata
, WORD_SWAP
, 0xffffffff);
1833 /* 1 dummy read of BYTE_TEST is needed after a write to
1834 * WORD_SWAP before its contents are valid */
1835 byte_test
= smsc911x_reg_read(pdata
, BYTE_TEST
);
1837 byte_test
= smsc911x_reg_read(pdata
, BYTE_TEST
);
1840 if (byte_test
!= 0x87654321) {
1841 SMSC_WARNING(DRV
, "BYTE_TEST: 0x%08X", byte_test
);
1842 if (((byte_test
>> 16) & 0xFFFF) == (byte_test
& 0xFFFF)) {
1844 "top 16 bits equal to bottom 16 bits");
1845 SMSC_TRACE(PROBE
, "This may mean the chip is set "
1846 "for 32 bit while the bus is reading 16 bit");
1851 /* Default generation to zero (all workarounds apply) */
1852 pdata
->generation
= 0;
1854 pdata
->idrev
= smsc911x_reg_read(pdata
, ID_REV
);
1855 switch (pdata
->idrev
& 0xFFFF0000) {
1860 /* LAN911[5678] family */
1861 pdata
->generation
= pdata
->idrev
& 0x0000FFFF;
1868 /* LAN921[5678] family */
1869 pdata
->generation
= 3;
1876 /* LAN9210/LAN9211/LAN9220/LAN9221 */
1877 pdata
->generation
= 4;
1881 SMSC_WARNING(PROBE
, "LAN911x not identified, idrev: 0x%08X",
1886 SMSC_TRACE(PROBE
, "LAN911x identified, idrev: 0x%08X, generation: %d",
1887 pdata
->idrev
, pdata
->generation
);
1889 if (pdata
->generation
== 0)
1891 "This driver is not intended for this chip revision");
1893 /* workaround for platforms without an eeprom, where the mac address
1894 * is stored elsewhere and set by the bootloader. This saves the
1895 * mac address before resetting the device */
1896 if (pdata
->config
.flags
& SMSC911X_SAVE_MAC_ADDRESS
)
1897 smsc911x_read_mac_address(dev
);
1899 /* Reset the LAN911x */
1900 if (smsc911x_soft_reset(pdata
))
1903 /* Disable all interrupt sources until we bring the device up */
1904 smsc911x_reg_write(pdata
, INT_EN
, 0);
1907 dev
->flags
|= IFF_MULTICAST
;
1908 netif_napi_add(dev
, &pdata
->napi
, smsc911x_poll
, SMSC_NAPI_WEIGHT
);
1909 dev
->netdev_ops
= &smsc911x_netdev_ops
;
1910 dev
->ethtool_ops
= &smsc911x_ethtool_ops
;
1915 static int __devexit
smsc911x_drv_remove(struct platform_device
*pdev
)
1917 struct net_device
*dev
;
1918 struct smsc911x_data
*pdata
;
1919 struct resource
*res
;
1921 dev
= platform_get_drvdata(pdev
);
1923 pdata
= netdev_priv(dev
);
1925 BUG_ON(!pdata
->ioaddr
);
1926 BUG_ON(!pdata
->phy_dev
);
1928 SMSC_TRACE(IFDOWN
, "Stopping driver.");
1930 phy_disconnect(pdata
->phy_dev
);
1931 pdata
->phy_dev
= NULL
;
1932 mdiobus_unregister(pdata
->mii_bus
);
1933 mdiobus_free(pdata
->mii_bus
);
1935 platform_set_drvdata(pdev
, NULL
);
1936 unregister_netdev(dev
);
1937 free_irq(dev
->irq
, dev
);
1938 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
1941 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1943 release_mem_region(res
->start
, resource_size(res
));
1945 iounmap(pdata
->ioaddr
);
1952 static int __devinit
smsc911x_drv_probe(struct platform_device
*pdev
)
1954 struct net_device
*dev
;
1955 struct smsc911x_data
*pdata
;
1956 struct smsc911x_platform_config
*config
= pdev
->dev
.platform_data
;
1957 struct resource
*res
, *irq_res
;
1958 unsigned int intcfg
= 0;
1959 int res_size
, irq_flags
;
1962 pr_info("%s: Driver version %s.\n", SMSC_CHIPNAME
, SMSC_DRV_VERSION
);
1964 /* platform data specifies irq & dynamic bus configuration */
1965 if (!pdev
->dev
.platform_data
) {
1966 pr_warning("%s: platform_data not provided\n", SMSC_CHIPNAME
);
1971 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
1974 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1976 pr_warning("%s: Could not allocate resource.\n",
1981 res_size
= resource_size(res
);
1983 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1985 pr_warning("%s: Could not allocate irq resource.\n",
1991 if (!request_mem_region(res
->start
, res_size
, SMSC_CHIPNAME
)) {
1996 dev
= alloc_etherdev(sizeof(struct smsc911x_data
));
1998 pr_warning("%s: Could not allocate device.\n", SMSC_CHIPNAME
);
2000 goto out_release_io_1
;
2003 SET_NETDEV_DEV(dev
, &pdev
->dev
);
2005 pdata
= netdev_priv(dev
);
2007 dev
->irq
= irq_res
->start
;
2008 irq_flags
= irq_res
->flags
& IRQF_TRIGGER_MASK
;
2009 pdata
->ioaddr
= ioremap_nocache(res
->start
, res_size
);
2011 /* copy config parameters across to pdata */
2012 memcpy(&pdata
->config
, config
, sizeof(pdata
->config
));
2015 pdata
->msg_enable
= ((1 << debug
) - 1);
2017 if (pdata
->ioaddr
== NULL
) {
2019 "Error smsc911x base address invalid");
2021 goto out_free_netdev_2
;
2024 retval
= smsc911x_init(dev
);
2026 goto out_unmap_io_3
;
2028 /* configure irq polarity and type before connecting isr */
2029 if (pdata
->config
.irq_polarity
== SMSC911X_IRQ_POLARITY_ACTIVE_HIGH
)
2030 intcfg
|= INT_CFG_IRQ_POL_
;
2032 if (pdata
->config
.irq_type
== SMSC911X_IRQ_TYPE_PUSH_PULL
)
2033 intcfg
|= INT_CFG_IRQ_TYPE_
;
2035 smsc911x_reg_write(pdata
, INT_CFG
, intcfg
);
2037 /* Ensure interrupts are globally disabled before connecting ISR */
2038 smsc911x_reg_write(pdata
, INT_EN
, 0);
2039 smsc911x_reg_write(pdata
, INT_STS
, 0xFFFFFFFF);
2041 retval
= request_irq(dev
->irq
, smsc911x_irqhandler
,
2042 irq_flags
| IRQF_SHARED
, dev
->name
, dev
);
2045 "Unable to claim requested irq: %d", dev
->irq
);
2046 goto out_unmap_io_3
;
2049 platform_set_drvdata(pdev
, dev
);
2051 retval
= register_netdev(dev
);
2054 "Error %i registering device", retval
);
2055 goto out_unset_drvdata_4
;
2057 SMSC_TRACE(PROBE
, "Network interface: \"%s\"", dev
->name
);
2060 spin_lock_init(&pdata
->mac_lock
);
2062 retval
= smsc911x_mii_init(pdev
, dev
);
2065 "Error %i initialising mii", retval
);
2066 goto out_unregister_netdev_5
;
2069 spin_lock_irq(&pdata
->mac_lock
);
2071 /* Check if mac address has been specified when bringing interface up */
2072 if (is_valid_ether_addr(dev
->dev_addr
)) {
2073 smsc911x_set_hw_mac_address(pdata
, dev
->dev_addr
);
2074 SMSC_TRACE(PROBE
, "MAC Address is specified by configuration");
2076 /* Try reading mac address from device. if EEPROM is present
2077 * it will already have been set */
2078 smsc911x_read_mac_address(dev
);
2080 if (is_valid_ether_addr(dev
->dev_addr
)) {
2081 /* eeprom values are valid so use them */
2083 "Mac Address is read from LAN911x EEPROM");
2085 /* eeprom values are invalid, generate random MAC */
2086 random_ether_addr(dev
->dev_addr
);
2087 smsc911x_set_hw_mac_address(pdata
, dev
->dev_addr
);
2089 "MAC Address is set to random_ether_addr");
2093 spin_unlock_irq(&pdata
->mac_lock
);
2095 dev_info(&dev
->dev
, "MAC Address: %pM\n", dev
->dev_addr
);
2099 out_unregister_netdev_5
:
2100 unregister_netdev(dev
);
2101 out_unset_drvdata_4
:
2102 platform_set_drvdata(pdev
, NULL
);
2103 free_irq(dev
->irq
, dev
);
2105 iounmap(pdata
->ioaddr
);
2109 release_mem_region(res
->start
, resource_size(res
));
2115 /* This implementation assumes the devices remains powered on its VDDVARIO
2116 * pins during suspend. */
2118 /* TODO: implement freeze/thaw callbacks for hibernation.*/
2120 static int smsc911x_suspend(struct device
*dev
)
2122 struct net_device
*ndev
= dev_get_drvdata(dev
);
2123 struct smsc911x_data
*pdata
= netdev_priv(ndev
);
2125 /* enable wake on LAN, energy detection and the external PME
2127 smsc911x_reg_write(pdata
, PMT_CTRL
,
2128 PMT_CTRL_PM_MODE_D1_
| PMT_CTRL_WOL_EN_
|
2129 PMT_CTRL_ED_EN_
| PMT_CTRL_PME_EN_
);
2134 static int smsc911x_resume(struct device
*dev
)
2136 struct net_device
*ndev
= dev_get_drvdata(dev
);
2137 struct smsc911x_data
*pdata
= netdev_priv(ndev
);
2138 unsigned int to
= 100;
2140 /* Note 3.11 from the datasheet:
2141 * "When the LAN9220 is in a power saving state, a write of any
2142 * data to the BYTE_TEST register will wake-up the device."
2144 smsc911x_reg_write(pdata
, BYTE_TEST
, 0);
2146 /* poll the READY bit in PMT_CTRL. Any other access to the device is
2147 * forbidden while this bit isn't set. Try for 100ms and return -EIO
2149 while (!(smsc911x_reg_read(pdata
, PMT_CTRL
) & PMT_CTRL_READY_
) && --to
)
2152 return (to
== 0) ? -EIO
: 0;
2155 static struct dev_pm_ops smsc911x_pm_ops
= {
2156 .suspend
= smsc911x_suspend
,
2157 .resume
= smsc911x_resume
,
2160 #define SMSC911X_PM_OPS (&smsc911x_pm_ops)
2163 #define SMSC911X_PM_OPS NULL
2166 static struct platform_driver smsc911x_driver
= {
2167 .probe
= smsc911x_drv_probe
,
2168 .remove
= __devexit_p(smsc911x_drv_remove
),
2170 .name
= SMSC_CHIPNAME
,
2171 .owner
= THIS_MODULE
,
2172 .pm
= SMSC911X_PM_OPS
,
2176 /* Entry point for loading the module */
2177 static int __init
smsc911x_init_module(void)
2179 return platform_driver_register(&smsc911x_driver
);
2182 /* entry point for unloading the module */
2183 static void __exit
smsc911x_cleanup_module(void)
2185 platform_driver_unregister(&smsc911x_driver
);
2188 module_init(smsc911x_init_module
);
2189 module_exit(smsc911x_cleanup_module
);