1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59static const char version[] =
60 "smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@fluxnic.net>";
61
62
63#ifndef SMC_DEBUG
64#define SMC_DEBUG 0
65#endif
66
67
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>
82#include <linux/of.h>
83#include <linux/of_device.h>
84#include <linux/of_gpio.h>
85
86#include <linux/netdevice.h>
87#include <linux/etherdevice.h>
88#include <linux/skbuff.h>
89
90#include <asm/io.h>
91
92#include "smc91x.h"
93
94#if defined(CONFIG_ASSABET_NEPONSET)
95#include <mach/assabet.h>
96#include <mach/neponset.h>
97#endif
98
99#ifndef SMC_NOWAIT
100# define SMC_NOWAIT 0
101#endif
102static int nowait = SMC_NOWAIT;
103module_param(nowait, int, 0400);
104MODULE_PARM_DESC(nowait, "set to 1 for no wait state");
105
106
107
108
109static int watchdog = 1000;
110module_param(watchdog, int, 0400);
111MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
112
113MODULE_LICENSE("GPL");
114MODULE_ALIAS("platform:smc91x");
115
116
117
118
119
120
121#define CARDNAME "smc91x"
122
123
124
125
126#define POWER_DOWN 1
127
128
129
130
131
132
133#define MEMORY_WAIT_TIME 16
134
135
136
137
138
139#define MAX_IRQ_LOOPS 8
140
141
142
143
144
145
146
147
148#define THROTTLE_TX_PKTS 0
149
150
151
152
153
154#define MII_DELAY 1
155
156#define DBG(n, dev, fmt, ...) \
157 do { \
158 if (SMC_DEBUG >= (n)) \
159 netdev_dbg(dev, fmt, ##__VA_ARGS__); \
160 } while (0)
161
162#define PRINTK(dev, fmt, ...) \
163 do { \
164 if (SMC_DEBUG > 0) \
165 netdev_info(dev, fmt, ##__VA_ARGS__); \
166 else \
167 netdev_dbg(dev, fmt, ##__VA_ARGS__); \
168 } while (0)
169
170#if SMC_DEBUG > 3
171static void PRINT_PKT(u_char *buf, int length)
172{
173 int i;
174 int remainder;
175 int lines;
176
177 lines = length / 16;
178 remainder = length % 16;
179
180 for (i = 0; i < lines ; i ++) {
181 int cur;
182 printk(KERN_DEBUG);
183 for (cur = 0; cur < 8; cur++) {
184 u_char a, b;
185 a = *buf++;
186 b = *buf++;
187 pr_cont("%02x%02x ", a, b);
188 }
189 pr_cont("\n");
190 }
191 printk(KERN_DEBUG);
192 for (i = 0; i < remainder/2 ; i++) {
193 u_char a, b;
194 a = *buf++;
195 b = *buf++;
196 pr_cont("%02x%02x ", a, b);
197 }
198 pr_cont("\n");
199}
200#else
201static inline void PRINT_PKT(u_char *buf, int length) { }
202#endif
203
204
205
206#define SMC_ENABLE_INT(lp, x) do { \
207 unsigned char mask; \
208 unsigned long smc_enable_flags; \
209 spin_lock_irqsave(&lp->lock, smc_enable_flags); \
210 mask = SMC_GET_INT_MASK(lp); \
211 mask |= (x); \
212 SMC_SET_INT_MASK(lp, mask); \
213 spin_unlock_irqrestore(&lp->lock, smc_enable_flags); \
214} while (0)
215
216
217#define SMC_DISABLE_INT(lp, x) do { \
218 unsigned char mask; \
219 unsigned long smc_disable_flags; \
220 spin_lock_irqsave(&lp->lock, smc_disable_flags); \
221 mask = SMC_GET_INT_MASK(lp); \
222 mask &= ~(x); \
223 SMC_SET_INT_MASK(lp, mask); \
224 spin_unlock_irqrestore(&lp->lock, smc_disable_flags); \
225} while (0)
226
227
228
229
230
231
232#define SMC_WAIT_MMU_BUSY(lp) do { \
233 if (unlikely(SMC_GET_MMU_CMD(lp) & MC_BUSY)) { \
234 unsigned long timeout = jiffies + 2; \
235 while (SMC_GET_MMU_CMD(lp) & MC_BUSY) { \
236 if (time_after(jiffies, timeout)) { \
237 netdev_dbg(dev, "timeout %s line %d\n", \
238 __FILE__, __LINE__); \
239 break; \
240 } \
241 cpu_relax(); \
242 } \
243 } \
244} while (0)
245
246
247
248
249
250static void smc_reset(struct net_device *dev)
251{
252 struct smc_local *lp = netdev_priv(dev);
253 void __iomem *ioaddr = lp->base;
254 unsigned int ctl, cfg;
255 struct sk_buff *pending_skb;
256
257 DBG(2, dev, "%s\n", __func__);
258
259
260 spin_lock_irq(&lp->lock);
261 SMC_SELECT_BANK(lp, 2);
262 SMC_SET_INT_MASK(lp, 0);
263 pending_skb = lp->pending_tx_skb;
264 lp->pending_tx_skb = NULL;
265 spin_unlock_irq(&lp->lock);
266
267
268 if (pending_skb) {
269 dev_kfree_skb(pending_skb);
270 dev->stats.tx_errors++;
271 dev->stats.tx_aborted_errors++;
272 }
273
274
275
276
277
278 SMC_SELECT_BANK(lp, 0);
279 SMC_SET_RCR(lp, RCR_SOFTRST);
280
281
282
283
284
285
286 SMC_SELECT_BANK(lp, 1);
287
288 cfg = CONFIG_DEFAULT;
289
290
291
292
293
294
295 if (lp->cfg.flags & SMC91X_NOWAIT)
296 cfg |= CONFIG_NO_WAIT;
297
298
299
300
301
302 cfg |= CONFIG_EPH_POWER_EN;
303
304 SMC_SET_CONFIG(lp, cfg);
305
306
307
308
309
310
311
312
313
314 udelay(1);
315
316
317 SMC_SELECT_BANK(lp, 0);
318 SMC_SET_RCR(lp, RCR_CLEAR);
319 SMC_SET_TCR(lp, TCR_CLEAR);
320
321 SMC_SELECT_BANK(lp, 1);
322 ctl = SMC_GET_CTL(lp) | CTL_LE_ENABLE;
323
324
325
326
327
328
329 if(!THROTTLE_TX_PKTS)
330 ctl |= CTL_AUTO_RELEASE;
331 else
332 ctl &= ~CTL_AUTO_RELEASE;
333 SMC_SET_CTL(lp, ctl);
334
335
336 SMC_SELECT_BANK(lp, 2);
337 SMC_SET_MMU_CMD(lp, MC_RESET);
338 SMC_WAIT_MMU_BUSY(lp);
339}
340
341
342
343
344static void smc_enable(struct net_device *dev)
345{
346 struct smc_local *lp = netdev_priv(dev);
347 void __iomem *ioaddr = lp->base;
348 int mask;
349
350 DBG(2, dev, "%s\n", __func__);
351
352
353 SMC_SELECT_BANK(lp, 0);
354 SMC_SET_TCR(lp, lp->tcr_cur_mode);
355 SMC_SET_RCR(lp, lp->rcr_cur_mode);
356
357 SMC_SELECT_BANK(lp, 1);
358 SMC_SET_MAC_ADDR(lp, dev->dev_addr);
359
360
361 mask = IM_EPH_INT|IM_RX_OVRN_INT|IM_RCV_INT;
362 if (lp->version >= (CHIP_91100 << 4))
363 mask |= IM_MDINT;
364 SMC_SELECT_BANK(lp, 2);
365 SMC_SET_INT_MASK(lp, mask);
366
367
368
369
370
371
372
373}
374
375
376
377
378static void smc_shutdown(struct net_device *dev)
379{
380 struct smc_local *lp = netdev_priv(dev);
381 void __iomem *ioaddr = lp->base;
382 struct sk_buff *pending_skb;
383
384 DBG(2, dev, "%s: %s\n", CARDNAME, __func__);
385
386
387 spin_lock_irq(&lp->lock);
388 SMC_SELECT_BANK(lp, 2);
389 SMC_SET_INT_MASK(lp, 0);
390 pending_skb = lp->pending_tx_skb;
391 lp->pending_tx_skb = NULL;
392 spin_unlock_irq(&lp->lock);
393 if (pending_skb)
394 dev_kfree_skb(pending_skb);
395
396
397 SMC_SELECT_BANK(lp, 0);
398 SMC_SET_RCR(lp, RCR_CLEAR);
399 SMC_SET_TCR(lp, TCR_CLEAR);
400
401#ifdef POWER_DOWN
402
403 SMC_SELECT_BANK(lp, 1);
404 SMC_SET_CONFIG(lp, SMC_GET_CONFIG(lp) & ~CONFIG_EPH_POWER_EN);
405#endif
406}
407
408
409
410
411static inline void smc_rcv(struct net_device *dev)
412{
413 struct smc_local *lp = netdev_priv(dev);
414 void __iomem *ioaddr = lp->base;
415 unsigned int packet_number, status, packet_len;
416
417 DBG(3, dev, "%s\n", __func__);
418
419 packet_number = SMC_GET_RXFIFO(lp);
420 if (unlikely(packet_number & RXFIFO_REMPTY)) {
421 PRINTK(dev, "smc_rcv with nothing on FIFO.\n");
422 return;
423 }
424
425
426 SMC_SET_PTR(lp, PTR_READ | PTR_RCV | PTR_AUTOINC);
427
428
429 SMC_GET_PKT_HDR(lp, status, packet_len);
430 packet_len &= 0x07ff;
431 DBG(2, dev, "RX PNR 0x%x STATUS 0x%04x LENGTH 0x%04x (%d)\n",
432 packet_number, status, packet_len, packet_len);
433
434 back:
435 if (unlikely(packet_len < 6 || status & RS_ERRORS)) {
436 if (status & RS_TOOLONG && packet_len <= (1514 + 4 + 6)) {
437
438 status &= ~RS_TOOLONG;
439 goto back;
440 }
441 if (packet_len < 6) {
442
443 netdev_err(dev, "fubar (rxlen %u status %x\n",
444 packet_len, status);
445 status |= RS_TOOSHORT;
446 }
447 SMC_WAIT_MMU_BUSY(lp);
448 SMC_SET_MMU_CMD(lp, MC_RELEASE);
449 dev->stats.rx_errors++;
450 if (status & RS_ALGNERR)
451 dev->stats.rx_frame_errors++;
452 if (status & (RS_TOOSHORT | RS_TOOLONG))
453 dev->stats.rx_length_errors++;
454 if (status & RS_BADCRC)
455 dev->stats.rx_crc_errors++;
456 } else {
457 struct sk_buff *skb;
458 unsigned char *data;
459 unsigned int data_len;
460
461
462 if (status & RS_MULTICAST)
463 dev->stats.multicast++;
464
465
466
467
468
469
470
471
472
473 skb = netdev_alloc_skb(dev, packet_len);
474 if (unlikely(skb == NULL)) {
475 SMC_WAIT_MMU_BUSY(lp);
476 SMC_SET_MMU_CMD(lp, MC_RELEASE);
477 dev->stats.rx_dropped++;
478 return;
479 }
480
481
482 skb_reserve(skb, 2);
483
484
485 if (lp->version == 0x90)
486 status |= RS_ODDFRAME;
487
488
489
490
491
492
493 data_len = packet_len - ((status & RS_ODDFRAME) ? 5 : 6);
494 data = skb_put(skb, data_len);
495 SMC_PULL_DATA(lp, data, packet_len - 4);
496
497 SMC_WAIT_MMU_BUSY(lp);
498 SMC_SET_MMU_CMD(lp, MC_RELEASE);
499
500 PRINT_PKT(data, packet_len - 4);
501
502 skb->protocol = eth_type_trans(skb, dev);
503 netif_rx(skb);
504 dev->stats.rx_packets++;
505 dev->stats.rx_bytes += data_len;
506 }
507}
508
509#ifdef CONFIG_SMP
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531#define smc_special_trylock(lock, flags) \
532({ \
533 int __ret; \
534 local_irq_save(flags); \
535 __ret = spin_trylock(lock); \
536 if (!__ret) \
537 local_irq_restore(flags); \
538 __ret; \
539})
540#define smc_special_lock(lock, flags) spin_lock_irqsave(lock, flags)
541#define smc_special_unlock(lock, flags) spin_unlock_irqrestore(lock, flags)
542#else
543#define smc_special_trylock(lock, flags) ((void)flags, true)
544#define smc_special_lock(lock, flags) do { flags = 0; } while (0)
545#define smc_special_unlock(lock, flags) do { flags = 0; } while (0)
546#endif
547
548
549
550
551static void smc_hardware_send_pkt(unsigned long data)
552{
553 struct net_device *dev = (struct net_device *)data;
554 struct smc_local *lp = netdev_priv(dev);
555 void __iomem *ioaddr = lp->base;
556 struct sk_buff *skb;
557 unsigned int packet_no, len;
558 unsigned char *buf;
559 unsigned long flags;
560
561 DBG(3, dev, "%s\n", __func__);
562
563 if (!smc_special_trylock(&lp->lock, flags)) {
564 netif_stop_queue(dev);
565 tasklet_schedule(&lp->tx_task);
566 return;
567 }
568
569 skb = lp->pending_tx_skb;
570 if (unlikely(!skb)) {
571 smc_special_unlock(&lp->lock, flags);
572 return;
573 }
574 lp->pending_tx_skb = NULL;
575
576 packet_no = SMC_GET_AR(lp);
577 if (unlikely(packet_no & AR_FAILED)) {
578 netdev_err(dev, "Memory allocation failed.\n");
579 dev->stats.tx_errors++;
580 dev->stats.tx_fifo_errors++;
581 smc_special_unlock(&lp->lock, flags);
582 goto done;
583 }
584
585
586 SMC_SET_PN(lp, packet_no);
587 SMC_SET_PTR(lp, PTR_AUTOINC);
588
589 buf = skb->data;
590 len = skb->len;
591 DBG(2, dev, "TX PNR 0x%x LENGTH 0x%04x (%d) BUF 0x%p\n",
592 packet_no, len, len, buf);
593 PRINT_PKT(buf, len);
594
595
596
597
598
599 SMC_PUT_PKT_HDR(lp, 0, len + 6);
600
601
602 SMC_PUSH_DATA(lp, buf, len & ~1);
603
604
605 SMC_outw(lp, ((len & 1) ? (0x2000 | buf[len - 1]) : 0), ioaddr,
606 DATA_REG(lp));
607
608
609
610
611
612
613
614
615
616 if (THROTTLE_TX_PKTS)
617 netif_stop_queue(dev);
618
619
620 SMC_SET_MMU_CMD(lp, MC_ENQUEUE);
621 smc_special_unlock(&lp->lock, flags);
622
623 netif_trans_update(dev);
624 dev->stats.tx_packets++;
625 dev->stats.tx_bytes += len;
626
627 SMC_ENABLE_INT(lp, IM_TX_INT | IM_TX_EMPTY_INT);
628
629done: if (!THROTTLE_TX_PKTS)
630 netif_wake_queue(dev);
631
632 dev_consume_skb_any(skb);
633}
634
635
636
637
638
639
640
641static int smc_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
642{
643 struct smc_local *lp = netdev_priv(dev);
644 void __iomem *ioaddr = lp->base;
645 unsigned int numPages, poll_count, status;
646 unsigned long flags;
647
648 DBG(3, dev, "%s\n", __func__);
649
650 BUG_ON(lp->pending_tx_skb != NULL);
651
652
653
654
655
656
657
658
659
660
661
662
663 numPages = ((skb->len & ~1) + (6 - 1)) >> 8;
664 if (unlikely(numPages > 7)) {
665 netdev_warn(dev, "Far too big packet error.\n");
666 dev->stats.tx_errors++;
667 dev->stats.tx_dropped++;
668 dev_kfree_skb_any(skb);
669 return NETDEV_TX_OK;
670 }
671
672 smc_special_lock(&lp->lock, flags);
673
674
675 SMC_SET_MMU_CMD(lp, MC_ALLOC | numPages);
676
677
678
679
680
681 poll_count = MEMORY_WAIT_TIME;
682 do {
683 status = SMC_GET_INT(lp);
684 if (status & IM_ALLOC_INT) {
685 SMC_ACK_INT(lp, IM_ALLOC_INT);
686 break;
687 }
688 } while (--poll_count);
689
690 smc_special_unlock(&lp->lock, flags);
691
692 lp->pending_tx_skb = skb;
693 if (!poll_count) {
694
695 netif_stop_queue(dev);
696 DBG(2, dev, "TX memory allocation deferred.\n");
697 SMC_ENABLE_INT(lp, IM_ALLOC_INT);
698 } else {
699
700
701
702
703 smc_hardware_send_pkt((unsigned long)dev);
704 }
705
706 return NETDEV_TX_OK;
707}
708
709
710
711
712
713
714static void smc_tx(struct net_device *dev)
715{
716 struct smc_local *lp = netdev_priv(dev);
717 void __iomem *ioaddr = lp->base;
718 unsigned int saved_packet, packet_no, tx_status, pkt_len;
719
720 DBG(3, dev, "%s\n", __func__);
721
722
723 packet_no = SMC_GET_TXFIFO(lp);
724 if (unlikely(packet_no & TXFIFO_TEMPTY)) {
725 PRINTK(dev, "smc_tx with nothing on FIFO.\n");
726 return;
727 }
728
729
730 saved_packet = SMC_GET_PN(lp);
731 SMC_SET_PN(lp, packet_no);
732
733
734 SMC_SET_PTR(lp, PTR_AUTOINC | PTR_READ);
735 SMC_GET_PKT_HDR(lp, tx_status, pkt_len);
736 DBG(2, dev, "TX STATUS 0x%04x PNR 0x%02x\n",
737 tx_status, packet_no);
738
739 if (!(tx_status & ES_TX_SUC))
740 dev->stats.tx_errors++;
741
742 if (tx_status & ES_LOSTCARR)
743 dev->stats.tx_carrier_errors++;
744
745 if (tx_status & (ES_LATCOL | ES_16COL)) {
746 PRINTK(dev, "%s occurred on last xmit\n",
747 (tx_status & ES_LATCOL) ?
748 "late collision" : "too many collisions");
749 dev->stats.tx_window_errors++;
750 if (!(dev->stats.tx_window_errors & 63) && net_ratelimit()) {
751 netdev_info(dev, "unexpectedly large number of bad collisions. Please check duplex setting.\n");
752 }
753 }
754
755
756 SMC_WAIT_MMU_BUSY(lp);
757 SMC_SET_MMU_CMD(lp, MC_FREEPKT);
758
759
760 SMC_WAIT_MMU_BUSY(lp);
761 SMC_SET_PN(lp, saved_packet);
762
763
764 SMC_SELECT_BANK(lp, 0);
765 SMC_SET_TCR(lp, lp->tcr_cur_mode);
766 SMC_SELECT_BANK(lp, 2);
767}
768
769
770
771
772static void smc_mii_out(struct net_device *dev, unsigned int val, int bits)
773{
774 struct smc_local *lp = netdev_priv(dev);
775 void __iomem *ioaddr = lp->base;
776 unsigned int mii_reg, mask;
777
778 mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
779 mii_reg |= MII_MDOE;
780
781 for (mask = 1 << (bits - 1); mask; mask >>= 1) {
782 if (val & mask)
783 mii_reg |= MII_MDO;
784 else
785 mii_reg &= ~MII_MDO;
786
787 SMC_SET_MII(lp, mii_reg);
788 udelay(MII_DELAY);
789 SMC_SET_MII(lp, mii_reg | MII_MCLK);
790 udelay(MII_DELAY);
791 }
792}
793
794static unsigned int smc_mii_in(struct net_device *dev, int bits)
795{
796 struct smc_local *lp = netdev_priv(dev);
797 void __iomem *ioaddr = lp->base;
798 unsigned int mii_reg, mask, val;
799
800 mii_reg = SMC_GET_MII(lp) & ~(MII_MCLK | MII_MDOE | MII_MDO);
801 SMC_SET_MII(lp, mii_reg);
802
803 for (mask = 1 << (bits - 1), val = 0; mask; mask >>= 1) {
804 if (SMC_GET_MII(lp) & MII_MDI)
805 val |= mask;
806
807 SMC_SET_MII(lp, mii_reg);
808 udelay(MII_DELAY);
809 SMC_SET_MII(lp, mii_reg | MII_MCLK);
810 udelay(MII_DELAY);
811 }
812
813 return val;
814}
815
816
817
818
819static int smc_phy_read(struct net_device *dev, int phyaddr, int phyreg)
820{
821 struct smc_local *lp = netdev_priv(dev);
822 void __iomem *ioaddr = lp->base;
823 unsigned int phydata;
824
825 SMC_SELECT_BANK(lp, 3);
826
827
828 smc_mii_out(dev, 0xffffffff, 32);
829
830
831 smc_mii_out(dev, 6 << 10 | phyaddr << 5 | phyreg, 14);
832
833
834 phydata = smc_mii_in(dev, 18);
835
836
837 SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
838
839 DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
840 __func__, phyaddr, phyreg, phydata);
841
842 SMC_SELECT_BANK(lp, 2);
843 return phydata;
844}
845
846
847
848
849static void smc_phy_write(struct net_device *dev, int phyaddr, int phyreg,
850 int phydata)
851{
852 struct smc_local *lp = netdev_priv(dev);
853 void __iomem *ioaddr = lp->base;
854
855 SMC_SELECT_BANK(lp, 3);
856
857
858 smc_mii_out(dev, 0xffffffff, 32);
859
860
861 smc_mii_out(dev, 5 << 28 | phyaddr << 23 | phyreg << 18 | 2 << 16 | phydata, 32);
862
863
864 SMC_SET_MII(lp, SMC_GET_MII(lp) & ~(MII_MCLK|MII_MDOE|MII_MDO));
865
866 DBG(3, dev, "%s: phyaddr=0x%x, phyreg=0x%x, phydata=0x%x\n",
867 __func__, phyaddr, phyreg, phydata);
868
869 SMC_SELECT_BANK(lp, 2);
870}
871
872
873
874
875static void smc_phy_detect(struct net_device *dev)
876{
877 struct smc_local *lp = netdev_priv(dev);
878 int phyaddr;
879
880 DBG(2, dev, "%s\n", __func__);
881
882 lp->phy_type = 0;
883
884
885
886
887
888 for (phyaddr = 1; phyaddr < 33; ++phyaddr) {
889 unsigned int id1, id2;
890
891
892 id1 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID1);
893 id2 = smc_phy_read(dev, phyaddr & 31, MII_PHYSID2);
894
895 DBG(3, dev, "phy_id1=0x%x, phy_id2=0x%x\n",
896 id1, id2);
897
898
899 if (id1 != 0x0000 && id1 != 0xffff && id1 != 0x8000 &&
900 id2 != 0x0000 && id2 != 0xffff && id2 != 0x8000) {
901
902 lp->mii.phy_id = phyaddr & 31;
903 lp->phy_type = id1 << 16 | id2;
904 break;
905 }
906 }
907}
908
909
910
911
912static int smc_phy_fixed(struct net_device *dev)
913{
914 struct smc_local *lp = netdev_priv(dev);
915 void __iomem *ioaddr = lp->base;
916 int phyaddr = lp->mii.phy_id;
917 int bmcr, cfg1;
918
919 DBG(3, dev, "%s\n", __func__);
920
921
922 cfg1 = smc_phy_read(dev, phyaddr, PHY_CFG1_REG);
923 cfg1 |= PHY_CFG1_LNKDIS;
924 smc_phy_write(dev, phyaddr, PHY_CFG1_REG, cfg1);
925
926
927
928
929
930 bmcr = 0;
931
932 if (lp->ctl_rfduplx)
933 bmcr |= BMCR_FULLDPLX;
934
935 if (lp->ctl_rspeed == 100)
936 bmcr |= BMCR_SPEED100;
937
938
939 smc_phy_write(dev, phyaddr, MII_BMCR, bmcr);
940
941
942 SMC_SELECT_BANK(lp, 0);
943 SMC_SET_RPC(lp, lp->rpc_cur_mode);
944 SMC_SELECT_BANK(lp, 2);
945
946 return 1;
947}
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962static int smc_phy_reset(struct net_device *dev, int phy)
963{
964 struct smc_local *lp = netdev_priv(dev);
965 unsigned int bmcr;
966 int timeout;
967
968 smc_phy_write(dev, phy, MII_BMCR, BMCR_RESET);
969
970 for (timeout = 2; timeout; timeout--) {
971 spin_unlock_irq(&lp->lock);
972 msleep(50);
973 spin_lock_irq(&lp->lock);
974
975 bmcr = smc_phy_read(dev, phy, MII_BMCR);
976 if (!(bmcr & BMCR_RESET))
977 break;
978 }
979
980 return bmcr & BMCR_RESET;
981}
982
983
984
985
986
987
988
989static void smc_phy_powerdown(struct net_device *dev)
990{
991 struct smc_local *lp = netdev_priv(dev);
992 unsigned int bmcr;
993 int phy = lp->mii.phy_id;
994
995 if (lp->phy_type == 0)
996 return;
997
998
999
1000
1001 cancel_work_sync(&lp->phy_configure);
1002
1003 bmcr = smc_phy_read(dev, phy, MII_BMCR);
1004 smc_phy_write(dev, phy, MII_BMCR, bmcr | BMCR_PDOWN);
1005}
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015static void smc_phy_check_media(struct net_device *dev, int init)
1016{
1017 struct smc_local *lp = netdev_priv(dev);
1018 void __iomem *ioaddr = lp->base;
1019
1020 if (mii_check_media(&lp->mii, netif_msg_link(lp), init)) {
1021
1022 if (lp->mii.full_duplex) {
1023 lp->tcr_cur_mode |= TCR_SWFDUP;
1024 } else {
1025 lp->tcr_cur_mode &= ~TCR_SWFDUP;
1026 }
1027
1028 SMC_SELECT_BANK(lp, 0);
1029 SMC_SET_TCR(lp, lp->tcr_cur_mode);
1030 }
1031}
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042static void smc_phy_configure(struct work_struct *work)
1043{
1044 struct smc_local *lp =
1045 container_of(work, struct smc_local, phy_configure);
1046 struct net_device *dev = lp->dev;
1047 void __iomem *ioaddr = lp->base;
1048 int phyaddr = lp->mii.phy_id;
1049 int my_phy_caps;
1050 int my_ad_caps;
1051 int status;
1052
1053 DBG(3, dev, "smc_program_phy()\n");
1054
1055 spin_lock_irq(&lp->lock);
1056
1057
1058
1059
1060 if (lp->phy_type == 0)
1061 goto smc_phy_configure_exit;
1062
1063 if (smc_phy_reset(dev, phyaddr)) {
1064 netdev_info(dev, "PHY reset timed out\n");
1065 goto smc_phy_configure_exit;
1066 }
1067
1068
1069
1070
1071
1072 smc_phy_write(dev, phyaddr, PHY_MASK_REG,
1073 PHY_INT_LOSSSYNC | PHY_INT_CWRD | PHY_INT_SSD |
1074 PHY_INT_ESD | PHY_INT_RPOL | PHY_INT_JAB |
1075 PHY_INT_SPDDET | PHY_INT_DPLXDET);
1076
1077
1078 SMC_SELECT_BANK(lp, 0);
1079 SMC_SET_RPC(lp, lp->rpc_cur_mode);
1080
1081
1082 if (lp->mii.force_media) {
1083 smc_phy_fixed(dev);
1084 goto smc_phy_configure_exit;
1085 }
1086
1087
1088 my_phy_caps = smc_phy_read(dev, phyaddr, MII_BMSR);
1089
1090 if (!(my_phy_caps & BMSR_ANEGCAPABLE)) {
1091 netdev_info(dev, "Auto negotiation NOT supported\n");
1092 smc_phy_fixed(dev);
1093 goto smc_phy_configure_exit;
1094 }
1095
1096 my_ad_caps = ADVERTISE_CSMA;
1097
1098 if (my_phy_caps & BMSR_100BASE4)
1099 my_ad_caps |= ADVERTISE_100BASE4;
1100 if (my_phy_caps & BMSR_100FULL)
1101 my_ad_caps |= ADVERTISE_100FULL;
1102 if (my_phy_caps & BMSR_100HALF)
1103 my_ad_caps |= ADVERTISE_100HALF;
1104 if (my_phy_caps & BMSR_10FULL)
1105 my_ad_caps |= ADVERTISE_10FULL;
1106 if (my_phy_caps & BMSR_10HALF)
1107 my_ad_caps |= ADVERTISE_10HALF;
1108
1109
1110 if (lp->ctl_rspeed != 100)
1111 my_ad_caps &= ~(ADVERTISE_100BASE4|ADVERTISE_100FULL|ADVERTISE_100HALF);
1112
1113 if (!lp->ctl_rfduplx)
1114 my_ad_caps &= ~(ADVERTISE_100FULL|ADVERTISE_10FULL);
1115
1116
1117 smc_phy_write(dev, phyaddr, MII_ADVERTISE, my_ad_caps);
1118 lp->mii.advertising = my_ad_caps;
1119
1120
1121
1122
1123
1124
1125 status = smc_phy_read(dev, phyaddr, MII_ADVERTISE);
1126
1127 DBG(2, dev, "phy caps=%x\n", my_phy_caps);
1128 DBG(2, dev, "phy advertised caps=%x\n", my_ad_caps);
1129
1130
1131 smc_phy_write(dev, phyaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
1132
1133 smc_phy_check_media(dev, 1);
1134
1135smc_phy_configure_exit:
1136 SMC_SELECT_BANK(lp, 2);
1137 spin_unlock_irq(&lp->lock);
1138}
1139
1140
1141
1142
1143
1144
1145
1146static void smc_phy_interrupt(struct net_device *dev)
1147{
1148 struct smc_local *lp = netdev_priv(dev);
1149 int phyaddr = lp->mii.phy_id;
1150 int phy18;
1151
1152 DBG(2, dev, "%s\n", __func__);
1153
1154 if (lp->phy_type == 0)
1155 return;
1156
1157 for(;;) {
1158 smc_phy_check_media(dev, 0);
1159
1160
1161 phy18 = smc_phy_read(dev, phyaddr, PHY_INT_REG);
1162 if ((phy18 & PHY_INT_INT) == 0)
1163 break;
1164 }
1165}
1166
1167
1168
1169static void smc_10bt_check_media(struct net_device *dev, int init)
1170{
1171 struct smc_local *lp = netdev_priv(dev);
1172 void __iomem *ioaddr = lp->base;
1173 unsigned int old_carrier, new_carrier;
1174
1175 old_carrier = netif_carrier_ok(dev) ? 1 : 0;
1176
1177 SMC_SELECT_BANK(lp, 0);
1178 new_carrier = (SMC_GET_EPH_STATUS(lp) & ES_LINK_OK) ? 1 : 0;
1179 SMC_SELECT_BANK(lp, 2);
1180
1181 if (init || (old_carrier != new_carrier)) {
1182 if (!new_carrier) {
1183 netif_carrier_off(dev);
1184 } else {
1185 netif_carrier_on(dev);
1186 }
1187 if (netif_msg_link(lp))
1188 netdev_info(dev, "link %s\n",
1189 new_carrier ? "up" : "down");
1190 }
1191}
1192
1193static void smc_eph_interrupt(struct net_device *dev)
1194{
1195 struct smc_local *lp = netdev_priv(dev);
1196 void __iomem *ioaddr = lp->base;
1197 unsigned int ctl;
1198
1199 smc_10bt_check_media(dev, 0);
1200
1201 SMC_SELECT_BANK(lp, 1);
1202 ctl = SMC_GET_CTL(lp);
1203 SMC_SET_CTL(lp, ctl & ~CTL_LE_ENABLE);
1204 SMC_SET_CTL(lp, ctl);
1205 SMC_SELECT_BANK(lp, 2);
1206}
1207
1208
1209
1210
1211
1212static irqreturn_t smc_interrupt(int irq, void *dev_id)
1213{
1214 struct net_device *dev = dev_id;
1215 struct smc_local *lp = netdev_priv(dev);
1216 void __iomem *ioaddr = lp->base;
1217 int status, mask, timeout, card_stats;
1218 int saved_pointer;
1219
1220 DBG(3, dev, "%s\n", __func__);
1221
1222 spin_lock(&lp->lock);
1223
1224
1225
1226
1227 SMC_INTERRUPT_PREAMBLE;
1228
1229 saved_pointer = SMC_GET_PTR(lp);
1230 mask = SMC_GET_INT_MASK(lp);
1231 SMC_SET_INT_MASK(lp, 0);
1232
1233
1234 timeout = MAX_IRQ_LOOPS;
1235
1236 do {
1237 status = SMC_GET_INT(lp);
1238
1239 DBG(2, dev, "INT 0x%02x MASK 0x%02x MEM 0x%04x FIFO 0x%04x\n",
1240 status, mask,
1241 ({ int meminfo; SMC_SELECT_BANK(lp, 0);
1242 meminfo = SMC_GET_MIR(lp);
1243 SMC_SELECT_BANK(lp, 2); meminfo; }),
1244 SMC_GET_FIFO(lp));
1245
1246 status &= mask;
1247 if (!status)
1248 break;
1249
1250 if (status & IM_TX_INT) {
1251
1252 DBG(3, dev, "TX int\n");
1253 smc_tx(dev);
1254 SMC_ACK_INT(lp, IM_TX_INT);
1255 if (THROTTLE_TX_PKTS)
1256 netif_wake_queue(dev);
1257 } else if (status & IM_RCV_INT) {
1258 DBG(3, dev, "RX irq\n");
1259 smc_rcv(dev);
1260 } else if (status & IM_ALLOC_INT) {
1261 DBG(3, dev, "Allocation irq\n");
1262 tasklet_hi_schedule(&lp->tx_task);
1263 mask &= ~IM_ALLOC_INT;
1264 } else if (status & IM_TX_EMPTY_INT) {
1265 DBG(3, dev, "TX empty\n");
1266 mask &= ~IM_TX_EMPTY_INT;
1267
1268
1269 SMC_SELECT_BANK(lp, 0);
1270 card_stats = SMC_GET_COUNTER(lp);
1271 SMC_SELECT_BANK(lp, 2);
1272
1273
1274 dev->stats.collisions += card_stats & 0xF;
1275 card_stats >>= 4;
1276
1277
1278 dev->stats.collisions += card_stats & 0xF;
1279 } else if (status & IM_RX_OVRN_INT) {
1280 DBG(1, dev, "RX overrun (EPH_ST 0x%04x)\n",
1281 ({ int eph_st; SMC_SELECT_BANK(lp, 0);
1282 eph_st = SMC_GET_EPH_STATUS(lp);
1283 SMC_SELECT_BANK(lp, 2); eph_st; }));
1284 SMC_ACK_INT(lp, IM_RX_OVRN_INT);
1285 dev->stats.rx_errors++;
1286 dev->stats.rx_fifo_errors++;
1287 } else if (status & IM_EPH_INT) {
1288 smc_eph_interrupt(dev);
1289 } else if (status & IM_MDINT) {
1290 SMC_ACK_INT(lp, IM_MDINT);
1291 smc_phy_interrupt(dev);
1292 } else if (status & IM_ERCV_INT) {
1293 SMC_ACK_INT(lp, IM_ERCV_INT);
1294 PRINTK(dev, "UNSUPPORTED: ERCV INTERRUPT\n");
1295 }
1296 } while (--timeout);
1297
1298
1299 SMC_SET_PTR(lp, saved_pointer);
1300 SMC_SET_INT_MASK(lp, mask);
1301 spin_unlock(&lp->lock);
1302
1303#ifndef CONFIG_NET_POLL_CONTROLLER
1304 if (timeout == MAX_IRQ_LOOPS)
1305 PRINTK(dev, "spurious interrupt (mask = 0x%02x)\n",
1306 mask);
1307#endif
1308 DBG(3, dev, "Interrupt done (%d loops)\n",
1309 MAX_IRQ_LOOPS - timeout);
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319 return IRQ_HANDLED;
1320}
1321
1322#ifdef CONFIG_NET_POLL_CONTROLLER
1323
1324
1325
1326
1327static void smc_poll_controller(struct net_device *dev)
1328{
1329 disable_irq(dev->irq);
1330 smc_interrupt(dev->irq, dev);
1331 enable_irq(dev->irq);
1332}
1333#endif
1334
1335
1336static void smc_timeout(struct net_device *dev)
1337{
1338 struct smc_local *lp = netdev_priv(dev);
1339 void __iomem *ioaddr = lp->base;
1340 int status, mask, eph_st, meminfo, fifo;
1341
1342 DBG(2, dev, "%s\n", __func__);
1343
1344 spin_lock_irq(&lp->lock);
1345 status = SMC_GET_INT(lp);
1346 mask = SMC_GET_INT_MASK(lp);
1347 fifo = SMC_GET_FIFO(lp);
1348 SMC_SELECT_BANK(lp, 0);
1349 eph_st = SMC_GET_EPH_STATUS(lp);
1350 meminfo = SMC_GET_MIR(lp);
1351 SMC_SELECT_BANK(lp, 2);
1352 spin_unlock_irq(&lp->lock);
1353 PRINTK(dev, "TX timeout (INT 0x%02x INTMASK 0x%02x MEM 0x%04x FIFO 0x%04x EPH_ST 0x%04x)\n",
1354 status, mask, meminfo, fifo, eph_st);
1355
1356 smc_reset(dev);
1357 smc_enable(dev);
1358
1359
1360
1361
1362
1363
1364 if (lp->phy_type != 0)
1365 schedule_work(&lp->phy_configure);
1366
1367
1368 netif_trans_update(dev);
1369 netif_wake_queue(dev);
1370}
1371
1372
1373
1374
1375
1376
1377
1378static void smc_set_multicast_list(struct net_device *dev)
1379{
1380 struct smc_local *lp = netdev_priv(dev);
1381 void __iomem *ioaddr = lp->base;
1382 unsigned char multicast_table[8];
1383 int update_multicast = 0;
1384
1385 DBG(2, dev, "%s\n", __func__);
1386
1387 if (dev->flags & IFF_PROMISC) {
1388 DBG(2, dev, "RCR_PRMS\n");
1389 lp->rcr_cur_mode |= RCR_PRMS;
1390 }
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402 else if (dev->flags & IFF_ALLMULTI || netdev_mc_count(dev) > 16) {
1403 DBG(2, dev, "RCR_ALMUL\n");
1404 lp->rcr_cur_mode |= RCR_ALMUL;
1405 }
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419 else if (!netdev_mc_empty(dev)) {
1420 struct netdev_hw_addr *ha;
1421
1422
1423 static const unsigned char invert3[] = {0, 4, 2, 6, 1, 5, 3, 7};
1424
1425
1426 memset(multicast_table, 0, sizeof(multicast_table));
1427
1428 netdev_for_each_mc_addr(ha, dev) {
1429 int position;
1430
1431
1432 position = crc32_le(~0, ha->addr, 6) & 0x3f;
1433
1434
1435 multicast_table[invert3[position&7]] |=
1436 (1<<invert3[(position>>3)&7]);
1437 }
1438
1439
1440 lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
1441
1442
1443 update_multicast = 1;
1444 } else {
1445 DBG(2, dev, "~(RCR_PRMS|RCR_ALMUL)\n");
1446 lp->rcr_cur_mode &= ~(RCR_PRMS | RCR_ALMUL);
1447
1448
1449
1450
1451
1452 memset(multicast_table, 0, sizeof(multicast_table));
1453 update_multicast = 1;
1454 }
1455
1456 spin_lock_irq(&lp->lock);
1457 SMC_SELECT_BANK(lp, 0);
1458 SMC_SET_RCR(lp, lp->rcr_cur_mode);
1459 if (update_multicast) {
1460 SMC_SELECT_BANK(lp, 3);
1461 SMC_SET_MCAST(lp, multicast_table);
1462 }
1463 SMC_SELECT_BANK(lp, 2);
1464 spin_unlock_irq(&lp->lock);
1465}
1466
1467
1468
1469
1470
1471
1472
1473static int
1474smc_open(struct net_device *dev)
1475{
1476 struct smc_local *lp = netdev_priv(dev);
1477
1478 DBG(2, dev, "%s\n", __func__);
1479
1480
1481 lp->tcr_cur_mode = TCR_DEFAULT;
1482 lp->rcr_cur_mode = RCR_DEFAULT;
1483 lp->rpc_cur_mode = RPC_DEFAULT |
1484 lp->cfg.leda << RPC_LSXA_SHFT |
1485 lp->cfg.ledb << RPC_LSXB_SHFT;
1486
1487
1488
1489
1490
1491 if (lp->phy_type == 0)
1492 lp->tcr_cur_mode |= TCR_MON_CSN;
1493
1494
1495 smc_reset(dev);
1496 smc_enable(dev);
1497
1498
1499 if (lp->phy_type != 0)
1500 smc_phy_configure(&lp->phy_configure);
1501 else {
1502 spin_lock_irq(&lp->lock);
1503 smc_10bt_check_media(dev, 1);
1504 spin_unlock_irq(&lp->lock);
1505 }
1506
1507 netif_start_queue(dev);
1508 return 0;
1509}
1510
1511
1512
1513
1514
1515
1516
1517
1518static int smc_close(struct net_device *dev)
1519{
1520 struct smc_local *lp = netdev_priv(dev);
1521
1522 DBG(2, dev, "%s\n", __func__);
1523
1524 netif_stop_queue(dev);
1525 netif_carrier_off(dev);
1526
1527
1528 smc_shutdown(dev);
1529 tasklet_kill(&lp->tx_task);
1530 smc_phy_powerdown(dev);
1531 return 0;
1532}
1533
1534
1535
1536
1537static int
1538smc_ethtool_get_link_ksettings(struct net_device *dev,
1539 struct ethtool_link_ksettings *cmd)
1540{
1541 struct smc_local *lp = netdev_priv(dev);
1542 int ret;
1543
1544 if (lp->phy_type != 0) {
1545 spin_lock_irq(&lp->lock);
1546 ret = mii_ethtool_get_link_ksettings(&lp->mii, cmd);
1547 spin_unlock_irq(&lp->lock);
1548 } else {
1549 u32 supported = SUPPORTED_10baseT_Half |
1550 SUPPORTED_10baseT_Full |
1551 SUPPORTED_TP | SUPPORTED_AUI;
1552
1553 if (lp->ctl_rspeed == 10)
1554 cmd->base.speed = SPEED_10;
1555 else if (lp->ctl_rspeed == 100)
1556 cmd->base.speed = SPEED_100;
1557
1558 cmd->base.autoneg = AUTONEG_DISABLE;
1559 cmd->base.port = 0;
1560 cmd->base.duplex = lp->tcr_cur_mode & TCR_SWFDUP ?
1561 DUPLEX_FULL : DUPLEX_HALF;
1562
1563 ethtool_convert_legacy_u32_to_link_mode(
1564 cmd->link_modes.supported, supported);
1565
1566 ret = 0;
1567 }
1568
1569 return ret;
1570}
1571
1572static int
1573smc_ethtool_set_link_ksettings(struct net_device *dev,
1574 const struct ethtool_link_ksettings *cmd)
1575{
1576 struct smc_local *lp = netdev_priv(dev);
1577 int ret;
1578
1579 if (lp->phy_type != 0) {
1580 spin_lock_irq(&lp->lock);
1581 ret = mii_ethtool_set_link_ksettings(&lp->mii, cmd);
1582 spin_unlock_irq(&lp->lock);
1583 } else {
1584 if (cmd->base.autoneg != AUTONEG_DISABLE ||
1585 cmd->base.speed != SPEED_10 ||
1586 (cmd->base.duplex != DUPLEX_HALF &&
1587 cmd->base.duplex != DUPLEX_FULL) ||
1588 (cmd->base.port != PORT_TP && cmd->base.port != PORT_AUI))
1589 return -EINVAL;
1590
1591
1592 lp->ctl_rfduplx = cmd->base.duplex == DUPLEX_FULL;
1593
1594
1595
1596
1597 ret = 0;
1598 }
1599
1600 return ret;
1601}
1602
1603static void
1604smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1605{
1606 strlcpy(info->driver, CARDNAME, sizeof(info->driver));
1607 strlcpy(info->version, version, sizeof(info->version));
1608 strlcpy(info->bus_info, dev_name(dev->dev.parent),
1609 sizeof(info->bus_info));
1610}
1611
1612static int smc_ethtool_nwayreset(struct net_device *dev)
1613{
1614 struct smc_local *lp = netdev_priv(dev);
1615 int ret = -EINVAL;
1616
1617 if (lp->phy_type != 0) {
1618 spin_lock_irq(&lp->lock);
1619 ret = mii_nway_restart(&lp->mii);
1620 spin_unlock_irq(&lp->lock);
1621 }
1622
1623 return ret;
1624}
1625
1626static u32 smc_ethtool_getmsglevel(struct net_device *dev)
1627{
1628 struct smc_local *lp = netdev_priv(dev);
1629 return lp->msg_enable;
1630}
1631
1632static void smc_ethtool_setmsglevel(struct net_device *dev, u32 level)
1633{
1634 struct smc_local *lp = netdev_priv(dev);
1635 lp->msg_enable = level;
1636}
1637
1638static int smc_write_eeprom_word(struct net_device *dev, u16 addr, u16 word)
1639{
1640 u16 ctl;
1641 struct smc_local *lp = netdev_priv(dev);
1642 void __iomem *ioaddr = lp->base;
1643
1644 spin_lock_irq(&lp->lock);
1645
1646 SMC_SELECT_BANK(lp, 1);
1647 SMC_SET_GP(lp, word);
1648
1649 SMC_SELECT_BANK(lp, 2);
1650 SMC_SET_PTR(lp, addr);
1651
1652 SMC_SELECT_BANK(lp, 1);
1653 ctl = SMC_GET_CTL(lp);
1654 SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_STORE));
1655
1656 do {
1657 udelay(1);
1658 } while (SMC_GET_CTL(lp) & CTL_STORE);
1659
1660 SMC_SET_CTL(lp, ctl);
1661 SMC_SELECT_BANK(lp, 2);
1662 spin_unlock_irq(&lp->lock);
1663 return 0;
1664}
1665
1666static int smc_read_eeprom_word(struct net_device *dev, u16 addr, u16 *word)
1667{
1668 u16 ctl;
1669 struct smc_local *lp = netdev_priv(dev);
1670 void __iomem *ioaddr = lp->base;
1671
1672 spin_lock_irq(&lp->lock);
1673
1674 SMC_SELECT_BANK(lp, 2);
1675 SMC_SET_PTR(lp, addr | PTR_READ);
1676
1677 SMC_SELECT_BANK(lp, 1);
1678 SMC_SET_GP(lp, 0xffff);
1679 ctl = SMC_GET_CTL(lp);
1680 SMC_SET_CTL(lp, ctl | (CTL_EEPROM_SELECT | CTL_RELOAD));
1681
1682 do {
1683 udelay(1);
1684 } while (SMC_GET_CTL(lp) & CTL_RELOAD);
1685
1686 *word = SMC_GET_GP(lp);
1687
1688 SMC_SET_CTL(lp, ctl);
1689 SMC_SELECT_BANK(lp, 2);
1690 spin_unlock_irq(&lp->lock);
1691 return 0;
1692}
1693
1694static int smc_ethtool_geteeprom_len(struct net_device *dev)
1695{
1696 return 0x23 * 2;
1697}
1698
1699static int smc_ethtool_geteeprom(struct net_device *dev,
1700 struct ethtool_eeprom *eeprom, u8 *data)
1701{
1702 int i;
1703 int imax;
1704
1705 DBG(1, dev, "Reading %d bytes at %d(0x%x)\n",
1706 eeprom->len, eeprom->offset, eeprom->offset);
1707 imax = smc_ethtool_geteeprom_len(dev);
1708 for (i = 0; i < eeprom->len; i += 2) {
1709 int ret;
1710 u16 wbuf;
1711 int offset = i + eeprom->offset;
1712 if (offset > imax)
1713 break;
1714 ret = smc_read_eeprom_word(dev, offset >> 1, &wbuf);
1715 if (ret != 0)
1716 return ret;
1717 DBG(2, dev, "Read 0x%x from 0x%x\n", wbuf, offset >> 1);
1718 data[i] = (wbuf >> 8) & 0xff;
1719 data[i+1] = wbuf & 0xff;
1720 }
1721 return 0;
1722}
1723
1724static int smc_ethtool_seteeprom(struct net_device *dev,
1725 struct ethtool_eeprom *eeprom, u8 *data)
1726{
1727 int i;
1728 int imax;
1729
1730 DBG(1, dev, "Writing %d bytes to %d(0x%x)\n",
1731 eeprom->len, eeprom->offset, eeprom->offset);
1732 imax = smc_ethtool_geteeprom_len(dev);
1733 for (i = 0; i < eeprom->len; i += 2) {
1734 int ret;
1735 u16 wbuf;
1736 int offset = i + eeprom->offset;
1737 if (offset > imax)
1738 break;
1739 wbuf = (data[i] << 8) | data[i + 1];
1740 DBG(2, dev, "Writing 0x%x to 0x%x\n", wbuf, offset >> 1);
1741 ret = smc_write_eeprom_word(dev, offset >> 1, wbuf);
1742 if (ret != 0)
1743 return ret;
1744 }
1745 return 0;
1746}
1747
1748
1749static const struct ethtool_ops smc_ethtool_ops = {
1750 .get_drvinfo = smc_ethtool_getdrvinfo,
1751
1752 .get_msglevel = smc_ethtool_getmsglevel,
1753 .set_msglevel = smc_ethtool_setmsglevel,
1754 .nway_reset = smc_ethtool_nwayreset,
1755 .get_link = ethtool_op_get_link,
1756 .get_eeprom_len = smc_ethtool_geteeprom_len,
1757 .get_eeprom = smc_ethtool_geteeprom,
1758 .set_eeprom = smc_ethtool_seteeprom,
1759 .get_link_ksettings = smc_ethtool_get_link_ksettings,
1760 .set_link_ksettings = smc_ethtool_set_link_ksettings,
1761};
1762
1763static const struct net_device_ops smc_netdev_ops = {
1764 .ndo_open = smc_open,
1765 .ndo_stop = smc_close,
1766 .ndo_start_xmit = smc_hard_start_xmit,
1767 .ndo_tx_timeout = smc_timeout,
1768 .ndo_set_rx_mode = smc_set_multicast_list,
1769 .ndo_validate_addr = eth_validate_addr,
1770 .ndo_set_mac_address = eth_mac_addr,
1771#ifdef CONFIG_NET_POLL_CONTROLLER
1772 .ndo_poll_controller = smc_poll_controller,
1773#endif
1774};
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788static int smc_findirq(struct smc_local *lp)
1789{
1790 void __iomem *ioaddr = lp->base;
1791 int timeout = 20;
1792 unsigned long cookie;
1793
1794 DBG(2, lp->dev, "%s: %s\n", CARDNAME, __func__);
1795
1796 cookie = probe_irq_on();
1797
1798
1799
1800
1801
1802
1803
1804 SMC_SELECT_BANK(lp, 2);
1805 SMC_SET_INT_MASK(lp, IM_ALLOC_INT);
1806
1807
1808
1809
1810
1811 SMC_SET_MMU_CMD(lp, MC_ALLOC | 1);
1812
1813
1814
1815
1816 do {
1817 int int_status;
1818 udelay(10);
1819 int_status = SMC_GET_INT(lp);
1820 if (int_status & IM_ALLOC_INT)
1821 break;
1822 } while (--timeout);
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832 SMC_SET_INT_MASK(lp, 0);
1833
1834
1835 return probe_irq_off(cookie);
1836}
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862static int smc_probe(struct net_device *dev, void __iomem *ioaddr,
1863 unsigned long irq_flags)
1864{
1865 struct smc_local *lp = netdev_priv(dev);
1866 int retval;
1867 unsigned int val, revision_register;
1868 const char *version_string;
1869
1870 DBG(2, dev, "%s: %s\n", CARDNAME, __func__);
1871
1872
1873 val = SMC_CURRENT_BANK(lp);
1874 DBG(2, dev, "%s: bank signature probe returned 0x%04x\n",
1875 CARDNAME, val);
1876 if ((val & 0xFF00) != 0x3300) {
1877 if ((val & 0xFF) == 0x33) {
1878 netdev_warn(dev,
1879 "%s: Detected possible byte-swapped interface at IOADDR %p\n",
1880 CARDNAME, ioaddr);
1881 }
1882 retval = -ENODEV;
1883 goto err_out;
1884 }
1885
1886
1887
1888
1889
1890 SMC_SELECT_BANK(lp, 0);
1891 val = SMC_CURRENT_BANK(lp);
1892 if ((val & 0xFF00) != 0x3300) {
1893 retval = -ENODEV;
1894 goto err_out;
1895 }
1896
1897
1898
1899
1900
1901
1902
1903 SMC_SELECT_BANK(lp, 1);
1904 val = SMC_GET_BASE(lp);
1905 val = ((val & 0x1F00) >> 3) << SMC_IO_SHIFT;
1906 if (((unsigned long)ioaddr & (0x3e0 << SMC_IO_SHIFT)) != val) {
1907 netdev_warn(dev, "%s: IOADDR %p doesn't match configuration (%x).\n",
1908 CARDNAME, ioaddr, val);
1909 }
1910
1911
1912
1913
1914
1915
1916 SMC_SELECT_BANK(lp, 3);
1917 revision_register = SMC_GET_REV(lp);
1918 DBG(2, dev, "%s: revision = 0x%04x\n", CARDNAME, revision_register);
1919 version_string = chip_ids[ (revision_register >> 4) & 0xF];
1920 if (!version_string || (revision_register & 0xff00) != 0x3300) {
1921
1922 netdev_warn(dev, "%s: IO %p: Unrecognized revision register 0x%04x, Contact author.\n",
1923 CARDNAME, ioaddr, revision_register);
1924
1925 retval = -ENODEV;
1926 goto err_out;
1927 }
1928
1929
1930 pr_info_once("%s\n", version);
1931
1932
1933 dev->base_addr = (unsigned long)ioaddr;
1934 lp->base = ioaddr;
1935 lp->version = revision_register & 0xff;
1936 spin_lock_init(&lp->lock);
1937
1938
1939 SMC_SELECT_BANK(lp, 1);
1940 SMC_GET_MAC_ADDR(lp, dev->dev_addr);
1941
1942
1943 smc_reset(dev);
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960 if (dev->irq < 1) {
1961 int trials;
1962
1963 trials = 3;
1964 while (trials--) {
1965 dev->irq = smc_findirq(lp);
1966 if (dev->irq)
1967 break;
1968
1969 smc_reset(dev);
1970 }
1971 }
1972 if (dev->irq == 0) {
1973 netdev_warn(dev, "Couldn't autodetect your IRQ. Use irq=xx.\n");
1974 retval = -ENODEV;
1975 goto err_out;
1976 }
1977 dev->irq = irq_canonicalize(dev->irq);
1978
1979 dev->watchdog_timeo = msecs_to_jiffies(watchdog);
1980 dev->netdev_ops = &smc_netdev_ops;
1981 dev->ethtool_ops = &smc_ethtool_ops;
1982
1983 tasklet_init(&lp->tx_task, smc_hardware_send_pkt, (unsigned long)dev);
1984 INIT_WORK(&lp->phy_configure, smc_phy_configure);
1985 lp->dev = dev;
1986 lp->mii.phy_id_mask = 0x1f;
1987 lp->mii.reg_num_mask = 0x1f;
1988 lp->mii.force_media = 0;
1989 lp->mii.full_duplex = 0;
1990 lp->mii.dev = dev;
1991 lp->mii.mdio_read = smc_phy_read;
1992 lp->mii.mdio_write = smc_phy_write;
1993
1994
1995
1996
1997 if (lp->version >= (CHIP_91100 << 4))
1998 smc_phy_detect(dev);
1999
2000
2001 smc_shutdown(dev);
2002 smc_phy_powerdown(dev);
2003
2004
2005 lp->msg_enable = NETIF_MSG_LINK;
2006 lp->ctl_rfduplx = 0;
2007 lp->ctl_rspeed = 10;
2008
2009 if (lp->version >= (CHIP_91100 << 4)) {
2010 lp->ctl_rfduplx = 1;
2011 lp->ctl_rspeed = 100;
2012 }
2013
2014
2015 retval = request_irq(dev->irq, smc_interrupt, irq_flags, dev->name, dev);
2016 if (retval)
2017 goto err_out;
2018
2019#ifdef CONFIG_ARCH_PXA
2020# ifdef SMC_USE_PXA_DMA
2021 lp->cfg.flags |= SMC91X_USE_DMA;
2022# endif
2023 if (lp->cfg.flags & SMC91X_USE_DMA) {
2024 dma_cap_mask_t mask;
2025 struct pxad_param param;
2026
2027 dma_cap_zero(mask);
2028 dma_cap_set(DMA_SLAVE, mask);
2029 param.prio = PXAD_PRIO_LOWEST;
2030 param.drcmr = -1UL;
2031
2032 lp->dma_chan =
2033 dma_request_slave_channel_compat(mask, pxad_filter_fn,
2034 ¶m, &dev->dev,
2035 "data");
2036 }
2037#endif
2038
2039 retval = register_netdev(dev);
2040 if (retval == 0) {
2041
2042 netdev_info(dev, "%s (rev %d) at %p IRQ %d",
2043 version_string, revision_register & 0x0f,
2044 lp->base, dev->irq);
2045
2046 if (lp->dma_chan)
2047 pr_cont(" DMA %p", lp->dma_chan);
2048
2049 pr_cont("%s%s\n",
2050 lp->cfg.flags & SMC91X_NOWAIT ? " [nowait]" : "",
2051 THROTTLE_TX_PKTS ? " [throttle_tx]" : "");
2052
2053 if (!is_valid_ether_addr(dev->dev_addr)) {
2054 netdev_warn(dev, "Invalid ethernet MAC address. Please set using ifconfig\n");
2055 } else {
2056
2057 netdev_info(dev, "Ethernet addr: %pM\n",
2058 dev->dev_addr);
2059 }
2060
2061 if (lp->phy_type == 0) {
2062 PRINTK(dev, "No PHY found\n");
2063 } else if ((lp->phy_type & 0xfffffff0) == 0x0016f840) {
2064 PRINTK(dev, "PHY LAN83C183 (LAN91C111 Internal)\n");
2065 } else if ((lp->phy_type & 0xfffffff0) == 0x02821c50) {
2066 PRINTK(dev, "PHY LAN83C180\n");
2067 }
2068 }
2069
2070err_out:
2071#ifdef CONFIG_ARCH_PXA
2072 if (retval && lp->dma_chan)
2073 dma_release_channel(lp->dma_chan);
2074#endif
2075 return retval;
2076}
2077
2078static int smc_enable_device(struct platform_device *pdev)
2079{
2080 struct net_device *ndev = platform_get_drvdata(pdev);
2081 struct smc_local *lp = netdev_priv(ndev);
2082 unsigned long flags;
2083 unsigned char ecor, ecsr;
2084 void __iomem *addr;
2085 struct resource * res;
2086
2087 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2088 if (!res)
2089 return 0;
2090
2091
2092
2093
2094 addr = ioremap(res->start, ATTRIB_SIZE);
2095 if (!addr)
2096 return -ENOMEM;
2097
2098
2099
2100
2101
2102 local_irq_save(flags);
2103 ecor = readb(addr + (ECOR << SMC_IO_SHIFT)) & ~ECOR_RESET;
2104 writeb(ecor | ECOR_RESET, addr + (ECOR << SMC_IO_SHIFT));
2105 readb(addr + (ECOR << SMC_IO_SHIFT));
2106
2107
2108
2109
2110 udelay(100);
2111
2112
2113
2114
2115
2116
2117 writeb(ecor, addr + (ECOR << SMC_IO_SHIFT));
2118 writeb(ecor | ECOR_ENABLE, addr + (ECOR << SMC_IO_SHIFT));
2119
2120
2121
2122
2123 ecsr = readb(addr + (ECSR << SMC_IO_SHIFT)) & ~ECSR_IOIS8;
2124 if (!SMC_16BIT(lp))
2125 ecsr |= ECSR_IOIS8;
2126 writeb(ecsr, addr + (ECSR << SMC_IO_SHIFT));
2127 local_irq_restore(flags);
2128
2129 iounmap(addr);
2130
2131
2132
2133
2134
2135
2136 msleep(1);
2137
2138 return 0;
2139}
2140
2141static int smc_request_attrib(struct platform_device *pdev,
2142 struct net_device *ndev)
2143{
2144 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2145 struct smc_local *lp __maybe_unused = netdev_priv(ndev);
2146
2147 if (!res)
2148 return 0;
2149
2150 if (!request_mem_region(res->start, ATTRIB_SIZE, CARDNAME))
2151 return -EBUSY;
2152
2153 return 0;
2154}
2155
2156static void smc_release_attrib(struct platform_device *pdev,
2157 struct net_device *ndev)
2158{
2159 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-attrib");
2160 struct smc_local *lp __maybe_unused = netdev_priv(ndev);
2161
2162 if (res)
2163 release_mem_region(res->start, ATTRIB_SIZE);
2164}
2165
2166static inline void smc_request_datacs(struct platform_device *pdev, struct net_device *ndev)
2167{
2168 if (SMC_CAN_USE_DATACS) {
2169 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2170 struct smc_local *lp = netdev_priv(ndev);
2171
2172 if (!res)
2173 return;
2174
2175 if(!request_mem_region(res->start, SMC_DATA_EXTENT, CARDNAME)) {
2176 netdev_info(ndev, "%s: failed to request datacs memory region.\n",
2177 CARDNAME);
2178 return;
2179 }
2180
2181 lp->datacs = ioremap(res->start, SMC_DATA_EXTENT);
2182 }
2183}
2184
2185static void smc_release_datacs(struct platform_device *pdev, struct net_device *ndev)
2186{
2187 if (SMC_CAN_USE_DATACS) {
2188 struct smc_local *lp = netdev_priv(ndev);
2189 struct resource * res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-data32");
2190
2191 if (lp->datacs)
2192 iounmap(lp->datacs);
2193
2194 lp->datacs = NULL;
2195
2196 if (res)
2197 release_mem_region(res->start, SMC_DATA_EXTENT);
2198 }
2199}
2200
2201static const struct acpi_device_id smc91x_acpi_match[] = {
2202 { "LNRO0003", 0 },
2203 { }
2204};
2205MODULE_DEVICE_TABLE(acpi, smc91x_acpi_match);
2206
2207#if IS_BUILTIN(CONFIG_OF)
2208static const struct of_device_id smc91x_match[] = {
2209 { .compatible = "smsc,lan91c94", },
2210 { .compatible = "smsc,lan91c111", },
2211 {},
2212};
2213MODULE_DEVICE_TABLE(of, smc91x_match);
2214
2215
2216
2217
2218static int try_toggle_control_gpio(struct device *dev,
2219 struct gpio_desc **desc,
2220 const char *name, int index,
2221 int value, unsigned int nsdelay)
2222{
2223 struct gpio_desc *gpio = *desc;
2224 enum gpiod_flags flags = value ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH;
2225
2226 gpio = devm_gpiod_get_index_optional(dev, name, index, flags);
2227 if (IS_ERR(gpio))
2228 return PTR_ERR(gpio);
2229
2230 if (gpio) {
2231 if (nsdelay)
2232 usleep_range(nsdelay, 2 * nsdelay);
2233 gpiod_set_value_cansleep(gpio, value);
2234 }
2235 *desc = gpio;
2236
2237 return 0;
2238}
2239#endif
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252static int smc_drv_probe(struct platform_device *pdev)
2253{
2254 struct smc91x_platdata *pd = dev_get_platdata(&pdev->dev);
2255 const struct of_device_id *match = NULL;
2256 struct smc_local *lp;
2257 struct net_device *ndev;
2258 struct resource *res;
2259 unsigned int __iomem *addr;
2260 unsigned long irq_flags = SMC_IRQ_FLAGS;
2261 unsigned long irq_resflags;
2262 int ret;
2263
2264 ndev = alloc_etherdev(sizeof(struct smc_local));
2265 if (!ndev) {
2266 ret = -ENOMEM;
2267 goto out;
2268 }
2269 SET_NETDEV_DEV(ndev, &pdev->dev);
2270
2271
2272
2273
2274
2275 lp = netdev_priv(ndev);
2276 lp->cfg.flags = 0;
2277
2278 if (pd) {
2279 memcpy(&lp->cfg, pd, sizeof(lp->cfg));
2280 lp->io_shift = SMC91X_IO_SHIFT(lp->cfg.flags);
2281
2282 if (!SMC_8BIT(lp) && !SMC_16BIT(lp)) {
2283 dev_err(&pdev->dev,
2284 "at least one of 8-bit or 16-bit access support is required.\n");
2285 ret = -ENXIO;
2286 goto out_free_netdev;
2287 }
2288 }
2289
2290#if IS_BUILTIN(CONFIG_OF)
2291 match = of_match_device(of_match_ptr(smc91x_match), &pdev->dev);
2292 if (match) {
2293 u32 val;
2294
2295
2296 ret = try_toggle_control_gpio(&pdev->dev, &lp->power_gpio,
2297 "power", 0, 0, 100);
2298 if (ret)
2299 return ret;
2300
2301
2302
2303
2304
2305 ret = try_toggle_control_gpio(&pdev->dev, &lp->reset_gpio,
2306 "reset", 0, 0, 100);
2307 if (ret)
2308 return ret;
2309
2310
2311
2312
2313
2314 if (lp->reset_gpio)
2315 usleep_range(750, 1000);
2316
2317
2318 if (!device_property_read_u32(&pdev->dev, "reg-io-width",
2319 &val)) {
2320 if (val & 1)
2321 lp->cfg.flags |= SMC91X_USE_8BIT;
2322 if ((val == 0) || (val & 2))
2323 lp->cfg.flags |= SMC91X_USE_16BIT;
2324 if (val & 4)
2325 lp->cfg.flags |= SMC91X_USE_32BIT;
2326 } else {
2327 lp->cfg.flags |= SMC91X_USE_16BIT;
2328 }
2329 if (!device_property_read_u32(&pdev->dev, "reg-shift",
2330 &val))
2331 lp->io_shift = val;
2332 lp->cfg.pxa_u16_align4 =
2333 device_property_read_bool(&pdev->dev, "pxa-u16-align4");
2334 }
2335#endif
2336
2337 if (!pd && !match) {
2338 lp->cfg.flags |= (SMC_CAN_USE_8BIT) ? SMC91X_USE_8BIT : 0;
2339 lp->cfg.flags |= (SMC_CAN_USE_16BIT) ? SMC91X_USE_16BIT : 0;
2340 lp->cfg.flags |= (SMC_CAN_USE_32BIT) ? SMC91X_USE_32BIT : 0;
2341 lp->cfg.flags |= (nowait) ? SMC91X_NOWAIT : 0;
2342 }
2343
2344 if (!lp->cfg.leda && !lp->cfg.ledb) {
2345 lp->cfg.leda = RPC_LSA_DEFAULT;
2346 lp->cfg.ledb = RPC_LSB_DEFAULT;
2347 }
2348
2349 ndev->dma = (unsigned char)-1;
2350
2351 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2352 if (!res)
2353 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2354 if (!res) {
2355 ret = -ENODEV;
2356 goto out_free_netdev;
2357 }
2358
2359
2360 if (!request_mem_region(res->start, SMC_IO_EXTENT, CARDNAME)) {
2361 ret = -EBUSY;
2362 goto out_free_netdev;
2363 }
2364
2365 ndev->irq = platform_get_irq(pdev, 0);
2366 if (ndev->irq < 0) {
2367 ret = ndev->irq;
2368 goto out_release_io;
2369 }
2370
2371
2372
2373
2374
2375 irq_resflags = irqd_get_trigger_type(irq_get_irq_data(ndev->irq));
2376 if (irq_flags == -1 || irq_resflags & IRQF_TRIGGER_MASK)
2377 irq_flags = irq_resflags & IRQF_TRIGGER_MASK;
2378
2379 ret = smc_request_attrib(pdev, ndev);
2380 if (ret)
2381 goto out_release_io;
2382#if defined(CONFIG_ASSABET_NEPONSET)
2383 if (machine_is_assabet() && machine_has_neponset())
2384 neponset_ncr_set(NCR_ENET_OSC_EN);
2385#endif
2386 platform_set_drvdata(pdev, ndev);
2387 ret = smc_enable_device(pdev);
2388 if (ret)
2389 goto out_release_attrib;
2390
2391 addr = ioremap(res->start, SMC_IO_EXTENT);
2392 if (!addr) {
2393 ret = -ENOMEM;
2394 goto out_release_attrib;
2395 }
2396
2397#ifdef CONFIG_ARCH_PXA
2398 {
2399 struct smc_local *lp = netdev_priv(ndev);
2400 lp->device = &pdev->dev;
2401 lp->physaddr = res->start;
2402
2403 }
2404#endif
2405
2406 ret = smc_probe(ndev, addr, irq_flags);
2407 if (ret != 0)
2408 goto out_iounmap;
2409
2410 smc_request_datacs(pdev, ndev);
2411
2412 return 0;
2413
2414 out_iounmap:
2415 iounmap(addr);
2416 out_release_attrib:
2417 smc_release_attrib(pdev, ndev);
2418 out_release_io:
2419 release_mem_region(res->start, SMC_IO_EXTENT);
2420 out_free_netdev:
2421 free_netdev(ndev);
2422 out:
2423 pr_info("%s: not found (%d).\n", CARDNAME, ret);
2424
2425 return ret;
2426}
2427
2428static int smc_drv_remove(struct platform_device *pdev)
2429{
2430 struct net_device *ndev = platform_get_drvdata(pdev);
2431 struct smc_local *lp = netdev_priv(ndev);
2432 struct resource *res;
2433
2434 unregister_netdev(ndev);
2435
2436 free_irq(ndev->irq, ndev);
2437
2438#ifdef CONFIG_ARCH_PXA
2439 if (lp->dma_chan)
2440 dma_release_channel(lp->dma_chan);
2441#endif
2442 iounmap(lp->base);
2443
2444 smc_release_datacs(pdev,ndev);
2445 smc_release_attrib(pdev,ndev);
2446
2447 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "smc91x-regs");
2448 if (!res)
2449 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2450 release_mem_region(res->start, SMC_IO_EXTENT);
2451
2452 free_netdev(ndev);
2453
2454 return 0;
2455}
2456
2457static int smc_drv_suspend(struct device *dev)
2458{
2459 struct platform_device *pdev = to_platform_device(dev);
2460 struct net_device *ndev = platform_get_drvdata(pdev);
2461
2462 if (ndev) {
2463 if (netif_running(ndev)) {
2464 netif_device_detach(ndev);
2465 smc_shutdown(ndev);
2466 smc_phy_powerdown(ndev);
2467 }
2468 }
2469 return 0;
2470}
2471
2472static int smc_drv_resume(struct device *dev)
2473{
2474 struct platform_device *pdev = to_platform_device(dev);
2475 struct net_device *ndev = platform_get_drvdata(pdev);
2476
2477 if (ndev) {
2478 struct smc_local *lp = netdev_priv(ndev);
2479 smc_enable_device(pdev);
2480 if (netif_running(ndev)) {
2481 smc_reset(ndev);
2482 smc_enable(ndev);
2483 if (lp->phy_type != 0)
2484 smc_phy_configure(&lp->phy_configure);
2485 netif_device_attach(ndev);
2486 }
2487 }
2488 return 0;
2489}
2490
2491static struct dev_pm_ops smc_drv_pm_ops = {
2492 .suspend = smc_drv_suspend,
2493 .resume = smc_drv_resume,
2494};
2495
2496static struct platform_driver smc_driver = {
2497 .probe = smc_drv_probe,
2498 .remove = smc_drv_remove,
2499 .driver = {
2500 .name = CARDNAME,
2501 .pm = &smc_drv_pm_ops,
2502 .of_match_table = of_match_ptr(smc91x_match),
2503 .acpi_match_table = smc91x_acpi_match,
2504 },
2505};
2506
2507module_platform_driver(smc_driver);
2508