1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Silan SC92031 PCI Fast Ethernet Adapter driver
4 * Based on vendor drivers:
5 * Silan Fast Ethernet Netcard Driver:
6 * MODULE_AUTHOR ("gaoyonghong");
7 * MODULE_DESCRIPTION ("SILAN Fast Ethernet driver");
8 * MODULE_LICENSE("GPL");
9 * 8139D Fast Ethernet driver:
10 * (C) 2002 by gaoyonghong
11 * MODULE_AUTHOR ("gaoyonghong");
12 * MODULE_DESCRIPTION ("Rsltek 8139D PCI Fast Ethernet Adapter driver");
13 * MODULE_LICENSE("GPL");
14 * Both are almost identical and seem to be based on pci-skeleton.c
16 * Rewritten for 2.6 by Cesar Eduardo Barros
18 * A datasheet for this chip can be found at
19 * http://www.silan.com.cn/english/product/pdf/SC92031AY.pdf
22 /* Note about set_mac_address: I don't know how to change the hardware
23 * matching, so you need to enable IFF_PROMISC when using it.
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/pci.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/ethtool.h>
35 #include <linux/mii.h>
36 #include <linux/crc32.h>
40 #define SC92031_NAME "sc92031"
42 /* BAR 0 is MMIO, BAR 1 is PIO */
43 #define SC92031_USE_PIO 0
45 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */
46 static int multicast_filter_limit
= 64;
47 module_param(multicast_filter_limit
, int, 0);
48 MODULE_PARM_DESC(multicast_filter_limit
,
49 "Maximum number of filtered multicast addresses");
52 module_param(media
, int, 0);
53 MODULE_PARM_DESC(media
, "Media type (0x00 = autodetect,"
54 " 0x01 = 10M half, 0x02 = 10M full,"
55 " 0x04 = 100M half, 0x08 = 100M full)");
57 /* Size of the in-memory receive ring. */
58 #define RX_BUF_LEN_IDX 3 /* 0==8K, 1==16K, 2==32K, 3==64K ,4==128K*/
59 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
61 /* Number of Tx descriptor registers. */
64 /* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
65 #define MAX_ETH_FRAME_SIZE 1536
67 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
68 #define TX_BUF_SIZE MAX_ETH_FRAME_SIZE
69 #define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC)
71 /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024, 7==end of packet. */
72 #define RX_FIFO_THRESH 7 /* Rx buffer level before first PCI xfer. */
74 /* Time in jiffies before concluding the transmitter is hung. */
75 #define TX_TIMEOUT (4*HZ)
77 #define SILAN_STATS_NUM 2 /* number of ETHTOOL_GSTATS */
80 #define AUTOSELECT 0x00
83 #define M100_HALF 0x04
84 #define M100_FULL 0x08
86 /* Symbolic offsets to registers. */
87 enum silan_registers
{
88 Config0
= 0x00, // Config0
89 Config1
= 0x04, // Config1
90 RxBufWPtr
= 0x08, // Rx buffer writer poiter
91 IntrStatus
= 0x0C, // Interrupt status
92 IntrMask
= 0x10, // Interrupt mask
93 RxbufAddr
= 0x14, // Rx buffer start address
94 RxBufRPtr
= 0x18, // Rx buffer read pointer
95 Txstatusall
= 0x1C, // Transmit status of all descriptors
96 TxStatus0
= 0x20, // Transmit status (Four 32bit registers).
97 TxAddr0
= 0x30, // Tx descriptors (also four 32bit).
98 RxConfig
= 0x40, // Rx configuration
99 MAC0
= 0x44, // Ethernet hardware address.
100 MAR0
= 0x4C, // Multicast filter.
101 RxStatus0
= 0x54, // Rx status
102 TxConfig
= 0x5C, // Tx configuration
103 PhyCtrl
= 0x60, // physical control
104 FlowCtrlConfig
= 0x64, // flow control
105 Miicmd0
= 0x68, // Mii command0 register
106 Miicmd1
= 0x6C, // Mii command1 register
107 Miistatus
= 0x70, // Mii status register
108 Timercnt
= 0x74, // Timer counter register
109 TimerIntr
= 0x78, // Timer interrupt register
110 PMConfig
= 0x7C, // Power Manager configuration
111 CRC0
= 0x80, // Power Manager CRC ( Two 32bit regisers)
112 Wakeup0
= 0x88, // power Manager wakeup( Eight 64bit regiser)
113 LSBCRC0
= 0xC8, // power Manager LSBCRC(Two 32bit regiser)
120 #define MII_OutputStatus 24
122 #define PHY_16_JAB_ENB 0x1000
123 #define PHY_16_PORT_ENB 0x1
125 enum IntrStatusBits
{
126 LinkFail
= 0x80000000,
128 TimeOut
= 0x20000000,
132 IntrBits
= LinkFail
|LinkOK
|TimeOut
|RxOverflow
|RxOK
|TxOK
,
136 TxCarrierLost
= 0x20000000,
137 TxAborted
= 0x10000000,
138 TxOutOfWindow
= 0x08000000,
140 EarlyTxThresShift
= 16,
147 RxStatesOK
= 0x80000,
148 RxBadAlign
= 0x40000,
149 RxHugeFrame
= 0x20000,
150 RxSmallFrame
= 0x10000,
153 Rx_Broadcast
= 0x2000,
154 Rx_Multicast
= 0x1000,
155 RxAddrMatch
= 0x0800,
160 RxFullDx
= 0x80000000,
162 RxSmall
= 0x20000000,
165 RxAllphys
= 0x04000000,
166 RxMulticast
= 0x02000000,
167 RxBroadcast
= 0x01000000,
168 RxLoopBack
= (1 << 23) | (1 << 22),
169 LowThresholdShift
= 12,
170 HighThresholdShift
= 2,
174 TxFullDx
= 0x80000000,
176 TxEnbPad
= 0x20000000,
177 TxEnbHuge
= 0x10000000,
178 TxEnbFCS
= 0x08000000,
179 TxNoBackOff
= 0x04000000,
180 TxEnbPrem
= 0x02000000,
181 TxCareLostCrs
= 0x1000000,
182 TxExdCollNum
= 0xf00000,
183 TxDataRate
= 0x80000,
186 enum PhyCtrlconfigbits
{
187 PhyCtrlAne
= 0x80000000,
188 PhyCtrlSpd100
= 0x40000000,
189 PhyCtrlSpd10
= 0x20000000,
190 PhyCtrlPhyBaseAddr
= 0x1f000000,
191 PhyCtrlDux
= 0x800000,
192 PhyCtrlReset
= 0x400000,
195 enum FlowCtrlConfigBits
{
196 FlowCtrlFullDX
= 0x80000000,
197 FlowCtrlEnb
= 0x40000000,
201 Cfg0_Reset
= 0x80000000,
202 Cfg0_Anaoff
= 0x40000000,
203 Cfg0_LDPS
= 0x20000000,
207 Cfg1_EarlyRx
= 1 << 31,
208 Cfg1_EarlyTx
= 1 << 30,
219 Mii_Divider
= 0x20000000,
220 Mii_WRITE
= 0x400000,
224 Mii_Drvmod
= 0x40000,
232 Mii_StatusBusy
= 0x80000000,
239 PM_LANWake
= 1 << 28,
240 PM_LWPTN
= (1 << 27 | 1<< 26),
246 * priv->lock protects most of the fields of priv and most of the
247 * hardware registers. It does not have to protect against softirqs
248 * between sc92031_disable_interrupts and sc92031_enable_interrupts;
249 * it also does not need to be used in ->open and ->stop while the
250 * device interrupts are off.
251 * Not having to protect against softirqs is very useful due to heavy
252 * use of mdelay() at _sc92031_reset.
253 * Functions prefixed with _sc92031_ must be called with the lock held;
254 * functions prefixed with sc92031_ must be called without the lock held.
257 /* Locking rules for the interrupt:
258 * - the interrupt and the tasklet never run at the same time
259 * - neither run between sc92031_disable_interrupts and
260 * sc92031_enable_interrupt
263 struct sc92031_priv
{
266 void __iomem
*port_base
;
267 /* pci device structure */
268 struct pci_dev
*pdev
;
270 struct tasklet_struct tasklet
;
272 /* CPU address of rx ring */
274 /* PCI address of rx ring */
275 dma_addr_t rx_ring_dma_addr
;
276 /* PCI address of rx ring read pointer */
277 dma_addr_t rx_ring_tail
;
279 /* tx ring write index */
281 /* tx ring read index */
283 /* CPU address of tx bounce buffer */
285 /* PCI address of tx bounce buffer */
286 dma_addr_t tx_bufs_dma_addr
;
288 /* copies of some hardware registers */
295 /* copy of some flags from dev->flags */
296 unsigned int mc_flags
;
298 /* for ETHTOOL_GSTATS */
302 /* for dev->get_stats */
304 struct net_device
*ndev
;
307 /* I don't know which registers can be safely read; however, I can guess
308 * MAC0 is one of them. */
309 static inline void _sc92031_dummy_read(void __iomem
*port_base
)
311 ioread32(port_base
+ MAC0
);
314 static u32
_sc92031_mii_wait(void __iomem
*port_base
)
320 mii_status
= ioread32(port_base
+ Miistatus
);
321 } while (mii_status
& Mii_StatusBusy
);
326 static u32
_sc92031_mii_cmd(void __iomem
*port_base
, u32 cmd0
, u32 cmd1
)
328 iowrite32(Mii_Divider
, port_base
+ Miicmd0
);
330 _sc92031_mii_wait(port_base
);
332 iowrite32(cmd1
, port_base
+ Miicmd1
);
333 iowrite32(Mii_Divider
| cmd0
, port_base
+ Miicmd0
);
335 return _sc92031_mii_wait(port_base
);
338 static void _sc92031_mii_scan(void __iomem
*port_base
)
340 _sc92031_mii_cmd(port_base
, Mii_SCAN
, 0x1 << 6);
343 static u16
_sc92031_mii_read(void __iomem
*port_base
, unsigned reg
)
345 return _sc92031_mii_cmd(port_base
, Mii_READ
, reg
<< 6) >> 13;
348 static void _sc92031_mii_write(void __iomem
*port_base
, unsigned reg
, u16 val
)
350 _sc92031_mii_cmd(port_base
, Mii_WRITE
, (reg
<< 6) | ((u32
)val
<< 11));
353 static void sc92031_disable_interrupts(struct net_device
*dev
)
355 struct sc92031_priv
*priv
= netdev_priv(dev
);
356 void __iomem
*port_base
= priv
->port_base
;
358 /* tell the tasklet/interrupt not to enable interrupts */
359 atomic_set(&priv
->intr_mask
, 0);
362 /* stop interrupts */
363 iowrite32(0, port_base
+ IntrMask
);
364 _sc92031_dummy_read(port_base
);
366 /* wait for any concurrent interrupt/tasklet to finish */
367 synchronize_irq(priv
->pdev
->irq
);
368 tasklet_disable(&priv
->tasklet
);
371 static void sc92031_enable_interrupts(struct net_device
*dev
)
373 struct sc92031_priv
*priv
= netdev_priv(dev
);
374 void __iomem
*port_base
= priv
->port_base
;
376 tasklet_enable(&priv
->tasklet
);
378 atomic_set(&priv
->intr_mask
, IntrBits
);
381 iowrite32(IntrBits
, port_base
+ IntrMask
);
384 static void _sc92031_disable_tx_rx(struct net_device
*dev
)
386 struct sc92031_priv
*priv
= netdev_priv(dev
);
387 void __iomem
*port_base
= priv
->port_base
;
389 priv
->rx_config
&= ~RxEnb
;
390 priv
->tx_config
&= ~TxEnb
;
391 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
392 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
395 static void _sc92031_enable_tx_rx(struct net_device
*dev
)
397 struct sc92031_priv
*priv
= netdev_priv(dev
);
398 void __iomem
*port_base
= priv
->port_base
;
400 priv
->rx_config
|= RxEnb
;
401 priv
->tx_config
|= TxEnb
;
402 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
403 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
406 static void _sc92031_tx_clear(struct net_device
*dev
)
408 struct sc92031_priv
*priv
= netdev_priv(dev
);
410 while (priv
->tx_head
- priv
->tx_tail
> 0) {
412 dev
->stats
.tx_dropped
++;
414 priv
->tx_head
= priv
->tx_tail
= 0;
417 static void _sc92031_set_mar(struct net_device
*dev
)
419 struct sc92031_priv
*priv
= netdev_priv(dev
);
420 void __iomem
*port_base
= priv
->port_base
;
421 u32 mar0
= 0, mar1
= 0;
423 if ((dev
->flags
& IFF_PROMISC
) ||
424 netdev_mc_count(dev
) > multicast_filter_limit
||
425 (dev
->flags
& IFF_ALLMULTI
))
426 mar0
= mar1
= 0xffffffff;
427 else if (dev
->flags
& IFF_MULTICAST
) {
428 struct netdev_hw_addr
*ha
;
430 netdev_for_each_mc_addr(ha
, dev
) {
434 crc
= ~ether_crc(ETH_ALEN
, ha
->addr
);
437 if (crc
& 0x01) bit
|= 0x02;
438 if (crc
& 0x02) bit
|= 0x01;
439 if (crc
& 0x10) bit
|= 0x20;
440 if (crc
& 0x20) bit
|= 0x10;
441 if (crc
& 0x40) bit
|= 0x08;
442 if (crc
& 0x80) bit
|= 0x04;
445 mar0
|= 0x1 << (bit
- 32);
451 iowrite32(mar0
, port_base
+ MAR0
);
452 iowrite32(mar1
, port_base
+ MAR0
+ 4);
455 static void _sc92031_set_rx_config(struct net_device
*dev
)
457 struct sc92031_priv
*priv
= netdev_priv(dev
);
458 void __iomem
*port_base
= priv
->port_base
;
459 unsigned int old_mc_flags
;
460 u32 rx_config_bits
= 0;
462 old_mc_flags
= priv
->mc_flags
;
464 if (dev
->flags
& IFF_PROMISC
)
465 rx_config_bits
|= RxSmall
| RxHuge
| RxErr
| RxBroadcast
466 | RxMulticast
| RxAllphys
;
468 if (dev
->flags
& (IFF_ALLMULTI
| IFF_MULTICAST
))
469 rx_config_bits
|= RxMulticast
;
471 if (dev
->flags
& IFF_BROADCAST
)
472 rx_config_bits
|= RxBroadcast
;
474 priv
->rx_config
&= ~(RxSmall
| RxHuge
| RxErr
| RxBroadcast
475 | RxMulticast
| RxAllphys
);
476 priv
->rx_config
|= rx_config_bits
;
478 priv
->mc_flags
= dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
479 | IFF_MULTICAST
| IFF_BROADCAST
);
481 if (netif_carrier_ok(dev
) && priv
->mc_flags
!= old_mc_flags
)
482 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
485 static bool _sc92031_check_media(struct net_device
*dev
)
487 struct sc92031_priv
*priv
= netdev_priv(dev
);
488 void __iomem
*port_base
= priv
->port_base
;
491 bmsr
= _sc92031_mii_read(port_base
, MII_BMSR
);
493 if (bmsr
& BMSR_LSTATUS
) {
494 bool speed_100
, duplex_full
;
495 u32 flow_ctrl_config
= 0;
496 u16 output_status
= _sc92031_mii_read(port_base
,
498 _sc92031_mii_scan(port_base
);
500 speed_100
= output_status
& 0x2;
501 duplex_full
= output_status
& 0x4;
503 /* Initial Tx/Rx configuration */
504 priv
->rx_config
= (0x40 << LowThresholdShift
) | (0x1c0 << HighThresholdShift
);
505 priv
->tx_config
= 0x48800000;
507 /* NOTE: vendor driver had dead code here to enable tx padding */
510 priv
->tx_config
|= 0x80000;
513 _sc92031_set_rx_config(dev
);
516 priv
->rx_config
|= RxFullDx
;
517 priv
->tx_config
|= TxFullDx
;
518 flow_ctrl_config
= FlowCtrlFullDX
| FlowCtrlEnb
;
520 priv
->rx_config
&= ~RxFullDx
;
521 priv
->tx_config
&= ~TxFullDx
;
524 _sc92031_set_mar(dev
);
525 _sc92031_set_rx_config(dev
);
526 _sc92031_enable_tx_rx(dev
);
527 iowrite32(flow_ctrl_config
, port_base
+ FlowCtrlConfig
);
529 netif_carrier_on(dev
);
531 if (printk_ratelimit())
532 printk(KERN_INFO
"%s: link up, %sMbps, %s-duplex\n",
534 speed_100
? "100" : "10",
535 duplex_full
? "full" : "half");
538 _sc92031_mii_scan(port_base
);
540 netif_carrier_off(dev
);
542 _sc92031_disable_tx_rx(dev
);
544 if (printk_ratelimit())
545 printk(KERN_INFO
"%s: link down\n", dev
->name
);
550 static void _sc92031_phy_reset(struct net_device
*dev
)
552 struct sc92031_priv
*priv
= netdev_priv(dev
);
553 void __iomem
*port_base
= priv
->port_base
;
556 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
557 phy_ctrl
&= ~(PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
);
558 phy_ctrl
|= PhyCtrlAne
| PhyCtrlReset
;
563 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
566 phy_ctrl
|= PhyCtrlSpd10
;
569 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd10
;
572 phy_ctrl
|= PhyCtrlSpd100
;
575 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
579 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
582 phy_ctrl
&= ~PhyCtrlReset
;
583 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
586 _sc92031_mii_write(port_base
, MII_JAB
,
587 PHY_16_JAB_ENB
| PHY_16_PORT_ENB
);
588 _sc92031_mii_scan(port_base
);
590 netif_carrier_off(dev
);
591 netif_stop_queue(dev
);
594 static void _sc92031_reset(struct net_device
*dev
)
596 struct sc92031_priv
*priv
= netdev_priv(dev
);
597 void __iomem
*port_base
= priv
->port_base
;
600 iowrite32(0, port_base
+ PMConfig
);
602 /* soft reset the chip */
603 iowrite32(Cfg0_Reset
, port_base
+ Config0
);
606 iowrite32(0, port_base
+ Config0
);
609 /* disable interrupts */
610 iowrite32(0, port_base
+ IntrMask
);
612 /* clear multicast address */
613 iowrite32(0, port_base
+ MAR0
);
614 iowrite32(0, port_base
+ MAR0
+ 4);
617 iowrite32(priv
->rx_ring_dma_addr
, port_base
+ RxbufAddr
);
618 priv
->rx_ring_tail
= priv
->rx_ring_dma_addr
;
621 _sc92031_tx_clear(dev
);
623 /* clear old register values */
624 priv
->intr_status
= 0;
625 atomic_set(&priv
->intr_mask
, 0);
630 /* configure rx buffer size */
631 /* NOTE: vendor driver had dead code here to enable early tx/rx */
632 iowrite32(Cfg1_Rcv64K
, port_base
+ Config1
);
634 _sc92031_phy_reset(dev
);
635 _sc92031_check_media(dev
);
637 /* calculate rx fifo overflow */
641 iowrite32(priv
->pm_config
, port_base
+ PMConfig
);
643 /* clear intr register */
644 ioread32(port_base
+ IntrStatus
);
647 static void _sc92031_tx_tasklet(struct net_device
*dev
)
649 struct sc92031_priv
*priv
= netdev_priv(dev
);
650 void __iomem
*port_base
= priv
->port_base
;
652 unsigned old_tx_tail
;
656 old_tx_tail
= priv
->tx_tail
;
657 while (priv
->tx_head
- priv
->tx_tail
> 0) {
658 entry
= priv
->tx_tail
% NUM_TX_DESC
;
659 tx_status
= ioread32(port_base
+ TxStatus0
+ entry
* 4);
661 if (!(tx_status
& (TxStatOK
| TxUnderrun
| TxAborted
)))
666 if (tx_status
& TxStatOK
) {
667 dev
->stats
.tx_bytes
+= tx_status
& 0x1fff;
668 dev
->stats
.tx_packets
++;
669 /* Note: TxCarrierLost is always asserted at 100mbps. */
670 dev
->stats
.collisions
+= (tx_status
>> 22) & 0xf;
673 if (tx_status
& (TxOutOfWindow
| TxAborted
)) {
674 dev
->stats
.tx_errors
++;
676 if (tx_status
& TxAborted
)
677 dev
->stats
.tx_aborted_errors
++;
679 if (tx_status
& TxCarrierLost
)
680 dev
->stats
.tx_carrier_errors
++;
682 if (tx_status
& TxOutOfWindow
)
683 dev
->stats
.tx_window_errors
++;
686 if (tx_status
& TxUnderrun
)
687 dev
->stats
.tx_fifo_errors
++;
690 if (priv
->tx_tail
!= old_tx_tail
)
691 if (netif_queue_stopped(dev
))
692 netif_wake_queue(dev
);
695 static void _sc92031_rx_tasklet_error(struct net_device
*dev
,
696 u32 rx_status
, unsigned rx_size
)
698 if(rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) || rx_size
< 16) {
699 dev
->stats
.rx_errors
++;
700 dev
->stats
.rx_length_errors
++;
703 if (!(rx_status
& RxStatesOK
)) {
704 dev
->stats
.rx_errors
++;
706 if (rx_status
& (RxHugeFrame
| RxSmallFrame
))
707 dev
->stats
.rx_length_errors
++;
709 if (rx_status
& RxBadAlign
)
710 dev
->stats
.rx_frame_errors
++;
712 if (!(rx_status
& RxCRCOK
))
713 dev
->stats
.rx_crc_errors
++;
715 struct sc92031_priv
*priv
= netdev_priv(dev
);
720 static void _sc92031_rx_tasklet(struct net_device
*dev
)
722 struct sc92031_priv
*priv
= netdev_priv(dev
);
723 void __iomem
*port_base
= priv
->port_base
;
725 dma_addr_t rx_ring_head
;
727 unsigned rx_ring_offset
;
728 void *rx_ring
= priv
->rx_ring
;
730 rx_ring_head
= ioread32(port_base
+ RxBufWPtr
);
733 /* rx_ring_head is only 17 bits in the RxBufWPtr register.
734 * we need to change it to 32 bits physical address
736 rx_ring_head
&= (dma_addr_t
)(RX_BUF_LEN
- 1);
737 rx_ring_head
|= priv
->rx_ring_dma_addr
& ~(dma_addr_t
)(RX_BUF_LEN
- 1);
738 if (rx_ring_head
< priv
->rx_ring_dma_addr
)
739 rx_ring_head
+= RX_BUF_LEN
;
741 if (rx_ring_head
>= priv
->rx_ring_tail
)
742 rx_len
= rx_ring_head
- priv
->rx_ring_tail
;
744 rx_len
= RX_BUF_LEN
- (priv
->rx_ring_tail
- rx_ring_head
);
749 if (unlikely(rx_len
> RX_BUF_LEN
)) {
750 if (printk_ratelimit())
751 printk(KERN_ERR
"%s: rx packets length > rx buffer\n",
756 rx_ring_offset
= (priv
->rx_ring_tail
- priv
->rx_ring_dma_addr
) % RX_BUF_LEN
;
760 unsigned rx_size
, rx_size_align
, pkt_size
;
763 rx_status
= le32_to_cpup((__le32
*)(rx_ring
+ rx_ring_offset
));
766 rx_size
= rx_status
>> 20;
767 rx_size_align
= (rx_size
+ 3) & ~3; // for 4 bytes aligned
768 pkt_size
= rx_size
- 4; // Omit the four octet CRC from the length.
770 rx_ring_offset
= (rx_ring_offset
+ 4) % RX_BUF_LEN
;
772 if (unlikely(rx_status
== 0 ||
773 rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) ||
775 !(rx_status
& RxStatesOK
))) {
776 _sc92031_rx_tasklet_error(dev
, rx_status
, rx_size
);
780 if (unlikely(rx_size_align
+ 4 > rx_len
)) {
781 if (printk_ratelimit())
782 printk(KERN_ERR
"%s: rx_len is too small\n", dev
->name
);
786 rx_len
-= rx_size_align
+ 4;
788 skb
= netdev_alloc_skb_ip_align(dev
, pkt_size
);
789 if (unlikely(!skb
)) {
790 if (printk_ratelimit())
791 printk(KERN_ERR
"%s: Couldn't allocate a skb_buff for a packet of size %u\n",
792 dev
->name
, pkt_size
);
796 if ((rx_ring_offset
+ pkt_size
) > RX_BUF_LEN
) {
797 skb_put_data(skb
, rx_ring
+ rx_ring_offset
,
798 RX_BUF_LEN
- rx_ring_offset
);
799 skb_put_data(skb
, rx_ring
,
800 pkt_size
- (RX_BUF_LEN
- rx_ring_offset
));
802 skb_put_data(skb
, rx_ring
+ rx_ring_offset
, pkt_size
);
805 skb
->protocol
= eth_type_trans(skb
, dev
);
808 dev
->stats
.rx_bytes
+= pkt_size
;
809 dev
->stats
.rx_packets
++;
811 if (rx_status
& Rx_Multicast
)
812 dev
->stats
.multicast
++;
815 rx_ring_offset
= (rx_ring_offset
+ rx_size_align
) % RX_BUF_LEN
;
819 priv
->rx_ring_tail
= rx_ring_head
;
820 iowrite32(priv
->rx_ring_tail
, port_base
+ RxBufRPtr
);
823 static void _sc92031_link_tasklet(struct net_device
*dev
)
825 if (_sc92031_check_media(dev
))
826 netif_wake_queue(dev
);
828 netif_stop_queue(dev
);
829 dev
->stats
.tx_carrier_errors
++;
833 static void sc92031_tasklet(struct tasklet_struct
*t
)
835 struct sc92031_priv
*priv
= from_tasklet(priv
, t
, tasklet
);
836 struct net_device
*dev
= priv
->ndev
;
837 void __iomem
*port_base
= priv
->port_base
;
838 u32 intr_status
, intr_mask
;
840 intr_status
= priv
->intr_status
;
842 spin_lock(&priv
->lock
);
844 if (unlikely(!netif_running(dev
)))
847 if (intr_status
& TxOK
)
848 _sc92031_tx_tasklet(dev
);
850 if (intr_status
& RxOK
)
851 _sc92031_rx_tasklet(dev
);
853 if (intr_status
& RxOverflow
)
854 dev
->stats
.rx_errors
++;
856 if (intr_status
& TimeOut
) {
857 dev
->stats
.rx_errors
++;
858 dev
->stats
.rx_length_errors
++;
861 if (intr_status
& (LinkFail
| LinkOK
))
862 _sc92031_link_tasklet(dev
);
865 intr_mask
= atomic_read(&priv
->intr_mask
);
868 iowrite32(intr_mask
, port_base
+ IntrMask
);
870 spin_unlock(&priv
->lock
);
873 static irqreturn_t
sc92031_interrupt(int irq
, void *dev_id
)
875 struct net_device
*dev
= dev_id
;
876 struct sc92031_priv
*priv
= netdev_priv(dev
);
877 void __iomem
*port_base
= priv
->port_base
;
878 u32 intr_status
, intr_mask
;
880 /* mask interrupts before clearing IntrStatus */
881 iowrite32(0, port_base
+ IntrMask
);
882 _sc92031_dummy_read(port_base
);
884 intr_status
= ioread32(port_base
+ IntrStatus
);
885 if (unlikely(intr_status
== 0xffffffff))
886 return IRQ_NONE
; // hardware has gone missing
888 intr_status
&= IntrBits
;
892 priv
->intr_status
= intr_status
;
893 tasklet_schedule(&priv
->tasklet
);
898 intr_mask
= atomic_read(&priv
->intr_mask
);
901 iowrite32(intr_mask
, port_base
+ IntrMask
);
906 static struct net_device_stats
*sc92031_get_stats(struct net_device
*dev
)
908 struct sc92031_priv
*priv
= netdev_priv(dev
);
909 void __iomem
*port_base
= priv
->port_base
;
911 // FIXME I do not understand what is this trying to do.
912 if (netif_running(dev
)) {
915 spin_lock_bh(&priv
->lock
);
917 /* Update the error count. */
918 temp
= (ioread32(port_base
+ RxStatus0
) >> 16) & 0xffff;
920 if (temp
== 0xffff) {
921 priv
->rx_value
+= temp
;
922 dev
->stats
.rx_fifo_errors
= priv
->rx_value
;
924 dev
->stats
.rx_fifo_errors
= temp
+ priv
->rx_value
;
926 spin_unlock_bh(&priv
->lock
);
932 static netdev_tx_t
sc92031_start_xmit(struct sk_buff
*skb
,
933 struct net_device
*dev
)
935 struct sc92031_priv
*priv
= netdev_priv(dev
);
936 void __iomem
*port_base
= priv
->port_base
;
941 if (unlikely(skb
->len
> TX_BUF_SIZE
)) {
942 dev
->stats
.tx_dropped
++;
946 spin_lock(&priv
->lock
);
948 if (unlikely(!netif_carrier_ok(dev
))) {
949 dev
->stats
.tx_dropped
++;
953 BUG_ON(priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
);
955 entry
= priv
->tx_head
++ % NUM_TX_DESC
;
957 skb_copy_and_csum_dev(skb
, priv
->tx_bufs
+ entry
* TX_BUF_SIZE
);
960 if (len
< ETH_ZLEN
) {
961 memset(priv
->tx_bufs
+ entry
* TX_BUF_SIZE
+ len
,
971 tx_status
= 0x30000 | len
;
973 tx_status
= 0x50000 | len
;
975 iowrite32(priv
->tx_bufs_dma_addr
+ entry
* TX_BUF_SIZE
,
976 port_base
+ TxAddr0
+ entry
* 4);
977 iowrite32(tx_status
, port_base
+ TxStatus0
+ entry
* 4);
979 if (priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
)
980 netif_stop_queue(dev
);
983 spin_unlock(&priv
->lock
);
986 dev_consume_skb_any(skb
);
991 static int sc92031_open(struct net_device
*dev
)
994 struct sc92031_priv
*priv
= netdev_priv(dev
);
995 struct pci_dev
*pdev
= priv
->pdev
;
997 priv
->rx_ring
= dma_alloc_coherent(&pdev
->dev
, RX_BUF_LEN
,
998 &priv
->rx_ring_dma_addr
, GFP_KERNEL
);
999 if (unlikely(!priv
->rx_ring
)) {
1001 goto out_alloc_rx_ring
;
1004 priv
->tx_bufs
= dma_alloc_coherent(&pdev
->dev
, TX_BUF_TOT_LEN
,
1005 &priv
->tx_bufs_dma_addr
, GFP_KERNEL
);
1006 if (unlikely(!priv
->tx_bufs
)) {
1008 goto out_alloc_tx_bufs
;
1010 priv
->tx_head
= priv
->tx_tail
= 0;
1012 err
= request_irq(pdev
->irq
, sc92031_interrupt
,
1013 IRQF_SHARED
, dev
->name
, dev
);
1014 if (unlikely(err
< 0))
1015 goto out_request_irq
;
1017 priv
->pm_config
= 0;
1019 /* Interrupts already disabled by sc92031_stop or sc92031_probe */
1020 spin_lock_bh(&priv
->lock
);
1022 _sc92031_reset(dev
);
1024 spin_unlock_bh(&priv
->lock
);
1025 sc92031_enable_interrupts(dev
);
1027 if (netif_carrier_ok(dev
))
1028 netif_start_queue(dev
);
1030 netif_tx_disable(dev
);
1035 dma_free_coherent(&pdev
->dev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1036 priv
->tx_bufs_dma_addr
);
1038 dma_free_coherent(&pdev
->dev
, RX_BUF_LEN
, priv
->rx_ring
,
1039 priv
->rx_ring_dma_addr
);
1044 static int sc92031_stop(struct net_device
*dev
)
1046 struct sc92031_priv
*priv
= netdev_priv(dev
);
1047 struct pci_dev
*pdev
= priv
->pdev
;
1049 netif_tx_disable(dev
);
1051 /* Disable interrupts, stop Tx and Rx. */
1052 sc92031_disable_interrupts(dev
);
1054 spin_lock_bh(&priv
->lock
);
1056 _sc92031_disable_tx_rx(dev
);
1057 _sc92031_tx_clear(dev
);
1059 spin_unlock_bh(&priv
->lock
);
1061 free_irq(pdev
->irq
, dev
);
1062 dma_free_coherent(&pdev
->dev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1063 priv
->tx_bufs_dma_addr
);
1064 dma_free_coherent(&pdev
->dev
, RX_BUF_LEN
, priv
->rx_ring
,
1065 priv
->rx_ring_dma_addr
);
1070 static void sc92031_set_multicast_list(struct net_device
*dev
)
1072 struct sc92031_priv
*priv
= netdev_priv(dev
);
1074 spin_lock_bh(&priv
->lock
);
1076 _sc92031_set_mar(dev
);
1077 _sc92031_set_rx_config(dev
);
1079 spin_unlock_bh(&priv
->lock
);
1082 static void sc92031_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
1084 struct sc92031_priv
*priv
= netdev_priv(dev
);
1086 /* Disable interrupts by clearing the interrupt mask.*/
1087 sc92031_disable_interrupts(dev
);
1089 spin_lock(&priv
->lock
);
1091 priv
->tx_timeouts
++;
1093 _sc92031_reset(dev
);
1095 spin_unlock(&priv
->lock
);
1097 /* enable interrupts */
1098 sc92031_enable_interrupts(dev
);
1100 if (netif_carrier_ok(dev
))
1101 netif_wake_queue(dev
);
1104 #ifdef CONFIG_NET_POLL_CONTROLLER
1105 static void sc92031_poll_controller(struct net_device
*dev
)
1107 struct sc92031_priv
*priv
= netdev_priv(dev
);
1108 const int irq
= priv
->pdev
->irq
;
1111 if (sc92031_interrupt(irq
, dev
) != IRQ_NONE
)
1112 sc92031_tasklet(&priv
->tasklet
);
1118 sc92031_ethtool_get_link_ksettings(struct net_device
*dev
,
1119 struct ethtool_link_ksettings
*cmd
)
1121 struct sc92031_priv
*priv
= netdev_priv(dev
);
1122 void __iomem
*port_base
= priv
->port_base
;
1126 u32 supported
, advertising
;
1128 spin_lock_bh(&priv
->lock
);
1130 phy_address
= ioread32(port_base
+ Miicmd1
) >> 27;
1131 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
1133 output_status
= _sc92031_mii_read(port_base
, MII_OutputStatus
);
1134 _sc92031_mii_scan(port_base
);
1136 spin_unlock_bh(&priv
->lock
);
1138 supported
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
1139 | SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
1140 | SUPPORTED_Autoneg
| SUPPORTED_TP
| SUPPORTED_MII
;
1142 advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
1144 if ((phy_ctrl
& (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1145 == (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1146 advertising
|= ADVERTISED_Autoneg
;
1148 if ((phy_ctrl
& PhyCtrlSpd10
) == PhyCtrlSpd10
)
1149 advertising
|= ADVERTISED_10baseT_Half
;
1151 if ((phy_ctrl
& (PhyCtrlSpd10
| PhyCtrlDux
))
1152 == (PhyCtrlSpd10
| PhyCtrlDux
))
1153 advertising
|= ADVERTISED_10baseT_Full
;
1155 if ((phy_ctrl
& PhyCtrlSpd100
) == PhyCtrlSpd100
)
1156 advertising
|= ADVERTISED_100baseT_Half
;
1158 if ((phy_ctrl
& (PhyCtrlSpd100
| PhyCtrlDux
))
1159 == (PhyCtrlSpd100
| PhyCtrlDux
))
1160 advertising
|= ADVERTISED_100baseT_Full
;
1162 if (phy_ctrl
& PhyCtrlAne
)
1163 advertising
|= ADVERTISED_Autoneg
;
1165 cmd
->base
.speed
= (output_status
& 0x2) ? SPEED_100
: SPEED_10
;
1166 cmd
->base
.duplex
= (output_status
& 0x4) ? DUPLEX_FULL
: DUPLEX_HALF
;
1167 cmd
->base
.port
= PORT_MII
;
1168 cmd
->base
.phy_address
= phy_address
;
1169 cmd
->base
.autoneg
= (phy_ctrl
& PhyCtrlAne
) ?
1170 AUTONEG_ENABLE
: AUTONEG_DISABLE
;
1172 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
1174 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
1181 sc92031_ethtool_set_link_ksettings(struct net_device
*dev
,
1182 const struct ethtool_link_ksettings
*cmd
)
1184 struct sc92031_priv
*priv
= netdev_priv(dev
);
1185 void __iomem
*port_base
= priv
->port_base
;
1186 u32 speed
= cmd
->base
.speed
;
1191 ethtool_convert_link_mode_to_legacy_u32(&advertising
,
1192 cmd
->link_modes
.advertising
);
1194 if (!(speed
== SPEED_10
|| speed
== SPEED_100
))
1196 if (!(cmd
->base
.duplex
== DUPLEX_HALF
||
1197 cmd
->base
.duplex
== DUPLEX_FULL
))
1199 if (!(cmd
->base
.port
== PORT_MII
))
1201 if (!(cmd
->base
.phy_address
== 0x1f))
1203 if (!(cmd
->base
.autoneg
== AUTONEG_DISABLE
||
1204 cmd
->base
.autoneg
== AUTONEG_ENABLE
))
1207 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
) {
1208 if (!(advertising
& (ADVERTISED_Autoneg
1209 | ADVERTISED_100baseT_Full
1210 | ADVERTISED_100baseT_Half
1211 | ADVERTISED_10baseT_Full
1212 | ADVERTISED_10baseT_Half
)))
1215 phy_ctrl
= PhyCtrlAne
;
1217 // FIXME: I'm not sure what the original code was trying to do
1218 if (advertising
& ADVERTISED_Autoneg
)
1219 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
1220 if (advertising
& ADVERTISED_100baseT_Full
)
1221 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
1222 if (advertising
& ADVERTISED_100baseT_Half
)
1223 phy_ctrl
|= PhyCtrlSpd100
;
1224 if (advertising
& ADVERTISED_10baseT_Full
)
1225 phy_ctrl
|= PhyCtrlSpd10
| PhyCtrlDux
;
1226 if (advertising
& ADVERTISED_10baseT_Half
)
1227 phy_ctrl
|= PhyCtrlSpd10
;
1229 // FIXME: Whole branch guessed
1232 if (speed
== SPEED_10
)
1233 phy_ctrl
|= PhyCtrlSpd10
;
1234 else /* cmd->speed == SPEED_100 */
1235 phy_ctrl
|= PhyCtrlSpd100
;
1237 if (cmd
->base
.duplex
== DUPLEX_FULL
)
1238 phy_ctrl
|= PhyCtrlDux
;
1241 spin_lock_bh(&priv
->lock
);
1243 old_phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
1244 phy_ctrl
|= old_phy_ctrl
& ~(PhyCtrlAne
| PhyCtrlDux
1245 | PhyCtrlSpd100
| PhyCtrlSpd10
);
1246 if (phy_ctrl
!= old_phy_ctrl
)
1247 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
1249 spin_unlock_bh(&priv
->lock
);
1254 static void sc92031_ethtool_get_wol(struct net_device
*dev
,
1255 struct ethtool_wolinfo
*wolinfo
)
1257 struct sc92031_priv
*priv
= netdev_priv(dev
);
1258 void __iomem
*port_base
= priv
->port_base
;
1261 spin_lock_bh(&priv
->lock
);
1262 pm_config
= ioread32(port_base
+ PMConfig
);
1263 spin_unlock_bh(&priv
->lock
);
1266 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
1267 | WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
;
1268 wolinfo
->wolopts
= 0;
1270 if (pm_config
& PM_LinkUp
)
1271 wolinfo
->wolopts
|= WAKE_PHY
;
1273 if (pm_config
& PM_Magic
)
1274 wolinfo
->wolopts
|= WAKE_MAGIC
;
1276 if (pm_config
& PM_WakeUp
)
1278 wolinfo
->wolopts
|= WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
;
1281 static int sc92031_ethtool_set_wol(struct net_device
*dev
,
1282 struct ethtool_wolinfo
*wolinfo
)
1284 struct sc92031_priv
*priv
= netdev_priv(dev
);
1285 void __iomem
*port_base
= priv
->port_base
;
1288 spin_lock_bh(&priv
->lock
);
1290 pm_config
= ioread32(port_base
+ PMConfig
)
1291 & ~(PM_LinkUp
| PM_Magic
| PM_WakeUp
);
1293 if (wolinfo
->wolopts
& WAKE_PHY
)
1294 pm_config
|= PM_LinkUp
;
1296 if (wolinfo
->wolopts
& WAKE_MAGIC
)
1297 pm_config
|= PM_Magic
;
1300 if (wolinfo
->wolopts
& (WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
))
1301 pm_config
|= PM_WakeUp
;
1303 priv
->pm_config
= pm_config
;
1304 iowrite32(pm_config
, port_base
+ PMConfig
);
1306 spin_unlock_bh(&priv
->lock
);
1311 static int sc92031_ethtool_nway_reset(struct net_device
*dev
)
1314 struct sc92031_priv
*priv
= netdev_priv(dev
);
1315 void __iomem
*port_base
= priv
->port_base
;
1318 spin_lock_bh(&priv
->lock
);
1320 bmcr
= _sc92031_mii_read(port_base
, MII_BMCR
);
1321 if (!(bmcr
& BMCR_ANENABLE
)) {
1326 _sc92031_mii_write(port_base
, MII_BMCR
, bmcr
| BMCR_ANRESTART
);
1329 _sc92031_mii_scan(port_base
);
1331 spin_unlock_bh(&priv
->lock
);
1336 static const char sc92031_ethtool_stats_strings
[SILAN_STATS_NUM
][ETH_GSTRING_LEN
] = {
1341 static void sc92031_ethtool_get_strings(struct net_device
*dev
,
1342 u32 stringset
, u8
*data
)
1344 if (stringset
== ETH_SS_STATS
)
1345 memcpy(data
, sc92031_ethtool_stats_strings
,
1346 SILAN_STATS_NUM
* ETH_GSTRING_LEN
);
1349 static int sc92031_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1353 return SILAN_STATS_NUM
;
1359 static void sc92031_ethtool_get_ethtool_stats(struct net_device
*dev
,
1360 struct ethtool_stats
*stats
, u64
*data
)
1362 struct sc92031_priv
*priv
= netdev_priv(dev
);
1364 spin_lock_bh(&priv
->lock
);
1365 data
[0] = priv
->tx_timeouts
;
1366 data
[1] = priv
->rx_loss
;
1367 spin_unlock_bh(&priv
->lock
);
1370 static const struct ethtool_ops sc92031_ethtool_ops
= {
1371 .get_wol
= sc92031_ethtool_get_wol
,
1372 .set_wol
= sc92031_ethtool_set_wol
,
1373 .nway_reset
= sc92031_ethtool_nway_reset
,
1374 .get_link
= ethtool_op_get_link
,
1375 .get_strings
= sc92031_ethtool_get_strings
,
1376 .get_sset_count
= sc92031_ethtool_get_sset_count
,
1377 .get_ethtool_stats
= sc92031_ethtool_get_ethtool_stats
,
1378 .get_link_ksettings
= sc92031_ethtool_get_link_ksettings
,
1379 .set_link_ksettings
= sc92031_ethtool_set_link_ksettings
,
1383 static const struct net_device_ops sc92031_netdev_ops
= {
1384 .ndo_get_stats
= sc92031_get_stats
,
1385 .ndo_start_xmit
= sc92031_start_xmit
,
1386 .ndo_open
= sc92031_open
,
1387 .ndo_stop
= sc92031_stop
,
1388 .ndo_set_rx_mode
= sc92031_set_multicast_list
,
1389 .ndo_validate_addr
= eth_validate_addr
,
1390 .ndo_set_mac_address
= eth_mac_addr
,
1391 .ndo_tx_timeout
= sc92031_tx_timeout
,
1392 #ifdef CONFIG_NET_POLL_CONTROLLER
1393 .ndo_poll_controller
= sc92031_poll_controller
,
1397 static int sc92031_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1400 void __iomem
* port_base
;
1401 struct net_device
*dev
;
1402 struct sc92031_priv
*priv
;
1406 err
= pci_enable_device(pdev
);
1407 if (unlikely(err
< 0))
1408 goto out_enable_device
;
1410 pci_set_master(pdev
);
1412 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
1413 if (unlikely(err
< 0))
1414 goto out_set_dma_mask
;
1416 err
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
1417 if (unlikely(err
< 0))
1418 goto out_set_dma_mask
;
1420 err
= pci_request_regions(pdev
, SC92031_NAME
);
1421 if (unlikely(err
< 0))
1422 goto out_request_regions
;
1424 port_base
= pci_iomap(pdev
, SC92031_USE_PIO
, 0);
1425 if (unlikely(!port_base
)) {
1430 dev
= alloc_etherdev(sizeof(struct sc92031_priv
));
1431 if (unlikely(!dev
)) {
1433 goto out_alloc_etherdev
;
1436 pci_set_drvdata(pdev
, dev
);
1437 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1439 /* faked with skb_copy_and_csum_dev */
1440 dev
->features
= NETIF_F_SG
| NETIF_F_HIGHDMA
|
1441 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
1443 dev
->netdev_ops
= &sc92031_netdev_ops
;
1444 dev
->watchdog_timeo
= TX_TIMEOUT
;
1445 dev
->ethtool_ops
= &sc92031_ethtool_ops
;
1447 priv
= netdev_priv(dev
);
1449 spin_lock_init(&priv
->lock
);
1450 priv
->port_base
= port_base
;
1452 tasklet_setup(&priv
->tasklet
, sc92031_tasklet
);
1453 /* Fudge tasklet count so the call to sc92031_enable_interrupts at
1454 * sc92031_open will work correctly */
1455 tasklet_disable_nosync(&priv
->tasklet
);
1458 iowrite32((~PM_LongWF
& ~PM_LWPTN
) | PM_Enable
, port_base
+ PMConfig
);
1460 mac0
= ioread32(port_base
+ MAC0
);
1461 mac1
= ioread32(port_base
+ MAC0
+ 4);
1462 addr
[0] = mac0
>> 24;
1463 addr
[1] = mac0
>> 16;
1464 addr
[2] = mac0
>> 8;
1466 addr
[4] = mac1
>> 8;
1468 eth_hw_addr_set(dev
, addr
);
1470 err
= register_netdev(dev
);
1472 goto out_register_netdev
;
1474 printk(KERN_INFO
"%s: SC92031 at 0x%lx, %pM, IRQ %d\n", dev
->name
,
1475 (long)pci_resource_start(pdev
, SC92031_USE_PIO
), dev
->dev_addr
,
1480 out_register_netdev
:
1483 pci_iounmap(pdev
, port_base
);
1485 pci_release_regions(pdev
);
1486 out_request_regions
:
1488 pci_disable_device(pdev
);
1493 static void sc92031_remove(struct pci_dev
*pdev
)
1495 struct net_device
*dev
= pci_get_drvdata(pdev
);
1496 struct sc92031_priv
*priv
= netdev_priv(dev
);
1497 void __iomem
* port_base
= priv
->port_base
;
1499 unregister_netdev(dev
);
1501 pci_iounmap(pdev
, port_base
);
1502 pci_release_regions(pdev
);
1503 pci_disable_device(pdev
);
1506 static int __maybe_unused
sc92031_suspend(struct device
*dev_d
)
1508 struct net_device
*dev
= dev_get_drvdata(dev_d
);
1509 struct sc92031_priv
*priv
= netdev_priv(dev
);
1511 if (!netif_running(dev
))
1514 netif_device_detach(dev
);
1516 /* Disable interrupts, stop Tx and Rx. */
1517 sc92031_disable_interrupts(dev
);
1519 spin_lock_bh(&priv
->lock
);
1521 _sc92031_disable_tx_rx(dev
);
1522 _sc92031_tx_clear(dev
);
1524 spin_unlock_bh(&priv
->lock
);
1529 static int __maybe_unused
sc92031_resume(struct device
*dev_d
)
1531 struct net_device
*dev
= dev_get_drvdata(dev_d
);
1532 struct sc92031_priv
*priv
= netdev_priv(dev
);
1534 if (!netif_running(dev
))
1537 /* Interrupts already disabled by sc92031_suspend */
1538 spin_lock_bh(&priv
->lock
);
1540 _sc92031_reset(dev
);
1542 spin_unlock_bh(&priv
->lock
);
1543 sc92031_enable_interrupts(dev
);
1545 netif_device_attach(dev
);
1547 if (netif_carrier_ok(dev
))
1548 netif_wake_queue(dev
);
1550 netif_tx_disable(dev
);
1555 static const struct pci_device_id sc92031_pci_device_id_table
[] = {
1556 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x2031) },
1557 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x8139) },
1558 { PCI_DEVICE(0x1088, 0x2031) },
1561 MODULE_DEVICE_TABLE(pci
, sc92031_pci_device_id_table
);
1563 static SIMPLE_DEV_PM_OPS(sc92031_pm_ops
, sc92031_suspend
, sc92031_resume
);
1565 static struct pci_driver sc92031_pci_driver
= {
1566 .name
= SC92031_NAME
,
1567 .id_table
= sc92031_pci_device_id_table
,
1568 .probe
= sc92031_probe
,
1569 .remove
= sc92031_remove
,
1570 .driver
.pm
= &sc92031_pm_ops
,
1573 module_pci_driver(sc92031_pci_driver
);
1574 MODULE_LICENSE("GPL");
1575 MODULE_AUTHOR("Cesar Eduardo Barros <cesarb@cesarb.net>");
1576 MODULE_DESCRIPTION("Silan SC92031 PCI Fast Ethernet Adapter driver");