1 /* Silan SC92031 PCI Fast Ethernet Adapter driver
3 * Based on vendor drivers:
4 * Silan Fast Ethernet Netcard Driver:
5 * MODULE_AUTHOR ("gaoyonghong");
6 * MODULE_DESCRIPTION ("SILAN Fast Ethernet driver");
7 * MODULE_LICENSE("GPL");
8 * 8139D Fast Ethernet driver:
9 * (C) 2002 by gaoyonghong
10 * MODULE_AUTHOR ("gaoyonghong");
11 * MODULE_DESCRIPTION ("Rsltek 8139D PCI Fast Ethernet Adapter driver");
12 * MODULE_LICENSE("GPL");
13 * Both are almost identical and seem to be based on pci-skeleton.c
15 * Rewritten for 2.6 by Cesar Eduardo Barros
17 * A datasheet for this chip can be found at
18 * http://www.silan.com.cn/english/product/pdf/SC92031AY.pdf
21 /* Note about set_mac_address: I don't know how to change the hardware
22 * matching, so you need to enable IFF_PROMISC when using it.
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/delay.h>
29 #include <linux/pci.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/netdevice.h>
32 #include <linux/etherdevice.h>
33 #include <linux/ethtool.h>
34 #include <linux/mii.h>
35 #include <linux/crc32.h>
39 #define SC92031_NAME "sc92031"
41 /* BAR 0 is MMIO, BAR 1 is PIO */
42 #ifndef SC92031_USE_BAR
43 #define SC92031_USE_BAR 0
46 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */
47 static int multicast_filter_limit
= 64;
48 module_param(multicast_filter_limit
, int, 0);
49 MODULE_PARM_DESC(multicast_filter_limit
,
50 "Maximum number of filtered multicast addresses");
53 module_param(media
, int, 0);
54 MODULE_PARM_DESC(media
, "Media type (0x00 = autodetect,"
55 " 0x01 = 10M half, 0x02 = 10M full,"
56 " 0x04 = 100M half, 0x08 = 100M full)");
58 /* Size of the in-memory receive ring. */
59 #define RX_BUF_LEN_IDX 3 /* 0==8K, 1==16K, 2==32K, 3==64K ,4==128K*/
60 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
62 /* Number of Tx descriptor registers. */
65 /* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
66 #define MAX_ETH_FRAME_SIZE 1536
68 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
69 #define TX_BUF_SIZE MAX_ETH_FRAME_SIZE
70 #define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC)
72 /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024, 7==end of packet. */
73 #define RX_FIFO_THRESH 7 /* Rx buffer level before first PCI xfer. */
75 /* Time in jiffies before concluding the transmitter is hung. */
76 #define TX_TIMEOUT (4*HZ)
78 #define SILAN_STATS_NUM 2 /* number of ETHTOOL_GSTATS */
81 #define AUTOSELECT 0x00
84 #define M100_HALF 0x04
85 #define M100_FULL 0x08
87 /* Symbolic offsets to registers. */
88 enum silan_registers
{
89 Config0
= 0x00, // Config0
90 Config1
= 0x04, // Config1
91 RxBufWPtr
= 0x08, // Rx buffer writer poiter
92 IntrStatus
= 0x0C, // Interrupt status
93 IntrMask
= 0x10, // Interrupt mask
94 RxbufAddr
= 0x14, // Rx buffer start address
95 RxBufRPtr
= 0x18, // Rx buffer read pointer
96 Txstatusall
= 0x1C, // Transmit status of all descriptors
97 TxStatus0
= 0x20, // Transmit status (Four 32bit registers).
98 TxAddr0
= 0x30, // Tx descriptors (also four 32bit).
99 RxConfig
= 0x40, // Rx configuration
100 MAC0
= 0x44, // Ethernet hardware address.
101 MAR0
= 0x4C, // Multicast filter.
102 RxStatus0
= 0x54, // Rx status
103 TxConfig
= 0x5C, // Tx configuration
104 PhyCtrl
= 0x60, // physical control
105 FlowCtrlConfig
= 0x64, // flow control
106 Miicmd0
= 0x68, // Mii command0 register
107 Miicmd1
= 0x6C, // Mii command1 register
108 Miistatus
= 0x70, // Mii status register
109 Timercnt
= 0x74, // Timer counter register
110 TimerIntr
= 0x78, // Timer interrupt register
111 PMConfig
= 0x7C, // Power Manager configuration
112 CRC0
= 0x80, // Power Manager CRC ( Two 32bit regisers)
113 Wakeup0
= 0x88, // power Manager wakeup( Eight 64bit regiser)
114 LSBCRC0
= 0xC8, // power Manager LSBCRC(Two 32bit regiser)
121 #define MII_OutputStatus 24
123 #define PHY_16_JAB_ENB 0x1000
124 #define PHY_16_PORT_ENB 0x1
126 enum IntrStatusBits
{
127 LinkFail
= 0x80000000,
129 TimeOut
= 0x20000000,
133 IntrBits
= LinkFail
|LinkOK
|TimeOut
|RxOverflow
|RxOK
|TxOK
,
137 TxCarrierLost
= 0x20000000,
138 TxAborted
= 0x10000000,
139 TxOutOfWindow
= 0x08000000,
141 EarlyTxThresShift
= 16,
148 RxStatesOK
= 0x80000,
149 RxBadAlign
= 0x40000,
150 RxHugeFrame
= 0x20000,
151 RxSmallFrame
= 0x10000,
154 Rx_Broadcast
= 0x2000,
155 Rx_Multicast
= 0x1000,
156 RxAddrMatch
= 0x0800,
161 RxFullDx
= 0x80000000,
163 RxSmall
= 0x20000000,
166 RxAllphys
= 0x04000000,
167 RxMulticast
= 0x02000000,
168 RxBroadcast
= 0x01000000,
169 RxLoopBack
= (1 << 23) | (1 << 22),
170 LowThresholdShift
= 12,
171 HighThresholdShift
= 2,
175 TxFullDx
= 0x80000000,
177 TxEnbPad
= 0x20000000,
178 TxEnbHuge
= 0x10000000,
179 TxEnbFCS
= 0x08000000,
180 TxNoBackOff
= 0x04000000,
181 TxEnbPrem
= 0x02000000,
182 TxCareLostCrs
= 0x1000000,
183 TxExdCollNum
= 0xf00000,
184 TxDataRate
= 0x80000,
187 enum PhyCtrlconfigbits
{
188 PhyCtrlAne
= 0x80000000,
189 PhyCtrlSpd100
= 0x40000000,
190 PhyCtrlSpd10
= 0x20000000,
191 PhyCtrlPhyBaseAddr
= 0x1f000000,
192 PhyCtrlDux
= 0x800000,
193 PhyCtrlReset
= 0x400000,
196 enum FlowCtrlConfigBits
{
197 FlowCtrlFullDX
= 0x80000000,
198 FlowCtrlEnb
= 0x40000000,
202 Cfg0_Reset
= 0x80000000,
203 Cfg0_Anaoff
= 0x40000000,
204 Cfg0_LDPS
= 0x20000000,
208 Cfg1_EarlyRx
= 1 << 31,
209 Cfg1_EarlyTx
= 1 << 30,
220 Mii_Divider
= 0x20000000,
221 Mii_WRITE
= 0x400000,
225 Mii_Drvmod
= 0x40000,
233 Mii_StatusBusy
= 0x80000000,
240 PM_LANWake
= 1 << 28,
241 PM_LWPTN
= (1 << 27 | 1<< 26),
247 * priv->lock protects most of the fields of priv and most of the
248 * hardware registers. It does not have to protect against softirqs
249 * between sc92031_disable_interrupts and sc92031_enable_interrupts;
250 * it also does not need to be used in ->open and ->stop while the
251 * device interrupts are off.
252 * Not having to protect against softirqs is very useful due to heavy
253 * use of mdelay() at _sc92031_reset.
254 * Functions prefixed with _sc92031_ must be called with the lock held;
255 * functions prefixed with sc92031_ must be called without the lock held.
256 * Use mmiowb() before unlocking if the hardware was written to.
259 /* Locking rules for the interrupt:
260 * - the interrupt and the tasklet never run at the same time
261 * - neither run between sc92031_disable_interrupts and
262 * sc92031_enable_interrupt
265 struct sc92031_priv
{
268 void __iomem
*port_base
;
269 /* pci device structure */
270 struct pci_dev
*pdev
;
272 struct tasklet_struct tasklet
;
274 /* CPU address of rx ring */
276 /* PCI address of rx ring */
277 dma_addr_t rx_ring_dma_addr
;
278 /* PCI address of rx ring read pointer */
279 dma_addr_t rx_ring_tail
;
281 /* tx ring write index */
283 /* tx ring read index */
285 /* CPU address of tx bounce buffer */
287 /* PCI address of tx bounce buffer */
288 dma_addr_t tx_bufs_dma_addr
;
290 /* copies of some hardware registers */
297 /* copy of some flags from dev->flags */
298 unsigned int mc_flags
;
300 /* for ETHTOOL_GSTATS */
304 /* for dev->get_stats */
308 /* I don't know which registers can be safely read; however, I can guess
309 * MAC0 is one of them. */
310 static inline void _sc92031_dummy_read(void __iomem
*port_base
)
312 ioread32(port_base
+ MAC0
);
315 static u32
_sc92031_mii_wait(void __iomem
*port_base
)
321 mii_status
= ioread32(port_base
+ Miistatus
);
322 } while (mii_status
& Mii_StatusBusy
);
327 static u32
_sc92031_mii_cmd(void __iomem
*port_base
, u32 cmd0
, u32 cmd1
)
329 iowrite32(Mii_Divider
, port_base
+ Miicmd0
);
331 _sc92031_mii_wait(port_base
);
333 iowrite32(cmd1
, port_base
+ Miicmd1
);
334 iowrite32(Mii_Divider
| cmd0
, port_base
+ Miicmd0
);
336 return _sc92031_mii_wait(port_base
);
339 static void _sc92031_mii_scan(void __iomem
*port_base
)
341 _sc92031_mii_cmd(port_base
, Mii_SCAN
, 0x1 << 6);
344 static u16
_sc92031_mii_read(void __iomem
*port_base
, unsigned reg
)
346 return _sc92031_mii_cmd(port_base
, Mii_READ
, reg
<< 6) >> 13;
349 static void _sc92031_mii_write(void __iomem
*port_base
, unsigned reg
, u16 val
)
351 _sc92031_mii_cmd(port_base
, Mii_WRITE
, (reg
<< 6) | ((u32
)val
<< 11));
354 static void sc92031_disable_interrupts(struct net_device
*dev
)
356 struct sc92031_priv
*priv
= netdev_priv(dev
);
357 void __iomem
*port_base
= priv
->port_base
;
359 /* tell the tasklet/interrupt not to enable interrupts */
360 atomic_set(&priv
->intr_mask
, 0);
363 /* stop interrupts */
364 iowrite32(0, port_base
+ IntrMask
);
365 _sc92031_dummy_read(port_base
);
368 /* wait for any concurrent interrupt/tasklet to finish */
369 synchronize_irq(dev
->irq
);
370 tasklet_disable(&priv
->tasklet
);
373 static void sc92031_enable_interrupts(struct net_device
*dev
)
375 struct sc92031_priv
*priv
= netdev_priv(dev
);
376 void __iomem
*port_base
= priv
->port_base
;
378 tasklet_enable(&priv
->tasklet
);
380 atomic_set(&priv
->intr_mask
, IntrBits
);
383 iowrite32(IntrBits
, port_base
+ IntrMask
);
387 static void _sc92031_disable_tx_rx(struct net_device
*dev
)
389 struct sc92031_priv
*priv
= netdev_priv(dev
);
390 void __iomem
*port_base
= priv
->port_base
;
392 priv
->rx_config
&= ~RxEnb
;
393 priv
->tx_config
&= ~TxEnb
;
394 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
395 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
398 static void _sc92031_enable_tx_rx(struct net_device
*dev
)
400 struct sc92031_priv
*priv
= netdev_priv(dev
);
401 void __iomem
*port_base
= priv
->port_base
;
403 priv
->rx_config
|= RxEnb
;
404 priv
->tx_config
|= TxEnb
;
405 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
406 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
409 static void _sc92031_tx_clear(struct net_device
*dev
)
411 struct sc92031_priv
*priv
= netdev_priv(dev
);
413 while (priv
->tx_head
- priv
->tx_tail
> 0) {
415 dev
->stats
.tx_dropped
++;
417 priv
->tx_head
= priv
->tx_tail
= 0;
420 static void _sc92031_set_mar(struct net_device
*dev
)
422 struct sc92031_priv
*priv
= netdev_priv(dev
);
423 void __iomem
*port_base
= priv
->port_base
;
424 u32 mar0
= 0, mar1
= 0;
426 if ((dev
->flags
& IFF_PROMISC
) ||
427 netdev_mc_count(dev
) > multicast_filter_limit
||
428 (dev
->flags
& IFF_ALLMULTI
))
429 mar0
= mar1
= 0xffffffff;
430 else if (dev
->flags
& IFF_MULTICAST
) {
431 struct netdev_hw_addr
*ha
;
433 netdev_for_each_mc_addr(ha
, dev
) {
437 crc
= ~ether_crc(ETH_ALEN
, ha
->addr
);
440 if (crc
& 0x01) bit
|= 0x02;
441 if (crc
& 0x02) bit
|= 0x01;
442 if (crc
& 0x10) bit
|= 0x20;
443 if (crc
& 0x20) bit
|= 0x10;
444 if (crc
& 0x40) bit
|= 0x08;
445 if (crc
& 0x80) bit
|= 0x04;
448 mar0
|= 0x1 << (bit
- 32);
454 iowrite32(mar0
, port_base
+ MAR0
);
455 iowrite32(mar1
, port_base
+ MAR0
+ 4);
458 static void _sc92031_set_rx_config(struct net_device
*dev
)
460 struct sc92031_priv
*priv
= netdev_priv(dev
);
461 void __iomem
*port_base
= priv
->port_base
;
462 unsigned int old_mc_flags
;
463 u32 rx_config_bits
= 0;
465 old_mc_flags
= priv
->mc_flags
;
467 if (dev
->flags
& IFF_PROMISC
)
468 rx_config_bits
|= RxSmall
| RxHuge
| RxErr
| RxBroadcast
469 | RxMulticast
| RxAllphys
;
471 if (dev
->flags
& (IFF_ALLMULTI
| IFF_MULTICAST
))
472 rx_config_bits
|= RxMulticast
;
474 if (dev
->flags
& IFF_BROADCAST
)
475 rx_config_bits
|= RxBroadcast
;
477 priv
->rx_config
&= ~(RxSmall
| RxHuge
| RxErr
| RxBroadcast
478 | RxMulticast
| RxAllphys
);
479 priv
->rx_config
|= rx_config_bits
;
481 priv
->mc_flags
= dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
482 | IFF_MULTICAST
| IFF_BROADCAST
);
484 if (netif_carrier_ok(dev
) && priv
->mc_flags
!= old_mc_flags
)
485 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
488 static bool _sc92031_check_media(struct net_device
*dev
)
490 struct sc92031_priv
*priv
= netdev_priv(dev
);
491 void __iomem
*port_base
= priv
->port_base
;
494 bmsr
= _sc92031_mii_read(port_base
, MII_BMSR
);
496 if (bmsr
& BMSR_LSTATUS
) {
497 bool speed_100
, duplex_full
;
498 u32 flow_ctrl_config
= 0;
499 u16 output_status
= _sc92031_mii_read(port_base
,
501 _sc92031_mii_scan(port_base
);
503 speed_100
= output_status
& 0x2;
504 duplex_full
= output_status
& 0x4;
506 /* Initial Tx/Rx configuration */
507 priv
->rx_config
= (0x40 << LowThresholdShift
) | (0x1c0 << HighThresholdShift
);
508 priv
->tx_config
= 0x48800000;
510 /* NOTE: vendor driver had dead code here to enable tx padding */
513 priv
->tx_config
|= 0x80000;
516 _sc92031_set_rx_config(dev
);
519 priv
->rx_config
|= RxFullDx
;
520 priv
->tx_config
|= TxFullDx
;
521 flow_ctrl_config
= FlowCtrlFullDX
| FlowCtrlEnb
;
523 priv
->rx_config
&= ~RxFullDx
;
524 priv
->tx_config
&= ~TxFullDx
;
527 _sc92031_set_mar(dev
);
528 _sc92031_set_rx_config(dev
);
529 _sc92031_enable_tx_rx(dev
);
530 iowrite32(flow_ctrl_config
, port_base
+ FlowCtrlConfig
);
532 netif_carrier_on(dev
);
534 if (printk_ratelimit())
535 printk(KERN_INFO
"%s: link up, %sMbps, %s-duplex\n",
537 speed_100
? "100" : "10",
538 duplex_full
? "full" : "half");
541 _sc92031_mii_scan(port_base
);
543 netif_carrier_off(dev
);
545 _sc92031_disable_tx_rx(dev
);
547 if (printk_ratelimit())
548 printk(KERN_INFO
"%s: link down\n", dev
->name
);
553 static void _sc92031_phy_reset(struct net_device
*dev
)
555 struct sc92031_priv
*priv
= netdev_priv(dev
);
556 void __iomem
*port_base
= priv
->port_base
;
559 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
560 phy_ctrl
&= ~(PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
);
561 phy_ctrl
|= PhyCtrlAne
| PhyCtrlReset
;
566 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
569 phy_ctrl
|= PhyCtrlSpd10
;
572 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd10
;
575 phy_ctrl
|= PhyCtrlSpd100
;
578 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
582 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
585 phy_ctrl
&= ~PhyCtrlReset
;
586 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
589 _sc92031_mii_write(port_base
, MII_JAB
,
590 PHY_16_JAB_ENB
| PHY_16_PORT_ENB
);
591 _sc92031_mii_scan(port_base
);
593 netif_carrier_off(dev
);
594 netif_stop_queue(dev
);
597 static void _sc92031_reset(struct net_device
*dev
)
599 struct sc92031_priv
*priv
= netdev_priv(dev
);
600 void __iomem
*port_base
= priv
->port_base
;
603 iowrite32(0, port_base
+ PMConfig
);
605 /* soft reset the chip */
606 iowrite32(Cfg0_Reset
, port_base
+ Config0
);
609 iowrite32(0, port_base
+ Config0
);
612 /* disable interrupts */
613 iowrite32(0, port_base
+ IntrMask
);
615 /* clear multicast address */
616 iowrite32(0, port_base
+ MAR0
);
617 iowrite32(0, port_base
+ MAR0
+ 4);
620 iowrite32(priv
->rx_ring_dma_addr
, port_base
+ RxbufAddr
);
621 priv
->rx_ring_tail
= priv
->rx_ring_dma_addr
;
624 _sc92031_tx_clear(dev
);
626 /* clear old register values */
627 priv
->intr_status
= 0;
628 atomic_set(&priv
->intr_mask
, 0);
633 /* configure rx buffer size */
634 /* NOTE: vendor driver had dead code here to enable early tx/rx */
635 iowrite32(Cfg1_Rcv64K
, port_base
+ Config1
);
637 _sc92031_phy_reset(dev
);
638 _sc92031_check_media(dev
);
640 /* calculate rx fifo overflow */
644 iowrite32(priv
->pm_config
, port_base
+ PMConfig
);
646 /* clear intr register */
647 ioread32(port_base
+ IntrStatus
);
650 static void _sc92031_tx_tasklet(struct net_device
*dev
)
652 struct sc92031_priv
*priv
= netdev_priv(dev
);
653 void __iomem
*port_base
= priv
->port_base
;
655 unsigned old_tx_tail
;
659 old_tx_tail
= priv
->tx_tail
;
660 while (priv
->tx_head
- priv
->tx_tail
> 0) {
661 entry
= priv
->tx_tail
% NUM_TX_DESC
;
662 tx_status
= ioread32(port_base
+ TxStatus0
+ entry
* 4);
664 if (!(tx_status
& (TxStatOK
| TxUnderrun
| TxAborted
)))
669 if (tx_status
& TxStatOK
) {
670 dev
->stats
.tx_bytes
+= tx_status
& 0x1fff;
671 dev
->stats
.tx_packets
++;
672 /* Note: TxCarrierLost is always asserted at 100mbps. */
673 dev
->stats
.collisions
+= (tx_status
>> 22) & 0xf;
676 if (tx_status
& (TxOutOfWindow
| TxAborted
)) {
677 dev
->stats
.tx_errors
++;
679 if (tx_status
& TxAborted
)
680 dev
->stats
.tx_aborted_errors
++;
682 if (tx_status
& TxCarrierLost
)
683 dev
->stats
.tx_carrier_errors
++;
685 if (tx_status
& TxOutOfWindow
)
686 dev
->stats
.tx_window_errors
++;
689 if (tx_status
& TxUnderrun
)
690 dev
->stats
.tx_fifo_errors
++;
693 if (priv
->tx_tail
!= old_tx_tail
)
694 if (netif_queue_stopped(dev
))
695 netif_wake_queue(dev
);
698 static void _sc92031_rx_tasklet_error(struct net_device
*dev
,
699 u32 rx_status
, unsigned rx_size
)
701 if(rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) || rx_size
< 16) {
702 dev
->stats
.rx_errors
++;
703 dev
->stats
.rx_length_errors
++;
706 if (!(rx_status
& RxStatesOK
)) {
707 dev
->stats
.rx_errors
++;
709 if (rx_status
& (RxHugeFrame
| RxSmallFrame
))
710 dev
->stats
.rx_length_errors
++;
712 if (rx_status
& RxBadAlign
)
713 dev
->stats
.rx_frame_errors
++;
715 if (!(rx_status
& RxCRCOK
))
716 dev
->stats
.rx_crc_errors
++;
718 struct sc92031_priv
*priv
= netdev_priv(dev
);
723 static void _sc92031_rx_tasklet(struct net_device
*dev
)
725 struct sc92031_priv
*priv
= netdev_priv(dev
);
726 void __iomem
*port_base
= priv
->port_base
;
728 dma_addr_t rx_ring_head
;
730 unsigned rx_ring_offset
;
731 void *rx_ring
= priv
->rx_ring
;
733 rx_ring_head
= ioread32(port_base
+ RxBufWPtr
);
736 /* rx_ring_head is only 17 bits in the RxBufWPtr register.
737 * we need to change it to 32 bits physical address
739 rx_ring_head
&= (dma_addr_t
)(RX_BUF_LEN
- 1);
740 rx_ring_head
|= priv
->rx_ring_dma_addr
& ~(dma_addr_t
)(RX_BUF_LEN
- 1);
741 if (rx_ring_head
< priv
->rx_ring_dma_addr
)
742 rx_ring_head
+= RX_BUF_LEN
;
744 if (rx_ring_head
>= priv
->rx_ring_tail
)
745 rx_len
= rx_ring_head
- priv
->rx_ring_tail
;
747 rx_len
= RX_BUF_LEN
- (priv
->rx_ring_tail
- rx_ring_head
);
752 if (unlikely(rx_len
> RX_BUF_LEN
)) {
753 if (printk_ratelimit())
754 printk(KERN_ERR
"%s: rx packets length > rx buffer\n",
759 rx_ring_offset
= (priv
->rx_ring_tail
- priv
->rx_ring_dma_addr
) % RX_BUF_LEN
;
763 unsigned rx_size
, rx_size_align
, pkt_size
;
766 rx_status
= le32_to_cpup((__le32
*)(rx_ring
+ rx_ring_offset
));
769 rx_size
= rx_status
>> 20;
770 rx_size_align
= (rx_size
+ 3) & ~3; // for 4 bytes aligned
771 pkt_size
= rx_size
- 4; // Omit the four octet CRC from the length.
773 rx_ring_offset
= (rx_ring_offset
+ 4) % RX_BUF_LEN
;
775 if (unlikely(rx_status
== 0 ||
776 rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) ||
778 !(rx_status
& RxStatesOK
))) {
779 _sc92031_rx_tasklet_error(dev
, rx_status
, rx_size
);
783 if (unlikely(rx_size_align
+ 4 > rx_len
)) {
784 if (printk_ratelimit())
785 printk(KERN_ERR
"%s: rx_len is too small\n", dev
->name
);
789 rx_len
-= rx_size_align
+ 4;
791 skb
= netdev_alloc_skb_ip_align(dev
, pkt_size
);
792 if (unlikely(!skb
)) {
793 if (printk_ratelimit())
794 printk(KERN_ERR
"%s: Couldn't allocate a skb_buff for a packet of size %u\n",
795 dev
->name
, pkt_size
);
799 if ((rx_ring_offset
+ pkt_size
) > RX_BUF_LEN
) {
800 memcpy(skb_put(skb
, RX_BUF_LEN
- rx_ring_offset
),
801 rx_ring
+ rx_ring_offset
, RX_BUF_LEN
- rx_ring_offset
);
802 memcpy(skb_put(skb
, pkt_size
- (RX_BUF_LEN
- rx_ring_offset
)),
803 rx_ring
, pkt_size
- (RX_BUF_LEN
- rx_ring_offset
));
805 memcpy(skb_put(skb
, pkt_size
), rx_ring
+ rx_ring_offset
, pkt_size
);
808 skb
->protocol
= eth_type_trans(skb
, dev
);
811 dev
->stats
.rx_bytes
+= pkt_size
;
812 dev
->stats
.rx_packets
++;
814 if (rx_status
& Rx_Multicast
)
815 dev
->stats
.multicast
++;
818 rx_ring_offset
= (rx_ring_offset
+ rx_size_align
) % RX_BUF_LEN
;
822 priv
->rx_ring_tail
= rx_ring_head
;
823 iowrite32(priv
->rx_ring_tail
, port_base
+ RxBufRPtr
);
826 static void _sc92031_link_tasklet(struct net_device
*dev
)
828 if (_sc92031_check_media(dev
))
829 netif_wake_queue(dev
);
831 netif_stop_queue(dev
);
832 dev
->stats
.tx_carrier_errors
++;
836 static void sc92031_tasklet(unsigned long data
)
838 struct net_device
*dev
= (struct net_device
*)data
;
839 struct sc92031_priv
*priv
= netdev_priv(dev
);
840 void __iomem
*port_base
= priv
->port_base
;
841 u32 intr_status
, intr_mask
;
843 intr_status
= priv
->intr_status
;
845 spin_lock(&priv
->lock
);
847 if (unlikely(!netif_running(dev
)))
850 if (intr_status
& TxOK
)
851 _sc92031_tx_tasklet(dev
);
853 if (intr_status
& RxOK
)
854 _sc92031_rx_tasklet(dev
);
856 if (intr_status
& RxOverflow
)
857 dev
->stats
.rx_errors
++;
859 if (intr_status
& TimeOut
) {
860 dev
->stats
.rx_errors
++;
861 dev
->stats
.rx_length_errors
++;
864 if (intr_status
& (LinkFail
| LinkOK
))
865 _sc92031_link_tasklet(dev
);
868 intr_mask
= atomic_read(&priv
->intr_mask
);
871 iowrite32(intr_mask
, port_base
+ IntrMask
);
874 spin_unlock(&priv
->lock
);
877 static irqreturn_t
sc92031_interrupt(int irq
, void *dev_id
)
879 struct net_device
*dev
= dev_id
;
880 struct sc92031_priv
*priv
= netdev_priv(dev
);
881 void __iomem
*port_base
= priv
->port_base
;
882 u32 intr_status
, intr_mask
;
884 /* mask interrupts before clearing IntrStatus */
885 iowrite32(0, port_base
+ IntrMask
);
886 _sc92031_dummy_read(port_base
);
888 intr_status
= ioread32(port_base
+ IntrStatus
);
889 if (unlikely(intr_status
== 0xffffffff))
890 return IRQ_NONE
; // hardware has gone missing
892 intr_status
&= IntrBits
;
896 priv
->intr_status
= intr_status
;
897 tasklet_schedule(&priv
->tasklet
);
902 intr_mask
= atomic_read(&priv
->intr_mask
);
905 iowrite32(intr_mask
, port_base
+ IntrMask
);
911 static struct net_device_stats
*sc92031_get_stats(struct net_device
*dev
)
913 struct sc92031_priv
*priv
= netdev_priv(dev
);
914 void __iomem
*port_base
= priv
->port_base
;
916 // FIXME I do not understand what is this trying to do.
917 if (netif_running(dev
)) {
920 spin_lock_bh(&priv
->lock
);
922 /* Update the error count. */
923 temp
= (ioread32(port_base
+ RxStatus0
) >> 16) & 0xffff;
925 if (temp
== 0xffff) {
926 priv
->rx_value
+= temp
;
927 dev
->stats
.rx_fifo_errors
= priv
->rx_value
;
929 dev
->stats
.rx_fifo_errors
= temp
+ priv
->rx_value
;
931 spin_unlock_bh(&priv
->lock
);
937 static netdev_tx_t
sc92031_start_xmit(struct sk_buff
*skb
,
938 struct net_device
*dev
)
940 struct sc92031_priv
*priv
= netdev_priv(dev
);
941 void __iomem
*port_base
= priv
->port_base
;
946 if (unlikely(skb
->len
> TX_BUF_SIZE
)) {
947 dev
->stats
.tx_dropped
++;
951 spin_lock(&priv
->lock
);
953 if (unlikely(!netif_carrier_ok(dev
))) {
954 dev
->stats
.tx_dropped
++;
958 BUG_ON(priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
);
960 entry
= priv
->tx_head
++ % NUM_TX_DESC
;
962 skb_copy_and_csum_dev(skb
, priv
->tx_bufs
+ entry
* TX_BUF_SIZE
);
965 if (len
< ETH_ZLEN
) {
966 memset(priv
->tx_bufs
+ entry
* TX_BUF_SIZE
+ len
,
976 tx_status
= 0x30000 | len
;
978 tx_status
= 0x50000 | len
;
980 iowrite32(priv
->tx_bufs_dma_addr
+ entry
* TX_BUF_SIZE
,
981 port_base
+ TxAddr0
+ entry
* 4);
982 iowrite32(tx_status
, port_base
+ TxStatus0
+ entry
* 4);
985 if (priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
)
986 netif_stop_queue(dev
);
989 spin_unlock(&priv
->lock
);
997 static int sc92031_open(struct net_device
*dev
)
1000 struct sc92031_priv
*priv
= netdev_priv(dev
);
1001 struct pci_dev
*pdev
= priv
->pdev
;
1003 priv
->rx_ring
= pci_alloc_consistent(pdev
, RX_BUF_LEN
,
1004 &priv
->rx_ring_dma_addr
);
1005 if (unlikely(!priv
->rx_ring
)) {
1007 goto out_alloc_rx_ring
;
1010 priv
->tx_bufs
= pci_alloc_consistent(pdev
, TX_BUF_TOT_LEN
,
1011 &priv
->tx_bufs_dma_addr
);
1012 if (unlikely(!priv
->tx_bufs
)) {
1014 goto out_alloc_tx_bufs
;
1016 priv
->tx_head
= priv
->tx_tail
= 0;
1018 err
= request_irq(pdev
->irq
, sc92031_interrupt
,
1019 IRQF_SHARED
, dev
->name
, dev
);
1020 if (unlikely(err
< 0))
1021 goto out_request_irq
;
1023 priv
->pm_config
= 0;
1025 /* Interrupts already disabled by sc92031_stop or sc92031_probe */
1026 spin_lock_bh(&priv
->lock
);
1028 _sc92031_reset(dev
);
1031 spin_unlock_bh(&priv
->lock
);
1032 sc92031_enable_interrupts(dev
);
1034 if (netif_carrier_ok(dev
))
1035 netif_start_queue(dev
);
1037 netif_tx_disable(dev
);
1042 pci_free_consistent(pdev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1043 priv
->tx_bufs_dma_addr
);
1045 pci_free_consistent(pdev
, RX_BUF_LEN
, priv
->rx_ring
,
1046 priv
->rx_ring_dma_addr
);
1051 static int sc92031_stop(struct net_device
*dev
)
1053 struct sc92031_priv
*priv
= netdev_priv(dev
);
1054 struct pci_dev
*pdev
= priv
->pdev
;
1056 netif_tx_disable(dev
);
1058 /* Disable interrupts, stop Tx and Rx. */
1059 sc92031_disable_interrupts(dev
);
1061 spin_lock_bh(&priv
->lock
);
1063 _sc92031_disable_tx_rx(dev
);
1064 _sc92031_tx_clear(dev
);
1067 spin_unlock_bh(&priv
->lock
);
1069 free_irq(pdev
->irq
, dev
);
1070 pci_free_consistent(pdev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1071 priv
->tx_bufs_dma_addr
);
1072 pci_free_consistent(pdev
, RX_BUF_LEN
, priv
->rx_ring
,
1073 priv
->rx_ring_dma_addr
);
1078 static void sc92031_set_multicast_list(struct net_device
*dev
)
1080 struct sc92031_priv
*priv
= netdev_priv(dev
);
1082 spin_lock_bh(&priv
->lock
);
1084 _sc92031_set_mar(dev
);
1085 _sc92031_set_rx_config(dev
);
1088 spin_unlock_bh(&priv
->lock
);
1091 static void sc92031_tx_timeout(struct net_device
*dev
)
1093 struct sc92031_priv
*priv
= netdev_priv(dev
);
1095 /* Disable interrupts by clearing the interrupt mask.*/
1096 sc92031_disable_interrupts(dev
);
1098 spin_lock(&priv
->lock
);
1100 priv
->tx_timeouts
++;
1102 _sc92031_reset(dev
);
1105 spin_unlock(&priv
->lock
);
1107 /* enable interrupts */
1108 sc92031_enable_interrupts(dev
);
1110 if (netif_carrier_ok(dev
))
1111 netif_wake_queue(dev
);
1114 #ifdef CONFIG_NET_POLL_CONTROLLER
1115 static void sc92031_poll_controller(struct net_device
*dev
)
1117 disable_irq(dev
->irq
);
1118 if (sc92031_interrupt(dev
->irq
, dev
) != IRQ_NONE
)
1119 sc92031_tasklet((unsigned long)dev
);
1120 enable_irq(dev
->irq
);
1124 static int sc92031_ethtool_get_settings(struct net_device
*dev
,
1125 struct ethtool_cmd
*cmd
)
1127 struct sc92031_priv
*priv
= netdev_priv(dev
);
1128 void __iomem
*port_base
= priv
->port_base
;
1133 spin_lock_bh(&priv
->lock
);
1135 phy_address
= ioread32(port_base
+ Miicmd1
) >> 27;
1136 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
1138 output_status
= _sc92031_mii_read(port_base
, MII_OutputStatus
);
1139 _sc92031_mii_scan(port_base
);
1142 spin_unlock_bh(&priv
->lock
);
1144 cmd
->supported
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
1145 | SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
1146 | SUPPORTED_Autoneg
| SUPPORTED_TP
| SUPPORTED_MII
;
1148 cmd
->advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
1150 if ((phy_ctrl
& (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1151 == (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1152 cmd
->advertising
|= ADVERTISED_Autoneg
;
1154 if ((phy_ctrl
& PhyCtrlSpd10
) == PhyCtrlSpd10
)
1155 cmd
->advertising
|= ADVERTISED_10baseT_Half
;
1157 if ((phy_ctrl
& (PhyCtrlSpd10
| PhyCtrlDux
))
1158 == (PhyCtrlSpd10
| PhyCtrlDux
))
1159 cmd
->advertising
|= ADVERTISED_10baseT_Full
;
1161 if ((phy_ctrl
& PhyCtrlSpd100
) == PhyCtrlSpd100
)
1162 cmd
->advertising
|= ADVERTISED_100baseT_Half
;
1164 if ((phy_ctrl
& (PhyCtrlSpd100
| PhyCtrlDux
))
1165 == (PhyCtrlSpd100
| PhyCtrlDux
))
1166 cmd
->advertising
|= ADVERTISED_100baseT_Full
;
1168 if (phy_ctrl
& PhyCtrlAne
)
1169 cmd
->advertising
|= ADVERTISED_Autoneg
;
1171 ethtool_cmd_speed_set(cmd
,
1172 (output_status
& 0x2) ? SPEED_100
: SPEED_10
);
1173 cmd
->duplex
= (output_status
& 0x4) ? DUPLEX_FULL
: DUPLEX_HALF
;
1174 cmd
->port
= PORT_MII
;
1175 cmd
->phy_address
= phy_address
;
1176 cmd
->transceiver
= XCVR_INTERNAL
;
1177 cmd
->autoneg
= (phy_ctrl
& PhyCtrlAne
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
1182 static int sc92031_ethtool_set_settings(struct net_device
*dev
,
1183 struct ethtool_cmd
*cmd
)
1185 struct sc92031_priv
*priv
= netdev_priv(dev
);
1186 void __iomem
*port_base
= priv
->port_base
;
1187 u32 speed
= ethtool_cmd_speed(cmd
);
1191 if (!(speed
== SPEED_10
|| speed
== SPEED_100
))
1193 if (!(cmd
->duplex
== DUPLEX_HALF
|| cmd
->duplex
== DUPLEX_FULL
))
1195 if (!(cmd
->port
== PORT_MII
))
1197 if (!(cmd
->phy_address
== 0x1f))
1199 if (!(cmd
->transceiver
== XCVR_INTERNAL
))
1201 if (!(cmd
->autoneg
== AUTONEG_DISABLE
|| cmd
->autoneg
== AUTONEG_ENABLE
))
1204 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
1205 if (!(cmd
->advertising
& (ADVERTISED_Autoneg
1206 | ADVERTISED_100baseT_Full
1207 | ADVERTISED_100baseT_Half
1208 | ADVERTISED_10baseT_Full
1209 | ADVERTISED_10baseT_Half
)))
1212 phy_ctrl
= PhyCtrlAne
;
1214 // FIXME: I'm not sure what the original code was trying to do
1215 if (cmd
->advertising
& ADVERTISED_Autoneg
)
1216 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
1217 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
1218 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
1219 if (cmd
->advertising
& ADVERTISED_100baseT_Half
)
1220 phy_ctrl
|= PhyCtrlSpd100
;
1221 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
1222 phy_ctrl
|= PhyCtrlSpd10
| PhyCtrlDux
;
1223 if (cmd
->advertising
& ADVERTISED_10baseT_Half
)
1224 phy_ctrl
|= PhyCtrlSpd10
;
1226 // FIXME: Whole branch guessed
1229 if (speed
== SPEED_10
)
1230 phy_ctrl
|= PhyCtrlSpd10
;
1231 else /* cmd->speed == SPEED_100 */
1232 phy_ctrl
|= PhyCtrlSpd100
;
1234 if (cmd
->duplex
== DUPLEX_FULL
)
1235 phy_ctrl
|= PhyCtrlDux
;
1238 spin_lock_bh(&priv
->lock
);
1240 old_phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
1241 phy_ctrl
|= old_phy_ctrl
& ~(PhyCtrlAne
| PhyCtrlDux
1242 | PhyCtrlSpd100
| PhyCtrlSpd10
);
1243 if (phy_ctrl
!= old_phy_ctrl
)
1244 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
1246 spin_unlock_bh(&priv
->lock
);
1251 static void sc92031_ethtool_get_wol(struct net_device
*dev
,
1252 struct ethtool_wolinfo
*wolinfo
)
1254 struct sc92031_priv
*priv
= netdev_priv(dev
);
1255 void __iomem
*port_base
= priv
->port_base
;
1258 spin_lock_bh(&priv
->lock
);
1259 pm_config
= ioread32(port_base
+ PMConfig
);
1260 spin_unlock_bh(&priv
->lock
);
1263 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
1264 | WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
;
1265 wolinfo
->wolopts
= 0;
1267 if (pm_config
& PM_LinkUp
)
1268 wolinfo
->wolopts
|= WAKE_PHY
;
1270 if (pm_config
& PM_Magic
)
1271 wolinfo
->wolopts
|= WAKE_MAGIC
;
1273 if (pm_config
& PM_WakeUp
)
1275 wolinfo
->wolopts
|= WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
;
1278 static int sc92031_ethtool_set_wol(struct net_device
*dev
,
1279 struct ethtool_wolinfo
*wolinfo
)
1281 struct sc92031_priv
*priv
= netdev_priv(dev
);
1282 void __iomem
*port_base
= priv
->port_base
;
1285 spin_lock_bh(&priv
->lock
);
1287 pm_config
= ioread32(port_base
+ PMConfig
)
1288 & ~(PM_LinkUp
| PM_Magic
| PM_WakeUp
);
1290 if (wolinfo
->wolopts
& WAKE_PHY
)
1291 pm_config
|= PM_LinkUp
;
1293 if (wolinfo
->wolopts
& WAKE_MAGIC
)
1294 pm_config
|= PM_Magic
;
1297 if (wolinfo
->wolopts
& (WAKE_UCAST
| WAKE_MCAST
| WAKE_BCAST
))
1298 pm_config
|= PM_WakeUp
;
1300 priv
->pm_config
= pm_config
;
1301 iowrite32(pm_config
, port_base
+ PMConfig
);
1304 spin_unlock_bh(&priv
->lock
);
1309 static int sc92031_ethtool_nway_reset(struct net_device
*dev
)
1312 struct sc92031_priv
*priv
= netdev_priv(dev
);
1313 void __iomem
*port_base
= priv
->port_base
;
1316 spin_lock_bh(&priv
->lock
);
1318 bmcr
= _sc92031_mii_read(port_base
, MII_BMCR
);
1319 if (!(bmcr
& BMCR_ANENABLE
)) {
1324 _sc92031_mii_write(port_base
, MII_BMCR
, bmcr
| BMCR_ANRESTART
);
1327 _sc92031_mii_scan(port_base
);
1330 spin_unlock_bh(&priv
->lock
);
1335 static const char sc92031_ethtool_stats_strings
[SILAN_STATS_NUM
][ETH_GSTRING_LEN
] = {
1340 static void sc92031_ethtool_get_strings(struct net_device
*dev
,
1341 u32 stringset
, u8
*data
)
1343 if (stringset
== ETH_SS_STATS
)
1344 memcpy(data
, sc92031_ethtool_stats_strings
,
1345 SILAN_STATS_NUM
* ETH_GSTRING_LEN
);
1348 static int sc92031_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1352 return SILAN_STATS_NUM
;
1358 static void sc92031_ethtool_get_ethtool_stats(struct net_device
*dev
,
1359 struct ethtool_stats
*stats
, u64
*data
)
1361 struct sc92031_priv
*priv
= netdev_priv(dev
);
1363 spin_lock_bh(&priv
->lock
);
1364 data
[0] = priv
->tx_timeouts
;
1365 data
[1] = priv
->rx_loss
;
1366 spin_unlock_bh(&priv
->lock
);
1369 static const struct ethtool_ops sc92031_ethtool_ops
= {
1370 .get_settings
= sc92031_ethtool_get_settings
,
1371 .set_settings
= sc92031_ethtool_set_settings
,
1372 .get_wol
= sc92031_ethtool_get_wol
,
1373 .set_wol
= sc92031_ethtool_set_wol
,
1374 .nway_reset
= sc92031_ethtool_nway_reset
,
1375 .get_link
= ethtool_op_get_link
,
1376 .get_strings
= sc92031_ethtool_get_strings
,
1377 .get_sset_count
= sc92031_ethtool_get_sset_count
,
1378 .get_ethtool_stats
= sc92031_ethtool_get_ethtool_stats
,
1382 static const struct net_device_ops sc92031_netdev_ops
= {
1383 .ndo_get_stats
= sc92031_get_stats
,
1384 .ndo_start_xmit
= sc92031_start_xmit
,
1385 .ndo_open
= sc92031_open
,
1386 .ndo_stop
= sc92031_stop
,
1387 .ndo_set_rx_mode
= sc92031_set_multicast_list
,
1388 .ndo_change_mtu
= eth_change_mtu
,
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 __devinit
sc92031_probe(struct pci_dev
*pdev
,
1398 const struct pci_device_id
*id
)
1401 void __iomem
* port_base
;
1402 struct net_device
*dev
;
1403 struct sc92031_priv
*priv
;
1405 unsigned long base_addr
;
1407 err
= pci_enable_device(pdev
);
1408 if (unlikely(err
< 0))
1409 goto out_enable_device
;
1411 pci_set_master(pdev
);
1413 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1414 if (unlikely(err
< 0))
1415 goto out_set_dma_mask
;
1417 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1418 if (unlikely(err
< 0))
1419 goto out_set_dma_mask
;
1421 err
= pci_request_regions(pdev
, SC92031_NAME
);
1422 if (unlikely(err
< 0))
1423 goto out_request_regions
;
1425 port_base
= pci_iomap(pdev
, SC92031_USE_BAR
, 0);
1426 if (unlikely(!port_base
)) {
1431 dev
= alloc_etherdev(sizeof(struct sc92031_priv
));
1432 if (unlikely(!dev
)) {
1434 goto out_alloc_etherdev
;
1437 pci_set_drvdata(pdev
, dev
);
1438 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1440 #if SC92031_USE_BAR == 0
1441 dev
->mem_start
= pci_resource_start(pdev
, SC92031_USE_BAR
);
1442 dev
->mem_end
= pci_resource_end(pdev
, SC92031_USE_BAR
);
1443 #elif SC92031_USE_BAR == 1
1444 dev
->base_addr
= pci_resource_start(pdev
, SC92031_USE_BAR
);
1446 dev
->irq
= pdev
->irq
;
1448 /* faked with skb_copy_and_csum_dev */
1449 dev
->features
= NETIF_F_SG
| NETIF_F_HIGHDMA
|
1450 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
1452 dev
->netdev_ops
= &sc92031_netdev_ops
;
1453 dev
->watchdog_timeo
= TX_TIMEOUT
;
1454 dev
->ethtool_ops
= &sc92031_ethtool_ops
;
1456 priv
= netdev_priv(dev
);
1457 spin_lock_init(&priv
->lock
);
1458 priv
->port_base
= port_base
;
1460 tasklet_init(&priv
->tasklet
, sc92031_tasklet
, (unsigned long)dev
);
1461 /* Fudge tasklet count so the call to sc92031_enable_interrupts at
1462 * sc92031_open will work correctly */
1463 tasklet_disable_nosync(&priv
->tasklet
);
1466 iowrite32((~PM_LongWF
& ~PM_LWPTN
) | PM_Enable
, port_base
+ PMConfig
);
1468 mac0
= ioread32(port_base
+ MAC0
);
1469 mac1
= ioread32(port_base
+ MAC0
+ 4);
1470 dev
->dev_addr
[0] = dev
->perm_addr
[0] = mac0
>> 24;
1471 dev
->dev_addr
[1] = dev
->perm_addr
[1] = mac0
>> 16;
1472 dev
->dev_addr
[2] = dev
->perm_addr
[2] = mac0
>> 8;
1473 dev
->dev_addr
[3] = dev
->perm_addr
[3] = mac0
;
1474 dev
->dev_addr
[4] = dev
->perm_addr
[4] = mac1
>> 8;
1475 dev
->dev_addr
[5] = dev
->perm_addr
[5] = mac1
;
1477 err
= register_netdev(dev
);
1479 goto out_register_netdev
;
1481 #if SC92031_USE_BAR == 0
1482 base_addr
= dev
->mem_start
;
1483 #elif SC92031_USE_BAR == 1
1484 base_addr
= dev
->base_addr
;
1486 printk(KERN_INFO
"%s: SC92031 at 0x%lx, %pM, IRQ %d\n", dev
->name
,
1487 base_addr
, dev
->dev_addr
, dev
->irq
);
1491 out_register_netdev
:
1494 pci_iounmap(pdev
, port_base
);
1496 pci_release_regions(pdev
);
1497 out_request_regions
:
1499 pci_disable_device(pdev
);
1504 static void __devexit
sc92031_remove(struct pci_dev
*pdev
)
1506 struct net_device
*dev
= pci_get_drvdata(pdev
);
1507 struct sc92031_priv
*priv
= netdev_priv(dev
);
1508 void __iomem
* port_base
= priv
->port_base
;
1510 unregister_netdev(dev
);
1512 pci_iounmap(pdev
, port_base
);
1513 pci_release_regions(pdev
);
1514 pci_disable_device(pdev
);
1517 static int sc92031_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1519 struct net_device
*dev
= pci_get_drvdata(pdev
);
1520 struct sc92031_priv
*priv
= netdev_priv(dev
);
1522 pci_save_state(pdev
);
1524 if (!netif_running(dev
))
1527 netif_device_detach(dev
);
1529 /* Disable interrupts, stop Tx and Rx. */
1530 sc92031_disable_interrupts(dev
);
1532 spin_lock_bh(&priv
->lock
);
1534 _sc92031_disable_tx_rx(dev
);
1535 _sc92031_tx_clear(dev
);
1538 spin_unlock_bh(&priv
->lock
);
1541 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1546 static int sc92031_resume(struct pci_dev
*pdev
)
1548 struct net_device
*dev
= pci_get_drvdata(pdev
);
1549 struct sc92031_priv
*priv
= netdev_priv(dev
);
1551 pci_restore_state(pdev
);
1552 pci_set_power_state(pdev
, PCI_D0
);
1554 if (!netif_running(dev
))
1557 /* Interrupts already disabled by sc92031_suspend */
1558 spin_lock_bh(&priv
->lock
);
1560 _sc92031_reset(dev
);
1563 spin_unlock_bh(&priv
->lock
);
1564 sc92031_enable_interrupts(dev
);
1566 netif_device_attach(dev
);
1568 if (netif_carrier_ok(dev
))
1569 netif_wake_queue(dev
);
1571 netif_tx_disable(dev
);
1577 static DEFINE_PCI_DEVICE_TABLE(sc92031_pci_device_id_table
) = {
1578 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x2031) },
1579 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x8139) },
1580 { PCI_DEVICE(0x1088, 0x2031) },
1583 MODULE_DEVICE_TABLE(pci
, sc92031_pci_device_id_table
);
1585 static struct pci_driver sc92031_pci_driver
= {
1586 .name
= SC92031_NAME
,
1587 .id_table
= sc92031_pci_device_id_table
,
1588 .probe
= sc92031_probe
,
1589 .remove
= __devexit_p(sc92031_remove
),
1590 .suspend
= sc92031_suspend
,
1591 .resume
= sc92031_resume
,
1594 static int __init
sc92031_init(void)
1596 return pci_register_driver(&sc92031_pci_driver
);
1599 static void __exit
sc92031_exit(void)
1601 pci_unregister_driver(&sc92031_pci_driver
);
1604 module_init(sc92031_init
);
1605 module_exit(sc92031_exit
);
1607 MODULE_LICENSE("GPL");
1608 MODULE_AUTHOR("Cesar Eduardo Barros <cesarb@cesarb.net>");
1609 MODULE_DESCRIPTION("Silan SC92031 PCI Fast Ethernet Adapter driver");