3 * This is a driver for SMSC's LAN911{5,6,7,8} single-chip Ethernet devices.
5 * Copyright (C) 2005 Sensoria Corp
6 * Derived from the unified SMC91x driver by Nicolas Pitre
7 * and the smsc911x.c reference driver by SMSC
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * watchdog = TX watchdog timeout
25 * tx_fifo_kb = Size of TX FIFO in KB
28 * 04/16/05 Dustin McIntire Initial version
30 static const char version
[] =
31 "smc911x.c: v1.0 04-16-2005 by Dustin McIntire <dustin@sensoria.com>\n";
33 /* Debugging options */
34 #define ENABLE_SMC_DEBUG_RX 0
35 #define ENABLE_SMC_DEBUG_TX 0
36 #define ENABLE_SMC_DEBUG_DMA 0
37 #define ENABLE_SMC_DEBUG_PKTS 0
38 #define ENABLE_SMC_DEBUG_MISC 0
39 #define ENABLE_SMC_DEBUG_FUNC 0
41 #define SMC_DEBUG_RX ((ENABLE_SMC_DEBUG_RX ? 1 : 0) << 0)
42 #define SMC_DEBUG_TX ((ENABLE_SMC_DEBUG_TX ? 1 : 0) << 1)
43 #define SMC_DEBUG_DMA ((ENABLE_SMC_DEBUG_DMA ? 1 : 0) << 2)
44 #define SMC_DEBUG_PKTS ((ENABLE_SMC_DEBUG_PKTS ? 1 : 0) << 3)
45 #define SMC_DEBUG_MISC ((ENABLE_SMC_DEBUG_MISC ? 1 : 0) << 4)
46 #define SMC_DEBUG_FUNC ((ENABLE_SMC_DEBUG_FUNC ? 1 : 0) << 5)
49 #define SMC_DEBUG ( SMC_DEBUG_RX | \
58 #include <linux/init.h>
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/slab.h>
63 #include <linux/delay.h>
64 #include <linux/interrupt.h>
65 #include <linux/errno.h>
66 #include <linux/ioport.h>
67 #include <linux/crc32.h>
68 #include <linux/device.h>
69 #include <linux/platform_device.h>
70 #include <linux/spinlock.h>
71 #include <linux/ethtool.h>
72 #include <linux/mii.h>
73 #include <linux/workqueue.h>
75 #include <linux/netdevice.h>
76 #include <linux/etherdevice.h>
77 #include <linux/skbuff.h>
85 * Transmit timeout, default 5 seconds.
87 static int watchdog
= 5000;
88 module_param(watchdog
, int, 0400);
89 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");
91 static int tx_fifo_kb
=8;
92 module_param(tx_fifo_kb
, int, 0400);
93 MODULE_PARM_DESC(tx_fifo_kb
,"transmit FIFO size in KB (1<x<15)(default=8)");
95 MODULE_LICENSE("GPL");
98 * The internal workings of the driver. If you are changing anything
99 * here with the SMC stuff, you should have the datasheet and know
100 * what you are doing.
102 #define CARDNAME "smc911x"
105 * Use power-down feature of the chip
110 /* store this information for the driver.. */
111 struct smc911x_local
{
113 * If I have to wait until the DMA is finished and ready to reload a
114 * packet, I will store the skbuff here. Then, the DMA will send it
117 struct sk_buff
*pending_tx_skb
;
120 * these are things that the kernel wants me to keep, so users
121 * can find out semi-useless statistics of how well the card is
124 struct net_device_stats stats
;
126 /* version/revision of the SMC911x chip */
136 /* Contains the current active receive/phy mode */
142 struct mii_if_info mii
;
145 struct work_struct phy_configure
;
152 /* DMA needs the physical address of the chip */
158 struct sk_buff
*current_rx_skb
;
159 struct sk_buff
*current_tx_skb
;
165 #define DBG(n, args...) \
167 if (SMC_DEBUG & (n)) \
171 #define PRINTK(args...) printk(args)
173 #define DBG(n, args...) do { } while (0)
174 #define PRINTK(args...) printk(KERN_DEBUG args)
177 #if SMC_DEBUG_PKTS > 0
178 static void PRINT_PKT(u_char
*buf
, int length
)
185 remainder
= length
% 16;
187 for (i
= 0; i
< lines
; i
++) {
189 for (cur
= 0; cur
< 8; cur
++) {
193 printk("%02x%02x ", a
, b
);
197 for (i
= 0; i
< remainder
/2 ; i
++) {
201 printk("%02x%02x ", a
, b
);
206 #define PRINT_PKT(x...) do { } while (0)
210 /* this enables an interrupt in the interrupt mask register */
211 #define SMC_ENABLE_INT(x) do { \
212 unsigned int __mask; \
213 unsigned long __flags; \
214 spin_lock_irqsave(&lp->lock, __flags); \
215 __mask = SMC_GET_INT_EN(); \
217 SMC_SET_INT_EN(__mask); \
218 spin_unlock_irqrestore(&lp->lock, __flags); \
221 /* this disables an interrupt from the interrupt mask register */
222 #define SMC_DISABLE_INT(x) do { \
223 unsigned int __mask; \
224 unsigned long __flags; \
225 spin_lock_irqsave(&lp->lock, __flags); \
226 __mask = SMC_GET_INT_EN(); \
228 SMC_SET_INT_EN(__mask); \
229 spin_unlock_irqrestore(&lp->lock, __flags); \
233 * this does a soft reset on the device
235 static void smc911x_reset(struct net_device
*dev
)
237 unsigned long ioaddr
= dev
->base_addr
;
238 struct smc911x_local
*lp
= netdev_priv(dev
);
239 unsigned int reg
, timeout
=0, resets
=1;
242 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
244 /* Take out of PM setting first */
245 if ((SMC_GET_PMT_CTRL() & PMT_CTRL_READY_
) == 0) {
246 /* Write to the bytetest will take out of powerdown */
247 SMC_SET_BYTE_TEST(0);
251 reg
= SMC_GET_PMT_CTRL() & PMT_CTRL_READY_
;
252 } while ( timeout
-- && !reg
);
254 PRINTK("%s: smc911x_reset timeout waiting for PM restore\n", dev
->name
);
259 /* Disable all interrupts */
260 spin_lock_irqsave(&lp
->lock
, flags
);
262 spin_unlock_irqrestore(&lp
->lock
, flags
);
265 SMC_SET_HW_CFG(HW_CFG_SRST_
);
269 reg
= SMC_GET_HW_CFG();
270 /* If chip indicates reset timeout then try again */
271 if (reg
& HW_CFG_SRST_TO_
) {
272 PRINTK("%s: chip reset timeout, retrying...\n", dev
->name
);
276 } while ( timeout
-- && (reg
& HW_CFG_SRST_
));
279 PRINTK("%s: smc911x_reset timeout waiting for reset\n", dev
->name
);
283 /* make sure EEPROM has finished loading before setting GPIO_CFG */
285 while ( timeout
-- && (SMC_GET_E2P_CMD() & E2P_CMD_EPC_BUSY_
)) {
289 PRINTK("%s: smc911x_reset timeout waiting for EEPROM busy\n", dev
->name
);
293 /* Initialize interrupts */
297 /* Reset the FIFO level and flow control settings */
298 SMC_SET_HW_CFG((lp
->tx_fifo_kb
& 0xF) << 16);
299 //TODO: Figure out what appropriate pause time is
300 SMC_SET_FLOW(FLOW_FCPT_
| FLOW_FCEN_
);
301 SMC_SET_AFC_CFG(lp
->afc_cfg
);
304 /* Set to LED outputs */
305 SMC_SET_GPIO_CFG(0x70070000);
308 * Deassert IRQ for 1*10us for edge type interrupts
309 * and drive IRQ pin push-pull
311 SMC_SET_IRQ_CFG( (1 << 24) | INT_CFG_IRQ_EN_
| INT_CFG_IRQ_TYPE_
);
313 /* clear anything saved */
314 if (lp
->pending_tx_skb
!= NULL
) {
315 dev_kfree_skb (lp
->pending_tx_skb
);
316 lp
->pending_tx_skb
= NULL
;
317 lp
->stats
.tx_errors
++;
318 lp
->stats
.tx_aborted_errors
++;
323 * Enable Interrupts, Receive, and Transmit
325 static void smc911x_enable(struct net_device
*dev
)
327 unsigned long ioaddr
= dev
->base_addr
;
328 struct smc911x_local
*lp
= netdev_priv(dev
);
329 unsigned mask
, cfg
, cr
;
332 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
334 SMC_SET_MAC_ADDR(dev
->dev_addr
);
337 cfg
= SMC_GET_HW_CFG();
338 cfg
&= HW_CFG_TX_FIF_SZ_
| 0xFFF;
341 SMC_SET_FIFO_TDA(0xFF);
342 /* Update TX stats on every 64 packets received or every 1 sec */
343 SMC_SET_FIFO_TSL(64);
344 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_
| 10000);
346 spin_lock_irqsave(&lp
->lock
, flags
);
348 cr
|= MAC_CR_TXEN_
| MAC_CR_HBDIS_
;
350 SMC_SET_TX_CFG(TX_CFG_TX_ON_
);
351 spin_unlock_irqrestore(&lp
->lock
, flags
);
353 /* Add 2 byte padding to start of packets */
354 SMC_SET_RX_CFG((2<<8) & RX_CFG_RXDOFF_
);
356 /* Turn on receiver and enable RX */
357 if (cr
& MAC_CR_RXEN_
)
358 DBG(SMC_DEBUG_RX
, "%s: Receiver already enabled\n", dev
->name
);
360 spin_lock_irqsave(&lp
->lock
, flags
);
361 SMC_SET_MAC_CR( cr
| MAC_CR_RXEN_
);
362 spin_unlock_irqrestore(&lp
->lock
, flags
);
364 /* Interrupt on every received packet */
365 SMC_SET_FIFO_RSA(0x01);
366 SMC_SET_FIFO_RSL(0x00);
368 /* now, enable interrupts */
369 mask
= INT_EN_TDFA_EN_
| INT_EN_TSFL_EN_
| INT_EN_RSFL_EN_
|
370 INT_EN_GPT_INT_EN_
| INT_EN_RXDFH_INT_EN_
| INT_EN_RXE_EN_
|
372 if (IS_REV_A(lp
->revision
))
373 mask
|=INT_EN_RDFL_EN_
;
375 mask
|=INT_EN_RDFO_EN_
;
377 SMC_ENABLE_INT(mask
);
381 * this puts the device in an inactive state
383 static void smc911x_shutdown(struct net_device
*dev
)
385 unsigned long ioaddr
= dev
->base_addr
;
386 struct smc911x_local
*lp
= netdev_priv(dev
);
390 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", CARDNAME
, __FUNCTION__
);
395 /* Turn of Rx and TX */
396 spin_lock_irqsave(&lp
->lock
, flags
);
398 cr
&= ~(MAC_CR_TXEN_
| MAC_CR_RXEN_
| MAC_CR_HBDIS_
);
400 SMC_SET_TX_CFG(TX_CFG_STOP_TX_
);
401 spin_unlock_irqrestore(&lp
->lock
, flags
);
404 static inline void smc911x_drop_pkt(struct net_device
*dev
)
406 unsigned long ioaddr
= dev
->base_addr
;
407 unsigned int fifo_count
, timeout
, reg
;
409 DBG(SMC_DEBUG_FUNC
| SMC_DEBUG_RX
, "%s: --> %s\n", CARDNAME
, __FUNCTION__
);
410 fifo_count
= SMC_GET_RX_FIFO_INF() & 0xFFFF;
411 if (fifo_count
<= 4) {
412 /* Manually dump the packet data */
416 /* Fast forward through the bad packet */
417 SMC_SET_RX_DP_CTRL(RX_DP_CTRL_FFWD_BUSY_
);
421 reg
= SMC_GET_RX_DP_CTRL() & RX_DP_CTRL_FFWD_BUSY_
;
422 } while ( timeout
-- && reg
);
424 PRINTK("%s: timeout waiting for RX fast forward\n", dev
->name
);
430 * This is the procedure to handle the receipt of a packet.
431 * It should be called after checking for packet presence in
432 * the RX status FIFO. It must be called with the spin lock
435 static inline void smc911x_rcv(struct net_device
*dev
)
437 struct smc911x_local
*lp
= netdev_priv(dev
);
438 unsigned long ioaddr
= dev
->base_addr
;
439 unsigned int pkt_len
, status
;
443 DBG(SMC_DEBUG_FUNC
| SMC_DEBUG_RX
, "%s: --> %s\n",
444 dev
->name
, __FUNCTION__
);
445 status
= SMC_GET_RX_STS_FIFO();
446 DBG(SMC_DEBUG_RX
, "%s: Rx pkt len %d status 0x%08x \n",
447 dev
->name
, (status
& 0x3fff0000) >> 16, status
& 0xc000ffff);
448 pkt_len
= (status
& RX_STS_PKT_LEN_
) >> 16;
449 if (status
& RX_STS_ES_
) {
450 /* Deal with a bad packet */
451 lp
->stats
.rx_errors
++;
452 if (status
& RX_STS_CRC_ERR_
)
453 lp
->stats
.rx_crc_errors
++;
455 if (status
& RX_STS_LEN_ERR_
)
456 lp
->stats
.rx_length_errors
++;
457 if (status
& RX_STS_MCAST_
)
458 lp
->stats
.multicast
++;
460 /* Remove the bad packet data from the RX FIFO */
461 smc911x_drop_pkt(dev
);
463 /* Receive a valid packet */
464 /* Alloc a buffer with extra room for DMA alignment */
465 skb
=dev_alloc_skb(pkt_len
+32);
466 if (unlikely(skb
== NULL
)) {
467 PRINTK( "%s: Low memory, rcvd packet dropped.\n",
469 lp
->stats
.rx_dropped
++;
470 smc911x_drop_pkt(dev
);
473 /* Align IP header to 32 bits
474 * Note that the device is configured to add a 2
475 * byte padding to the packet start, so we really
476 * want to write to the orignal data pointer */
479 skb_put(skb
,pkt_len
-4);
483 /* Lower the FIFO threshold if possible */
484 fifo
= SMC_GET_FIFO_INT();
485 if (fifo
& 0xFF) fifo
--;
486 DBG(SMC_DEBUG_RX
, "%s: Setting RX stat FIFO threshold to %d\n",
487 dev
->name
, fifo
& 0xff);
488 SMC_SET_FIFO_INT(fifo
);
490 SMC_SET_RX_CFG(RX_CFG_RX_END_ALGN16_
| ((2<<8) & RX_CFG_RXDOFF_
));
491 lp
->rxdma_active
= 1;
492 lp
->current_rx_skb
= skb
;
493 SMC_PULL_DATA(data
, (pkt_len
+2+15) & ~15);
494 /* Packet processing deferred to DMA RX interrupt */
497 SMC_SET_RX_CFG(RX_CFG_RX_END_ALGN4_
| ((2<<8) & RX_CFG_RXDOFF_
));
498 SMC_PULL_DATA(data
, pkt_len
+2+3);
500 DBG(SMC_DEBUG_PKTS
, "%s: Received packet\n", dev
->name
,);
501 PRINT_PKT(data
, ((pkt_len
- 4) <= 64) ? pkt_len
- 4 : 64);
502 dev
->last_rx
= jiffies
;
504 skb
->protocol
= eth_type_trans(skb
, dev
);
506 lp
->stats
.rx_packets
++;
507 lp
->stats
.rx_bytes
+= pkt_len
-4;
513 * This is called to actually send a packet to the chip.
515 static void smc911x_hardware_send_pkt(struct net_device
*dev
)
517 struct smc911x_local
*lp
= netdev_priv(dev
);
518 unsigned long ioaddr
= dev
->base_addr
;
520 unsigned int cmdA
, cmdB
, len
;
524 DBG(SMC_DEBUG_FUNC
| SMC_DEBUG_TX
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
525 BUG_ON(lp
->pending_tx_skb
== NULL
);
527 skb
= lp
->pending_tx_skb
;
528 lp
->pending_tx_skb
= NULL
;
530 /* cmdA {25:24] data alignment [20:16] start offset [10:0] buffer length */
531 /* cmdB {31:16] pkt tag [10:0] length */
533 /* 16 byte buffer alignment mode */
534 buf
= (char*)((u32
)(skb
->data
) & ~0xF);
535 len
= (skb
->len
+ 0xF + ((u32
)skb
->data
& 0xF)) & ~0xF;
536 cmdA
= (1<<24) | (((u32
)skb
->data
& 0xF)<<16) |
537 TX_CMD_A_INT_FIRST_SEG_
| TX_CMD_A_INT_LAST_SEG_
|
540 buf
= (char*)((u32
)skb
->data
& ~0x3);
541 len
= (skb
->len
+ 3 + ((u32
)skb
->data
& 3)) & ~0x3;
542 cmdA
= (((u32
)skb
->data
& 0x3) << 16) |
543 TX_CMD_A_INT_FIRST_SEG_
| TX_CMD_A_INT_LAST_SEG_
|
546 /* tag is packet length so we can use this in stats update later */
547 cmdB
= (skb
->len
<< 16) | (skb
->len
& 0x7FF);
549 DBG(SMC_DEBUG_TX
, "%s: TX PKT LENGTH 0x%04x (%d) BUF 0x%p CMDA 0x%08x CMDB 0x%08x\n",
550 dev
->name
, len
, len
, buf
, cmdA
, cmdB
);
551 SMC_SET_TX_FIFO(cmdA
);
552 SMC_SET_TX_FIFO(cmdB
);
554 DBG(SMC_DEBUG_PKTS
, "%s: Transmitted packet\n", dev
->name
);
555 PRINT_PKT(buf
, len
<= 64 ? len
: 64);
557 /* Send pkt via PIO or DMA */
559 lp
->current_tx_skb
= skb
;
560 SMC_PUSH_DATA(buf
, len
);
561 /* DMA complete IRQ will free buffer and set jiffies */
563 SMC_PUSH_DATA(buf
, len
);
564 dev
->trans_start
= jiffies
;
567 spin_lock_irqsave(&lp
->lock
, flags
);
568 if (!lp
->tx_throttle
) {
569 netif_wake_queue(dev
);
571 spin_unlock_irqrestore(&lp
->lock
, flags
);
572 SMC_ENABLE_INT(INT_EN_TDFA_EN_
| INT_EN_TSFL_EN_
);
576 * Since I am not sure if I will have enough room in the chip's ram
577 * to store the packet, I call this routine which either sends it
578 * now, or set the card to generates an interrupt when ready
581 static int smc911x_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
583 struct smc911x_local
*lp
= netdev_priv(dev
);
584 unsigned long ioaddr
= dev
->base_addr
;
588 DBG(SMC_DEBUG_FUNC
| SMC_DEBUG_TX
, "%s: --> %s\n",
589 dev
->name
, __FUNCTION__
);
591 BUG_ON(lp
->pending_tx_skb
!= NULL
);
593 free
= SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TDFREE_
;
594 DBG(SMC_DEBUG_TX
, "%s: TX free space %d\n", dev
->name
, free
);
596 /* Turn off the flow when running out of space in FIFO */
597 if (free
<= SMC911X_TX_FIFO_LOW_THRESHOLD
) {
598 DBG(SMC_DEBUG_TX
, "%s: Disabling data flow due to low FIFO space (%d)\n",
600 spin_lock_irqsave(&lp
->lock
, flags
);
601 /* Reenable when at least 1 packet of size MTU present */
602 SMC_SET_FIFO_TDA((SMC911X_TX_FIFO_LOW_THRESHOLD
)/64);
604 netif_stop_queue(dev
);
605 spin_unlock_irqrestore(&lp
->lock
, flags
);
608 /* Drop packets when we run out of space in TX FIFO
609 * Account for overhead required for:
611 * Tx command words 8 bytes
612 * Start offset 15 bytes
613 * End padding 15 bytes
615 if (unlikely(free
< (skb
->len
+ 8 + 15 + 15))) {
616 printk("%s: No Tx free space %d < %d\n",
617 dev
->name
, free
, skb
->len
);
618 lp
->pending_tx_skb
= NULL
;
619 lp
->stats
.tx_errors
++;
620 lp
->stats
.tx_dropped
++;
627 /* If the DMA is already running then defer this packet Tx until
628 * the DMA IRQ starts it
630 spin_lock_irqsave(&lp
->lock
, flags
);
631 if (lp
->txdma_active
) {
632 DBG(SMC_DEBUG_TX
| SMC_DEBUG_DMA
, "%s: Tx DMA running, deferring packet\n", dev
->name
);
633 lp
->pending_tx_skb
= skb
;
634 netif_stop_queue(dev
);
635 spin_unlock_irqrestore(&lp
->lock
, flags
);
638 DBG(SMC_DEBUG_TX
| SMC_DEBUG_DMA
, "%s: Activating Tx DMA\n", dev
->name
);
639 lp
->txdma_active
= 1;
641 spin_unlock_irqrestore(&lp
->lock
, flags
);
644 lp
->pending_tx_skb
= skb
;
645 smc911x_hardware_send_pkt(dev
);
651 * This handles a TX status interrupt, which is only called when:
652 * - a TX error occurred, or
653 * - TX of a packet completed.
655 static void smc911x_tx(struct net_device
*dev
)
657 unsigned long ioaddr
= dev
->base_addr
;
658 struct smc911x_local
*lp
= netdev_priv(dev
);
659 unsigned int tx_status
;
661 DBG(SMC_DEBUG_FUNC
| SMC_DEBUG_TX
, "%s: --> %s\n",
662 dev
->name
, __FUNCTION__
);
664 /* Collect the TX status */
665 while (((SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TSUSED_
) >> 16) != 0) {
666 DBG(SMC_DEBUG_TX
, "%s: Tx stat FIFO used 0x%04x\n",
668 (SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TSUSED_
) >> 16);
669 tx_status
= SMC_GET_TX_STS_FIFO();
670 lp
->stats
.tx_packets
++;
671 lp
->stats
.tx_bytes
+=tx_status
>>16;
672 DBG(SMC_DEBUG_TX
, "%s: Tx FIFO tag 0x%04x status 0x%04x\n",
673 dev
->name
, (tx_status
& 0xffff0000) >> 16,
674 tx_status
& 0x0000ffff);
675 /* count Tx errors, but ignore lost carrier errors when in
676 * full-duplex mode */
677 if ((tx_status
& TX_STS_ES_
) && !(lp
->ctl_rfduplx
&&
678 !(tx_status
& 0x00000306))) {
679 lp
->stats
.tx_errors
++;
681 if (tx_status
& TX_STS_MANY_COLL_
) {
682 lp
->stats
.collisions
+=16;
683 lp
->stats
.tx_aborted_errors
++;
685 lp
->stats
.collisions
+=(tx_status
& TX_STS_COLL_CNT_
) >> 3;
687 /* carrier error only has meaning for half-duplex communication */
688 if ((tx_status
& (TX_STS_LOC_
| TX_STS_NO_CARR_
)) &&
690 lp
->stats
.tx_carrier_errors
++;
692 if (tx_status
& TX_STS_LATE_COLL_
) {
693 lp
->stats
.collisions
++;
694 lp
->stats
.tx_aborted_errors
++;
700 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
702 * Reads a register from the MII Management serial interface
705 static int smc911x_phy_read(struct net_device
*dev
, int phyaddr
, int phyreg
)
707 unsigned long ioaddr
= dev
->base_addr
;
708 unsigned int phydata
;
710 SMC_GET_MII(phyreg
, phyaddr
, phydata
);
712 DBG(SMC_DEBUG_MISC
, "%s: phyaddr=0x%x, phyreg=0x%02x, phydata=0x%04x\n",
713 __FUNCTION__
, phyaddr
, phyreg
, phydata
);
719 * Writes a register to the MII Management serial interface
721 static void smc911x_phy_write(struct net_device
*dev
, int phyaddr
, int phyreg
,
724 unsigned long ioaddr
= dev
->base_addr
;
726 DBG(SMC_DEBUG_MISC
, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
727 __FUNCTION__
, phyaddr
, phyreg
, phydata
);
729 SMC_SET_MII(phyreg
, phyaddr
, phydata
);
733 * Finds and reports the PHY address (115 and 117 have external
734 * PHY interface 118 has internal only
736 static void smc911x_phy_detect(struct net_device
*dev
)
738 unsigned long ioaddr
= dev
->base_addr
;
739 struct smc911x_local
*lp
= netdev_priv(dev
);
741 unsigned int cfg
, id1
, id2
;
743 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
748 * Scan all 32 PHY addresses if necessary, starting at
749 * PHY#1 to PHY#31, and then PHY#0 last.
751 switch(lp
->version
) {
754 cfg
= SMC_GET_HW_CFG();
755 if (cfg
& HW_CFG_EXT_PHY_DET_
) {
756 cfg
&= ~HW_CFG_PHY_CLK_SEL_
;
757 cfg
|= HW_CFG_PHY_CLK_SEL_CLK_DIS_
;
759 udelay(10); /* Wait for clocks to stop */
761 cfg
|= HW_CFG_EXT_PHY_EN_
;
763 udelay(10); /* Wait for clocks to stop */
765 cfg
&= ~HW_CFG_PHY_CLK_SEL_
;
766 cfg
|= HW_CFG_PHY_CLK_SEL_EXT_PHY_
;
768 udelay(10); /* Wait for clocks to stop */
770 cfg
|= HW_CFG_SMI_SEL_
;
773 for (phyaddr
= 1; phyaddr
< 32; ++phyaddr
) {
775 /* Read the PHY identifiers */
776 SMC_GET_PHY_ID1(phyaddr
& 31, id1
);
777 SMC_GET_PHY_ID2(phyaddr
& 31, id2
);
779 /* Make sure it is a valid identifier */
780 if (id1
!= 0x0000 && id1
!= 0xffff &&
781 id1
!= 0x8000 && id2
!= 0x0000 &&
782 id2
!= 0xffff && id2
!= 0x8000) {
783 /* Save the PHY's address */
784 lp
->mii
.phy_id
= phyaddr
& 31;
785 lp
->phy_type
= id1
<< 16 | id2
;
791 /* Internal media only */
792 SMC_GET_PHY_ID1(1, id1
);
793 SMC_GET_PHY_ID2(1, id2
);
794 /* Save the PHY's address */
796 lp
->phy_type
= id1
<< 16 | id2
;
799 DBG(SMC_DEBUG_MISC
, "%s: phy_id1=0x%x, phy_id2=0x%x phyaddr=0x%d\n",
800 dev
->name
, id1
, id2
, lp
->mii
.phy_id
);
804 * Sets the PHY to a configuration as determined by the user.
805 * Called with spin_lock held.
807 static int smc911x_phy_fixed(struct net_device
*dev
)
809 struct smc911x_local
*lp
= netdev_priv(dev
);
810 unsigned long ioaddr
= dev
->base_addr
;
811 int phyaddr
= lp
->mii
.phy_id
;
814 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
816 /* Enter Link Disable state */
817 SMC_GET_PHY_BMCR(phyaddr
, bmcr
);
819 SMC_SET_PHY_BMCR(phyaddr
, bmcr
);
822 * Set our fixed capabilities
823 * Disable auto-negotiation
825 bmcr
&= ~BMCR_ANENABLE
;
827 bmcr
|= BMCR_FULLDPLX
;
829 if (lp
->ctl_rspeed
== 100)
830 bmcr
|= BMCR_SPEED100
;
832 /* Write our capabilities to the phy control register */
833 SMC_SET_PHY_BMCR(phyaddr
, bmcr
);
835 /* Re-Configure the Receive/Phy Control register */
837 SMC_SET_PHY_BMCR(phyaddr
, bmcr
);
843 * smc911x_phy_reset - reset the phy
847 * Issue a software reset for the specified PHY and
848 * wait up to 100ms for the reset to complete. We should
849 * not access the PHY for 50ms after issuing the reset.
851 * The time to wait appears to be dependent on the PHY.
854 static int smc911x_phy_reset(struct net_device
*dev
, int phy
)
856 struct smc911x_local
*lp
= netdev_priv(dev
);
857 unsigned long ioaddr
= dev
->base_addr
;
862 DBG(SMC_DEBUG_FUNC
, "%s: --> %s()\n", dev
->name
, __FUNCTION__
);
864 spin_lock_irqsave(&lp
->lock
, flags
);
865 reg
= SMC_GET_PMT_CTRL();
867 reg
|= PMT_CTRL_PHY_RST_
;
868 SMC_SET_PMT_CTRL(reg
);
869 spin_unlock_irqrestore(&lp
->lock
, flags
);
870 for (timeout
= 2; timeout
; timeout
--) {
872 spin_lock_irqsave(&lp
->lock
, flags
);
873 reg
= SMC_GET_PMT_CTRL();
874 spin_unlock_irqrestore(&lp
->lock
, flags
);
875 if (!(reg
& PMT_CTRL_PHY_RST_
)) {
876 /* extra delay required because the phy may
877 * not be completed with its reset
878 * when PHY_BCR_RESET_ is cleared. 256us
879 * should suffice, but use 500us to be safe
886 return reg
& PMT_CTRL_PHY_RST_
;
890 * smc911x_phy_powerdown - powerdown phy
894 * Power down the specified PHY
896 static void smc911x_phy_powerdown(struct net_device
*dev
, int phy
)
898 unsigned long ioaddr
= dev
->base_addr
;
901 /* Enter Link Disable state */
902 SMC_GET_PHY_BMCR(phy
, bmcr
);
904 SMC_SET_PHY_BMCR(phy
, bmcr
);
908 * smc911x_phy_check_media - check the media status and adjust BMCR
910 * @init: set true for initialisation
912 * Select duplex mode depending on negotiation state. This
913 * also updates our carrier state.
915 static void smc911x_phy_check_media(struct net_device
*dev
, int init
)
917 struct smc911x_local
*lp
= netdev_priv(dev
);
918 unsigned long ioaddr
= dev
->base_addr
;
919 int phyaddr
= lp
->mii
.phy_id
;
920 unsigned int bmcr
, cr
;
922 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
924 if (mii_check_media(&lp
->mii
, netif_msg_link(lp
), init
)) {
925 /* duplex state has changed */
926 SMC_GET_PHY_BMCR(phyaddr
, bmcr
);
928 if (lp
->mii
.full_duplex
) {
929 DBG(SMC_DEBUG_MISC
, "%s: Configuring for full-duplex mode\n", dev
->name
);
930 bmcr
|= BMCR_FULLDPLX
;
931 cr
|= MAC_CR_RCVOWN_
;
933 DBG(SMC_DEBUG_MISC
, "%s: Configuring for half-duplex mode\n", dev
->name
);
934 bmcr
&= ~BMCR_FULLDPLX
;
935 cr
&= ~MAC_CR_RCVOWN_
;
937 SMC_SET_PHY_BMCR(phyaddr
, bmcr
);
943 * Configures the specified PHY through the MII management interface
944 * using Autonegotiation.
945 * Calls smc911x_phy_fixed() if the user has requested a certain config.
946 * If RPC ANEG bit is set, the media selection is dependent purely on
947 * the selection by the MII (either in the MII BMCR reg or the result
948 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
949 * is controlled by the RPC SPEED and RPC DPLX bits.
951 static void smc911x_phy_configure(void *data
)
953 struct net_device
*dev
= data
;
954 struct smc911x_local
*lp
= netdev_priv(dev
);
955 unsigned long ioaddr
= dev
->base_addr
;
956 int phyaddr
= lp
->mii
.phy_id
;
957 int my_phy_caps
; /* My PHY capabilities */
958 int my_ad_caps
; /* My Advertised capabilities */
962 DBG(SMC_DEBUG_FUNC
, "%s: --> %s()\n", dev
->name
, __FUNCTION__
);
965 * We should not be called if phy_type is zero.
967 if (lp
->phy_type
== 0)
968 goto smc911x_phy_configure_exit
;
970 if (smc911x_phy_reset(dev
, phyaddr
)) {
971 printk("%s: PHY reset timed out\n", dev
->name
);
972 goto smc911x_phy_configure_exit
;
974 spin_lock_irqsave(&lp
->lock
, flags
);
977 * Enable PHY Interrupts (for register 18)
978 * Interrupts listed here are enabled
980 SMC_SET_PHY_INT_MASK(phyaddr
, PHY_INT_MASK_ENERGY_ON_
|
981 PHY_INT_MASK_ANEG_COMP_
| PHY_INT_MASK_REMOTE_FAULT_
|
982 PHY_INT_MASK_LINK_DOWN_
);
984 /* If the user requested no auto neg, then go set his request */
985 if (lp
->mii
.force_media
) {
986 smc911x_phy_fixed(dev
);
987 goto smc911x_phy_configure_exit
;
990 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
991 SMC_GET_PHY_BMSR(phyaddr
, my_phy_caps
);
992 if (!(my_phy_caps
& BMSR_ANEGCAPABLE
)) {
993 printk(KERN_INFO
"Auto negotiation NOT supported\n");
994 smc911x_phy_fixed(dev
);
995 goto smc911x_phy_configure_exit
;
998 /* CSMA capable w/ both pauses */
999 my_ad_caps
= ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
;
1001 if (my_phy_caps
& BMSR_100BASE4
)
1002 my_ad_caps
|= ADVERTISE_100BASE4
;
1003 if (my_phy_caps
& BMSR_100FULL
)
1004 my_ad_caps
|= ADVERTISE_100FULL
;
1005 if (my_phy_caps
& BMSR_100HALF
)
1006 my_ad_caps
|= ADVERTISE_100HALF
;
1007 if (my_phy_caps
& BMSR_10FULL
)
1008 my_ad_caps
|= ADVERTISE_10FULL
;
1009 if (my_phy_caps
& BMSR_10HALF
)
1010 my_ad_caps
|= ADVERTISE_10HALF
;
1012 /* Disable capabilities not selected by our user */
1013 if (lp
->ctl_rspeed
!= 100)
1014 my_ad_caps
&= ~(ADVERTISE_100BASE4
|ADVERTISE_100FULL
|ADVERTISE_100HALF
);
1016 if (!lp
->ctl_rfduplx
)
1017 my_ad_caps
&= ~(ADVERTISE_100FULL
|ADVERTISE_10FULL
);
1019 /* Update our Auto-Neg Advertisement Register */
1020 SMC_SET_PHY_MII_ADV(phyaddr
, my_ad_caps
);
1021 lp
->mii
.advertising
= my_ad_caps
;
1024 * Read the register back. Without this, it appears that when
1025 * auto-negotiation is restarted, sometimes it isn't ready and
1026 * the link does not come up.
1029 SMC_GET_PHY_MII_ADV(phyaddr
, status
);
1031 DBG(SMC_DEBUG_MISC
, "%s: phy caps=0x%04x\n", dev
->name
, my_phy_caps
);
1032 DBG(SMC_DEBUG_MISC
, "%s: phy advertised caps=0x%04x\n", dev
->name
, my_ad_caps
);
1034 /* Restart auto-negotiation process in order to advertise my caps */
1035 SMC_SET_PHY_BMCR(phyaddr
, BMCR_ANENABLE
| BMCR_ANRESTART
);
1037 smc911x_phy_check_media(dev
, 1);
1039 smc911x_phy_configure_exit
:
1040 spin_unlock_irqrestore(&lp
->lock
, flags
);
1041 lp
->work_pending
= 0;
1045 * smc911x_phy_interrupt
1047 * Purpose: Handle interrupts relating to PHY register 18. This is
1048 * called from the "hard" interrupt handler under our private spinlock.
1050 static void smc911x_phy_interrupt(struct net_device
*dev
)
1052 struct smc911x_local
*lp
= netdev_priv(dev
);
1053 unsigned long ioaddr
= dev
->base_addr
;
1054 int phyaddr
= lp
->mii
.phy_id
;
1057 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1059 if (lp
->phy_type
== 0)
1062 smc911x_phy_check_media(dev
, 0);
1063 /* read to clear status bits */
1064 SMC_GET_PHY_INT_SRC(phyaddr
,status
);
1065 DBG(SMC_DEBUG_MISC
, "%s: PHY interrupt status 0x%04x\n",
1066 dev
->name
, status
& 0xffff);
1067 DBG(SMC_DEBUG_MISC
, "%s: AFC_CFG 0x%08x\n",
1068 dev
->name
, SMC_GET_AFC_CFG());
1071 /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
1074 * This is the main routine of the driver, to handle the device when
1075 * it needs some attention.
1077 static irqreturn_t
smc911x_interrupt(int irq
, void *dev_id
)
1079 struct net_device
*dev
= dev_id
;
1080 unsigned long ioaddr
= dev
->base_addr
;
1081 struct smc911x_local
*lp
= netdev_priv(dev
);
1082 unsigned int status
, mask
, timeout
;
1083 unsigned int rx_overrun
=0, cr
, pkts
;
1084 unsigned long flags
;
1086 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1088 spin_lock_irqsave(&lp
->lock
, flags
);
1090 /* Spurious interrupt check */
1091 if ((SMC_GET_IRQ_CFG() & (INT_CFG_IRQ_INT_
| INT_CFG_IRQ_EN_
)) !=
1092 (INT_CFG_IRQ_INT_
| INT_CFG_IRQ_EN_
)) {
1093 spin_unlock_irqrestore(&lp
->lock
, flags
);
1097 mask
= SMC_GET_INT_EN();
1100 /* set a timeout value, so I don't stay here forever */
1105 status
= SMC_GET_INT();
1107 DBG(SMC_DEBUG_MISC
, "%s: INT 0x%08x MASK 0x%08x OUTSIDE MASK 0x%08x\n",
1108 dev
->name
, status
, mask
, status
& ~mask
);
1114 /* Handle SW interrupt condition */
1115 if (status
& INT_STS_SW_INT_
) {
1116 SMC_ACK_INT(INT_STS_SW_INT_
);
1117 mask
&= ~INT_EN_SW_INT_EN_
;
1119 /* Handle various error conditions */
1120 if (status
& INT_STS_RXE_
) {
1121 SMC_ACK_INT(INT_STS_RXE_
);
1122 lp
->stats
.rx_errors
++;
1124 if (status
& INT_STS_RXDFH_INT_
) {
1125 SMC_ACK_INT(INT_STS_RXDFH_INT_
);
1126 lp
->stats
.rx_dropped
+=SMC_GET_RX_DROP();
1128 /* Undocumented interrupt-what is the right thing to do here? */
1129 if (status
& INT_STS_RXDF_INT_
) {
1130 SMC_ACK_INT(INT_STS_RXDF_INT_
);
1133 /* Rx Data FIFO exceeds set level */
1134 if (status
& INT_STS_RDFL_
) {
1135 if (IS_REV_A(lp
->revision
)) {
1138 cr
&= ~MAC_CR_RXEN_
;
1140 DBG(SMC_DEBUG_RX
, "%s: RX overrun\n", dev
->name
);
1141 lp
->stats
.rx_errors
++;
1142 lp
->stats
.rx_fifo_errors
++;
1144 SMC_ACK_INT(INT_STS_RDFL_
);
1146 if (status
& INT_STS_RDFO_
) {
1147 if (!IS_REV_A(lp
->revision
)) {
1149 cr
&= ~MAC_CR_RXEN_
;
1152 DBG(SMC_DEBUG_RX
, "%s: RX overrun\n", dev
->name
);
1153 lp
->stats
.rx_errors
++;
1154 lp
->stats
.rx_fifo_errors
++;
1156 SMC_ACK_INT(INT_STS_RDFO_
);
1158 /* Handle receive condition */
1159 if ((status
& INT_STS_RSFL_
) || rx_overrun
) {
1161 DBG(SMC_DEBUG_RX
, "%s: RX irq\n", dev
->name
);
1162 fifo
= SMC_GET_RX_FIFO_INF();
1163 pkts
= (fifo
& RX_FIFO_INF_RXSUSED_
) >> 16;
1164 DBG(SMC_DEBUG_RX
, "%s: Rx FIFO pkts %d, bytes %d\n",
1165 dev
->name
, pkts
, fifo
& 0xFFFF );
1169 if (lp
->rxdma_active
){
1170 DBG(SMC_DEBUG_RX
| SMC_DEBUG_DMA
,
1171 "%s: RX DMA active\n", dev
->name
);
1172 /* The DMA is already running so up the IRQ threshold */
1173 fifo
= SMC_GET_FIFO_INT() & ~0xFF;
1174 fifo
|= pkts
& 0xFF;
1176 "%s: Setting RX stat FIFO threshold to %d\n",
1177 dev
->name
, fifo
& 0xff);
1178 SMC_SET_FIFO_INT(fifo
);
1183 SMC_ACK_INT(INT_STS_RSFL_
);
1185 /* Handle transmit FIFO available */
1186 if (status
& INT_STS_TDFA_
) {
1187 DBG(SMC_DEBUG_TX
, "%s: TX data FIFO space available irq\n", dev
->name
);
1188 SMC_SET_FIFO_TDA(0xFF);
1189 lp
->tx_throttle
= 0;
1191 if (!lp
->txdma_active
)
1193 netif_wake_queue(dev
);
1194 SMC_ACK_INT(INT_STS_TDFA_
);
1196 /* Handle transmit done condition */
1198 if (status
& (INT_STS_TSFL_
| INT_STS_GPT_INT_
)) {
1199 DBG(SMC_DEBUG_TX
| SMC_DEBUG_MISC
,
1200 "%s: Tx stat FIFO limit (%d) /GPT irq\n",
1201 dev
->name
, (SMC_GET_FIFO_INT() & 0x00ff0000) >> 16);
1203 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_
| 10000);
1204 SMC_ACK_INT(INT_STS_TSFL_
);
1205 SMC_ACK_INT(INT_STS_TSFL_
| INT_STS_GPT_INT_
);
1208 if (status
& INT_STS_TSFL_
) {
1209 DBG(SMC_DEBUG_TX
, "%s: TX status FIFO limit (%d) irq \n", dev
->name
, );
1211 SMC_ACK_INT(INT_STS_TSFL_
);
1214 if (status
& INT_STS_GPT_INT_
) {
1215 DBG(SMC_DEBUG_RX
, "%s: IRQ_CFG 0x%08x FIFO_INT 0x%08x RX_CFG 0x%08x\n",
1220 DBG(SMC_DEBUG_RX
, "%s: Rx Stat FIFO Used 0x%02x "
1221 "Data FIFO Used 0x%04x Stat FIFO 0x%08x\n",
1223 (SMC_GET_RX_FIFO_INF() & 0x00ff0000) >> 16,
1224 SMC_GET_RX_FIFO_INF() & 0xffff,
1225 SMC_GET_RX_STS_FIFO_PEEK());
1226 SMC_SET_GPT_CFG(GPT_CFG_TIMER_EN_
| 10000);
1227 SMC_ACK_INT(INT_STS_GPT_INT_
);
1231 /* Handle PHY interupt condition */
1232 if (status
& INT_STS_PHY_INT_
) {
1233 DBG(SMC_DEBUG_MISC
, "%s: PHY irq\n", dev
->name
);
1234 smc911x_phy_interrupt(dev
);
1235 SMC_ACK_INT(INT_STS_PHY_INT_
);
1237 } while (--timeout
);
1239 /* restore mask state */
1240 SMC_SET_INT_EN(mask
);
1242 DBG(SMC_DEBUG_MISC
, "%s: Interrupt done (%d loops)\n",
1243 dev
->name
, 8-timeout
);
1245 spin_unlock_irqrestore(&lp
->lock
, flags
);
1247 DBG(3, "%s: Interrupt done (%d loops)\n", dev
->name
, 8-timeout
);
1254 smc911x_tx_dma_irq(int dma
, void *data
)
1256 struct net_device
*dev
= (struct net_device
*)data
;
1257 struct smc911x_local
*lp
= netdev_priv(dev
);
1258 struct sk_buff
*skb
= lp
->current_tx_skb
;
1259 unsigned long flags
;
1261 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1263 DBG(SMC_DEBUG_TX
| SMC_DEBUG_DMA
, "%s: TX DMA irq handler\n", dev
->name
);
1264 /* Clear the DMA interrupt sources */
1265 SMC_DMA_ACK_IRQ(dev
, dma
);
1266 BUG_ON(skb
== NULL
);
1267 dma_unmap_single(NULL
, tx_dmabuf
, tx_dmalen
, DMA_TO_DEVICE
);
1268 dev
->trans_start
= jiffies
;
1269 dev_kfree_skb_irq(skb
);
1270 lp
->current_tx_skb
= NULL
;
1271 if (lp
->pending_tx_skb
!= NULL
)
1272 smc911x_hardware_send_pkt(dev
);
1274 DBG(SMC_DEBUG_TX
| SMC_DEBUG_DMA
,
1275 "%s: No pending Tx packets. DMA disabled\n", dev
->name
);
1276 spin_lock_irqsave(&lp
->lock
, flags
);
1277 lp
->txdma_active
= 0;
1278 if (!lp
->tx_throttle
) {
1279 netif_wake_queue(dev
);
1281 spin_unlock_irqrestore(&lp
->lock
, flags
);
1284 DBG(SMC_DEBUG_TX
| SMC_DEBUG_DMA
,
1285 "%s: TX DMA irq completed\n", dev
->name
);
1288 smc911x_rx_dma_irq(int dma
, void *data
)
1290 struct net_device
*dev
= (struct net_device
*)data
;
1291 unsigned long ioaddr
= dev
->base_addr
;
1292 struct smc911x_local
*lp
= netdev_priv(dev
);
1293 struct sk_buff
*skb
= lp
->current_rx_skb
;
1294 unsigned long flags
;
1297 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1298 DBG(SMC_DEBUG_RX
| SMC_DEBUG_DMA
, "%s: RX DMA irq handler\n", dev
->name
);
1299 /* Clear the DMA interrupt sources */
1300 SMC_DMA_ACK_IRQ(dev
, dma
);
1301 dma_unmap_single(NULL
, rx_dmabuf
, rx_dmalen
, DMA_FROM_DEVICE
);
1302 BUG_ON(skb
== NULL
);
1303 lp
->current_rx_skb
= NULL
;
1304 PRINT_PKT(skb
->data
, skb
->len
);
1305 dev
->last_rx
= jiffies
;
1307 skb
->protocol
= eth_type_trans(skb
, dev
);
1309 lp
->stats
.rx_packets
++;
1310 lp
->stats
.rx_bytes
+= skb
->len
;
1312 spin_lock_irqsave(&lp
->lock
, flags
);
1313 pkts
= (SMC_GET_RX_FIFO_INF() & RX_FIFO_INF_RXSUSED_
) >> 16;
1317 lp
->rxdma_active
= 0;
1319 spin_unlock_irqrestore(&lp
->lock
, flags
);
1320 DBG(SMC_DEBUG_RX
| SMC_DEBUG_DMA
,
1321 "%s: RX DMA irq completed. DMA RX FIFO PKTS %d\n",
1324 #endif /* SMC_USE_DMA */
1326 #ifdef CONFIG_NET_POLL_CONTROLLER
1328 * Polling receive - used by netconsole and other diagnostic tools
1329 * to allow network i/o with interrupts disabled.
1331 static void smc911x_poll_controller(struct net_device
*dev
)
1333 disable_irq(dev
->irq
);
1334 smc911x_interrupt(dev
->irq
, dev
, NULL
);
1335 enable_irq(dev
->irq
);
1339 /* Our watchdog timed out. Called by the networking layer */
1340 static void smc911x_timeout(struct net_device
*dev
)
1342 struct smc911x_local
*lp
= netdev_priv(dev
);
1343 unsigned long ioaddr
= dev
->base_addr
;
1345 unsigned long flags
;
1347 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1349 spin_lock_irqsave(&lp
->lock
, flags
);
1350 status
= SMC_GET_INT();
1351 mask
= SMC_GET_INT_EN();
1352 spin_unlock_irqrestore(&lp
->lock
, flags
);
1353 DBG(SMC_DEBUG_MISC
, "%s: INT 0x%02x MASK 0x%02x \n",
1354 dev
->name
, status
, mask
);
1356 /* Dump the current TX FIFO contents and restart */
1357 mask
= SMC_GET_TX_CFG();
1358 SMC_SET_TX_CFG(mask
| TX_CFG_TXS_DUMP_
| TX_CFG_TXD_DUMP_
);
1360 * Reconfiguring the PHY doesn't seem like a bad idea here, but
1361 * smc911x_phy_configure() calls msleep() which calls schedule_timeout()
1362 * which calls schedule(). Hence we use a work queue.
1364 if (lp
->phy_type
!= 0) {
1365 if (schedule_work(&lp
->phy_configure
)) {
1366 lp
->work_pending
= 1;
1370 /* We can accept TX packets again */
1371 dev
->trans_start
= jiffies
;
1372 netif_wake_queue(dev
);
1376 * This routine will, depending on the values passed to it,
1377 * either make it accept multicast packets, go into
1378 * promiscuous mode (for TCPDUMP and cousins) or accept
1379 * a select set of multicast packets
1381 static void smc911x_set_multicast_list(struct net_device
*dev
)
1383 struct smc911x_local
*lp
= netdev_priv(dev
);
1384 unsigned long ioaddr
= dev
->base_addr
;
1385 unsigned int multicast_table
[2];
1386 unsigned int mcr
, update_multicast
= 0;
1387 unsigned long flags
;
1388 /* table for flipping the order of 5 bits */
1389 static const unsigned char invert5
[] =
1390 {0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0C, 0x1C,
1391 0x02, 0x12, 0x0A, 0x1A, 0x06, 0x16, 0x0E, 0x1E,
1392 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0D, 0x1D,
1393 0x03, 0x13, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F};
1396 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1398 spin_lock_irqsave(&lp
->lock
, flags
);
1399 SMC_GET_MAC_CR(mcr
);
1400 spin_unlock_irqrestore(&lp
->lock
, flags
);
1402 if (dev
->flags
& IFF_PROMISC
) {
1404 DBG(SMC_DEBUG_MISC
, "%s: RCR_PRMS\n", dev
->name
);
1405 mcr
|= MAC_CR_PRMS_
;
1408 * Here, I am setting this to accept all multicast packets.
1409 * I don't need to zero the multicast table, because the flag is
1410 * checked before the table is
1412 else if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
> 16) {
1413 DBG(SMC_DEBUG_MISC
, "%s: RCR_ALMUL\n", dev
->name
);
1414 mcr
|= MAC_CR_MCPAS_
;
1418 * This sets the internal hardware table to filter out unwanted
1419 * multicast packets before they take up memory.
1421 * The SMC chip uses a hash table where the high 6 bits of the CRC of
1422 * address are the offset into the table. If that bit is 1, then the
1423 * multicast packet is accepted. Otherwise, it's dropped silently.
1425 * To use the 6 bits as an offset into the table, the high 1 bit is
1426 * the number of the 32 bit register, while the low 5 bits are the bit
1427 * within that register.
1429 else if (dev
->mc_count
) {
1431 struct dev_mc_list
*cur_addr
;
1433 /* Set the Hash perfec mode */
1434 mcr
|= MAC_CR_HPFILT_
;
1436 /* start with a table of all zeros: reject all */
1437 memset(multicast_table
, 0, sizeof(multicast_table
));
1439 cur_addr
= dev
->mc_list
;
1440 for (i
= 0; i
< dev
->mc_count
; i
++, cur_addr
= cur_addr
->next
) {
1443 /* do we have a pointer here? */
1446 /* make sure this is a multicast address -
1447 shouldn't this be a given if we have it here ? */
1448 if (!(*cur_addr
->dmi_addr
& 1))
1451 /* only use the low order bits */
1452 position
= crc32_le(~0, cur_addr
->dmi_addr
, 6) & 0x3f;
1454 /* do some messy swapping to put the bit in the right spot */
1455 multicast_table
[invert5
[position
&0x1F]&0x1] |=
1456 (1<<invert5
[(position
>>1)&0x1F]);
1459 /* be sure I get rid of flags I might have set */
1460 mcr
&= ~(MAC_CR_PRMS_
| MAC_CR_MCPAS_
);
1462 /* now, the table can be loaded into the chipset */
1463 update_multicast
= 1;
1465 DBG(SMC_DEBUG_MISC
, "%s: ~(MAC_CR_PRMS_|MAC_CR_MCPAS_)\n",
1467 mcr
&= ~(MAC_CR_PRMS_
| MAC_CR_MCPAS_
);
1470 * since I'm disabling all multicast entirely, I need to
1471 * clear the multicast list
1473 memset(multicast_table
, 0, sizeof(multicast_table
));
1474 update_multicast
= 1;
1477 spin_lock_irqsave(&lp
->lock
, flags
);
1478 SMC_SET_MAC_CR(mcr
);
1479 if (update_multicast
) {
1481 "%s: update mcast hash table 0x%08x 0x%08x\n",
1482 dev
->name
, multicast_table
[0], multicast_table
[1]);
1483 SMC_SET_HASHL(multicast_table
[0]);
1484 SMC_SET_HASHH(multicast_table
[1]);
1486 spin_unlock_irqrestore(&lp
->lock
, flags
);
1491 * Open and Initialize the board
1493 * Set up everything, reset the card, etc..
1496 smc911x_open(struct net_device
*dev
)
1498 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1501 * Check that the address is valid. If its not, refuse
1502 * to bring the device up. The user must specify an
1503 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
1505 if (!is_valid_ether_addr(dev
->dev_addr
)) {
1506 PRINTK("%s: no valid ethernet hw addr\n", __FUNCTION__
);
1510 /* reset the hardware */
1513 /* Configure the PHY, initialize the link state */
1514 smc911x_phy_configure(dev
);
1516 /* Turn on Tx + Rx */
1517 smc911x_enable(dev
);
1519 netif_start_queue(dev
);
1527 * this makes the board clean up everything that it can
1528 * and not talk to the outside world. Caused by
1529 * an 'ifconfig ethX down'
1531 static int smc911x_close(struct net_device
*dev
)
1533 struct smc911x_local
*lp
= netdev_priv(dev
);
1535 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1537 netif_stop_queue(dev
);
1538 netif_carrier_off(dev
);
1540 /* clear everything */
1541 smc911x_shutdown(dev
);
1543 if (lp
->phy_type
!= 0) {
1544 /* We need to ensure that no calls to
1545 * smc911x_phy_configure are pending.
1547 * flush_scheduled_work() cannot be called because we
1548 * are running with the netlink semaphore held (from
1549 * devinet_ioctl()) and the pending work queue
1550 * contains linkwatch_event() (scheduled by
1551 * netif_carrier_off() above). linkwatch_event() also
1552 * wants the netlink semaphore.
1554 while (lp
->work_pending
)
1556 smc911x_phy_powerdown(dev
, lp
->mii
.phy_id
);
1559 if (lp
->pending_tx_skb
) {
1560 dev_kfree_skb(lp
->pending_tx_skb
);
1561 lp
->pending_tx_skb
= NULL
;
1568 * Get the current statistics.
1569 * This may be called with the card open or closed.
1571 static struct net_device_stats
*smc911x_query_statistics(struct net_device
*dev
)
1573 struct smc911x_local
*lp
= netdev_priv(dev
);
1574 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1584 smc911x_ethtool_getsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1586 struct smc911x_local
*lp
= netdev_priv(dev
);
1587 unsigned long ioaddr
= dev
->base_addr
;
1589 unsigned long flags
;
1591 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1595 if (lp
->phy_type
!= 0) {
1596 spin_lock_irqsave(&lp
->lock
, flags
);
1597 ret
= mii_ethtool_gset(&lp
->mii
, cmd
);
1598 spin_unlock_irqrestore(&lp
->lock
, flags
);
1600 cmd
->supported
= SUPPORTED_10baseT_Half
|
1601 SUPPORTED_10baseT_Full
|
1602 SUPPORTED_TP
| SUPPORTED_AUI
;
1604 if (lp
->ctl_rspeed
== 10)
1605 cmd
->speed
= SPEED_10
;
1606 else if (lp
->ctl_rspeed
== 100)
1607 cmd
->speed
= SPEED_100
;
1609 cmd
->autoneg
= AUTONEG_DISABLE
;
1610 if (lp
->mii
.phy_id
==1)
1611 cmd
->transceiver
= XCVR_INTERNAL
;
1613 cmd
->transceiver
= XCVR_EXTERNAL
;
1615 SMC_GET_PHY_SPECIAL(lp
->mii
.phy_id
, status
);
1617 (status
& (PHY_SPECIAL_SPD_10FULL_
| PHY_SPECIAL_SPD_100FULL_
)) ?
1618 DUPLEX_FULL
: DUPLEX_HALF
;
1626 smc911x_ethtool_setsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1628 struct smc911x_local
*lp
= netdev_priv(dev
);
1630 unsigned long flags
;
1632 if (lp
->phy_type
!= 0) {
1633 spin_lock_irqsave(&lp
->lock
, flags
);
1634 ret
= mii_ethtool_sset(&lp
->mii
, cmd
);
1635 spin_unlock_irqrestore(&lp
->lock
, flags
);
1637 if (cmd
->autoneg
!= AUTONEG_DISABLE
||
1638 cmd
->speed
!= SPEED_10
||
1639 (cmd
->duplex
!= DUPLEX_HALF
&& cmd
->duplex
!= DUPLEX_FULL
) ||
1640 (cmd
->port
!= PORT_TP
&& cmd
->port
!= PORT_AUI
))
1643 lp
->ctl_rfduplx
= cmd
->duplex
== DUPLEX_FULL
;
1652 smc911x_ethtool_getdrvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1654 strncpy(info
->driver
, CARDNAME
, sizeof(info
->driver
));
1655 strncpy(info
->version
, version
, sizeof(info
->version
));
1656 strncpy(info
->bus_info
, dev
->class_dev
.dev
->bus_id
, sizeof(info
->bus_info
));
1659 static int smc911x_ethtool_nwayreset(struct net_device
*dev
)
1661 struct smc911x_local
*lp
= netdev_priv(dev
);
1663 unsigned long flags
;
1665 if (lp
->phy_type
!= 0) {
1666 spin_lock_irqsave(&lp
->lock
, flags
);
1667 ret
= mii_nway_restart(&lp
->mii
);
1668 spin_unlock_irqrestore(&lp
->lock
, flags
);
1674 static u32
smc911x_ethtool_getmsglevel(struct net_device
*dev
)
1676 struct smc911x_local
*lp
= netdev_priv(dev
);
1677 return lp
->msg_enable
;
1680 static void smc911x_ethtool_setmsglevel(struct net_device
*dev
, u32 level
)
1682 struct smc911x_local
*lp
= netdev_priv(dev
);
1683 lp
->msg_enable
= level
;
1686 static int smc911x_ethtool_getregslen(struct net_device
*dev
)
1688 /* System regs + MAC regs + PHY regs */
1689 return (((E2P_CMD
- ID_REV
)/4 + 1) +
1690 (WUCSR
- MAC_CR
)+1 + 32) * sizeof(u32
);
1693 static void smc911x_ethtool_getregs(struct net_device
*dev
,
1694 struct ethtool_regs
* regs
, void *buf
)
1696 unsigned long ioaddr
= dev
->base_addr
;
1697 struct smc911x_local
*lp
= netdev_priv(dev
);
1698 unsigned long flags
;
1700 u32
*data
= (u32
*)buf
;
1702 regs
->version
= lp
->version
;
1703 for(i
=ID_REV
;i
<=E2P_CMD
;i
+=4) {
1704 data
[j
++] = SMC_inl(ioaddr
,i
);
1706 for(i
=MAC_CR
;i
<=WUCSR
;i
++) {
1707 spin_lock_irqsave(&lp
->lock
, flags
);
1708 SMC_GET_MAC_CSR(i
, reg
);
1709 spin_unlock_irqrestore(&lp
->lock
, flags
);
1712 for(i
=0;i
<=31;i
++) {
1713 spin_lock_irqsave(&lp
->lock
, flags
);
1714 SMC_GET_MII(i
, lp
->mii
.phy_id
, reg
);
1715 spin_unlock_irqrestore(&lp
->lock
, flags
);
1716 data
[j
++] = reg
& 0xFFFF;
1720 static int smc911x_ethtool_wait_eeprom_ready(struct net_device
*dev
)
1722 unsigned long ioaddr
= dev
->base_addr
;
1723 unsigned int timeout
;
1726 e2p_cmd
= SMC_GET_E2P_CMD();
1727 for(timeout
=10;(e2p_cmd
& E2P_CMD_EPC_BUSY_
) && timeout
; timeout
--) {
1728 if (e2p_cmd
& E2P_CMD_EPC_TIMEOUT_
) {
1729 PRINTK("%s: %s timeout waiting for EEPROM to respond\n",
1730 dev
->name
, __FUNCTION__
);
1734 e2p_cmd
= SMC_GET_E2P_CMD();
1737 PRINTK("%s: %s timeout waiting for EEPROM CMD not busy\n",
1738 dev
->name
, __FUNCTION__
);
1744 static inline int smc911x_ethtool_write_eeprom_cmd(struct net_device
*dev
,
1747 unsigned long ioaddr
= dev
->base_addr
;
1750 if ((ret
= smc911x_ethtool_wait_eeprom_ready(dev
))!=0)
1752 SMC_SET_E2P_CMD(E2P_CMD_EPC_BUSY_
|
1753 ((cmd
) & (0x7<<28)) |
1758 static inline int smc911x_ethtool_read_eeprom_byte(struct net_device
*dev
,
1761 unsigned long ioaddr
= dev
->base_addr
;
1764 if ((ret
= smc911x_ethtool_wait_eeprom_ready(dev
))!=0)
1766 *data
= SMC_GET_E2P_DATA();
1770 static inline int smc911x_ethtool_write_eeprom_byte(struct net_device
*dev
,
1773 unsigned long ioaddr
= dev
->base_addr
;
1776 if ((ret
= smc911x_ethtool_wait_eeprom_ready(dev
))!=0)
1778 SMC_SET_E2P_DATA(data
);
1782 static int smc911x_ethtool_geteeprom(struct net_device
*dev
,
1783 struct ethtool_eeprom
*eeprom
, u8
*data
)
1785 u8 eebuf
[SMC911X_EEPROM_LEN
];
1788 for(i
=0;i
<SMC911X_EEPROM_LEN
;i
++) {
1789 if ((ret
=smc911x_ethtool_write_eeprom_cmd(dev
, E2P_CMD_EPC_CMD_READ_
, i
))!=0)
1791 if ((ret
=smc911x_ethtool_read_eeprom_byte(dev
, &eebuf
[i
]))!=0)
1794 memcpy(data
, eebuf
+eeprom
->offset
, eeprom
->len
);
1798 static int smc911x_ethtool_seteeprom(struct net_device
*dev
,
1799 struct ethtool_eeprom
*eeprom
, u8
*data
)
1804 if ((ret
=smc911x_ethtool_write_eeprom_cmd(dev
, E2P_CMD_EPC_CMD_EWEN_
, 0 ))!=0)
1806 for(i
=eeprom
->offset
;i
<(eeprom
->offset
+eeprom
->len
);i
++) {
1808 if ((ret
=smc911x_ethtool_write_eeprom_cmd(dev
, E2P_CMD_EPC_CMD_ERASE_
, i
))!=0)
1811 if ((ret
=smc911x_ethtool_write_eeprom_byte(dev
, *data
))!=0)
1813 if ((ret
=smc911x_ethtool_write_eeprom_cmd(dev
, E2P_CMD_EPC_CMD_WRITE_
, i
))!=0)
1819 static int smc911x_ethtool_geteeprom_len(struct net_device
*dev
)
1821 return SMC911X_EEPROM_LEN
;
1824 static const struct ethtool_ops smc911x_ethtool_ops
= {
1825 .get_settings
= smc911x_ethtool_getsettings
,
1826 .set_settings
= smc911x_ethtool_setsettings
,
1827 .get_drvinfo
= smc911x_ethtool_getdrvinfo
,
1828 .get_msglevel
= smc911x_ethtool_getmsglevel
,
1829 .set_msglevel
= smc911x_ethtool_setmsglevel
,
1830 .nway_reset
= smc911x_ethtool_nwayreset
,
1831 .get_link
= ethtool_op_get_link
,
1832 .get_regs_len
= smc911x_ethtool_getregslen
,
1833 .get_regs
= smc911x_ethtool_getregs
,
1834 .get_eeprom_len
= smc911x_ethtool_geteeprom_len
,
1835 .get_eeprom
= smc911x_ethtool_geteeprom
,
1836 .set_eeprom
= smc911x_ethtool_seteeprom
,
1842 * This routine has a simple purpose -- make the SMC chip generate an
1843 * interrupt, so an auto-detect routine can detect it, and find the IRQ,
1845 static int __init
smc911x_findirq(unsigned long ioaddr
)
1848 unsigned long cookie
;
1850 DBG(SMC_DEBUG_FUNC
, "--> %s\n", __FUNCTION__
);
1852 cookie
= probe_irq_on();
1855 * Force a SW interrupt
1858 SMC_SET_INT_EN(INT_EN_SW_INT_EN_
);
1861 * Wait until positive that the interrupt has been generated
1866 int_status
= SMC_GET_INT_EN();
1867 if (int_status
& INT_EN_SW_INT_EN_
)
1868 break; /* got the interrupt */
1869 } while (--timeout
);
1872 * there is really nothing that I can do here if timeout fails,
1873 * as autoirq_report will return a 0 anyway, which is what I
1874 * want in this case. Plus, the clean up is needed in both
1878 /* and disable all interrupts again */
1881 /* and return what I found */
1882 return probe_irq_off(cookie
);
1886 * Function: smc911x_probe(unsigned long ioaddr)
1889 * Tests to see if a given ioaddr points to an SMC911x chip.
1890 * Returns a 0 on success
1893 * (1) see if the endian word is OK
1894 * (1) see if I recognize the chip ID in the appropriate register
1896 * Here I do typical initialization tasks.
1898 * o Initialize the structure if needed
1899 * o print out my vanity message if not done so already
1900 * o print out what type of hardware is detected
1901 * o print out the ethernet address
1903 * o set up my private data
1904 * o configure the dev structure with my subroutines
1905 * o actually GRAB the irq.
1908 static int __init
smc911x_probe(struct net_device
*dev
, unsigned long ioaddr
)
1910 struct smc911x_local
*lp
= netdev_priv(dev
);
1912 unsigned int val
, chip_id
, revision
;
1913 const char *version_string
;
1915 DBG(SMC_DEBUG_FUNC
, "%s: --> %s\n", dev
->name
, __FUNCTION__
);
1917 /* First, see if the endian word is recognized */
1918 val
= SMC_GET_BYTE_TEST();
1919 DBG(SMC_DEBUG_MISC
, "%s: endian probe returned 0x%04x\n", CARDNAME
, val
);
1920 if (val
!= 0x87654321) {
1921 printk(KERN_ERR
"Invalid chip endian 0x08%x\n",val
);
1927 * check if the revision register is something that I
1928 * recognize. These might need to be added to later,
1929 * as future revisions could be added.
1931 chip_id
= SMC_GET_PN();
1932 DBG(SMC_DEBUG_MISC
, "%s: id probe returned 0x%04x\n", CARDNAME
, chip_id
);
1933 for(i
=0;chip_ids
[i
].id
!= 0; i
++) {
1934 if (chip_ids
[i
].id
== chip_id
) break;
1936 if (!chip_ids
[i
].id
) {
1937 printk(KERN_ERR
"Unknown chip ID %04x\n", chip_id
);
1941 version_string
= chip_ids
[i
].name
;
1943 revision
= SMC_GET_REV();
1944 DBG(SMC_DEBUG_MISC
, "%s: revision = 0x%04x\n", CARDNAME
, revision
);
1946 /* At this point I'll assume that the chip is an SMC911x. */
1947 DBG(SMC_DEBUG_MISC
, "%s: Found a %s\n", CARDNAME
, chip_ids
[i
].name
);
1949 /* Validate the TX FIFO size requested */
1950 if ((tx_fifo_kb
< 2) || (tx_fifo_kb
> 14)) {
1951 printk(KERN_ERR
"Invalid TX FIFO size requested %d\n", tx_fifo_kb
);
1956 /* fill in some of the fields */
1957 dev
->base_addr
= ioaddr
;
1958 lp
->version
= chip_ids
[i
].id
;
1959 lp
->revision
= revision
;
1960 lp
->tx_fifo_kb
= tx_fifo_kb
;
1961 /* Reverse calculate the RX FIFO size from the TX */
1962 lp
->tx_fifo_size
=(lp
->tx_fifo_kb
<<10) - 512;
1963 lp
->rx_fifo_size
= ((0x4000 - 512 - lp
->tx_fifo_size
) / 16) * 15;
1965 /* Set the automatic flow control values */
1966 switch(lp
->tx_fifo_kb
) {
1968 * AFC_HI is about ((Rx Data Fifo Size)*2/3)/64
1969 * AFC_LO is AFC_HI/2
1970 * BACK_DUR is about 5uS*(AFC_LO) rounded down
1972 case 2:/* 13440 Rx Data Fifo Size */
1973 lp
->afc_cfg
=0x008C46AF;break;
1974 case 3:/* 12480 Rx Data Fifo Size */
1975 lp
->afc_cfg
=0x0082419F;break;
1976 case 4:/* 11520 Rx Data Fifo Size */
1977 lp
->afc_cfg
=0x00783C9F;break;
1978 case 5:/* 10560 Rx Data Fifo Size */
1979 lp
->afc_cfg
=0x006E374F;break;
1980 case 6:/* 9600 Rx Data Fifo Size */
1981 lp
->afc_cfg
=0x0064328F;break;
1982 case 7:/* 8640 Rx Data Fifo Size */
1983 lp
->afc_cfg
=0x005A2D7F;break;
1984 case 8:/* 7680 Rx Data Fifo Size */
1985 lp
->afc_cfg
=0x0050287F;break;
1986 case 9:/* 6720 Rx Data Fifo Size */
1987 lp
->afc_cfg
=0x0046236F;break;
1988 case 10:/* 5760 Rx Data Fifo Size */
1989 lp
->afc_cfg
=0x003C1E6F;break;
1990 case 11:/* 4800 Rx Data Fifo Size */
1991 lp
->afc_cfg
=0x0032195F;break;
1993 * AFC_HI is ~1520 bytes less than RX Data Fifo Size
1994 * AFC_LO is AFC_HI/2
1995 * BACK_DUR is about 5uS*(AFC_LO) rounded down
1997 case 12:/* 3840 Rx Data Fifo Size */
1998 lp
->afc_cfg
=0x0024124F;break;
1999 case 13:/* 2880 Rx Data Fifo Size */
2000 lp
->afc_cfg
=0x0015073F;break;
2001 case 14:/* 1920 Rx Data Fifo Size */
2002 lp
->afc_cfg
=0x0006032F;break;
2004 PRINTK("%s: ERROR -- no AFC_CFG setting found",
2009 DBG(SMC_DEBUG_MISC
| SMC_DEBUG_TX
| SMC_DEBUG_RX
,
2010 "%s: tx_fifo %d rx_fifo %d afc_cfg 0x%08x\n", CARDNAME
,
2011 lp
->tx_fifo_size
, lp
->rx_fifo_size
, lp
->afc_cfg
);
2013 spin_lock_init(&lp
->lock
);
2015 /* Get the MAC address */
2016 SMC_GET_MAC_ADDR(dev
->dev_addr
);
2018 /* now, reset the chip, and put it into a known state */
2022 * If dev->irq is 0, then the device has to be banged on to see
2025 * Specifying an IRQ is done with the assumption that the user knows
2026 * what (s)he is doing. No checking is done!!!!
2033 dev
->irq
= smc911x_findirq(ioaddr
);
2036 /* kick the card and try again */
2040 if (dev
->irq
== 0) {
2041 printk("%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
2046 dev
->irq
= irq_canonicalize(dev
->irq
);
2048 /* Fill in the fields of the device structure with ethernet values. */
2051 dev
->open
= smc911x_open
;
2052 dev
->stop
= smc911x_close
;
2053 dev
->hard_start_xmit
= smc911x_hard_start_xmit
;
2054 dev
->tx_timeout
= smc911x_timeout
;
2055 dev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
2056 dev
->get_stats
= smc911x_query_statistics
;
2057 dev
->set_multicast_list
= smc911x_set_multicast_list
;
2058 dev
->ethtool_ops
= &smc911x_ethtool_ops
;
2059 #ifdef CONFIG_NET_POLL_CONTROLLER
2060 dev
->poll_controller
= smc911x_poll_controller
;
2063 INIT_WORK(&lp
->phy_configure
, smc911x_phy_configure
, dev
);
2064 lp
->mii
.phy_id_mask
= 0x1f;
2065 lp
->mii
.reg_num_mask
= 0x1f;
2066 lp
->mii
.force_media
= 0;
2067 lp
->mii
.full_duplex
= 0;
2069 lp
->mii
.mdio_read
= smc911x_phy_read
;
2070 lp
->mii
.mdio_write
= smc911x_phy_write
;
2073 * Locate the phy, if any.
2075 smc911x_phy_detect(dev
);
2077 /* Set default parameters */
2078 lp
->msg_enable
= NETIF_MSG_LINK
;
2079 lp
->ctl_rfduplx
= 1;
2080 lp
->ctl_rspeed
= 100;
2083 retval
= request_irq(dev
->irq
, &smc911x_interrupt
, IRQF_SHARED
, dev
->name
, dev
);
2087 set_irq_type(dev
->irq
, IRQT_FALLING
);
2090 lp
->rxdma
= SMC_DMA_REQUEST(dev
, smc911x_rx_dma_irq
);
2091 lp
->txdma
= SMC_DMA_REQUEST(dev
, smc911x_tx_dma_irq
);
2092 lp
->rxdma_active
= 0;
2093 lp
->txdma_active
= 0;
2094 dev
->dma
= lp
->rxdma
;
2097 retval
= register_netdev(dev
);
2099 /* now, print out the card info, in a short format.. */
2100 printk("%s: %s (rev %d) at %#lx IRQ %d",
2101 dev
->name
, version_string
, lp
->revision
,
2102 dev
->base_addr
, dev
->irq
);
2105 if (lp
->rxdma
!= -1)
2106 printk(" RXDMA %d ", lp
->rxdma
);
2108 if (lp
->txdma
!= -1)
2109 printk("TXDMA %d", lp
->txdma
);
2112 if (!is_valid_ether_addr(dev
->dev_addr
)) {
2113 printk("%s: Invalid ethernet MAC address. Please "
2114 "set using ifconfig\n", dev
->name
);
2116 /* Print the Ethernet address */
2117 printk("%s: Ethernet addr: ", dev
->name
);
2118 for (i
= 0; i
< 5; i
++)
2119 printk("%2.2x:", dev
->dev_addr
[i
]);
2120 printk("%2.2x\n", dev
->dev_addr
[5]);
2123 if (lp
->phy_type
== 0) {
2124 PRINTK("%s: No PHY found\n", dev
->name
);
2125 } else if ((lp
->phy_type
& ~0xff) == LAN911X_INTERNAL_PHY_ID
) {
2126 PRINTK("%s: LAN911x Internal PHY\n", dev
->name
);
2128 PRINTK("%s: External PHY 0x%08x\n", dev
->name
, lp
->phy_type
);
2135 if (lp
->rxdma
!= -1) {
2136 SMC_DMA_FREE(dev
, lp
->rxdma
);
2138 if (lp
->txdma
!= -1) {
2139 SMC_DMA_FREE(dev
, lp
->txdma
);
2147 * smc911x_init(void)
2150 * 0 --> there is a device
2151 * anything else, error
2153 static int smc911x_drv_probe(struct platform_device
*pdev
)
2155 struct net_device
*ndev
;
2156 struct resource
*res
;
2160 DBG(SMC_DEBUG_FUNC
, "--> %s\n", __FUNCTION__
);
2161 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2168 * Request the regions.
2170 if (!request_mem_region(res
->start
, SMC911X_IO_EXTENT
, CARDNAME
)) {
2175 ndev
= alloc_etherdev(sizeof(struct smc911x_local
));
2177 printk("%s: could not allocate device.\n", CARDNAME
);
2181 SET_MODULE_OWNER(ndev
);
2182 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
2184 ndev
->dma
= (unsigned char)-1;
2185 ndev
->irq
= platform_get_irq(pdev
, 0);
2187 addr
= ioremap(res
->start
, SMC911X_IO_EXTENT
);
2193 platform_set_drvdata(pdev
, ndev
);
2194 ret
= smc911x_probe(ndev
, (unsigned long)addr
);
2196 platform_set_drvdata(pdev
, NULL
);
2201 release_mem_region(res
->start
, SMC911X_IO_EXTENT
);
2203 printk("%s: not found (%d).\n", CARDNAME
, ret
);
2207 struct smc911x_local
*lp
= netdev_priv(ndev
);
2208 lp
->physaddr
= res
->start
;
2209 lp
->dev
= &pdev
->dev
;
2216 static int smc911x_drv_remove(struct platform_device
*pdev
)
2218 struct net_device
*ndev
= platform_get_drvdata(pdev
);
2219 struct resource
*res
;
2221 DBG(SMC_DEBUG_FUNC
, "--> %s\n", __FUNCTION__
);
2222 platform_set_drvdata(pdev
, NULL
);
2224 unregister_netdev(ndev
);
2226 free_irq(ndev
->irq
, ndev
);
2230 struct smc911x_local
*lp
= netdev_priv(ndev
);
2231 if (lp
->rxdma
!= -1) {
2232 SMC_DMA_FREE(dev
, lp
->rxdma
);
2234 if (lp
->txdma
!= -1) {
2235 SMC_DMA_FREE(dev
, lp
->txdma
);
2239 iounmap((void *)ndev
->base_addr
);
2240 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2241 release_mem_region(res
->start
, SMC911X_IO_EXTENT
);
2247 static int smc911x_drv_suspend(struct platform_device
*dev
, pm_message_t state
)
2249 struct net_device
*ndev
= platform_get_drvdata(dev
);
2250 unsigned long ioaddr
= ndev
->base_addr
;
2252 DBG(SMC_DEBUG_FUNC
, "--> %s\n", __FUNCTION__
);
2254 if (netif_running(ndev
)) {
2255 netif_device_detach(ndev
);
2256 smc911x_shutdown(ndev
);
2258 /* Set D2 - Energy detect only setting */
2259 SMC_SET_PMT_CTRL(2<<12);
2266 static int smc911x_drv_resume(struct platform_device
*dev
)
2268 struct net_device
*ndev
= platform_get_drvdata(dev
);
2270 DBG(SMC_DEBUG_FUNC
, "--> %s\n", __FUNCTION__
);
2272 struct smc911x_local
*lp
= netdev_priv(ndev
);
2274 if (netif_running(ndev
)) {
2275 smc911x_reset(ndev
);
2276 smc911x_enable(ndev
);
2277 if (lp
->phy_type
!= 0)
2278 smc911x_phy_configure(ndev
);
2279 netif_device_attach(ndev
);
2285 static struct platform_driver smc911x_driver
= {
2286 .probe
= smc911x_drv_probe
,
2287 .remove
= smc911x_drv_remove
,
2288 .suspend
= smc911x_drv_suspend
,
2289 .resume
= smc911x_drv_resume
,
2295 static int __init
smc911x_init(void)
2297 return platform_driver_register(&smc911x_driver
);
2300 static void __exit
smc911x_cleanup(void)
2302 platform_driver_unregister(&smc911x_driver
);
2305 module_init(smc911x_init
);
2306 module_exit(smc911x_cleanup
);