3 * This is a driver for SMSC's 91C9x/91C1xx single-chip Ethernet devices.
5 * Copyright (C) 1996 by Erik Stahlman
6 * Copyright (C) 2001 Standard Microsystems Corporation
7 * Developed by Simple Network Magic Corporation
8 * Copyright (C) 2003 Monta Vista Software, Inc.
9 * Unified SMC91x driver by Nicolas Pitre
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * io = for the base address
28 * nowait = 0 for normal wait states, 1 eliminates additional wait states
31 * Erik Stahlman <erik@vt.edu>
33 * hardware multicast code:
34 * Peter Cammaert <pc@denkart.be>
37 * Daris A Nevil <dnevil@snmc.com>
38 * Nicolas Pitre <nico@cam.org>
39 * Russell King <rmk@arm.linux.org.uk>
42 * 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet
43 * 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ"
44 * 03/16/01 Daris A Nevil modified smc9194.c for use with LAN91C111
45 * 08/22/01 Scott Anderson merge changes from smc9194 to smc91111
46 * 08/21/01 Pramod B Bhardwaj added support for RevB of LAN91C111
47 * 12/20/01 Jeff Sutherland initial port to Xscale PXA with DMA support
48 * 04/07/03 Nicolas Pitre unified SMC91x driver, killed irq races,
49 * more bus abstraction, big cleanup, etc.
50 * 29/09/03 Russell King - add driver model support
52 * - convert to use generic MII interface
53 * - add link up/down notification
54 * - don't try to handle full negotiation in
56 * - clean up (and fix stack overrun) in PHY
57 * MII read/write functions
58 * 09/15/04 Hayato Fujiwara - Add m32r support.
59 * - Modify for SMP kernel; Change spin-locked
62 static const char version
[] =
63 "smc91x.c: v1.0, mar 07 2003 by Nicolas Pitre <nico@cam.org>\n";
71 #include <linux/config.h>
72 #include <linux/init.h>
73 #include <linux/module.h>
74 #include <linux/kernel.h>
75 #include <linux/sched.h>
76 #include <linux/slab.h>
77 #include <linux/delay.h>
78 #include <linux/timer.h>
79 #include <linux/errno.h>
80 #include <linux/ioport.h>
81 #include <linux/crc32.h>
82 #include <linux/device.h>
83 #include <linux/spinlock.h>
84 #include <linux/ethtool.h>
85 #include <linux/mii.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
98 * the LAN91C111 can be at any of the following port addresses. To change,
99 * for a slightly different card, you can add it to the array. Keep in
100 * mind that the array must end in zero.
102 static unsigned int smc_portlist
[] __initdata
= {
103 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,
104 0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0, 0
108 # define SMC_IOADDR -1
110 static unsigned long io
= SMC_IOADDR
;
111 module_param(io
, ulong
, 0400);
112 MODULE_PARM_DESC(io
, "I/O base address");
117 static int irq
= SMC_IRQ
;
118 module_param(irq
, int, 0400);
119 MODULE_PARM_DESC(irq
, "IRQ number");
121 #endif /* CONFIG_ISA */
124 # define SMC_NOWAIT 0
126 static int nowait
= SMC_NOWAIT
;
127 module_param(nowait
, int, 0400);
128 MODULE_PARM_DESC(nowait
, "set to 1 for no wait state");
131 * Transmit timeout, default 5 seconds.
133 static int watchdog
= 5000;
134 module_param(watchdog
, int, 0400);
135 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");
137 MODULE_LICENSE("GPL");
140 * The internal workings of the driver. If you are changing anything
141 * here with the SMC stuff, you should have the datasheet and know
142 * what you are doing.
144 #define CARDNAME "smc91x"
147 * Use power-down feature of the chip
152 * Wait time for memory to be free. This probably shouldn't be
153 * tuned that much, as waiting for this means nothing else happens
156 #define MEMORY_WAIT_TIME 16
159 * This selects whether TX packets are sent one by one to the SMC91x internal
160 * memory and throttled until transmission completes. This may prevent
161 * RX overruns a litle by keeping much of the memory free for RX packets
162 * but to the expense of reduced TX throughput and increased IRQ overhead.
163 * Note this is not a cure for a too slow data bus or too high IRQ latency.
165 #define THROTTLE_TX_PKTS 0
168 * The MII clock high/low times. 2x this number gives the MII clock period
169 * in microseconds. (was 50, but this gives 6.4ms for each MII transaction!)
173 /* store this information for the driver.. */
176 * If I have to wait until memory is available to send a
177 * packet, I will store the skbuff here, until I get the
178 * desired memory. Then, I'll send it out and free it.
180 struct sk_buff
*saved_skb
;
183 * these are things that the kernel wants me to keep, so users
184 * can find out semi-useless statistics of how well the card is
187 struct net_device_stats stats
;
189 /* version/revision of the SMC91x chip */
192 /* Contains the current active transmission mode */
195 /* Contains the current active receive mode */
198 /* Contains the current active receive/phy mode */
205 struct mii_if_info mii
;
208 #ifdef SMC_USE_PXA_DMA
209 /* DMA needs the physical address of the chip */
215 #define DBG(n, args...) \
217 if (SMC_DEBUG >= (n)) \
218 printk(KERN_DEBUG args); \
221 #define PRINTK(args...) printk(args)
223 #define DBG(n, args...) do { } while(0)
224 #define PRINTK(args...) printk(KERN_DEBUG args)
228 static void PRINT_PKT(u_char
*buf
, int length
)
235 remainder
= length
% 16;
237 for (i
= 0; i
< lines
; i
++) {
239 for (cur
= 0; cur
< 8; cur
++) {
243 printk("%02x%02x ", a
, b
);
247 for (i
= 0; i
< remainder
/2 ; i
++) {
251 printk("%02x%02x ", a
, b
);
256 #define PRINT_PKT(x...) do { } while(0)
260 /* this enables an interrupt in the interrupt mask register */
261 #define SMC_ENABLE_INT(x) do { \
262 unsigned char mask; \
263 mask = SMC_GET_INT_MASK(); \
265 SMC_SET_INT_MASK(mask); \
268 /* this disables an interrupt from the interrupt mask register */
269 #define SMC_DISABLE_INT(x) do { \
270 unsigned char mask; \
271 mask = SMC_GET_INT_MASK(); \
273 SMC_SET_INT_MASK(mask); \
277 * Wait while MMU is busy. This is usually in the order of a few nanosecs
278 * if at all, but let's avoid deadlocking the system if the hardware
279 * decides to go south.
281 #define SMC_WAIT_MMU_BUSY() do { \
282 if (unlikely(SMC_GET_MMU_CMD() & MC_BUSY)) { \
283 unsigned long timeout = jiffies + 2; \
284 while (SMC_GET_MMU_CMD() & MC_BUSY) { \
285 if (time_after(jiffies, timeout)) { \
286 printk("%s: timeout %s line %d\n", \
287 dev->name, __FILE__, __LINE__); \
297 * this does a soft reset on the device
299 static void smc_reset(struct net_device
*dev
)
301 unsigned long ioaddr
= dev
->base_addr
;
302 unsigned int ctl
, cfg
;
304 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
307 * This resets the registers mostly to defaults, but doesn't
308 * affect EEPROM. That seems unnecessary
311 SMC_SET_RCR(RCR_SOFTRST
);
314 * Setup the Configuration Register
315 * This is necessary because the CONFIG_REG is not affected
320 cfg
= CONFIG_DEFAULT
;
323 * Setup for fast accesses if requested. If the card/system
324 * can't handle it then there will be no recovery except for
325 * a hard reset or power cycle
328 cfg
|= CONFIG_NO_WAIT
;
331 * Release from possible power-down state
332 * Configuration register is not affected by Soft Reset
334 cfg
|= CONFIG_EPH_POWER_EN
;
338 /* this should pause enough for the chip to be happy */
340 * elaborate? What does the chip _need_? --jgarzik
342 * This seems to be undocumented, but something the original
343 * driver(s) have always done. Suspect undocumented timing
344 * info/determined empirically. --rmk
348 /* Disable transmit and receive functionality */
350 SMC_SET_RCR(RCR_CLEAR
);
351 SMC_SET_TCR(TCR_CLEAR
);
354 ctl
= SMC_GET_CTL() | CTL_LE_ENABLE
;
357 * Set the control register to automatically release successfully
358 * transmitted packets, to make the best use out of our limited
361 #if ! THROTTLE_TX_PKTS
362 ctl
|= CTL_AUTO_RELEASE
;
364 ctl
&= ~CTL_AUTO_RELEASE
;
368 /* Disable all interrupts */
373 SMC_SET_MMU_CMD(MC_RESET
);
378 * Enable Interrupts, Receive, and Transmit
380 static void smc_enable(struct net_device
*dev
)
382 unsigned long ioaddr
= dev
->base_addr
;
383 struct smc_local
*lp
= netdev_priv(dev
);
386 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
388 /* see the header file for options in TCR/RCR DEFAULT */
390 SMC_SET_TCR(lp
->tcr_cur_mode
);
391 SMC_SET_RCR(lp
->rcr_cur_mode
);
393 /* now, enable interrupts */
394 mask
= IM_EPH_INT
|IM_RX_OVRN_INT
|IM_RCV_INT
;
395 if (lp
->version
>= (CHIP_91100
<< 4))
398 SMC_SET_INT_MASK(mask
);
402 * this puts the device in an inactive state
404 static void smc_shutdown(unsigned long ioaddr
)
406 DBG(2, "%s: %s\n", CARDNAME
, __FUNCTION__
);
408 /* no more interrupts for me */
412 /* and tell the card to stay away from that nasty outside world */
414 SMC_SET_RCR(RCR_CLEAR
);
415 SMC_SET_TCR(TCR_CLEAR
);
418 /* finally, shut the chip down */
420 SMC_SET_CONFIG(SMC_GET_CONFIG() & ~CONFIG_EPH_POWER_EN
);
425 * This is the procedure to handle the receipt of a packet.
427 static inline void smc_rcv(struct net_device
*dev
)
429 struct smc_local
*lp
= netdev_priv(dev
);
430 unsigned long ioaddr
= dev
->base_addr
;
431 unsigned int packet_number
, status
, packet_len
;
433 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
435 packet_number
= SMC_GET_RXFIFO();
436 if (unlikely(packet_number
& RXFIFO_REMPTY
)) {
437 PRINTK("%s: smc_rcv with nothing on FIFO.\n", dev
->name
);
441 /* read from start of packet */
442 SMC_SET_PTR(PTR_READ
| PTR_RCV
| PTR_AUTOINC
);
444 /* First two words are status and packet length */
445 SMC_GET_PKT_HDR(status
, packet_len
);
446 packet_len
&= 0x07ff; /* mask off top bits */
447 DBG(2, "%s: RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
448 dev
->name
, packet_number
, status
,
449 packet_len
, packet_len
);
451 if (unlikely(status
& RS_ERRORS
)) {
452 lp
->stats
.rx_errors
++;
453 if (status
& RS_ALGNERR
)
454 lp
->stats
.rx_frame_errors
++;
455 if (status
& (RS_TOOSHORT
| RS_TOOLONG
))
456 lp
->stats
.rx_length_errors
++;
457 if (status
& RS_BADCRC
)
458 lp
->stats
.rx_crc_errors
++;
462 unsigned int data_len
;
464 /* set multicast stats */
465 if (status
& RS_MULTICAST
)
466 lp
->stats
.multicast
++;
469 * Actual payload is packet_len - 4 (or 3 if odd byte).
470 * We want skb_reserve(2) and the final ctrl word
471 * (2 bytes, possibly containing the payload odd byte).
472 * Ence packet_len - 4 + 2 + 2.
474 skb
= dev_alloc_skb(packet_len
);
475 if (unlikely(skb
== NULL
)) {
476 printk(KERN_NOTICE
"%s: Low memory, packet dropped.\n",
478 lp
->stats
.rx_dropped
++;
482 /* Align IP header to 32 bits */
485 /* BUG: the LAN91C111 rev A never sets this bit. Force it. */
486 if (lp
->version
== 0x90)
487 status
|= RS_ODDFRAME
;
490 * If odd length: packet_len - 3,
491 * otherwise packet_len - 4.
493 data_len
= packet_len
- ((status
& RS_ODDFRAME
) ? 3 : 4);
494 data
= skb_put(skb
, data_len
);
495 SMC_PULL_DATA(data
, packet_len
- 2);
497 PRINT_PKT(data
, packet_len
- 2);
499 dev
->last_rx
= jiffies
;
501 skb
->protocol
= eth_type_trans(skb
, dev
);
503 lp
->stats
.rx_packets
++;
504 lp
->stats
.rx_bytes
+= data_len
;
509 SMC_SET_MMU_CMD(MC_RELEASE
);
513 * This is called to actually send a packet to the chip.
514 * Returns non-zero when successful.
516 static void smc_hardware_send_packet(struct net_device
*dev
)
518 struct smc_local
*lp
= netdev_priv(dev
);
519 unsigned long ioaddr
= dev
->base_addr
;
520 struct sk_buff
*skb
= lp
->saved_skb
;
521 unsigned int packet_no
, len
;
524 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
526 packet_no
= SMC_GET_AR();
527 if (unlikely(packet_no
& AR_FAILED
)) {
528 printk("%s: Memory allocation failed.\n", dev
->name
);
529 lp
->saved_skb
= NULL
;
530 lp
->stats
.tx_errors
++;
531 lp
->stats
.tx_fifo_errors
++;
532 dev_kfree_skb_any(skb
);
536 /* point to the beginning of the packet */
537 SMC_SET_PN(packet_no
);
538 SMC_SET_PTR(PTR_AUTOINC
);
542 DBG(2, "%s: TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
543 dev
->name
, packet_no
, len
, len
, buf
);
547 * Send the packet length (+6 for status words, length, and ctl.
548 * The card will pad to 64 bytes with zeroes if packet is too small.
550 SMC_PUT_PKT_HDR(0, len
+ 6);
552 /* send the actual data */
553 SMC_PUSH_DATA(buf
, len
& ~1);
555 /* Send final ctl word with the last byte if there is one */
556 SMC_outw(((len
& 1) ? (0x2000 | buf
[len
-1]) : 0), ioaddr
, DATA_REG
);
558 /* and let the chipset deal with it */
559 SMC_SET_MMU_CMD(MC_ENQUEUE
);
560 SMC_ACK_INT(IM_TX_EMPTY_INT
);
562 dev
->trans_start
= jiffies
;
563 dev_kfree_skb_any(skb
);
564 lp
->saved_skb
= NULL
;
565 lp
->stats
.tx_packets
++;
566 lp
->stats
.tx_bytes
+= len
;
570 * Since I am not sure if I will have enough room in the chip's ram
571 * to store the packet, I call this routine which either sends it
572 * now, or set the card to generates an interrupt when ready
575 static int smc_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
577 struct smc_local
*lp
= netdev_priv(dev
);
578 unsigned long ioaddr
= dev
->base_addr
;
579 unsigned int numPages
, poll_count
, status
, saved_bank
;
582 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
584 spin_lock_irqsave(&lp
->lock
, flags
);
586 BUG_ON(lp
->saved_skb
!= NULL
);
590 * The MMU wants the number of pages to be the number of 256 bytes
591 * 'pages', minus 1 (since a packet can't ever have 0 pages :))
593 * The 91C111 ignores the size bits, but earlier models don't.
595 * Pkt size for allocating is data length +6 (for additional status
596 * words, length and ctl)
598 * If odd size then last byte is included in ctl word.
600 numPages
= ((skb
->len
& ~1) + (6 - 1)) >> 8;
601 if (unlikely(numPages
> 7)) {
602 printk("%s: Far too big packet error.\n", dev
->name
);
603 lp
->saved_skb
= NULL
;
604 lp
->stats
.tx_errors
++;
605 lp
->stats
.tx_dropped
++;
607 spin_unlock_irqrestore(&lp
->lock
, flags
);
611 /* now, try to allocate the memory */
612 saved_bank
= SMC_CURRENT_BANK();
614 SMC_SET_MMU_CMD(MC_ALLOC
| numPages
);
617 * Poll the chip for a short amount of time in case the
618 * allocation succeeds quickly.
620 poll_count
= MEMORY_WAIT_TIME
;
622 status
= SMC_GET_INT();
623 if (status
& IM_ALLOC_INT
) {
624 SMC_ACK_INT(IM_ALLOC_INT
);
627 } while (--poll_count
);
630 /* oh well, wait until the chip finds memory later */
631 netif_stop_queue(dev
);
632 DBG(2, "%s: TX memory allocation deferred.\n", dev
->name
);
633 SMC_ENABLE_INT(IM_ALLOC_INT
);
636 * Allocation succeeded: push packet to the chip's own memory
639 * If THROTTLE_TX_PKTS is selected that means we don't want
640 * more than a single TX packet taking up space in the chip's
641 * internal memory at all time, in which case we stop the
642 * queue right here until we're notified of TX completion.
644 * Otherwise we're quite happy to feed more TX packets right
645 * away for better TX throughput, in which case the queue is
649 netif_stop_queue(dev
);
651 smc_hardware_send_packet(dev
);
652 SMC_ENABLE_INT(IM_TX_INT
| IM_TX_EMPTY_INT
);
655 SMC_SELECT_BANK(saved_bank
);
656 spin_unlock_irqrestore(&lp
->lock
, flags
);
661 * This handles a TX interrupt, which is only called when:
662 * - a TX error occurred, or
663 * - CTL_AUTO_RELEASE is not set and TX of a packet completed.
665 static void smc_tx(struct net_device
*dev
)
667 unsigned long ioaddr
= dev
->base_addr
;
668 struct smc_local
*lp
= netdev_priv(dev
);
669 unsigned int saved_packet
, packet_no
, tx_status
, pkt_len
;
671 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
673 /* If the TX FIFO is empty then nothing to do */
674 packet_no
= SMC_GET_TXFIFO();
675 if (unlikely(packet_no
& TXFIFO_TEMPTY
)) {
676 PRINTK("%s: smc_tx with nothing on FIFO.\n", dev
->name
);
680 /* select packet to read from */
681 saved_packet
= SMC_GET_PN();
682 SMC_SET_PN(packet_no
);
684 /* read the first word (status word) from this packet */
685 SMC_SET_PTR(PTR_AUTOINC
| PTR_READ
);
686 SMC_GET_PKT_HDR(tx_status
, pkt_len
);
687 DBG(2, "%s: TX STATUS 0x%04x PNR 0x%02x\n",
688 dev
->name
, tx_status
, packet_no
);
690 if (!(tx_status
& TS_SUCCESS
))
691 lp
->stats
.tx_errors
++;
692 if (tx_status
& TS_LOSTCAR
)
693 lp
->stats
.tx_carrier_errors
++;
695 if (tx_status
& TS_LATCOL
) {
696 PRINTK("%s: late collision occurred on last xmit\n", dev
->name
);
697 lp
->stats
.tx_window_errors
++;
698 if (!(lp
->stats
.tx_window_errors
& 63) && net_ratelimit()) {
699 printk(KERN_INFO
"%s: unexpectedly large numbers of "
700 "late collisions. Please check duplex "
701 "setting.\n", dev
->name
);
705 /* kill the packet */
707 SMC_SET_MMU_CMD(MC_FREEPKT
);
709 /* Don't restore Packet Number Reg until busy bit is cleared */
711 SMC_SET_PN(saved_packet
);
713 /* re-enable transmit */
715 SMC_SET_TCR(lp
->tcr_cur_mode
);
720 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
722 static void smc_mii_out(struct net_device
*dev
, unsigned int val
, int bits
)
724 unsigned long ioaddr
= dev
->base_addr
;
725 unsigned int mii_reg
, mask
;
727 mii_reg
= SMC_GET_MII() & ~(MII_MCLK
| MII_MDOE
| MII_MDO
);
730 for (mask
= 1 << (bits
- 1); mask
; mask
>>= 1) {
736 SMC_SET_MII(mii_reg
);
738 SMC_SET_MII(mii_reg
| MII_MCLK
);
743 static unsigned int smc_mii_in(struct net_device
*dev
, int bits
)
745 unsigned long ioaddr
= dev
->base_addr
;
746 unsigned int mii_reg
, mask
, val
;
748 mii_reg
= SMC_GET_MII() & ~(MII_MCLK
| MII_MDOE
| MII_MDO
);
749 SMC_SET_MII(mii_reg
);
751 for (mask
= 1 << (bits
- 1), val
= 0; mask
; mask
>>= 1) {
752 if (SMC_GET_MII() & MII_MDI
)
755 SMC_SET_MII(mii_reg
);
757 SMC_SET_MII(mii_reg
| MII_MCLK
);
765 * Reads a register from the MII Management serial interface
767 static int smc_phy_read(struct net_device
*dev
, int phyaddr
, int phyreg
)
769 unsigned long ioaddr
= dev
->base_addr
;
770 unsigned int phydata
, old_bank
;
772 /* Save the current bank, and select bank 3 */
773 old_bank
= SMC_CURRENT_BANK();
777 smc_mii_out(dev
, 0xffffffff, 32);
779 /* Start code (01) + read (10) + phyaddr + phyreg */
780 smc_mii_out(dev
, 6 << 10 | phyaddr
<< 5 | phyreg
, 14);
782 /* Turnaround (2bits) + phydata */
783 phydata
= smc_mii_in(dev
, 18);
785 /* Return to idle state */
786 SMC_SET_MII(SMC_GET_MII() & ~(MII_MCLK
|MII_MDOE
|MII_MDO
));
788 /* And select original bank */
789 SMC_SELECT_BANK(old_bank
);
791 DBG(3, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
792 __FUNCTION__
, phyaddr
, phyreg
, phydata
);
798 * Writes a register to the MII Management serial interface
800 static void smc_phy_write(struct net_device
*dev
, int phyaddr
, int phyreg
,
803 unsigned long ioaddr
= dev
->base_addr
;
804 unsigned int old_bank
;
806 /* Save the current bank, and select bank 3 */
807 old_bank
= SMC_CURRENT_BANK();
811 smc_mii_out(dev
, 0xffffffff, 32);
813 /* Start code (01) + write (01) + phyaddr + phyreg + turnaround + phydata */
814 smc_mii_out(dev
, 5 << 28 | phyaddr
<< 23 | phyreg
<< 18 | 2 << 16 | phydata
, 32);
816 /* Return to idle state */
817 SMC_SET_MII(SMC_GET_MII() & ~(MII_MCLK
|MII_MDOE
|MII_MDO
));
819 /* And select original bank */
820 SMC_SELECT_BANK(old_bank
);
822 DBG(3, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
823 __FUNCTION__
, phyaddr
, phyreg
, phydata
);
827 * Finds and reports the PHY address
829 static void smc_detect_phy(struct net_device
*dev
)
831 struct smc_local
*lp
= netdev_priv(dev
);
834 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
839 * Scan all 32 PHY addresses if necessary, starting at
840 * PHY#1 to PHY#31, and then PHY#0 last.
842 for (phyaddr
= 1; phyaddr
< 33; ++phyaddr
) {
843 unsigned int id1
, id2
;
845 /* Read the PHY identifiers */
846 id1
= smc_phy_read(dev
, phyaddr
& 31, MII_PHYSID1
);
847 id2
= smc_phy_read(dev
, phyaddr
& 31, MII_PHYSID2
);
849 DBG(3, "%s: phy_id1=0x%x, phy_id2=0x%x\n",
850 dev
->name
, id1
, id2
);
852 /* Make sure it is a valid identifier */
853 if (id1
!= 0x0000 && id1
!= 0xffff && id1
!= 0x8000 &&
854 id2
!= 0x0000 && id2
!= 0xffff && id2
!= 0x8000) {
855 /* Save the PHY's address */
856 lp
->mii
.phy_id
= phyaddr
& 31;
857 lp
->phy_type
= id1
<< 16 | id2
;
864 * Sets the PHY to a configuration as determined by the user
866 static int smc_phy_fixed(struct net_device
*dev
)
868 struct smc_local
*lp
= netdev_priv(dev
);
869 unsigned long ioaddr
= dev
->base_addr
;
870 int phyaddr
= lp
->mii
.phy_id
;
873 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
875 /* Enter Link Disable state */
876 cfg1
= smc_phy_read(dev
, phyaddr
, PHY_CFG1_REG
);
877 cfg1
|= PHY_CFG1_LNKDIS
;
878 smc_phy_write(dev
, phyaddr
, PHY_CFG1_REG
, cfg1
);
881 * Set our fixed capabilities
882 * Disable auto-negotiation
887 bmcr
|= BMCR_FULLDPLX
;
889 if (lp
->ctl_rspeed
== 100)
890 bmcr
|= BMCR_SPEED100
;
892 /* Write our capabilities to the phy control register */
893 smc_phy_write(dev
, phyaddr
, MII_BMCR
, bmcr
);
895 /* Re-Configure the Receive/Phy Control register */
896 SMC_SET_RPC(lp
->rpc_cur_mode
);
902 * smc_phy_reset - reset the phy
906 * Issue a software reset for the specified PHY and
907 * wait up to 100ms for the reset to complete. We should
908 * not access the PHY for 50ms after issuing the reset.
910 * The time to wait appears to be dependent on the PHY.
912 * Must be called with lp->lock locked.
914 static int smc_phy_reset(struct net_device
*dev
, int phy
)
916 struct smc_local
*lp
= netdev_priv(dev
);
920 smc_phy_write(dev
, phy
, MII_BMCR
, BMCR_RESET
);
922 for (timeout
= 2; timeout
; timeout
--) {
923 spin_unlock_irq(&lp
->lock
);
925 spin_lock_irq(&lp
->lock
);
927 bmcr
= smc_phy_read(dev
, phy
, MII_BMCR
);
928 if (!(bmcr
& BMCR_RESET
))
932 return bmcr
& BMCR_RESET
;
936 * smc_phy_powerdown - powerdown phy
940 * Power down the specified PHY
942 static void smc_phy_powerdown(struct net_device
*dev
, int phy
)
944 struct smc_local
*lp
= netdev_priv(dev
);
947 spin_lock_irq(&lp
->lock
);
948 bmcr
= smc_phy_read(dev
, phy
, MII_BMCR
);
949 smc_phy_write(dev
, phy
, MII_BMCR
, bmcr
| BMCR_PDOWN
);
950 spin_unlock_irq(&lp
->lock
);
954 * smc_phy_check_media - check the media status and adjust TCR
956 * @init: set true for initialisation
958 * Select duplex mode depending on negotiation state. This
959 * also updates our carrier state.
961 static void smc_phy_check_media(struct net_device
*dev
, int init
)
963 struct smc_local
*lp
= netdev_priv(dev
);
964 unsigned long ioaddr
= dev
->base_addr
;
966 if (mii_check_media(&lp
->mii
, netif_msg_link(lp
), init
)) {
967 unsigned int old_bank
;
969 /* duplex state has changed */
970 if (lp
->mii
.full_duplex
) {
971 lp
->tcr_cur_mode
|= TCR_SWFDUP
;
973 lp
->tcr_cur_mode
&= ~TCR_SWFDUP
;
976 old_bank
= SMC_CURRENT_BANK();
978 SMC_SET_TCR(lp
->tcr_cur_mode
);
979 SMC_SELECT_BANK(old_bank
);
984 * Configures the specified PHY through the MII management interface
985 * using Autonegotiation.
986 * Calls smc_phy_fixed() if the user has requested a certain config.
987 * If RPC ANEG bit is set, the media selection is dependent purely on
988 * the selection by the MII (either in the MII BMCR reg or the result
989 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
990 * is controlled by the RPC SPEED and RPC DPLX bits.
992 static void smc_phy_configure(struct net_device
*dev
)
994 struct smc_local
*lp
= netdev_priv(dev
);
995 unsigned long ioaddr
= dev
->base_addr
;
996 int phyaddr
= lp
->mii
.phy_id
;
997 int my_phy_caps
; /* My PHY capabilities */
998 int my_ad_caps
; /* My Advertised capabilities */
1001 DBG(3, "%s:smc_program_phy()\n", dev
->name
);
1003 spin_lock_irq(&lp
->lock
);
1006 * We should not be called if phy_type is zero.
1008 if (lp
->phy_type
== 0)
1009 goto smc_phy_configure_exit
;
1011 if (smc_phy_reset(dev
, phyaddr
)) {
1012 printk("%s: PHY reset timed out\n", dev
->name
);
1013 goto smc_phy_configure_exit
;
1017 * Enable PHY Interrupts (for register 18)
1018 * Interrupts listed here are disabled
1020 smc_phy_write(dev
, phyaddr
, PHY_MASK_REG
,
1021 PHY_INT_LOSSSYNC
| PHY_INT_CWRD
| PHY_INT_SSD
|
1022 PHY_INT_ESD
| PHY_INT_RPOL
| PHY_INT_JAB
|
1023 PHY_INT_SPDDET
| PHY_INT_DPLXDET
);
1025 /* Configure the Receive/Phy Control register */
1027 SMC_SET_RPC(lp
->rpc_cur_mode
);
1029 /* If the user requested no auto neg, then go set his request */
1030 if (lp
->mii
.force_media
) {
1032 goto smc_phy_configure_exit
;
1035 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
1036 my_phy_caps
= smc_phy_read(dev
, phyaddr
, MII_BMSR
);
1038 if (!(my_phy_caps
& BMSR_ANEGCAPABLE
)) {
1039 printk(KERN_INFO
"Auto negotiation NOT supported\n");
1041 goto smc_phy_configure_exit
;
1044 my_ad_caps
= ADVERTISE_CSMA
; /* I am CSMA capable */
1046 if (my_phy_caps
& BMSR_100BASE4
)
1047 my_ad_caps
|= ADVERTISE_100BASE4
;
1048 if (my_phy_caps
& BMSR_100FULL
)
1049 my_ad_caps
|= ADVERTISE_100FULL
;
1050 if (my_phy_caps
& BMSR_100HALF
)
1051 my_ad_caps
|= ADVERTISE_100HALF
;
1052 if (my_phy_caps
& BMSR_10FULL
)
1053 my_ad_caps
|= ADVERTISE_10FULL
;
1054 if (my_phy_caps
& BMSR_10HALF
)
1055 my_ad_caps
|= ADVERTISE_10HALF
;
1057 /* Disable capabilities not selected by our user */
1058 if (lp
->ctl_rspeed
!= 100)
1059 my_ad_caps
&= ~(ADVERTISE_100BASE4
|ADVERTISE_100FULL
|ADVERTISE_100HALF
);
1061 if (!lp
->ctl_rfduplx
)
1062 my_ad_caps
&= ~(ADVERTISE_100FULL
|ADVERTISE_10FULL
);
1064 /* Update our Auto-Neg Advertisement Register */
1065 smc_phy_write(dev
, phyaddr
, MII_ADVERTISE
, my_ad_caps
);
1066 lp
->mii
.advertising
= my_ad_caps
;
1069 * Read the register back. Without this, it appears that when
1070 * auto-negotiation is restarted, sometimes it isn't ready and
1071 * the link does not come up.
1073 status
= smc_phy_read(dev
, phyaddr
, MII_ADVERTISE
);
1075 DBG(2, "%s: phy caps=%x\n", dev
->name
, my_phy_caps
);
1076 DBG(2, "%s: phy advertised caps=%x\n", dev
->name
, my_ad_caps
);
1078 /* Restart auto-negotiation process in order to advertise my caps */
1079 smc_phy_write(dev
, phyaddr
, MII_BMCR
, BMCR_ANENABLE
| BMCR_ANRESTART
);
1081 smc_phy_check_media(dev
, 1);
1083 smc_phy_configure_exit
:
1084 spin_unlock_irq(&lp
->lock
);
1090 * Purpose: Handle interrupts relating to PHY register 18. This is
1091 * called from the "hard" interrupt handler under our private spinlock.
1093 static void smc_phy_interrupt(struct net_device
*dev
)
1095 struct smc_local
*lp
= netdev_priv(dev
);
1096 int phyaddr
= lp
->mii
.phy_id
;
1099 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1101 if (lp
->phy_type
== 0)
1105 smc_phy_check_media(dev
, 0);
1107 /* Read PHY Register 18, Status Output */
1108 phy18
= smc_phy_read(dev
, phyaddr
, PHY_INT_REG
);
1109 if ((phy18
& PHY_INT_INT
) == 0)
1114 /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
1116 static void smc_10bt_check_media(struct net_device
*dev
, int init
)
1118 struct smc_local
*lp
= netdev_priv(dev
);
1119 unsigned long ioaddr
= dev
->base_addr
;
1120 unsigned int old_carrier
, new_carrier
, old_bank
;
1122 old_bank
= SMC_CURRENT_BANK();
1124 old_carrier
= netif_carrier_ok(dev
) ? 1 : 0;
1125 new_carrier
= SMC_inw(ioaddr
, EPH_STATUS_REG
) & ES_LINK_OK
? 1 : 0;
1127 if (init
|| (old_carrier
!= new_carrier
)) {
1129 netif_carrier_off(dev
);
1131 netif_carrier_on(dev
);
1133 if (netif_msg_link(lp
))
1134 printk(KERN_INFO
"%s: link %s\n", dev
->name
,
1135 new_carrier
? "up" : "down");
1137 SMC_SELECT_BANK(old_bank
);
1140 static void smc_eph_interrupt(struct net_device
*dev
)
1142 unsigned long ioaddr
= dev
->base_addr
;
1143 unsigned int old_bank
, ctl
;
1145 smc_10bt_check_media(dev
, 0);
1147 old_bank
= SMC_CURRENT_BANK();
1150 ctl
= SMC_GET_CTL();
1151 SMC_SET_CTL(ctl
& ~CTL_LE_ENABLE
);
1154 SMC_SELECT_BANK(old_bank
);
1158 * This is the main routine of the driver, to handle the device when
1159 * it needs some attention.
1161 static irqreturn_t
smc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1163 struct net_device
*dev
= dev_id
;
1164 unsigned long ioaddr
= dev
->base_addr
;
1165 struct smc_local
*lp
= netdev_priv(dev
);
1166 int status
, mask
, timeout
, card_stats
;
1167 int saved_bank
, saved_pointer
;
1169 DBG(3, "%s: %s\n", dev
->name
, __FUNCTION__
);
1171 spin_lock(&lp
->lock
);
1173 saved_bank
= SMC_CURRENT_BANK();
1175 saved_pointer
= SMC_GET_PTR();
1176 mask
= SMC_GET_INT_MASK();
1177 SMC_SET_INT_MASK(0);
1179 /* set a timeout value, so I don't stay here forever */
1183 status
= SMC_GET_INT();
1185 DBG(2, "%s: IRQ 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
1186 dev
->name
, status
, mask
,
1187 ({ int meminfo
; SMC_SELECT_BANK(0);
1188 meminfo
= SMC_GET_MIR();
1189 SMC_SELECT_BANK(2); meminfo
; }),
1196 if (status
& IM_RCV_INT
) {
1197 DBG(3, "%s: RX irq\n", dev
->name
);
1199 } else if (status
& IM_TX_INT
) {
1200 DBG(3, "%s: TX int\n", dev
->name
);
1202 SMC_ACK_INT(IM_TX_INT
);
1203 #if THROTTLE_TX_PKTS
1204 netif_wake_queue(dev
);
1206 } else if (status
& IM_ALLOC_INT
) {
1207 DBG(3, "%s: Allocation irq\n", dev
->name
);
1208 smc_hardware_send_packet(dev
);
1209 mask
|= (IM_TX_INT
| IM_TX_EMPTY_INT
);
1210 mask
&= ~IM_ALLOC_INT
;
1211 #if ! THROTTLE_TX_PKTS
1212 netif_wake_queue(dev
);
1214 } else if (status
& IM_TX_EMPTY_INT
) {
1215 DBG(3, "%s: TX empty\n", dev
->name
);
1216 mask
&= ~IM_TX_EMPTY_INT
;
1220 card_stats
= SMC_GET_COUNTER();
1223 /* single collisions */
1224 lp
->stats
.collisions
+= card_stats
& 0xF;
1227 /* multiple collisions */
1228 lp
->stats
.collisions
+= card_stats
& 0xF;
1229 } else if (status
& IM_RX_OVRN_INT
) {
1230 DBG(1, "%s: RX overrun\n", dev
->name
);
1231 SMC_ACK_INT(IM_RX_OVRN_INT
);
1232 lp
->stats
.rx_errors
++;
1233 lp
->stats
.rx_fifo_errors
++;
1234 } else if (status
& IM_EPH_INT
) {
1235 smc_eph_interrupt(dev
);
1236 } else if (status
& IM_MDINT
) {
1237 SMC_ACK_INT(IM_MDINT
);
1238 smc_phy_interrupt(dev
);
1239 } else if (status
& IM_ERCV_INT
) {
1240 SMC_ACK_INT(IM_ERCV_INT
);
1241 PRINTK("%s: UNSUPPORTED: ERCV INTERRUPT \n", dev
->name
);
1244 } while (--timeout
);
1246 /* restore register states */
1247 SMC_SET_INT_MASK(mask
);
1248 SMC_SET_PTR(saved_pointer
);
1249 SMC_SELECT_BANK(saved_bank
);
1251 DBG(3, "%s: Interrupt done (%d loops)\n", dev
->name
, 8-timeout
);
1253 spin_unlock(&lp
->lock
);
1255 * We return IRQ_HANDLED unconditionally here even if there was
1256 * nothing to do. There is a possibility that a packet might
1257 * get enqueued into the chip right after TX_EMPTY_INT is raised
1258 * but just before the CPU acknowledges the IRQ.
1259 * Better take an unneeded IRQ in some occasions than complexifying
1260 * the code for all cases.
1265 /* Our watchdog timed out. Called by the networking layer */
1266 static void smc_timeout(struct net_device
*dev
)
1268 struct smc_local
*lp
= netdev_priv(dev
);
1269 unsigned long flags
;
1271 spin_lock_irqsave(&lp
->lock
, flags
);
1272 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1279 * Reconfiguring the PHY doesn't seem like a bad idea here, but
1280 * it introduced a problem. Now that this is a timeout routine,
1281 * we are getting called from within an interrupt context.
1282 * smc_phy_configure() calls msleep() which calls
1283 * schedule_timeout() which calls schedule(). When schedule()
1284 * is called from an interrupt context, it prints out
1285 * "Scheduling in interrupt" and then calls BUG(). This is
1286 * obviously not desirable. This was worked around by removing
1287 * the call to smc_phy_configure() here because it didn't seem
1288 * absolutely necessary. Ultimately, if msleep() is
1289 * supposed to be usable from an interrupt context (which it
1290 * looks like it thinks it should handle), it should be fixed.
1292 if (lp
->phy_type
!= 0)
1293 smc_phy_configure(dev
);
1296 /* clear anything saved */
1297 if (lp
->saved_skb
!= NULL
) {
1298 dev_kfree_skb (lp
->saved_skb
);
1299 lp
->saved_skb
= NULL
;
1300 lp
->stats
.tx_errors
++;
1301 lp
->stats
.tx_aborted_errors
++;
1303 /* We can accept TX packets again */
1304 dev
->trans_start
= jiffies
;
1306 spin_unlock_irqrestore(&lp
->lock
, flags
);
1308 netif_wake_queue(dev
);
1312 * This sets the internal hardware table to filter out unwanted multicast
1313 * packets before they take up memory.
1315 * The SMC chip uses a hash table where the high 6 bits of the CRC of
1316 * address are the offset into the table. If that bit is 1, then the
1317 * multicast packet is accepted. Otherwise, it's dropped silently.
1319 * To use the 6 bits as an offset into the table, the high 3 bits are the
1320 * number of the 8 bit register, while the low 3 bits are the bit within
1323 * This routine is based very heavily on the one provided by Peter Cammaert.
1326 smc_setmulticast(unsigned long ioaddr
, int count
, struct dev_mc_list
*addrs
)
1329 unsigned char multicast_table
[8];
1330 struct dev_mc_list
*cur_addr
;
1332 /* table for flipping the order of 3 bits */
1333 static unsigned char invert3
[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
1335 /* start with a table of all zeros: reject all */
1336 memset(multicast_table
, 0, sizeof(multicast_table
));
1339 for (i
= 0; i
< count
; i
++, cur_addr
= cur_addr
->next
) {
1342 /* do we have a pointer here? */
1345 /* make sure this is a multicast address - shouldn't this
1346 be a given if we have it here ? */
1347 if (!(*cur_addr
->dmi_addr
& 1))
1350 /* only use the low order bits */
1351 position
= crc32_le(~0, cur_addr
->dmi_addr
, 6) & 0x3f;
1353 /* do some messy swapping to put the bit in the right spot */
1354 multicast_table
[invert3
[position
&7]] |=
1355 (1<<invert3
[(position
>>3)&7]);
1358 /* now, the table can be loaded into the chipset */
1360 SMC_SET_MCAST(multicast_table
);
1364 * This routine will, depending on the values passed to it,
1365 * either make it accept multicast packets, go into
1366 * promiscuous mode (for TCPDUMP and cousins) or accept
1367 * a select set of multicast packets
1369 static void smc_set_multicast_list(struct net_device
*dev
)
1371 struct smc_local
*lp
= netdev_priv(dev
);
1372 unsigned long ioaddr
= dev
->base_addr
;
1374 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1377 if (dev
->flags
& IFF_PROMISC
) {
1378 DBG(2, "%s: RCR_PRMS\n", dev
->name
);
1379 lp
->rcr_cur_mode
|= RCR_PRMS
;
1380 SMC_SET_RCR(lp
->rcr_cur_mode
);
1383 /* BUG? I never disable promiscuous mode if multicasting was turned on.
1384 Now, I turn off promiscuous mode, but I don't do anything to multicasting
1385 when promiscuous mode is turned on.
1389 * Here, I am setting this to accept all multicast packets.
1390 * I don't need to zero the multicast table, because the flag is
1391 * checked before the table is
1393 else if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
> 16) {
1394 lp
->rcr_cur_mode
|= RCR_ALMUL
;
1395 SMC_SET_RCR(lp
->rcr_cur_mode
);
1396 DBG(2, "%s: RCR_ALMUL\n", dev
->name
);
1400 * We just get all multicast packets even if we only want them
1401 * from one source. This will be changed at some future point.
1403 else if (dev
->mc_count
) {
1404 /* support hardware multicasting */
1406 /* be sure I get rid of flags I might have set */
1407 lp
->rcr_cur_mode
&= ~(RCR_PRMS
| RCR_ALMUL
);
1408 SMC_SET_RCR(lp
->rcr_cur_mode
);
1410 * NOTE: this has to set the bank, so make sure it is the
1411 * last thing called. The bank is set to zero at the top
1413 smc_setmulticast(ioaddr
, dev
->mc_count
, dev
->mc_list
);
1415 DBG(2, "%s: ~(RCR_PRMS|RCR_ALMUL)\n", dev
->name
);
1416 lp
->rcr_cur_mode
&= ~(RCR_PRMS
| RCR_ALMUL
);
1417 SMC_SET_RCR(lp
->rcr_cur_mode
);
1420 * since I'm disabling all multicast entirely, I need to
1421 * clear the multicast list
1430 * Open and Initialize the board
1432 * Set up everything, reset the card, etc..
1435 smc_open(struct net_device
*dev
)
1437 struct smc_local
*lp
= netdev_priv(dev
);
1438 unsigned long ioaddr
= dev
->base_addr
;
1440 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1443 * Check that the address is valid. If its not, refuse
1444 * to bring the device up. The user must specify an
1445 * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
1447 if (!is_valid_ether_addr(dev
->dev_addr
)) {
1448 DBG(2, "smc_open: no valid ethernet hw addr\n");
1452 /* clear out all the junk that was put here before... */
1453 lp
->saved_skb
= NULL
;
1455 /* Setup the default Register Modes */
1456 lp
->tcr_cur_mode
= TCR_DEFAULT
;
1457 lp
->rcr_cur_mode
= RCR_DEFAULT
;
1458 lp
->rpc_cur_mode
= RPC_DEFAULT
;
1461 * If we are not using a MII interface, we need to
1462 * monitor our own carrier signal to detect faults.
1464 if (lp
->phy_type
== 0)
1465 lp
->tcr_cur_mode
|= TCR_MON_CSN
;
1467 /* reset the hardware */
1472 SMC_SET_MAC_ADDR(dev
->dev_addr
);
1474 /* Configure the PHY */
1475 if (lp
->phy_type
!= 0)
1476 smc_phy_configure(dev
);
1478 spin_lock_irq(&lp
->lock
);
1479 smc_10bt_check_media(dev
, 1);
1480 spin_unlock_irq(&lp
->lock
);
1484 * make sure to initialize the link state with netif_carrier_off()
1485 * somewhere, too --jgarzik
1487 * smc_phy_configure() and smc_10bt_check_media() does that. --rmk
1489 netif_start_queue(dev
);
1496 * this makes the board clean up everything that it can
1497 * and not talk to the outside world. Caused by
1498 * an 'ifconfig ethX down'
1500 static int smc_close(struct net_device
*dev
)
1502 struct smc_local
*lp
= netdev_priv(dev
);
1504 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1506 netif_stop_queue(dev
);
1507 netif_carrier_off(dev
);
1509 /* clear everything */
1510 smc_shutdown(dev
->base_addr
);
1512 if (lp
->phy_type
!= 0)
1513 smc_phy_powerdown(dev
, lp
->mii
.phy_id
);
1519 * Get the current statistics.
1520 * This may be called with the card open or closed.
1522 static struct net_device_stats
*smc_query_statistics(struct net_device
*dev
)
1524 struct smc_local
*lp
= netdev_priv(dev
);
1526 DBG(2, "%s: %s\n", dev
->name
, __FUNCTION__
);
1535 smc_ethtool_getsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1537 struct smc_local
*lp
= netdev_priv(dev
);
1543 if (lp
->phy_type
!= 0) {
1544 spin_lock_irq(&lp
->lock
);
1545 ret
= mii_ethtool_gset(&lp
->mii
, cmd
);
1546 spin_unlock_irq(&lp
->lock
);
1548 cmd
->supported
= SUPPORTED_10baseT_Half
|
1549 SUPPORTED_10baseT_Full
|
1550 SUPPORTED_TP
| SUPPORTED_AUI
;
1552 if (lp
->ctl_rspeed
== 10)
1553 cmd
->speed
= SPEED_10
;
1554 else if (lp
->ctl_rspeed
== 100)
1555 cmd
->speed
= SPEED_100
;
1557 cmd
->autoneg
= AUTONEG_DISABLE
;
1558 cmd
->transceiver
= XCVR_INTERNAL
;
1560 cmd
->duplex
= lp
->tcr_cur_mode
& TCR_SWFDUP
? DUPLEX_FULL
: DUPLEX_HALF
;
1569 smc_ethtool_setsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1571 struct smc_local
*lp
= netdev_priv(dev
);
1574 if (lp
->phy_type
!= 0) {
1575 spin_lock_irq(&lp
->lock
);
1576 ret
= mii_ethtool_sset(&lp
->mii
, cmd
);
1577 spin_unlock_irq(&lp
->lock
);
1579 if (cmd
->autoneg
!= AUTONEG_DISABLE
||
1580 cmd
->speed
!= SPEED_10
||
1581 (cmd
->duplex
!= DUPLEX_HALF
&& cmd
->duplex
!= DUPLEX_FULL
) ||
1582 (cmd
->port
!= PORT_TP
&& cmd
->port
!= PORT_AUI
))
1585 // lp->port = cmd->port;
1586 lp
->ctl_rfduplx
= cmd
->duplex
== DUPLEX_FULL
;
1588 // if (netif_running(dev))
1589 // smc_set_port(dev);
1598 smc_ethtool_getdrvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1600 strncpy(info
->driver
, CARDNAME
, sizeof(info
->driver
));
1601 strncpy(info
->version
, version
, sizeof(info
->version
));
1602 strncpy(info
->bus_info
, dev
->class_dev
.dev
->bus_id
, sizeof(info
->bus_info
));
1605 static int smc_ethtool_nwayreset(struct net_device
*dev
)
1607 struct smc_local
*lp
= netdev_priv(dev
);
1610 if (lp
->phy_type
!= 0) {
1611 spin_lock_irq(&lp
->lock
);
1612 ret
= mii_nway_restart(&lp
->mii
);
1613 spin_unlock_irq(&lp
->lock
);
1619 static u32
smc_ethtool_getmsglevel(struct net_device
*dev
)
1621 struct smc_local
*lp
= netdev_priv(dev
);
1622 return lp
->msg_enable
;
1625 static void smc_ethtool_setmsglevel(struct net_device
*dev
, u32 level
)
1627 struct smc_local
*lp
= netdev_priv(dev
);
1628 lp
->msg_enable
= level
;
1631 static struct ethtool_ops smc_ethtool_ops
= {
1632 .get_settings
= smc_ethtool_getsettings
,
1633 .set_settings
= smc_ethtool_setsettings
,
1634 .get_drvinfo
= smc_ethtool_getdrvinfo
,
1636 .get_msglevel
= smc_ethtool_getmsglevel
,
1637 .set_msglevel
= smc_ethtool_setmsglevel
,
1638 .nway_reset
= smc_ethtool_nwayreset
,
1639 .get_link
= ethtool_op_get_link
,
1640 // .get_eeprom = smc_ethtool_geteeprom,
1641 // .set_eeprom = smc_ethtool_seteeprom,
1647 * This routine has a simple purpose -- make the SMC chip generate an
1648 * interrupt, so an auto-detect routine can detect it, and find the IRQ,
1651 * does this still work?
1653 * I just deleted auto_irq.c, since it was never built...
1656 static int __init
smc_findirq(unsigned long ioaddr
)
1659 unsigned long cookie
;
1661 DBG(2, "%s: %s\n", CARDNAME
, __FUNCTION__
);
1663 cookie
= probe_irq_on();
1666 * What I try to do here is trigger an ALLOC_INT. This is done
1667 * by allocating a small chunk of memory, which will give an interrupt
1670 /* enable ALLOCation interrupts ONLY */
1672 SMC_SET_INT_MASK(IM_ALLOC_INT
);
1675 * Allocate 512 bytes of memory. Note that the chip was just
1676 * reset so all the memory is available
1678 SMC_SET_MMU_CMD(MC_ALLOC
| 1);
1681 * Wait until positive that the interrupt has been generated
1686 int_status
= SMC_GET_INT();
1687 if (int_status
& IM_ALLOC_INT
)
1688 break; /* got the interrupt */
1689 } while (--timeout
);
1692 * there is really nothing that I can do here if timeout fails,
1693 * as autoirq_report will return a 0 anyway, which is what I
1694 * want in this case. Plus, the clean up is needed in both
1698 /* and disable all interrupts again */
1699 SMC_SET_INT_MASK(0);
1701 /* and return what I found */
1702 return probe_irq_off(cookie
);
1706 * Function: smc_probe(unsigned long ioaddr)
1709 * Tests to see if a given ioaddr points to an SMC91x chip.
1710 * Returns a 0 on success
1713 * (1) see if the high byte of BANK_SELECT is 0x33
1714 * (2) compare the ioaddr with the base register's address
1715 * (3) see if I recognize the chip ID in the appropriate register
1717 * Here I do typical initialization tasks.
1719 * o Initialize the structure if needed
1720 * o print out my vanity message if not done so already
1721 * o print out what type of hardware is detected
1722 * o print out the ethernet address
1724 * o set up my private data
1725 * o configure the dev structure with my subroutines
1726 * o actually GRAB the irq.
1729 static int __init
smc_probe(struct net_device
*dev
, unsigned long ioaddr
)
1731 struct smc_local
*lp
= netdev_priv(dev
);
1732 static int version_printed
= 0;
1734 unsigned int val
, revision_register
;
1735 const char *version_string
;
1737 DBG(2, "%s: %s\n", CARDNAME
, __FUNCTION__
);
1739 /* First, see if the high byte is 0x33 */
1740 val
= SMC_CURRENT_BANK();
1741 DBG(2, "%s: bank signature probe returned 0x%04x\n", CARDNAME
, val
);
1742 if ((val
& 0xFF00) != 0x3300) {
1743 if ((val
& 0xFF) == 0x33) {
1745 "%s: Detected possible byte-swapped interface"
1746 " at IOADDR 0x%lx\n", CARDNAME
, ioaddr
);
1753 * The above MIGHT indicate a device, but I need to write to
1754 * further test this.
1757 val
= SMC_CURRENT_BANK();
1758 if ((val
& 0xFF00) != 0x3300) {
1764 * well, we've already written once, so hopefully another
1765 * time won't hurt. This time, I need to switch the bank
1766 * register to bank 1, so I can access the base address
1770 val
= SMC_GET_BASE();
1771 val
= ((val
& 0x1F00) >> 3) << SMC_IO_SHIFT
;
1772 if ((ioaddr
& ((PAGE_SIZE
-1)<<SMC_IO_SHIFT
)) != val
) {
1773 printk("%s: IOADDR %lx doesn't match configuration (%x).\n",
1774 CARDNAME
, ioaddr
, val
);
1778 * check if the revision register is something that I
1779 * recognize. These might need to be added to later,
1780 * as future revisions could be added.
1783 revision_register
= SMC_GET_REV();
1784 DBG(2, "%s: revision = 0x%04x\n", CARDNAME
, revision_register
);
1785 version_string
= chip_ids
[ (revision_register
>> 4) & 0xF];
1786 if (!version_string
|| (revision_register
& 0xff00) != 0x3300) {
1787 /* I don't recognize this chip, so... */
1788 printk("%s: IO 0x%lx: Unrecognized revision register 0x%04x"
1789 ", Contact author.\n", CARDNAME
,
1790 ioaddr
, revision_register
);
1796 /* At this point I'll assume that the chip is an SMC91x. */
1797 if (version_printed
++ == 0)
1798 printk("%s", version
);
1800 /* fill in some of the fields */
1801 dev
->base_addr
= ioaddr
;
1802 lp
->version
= revision_register
& 0xff;
1804 /* Get the MAC address */
1806 SMC_GET_MAC_ADDR(dev
->dev_addr
);
1808 /* now, reset the chip, and put it into a known state */
1812 * If dev->irq is 0, then the device has to be banged on to see
1815 * This banging doesn't always detect the IRQ, for unknown reasons.
1816 * a workaround is to reset the chip and try again.
1818 * Interestingly, the DOS packet driver *SETS* the IRQ on the card to
1819 * be what is requested on the command line. I don't do that, mostly
1820 * because the card that I have uses a non-standard method of accessing
1821 * the IRQs, and because this _should_ work in most configurations.
1823 * Specifying an IRQ is done with the assumption that the user knows
1824 * what (s)he is doing. No checking is done!!!!
1831 dev
->irq
= smc_findirq(ioaddr
);
1834 /* kick the card and try again */
1838 if (dev
->irq
== 0) {
1839 printk("%s: Couldn't autodetect your IRQ. Use irq=xx.\n",
1844 dev
->irq
= irq_canonicalize(dev
->irq
);
1846 /* Fill in the fields of the device structure with ethernet values. */
1849 dev
->open
= smc_open
;
1850 dev
->stop
= smc_close
;
1851 dev
->hard_start_xmit
= smc_hard_start_xmit
;
1852 dev
->tx_timeout
= smc_timeout
;
1853 dev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1854 dev
->get_stats
= smc_query_statistics
;
1855 dev
->set_multicast_list
= smc_set_multicast_list
;
1856 dev
->ethtool_ops
= &smc_ethtool_ops
;
1858 spin_lock_init(&lp
->lock
);
1859 lp
->mii
.phy_id_mask
= 0x1f;
1860 lp
->mii
.reg_num_mask
= 0x1f;
1861 lp
->mii
.force_media
= 0;
1862 lp
->mii
.full_duplex
= 0;
1864 lp
->mii
.mdio_read
= smc_phy_read
;
1865 lp
->mii
.mdio_write
= smc_phy_write
;
1868 * Locate the phy, if any.
1870 if (lp
->version
>= (CHIP_91100
<< 4))
1871 smc_detect_phy(dev
);
1873 /* Set default parameters */
1874 lp
->msg_enable
= NETIF_MSG_LINK
;
1875 lp
->ctl_rfduplx
= 0;
1876 lp
->ctl_rspeed
= 10;
1878 if (lp
->version
>= (CHIP_91100
<< 4)) {
1879 lp
->ctl_rfduplx
= 1;
1880 lp
->ctl_rspeed
= 100;
1884 retval
= request_irq(dev
->irq
, &smc_interrupt
, 0, dev
->name
, dev
);
1888 #if !defined(__m32r__)
1889 set_irq_type(dev
->irq
, IRQT_RISING
);
1891 #ifdef SMC_USE_PXA_DMA
1893 int dma
= pxa_request_dma(dev
->name
, DMA_PRIO_LOW
,
1894 smc_pxa_dma_irq
, NULL
);
1900 retval
= register_netdev(dev
);
1902 /* now, print out the card info, in a short format.. */
1903 printk("%s: %s (rev %d) at %#lx IRQ %d",
1904 dev
->name
, version_string
, revision_register
& 0x0f,
1905 dev
->base_addr
, dev
->irq
);
1907 if (dev
->dma
!= (unsigned char)-1)
1908 printk(" DMA %d", dev
->dma
);
1910 printk("%s%s\n", nowait
? " [nowait]" : "",
1911 THROTTLE_TX_PKTS
? " [throttle_tx]" : "");
1913 if (!is_valid_ether_addr(dev
->dev_addr
)) {
1914 printk("%s: Invalid ethernet MAC address. Please "
1915 "set using ifconfig\n", dev
->name
);
1917 /* Print the Ethernet address */
1918 printk("%s: Ethernet addr: ", dev
->name
);
1919 for (i
= 0; i
< 5; i
++)
1920 printk("%2.2x:", dev
->dev_addr
[i
]);
1921 printk("%2.2x\n", dev
->dev_addr
[5]);
1924 if (lp
->phy_type
== 0) {
1925 PRINTK("%s: No PHY found\n", dev
->name
);
1926 } else if ((lp
->phy_type
& 0xfffffff0) == 0x0016f840) {
1927 PRINTK("%s: PHY LAN83C183 (LAN91C111 Internal)\n", dev
->name
);
1928 } else if ((lp
->phy_type
& 0xfffffff0) == 0x02821c50) {
1929 PRINTK("%s: PHY LAN83C180\n", dev
->name
);
1934 #ifdef SMC_USE_PXA_DMA
1935 if (retval
&& dev
->dma
!= (unsigned char)-1)
1936 pxa_free_dma(dev
->dma
);
1941 static int smc_enable_device(unsigned long attrib_phys
)
1943 unsigned long flags
;
1944 unsigned char ecor
, ecsr
;
1948 * Map the attribute space. This is overkill, but clean.
1950 addr
= ioremap(attrib_phys
, ATTRIB_SIZE
);
1955 * Reset the device. We must disable IRQs around this
1956 * since a reset causes the IRQ line become active.
1958 local_irq_save(flags
);
1959 ecor
= readb(addr
+ (ECOR
<< SMC_IO_SHIFT
)) & ~ECOR_RESET
;
1960 writeb(ecor
| ECOR_RESET
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
1961 readb(addr
+ (ECOR
<< SMC_IO_SHIFT
));
1964 * Wait 100us for the chip to reset.
1969 * The device will ignore all writes to the enable bit while
1970 * reset is asserted, even if the reset bit is cleared in the
1971 * same write. Must clear reset first, then enable the device.
1973 writeb(ecor
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
1974 writeb(ecor
| ECOR_ENABLE
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
1977 * Set the appropriate byte/word mode.
1979 ecsr
= readb(addr
+ (ECSR
<< SMC_IO_SHIFT
)) & ~ECSR_IOIS8
;
1980 #ifndef SMC_CAN_USE_16BIT
1983 writeb(ecsr
, addr
+ (ECSR
<< SMC_IO_SHIFT
));
1984 local_irq_restore(flags
);
1989 * Wait for the chip to wake up. We could poll the control
1990 * register in the main register space, but that isn't mapped
1991 * yet. We know this is going to take 750us.
2001 * dev->base_addr == 0, try to find all possible locations
2002 * dev->base_addr > 0x1ff, this is the address to check
2003 * dev->base_addr == <anything else>, return failure code
2006 * 0 --> there is a device
2007 * anything else, error
2009 static int smc_drv_probe(struct device
*dev
)
2011 struct platform_device
*pdev
= to_platform_device(dev
);
2012 struct net_device
*ndev
;
2013 struct resource
*res
, *ext
= NULL
;
2017 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2024 * Request the regions.
2026 if (!request_mem_region(res
->start
, SMC_IO_EXTENT
, "smc91x")) {
2031 ndev
= alloc_etherdev(sizeof(struct smc_local
));
2033 printk("%s: could not allocate device.\n", CARDNAME
);
2037 SET_MODULE_OWNER(ndev
);
2038 SET_NETDEV_DEV(ndev
, dev
);
2040 ndev
->dma
= (unsigned char)-1;
2041 ndev
->irq
= platform_get_irq(pdev
, 0);
2043 ext
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
2045 if (!request_mem_region(ext
->start
, ATTRIB_SIZE
, ndev
->name
)) {
2050 #if defined(CONFIG_SA1100_ASSABET)
2051 NCR_0
|= NCR_ENET_OSC_EN
;
2054 ret
= smc_enable_device(ext
->start
);
2059 addr
= ioremap(res
->start
, SMC_IO_EXTENT
);
2065 dev_set_drvdata(dev
, ndev
);
2066 ret
= smc_probe(ndev
, (unsigned long)addr
);
2068 dev_set_drvdata(dev
, NULL
);
2072 release_mem_region(ext
->start
, ATTRIB_SIZE
);
2075 release_mem_region(res
->start
, SMC_IO_EXTENT
);
2077 printk("%s: not found (%d).\n", CARDNAME
, ret
);
2079 #ifdef SMC_USE_PXA_DMA
2081 struct smc_local
*lp
= netdev_priv(ndev
);
2082 lp
->physaddr
= res
->start
;
2089 static int smc_drv_remove(struct device
*dev
)
2091 struct platform_device
*pdev
= to_platform_device(dev
);
2092 struct net_device
*ndev
= dev_get_drvdata(dev
);
2093 struct resource
*res
;
2095 dev_set_drvdata(dev
, NULL
);
2097 unregister_netdev(ndev
);
2099 free_irq(ndev
->irq
, ndev
);
2101 #ifdef SMC_USE_PXA_DMA
2102 if (ndev
->dma
!= (unsigned char)-1)
2103 pxa_free_dma(ndev
->dma
);
2105 iounmap((void *)ndev
->base_addr
);
2106 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
2108 release_mem_region(res
->start
, ATTRIB_SIZE
);
2109 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2110 release_mem_region(res
->start
, SMC_IO_EXTENT
);
2117 static int smc_drv_suspend(struct device
*dev
, u32 state
, u32 level
)
2119 struct net_device
*ndev
= dev_get_drvdata(dev
);
2121 if (ndev
&& level
== SUSPEND_DISABLE
) {
2122 if (netif_running(ndev
)) {
2123 netif_device_detach(ndev
);
2124 smc_shutdown(ndev
->base_addr
);
2130 static int smc_drv_resume(struct device
*dev
, u32 level
)
2132 struct platform_device
*pdev
= to_platform_device(dev
);
2133 struct net_device
*ndev
= dev_get_drvdata(dev
);
2135 if (ndev
&& level
== RESUME_ENABLE
) {
2136 struct smc_local
*lp
= netdev_priv(ndev
);
2137 unsigned long ioaddr
= ndev
->base_addr
;
2139 if (pdev
->num_resources
== 3)
2140 smc_enable_device(pdev
->resource
[2].start
);
2141 if (netif_running(ndev
)) {
2145 SMC_SET_MAC_ADDR(ndev
->dev_addr
);
2146 if (lp
->phy_type
!= 0)
2147 smc_phy_configure(ndev
);
2148 netif_device_attach(ndev
);
2154 static struct device_driver smc_driver
= {
2156 .bus
= &platform_bus_type
,
2157 .probe
= smc_drv_probe
,
2158 .remove
= smc_drv_remove
,
2159 .suspend
= smc_drv_suspend
,
2160 .resume
= smc_drv_resume
,
2163 static int __init
smc_init(void)
2169 "%s: You shouldn't use auto-probing with insmod!\n",
2174 return driver_register(&smc_driver
);
2177 static void __exit
smc_cleanup(void)
2179 driver_unregister(&smc_driver
);
2182 module_init(smc_init
);
2183 module_exit(smc_cleanup
);