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/products/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/module.h>
26 #include <linux/kernel.h>
27 #include <linux/delay.h>
28 #include <linux/pci.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/ethtool.h>
33 #include <linux/crc32.h>
37 #define SC92031_NAME "sc92031"
39 /* BAR 0 is MMIO, BAR 1 is PIO */
40 #ifndef SC92031_USE_BAR
41 #define SC92031_USE_BAR 0
44 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */
45 static int multicast_filter_limit
= 64;
46 module_param(multicast_filter_limit
, int, 0);
47 MODULE_PARM_DESC(multicast_filter_limit
,
48 "Maximum number of filtered multicast addresses");
51 module_param(media
, int, 0);
52 MODULE_PARM_DESC(media
, "Media type (0x00 = autodetect,"
53 " 0x01 = 10M half, 0x02 = 10M full,"
54 " 0x04 = 100M half, 0x08 = 100M full)");
56 /* Size of the in-memory receive ring. */
57 #define RX_BUF_LEN_IDX 3 /* 0==8K, 1==16K, 2==32K, 3==64K ,4==128K*/
58 #define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX)
60 /* Number of Tx descriptor registers. */
63 /* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/
64 #define MAX_ETH_FRAME_SIZE 1536
66 /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
67 #define TX_BUF_SIZE MAX_ETH_FRAME_SIZE
68 #define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC)
70 /* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024, 7==end of packet. */
71 #define RX_FIFO_THRESH 7 /* Rx buffer level before first PCI xfer. */
73 /* Time in jiffies before concluding the transmitter is hung. */
74 #define TX_TIMEOUT (4*HZ)
76 #define SILAN_STATS_NUM 2 /* number of ETHTOOL_GSTATS */
79 #define AUTOSELECT 0x00
82 #define M100_HALF 0x04
83 #define M100_FULL 0x08
85 /* Symbolic offsets to registers. */
86 enum silan_registers
{
87 Config0
= 0x00, // Config0
88 Config1
= 0x04, // Config1
89 RxBufWPtr
= 0x08, // Rx buffer writer poiter
90 IntrStatus
= 0x0C, // Interrupt status
91 IntrMask
= 0x10, // Interrupt mask
92 RxbufAddr
= 0x14, // Rx buffer start address
93 RxBufRPtr
= 0x18, // Rx buffer read pointer
94 Txstatusall
= 0x1C, // Transmit status of all descriptors
95 TxStatus0
= 0x20, // Transmit status (Four 32bit registers).
96 TxAddr0
= 0x30, // Tx descriptors (also four 32bit).
97 RxConfig
= 0x40, // Rx configuration
98 MAC0
= 0x44, // Ethernet hardware address.
99 MAR0
= 0x4C, // Multicast filter.
100 RxStatus0
= 0x54, // Rx status
101 TxConfig
= 0x5C, // Tx configuration
102 PhyCtrl
= 0x60, // physical control
103 FlowCtrlConfig
= 0x64, // flow control
104 Miicmd0
= 0x68, // Mii command0 register
105 Miicmd1
= 0x6C, // Mii command1 register
106 Miistatus
= 0x70, // Mii status register
107 Timercnt
= 0x74, // Timer counter register
108 TimerIntr
= 0x78, // Timer interrupt register
109 PMConfig
= 0x7C, // Power Manager configuration
110 CRC0
= 0x80, // Power Manager CRC ( Two 32bit regisers)
111 Wakeup0
= 0x88, // power Manager wakeup( Eight 64bit regiser)
112 LSBCRC0
= 0xC8, // power Manager LSBCRC(Two 32bit regiser)
118 #define MII_BMCR 0 // Basic mode control register
119 #define MII_BMSR 1 // Basic mode status register
121 #define MII_OutputStatus 24
123 #define BMCR_FULLDPLX 0x0100 // Full duplex
124 #define BMCR_ANRESTART 0x0200 // Auto negotiation restart
125 #define BMCR_ANENABLE 0x1000 // Enable auto negotiation
126 #define BMCR_SPEED100 0x2000 // Select 100Mbps
127 #define BMSR_LSTATUS 0x0004 // Link status
128 #define PHY_16_JAB_ENB 0x1000
129 #define PHY_16_PORT_ENB 0x1
131 enum IntrStatusBits
{
132 LinkFail
= 0x80000000,
134 TimeOut
= 0x20000000,
138 IntrBits
= LinkFail
|LinkOK
|TimeOut
|RxOverflow
|RxOK
|TxOK
,
142 TxCarrierLost
= 0x20000000,
143 TxAborted
= 0x10000000,
144 TxOutOfWindow
= 0x08000000,
146 EarlyTxThresShift
= 16,
153 RxStatesOK
= 0x80000,
154 RxBadAlign
= 0x40000,
155 RxHugeFrame
= 0x20000,
156 RxSmallFrame
= 0x10000,
159 Rx_Broadcast
= 0x2000,
160 Rx_Multicast
= 0x1000,
161 RxAddrMatch
= 0x0800,
166 RxFullDx
= 0x80000000,
168 RxSmall
= 0x20000000,
171 RxAllphys
= 0x04000000,
172 RxMulticast
= 0x02000000,
173 RxBroadcast
= 0x01000000,
174 RxLoopBack
= (1 << 23) | (1 << 22),
175 LowThresholdShift
= 12,
176 HighThresholdShift
= 2,
180 TxFullDx
= 0x80000000,
182 TxEnbPad
= 0x20000000,
183 TxEnbHuge
= 0x10000000,
184 TxEnbFCS
= 0x08000000,
185 TxNoBackOff
= 0x04000000,
186 TxEnbPrem
= 0x02000000,
187 TxCareLostCrs
= 0x1000000,
188 TxExdCollNum
= 0xf00000,
189 TxDataRate
= 0x80000,
192 enum PhyCtrlconfigbits
{
193 PhyCtrlAne
= 0x80000000,
194 PhyCtrlSpd100
= 0x40000000,
195 PhyCtrlSpd10
= 0x20000000,
196 PhyCtrlPhyBaseAddr
= 0x1f000000,
197 PhyCtrlDux
= 0x800000,
198 PhyCtrlReset
= 0x400000,
201 enum FlowCtrlConfigBits
{
202 FlowCtrlFullDX
= 0x80000000,
203 FlowCtrlEnb
= 0x40000000,
207 Cfg0_Reset
= 0x80000000,
208 Cfg0_Anaoff
= 0x40000000,
209 Cfg0_LDPS
= 0x20000000,
213 Cfg1_EarlyRx
= 1 << 31,
214 Cfg1_EarlyTx
= 1 << 30,
225 Mii_Divider
= 0x20000000,
226 Mii_WRITE
= 0x400000,
230 Mii_Drvmod
= 0x40000,
238 Mii_StatusBusy
= 0x80000000,
245 PM_LANWake
= 1 << 28,
246 PM_LWPTN
= (1 << 27 | 1<< 26),
252 * priv->lock protects most of the fields of priv and most of the
253 * hardware registers. It does not have to protect against softirqs
254 * between sc92031_disable_interrupts and sc92031_enable_interrupts;
255 * it also does not need to be used in ->open and ->stop while the
256 * device interrupts are off.
257 * Not having to protect against softirqs is very useful due to heavy
258 * use of mdelay() at _sc92031_reset.
259 * Functions prefixed with _sc92031_ must be called with the lock held;
260 * functions prefixed with sc92031_ must be called without the lock held.
261 * Use mmiowb() before unlocking if the hardware was written to.
264 /* Locking rules for the interrupt:
265 * - the interrupt and the tasklet never run at the same time
266 * - neither run between sc92031_disable_interrupts and
267 * sc92031_enable_interrupt
270 struct sc92031_priv
{
273 void __iomem
*port_base
;
274 /* pci device structure */
275 struct pci_dev
*pdev
;
277 struct tasklet_struct tasklet
;
279 /* CPU address of rx ring */
281 /* PCI address of rx ring */
282 dma_addr_t rx_ring_dma_addr
;
283 /* PCI address of rx ring read pointer */
284 dma_addr_t rx_ring_tail
;
286 /* tx ring write index */
288 /* tx ring read index */
290 /* CPU address of tx bounce buffer */
292 /* PCI address of tx bounce buffer */
293 dma_addr_t tx_bufs_dma_addr
;
295 /* copies of some hardware registers */
302 /* copy of some flags from dev->flags */
303 unsigned int mc_flags
;
305 /* for ETHTOOL_GSTATS */
309 /* for dev->get_stats */
313 /* I don't know which registers can be safely read; however, I can guess
314 * MAC0 is one of them. */
315 static inline void _sc92031_dummy_read(void __iomem
*port_base
)
317 ioread32(port_base
+ MAC0
);
320 static u32
_sc92031_mii_wait(void __iomem
*port_base
)
326 mii_status
= ioread32(port_base
+ Miistatus
);
327 } while (mii_status
& Mii_StatusBusy
);
332 static u32
_sc92031_mii_cmd(void __iomem
*port_base
, u32 cmd0
, u32 cmd1
)
334 iowrite32(Mii_Divider
, port_base
+ Miicmd0
);
336 _sc92031_mii_wait(port_base
);
338 iowrite32(cmd1
, port_base
+ Miicmd1
);
339 iowrite32(Mii_Divider
| cmd0
, port_base
+ Miicmd0
);
341 return _sc92031_mii_wait(port_base
);
344 static void _sc92031_mii_scan(void __iomem
*port_base
)
346 _sc92031_mii_cmd(port_base
, Mii_SCAN
, 0x1 << 6);
349 static u16
_sc92031_mii_read(void __iomem
*port_base
, unsigned reg
)
351 return _sc92031_mii_cmd(port_base
, Mii_READ
, reg
<< 6) >> 13;
354 static void _sc92031_mii_write(void __iomem
*port_base
, unsigned reg
, u16 val
)
356 _sc92031_mii_cmd(port_base
, Mii_WRITE
, (reg
<< 6) | ((u32
)val
<< 11));
359 static void sc92031_disable_interrupts(struct net_device
*dev
)
361 struct sc92031_priv
*priv
= netdev_priv(dev
);
362 void __iomem
*port_base
= priv
->port_base
;
364 /* tell the tasklet/interrupt not to enable interrupts */
365 atomic_set(&priv
->intr_mask
, 0);
368 /* stop interrupts */
369 iowrite32(0, port_base
+ IntrMask
);
370 _sc92031_dummy_read(port_base
);
373 /* wait for any concurrent interrupt/tasklet to finish */
374 synchronize_irq(dev
->irq
);
375 tasklet_disable(&priv
->tasklet
);
378 static void sc92031_enable_interrupts(struct net_device
*dev
)
380 struct sc92031_priv
*priv
= netdev_priv(dev
);
381 void __iomem
*port_base
= priv
->port_base
;
383 tasklet_enable(&priv
->tasklet
);
385 atomic_set(&priv
->intr_mask
, IntrBits
);
388 iowrite32(IntrBits
, port_base
+ IntrMask
);
392 static void _sc92031_disable_tx_rx(struct net_device
*dev
)
394 struct sc92031_priv
*priv
= netdev_priv(dev
);
395 void __iomem
*port_base
= priv
->port_base
;
397 priv
->rx_config
&= ~RxEnb
;
398 priv
->tx_config
&= ~TxEnb
;
399 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
400 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
403 static void _sc92031_enable_tx_rx(struct net_device
*dev
)
405 struct sc92031_priv
*priv
= netdev_priv(dev
);
406 void __iomem
*port_base
= priv
->port_base
;
408 priv
->rx_config
|= RxEnb
;
409 priv
->tx_config
|= TxEnb
;
410 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
411 iowrite32(priv
->tx_config
, port_base
+ TxConfig
);
414 static void _sc92031_tx_clear(struct net_device
*dev
)
416 struct sc92031_priv
*priv
= netdev_priv(dev
);
418 while (priv
->tx_head
- priv
->tx_tail
> 0) {
420 dev
->stats
.tx_dropped
++;
422 priv
->tx_head
= priv
->tx_tail
= 0;
425 static void _sc92031_set_mar(struct net_device
*dev
)
427 struct sc92031_priv
*priv
= netdev_priv(dev
);
428 void __iomem
*port_base
= priv
->port_base
;
429 u32 mar0
= 0, mar1
= 0;
431 if ((dev
->flags
& IFF_PROMISC
) ||
432 netdev_mc_count(dev
) > multicast_filter_limit
||
433 (dev
->flags
& IFF_ALLMULTI
))
434 mar0
= mar1
= 0xffffffff;
435 else if (dev
->flags
& IFF_MULTICAST
) {
436 struct netdev_hw_addr
*ha
;
438 netdev_for_each_mc_addr(ha
, dev
) {
442 crc
= ~ether_crc(ETH_ALEN
, ha
->addr
);
445 if (crc
& 0x01) bit
|= 0x02;
446 if (crc
& 0x02) bit
|= 0x01;
447 if (crc
& 0x10) bit
|= 0x20;
448 if (crc
& 0x20) bit
|= 0x10;
449 if (crc
& 0x40) bit
|= 0x08;
450 if (crc
& 0x80) bit
|= 0x04;
453 mar0
|= 0x1 << (bit
- 32);
459 iowrite32(mar0
, port_base
+ MAR0
);
460 iowrite32(mar1
, port_base
+ MAR0
+ 4);
463 static void _sc92031_set_rx_config(struct net_device
*dev
)
465 struct sc92031_priv
*priv
= netdev_priv(dev
);
466 void __iomem
*port_base
= priv
->port_base
;
467 unsigned int old_mc_flags
;
468 u32 rx_config_bits
= 0;
470 old_mc_flags
= priv
->mc_flags
;
472 if (dev
->flags
& IFF_PROMISC
)
473 rx_config_bits
|= RxSmall
| RxHuge
| RxErr
| RxBroadcast
474 | RxMulticast
| RxAllphys
;
476 if (dev
->flags
& (IFF_ALLMULTI
| IFF_MULTICAST
))
477 rx_config_bits
|= RxMulticast
;
479 if (dev
->flags
& IFF_BROADCAST
)
480 rx_config_bits
|= RxBroadcast
;
482 priv
->rx_config
&= ~(RxSmall
| RxHuge
| RxErr
| RxBroadcast
483 | RxMulticast
| RxAllphys
);
484 priv
->rx_config
|= rx_config_bits
;
486 priv
->mc_flags
= dev
->flags
& (IFF_PROMISC
| IFF_ALLMULTI
487 | IFF_MULTICAST
| IFF_BROADCAST
);
489 if (netif_carrier_ok(dev
) && priv
->mc_flags
!= old_mc_flags
)
490 iowrite32(priv
->rx_config
, port_base
+ RxConfig
);
493 static bool _sc92031_check_media(struct net_device
*dev
)
495 struct sc92031_priv
*priv
= netdev_priv(dev
);
496 void __iomem
*port_base
= priv
->port_base
;
499 bmsr
= _sc92031_mii_read(port_base
, MII_BMSR
);
501 if (bmsr
& BMSR_LSTATUS
) {
502 bool speed_100
, duplex_full
;
503 u32 flow_ctrl_config
= 0;
504 u16 output_status
= _sc92031_mii_read(port_base
,
506 _sc92031_mii_scan(port_base
);
508 speed_100
= output_status
& 0x2;
509 duplex_full
= output_status
& 0x4;
511 /* Initial Tx/Rx configuration */
512 priv
->rx_config
= (0x40 << LowThresholdShift
) | (0x1c0 << HighThresholdShift
);
513 priv
->tx_config
= 0x48800000;
515 /* NOTE: vendor driver had dead code here to enable tx padding */
518 priv
->tx_config
|= 0x80000;
521 _sc92031_set_rx_config(dev
);
524 priv
->rx_config
|= RxFullDx
;
525 priv
->tx_config
|= TxFullDx
;
526 flow_ctrl_config
= FlowCtrlFullDX
| FlowCtrlEnb
;
528 priv
->rx_config
&= ~RxFullDx
;
529 priv
->tx_config
&= ~TxFullDx
;
532 _sc92031_set_mar(dev
);
533 _sc92031_set_rx_config(dev
);
534 _sc92031_enable_tx_rx(dev
);
535 iowrite32(flow_ctrl_config
, port_base
+ FlowCtrlConfig
);
537 netif_carrier_on(dev
);
539 if (printk_ratelimit())
540 printk(KERN_INFO
"%s: link up, %sMbps, %s-duplex\n",
542 speed_100
? "100" : "10",
543 duplex_full
? "full" : "half");
546 _sc92031_mii_scan(port_base
);
548 netif_carrier_off(dev
);
550 _sc92031_disable_tx_rx(dev
);
552 if (printk_ratelimit())
553 printk(KERN_INFO
"%s: link down\n", dev
->name
);
558 static void _sc92031_phy_reset(struct net_device
*dev
)
560 struct sc92031_priv
*priv
= netdev_priv(dev
);
561 void __iomem
*port_base
= priv
->port_base
;
564 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
565 phy_ctrl
&= ~(PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
);
566 phy_ctrl
|= PhyCtrlAne
| PhyCtrlReset
;
571 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
574 phy_ctrl
|= PhyCtrlSpd10
;
577 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd10
;
580 phy_ctrl
|= PhyCtrlSpd100
;
583 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
587 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
590 phy_ctrl
&= ~PhyCtrlReset
;
591 iowrite32(phy_ctrl
, port_base
+ PhyCtrl
);
594 _sc92031_mii_write(port_base
, MII_JAB
,
595 PHY_16_JAB_ENB
| PHY_16_PORT_ENB
);
596 _sc92031_mii_scan(port_base
);
598 netif_carrier_off(dev
);
599 netif_stop_queue(dev
);
602 static void _sc92031_reset(struct net_device
*dev
)
604 struct sc92031_priv
*priv
= netdev_priv(dev
);
605 void __iomem
*port_base
= priv
->port_base
;
608 iowrite32(0, port_base
+ PMConfig
);
610 /* soft reset the chip */
611 iowrite32(Cfg0_Reset
, port_base
+ Config0
);
614 iowrite32(0, port_base
+ Config0
);
617 /* disable interrupts */
618 iowrite32(0, port_base
+ IntrMask
);
620 /* clear multicast address */
621 iowrite32(0, port_base
+ MAR0
);
622 iowrite32(0, port_base
+ MAR0
+ 4);
625 iowrite32(priv
->rx_ring_dma_addr
, port_base
+ RxbufAddr
);
626 priv
->rx_ring_tail
= priv
->rx_ring_dma_addr
;
629 _sc92031_tx_clear(dev
);
631 /* clear old register values */
632 priv
->intr_status
= 0;
633 atomic_set(&priv
->intr_mask
, 0);
638 /* configure rx buffer size */
639 /* NOTE: vendor driver had dead code here to enable early tx/rx */
640 iowrite32(Cfg1_Rcv64K
, port_base
+ Config1
);
642 _sc92031_phy_reset(dev
);
643 _sc92031_check_media(dev
);
645 /* calculate rx fifo overflow */
649 iowrite32(priv
->pm_config
, port_base
+ PMConfig
);
651 /* clear intr register */
652 ioread32(port_base
+ IntrStatus
);
655 static void _sc92031_tx_tasklet(struct net_device
*dev
)
657 struct sc92031_priv
*priv
= netdev_priv(dev
);
658 void __iomem
*port_base
= priv
->port_base
;
660 unsigned old_tx_tail
;
664 old_tx_tail
= priv
->tx_tail
;
665 while (priv
->tx_head
- priv
->tx_tail
> 0) {
666 entry
= priv
->tx_tail
% NUM_TX_DESC
;
667 tx_status
= ioread32(port_base
+ TxStatus0
+ entry
* 4);
669 if (!(tx_status
& (TxStatOK
| TxUnderrun
| TxAborted
)))
674 if (tx_status
& TxStatOK
) {
675 dev
->stats
.tx_bytes
+= tx_status
& 0x1fff;
676 dev
->stats
.tx_packets
++;
677 /* Note: TxCarrierLost is always asserted at 100mbps. */
678 dev
->stats
.collisions
+= (tx_status
>> 22) & 0xf;
681 if (tx_status
& (TxOutOfWindow
| TxAborted
)) {
682 dev
->stats
.tx_errors
++;
684 if (tx_status
& TxAborted
)
685 dev
->stats
.tx_aborted_errors
++;
687 if (tx_status
& TxCarrierLost
)
688 dev
->stats
.tx_carrier_errors
++;
690 if (tx_status
& TxOutOfWindow
)
691 dev
->stats
.tx_window_errors
++;
694 if (tx_status
& TxUnderrun
)
695 dev
->stats
.tx_fifo_errors
++;
698 if (priv
->tx_tail
!= old_tx_tail
)
699 if (netif_queue_stopped(dev
))
700 netif_wake_queue(dev
);
703 static void _sc92031_rx_tasklet_error(struct net_device
*dev
,
704 u32 rx_status
, unsigned rx_size
)
706 if(rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) || rx_size
< 16) {
707 dev
->stats
.rx_errors
++;
708 dev
->stats
.rx_length_errors
++;
711 if (!(rx_status
& RxStatesOK
)) {
712 dev
->stats
.rx_errors
++;
714 if (rx_status
& (RxHugeFrame
| RxSmallFrame
))
715 dev
->stats
.rx_length_errors
++;
717 if (rx_status
& RxBadAlign
)
718 dev
->stats
.rx_frame_errors
++;
720 if (!(rx_status
& RxCRCOK
))
721 dev
->stats
.rx_crc_errors
++;
723 struct sc92031_priv
*priv
= netdev_priv(dev
);
728 static void _sc92031_rx_tasklet(struct net_device
*dev
)
730 struct sc92031_priv
*priv
= netdev_priv(dev
);
731 void __iomem
*port_base
= priv
->port_base
;
733 dma_addr_t rx_ring_head
;
735 unsigned rx_ring_offset
;
736 void *rx_ring
= priv
->rx_ring
;
738 rx_ring_head
= ioread32(port_base
+ RxBufWPtr
);
741 /* rx_ring_head is only 17 bits in the RxBufWPtr register.
742 * we need to change it to 32 bits physical address
744 rx_ring_head
&= (dma_addr_t
)(RX_BUF_LEN
- 1);
745 rx_ring_head
|= priv
->rx_ring_dma_addr
& ~(dma_addr_t
)(RX_BUF_LEN
- 1);
746 if (rx_ring_head
< priv
->rx_ring_dma_addr
)
747 rx_ring_head
+= RX_BUF_LEN
;
749 if (rx_ring_head
>= priv
->rx_ring_tail
)
750 rx_len
= rx_ring_head
- priv
->rx_ring_tail
;
752 rx_len
= RX_BUF_LEN
- (priv
->rx_ring_tail
- rx_ring_head
);
757 if (unlikely(rx_len
> RX_BUF_LEN
)) {
758 if (printk_ratelimit())
759 printk(KERN_ERR
"%s: rx packets length > rx buffer\n",
764 rx_ring_offset
= (priv
->rx_ring_tail
- priv
->rx_ring_dma_addr
) % RX_BUF_LEN
;
768 unsigned rx_size
, rx_size_align
, pkt_size
;
771 rx_status
= le32_to_cpup((__le32
*)(rx_ring
+ rx_ring_offset
));
774 rx_size
= rx_status
>> 20;
775 rx_size_align
= (rx_size
+ 3) & ~3; // for 4 bytes aligned
776 pkt_size
= rx_size
- 4; // Omit the four octet CRC from the length.
778 rx_ring_offset
= (rx_ring_offset
+ 4) % RX_BUF_LEN
;
780 if (unlikely(rx_status
== 0 ||
781 rx_size
> (MAX_ETH_FRAME_SIZE
+ 4) ||
783 !(rx_status
& RxStatesOK
))) {
784 _sc92031_rx_tasklet_error(dev
, rx_status
, rx_size
);
788 if (unlikely(rx_size_align
+ 4 > rx_len
)) {
789 if (printk_ratelimit())
790 printk(KERN_ERR
"%s: rx_len is too small\n", dev
->name
);
794 rx_len
-= rx_size_align
+ 4;
796 skb
= netdev_alloc_skb_ip_align(dev
, pkt_size
);
797 if (unlikely(!skb
)) {
798 if (printk_ratelimit())
799 printk(KERN_ERR
"%s: Couldn't allocate a skb_buff for a packet of size %u\n",
800 dev
->name
, pkt_size
);
804 if ((rx_ring_offset
+ pkt_size
) > RX_BUF_LEN
) {
805 memcpy(skb_put(skb
, RX_BUF_LEN
- rx_ring_offset
),
806 rx_ring
+ rx_ring_offset
, RX_BUF_LEN
- rx_ring_offset
);
807 memcpy(skb_put(skb
, pkt_size
- (RX_BUF_LEN
- rx_ring_offset
)),
808 rx_ring
, pkt_size
- (RX_BUF_LEN
- rx_ring_offset
));
810 memcpy(skb_put(skb
, pkt_size
), rx_ring
+ rx_ring_offset
, pkt_size
);
813 skb
->protocol
= eth_type_trans(skb
, dev
);
816 dev
->stats
.rx_bytes
+= pkt_size
;
817 dev
->stats
.rx_packets
++;
819 if (rx_status
& Rx_Multicast
)
820 dev
->stats
.multicast
++;
823 rx_ring_offset
= (rx_ring_offset
+ rx_size_align
) % RX_BUF_LEN
;
827 priv
->rx_ring_tail
= rx_ring_head
;
828 iowrite32(priv
->rx_ring_tail
, port_base
+ RxBufRPtr
);
831 static void _sc92031_link_tasklet(struct net_device
*dev
)
833 if (_sc92031_check_media(dev
))
834 netif_wake_queue(dev
);
836 netif_stop_queue(dev
);
837 dev
->stats
.tx_carrier_errors
++;
841 static void sc92031_tasklet(unsigned long data
)
843 struct net_device
*dev
= (struct net_device
*)data
;
844 struct sc92031_priv
*priv
= netdev_priv(dev
);
845 void __iomem
*port_base
= priv
->port_base
;
846 u32 intr_status
, intr_mask
;
848 intr_status
= priv
->intr_status
;
850 spin_lock(&priv
->lock
);
852 if (unlikely(!netif_running(dev
)))
855 if (intr_status
& TxOK
)
856 _sc92031_tx_tasklet(dev
);
858 if (intr_status
& RxOK
)
859 _sc92031_rx_tasklet(dev
);
861 if (intr_status
& RxOverflow
)
862 dev
->stats
.rx_errors
++;
864 if (intr_status
& TimeOut
) {
865 dev
->stats
.rx_errors
++;
866 dev
->stats
.rx_length_errors
++;
869 if (intr_status
& (LinkFail
| LinkOK
))
870 _sc92031_link_tasklet(dev
);
873 intr_mask
= atomic_read(&priv
->intr_mask
);
876 iowrite32(intr_mask
, port_base
+ IntrMask
);
879 spin_unlock(&priv
->lock
);
882 static irqreturn_t
sc92031_interrupt(int irq
, void *dev_id
)
884 struct net_device
*dev
= dev_id
;
885 struct sc92031_priv
*priv
= netdev_priv(dev
);
886 void __iomem
*port_base
= priv
->port_base
;
887 u32 intr_status
, intr_mask
;
889 /* mask interrupts before clearing IntrStatus */
890 iowrite32(0, port_base
+ IntrMask
);
891 _sc92031_dummy_read(port_base
);
893 intr_status
= ioread32(port_base
+ IntrStatus
);
894 if (unlikely(intr_status
== 0xffffffff))
895 return IRQ_NONE
; // hardware has gone missing
897 intr_status
&= IntrBits
;
901 priv
->intr_status
= intr_status
;
902 tasklet_schedule(&priv
->tasklet
);
907 intr_mask
= atomic_read(&priv
->intr_mask
);
910 iowrite32(intr_mask
, port_base
+ IntrMask
);
916 static struct net_device_stats
*sc92031_get_stats(struct net_device
*dev
)
918 struct sc92031_priv
*priv
= netdev_priv(dev
);
919 void __iomem
*port_base
= priv
->port_base
;
921 // FIXME I do not understand what is this trying to do.
922 if (netif_running(dev
)) {
925 spin_lock_bh(&priv
->lock
);
927 /* Update the error count. */
928 temp
= (ioread32(port_base
+ RxStatus0
) >> 16) & 0xffff;
930 if (temp
== 0xffff) {
931 priv
->rx_value
+= temp
;
932 dev
->stats
.rx_fifo_errors
= priv
->rx_value
;
934 dev
->stats
.rx_fifo_errors
= temp
+ priv
->rx_value
;
936 spin_unlock_bh(&priv
->lock
);
942 static netdev_tx_t
sc92031_start_xmit(struct sk_buff
*skb
,
943 struct net_device
*dev
)
945 struct sc92031_priv
*priv
= netdev_priv(dev
);
946 void __iomem
*port_base
= priv
->port_base
;
951 if (unlikely(skb
->len
> TX_BUF_SIZE
)) {
952 dev
->stats
.tx_dropped
++;
956 spin_lock(&priv
->lock
);
958 if (unlikely(!netif_carrier_ok(dev
))) {
959 dev
->stats
.tx_dropped
++;
963 BUG_ON(priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
);
965 entry
= priv
->tx_head
++ % NUM_TX_DESC
;
967 skb_copy_and_csum_dev(skb
, priv
->tx_bufs
+ entry
* TX_BUF_SIZE
);
970 if (len
< ETH_ZLEN
) {
971 memset(priv
->tx_bufs
+ entry
* TX_BUF_SIZE
+ len
,
981 tx_status
= 0x30000 | len
;
983 tx_status
= 0x50000 | len
;
985 iowrite32(priv
->tx_bufs_dma_addr
+ entry
* TX_BUF_SIZE
,
986 port_base
+ TxAddr0
+ entry
* 4);
987 iowrite32(tx_status
, port_base
+ TxStatus0
+ entry
* 4);
990 if (priv
->tx_head
- priv
->tx_tail
>= NUM_TX_DESC
)
991 netif_stop_queue(dev
);
994 spin_unlock(&priv
->lock
);
1002 static int sc92031_open(struct net_device
*dev
)
1005 struct sc92031_priv
*priv
= netdev_priv(dev
);
1006 struct pci_dev
*pdev
= priv
->pdev
;
1008 priv
->rx_ring
= pci_alloc_consistent(pdev
, RX_BUF_LEN
,
1009 &priv
->rx_ring_dma_addr
);
1010 if (unlikely(!priv
->rx_ring
)) {
1012 goto out_alloc_rx_ring
;
1015 priv
->tx_bufs
= pci_alloc_consistent(pdev
, TX_BUF_TOT_LEN
,
1016 &priv
->tx_bufs_dma_addr
);
1017 if (unlikely(!priv
->tx_bufs
)) {
1019 goto out_alloc_tx_bufs
;
1021 priv
->tx_head
= priv
->tx_tail
= 0;
1023 err
= request_irq(pdev
->irq
, sc92031_interrupt
,
1024 IRQF_SHARED
, dev
->name
, dev
);
1025 if (unlikely(err
< 0))
1026 goto out_request_irq
;
1028 priv
->pm_config
= 0;
1030 /* Interrupts already disabled by sc92031_stop or sc92031_probe */
1031 spin_lock_bh(&priv
->lock
);
1033 _sc92031_reset(dev
);
1036 spin_unlock_bh(&priv
->lock
);
1037 sc92031_enable_interrupts(dev
);
1039 if (netif_carrier_ok(dev
))
1040 netif_start_queue(dev
);
1042 netif_tx_disable(dev
);
1047 pci_free_consistent(pdev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1048 priv
->tx_bufs_dma_addr
);
1050 pci_free_consistent(pdev
, RX_BUF_LEN
, priv
->rx_ring
,
1051 priv
->rx_ring_dma_addr
);
1056 static int sc92031_stop(struct net_device
*dev
)
1058 struct sc92031_priv
*priv
= netdev_priv(dev
);
1059 struct pci_dev
*pdev
= priv
->pdev
;
1061 netif_tx_disable(dev
);
1063 /* Disable interrupts, stop Tx and Rx. */
1064 sc92031_disable_interrupts(dev
);
1066 spin_lock_bh(&priv
->lock
);
1068 _sc92031_disable_tx_rx(dev
);
1069 _sc92031_tx_clear(dev
);
1072 spin_unlock_bh(&priv
->lock
);
1074 free_irq(pdev
->irq
, dev
);
1075 pci_free_consistent(pdev
, TX_BUF_TOT_LEN
, priv
->tx_bufs
,
1076 priv
->tx_bufs_dma_addr
);
1077 pci_free_consistent(pdev
, RX_BUF_LEN
, priv
->rx_ring
,
1078 priv
->rx_ring_dma_addr
);
1083 static void sc92031_set_multicast_list(struct net_device
*dev
)
1085 struct sc92031_priv
*priv
= netdev_priv(dev
);
1087 spin_lock_bh(&priv
->lock
);
1089 _sc92031_set_mar(dev
);
1090 _sc92031_set_rx_config(dev
);
1093 spin_unlock_bh(&priv
->lock
);
1096 static void sc92031_tx_timeout(struct net_device
*dev
)
1098 struct sc92031_priv
*priv
= netdev_priv(dev
);
1100 /* Disable interrupts by clearing the interrupt mask.*/
1101 sc92031_disable_interrupts(dev
);
1103 spin_lock(&priv
->lock
);
1105 priv
->tx_timeouts
++;
1107 _sc92031_reset(dev
);
1110 spin_unlock(&priv
->lock
);
1112 /* enable interrupts */
1113 sc92031_enable_interrupts(dev
);
1115 if (netif_carrier_ok(dev
))
1116 netif_wake_queue(dev
);
1119 #ifdef CONFIG_NET_POLL_CONTROLLER
1120 static void sc92031_poll_controller(struct net_device
*dev
)
1122 disable_irq(dev
->irq
);
1123 if (sc92031_interrupt(dev
->irq
, dev
) != IRQ_NONE
)
1124 sc92031_tasklet((unsigned long)dev
);
1125 enable_irq(dev
->irq
);
1129 static int sc92031_ethtool_get_settings(struct net_device
*dev
,
1130 struct ethtool_cmd
*cmd
)
1132 struct sc92031_priv
*priv
= netdev_priv(dev
);
1133 void __iomem
*port_base
= priv
->port_base
;
1138 spin_lock_bh(&priv
->lock
);
1140 phy_address
= ioread32(port_base
+ Miicmd1
) >> 27;
1141 phy_ctrl
= ioread32(port_base
+ PhyCtrl
);
1143 output_status
= _sc92031_mii_read(port_base
, MII_OutputStatus
);
1144 _sc92031_mii_scan(port_base
);
1147 spin_unlock_bh(&priv
->lock
);
1149 cmd
->supported
= SUPPORTED_10baseT_Half
| SUPPORTED_10baseT_Full
1150 | SUPPORTED_100baseT_Half
| SUPPORTED_100baseT_Full
1151 | SUPPORTED_Autoneg
| SUPPORTED_TP
| SUPPORTED_MII
;
1153 cmd
->advertising
= ADVERTISED_TP
| ADVERTISED_MII
;
1155 if ((phy_ctrl
& (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1156 == (PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
))
1157 cmd
->advertising
|= ADVERTISED_Autoneg
;
1159 if ((phy_ctrl
& PhyCtrlSpd10
) == PhyCtrlSpd10
)
1160 cmd
->advertising
|= ADVERTISED_10baseT_Half
;
1162 if ((phy_ctrl
& (PhyCtrlSpd10
| PhyCtrlDux
))
1163 == (PhyCtrlSpd10
| PhyCtrlDux
))
1164 cmd
->advertising
|= ADVERTISED_10baseT_Full
;
1166 if ((phy_ctrl
& PhyCtrlSpd100
) == PhyCtrlSpd100
)
1167 cmd
->advertising
|= ADVERTISED_100baseT_Half
;
1169 if ((phy_ctrl
& (PhyCtrlSpd100
| PhyCtrlDux
))
1170 == (PhyCtrlSpd100
| PhyCtrlDux
))
1171 cmd
->advertising
|= ADVERTISED_100baseT_Full
;
1173 if (phy_ctrl
& PhyCtrlAne
)
1174 cmd
->advertising
|= ADVERTISED_Autoneg
;
1176 cmd
->speed
= (output_status
& 0x2) ? SPEED_100
: SPEED_10
;
1177 cmd
->duplex
= (output_status
& 0x4) ? DUPLEX_FULL
: DUPLEX_HALF
;
1178 cmd
->port
= PORT_MII
;
1179 cmd
->phy_address
= phy_address
;
1180 cmd
->transceiver
= XCVR_INTERNAL
;
1181 cmd
->autoneg
= (phy_ctrl
& PhyCtrlAne
) ? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
1186 static int sc92031_ethtool_set_settings(struct net_device
*dev
,
1187 struct ethtool_cmd
*cmd
)
1189 struct sc92031_priv
*priv
= netdev_priv(dev
);
1190 void __iomem
*port_base
= priv
->port_base
;
1194 if (!(cmd
->speed
== SPEED_10
|| cmd
->speed
== SPEED_100
))
1196 if (!(cmd
->duplex
== DUPLEX_HALF
|| cmd
->duplex
== DUPLEX_FULL
))
1198 if (!(cmd
->port
== PORT_MII
))
1200 if (!(cmd
->phy_address
== 0x1f))
1202 if (!(cmd
->transceiver
== XCVR_INTERNAL
))
1204 if (!(cmd
->autoneg
== AUTONEG_DISABLE
|| cmd
->autoneg
== AUTONEG_ENABLE
))
1207 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
1208 if (!(cmd
->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 (cmd
->advertising
& ADVERTISED_Autoneg
)
1219 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
| PhyCtrlSpd10
;
1220 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
1221 phy_ctrl
|= PhyCtrlDux
| PhyCtrlSpd100
;
1222 if (cmd
->advertising
& ADVERTISED_100baseT_Half
)
1223 phy_ctrl
|= PhyCtrlSpd100
;
1224 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
1225 phy_ctrl
|= PhyCtrlSpd10
| PhyCtrlDux
;
1226 if (cmd
->advertising
& ADVERTISED_10baseT_Half
)
1227 phy_ctrl
|= PhyCtrlSpd10
;
1229 // FIXME: Whole branch guessed
1232 if (cmd
->speed
== SPEED_10
)
1233 phy_ctrl
|= PhyCtrlSpd10
;
1234 else /* cmd->speed == SPEED_100 */
1235 phy_ctrl
|= PhyCtrlSpd100
;
1237 if (cmd
->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
);
1307 spin_unlock_bh(&priv
->lock
);
1312 static int sc92031_ethtool_nway_reset(struct net_device
*dev
)
1315 struct sc92031_priv
*priv
= netdev_priv(dev
);
1316 void __iomem
*port_base
= priv
->port_base
;
1319 spin_lock_bh(&priv
->lock
);
1321 bmcr
= _sc92031_mii_read(port_base
, MII_BMCR
);
1322 if (!(bmcr
& BMCR_ANENABLE
)) {
1327 _sc92031_mii_write(port_base
, MII_BMCR
, bmcr
| BMCR_ANRESTART
);
1330 _sc92031_mii_scan(port_base
);
1333 spin_unlock_bh(&priv
->lock
);
1338 static const char sc92031_ethtool_stats_strings
[SILAN_STATS_NUM
][ETH_GSTRING_LEN
] = {
1343 static void sc92031_ethtool_get_strings(struct net_device
*dev
,
1344 u32 stringset
, u8
*data
)
1346 if (stringset
== ETH_SS_STATS
)
1347 memcpy(data
, sc92031_ethtool_stats_strings
,
1348 SILAN_STATS_NUM
* ETH_GSTRING_LEN
);
1351 static int sc92031_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1355 return SILAN_STATS_NUM
;
1361 static void sc92031_ethtool_get_ethtool_stats(struct net_device
*dev
,
1362 struct ethtool_stats
*stats
, u64
*data
)
1364 struct sc92031_priv
*priv
= netdev_priv(dev
);
1366 spin_lock_bh(&priv
->lock
);
1367 data
[0] = priv
->tx_timeouts
;
1368 data
[1] = priv
->rx_loss
;
1369 spin_unlock_bh(&priv
->lock
);
1372 static const struct ethtool_ops sc92031_ethtool_ops
= {
1373 .get_settings
= sc92031_ethtool_get_settings
,
1374 .set_settings
= sc92031_ethtool_set_settings
,
1375 .get_wol
= sc92031_ethtool_get_wol
,
1376 .set_wol
= sc92031_ethtool_set_wol
,
1377 .nway_reset
= sc92031_ethtool_nway_reset
,
1378 .get_link
= ethtool_op_get_link
,
1379 .get_strings
= sc92031_ethtool_get_strings
,
1380 .get_sset_count
= sc92031_ethtool_get_sset_count
,
1381 .get_ethtool_stats
= sc92031_ethtool_get_ethtool_stats
,
1385 static const struct net_device_ops sc92031_netdev_ops
= {
1386 .ndo_get_stats
= sc92031_get_stats
,
1387 .ndo_start_xmit
= sc92031_start_xmit
,
1388 .ndo_open
= sc92031_open
,
1389 .ndo_stop
= sc92031_stop
,
1390 .ndo_set_multicast_list
= sc92031_set_multicast_list
,
1391 .ndo_change_mtu
= eth_change_mtu
,
1392 .ndo_validate_addr
= eth_validate_addr
,
1393 .ndo_set_mac_address
= eth_mac_addr
,
1394 .ndo_tx_timeout
= sc92031_tx_timeout
,
1395 #ifdef CONFIG_NET_POLL_CONTROLLER
1396 .ndo_poll_controller
= sc92031_poll_controller
,
1400 static int __devinit
sc92031_probe(struct pci_dev
*pdev
,
1401 const struct pci_device_id
*id
)
1404 void __iomem
* port_base
;
1405 struct net_device
*dev
;
1406 struct sc92031_priv
*priv
;
1408 unsigned long base_addr
;
1410 err
= pci_enable_device(pdev
);
1411 if (unlikely(err
< 0))
1412 goto out_enable_device
;
1414 pci_set_master(pdev
);
1416 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1417 if (unlikely(err
< 0))
1418 goto out_set_dma_mask
;
1420 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1421 if (unlikely(err
< 0))
1422 goto out_set_dma_mask
;
1424 err
= pci_request_regions(pdev
, SC92031_NAME
);
1425 if (unlikely(err
< 0))
1426 goto out_request_regions
;
1428 port_base
= pci_iomap(pdev
, SC92031_USE_BAR
, 0);
1429 if (unlikely(!port_base
)) {
1434 dev
= alloc_etherdev(sizeof(struct sc92031_priv
));
1435 if (unlikely(!dev
)) {
1437 goto out_alloc_etherdev
;
1440 pci_set_drvdata(pdev
, dev
);
1441 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1443 #if SC92031_USE_BAR == 0
1444 dev
->mem_start
= pci_resource_start(pdev
, SC92031_USE_BAR
);
1445 dev
->mem_end
= pci_resource_end(pdev
, SC92031_USE_BAR
);
1446 #elif SC92031_USE_BAR == 1
1447 dev
->base_addr
= pci_resource_start(pdev
, SC92031_USE_BAR
);
1449 dev
->irq
= pdev
->irq
;
1451 /* faked with skb_copy_and_csum_dev */
1452 dev
->features
= NETIF_F_SG
| NETIF_F_HW_CSUM
| NETIF_F_HIGHDMA
;
1454 dev
->netdev_ops
= &sc92031_netdev_ops
;
1455 dev
->watchdog_timeo
= TX_TIMEOUT
;
1456 dev
->ethtool_ops
= &sc92031_ethtool_ops
;
1458 priv
= netdev_priv(dev
);
1459 spin_lock_init(&priv
->lock
);
1460 priv
->port_base
= port_base
;
1462 tasklet_init(&priv
->tasklet
, sc92031_tasklet
, (unsigned long)dev
);
1463 /* Fudge tasklet count so the call to sc92031_enable_interrupts at
1464 * sc92031_open will work correctly */
1465 tasklet_disable_nosync(&priv
->tasklet
);
1468 iowrite32((~PM_LongWF
& ~PM_LWPTN
) | PM_Enable
, port_base
+ PMConfig
);
1470 mac0
= ioread32(port_base
+ MAC0
);
1471 mac1
= ioread32(port_base
+ MAC0
+ 4);
1472 dev
->dev_addr
[0] = dev
->perm_addr
[0] = mac0
>> 24;
1473 dev
->dev_addr
[1] = dev
->perm_addr
[1] = mac0
>> 16;
1474 dev
->dev_addr
[2] = dev
->perm_addr
[2] = mac0
>> 8;
1475 dev
->dev_addr
[3] = dev
->perm_addr
[3] = mac0
;
1476 dev
->dev_addr
[4] = dev
->perm_addr
[4] = mac1
>> 8;
1477 dev
->dev_addr
[5] = dev
->perm_addr
[5] = mac1
;
1479 err
= register_netdev(dev
);
1481 goto out_register_netdev
;
1483 #if SC92031_USE_BAR == 0
1484 base_addr
= dev
->mem_start
;
1485 #elif SC92031_USE_BAR == 1
1486 base_addr
= dev
->base_addr
;
1488 printk(KERN_INFO
"%s: SC92031 at 0x%lx, %pM, IRQ %d\n", dev
->name
,
1489 base_addr
, dev
->dev_addr
, dev
->irq
);
1493 out_register_netdev
:
1496 pci_iounmap(pdev
, port_base
);
1498 pci_release_regions(pdev
);
1499 out_request_regions
:
1501 pci_disable_device(pdev
);
1506 static void __devexit
sc92031_remove(struct pci_dev
*pdev
)
1508 struct net_device
*dev
= pci_get_drvdata(pdev
);
1509 struct sc92031_priv
*priv
= netdev_priv(dev
);
1510 void __iomem
* port_base
= priv
->port_base
;
1512 unregister_netdev(dev
);
1514 pci_iounmap(pdev
, port_base
);
1515 pci_release_regions(pdev
);
1516 pci_disable_device(pdev
);
1519 static int sc92031_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1521 struct net_device
*dev
= pci_get_drvdata(pdev
);
1522 struct sc92031_priv
*priv
= netdev_priv(dev
);
1524 pci_save_state(pdev
);
1526 if (!netif_running(dev
))
1529 netif_device_detach(dev
);
1531 /* Disable interrupts, stop Tx and Rx. */
1532 sc92031_disable_interrupts(dev
);
1534 spin_lock_bh(&priv
->lock
);
1536 _sc92031_disable_tx_rx(dev
);
1537 _sc92031_tx_clear(dev
);
1540 spin_unlock_bh(&priv
->lock
);
1543 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1548 static int sc92031_resume(struct pci_dev
*pdev
)
1550 struct net_device
*dev
= pci_get_drvdata(pdev
);
1551 struct sc92031_priv
*priv
= netdev_priv(dev
);
1553 pci_restore_state(pdev
);
1554 pci_set_power_state(pdev
, PCI_D0
);
1556 if (!netif_running(dev
))
1559 /* Interrupts already disabled by sc92031_suspend */
1560 spin_lock_bh(&priv
->lock
);
1562 _sc92031_reset(dev
);
1565 spin_unlock_bh(&priv
->lock
);
1566 sc92031_enable_interrupts(dev
);
1568 netif_device_attach(dev
);
1570 if (netif_carrier_ok(dev
))
1571 netif_wake_queue(dev
);
1573 netif_tx_disable(dev
);
1579 static DEFINE_PCI_DEVICE_TABLE(sc92031_pci_device_id_table
) = {
1580 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x2031) },
1581 { PCI_DEVICE(PCI_VENDOR_ID_SILAN
, 0x8139) },
1582 { PCI_DEVICE(0x1088, 0x2031) },
1585 MODULE_DEVICE_TABLE(pci
, sc92031_pci_device_id_table
);
1587 static struct pci_driver sc92031_pci_driver
= {
1588 .name
= SC92031_NAME
,
1589 .id_table
= sc92031_pci_device_id_table
,
1590 .probe
= sc92031_probe
,
1591 .remove
= __devexit_p(sc92031_remove
),
1592 .suspend
= sc92031_suspend
,
1593 .resume
= sc92031_resume
,
1596 static int __init
sc92031_init(void)
1598 return pci_register_driver(&sc92031_pci_driver
);
1601 static void __exit
sc92031_exit(void)
1603 pci_unregister_driver(&sc92031_pci_driver
);
1606 module_init(sc92031_init
);
1607 module_exit(sc92031_exit
);
1609 MODULE_LICENSE("GPL");
1610 MODULE_AUTHOR("Cesar Eduardo Barros <cesarb@cesarb.net>");
1611 MODULE_DESCRIPTION("Silan SC92031 PCI Fast Ethernet Adapter driver");