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!)
150 #define DBG(n, dev, fmt, ...) \
152 if (SMC_DEBUG >= (n)) \
153 netdev_dbg(dev, fmt, ##__VA_ARGS__); \
156 #define PRINTK(dev, fmt, ...) \
159 netdev_info(dev, fmt, ##__VA_ARGS__); \
161 netdev_dbg(dev, fmt, ##__VA_ARGS__); \
165 static void PRINT_PKT(u_char *buf, int length)
172 remainder = length % 16;
174 for (i = 0; i < lines ; i ++) {
177 for (cur = 0; cur < 8; cur++) {
181 pr_cont("%02x%02x ", a, b);
186 for (i = 0; i < remainder/2 ; i++) {
190 pr_cont("%02x%02x ", a, b);
195 static inline void PRINT_PKT(u_char *buf, int length) { }
199 /* this enables an interrupt in the interrupt mask register */
200 #define SMC_ENABLE_INT(lp, x) do { \
201 unsigned char mask; \
202 unsigned long smc_enable_flags; \
203 spin_lock_irqsave(&lp->lock, smc_enable_flags); \
204 mask = SMC_GET_INT_MASK(lp); \
206 SMC_SET_INT_MASK(lp, mask); \
207 spin_unlock_irqrestore(&lp->lock, smc_enable_flags); \
210 /* this disables an interrupt from the interrupt mask register */
211 #define SMC_DISABLE_INT(lp, x) do { \
212 unsigned char mask; \
213 unsigned long smc_disable_flags; \
214 spin_lock_irqsave(&lp->lock, smc_disable_flags); \
215 mask = SMC_GET_INT_MASK(lp); \
217 SMC_SET_INT_MASK(lp, mask); \
218 spin_unlock_irqrestore(&lp->lock, smc_disable_flags); \
222 * Wait while MMU is busy. This is usually in the order of a few nanosecs
223 * if at all, but let's avoid deadlocking the system if the hardware
224 * decides to go south.
226 #define SMC_WAIT_MMU_BUSY(lp) do { \
227 if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \
228 unsigned long timeout = jiffies + 2; \
229 while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \
230 if (time_after(jiffies, timeout)) { \
231 netdev_dbg(dev, "timeout %s line %d\n", \
232 __FILE__, __LINE__); \
242 * this does a soft reset on the device
244 static void smc_reset(struct net_device *dev)
246 struct smc_local *lp = netdev_priv(dev);
247 void __iomem *ioaddr = lp->base;
248 unsigned int ctl, cfg;
249 struct sk_buff *pending_skb;
251 DBG(2, dev, "%s\n", __func__);
253 /* Disable all interrupts, block TX tasklet */
254 spin_lock_irq(&lp->lock);
255 SMC_SELECT_BANK(lp, 2);
256 SMC_SET_INT_MASK(lp, 0);
257 pending_skb = lp->pending_tx_skb;
258 lp->pending_tx_skb = NULL;
259 spin_unlock_irq(&lp->lock);
261 /* free any pending tx skb */
263 dev_kfree_skb(pending_skb);
264 dev->stats.tx_errors++;
265 dev->stats.tx_aborted_errors++;
269 * This resets the registers mostly to defaults, but doesn't
270 * affect EEPROM. That seems unnecessary
272 SMC_SELECT_BANK(lp, 0);
273 SMC_SET_RCR(lp, RCR_SOFTRST);
276 * Setup the Configuration Register
277 * This is necessary because the CONFIG_REG is not affected
280 SMC_SELECT_BANK(lp, 1);
282 cfg = CONFIG_DEFAULT;
285 * Setup for fast accesses if requested. If the card/system
286 * can't handle it then there will be no recovery except for
287 * a hard reset or power cycle
289 if (lp->cfg.flags & SMC91X_NOWAIT)
290 cfg |= CONFIG_NO_WAIT;
293 * Release from possible power-down state
294 * Configuration register is not affected by Soft Reset
296 cfg |= CONFIG_EPH_POWER_EN;
298 SMC_SET_CONFIG(lp, cfg);
300 /* this should pause enough for the chip to be happy */
302 * elaborate? What does the chip _need_? --jgarzik
304 * This seems to be undocumented, but something the original
305 * driver(s) have always done. Suspect undocumented timing
306 * info/determined empirically. --rmk
310 /* Disable transmit and receive functionality */
311 SMC_SELECT_BANK(lp, 0);
312 SMC_SET_RCR(lp, RCR_CLEAR);
313 SMC_SET_TCR(lp, TCR_CLEAR);
315 SMC_SELECT_BANK(lp, 1);
316 ctl = SMC_GET_CTL(lp) | CTL_LE_ENABLE;
319 * Set the control register to automatically release successfully
320 * transmitted packets, to make the best use out of our limited
323 if(!THROTTLE_TX_PKTS)
324 ctl |= CTL_AUTO_RELEASE;
326 ctl &= ~CTL_AUTO_RELEASE;
327 SMC_SET_CTL(lp, ctl);
330 SMC_SELECT_BANK(lp, 2);
331 SMC_SET_MMU_CMD(lp, MC_RESET);
332 SMC_WAIT_MMU_BUSY(lp);
336 * Enable Interrupts, Receive, and Transmit
338 static void smc_enable(struct net_device *dev)
340 struct smc_local *lp = netdev_priv(dev);
341 void __iomem *ioaddr = lp->base;
344 DBG(2, dev, "%s\n", __func__);
346 /* see the header file for options in TCR/RCR DEFAULT */
347 SMC_SELECT_BANK(lp, 0);
348 SMC_SET_TCR(lp, lp->tcr_cur_mode);
349 SMC_SET_RCR(lp, lp->rcr_cur_mode);
351 SMC_SELECT_BANK(lp, 1);
352 SMC_SET_MAC_ADDR(lp, dev->dev_addr);
354 /* now, enable interrupts */
355 mask = IM_EPH_INT|IM_RX_OVRN_INT|IM_RCV_INT;
356 if (lp->version >= (CHIP_91100 << 4))
358 SMC_SELECT_BANK(lp, 2);
359 SMC_SET_INT_MASK(lp, mask);
362 * From this point the register bank must _NOT_ be switched away
363 * to something else than bank 2 without proper locking against
364 * races with any tasklet or interrupt handlers until smc_shutdown()
365 * or smc_reset() is called.
370 * this puts the device in an inactive state
372 static void smc_shutdown(struct net_device *dev)
374 struct smc_local *lp = netdev_priv(dev);
375 void __iomem *ioaddr = lp->base;
376 struct sk_buff *pending_skb;
378 DBG(2, dev, "%s: %s\n", CARDNAME, __func__);
380 /* no more interrupts for me */
381 spin_lock_irq(&lp->lock);
382 SMC_SELECT_BANK(lp, 2);
383 SMC_SET_INT_MASK(lp, 0);
384 pending_skb = lp->pending_tx_skb;
385 lp->pending_tx_skb = NULL;
386 spin_unlock_irq(&lp->lock);
388 dev_kfree_skb(pending_skb);
390 /* and tell the card to stay away from that nasty outside world */
391 SMC_SELECT_BANK(lp, 0);
392 SMC_SET_RCR(lp, RCR_CLEAR);
393 SMC_SET_TCR(lp, TCR_CLEAR);
396 /* finally, shut the chip down */
397 SMC_SELECT_BANK(lp, 1);
398 SMC_SET_CONFIG(lp, SMC_GET_CONFIG(lp) & ~CONFIG_EPH_POWER_EN);
403 * This is the procedure to handle the receipt of a packet.
405 static inline void smc_rcv(struct net_device *dev)
407 struct smc_local *lp = netdev_priv(dev);
408 void __iomem *ioaddr = lp->base;
409 unsigned int packet_number, status, packet_len;
411 DBG(3, dev, "%s\n", __func__);
413 packet_number = SMC_GET_RXFIFO(lp);
414 if (unlikely(packet_number & RXFIFO_REMPTY)) {
415 PRINTK(dev, "smc_rcv with nothing on FIFO.\n");
419 /* read from start of packet */
420 SMC_SET_PTR(lp, PTR_READ | PTR_RCV | PTR_AUTOINC);
422 /* First two words are status and packet length */
423 SMC_GET_PKT_HDR(lp, status, packet_len);
424 packet_len &= 0x07ff; /* mask off top bits */
425 DBG(2, dev, "RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
426 packet_number, status, packet_len, packet_len);
429 if (unlikely(packet_len < 6 || status & RS_ERRORS)) {
430 if (status & RS_TOOLONG && packet_len <= (1514 + 4 + 6)) {
431 /* accept VLAN packets */
432 status &= ~RS_TOOLONG;
435 if (packet_len < 6) {
436 /* bloody hardware */
437 netdev_err(dev, "fubar (rxlen %u status %x\n",
439 status |= RS_TOOSHORT;
441 SMC_WAIT_MMU_BUSY(lp);
442 SMC_SET_MMU_CMD(lp, MC_RELEASE);
443 dev->stats.rx_errors++;
444 if (status & RS_ALGNERR)
445 dev->stats.rx_frame_errors++;
446 if (status & (RS_TOOSHORT | RS_TOOLONG))
447 dev->stats.rx_length_errors++;
448 if (status & RS_BADCRC)
449 dev->stats.rx_crc_errors++;
453 unsigned int data_len;
455 /* set multicast stats */
456 if (status & RS_MULTICAST)
457 dev->stats.multicast++;
460 * Actual payload is packet_len - 6 (or 5 if odd byte).
461 * We want skb_reserve(2) and the final ctrl word
462 * (2 bytes, possibly containing the payload odd byte).
463 * Furthermore, we add 2 bytes to allow rounding up to
464 * multiple of 4 bytes on 32 bit buses.
465 * Hence packet_len - 6 + 2 + 2 + 2.
467 skb = netdev_alloc_skb(dev, packet_len);
468 if (unlikely(skb == NULL)) {
469 SMC_WAIT_MMU_BUSY(lp);
470 SMC_SET_MMU_CMD(lp, MC_RELEASE);
471 dev->stats.rx_dropped++;
475 /* Align IP header to 32 bits */
478 /* BUG: the LAN91C111 rev A never sets this bit. Force it. */
479 if (lp->version == 0x90)
480 status |= RS_ODDFRAME;
483 * If odd length: packet_len - 5,
484 * otherwise packet_len - 6.
485 * With the trailing ctrl byte it's packet_len - 4.
487 data_len = packet_len - ((status & RS_ODDFRAME) ? 5 : 6);
488 data = skb_put(skb, data_len);
489 SMC_PULL_DATA(lp, data, packet_len - 4);
491 SMC_WAIT_MMU_BUSY(lp);
492 SMC_SET_MMU_CMD(lp, MC_RELEASE);
494 PRINT_PKT(data, packet_len - 4);
496 skb->protocol = eth_type_trans(skb, dev);
498 dev->stats.rx_packets++;
499 dev->stats.rx_bytes += data_len;
505 * On SMP we have the following problem:
507 * A = smc_hardware_send_pkt()
508 * B = smc_hard_start_xmit()
509 * C = smc_interrupt()
511 * A and B can never be executed simultaneously. However, at least on UP,
512 * it is possible (and even desirable) for C to interrupt execution of
513 * A or B in order to have better RX reliability and avoid overruns.
514 * C, just like A and B, must have exclusive access to the chip and
515 * each of them must lock against any other concurrent access.
516 * Unfortunately this is not possible to have C suspend execution of A or
517 * B taking place on another CPU. On UP this is no an issue since A and B
518 * are run from softirq context and C from hard IRQ context, and there is
519 * no other CPU where concurrent access can happen.
520 * If ever there is a way to force at least B and C to always be executed
521 * on the same CPU then we could use read/write locks to protect against
522 * any other concurrent access and C would always interrupt B. But life
523 * isn't that easy in a SMP world...
525 #define smc_special_trylock(lock, flags) \
528 local_irq_save(flags); \
529 __ret = spin_trylock(lock); \
531 local_irq_restore(flags); \
534 #define smc_special_lock(lock, flags) spin_lock_irqsave(lock, flags)
535 #define smc_special_unlock(lock, flags) spin_unlock_irqrestore(lock, flags)
537 #define smc_special_trylock(lock, flags) (flags == flags)
538 #define smc_special_lock(lock, flags) do { flags = 0; } while (0)
539 #define smc_special_unlock(lock, flags) do { flags = 0; } while (0)
543 * This is called to actually send a packet to the chip.
545 static void smc_hardware_send_pkt(unsigned long data)
547 struct net_device *dev = (struct net_device *)data;
548 struct smc_local *lp = netdev_priv(dev);
549 void __iomem *ioaddr = lp->base;
551 unsigned int packet_no, len;
555 DBG(3, dev, "%s\n", __func__);
557 if (!smc_special_trylock(&lp->lock, flags)) {
558 netif_stop_queue(dev);
559 tasklet_schedule(&lp->tx_task);
563 skb = lp->pending_tx_skb;
564 if (unlikely(!skb)) {
565 smc_special_unlock(&lp->lock, flags);
568 lp->pending_tx_skb = NULL;
570 packet_no = SMC_GET_AR(lp);
571 if (unlikely(packet_no & AR_FAILED)) {
572 netdev_err(dev, "Memory allocation failed.\n");
573 dev->stats.tx_errors++;
574 dev->stats.tx_fifo_errors++;
575 smc_special_unlock(&lp->lock, flags);
579 /* point to the beginning of the packet */
580 SMC_SET_PN(lp, packet_no);
581 SMC_SET_PTR(lp, PTR_AUTOINC);
585 DBG(2, dev, "TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
586 packet_no, len, len, buf);
590 * Send the packet length (+6 for status words, length, and ctl.
591 * The card will pad to 64 bytes with zeroes if packet is too small.
593 SMC_PUT_PKT_HDR(lp, 0, len + 6);
595 /* send the actual data */
596 SMC_PUSH_DATA(lp, buf, len & ~1);
598 /* Send final ctl word with the last byte if there is one */
599 SMC_outw(((len & 1) ? (0x2000 | buf[len-1]) : 0), ioaddr, DATA_REG(lp));
602 * If THROTTLE_TX_PKTS is set, we stop the queue here. This will
603 * have the effect of having at most one packet queued for TX
604 * in the chip's memory at all time.
606 * If THROTTLE_TX_PKTS is not set then the queue is stopped only
607 * when memory allocation (MC_ALLOC) does not succeed right away.
609 if (THROTTLE_TX_PKTS)
610 netif_stop_queue(dev);
612 /* queue the packet for TX */
613 SMC_SET_MMU_CMD(lp, MC_ENQUEUE);
614 smc_special_unlock(&lp->lock, flags);
616 dev->trans_start = jiffies;
617 dev->stats.tx_packets++;
618 dev->stats.tx_bytes += len;
620 SMC_ENABLE_INT(lp, IM_TX_INT | IM_TX_EMPTY_INT);
622 done: if (!THROTTLE_TX_PKTS)
623 netif_wake_queue(dev);
625 dev_consume_skb_any(skb);
629 * Since I am not sure if I will have enough room in the chip's ram
630 * to store the packet, I call this routine which either sends it
631 * now, or set the card to generates an interrupt when ready
634 static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
636 struct smc_local *lp = netdev_priv(dev);
637 void __iomem *ioaddr = lp->base;
638 unsigned int numPages, poll_count, status;
641 DBG(3, dev, "%s\n", __func__);
643 BUG_ON(lp->pending_tx_skb != NULL);
646 * The MMU wants the number of pages to be the number of 256 bytes
647 * 'pages', minus 1 (since a packet can't ever have 0 pages :))
649 * The 91C111 ignores the size bits, but earlier models don't.
651 * Pkt size for allocating is data length +6 (for additional status
652 * words, length and ctl)
654 * If odd size then last byte is included in ctl word.
656 numPages = ((skb->len & ~1) + (6 - 1)) >> 8;
657 if (unlikely(numPages > 7)) {
658 netdev_warn(dev, "Far too big packet error.\n");
659 dev->stats.tx_errors++;
660 dev->stats.tx_dropped++;
661 dev_kfree_skb_any(skb);
665 smc_special_lock(&lp->lock, flags);
667 /* now, try to allocate the memory */
668 SMC_SET_MMU_CMD(lp, MC_ALLOC | numPages);
671 * Poll the chip for a short amount of time in case the
672 * allocation succeeds quickly.
674 poll_count = MEMORY_WAIT_TIME;
676 status = SMC_GET_INT(lp);
677 if (status & IM_ALLOC_INT) {
678 SMC_ACK_INT(lp, IM_ALLOC_INT);
681 } while (--poll_count);
683 smc_special_unlock(&lp->lock, flags);
685 lp->pending_tx_skb = skb;
687 /* oh well, wait until the chip finds memory later */
688 netif_stop_queue(dev);
689 DBG(2, dev, "TX memory allocation deferred.\n");
690 SMC_ENABLE_INT(lp, IM_ALLOC_INT);
693 * Allocation succeeded: push packet to the chip's own memory
696 smc_hardware_send_pkt((unsigned long)dev);
703 * This handles a TX interrupt, which is only called when:
704 * - a TX error occurred, or
705 * - CTL_AUTO_RELEASE is not set and TX of a packet completed.
707 static void smc_tx(struct net_device *dev)
709 struct smc_local *lp = netdev_priv(dev);
710 void __iomem *ioaddr = lp->base;
711 unsigned int saved_packet, packet_no, tx_status, pkt_len;
713 DBG(3, dev, "%s\n", __func__);
715 /* If the TX FIFO is empty then nothing to do */
716 packet_no = SMC_GET_TXFIFO(lp);
717 if (unlikely(packet_no & TXFIFO_TEMPTY)) {
718 PRINTK(dev, "smc_tx with nothing on FIFO.\n");
722 /* select packet to read from */
723 saved_packet = SMC_GET_PN(lp);
724 SMC_SET_PN(lp, packet_no);
726 /* read the first word (status word) from this packet */
727 SMC_SET_PTR(lp, PTR_AUTOINC | PTR_READ);
728 SMC_GET_PKT_HDR(lp, tx_status, pkt_len);
729 DBG(2, dev, "TX STATUS 0x%04x PNR 0x%02x\n",
730 tx_status, packet_no);
732 if (!(tx_status & ES_TX_SUC))
733 dev->stats.tx_errors++;
735 if (tx_status & ES_LOSTCARR)
736 dev->stats.tx_carrier_errors++;
738 if (tx_status & (ES_LATCOL | ES_16COL)) {
739 PRINTK(dev, "%s occurred on last xmit\n",
740 (tx_status & ES_LATCOL) ?
741 "late collision" : "too many collisions");
742 dev->stats.tx_window_errors++;
743 if (!(dev->stats.tx_window_errors & 63) && net_ratelimit()) {
744 netdev_info(dev, "unexpectedly large number of bad collisions. Please check duplex setting.\n");
748 /* kill the packet */
749 SMC_WAIT_MMU_BUSY(lp);
750 SMC_SET_MMU_CMD(lp, MC_FREEPKT);
752 /* Don't restore Packet Number Reg until busy bit is cleared */
753 SMC_WAIT_MMU_BUSY(lp);
754 SMC_SET_PN(lp, saved_packet);
756 /* re-enable transmit */
757 SMC_SELECT_BANK(lp, 0);
758 SMC_SET_TCR(lp, lp->tcr_cur_mode);
759 SMC_SELECT_BANK(lp, 2);
763 /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
765 static void smc_mii_out(struct net_device *dev, unsigned int val, int bits)
767 struct smc_local *lp = netdev_priv(dev);
768 void __iomem *ioaddr = lp->base;
769 unsigned int mii_reg, mask;
771 mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
774 for (mask = 1 << (bits - 1); mask; mask >>= 1) {
780 SMC_SET_MII(lp, mii_reg);
782 SMC_SET_MII(lp, mii_reg | MII_MCLK);
787 static unsigned int smc_mii_in(struct net_device *dev, int bits)
789 struct smc_local *lp = netdev_priv(dev);
790 void __iomem *ioaddr = lp->base;
791 unsigned int mii_reg, mask, val;
793 mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
794 SMC_SET_MII(lp, mii_reg);
796 for (mask = 1 << (bits - 1), val = 0; mask; mask >>= 1) {
797 if (SMC_GET_MII(lp) & MII_MDI)
800 SMC_SET_MII(lp, mii_reg);
802 SMC_SET_MII(lp, mii_reg | MII_MCLK);
810 * Reads a register from the MII Management serial interface
812 static int smc_phy_read(struct net_device *dev, int phyaddr, int phyreg)
814 struct smc_local *lp = netdev_priv(dev);
815 void __iomem *ioaddr = lp->base;
816 unsigned int phydata;
818 SMC_SELECT_BANK(lp, 3);
821 smc_mii_out(dev, 0xffffffff, 32);
823 /* Start code (01) + read (10) + phyaddr + phyreg */
824 smc_mii_out(dev, 6 << 10 | phyaddr << 5 | phyreg, 14);
826 /* Turnaround (2bits) + phydata */
827 phydata = smc_mii_in(dev, 18);
829 /* Return to idle state */
830 SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
832 DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
833 __func__, phyaddr, phyreg, phydata);
835 SMC_SELECT_BANK(lp, 2);
840 * Writes a register to the MII Management serial interface
842 static void smc_phy_write(struct net_device *dev, int phyaddr, int phyreg,
845 struct smc_local *lp = netdev_priv(dev);
846 void __iomem *ioaddr = lp->base;
848 SMC_SELECT_BANK(lp, 3);
851 smc_mii_out(dev, 0xffffffff, 32);
853 /* Start code (01) + write (01) + phyaddr + phyreg + turnaround + phydata */
854 smc_mii_out(dev, 5 << 28 | phyaddr << 23 | phyreg << 18 | 2 << 16 | phydata, 32);
856 /* Return to idle state */
857 SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
859 DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
860 __func__, phyaddr, phyreg, phydata);
862 SMC_SELECT_BANK(lp, 2);
866 * Finds and reports the PHY address
868 static void smc_phy_detect(struct net_device *dev)
870 struct smc_local *lp = netdev_priv(dev);
873 DBG(2, dev, "%s\n", __func__);
878 * Scan all 32 PHY addresses if necessary, starting at
879 * PHY#1 to PHY#31, and then PHY#0 last.
881 for (phyaddr = 1; phyaddr < 33; ++phyaddr) {
882 unsigned int id1, id2;
884 /* Read the PHY identifiers */
885 id1 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID1);
886 id2 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID2);
888 DBG(3, dev, "phy_id1=0x%x, phy_id2=0x%x\n",
891 /* Make sure it is a valid identifier */
892 if (id1 != 0x0000 && id1 != 0xffff && id1 != 0x8000 &&
893 id2 != 0x0000 && id2 != 0xffff && id2 != 0x8000) {
894 /* Save the PHY's address */
895 lp->mii.phy_id = phyaddr & 31;
896 lp->phy_type = id1 << 16 | id2;
903 * Sets the PHY to a configuration as determined by the user
905 static int smc_phy_fixed(struct net_device *dev)
907 struct smc_local *lp = netdev_priv(dev);
908 void __iomem *ioaddr = lp->base;
909 int phyaddr = lp->mii.phy_id;
912 DBG(3, dev, "%s\n", __func__);
914 /* Enter Link Disable state */
915 cfg1 = smc_phy_read(dev, phyaddr, PHY_CFG1_REG);
916 cfg1 |= PHY_CFG1_LNKDIS;
917 smc_phy_write(dev, phyaddr, PHY_CFG1_REG, cfg1);
920 * Set our fixed capabilities
921 * Disable auto-negotiation
926 bmcr |= BMCR_FULLDPLX;
928 if (lp->ctl_rspeed == 100)
929 bmcr |= BMCR_SPEED100;
931 /* Write our capabilities to the phy control register */
932 smc_phy_write(dev, phyaddr, MII_BMCR, bmcr);
934 /* Re-Configure the Receive/Phy Control register */
935 SMC_SELECT_BANK(lp, 0);
936 SMC_SET_RPC(lp, lp->rpc_cur_mode);
937 SMC_SELECT_BANK(lp, 2);
943 * smc_phy_reset - reset the phy
947 * Issue a software reset for the specified PHY and
948 * wait up to 100ms for the reset to complete. We should
949 * not access the PHY for 50ms after issuing the reset.
951 * The time to wait appears to be dependent on the PHY.
953 * Must be called with lp->lock locked.
955 static int smc_phy_reset(struct net_device *dev, int phy)
957 struct smc_local *lp = netdev_priv(dev);
961 smc_phy_write(dev, phy, MII_BMCR, BMCR_RESET);
963 for (timeout = 2; timeout; timeout--) {
964 spin_unlock_irq(&lp->lock);
966 spin_lock_irq(&lp->lock);
968 bmcr = smc_phy_read(dev, phy, MII_BMCR);
969 if (!(bmcr & BMCR_RESET))
973 return bmcr & BMCR_RESET;
977 * smc_phy_powerdown - powerdown phy
980 * Power down the specified PHY
982 static void smc_phy_powerdown(struct net_device *dev)
984 struct smc_local *lp = netdev_priv(dev);
986 int phy = lp->mii.phy_id;
988 if (lp->phy_type == 0)
991 /* We need to ensure that no calls to smc_phy_configure are
994 cancel_work_sync(&lp->phy_configure);
996 bmcr = smc_phy_read(dev, phy, MII_BMCR);
997 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN);
1001 * smc_phy_check_media - check the media status and adjust TCR
1003 * @init: set true for initialisation
1005 * Select duplex mode depending on negotiation state. This
1006 * also updates our carrier state.
1008 static void smc_phy_check_media(struct net_device *dev, int init)
1010 struct smc_local *lp = netdev_priv(dev);
1011 void __iomem *ioaddr = lp->base;
1013 if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
1014 /* duplex state has changed */
1015 if (lp->mii.full_duplex) {
1016 lp->tcr_cur_mode |= TCR_SWFDUP;
1018 lp->tcr_cur_mode &= ~TCR_SWFDUP;
1021 SMC_SELECT_BANK(lp, 0);
1022 SMC_SET_TCR(lp, lp->tcr_cur_mode);
1027 * Configures the specified PHY through the MII management interface
1028 * using Autonegotiation.
1029 * Calls smc_phy_fixed() if the user has requested a certain config.
1030 * If RPC ANEG bit is set, the media selection is dependent purely on
1031 * the selection by the MII (either in the MII BMCR reg or the result
1032 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
1033 * is controlled by the RPC SPEED and RPC DPLX bits.
1035 static void smc_phy_configure(struct work_struct *work)
1037 struct smc_local *lp =
1038 container_of(work, struct smc_local, phy_configure);
1039 struct net_device *dev = lp->dev;
1040 void __iomem *ioaddr = lp->base;
1041 int phyaddr = lp->mii.phy_id;
1042 int my_phy_caps; /* My PHY capabilities */
1043 int my_ad_caps; /* My Advertised capabilities */
1046 DBG(3, dev, "smc_program_phy()\n");
1048 spin_lock_irq(&lp->lock);
1051 * We should not be called if phy_type is zero.
1053 if (lp->phy_type == 0)
1054 goto smc_phy_configure_exit;
1056 if (smc_phy_reset(dev, phyaddr)) {
1057 netdev_info(dev, "PHY reset timed out\n");
1058 goto smc_phy_configure_exit;
1062 * Enable PHY Interrupts (for register 18)
1063 * Interrupts listed here are disabled
1065 smc_phy_write(dev, phyaddr, PHY_MASK_REG,
1066 PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
1067 PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
1068 PHY_INT_SPDDET | PHY_INT_DPLXDET);
1070 /* Configure the Receive/Phy Control register */
1071 SMC_SELECT_BANK(lp, 0);
1072 SMC_SET_RPC(lp, lp->rpc_cur_mode);
1074 /* If the user requested no auto neg, then go set his request */
1075 if (lp->mii.force_media) {
1077 goto smc_phy_configure_exit;
1080 /* Copy our capabilities from MII_BMSR to MII_ADVERTISE */
1081 my_phy_caps = smc_phy_read(dev, phyaddr, MII_BMSR);
1083 if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
1084 netdev_info(dev, "Auto negotiation NOT supported\n");
1086 goto smc_phy_configure_exit;
1089 my_ad_caps = ADVERTISE_CSMA; /* I am CSMA capable */
1091 if (my_phy_caps & BMSR_100BASE4)
1092 my_ad_caps |= ADVERTISE_100BASE4;
1093 if (my_phy_caps & BMSR_100FULL)
1094 my_ad_caps |= ADVERTISE_100FULL;
1095 if (my_phy_caps & BMSR_100HALF)
1096 my_ad_caps |= ADVERTISE_100HALF;
1097 if (my_phy_caps & BMSR_10FULL)
1098 my_ad_caps |= ADVERTISE_10FULL;
1099 if (my_phy_caps & BMSR_10HALF)
1100 my_ad_caps |= ADVERTISE_10HALF;
1102 /* Disable capabilities not selected by our user */
1103 if (lp->ctl_rspeed != 100)
1104 my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF);
1106 if (!lp->ctl_rfduplx)
1107 my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
1109 /* Update our Auto-Neg Advertisement Register */
1110 smc_phy_write(dev, phyaddr, MII_ADVERTISE, my_ad_caps);
1111 lp->mii.advertising = my_ad_caps;
1114 * Read the register back. Without this, it appears that when
1115 * auto-negotiation is restarted, sometimes it isn't ready and
1116 * the link does not come up.
1118 status = smc_phy_read(dev, phyaddr, MII_ADVERTISE);
1120 DBG(2, dev, "phy caps=%x\n", my_phy_caps);
1121 DBG(2, dev, "phy advertised caps=%x\n", my_ad_caps);
1123 /* Restart auto-negotiation process in order to advertise my caps */
1124 smc_phy_write(dev, phyaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
1126 smc_phy_check_media(dev, 1);
1128 smc_phy_configure_exit:
1129 SMC_SELECT_BANK(lp, 2);
1130 spin_unlock_irq(&lp->lock);
1136 * Purpose: Handle interrupts relating to PHY register 18. This is
1137 * called from the "hard" interrupt handler under our private spinlock.
1139 static void smc_phy_interrupt(struct net_device *dev)
1141 struct smc_local *lp = netdev_priv(dev);
1142 int phyaddr = lp->mii.phy_id;
1145 DBG(2, dev, "%s\n", __func__);
1147 if (lp->phy_type == 0)
1151 smc_phy_check_media(dev, 0);
1153 /* Read PHY Register 18, Status Output */
1154 phy18 = smc_phy_read(dev, phyaddr, PHY_INT_REG);
1155 if ((phy18 & PHY_INT_INT) == 0)
1160 /*--- END PHY CONTROL AND CONFIGURATION-------------------------------------*/
1162 static void smc_10bt_check_media(struct net_device *dev, int init)
1164 struct smc_local *lp = netdev_priv(dev);
1165 void __iomem *ioaddr = lp->base;
1166 unsigned int old_carrier, new_carrier;
1168 old_carrier = netif_carrier_ok(dev) ? 1 : 0;
1170 SMC_SELECT_BANK(lp, 0);
1171 new_carrier = (SMC_GET_EPH_STATUS(lp) & ES_LINK_OK) ? 1 : 0;
1172 SMC_SELECT_BANK(lp, 2);
1174 if (init || (old_carrier != new_carrier)) {
1176 netif_carrier_off(dev);
1178 netif_carrier_on(dev);
1180 if (netif_msg_link(lp))
1181 netdev_info(dev, "link %s\n",
1182 new_carrier ? "up" : "down");
1186 static void smc_eph_interrupt(struct net_device *dev)
1188 struct smc_local *lp = netdev_priv(dev);
1189 void __iomem *ioaddr = lp->base;
1192 smc_10bt_check_media(dev, 0);
1194 SMC_SELECT_BANK(lp, 1);
1195 ctl = SMC_GET_CTL(lp);
1196 SMC_SET_CTL(lp, ctl & ~CTL_LE_ENABLE);
1197 SMC_SET_CTL(lp, ctl);
1198 SMC_SELECT_BANK(lp, 2);
1202 * This is the main routine of the driver, to handle the device when
1203 * it needs some attention.
1205 static irqreturn_t smc_interrupt(int irq, void *dev_id)
1207 struct net_device *dev = dev_id;
1208 struct smc_local *lp = netdev_priv(dev);
1209 void __iomem *ioaddr = lp->base;
1210 int status, mask, timeout, card_stats;
1213 DBG(3, dev, "%s\n", __func__);
1215 spin_lock(&lp->lock);
1217 /* A preamble may be used when there is a potential race
1218 * between the interruptible transmit functions and this
1220 SMC_INTERRUPT_PREAMBLE;
1222 saved_pointer = SMC_GET_PTR(lp);
1223 mask = SMC_GET_INT_MASK(lp);
1224 SMC_SET_INT_MASK(lp, 0);
1226 /* set a timeout value, so I don't stay here forever */
1227 timeout = MAX_IRQ_LOOPS;
1230 status = SMC_GET_INT(lp);
1232 DBG(2, dev, "INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
1234 ({ int meminfo; SMC_SELECT_BANK(lp, 0);
1235 meminfo = SMC_GET_MIR(lp);
1236 SMC_SELECT_BANK(lp, 2); meminfo; }),
1243 if (status & IM_TX_INT) {
1244 /* do this before RX as it will free memory quickly */
1245 DBG(3, dev, "TX int\n");
1247 SMC_ACK_INT(lp, IM_TX_INT);
1248 if (THROTTLE_TX_PKTS)
1249 netif_wake_queue(dev);
1250 } else if (status & IM_RCV_INT) {
1251 DBG(3, dev, "RX irq\n");
1253 } else if (status & IM_ALLOC_INT) {
1254 DBG(3, dev, "Allocation irq\n");
1255 tasklet_hi_schedule(&lp->tx_task);
1256 mask &= ~IM_ALLOC_INT;
1257 } else if (status & IM_TX_EMPTY_INT) {
1258 DBG(3, dev, "TX empty\n");
1259 mask &= ~IM_TX_EMPTY_INT;
1262 SMC_SELECT_BANK(lp, 0);
1263 card_stats = SMC_GET_COUNTER(lp);
1264 SMC_SELECT_BANK(lp, 2);
1266 /* single collisions */
1267 dev->stats.collisions += card_stats & 0xF;
1270 /* multiple collisions */
1271 dev->stats.collisions += card_stats & 0xF;
1272 } else if (status & IM_RX_OVRN_INT) {
1273 DBG(1, dev, "RX overrun (EPH_ST 0x%04x)\n",
1274 ({ int eph_st; SMC_SELECT_BANK(lp, 0);
1275 eph_st = SMC_GET_EPH_STATUS(lp);
1276 SMC_SELECT_BANK(lp, 2); eph_st; }));
1277 SMC_ACK_INT(lp, IM_RX_OVRN_INT);
1278 dev->stats.rx_errors++;
1279 dev->stats.rx_fifo_errors++;
1280 } else if (status & IM_EPH_INT) {
1281 smc_eph_interrupt(dev);
1282 } else if (status & IM_MDINT) {
1283 SMC_ACK_INT(lp, IM_MDINT);
1284 smc_phy_interrupt(dev);
1285 } else if (status & IM_ERCV_INT) {
1286 SMC_ACK_INT(lp, IM_ERCV_INT);
1287 PRINTK(dev, "UNSUPPORTED: ERCV INTERRUPT\n");
1289 } while (--timeout);
1291 /* restore register states */
1292 SMC_SET_PTR(lp, saved_pointer);
1293 SMC_SET_INT_MASK(lp, mask);
1294 spin_unlock(&lp->lock);
1296 #ifndef CONFIG_NET_POLL_CONTROLLER
1297 if (timeout == MAX_IRQ_LOOPS)
1298 PRINTK(dev, "spurious interrupt (mask = 0x%02x)\n",
1301 DBG(3, dev, "Interrupt done (%d loops)\n",
1302 MAX_IRQ_LOOPS - timeout);
1305 * We return IRQ_HANDLED unconditionally here even if there was
1306 * nothing to do. There is a possibility that a packet might
1307 * get enqueued into the chip right after TX_EMPTY_INT is raised
1308 * but just before the CPU acknowledges the IRQ.
1309 * Better take an unneeded IRQ in some occasions than complexifying
1310 * the code for all cases.
1315 #ifdef CONFIG_NET_POLL_CONTROLLER
1317 * Polling receive - used by netconsole and other diagnostic tools
1318 * to allow network i/o with interrupts disabled.
1320 static void smc_poll_controller(struct net_device *dev)
1322 disable_irq(dev->irq);
1323 smc_interrupt(dev->irq, dev);
1324 enable_irq(dev->irq);
1328 /* Our watchdog timed out. Called by the networking layer */
1329 static void smc_timeout(struct net_device *dev)
1331 struct smc_local *lp = netdev_priv(dev);
1332 void __iomem *ioaddr = lp->base;
1333 int status, mask, eph_st, meminfo, fifo;
1335 DBG(2, dev, "%s\n", __func__);
1337 spin_lock_irq(&lp->lock);
1338 status = SMC_GET_INT(lp);
1339 mask = SMC_GET_INT_MASK(lp);
1340 fifo = SMC_GET_FIFO(lp);
1341 SMC_SELECT_BANK(lp, 0);
1342 eph_st = SMC_GET_EPH_STATUS(lp);
1343 meminfo = SMC_GET_MIR(lp);
1344 SMC_SELECT_BANK(lp, 2);
1345 spin_unlock_irq(&lp->lock);
1346 PRINTK(dev, "TX timeout (INT 0x%02x INTMASK 0x%02x MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n",
1347 status, mask, meminfo, fifo, eph_st);
1353 * Reconfiguring the PHY doesn't seem like a bad idea here, but
1354 * smc_phy_configure() calls msleep() which calls schedule_timeout()
1355 * which calls schedule(). Hence we use a work queue.
1357 if (lp->phy_type != 0)
1358 schedule_work(&lp->phy_configure);
1360 /* We can accept TX packets again */
1361 dev->trans_start = jiffies; /* prevent tx timeout */
1362 netif_wake_queue(dev);
1366 * This routine will, depending on the values passed to it,
1367 * either make it accept multicast packets, go into
1368 * promiscuous mode (for TCPDUMP and cousins) or accept
1369 * a select set of multicast packets
1371 static void smc_set_multicast_list(struct net_device *dev)
1373 struct smc_local *lp = netdev_priv(dev);
1374 void __iomem *ioaddr = lp->base;
1375 unsigned char multicast_table[8];
1376 int update_multicast = 0;
1378 DBG(2, dev, "%s\n", __func__);
1380 if (dev->flags & IFF_PROMISC) {
1381 DBG(2, dev, "RCR_PRMS\n");
1382 lp->rcr_cur_mode |= RCR_PRMS;
1385 /* BUG? I never disable promiscuous mode if multicasting was turned on.
1386 Now, I turn off promiscuous mode, but I don't do anything to multicasting
1387 when promiscuous mode is turned on.
1391 * Here, I am setting this to accept all multicast packets.
1392 * I don't need to zero the multicast table, because the flag is
1393 * checked before the table is
1395 else if (dev->flags & IFF_ALLMULTI || netdev_mc_count(dev) > 16) {
1396 DBG(2, dev, "RCR_ALMUL\n");
1397 lp->rcr_cur_mode |= RCR_ALMUL;
1401 * This sets the internal hardware table to filter out unwanted
1402 * multicast packets before they take up memory.
1404 * The SMC chip uses a hash table where the high 6 bits of the CRC of
1405 * address are the offset into the table. If that bit is 1, then the
1406 * multicast packet is accepted. Otherwise, it's dropped silently.
1408 * To use the 6 bits as an offset into the table, the high 3 bits are
1409 * the number of the 8 bit register, while the low 3 bits are the bit
1410 * within that register.
1412 else if (!netdev_mc_empty(dev)) {
1413 struct netdev_hw_addr *ha;
1415 /* table for flipping the order of 3 bits */
1416 static const unsigned char invert3[] = {0, 4, 2, 6, 1, 5, 3, 7};
1418 /* start with a table of all zeros: reject all */
1419 memset(multicast_table, 0, sizeof(multicast_table));
1421 netdev_for_each_mc_addr(ha, dev) {
1424 /* only use the low order bits */
1425 position = crc32_le(~0, ha->addr, 6) & 0x3f;
1427 /* do some messy swapping to put the bit in the right spot */
1428 multicast_table[invert3[position&7]] |=
1429 (1<<invert3[(position>>3)&7]);
1432 /* be sure I get rid of flags I might have set */
1433 lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
1435 /* now, the table can be loaded into the chipset */
1436 update_multicast = 1;
1438 DBG(2, dev, "~(RCR_PRMS|RCR_ALMUL)\n");
1439 lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
1442 * since I'm disabling all multicast entirely, I need to
1443 * clear the multicast list
1445 memset(multicast_table, 0, sizeof(multicast_table));
1446 update_multicast = 1;
1449 spin_lock_irq(&lp->lock);
1450 SMC_SELECT_BANK(lp, 0);
1451 SMC_SET_RCR(lp, lp->rcr_cur_mode);
1452 if (update_multicast) {
1453 SMC_SELECT_BANK(lp, 3);
1454 SMC_SET_MCAST(lp, multicast_table);
1456 SMC_SELECT_BANK(lp, 2);
1457 spin_unlock_irq(&lp->lock);
1462 * Open and Initialize the board
1464 * Set up everything, reset the card, etc..
1467 smc_open(struct net_device *dev)
1469 struct smc_local *lp = netdev_priv(dev);
1471 DBG(2, dev, "%s\n", __func__);
1473 /* Setup the default Register Modes */
1474 lp->tcr_cur_mode = TCR_DEFAULT;
1475 lp->rcr_cur_mode = RCR_DEFAULT;
1476 lp->rpc_cur_mode = RPC_DEFAULT |
1477 lp->cfg.leda << RPC_LSXA_SHFT |
1478 lp->cfg.ledb << RPC_LSXB_SHFT;
1481 * If we are not using a MII interface, we need to
1482 * monitor our own carrier signal to detect faults.
1484 if (lp->phy_type == 0)
1485 lp->tcr_cur_mode |= TCR_MON_CSN;
1487 /* reset the hardware */
1491 /* Configure the PHY, initialize the link state */
1492 if (lp->phy_type != 0)
1493 smc_phy_configure(&lp->phy_configure);
1495 spin_lock_irq(&lp->lock);
1496 smc_10bt_check_media(dev, 1);
1497 spin_unlock_irq(&lp->lock);
1500 netif_start_queue(dev);
1507 * this makes the board clean up everything that it can
1508 * and not talk to the outside world. Caused by
1509 * an 'ifconfig ethX down'
1511 static int smc_close(struct net_device *dev)
1513 struct smc_local *lp = netdev_priv(dev);
1515 DBG(2, dev, "%s\n", __func__);
1517 netif_stop_queue(dev);
1518 netif_carrier_off(dev);
1520 /* clear everything */
1522 tasklet_kill(&lp->tx_task);
1523 smc_phy_powerdown(dev);
1531 smc_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1533 struct smc_local *lp = netdev_priv(dev);
1539 if (lp->phy_type != 0) {
1540 spin_lock_irq(&lp->lock);
1541 ret = mii_ethtool_gset(&lp->mii, cmd);
1542 spin_unlock_irq(&lp->lock);
1544 cmd->supported = SUPPORTED_10baseT_Half |
1545 SUPPORTED_10baseT_Full |
1546 SUPPORTED_TP | SUPPORTED_AUI;
1548 if (lp->ctl_rspeed == 10)
1549 ethtool_cmd_speed_set(cmd, SPEED_10);
1550 else if (lp->ctl_rspeed == 100)
1551 ethtool_cmd_speed_set(cmd, SPEED_100);
1553 cmd->autoneg = AUTONEG_DISABLE;
1554 cmd->transceiver = XCVR_INTERNAL;
1556 cmd->duplex = lp->tcr_cur_mode & TCR_SWFDUP ? DUPLEX_FULL : DUPLEX_HALF;
1565 smc_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
1567 struct smc_local *lp = netdev_priv(dev);
1570 if (lp->phy_type != 0) {
1571 spin_lock_irq(&lp->lock);
1572 ret = mii_ethtool_sset(&lp->mii, cmd);
1573 spin_unlock_irq(&lp->lock);
1575 if (cmd->autoneg != AUTONEG_DISABLE ||
1576 cmd->speed != SPEED_10 ||
1577 (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) ||
1578 (cmd->port != PORT_TP && cmd->port != PORT_AUI))
1581 // lp->port = cmd->port;
1582 lp->ctl_rfduplx = cmd->duplex == DUPLEX_FULL;
1584 // if (netif_running(dev))
1585 // smc_set_port(dev);
1594 smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1596 strlcpy(info->driver, CARDNAME, sizeof(info->driver));
1597 strlcpy(info->version, version, sizeof(info->version));
1598 strlcpy(info->bus_info, dev_name(dev->dev.parent),
1599 sizeof(info->bus_info));
1602 static int smc_ethtool_nwayreset(struct net_device *dev)
1604 struct smc_local *lp = netdev_priv(dev);
1607 if (lp->phy_type != 0) {
1608 spin_lock_irq(&lp->lock);
1609 ret = mii_nway_restart(&lp->mii);
1610 spin_unlock_irq(&lp->lock);
1616 static u32 smc_ethtool_getmsglevel(struct net_device *dev)
1618 struct smc_local *lp = netdev_priv(dev);
1619 return lp->msg_enable;
1622 static void smc_ethtool_setmsglevel(struct net_device *dev, u32 level)
1624 struct smc_local *lp = netdev_priv(dev);
1625 lp->msg_enable = level;
1628 static int smc_write_eeprom_word(struct net_device *dev, u16 addr, u16 word)
1631 struct smc_local *lp = netdev_priv(dev);
1632 void __iomem *ioaddr = lp->base;
1634 spin_lock_irq(&lp->lock);
1635 /* load word into GP register */
1636 SMC_SELECT_BANK(lp, 1);
1637 SMC_SET_GP(lp, word);
1638 /* set the address to put the data in EEPROM */
1639 SMC_SELECT_BANK(lp, 2);
1640 SMC_SET_PTR(lp, addr);
1641 /* tell it to write */
1642 SMC_SELECT_BANK(lp, 1);
1643 ctl = SMC_GET_CTL(lp);
1644 SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_STORE));
1645 /* wait for it to finish */
1648 } while (SMC_GET_CTL(lp) & CTL_STORE);
1650 SMC_SET_CTL(lp, ctl);
1651 SMC_SELECT_BANK(lp, 2);
1652 spin_unlock_irq(&lp->lock);
1656 static int smc_read_eeprom_word(struct net_device *dev, u16 addr, u16 *word)
1659 struct smc_local *lp = netdev_priv(dev);
1660 void __iomem *ioaddr = lp->base;
1662 spin_lock_irq(&lp->lock);
1663 /* set the EEPROM address to get the data from */
1664 SMC_SELECT_BANK(lp, 2);
1665 SMC_SET_PTR(lp, addr | PTR_READ);
1666 /* tell it to load */
1667 SMC_SELECT_BANK(lp, 1);
1668 SMC_SET_GP(lp, 0xffff); /* init to known */
1669 ctl = SMC_GET_CTL(lp);
1670 SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_RELOAD));
1671 /* wait for it to finish */
1674 } while (SMC_GET_CTL(lp) & CTL_RELOAD);
1675 /* read word from GP register */
1676 *word = SMC_GET_GP(lp);
1678 SMC_SET_CTL(lp, ctl);
1679 SMC_SELECT_BANK(lp, 2);
1680 spin_unlock_irq(&lp->lock);
1684 static int smc_ethtool_geteeprom_len(struct net_device *dev)
1689 static int smc_ethtool_geteeprom(struct net_device *dev,
1690 struct ethtool_eeprom *eeprom, u8 *data)
1695 DBG(1, dev, "Reading %d bytes at %d(0x%x)\n",
1696 eeprom->len, eeprom->offset, eeprom->offset);
1697 imax = smc_ethtool_geteeprom_len(dev);
1698 for (i = 0; i < eeprom->len; i += 2) {
1701 int offset = i + eeprom->offset;
1704 ret = smc_read_eeprom_word(dev, offset >> 1, &wbuf);
1707 DBG(2, dev, "Read 0x%x from 0x%x\n", wbuf, offset >> 1);
1708 data[i] = (wbuf >> 8) & 0xff;
1709 data[i+1] = wbuf & 0xff;
1714 static int smc_ethtool_seteeprom(struct net_device *dev,
1715 struct ethtool_eeprom *eeprom, u8 *data)
1720 DBG(1, dev, "Writing %d bytes to %d(0x%x)\n",
1721 eeprom->len, eeprom->offset, eeprom->offset);
1722 imax = smc_ethtool_geteeprom_len(dev);
1723 for (i = 0; i < eeprom->len; i += 2) {
1726 int offset = i + eeprom->offset;
1729 wbuf = (data[i] << 8) | data[i + 1];
1730 DBG(2, dev, "Writing 0x%x to 0x%x\n", wbuf, offset >> 1);
1731 ret = smc_write_eeprom_word(dev, offset >> 1, wbuf);
1739 static const struct ethtool_ops smc_ethtool_ops = {
1740 .get_settings = smc_ethtool_getsettings,
1741 .set_settings = smc_ethtool_setsettings,
1742 .get_drvinfo = smc_ethtool_getdrvinfo,
1744 .get_msglevel = smc_ethtool_getmsglevel,
1745 .set_msglevel = smc_ethtool_setmsglevel,
1746 .nway_reset = smc_ethtool_nwayreset,
1747 .get_link = ethtool_op_get_link,
1748 .get_eeprom_len = smc_ethtool_geteeprom_len,
1749 .get_eeprom = smc_ethtool_geteeprom,
1750 .set_eeprom = smc_ethtool_seteeprom,
1753 static const struct net_device_ops smc_netdev_ops = {
1754 .ndo_open = smc_open,
1755 .ndo_stop = smc_close,
1756 .ndo_start_xmit = smc_hard_start_xmit,
1757 .ndo_tx_timeout = smc_timeout,
1758 .ndo_set_rx_mode = smc_set_multicast_list,
1759 .ndo_change_mtu = eth_change_mtu,
1760 .ndo_validate_addr = eth_validate_addr,
1761 .ndo_set_mac_address = eth_mac_addr,
1762 #ifdef CONFIG_NET_POLL_CONTROLLER
1763 .ndo_poll_controller = smc_poll_controller,
1770 * This routine has a simple purpose -- make the SMC chip generate an
1771 * interrupt, so an auto-detect routine can detect it, and find the IRQ,
1774 * does this still work?
1776 * I just deleted auto_irq.c, since it was never built...
1779 static int smc_findirq(struct smc_local *lp)
1781 void __iomem *ioaddr = lp->base;
1783 unsigned long cookie;
1785 DBG(2, lp->dev, "%s: %s\n", CARDNAME, __func__);
1787 cookie = probe_irq_on();
1790 * What I try to do here is trigger an ALLOC_INT. This is done
1791 * by allocating a small chunk of memory, which will give an interrupt
1794 /* enable ALLOCation interrupts ONLY */
1795 SMC_SELECT_BANK(lp, 2);
1796 SMC_SET_INT_MASK(lp, IM_ALLOC_INT);
1799 * Allocate 512 bytes of memory. Note that the chip was just
1800 * reset so all the memory is available
1802 SMC_SET_MMU_CMD(lp, MC_ALLOC | 1);
1805 * Wait until positive that the interrupt has been generated
1810 int_status = SMC_GET_INT(lp);
1811 if (int_status & IM_ALLOC_INT)
1812 break; /* got the interrupt */
1813 } while (--timeout);
1816 * there is really nothing that I can do here if timeout fails,
1817 * as autoirq_report will return a 0 anyway, which is what I
1818 * want in this case. Plus, the clean up is needed in both
1822 /* and disable all interrupts again */
1823 SMC_SET_INT_MASK(lp, 0);
1825 /* and return what I found */
1826 return probe_irq_off(cookie);
1830 * Function: smc_probe(unsigned long ioaddr)
1833 * Tests to see if a given ioaddr points to an SMC91x chip.
1834 * Returns a 0 on success
1837 * (1) see if the high byte of BANK_SELECT is 0x33
1838 * (2) compare the ioaddr with the base register's address
1839 * (3) see if I recognize the chip ID in the appropriate register
1841 * Here I do typical initialization tasks.
1843 * o Initialize the structure if needed
1844 * o print out my vanity message if not done so already
1845 * o print out what type of hardware is detected
1846 * o print out the ethernet address
1848 * o set up my private data
1849 * o configure the dev structure with my subroutines
1850 * o actually GRAB the irq.
1853 static int smc_probe(struct net_device *dev, void __iomem *ioaddr,
1854 unsigned long irq_flags)
1856 struct smc_local *lp = netdev_priv(dev);
1858 unsigned int val, revision_register;
1859 const char *version_string;
1861 DBG(2, dev, "%s: %s\n", CARDNAME, __func__);
1863 /* First, see if the high byte is 0x33 */
1864 val = SMC_CURRENT_BANK(lp);
1865 DBG(2, dev, "%s: bank signature probe returned 0x%04x\n",
1867 if ((val & 0xFF00) != 0x3300) {
1868 if ((val & 0xFF) == 0x33) {
1870 "%s: Detected possible byte-swapped interface at IOADDR %p\n",
1878 * The above MIGHT indicate a device, but I need to write to
1879 * further test this.
1881 SMC_SELECT_BANK(lp, 0);
1882 val = SMC_CURRENT_BANK(lp);
1883 if ((val & 0xFF00) != 0x3300) {
1889 * well, we've already written once, so hopefully another
1890 * time won't hurt. This time, I need to switch the bank
1891 * register to bank 1, so I can access the base address
1894 SMC_SELECT_BANK(lp, 1);
1895 val = SMC_GET_BASE(lp);
1896 val = ((val & 0x1F00) >> 3) << SMC_IO_SHIFT;
1897 if (((unsigned long)ioaddr & (0x3e0 << SMC_IO_SHIFT)) != val) {
1898 netdev_warn(dev, "%s: IOADDR %p doesn't match configuration (%x).\n",
1899 CARDNAME, ioaddr, val);
1903 * check if the revision register is something that I
1904 * recognize. These might need to be added to later,
1905 * as future revisions could be added.
1907 SMC_SELECT_BANK(lp, 3);
1908 revision_register = SMC_GET_REV(lp);
1909 DBG(2, dev, "%s: revision = 0x%04x\n", CARDNAME, revision_register);
1910 version_string = chip_ids[ (revision_register >> 4) & 0xF];
1911 if (!version_string || (revision_register & 0xff00) != 0x3300) {
1912 /* I don't recognize this chip, so... */
1913 netdev_warn(dev, "%s: IO %p: Unrecognized revision register 0x%04x, Contact author.\n",
1914 CARDNAME, ioaddr, revision_register);
1920 /* At this point I'll assume that the chip is an SMC91x. */
1921 pr_info_once("%s\n", version);
1923 /* fill in some of the fields */
1924 dev->base_addr = (unsigned long)ioaddr;
1926 lp->version = revision_register & 0xff;
1927 spin_lock_init(&lp->lock);
1929 /* Get the MAC address */
1930 SMC_SELECT_BANK(lp, 1);
1931 SMC_GET_MAC_ADDR(lp, dev->dev_addr);
1933 /* now, reset the chip, and put it into a known state */
1937 * If dev->irq is 0, then the device has to be banged on to see
1940 * This banging doesn't always detect the IRQ, for unknown reasons.
1941 * a workaround is to reset the chip and try again.
1943 * Interestingly, the DOS packet driver *SETS* the IRQ on the card to
1944 * be what is requested on the command line. I don't do that, mostly
1945 * because the card that I have uses a non-standard method of accessing
1946 * the IRQs, and because this _should_ work in most configurations.
1948 * Specifying an IRQ is done with the assumption that the user knows
1949 * what (s)he is doing. No checking is done!!!!
1956 dev->irq = smc_findirq(lp);
1959 /* kick the card and try again */
1963 if (dev->irq == 0) {
1964 netdev_warn(dev, "Couldn't autodetect your IRQ. Use irq=xx.\n");
1968 dev->irq = irq_canonicalize(dev->irq);
1970 dev->watchdog_timeo = msecs_to_jiffies(watchdog);
1971 dev->netdev_ops = &smc_netdev_ops;
1972 dev->ethtool_ops = &smc_ethtool_ops;
1974 tasklet_init(&lp->tx_task, smc_hardware_send_pkt, (unsigned long)dev);
1975 INIT_WORK(&lp->phy_configure, smc_phy_configure);
1977 lp->mii.phy_id_mask = 0x1f;
1978 lp->mii.reg_num_mask = 0x1f;
1979 lp->mii.force_media = 0;
1980 lp->mii.full_duplex = 0;
1982 lp->mii.mdio_read = smc_phy_read;
1983 lp->mii.mdio_write = smc_phy_write;
1986 * Locate the phy, if any.
1988 if (lp->version >= (CHIP_91100 << 4))
1989 smc_phy_detect(dev);
1991 /* then shut everything down to save power */
1993 smc_phy_powerdown(dev);
1995 /* Set default parameters */
1996 lp->msg_enable = NETIF_MSG_LINK;
1997 lp->ctl_rfduplx = 0;
1998 lp->ctl_rspeed = 10;
2000 if (lp->version >= (CHIP_91100 << 4)) {
2001 lp->ctl_rfduplx = 1;
2002 lp->ctl_rspeed = 100;
2006 retval = request_irq(dev->irq, smc_interrupt, irq_flags, dev->name, dev);
2010 #ifdef CONFIG_ARCH_PXA
2011 # ifdef SMC_USE_PXA_DMA
2012 lp->cfg.flags |= SMC91X_USE_DMA;
2014 if (lp->cfg.flags & SMC91X_USE_DMA) {
2015 int dma = pxa_request_dma(dev->name, DMA_PRIO_LOW,
2016 smc_pxa_dma_irq, NULL);
2022 retval = register_netdev(dev);
2024 /* now, print out the card info, in a short format.. */
2025 netdev_info(dev, "%s (rev %d) at %p IRQ %d",
2026 version_string, revision_register & 0x0f,
2027 lp->base, dev->irq);
2029 if (dev->dma != (unsigned char)-1)
2030 pr_cont(" DMA %d", dev->dma);
2033 lp->cfg.flags & SMC91X_NOWAIT ? " [nowait]" : "",
2034 THROTTLE_TX_PKTS ? " [throttle_tx]" : "");
2036 if (!is_valid_ether_addr(dev->dev_addr)) {
2037 netdev_warn(dev, "Invalid ethernet MAC address. Please set using ifconfig\n");
2039 /* Print the Ethernet address */
2040 netdev_info(dev, "Ethernet addr: %pM\n",
2044 if (lp->phy_type == 0) {
2045 PRINTK(dev, "No PHY found\n");
2046 } else if ((lp->phy_type & 0xfffffff0) == 0x0016f840) {
2047 PRINTK(dev, "PHY LAN83C183 (LAN91C111 Internal)\n");
2048 } else if ((lp->phy_type & 0xfffffff0) == 0x02821c50) {
2049 PRINTK(dev, "PHY LAN83C180\n");
2054 #ifdef CONFIG_ARCH_PXA
2055 if (retval && dev->dma != (unsigned char)-1)
2056 pxa_free_dma(dev->dma);
2061 static int smc_enable_device(struct platform_device *pdev)
2063 struct net_device *ndev = platform_get_drvdata(pdev);
2064 struct smc_local *lp = netdev_priv(ndev);
2065 unsigned long flags;
2066 unsigned char ecor, ecsr;
2068 struct resource * res;
2070 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2075 * Map the attribute space. This is overkill, but clean.
2077 addr = ioremap(res->start, ATTRIB_SIZE);
2082 * Reset the device. We must disable IRQs around this
2083 * since a reset causes the IRQ line become active.
2085 local_irq_save(flags);
2086 ecor = readb(addr + (ECOR << SMC_IO_SHIFT)) & ~ECOR_RESET;
2087 writeb(ecor | ECOR_RESET, addr + (ECOR << SMC_IO_SHIFT));
2088 readb(addr + (ECOR << SMC_IO_SHIFT));
2091 * Wait 100us for the chip to reset.
2096 * The device will ignore all writes to the enable bit while
2097 * reset is asserted, even if the reset bit is cleared in the
2098 * same write. Must clear reset first, then enable the device.
2100 writeb(ecor, addr + (ECOR << SMC_IO_SHIFT));
2101 writeb(ecor | ECOR_ENABLE, addr + (ECOR << SMC_IO_SHIFT));
2104 * Set the appropriate byte/word mode.
2106 ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8;
2109 writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT));
2110 local_irq_restore(flags);
2115 * Wait for the chip to wake up. We could poll the control
2116 * register in the main register space, but that isn't mapped
2117 * yet. We know this is going to take 750us.
2124 static int smc_request_attrib(struct platform_device *pdev,
2125 struct net_device *ndev)
2127 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2128 struct smc_local *lp __maybe_unused = netdev_priv(ndev);
2133 if (!request_mem_region(res->start, ATTRIB_SIZE, CARDNAME))
2139 static void smc_release_attrib(struct platform_device *pdev,
2140 struct net_device *ndev)
2142 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2143 struct smc_local *lp __maybe_unused = netdev_priv(ndev);
2146 release_mem_region(res->start, ATTRIB_SIZE);
2149 static inline void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev)
2151 if (SMC_CAN_USE_DATACS) {
2152 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2153 struct smc_local *lp = netdev_priv(ndev);
2158 if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) {
2159 netdev_info(ndev, "%s: failed to request datacs memory region.\n",
2164 lp->datacs = ioremap(res->start, SMC_DATA_EXTENT);
2168 static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev)
2170 if (SMC_CAN_USE_DATACS) {
2171 struct smc_local *lp = netdev_priv(ndev);
2172 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2175 iounmap(lp->datacs);
2180 release_mem_region(res->start, SMC_DATA_EXTENT);
2184 #if IS_BUILTIN(CONFIG_OF)
2185 static const struct of_device_id smc91x_match[] = {
2186 { .compatible = "smsc,lan91c94", },
2187 { .compatible = "smsc,lan91c111", },
2190 MODULE_DEVICE_TABLE(of, smc91x_match);
2196 * dev->base_addr == 0, try to find all possible locations
2197 * dev->base_addr > 0x1ff, this is the address to check
2198 * dev->base_addr == <anything else>, return failure code
2201 * 0 --> there is a device
2202 * anything else, error
2204 static int smc_drv_probe(struct platform_device *pdev)
2206 struct smc91x_platdata *pd = dev_get_platdata(&pdev->dev);
2207 const struct of_device_id *match = NULL;
2208 struct smc_local *lp;
2209 struct net_device *ndev;
2210 struct resource *res, *ires;
2211 unsigned int __iomem *addr;
2212 unsigned long irq_flags = SMC_IRQ_FLAGS;
2215 ndev = alloc_etherdev(sizeof(struct smc_local));
2220 SET_NETDEV_DEV(ndev, &pdev->dev);
2222 /* get configuration from platform data, only allow use of
2223 * bus width if both SMC_CAN_USE_xxx and SMC91X_USE_xxx are set.
2226 lp = netdev_priv(ndev);
2230 memcpy(&lp->cfg, pd, sizeof(lp->cfg));
2231 lp->io_shift = SMC91X_IO_SHIFT(lp->cfg.flags);
2234 #if IS_BUILTIN(CONFIG_OF)
2235 match = of_match_device(of_match_ptr(smc91x_match), &pdev->dev);
2237 struct device_node *np = pdev->dev.of_node;
2240 /* Combination of IO widths supported, default to 16-bit */
2241 if (!of_property_read_u32(np, "reg-io-width", &val)) {
2243 lp->cfg.flags |= SMC91X_USE_8BIT;
2244 if ((val == 0) || (val & 2))
2245 lp->cfg.flags |= SMC91X_USE_16BIT;
2247 lp->cfg.flags |= SMC91X_USE_32BIT;
2249 lp->cfg.flags |= SMC91X_USE_16BIT;
2254 if (!pd && !match) {
2255 lp->cfg.flags |= (SMC_CAN_USE_8BIT) ? SMC91X_USE_8BIT : 0;
2256 lp->cfg.flags |= (SMC_CAN_USE_16BIT) ? SMC91X_USE_16BIT : 0;
2257 lp->cfg.flags |= (SMC_CAN_USE_32BIT) ? SMC91X_USE_32BIT : 0;
2258 lp->cfg.flags |= (nowait) ? SMC91X_NOWAIT : 0;
2261 if (!lp->cfg.leda && !lp->cfg.ledb) {
2262 lp->cfg.leda = RPC_LSA_DEFAULT;
2263 lp->cfg.ledb = RPC_LSB_DEFAULT;
2266 ndev->dma = (unsigned char)-1;
2268 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2270 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2273 goto out_free_netdev;
2277 if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) {
2279 goto out_free_netdev;
2282 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2285 goto out_release_io;
2288 ndev->irq = ires->start;
2290 if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK)
2291 irq_flags = ires->flags & IRQF_TRIGGER_MASK;
2293 ret = smc_request_attrib(pdev, ndev);
2295 goto out_release_io;
2296 #if defined(CONFIG_SA1100_ASSABET)
2297 neponset_ncr_set(NCR_ENET_OSC_EN);
2299 platform_set_drvdata(pdev, ndev);
2300 ret = smc_enable_device(pdev);
2302 goto out_release_attrib;
2304 addr = ioremap(res->start, SMC_IO_EXTENT);
2307 goto out_release_attrib;
2310 #ifdef CONFIG_ARCH_PXA
2312 struct smc_local *lp = netdev_priv(ndev);
2313 lp->device = &pdev->dev;
2314 lp->physaddr = res->start;
2318 ret = smc_probe(ndev, addr, irq_flags);
2322 smc_request_datacs(pdev, ndev);
2329 smc_release_attrib(pdev, ndev);
2331 release_mem_region(res->start, SMC_IO_EXTENT);
2335 pr_info("%s: not found (%d).\n", CARDNAME, ret);
2340 static int smc_drv_remove(struct platform_device *pdev)
2342 struct net_device *ndev = platform_get_drvdata(pdev);
2343 struct smc_local *lp = netdev_priv(ndev);
2344 struct resource *res;
2346 unregister_netdev(ndev);
2348 free_irq(ndev->irq, ndev);
2350 #ifdef CONFIG_ARCH_PXA
2351 if (ndev->dma != (unsigned char)-1)
2352 pxa_free_dma(ndev->dma);
2356 smc_release_datacs(pdev,ndev);
2357 smc_release_attrib(pdev,ndev);
2359 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2361 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2362 release_mem_region(res->start, SMC_IO_EXTENT);
2369 static int smc_drv_suspend(struct device *dev)
2371 struct platform_device *pdev = to_platform_device(dev);
2372 struct net_device *ndev = platform_get_drvdata(pdev);
2375 if (netif_running(ndev)) {
2376 netif_device_detach(ndev);
2378 smc_phy_powerdown(ndev);
2384 static int smc_drv_resume(struct device *dev)
2386 struct platform_device *pdev = to_platform_device(dev);
2387 struct net_device *ndev = platform_get_drvdata(pdev);
2390 struct smc_local *lp = netdev_priv(ndev);
2391 smc_enable_device(pdev);
2392 if (netif_running(ndev)) {
2395 if (lp->phy_type != 0)
2396 smc_phy_configure(&lp->phy_configure);
2397 netif_device_attach(ndev);
2403 static struct dev_pm_ops smc_drv_pm_ops = {
2404 .suspend = smc_drv_suspend,
2405 .resume = smc_drv_resume,
2408 static struct platform_driver smc_driver = {
2409 .probe = smc_drv_probe,
2410 .remove = smc_drv_remove,
2413 .owner = THIS_MODULE,
2414 .pm = &smc_drv_pm_ops,
2415 .of_match_table = of_match_ptr(smc91x_match),
2419 module_platform_driver(smc_driver);