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, see <http://www.gnu.org/licenses/>.
25 * io = for the base address
27 * nowait = 0 for normal wait states, 1 eliminates additional wait states
30 * Erik Stahlman <erik@vt.edu>
32 * hardware multicast code:
33 * Peter Cammaert <pc@denkart.be>
36 * Daris A Nevil <dnevil@snmc.com>
37 * Nicolas Pitre <nico@fluxnic.net>
38 * Russell King <rmk@arm.linux.org.uk>
41 * 08/20/00 Arnaldo Melo fix kfree(skb) in smc_hardware_send_packet
42 * 12/15/00 Christian Jullien fix "Warning: kfree_skb on hard IRQ"
43 * 03/16/01 Daris A Nevil modified smc9194.c for use with LAN91C111
44 * 08/22/01 Scott Anderson merge changes from smc9194 to smc91111
45 * 08/21/01 Pramod B Bhardwaj added support for RevB of LAN91C111
46 * 12/20/01 Jeff Sutherland initial port to Xscale PXA with DMA support
47 * 04/07/03 Nicolas Pitre unified SMC91x driver, killed irq races,
48 * more bus abstraction, big cleanup, etc.
49 * 29/09/03 Russell King - add driver model support
51 * - convert to use generic MII interface
52 * - add link up/down notification
53 * - don't try to handle full negotiation in
55 * - clean up (and fix stack overrun) in PHY
56 * MII read/write functions
57 * 22/09/04 Nicolas Pitre big update (see commit log for details)
59 static const char version
[] =
60 "smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@fluxnic.net>";
68 #include <linux/module.h>
69 #include <linux/kernel.h>
70 #include <linux/sched.h>
71 #include <linux/delay.h>
72 #include <linux/interrupt.h>
73 #include <linux/irq.h>
74 #include <linux/errno.h>
75 #include <linux/ioport.h>
76 #include <linux/crc32.h>
77 #include <linux/platform_device.h>
78 #include <linux/spinlock.h>
79 #include <linux/ethtool.h>
80 #include <linux/mii.h>
81 #include <linux/workqueue.h>
83 #include <linux/of_device.h>
85 #include <linux/netdevice.h>
86 #include <linux/etherdevice.h>
87 #include <linux/skbuff.h>
96 static int nowait
= SMC_NOWAIT
;
97 module_param(nowait
, int, 0400);
98 MODULE_PARM_DESC(nowait
, "set to 1 for no wait state");
101 * Transmit timeout, default 5 seconds.
103 static int watchdog
= 1000;
104 module_param(watchdog
, int, 0400);
105 MODULE_PARM_DESC(watchdog
, "transmit timeout in milliseconds");
107 MODULE_LICENSE("GPL");
108 MODULE_ALIAS("platform:smc91x");
111 * The internal workings of the driver. If you are changing anything
112 * here with the SMC stuff, you should have the datasheet and know
113 * what you are doing.
115 #define CARDNAME "smc91x"
118 * Use power-down feature of the chip
123 * Wait time for memory to be free. This probably shouldn't be
124 * tuned that much, as waiting for this means nothing else happens
127 #define MEMORY_WAIT_TIME 16
130 * The maximum number of processing loops allowed for each call to the
133 #define MAX_IRQ_LOOPS 8
136 * This selects whether TX packets are sent one by one to the SMC91x internal
137 * memory and throttled until transmission completes. This may prevent
138 * RX overruns a litle by keeping much of the memory free for RX packets
139 * but to the expense of reduced TX throughput and increased IRQ overhead.
140 * Note this is not a cure for a too slow data bus or too high IRQ latency.
142 #define THROTTLE_TX_PKTS 0
145 * The MII clock high/low times. 2x this number gives the MII clock period
146 * in microseconds. (was 50, but this gives 6.4ms for each MII transaction!)
151 #define DBG(n, dev, args...) \
153 if (SMC_DEBUG >= (n)) \
154 netdev_dbg(dev, args); \
157 #define PRINTK(dev, args...) netdev_info(dev, args)
159 #define DBG(n, dev, args...) do { } while (0)
160 #define PRINTK(dev, args...) netdev_dbg(dev, args)
164 static void PRINT_PKT(u_char
*buf
, int length
)
171 remainder
= length
% 16;
173 for (i
= 0; i
< lines
; i
++) {
176 for (cur
= 0; cur
< 8; cur
++) {
180 pr_cont("%02x%02x ", a
, b
);
185 for (i
= 0; i
< remainder
/2 ; i
++) {
189 pr_cont("%02x%02x ", a
, b
);
194 #define PRINT_PKT(x...) do { } while (0)
198 /* this enables an interrupt in the interrupt mask register */
199 #define SMC_ENABLE_INT(lp, x) do { \
200 unsigned char mask; \
201 unsigned long smc_enable_flags; \
202 spin_lock_irqsave(&lp->lock, smc_enable_flags); \
203 mask = SMC_GET_INT_MASK(lp); \
205 SMC_SET_INT_MASK(lp, mask); \
206 spin_unlock_irqrestore(&lp->lock, smc_enable_flags); \
209 /* this disables an interrupt from the interrupt mask register */
210 #define SMC_DISABLE_INT(lp, x) do { \
211 unsigned char mask; \
212 unsigned long smc_disable_flags; \
213 spin_lock_irqsave(&lp->lock, smc_disable_flags); \
214 mask = SMC_GET_INT_MASK(lp); \
216 SMC_SET_INT_MASK(lp, mask); \
217 spin_unlock_irqrestore(&lp->lock, smc_disable_flags); \
221 * Wait while MMU is busy. This is usually in the order of a few nanosecs
222 * if at all, but let's avoid deadlocking the system if the hardware
223 * decides to go south.
225 #define SMC_WAIT_MMU_BUSY(lp) do { \
226 if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \
227 unsigned long timeout = jiffies + 2; \
228 while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \
229 if (time_after(jiffies, timeout)) { \
230 netdev_dbg(dev, "timeout %s line %d\n", \
231 __FILE__, __LINE__); \
241 * this does a soft reset on the device
243 static void smc_reset(struct net_device
*dev
)
245 struct smc_local
*lp
= netdev_priv(dev
);
246 void __iomem
*ioaddr
= lp
->base
;
247 unsigned int ctl
, cfg
;
248 struct sk_buff
*pending_skb
;
250 DBG(2, dev
, "%s\n", __func__
);
252 /* Disable all interrupts, block TX tasklet */
253 spin_lock_irq(&lp
->lock
);
254 SMC_SELECT_BANK(lp
, 2);
255 SMC_SET_INT_MASK(lp
, 0);
256 pending_skb
= lp
->pending_tx_skb
;
257 lp
->pending_tx_skb
= NULL
;
258 spin_unlock_irq(&lp
->lock
);
260 /* free any pending tx skb */
262 dev_kfree_skb(pending_skb
);
263 dev
->stats
.tx_errors
++;
264 dev
->stats
.tx_aborted_errors
++;
268 * This resets the registers mostly to defaults, but doesn't
269 * affect EEPROM. That seems unnecessary
271 SMC_SELECT_BANK(lp
, 0);
272 SMC_SET_RCR(lp
, RCR_SOFTRST
);
275 * Setup the Configuration Register
276 * This is necessary because the CONFIG_REG is not affected
279 SMC_SELECT_BANK(lp
, 1);
281 cfg
= CONFIG_DEFAULT
;
284 * Setup for fast accesses if requested. If the card/system
285 * can't handle it then there will be no recovery except for
286 * a hard reset or power cycle
288 if (lp
->cfg
.flags
& SMC91X_NOWAIT
)
289 cfg
|= CONFIG_NO_WAIT
;
292 * Release from possible power-down state
293 * Configuration register is not affected by Soft Reset
295 cfg
|= CONFIG_EPH_POWER_EN
;
297 SMC_SET_CONFIG(lp
, cfg
);
299 /* this should pause enough for the chip to be happy */
301 * elaborate? What does the chip _need_? --jgarzik
303 * This seems to be undocumented, but something the original
304 * driver(s) have always done. Suspect undocumented timing
305 * info/determined empirically. --rmk
309 /* Disable transmit and receive functionality */
310 SMC_SELECT_BANK(lp
, 0);
311 SMC_SET_RCR(lp
, RCR_CLEAR
);
312 SMC_SET_TCR(lp
, TCR_CLEAR
);
314 SMC_SELECT_BANK(lp
, 1);
315 ctl
= SMC_GET_CTL(lp
) | CTL_LE_ENABLE
;
318 * Set the control register to automatically release successfully
319 * transmitted packets, to make the best use out of our limited
322 if(!THROTTLE_TX_PKTS
)
323 ctl
|= CTL_AUTO_RELEASE
;
325 ctl
&= ~CTL_AUTO_RELEASE
;
326 SMC_SET_CTL(lp
, ctl
);
329 SMC_SELECT_BANK(lp
, 2);
330 SMC_SET_MMU_CMD(lp
, MC_RESET
);
331 SMC_WAIT_MMU_BUSY(lp
);
335 * Enable Interrupts, Receive, and Transmit
337 static void smc_enable(struct net_device
*dev
)
339 struct smc_local
*lp
= netdev_priv(dev
);
340 void __iomem
*ioaddr
= lp
->base
;
343 DBG(2, dev
, "%s\n", __func__
);
345 /* see the header file for options in TCR/RCR DEFAULT */
346 SMC_SELECT_BANK(lp
, 0);
347 SMC_SET_TCR(lp
, lp
->tcr_cur_mode
);
348 SMC_SET_RCR(lp
, lp
->rcr_cur_mode
);
350 SMC_SELECT_BANK(lp
, 1);
351 SMC_SET_MAC_ADDR(lp
, dev
->dev_addr
);
353 /* now, enable interrupts */
354 mask
= IM_EPH_INT
|IM_RX_OVRN_INT
|IM_RCV_INT
;
355 if (lp
->version
>= (CHIP_91100
<< 4))
357 SMC_SELECT_BANK(lp
, 2);
358 SMC_SET_INT_MASK(lp
, mask
);
361 * From this point the register bank must _NOT_ be switched away
362 * to something else than bank 2 without proper locking against
363 * races with any tasklet or interrupt handlers until smc_shutdown()
364 * or smc_reset() is called.
369 * this puts the device in an inactive state
371 static void smc_shutdown(struct net_device
*dev
)
373 struct smc_local
*lp
= netdev_priv(dev
);
374 void __iomem
*ioaddr
= lp
->base
;
375 struct sk_buff
*pending_skb
;
377 DBG(2, dev
, "%s: %s\n", CARDNAME
, __func__
);
379 /* no more interrupts for me */
380 spin_lock_irq(&lp
->lock
);
381 SMC_SELECT_BANK(lp
, 2);
382 SMC_SET_INT_MASK(lp
, 0);
383 pending_skb
= lp
->pending_tx_skb
;
384 lp
->pending_tx_skb
= NULL
;
385 spin_unlock_irq(&lp
->lock
);
387 dev_kfree_skb(pending_skb
);
389 /* and tell the card to stay away from that nasty outside world */
390 SMC_SELECT_BANK(lp
, 0);
391 SMC_SET_RCR(lp
, RCR_CLEAR
);
392 SMC_SET_TCR(lp
, TCR_CLEAR
);
395 /* finally, shut the chip down */
396 SMC_SELECT_BANK(lp
, 1);
397 SMC_SET_CONFIG(lp
, SMC_GET_CONFIG(lp
) & ~CONFIG_EPH_POWER_EN
);
402 * This is the procedure to handle the receipt of a packet.
404 static inline void smc_rcv(struct net_device
*dev
)
406 struct smc_local
*lp
= netdev_priv(dev
);
407 void __iomem
*ioaddr
= lp
->base
;
408 unsigned int packet_number
, status
, packet_len
;
410 DBG(3, dev
, "%s\n", __func__
);
412 packet_number
= SMC_GET_RXFIFO(lp
);
413 if (unlikely(packet_number
& RXFIFO_REMPTY
)) {
414 PRINTK(dev
, "smc_rcv with nothing on FIFO.\n");
418 /* read from start of packet */
419 SMC_SET_PTR(lp
, PTR_READ
| PTR_RCV
| PTR_AUTOINC
);
421 /* First two words are status and packet length */
422 SMC_GET_PKT_HDR(lp
, status
, packet_len
);
423 packet_len
&= 0x07ff; /* mask off top bits */
424 DBG(2, dev
, "RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
425 packet_number
, status
, packet_len
, packet_len
);
428 if (unlikely(packet_len
< 6 || status
& RS_ERRORS
)) {
429 if (status
& RS_TOOLONG
&& packet_len
<= (1514 + 4 + 6)) {
430 /* accept VLAN packets */
431 status
&= ~RS_TOOLONG
;
434 if (packet_len
< 6) {
435 /* bloody hardware */
436 netdev_err(dev
, "fubar (rxlen %u status %x\n",
438 status
|= RS_TOOSHORT
;
440 SMC_WAIT_MMU_BUSY(lp
);
441 SMC_SET_MMU_CMD(lp
, MC_RELEASE
);
442 dev
->stats
.rx_errors
++;
443 if (status
& RS_ALGNERR
)
444 dev
->stats
.rx_frame_errors
++;
445 if (status
& (RS_TOOSHORT
| RS_TOOLONG
))
446 dev
->stats
.rx_length_errors
++;
447 if (status
& RS_BADCRC
)
448 dev
->stats
.rx_crc_errors
++;
452 unsigned int data_len
;
454 /* set multicast stats */
455 if (status
& RS_MULTICAST
)
456 dev
->stats
.multicast
++;
459 * Actual payload is packet_len - 6 (or 5 if odd byte).
460 * We want skb_reserve(2) and the final ctrl word
461 * (2 bytes, possibly containing the payload odd byte).
462 * Furthermore, we add 2 bytes to allow rounding up to
463 * multiple of 4 bytes on 32 bit buses.
464 * Hence packet_len - 6 + 2 + 2 + 2.
466 skb
= netdev_alloc_skb(dev
, packet_len
);
467 if (unlikely(skb
== NULL
)) {
468 SMC_WAIT_MMU_BUSY(lp
);
469 SMC_SET_MMU_CMD(lp
, MC_RELEASE
);
470 dev
->stats
.rx_dropped
++;
474 /* Align IP header to 32 bits */
477 /* BUG: the LAN91C111 rev A never sets this bit. Force it. */
478 if (lp
->version
== 0x90)
479 status
|= RS_ODDFRAME
;
482 * If odd length: packet_len - 5,
483 * otherwise packet_len - 6.
484 * With the trailing ctrl byte it's packet_len - 4.
486 data_len
= packet_len
- ((status
& RS_ODDFRAME
) ? 5 : 6);
487 data
= skb_put(skb
, data_len
);
488 SMC_PULL_DATA(lp
, data
, packet_len
- 4);
490 SMC_WAIT_MMU_BUSY(lp
);
491 SMC_SET_MMU_CMD(lp
, MC_RELEASE
);
493 PRINT_PKT(data
, packet_len
- 4);
495 skb
->protocol
= eth_type_trans(skb
, dev
);
497 dev
->stats
.rx_packets
++;
498 dev
->stats
.rx_bytes
+= data_len
;
504 * On SMP we have the following problem:
506 * A = smc_hardware_send_pkt()
507 * B = smc_hard_start_xmit()
508 * C = smc_interrupt()
510 * A and B can never be executed simultaneously. However, at least on UP,
511 * it is possible (and even desirable) for C to interrupt execution of
512 * A or B in order to have better RX reliability and avoid overruns.
513 * C, just like A and B, must have exclusive access to the chip and
514 * each of them must lock against any other concurrent access.
515 * Unfortunately this is not possible to have C suspend execution of A or
516 * B taking place on another CPU. On UP this is no an issue since A and B
517 * are run from softirq context and C from hard IRQ context, and there is
518 * no other CPU where concurrent access can happen.
519 * If ever there is a way to force at least B and C to always be executed
520 * on the same CPU then we could use read/write locks to protect against
521 * any other concurrent access and C would always interrupt B. But life
522 * isn't that easy in a SMP world...
524 #define smc_special_trylock(lock, flags) \
527 local_irq_save(flags); \
528 __ret = spin_trylock(lock); \
530 local_irq_restore(flags); \
533 #define smc_special_lock(lock, flags) spin_lock_irqsave(lock, flags)
534 #define smc_special_unlock(lock, flags) spin_unlock_irqrestore(lock, flags)
536 #define smc_special_trylock(lock, flags) (flags == flags)
537 #define smc_special_lock(lock, flags) do { flags = 0; } while (0)
538 #define smc_special_unlock(lock, flags) do { flags = 0; } while (0)
542 * This is called to actually send a packet to the chip.
544 static void smc_hardware_send_pkt(unsigned long data
)
546 struct net_device
*dev
= (struct net_device
*)data
;
547 struct smc_local
*lp
= netdev_priv(dev
);
548 void __iomem
*ioaddr
= lp
->base
;
550 unsigned int packet_no
, len
;
554 DBG(3, dev
, "%s\n", __func__
);
556 if (!smc_special_trylock(&lp
->lock
, flags
)) {
557 netif_stop_queue(dev
);
558 tasklet_schedule(&lp
->tx_task
);
562 skb
= lp
->pending_tx_skb
;
563 if (unlikely(!skb
)) {
564 smc_special_unlock(&lp
->lock
, flags
);
567 lp
->pending_tx_skb
= NULL
;
569 packet_no
= SMC_GET_AR(lp
);
570 if (unlikely(packet_no
& AR_FAILED
)) {
571 netdev_err(dev
, "Memory allocation failed.\n");
572 dev
->stats
.tx_errors
++;
573 dev
->stats
.tx_fifo_errors
++;
574 smc_special_unlock(&lp
->lock
, flags
);
578 /* point to the beginning of the packet */
579 SMC_SET_PN(lp
, packet_no
);
580 SMC_SET_PTR(lp
, PTR_AUTOINC
);
584 DBG(2, dev
, "TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
585 packet_no
, len
, len
, buf
);
589 * Send the packet length (+6 for status words, length, and ctl.
590 * The card will pad to 64 bytes with zeroes if packet is too small.
592 SMC_PUT_PKT_HDR(lp
, 0, len
+ 6);
594 /* send the actual data */
595 SMC_PUSH_DATA(lp
, buf
, len
& ~1);
597 /* Send final ctl word with the last byte if there is one */
598 SMC_outw(((len
& 1) ? (0x2000 | buf
[len
-1]) : 0), ioaddr
, DATA_REG(lp
));
601 * If THROTTLE_TX_PKTS is set, we stop the queue here. This will
602 * have the effect of having at most one packet queued for TX
603 * in the chip's memory at all time.
605 * If THROTTLE_TX_PKTS is not set then the queue is stopped only
606 * when memory allocation (MC_ALLOC) does not succeed right away.
608 if (THROTTLE_TX_PKTS
)
609 netif_stop_queue(dev
);
611 /* queue the packet for TX */
612 SMC_SET_MMU_CMD(lp
, MC_ENQUEUE
);
613 smc_special_unlock(&lp
->lock
, flags
);
615 dev
->trans_start
= jiffies
;
616 dev
->stats
.tx_packets
++;
617 dev
->stats
.tx_bytes
+= len
;
619 SMC_ENABLE_INT(lp
, IM_TX_INT
| IM_TX_EMPTY_INT
);
621 done
: if (!THROTTLE_TX_PKTS
)
622 netif_wake_queue(dev
);
628 * Since I am not sure if I will have enough room in the chip's ram
629 * to store the packet, I call this routine which either sends it
630 * now, or set the card to generates an interrupt when ready
633 static int smc_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
635 struct smc_local
*lp
= netdev_priv(dev
);
636 void __iomem
*ioaddr
= lp
->base
;
637 unsigned int numPages
, poll_count
, status
;
640 DBG(3, dev
, "%s\n", __func__
);
642 BUG_ON(lp
->pending_tx_skb
!= NULL
);
645 * The MMU wants the number of pages to be the number of 256 bytes
646 * 'pages', minus 1 (since a packet can't ever have 0 pages :))
648 * The 91C111 ignores the size bits, but earlier models don't.
650 * Pkt size for allocating is data length +6 (for additional status
651 * words, length and ctl)
653 * If odd size then last byte is included in ctl word.
655 numPages
= ((skb
->len
& ~1) + (6 - 1)) >> 8;
656 if (unlikely(numPages
> 7)) {
657 netdev_warn(dev
, "Far too big packet error.\n");
658 dev
->stats
.tx_errors
++;
659 dev
->stats
.tx_dropped
++;
664 smc_special_lock(&lp
->lock
, flags
);
666 /* now, try to allocate the memory */
667 SMC_SET_MMU_CMD(lp
, MC_ALLOC
| numPages
);
670 * Poll the chip for a short amount of time in case the
671 * allocation succeeds quickly.
673 poll_count
= MEMORY_WAIT_TIME
;
675 status
= SMC_GET_INT(lp
);
676 if (status
& IM_ALLOC_INT
) {
677 SMC_ACK_INT(lp
, IM_ALLOC_INT
);
680 } while (--poll_count
);
682 smc_special_unlock(&lp
->lock
, flags
);
684 lp
->pending_tx_skb
= skb
;
686 /* oh well, wait until the chip finds memory later */
687 netif_stop_queue(dev
);
688 DBG(2, dev
, "TX memory allocation deferred.\n");
689 SMC_ENABLE_INT(lp
, IM_ALLOC_INT
);
692 * Allocation succeeded: push packet to the chip's own memory
695 smc_hardware_send_pkt((unsigned long)dev
);
702 * This handles a TX interrupt, which is only called when:
703 * - a TX error occurred, or
704 * - CTL_AUTO_RELEASE is not set and TX of a packet completed.
706 static void smc_tx(struct net_device
*dev
)
708 struct smc_local
*lp
= netdev_priv(dev
);
709 void __iomem
*ioaddr
= lp
->base
;
710 unsigned int saved_packet
, packet_no
, tx_status
, pkt_len
;
712 DBG(3, dev
, "%s\n", __func__
);
714 /* If the TX FIFO is empty then nothing to do */
715 packet_no
= SMC_GET_TXFIFO(lp
);
716 if (unlikely(packet_no
& TXFIFO_TEMPTY
)) {
717 PRINTK(dev
, "smc_tx with nothing on FIFO.\n");
721 /* select packet to read from */
722 saved_packet
= SMC_GET_PN(lp
);
723 SMC_SET_PN(lp
, packet_no
);
725 /* read the first word (status word) from this packet */
726 SMC_SET_PTR(lp
, PTR_AUTOINC
| PTR_READ
);
727 SMC_GET_PKT_HDR(lp
, tx_status
, pkt_len
);
728 DBG(2, dev
, "TX STATUS 0x%04x PNR 0x%02x\n",
729 tx_status
, packet_no
);
731 if (!(tx_status
& ES_TX_SUC
))
732 dev
->stats
.tx_errors
++;
734 if (tx_status
& ES_LOSTCARR
)
735 dev
->stats
.tx_carrier_errors
++;
737 if (tx_status
& (ES_LATCOL
| ES_16COL
)) {
738 PRINTK(dev
, "%s occurred on last xmit\n",
739 (tx_status
& ES_LATCOL
) ?
740 "late collision" : "too many collisions");
741 dev
->stats
.tx_window_errors
++;
742 if (!(dev
->stats
.tx_window_errors
& 63) && net_ratelimit()) {
743 netdev_info(dev
, "unexpectedly large number of bad collisions. Please check duplex setting.\n");
747 /* kill the packet */
748 SMC_WAIT_MMU_BUSY(lp
);
749 SMC_SET_MMU_CMD(lp
, MC_FREEPKT
);
751 /* Don't restore Packet Number Reg until busy bit is cleared */
752 SMC_WAIT_MMU_BUSY(lp
);
753 SMC_SET_PN(lp
, saved_packet
);
755 /* re-enable transmit */
756 SMC_SELECT_BANK(lp
, 0);
757 SMC_SET_TCR(lp
, lp
->tcr_cur_mode
);
758 SMC_SELECT_BANK(lp
, 2);
762 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
764 static void smc_mii_out(struct net_device
*dev
, unsigned int val
, int bits
)
766 struct smc_local
*lp
= netdev_priv(dev
);
767 void __iomem
*ioaddr
= lp
->base
;
768 unsigned int mii_reg
, mask
;
770 mii_reg
= SMC_GET_MII(lp
) & ~(MII_MCLK
| MII_MDOE
| MII_MDO
);
773 for (mask
= 1 << (bits
- 1); mask
; mask
>>= 1) {
779 SMC_SET_MII(lp
, mii_reg
);
781 SMC_SET_MII(lp
, mii_reg
| MII_MCLK
);
786 static unsigned int smc_mii_in(struct net_device
*dev
, int bits
)
788 struct smc_local
*lp
= netdev_priv(dev
);
789 void __iomem
*ioaddr
= lp
->base
;
790 unsigned int mii_reg
, mask
, val
;
792 mii_reg
= SMC_GET_MII(lp
) & ~(MII_MCLK
| MII_MDOE
| MII_MDO
);
793 SMC_SET_MII(lp
, mii_reg
);
795 for (mask
= 1 << (bits
- 1), val
= 0; mask
; mask
>>= 1) {
796 if (SMC_GET_MII(lp
) & MII_MDI
)
799 SMC_SET_MII(lp
, mii_reg
);
801 SMC_SET_MII(lp
, mii_reg
| MII_MCLK
);
809 * Reads a register from the MII Management serial interface
811 static int smc_phy_read(struct net_device
*dev
, int phyaddr
, int phyreg
)
813 struct smc_local
*lp
= netdev_priv(dev
);
814 void __iomem
*ioaddr
= lp
->base
;
815 unsigned int phydata
;
817 SMC_SELECT_BANK(lp
, 3);
820 smc_mii_out(dev
, 0xffffffff, 32);
822 /* Start code (01) + read (10) + phyaddr + phyreg */
823 smc_mii_out(dev
, 6 << 10 | phyaddr
<< 5 | phyreg
, 14);
825 /* Turnaround (2bits) + phydata */
826 phydata
= smc_mii_in(dev
, 18);
828 /* Return to idle state */
829 SMC_SET_MII(lp
, SMC_GET_MII(lp
) & ~(MII_MCLK
|MII_MDOE
|MII_MDO
));
831 DBG(3, dev
, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
832 __func__
, phyaddr
, phyreg
, phydata
);
834 SMC_SELECT_BANK(lp
, 2);
839 * Writes a register to the MII Management serial interface
841 static void smc_phy_write(struct net_device
*dev
, int phyaddr
, int phyreg
,
844 struct smc_local
*lp
= netdev_priv(dev
);
845 void __iomem
*ioaddr
= lp
->base
;
847 SMC_SELECT_BANK(lp
, 3);
850 smc_mii_out(dev
, 0xffffffff, 32);
852 /* Start code (01) + write (01) + phyaddr + phyreg + turnaround + phydata */
853 smc_mii_out(dev
, 5 << 28 | phyaddr
<< 23 | phyreg
<< 18 | 2 << 16 | phydata
, 32);
855 /* Return to idle state */
856 SMC_SET_MII(lp
, SMC_GET_MII(lp
) & ~(MII_MCLK
|MII_MDOE
|MII_MDO
));
858 DBG(3, dev
, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
859 __func__
, phyaddr
, phyreg
, phydata
);
861 SMC_SELECT_BANK(lp
, 2);
865 * Finds and reports the PHY address
867 static void smc_phy_detect(struct net_device
*dev
)
869 struct smc_local
*lp
= netdev_priv(dev
);
872 DBG(2, dev
, "%s\n", __func__
);
877 * Scan all 32 PHY addresses if necessary, starting at
878 * PHY#1 to PHY#31, and then PHY#0 last.
880 for (phyaddr
= 1; phyaddr
< 33; ++phyaddr
) {
881 unsigned int id1
, id2
;
883 /* Read the PHY identifiers */
884 id1
= smc_phy_read(dev
, phyaddr
& 31, MII_PHYSID1
);
885 id2
= smc_phy_read(dev
, phyaddr
& 31, MII_PHYSID2
);
887 DBG(3, dev
, "phy_id1=0x%x, phy_id2=0x%x\n",
890 /* Make sure it is a valid identifier */
891 if (id1
!= 0x0000 && id1
!= 0xffff && id1
!= 0x8000 &&
892 id2
!= 0x0000 && id2
!= 0xffff && id2
!= 0x8000) {
893 /* Save the PHY's address */
894 lp
->mii
.phy_id
= phyaddr
& 31;
895 lp
->phy_type
= id1
<< 16 | id2
;
902 * Sets the PHY to a configuration as determined by the user
904 static int smc_phy_fixed(struct net_device
*dev
)
906 struct smc_local
*lp
= netdev_priv(dev
);
907 void __iomem
*ioaddr
= lp
->base
;
908 int phyaddr
= lp
->mii
.phy_id
;
911 DBG(3, dev
, "%s\n", __func__
);
913 /* Enter Link Disable state */
914 cfg1
= smc_phy_read(dev
, phyaddr
, PHY_CFG1_REG
);
915 cfg1
|= PHY_CFG1_LNKDIS
;
916 smc_phy_write(dev
, phyaddr
, PHY_CFG1_REG
, cfg1
);
919 * Set our fixed capabilities
920 * Disable auto-negotiation
925 bmcr
|= BMCR_FULLDPLX
;
927 if (lp
->ctl_rspeed
== 100)
928 bmcr
|= BMCR_SPEED100
;
930 /* Write our capabilities to the phy control register */
931 smc_phy_write(dev
, phyaddr
, MII_BMCR
, bmcr
);
933 /* Re-Configure the Receive/Phy Control register */
934 SMC_SELECT_BANK(lp
, 0);
935 SMC_SET_RPC(lp
, lp
->rpc_cur_mode
);
936 SMC_SELECT_BANK(lp
, 2);
942 * smc_phy_reset - reset the phy
946 * Issue a software reset for the specified PHY and
947 * wait up to 100ms for the reset to complete. We should
948 * not access the PHY for 50ms after issuing the reset.
950 * The time to wait appears to be dependent on the PHY.
952 * Must be called with lp->lock locked.
954 static int smc_phy_reset(struct net_device
*dev
, int phy
)
956 struct smc_local
*lp
= netdev_priv(dev
);
960 smc_phy_write(dev
, phy
, MII_BMCR
, BMCR_RESET
);
962 for (timeout
= 2; timeout
; timeout
--) {
963 spin_unlock_irq(&lp
->lock
);
965 spin_lock_irq(&lp
->lock
);
967 bmcr
= smc_phy_read(dev
, phy
, MII_BMCR
);
968 if (!(bmcr
& BMCR_RESET
))
972 return bmcr
& BMCR_RESET
;
976 * smc_phy_powerdown - powerdown phy
979 * Power down the specified PHY
981 static void smc_phy_powerdown(struct net_device
*dev
)
983 struct smc_local
*lp
= netdev_priv(dev
);
985 int phy
= lp
->mii
.phy_id
;
987 if (lp
->phy_type
== 0)
990 /* We need to ensure that no calls to smc_phy_configure are
993 cancel_work_sync(&lp
->phy_configure
);
995 bmcr
= smc_phy_read(dev
, phy
, MII_BMCR
);
996 smc_phy_write(dev
, phy
, MII_BMCR
, bmcr
| BMCR_PDOWN
);
1000 * smc_phy_check_media - check the media status and adjust TCR
1002 * @init: set true for initialisation
1004 * Select duplex mode depending on negotiation state. This
1005 * also updates our carrier state.
1007 static void smc_phy_check_media(struct net_device
*dev
, int init
)
1009 struct smc_local
*lp
= netdev_priv(dev
);
1010 void __iomem
*ioaddr
= lp
->base
;
1012 if (mii_check_media(&lp
->mii
, netif_msg_link(lp
), init
)) {
1013 /* duplex state has changed */
1014 if (lp
->mii
.full_duplex
) {
1015 lp
->tcr_cur_mode
|= TCR_SWFDUP
;
1017 lp
->tcr_cur_mode
&= ~TCR_SWFDUP
;
1020 SMC_SELECT_BANK(lp
, 0);
1021 SMC_SET_TCR(lp
, lp
->tcr_cur_mode
);
1026 * Configures the specified PHY through the MII management interface
1027 * using Autonegotiation.
1028 * Calls smc_phy_fixed() if the user has requested a certain config.
1029 * If RPC ANEG bit is set, the media selection is dependent purely on
1030 * the selection by the MII (either in the MII BMCR reg or the result
1031 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
1032 * is controlled by the RPC SPEED and RPC DPLX bits.
1034 static void smc_phy_configure(struct work_struct
*work
)
1036 struct smc_local
*lp
=
1037 container_of(work
, struct smc_local
, phy_configure
);
1038 struct net_device
*dev
= lp
->dev
;
1039 void __iomem
*ioaddr
= lp
->base
;
1040 int phyaddr
= lp
->mii
.phy_id
;
1041 int my_phy_caps
; /* My PHY capabilities */
1042 int my_ad_caps
; /* My Advertised capabilities */
1045 DBG(3, dev
, "smc_program_phy()\n");
1047 spin_lock_irq(&lp
->lock
);
1050 * We should not be called if phy_type is zero.
1052 if (lp
->phy_type
== 0)
1053 goto smc_phy_configure_exit
;
1055 if (smc_phy_reset(dev
, phyaddr
)) {
1056 netdev_info(dev
, "PHY reset timed out\n");
1057 goto smc_phy_configure_exit
;
1061 * Enable PHY Interrupts (for register 18)
1062 * Interrupts listed here are disabled
1064 smc_phy_write(dev
, phyaddr
, PHY_MASK_REG
,
1065 PHY_INT_LOSSSYNC
| PHY_INT_CWRD
| PHY_INT_SSD
|
1066 PHY_INT_ESD
| PHY_INT_RPOL
| PHY_INT_JAB
|
1067 PHY_INT_SPDDET
| PHY_INT_DPLXDET
);
1069 /* Configure the Receive/Phy Control register */
1070 SMC_SELECT_BANK(lp
, 0);
1071 SMC_SET_RPC(lp
, lp
->rpc_cur_mode
);
1073 /* If the user requested no auto neg, then go set his request */
1074 if (lp
->mii
.force_media
) {
1076 goto smc_phy_configure_exit
;
1079 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
1080 my_phy_caps
= smc_phy_read(dev
, phyaddr
, MII_BMSR
);
1082 if (!(my_phy_caps
& BMSR_ANEGCAPABLE
)) {
1083 netdev_info(dev
, "Auto negotiation NOT supported\n");
1085 goto smc_phy_configure_exit
;
1088 my_ad_caps
= ADVERTISE_CSMA
; /* I am CSMA capable */
1090 if (my_phy_caps
& BMSR_100BASE4
)
1091 my_ad_caps
|= ADVERTISE_100BASE4
;
1092 if (my_phy_caps
& BMSR_100FULL
)
1093 my_ad_caps
|= ADVERTISE_100FULL
;
1094 if (my_phy_caps
& BMSR_100HALF
)
1095 my_ad_caps
|= ADVERTISE_100HALF
;
1096 if (my_phy_caps
& BMSR_10FULL
)
1097 my_ad_caps
|= ADVERTISE_10FULL
;
1098 if (my_phy_caps
& BMSR_10HALF
)
1099 my_ad_caps
|= ADVERTISE_10HALF
;
1101 /* Disable capabilities not selected by our user */
1102 if (lp
->ctl_rspeed
!= 100)
1103 my_ad_caps
&= ~(ADVERTISE_100BASE4
|ADVERTISE_100FULL
|ADVERTISE_100HALF
);
1105 if (!lp
->ctl_rfduplx
)
1106 my_ad_caps
&= ~(ADVERTISE_100FULL
|ADVERTISE_10FULL
);
1108 /* Update our Auto-Neg Advertisement Register */
1109 smc_phy_write(dev
, phyaddr
, MII_ADVERTISE
, my_ad_caps
);
1110 lp
->mii
.advertising
= my_ad_caps
;
1113 * Read the register back. Without this, it appears that when
1114 * auto-negotiation is restarted, sometimes it isn't ready and
1115 * the link does not come up.
1117 status
= smc_phy_read(dev
, phyaddr
, MII_ADVERTISE
);
1119 DBG(2, dev
, "phy caps=%x\n", my_phy_caps
);
1120 DBG(2, dev
, "phy advertised caps=%x\n", my_ad_caps
);
1122 /* Restart auto-negotiation process in order to advertise my caps */
1123 smc_phy_write(dev
, phyaddr
, MII_BMCR
, BMCR_ANENABLE
| BMCR_ANRESTART
);
1125 smc_phy_check_media(dev
, 1);
1127 smc_phy_configure_exit
:
1128 SMC_SELECT_BANK(lp
, 2);
1129 spin_unlock_irq(&lp
->lock
);
1135 * Purpose: Handle interrupts relating to PHY register 18. This is
1136 * called from the "hard" interrupt handler under our private spinlock.
1138 static void smc_phy_interrupt(struct net_device
*dev
)
1140 struct smc_local
*lp
= netdev_priv(dev
);
1141 int phyaddr
= lp
->mii
.phy_id
;
1144 DBG(2, dev
, "%s\n", __func__
);
1146 if (lp
->phy_type
== 0)
1150 smc_phy_check_media(dev
, 0);
1152 /* Read PHY Register 18, Status Output */
1153 phy18
= smc_phy_read(dev
, phyaddr
, PHY_INT_REG
);
1154 if ((phy18
& PHY_INT_INT
) == 0)
1159 /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
1161 static void smc_10bt_check_media(struct net_device
*dev
, int init
)
1163 struct smc_local
*lp
= netdev_priv(dev
);
1164 void __iomem
*ioaddr
= lp
->base
;
1165 unsigned int old_carrier
, new_carrier
;
1167 old_carrier
= netif_carrier_ok(dev
) ? 1 : 0;
1169 SMC_SELECT_BANK(lp
, 0);
1170 new_carrier
= (SMC_GET_EPH_STATUS(lp
) & ES_LINK_OK
) ? 1 : 0;
1171 SMC_SELECT_BANK(lp
, 2);
1173 if (init
|| (old_carrier
!= new_carrier
)) {
1175 netif_carrier_off(dev
);
1177 netif_carrier_on(dev
);
1179 if (netif_msg_link(lp
))
1180 netdev_info(dev
, "link %s\n",
1181 new_carrier
? "up" : "down");
1185 static void smc_eph_interrupt(struct net_device
*dev
)
1187 struct smc_local
*lp
= netdev_priv(dev
);
1188 void __iomem
*ioaddr
= lp
->base
;
1191 smc_10bt_check_media(dev
, 0);
1193 SMC_SELECT_BANK(lp
, 1);
1194 ctl
= SMC_GET_CTL(lp
);
1195 SMC_SET_CTL(lp
, ctl
& ~CTL_LE_ENABLE
);
1196 SMC_SET_CTL(lp
, ctl
);
1197 SMC_SELECT_BANK(lp
, 2);
1201 * This is the main routine of the driver, to handle the device when
1202 * it needs some attention.
1204 static irqreturn_t
smc_interrupt(int irq
, void *dev_id
)
1206 struct net_device
*dev
= dev_id
;
1207 struct smc_local
*lp
= netdev_priv(dev
);
1208 void __iomem
*ioaddr
= lp
->base
;
1209 int status
, mask
, timeout
, card_stats
;
1212 DBG(3, dev
, "%s\n", __func__
);
1214 spin_lock(&lp
->lock
);
1216 /* A preamble may be used when there is a potential race
1217 * between the interruptible transmit functions and this
1219 SMC_INTERRUPT_PREAMBLE
;
1221 saved_pointer
= SMC_GET_PTR(lp
);
1222 mask
= SMC_GET_INT_MASK(lp
);
1223 SMC_SET_INT_MASK(lp
, 0);
1225 /* set a timeout value, so I don't stay here forever */
1226 timeout
= MAX_IRQ_LOOPS
;
1229 status
= SMC_GET_INT(lp
);
1231 DBG(2, dev
, "INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
1233 ({ int meminfo
; SMC_SELECT_BANK(lp
, 0);
1234 meminfo
= SMC_GET_MIR(lp
);
1235 SMC_SELECT_BANK(lp
, 2); meminfo
; }),
1242 if (status
& IM_TX_INT
) {
1243 /* do this before RX as it will free memory quickly */
1244 DBG(3, dev
, "TX int\n");
1246 SMC_ACK_INT(lp
, IM_TX_INT
);
1247 if (THROTTLE_TX_PKTS
)
1248 netif_wake_queue(dev
);
1249 } else if (status
& IM_RCV_INT
) {
1250 DBG(3, dev
, "RX irq\n");
1252 } else if (status
& IM_ALLOC_INT
) {
1253 DBG(3, dev
, "Allocation irq\n");
1254 tasklet_hi_schedule(&lp
->tx_task
);
1255 mask
&= ~IM_ALLOC_INT
;
1256 } else if (status
& IM_TX_EMPTY_INT
) {
1257 DBG(3, dev
, "TX empty\n");
1258 mask
&= ~IM_TX_EMPTY_INT
;
1261 SMC_SELECT_BANK(lp
, 0);
1262 card_stats
= SMC_GET_COUNTER(lp
);
1263 SMC_SELECT_BANK(lp
, 2);
1265 /* single collisions */
1266 dev
->stats
.collisions
+= card_stats
& 0xF;
1269 /* multiple collisions */
1270 dev
->stats
.collisions
+= card_stats
& 0xF;
1271 } else if (status
& IM_RX_OVRN_INT
) {
1272 DBG(1, dev
, "RX overrun (EPH_ST 0x%04x)\n",
1273 ({ int eph_st
; SMC_SELECT_BANK(lp
, 0);
1274 eph_st
= SMC_GET_EPH_STATUS(lp
);
1275 SMC_SELECT_BANK(lp
, 2); eph_st
; }));
1276 SMC_ACK_INT(lp
, IM_RX_OVRN_INT
);
1277 dev
->stats
.rx_errors
++;
1278 dev
->stats
.rx_fifo_errors
++;
1279 } else if (status
& IM_EPH_INT
) {
1280 smc_eph_interrupt(dev
);
1281 } else if (status
& IM_MDINT
) {
1282 SMC_ACK_INT(lp
, IM_MDINT
);
1283 smc_phy_interrupt(dev
);
1284 } else if (status
& IM_ERCV_INT
) {
1285 SMC_ACK_INT(lp
, IM_ERCV_INT
);
1286 PRINTK(dev
, "UNSUPPORTED: ERCV INTERRUPT\n");
1288 } while (--timeout
);
1290 /* restore register states */
1291 SMC_SET_PTR(lp
, saved_pointer
);
1292 SMC_SET_INT_MASK(lp
, mask
);
1293 spin_unlock(&lp
->lock
);
1295 #ifndef CONFIG_NET_POLL_CONTROLLER
1296 if (timeout
== MAX_IRQ_LOOPS
)
1297 PRINTK(dev
, "spurious interrupt (mask = 0x%02x)\n",
1300 DBG(3, dev
, "Interrupt done (%d loops)\n",
1301 MAX_IRQ_LOOPS
- timeout
);
1304 * We return IRQ_HANDLED unconditionally here even if there was
1305 * nothing to do. There is a possibility that a packet might
1306 * get enqueued into the chip right after TX_EMPTY_INT is raised
1307 * but just before the CPU acknowledges the IRQ.
1308 * Better take an unneeded IRQ in some occasions than complexifying
1309 * the code for all cases.
1314 #ifdef CONFIG_NET_POLL_CONTROLLER
1316 * Polling receive - used by netconsole and other diagnostic tools
1317 * to allow network i/o with interrupts disabled.
1319 static void smc_poll_controller(struct net_device
*dev
)
1321 disable_irq(dev
->irq
);
1322 smc_interrupt(dev
->irq
, dev
);
1323 enable_irq(dev
->irq
);
1327 /* Our watchdog timed out. Called by the networking layer */
1328 static void smc_timeout(struct net_device
*dev
)
1330 struct smc_local
*lp
= netdev_priv(dev
);
1331 void __iomem
*ioaddr
= lp
->base
;
1332 int status
, mask
, eph_st
, meminfo
, fifo
;
1334 DBG(2, dev
, "%s\n", __func__
);
1336 spin_lock_irq(&lp
->lock
);
1337 status
= SMC_GET_INT(lp
);
1338 mask
= SMC_GET_INT_MASK(lp
);
1339 fifo
= SMC_GET_FIFO(lp
);
1340 SMC_SELECT_BANK(lp
, 0);
1341 eph_st
= SMC_GET_EPH_STATUS(lp
);
1342 meminfo
= SMC_GET_MIR(lp
);
1343 SMC_SELECT_BANK(lp
, 2);
1344 spin_unlock_irq(&lp
->lock
);
1345 PRINTK(dev
, "TX timeout (INT 0x%02x INTMASK 0x%02x MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n",
1346 status
, mask
, meminfo
, fifo
, eph_st
);
1352 * Reconfiguring the PHY doesn't seem like a bad idea here, but
1353 * smc_phy_configure() calls msleep() which calls schedule_timeout()
1354 * which calls schedule(). Hence we use a work queue.
1356 if (lp
->phy_type
!= 0)
1357 schedule_work(&lp
->phy_configure
);
1359 /* We can accept TX packets again */
1360 dev
->trans_start
= jiffies
; /* prevent tx timeout */
1361 netif_wake_queue(dev
);
1365 * This routine will, depending on the values passed to it,
1366 * either make it accept multicast packets, go into
1367 * promiscuous mode (for TCPDUMP and cousins) or accept
1368 * a select set of multicast packets
1370 static void smc_set_multicast_list(struct net_device
*dev
)
1372 struct smc_local
*lp
= netdev_priv(dev
);
1373 void __iomem
*ioaddr
= lp
->base
;
1374 unsigned char multicast_table
[8];
1375 int update_multicast
= 0;
1377 DBG(2, dev
, "%s\n", __func__
);
1379 if (dev
->flags
& IFF_PROMISC
) {
1380 DBG(2, dev
, "RCR_PRMS\n");
1381 lp
->rcr_cur_mode
|= RCR_PRMS
;
1384 /* BUG? I never disable promiscuous mode if multicasting was turned on.
1385 Now, I turn off promiscuous mode, but I don't do anything to multicasting
1386 when promiscuous mode is turned on.
1390 * Here, I am setting this to accept all multicast packets.
1391 * I don't need to zero the multicast table, because the flag is
1392 * checked before the table is
1394 else if (dev
->flags
& IFF_ALLMULTI
|| netdev_mc_count(dev
) > 16) {
1395 DBG(2, dev
, "RCR_ALMUL\n");
1396 lp
->rcr_cur_mode
|= RCR_ALMUL
;
1400 * This sets the internal hardware table to filter out unwanted
1401 * multicast packets before they take up memory.
1403 * The SMC chip uses a hash table where the high 6 bits of the CRC of
1404 * address are the offset into the table. If that bit is 1, then the
1405 * multicast packet is accepted. Otherwise, it's dropped silently.
1407 * To use the 6 bits as an offset into the table, the high 3 bits are
1408 * the number of the 8 bit register, while the low 3 bits are the bit
1409 * within that register.
1411 else if (!netdev_mc_empty(dev
)) {
1412 struct netdev_hw_addr
*ha
;
1414 /* table for flipping the order of 3 bits */
1415 static const unsigned char invert3
[] = {0, 4, 2, 6, 1, 5, 3, 7};
1417 /* start with a table of all zeros: reject all */
1418 memset(multicast_table
, 0, sizeof(multicast_table
));
1420 netdev_for_each_mc_addr(ha
, dev
) {
1423 /* only use the low order bits */
1424 position
= crc32_le(~0, ha
->addr
, 6) & 0x3f;
1426 /* do some messy swapping to put the bit in the right spot */
1427 multicast_table
[invert3
[position
&7]] |=
1428 (1<<invert3
[(position
>>3)&7]);
1431 /* be sure I get rid of flags I might have set */
1432 lp
->rcr_cur_mode
&= ~(RCR_PRMS
| RCR_ALMUL
);
1434 /* now, the table can be loaded into the chipset */
1435 update_multicast
= 1;
1437 DBG(2, dev
, "~(RCR_PRMS|RCR_ALMUL)\n");
1438 lp
->rcr_cur_mode
&= ~(RCR_PRMS
| RCR_ALMUL
);
1441 * since I'm disabling all multicast entirely, I need to
1442 * clear the multicast list
1444 memset(multicast_table
, 0, sizeof(multicast_table
));
1445 update_multicast
= 1;
1448 spin_lock_irq(&lp
->lock
);
1449 SMC_SELECT_BANK(lp
, 0);
1450 SMC_SET_RCR(lp
, lp
->rcr_cur_mode
);
1451 if (update_multicast
) {
1452 SMC_SELECT_BANK(lp
, 3);
1453 SMC_SET_MCAST(lp
, multicast_table
);
1455 SMC_SELECT_BANK(lp
, 2);
1456 spin_unlock_irq(&lp
->lock
);
1461 * Open and Initialize the board
1463 * Set up everything, reset the card, etc..
1466 smc_open(struct net_device
*dev
)
1468 struct smc_local
*lp
= netdev_priv(dev
);
1470 DBG(2, dev
, "%s\n", __func__
);
1472 /* Setup the default Register Modes */
1473 lp
->tcr_cur_mode
= TCR_DEFAULT
;
1474 lp
->rcr_cur_mode
= RCR_DEFAULT
;
1475 lp
->rpc_cur_mode
= RPC_DEFAULT
|
1476 lp
->cfg
.leda
<< RPC_LSXA_SHFT
|
1477 lp
->cfg
.ledb
<< RPC_LSXB_SHFT
;
1480 * If we are not using a MII interface, we need to
1481 * monitor our own carrier signal to detect faults.
1483 if (lp
->phy_type
== 0)
1484 lp
->tcr_cur_mode
|= TCR_MON_CSN
;
1486 /* reset the hardware */
1490 /* Configure the PHY, initialize the link state */
1491 if (lp
->phy_type
!= 0)
1492 smc_phy_configure(&lp
->phy_configure
);
1494 spin_lock_irq(&lp
->lock
);
1495 smc_10bt_check_media(dev
, 1);
1496 spin_unlock_irq(&lp
->lock
);
1499 netif_start_queue(dev
);
1506 * this makes the board clean up everything that it can
1507 * and not talk to the outside world. Caused by
1508 * an 'ifconfig ethX down'
1510 static int smc_close(struct net_device
*dev
)
1512 struct smc_local
*lp
= netdev_priv(dev
);
1514 DBG(2, dev
, "%s\n", __func__
);
1516 netif_stop_queue(dev
);
1517 netif_carrier_off(dev
);
1519 /* clear everything */
1521 tasklet_kill(&lp
->tx_task
);
1522 smc_phy_powerdown(dev
);
1530 smc_ethtool_getsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1532 struct smc_local
*lp
= netdev_priv(dev
);
1538 if (lp
->phy_type
!= 0) {
1539 spin_lock_irq(&lp
->lock
);
1540 ret
= mii_ethtool_gset(&lp
->mii
, cmd
);
1541 spin_unlock_irq(&lp
->lock
);
1543 cmd
->supported
= SUPPORTED_10baseT_Half
|
1544 SUPPORTED_10baseT_Full
|
1545 SUPPORTED_TP
| SUPPORTED_AUI
;
1547 if (lp
->ctl_rspeed
== 10)
1548 ethtool_cmd_speed_set(cmd
, SPEED_10
);
1549 else if (lp
->ctl_rspeed
== 100)
1550 ethtool_cmd_speed_set(cmd
, SPEED_100
);
1552 cmd
->autoneg
= AUTONEG_DISABLE
;
1553 cmd
->transceiver
= XCVR_INTERNAL
;
1555 cmd
->duplex
= lp
->tcr_cur_mode
& TCR_SWFDUP
? DUPLEX_FULL
: DUPLEX_HALF
;
1564 smc_ethtool_setsettings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1566 struct smc_local
*lp
= netdev_priv(dev
);
1569 if (lp
->phy_type
!= 0) {
1570 spin_lock_irq(&lp
->lock
);
1571 ret
= mii_ethtool_sset(&lp
->mii
, cmd
);
1572 spin_unlock_irq(&lp
->lock
);
1574 if (cmd
->autoneg
!= AUTONEG_DISABLE
||
1575 cmd
->speed
!= SPEED_10
||
1576 (cmd
->duplex
!= DUPLEX_HALF
&& cmd
->duplex
!= DUPLEX_FULL
) ||
1577 (cmd
->port
!= PORT_TP
&& cmd
->port
!= PORT_AUI
))
1580 // lp->port = cmd->port;
1581 lp
->ctl_rfduplx
= cmd
->duplex
== DUPLEX_FULL
;
1583 // if (netif_running(dev))
1584 // smc_set_port(dev);
1593 smc_ethtool_getdrvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1595 strlcpy(info
->driver
, CARDNAME
, sizeof(info
->driver
));
1596 strlcpy(info
->version
, version
, sizeof(info
->version
));
1597 strlcpy(info
->bus_info
, dev_name(dev
->dev
.parent
),
1598 sizeof(info
->bus_info
));
1601 static int smc_ethtool_nwayreset(struct net_device
*dev
)
1603 struct smc_local
*lp
= netdev_priv(dev
);
1606 if (lp
->phy_type
!= 0) {
1607 spin_lock_irq(&lp
->lock
);
1608 ret
= mii_nway_restart(&lp
->mii
);
1609 spin_unlock_irq(&lp
->lock
);
1615 static u32
smc_ethtool_getmsglevel(struct net_device
*dev
)
1617 struct smc_local
*lp
= netdev_priv(dev
);
1618 return lp
->msg_enable
;
1621 static void smc_ethtool_setmsglevel(struct net_device
*dev
, u32 level
)
1623 struct smc_local
*lp
= netdev_priv(dev
);
1624 lp
->msg_enable
= level
;
1627 static int smc_write_eeprom_word(struct net_device
*dev
, u16 addr
, u16 word
)
1630 struct smc_local
*lp
= netdev_priv(dev
);
1631 void __iomem
*ioaddr
= lp
->base
;
1633 spin_lock_irq(&lp
->lock
);
1634 /* load word into GP register */
1635 SMC_SELECT_BANK(lp
, 1);
1636 SMC_SET_GP(lp
, word
);
1637 /* set the address to put the data in EEPROM */
1638 SMC_SELECT_BANK(lp
, 2);
1639 SMC_SET_PTR(lp
, addr
);
1640 /* tell it to write */
1641 SMC_SELECT_BANK(lp
, 1);
1642 ctl
= SMC_GET_CTL(lp
);
1643 SMC_SET_CTL(lp
, ctl
| (CTL_EEPROM_SELECT
| CTL_STORE
));
1644 /* wait for it to finish */
1647 } while (SMC_GET_CTL(lp
) & CTL_STORE
);
1649 SMC_SET_CTL(lp
, ctl
);
1650 SMC_SELECT_BANK(lp
, 2);
1651 spin_unlock_irq(&lp
->lock
);
1655 static int smc_read_eeprom_word(struct net_device
*dev
, u16 addr
, u16
*word
)
1658 struct smc_local
*lp
= netdev_priv(dev
);
1659 void __iomem
*ioaddr
= lp
->base
;
1661 spin_lock_irq(&lp
->lock
);
1662 /* set the EEPROM address to get the data from */
1663 SMC_SELECT_BANK(lp
, 2);
1664 SMC_SET_PTR(lp
, addr
| PTR_READ
);
1665 /* tell it to load */
1666 SMC_SELECT_BANK(lp
, 1);
1667 SMC_SET_GP(lp
, 0xffff); /* init to known */
1668 ctl
= SMC_GET_CTL(lp
);
1669 SMC_SET_CTL(lp
, ctl
| (CTL_EEPROM_SELECT
| CTL_RELOAD
));
1670 /* wait for it to finish */
1673 } while (SMC_GET_CTL(lp
) & CTL_RELOAD
);
1674 /* read word from GP register */
1675 *word
= SMC_GET_GP(lp
);
1677 SMC_SET_CTL(lp
, ctl
);
1678 SMC_SELECT_BANK(lp
, 2);
1679 spin_unlock_irq(&lp
->lock
);
1683 static int smc_ethtool_geteeprom_len(struct net_device
*dev
)
1688 static int smc_ethtool_geteeprom(struct net_device
*dev
,
1689 struct ethtool_eeprom
*eeprom
, u8
*data
)
1694 DBG(1, dev
, "Reading %d bytes at %d(0x%x)\n",
1695 eeprom
->len
, eeprom
->offset
, eeprom
->offset
);
1696 imax
= smc_ethtool_geteeprom_len(dev
);
1697 for (i
= 0; i
< eeprom
->len
; i
+= 2) {
1700 int offset
= i
+ eeprom
->offset
;
1703 ret
= smc_read_eeprom_word(dev
, offset
>> 1, &wbuf
);
1706 DBG(2, dev
, "Read 0x%x from 0x%x\n", wbuf
, offset
>> 1);
1707 data
[i
] = (wbuf
>> 8) & 0xff;
1708 data
[i
+1] = wbuf
& 0xff;
1713 static int smc_ethtool_seteeprom(struct net_device
*dev
,
1714 struct ethtool_eeprom
*eeprom
, u8
*data
)
1719 DBG(1, dev
, "Writing %d bytes to %d(0x%x)\n",
1720 eeprom
->len
, eeprom
->offset
, eeprom
->offset
);
1721 imax
= smc_ethtool_geteeprom_len(dev
);
1722 for (i
= 0; i
< eeprom
->len
; i
+= 2) {
1725 int offset
= i
+ eeprom
->offset
;
1728 wbuf
= (data
[i
] << 8) | data
[i
+ 1];
1729 DBG(2, dev
, "Writing 0x%x to 0x%x\n", wbuf
, offset
>> 1);
1730 ret
= smc_write_eeprom_word(dev
, offset
>> 1, wbuf
);
1738 static const struct ethtool_ops smc_ethtool_ops
= {
1739 .get_settings
= smc_ethtool_getsettings
,
1740 .set_settings
= smc_ethtool_setsettings
,
1741 .get_drvinfo
= smc_ethtool_getdrvinfo
,
1743 .get_msglevel
= smc_ethtool_getmsglevel
,
1744 .set_msglevel
= smc_ethtool_setmsglevel
,
1745 .nway_reset
= smc_ethtool_nwayreset
,
1746 .get_link
= ethtool_op_get_link
,
1747 .get_eeprom_len
= smc_ethtool_geteeprom_len
,
1748 .get_eeprom
= smc_ethtool_geteeprom
,
1749 .set_eeprom
= smc_ethtool_seteeprom
,
1752 static const struct net_device_ops smc_netdev_ops
= {
1753 .ndo_open
= smc_open
,
1754 .ndo_stop
= smc_close
,
1755 .ndo_start_xmit
= smc_hard_start_xmit
,
1756 .ndo_tx_timeout
= smc_timeout
,
1757 .ndo_set_rx_mode
= smc_set_multicast_list
,
1758 .ndo_change_mtu
= eth_change_mtu
,
1759 .ndo_validate_addr
= eth_validate_addr
,
1760 .ndo_set_mac_address
= eth_mac_addr
,
1761 #ifdef CONFIG_NET_POLL_CONTROLLER
1762 .ndo_poll_controller
= smc_poll_controller
,
1769 * This routine has a simple purpose -- make the SMC chip generate an
1770 * interrupt, so an auto-detect routine can detect it, and find the IRQ,
1773 * does this still work?
1775 * I just deleted auto_irq.c, since it was never built...
1778 static int smc_findirq(struct smc_local
*lp
)
1780 void __iomem
*ioaddr
= lp
->base
;
1782 unsigned long cookie
;
1784 DBG(2, dev
, "%s: %s\n", CARDNAME
, __func__
);
1786 cookie
= probe_irq_on();
1789 * What I try to do here is trigger an ALLOC_INT. This is done
1790 * by allocating a small chunk of memory, which will give an interrupt
1793 /* enable ALLOCation interrupts ONLY */
1794 SMC_SELECT_BANK(lp
, 2);
1795 SMC_SET_INT_MASK(lp
, IM_ALLOC_INT
);
1798 * Allocate 512 bytes of memory. Note that the chip was just
1799 * reset so all the memory is available
1801 SMC_SET_MMU_CMD(lp
, MC_ALLOC
| 1);
1804 * Wait until positive that the interrupt has been generated
1809 int_status
= SMC_GET_INT(lp
);
1810 if (int_status
& IM_ALLOC_INT
)
1811 break; /* got the interrupt */
1812 } while (--timeout
);
1815 * there is really nothing that I can do here if timeout fails,
1816 * as autoirq_report will return a 0 anyway, which is what I
1817 * want in this case. Plus, the clean up is needed in both
1821 /* and disable all interrupts again */
1822 SMC_SET_INT_MASK(lp
, 0);
1824 /* and return what I found */
1825 return probe_irq_off(cookie
);
1829 * Function: smc_probe(unsigned long ioaddr)
1832 * Tests to see if a given ioaddr points to an SMC91x chip.
1833 * Returns a 0 on success
1836 * (1) see if the high byte of BANK_SELECT is 0x33
1837 * (2) compare the ioaddr with the base register's address
1838 * (3) see if I recognize the chip ID in the appropriate register
1840 * Here I do typical initialization tasks.
1842 * o Initialize the structure if needed
1843 * o print out my vanity message if not done so already
1844 * o print out what type of hardware is detected
1845 * o print out the ethernet address
1847 * o set up my private data
1848 * o configure the dev structure with my subroutines
1849 * o actually GRAB the irq.
1852 static int smc_probe(struct net_device
*dev
, void __iomem
*ioaddr
,
1853 unsigned long irq_flags
)
1855 struct smc_local
*lp
= netdev_priv(dev
);
1857 unsigned int val
, revision_register
;
1858 const char *version_string
;
1860 DBG(2, dev
, "%s: %s\n", CARDNAME
, __func__
);
1862 /* First, see if the high byte is 0x33 */
1863 val
= SMC_CURRENT_BANK(lp
);
1864 DBG(2, dev
, "%s: bank signature probe returned 0x%04x\n",
1866 if ((val
& 0xFF00) != 0x3300) {
1867 if ((val
& 0xFF) == 0x33) {
1869 "%s: Detected possible byte-swapped interface at IOADDR %p\n",
1877 * The above MIGHT indicate a device, but I need to write to
1878 * further test this.
1880 SMC_SELECT_BANK(lp
, 0);
1881 val
= SMC_CURRENT_BANK(lp
);
1882 if ((val
& 0xFF00) != 0x3300) {
1888 * well, we've already written once, so hopefully another
1889 * time won't hurt. This time, I need to switch the bank
1890 * register to bank 1, so I can access the base address
1893 SMC_SELECT_BANK(lp
, 1);
1894 val
= SMC_GET_BASE(lp
);
1895 val
= ((val
& 0x1F00) >> 3) << SMC_IO_SHIFT
;
1896 if (((unsigned long)ioaddr
& (0x3e0 << SMC_IO_SHIFT
)) != val
) {
1897 netdev_warn(dev
, "%s: IOADDR %p doesn't match configuration (%x).\n",
1898 CARDNAME
, ioaddr
, val
);
1902 * check if the revision register is something that I
1903 * recognize. These might need to be added to later,
1904 * as future revisions could be added.
1906 SMC_SELECT_BANK(lp
, 3);
1907 revision_register
= SMC_GET_REV(lp
);
1908 DBG(2, dev
, "%s: revision = 0x%04x\n", CARDNAME
, revision_register
);
1909 version_string
= chip_ids
[ (revision_register
>> 4) & 0xF];
1910 if (!version_string
|| (revision_register
& 0xff00) != 0x3300) {
1911 /* I don't recognize this chip, so... */
1912 netdev_warn(dev
, "%s: IO %p: Unrecognized revision register 0x%04x, Contact author.\n",
1913 CARDNAME
, ioaddr
, revision_register
);
1919 /* At this point I'll assume that the chip is an SMC91x. */
1920 pr_info_once("%s\n", version
);
1922 /* fill in some of the fields */
1923 dev
->base_addr
= (unsigned long)ioaddr
;
1925 lp
->version
= revision_register
& 0xff;
1926 spin_lock_init(&lp
->lock
);
1928 /* Get the MAC address */
1929 SMC_SELECT_BANK(lp
, 1);
1930 SMC_GET_MAC_ADDR(lp
, dev
->dev_addr
);
1932 /* now, reset the chip, and put it into a known state */
1936 * If dev->irq is 0, then the device has to be banged on to see
1939 * This banging doesn't always detect the IRQ, for unknown reasons.
1940 * a workaround is to reset the chip and try again.
1942 * Interestingly, the DOS packet driver *SETS* the IRQ on the card to
1943 * be what is requested on the command line. I don't do that, mostly
1944 * because the card that I have uses a non-standard method of accessing
1945 * the IRQs, and because this _should_ work in most configurations.
1947 * Specifying an IRQ is done with the assumption that the user knows
1948 * what (s)he is doing. No checking is done!!!!
1955 dev
->irq
= smc_findirq(lp
);
1958 /* kick the card and try again */
1962 if (dev
->irq
== 0) {
1963 netdev_warn(dev
, "Couldn't autodetect your IRQ. Use irq=xx.\n");
1967 dev
->irq
= irq_canonicalize(dev
->irq
);
1969 /* Fill in the fields of the device structure with ethernet values. */
1972 dev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1973 dev
->netdev_ops
= &smc_netdev_ops
;
1974 dev
->ethtool_ops
= &smc_ethtool_ops
;
1976 tasklet_init(&lp
->tx_task
, smc_hardware_send_pkt
, (unsigned long)dev
);
1977 INIT_WORK(&lp
->phy_configure
, smc_phy_configure
);
1979 lp
->mii
.phy_id_mask
= 0x1f;
1980 lp
->mii
.reg_num_mask
= 0x1f;
1981 lp
->mii
.force_media
= 0;
1982 lp
->mii
.full_duplex
= 0;
1984 lp
->mii
.mdio_read
= smc_phy_read
;
1985 lp
->mii
.mdio_write
= smc_phy_write
;
1988 * Locate the phy, if any.
1990 if (lp
->version
>= (CHIP_91100
<< 4))
1991 smc_phy_detect(dev
);
1993 /* then shut everything down to save power */
1995 smc_phy_powerdown(dev
);
1997 /* Set default parameters */
1998 lp
->msg_enable
= NETIF_MSG_LINK
;
1999 lp
->ctl_rfduplx
= 0;
2000 lp
->ctl_rspeed
= 10;
2002 if (lp
->version
>= (CHIP_91100
<< 4)) {
2003 lp
->ctl_rfduplx
= 1;
2004 lp
->ctl_rspeed
= 100;
2008 retval
= request_irq(dev
->irq
, smc_interrupt
, irq_flags
, dev
->name
, dev
);
2012 #ifdef CONFIG_ARCH_PXA
2013 # ifdef SMC_USE_PXA_DMA
2014 lp
->cfg
.flags
|= SMC91X_USE_DMA
;
2016 if (lp
->cfg
.flags
& SMC91X_USE_DMA
) {
2017 int dma
= pxa_request_dma(dev
->name
, DMA_PRIO_LOW
,
2018 smc_pxa_dma_irq
, NULL
);
2024 retval
= register_netdev(dev
);
2026 /* now, print out the card info, in a short format.. */
2027 netdev_info(dev
, "%s (rev %d) at %p IRQ %d",
2028 version_string
, revision_register
& 0x0f,
2029 lp
->base
, dev
->irq
);
2031 if (dev
->dma
!= (unsigned char)-1)
2032 pr_cont(" DMA %d", dev
->dma
);
2035 lp
->cfg
.flags
& SMC91X_NOWAIT
? " [nowait]" : "",
2036 THROTTLE_TX_PKTS
? " [throttle_tx]" : "");
2038 if (!is_valid_ether_addr(dev
->dev_addr
)) {
2039 netdev_warn(dev
, "Invalid ethernet MAC address. Please set using ifconfig\n");
2041 /* Print the Ethernet address */
2042 netdev_info(dev
, "Ethernet addr: %pM\n",
2046 if (lp
->phy_type
== 0) {
2047 PRINTK(dev
, "No PHY found\n");
2048 } else if ((lp
->phy_type
& 0xfffffff0) == 0x0016f840) {
2049 PRINTK(dev
, "PHY LAN83C183 (LAN91C111 Internal)\n");
2050 } else if ((lp
->phy_type
& 0xfffffff0) == 0x02821c50) {
2051 PRINTK(dev
, "PHY LAN83C180\n");
2056 #ifdef CONFIG_ARCH_PXA
2057 if (retval
&& dev
->dma
!= (unsigned char)-1)
2058 pxa_free_dma(dev
->dma
);
2063 static int smc_enable_device(struct platform_device
*pdev
)
2065 struct net_device
*ndev
= platform_get_drvdata(pdev
);
2066 struct smc_local
*lp
= netdev_priv(ndev
);
2067 unsigned long flags
;
2068 unsigned char ecor
, ecsr
;
2070 struct resource
* res
;
2072 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-attrib");
2077 * Map the attribute space. This is overkill, but clean.
2079 addr
= ioremap(res
->start
, ATTRIB_SIZE
);
2084 * Reset the device. We must disable IRQs around this
2085 * since a reset causes the IRQ line become active.
2087 local_irq_save(flags
);
2088 ecor
= readb(addr
+ (ECOR
<< SMC_IO_SHIFT
)) & ~ECOR_RESET
;
2089 writeb(ecor
| ECOR_RESET
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
2090 readb(addr
+ (ECOR
<< SMC_IO_SHIFT
));
2093 * Wait 100us for the chip to reset.
2098 * The device will ignore all writes to the enable bit while
2099 * reset is asserted, even if the reset bit is cleared in the
2100 * same write. Must clear reset first, then enable the device.
2102 writeb(ecor
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
2103 writeb(ecor
| ECOR_ENABLE
, addr
+ (ECOR
<< SMC_IO_SHIFT
));
2106 * Set the appropriate byte/word mode.
2108 ecsr
= readb(addr
+ (ECSR
<< SMC_IO_SHIFT
)) & ~ECSR_IOIS8
;
2111 writeb(ecsr
, addr
+ (ECSR
<< SMC_IO_SHIFT
));
2112 local_irq_restore(flags
);
2117 * Wait for the chip to wake up. We could poll the control
2118 * register in the main register space, but that isn't mapped
2119 * yet. We know this is going to take 750us.
2126 static int smc_request_attrib(struct platform_device
*pdev
,
2127 struct net_device
*ndev
)
2129 struct resource
* res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-attrib");
2130 struct smc_local
*lp __maybe_unused
= netdev_priv(ndev
);
2135 if (!request_mem_region(res
->start
, ATTRIB_SIZE
, CARDNAME
))
2141 static void smc_release_attrib(struct platform_device
*pdev
,
2142 struct net_device
*ndev
)
2144 struct resource
* res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-attrib");
2145 struct smc_local
*lp __maybe_unused
= netdev_priv(ndev
);
2148 release_mem_region(res
->start
, ATTRIB_SIZE
);
2151 static inline void smc_request_datacs(struct platform_device
*pdev
, struct net_device
*ndev
)
2153 if (SMC_CAN_USE_DATACS
) {
2154 struct resource
* res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-data32");
2155 struct smc_local
*lp
= netdev_priv(ndev
);
2160 if(!request_mem_region(res
->start
, SMC_DATA_EXTENT
, CARDNAME
)) {
2161 netdev_info(ndev
, "%s: failed to request datacs memory region.\n",
2166 lp
->datacs
= ioremap(res
->start
, SMC_DATA_EXTENT
);
2170 static void smc_release_datacs(struct platform_device
*pdev
, struct net_device
*ndev
)
2172 if (SMC_CAN_USE_DATACS
) {
2173 struct smc_local
*lp
= netdev_priv(ndev
);
2174 struct resource
* res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-data32");
2177 iounmap(lp
->datacs
);
2182 release_mem_region(res
->start
, SMC_DATA_EXTENT
);
2186 #if IS_BUILTIN(CONFIG_OF)
2187 static const struct of_device_id smc91x_match
[] = {
2188 { .compatible
= "smsc,lan91c94", },
2189 { .compatible
= "smsc,lan91c111", },
2192 MODULE_DEVICE_TABLE(of
, smc91x_match
);
2198 * dev->base_addr == 0, try to find all possible locations
2199 * dev->base_addr > 0x1ff, this is the address to check
2200 * dev->base_addr == <anything else>, return failure code
2203 * 0 --> there is a device
2204 * anything else, error
2206 static int smc_drv_probe(struct platform_device
*pdev
)
2208 struct smc91x_platdata
*pd
= dev_get_platdata(&pdev
->dev
);
2209 const struct of_device_id
*match
= NULL
;
2210 struct smc_local
*lp
;
2211 struct net_device
*ndev
;
2212 struct resource
*res
, *ires
;
2213 unsigned int __iomem
*addr
;
2214 unsigned long irq_flags
= SMC_IRQ_FLAGS
;
2217 ndev
= alloc_etherdev(sizeof(struct smc_local
));
2222 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
2224 /* get configuration from platform data, only allow use of
2225 * bus width if both SMC_CAN_USE_xxx and SMC91X_USE_xxx are set.
2228 lp
= netdev_priv(ndev
);
2232 memcpy(&lp
->cfg
, pd
, sizeof(lp
->cfg
));
2233 lp
->io_shift
= SMC91X_IO_SHIFT(lp
->cfg
.flags
);
2236 #if IS_BUILTIN(CONFIG_OF)
2237 match
= of_match_device(of_match_ptr(smc91x_match
), &pdev
->dev
);
2239 struct device_node
*np
= pdev
->dev
.of_node
;
2242 /* Combination of IO widths supported, default to 16-bit */
2243 if (!of_property_read_u32(np
, "reg-io-width", &val
)) {
2245 lp
->cfg
.flags
|= SMC91X_USE_8BIT
;
2246 if ((val
== 0) || (val
& 2))
2247 lp
->cfg
.flags
|= SMC91X_USE_16BIT
;
2249 lp
->cfg
.flags
|= SMC91X_USE_32BIT
;
2251 lp
->cfg
.flags
|= SMC91X_USE_16BIT
;
2256 if (!pd
&& !match
) {
2257 lp
->cfg
.flags
|= (SMC_CAN_USE_8BIT
) ? SMC91X_USE_8BIT
: 0;
2258 lp
->cfg
.flags
|= (SMC_CAN_USE_16BIT
) ? SMC91X_USE_16BIT
: 0;
2259 lp
->cfg
.flags
|= (SMC_CAN_USE_32BIT
) ? SMC91X_USE_32BIT
: 0;
2260 lp
->cfg
.flags
|= (nowait
) ? SMC91X_NOWAIT
: 0;
2263 if (!lp
->cfg
.leda
&& !lp
->cfg
.ledb
) {
2264 lp
->cfg
.leda
= RPC_LSA_DEFAULT
;
2265 lp
->cfg
.ledb
= RPC_LSB_DEFAULT
;
2268 ndev
->dma
= (unsigned char)-1;
2270 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-regs");
2272 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2275 goto out_free_netdev
;
2279 if (!request_mem_region(res
->start
, SMC_IO_EXTENT
, CARDNAME
)) {
2281 goto out_free_netdev
;
2284 ires
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
2287 goto out_release_io
;
2290 ndev
->irq
= ires
->start
;
2292 if (irq_flags
== -1 || ires
->flags
& IRQF_TRIGGER_MASK
)
2293 irq_flags
= ires
->flags
& IRQF_TRIGGER_MASK
;
2295 ret
= smc_request_attrib(pdev
, ndev
);
2297 goto out_release_io
;
2298 #if defined(CONFIG_SA1100_ASSABET)
2299 neponset_ncr_set(NCR_ENET_OSC_EN
);
2301 platform_set_drvdata(pdev
, ndev
);
2302 ret
= smc_enable_device(pdev
);
2304 goto out_release_attrib
;
2306 addr
= ioremap(res
->start
, SMC_IO_EXTENT
);
2309 goto out_release_attrib
;
2312 #ifdef CONFIG_ARCH_PXA
2314 struct smc_local
*lp
= netdev_priv(ndev
);
2315 lp
->device
= &pdev
->dev
;
2316 lp
->physaddr
= res
->start
;
2320 ret
= smc_probe(ndev
, addr
, irq_flags
);
2324 smc_request_datacs(pdev
, ndev
);
2331 smc_release_attrib(pdev
, ndev
);
2333 release_mem_region(res
->start
, SMC_IO_EXTENT
);
2337 pr_info("%s: not found (%d).\n", CARDNAME
, ret
);
2342 static int smc_drv_remove(struct platform_device
*pdev
)
2344 struct net_device
*ndev
= platform_get_drvdata(pdev
);
2345 struct smc_local
*lp
= netdev_priv(ndev
);
2346 struct resource
*res
;
2348 unregister_netdev(ndev
);
2350 free_irq(ndev
->irq
, ndev
);
2352 #ifdef CONFIG_ARCH_PXA
2353 if (ndev
->dma
!= (unsigned char)-1)
2354 pxa_free_dma(ndev
->dma
);
2358 smc_release_datacs(pdev
,ndev
);
2359 smc_release_attrib(pdev
,ndev
);
2361 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "smc91x-regs");
2363 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2364 release_mem_region(res
->start
, SMC_IO_EXTENT
);
2371 static int smc_drv_suspend(struct device
*dev
)
2373 struct platform_device
*pdev
= to_platform_device(dev
);
2374 struct net_device
*ndev
= platform_get_drvdata(pdev
);
2377 if (netif_running(ndev
)) {
2378 netif_device_detach(ndev
);
2380 smc_phy_powerdown(ndev
);
2386 static int smc_drv_resume(struct device
*dev
)
2388 struct platform_device
*pdev
= to_platform_device(dev
);
2389 struct net_device
*ndev
= platform_get_drvdata(pdev
);
2392 struct smc_local
*lp
= netdev_priv(ndev
);
2393 smc_enable_device(pdev
);
2394 if (netif_running(ndev
)) {
2397 if (lp
->phy_type
!= 0)
2398 smc_phy_configure(&lp
->phy_configure
);
2399 netif_device_attach(ndev
);
2405 static struct dev_pm_ops smc_drv_pm_ops
= {
2406 .suspend
= smc_drv_suspend
,
2407 .resume
= smc_drv_resume
,
2410 static struct platform_driver smc_driver
= {
2411 .probe
= smc_drv_probe
,
2412 .remove
= smc_drv_remove
,
2415 .owner
= THIS_MODULE
,
2416 .pm
= &smc_drv_pm_ops
,
2417 .of_match_table
= of_match_ptr(smc91x_match
),
2421 module_platform_driver(smc_driver
);