blob: 8ad7bfbaa3afb07b61136e0284d8fce1fc25bd40 [file] [log] [blame]
Francois Romieu890e8d02005-07-30 13:08:43 +02001/*
2 sis190.c: Silicon Integrated Systems SiS190 ethernet driver
3
4 Copyright (c) 2003 K.M. Liu <kmliu@sis.com>
5 Copyright (c) 2003, 2004 Jeff Garzik <jgarzik@pobox.com>
6 Copyright (c) 2003, 2004, 2005 Francois Romieu <romieu@fr.zoreil.com>
7
Francois Romieu40292fb2005-07-30 13:12:06 +02008 Based on r8169.c, tg3.c, 8139cp.c, skge.c, epic100.c and SiS 190/191
9 genuine driver.
Francois Romieu890e8d02005-07-30 13:08:43 +020010
11 This software may be used and distributed according to the terms of
12 the GNU General Public License (GPL), incorporated herein by reference.
13 Drivers based on or derived from this code fall under the GPL and must
14 retain the authorship, copyright and license notice. This file is not
15 a complete program and may only be used when the entire operating
16 system is licensed under the GPL.
17
18 See the file COPYING in this distribution for more information.
19
Joe Perchesad06ab22010-02-17 20:00:17 +000020*/
21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Francois Romieu890e8d02005-07-30 13:08:43 +020023
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000024#include <linux/interrupt.h>
Francois Romieu890e8d02005-07-30 13:08:43 +020025#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/netdevice.h>
Francois Romieu43afb942005-07-30 13:10:21 +020028#include <linux/rtnetlink.h>
Francois Romieu890e8d02005-07-30 13:08:43 +020029#include <linux/etherdevice.h>
30#include <linux/ethtool.h>
31#include <linux/pci.h>
32#include <linux/mii.h>
33#include <linux/delay.h>
34#include <linux/crc32.h>
35#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Francois Romieu890e8d02005-07-30 13:08:43 +020037#include <asm/irq.h>
38
Francois Romieufcb98212005-07-30 13:15:22 +020039#define PHY_MAX_ADDR 32
40#define PHY_ID_ANY 0x1f
41#define MII_REG_ANY 0x1f
42
Riccardo Ghetta08326db2010-02-17 09:28:58 +000043#define DRV_VERSION "1.4"
Francois Romieu890e8d02005-07-30 13:08:43 +020044#define DRV_NAME "sis190"
45#define SIS190_DRIVER_NAME DRV_NAME " Gigabit Ethernet driver " DRV_VERSION
Francois Romieu890e8d02005-07-30 13:08:43 +020046
Francois Romieu890e8d02005-07-30 13:08:43 +020047#define sis190_rx_skb netif_rx
48#define sis190_rx_quota(count, quota) count
Francois Romieu890e8d02005-07-30 13:08:43 +020049
50#define MAC_ADDR_LEN 6
51
Francois Romieubcad5e52005-07-30 13:13:47 +020052#define NUM_TX_DESC 64 /* [8..1024] */
53#define NUM_RX_DESC 64 /* [8..8192] */
Francois Romieu890e8d02005-07-30 13:08:43 +020054#define TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
55#define RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
56#define RX_BUF_SIZE 1536
Francois Romieu8b5641d2005-07-30 13:13:03 +020057#define RX_BUF_MASK 0xfff8
Francois Romieu890e8d02005-07-30 13:08:43 +020058
59#define SIS190_REGS_SIZE 0x80
60#define SIS190_TX_TIMEOUT (6*HZ)
61#define SIS190_PHY_TIMEOUT (10*HZ)
62#define SIS190_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | \
63 NETIF_MSG_LINK | NETIF_MSG_IFUP | \
64 NETIF_MSG_IFDOWN)
65
66/* Enhanced PHY access register bit definitions */
67#define EhnMIIread 0x0000
68#define EhnMIIwrite 0x0020
69#define EhnMIIdataShift 16
70#define EhnMIIpmdShift 6 /* 7016 only */
71#define EhnMIIregShift 11
72#define EhnMIIreq 0x0010
73#define EhnMIInotDone 0x0010
74
75/* Write/read MMIO register */
76#define SIS_W8(reg, val) writeb ((val), ioaddr + (reg))
77#define SIS_W16(reg, val) writew ((val), ioaddr + (reg))
78#define SIS_W32(reg, val) writel ((val), ioaddr + (reg))
79#define SIS_R8(reg) readb (ioaddr + (reg))
80#define SIS_R16(reg) readw (ioaddr + (reg))
81#define SIS_R32(reg) readl (ioaddr + (reg))
82
83#define SIS_PCI_COMMIT() SIS_R32(IntrControl)
84
85enum sis190_registers {
86 TxControl = 0x00,
87 TxDescStartAddr = 0x04,
Francois Romieu188f23b2005-07-30 13:11:43 +020088 rsv0 = 0x08, // reserved
89 TxSts = 0x0c, // unused (Control/Status)
Francois Romieu890e8d02005-07-30 13:08:43 +020090 RxControl = 0x10,
91 RxDescStartAddr = 0x14,
Francois Romieu188f23b2005-07-30 13:11:43 +020092 rsv1 = 0x18, // reserved
93 RxSts = 0x1c, // unused
Francois Romieu890e8d02005-07-30 13:08:43 +020094 IntrStatus = 0x20,
95 IntrMask = 0x24,
96 IntrControl = 0x28,
Lucas De Marchi25985ed2011-03-30 22:57:33 -030097 IntrTimer = 0x2c, // unused (Interrupt Timer)
Francois Romieu188f23b2005-07-30 13:11:43 +020098 PMControl = 0x30, // unused (Power Mgmt Control/Status)
99 rsv2 = 0x34, // reserved
Francois Romieu890e8d02005-07-30 13:08:43 +0200100 ROMControl = 0x38,
101 ROMInterface = 0x3c,
102 StationControl = 0x40,
103 GMIIControl = 0x44,
Francois Romieu188f23b2005-07-30 13:11:43 +0200104 GIoCR = 0x48, // unused (GMAC IO Compensation)
105 GIoCtrl = 0x4c, // unused (GMAC IO Control)
Francois Romieu890e8d02005-07-30 13:08:43 +0200106 TxMacControl = 0x50,
Francois Romieu188f23b2005-07-30 13:11:43 +0200107 TxLimit = 0x54, // unused (Tx MAC Timer/TryLimit)
108 RGDelay = 0x58, // unused (RGMII Tx Internal Delay)
109 rsv3 = 0x5c, // reserved
Francois Romieu890e8d02005-07-30 13:08:43 +0200110 RxMacControl = 0x60,
111 RxMacAddr = 0x62,
112 RxHashTable = 0x68,
113 // Undocumented = 0x6c,
Francois Romieu188f23b2005-07-30 13:11:43 +0200114 RxWolCtrl = 0x70,
115 RxWolData = 0x74, // unused (Rx WOL Data Access)
116 RxMPSControl = 0x78, // unused (Rx MPS Control)
117 rsv4 = 0x7c, // reserved
Francois Romieu890e8d02005-07-30 13:08:43 +0200118};
119
120enum sis190_register_content {
121 /* IntrStatus */
122 SoftInt = 0x40000000, // unused
123 Timeup = 0x20000000, // unused
124 PauseFrame = 0x00080000, // unused
125 MagicPacket = 0x00040000, // unused
126 WakeupFrame = 0x00020000, // unused
127 LinkChange = 0x00010000,
128 RxQEmpty = 0x00000080,
129 RxQInt = 0x00000040,
130 TxQ1Empty = 0x00000020, // unused
131 TxQ1Int = 0x00000010,
132 TxQ0Empty = 0x00000008, // unused
133 TxQ0Int = 0x00000004,
134 RxHalt = 0x00000002,
135 TxHalt = 0x00000001,
136
Francois Romieu890e8d02005-07-30 13:08:43 +0200137 /* {Rx/Tx}CmdBits */
138 CmdReset = 0x10,
139 CmdRxEnb = 0x08, // unused
140 CmdTxEnb = 0x01,
141 RxBufEmpty = 0x01, // unused
142
143 /* Cfg9346Bits */
144 Cfg9346_Lock = 0x00, // unused
145 Cfg9346_Unlock = 0xc0, // unused
146
147 /* RxMacControl */
148 AcceptErr = 0x20, // unused
149 AcceptRunt = 0x10, // unused
150 AcceptBroadcast = 0x0800,
151 AcceptMulticast = 0x0400,
152 AcceptMyPhys = 0x0200,
153 AcceptAllPhys = 0x0100,
154
155 /* RxConfigBits */
156 RxCfgFIFOShift = 13,
157 RxCfgDMAShift = 8, // 0x1a in RxControl ?
158
159 /* TxConfigBits */
160 TxInterFrameGapShift = 24,
161 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
162
Francois Romieu890e8d02005-07-30 13:08:43 +0200163 LinkStatus = 0x02, // unused
164 FullDup = 0x01, // unused
165
166 /* TBICSRBit */
167 TBILinkOK = 0x02000000, // unused
168};
169
170struct TxDesc {
Francois Romieu3cec93c2005-07-30 13:14:18 +0200171 __le32 PSize;
172 __le32 status;
173 __le32 addr;
174 __le32 size;
Francois Romieu890e8d02005-07-30 13:08:43 +0200175};
176
177struct RxDesc {
Francois Romieu3cec93c2005-07-30 13:14:18 +0200178 __le32 PSize;
179 __le32 status;
180 __le32 addr;
181 __le32 size;
Francois Romieu890e8d02005-07-30 13:08:43 +0200182};
183
184enum _DescStatusBit {
185 /* _Desc.status */
Francois Romieubcad5e52005-07-30 13:13:47 +0200186 OWNbit = 0x80000000, // RXOWN/TXOWN
187 INTbit = 0x40000000, // RXINT/TXINT
188 CRCbit = 0x00020000, // CRCOFF/CRCEN
189 PADbit = 0x00010000, // PREADD/PADEN
Francois Romieu890e8d02005-07-30 13:08:43 +0200190 /* _Desc.size */
Francois Romieubcad5e52005-07-30 13:13:47 +0200191 RingEnd = 0x80000000,
192 /* TxDesc.status */
193 LSEN = 0x08000000, // TSO ? -- FR
194 IPCS = 0x04000000,
195 TCPCS = 0x02000000,
196 UDPCS = 0x01000000,
197 BSTEN = 0x00800000,
198 EXTEN = 0x00400000,
199 DEFEN = 0x00200000,
200 BKFEN = 0x00100000,
201 CRSEN = 0x00080000,
202 COLEN = 0x00040000,
203 THOL3 = 0x30000000,
204 THOL2 = 0x20000000,
205 THOL1 = 0x10000000,
206 THOL0 = 0x00000000,
Francois Romieu697c2692007-11-21 22:30:37 +0100207
208 WND = 0x00080000,
209 TABRT = 0x00040000,
210 FIFO = 0x00020000,
211 LINK = 0x00010000,
212 ColCountMask = 0x0000ffff,
Francois Romieubcad5e52005-07-30 13:13:47 +0200213 /* RxDesc.status */
214 IPON = 0x20000000,
215 TCPON = 0x10000000,
216 UDPON = 0x08000000,
217 Wakup = 0x00400000,
218 Magic = 0x00200000,
219 Pause = 0x00100000,
220 DEFbit = 0x00200000,
221 BCAST = 0x000c0000,
222 MCAST = 0x00080000,
223 UCAST = 0x00040000,
224 /* RxDesc.PSize */
225 TAGON = 0x80000000,
226 RxDescCountMask = 0x7f000000, // multi-desc pkt when > 1 ? -- FR
227 ABORT = 0x00800000,
228 SHORT = 0x00400000,
229 LIMIT = 0x00200000,
230 MIIER = 0x00100000,
231 OVRUN = 0x00080000,
232 NIBON = 0x00040000,
233 COLON = 0x00020000,
234 CRCOK = 0x00010000,
Francois Romieu890e8d02005-07-30 13:08:43 +0200235 RxSizeMask = 0x0000ffff
Francois Romieubcad5e52005-07-30 13:13:47 +0200236 /*
237 * The asic could apparently do vlan, TSO, jumbo (sis191 only) and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300238 * provide two (unused with Linux) Tx queues. No publicly
Francois Romieubcad5e52005-07-30 13:13:47 +0200239 * available documentation alas.
240 */
Francois Romieu890e8d02005-07-30 13:08:43 +0200241};
242
Francois Romieu40292fb2005-07-30 13:12:06 +0200243enum sis190_eeprom_access_register_bits {
244 EECS = 0x00000001, // unused
245 EECLK = 0x00000002, // unused
246 EEDO = 0x00000008, // unused
247 EEDI = 0x00000004, // unused
248 EEREQ = 0x00000080,
249 EEROP = 0x00000200,
250 EEWOP = 0x00000100 // unused
251};
252
Francois Romieu830fb7d2005-07-30 13:12:37 +0200253/* EEPROM Addresses */
254enum sis190_eeprom_address {
255 EEPROMSignature = 0x00,
256 EEPROMCLK = 0x01, // unused
257 EEPROMInfo = 0x02,
258 EEPROMMACAddr = 0x03
259};
260
Francois Romieu900eb9d2005-09-03 00:55:27 +0200261enum sis190_feature {
262 F_HAS_RGMII = 1,
Francois Romieuc3d6f1f2005-09-03 00:56:57 +0200263 F_PHY_88E1111 = 2,
264 F_PHY_BCM5461 = 4
Francois Romieu900eb9d2005-09-03 00:55:27 +0200265};
266
Francois Romieu890e8d02005-07-30 13:08:43 +0200267struct sis190_private {
268 void __iomem *mmio_addr;
269 struct pci_dev *pci_dev;
David Howellsc4028952006-11-22 14:57:56 +0000270 struct net_device *dev;
Francois Romieu890e8d02005-07-30 13:08:43 +0200271 spinlock_t lock;
272 u32 rx_buf_sz;
273 u32 cur_rx;
274 u32 cur_tx;
275 u32 dirty_rx;
276 u32 dirty_tx;
277 dma_addr_t rx_dma;
278 dma_addr_t tx_dma;
279 struct RxDesc *RxDescRing;
280 struct TxDesc *TxDescRing;
281 struct sk_buff *Rx_skbuff[NUM_RX_DESC];
282 struct sk_buff *Tx_skbuff[NUM_TX_DESC];
283 struct work_struct phy_task;
284 struct timer_list timer;
285 u32 msg_enable;
Francois Romieu43afb942005-07-30 13:10:21 +0200286 struct mii_if_info mii_if;
Francois Romieufcb98212005-07-30 13:15:22 +0200287 struct list_head first_phy;
Francois Romieu900eb9d2005-09-03 00:55:27 +0200288 u32 features;
Riccardo Ghetta08326db2010-02-17 09:28:58 +0000289 u32 negotiated_lpa;
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -0800290 enum {
291 LNK_OFF,
292 LNK_ON,
293 LNK_AUTONEG,
294 } link_status;
Francois Romieufcb98212005-07-30 13:15:22 +0200295};
296
297struct sis190_phy {
298 struct list_head list;
299 int phy_id;
300 u16 id[2];
301 u16 status;
302 u8 type;
303};
304
305enum sis190_phy_type {
306 UNKNOWN = 0x00,
307 HOME = 0x01,
308 LAN = 0x02,
309 MIX = 0x03
310};
311
312static struct mii_chip_info {
313 const char *name;
314 u16 id[2];
315 unsigned int type;
Francois Romieu900eb9d2005-09-03 00:55:27 +0200316 u32 feature;
Francois Romieufcb98212005-07-30 13:15:22 +0200317} mii_chip_table[] = {
Riccardo Ghetta856f8f42009-06-04 09:05:07 +0000318 { "Atheros PHY", { 0x004d, 0xd010 }, LAN, 0 },
Francois Romieu708f6e22008-10-20 23:37:55 +0200319 { "Atheros PHY AR8012", { 0x004d, 0xd020 }, LAN, 0 },
Francois Romieuc3d6f1f2005-09-03 00:56:57 +0200320 { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN, F_PHY_BCM5461 },
Francois Romieubd7a4442007-03-29 00:18:50 +0200321 { "Broadcom PHY AC131", { 0x0143, 0xbc70 }, LAN, 0 },
Francois Romieu900eb9d2005-09-03 00:55:27 +0200322 { "Agere PHY ET1101B", { 0x0282, 0xf010 }, LAN, 0 },
323 { "Marvell PHY 88E1111", { 0x0141, 0x0cc0 }, LAN, F_PHY_88E1111 },
324 { "Realtek PHY RTL8201", { 0x0000, 0x8200 }, LAN, 0 },
Francois Romieufcb98212005-07-30 13:15:22 +0200325 { NULL, }
Francois Romieu890e8d02005-07-30 13:08:43 +0200326};
327
Jesper Juhl3c6bee12006-01-09 20:54:01 -0800328static const struct {
Francois Romieu890e8d02005-07-30 13:08:43 +0200329 const char *name;
Francois Romieu890e8d02005-07-30 13:08:43 +0200330} sis_chip_info[] = {
Francois Romieue7976372005-09-03 00:57:51 +0200331 { "SiS 190 PCI Fast Ethernet adapter" },
332 { "SiS 191 PCI Gigabit Ethernet adapter" },
Francois Romieu890e8d02005-07-30 13:08:43 +0200333};
334
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000335static DEFINE_PCI_DEVICE_TABLE(sis190_pci_tbl) = {
Francois Romieu890e8d02005-07-30 13:08:43 +0200336 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 },
Francois Romieue7976372005-09-03 00:57:51 +0200337 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0191), 0, 0, 1 },
Francois Romieu890e8d02005-07-30 13:08:43 +0200338 { 0, },
339};
340
341MODULE_DEVICE_TABLE(pci, sis190_pci_tbl);
342
343static int rx_copybreak = 200;
344
345static struct {
346 u32 msg_enable;
347} debug = { -1 };
348
Riccardo Ghettac3223d22009-06-04 09:04:55 +0000349MODULE_DESCRIPTION("SiS sis190/191 Gigabit Ethernet driver");
Francois Romieu890e8d02005-07-30 13:08:43 +0200350module_param(rx_copybreak, int, 0);
351MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
352module_param_named(debug, debug.msg_enable, int, 0);
353MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
354MODULE_AUTHOR("K.M. Liu <kmliu@sis.com>, Ueimor <romieu@fr.zoreil.com>");
355MODULE_VERSION(DRV_VERSION);
356MODULE_LICENSE("GPL");
357
358static const u32 sis190_intr_mask =
Francois Romieu21461382005-09-03 00:54:25 +0200359 RxQEmpty | RxQInt | TxQ1Int | TxQ0Int | RxHalt | TxHalt | LinkChange;
Francois Romieu890e8d02005-07-30 13:08:43 +0200360
361/*
362 * Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
363 * The chips use a 64 element hash table based on the Ethernet CRC.
364 */
Arjan van de Venf71e1302006-03-03 21:33:57 -0500365static const int multicast_filter_limit = 32;
Francois Romieu890e8d02005-07-30 13:08:43 +0200366
367static void __mdio_cmd(void __iomem *ioaddr, u32 ctl)
368{
369 unsigned int i;
370
371 SIS_W32(GMIIControl, ctl);
372
373 msleep(1);
374
375 for (i = 0; i < 100; i++) {
376 if (!(SIS_R32(GMIIControl) & EhnMIInotDone))
377 break;
378 msleep(1);
379 }
380
Francois Romieu7bf3f232007-11-17 16:56:43 +0100381 if (i > 99)
Joe Perchesad06ab22010-02-17 20:00:17 +0000382 pr_err("PHY command failed !\n");
Francois Romieu890e8d02005-07-30 13:08:43 +0200383}
384
Francois Romieu9ede1092005-07-30 13:14:38 +0200385static void mdio_write(void __iomem *ioaddr, int phy_id, int reg, int val)
Francois Romieu890e8d02005-07-30 13:08:43 +0200386{
Francois Romieu890e8d02005-07-30 13:08:43 +0200387 __mdio_cmd(ioaddr, EhnMIIreq | EhnMIIwrite |
Francois Romieu9ede1092005-07-30 13:14:38 +0200388 (((u32) reg) << EhnMIIregShift) | (phy_id << EhnMIIpmdShift) |
Francois Romieu890e8d02005-07-30 13:08:43 +0200389 (((u32) val) << EhnMIIdataShift));
390}
391
Francois Romieu9ede1092005-07-30 13:14:38 +0200392static int mdio_read(void __iomem *ioaddr, int phy_id, int reg)
Francois Romieu890e8d02005-07-30 13:08:43 +0200393{
Francois Romieu890e8d02005-07-30 13:08:43 +0200394 __mdio_cmd(ioaddr, EhnMIIreq | EhnMIIread |
Francois Romieu9ede1092005-07-30 13:14:38 +0200395 (((u32) reg) << EhnMIIregShift) | (phy_id << EhnMIIpmdShift));
Francois Romieu890e8d02005-07-30 13:08:43 +0200396
397 return (u16) (SIS_R32(GMIIControl) >> EhnMIIdataShift);
398}
399
Francois Romieu43afb942005-07-30 13:10:21 +0200400static void __mdio_write(struct net_device *dev, int phy_id, int reg, int val)
401{
402 struct sis190_private *tp = netdev_priv(dev);
403
Francois Romieu9ede1092005-07-30 13:14:38 +0200404 mdio_write(tp->mmio_addr, phy_id, reg, val);
Francois Romieu43afb942005-07-30 13:10:21 +0200405}
406
407static int __mdio_read(struct net_device *dev, int phy_id, int reg)
408{
409 struct sis190_private *tp = netdev_priv(dev);
410
Francois Romieu9ede1092005-07-30 13:14:38 +0200411 return mdio_read(tp->mmio_addr, phy_id, reg);
Francois Romieu43afb942005-07-30 13:10:21 +0200412}
413
Francois Romieufc10c392005-07-30 13:15:01 +0200414static u16 mdio_read_latched(void __iomem *ioaddr, int phy_id, int reg)
415{
416 mdio_read(ioaddr, phy_id, reg);
417 return mdio_read(ioaddr, phy_id, reg);
418}
419
Francois Romieu40292fb2005-07-30 13:12:06 +0200420static u16 __devinit sis190_read_eeprom(void __iomem *ioaddr, u32 reg)
Francois Romieu890e8d02005-07-30 13:08:43 +0200421{
Francois Romieu40292fb2005-07-30 13:12:06 +0200422 u16 data = 0xffff;
Francois Romieu890e8d02005-07-30 13:08:43 +0200423 unsigned int i;
Francois Romieu890e8d02005-07-30 13:08:43 +0200424
425 if (!(SIS_R32(ROMControl) & 0x0002))
426 return 0;
427
Francois Romieu40292fb2005-07-30 13:12:06 +0200428 SIS_W32(ROMInterface, EEREQ | EEROP | (reg << 10));
Francois Romieu890e8d02005-07-30 13:08:43 +0200429
430 for (i = 0; i < 200; i++) {
Francois Romieu40292fb2005-07-30 13:12:06 +0200431 if (!(SIS_R32(ROMInterface) & EEREQ)) {
432 data = (SIS_R32(ROMInterface) & 0xffff0000) >> 16;
Francois Romieu890e8d02005-07-30 13:08:43 +0200433 break;
Francois Romieu40292fb2005-07-30 13:12:06 +0200434 }
Francois Romieu890e8d02005-07-30 13:08:43 +0200435 msleep(1);
436 }
437
Francois Romieu890e8d02005-07-30 13:08:43 +0200438 return data;
439}
440
441static void sis190_irq_mask_and_ack(void __iomem *ioaddr)
442{
443 SIS_W32(IntrMask, 0x00);
444 SIS_W32(IntrStatus, 0xffffffff);
445 SIS_PCI_COMMIT();
446}
447
448static void sis190_asic_down(void __iomem *ioaddr)
449{
450 /* Stop the chip's Tx and Rx DMA processes. */
451
452 SIS_W32(TxControl, 0x1a00);
453 SIS_W32(RxControl, 0x1a00);
454
455 sis190_irq_mask_and_ack(ioaddr);
456}
457
458static void sis190_mark_as_last_descriptor(struct RxDesc *desc)
459{
460 desc->size |= cpu_to_le32(RingEnd);
461}
462
463static inline void sis190_give_to_asic(struct RxDesc *desc, u32 rx_buf_sz)
464{
465 u32 eor = le32_to_cpu(desc->size) & RingEnd;
466
467 desc->PSize = 0x0;
Francois Romieu8b5641d2005-07-30 13:13:03 +0200468 desc->size = cpu_to_le32((rx_buf_sz & RX_BUF_MASK) | eor);
Francois Romieu890e8d02005-07-30 13:08:43 +0200469 wmb();
470 desc->status = cpu_to_le32(OWNbit | INTbit);
471}
472
473static inline void sis190_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
474 u32 rx_buf_sz)
475{
476 desc->addr = cpu_to_le32(mapping);
477 sis190_give_to_asic(desc, rx_buf_sz);
478}
479
480static inline void sis190_make_unusable_by_asic(struct RxDesc *desc)
481{
482 desc->PSize = 0x0;
Al Viro961994a2007-12-15 01:44:33 +0000483 desc->addr = cpu_to_le32(0xdeadbeef);
Francois Romieu890e8d02005-07-30 13:08:43 +0200484 desc->size &= cpu_to_le32(RingEnd);
485 wmb();
486 desc->status = 0x0;
487}
488
Stephen Hemminger35aeb782008-04-27 14:54:32 +0200489static struct sk_buff *sis190_alloc_rx_skb(struct sis190_private *tp,
490 struct RxDesc *desc)
Francois Romieu890e8d02005-07-30 13:08:43 +0200491{
Stephen Hemminger35aeb782008-04-27 14:54:32 +0200492 u32 rx_buf_sz = tp->rx_buf_sz;
Francois Romieu890e8d02005-07-30 13:08:43 +0200493 struct sk_buff *skb;
kirjanov@gmail.come382c302010-02-24 08:41:18 +0000494 dma_addr_t mapping;
Francois Romieu890e8d02005-07-30 13:08:43 +0200495
Stephen Hemminger35aeb782008-04-27 14:54:32 +0200496 skb = netdev_alloc_skb(tp->dev, rx_buf_sz);
kirjanov@gmail.come382c302010-02-24 08:41:18 +0000497 if (unlikely(!skb))
498 goto skb_alloc_failed;
499 mapping = pci_map_single(tp->pci_dev, skb->data, tp->rx_buf_sz,
500 PCI_DMA_FROMDEVICE);
501 if (pci_dma_mapping_error(tp->pci_dev, mapping))
502 goto out;
503 sis190_map_to_asic(desc, mapping, rx_buf_sz);
Francois Romieu890e8d02005-07-30 13:08:43 +0200504
Stephen Hemminger4709aa52008-04-27 14:36:59 +0200505 return skb;
kirjanov@gmail.come382c302010-02-24 08:41:18 +0000506
507out:
508 dev_kfree_skb_any(skb);
509skb_alloc_failed:
510 sis190_make_unusable_by_asic(desc);
511 return NULL;
Francois Romieu890e8d02005-07-30 13:08:43 +0200512}
513
514static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev,
515 u32 start, u32 end)
516{
517 u32 cur;
518
519 for (cur = start; cur < end; cur++) {
Stephen Hemminger4709aa52008-04-27 14:36:59 +0200520 unsigned int i = cur % NUM_RX_DESC;
Francois Romieu890e8d02005-07-30 13:08:43 +0200521
522 if (tp->Rx_skbuff[i])
523 continue;
524
Stephen Hemminger35aeb782008-04-27 14:54:32 +0200525 tp->Rx_skbuff[i] = sis190_alloc_rx_skb(tp, tp->RxDescRing + i);
526
Stephen Hemminger4709aa52008-04-27 14:36:59 +0200527 if (!tp->Rx_skbuff[i])
Francois Romieu890e8d02005-07-30 13:08:43 +0200528 break;
529 }
530 return cur - start;
531}
532
Francois Romieu47e47812008-04-27 17:59:52 +0200533static bool sis190_try_rx_copy(struct sis190_private *tp,
534 struct sk_buff **sk_buff, int pkt_size,
535 dma_addr_t addr)
Francois Romieu890e8d02005-07-30 13:08:43 +0200536{
Francois Romieu47e47812008-04-27 17:59:52 +0200537 struct sk_buff *skb;
538 bool done = false;
Francois Romieu890e8d02005-07-30 13:08:43 +0200539
Francois Romieu47e47812008-04-27 17:59:52 +0200540 if (pkt_size >= rx_copybreak)
541 goto out;
Francois Romieu890e8d02005-07-30 13:08:43 +0200542
Eric Dumazet89d71a62009-10-13 05:34:20 +0000543 skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size);
Francois Romieu47e47812008-04-27 17:59:52 +0200544 if (!skb)
545 goto out;
546
Riccardo Ghetta744c6b22009-06-07 19:47:58 +0000547 pci_dma_sync_single_for_cpu(tp->pci_dev, addr, tp->rx_buf_sz,
548 PCI_DMA_FROMDEVICE);
Francois Romieu47e47812008-04-27 17:59:52 +0200549 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
550 *sk_buff = skb;
551 done = true;
552out:
553 return done;
Francois Romieu890e8d02005-07-30 13:08:43 +0200554}
555
Francois Romieubcad5e52005-07-30 13:13:47 +0200556static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats)
557{
558#define ErrMask (OVRUN | SHORT | LIMIT | MIIER | NIBON | COLON | ABORT)
559
560 if ((status & CRCOK) && !(status & ErrMask))
561 return 0;
562
563 if (!(status & CRCOK))
564 stats->rx_crc_errors++;
565 else if (status & OVRUN)
566 stats->rx_over_errors++;
567 else if (status & (SHORT | LIMIT))
568 stats->rx_length_errors++;
569 else if (status & (MIIER | NIBON | COLON))
570 stats->rx_frame_errors++;
571
572 stats->rx_errors++;
573 return -1;
574}
575
Francois Romieu890e8d02005-07-30 13:08:43 +0200576static int sis190_rx_interrupt(struct net_device *dev,
577 struct sis190_private *tp, void __iomem *ioaddr)
578{
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700579 struct net_device_stats *stats = &dev->stats;
Francois Romieu890e8d02005-07-30 13:08:43 +0200580 u32 rx_left, cur_rx = tp->cur_rx;
581 u32 delta, count;
582
583 rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx;
584 rx_left = sis190_rx_quota(rx_left, (u32) dev->quota);
585
586 for (; rx_left > 0; rx_left--, cur_rx++) {
587 unsigned int entry = cur_rx % NUM_RX_DESC;
588 struct RxDesc *desc = tp->RxDescRing + entry;
589 u32 status;
590
Al Viro961994a2007-12-15 01:44:33 +0000591 if (le32_to_cpu(desc->status) & OWNbit)
Francois Romieu890e8d02005-07-30 13:08:43 +0200592 break;
593
594 status = le32_to_cpu(desc->PSize);
595
Joe Perchesad06ab22010-02-17 20:00:17 +0000596 //netif_info(tp, intr, dev, "Rx PSize = %08x\n", status);
Francois Romieu890e8d02005-07-30 13:08:43 +0200597
Francois Romieubcad5e52005-07-30 13:13:47 +0200598 if (sis190_rx_pkt_err(status, stats) < 0)
Francois Romieu890e8d02005-07-30 13:08:43 +0200599 sis190_give_to_asic(desc, tp->rx_buf_sz);
Francois Romieubcad5e52005-07-30 13:13:47 +0200600 else {
Francois Romieu890e8d02005-07-30 13:08:43 +0200601 struct sk_buff *skb = tp->Rx_skbuff[entry];
Francois Romieu47e47812008-04-27 17:59:52 +0200602 dma_addr_t addr = le32_to_cpu(desc->addr);
Francois Romieu890e8d02005-07-30 13:08:43 +0200603 int pkt_size = (status & RxSizeMask) - 4;
Francois Romieu47e47812008-04-27 17:59:52 +0200604 struct pci_dev *pdev = tp->pci_dev;
Francois Romieu890e8d02005-07-30 13:08:43 +0200605
606 if (unlikely(pkt_size > tp->rx_buf_sz)) {
Joe Perchesad06ab22010-02-17 20:00:17 +0000607 netif_info(tp, intr, dev,
608 "(frag) status = %08x\n", status);
Francois Romieu890e8d02005-07-30 13:08:43 +0200609 stats->rx_dropped++;
610 stats->rx_length_errors++;
611 sis190_give_to_asic(desc, tp->rx_buf_sz);
612 continue;
613 }
614
Francois Romieu890e8d02005-07-30 13:08:43 +0200615
Francois Romieu47e47812008-04-27 17:59:52 +0200616 if (sis190_try_rx_copy(tp, &skb, pkt_size, addr)) {
617 pci_dma_sync_single_for_device(pdev, addr,
618 tp->rx_buf_sz, PCI_DMA_FROMDEVICE);
619 sis190_give_to_asic(desc, tp->rx_buf_sz);
620 } else {
621 pci_unmap_single(pdev, addr, tp->rx_buf_sz,
622 PCI_DMA_FROMDEVICE);
Francois Romieu890e8d02005-07-30 13:08:43 +0200623 tp->Rx_skbuff[entry] = NULL;
624 sis190_make_unusable_by_asic(desc);
625 }
626
Francois Romieu890e8d02005-07-30 13:08:43 +0200627 skb_put(skb, pkt_size);
628 skb->protocol = eth_type_trans(skb, dev);
629
630 sis190_rx_skb(skb);
631
Francois Romieu890e8d02005-07-30 13:08:43 +0200632 stats->rx_packets++;
Francois Romieubcad5e52005-07-30 13:13:47 +0200633 stats->rx_bytes += pkt_size;
634 if ((status & BCAST) == MCAST)
635 stats->multicast++;
Francois Romieu890e8d02005-07-30 13:08:43 +0200636 }
637 }
638 count = cur_rx - tp->cur_rx;
639 tp->cur_rx = cur_rx;
640
641 delta = sis190_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx);
Joe Perchesad06ab22010-02-17 20:00:17 +0000642 if (!delta && count)
643 netif_info(tp, intr, dev, "no Rx buffer allocated\n");
Francois Romieu890e8d02005-07-30 13:08:43 +0200644 tp->dirty_rx += delta;
645
Joe Perchesad06ab22010-02-17 20:00:17 +0000646 if ((tp->dirty_rx + NUM_RX_DESC) == tp->cur_rx)
647 netif_emerg(tp, intr, dev, "Rx buffers exhausted\n");
Francois Romieu890e8d02005-07-30 13:08:43 +0200648
649 return count;
650}
651
652static void sis190_unmap_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
653 struct TxDesc *desc)
654{
655 unsigned int len;
656
657 len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
658
659 pci_unmap_single(pdev, le32_to_cpu(desc->addr), len, PCI_DMA_TODEVICE);
660
661 memset(desc, 0x00, sizeof(*desc));
662}
663
Francois Romieu697c2692007-11-21 22:30:37 +0100664static inline int sis190_tx_pkt_err(u32 status, struct net_device_stats *stats)
665{
666#define TxErrMask (WND | TABRT | FIFO | LINK)
667
668 if (!unlikely(status & TxErrMask))
669 return 0;
670
671 if (status & WND)
672 stats->tx_window_errors++;
673 if (status & TABRT)
674 stats->tx_aborted_errors++;
675 if (status & FIFO)
676 stats->tx_fifo_errors++;
677 if (status & LINK)
678 stats->tx_carrier_errors++;
679
680 stats->tx_errors++;
681
682 return -1;
683}
684
Francois Romieu890e8d02005-07-30 13:08:43 +0200685static void sis190_tx_interrupt(struct net_device *dev,
686 struct sis190_private *tp, void __iomem *ioaddr)
687{
Francois Romieu697c2692007-11-21 22:30:37 +0100688 struct net_device_stats *stats = &dev->stats;
Francois Romieu890e8d02005-07-30 13:08:43 +0200689 u32 pending, dirty_tx = tp->dirty_tx;
690 /*
691 * It would not be needed if queueing was allowed to be enabled
692 * again too early (hint: think preempt and unclocked smp systems).
693 */
694 unsigned int queue_stopped;
695
696 smp_rmb();
697 pending = tp->cur_tx - dirty_tx;
698 queue_stopped = (pending == NUM_TX_DESC);
699
700 for (; pending; pending--, dirty_tx++) {
701 unsigned int entry = dirty_tx % NUM_TX_DESC;
702 struct TxDesc *txd = tp->TxDescRing + entry;
Francois Romieu697c2692007-11-21 22:30:37 +0100703 u32 status = le32_to_cpu(txd->status);
Francois Romieu890e8d02005-07-30 13:08:43 +0200704 struct sk_buff *skb;
705
Francois Romieu697c2692007-11-21 22:30:37 +0100706 if (status & OWNbit)
Francois Romieu890e8d02005-07-30 13:08:43 +0200707 break;
708
709 skb = tp->Tx_skbuff[entry];
710
Francois Romieu697c2692007-11-21 22:30:37 +0100711 if (likely(sis190_tx_pkt_err(status, stats) == 0)) {
712 stats->tx_packets++;
713 stats->tx_bytes += skb->len;
714 stats->collisions += ((status & ColCountMask) - 1);
715 }
Francois Romieu890e8d02005-07-30 13:08:43 +0200716
717 sis190_unmap_tx_skb(tp->pci_dev, skb, txd);
718 tp->Tx_skbuff[entry] = NULL;
719 dev_kfree_skb_irq(skb);
720 }
721
722 if (tp->dirty_tx != dirty_tx) {
723 tp->dirty_tx = dirty_tx;
724 smp_wmb();
725 if (queue_stopped)
726 netif_wake_queue(dev);
727 }
728}
729
730/*
731 * The interrupt handler does all of the Rx thread work and cleans up after
732 * the Tx thread.
733 */
David Howells7d12e782006-10-05 14:55:46 +0100734static irqreturn_t sis190_interrupt(int irq, void *__dev)
Francois Romieu890e8d02005-07-30 13:08:43 +0200735{
736 struct net_device *dev = __dev;
737 struct sis190_private *tp = netdev_priv(dev);
738 void __iomem *ioaddr = tp->mmio_addr;
739 unsigned int handled = 0;
740 u32 status;
741
742 status = SIS_R32(IntrStatus);
743
744 if ((status == 0xffffffff) || !status)
745 goto out;
746
747 handled = 1;
748
749 if (unlikely(!netif_running(dev))) {
750 sis190_asic_down(ioaddr);
751 goto out;
752 }
753
754 SIS_W32(IntrStatus, status);
755
Joe Perchesad06ab22010-02-17 20:00:17 +0000756// netif_info(tp, intr, dev, "status = %08x\n", status);
Francois Romieu890e8d02005-07-30 13:08:43 +0200757
758 if (status & LinkChange) {
Joe Perchesad06ab22010-02-17 20:00:17 +0000759 netif_info(tp, intr, dev, "link change\n");
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -0800760 del_timer(&tp->timer);
Francois Romieu890e8d02005-07-30 13:08:43 +0200761 schedule_work(&tp->phy_task);
762 }
763
764 if (status & RxQInt)
765 sis190_rx_interrupt(dev, tp, ioaddr);
766
767 if (status & TxQ0Int)
768 sis190_tx_interrupt(dev, tp, ioaddr);
769out:
770 return IRQ_RETVAL(handled);
771}
772
Francois Romieu4405d3b2005-07-30 13:09:20 +0200773#ifdef CONFIG_NET_POLL_CONTROLLER
774static void sis190_netpoll(struct net_device *dev)
775{
776 struct sis190_private *tp = netdev_priv(dev);
777 struct pci_dev *pdev = tp->pci_dev;
778
779 disable_irq(pdev->irq);
David Howells7d12e782006-10-05 14:55:46 +0100780 sis190_interrupt(pdev->irq, dev);
Francois Romieu4405d3b2005-07-30 13:09:20 +0200781 enable_irq(pdev->irq);
782}
783#endif
784
Francois Romieu890e8d02005-07-30 13:08:43 +0200785static void sis190_free_rx_skb(struct sis190_private *tp,
786 struct sk_buff **sk_buff, struct RxDesc *desc)
787{
788 struct pci_dev *pdev = tp->pci_dev;
789
790 pci_unmap_single(pdev, le32_to_cpu(desc->addr), tp->rx_buf_sz,
791 PCI_DMA_FROMDEVICE);
792 dev_kfree_skb(*sk_buff);
793 *sk_buff = NULL;
794 sis190_make_unusable_by_asic(desc);
795}
796
797static void sis190_rx_clear(struct sis190_private *tp)
798{
799 unsigned int i;
800
801 for (i = 0; i < NUM_RX_DESC; i++) {
802 if (!tp->Rx_skbuff[i])
803 continue;
804 sis190_free_rx_skb(tp, tp->Rx_skbuff + i, tp->RxDescRing + i);
805 }
806}
807
808static void sis190_init_ring_indexes(struct sis190_private *tp)
809{
810 tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0;
811}
812
813static int sis190_init_ring(struct net_device *dev)
814{
815 struct sis190_private *tp = netdev_priv(dev);
816
817 sis190_init_ring_indexes(tp);
818
819 memset(tp->Tx_skbuff, 0x0, NUM_TX_DESC * sizeof(struct sk_buff *));
820 memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *));
821
822 if (sis190_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC)
823 goto err_rx_clear;
824
825 sis190_mark_as_last_descriptor(tp->RxDescRing + NUM_RX_DESC - 1);
826
827 return 0;
828
829err_rx_clear:
830 sis190_rx_clear(tp);
831 return -ENOMEM;
832}
833
834static void sis190_set_rx_mode(struct net_device *dev)
835{
836 struct sis190_private *tp = netdev_priv(dev);
837 void __iomem *ioaddr = tp->mmio_addr;
838 unsigned long flags;
839 u32 mc_filter[2]; /* Multicast hash filter */
840 u16 rx_mode;
841
842 if (dev->flags & IFF_PROMISC) {
Francois Romieu890e8d02005-07-30 13:08:43 +0200843 rx_mode =
844 AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
845 AcceptAllPhys;
846 mc_filter[1] = mc_filter[0] = 0xffffffff;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000847 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
Francois Romieu890e8d02005-07-30 13:08:43 +0200848 (dev->flags & IFF_ALLMULTI)) {
849 /* Too many to filter perfectly -- accept all multicasts. */
850 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
851 mc_filter[1] = mc_filter[0] = 0xffffffff;
852 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000853 struct netdev_hw_addr *ha;
Francois Romieu890e8d02005-07-30 13:08:43 +0200854
855 rx_mode = AcceptBroadcast | AcceptMyPhys;
856 mc_filter[1] = mc_filter[0] = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000857 netdev_for_each_mc_addr(ha, dev) {
Francois Romieu890e8d02005-07-30 13:08:43 +0200858 int bit_nr =
Jiri Pirko22bedad32010-04-01 21:22:57 +0000859 ether_crc(ETH_ALEN, ha->addr) & 0x3f;
Francois Romieu890e8d02005-07-30 13:08:43 +0200860 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
861 rx_mode |= AcceptMulticast;
862 }
863 }
864
865 spin_lock_irqsave(&tp->lock, flags);
866
867 SIS_W16(RxMacControl, rx_mode | 0x2);
868 SIS_W32(RxHashTable, mc_filter[0]);
869 SIS_W32(RxHashTable + 4, mc_filter[1]);
870
871 spin_unlock_irqrestore(&tp->lock, flags);
872}
873
874static void sis190_soft_reset(void __iomem *ioaddr)
875{
876 SIS_W32(IntrControl, 0x8000);
877 SIS_PCI_COMMIT();
Francois Romieu890e8d02005-07-30 13:08:43 +0200878 SIS_W32(IntrControl, 0x0);
879 sis190_asic_down(ioaddr);
Francois Romieu890e8d02005-07-30 13:08:43 +0200880}
881
882static void sis190_hw_start(struct net_device *dev)
883{
884 struct sis190_private *tp = netdev_priv(dev);
885 void __iomem *ioaddr = tp->mmio_addr;
886
887 sis190_soft_reset(ioaddr);
888
889 SIS_W32(TxDescStartAddr, tp->tx_dma);
890 SIS_W32(RxDescStartAddr, tp->rx_dma);
891
892 SIS_W32(IntrStatus, 0xffffffff);
893 SIS_W32(IntrMask, 0x0);
Francois Romieu890e8d02005-07-30 13:08:43 +0200894 SIS_W32(GMIIControl, 0x0);
895 SIS_W32(TxMacControl, 0x60);
896 SIS_W16(RxMacControl, 0x02);
897 SIS_W32(RxHashTable, 0x0);
898 SIS_W32(0x6c, 0x0);
Francois Romieu188f23b2005-07-30 13:11:43 +0200899 SIS_W32(RxWolCtrl, 0x0);
900 SIS_W32(RxWolData, 0x0);
Francois Romieu890e8d02005-07-30 13:08:43 +0200901
902 SIS_PCI_COMMIT();
903
904 sis190_set_rx_mode(dev);
905
906 /* Enable all known interrupts by setting the interrupt mask. */
907 SIS_W32(IntrMask, sis190_intr_mask);
908
909 SIS_W32(TxControl, 0x1a00 | CmdTxEnb);
910 SIS_W32(RxControl, 0x1a1d);
911
912 netif_start_queue(dev);
913}
914
David Howellsc4028952006-11-22 14:57:56 +0000915static void sis190_phy_task(struct work_struct *work)
Francois Romieu890e8d02005-07-30 13:08:43 +0200916{
David Howellsc4028952006-11-22 14:57:56 +0000917 struct sis190_private *tp =
918 container_of(work, struct sis190_private, phy_task);
919 struct net_device *dev = tp->dev;
Francois Romieu890e8d02005-07-30 13:08:43 +0200920 void __iomem *ioaddr = tp->mmio_addr;
Francois Romieu9ede1092005-07-30 13:14:38 +0200921 int phy_id = tp->mii_if.phy_id;
Francois Romieu890e8d02005-07-30 13:08:43 +0200922 u16 val;
923
Francois Romieu43afb942005-07-30 13:10:21 +0200924 rtnl_lock();
925
Francois Romieuc014f6c2007-02-15 23:37:29 +0100926 if (!netif_running(dev))
927 goto out_unlock;
928
Francois Romieu9ede1092005-07-30 13:14:38 +0200929 val = mdio_read(ioaddr, phy_id, MII_BMCR);
Francois Romieu890e8d02005-07-30 13:08:43 +0200930 if (val & BMCR_RESET) {
931 // FIXME: needlessly high ? -- FR 02/07/2005
932 mod_timer(&tp->timer, jiffies + HZ/10);
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -0800933 goto out_unlock;
934 }
935
936 val = mdio_read_latched(ioaddr, phy_id, MII_BMSR);
937 if (!(val & BMSR_ANEGCOMPLETE) && tp->link_status != LNK_AUTONEG) {
Francois Romieu21461382005-09-03 00:54:25 +0200938 netif_carrier_off(dev);
Joe Perchesad06ab22010-02-17 20:00:17 +0000939 netif_warn(tp, link, dev, "auto-negotiating...\n");
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -0800940 tp->link_status = LNK_AUTONEG;
941 } else if ((val & BMSR_LSTATUS) && tp->link_status != LNK_ON) {
Francois Romieu890e8d02005-07-30 13:08:43 +0200942 /* Rejoice ! */
943 struct {
944 int val;
Francois Romieu6614a6d2005-09-03 00:56:16 +0200945 u32 ctl;
Francois Romieu890e8d02005-07-30 13:08:43 +0200946 const char *msg;
Francois Romieu890e8d02005-07-30 13:08:43 +0200947 } reg31[] = {
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000948 { LPA_1000FULL, 0x07000c00 | 0x00001000,
Francois Romieu6614a6d2005-09-03 00:56:16 +0200949 "1000 Mbps Full Duplex" },
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000950 { LPA_1000HALF, 0x07000c00,
Francois Romieu6614a6d2005-09-03 00:56:16 +0200951 "1000 Mbps Half Duplex" },
952 { LPA_100FULL, 0x04000800 | 0x00001000,
953 "100 Mbps Full Duplex" },
954 { LPA_100HALF, 0x04000800,
955 "100 Mbps Half Duplex" },
956 { LPA_10FULL, 0x04000400 | 0x00001000,
957 "10 Mbps Full Duplex" },
958 { LPA_10HALF, 0x04000400,
959 "10 Mbps Half Duplex" },
960 { 0, 0x04000400, "unknown" }
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000961 }, *p = NULL;
962 u16 adv, autoexp, gigadv, gigrec;
Francois Romieu890e8d02005-07-30 13:08:43 +0200963
Francois Romieu9ede1092005-07-30 13:14:38 +0200964 val = mdio_read(ioaddr, phy_id, 0x1f);
Joe Perchesad06ab22010-02-17 20:00:17 +0000965 netif_info(tp, link, dev, "mii ext = %04x\n", val);
Francois Romieu890e8d02005-07-30 13:08:43 +0200966
Francois Romieu9ede1092005-07-30 13:14:38 +0200967 val = mdio_read(ioaddr, phy_id, MII_LPA);
Francois Romieu8348b4d2005-07-30 13:16:14 +0200968 adv = mdio_read(ioaddr, phy_id, MII_ADVERTISE);
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000969 autoexp = mdio_read(ioaddr, phy_id, MII_EXPANSION);
Joe Perchesad06ab22010-02-17 20:00:17 +0000970 netif_info(tp, link, dev, "mii lpa=%04x adv=%04x exp=%04x\n",
971 val, adv, autoexp);
Francois Romieu8348b4d2005-07-30 13:16:14 +0200972
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000973 if (val & LPA_NPAGE && autoexp & EXPANSION_NWAY) {
974 /* check for gigabit speed */
975 gigadv = mdio_read(ioaddr, phy_id, MII_CTRL1000);
976 gigrec = mdio_read(ioaddr, phy_id, MII_STAT1000);
977 val = (gigadv & (gigrec >> 2));
978 if (val & ADVERTISE_1000FULL)
979 p = reg31;
980 else if (val & ADVERTISE_1000HALF)
981 p = reg31 + 1;
982 }
983 if (!p) {
984 val &= adv;
Francois Romieu890e8d02005-07-30 13:08:43 +0200985
Riccardo Ghetta1feede02009-06-04 09:05:20 +0000986 for (p = reg31; p->val; p++) {
987 if ((val & p->val) == p->val)
988 break;
989 }
Francois Romieu890e8d02005-07-30 13:08:43 +0200990 }
Francois Romieu6614a6d2005-09-03 00:56:16 +0200991
992 p->ctl |= SIS_R32(StationControl) & ~0x0f001c00;
993
Francois Romieuc3d6f1f2005-09-03 00:56:57 +0200994 if ((tp->features & F_HAS_RGMII) &&
995 (tp->features & F_PHY_BCM5461)) {
996 // Set Tx Delay in RGMII mode.
997 mdio_write(ioaddr, phy_id, 0x18, 0xf1c7);
998 udelay(200);
999 mdio_write(ioaddr, phy_id, 0x1c, 0x8c00);
1000 p->ctl |= 0x03000000;
1001 }
1002
Francois Romieu6614a6d2005-09-03 00:56:16 +02001003 SIS_W32(StationControl, p->ctl);
1004
Francois Romieuc3d6f1f2005-09-03 00:56:57 +02001005 if (tp->features & F_HAS_RGMII) {
1006 SIS_W32(RGDelay, 0x0441);
1007 SIS_W32(RGDelay, 0x0440);
1008 }
1009
Riccardo Ghetta08326db2010-02-17 09:28:58 +00001010 tp->negotiated_lpa = p->val;
1011
Joe Perchesad06ab22010-02-17 20:00:17 +00001012 netif_info(tp, link, dev, "link on %s mode\n", p->msg);
Francois Romieu890e8d02005-07-30 13:08:43 +02001013 netif_carrier_on(dev);
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -08001014 tp->link_status = LNK_ON;
1015 } else if (!(val & BMSR_LSTATUS) && tp->link_status != LNK_AUTONEG)
1016 tp->link_status = LNK_OFF;
1017 mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT);
Francois Romieu43afb942005-07-30 13:10:21 +02001018
Francois Romieuc014f6c2007-02-15 23:37:29 +01001019out_unlock:
Francois Romieu43afb942005-07-30 13:10:21 +02001020 rtnl_unlock();
Francois Romieu890e8d02005-07-30 13:08:43 +02001021}
1022
1023static void sis190_phy_timer(unsigned long __opaque)
1024{
1025 struct net_device *dev = (struct net_device *)__opaque;
1026 struct sis190_private *tp = netdev_priv(dev);
1027
1028 if (likely(netif_running(dev)))
1029 schedule_work(&tp->phy_task);
1030}
1031
1032static inline void sis190_delete_timer(struct net_device *dev)
1033{
1034 struct sis190_private *tp = netdev_priv(dev);
1035
1036 del_timer_sync(&tp->timer);
1037}
1038
1039static inline void sis190_request_timer(struct net_device *dev)
1040{
1041 struct sis190_private *tp = netdev_priv(dev);
1042 struct timer_list *timer = &tp->timer;
1043
1044 init_timer(timer);
1045 timer->expires = jiffies + SIS190_PHY_TIMEOUT;
1046 timer->data = (unsigned long)dev;
1047 timer->function = sis190_phy_timer;
1048 add_timer(timer);
1049}
1050
1051static void sis190_set_rxbufsize(struct sis190_private *tp,
1052 struct net_device *dev)
1053{
1054 unsigned int mtu = dev->mtu;
1055
1056 tp->rx_buf_sz = (mtu > RX_BUF_SIZE) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE;
Francois Romieu8b5641d2005-07-30 13:13:03 +02001057 /* RxDesc->size has a licence to kill the lower bits */
1058 if (tp->rx_buf_sz & 0x07) {
1059 tp->rx_buf_sz += 8;
1060 tp->rx_buf_sz &= RX_BUF_MASK;
1061 }
Francois Romieu890e8d02005-07-30 13:08:43 +02001062}
1063
1064static int sis190_open(struct net_device *dev)
1065{
1066 struct sis190_private *tp = netdev_priv(dev);
1067 struct pci_dev *pdev = tp->pci_dev;
1068 int rc = -ENOMEM;
1069
1070 sis190_set_rxbufsize(tp, dev);
1071
1072 /*
1073 * Rx and Tx descriptors need 256 bytes alignment.
1074 * pci_alloc_consistent() guarantees a stronger alignment.
1075 */
1076 tp->TxDescRing = pci_alloc_consistent(pdev, TX_RING_BYTES, &tp->tx_dma);
1077 if (!tp->TxDescRing)
1078 goto out;
1079
1080 tp->RxDescRing = pci_alloc_consistent(pdev, RX_RING_BYTES, &tp->rx_dma);
1081 if (!tp->RxDescRing)
1082 goto err_free_tx_0;
1083
1084 rc = sis190_init_ring(dev);
1085 if (rc < 0)
1086 goto err_free_rx_1;
1087
Francois Romieu890e8d02005-07-30 13:08:43 +02001088 sis190_request_timer(dev);
1089
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001090 rc = request_irq(dev->irq, sis190_interrupt, IRQF_SHARED, dev->name, dev);
Francois Romieu890e8d02005-07-30 13:08:43 +02001091 if (rc < 0)
1092 goto err_release_timer_2;
1093
1094 sis190_hw_start(dev);
1095out:
1096 return rc;
1097
1098err_release_timer_2:
1099 sis190_delete_timer(dev);
1100 sis190_rx_clear(tp);
1101err_free_rx_1:
1102 pci_free_consistent(tp->pci_dev, RX_RING_BYTES, tp->RxDescRing,
1103 tp->rx_dma);
1104err_free_tx_0:
1105 pci_free_consistent(tp->pci_dev, TX_RING_BYTES, tp->TxDescRing,
1106 tp->tx_dma);
1107 goto out;
1108}
1109
1110static void sis190_tx_clear(struct sis190_private *tp)
1111{
1112 unsigned int i;
1113
1114 for (i = 0; i < NUM_TX_DESC; i++) {
1115 struct sk_buff *skb = tp->Tx_skbuff[i];
1116
1117 if (!skb)
1118 continue;
1119
1120 sis190_unmap_tx_skb(tp->pci_dev, skb, tp->TxDescRing + i);
1121 tp->Tx_skbuff[i] = NULL;
1122 dev_kfree_skb(skb);
1123
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001124 tp->dev->stats.tx_dropped++;
Francois Romieu890e8d02005-07-30 13:08:43 +02001125 }
1126 tp->cur_tx = tp->dirty_tx = 0;
1127}
1128
1129static void sis190_down(struct net_device *dev)
1130{
1131 struct sis190_private *tp = netdev_priv(dev);
1132 void __iomem *ioaddr = tp->mmio_addr;
1133 unsigned int poll_locked = 0;
1134
1135 sis190_delete_timer(dev);
1136
1137 netif_stop_queue(dev);
1138
Francois Romieu890e8d02005-07-30 13:08:43 +02001139 do {
1140 spin_lock_irq(&tp->lock);
1141
1142 sis190_asic_down(ioaddr);
1143
1144 spin_unlock_irq(&tp->lock);
1145
1146 synchronize_irq(dev->irq);
1147
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001148 if (!poll_locked)
Francois Romieu890e8d02005-07-30 13:08:43 +02001149 poll_locked++;
Francois Romieu890e8d02005-07-30 13:08:43 +02001150
1151 synchronize_sched();
1152
1153 } while (SIS_R32(IntrMask));
1154
1155 sis190_tx_clear(tp);
1156 sis190_rx_clear(tp);
1157}
1158
1159static int sis190_close(struct net_device *dev)
1160{
1161 struct sis190_private *tp = netdev_priv(dev);
1162 struct pci_dev *pdev = tp->pci_dev;
1163
1164 sis190_down(dev);
1165
1166 free_irq(dev->irq, dev);
1167
Francois Romieu890e8d02005-07-30 13:08:43 +02001168 pci_free_consistent(pdev, TX_RING_BYTES, tp->TxDescRing, tp->tx_dma);
1169 pci_free_consistent(pdev, RX_RING_BYTES, tp->RxDescRing, tp->rx_dma);
1170
1171 tp->TxDescRing = NULL;
1172 tp->RxDescRing = NULL;
1173
1174 return 0;
1175}
1176
Stephen Hemminger613573252009-08-31 19:50:58 +00001177static netdev_tx_t sis190_start_xmit(struct sk_buff *skb,
1178 struct net_device *dev)
Francois Romieu890e8d02005-07-30 13:08:43 +02001179{
1180 struct sis190_private *tp = netdev_priv(dev);
1181 void __iomem *ioaddr = tp->mmio_addr;
1182 u32 len, entry, dirty_tx;
1183 struct TxDesc *desc;
1184 dma_addr_t mapping;
1185
1186 if (unlikely(skb->len < ETH_ZLEN)) {
Herbert Xu5b057c62006-06-23 02:06:41 -07001187 if (skb_padto(skb, ETH_ZLEN)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001188 dev->stats.tx_dropped++;
Francois Romieu890e8d02005-07-30 13:08:43 +02001189 goto out;
1190 }
1191 len = ETH_ZLEN;
1192 } else {
1193 len = skb->len;
1194 }
1195
1196 entry = tp->cur_tx % NUM_TX_DESC;
1197 desc = tp->TxDescRing + entry;
1198
1199 if (unlikely(le32_to_cpu(desc->status) & OWNbit)) {
1200 netif_stop_queue(dev);
Joe Perchesad06ab22010-02-17 20:00:17 +00001201 netif_err(tp, tx_err, dev,
1202 "BUG! Tx Ring full when queue awake!\n");
Francois Romieu890e8d02005-07-30 13:08:43 +02001203 return NETDEV_TX_BUSY;
1204 }
1205
1206 mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE);
kirjanov@gmail.come382c302010-02-24 08:41:18 +00001207 if (pci_dma_mapping_error(tp->pci_dev, mapping)) {
1208 netif_err(tp, tx_err, dev,
1209 "PCI mapping failed, dropping packet");
1210 return NETDEV_TX_BUSY;
1211 }
Francois Romieu890e8d02005-07-30 13:08:43 +02001212
1213 tp->Tx_skbuff[entry] = skb;
1214
1215 desc->PSize = cpu_to_le32(len);
1216 desc->addr = cpu_to_le32(mapping);
1217
1218 desc->size = cpu_to_le32(len);
1219 if (entry == (NUM_TX_DESC - 1))
1220 desc->size |= cpu_to_le32(RingEnd);
1221
1222 wmb();
1223
1224 desc->status = cpu_to_le32(OWNbit | INTbit | DEFbit | CRCbit | PADbit);
Riccardo Ghetta08326db2010-02-17 09:28:58 +00001225 if (tp->negotiated_lpa & (LPA_1000HALF | LPA_100HALF | LPA_10HALF)) {
1226 /* Half Duplex */
1227 desc->status |= cpu_to_le32(COLEN | CRSEN | BKFEN);
1228 if (tp->negotiated_lpa & (LPA_1000HALF | LPA_1000FULL))
1229 desc->status |= cpu_to_le32(EXTEN | BSTEN); /* gigabit HD */
1230 }
Francois Romieu890e8d02005-07-30 13:08:43 +02001231
1232 tp->cur_tx++;
1233
1234 smp_wmb();
1235
1236 SIS_W32(TxControl, 0x1a00 | CmdReset | CmdTxEnb);
1237
Francois Romieu890e8d02005-07-30 13:08:43 +02001238 dirty_tx = tp->dirty_tx;
1239 if ((tp->cur_tx - NUM_TX_DESC) == dirty_tx) {
1240 netif_stop_queue(dev);
1241 smp_rmb();
1242 if (dirty_tx != tp->dirty_tx)
1243 netif_wake_queue(dev);
1244 }
1245out:
1246 return NETDEV_TX_OK;
1247}
1248
Francois Romieufcb98212005-07-30 13:15:22 +02001249static void sis190_free_phy(struct list_head *first_phy)
1250{
1251 struct sis190_phy *cur, *next;
1252
1253 list_for_each_entry_safe(cur, next, first_phy, list) {
1254 kfree(cur);
1255 }
1256}
1257
1258/**
1259 * sis190_default_phy - Select default PHY for sis190 mac.
1260 * @dev: the net device to probe for
1261 *
1262 * Select first detected PHY with link as default.
1263 * If no one is link on, select PHY whose types is HOME as default.
1264 * If HOME doesn't exist, select LAN.
1265 */
1266static u16 sis190_default_phy(struct net_device *dev)
1267{
1268 struct sis190_phy *phy, *phy_home, *phy_default, *phy_lan;
1269 struct sis190_private *tp = netdev_priv(dev);
1270 struct mii_if_info *mii_if = &tp->mii_if;
1271 void __iomem *ioaddr = tp->mmio_addr;
1272 u16 status;
1273
1274 phy_home = phy_default = phy_lan = NULL;
1275
1276 list_for_each_entry(phy, &tp->first_phy, list) {
1277 status = mdio_read_latched(ioaddr, phy->phy_id, MII_BMSR);
1278
1279 // Link ON & Not select default PHY & not ghost PHY.
1280 if ((status & BMSR_LSTATUS) &&
1281 !phy_default &&
1282 (phy->type != UNKNOWN)) {
1283 phy_default = phy;
1284 } else {
1285 status = mdio_read(ioaddr, phy->phy_id, MII_BMCR);
1286 mdio_write(ioaddr, phy->phy_id, MII_BMCR,
1287 status | BMCR_ANENABLE | BMCR_ISOLATE);
1288 if (phy->type == HOME)
1289 phy_home = phy;
1290 else if (phy->type == LAN)
1291 phy_lan = phy;
1292 }
1293 }
1294
1295 if (!phy_default) {
1296 if (phy_home)
1297 phy_default = phy_home;
1298 else if (phy_lan)
1299 phy_default = phy_lan;
1300 else
françois romieuc2f3f3a2009-06-17 11:43:11 +00001301 phy_default = list_first_entry(&tp->first_phy,
Francois Romieufcb98212005-07-30 13:15:22 +02001302 struct sis190_phy, list);
1303 }
1304
1305 if (mii_if->phy_id != phy_default->phy_id) {
1306 mii_if->phy_id = phy_default->phy_id;
Joe Perchesad06ab22010-02-17 20:00:17 +00001307 if (netif_msg_probe(tp))
1308 pr_info("%s: Using transceiver at address %d as default\n",
1309 pci_name(tp->pci_dev), mii_if->phy_id);
Francois Romieufcb98212005-07-30 13:15:22 +02001310 }
1311
1312 status = mdio_read(ioaddr, mii_if->phy_id, MII_BMCR);
1313 status &= (~BMCR_ISOLATE);
1314
1315 mdio_write(ioaddr, mii_if->phy_id, MII_BMCR, status);
1316 status = mdio_read_latched(ioaddr, mii_if->phy_id, MII_BMSR);
1317
1318 return status;
1319}
1320
1321static void sis190_init_phy(struct net_device *dev, struct sis190_private *tp,
1322 struct sis190_phy *phy, unsigned int phy_id,
1323 u16 mii_status)
1324{
1325 void __iomem *ioaddr = tp->mmio_addr;
1326 struct mii_chip_info *p;
1327
1328 INIT_LIST_HEAD(&phy->list);
1329 phy->status = mii_status;
1330 phy->phy_id = phy_id;
1331
1332 phy->id[0] = mdio_read(ioaddr, phy_id, MII_PHYSID1);
1333 phy->id[1] = mdio_read(ioaddr, phy_id, MII_PHYSID2);
1334
1335 for (p = mii_chip_table; p->type; p++) {
1336 if ((p->id[0] == phy->id[0]) &&
1337 (p->id[1] == (phy->id[1] & 0xfff0))) {
1338 break;
1339 }
1340 }
1341
1342 if (p->id[1]) {
1343 phy->type = (p->type == MIX) ?
1344 ((mii_status & (BMSR_100FULL | BMSR_100HALF)) ?
1345 LAN : HOME) : p->type;
Francois Romieu900eb9d2005-09-03 00:55:27 +02001346 tp->features |= p->feature;
Joe Perchesad06ab22010-02-17 20:00:17 +00001347 if (netif_msg_probe(tp))
1348 pr_info("%s: %s transceiver at address %d\n",
1349 pci_name(tp->pci_dev), p->name, phy_id);
Riccardo Ghettac3223d22009-06-04 09:04:55 +00001350 } else {
Francois Romieufcb98212005-07-30 13:15:22 +02001351 phy->type = UNKNOWN;
Joe Perchesad06ab22010-02-17 20:00:17 +00001352 if (netif_msg_probe(tp))
1353 pr_info("%s: unknown PHY 0x%x:0x%x transceiver at address %d\n",
1354 pci_name(tp->pci_dev),
1355 phy->id[0], (phy->id[1] & 0xfff0), phy_id);
Riccardo Ghettac3223d22009-06-04 09:04:55 +00001356 }
Francois Romieufcb98212005-07-30 13:15:22 +02001357}
1358
Francois Romieu900eb9d2005-09-03 00:55:27 +02001359static void sis190_mii_probe_88e1111_fixup(struct sis190_private *tp)
1360{
1361 if (tp->features & F_PHY_88E1111) {
1362 void __iomem *ioaddr = tp->mmio_addr;
1363 int phy_id = tp->mii_if.phy_id;
1364 u16 reg[2][2] = {
1365 { 0x808b, 0x0ce1 },
1366 { 0x808f, 0x0c60 }
1367 }, *p;
1368
1369 p = (tp->features & F_HAS_RGMII) ? reg[0] : reg[1];
1370
1371 mdio_write(ioaddr, phy_id, 0x1b, p[0]);
1372 udelay(200);
1373 mdio_write(ioaddr, phy_id, 0x14, p[1]);
1374 udelay(200);
1375 }
1376}
1377
Francois Romieufcb98212005-07-30 13:15:22 +02001378/**
1379 * sis190_mii_probe - Probe MII PHY for sis190
1380 * @dev: the net device to probe for
1381 *
1382 * Search for total of 32 possible mii phy addresses.
1383 * Identify and set current phy if found one,
1384 * return error if it failed to found.
1385 */
1386static int __devinit sis190_mii_probe(struct net_device *dev)
1387{
1388 struct sis190_private *tp = netdev_priv(dev);
1389 struct mii_if_info *mii_if = &tp->mii_if;
1390 void __iomem *ioaddr = tp->mmio_addr;
1391 int phy_id;
1392 int rc = 0;
1393
1394 INIT_LIST_HEAD(&tp->first_phy);
1395
1396 for (phy_id = 0; phy_id < PHY_MAX_ADDR; phy_id++) {
1397 struct sis190_phy *phy;
1398 u16 status;
1399
1400 status = mdio_read_latched(ioaddr, phy_id, MII_BMSR);
1401
1402 // Try next mii if the current one is not accessible.
1403 if (status == 0xffff || status == 0x0000)
1404 continue;
1405
1406 phy = kmalloc(sizeof(*phy), GFP_KERNEL);
1407 if (!phy) {
1408 sis190_free_phy(&tp->first_phy);
1409 rc = -ENOMEM;
1410 goto out;
1411 }
1412
1413 sis190_init_phy(dev, tp, phy, phy_id, status);
1414
1415 list_add(&tp->first_phy, &phy->list);
1416 }
1417
1418 if (list_empty(&tp->first_phy)) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001419 if (netif_msg_probe(tp))
1420 pr_info("%s: No MII transceivers found!\n",
1421 pci_name(tp->pci_dev));
Francois Romieufcb98212005-07-30 13:15:22 +02001422 rc = -EIO;
1423 goto out;
1424 }
1425
1426 /* Select default PHY for mac */
1427 sis190_default_phy(dev);
1428
Francois Romieu900eb9d2005-09-03 00:55:27 +02001429 sis190_mii_probe_88e1111_fixup(tp);
1430
Francois Romieufcb98212005-07-30 13:15:22 +02001431 mii_if->dev = dev;
1432 mii_if->mdio_read = __mdio_read;
1433 mii_if->mdio_write = __mdio_write;
1434 mii_if->phy_id_mask = PHY_ID_ANY;
1435 mii_if->reg_num_mask = MII_REG_ANY;
1436out:
1437 return rc;
1438}
1439
Adrian Bunkc2b75f02007-12-11 23:23:56 +01001440static void sis190_mii_remove(struct net_device *dev)
Francois Romieufcb98212005-07-30 13:15:22 +02001441{
1442 struct sis190_private *tp = netdev_priv(dev);
1443
1444 sis190_free_phy(&tp->first_phy);
1445}
1446
Francois Romieu890e8d02005-07-30 13:08:43 +02001447static void sis190_release_board(struct pci_dev *pdev)
1448{
1449 struct net_device *dev = pci_get_drvdata(pdev);
1450 struct sis190_private *tp = netdev_priv(dev);
1451
1452 iounmap(tp->mmio_addr);
1453 pci_release_regions(pdev);
1454 pci_disable_device(pdev);
1455 free_netdev(dev);
1456}
1457
1458static struct net_device * __devinit sis190_init_board(struct pci_dev *pdev)
1459{
1460 struct sis190_private *tp;
1461 struct net_device *dev;
1462 void __iomem *ioaddr;
1463 int rc;
1464
1465 dev = alloc_etherdev(sizeof(*tp));
1466 if (!dev) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001467 if (netif_msg_drv(&debug))
1468 pr_err("unable to alloc new ethernet\n");
Francois Romieu890e8d02005-07-30 13:08:43 +02001469 rc = -ENOMEM;
1470 goto err_out_0;
1471 }
1472
Francois Romieu890e8d02005-07-30 13:08:43 +02001473 SET_NETDEV_DEV(dev, &pdev->dev);
1474
1475 tp = netdev_priv(dev);
David Howellsc4028952006-11-22 14:57:56 +00001476 tp->dev = dev;
Francois Romieu890e8d02005-07-30 13:08:43 +02001477 tp->msg_enable = netif_msg_init(debug.msg_enable, SIS190_MSG_DEFAULT);
1478
1479 rc = pci_enable_device(pdev);
1480 if (rc < 0) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001481 if (netif_msg_probe(tp))
1482 pr_err("%s: enable failure\n", pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001483 goto err_free_dev_1;
1484 }
1485
1486 rc = -ENODEV;
1487
1488 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001489 if (netif_msg_probe(tp))
1490 pr_err("%s: region #0 is no MMIO resource\n",
1491 pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001492 goto err_pci_disable_2;
1493 }
1494 if (pci_resource_len(pdev, 0) < SIS190_REGS_SIZE) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001495 if (netif_msg_probe(tp))
1496 pr_err("%s: invalid PCI region size(s)\n",
1497 pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001498 goto err_pci_disable_2;
1499 }
1500
1501 rc = pci_request_regions(pdev, DRV_NAME);
1502 if (rc < 0) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001503 if (netif_msg_probe(tp))
1504 pr_err("%s: could not request regions\n",
1505 pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001506 goto err_pci_disable_2;
1507 }
1508
Yang Hongyang284901a2009-04-06 19:01:15 -07001509 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Francois Romieu890e8d02005-07-30 13:08:43 +02001510 if (rc < 0) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001511 if (netif_msg_probe(tp))
1512 pr_err("%s: DMA configuration failed\n",
1513 pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001514 goto err_free_res_3;
1515 }
1516
1517 pci_set_master(pdev);
1518
1519 ioaddr = ioremap(pci_resource_start(pdev, 0), SIS190_REGS_SIZE);
1520 if (!ioaddr) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001521 if (netif_msg_probe(tp))
1522 pr_err("%s: cannot remap MMIO, aborting\n",
1523 pci_name(pdev));
Francois Romieu890e8d02005-07-30 13:08:43 +02001524 rc = -EIO;
1525 goto err_free_res_3;
1526 }
1527
1528 tp->pci_dev = pdev;
1529 tp->mmio_addr = ioaddr;
Herton Ronaldo Krzesinskib88aafd2010-03-02 03:44:41 -08001530 tp->link_status = LNK_OFF;
Francois Romieu890e8d02005-07-30 13:08:43 +02001531
1532 sis190_irq_mask_and_ack(ioaddr);
1533
1534 sis190_soft_reset(ioaddr);
1535out:
1536 return dev;
1537
1538err_free_res_3:
1539 pci_release_regions(pdev);
1540err_pci_disable_2:
1541 pci_disable_device(pdev);
1542err_free_dev_1:
1543 free_netdev(dev);
1544err_out_0:
1545 dev = ERR_PTR(rc);
1546 goto out;
1547}
1548
1549static void sis190_tx_timeout(struct net_device *dev)
1550{
1551 struct sis190_private *tp = netdev_priv(dev);
1552 void __iomem *ioaddr = tp->mmio_addr;
1553 u8 tmp8;
1554
1555 /* Disable Tx, if not already */
1556 tmp8 = SIS_R8(TxControl);
1557 if (tmp8 & CmdTxEnb)
1558 SIS_W8(TxControl, tmp8 & ~CmdTxEnb);
1559
Joe Perchesad06ab22010-02-17 20:00:17 +00001560 netif_info(tp, tx_err, dev, "Transmit timeout, status %08x %08x\n",
1561 SIS_R32(TxControl), SIS_R32(TxSts));
Francois Romieu188f23b2005-07-30 13:11:43 +02001562
Francois Romieu890e8d02005-07-30 13:08:43 +02001563 /* Disable interrupts by clearing the interrupt mask. */
1564 SIS_W32(IntrMask, 0x0000);
1565
1566 /* Stop a shared interrupt from scavenging while we are. */
1567 spin_lock_irq(&tp->lock);
1568 sis190_tx_clear(tp);
1569 spin_unlock_irq(&tp->lock);
1570
1571 /* ...and finally, reset everything. */
1572 sis190_hw_start(dev);
1573
1574 netif_wake_queue(dev);
1575}
1576
Francois Romieu900eb9d2005-09-03 00:55:27 +02001577static void sis190_set_rgmii(struct sis190_private *tp, u8 reg)
1578{
1579 tp->features |= (reg & 0x80) ? F_HAS_RGMII : 0;
1580}
1581
Francois Romieu830fb7d2005-07-30 13:12:37 +02001582static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1583 struct net_device *dev)
1584{
1585 struct sis190_private *tp = netdev_priv(dev);
1586 void __iomem *ioaddr = tp->mmio_addr;
1587 u16 sig;
1588 int i;
1589
Joe Perchesad06ab22010-02-17 20:00:17 +00001590 if (netif_msg_probe(tp))
1591 pr_info("%s: Read MAC address from EEPROM\n", pci_name(pdev));
Francois Romieu830fb7d2005-07-30 13:12:37 +02001592
1593 /* Check to see if there is a sane EEPROM */
1594 sig = (u16) sis190_read_eeprom(ioaddr, EEPROMSignature);
1595
1596 if ((sig == 0xffff) || (sig == 0x0000)) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001597 if (netif_msg_probe(tp))
1598 pr_info("%s: Error EEPROM read %x\n",
1599 pci_name(pdev), sig);
Francois Romieu830fb7d2005-07-30 13:12:37 +02001600 return -EIO;
1601 }
1602
1603 /* Get MAC address from EEPROM */
1604 for (i = 0; i < MAC_ADDR_LEN / 2; i++) {
Al Viro961994a2007-12-15 01:44:33 +00001605 u16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
Francois Romieu830fb7d2005-07-30 13:12:37 +02001606
Al Viro961994a2007-12-15 01:44:33 +00001607 ((__le16 *)dev->dev_addr)[i] = cpu_to_le16(w);
Francois Romieu830fb7d2005-07-30 13:12:37 +02001608 }
1609
Francois Romieu900eb9d2005-09-03 00:55:27 +02001610 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
1611
Francois Romieu830fb7d2005-07-30 13:12:37 +02001612 return 0;
1613}
1614
1615/**
Francois Romieuebc71642007-12-04 22:58:41 +01001616 * sis190_get_mac_addr_from_apc - Get MAC address for SiS96x model
Francois Romieu830fb7d2005-07-30 13:12:37 +02001617 * @pdev: PCI device
1618 * @dev: network device to get address for
1619 *
Francois Romieuebc71642007-12-04 22:58:41 +01001620 * SiS96x model, use APC CMOS RAM to store MAC address.
Francois Romieu830fb7d2005-07-30 13:12:37 +02001621 * APC CMOS RAM is accessed through ISA bridge.
1622 * MAC address is read into @net_dev->dev_addr.
1623 */
1624static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
1625 struct net_device *dev)
1626{
Francois Romieuebc71642007-12-04 22:58:41 +01001627 static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
Francois Romieu830fb7d2005-07-30 13:12:37 +02001628 struct sis190_private *tp = netdev_priv(dev);
1629 struct pci_dev *isa_bridge;
1630 u8 reg, tmp8;
Francois Romieuebc71642007-12-04 22:58:41 +01001631 unsigned int i;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001632
Joe Perchesad06ab22010-02-17 20:00:17 +00001633 if (netif_msg_probe(tp))
1634 pr_info("%s: Read MAC address from APC\n", pci_name(pdev));
Francois Romieu830fb7d2005-07-30 13:12:37 +02001635
Francois Romieuebc71642007-12-04 22:58:41 +01001636 for (i = 0; i < ARRAY_SIZE(ids); i++) {
1637 isa_bridge = pci_get_device(PCI_VENDOR_ID_SI, ids[i], NULL);
1638 if (isa_bridge)
1639 break;
1640 }
Neil Muller8eb7ad62007-08-01 17:52:04 +02001641
Francois Romieu830fb7d2005-07-30 13:12:37 +02001642 if (!isa_bridge) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001643 if (netif_msg_probe(tp))
1644 pr_info("%s: Can not find ISA bridge\n",
1645 pci_name(pdev));
Francois Romieu830fb7d2005-07-30 13:12:37 +02001646 return -EIO;
1647 }
1648
1649 /* Enable port 78h & 79h to access APC Registers. */
1650 pci_read_config_byte(isa_bridge, 0x48, &tmp8);
1651 reg = (tmp8 & ~0x02);
1652 pci_write_config_byte(isa_bridge, 0x48, reg);
1653 udelay(50);
1654 pci_read_config_byte(isa_bridge, 0x48, &reg);
1655
1656 for (i = 0; i < MAC_ADDR_LEN; i++) {
1657 outb(0x9 + i, 0x78);
1658 dev->dev_addr[i] = inb(0x79);
1659 }
1660
1661 outb(0x12, 0x78);
1662 reg = inb(0x79);
1663
Francois Romieu900eb9d2005-09-03 00:55:27 +02001664 sis190_set_rgmii(tp, reg);
1665
Francois Romieu830fb7d2005-07-30 13:12:37 +02001666 /* Restore the value to ISA Bridge */
1667 pci_write_config_byte(isa_bridge, 0x48, tmp8);
1668 pci_dev_put(isa_bridge);
1669
1670 return 0;
1671}
1672
1673/**
1674 * sis190_init_rxfilter - Initialize the Rx filter
1675 * @dev: network device to initialize
1676 *
1677 * Set receive filter address to our MAC address
1678 * and enable packet filtering.
1679 */
1680static inline void sis190_init_rxfilter(struct net_device *dev)
1681{
1682 struct sis190_private *tp = netdev_priv(dev);
1683 void __iomem *ioaddr = tp->mmio_addr;
1684 u16 ctl;
1685 int i;
1686
1687 ctl = SIS_R16(RxMacControl);
1688 /*
1689 * Disable packet filtering before setting filter.
1690 * Note: SiS's driver writes 32 bits but RxMacControl is 16 bits
1691 * only and followed by RxMacAddr (6 bytes). Strange. -- FR
1692 */
1693 SIS_W16(RxMacControl, ctl & ~0x0f00);
1694
1695 for (i = 0; i < MAC_ADDR_LEN; i++)
1696 SIS_W8(RxMacAddr + i, dev->dev_addr[i]);
1697
1698 SIS_W16(RxMacControl, ctl);
1699 SIS_PCI_COMMIT();
1700}
1701
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04001702static int __devinit sis190_get_mac_addr(struct pci_dev *pdev,
Sergio Luisd785ad72008-02-10 17:56:25 -03001703 struct net_device *dev)
Francois Romieu830fb7d2005-07-30 13:12:37 +02001704{
Francois Romieu563e0ae2008-02-18 21:20:32 +01001705 int rc;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001706
Francois Romieu563e0ae2008-02-18 21:20:32 +01001707 rc = sis190_get_mac_addr_from_eeprom(pdev, dev);
1708 if (rc < 0) {
1709 u8 reg;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001710
Francois Romieu563e0ae2008-02-18 21:20:32 +01001711 pci_read_config_byte(pdev, 0x73, &reg);
1712
1713 if (reg & 0x00000001)
1714 rc = sis190_get_mac_addr_from_apc(pdev, dev);
1715 }
1716 return rc;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001717}
1718
Francois Romieu890e8d02005-07-30 13:08:43 +02001719static void sis190_set_speed_auto(struct net_device *dev)
1720{
1721 struct sis190_private *tp = netdev_priv(dev);
1722 void __iomem *ioaddr = tp->mmio_addr;
Francois Romieu9ede1092005-07-30 13:14:38 +02001723 int phy_id = tp->mii_if.phy_id;
Francois Romieu890e8d02005-07-30 13:08:43 +02001724 int val;
1725
Joe Perchesad06ab22010-02-17 20:00:17 +00001726 netif_info(tp, link, dev, "Enabling Auto-negotiation\n");
Francois Romieu890e8d02005-07-30 13:08:43 +02001727
Francois Romieu9ede1092005-07-30 13:14:38 +02001728 val = mdio_read(ioaddr, phy_id, MII_ADVERTISE);
Francois Romieu890e8d02005-07-30 13:08:43 +02001729
1730 // Enable 10/100 Full/Half Mode, leave MII_ADVERTISE bit4:0
1731 // unchanged.
Francois Romieu9ede1092005-07-30 13:14:38 +02001732 mdio_write(ioaddr, phy_id, MII_ADVERTISE, (val & ADVERTISE_SLCT) |
Francois Romieu890e8d02005-07-30 13:08:43 +02001733 ADVERTISE_100FULL | ADVERTISE_10FULL |
1734 ADVERTISE_100HALF | ADVERTISE_10HALF);
1735
1736 // Enable 1000 Full Mode.
Francois Romieu9ede1092005-07-30 13:14:38 +02001737 mdio_write(ioaddr, phy_id, MII_CTRL1000, ADVERTISE_1000FULL);
Francois Romieu890e8d02005-07-30 13:08:43 +02001738
1739 // Enable auto-negotiation and restart auto-negotiation.
Francois Romieu9ede1092005-07-30 13:14:38 +02001740 mdio_write(ioaddr, phy_id, MII_BMCR,
Francois Romieu890e8d02005-07-30 13:08:43 +02001741 BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET);
1742}
1743
Francois Romieu43afb942005-07-30 13:10:21 +02001744static int sis190_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1745{
1746 struct sis190_private *tp = netdev_priv(dev);
1747
1748 return mii_ethtool_gset(&tp->mii_if, cmd);
1749}
1750
1751static int sis190_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1752{
1753 struct sis190_private *tp = netdev_priv(dev);
1754
1755 return mii_ethtool_sset(&tp->mii_if, cmd);
1756}
1757
Francois Romieu890e8d02005-07-30 13:08:43 +02001758static void sis190_get_drvinfo(struct net_device *dev,
1759 struct ethtool_drvinfo *info)
1760{
1761 struct sis190_private *tp = netdev_priv(dev);
1762
1763 strcpy(info->driver, DRV_NAME);
1764 strcpy(info->version, DRV_VERSION);
1765 strcpy(info->bus_info, pci_name(tp->pci_dev));
1766}
1767
1768static int sis190_get_regs_len(struct net_device *dev)
1769{
1770 return SIS190_REGS_SIZE;
1771}
1772
1773static void sis190_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1774 void *p)
1775{
1776 struct sis190_private *tp = netdev_priv(dev);
1777 unsigned long flags;
1778
1779 if (regs->len > SIS190_REGS_SIZE)
1780 regs->len = SIS190_REGS_SIZE;
1781
1782 spin_lock_irqsave(&tp->lock, flags);
1783 memcpy_fromio(p, tp->mmio_addr, regs->len);
1784 spin_unlock_irqrestore(&tp->lock, flags);
1785}
1786
Francois Romieu43afb942005-07-30 13:10:21 +02001787static int sis190_nway_reset(struct net_device *dev)
1788{
1789 struct sis190_private *tp = netdev_priv(dev);
1790
1791 return mii_nway_restart(&tp->mii_if);
1792}
1793
Francois Romieu890e8d02005-07-30 13:08:43 +02001794static u32 sis190_get_msglevel(struct net_device *dev)
1795{
1796 struct sis190_private *tp = netdev_priv(dev);
1797
1798 return tp->msg_enable;
1799}
1800
1801static void sis190_set_msglevel(struct net_device *dev, u32 value)
1802{
1803 struct sis190_private *tp = netdev_priv(dev);
1804
1805 tp->msg_enable = value;
1806}
1807
Jeff Garzik7282d492006-09-13 14:30:00 -04001808static const struct ethtool_ops sis190_ethtool_ops = {
Francois Romieu43afb942005-07-30 13:10:21 +02001809 .get_settings = sis190_get_settings,
1810 .set_settings = sis190_set_settings,
Francois Romieu890e8d02005-07-30 13:08:43 +02001811 .get_drvinfo = sis190_get_drvinfo,
1812 .get_regs_len = sis190_get_regs_len,
1813 .get_regs = sis190_get_regs,
1814 .get_link = ethtool_op_get_link,
1815 .get_msglevel = sis190_get_msglevel,
1816 .set_msglevel = sis190_set_msglevel,
Francois Romieu43afb942005-07-30 13:10:21 +02001817 .nway_reset = sis190_nway_reset,
Francois Romieu890e8d02005-07-30 13:08:43 +02001818};
1819
Francois Romieu43afb942005-07-30 13:10:21 +02001820static int sis190_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1821{
1822 struct sis190_private *tp = netdev_priv(dev);
1823
1824 return !netif_running(dev) ? -EINVAL :
1825 generic_mii_ioctl(&tp->mii_if, if_mii(ifr), cmd, NULL);
1826}
1827
Stephen Hemminger97488c52009-01-07 17:35:41 -08001828static const struct net_device_ops sis190_netdev_ops = {
1829 .ndo_open = sis190_open,
1830 .ndo_stop = sis190_close,
1831 .ndo_do_ioctl = sis190_ioctl,
1832 .ndo_start_xmit = sis190_start_xmit,
1833 .ndo_tx_timeout = sis190_tx_timeout,
1834 .ndo_set_multicast_list = sis190_set_rx_mode,
1835 .ndo_change_mtu = eth_change_mtu,
1836 .ndo_set_mac_address = eth_mac_addr,
1837 .ndo_validate_addr = eth_validate_addr,
1838#ifdef CONFIG_NET_POLL_CONTROLLER
1839 .ndo_poll_controller = sis190_netpoll,
1840#endif
1841};
1842
Francois Romieu890e8d02005-07-30 13:08:43 +02001843static int __devinit sis190_init_one(struct pci_dev *pdev,
1844 const struct pci_device_id *ent)
1845{
1846 static int printed_version = 0;
1847 struct sis190_private *tp;
1848 struct net_device *dev;
1849 void __iomem *ioaddr;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001850 int rc;
Francois Romieu890e8d02005-07-30 13:08:43 +02001851
1852 if (!printed_version) {
Joe Perchesad06ab22010-02-17 20:00:17 +00001853 if (netif_msg_drv(&debug))
1854 pr_info(SIS190_DRIVER_NAME " loaded\n");
Francois Romieu890e8d02005-07-30 13:08:43 +02001855 printed_version = 1;
1856 }
1857
1858 dev = sis190_init_board(pdev);
1859 if (IS_ERR(dev)) {
1860 rc = PTR_ERR(dev);
1861 goto out;
1862 }
1863
Francois Romieu10487fb2006-02-16 22:17:00 +01001864 pci_set_drvdata(pdev, dev);
1865
Francois Romieu890e8d02005-07-30 13:08:43 +02001866 tp = netdev_priv(dev);
1867 ioaddr = tp->mmio_addr;
1868
Francois Romieu830fb7d2005-07-30 13:12:37 +02001869 rc = sis190_get_mac_addr(pdev, dev);
1870 if (rc < 0)
1871 goto err_release_board;
Francois Romieu890e8d02005-07-30 13:08:43 +02001872
Francois Romieu830fb7d2005-07-30 13:12:37 +02001873 sis190_init_rxfilter(dev);
Francois Romieu890e8d02005-07-30 13:08:43 +02001874
David Howellsc4028952006-11-22 14:57:56 +00001875 INIT_WORK(&tp->phy_task, sis190_phy_task);
Francois Romieu890e8d02005-07-30 13:08:43 +02001876
Stephen Hemminger97488c52009-01-07 17:35:41 -08001877 dev->netdev_ops = &sis190_netdev_ops;
1878
Francois Romieu890e8d02005-07-30 13:08:43 +02001879 SET_ETHTOOL_OPS(dev, &sis190_ethtool_ops);
1880 dev->irq = pdev->irq;
1881 dev->base_addr = (unsigned long) 0xdead;
Stephen Hemminger97488c52009-01-07 17:35:41 -08001882 dev->watchdog_timeo = SIS190_TX_TIMEOUT;
Francois Romieu890e8d02005-07-30 13:08:43 +02001883
1884 spin_lock_init(&tp->lock);
Francois Romieu890e8d02005-07-30 13:08:43 +02001885
Francois Romieufcb98212005-07-30 13:15:22 +02001886 rc = sis190_mii_probe(dev);
1887 if (rc < 0)
Francois Romieu3690b6c2005-08-26 00:30:37 +02001888 goto err_release_board;
1889
1890 rc = register_netdev(dev);
1891 if (rc < 0)
1892 goto err_remove_mii;
1893
Joe Perchesad06ab22010-02-17 20:00:17 +00001894 if (netif_msg_probe(tp)) {
1895 netdev_info(dev, "%s: %s at %p (IRQ: %d), %pM\n",
1896 pci_name(pdev),
1897 sis_chip_info[ent->driver_data].name,
1898 ioaddr, dev->irq, dev->dev_addr);
1899 netdev_info(dev, "%s mode.\n",
1900 (tp->features & F_HAS_RGMII) ? "RGMII" : "GMII");
1901 }
Francois Romieu900eb9d2005-09-03 00:55:27 +02001902
Francois Romieu890e8d02005-07-30 13:08:43 +02001903 netif_carrier_off(dev);
1904
1905 sis190_set_speed_auto(dev);
1906out:
1907 return rc;
Francois Romieu830fb7d2005-07-30 13:12:37 +02001908
Francois Romieu3690b6c2005-08-26 00:30:37 +02001909err_remove_mii:
1910 sis190_mii_remove(dev);
Francois Romieu830fb7d2005-07-30 13:12:37 +02001911err_release_board:
1912 sis190_release_board(pdev);
1913 goto out;
Francois Romieu890e8d02005-07-30 13:08:43 +02001914}
1915
1916static void __devexit sis190_remove_one(struct pci_dev *pdev)
1917{
1918 struct net_device *dev = pci_get_drvdata(pdev);
Tejun Heo23f333a2010-12-12 16:45:14 +01001919 struct sis190_private *tp = netdev_priv(dev);
Francois Romieu890e8d02005-07-30 13:08:43 +02001920
Francois Romieufcb98212005-07-30 13:15:22 +02001921 sis190_mii_remove(dev);
Tejun Heo23f333a2010-12-12 16:45:14 +01001922 cancel_work_sync(&tp->phy_task);
Francois Romieu890e8d02005-07-30 13:08:43 +02001923 unregister_netdev(dev);
1924 sis190_release_board(pdev);
1925 pci_set_drvdata(pdev, NULL);
1926}
1927
1928static struct pci_driver sis190_pci_driver = {
1929 .name = DRV_NAME,
1930 .id_table = sis190_pci_tbl,
1931 .probe = sis190_init_one,
1932 .remove = __devexit_p(sis190_remove_one),
1933};
1934
1935static int __init sis190_init_module(void)
1936{
Jeff Garzik29917622006-08-19 17:48:59 -04001937 return pci_register_driver(&sis190_pci_driver);
Francois Romieu890e8d02005-07-30 13:08:43 +02001938}
1939
1940static void __exit sis190_cleanup_module(void)
1941{
1942 pci_unregister_driver(&sis190_pci_driver);
1943}
1944
1945module_init(sis190_init_module);
1946module_exit(sis190_cleanup_module);