1 |
1275 |
phoenix |
/* sis900.c: A SiS 900/7016 PCI Fast Ethernet driver for Linux.
|
2 |
|
|
Copyright 1999 Silicon Integrated System Corporation
|
3 |
|
|
Revision: 1.08.06 Sep. 24 2002
|
4 |
|
|
|
5 |
|
|
Modified from the driver which is originally written by Donald Becker.
|
6 |
|
|
|
7 |
|
|
This software may be used and distributed according to the terms
|
8 |
|
|
of the GNU General Public License (GPL), incorporated herein by reference.
|
9 |
|
|
Drivers based on this skeleton fall under the GPL and must retain
|
10 |
|
|
the authorship (implicit copyright) notice.
|
11 |
|
|
|
12 |
|
|
References:
|
13 |
|
|
SiS 7016 Fast Ethernet PCI Bus 10/100 Mbps LAN Controller with OnNow Support,
|
14 |
|
|
preliminary Rev. 1.0 Jan. 14, 1998
|
15 |
|
|
SiS 900 Fast Ethernet PCI Bus 10/100 Mbps LAN Single Chip with OnNow Support,
|
16 |
|
|
preliminary Rev. 1.0 Nov. 10, 1998
|
17 |
|
|
SiS 7014 Single Chip 100BASE-TX/10BASE-T Physical Layer Solution,
|
18 |
|
|
preliminary Rev. 1.0 Jan. 18, 1998
|
19 |
|
|
http://www.sis.com.tw/support/databook.htm
|
20 |
|
|
|
21 |
|
|
Rev 1.08.06 Sep. 24 2002 Mufasa Yang bug fix for Tx timeout & add SiS963 support
|
22 |
|
|
Rev 1.08.05 Jun. 6 2002 Mufasa Yang bug fix for read_eeprom & Tx descriptor over-boundary
|
23 |
|
|
Rev 1.08.04 Apr. 25 2002 Mufasa Yang <mufasa@sis.com.tw> added SiS962 support
|
24 |
|
|
Rev 1.08.03 Feb. 1 2002 Matt Domsch <Matt_Domsch@dell.com> update to use library crc32 function
|
25 |
|
|
Rev 1.08.02 Nov. 30 2001 Hui-Fen Hsu workaround for EDB & bug fix for dhcp problem
|
26 |
|
|
Rev 1.08.01 Aug. 25 2001 Hui-Fen Hsu update for 630ET & workaround for ICS1893 PHY
|
27 |
|
|
Rev 1.08.00 Jun. 11 2001 Hui-Fen Hsu workaround for RTL8201 PHY and some bug fix
|
28 |
|
|
Rev 1.07.11 Apr. 2 2001 Hui-Fen Hsu updates PCI drivers to use the new pci_set_dma_mask for kernel 2.4.3
|
29 |
|
|
Rev 1.07.10 Mar. 1 2001 Hui-Fen Hsu <hfhsu@sis.com.tw> some bug fix & 635M/B support
|
30 |
|
|
Rev 1.07.09 Feb. 9 2001 Dave Jones <davej@suse.de> PCI enable cleanup
|
31 |
|
|
Rev 1.07.08 Jan. 8 2001 Lei-Chun Chang added RTL8201 PHY support
|
32 |
|
|
Rev 1.07.07 Nov. 29 2000 Lei-Chun Chang added kernel-doc extractable documentation and 630 workaround fix
|
33 |
|
|
Rev 1.07.06 Nov. 7 2000 Jeff Garzik <jgarzik@pobox.com> some bug fix and cleaning
|
34 |
|
|
Rev 1.07.05 Nov. 6 2000 metapirat<metapirat@gmx.de> contribute media type select by ifconfig
|
35 |
|
|
Rev 1.07.04 Sep. 6 2000 Lei-Chun Chang added ICS1893 PHY support
|
36 |
|
|
Rev 1.07.03 Aug. 24 2000 Lei-Chun Chang (lcchang@sis.com.tw) modified 630E eqaulizer workaround rule
|
37 |
|
|
Rev 1.07.01 Aug. 08 2000 Ollie Lho minor update for SiS 630E and SiS 630E A1
|
38 |
|
|
Rev 1.07 Mar. 07 2000 Ollie Lho bug fix in Rx buffer ring
|
39 |
|
|
Rev 1.06.04 Feb. 11 2000 Jeff Garzik <jgarzik@pobox.com> softnet and init for kernel 2.4
|
40 |
|
|
Rev 1.06.03 Dec. 23 1999 Ollie Lho Third release
|
41 |
|
|
Rev 1.06.02 Nov. 23 1999 Ollie Lho bug in mac probing fixed
|
42 |
|
|
Rev 1.06.01 Nov. 16 1999 Ollie Lho CRC calculation provide by Joseph Zbiciak (im14u2c@primenet.com)
|
43 |
|
|
Rev 1.06 Nov. 4 1999 Ollie Lho (ollie@sis.com.tw) Second release
|
44 |
|
|
Rev 1.05.05 Oct. 29 1999 Ollie Lho (ollie@sis.com.tw) Single buffer Tx/Rx
|
45 |
|
|
Chin-Shan Li (lcs@sis.com.tw) Added AMD Am79c901 HomePNA PHY support
|
46 |
|
|
Rev 1.05 Aug. 7 1999 Jim Huang (cmhuang@sis.com.tw) Initial release
|
47 |
|
|
*/
|
48 |
|
|
|
49 |
|
|
#include <linux/module.h>
|
50 |
|
|
#include <linux/version.h>
|
51 |
|
|
#include <linux/kernel.h>
|
52 |
|
|
#include <linux/sched.h>
|
53 |
|
|
#include <linux/string.h>
|
54 |
|
|
#include <linux/timer.h>
|
55 |
|
|
#include <linux/errno.h>
|
56 |
|
|
#include <linux/ioport.h>
|
57 |
|
|
#include <linux/slab.h>
|
58 |
|
|
#include <linux/interrupt.h>
|
59 |
|
|
#include <linux/pci.h>
|
60 |
|
|
#include <linux/netdevice.h>
|
61 |
|
|
#include <linux/init.h>
|
62 |
|
|
#include <linux/mii.h>
|
63 |
|
|
#include <linux/etherdevice.h>
|
64 |
|
|
#include <linux/skbuff.h>
|
65 |
|
|
#include <linux/delay.h>
|
66 |
|
|
#include <linux/ethtool.h>
|
67 |
|
|
#include <linux/crc32.h>
|
68 |
|
|
|
69 |
|
|
#include <asm/processor.h> /* Processor type for cache alignment. */
|
70 |
|
|
#include <asm/bitops.h>
|
71 |
|
|
#include <asm/io.h>
|
72 |
|
|
#include <asm/uaccess.h> /* User space memory access functions */
|
73 |
|
|
|
74 |
|
|
#include "sis900.h"
|
75 |
|
|
|
76 |
|
|
#define SIS900_MODULE_NAME "sis900"
|
77 |
|
|
#define SIS900_DRV_VERSION "v1.08.06 9/24/2002"
|
78 |
|
|
|
79 |
|
|
static char version[] __devinitdata =
|
80 |
|
|
KERN_INFO "sis900.c: " SIS900_DRV_VERSION "\n";
|
81 |
|
|
|
82 |
|
|
static int max_interrupt_work = 40;
|
83 |
|
|
static int multicast_filter_limit = 128;
|
84 |
|
|
|
85 |
|
|
#define sis900_debug debug
|
86 |
|
|
static int sis900_debug;
|
87 |
|
|
|
88 |
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
89 |
|
|
#define TX_TIMEOUT (4*HZ)
|
90 |
|
|
/* SiS 900 is capable of 32 bits BM DMA */
|
91 |
|
|
#define SIS900_DMA_MASK 0xffffffff
|
92 |
|
|
|
93 |
|
|
enum {
|
94 |
|
|
SIS_900 = 0,
|
95 |
|
|
SIS_7016
|
96 |
|
|
};
|
97 |
|
|
static char * card_names[] = {
|
98 |
|
|
"SiS 900 PCI Fast Ethernet",
|
99 |
|
|
"SiS 7016 PCI Fast Ethernet"
|
100 |
|
|
};
|
101 |
|
|
static struct pci_device_id sis900_pci_tbl [] = {
|
102 |
|
|
{PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_900,
|
103 |
|
|
PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_900},
|
104 |
|
|
{PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7016,
|
105 |
|
|
PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_7016},
|
106 |
|
|
{0,}
|
107 |
|
|
};
|
108 |
|
|
MODULE_DEVICE_TABLE (pci, sis900_pci_tbl);
|
109 |
|
|
|
110 |
|
|
static void sis900_read_mode(struct net_device *net_dev, int *speed, int *duplex);
|
111 |
|
|
|
112 |
|
|
static struct mii_chip_info {
|
113 |
|
|
const char * name;
|
114 |
|
|
u16 phy_id0;
|
115 |
|
|
u16 phy_id1;
|
116 |
|
|
u8 phy_types;
|
117 |
|
|
#define HOME 0x0001
|
118 |
|
|
#define LAN 0x0002
|
119 |
|
|
#define MIX 0x0003
|
120 |
|
|
} mii_chip_table[] = {
|
121 |
|
|
{ "SiS 900 Internal MII PHY", 0x001d, 0x8000, LAN },
|
122 |
|
|
{ "SiS 7014 Physical Layer Solution", 0x0016, 0xf830, LAN },
|
123 |
|
|
{ "AMD 79C901 10BASE-T PHY", 0x0000, 0x6B70, LAN },
|
124 |
|
|
{ "AMD 79C901 HomePNA PHY", 0x0000, 0x6B90, HOME},
|
125 |
|
|
{ "ICS LAN PHY", 0x0015, 0xF440, LAN },
|
126 |
|
|
{ "NS 83851 PHY", 0x2000, 0x5C20, MIX },
|
127 |
|
|
{ "Realtek RTL8201 PHY", 0x0000, 0x8200, LAN },
|
128 |
|
|
{ "VIA 6103 PHY", 0x0101, 0x8f20, LAN },
|
129 |
|
|
{0,},
|
130 |
|
|
};
|
131 |
|
|
|
132 |
|
|
struct mii_phy {
|
133 |
|
|
struct mii_phy * next;
|
134 |
|
|
int phy_addr;
|
135 |
|
|
u16 phy_id0;
|
136 |
|
|
u16 phy_id1;
|
137 |
|
|
u16 status;
|
138 |
|
|
u8 phy_types;
|
139 |
|
|
};
|
140 |
|
|
|
141 |
|
|
typedef struct _BufferDesc {
|
142 |
|
|
u32 link;
|
143 |
|
|
u32 cmdsts;
|
144 |
|
|
u32 bufptr;
|
145 |
|
|
} BufferDesc;
|
146 |
|
|
|
147 |
|
|
struct sis900_private {
|
148 |
|
|
struct net_device_stats stats;
|
149 |
|
|
struct pci_dev * pci_dev;
|
150 |
|
|
|
151 |
|
|
spinlock_t lock;
|
152 |
|
|
|
153 |
|
|
struct mii_phy * mii;
|
154 |
|
|
struct mii_phy * first_mii; /* record the first mii structure */
|
155 |
|
|
unsigned int cur_phy;
|
156 |
|
|
|
157 |
|
|
struct timer_list timer; /* Link status detection timer. */
|
158 |
|
|
u8 autong_complete; /* 1: auto-negotiate complete */
|
159 |
|
|
|
160 |
|
|
unsigned int cur_rx, dirty_rx; /* producer/comsumer pointers for Tx/Rx ring */
|
161 |
|
|
unsigned int cur_tx, dirty_tx;
|
162 |
|
|
|
163 |
|
|
/* The saved address of a sent/receive-in-place packet buffer */
|
164 |
|
|
struct sk_buff *tx_skbuff[NUM_TX_DESC];
|
165 |
|
|
struct sk_buff *rx_skbuff[NUM_RX_DESC];
|
166 |
|
|
BufferDesc *tx_ring;
|
167 |
|
|
BufferDesc *rx_ring;
|
168 |
|
|
|
169 |
|
|
dma_addr_t tx_ring_dma;
|
170 |
|
|
dma_addr_t rx_ring_dma;
|
171 |
|
|
|
172 |
|
|
unsigned int tx_full; /* The Tx queue is full. */
|
173 |
|
|
u8 host_bridge_rev;
|
174 |
|
|
};
|
175 |
|
|
|
176 |
|
|
MODULE_AUTHOR("Jim Huang <cmhuang@sis.com.tw>, Ollie Lho <ollie@sis.com.tw>");
|
177 |
|
|
MODULE_DESCRIPTION("SiS 900 PCI Fast Ethernet driver");
|
178 |
|
|
MODULE_LICENSE("GPL");
|
179 |
|
|
|
180 |
|
|
MODULE_PARM(multicast_filter_limit, "i");
|
181 |
|
|
MODULE_PARM(max_interrupt_work, "i");
|
182 |
|
|
MODULE_PARM(debug, "i");
|
183 |
|
|
MODULE_PARM_DESC(multicast_filter_limit, "SiS 900/7016 maximum number of filtered multicast addresses");
|
184 |
|
|
MODULE_PARM_DESC(max_interrupt_work, "SiS 900/7016 maximum events handled per interrupt");
|
185 |
|
|
MODULE_PARM_DESC(debug, "SiS 900/7016 debug level (2-4)");
|
186 |
|
|
|
187 |
|
|
static int sis900_open(struct net_device *net_dev);
|
188 |
|
|
static int sis900_mii_probe (struct net_device * net_dev);
|
189 |
|
|
static void sis900_init_rxfilter (struct net_device * net_dev);
|
190 |
|
|
static u16 read_eeprom(long ioaddr, int location);
|
191 |
|
|
static u16 mdio_read(struct net_device *net_dev, int phy_id, int location);
|
192 |
|
|
static void mdio_write(struct net_device *net_dev, int phy_id, int location, int val);
|
193 |
|
|
static void sis900_timer(unsigned long data);
|
194 |
|
|
static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy);
|
195 |
|
|
static void sis900_tx_timeout(struct net_device *net_dev);
|
196 |
|
|
static void sis900_init_tx_ring(struct net_device *net_dev);
|
197 |
|
|
static void sis900_init_rx_ring(struct net_device *net_dev);
|
198 |
|
|
static int sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev);
|
199 |
|
|
static int sis900_rx(struct net_device *net_dev);
|
200 |
|
|
static void sis900_finish_xmit (struct net_device *net_dev);
|
201 |
|
|
static irqreturn_t sis900_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
|
202 |
|
|
static int sis900_close(struct net_device *net_dev);
|
203 |
|
|
static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd);
|
204 |
|
|
static struct net_device_stats *sis900_get_stats(struct net_device *net_dev);
|
205 |
|
|
static u16 sis900_mcast_bitnr(u8 *addr, u8 revision);
|
206 |
|
|
static void set_rx_mode(struct net_device *net_dev);
|
207 |
|
|
static void sis900_reset(struct net_device *net_dev);
|
208 |
|
|
static void sis630_set_eq(struct net_device *net_dev, u8 revision);
|
209 |
|
|
static int sis900_set_config(struct net_device *dev, struct ifmap *map);
|
210 |
|
|
static u16 sis900_default_phy(struct net_device * net_dev);
|
211 |
|
|
static void sis900_set_capability( struct net_device *net_dev ,struct mii_phy *phy);
|
212 |
|
|
static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr);
|
213 |
|
|
static void sis900_auto_negotiate(struct net_device *net_dev, int phy_addr);
|
214 |
|
|
static void sis900_set_mode (long ioaddr, int speed, int duplex);
|
215 |
|
|
static struct ethtool_ops sis900_ethtool_ops;
|
216 |
|
|
|
217 |
|
|
/**
|
218 |
|
|
* sis900_get_mac_addr - Get MAC address for stand alone SiS900 model
|
219 |
|
|
* @pci_dev: the sis900 pci device
|
220 |
|
|
* @net_dev: the net device to get address for
|
221 |
|
|
*
|
222 |
|
|
* Older SiS900 and friends, use EEPROM to store MAC address.
|
223 |
|
|
* MAC address is read from read_eeprom() into @net_dev->dev_addr.
|
224 |
|
|
*/
|
225 |
|
|
|
226 |
|
|
static int __devinit sis900_get_mac_addr(struct pci_dev * pci_dev, struct net_device *net_dev)
|
227 |
|
|
{
|
228 |
|
|
long ioaddr = pci_resource_start(pci_dev, 0);
|
229 |
|
|
u16 signature;
|
230 |
|
|
int i;
|
231 |
|
|
|
232 |
|
|
/* check to see if we have sane EEPROM */
|
233 |
|
|
signature = (u16) read_eeprom(ioaddr, EEPROMSignature);
|
234 |
|
|
if (signature == 0xffff || signature == 0x0000) {
|
235 |
|
|
printk (KERN_INFO "%s: Error EERPOM read %x\n",
|
236 |
|
|
net_dev->name, signature);
|
237 |
|
|
return 0;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
/* get MAC address from EEPROM */
|
241 |
|
|
for (i = 0; i < 3; i++)
|
242 |
|
|
((u16 *)(net_dev->dev_addr))[i] = read_eeprom(ioaddr, i+EEPROMMACAddr);
|
243 |
|
|
|
244 |
|
|
return 1;
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
/**
|
248 |
|
|
* sis630e_get_mac_addr - Get MAC address for SiS630E model
|
249 |
|
|
* @pci_dev: the sis900 pci device
|
250 |
|
|
* @net_dev: the net device to get address for
|
251 |
|
|
*
|
252 |
|
|
* SiS630E model, use APC CMOS RAM to store MAC address.
|
253 |
|
|
* APC CMOS RAM is accessed through ISA bridge.
|
254 |
|
|
* MAC address is read into @net_dev->dev_addr.
|
255 |
|
|
*/
|
256 |
|
|
|
257 |
|
|
static int __devinit sis630e_get_mac_addr(struct pci_dev * pci_dev, struct net_device *net_dev)
|
258 |
|
|
{
|
259 |
|
|
struct pci_dev *isa_bridge = NULL;
|
260 |
|
|
u8 reg;
|
261 |
|
|
int i;
|
262 |
|
|
|
263 |
|
|
if ((isa_bridge = pci_find_device(0x1039, 0x0008, isa_bridge)) == NULL) {
|
264 |
|
|
printk("%s: Can not find ISA bridge\n", net_dev->name);
|
265 |
|
|
return 0;
|
266 |
|
|
}
|
267 |
|
|
pci_read_config_byte(isa_bridge, 0x48, ®);
|
268 |
|
|
pci_write_config_byte(isa_bridge, 0x48, reg | 0x40);
|
269 |
|
|
|
270 |
|
|
for (i = 0; i < 6; i++) {
|
271 |
|
|
outb(0x09 + i, 0x70);
|
272 |
|
|
((u8 *)(net_dev->dev_addr))[i] = inb(0x71);
|
273 |
|
|
}
|
274 |
|
|
pci_write_config_byte(isa_bridge, 0x48, reg & ~0x40);
|
275 |
|
|
|
276 |
|
|
return 1;
|
277 |
|
|
}
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
/**
|
281 |
|
|
* sis635_get_mac_addr - Get MAC address for SIS635 model
|
282 |
|
|
* @pci_dev: the sis900 pci device
|
283 |
|
|
* @net_dev: the net device to get address for
|
284 |
|
|
*
|
285 |
|
|
* SiS635 model, set MAC Reload Bit to load Mac address from APC
|
286 |
|
|
* to rfdr. rfdr is accessed through rfcr. MAC address is read into
|
287 |
|
|
* @net_dev->dev_addr.
|
288 |
|
|
*/
|
289 |
|
|
|
290 |
|
|
static int __devinit sis635_get_mac_addr(struct pci_dev * pci_dev, struct net_device *net_dev)
|
291 |
|
|
{
|
292 |
|
|
long ioaddr = net_dev->base_addr;
|
293 |
|
|
u32 rfcrSave;
|
294 |
|
|
u32 i;
|
295 |
|
|
|
296 |
|
|
rfcrSave = inl(rfcr + ioaddr);
|
297 |
|
|
|
298 |
|
|
outl(rfcrSave | RELOAD, ioaddr + cr);
|
299 |
|
|
outl(0, ioaddr + cr);
|
300 |
|
|
|
301 |
|
|
/* disable packet filtering before setting filter */
|
302 |
|
|
outl(rfcrSave & ~RFEN, rfcr + ioaddr);
|
303 |
|
|
|
304 |
|
|
/* load MAC addr to filter data register */
|
305 |
|
|
for (i = 0 ; i < 3 ; i++) {
|
306 |
|
|
outl((i << RFADDR_shift), ioaddr + rfcr);
|
307 |
|
|
*( ((u16 *)net_dev->dev_addr) + i) = inw(ioaddr + rfdr);
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
/* enable packet filitering */
|
311 |
|
|
outl(rfcrSave | RFEN, rfcr + ioaddr);
|
312 |
|
|
|
313 |
|
|
return 1;
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
/**
|
317 |
|
|
* sis96x_get_mac_addr - Get MAC address for SiS962 or SiS963 model
|
318 |
|
|
* @pci_dev: the sis900 pci device
|
319 |
|
|
* @net_dev: the net device to get address for
|
320 |
|
|
*
|
321 |
|
|
* SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
|
322 |
|
|
* is shared by
|
323 |
|
|
* LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
|
324 |
|
|
* and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
|
325 |
|
|
* by LAN, otherwise is not. After MAC address is read from EEPROM, send
|
326 |
|
|
* EEDONE signal to refuse EEPROM access by LAN.
|
327 |
|
|
* The EEPROM map of SiS962 or SiS963 is different to SiS900.
|
328 |
|
|
* The signature field in SiS962 or SiS963 spec is meaningless.
|
329 |
|
|
* MAC address is read into @net_dev->dev_addr.
|
330 |
|
|
*/
|
331 |
|
|
|
332 |
|
|
static int __devinit sis96x_get_mac_addr(struct pci_dev * pci_dev, struct net_device *net_dev)
|
333 |
|
|
{
|
334 |
|
|
long ioaddr = net_dev->base_addr;
|
335 |
|
|
long ee_addr = ioaddr + mear;
|
336 |
|
|
u32 waittime = 0;
|
337 |
|
|
int i;
|
338 |
|
|
|
339 |
|
|
outl(EEREQ, ee_addr);
|
340 |
|
|
while(waittime < 2000) {
|
341 |
|
|
if(inl(ee_addr) & EEGNT) {
|
342 |
|
|
|
343 |
|
|
/* get MAC address from EEPROM */
|
344 |
|
|
for (i = 0; i < 3; i++)
|
345 |
|
|
((u16 *)(net_dev->dev_addr))[i] = read_eeprom(ioaddr, i+EEPROMMACAddr);
|
346 |
|
|
|
347 |
|
|
outl(EEDONE, ee_addr);
|
348 |
|
|
return 1;
|
349 |
|
|
} else {
|
350 |
|
|
udelay(1);
|
351 |
|
|
waittime ++;
|
352 |
|
|
}
|
353 |
|
|
}
|
354 |
|
|
outl(EEDONE, ee_addr);
|
355 |
|
|
return 0;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
/**
|
359 |
|
|
* sis900_probe - Probe for sis900 device
|
360 |
|
|
* @pci_dev: the sis900 pci device
|
361 |
|
|
* @pci_id: the pci device ID
|
362 |
|
|
*
|
363 |
|
|
* Check and probe sis900 net device for @pci_dev.
|
364 |
|
|
* Get mac address according to the chip revision,
|
365 |
|
|
* and assign SiS900-specific entries in the device structure.
|
366 |
|
|
* ie: sis900_open(), sis900_start_xmit(), sis900_close(), etc.
|
367 |
|
|
*/
|
368 |
|
|
|
369 |
|
|
static int __devinit sis900_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
|
370 |
|
|
{
|
371 |
|
|
struct sis900_private *sis_priv;
|
372 |
|
|
struct net_device *net_dev;
|
373 |
|
|
struct pci_dev *dev;
|
374 |
|
|
dma_addr_t ring_dma;
|
375 |
|
|
void *ring_space;
|
376 |
|
|
long ioaddr;
|
377 |
|
|
int i, ret;
|
378 |
|
|
u8 revision;
|
379 |
|
|
char *card_name = card_names[pci_id->driver_data];
|
380 |
|
|
|
381 |
|
|
/* when built into the kernel, we only print version if device is found */
|
382 |
|
|
#ifndef MODULE
|
383 |
|
|
static int printed_version;
|
384 |
|
|
if (!printed_version++)
|
385 |
|
|
printk(version);
|
386 |
|
|
#endif
|
387 |
|
|
|
388 |
|
|
/* setup various bits in PCI command register */
|
389 |
|
|
ret = pci_enable_device(pci_dev);
|
390 |
|
|
if(ret) return ret;
|
391 |
|
|
|
392 |
|
|
i = pci_set_dma_mask(pci_dev, SIS900_DMA_MASK);
|
393 |
|
|
if(i){
|
394 |
|
|
printk(KERN_ERR "sis900.c: architecture does not support"
|
395 |
|
|
"32bit PCI busmaster DMA\n");
|
396 |
|
|
return i;
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
pci_set_master(pci_dev);
|
400 |
|
|
|
401 |
|
|
net_dev = alloc_etherdev(sizeof(struct sis900_private));
|
402 |
|
|
if (!net_dev)
|
403 |
|
|
return -ENOMEM;
|
404 |
|
|
SET_MODULE_OWNER(net_dev);
|
405 |
|
|
|
406 |
|
|
/* We do a request_region() to register /proc/ioports info. */
|
407 |
|
|
ioaddr = pci_resource_start(pci_dev, 0);
|
408 |
|
|
ret = pci_request_regions(pci_dev, "sis900");
|
409 |
|
|
if (ret)
|
410 |
|
|
goto err_out;
|
411 |
|
|
|
412 |
|
|
sis_priv = net_dev->priv;
|
413 |
|
|
net_dev->base_addr = ioaddr;
|
414 |
|
|
net_dev->irq = pci_dev->irq;
|
415 |
|
|
sis_priv->pci_dev = pci_dev;
|
416 |
|
|
spin_lock_init(&sis_priv->lock);
|
417 |
|
|
|
418 |
|
|
pci_set_drvdata(pci_dev, net_dev);
|
419 |
|
|
|
420 |
|
|
ring_space = pci_alloc_consistent(pci_dev, TX_TOTAL_SIZE, &ring_dma);
|
421 |
|
|
if (!ring_space) {
|
422 |
|
|
ret = -ENOMEM;
|
423 |
|
|
goto err_out_cleardev;
|
424 |
|
|
}
|
425 |
|
|
sis_priv->tx_ring = (BufferDesc *)ring_space;
|
426 |
|
|
sis_priv->tx_ring_dma = ring_dma;
|
427 |
|
|
|
428 |
|
|
ring_space = pci_alloc_consistent(pci_dev, RX_TOTAL_SIZE, &ring_dma);
|
429 |
|
|
if (!ring_space) {
|
430 |
|
|
ret = -ENOMEM;
|
431 |
|
|
goto err_unmap_tx;
|
432 |
|
|
}
|
433 |
|
|
sis_priv->rx_ring = (BufferDesc *)ring_space;
|
434 |
|
|
sis_priv->rx_ring_dma = ring_dma;
|
435 |
|
|
|
436 |
|
|
/* The SiS900-specific entries in the device structure. */
|
437 |
|
|
net_dev->open = &sis900_open;
|
438 |
|
|
net_dev->hard_start_xmit = &sis900_start_xmit;
|
439 |
|
|
net_dev->stop = &sis900_close;
|
440 |
|
|
net_dev->get_stats = &sis900_get_stats;
|
441 |
|
|
net_dev->set_config = &sis900_set_config;
|
442 |
|
|
net_dev->set_multicast_list = &set_rx_mode;
|
443 |
|
|
net_dev->do_ioctl = &mii_ioctl;
|
444 |
|
|
net_dev->tx_timeout = sis900_tx_timeout;
|
445 |
|
|
net_dev->watchdog_timeo = TX_TIMEOUT;
|
446 |
|
|
net_dev->ethtool_ops = &sis900_ethtool_ops;
|
447 |
|
|
|
448 |
|
|
ret = register_netdev(net_dev);
|
449 |
|
|
if (ret)
|
450 |
|
|
goto err_unmap_rx;
|
451 |
|
|
|
452 |
|
|
/* Get Mac address according to the chip revision */
|
453 |
|
|
pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
|
454 |
|
|
ret = 0;
|
455 |
|
|
|
456 |
|
|
if (revision == SIS630E_900_REV)
|
457 |
|
|
ret = sis630e_get_mac_addr(pci_dev, net_dev);
|
458 |
|
|
else if ((revision > 0x81) && (revision <= 0x90) )
|
459 |
|
|
ret = sis635_get_mac_addr(pci_dev, net_dev);
|
460 |
|
|
else if (revision == SIS96x_900_REV)
|
461 |
|
|
ret = sis96x_get_mac_addr(pci_dev, net_dev);
|
462 |
|
|
else
|
463 |
|
|
ret = sis900_get_mac_addr(pci_dev, net_dev);
|
464 |
|
|
|
465 |
|
|
if (ret == 0) {
|
466 |
|
|
ret = -ENODEV;
|
467 |
|
|
goto err_out_unregister;
|
468 |
|
|
}
|
469 |
|
|
|
470 |
|
|
/* 630ET : set the mii access mode as software-mode */
|
471 |
|
|
if (revision == SIS630ET_900_REV)
|
472 |
|
|
outl(ACCESSMODE | inl(ioaddr + cr), ioaddr + cr);
|
473 |
|
|
|
474 |
|
|
/* probe for mii transceiver */
|
475 |
|
|
if (sis900_mii_probe(net_dev) == 0) {
|
476 |
|
|
ret = -ENODEV;
|
477 |
|
|
goto err_out_unregister;
|
478 |
|
|
}
|
479 |
|
|
|
480 |
|
|
/* save our host bridge revision */
|
481 |
|
|
dev = pci_find_device(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_630, NULL);
|
482 |
|
|
if (dev)
|
483 |
|
|
pci_read_config_byte(dev, PCI_CLASS_REVISION, &sis_priv->host_bridge_rev);
|
484 |
|
|
|
485 |
|
|
/* print some information about our NIC */
|
486 |
|
|
printk(KERN_INFO "%s: %s at %#lx, IRQ %d, ", net_dev->name,
|
487 |
|
|
card_name, ioaddr, net_dev->irq);
|
488 |
|
|
for (i = 0; i < 5; i++)
|
489 |
|
|
printk("%2.2x:", (u8)net_dev->dev_addr[i]);
|
490 |
|
|
printk("%2.2x.\n", net_dev->dev_addr[i]);
|
491 |
|
|
|
492 |
|
|
return 0;
|
493 |
|
|
|
494 |
|
|
err_out_unregister:
|
495 |
|
|
unregister_netdev(net_dev);
|
496 |
|
|
err_unmap_rx:
|
497 |
|
|
pci_free_consistent(pci_dev, RX_TOTAL_SIZE, sis_priv->rx_ring,
|
498 |
|
|
sis_priv->rx_ring_dma);
|
499 |
|
|
err_unmap_tx:
|
500 |
|
|
pci_free_consistent(pci_dev, TX_TOTAL_SIZE, sis_priv->tx_ring,
|
501 |
|
|
sis_priv->tx_ring_dma);
|
502 |
|
|
err_out_cleardev:
|
503 |
|
|
pci_set_drvdata(pci_dev, NULL);
|
504 |
|
|
pci_release_regions(pci_dev);
|
505 |
|
|
err_out:
|
506 |
|
|
kfree(net_dev);
|
507 |
|
|
return ret;
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
/**
|
511 |
|
|
* sis900_mii_probe - Probe MII PHY for sis900
|
512 |
|
|
* @net_dev: the net device to probe for
|
513 |
|
|
*
|
514 |
|
|
* Search for total of 32 possible mii phy addresses.
|
515 |
|
|
* Identify and set current phy if found one,
|
516 |
|
|
* return error if it failed to found.
|
517 |
|
|
*/
|
518 |
|
|
|
519 |
|
|
static int __init sis900_mii_probe (struct net_device * net_dev)
|
520 |
|
|
{
|
521 |
|
|
struct sis900_private * sis_priv = net_dev->priv;
|
522 |
|
|
u16 poll_bit = MII_STAT_LINK, status = 0;
|
523 |
|
|
unsigned long timeout = jiffies + 5 * HZ;
|
524 |
|
|
int phy_addr;
|
525 |
|
|
u8 revision;
|
526 |
|
|
|
527 |
|
|
sis_priv->mii = NULL;
|
528 |
|
|
|
529 |
|
|
/* search for total of 32 possible mii phy addresses */
|
530 |
|
|
for (phy_addr = 0; phy_addr < 32; phy_addr++) {
|
531 |
|
|
struct mii_phy * mii_phy = NULL;
|
532 |
|
|
u16 mii_status;
|
533 |
|
|
int i;
|
534 |
|
|
|
535 |
|
|
mii_phy = NULL;
|
536 |
|
|
for(i = 0; i < 2; i++)
|
537 |
|
|
mii_status = mdio_read(net_dev, phy_addr, MII_STATUS);
|
538 |
|
|
|
539 |
|
|
if (mii_status == 0xffff || mii_status == 0x0000)
|
540 |
|
|
/* the mii is not accessible, try next one */
|
541 |
|
|
continue;
|
542 |
|
|
|
543 |
|
|
if ((mii_phy = kmalloc(sizeof(struct mii_phy), GFP_KERNEL)) == NULL) {
|
544 |
|
|
printk(KERN_INFO "Cannot allocate mem for struct mii_phy\n");
|
545 |
|
|
mii_phy = sis_priv->first_mii;
|
546 |
|
|
while (mii_phy) {
|
547 |
|
|
struct mii_phy *phy;
|
548 |
|
|
phy = mii_phy;
|
549 |
|
|
mii_phy = mii_phy->next;
|
550 |
|
|
kfree(phy);
|
551 |
|
|
}
|
552 |
|
|
return 0;
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
mii_phy->phy_id0 = mdio_read(net_dev, phy_addr, MII_PHY_ID0);
|
556 |
|
|
mii_phy->phy_id1 = mdio_read(net_dev, phy_addr, MII_PHY_ID1);
|
557 |
|
|
mii_phy->phy_addr = phy_addr;
|
558 |
|
|
mii_phy->status = mii_status;
|
559 |
|
|
mii_phy->next = sis_priv->mii;
|
560 |
|
|
sis_priv->mii = mii_phy;
|
561 |
|
|
sis_priv->first_mii = mii_phy;
|
562 |
|
|
|
563 |
|
|
for (i = 0; mii_chip_table[i].phy_id1; i++)
|
564 |
|
|
if ((mii_phy->phy_id0 == mii_chip_table[i].phy_id0 ) &&
|
565 |
|
|
((mii_phy->phy_id1 & 0xFFF0) == mii_chip_table[i].phy_id1)){
|
566 |
|
|
mii_phy->phy_types = mii_chip_table[i].phy_types;
|
567 |
|
|
if (mii_chip_table[i].phy_types == MIX)
|
568 |
|
|
mii_phy->phy_types =
|
569 |
|
|
(mii_status & (MII_STAT_CAN_TX_FDX | MII_STAT_CAN_TX)) ? LAN : HOME;
|
570 |
|
|
printk(KERN_INFO "%s: %s transceiver found at address %d.\n",
|
571 |
|
|
net_dev->name, mii_chip_table[i].name, phy_addr);
|
572 |
|
|
break;
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
if( !mii_chip_table[i].phy_id1 )
|
576 |
|
|
printk(KERN_INFO "%s: Unknown PHY transceiver found at address %d.\n",
|
577 |
|
|
net_dev->name, phy_addr);
|
578 |
|
|
}
|
579 |
|
|
|
580 |
|
|
if (sis_priv->mii == NULL) {
|
581 |
|
|
printk(KERN_INFO "%s: No MII transceivers found!\n",
|
582 |
|
|
net_dev->name);
|
583 |
|
|
return 0;
|
584 |
|
|
}
|
585 |
|
|
|
586 |
|
|
/* select default PHY for mac */
|
587 |
|
|
sis_priv->mii = NULL;
|
588 |
|
|
sis900_default_phy( net_dev );
|
589 |
|
|
|
590 |
|
|
/* Reset phy if default phy is internal sis900 */
|
591 |
|
|
if ((sis_priv->mii->phy_id0 == 0x001D) &&
|
592 |
|
|
((sis_priv->mii->phy_id1&0xFFF0) == 0x8000))
|
593 |
|
|
status = sis900_reset_phy(net_dev, sis_priv->cur_phy);
|
594 |
|
|
|
595 |
|
|
/* workaround for ICS1893 PHY */
|
596 |
|
|
if ((sis_priv->mii->phy_id0 == 0x0015) &&
|
597 |
|
|
((sis_priv->mii->phy_id1&0xFFF0) == 0xF440))
|
598 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, 0x0018, 0xD200);
|
599 |
|
|
|
600 |
|
|
if(status & MII_STAT_LINK){
|
601 |
|
|
while (poll_bit) {
|
602 |
|
|
current->state = TASK_INTERRUPTIBLE;
|
603 |
|
|
schedule_timeout(0);
|
604 |
|
|
poll_bit ^= (mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS) & poll_bit);
|
605 |
|
|
if (time_after_eq(jiffies, timeout)) {
|
606 |
|
|
printk(KERN_WARNING "%s: reset phy and link down now\n", net_dev->name);
|
607 |
|
|
return -ETIME;
|
608 |
|
|
}
|
609 |
|
|
}
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
613 |
|
|
if (revision == SIS630E_900_REV) {
|
614 |
|
|
/* SiS 630E has some bugs on default value of PHY registers */
|
615 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_ANADV, 0x05e1);
|
616 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_CONFIG1, 0x22);
|
617 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_CONFIG2, 0xff00);
|
618 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_MASK, 0xffc0);
|
619 |
|
|
//mdio_write(net_dev, sis_priv->cur_phy, MII_CONTROL, 0x1000);
|
620 |
|
|
}
|
621 |
|
|
|
622 |
|
|
if (sis_priv->mii->status & MII_STAT_LINK)
|
623 |
|
|
netif_carrier_on(net_dev);
|
624 |
|
|
else
|
625 |
|
|
netif_carrier_off(net_dev);
|
626 |
|
|
|
627 |
|
|
return 1;
|
628 |
|
|
}
|
629 |
|
|
|
630 |
|
|
/**
|
631 |
|
|
* sis900_default_phy - Select default PHY for sis900 mac.
|
632 |
|
|
* @net_dev: the net device to probe for
|
633 |
|
|
*
|
634 |
|
|
* Select first detected PHY with link as default.
|
635 |
|
|
* If no one is link on, select PHY whose types is HOME as default.
|
636 |
|
|
* If HOME doesn't exist, select LAN.
|
637 |
|
|
*/
|
638 |
|
|
|
639 |
|
|
static u16 sis900_default_phy(struct net_device * net_dev)
|
640 |
|
|
{
|
641 |
|
|
struct sis900_private * sis_priv = net_dev->priv;
|
642 |
|
|
struct mii_phy *phy = NULL, *phy_home = NULL, *default_phy = NULL;
|
643 |
|
|
u16 status;
|
644 |
|
|
|
645 |
|
|
for( phy=sis_priv->first_mii; phy; phy=phy->next ){
|
646 |
|
|
status = mdio_read(net_dev, phy->phy_addr, MII_STATUS);
|
647 |
|
|
status = mdio_read(net_dev, phy->phy_addr, MII_STATUS);
|
648 |
|
|
|
649 |
|
|
/* Link ON & Not select deafalut PHY */
|
650 |
|
|
if ( (status & MII_STAT_LINK) && !(default_phy) )
|
651 |
|
|
default_phy = phy;
|
652 |
|
|
else{
|
653 |
|
|
status = mdio_read(net_dev, phy->phy_addr, MII_CONTROL);
|
654 |
|
|
mdio_write(net_dev, phy->phy_addr, MII_CONTROL,
|
655 |
|
|
status | MII_CNTL_AUTO | MII_CNTL_ISOLATE);
|
656 |
|
|
if( phy->phy_types == HOME )
|
657 |
|
|
phy_home = phy;
|
658 |
|
|
}
|
659 |
|
|
}
|
660 |
|
|
|
661 |
|
|
if( (!default_phy) && phy_home )
|
662 |
|
|
default_phy = phy_home;
|
663 |
|
|
else if(!default_phy)
|
664 |
|
|
default_phy = sis_priv->first_mii;
|
665 |
|
|
|
666 |
|
|
if( sis_priv->mii != default_phy ){
|
667 |
|
|
sis_priv->mii = default_phy;
|
668 |
|
|
sis_priv->cur_phy = default_phy->phy_addr;
|
669 |
|
|
printk(KERN_INFO "%s: Using transceiver found at address %d as default\n", net_dev->name,sis_priv->cur_phy);
|
670 |
|
|
}
|
671 |
|
|
|
672 |
|
|
status = mdio_read(net_dev, sis_priv->cur_phy, MII_CONTROL);
|
673 |
|
|
status &= (~MII_CNTL_ISOLATE);
|
674 |
|
|
|
675 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_CONTROL, status);
|
676 |
|
|
status = mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS);
|
677 |
|
|
status = mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS);
|
678 |
|
|
|
679 |
|
|
return status;
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
|
683 |
|
|
/**
|
684 |
|
|
* sis900_set_capability - set the media capability of network adapter.
|
685 |
|
|
* @net_dev : the net device to probe for
|
686 |
|
|
* @phy : default PHY
|
687 |
|
|
*
|
688 |
|
|
* Set the media capability of network adapter according to
|
689 |
|
|
* mii status register. It's necessary before auto-negotiate.
|
690 |
|
|
*/
|
691 |
|
|
|
692 |
|
|
static void sis900_set_capability( struct net_device *net_dev , struct mii_phy *phy )
|
693 |
|
|
{
|
694 |
|
|
u16 cap;
|
695 |
|
|
u16 status;
|
696 |
|
|
|
697 |
|
|
status = mdio_read(net_dev, phy->phy_addr, MII_STATUS);
|
698 |
|
|
status = mdio_read(net_dev, phy->phy_addr, MII_STATUS);
|
699 |
|
|
|
700 |
|
|
cap = MII_NWAY_CSMA_CD |
|
701 |
|
|
((phy->status & MII_STAT_CAN_TX_FDX)? MII_NWAY_TX_FDX:0) |
|
702 |
|
|
((phy->status & MII_STAT_CAN_TX) ? MII_NWAY_TX:0) |
|
703 |
|
|
((phy->status & MII_STAT_CAN_T_FDX) ? MII_NWAY_T_FDX:0)|
|
704 |
|
|
((phy->status & MII_STAT_CAN_T) ? MII_NWAY_T:0);
|
705 |
|
|
|
706 |
|
|
mdio_write(net_dev, phy->phy_addr, MII_ANADV, cap);
|
707 |
|
|
}
|
708 |
|
|
|
709 |
|
|
|
710 |
|
|
/* Delay between EEPROM clock transitions. */
|
711 |
|
|
#define eeprom_delay() inl(ee_addr)
|
712 |
|
|
|
713 |
|
|
/**
|
714 |
|
|
* read_eeprom - Read Serial EEPROM
|
715 |
|
|
* @ioaddr: base i/o address
|
716 |
|
|
* @location: the EEPROM location to read
|
717 |
|
|
*
|
718 |
|
|
* Read Serial EEPROM through EEPROM Access Register.
|
719 |
|
|
* Note that location is in word (16 bits) unit
|
720 |
|
|
*/
|
721 |
|
|
|
722 |
|
|
static u16 __devinit read_eeprom(long ioaddr, int location)
|
723 |
|
|
{
|
724 |
|
|
int i;
|
725 |
|
|
u16 retval = 0;
|
726 |
|
|
long ee_addr = ioaddr + mear;
|
727 |
|
|
u32 read_cmd = location | EEread;
|
728 |
|
|
|
729 |
|
|
outl(0, ee_addr);
|
730 |
|
|
eeprom_delay();
|
731 |
|
|
outl(EECS, ee_addr);
|
732 |
|
|
eeprom_delay();
|
733 |
|
|
|
734 |
|
|
/* Shift the read command (9) bits out. */
|
735 |
|
|
for (i = 8; i >= 0; i--) {
|
736 |
|
|
u32 dataval = (read_cmd & (1 << i)) ? EEDI | EECS : EECS;
|
737 |
|
|
outl(dataval, ee_addr);
|
738 |
|
|
eeprom_delay();
|
739 |
|
|
outl(dataval | EECLK, ee_addr);
|
740 |
|
|
eeprom_delay();
|
741 |
|
|
}
|
742 |
|
|
outl(EECS, ee_addr);
|
743 |
|
|
eeprom_delay();
|
744 |
|
|
|
745 |
|
|
/* read the 16-bits data in */
|
746 |
|
|
for (i = 16; i > 0; i--) {
|
747 |
|
|
outl(EECS, ee_addr);
|
748 |
|
|
eeprom_delay();
|
749 |
|
|
outl(EECS | EECLK, ee_addr);
|
750 |
|
|
eeprom_delay();
|
751 |
|
|
retval = (retval << 1) | ((inl(ee_addr) & EEDO) ? 1 : 0);
|
752 |
|
|
eeprom_delay();
|
753 |
|
|
}
|
754 |
|
|
|
755 |
|
|
/* Terminate the EEPROM access. */
|
756 |
|
|
outl(0, ee_addr);
|
757 |
|
|
eeprom_delay();
|
758 |
|
|
|
759 |
|
|
return (retval);
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
/* Read and write the MII management registers using software-generated
|
763 |
|
|
serial MDIO protocol. Note that the command bits and data bits are
|
764 |
|
|
send out separately */
|
765 |
|
|
#define mdio_delay() inl(mdio_addr)
|
766 |
|
|
|
767 |
|
|
static void mdio_idle(long mdio_addr)
|
768 |
|
|
{
|
769 |
|
|
outl(MDIO | MDDIR, mdio_addr);
|
770 |
|
|
mdio_delay();
|
771 |
|
|
outl(MDIO | MDDIR | MDC, mdio_addr);
|
772 |
|
|
}
|
773 |
|
|
|
774 |
|
|
/* Syncronize the MII management interface by shifting 32 one bits out. */
|
775 |
|
|
static void mdio_reset(long mdio_addr)
|
776 |
|
|
{
|
777 |
|
|
int i;
|
778 |
|
|
|
779 |
|
|
for (i = 31; i >= 0; i--) {
|
780 |
|
|
outl(MDDIR | MDIO, mdio_addr);
|
781 |
|
|
mdio_delay();
|
782 |
|
|
outl(MDDIR | MDIO | MDC, mdio_addr);
|
783 |
|
|
mdio_delay();
|
784 |
|
|
}
|
785 |
|
|
return;
|
786 |
|
|
}
|
787 |
|
|
|
788 |
|
|
/**
|
789 |
|
|
* mdio_read - read MII PHY register
|
790 |
|
|
* @net_dev: the net device to read
|
791 |
|
|
* @phy_id: the phy address to read
|
792 |
|
|
* @location: the phy regiester id to read
|
793 |
|
|
*
|
794 |
|
|
* Read MII registers through MDIO and MDC
|
795 |
|
|
* using MDIO management frame structure and protocol(defined by ISO/IEC).
|
796 |
|
|
* Please see SiS7014 or ICS spec
|
797 |
|
|
*/
|
798 |
|
|
|
799 |
|
|
static u16 mdio_read(struct net_device *net_dev, int phy_id, int location)
|
800 |
|
|
{
|
801 |
|
|
long mdio_addr = net_dev->base_addr + mear;
|
802 |
|
|
int mii_cmd = MIIread|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
|
803 |
|
|
u16 retval = 0;
|
804 |
|
|
int i;
|
805 |
|
|
|
806 |
|
|
mdio_reset(mdio_addr);
|
807 |
|
|
mdio_idle(mdio_addr);
|
808 |
|
|
|
809 |
|
|
for (i = 15; i >= 0; i--) {
|
810 |
|
|
int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
|
811 |
|
|
outl(dataval, mdio_addr);
|
812 |
|
|
mdio_delay();
|
813 |
|
|
outl(dataval | MDC, mdio_addr);
|
814 |
|
|
mdio_delay();
|
815 |
|
|
}
|
816 |
|
|
|
817 |
|
|
/* Read the 16 data bits. */
|
818 |
|
|
for (i = 16; i > 0; i--) {
|
819 |
|
|
outl(0, mdio_addr);
|
820 |
|
|
mdio_delay();
|
821 |
|
|
retval = (retval << 1) | ((inl(mdio_addr) & MDIO) ? 1 : 0);
|
822 |
|
|
outl(MDC, mdio_addr);
|
823 |
|
|
mdio_delay();
|
824 |
|
|
}
|
825 |
|
|
outl(0x00, mdio_addr);
|
826 |
|
|
|
827 |
|
|
return retval;
|
828 |
|
|
}
|
829 |
|
|
|
830 |
|
|
/**
|
831 |
|
|
* mdio_write - write MII PHY register
|
832 |
|
|
* @net_dev: the net device to write
|
833 |
|
|
* @phy_id: the phy address to write
|
834 |
|
|
* @location: the phy regiester id to write
|
835 |
|
|
* @value: the register value to write with
|
836 |
|
|
*
|
837 |
|
|
* Write MII registers with @value through MDIO and MDC
|
838 |
|
|
* using MDIO management frame structure and protocol(defined by ISO/IEC)
|
839 |
|
|
* please see SiS7014 or ICS spec
|
840 |
|
|
*/
|
841 |
|
|
|
842 |
|
|
static void mdio_write(struct net_device *net_dev, int phy_id, int location, int value)
|
843 |
|
|
{
|
844 |
|
|
long mdio_addr = net_dev->base_addr + mear;
|
845 |
|
|
int mii_cmd = MIIwrite|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
|
846 |
|
|
int i;
|
847 |
|
|
|
848 |
|
|
mdio_reset(mdio_addr);
|
849 |
|
|
mdio_idle(mdio_addr);
|
850 |
|
|
|
851 |
|
|
/* Shift the command bits out. */
|
852 |
|
|
for (i = 15; i >= 0; i--) {
|
853 |
|
|
int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
|
854 |
|
|
outb(dataval, mdio_addr);
|
855 |
|
|
mdio_delay();
|
856 |
|
|
outb(dataval | MDC, mdio_addr);
|
857 |
|
|
mdio_delay();
|
858 |
|
|
}
|
859 |
|
|
mdio_delay();
|
860 |
|
|
|
861 |
|
|
/* Shift the value bits out. */
|
862 |
|
|
for (i = 15; i >= 0; i--) {
|
863 |
|
|
int dataval = (value & (1 << i)) ? MDDIR | MDIO : MDDIR;
|
864 |
|
|
outl(dataval, mdio_addr);
|
865 |
|
|
mdio_delay();
|
866 |
|
|
outl(dataval | MDC, mdio_addr);
|
867 |
|
|
mdio_delay();
|
868 |
|
|
}
|
869 |
|
|
mdio_delay();
|
870 |
|
|
|
871 |
|
|
/* Clear out extra bits. */
|
872 |
|
|
for (i = 2; i > 0; i--) {
|
873 |
|
|
outb(0, mdio_addr);
|
874 |
|
|
mdio_delay();
|
875 |
|
|
outb(MDC, mdio_addr);
|
876 |
|
|
mdio_delay();
|
877 |
|
|
}
|
878 |
|
|
outl(0x00, mdio_addr);
|
879 |
|
|
|
880 |
|
|
return;
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
|
884 |
|
|
/**
|
885 |
|
|
* sis900_reset_phy - reset sis900 mii phy.
|
886 |
|
|
* @net_dev: the net device to write
|
887 |
|
|
* @phy_addr: default phy address
|
888 |
|
|
*
|
889 |
|
|
* Some specific phy can't work properly without reset.
|
890 |
|
|
* This function will be called during initialization and
|
891 |
|
|
* link status change from ON to DOWN.
|
892 |
|
|
*/
|
893 |
|
|
|
894 |
|
|
static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr)
|
895 |
|
|
{
|
896 |
|
|
int i = 0;
|
897 |
|
|
u16 status;
|
898 |
|
|
|
899 |
|
|
while (i++ < 2)
|
900 |
|
|
status = mdio_read(net_dev, phy_addr, MII_STATUS);
|
901 |
|
|
|
902 |
|
|
mdio_write( net_dev, phy_addr, MII_CONTROL, MII_CNTL_RESET );
|
903 |
|
|
|
904 |
|
|
return status;
|
905 |
|
|
}
|
906 |
|
|
|
907 |
|
|
/**
|
908 |
|
|
* sis900_open - open sis900 device
|
909 |
|
|
* @net_dev: the net device to open
|
910 |
|
|
*
|
911 |
|
|
* Do some initialization and start net interface.
|
912 |
|
|
* enable interrupts and set sis900 timer.
|
913 |
|
|
*/
|
914 |
|
|
|
915 |
|
|
static int
|
916 |
|
|
sis900_open(struct net_device *net_dev)
|
917 |
|
|
{
|
918 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
919 |
|
|
long ioaddr = net_dev->base_addr;
|
920 |
|
|
u8 revision;
|
921 |
|
|
int ret;
|
922 |
|
|
|
923 |
|
|
/* Soft reset the chip. */
|
924 |
|
|
sis900_reset(net_dev);
|
925 |
|
|
|
926 |
|
|
/* Equalizer workaround Rule */
|
927 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
928 |
|
|
sis630_set_eq(net_dev, revision);
|
929 |
|
|
|
930 |
|
|
ret = request_irq(net_dev->irq, &sis900_interrupt, SA_SHIRQ, net_dev->name, net_dev);
|
931 |
|
|
if (ret)
|
932 |
|
|
return ret;
|
933 |
|
|
|
934 |
|
|
sis900_init_rxfilter(net_dev);
|
935 |
|
|
|
936 |
|
|
sis900_init_tx_ring(net_dev);
|
937 |
|
|
sis900_init_rx_ring(net_dev);
|
938 |
|
|
|
939 |
|
|
set_rx_mode(net_dev);
|
940 |
|
|
|
941 |
|
|
netif_start_queue(net_dev);
|
942 |
|
|
|
943 |
|
|
/* Workaround for EDB */
|
944 |
|
|
sis900_set_mode(ioaddr, HW_SPEED_10_MBPS, FDX_CAPABLE_HALF_SELECTED);
|
945 |
|
|
|
946 |
|
|
/* Enable all known interrupts by setting the interrupt mask. */
|
947 |
|
|
outl((RxSOVR|RxORN|RxERR|RxOK|TxURN|TxERR|TxIDLE), ioaddr + imr);
|
948 |
|
|
outl(RxENA | inl(ioaddr + cr), ioaddr + cr);
|
949 |
|
|
outl(IE, ioaddr + ier);
|
950 |
|
|
|
951 |
|
|
sis900_check_mode(net_dev, sis_priv->mii);
|
952 |
|
|
|
953 |
|
|
/* Set the timer to switch to check for link beat and perhaps switch
|
954 |
|
|
to an alternate media type. */
|
955 |
|
|
init_timer(&sis_priv->timer);
|
956 |
|
|
sis_priv->timer.expires = jiffies + HZ;
|
957 |
|
|
sis_priv->timer.data = (unsigned long)net_dev;
|
958 |
|
|
sis_priv->timer.function = &sis900_timer;
|
959 |
|
|
add_timer(&sis_priv->timer);
|
960 |
|
|
|
961 |
|
|
return 0;
|
962 |
|
|
}
|
963 |
|
|
|
964 |
|
|
/**
|
965 |
|
|
* sis900_init_rxfilter - Initialize the Rx filter
|
966 |
|
|
* @net_dev: the net device to initialize for
|
967 |
|
|
*
|
968 |
|
|
* Set receive filter address to our MAC address
|
969 |
|
|
* and enable packet filtering.
|
970 |
|
|
*/
|
971 |
|
|
|
972 |
|
|
static void
|
973 |
|
|
sis900_init_rxfilter (struct net_device * net_dev)
|
974 |
|
|
{
|
975 |
|
|
long ioaddr = net_dev->base_addr;
|
976 |
|
|
u32 rfcrSave;
|
977 |
|
|
u32 i;
|
978 |
|
|
|
979 |
|
|
rfcrSave = inl(rfcr + ioaddr);
|
980 |
|
|
|
981 |
|
|
/* disable packet filtering before setting filter */
|
982 |
|
|
outl(rfcrSave & ~RFEN, rfcr + ioaddr);
|
983 |
|
|
|
984 |
|
|
/* load MAC addr to filter data register */
|
985 |
|
|
for (i = 0 ; i < 3 ; i++) {
|
986 |
|
|
u32 w;
|
987 |
|
|
|
988 |
|
|
w = (u32) *((u16 *)(net_dev->dev_addr)+i);
|
989 |
|
|
outl((i << RFADDR_shift), ioaddr + rfcr);
|
990 |
|
|
outl(w, ioaddr + rfdr);
|
991 |
|
|
|
992 |
|
|
if (sis900_debug > 2) {
|
993 |
|
|
printk(KERN_INFO "%s: Receive Filter Addrss[%d]=%x\n",
|
994 |
|
|
net_dev->name, i, inl(ioaddr + rfdr));
|
995 |
|
|
}
|
996 |
|
|
}
|
997 |
|
|
|
998 |
|
|
/* enable packet filitering */
|
999 |
|
|
outl(rfcrSave | RFEN, rfcr + ioaddr);
|
1000 |
|
|
}
|
1001 |
|
|
|
1002 |
|
|
/**
|
1003 |
|
|
* sis900_init_tx_ring - Initialize the Tx descriptor ring
|
1004 |
|
|
* @net_dev: the net device to initialize for
|
1005 |
|
|
*
|
1006 |
|
|
* Initialize the Tx descriptor ring,
|
1007 |
|
|
*/
|
1008 |
|
|
|
1009 |
|
|
static void
|
1010 |
|
|
sis900_init_tx_ring(struct net_device *net_dev)
|
1011 |
|
|
{
|
1012 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1013 |
|
|
long ioaddr = net_dev->base_addr;
|
1014 |
|
|
int i;
|
1015 |
|
|
|
1016 |
|
|
sis_priv->tx_full = 0;
|
1017 |
|
|
sis_priv->dirty_tx = sis_priv->cur_tx = 0;
|
1018 |
|
|
|
1019 |
|
|
for (i = 0; i < NUM_TX_DESC; i++) {
|
1020 |
|
|
sis_priv->tx_skbuff[i] = NULL;
|
1021 |
|
|
|
1022 |
|
|
sis_priv->tx_ring[i].link = sis_priv->tx_ring_dma +
|
1023 |
|
|
((i+1)%NUM_TX_DESC)*sizeof(BufferDesc);
|
1024 |
|
|
sis_priv->tx_ring[i].cmdsts = 0;
|
1025 |
|
|
sis_priv->tx_ring[i].bufptr = 0;
|
1026 |
|
|
}
|
1027 |
|
|
|
1028 |
|
|
/* load Transmit Descriptor Register */
|
1029 |
|
|
outl(sis_priv->tx_ring_dma, ioaddr + txdp);
|
1030 |
|
|
if (sis900_debug > 2)
|
1031 |
|
|
printk(KERN_INFO "%s: TX descriptor register loaded with: %8.8x\n",
|
1032 |
|
|
net_dev->name, inl(ioaddr + txdp));
|
1033 |
|
|
}
|
1034 |
|
|
|
1035 |
|
|
/**
|
1036 |
|
|
* sis900_init_rx_ring - Initialize the Rx descriptor ring
|
1037 |
|
|
* @net_dev: the net device to initialize for
|
1038 |
|
|
*
|
1039 |
|
|
* Initialize the Rx descriptor ring,
|
1040 |
|
|
* and pre-allocate recevie buffers (socket buffer)
|
1041 |
|
|
*/
|
1042 |
|
|
|
1043 |
|
|
static void
|
1044 |
|
|
sis900_init_rx_ring(struct net_device *net_dev)
|
1045 |
|
|
{
|
1046 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1047 |
|
|
long ioaddr = net_dev->base_addr;
|
1048 |
|
|
int i;
|
1049 |
|
|
|
1050 |
|
|
sis_priv->cur_rx = 0;
|
1051 |
|
|
sis_priv->dirty_rx = 0;
|
1052 |
|
|
|
1053 |
|
|
/* init RX descriptor */
|
1054 |
|
|
for (i = 0; i < NUM_RX_DESC; i++) {
|
1055 |
|
|
sis_priv->rx_skbuff[i] = NULL;
|
1056 |
|
|
|
1057 |
|
|
sis_priv->rx_ring[i].link = sis_priv->rx_ring_dma +
|
1058 |
|
|
((i+1)%NUM_RX_DESC)*sizeof(BufferDesc);
|
1059 |
|
|
sis_priv->rx_ring[i].cmdsts = 0;
|
1060 |
|
|
sis_priv->rx_ring[i].bufptr = 0;
|
1061 |
|
|
}
|
1062 |
|
|
|
1063 |
|
|
/* allocate sock buffers */
|
1064 |
|
|
for (i = 0; i < NUM_RX_DESC; i++) {
|
1065 |
|
|
struct sk_buff *skb;
|
1066 |
|
|
|
1067 |
|
|
if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
|
1068 |
|
|
/* not enough memory for skbuff, this makes a "hole"
|
1069 |
|
|
on the buffer ring, it is not clear how the
|
1070 |
|
|
hardware will react to this kind of degenerated
|
1071 |
|
|
buffer */
|
1072 |
|
|
break;
|
1073 |
|
|
}
|
1074 |
|
|
skb->dev = net_dev;
|
1075 |
|
|
sis_priv->rx_skbuff[i] = skb;
|
1076 |
|
|
sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE;
|
1077 |
|
|
sis_priv->rx_ring[i].bufptr = pci_map_single(sis_priv->pci_dev,
|
1078 |
|
|
skb->tail, RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
|
1079 |
|
|
}
|
1080 |
|
|
sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC);
|
1081 |
|
|
|
1082 |
|
|
/* load Receive Descriptor Register */
|
1083 |
|
|
outl(sis_priv->rx_ring_dma, ioaddr + rxdp);
|
1084 |
|
|
if (sis900_debug > 2)
|
1085 |
|
|
printk(KERN_INFO "%s: RX descriptor register loaded with: %8.8x\n",
|
1086 |
|
|
net_dev->name, inl(ioaddr + rxdp));
|
1087 |
|
|
}
|
1088 |
|
|
|
1089 |
|
|
/**
|
1090 |
|
|
* sis630_set_eq - set phy equalizer value for 630 LAN
|
1091 |
|
|
* @net_dev: the net device to set equalizer value
|
1092 |
|
|
* @revision: 630 LAN revision number
|
1093 |
|
|
*
|
1094 |
|
|
* 630E equalizer workaround rule(Cyrus Huang 08/15)
|
1095 |
|
|
* PHY register 14h(Test)
|
1096 |
|
|
* Bit 14: 0 -- Automatically dectect (default)
|
1097 |
|
|
* 1 -- Manually set Equalizer filter
|
1098 |
|
|
* Bit 13: 0 -- (Default)
|
1099 |
|
|
* 1 -- Speed up convergence of equalizer setting
|
1100 |
|
|
* Bit 9 : 0 -- (Default)
|
1101 |
|
|
* 1 -- Disable Baseline Wander
|
1102 |
|
|
* Bit 3~7 -- Equalizer filter setting
|
1103 |
|
|
* Link ON: Set Bit 9, 13 to 1, Bit 14 to 0
|
1104 |
|
|
* Then calculate equalizer value
|
1105 |
|
|
* Then set equalizer value, and set Bit 14 to 1, Bit 9 to 0
|
1106 |
|
|
* Link Off:Set Bit 13 to 1, Bit 14 to 0
|
1107 |
|
|
* Calculate Equalizer value:
|
1108 |
|
|
* When Link is ON and Bit 14 is 0, SIS900PHY will auto-dectect proper equalizer value.
|
1109 |
|
|
* When the equalizer is stable, this value is not a fixed value. It will be within
|
1110 |
|
|
* a small range(eg. 7~9). Then we get a minimum and a maximum value(eg. min=7, max=9)
|
1111 |
|
|
* 0 <= max <= 4 --> set equalizer to max
|
1112 |
|
|
* 5 <= max <= 14 --> set equalizer to max+1 or set equalizer to max+2 if max == min
|
1113 |
|
|
* max >= 15 --> set equalizer to max+5 or set equalizer to max+6 if max == min
|
1114 |
|
|
*/
|
1115 |
|
|
|
1116 |
|
|
static void sis630_set_eq(struct net_device *net_dev, u8 revision)
|
1117 |
|
|
{
|
1118 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1119 |
|
|
u16 reg14h, eq_value=0, max_value=0, min_value=0;
|
1120 |
|
|
int i, maxcount=10;
|
1121 |
|
|
|
1122 |
|
|
if ( !(revision == SIS630E_900_REV || revision == SIS630EA1_900_REV ||
|
1123 |
|
|
revision == SIS630A_900_REV || revision == SIS630ET_900_REV) )
|
1124 |
|
|
return;
|
1125 |
|
|
|
1126 |
|
|
if (netif_carrier_ok(net_dev)) {
|
1127 |
|
|
reg14h=mdio_read(net_dev, sis_priv->cur_phy, MII_RESV);
|
1128 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_RESV, (0x2200 | reg14h) & 0xBFFF);
|
1129 |
|
|
for (i=0; i < maxcount; i++) {
|
1130 |
|
|
eq_value=(0x00F8 & mdio_read(net_dev, sis_priv->cur_phy, MII_RESV)) >> 3;
|
1131 |
|
|
if (i == 0)
|
1132 |
|
|
max_value=min_value=eq_value;
|
1133 |
|
|
max_value=(eq_value > max_value) ? eq_value : max_value;
|
1134 |
|
|
min_value=(eq_value < min_value) ? eq_value : min_value;
|
1135 |
|
|
}
|
1136 |
|
|
/* 630E rule to determine the equalizer value */
|
1137 |
|
|
if (revision == SIS630E_900_REV || revision == SIS630EA1_900_REV ||
|
1138 |
|
|
revision == SIS630ET_900_REV) {
|
1139 |
|
|
if (max_value < 5)
|
1140 |
|
|
eq_value=max_value;
|
1141 |
|
|
else if (max_value >= 5 && max_value < 15)
|
1142 |
|
|
eq_value=(max_value == min_value) ? max_value+2 : max_value+1;
|
1143 |
|
|
else if (max_value >= 15)
|
1144 |
|
|
eq_value=(max_value == min_value) ? max_value+6 : max_value+5;
|
1145 |
|
|
}
|
1146 |
|
|
/* 630B0&B1 rule to determine the equalizer value */
|
1147 |
|
|
if (revision == SIS630A_900_REV &&
|
1148 |
|
|
(sis_priv->host_bridge_rev == SIS630B0 ||
|
1149 |
|
|
sis_priv->host_bridge_rev == SIS630B1)) {
|
1150 |
|
|
if (max_value == 0)
|
1151 |
|
|
eq_value=3;
|
1152 |
|
|
else
|
1153 |
|
|
eq_value=(max_value+min_value+1)/2;
|
1154 |
|
|
}
|
1155 |
|
|
/* write equalizer value and setting */
|
1156 |
|
|
reg14h=mdio_read(net_dev, sis_priv->cur_phy, MII_RESV);
|
1157 |
|
|
reg14h=(reg14h & 0xFF07) | ((eq_value << 3) & 0x00F8);
|
1158 |
|
|
reg14h=(reg14h | 0x6000) & 0xFDFF;
|
1159 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_RESV, reg14h);
|
1160 |
|
|
}
|
1161 |
|
|
else {
|
1162 |
|
|
reg14h=mdio_read(net_dev, sis_priv->cur_phy, MII_RESV);
|
1163 |
|
|
if (revision == SIS630A_900_REV &&
|
1164 |
|
|
(sis_priv->host_bridge_rev == SIS630B0 ||
|
1165 |
|
|
sis_priv->host_bridge_rev == SIS630B1))
|
1166 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_RESV, (reg14h | 0x2200) & 0xBFFF);
|
1167 |
|
|
else
|
1168 |
|
|
mdio_write(net_dev, sis_priv->cur_phy, MII_RESV, (reg14h | 0x2000) & 0xBFFF);
|
1169 |
|
|
}
|
1170 |
|
|
return;
|
1171 |
|
|
}
|
1172 |
|
|
|
1173 |
|
|
/**
|
1174 |
|
|
* sis900_timer - sis900 timer routine
|
1175 |
|
|
* @data: pointer to sis900 net device
|
1176 |
|
|
*
|
1177 |
|
|
* On each timer ticks we check two things,
|
1178 |
|
|
* link status (ON/OFF) and link mode (10/100/Full/Half)
|
1179 |
|
|
*/
|
1180 |
|
|
|
1181 |
|
|
static void sis900_timer(unsigned long data)
|
1182 |
|
|
{
|
1183 |
|
|
struct net_device *net_dev = (struct net_device *)data;
|
1184 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1185 |
|
|
struct mii_phy *mii_phy = sis_priv->mii;
|
1186 |
|
|
static int next_tick = 5*HZ;
|
1187 |
|
|
u16 status;
|
1188 |
|
|
u8 revision;
|
1189 |
|
|
|
1190 |
|
|
if (!sis_priv->autong_complete){
|
1191 |
|
|
int speed, duplex = 0;
|
1192 |
|
|
|
1193 |
|
|
sis900_read_mode(net_dev, &speed, &duplex);
|
1194 |
|
|
if (duplex){
|
1195 |
|
|
sis900_set_mode(net_dev->base_addr, speed, duplex);
|
1196 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
1197 |
|
|
sis630_set_eq(net_dev, revision);
|
1198 |
|
|
netif_start_queue(net_dev);
|
1199 |
|
|
}
|
1200 |
|
|
|
1201 |
|
|
sis_priv->timer.expires = jiffies + HZ;
|
1202 |
|
|
add_timer(&sis_priv->timer);
|
1203 |
|
|
return;
|
1204 |
|
|
}
|
1205 |
|
|
|
1206 |
|
|
status = mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS);
|
1207 |
|
|
status = mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS);
|
1208 |
|
|
|
1209 |
|
|
/* Link OFF -> ON */
|
1210 |
|
|
if (!netif_carrier_ok(net_dev)) {
|
1211 |
|
|
LookForLink:
|
1212 |
|
|
/* Search for new PHY */
|
1213 |
|
|
status = sis900_default_phy(net_dev);
|
1214 |
|
|
mii_phy = sis_priv->mii;
|
1215 |
|
|
|
1216 |
|
|
if (status & MII_STAT_LINK){
|
1217 |
|
|
sis900_check_mode(net_dev, mii_phy);
|
1218 |
|
|
netif_carrier_on(net_dev);
|
1219 |
|
|
}
|
1220 |
|
|
}
|
1221 |
|
|
/* Link ON -> OFF */
|
1222 |
|
|
else {
|
1223 |
|
|
if (!(status & MII_STAT_LINK)){
|
1224 |
|
|
netif_carrier_off(net_dev);
|
1225 |
|
|
printk(KERN_INFO "%s: Media Link Off\n", net_dev->name);
|
1226 |
|
|
|
1227 |
|
|
/* Change mode issue */
|
1228 |
|
|
if ((mii_phy->phy_id0 == 0x001D) &&
|
1229 |
|
|
((mii_phy->phy_id1 & 0xFFF0) == 0x8000))
|
1230 |
|
|
sis900_reset_phy(net_dev, sis_priv->cur_phy);
|
1231 |
|
|
|
1232 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
1233 |
|
|
sis630_set_eq(net_dev, revision);
|
1234 |
|
|
|
1235 |
|
|
goto LookForLink;
|
1236 |
|
|
}
|
1237 |
|
|
}
|
1238 |
|
|
|
1239 |
|
|
sis_priv->timer.expires = jiffies + next_tick;
|
1240 |
|
|
add_timer(&sis_priv->timer);
|
1241 |
|
|
}
|
1242 |
|
|
|
1243 |
|
|
/**
|
1244 |
|
|
* sis900_check_mode - check the media mode for sis900
|
1245 |
|
|
* @net_dev: the net device to be checked
|
1246 |
|
|
* @mii_phy: the mii phy
|
1247 |
|
|
*
|
1248 |
|
|
* Older driver gets the media mode from mii status output
|
1249 |
|
|
* register. Now we set our media capability and auto-negotiate
|
1250 |
|
|
* to get the upper bound of speed and duplex between two ends.
|
1251 |
|
|
* If the types of mii phy is HOME, it doesn't need to auto-negotiate
|
1252 |
|
|
* and autong_complete should be set to 1.
|
1253 |
|
|
*/
|
1254 |
|
|
|
1255 |
|
|
static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy)
|
1256 |
|
|
{
|
1257 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1258 |
|
|
long ioaddr = net_dev->base_addr;
|
1259 |
|
|
int speed, duplex;
|
1260 |
|
|
|
1261 |
|
|
if( mii_phy->phy_types == LAN ){
|
1262 |
|
|
outl( ~EXD & inl( ioaddr + cfg ), ioaddr + cfg);
|
1263 |
|
|
sis900_set_capability(net_dev , mii_phy);
|
1264 |
|
|
sis900_auto_negotiate(net_dev, sis_priv->cur_phy);
|
1265 |
|
|
}else{
|
1266 |
|
|
outl(EXD | inl( ioaddr + cfg ), ioaddr + cfg);
|
1267 |
|
|
speed = HW_SPEED_HOME;
|
1268 |
|
|
duplex = FDX_CAPABLE_HALF_SELECTED;
|
1269 |
|
|
sis900_set_mode(ioaddr, speed, duplex);
|
1270 |
|
|
sis_priv->autong_complete = 1;
|
1271 |
|
|
}
|
1272 |
|
|
}
|
1273 |
|
|
|
1274 |
|
|
/**
|
1275 |
|
|
* sis900_set_mode - Set the media mode of mac register.
|
1276 |
|
|
* @ioaddr: the address of the device
|
1277 |
|
|
* @speed : the transmit speed to be determined
|
1278 |
|
|
* @duplex: the duplex mode to be determined
|
1279 |
|
|
*
|
1280 |
|
|
* Set the media mode of mac register txcfg/rxcfg according to
|
1281 |
|
|
* speed and duplex of phy. Bit EDB_MASTER_EN indicates the EDB
|
1282 |
|
|
* bus is used instead of PCI bus. When this bit is set 1, the
|
1283 |
|
|
* Max DMA Burst Size for TX/RX DMA should be no larger than 16
|
1284 |
|
|
* double words.
|
1285 |
|
|
*/
|
1286 |
|
|
|
1287 |
|
|
static void sis900_set_mode (long ioaddr, int speed, int duplex)
|
1288 |
|
|
{
|
1289 |
|
|
u32 tx_flags = 0, rx_flags = 0;
|
1290 |
|
|
|
1291 |
|
|
if( inl(ioaddr + cfg) & EDB_MASTER_EN ){
|
1292 |
|
|
tx_flags = TxATP | (DMA_BURST_64 << TxMXDMA_shift) | (TX_FILL_THRESH << TxFILLT_shift);
|
1293 |
|
|
rx_flags = DMA_BURST_64 << RxMXDMA_shift;
|
1294 |
|
|
}
|
1295 |
|
|
else{
|
1296 |
|
|
tx_flags = TxATP | (DMA_BURST_512 << TxMXDMA_shift) | (TX_FILL_THRESH << TxFILLT_shift);
|
1297 |
|
|
rx_flags = DMA_BURST_512 << RxMXDMA_shift;
|
1298 |
|
|
}
|
1299 |
|
|
|
1300 |
|
|
if (speed == HW_SPEED_HOME || speed == HW_SPEED_10_MBPS ) {
|
1301 |
|
|
rx_flags |= (RxDRNT_10 << RxDRNT_shift);
|
1302 |
|
|
tx_flags |= (TxDRNT_10 << TxDRNT_shift);
|
1303 |
|
|
}
|
1304 |
|
|
else {
|
1305 |
|
|
rx_flags |= (RxDRNT_100 << RxDRNT_shift);
|
1306 |
|
|
tx_flags |= (TxDRNT_100 << TxDRNT_shift);
|
1307 |
|
|
}
|
1308 |
|
|
|
1309 |
|
|
if (duplex == FDX_CAPABLE_FULL_SELECTED) {
|
1310 |
|
|
tx_flags |= (TxCSI | TxHBI);
|
1311 |
|
|
rx_flags |= RxATX;
|
1312 |
|
|
}
|
1313 |
|
|
|
1314 |
|
|
outl (tx_flags, ioaddr + txcfg);
|
1315 |
|
|
outl (rx_flags, ioaddr + rxcfg);
|
1316 |
|
|
}
|
1317 |
|
|
|
1318 |
|
|
/**
|
1319 |
|
|
* sis900_auto_negotiate - Set the Auto-Negotiation Enable/Reset bit.
|
1320 |
|
|
* @net_dev: the net device to read mode for
|
1321 |
|
|
* @phy_addr: mii phy address
|
1322 |
|
|
*
|
1323 |
|
|
* If the adapter is link-on, set the auto-negotiate enable/reset bit.
|
1324 |
|
|
* autong_complete should be set to 0 when starting auto-negotiation.
|
1325 |
|
|
* autong_complete should be set to 1 if we didn't start auto-negotiation.
|
1326 |
|
|
* sis900_timer will wait for link on again if autong_complete = 0.
|
1327 |
|
|
*/
|
1328 |
|
|
|
1329 |
|
|
static void sis900_auto_negotiate(struct net_device *net_dev, int phy_addr)
|
1330 |
|
|
{
|
1331 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1332 |
|
|
int i = 0;
|
1333 |
|
|
u32 status;
|
1334 |
|
|
|
1335 |
|
|
while (i++ < 2)
|
1336 |
|
|
status = mdio_read(net_dev, phy_addr, MII_STATUS);
|
1337 |
|
|
|
1338 |
|
|
if (!(status & MII_STAT_LINK)){
|
1339 |
|
|
printk(KERN_INFO "%s: Media Link Off\n", net_dev->name);
|
1340 |
|
|
sis_priv->autong_complete = 1;
|
1341 |
|
|
netif_carrier_off(net_dev);
|
1342 |
|
|
return;
|
1343 |
|
|
}
|
1344 |
|
|
|
1345 |
|
|
/* (Re)start AutoNegotiate */
|
1346 |
|
|
mdio_write(net_dev, phy_addr, MII_CONTROL,
|
1347 |
|
|
MII_CNTL_AUTO | MII_CNTL_RST_AUTO);
|
1348 |
|
|
sis_priv->autong_complete = 0;
|
1349 |
|
|
}
|
1350 |
|
|
|
1351 |
|
|
|
1352 |
|
|
/**
|
1353 |
|
|
* sis900_read_mode - read media mode for sis900 internal phy
|
1354 |
|
|
* @net_dev: the net device to read mode for
|
1355 |
|
|
* @speed : the transmit speed to be determined
|
1356 |
|
|
* @duplex : the duplex mode to be determined
|
1357 |
|
|
*
|
1358 |
|
|
* The capability of remote end will be put in mii register autorec
|
1359 |
|
|
* after auto-negotiation. Use AND operation to get the upper bound
|
1360 |
|
|
* of speed and duplex between two ends.
|
1361 |
|
|
*/
|
1362 |
|
|
|
1363 |
|
|
static void sis900_read_mode(struct net_device *net_dev, int *speed, int *duplex)
|
1364 |
|
|
{
|
1365 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1366 |
|
|
struct mii_phy *phy = sis_priv->mii;
|
1367 |
|
|
int phy_addr = sis_priv->cur_phy;
|
1368 |
|
|
u32 status;
|
1369 |
|
|
u16 autoadv, autorec;
|
1370 |
|
|
int i = 0;
|
1371 |
|
|
|
1372 |
|
|
while (i++ < 2)
|
1373 |
|
|
status = mdio_read(net_dev, phy_addr, MII_STATUS);
|
1374 |
|
|
|
1375 |
|
|
if (!(status & MII_STAT_LINK))
|
1376 |
|
|
return;
|
1377 |
|
|
|
1378 |
|
|
/* AutoNegotiate completed */
|
1379 |
|
|
autoadv = mdio_read(net_dev, phy_addr, MII_ANADV);
|
1380 |
|
|
autorec = mdio_read(net_dev, phy_addr, MII_ANLPAR);
|
1381 |
|
|
status = autoadv & autorec;
|
1382 |
|
|
|
1383 |
|
|
*speed = HW_SPEED_10_MBPS;
|
1384 |
|
|
*duplex = FDX_CAPABLE_HALF_SELECTED;
|
1385 |
|
|
|
1386 |
|
|
if (status & (MII_NWAY_TX | MII_NWAY_TX_FDX))
|
1387 |
|
|
*speed = HW_SPEED_100_MBPS;
|
1388 |
|
|
if (status & ( MII_NWAY_TX_FDX | MII_NWAY_T_FDX))
|
1389 |
|
|
*duplex = FDX_CAPABLE_FULL_SELECTED;
|
1390 |
|
|
|
1391 |
|
|
sis_priv->autong_complete = 1;
|
1392 |
|
|
|
1393 |
|
|
/* Workaround for Realtek RTL8201 PHY issue */
|
1394 |
|
|
if((phy->phy_id0 == 0x0000) && ((phy->phy_id1 & 0xFFF0) == 0x8200)){
|
1395 |
|
|
if(mdio_read(net_dev, phy_addr, MII_CONTROL) & MII_CNTL_FDX)
|
1396 |
|
|
*duplex = FDX_CAPABLE_FULL_SELECTED;
|
1397 |
|
|
if(mdio_read(net_dev, phy_addr, 0x0019) & 0x01)
|
1398 |
|
|
*speed = HW_SPEED_100_MBPS;
|
1399 |
|
|
}
|
1400 |
|
|
|
1401 |
|
|
printk(KERN_INFO "%s: Media Link On %s %s-duplex \n",
|
1402 |
|
|
net_dev->name,
|
1403 |
|
|
*speed == HW_SPEED_100_MBPS ?
|
1404 |
|
|
"100mbps" : "10mbps",
|
1405 |
|
|
*duplex == FDX_CAPABLE_FULL_SELECTED ?
|
1406 |
|
|
"full" : "half");
|
1407 |
|
|
}
|
1408 |
|
|
|
1409 |
|
|
/**
|
1410 |
|
|
* sis900_tx_timeout - sis900 transmit timeout routine
|
1411 |
|
|
* @net_dev: the net device to transmit
|
1412 |
|
|
*
|
1413 |
|
|
* print transmit timeout status
|
1414 |
|
|
* disable interrupts and do some tasks
|
1415 |
|
|
*/
|
1416 |
|
|
|
1417 |
|
|
static void sis900_tx_timeout(struct net_device *net_dev)
|
1418 |
|
|
{
|
1419 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1420 |
|
|
long ioaddr = net_dev->base_addr;
|
1421 |
|
|
unsigned long flags;
|
1422 |
|
|
int i;
|
1423 |
|
|
|
1424 |
|
|
printk(KERN_INFO "%s: Transmit timeout, status %8.8x %8.8x \n",
|
1425 |
|
|
net_dev->name, inl(ioaddr + cr), inl(ioaddr + isr));
|
1426 |
|
|
|
1427 |
|
|
/* Disable interrupts by clearing the interrupt mask. */
|
1428 |
|
|
outl(0x0000, ioaddr + imr);
|
1429 |
|
|
|
1430 |
|
|
/* use spinlock to prevent interrupt handler accessing buffer ring */
|
1431 |
|
|
spin_lock_irqsave(&sis_priv->lock, flags);
|
1432 |
|
|
|
1433 |
|
|
/* discard unsent packets */
|
1434 |
|
|
sis_priv->dirty_tx = sis_priv->cur_tx = 0;
|
1435 |
|
|
for (i = 0; i < NUM_TX_DESC; i++) {
|
1436 |
|
|
struct sk_buff *skb = sis_priv->tx_skbuff[i];
|
1437 |
|
|
|
1438 |
|
|
if (skb) {
|
1439 |
|
|
pci_unmap_single(sis_priv->pci_dev,
|
1440 |
|
|
sis_priv->tx_ring[i].bufptr, skb->len,
|
1441 |
|
|
PCI_DMA_TODEVICE);
|
1442 |
|
|
dev_kfree_skb_irq(skb);
|
1443 |
|
|
sis_priv->tx_skbuff[i] = 0;
|
1444 |
|
|
sis_priv->tx_ring[i].cmdsts = 0;
|
1445 |
|
|
sis_priv->tx_ring[i].bufptr = 0;
|
1446 |
|
|
sis_priv->stats.tx_dropped++;
|
1447 |
|
|
}
|
1448 |
|
|
}
|
1449 |
|
|
sis_priv->tx_full = 0;
|
1450 |
|
|
netif_wake_queue(net_dev);
|
1451 |
|
|
|
1452 |
|
|
spin_unlock_irqrestore(&sis_priv->lock, flags);
|
1453 |
|
|
|
1454 |
|
|
net_dev->trans_start = jiffies;
|
1455 |
|
|
|
1456 |
|
|
/* load Transmit Descriptor Register */
|
1457 |
|
|
outl(sis_priv->tx_ring_dma, ioaddr + txdp);
|
1458 |
|
|
|
1459 |
|
|
/* Enable all known interrupts by setting the interrupt mask. */
|
1460 |
|
|
outl((RxSOVR|RxORN|RxERR|RxOK|TxURN|TxERR|TxIDLE), ioaddr + imr);
|
1461 |
|
|
return;
|
1462 |
|
|
}
|
1463 |
|
|
|
1464 |
|
|
/**
|
1465 |
|
|
* sis900_start_xmit - sis900 start transmit routine
|
1466 |
|
|
* @skb: socket buffer pointer to put the data being transmitted
|
1467 |
|
|
* @net_dev: the net device to transmit with
|
1468 |
|
|
*
|
1469 |
|
|
* Set the transmit buffer descriptor,
|
1470 |
|
|
* and write TxENA to enable transimt state machine.
|
1471 |
|
|
* tell upper layer if the buffer is full
|
1472 |
|
|
*/
|
1473 |
|
|
|
1474 |
|
|
static int
|
1475 |
|
|
sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
|
1476 |
|
|
{
|
1477 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1478 |
|
|
long ioaddr = net_dev->base_addr;
|
1479 |
|
|
unsigned int entry;
|
1480 |
|
|
unsigned long flags;
|
1481 |
|
|
unsigned int index_cur_tx, index_dirty_tx;
|
1482 |
|
|
unsigned int count_dirty_tx;
|
1483 |
|
|
|
1484 |
|
|
/* Don't transmit data before the complete of auto-negotiation */
|
1485 |
|
|
if(!sis_priv->autong_complete){
|
1486 |
|
|
netif_stop_queue(net_dev);
|
1487 |
|
|
return 1;
|
1488 |
|
|
}
|
1489 |
|
|
|
1490 |
|
|
spin_lock_irqsave(&sis_priv->lock, flags);
|
1491 |
|
|
|
1492 |
|
|
/* Calculate the next Tx descriptor entry. */
|
1493 |
|
|
entry = sis_priv->cur_tx % NUM_TX_DESC;
|
1494 |
|
|
sis_priv->tx_skbuff[entry] = skb;
|
1495 |
|
|
|
1496 |
|
|
/* set the transmit buffer descriptor and enable Transmit State Machine */
|
1497 |
|
|
sis_priv->tx_ring[entry].bufptr = pci_map_single(sis_priv->pci_dev,
|
1498 |
|
|
skb->data, skb->len, PCI_DMA_TODEVICE);
|
1499 |
|
|
sis_priv->tx_ring[entry].cmdsts = (OWN | skb->len);
|
1500 |
|
|
outl(TxENA | inl(ioaddr + cr), ioaddr + cr);
|
1501 |
|
|
|
1502 |
|
|
sis_priv->cur_tx ++;
|
1503 |
|
|
index_cur_tx = sis_priv->cur_tx;
|
1504 |
|
|
index_dirty_tx = sis_priv->dirty_tx;
|
1505 |
|
|
|
1506 |
|
|
for (count_dirty_tx = 0; index_cur_tx != index_dirty_tx; index_dirty_tx++)
|
1507 |
|
|
count_dirty_tx ++;
|
1508 |
|
|
|
1509 |
|
|
if (index_cur_tx == index_dirty_tx) {
|
1510 |
|
|
/* dirty_tx is met in the cycle of cur_tx, buffer full */
|
1511 |
|
|
sis_priv->tx_full = 1;
|
1512 |
|
|
netif_stop_queue(net_dev);
|
1513 |
|
|
} else if (count_dirty_tx < NUM_TX_DESC) {
|
1514 |
|
|
/* Typical path, tell upper layer that more transmission is possible */
|
1515 |
|
|
netif_start_queue(net_dev);
|
1516 |
|
|
} else {
|
1517 |
|
|
/* buffer full, tell upper layer no more transmission */
|
1518 |
|
|
sis_priv->tx_full = 1;
|
1519 |
|
|
netif_stop_queue(net_dev);
|
1520 |
|
|
}
|
1521 |
|
|
|
1522 |
|
|
spin_unlock_irqrestore(&sis_priv->lock, flags);
|
1523 |
|
|
|
1524 |
|
|
net_dev->trans_start = jiffies;
|
1525 |
|
|
|
1526 |
|
|
if (sis900_debug > 3)
|
1527 |
|
|
printk(KERN_INFO "%s: Queued Tx packet at %p size %d "
|
1528 |
|
|
"to slot %d.\n",
|
1529 |
|
|
net_dev->name, skb->data, (int)skb->len, entry);
|
1530 |
|
|
|
1531 |
|
|
return 0;
|
1532 |
|
|
}
|
1533 |
|
|
|
1534 |
|
|
/**
|
1535 |
|
|
* sis900_interrupt - sis900 interrupt handler
|
1536 |
|
|
* @irq: the irq number
|
1537 |
|
|
* @dev_instance: the client data object
|
1538 |
|
|
* @regs: snapshot of processor context
|
1539 |
|
|
*
|
1540 |
|
|
* The interrupt handler does all of the Rx thread work,
|
1541 |
|
|
* and cleans up after the Tx thread
|
1542 |
|
|
*/
|
1543 |
|
|
|
1544 |
|
|
static irqreturn_t sis900_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
|
1545 |
|
|
{
|
1546 |
|
|
struct net_device *net_dev = dev_instance;
|
1547 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1548 |
|
|
int boguscnt = max_interrupt_work;
|
1549 |
|
|
long ioaddr = net_dev->base_addr;
|
1550 |
|
|
u32 status;
|
1551 |
|
|
unsigned int handled = 0;
|
1552 |
|
|
|
1553 |
|
|
spin_lock (&sis_priv->lock);
|
1554 |
|
|
|
1555 |
|
|
do {
|
1556 |
|
|
status = inl(ioaddr + isr);
|
1557 |
|
|
|
1558 |
|
|
if ((status & (HIBERR|TxURN|TxERR|TxIDLE|RxORN|RxERR|RxOK)) == 0)
|
1559 |
|
|
/* nothing intresting happened */
|
1560 |
|
|
break;
|
1561 |
|
|
handled = 1;
|
1562 |
|
|
|
1563 |
|
|
/* why dow't we break after Tx/Rx case ?? keyword: full-duplex */
|
1564 |
|
|
if (status & (RxORN | RxERR | RxOK))
|
1565 |
|
|
/* Rx interrupt */
|
1566 |
|
|
sis900_rx(net_dev);
|
1567 |
|
|
|
1568 |
|
|
if (status & (TxURN | TxERR | TxIDLE))
|
1569 |
|
|
/* Tx interrupt */
|
1570 |
|
|
sis900_finish_xmit(net_dev);
|
1571 |
|
|
|
1572 |
|
|
/* something strange happened !!! */
|
1573 |
|
|
if (status & HIBERR) {
|
1574 |
|
|
printk(KERN_INFO "%s: Abnormal interrupt,"
|
1575 |
|
|
"status %#8.8x.\n", net_dev->name, status);
|
1576 |
|
|
break;
|
1577 |
|
|
}
|
1578 |
|
|
if (--boguscnt < 0) {
|
1579 |
|
|
printk(KERN_INFO "%s: Too much work at interrupt, "
|
1580 |
|
|
"interrupt status = %#8.8x.\n",
|
1581 |
|
|
net_dev->name, status);
|
1582 |
|
|
break;
|
1583 |
|
|
}
|
1584 |
|
|
} while (1);
|
1585 |
|
|
|
1586 |
|
|
if (sis900_debug > 3)
|
1587 |
|
|
printk(KERN_INFO "%s: exiting interrupt, "
|
1588 |
|
|
"interrupt status = 0x%#8.8x.\n",
|
1589 |
|
|
net_dev->name, inl(ioaddr + isr));
|
1590 |
|
|
|
1591 |
|
|
spin_unlock (&sis_priv->lock);
|
1592 |
|
|
return IRQ_RETVAL(handled);
|
1593 |
|
|
}
|
1594 |
|
|
|
1595 |
|
|
/**
|
1596 |
|
|
* sis900_rx - sis900 receive routine
|
1597 |
|
|
* @net_dev: the net device which receives data
|
1598 |
|
|
*
|
1599 |
|
|
* Process receive interrupt events,
|
1600 |
|
|
* put buffer to higher layer and refill buffer pool
|
1601 |
|
|
* Note: This fucntion is called by interrupt handler,
|
1602 |
|
|
* don't do "too much" work here
|
1603 |
|
|
*/
|
1604 |
|
|
|
1605 |
|
|
static int sis900_rx(struct net_device *net_dev)
|
1606 |
|
|
{
|
1607 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1608 |
|
|
long ioaddr = net_dev->base_addr;
|
1609 |
|
|
unsigned int entry = sis_priv->cur_rx % NUM_RX_DESC;
|
1610 |
|
|
u32 rx_status = sis_priv->rx_ring[entry].cmdsts;
|
1611 |
|
|
|
1612 |
|
|
if (sis900_debug > 3)
|
1613 |
|
|
printk(KERN_INFO "sis900_rx, cur_rx:%4.4d, dirty_rx:%4.4d "
|
1614 |
|
|
"status:0x%8.8x\n",
|
1615 |
|
|
sis_priv->cur_rx, sis_priv->dirty_rx, rx_status);
|
1616 |
|
|
|
1617 |
|
|
while (rx_status & OWN) {
|
1618 |
|
|
unsigned int rx_size;
|
1619 |
|
|
|
1620 |
|
|
rx_size = (rx_status & DSIZE) - CRC_SIZE;
|
1621 |
|
|
|
1622 |
|
|
if (rx_status & (ABORT|OVERRUN|TOOLONG|RUNT|RXISERR|CRCERR|FAERR)) {
|
1623 |
|
|
/* corrupted packet received */
|
1624 |
|
|
if (sis900_debug > 3)
|
1625 |
|
|
printk(KERN_INFO "%s: Corrupted packet "
|
1626 |
|
|
"received, buffer status = 0x%8.8x.\n",
|
1627 |
|
|
net_dev->name, rx_status);
|
1628 |
|
|
sis_priv->stats.rx_errors++;
|
1629 |
|
|
if (rx_status & OVERRUN)
|
1630 |
|
|
sis_priv->stats.rx_over_errors++;
|
1631 |
|
|
if (rx_status & (TOOLONG|RUNT))
|
1632 |
|
|
sis_priv->stats.rx_length_errors++;
|
1633 |
|
|
if (rx_status & (RXISERR | FAERR))
|
1634 |
|
|
sis_priv->stats.rx_frame_errors++;
|
1635 |
|
|
if (rx_status & CRCERR)
|
1636 |
|
|
sis_priv->stats.rx_crc_errors++;
|
1637 |
|
|
/* reset buffer descriptor state */
|
1638 |
|
|
sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
|
1639 |
|
|
} else {
|
1640 |
|
|
struct sk_buff * skb;
|
1641 |
|
|
|
1642 |
|
|
/* This situation should never happen, but due to
|
1643 |
|
|
some unknow bugs, it is possible that
|
1644 |
|
|
we are working on NULL sk_buff :-( */
|
1645 |
|
|
if (sis_priv->rx_skbuff[entry] == NULL) {
|
1646 |
|
|
printk(KERN_INFO "%s: NULL pointer "
|
1647 |
|
|
"encountered in Rx ring, skipping\n",
|
1648 |
|
|
net_dev->name);
|
1649 |
|
|
break;
|
1650 |
|
|
}
|
1651 |
|
|
|
1652 |
|
|
pci_dma_sync_single(sis_priv->pci_dev,
|
1653 |
|
|
sis_priv->rx_ring[entry].bufptr, RX_BUF_SIZE,
|
1654 |
|
|
PCI_DMA_FROMDEVICE);
|
1655 |
|
|
pci_unmap_single(sis_priv->pci_dev,
|
1656 |
|
|
sis_priv->rx_ring[entry].bufptr, RX_BUF_SIZE,
|
1657 |
|
|
PCI_DMA_FROMDEVICE);
|
1658 |
|
|
/* give the socket buffer to upper layers */
|
1659 |
|
|
skb = sis_priv->rx_skbuff[entry];
|
1660 |
|
|
skb_put(skb, rx_size);
|
1661 |
|
|
skb->protocol = eth_type_trans(skb, net_dev);
|
1662 |
|
|
netif_rx(skb);
|
1663 |
|
|
|
1664 |
|
|
/* some network statistics */
|
1665 |
|
|
if ((rx_status & BCAST) == MCAST)
|
1666 |
|
|
sis_priv->stats.multicast++;
|
1667 |
|
|
net_dev->last_rx = jiffies;
|
1668 |
|
|
sis_priv->stats.rx_bytes += rx_size;
|
1669 |
|
|
sis_priv->stats.rx_packets++;
|
1670 |
|
|
|
1671 |
|
|
/* refill the Rx buffer, what if there is not enought memory for
|
1672 |
|
|
new socket buffer ?? */
|
1673 |
|
|
if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
|
1674 |
|
|
/* not enough memory for skbuff, this makes a "hole"
|
1675 |
|
|
on the buffer ring, it is not clear how the
|
1676 |
|
|
hardware will react to this kind of degenerated
|
1677 |
|
|
buffer */
|
1678 |
|
|
printk(KERN_INFO "%s: Memory squeeze,"
|
1679 |
|
|
"deferring packet.\n",
|
1680 |
|
|
net_dev->name);
|
1681 |
|
|
sis_priv->rx_skbuff[entry] = NULL;
|
1682 |
|
|
/* reset buffer descriptor state */
|
1683 |
|
|
sis_priv->rx_ring[entry].cmdsts = 0;
|
1684 |
|
|
sis_priv->rx_ring[entry].bufptr = 0;
|
1685 |
|
|
sis_priv->stats.rx_dropped++;
|
1686 |
|
|
break;
|
1687 |
|
|
}
|
1688 |
|
|
skb->dev = net_dev;
|
1689 |
|
|
sis_priv->rx_skbuff[entry] = skb;
|
1690 |
|
|
sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
|
1691 |
|
|
sis_priv->rx_ring[entry].bufptr =
|
1692 |
|
|
pci_map_single(sis_priv->pci_dev, skb->tail,
|
1693 |
|
|
RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
|
1694 |
|
|
sis_priv->dirty_rx++;
|
1695 |
|
|
}
|
1696 |
|
|
sis_priv->cur_rx++;
|
1697 |
|
|
entry = sis_priv->cur_rx % NUM_RX_DESC;
|
1698 |
|
|
rx_status = sis_priv->rx_ring[entry].cmdsts;
|
1699 |
|
|
} // while
|
1700 |
|
|
|
1701 |
|
|
/* refill the Rx buffer, what if the rate of refilling is slower than
|
1702 |
|
|
consuming ?? */
|
1703 |
|
|
for (;sis_priv->cur_rx - sis_priv->dirty_rx > 0; sis_priv->dirty_rx++) {
|
1704 |
|
|
struct sk_buff *skb;
|
1705 |
|
|
|
1706 |
|
|
entry = sis_priv->dirty_rx % NUM_RX_DESC;
|
1707 |
|
|
|
1708 |
|
|
if (sis_priv->rx_skbuff[entry] == NULL) {
|
1709 |
|
|
if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
|
1710 |
|
|
/* not enough memory for skbuff, this makes a "hole"
|
1711 |
|
|
on the buffer ring, it is not clear how the
|
1712 |
|
|
hardware will react to this kind of degenerated
|
1713 |
|
|
buffer */
|
1714 |
|
|
printk(KERN_INFO "%s: Memory squeeze,"
|
1715 |
|
|
"deferring packet.\n",
|
1716 |
|
|
net_dev->name);
|
1717 |
|
|
sis_priv->stats.rx_dropped++;
|
1718 |
|
|
break;
|
1719 |
|
|
}
|
1720 |
|
|
skb->dev = net_dev;
|
1721 |
|
|
sis_priv->rx_skbuff[entry] = skb;
|
1722 |
|
|
sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
|
1723 |
|
|
sis_priv->rx_ring[entry].bufptr =
|
1724 |
|
|
pci_map_single(sis_priv->pci_dev, skb->tail,
|
1725 |
|
|
RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
|
1726 |
|
|
}
|
1727 |
|
|
}
|
1728 |
|
|
/* re-enable the potentially idle receive state matchine */
|
1729 |
|
|
outl(RxENA | inl(ioaddr + cr), ioaddr + cr );
|
1730 |
|
|
|
1731 |
|
|
return 0;
|
1732 |
|
|
}
|
1733 |
|
|
|
1734 |
|
|
/**
|
1735 |
|
|
* sis900_finish_xmit - finish up transmission of packets
|
1736 |
|
|
* @net_dev: the net device to be transmitted on
|
1737 |
|
|
*
|
1738 |
|
|
* Check for error condition and free socket buffer etc
|
1739 |
|
|
* schedule for more transmission as needed
|
1740 |
|
|
* Note: This fucntion is called by interrupt handler,
|
1741 |
|
|
* don't do "too much" work here
|
1742 |
|
|
*/
|
1743 |
|
|
|
1744 |
|
|
static void sis900_finish_xmit (struct net_device *net_dev)
|
1745 |
|
|
{
|
1746 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1747 |
|
|
|
1748 |
|
|
for (; sis_priv->dirty_tx != sis_priv->cur_tx; sis_priv->dirty_tx++) {
|
1749 |
|
|
struct sk_buff *skb;
|
1750 |
|
|
unsigned int entry;
|
1751 |
|
|
u32 tx_status;
|
1752 |
|
|
|
1753 |
|
|
entry = sis_priv->dirty_tx % NUM_TX_DESC;
|
1754 |
|
|
tx_status = sis_priv->tx_ring[entry].cmdsts;
|
1755 |
|
|
|
1756 |
|
|
if (tx_status & OWN) {
|
1757 |
|
|
/* The packet is not transmitted yet (owned by hardware) !
|
1758 |
|
|
Note: the interrupt is generated only when Tx Machine
|
1759 |
|
|
is idle, so this is an almost impossible case */
|
1760 |
|
|
break;
|
1761 |
|
|
}
|
1762 |
|
|
|
1763 |
|
|
if (tx_status & (ABORT | UNDERRUN | OWCOLL)) {
|
1764 |
|
|
/* packet unsuccessfully transmitted */
|
1765 |
|
|
if (sis900_debug > 3)
|
1766 |
|
|
printk(KERN_INFO "%s: Transmit "
|
1767 |
|
|
"error, Tx status %8.8x.\n",
|
1768 |
|
|
net_dev->name, tx_status);
|
1769 |
|
|
sis_priv->stats.tx_errors++;
|
1770 |
|
|
if (tx_status & UNDERRUN)
|
1771 |
|
|
sis_priv->stats.tx_fifo_errors++;
|
1772 |
|
|
if (tx_status & ABORT)
|
1773 |
|
|
sis_priv->stats.tx_aborted_errors++;
|
1774 |
|
|
if (tx_status & NOCARRIER)
|
1775 |
|
|
sis_priv->stats.tx_carrier_errors++;
|
1776 |
|
|
if (tx_status & OWCOLL)
|
1777 |
|
|
sis_priv->stats.tx_window_errors++;
|
1778 |
|
|
} else {
|
1779 |
|
|
/* packet successfully transmitted */
|
1780 |
|
|
sis_priv->stats.collisions += (tx_status & COLCNT) >> 16;
|
1781 |
|
|
sis_priv->stats.tx_bytes += tx_status & DSIZE;
|
1782 |
|
|
sis_priv->stats.tx_packets++;
|
1783 |
|
|
}
|
1784 |
|
|
/* Free the original skb. */
|
1785 |
|
|
skb = sis_priv->tx_skbuff[entry];
|
1786 |
|
|
pci_unmap_single(sis_priv->pci_dev,
|
1787 |
|
|
sis_priv->tx_ring[entry].bufptr, skb->len,
|
1788 |
|
|
PCI_DMA_TODEVICE);
|
1789 |
|
|
dev_kfree_skb_irq(skb);
|
1790 |
|
|
sis_priv->tx_skbuff[entry] = NULL;
|
1791 |
|
|
sis_priv->tx_ring[entry].bufptr = 0;
|
1792 |
|
|
sis_priv->tx_ring[entry].cmdsts = 0;
|
1793 |
|
|
}
|
1794 |
|
|
|
1795 |
|
|
if (sis_priv->tx_full && netif_queue_stopped(net_dev) &&
|
1796 |
|
|
sis_priv->cur_tx - sis_priv->dirty_tx < NUM_TX_DESC - 4) {
|
1797 |
|
|
/* The ring is no longer full, clear tx_full and schedule more transmission
|
1798 |
|
|
by netif_wake_queue(net_dev) */
|
1799 |
|
|
sis_priv->tx_full = 0;
|
1800 |
|
|
netif_wake_queue (net_dev);
|
1801 |
|
|
}
|
1802 |
|
|
}
|
1803 |
|
|
|
1804 |
|
|
/**
|
1805 |
|
|
* sis900_close - close sis900 device
|
1806 |
|
|
* @net_dev: the net device to be closed
|
1807 |
|
|
*
|
1808 |
|
|
* Disable interrupts, stop the Tx and Rx Status Machine
|
1809 |
|
|
* free Tx and RX socket buffer
|
1810 |
|
|
*/
|
1811 |
|
|
|
1812 |
|
|
static int
|
1813 |
|
|
sis900_close(struct net_device *net_dev)
|
1814 |
|
|
{
|
1815 |
|
|
long ioaddr = net_dev->base_addr;
|
1816 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1817 |
|
|
struct sk_buff *skb;
|
1818 |
|
|
int i;
|
1819 |
|
|
|
1820 |
|
|
netif_stop_queue(net_dev);
|
1821 |
|
|
|
1822 |
|
|
/* Disable interrupts by clearing the interrupt mask. */
|
1823 |
|
|
outl(0x0000, ioaddr + imr);
|
1824 |
|
|
outl(0x0000, ioaddr + ier);
|
1825 |
|
|
|
1826 |
|
|
/* Stop the chip's Tx and Rx Status Machine */
|
1827 |
|
|
outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
|
1828 |
|
|
|
1829 |
|
|
del_timer(&sis_priv->timer);
|
1830 |
|
|
|
1831 |
|
|
free_irq(net_dev->irq, net_dev);
|
1832 |
|
|
|
1833 |
|
|
/* Free Tx and RX skbuff */
|
1834 |
|
|
for (i = 0; i < NUM_RX_DESC; i++) {
|
1835 |
|
|
skb = sis_priv->rx_skbuff[i];
|
1836 |
|
|
if (skb) {
|
1837 |
|
|
pci_unmap_single(sis_priv->pci_dev,
|
1838 |
|
|
sis_priv->rx_ring[i].bufptr,
|
1839 |
|
|
RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
|
1840 |
|
|
dev_kfree_skb(skb);
|
1841 |
|
|
sis_priv->rx_skbuff[i] = 0;
|
1842 |
|
|
}
|
1843 |
|
|
}
|
1844 |
|
|
for (i = 0; i < NUM_TX_DESC; i++) {
|
1845 |
|
|
skb = sis_priv->tx_skbuff[i];
|
1846 |
|
|
if (skb) {
|
1847 |
|
|
pci_unmap_single(sis_priv->pci_dev,
|
1848 |
|
|
sis_priv->tx_ring[i].bufptr, skb->len,
|
1849 |
|
|
PCI_DMA_TODEVICE);
|
1850 |
|
|
dev_kfree_skb(skb);
|
1851 |
|
|
sis_priv->tx_skbuff[i] = 0;
|
1852 |
|
|
}
|
1853 |
|
|
}
|
1854 |
|
|
|
1855 |
|
|
/* Green! Put the chip in low-power mode. */
|
1856 |
|
|
|
1857 |
|
|
return 0;
|
1858 |
|
|
}
|
1859 |
|
|
|
1860 |
|
|
/**
|
1861 |
|
|
* sis900_get_drvinfo - Return information about driver
|
1862 |
|
|
* @net_dev: the net device to probe
|
1863 |
|
|
* @info: container for info returned
|
1864 |
|
|
*
|
1865 |
|
|
* Process ethtool command such as "ehtool -i" to show information
|
1866 |
|
|
*/
|
1867 |
|
|
|
1868 |
|
|
static void sis900_get_drvinfo(struct net_device *net_dev,
|
1869 |
|
|
struct ethtool_drvinfo *info)
|
1870 |
|
|
{
|
1871 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1872 |
|
|
|
1873 |
|
|
strcpy (info->driver, SIS900_MODULE_NAME);
|
1874 |
|
|
strcpy (info->version, SIS900_DRV_VERSION);
|
1875 |
|
|
strcpy (info->bus_info, pci_name(sis_priv->pci_dev));
|
1876 |
|
|
}
|
1877 |
|
|
|
1878 |
|
|
static struct ethtool_ops sis900_ethtool_ops = {
|
1879 |
|
|
.get_drvinfo = sis900_get_drvinfo,
|
1880 |
|
|
};
|
1881 |
|
|
|
1882 |
|
|
/**
|
1883 |
|
|
* mii_ioctl - process MII i/o control command
|
1884 |
|
|
* @net_dev: the net device to command for
|
1885 |
|
|
* @rq: parameter for command
|
1886 |
|
|
* @cmd: the i/o command
|
1887 |
|
|
*
|
1888 |
|
|
* Process MII command like read/write MII register
|
1889 |
|
|
*/
|
1890 |
|
|
|
1891 |
|
|
static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd)
|
1892 |
|
|
{
|
1893 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1894 |
|
|
struct mii_ioctl_data *data = (struct mii_ioctl_data *)&rq->ifr_data;
|
1895 |
|
|
|
1896 |
|
|
switch(cmd) {
|
1897 |
|
|
case SIOCGMIIPHY: /* Get address of MII PHY in use. */
|
1898 |
|
|
case SIOCDEVPRIVATE: /* for binary compat, remove in 2.5 */
|
1899 |
|
|
data->phy_id = sis_priv->mii->phy_addr;
|
1900 |
|
|
/* Fall Through */
|
1901 |
|
|
|
1902 |
|
|
case SIOCGMIIREG: /* Read MII PHY register. */
|
1903 |
|
|
case SIOCDEVPRIVATE+1: /* for binary compat, remove in 2.5 */
|
1904 |
|
|
data->val_out = mdio_read(net_dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
|
1905 |
|
|
return 0;
|
1906 |
|
|
|
1907 |
|
|
case SIOCSMIIREG: /* Write MII PHY register. */
|
1908 |
|
|
case SIOCDEVPRIVATE+2: /* for binary compat, remove in 2.5 */
|
1909 |
|
|
if (!capable(CAP_NET_ADMIN))
|
1910 |
|
|
return -EPERM;
|
1911 |
|
|
mdio_write(net_dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
|
1912 |
|
|
return 0;
|
1913 |
|
|
default:
|
1914 |
|
|
return -EOPNOTSUPP;
|
1915 |
|
|
}
|
1916 |
|
|
}
|
1917 |
|
|
|
1918 |
|
|
/**
|
1919 |
|
|
* sis900_get_stats - Get sis900 read/write statistics
|
1920 |
|
|
* @net_dev: the net device to get statistics for
|
1921 |
|
|
*
|
1922 |
|
|
* get tx/rx statistics for sis900
|
1923 |
|
|
*/
|
1924 |
|
|
|
1925 |
|
|
static struct net_device_stats *
|
1926 |
|
|
sis900_get_stats(struct net_device *net_dev)
|
1927 |
|
|
{
|
1928 |
|
|
struct sis900_private *sis_priv = net_dev->priv;
|
1929 |
|
|
|
1930 |
|
|
return &sis_priv->stats;
|
1931 |
|
|
}
|
1932 |
|
|
|
1933 |
|
|
/**
|
1934 |
|
|
* sis900_set_config - Set media type by net_device.set_config
|
1935 |
|
|
* @dev: the net device for media type change
|
1936 |
|
|
* @map: ifmap passed by ifconfig
|
1937 |
|
|
*
|
1938 |
|
|
* Set media type to 10baseT, 100baseT or 0(for auto) by ifconfig
|
1939 |
|
|
* we support only port changes. All other runtime configuration
|
1940 |
|
|
* changes will be ignored
|
1941 |
|
|
*/
|
1942 |
|
|
|
1943 |
|
|
static int sis900_set_config(struct net_device *dev, struct ifmap *map)
|
1944 |
|
|
{
|
1945 |
|
|
struct sis900_private *sis_priv = dev->priv;
|
1946 |
|
|
struct mii_phy *mii_phy = sis_priv->mii;
|
1947 |
|
|
|
1948 |
|
|
u16 status;
|
1949 |
|
|
|
1950 |
|
|
if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
|
1951 |
|
|
/* we switch on the ifmap->port field. I couldn't find anything
|
1952 |
|
|
like a definition or standard for the values of that field.
|
1953 |
|
|
I think the meaning of those values is device specific. But
|
1954 |
|
|
since I would like to change the media type via the ifconfig
|
1955 |
|
|
command I use the definition from linux/netdevice.h
|
1956 |
|
|
(which seems to be different from the ifport(pcmcia) definition)
|
1957 |
|
|
*/
|
1958 |
|
|
switch(map->port){
|
1959 |
|
|
case IF_PORT_UNKNOWN: /* use auto here */
|
1960 |
|
|
dev->if_port = map->port;
|
1961 |
|
|
/* we are going to change the media type, so the Link will
|
1962 |
|
|
be temporary down and we need to reflect that here. When
|
1963 |
|
|
the Link comes up again, it will be sensed by the sis_timer
|
1964 |
|
|
procedure, which also does all the rest for us */
|
1965 |
|
|
netif_carrier_off(dev);
|
1966 |
|
|
|
1967 |
|
|
/* read current state */
|
1968 |
|
|
status = mdio_read(dev, mii_phy->phy_addr, MII_CONTROL);
|
1969 |
|
|
|
1970 |
|
|
/* enable auto negotiation and reset the negotioation
|
1971 |
|
|
(I don't really know what the auto negatiotiation reset
|
1972 |
|
|
really means, but it sounds for me right to do one here)*/
|
1973 |
|
|
mdio_write(dev, mii_phy->phy_addr,
|
1974 |
|
|
MII_CONTROL, status | MII_CNTL_AUTO | MII_CNTL_RST_AUTO);
|
1975 |
|
|
|
1976 |
|
|
break;
|
1977 |
|
|
|
1978 |
|
|
case IF_PORT_10BASET: /* 10BaseT */
|
1979 |
|
|
dev->if_port = map->port;
|
1980 |
|
|
|
1981 |
|
|
/* we are going to change the media type, so the Link will
|
1982 |
|
|
be temporary down and we need to reflect that here. When
|
1983 |
|
|
the Link comes up again, it will be sensed by the sis_timer
|
1984 |
|
|
procedure, which also does all the rest for us */
|
1985 |
|
|
netif_carrier_off(dev);
|
1986 |
|
|
|
1987 |
|
|
/* set Speed to 10Mbps */
|
1988 |
|
|
/* read current state */
|
1989 |
|
|
status = mdio_read(dev, mii_phy->phy_addr, MII_CONTROL);
|
1990 |
|
|
|
1991 |
|
|
/* disable auto negotiation and force 10MBit mode*/
|
1992 |
|
|
mdio_write(dev, mii_phy->phy_addr,
|
1993 |
|
|
MII_CONTROL, status & ~(MII_CNTL_SPEED | MII_CNTL_AUTO));
|
1994 |
|
|
break;
|
1995 |
|
|
|
1996 |
|
|
case IF_PORT_100BASET: /* 100BaseT */
|
1997 |
|
|
case IF_PORT_100BASETX: /* 100BaseTx */
|
1998 |
|
|
dev->if_port = map->port;
|
1999 |
|
|
|
2000 |
|
|
/* we are going to change the media type, so the Link will
|
2001 |
|
|
be temporary down and we need to reflect that here. When
|
2002 |
|
|
the Link comes up again, it will be sensed by the sis_timer
|
2003 |
|
|
procedure, which also does all the rest for us */
|
2004 |
|
|
netif_carrier_off(dev);
|
2005 |
|
|
|
2006 |
|
|
/* set Speed to 100Mbps */
|
2007 |
|
|
/* disable auto negotiation and enable 100MBit Mode */
|
2008 |
|
|
status = mdio_read(dev, mii_phy->phy_addr, MII_CONTROL);
|
2009 |
|
|
mdio_write(dev, mii_phy->phy_addr,
|
2010 |
|
|
MII_CONTROL, (status & ~MII_CNTL_SPEED) | MII_CNTL_SPEED);
|
2011 |
|
|
|
2012 |
|
|
break;
|
2013 |
|
|
|
2014 |
|
|
case IF_PORT_10BASE2: /* 10Base2 */
|
2015 |
|
|
case IF_PORT_AUI: /* AUI */
|
2016 |
|
|
case IF_PORT_100BASEFX: /* 100BaseFx */
|
2017 |
|
|
/* These Modes are not supported (are they?)*/
|
2018 |
|
|
printk(KERN_INFO "Not supported");
|
2019 |
|
|
return -EOPNOTSUPP;
|
2020 |
|
|
break;
|
2021 |
|
|
|
2022 |
|
|
default:
|
2023 |
|
|
printk(KERN_INFO "Invalid");
|
2024 |
|
|
return -EINVAL;
|
2025 |
|
|
}
|
2026 |
|
|
}
|
2027 |
|
|
return 0;
|
2028 |
|
|
}
|
2029 |
|
|
|
2030 |
|
|
/**
|
2031 |
|
|
* sis900_mcast_bitnr - compute hashtable index
|
2032 |
|
|
* @addr: multicast address
|
2033 |
|
|
* @revision: revision id of chip
|
2034 |
|
|
*
|
2035 |
|
|
* SiS 900 uses the most sigificant 7 bits to index a 128 bits multicast
|
2036 |
|
|
* hash table, which makes this function a little bit different from other drivers
|
2037 |
|
|
* SiS 900 B0 & 635 M/B uses the most significat 8 bits to index 256 bits
|
2038 |
|
|
* multicast hash table.
|
2039 |
|
|
*/
|
2040 |
|
|
|
2041 |
|
|
static inline u16 sis900_mcast_bitnr(u8 *addr, u8 revision)
|
2042 |
|
|
{
|
2043 |
|
|
|
2044 |
|
|
u32 crc = ether_crc(6, addr);
|
2045 |
|
|
|
2046 |
|
|
/* leave 8 or 7 most siginifant bits */
|
2047 |
|
|
if ((revision >= SIS635A_900_REV) || (revision == SIS900B_900_REV))
|
2048 |
|
|
return ((int)(crc >> 24));
|
2049 |
|
|
else
|
2050 |
|
|
return ((int)(crc >> 25));
|
2051 |
|
|
}
|
2052 |
|
|
|
2053 |
|
|
/**
|
2054 |
|
|
* set_rx_mode - Set SiS900 receive mode
|
2055 |
|
|
* @net_dev: the net device to be set
|
2056 |
|
|
*
|
2057 |
|
|
* Set SiS900 receive mode for promiscuous, multicast, or broadcast mode.
|
2058 |
|
|
* And set the appropriate multicast filter.
|
2059 |
|
|
* Multicast hash table changes from 128 to 256 bits for 635M/B & 900B0.
|
2060 |
|
|
*/
|
2061 |
|
|
|
2062 |
|
|
static void set_rx_mode(struct net_device *net_dev)
|
2063 |
|
|
{
|
2064 |
|
|
long ioaddr = net_dev->base_addr;
|
2065 |
|
|
struct sis900_private * sis_priv = net_dev->priv;
|
2066 |
|
|
u16 mc_filter[16] = {0}; /* 256/128 bits multicast hash table */
|
2067 |
|
|
int i, table_entries;
|
2068 |
|
|
u32 rx_mode;
|
2069 |
|
|
u8 revision;
|
2070 |
|
|
|
2071 |
|
|
/* 635 Hash Table entires = 256(2^16) */
|
2072 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
2073 |
|
|
if((revision >= SIS635A_900_REV) || (revision == SIS900B_900_REV))
|
2074 |
|
|
table_entries = 16;
|
2075 |
|
|
else
|
2076 |
|
|
table_entries = 8;
|
2077 |
|
|
|
2078 |
|
|
if (net_dev->flags & IFF_PROMISC) {
|
2079 |
|
|
/* Accept any kinds of packets */
|
2080 |
|
|
rx_mode = RFPromiscuous;
|
2081 |
|
|
for (i = 0; i < table_entries; i++)
|
2082 |
|
|
mc_filter[i] = 0xffff;
|
2083 |
|
|
} else if ((net_dev->mc_count > multicast_filter_limit) ||
|
2084 |
|
|
(net_dev->flags & IFF_ALLMULTI)) {
|
2085 |
|
|
/* too many multicast addresses or accept all multicast packet */
|
2086 |
|
|
rx_mode = RFAAB | RFAAM;
|
2087 |
|
|
for (i = 0; i < table_entries; i++)
|
2088 |
|
|
mc_filter[i] = 0xffff;
|
2089 |
|
|
} else {
|
2090 |
|
|
/* Accept Broadcast packet, destination address matchs our MAC address,
|
2091 |
|
|
use Receive Filter to reject unwanted MCAST packet */
|
2092 |
|
|
struct dev_mc_list *mclist;
|
2093 |
|
|
rx_mode = RFAAB;
|
2094 |
|
|
for (i = 0, mclist = net_dev->mc_list; mclist && i < net_dev->mc_count;
|
2095 |
|
|
i++, mclist = mclist->next) {
|
2096 |
|
|
unsigned int bit_nr =
|
2097 |
|
|
sis900_mcast_bitnr(mclist->dmi_addr, revision);
|
2098 |
|
|
mc_filter[bit_nr >> 4] |= (1 << (bit_nr & 0xf));
|
2099 |
|
|
}
|
2100 |
|
|
}
|
2101 |
|
|
|
2102 |
|
|
/* update Multicast Hash Table in Receive Filter */
|
2103 |
|
|
for (i = 0; i < table_entries; i++) {
|
2104 |
|
|
/* why plus 0x04 ??, That makes the correct value for hash table. */
|
2105 |
|
|
outl((u32)(0x00000004+i) << RFADDR_shift, ioaddr + rfcr);
|
2106 |
|
|
outl(mc_filter[i], ioaddr + rfdr);
|
2107 |
|
|
}
|
2108 |
|
|
|
2109 |
|
|
outl(RFEN | rx_mode, ioaddr + rfcr);
|
2110 |
|
|
|
2111 |
|
|
/* sis900 is capatable of looping back packet at MAC level for debugging purpose */
|
2112 |
|
|
if (net_dev->flags & IFF_LOOPBACK) {
|
2113 |
|
|
u32 cr_saved;
|
2114 |
|
|
/* We must disable Tx/Rx before setting loopback mode */
|
2115 |
|
|
cr_saved = inl(ioaddr + cr);
|
2116 |
|
|
outl(cr_saved | TxDIS | RxDIS, ioaddr + cr);
|
2117 |
|
|
/* enable loopback */
|
2118 |
|
|
outl(inl(ioaddr + txcfg) | TxMLB, ioaddr + txcfg);
|
2119 |
|
|
outl(inl(ioaddr + rxcfg) | RxATX, ioaddr + rxcfg);
|
2120 |
|
|
/* restore cr */
|
2121 |
|
|
outl(cr_saved, ioaddr + cr);
|
2122 |
|
|
}
|
2123 |
|
|
|
2124 |
|
|
return;
|
2125 |
|
|
}
|
2126 |
|
|
|
2127 |
|
|
/**
|
2128 |
|
|
* sis900_reset - Reset sis900 MAC
|
2129 |
|
|
* @net_dev: the net device to reset
|
2130 |
|
|
*
|
2131 |
|
|
* reset sis900 MAC and wait until finished
|
2132 |
|
|
* reset through command register
|
2133 |
|
|
* change backoff algorithm for 900B0 & 635 M/B
|
2134 |
|
|
*/
|
2135 |
|
|
|
2136 |
|
|
static void sis900_reset(struct net_device *net_dev)
|
2137 |
|
|
{
|
2138 |
|
|
struct sis900_private * sis_priv = net_dev->priv;
|
2139 |
|
|
long ioaddr = net_dev->base_addr;
|
2140 |
|
|
int i = 0;
|
2141 |
|
|
u32 status = TxRCMP | RxRCMP;
|
2142 |
|
|
u8 revision;
|
2143 |
|
|
|
2144 |
|
|
outl(0, ioaddr + ier);
|
2145 |
|
|
outl(0, ioaddr + imr);
|
2146 |
|
|
outl(0, ioaddr + rfcr);
|
2147 |
|
|
|
2148 |
|
|
outl(RxRESET | TxRESET | RESET | inl(ioaddr + cr), ioaddr + cr);
|
2149 |
|
|
|
2150 |
|
|
/* Check that the chip has finished the reset. */
|
2151 |
|
|
while (status && (i++ < 1000)) {
|
2152 |
|
|
status ^= (inl(isr + ioaddr) & status);
|
2153 |
|
|
}
|
2154 |
|
|
|
2155 |
|
|
pci_read_config_byte(sis_priv->pci_dev, PCI_CLASS_REVISION, &revision);
|
2156 |
|
|
if( (revision >= SIS635A_900_REV) || (revision == SIS900B_900_REV) )
|
2157 |
|
|
outl(PESEL | RND_CNT, ioaddr + cfg);
|
2158 |
|
|
else
|
2159 |
|
|
outl(PESEL, ioaddr + cfg);
|
2160 |
|
|
}
|
2161 |
|
|
|
2162 |
|
|
/**
|
2163 |
|
|
* sis900_remove - Remove sis900 device
|
2164 |
|
|
* @pci_dev: the pci device to be removed
|
2165 |
|
|
*
|
2166 |
|
|
* remove and release SiS900 net device
|
2167 |
|
|
*/
|
2168 |
|
|
|
2169 |
|
|
static void __devexit sis900_remove(struct pci_dev *pci_dev)
|
2170 |
|
|
{
|
2171 |
|
|
struct net_device *net_dev = pci_get_drvdata(pci_dev);
|
2172 |
|
|
struct sis900_private * sis_priv = net_dev->priv;
|
2173 |
|
|
struct mii_phy *phy = NULL;
|
2174 |
|
|
|
2175 |
|
|
while (sis_priv->first_mii) {
|
2176 |
|
|
phy = sis_priv->first_mii;
|
2177 |
|
|
sis_priv->first_mii = phy->next;
|
2178 |
|
|
kfree(phy);
|
2179 |
|
|
}
|
2180 |
|
|
|
2181 |
|
|
pci_free_consistent(pci_dev, RX_TOTAL_SIZE, sis_priv->rx_ring,
|
2182 |
|
|
sis_priv->rx_ring_dma);
|
2183 |
|
|
pci_free_consistent(pci_dev, TX_TOTAL_SIZE, sis_priv->tx_ring,
|
2184 |
|
|
sis_priv->tx_ring_dma);
|
2185 |
|
|
unregister_netdev(net_dev);
|
2186 |
|
|
kfree(net_dev);
|
2187 |
|
|
pci_release_regions(pci_dev);
|
2188 |
|
|
pci_set_drvdata(pci_dev, NULL);
|
2189 |
|
|
}
|
2190 |
|
|
|
2191 |
|
|
static struct pci_driver sis900_pci_driver = {
|
2192 |
|
|
.name = SIS900_MODULE_NAME,
|
2193 |
|
|
.id_table = sis900_pci_tbl,
|
2194 |
|
|
.probe = sis900_probe,
|
2195 |
|
|
.remove = __devexit_p(sis900_remove),
|
2196 |
|
|
};
|
2197 |
|
|
|
2198 |
|
|
static int __init sis900_init_module(void)
|
2199 |
|
|
{
|
2200 |
|
|
/* when a module, this is printed whether or not devices are found in probe */
|
2201 |
|
|
#ifdef MODULE
|
2202 |
|
|
printk(version);
|
2203 |
|
|
#endif
|
2204 |
|
|
|
2205 |
|
|
return pci_module_init(&sis900_pci_driver);
|
2206 |
|
|
}
|
2207 |
|
|
|
2208 |
|
|
static void __exit sis900_cleanup_module(void)
|
2209 |
|
|
{
|
2210 |
|
|
pci_unregister_driver(&sis900_pci_driver);
|
2211 |
|
|
}
|
2212 |
|
|
|
2213 |
|
|
module_init(sis900_init_module);
|
2214 |
|
|
module_exit(sis900_cleanup_module);
|
2215 |
|
|
|