File: /usr/src/linux-2.4.7/drivers/net/3c515.c

1     /* 3c515.c: A 3Com ISA EtherLink XL "Corkscrew" ethernet driver for linux. */
2     /*
3     	Written 1997-1998 by Donald Becker.
4     
5     	This software may be used and distributed according to the terms
6     	of the GNU General Public License, incorporated herein by reference.
7     
8     	This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.
9     
10     	The author may be reached as becker@scyld.com, or C/O
11     	Scyld Computing Corporation
12     	410 Severn Ave., Suite 210
13     	Annapolis MD 21403
14     
15     
16     	2/2/00- Added support for kernel-level ISAPnP 
17     		by Stephen Frost <sfrost@snowman.net> and Alessandro Zummo
18     	Cleaned up for 2.3.x/softnet by Jeff Garzik and Alan Cox.
19     */
20     
21     static char *version = "3c515.c:v0.99-sn 2000/02/12 becker@cesdis.gsfc.nasa.gov and others\n";
22     
23     #define CORKSCREW 1
24     
25     /* "Knobs" that adjust features and parameters. */
26     /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
27        Setting to > 1512 effectively disables this feature. */
28     static const int rx_copybreak = 200;
29     
30     /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
31     static const int mtu = 1500;
32     
33     /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
34     static int max_interrupt_work = 20;
35     
36     /* Enable the automatic media selection code -- usually set. */
37     #define AUTOMEDIA 1
38     
39     /* Allow the use of fragment bus master transfers instead of only
40        programmed-I/O for Vortex cards.  Full-bus-master transfers are always
41        enabled by default on Boomerang cards.  If VORTEX_BUS_MASTER is defined,
42        the feature may be turned on using 'options'. */
43     #define VORTEX_BUS_MASTER
44     
45     /* A few values that may be tweaked. */
46     /* Keep the ring sizes a power of two for efficiency. */
47     #define TX_RING_SIZE	16
48     #define RX_RING_SIZE	16
49     #define PKT_BUF_SZ		1536	/* Size of each temporary Rx buffer. */
50     
51     #include <linux/config.h>
52     #include <linux/module.h>
53     #include <linux/version.h>
54     #include <linux/isapnp.h>
55     
56     #include <linux/kernel.h>
57     #include <linux/sched.h>
58     #include <linux/string.h>
59     #include <linux/ptrace.h>
60     #include <linux/errno.h>
61     #include <linux/in.h>
62     #include <linux/ioport.h>
63     #include <linux/slab.h>
64     #include <linux/interrupt.h>
65     #include <linux/timer.h>
66     #include <asm/bitops.h>
67     #include <asm/io.h>
68     #include <asm/dma.h>
69     
70     #include <linux/netdevice.h>
71     #include <linux/etherdevice.h>
72     #include <linux/skbuff.h>
73     
74     #define NEW_MULTICAST
75     #include <linux/delay.h>
76     
77     /* Kernel version compatibility functions. */
78     #define RUN_AT(x) (jiffies + (x))
79     
80     #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)
81     #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
82     
83     MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
84     MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
85     MODULE_PARM(debug, "i");
86     MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
87     MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
88     MODULE_PARM(rx_copybreak, "i");
89     MODULE_PARM(max_interrupt_work, "i");
90     MODULE_PARM_DESC(debug, "3c515 debug level (0-6)");
91     MODULE_PARM_DESC(options, "3c515: Bits 0-2: media type, bit 3: full duplex, bit 4: bus mastering");
92     MODULE_PARM_DESC(full_duplex, "(ignored)");
93     MODULE_PARM_DESC(rx_copybreak, "3c515 copy breakpoint for copy-only-tiny-frames");
94     MODULE_PARM_DESC(max_interrupt_work, "3c515 maximum events handled per interrupt");
95     
96     /* "Knobs" for adjusting internal parameters. */
97     /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
98     #define DRIVER_DEBUG 1
99     /* Some values here only for performance evaluation and path-coverage
100        debugging. */
101     static int rx_nocopy, rx_copy, queued_packet;
102     
103     /* Number of times to check to see if the Tx FIFO has space, used in some
104        limited cases. */
105     #define WAIT_TX_AVAIL 200
106     
107     /* Operational parameter that usually are not changed. */
108     #define TX_TIMEOUT  40		/* Time in jiffies before concluding Tx hung */
109     
110     /* The size here is somewhat misleading: the Corkscrew also uses the ISA
111        aliased registers at <base>+0x400.
112        */
113     #define CORKSCREW_TOTAL_SIZE 0x20
114     
115     #ifdef DRIVER_DEBUG
116     static int corkscrew_debug = DRIVER_DEBUG;
117     #else
118     static int corkscrew_debug = 1;
119     #endif
120     
121     #define CORKSCREW_ID 10
122     
123     /*
124     				Theory of Operation
125     
126     I. Board Compatibility
127     
128     This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
129     3Com's ISA bus adapter for Fast Ethernet.  Due to the unique I/O port layout,
130     it's not practical to integrate this driver with the other EtherLink drivers.
131     
132     II. Board-specific settings
133     
134     The Corkscrew has an EEPROM for configuration, but no special settings are
135     needed for Linux.
136     
137     III. Driver operation
138     
139     The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
140     PCI cards, with the bus master interface extensively modified to work with
141     the ISA bus.
142     
143     The card is capable of full-bus-master transfers with separate
144     lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
145     DEC Tulip and Intel Speedo3.
146     
147     This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
148     receive buffer.  This scheme allocates full-sized skbuffs as receive
149     buffers.  The value RX_COPYBREAK is used as the copying breakpoint: it is
150     chosen to trade-off the memory wasted by passing the full-sized skbuff to
151     the queue layer for all frames vs. the copying cost of copying a frame to a
152     correctly-sized skbuff.
153     
154     
155     IIIC. Synchronization
156     The driver runs as two independent, single-threaded flows of control.  One
157     is the send-packet routine, which enforces single-threaded use by the netif
158     layer.  The other thread is the interrupt handler, which is single
159     threaded by the hardware and other software.
160     
161     IV. Notes
162     
163     Thanks to Terry Murphy of 3Com for providing documentation and a development
164     board.
165     
166     The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
167     project names.  I use these names to eliminate confusion -- 3Com product
168     numbers and names are very similar and often confused.
169     
170     The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
171     This driver only supports ethernet frames because of the recent MTU limit
172     of 1.5K, but the changes to support 4.5K are minimal.
173     */
174     
175     /* Operational definitions.
176        These are not used by other compilation units and thus are not
177        exported in a ".h" file.
178     
179        First the windows.  There are eight register windows, with the command
180        and status registers available in each.
181        */
182     #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
183     #define EL3_CMD 0x0e
184     #define EL3_STATUS 0x0e
185     
186     /* The top five bits written to EL3_CMD are a command, the lower
187        11 bits are the parameter, if applicable.
188        Note that 11 parameters bits was fine for ethernet, but the new chips
189        can handle FDDI length frames (~4500 octets) and now parameters count
190        32-bit 'Dwords' rather than octets. */
191     
192     enum corkscrew_cmd {
193     	TotalReset = 0 << 11, SelectWindow = 1 << 11, StartCoax = 2 << 11,
194     	RxDisable = 3 << 11, RxEnable = 4 << 11, RxReset = 5 << 11,
195     	UpStall = 6 << 11, UpUnstall = (6 << 11) + 1,
196     	DownStall = (6 << 11) + 2, DownUnstall = (6 << 11) + 3,
197     	RxDiscard = 8 << 11, TxEnable = 9 << 11, TxDisable =
198     	    10 << 11, TxReset = 11 << 11,
199     	FakeIntr = 12 << 11, AckIntr = 13 << 11, SetIntrEnb = 14 << 11,
200     	SetStatusEnb = 15 << 11, SetRxFilter = 16 << 11, SetRxThreshold =
201     	    17 << 11,
202     	SetTxThreshold = 18 << 11, SetTxStart = 19 << 11,
203     	StartDMAUp = 20 << 11, StartDMADown = (20 << 11) + 1, StatsEnable =
204     	    21 << 11,
205     	StatsDisable = 22 << 11, StopCoax = 23 << 11,
206     };
207     
208     /* The SetRxFilter command accepts the following classes: */
209     enum RxFilter {
210     	RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8
211     };
212     
213     /* Bits in the general status register. */
214     enum corkscrew_status {
215     	IntLatch = 0x0001, AdapterFailure = 0x0002, TxComplete = 0x0004,
216     	TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
217     	IntReq = 0x0040, StatsFull = 0x0080,
218     	DMADone = 1 << 8, DownComplete = 1 << 9, UpComplete = 1 << 10,
219     	DMAInProgress = 1 << 11,	/* DMA controller is still busy. */
220     	CmdInProgress = 1 << 12,	/* EL3_CMD is still busy. */
221     };
222     
223     /* Register window 1 offsets, the window used in normal operation.
224        On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
225     enum Window1 {
226     	TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
227     	RxStatus = 0x18, Timer = 0x1A, TxStatus = 0x1B,
228     	TxFree = 0x1C,		/* Remaining free bytes in Tx buffer. */
229     };
230     enum Window0 {
231     	Wn0IRQ = 0x08,
232     #if defined(CORKSCREW)
233     	Wn0EepromCmd = 0x200A,	/* Corkscrew EEPROM command register. */
234     	Wn0EepromData = 0x200C,	/* Corkscrew EEPROM results register. */
235     #else
236     	Wn0EepromCmd = 10,	/* Window 0: EEPROM command register. */
237     	Wn0EepromData = 12,	/* Window 0: EEPROM results register. */
238     #endif
239     };
240     enum Win0_EEPROM_bits {
241     	EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
242     	EEPROM_EWENB = 0x30,	/* Enable erasing/writing for 10 msec. */
243     	EEPROM_EWDIS = 0x00,	/* Disable EWENB before 10 msec timeout. */
244     };
245     
246     /* EEPROM locations. */
247     enum eeprom_offset {
248     	PhysAddr01 = 0, PhysAddr23 = 1, PhysAddr45 = 2, ModelID = 3,
249     	EtherLink3ID = 7,
250     };
251     
252     enum Window3 {			/* Window 3: MAC/config bits. */
253     	Wn3_Config = 0, Wn3_MAC_Ctrl = 6, Wn3_Options = 8,
254     };
255     union wn3_config {
256     	int i;
257     	struct w3_config_fields {
258     		unsigned int ram_size:3, ram_width:1, ram_speed:2,
259     		    rom_size:2;
260     		int pad8:8;
261     		unsigned int ram_split:2, pad18:2, xcvr:3, pad21:1,
262     		    autoselect:1;
263     		int pad24:7;
264     	} u;
265     };
266     
267     enum Window4 {
268     	Wn4_NetDiag = 6, Wn4_Media = 10,	/* Window 4: Xcvr/media bits. */
269     };
270     enum Win4_Media_bits {
271     	Media_SQE = 0x0008,	/* Enable SQE error counting for AUI. */
272     	Media_10TP = 0x00C0,	/* Enable link beat and jabber for 10baseT. */
273     	Media_Lnk = 0x0080,	/* Enable just link beat for 100TX/100FX. */
274     	Media_LnkBeat = 0x0800,
275     };
276     enum Window7 {			/* Window 7: Bus Master control. */
277     	Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
278     };
279     
280     /* Boomerang-style bus master control registers.  Note ISA aliases! */
281     enum MasterCtrl {
282     	PktStatus = 0x400, DownListPtr = 0x404, FragAddr = 0x408, FragLen =
283     	    0x40c,
284     	TxFreeThreshold = 0x40f, UpPktStatus = 0x410, UpListPtr = 0x418,
285     };
286     
287     /* The Rx and Tx descriptor lists.
288        Caution Alpha hackers: these types are 32 bits!  Note also the 8 byte
289        alignment contraint on tx_ring[] and rx_ring[]. */
290     struct boom_rx_desc {
291     	u32 next;
292     	s32 status;
293     	u32 addr;
294     	s32 length;
295     };
296     
297     /* Values for the Rx status entry. */
298     enum rx_desc_status {
299     	RxDComplete = 0x00008000, RxDError = 0x4000,
300     	/* See boomerang_rx() for actual error bits */
301     };
302     
303     struct boom_tx_desc {
304     	u32 next;
305     	s32 status;
306     	u32 addr;
307     	s32 length;
308     };
309     
310     struct corkscrew_private {
311     	const char *product_name;
312     	struct net_device *next_module;
313     	/* The Rx and Tx rings are here to keep them quad-word-aligned. */
314     	struct boom_rx_desc rx_ring[RX_RING_SIZE];
315     	struct boom_tx_desc tx_ring[TX_RING_SIZE];
316     	/* The addresses of transmit- and receive-in-place skbuffs. */
317     	struct sk_buff *rx_skbuff[RX_RING_SIZE];
318     	struct sk_buff *tx_skbuff[TX_RING_SIZE];
319     	unsigned int cur_rx, cur_tx;	/* The next free ring entry */
320     	unsigned int dirty_rx, dirty_tx;/* The ring entries to be free()ed. */
321     	struct net_device_stats stats;
322     	struct sk_buff *tx_skb;	/* Packet being eaten by bus master ctrl.  */
323     	struct timer_list timer;	/* Media selection timer. */
324     	int capabilities	;	/* Adapter capabilities word. */
325     	int options;			/* User-settable misc. driver options. */
326     	int last_rx_packets;		/* For media autoselection. */
327     	unsigned int available_media:8,	/* From Wn3_Options */
328     		media_override:3,	/* Passed-in media type. */
329     		default_media:3,	/* Read from the EEPROM. */
330     		full_duplex:1, autoselect:1, bus_master:1,	/* Vortex can only do a fragment bus-m. */
331     		full_bus_master_tx:1, full_bus_master_rx:1,	/* Boomerang  */
332     		tx_full:1;
333     };
334     
335     /* The action to take with a media selection timer tick.
336        Note that we deviate from the 3Com order by checking 10base2 before AUI.
337      */
338     enum xcvr_types {
339     	XCVR_10baseT =
340     	    0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
341     	XCVR_100baseFx, XCVR_MII = 6, XCVR_Default = 8,
342     };
343     
344     static struct media_table {
345     	char *name;
346     	unsigned int media_bits:16,	/* Bits to set in Wn4_Media register. */
347     		mask:8,			/* The transceiver-present bit in Wn3_Config. */
348     		next:8;			/* The media type to try next. */
349     	short wait;			/* Time before we check media status. */
350     } media_tbl[] = {	
351     	{ "10baseT", Media_10TP, 0x08, XCVR_10base2, (14 * HZ) / 10 }, 
352     	{ "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1 * HZ) / 10}, 
353     	{ "undefined", 0, 0x80, XCVR_10baseT, 10000}, 
354     	{ "10base2", 0, 0x10, XCVR_AUI, (1 * HZ) / 10}, 
355     	{ "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14 * HZ) / 10}, 
356     	{ "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14 * HZ) / 10}, 
357     	{ "MII", 0, 0x40, XCVR_10baseT, 3 * HZ}, 
358     	{ "undefined", 0, 0x01, XCVR_10baseT, 10000}, 
359     	{ "Default", 0, 0xFF, XCVR_10baseT, 10000},
360     };
361     
362     #ifdef CONFIG_ISAPNP
363     static struct isapnp_device_id corkscrew_isapnp_adapters[] = {
364     	{	ISAPNP_ANY_ID, ISAPNP_ANY_ID,
365     		ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5051),
366     		(long) "3Com Fast EtherLink ISA" },
367     	{ }	/* terminate list */
368     };
369     
370     MODULE_DEVICE_TABLE(isapnp, corkscrew_isapnp_adapters);
371     
372     static int corkscrew_isapnp_phys_addr[3];
373     
374     static int nopnp;
375     #endif /* CONFIG_ISAPNP */
376     
377     static int corkscrew_scan(struct net_device *dev);
378     static struct net_device *corkscrew_found_device(struct net_device *dev,
379     						 int ioaddr, int irq,
380     						 int product_index,
381     						 int options);
382     static int corkscrew_probe1(struct net_device *dev);
383     static int corkscrew_open(struct net_device *dev);
384     static void corkscrew_timer(unsigned long arg);
385     static int corkscrew_start_xmit(struct sk_buff *skb,
386     				struct net_device *dev);
387     static int corkscrew_rx(struct net_device *dev);
388     static void corkscrew_timeout(struct net_device *dev);
389     static int boomerang_rx(struct net_device *dev);
390     static void corkscrew_interrupt(int irq, void *dev_id,
391     				    struct pt_regs *regs);
392     static int corkscrew_close(struct net_device *dev);
393     static void update_stats(int addr, struct net_device *dev);
394     static struct net_device_stats *corkscrew_get_stats(struct net_device *dev);
395     static void set_rx_mode(struct net_device *dev);
396     
397     
398     /* 
399        Unfortunately maximizing the shared code between the integrated and
400        module version of the driver results in a complicated set of initialization
401        procedures.
402        init_module() -- modules /  tc59x_init()  -- built-in
403     		The wrappers for corkscrew_scan()
404        corkscrew_scan()  		 The common routine that scans for PCI and EISA cards
405        corkscrew_found_device() Allocate a device structure when we find a card.
406     					Different versions exist for modules and built-in.
407        corkscrew_probe1()		Fill in the device structure -- this is separated
408     					so that the modules code can put it in dev->init.
409     */
410     /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
411     /* Note: this is the only limit on the number of cards supported!! */
412     static int options[8] = { -1, -1, -1, -1, -1, -1, -1, -1, };
413     
414     #ifdef MODULE
415     static int debug = -1;
416     /* A list of all installed Vortex devices, for removing the driver module. */
417     static struct net_device *root_corkscrew_dev;
418     
419     int init_module(void)
420     {
421     	int cards_found;
422     
423     	if (debug >= 0)
424     		corkscrew_debug = debug;
425     	if (corkscrew_debug)
426     		printk(version);
427     
428     	root_corkscrew_dev = NULL;
429     	cards_found = corkscrew_scan(NULL);
430     	return cards_found ? 0 : -ENODEV;
431     }
432     
433     #else
434     int tc515_probe(struct net_device *dev)
435     {
436     	int cards_found = 0;
437     
438     	SET_MODULE_OWNER(dev);
439     
440     	cards_found = corkscrew_scan(dev);
441     
442     	if (corkscrew_debug > 0 && cards_found)
443     		printk(version);
444     
445     	return cards_found ? 0 : -ENODEV;
446     }
447     #endif				/* not MODULE */
448     
449     static int corkscrew_scan(struct net_device *dev)
450     {
451     	int cards_found = 0;
452     	static int ioaddr;
453     #ifdef CONFIG_ISAPNP
454     	short i;
455     	static int pnp_cards;
456     #endif
457     
458     #ifdef CONFIG_ISAPNP
459     	if(nopnp == 1)
460     		goto no_pnp;
461     	for(i=0; corkscrew_isapnp_adapters[i].vendor != 0; i++) {
462     		struct pci_dev *idev = NULL;
463     		int irq;
464     		while((idev = isapnp_find_dev(NULL,
465     						corkscrew_isapnp_adapters[i].vendor,
466     						corkscrew_isapnp_adapters[i].function,
467     						idev))) {
468     
469     			if(idev->active) idev->deactivate(idev);
470     
471     			if(idev->prepare(idev)<0)
472     				continue;
473     			if (!(idev->resource[0].flags & IORESOURCE_IO))
474     				continue;
475     			if(idev->activate(idev)<0) {
476     				printk("isapnp configure failed (out of resources?)\n");
477     				return -ENOMEM;
478     			}
479     			if (!idev->resource[0].start || check_region(idev->resource[0].start,16))
480     				continue;
481     			ioaddr = idev->resource[0].start;
482     			irq = idev->irq_resource[0].start;
483     			if(corkscrew_debug)
484     				printk ("ISAPNP reports %s at i/o 0x%x, irq %d\n",
485     					(char*) corkscrew_isapnp_adapters[i].driver_data, ioaddr, irq);
486     					
487     			if ((inw(ioaddr + 0x2002) & 0x1f0) != (ioaddr & 0x1f0))
488     				continue;
489     			/* Verify by reading the device ID from the EEPROM. */
490     			{
491     				int timer;
492     				outw(EEPROM_Read + 7, ioaddr + Wn0EepromCmd);
493     				/* Pause for at least 162 us. for the read to take place. */
494     				for (timer = 4; timer >= 0; timer--) {
495     					udelay(162);
496     					if ((inw(ioaddr + Wn0EepromCmd) & 0x0200)
497     				    		== 0)
498     							break;
499     				}
500     				if (inw(ioaddr + Wn0EepromData) != 0x6d50)
501     					continue;
502     			}
503     			printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
504     		     		inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
505     			/* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
506     			corkscrew_isapnp_phys_addr[pnp_cards] = ioaddr;
507     			corkscrew_found_device(dev, ioaddr, irq, CORKSCREW_ID, dev
508     				       	&& dev->mem_start ? dev->
509     				       	mem_start : options[cards_found]);
510     			dev = 0;
511     			pnp_cards++;
512     			cards_found++;
513     		}
514     	}
515     no_pnp:
516     #endif /* CONFIG_ISAPNP */
517     
518     	/* Check all locations on the ISA bus -- evil! */
519     	for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x20) {
520     		int irq;
521     #ifdef CONFIG_ISAPNP
522     		/* Make sure this was not already picked up by isapnp */
523     		if(ioaddr == corkscrew_isapnp_phys_addr[0]) continue;
524     		if(ioaddr == corkscrew_isapnp_phys_addr[1]) continue;
525     		if(ioaddr == corkscrew_isapnp_phys_addr[2]) continue;
526     #endif /* CONFIG_ISAPNP */
527     		if (check_region(ioaddr, CORKSCREW_TOTAL_SIZE))
528     			continue;
529     		/* Check the resource configuration for a matching ioaddr. */
530     		if ((inw(ioaddr + 0x2002) & 0x1f0) != (ioaddr & 0x1f0))
531     			continue;
532     		/* Verify by reading the device ID from the EEPROM. */
533     		{
534     			int timer;
535     			outw(EEPROM_Read + 7, ioaddr + Wn0EepromCmd);
536     			/* Pause for at least 162 us. for the read to take place. */
537     			for (timer = 4; timer >= 0; timer--) {
538     				udelay(162);
539     				if ((inw(ioaddr + Wn0EepromCmd) & 0x0200)
540     				    == 0)
541     					break;
542     			}
543     			if (inw(ioaddr + Wn0EepromData) != 0x6d50)
544     				continue;
545     		}
546     		printk(KERN_INFO "3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
547     		     inl(ioaddr + 0x2002), inw(ioaddr + 0x2000));
548     		irq = inw(ioaddr + 0x2002) & 15;
549     		corkscrew_found_device(dev, ioaddr, irq, CORKSCREW_ID, dev
550     				       && dev->mem_start ? dev->
551     				       mem_start : options[cards_found]);
552     		dev = 0;
553     		cards_found++;
554     	}
555     	if (corkscrew_debug)
556     		printk(KERN_INFO "%d 3c515 cards found.\n", cards_found);
557     	return cards_found;
558     }
559     
560     static struct net_device *corkscrew_found_device(struct net_device *dev,
561     						 int ioaddr, int irq,
562     						 int product_index,
563     						 int options)
564     {
565     	struct corkscrew_private *vp;
566     
567     #ifdef MODULE
568     	/* Allocate and fill new device structure. */
569     	int dev_size = sizeof(struct net_device) +
570     	    sizeof(struct corkscrew_private) + 15;	/* Pad for alignment */
571     
572     	dev = (struct net_device *) kmalloc(dev_size, GFP_KERNEL);
573     	if (!dev)
574     		return NULL;
575     	memset(dev, 0, dev_size);
576     	/* Align the Rx and Tx ring entries.  */
577     	dev->priv =
578     	    (void *) (((long) dev + sizeof(struct net_device) + 15) & ~15);
579     	vp = (struct corkscrew_private *) dev->priv;
580     	dev->base_addr = ioaddr;
581     	dev->irq = irq;
582     	dev->dma =
583     	    (product_index == CORKSCREW_ID ? inw(ioaddr + 0x2000) & 7 : 0);
584     	dev->init = corkscrew_probe1;
585     	vp->product_name = "3c515";
586     	vp->options = options;
587     	if (options >= 0) {
588     		vp->media_override =
589     		    ((options & 7) == 2) ? 0 : options & 7;
590     		vp->full_duplex = (options & 8) ? 1 : 0;
591     		vp->bus_master = (options & 16) ? 1 : 0;
592     	} else {
593     		vp->media_override = 7;
594     		vp->full_duplex = 0;
595     		vp->bus_master = 0;
596     	}
597     	ether_setup(dev);
598     	vp->next_module = root_corkscrew_dev;
599     	root_corkscrew_dev = dev;
600     	SET_MODULE_OWNER(dev);
601     	if (register_netdev(dev) != 0) {
602     		kfree(dev);
603     		return NULL;
604     	}
605     #else				/* not a MODULE */
606     	/* Caution: quad-word alignment required for rings! */
607     	dev->priv =
608     	    kmalloc(sizeof(struct corkscrew_private), GFP_KERNEL);
609     	if (!dev->priv)
610     		return NULL;
611     	memset(dev->priv, 0, sizeof(struct corkscrew_private));
612     	dev = init_etherdev(dev, sizeof(struct corkscrew_private));
613     	dev->base_addr = ioaddr;
614     	dev->irq = irq;
615     	dev->dma =
616     	    (product_index == CORKSCREW_ID ? inw(ioaddr + 0x2000) & 7 : 0);
617     	vp = (struct corkscrew_private *) dev->priv;
618     	vp->product_name = "3c515";
619     	vp->options = options;
620     	if (options >= 0) {
621     		vp->media_override =
622     		    ((options & 7) == 2) ? 0 : options & 7;
623     		vp->full_duplex = (options & 8) ? 1 : 0;
624     		vp->bus_master = (options & 16) ? 1 : 0;
625     	} else {
626     		vp->media_override = 7;
627     		vp->full_duplex = 0;
628     		vp->bus_master = 0;
629     	}
630     
631     	corkscrew_probe1(dev);
632     #endif				/* MODULE */
633     	return dev;
634     }
635     
636     static int corkscrew_probe1(struct net_device *dev)
637     {
638     	int ioaddr = dev->base_addr;
639     	struct corkscrew_private *vp =
640     	    (struct corkscrew_private *) dev->priv;
641     	unsigned int eeprom[0x40], checksum = 0;	/* EEPROM contents */
642     	int i;
643     
644     	printk(KERN_INFO "%s: 3Com %s at %#3x,", dev->name,
645     	       vp->product_name, ioaddr);
646     
647     	/* Read the station address from the EEPROM. */
648     	EL3WINDOW(0);
649     	for (i = 0; i < 0x18; i++) {
650     		short *phys_addr = (short *) dev->dev_addr;
651     		int timer;
652     		outw(EEPROM_Read + i, ioaddr + Wn0EepromCmd);
653     		/* Pause for at least 162 us. for the read to take place. */
654     		for (timer = 4; timer >= 0; timer--) {
655     			udelay(162);
656     			if ((inw(ioaddr + Wn0EepromCmd) & 0x0200) == 0)
657     				break;
658     		}
659     		eeprom[i] = inw(ioaddr + Wn0EepromData);
660     		checksum ^= eeprom[i];
661     		if (i < 3)
662     			phys_addr[i] = htons(eeprom[i]);
663     	}
664     	checksum = (checksum ^ (checksum >> 8)) & 0xff;
665     	if (checksum != 0x00)
666     		printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
667     	for (i = 0; i < 6; i++)
668     		printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
669     	if (eeprom[16] == 0x11c7) {	/* Corkscrew */
670     		if (request_dma(dev->dma, "3c515")) {
671     			printk(", DMA %d allocation failed", dev->dma);
672     			dev->dma = 0;
673     		} else
674     			printk(", DMA %d", dev->dma);
675     	}
676     	printk(", IRQ %d\n", dev->irq);
677     	/* Tell them about an invalid IRQ. */
678     	if (corkscrew_debug && (dev->irq <= 0 || dev->irq > 15))
679     		printk(KERN_WARNING " *** Warning: this IRQ is unlikely to work! ***\n");
680     
681     	{
682     		char *ram_split[] = { "5:3", "3:1", "1:1", "3:5" };
683     		union wn3_config config;
684     		EL3WINDOW(3);
685     		vp->available_media = inw(ioaddr + Wn3_Options);
686     		config.i = inl(ioaddr + Wn3_Config);
687     		if (corkscrew_debug > 1)
688     			printk(KERN_INFO "  Internal config register is %4.4x, transceivers %#x.\n",
689     				config.i, inw(ioaddr + Wn3_Options));
690     		printk(KERN_INFO "  %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
691     			8 << config.u.ram_size,
692     			config.u.ram_width ? "word" : "byte",
693     			ram_split[config.u.ram_split],
694     			config.u.autoselect ? "autoselect/" : "",
695     			media_tbl[config.u.xcvr].name);
696     		dev->if_port = config.u.xcvr;
697     		vp->default_media = config.u.xcvr;
698     		vp->autoselect = config.u.autoselect;
699     	}
700     	if (vp->media_override != 7) {
701     		printk(KERN_INFO "  Media override to transceiver type %d (%s).\n",
702     		       vp->media_override,
703     		       media_tbl[vp->media_override].name);
704     		dev->if_port = vp->media_override;
705     	}
706     
707     	vp->capabilities = eeprom[16];
708     	vp->full_bus_master_tx = (vp->capabilities & 0x20) ? 1 : 0;
709     	/* Rx is broken at 10mbps, so we always disable it. */
710     	/* vp->full_bus_master_rx = 0; */
711     	vp->full_bus_master_rx = (vp->capabilities & 0x20) ? 1 : 0;
712     
713     	/* We do a request_region() to register /proc/ioports info. */
714     	request_region(ioaddr, CORKSCREW_TOTAL_SIZE, vp->product_name);
715     
716     	/* The 3c51x-specific entries in the device structure. */
717     	dev->open = &corkscrew_open;
718     	dev->hard_start_xmit = &corkscrew_start_xmit;
719     	dev->tx_timeout = &corkscrew_timeout;
720     	dev->watchdog_timeo = (400 * HZ) / 1000;
721     	dev->stop = &corkscrew_close;
722     	dev->get_stats = &corkscrew_get_stats;
723     	dev->set_multicast_list = &set_rx_mode;
724     
725     	return 0;
726     }
727     
728     
729     static int corkscrew_open(struct net_device *dev)
730     {
731     	int ioaddr = dev->base_addr;
732     	struct corkscrew_private *vp =
733     	    (struct corkscrew_private *) dev->priv;
734     	union wn3_config config;
735     	int i;
736     
737     	/* Before initializing select the active media port. */
738     	EL3WINDOW(3);
739     	if (vp->full_duplex)
740     		outb(0x20, ioaddr + Wn3_MAC_Ctrl);	/* Set the full-duplex bit. */
741     	config.i = inl(ioaddr + Wn3_Config);
742     
743     	if (vp->media_override != 7) {
744     		if (corkscrew_debug > 1)
745     			printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
746     				dev->name, vp->media_override,
747     				media_tbl[vp->media_override].name);
748     		dev->if_port = vp->media_override;
749     	} else if (vp->autoselect) {
750     		/* Find first available media type, starting with 100baseTx. */
751     		dev->if_port = 4;
752     		while (!(vp->available_media & media_tbl[dev->if_port].mask)) 
753     			dev->if_port = media_tbl[dev->if_port].next;
754     
755     		if (corkscrew_debug > 1)
756     			printk("%s: Initial media type %s.\n",
757     			       dev->name, media_tbl[dev->if_port].name);
758     
759     		init_timer(&vp->timer);
760     		vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
761     		vp->timer.data = (unsigned long) dev;
762     		vp->timer.function = &corkscrew_timer;	/* timer handler */
763     		add_timer(&vp->timer);
764     	} else
765     		dev->if_port = vp->default_media;
766     
767     	config.u.xcvr = dev->if_port;
768     	outl(config.i, ioaddr + Wn3_Config);
769     
770     	if (corkscrew_debug > 1) {
771     		printk("%s: corkscrew_open() InternalConfig %8.8x.\n",
772     		       dev->name, config.i);
773     	}
774     
775     	outw(TxReset, ioaddr + EL3_CMD);
776     	for (i = 20; i >= 0; i--)
777     		if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
778     			break;
779     
780     	outw(RxReset, ioaddr + EL3_CMD);
781     	/* Wait a few ticks for the RxReset command to complete. */
782     	for (i = 20; i >= 0; i--)
783     		if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
784     			break;
785     
786     	outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
787     
788     	/* Use the now-standard shared IRQ implementation. */
789     	if (vp->capabilities == 0x11c7) {
790     		/* Corkscrew: Cannot share ISA resources. */
791     		if (dev->irq == 0
792     		    || dev->dma == 0
793     		    || request_irq(dev->irq, &corkscrew_interrupt, 0,
794     				   vp->product_name, dev)) return -EAGAIN;
795     		enable_dma(dev->dma);
796     		set_dma_mode(dev->dma, DMA_MODE_CASCADE);
797     	} else if (request_irq(dev->irq, &corkscrew_interrupt, SA_SHIRQ,
798     			       vp->product_name, dev)) {
799     		return -EAGAIN;
800     	}
801     
802     	if (corkscrew_debug > 1) {
803     		EL3WINDOW(4);
804     		printk("%s: corkscrew_open() irq %d media status %4.4x.\n",
805     		       dev->name, dev->irq, inw(ioaddr + Wn4_Media));
806     	}
807     
808     	/* Set the station address and mask in window 2 each time opened. */
809     	EL3WINDOW(2);
810     	for (i = 0; i < 6; i++)
811     		outb(dev->dev_addr[i], ioaddr + i);
812     	for (; i < 12; i += 2)
813     		outw(0, ioaddr + i);
814     
815     	if (dev->if_port == 3)
816     		/* Start the thinnet transceiver. We should really wait 50ms... */
817     		outw(StartCoax, ioaddr + EL3_CMD);
818     	EL3WINDOW(4);
819     	outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP | Media_SQE)) |
820     	     media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
821     
822     	/* Switch to the stats window, and clear all stats by reading. */
823     	outw(StatsDisable, ioaddr + EL3_CMD);
824     	EL3WINDOW(6);
825     	for (i = 0; i < 10; i++)
826     		inb(ioaddr + i);
827     	inw(ioaddr + 10);
828     	inw(ioaddr + 12);
829     	/* New: On the Vortex we must also clear the BadSSD counter. */
830     	EL3WINDOW(4);
831     	inb(ioaddr + 12);
832     	/* ..and on the Boomerang we enable the extra statistics bits. */
833     	outw(0x0040, ioaddr + Wn4_NetDiag);
834     
835     	/* Switch to register set 7 for normal use. */
836     	EL3WINDOW(7);
837     
838     	if (vp->full_bus_master_rx) {	/* Boomerang bus master. */
839     		vp->cur_rx = vp->dirty_rx = 0;
840     		if (corkscrew_debug > 2)
841     			printk("%s:  Filling in the Rx ring.\n",
842     			       dev->name);
843     		for (i = 0; i < RX_RING_SIZE; i++) {
844     			struct sk_buff *skb;
845     			if (i < (RX_RING_SIZE - 1))
846     				vp->rx_ring[i].next =
847     				    virt_to_bus(&vp->rx_ring[i + 1]);
848     			else
849     				vp->rx_ring[i].next = 0;
850     			vp->rx_ring[i].status = 0;	/* Clear complete bit. */
851     			vp->rx_ring[i].length = PKT_BUF_SZ | 0x80000000;
852     			skb = dev_alloc_skb(PKT_BUF_SZ);
853     			vp->rx_skbuff[i] = skb;
854     			if (skb == NULL)
855     				break;	/* Bad news!  */
856     			skb->dev = dev;	/* Mark as being used by this device. */
857     			skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */
858     			vp->rx_ring[i].addr = virt_to_bus(skb->tail);
859     		}
860     		vp->rx_ring[i - 1].next = virt_to_bus(&vp->rx_ring[0]);	/* Wrap the ring. */
861     		outl(virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
862     	}
863     	if (vp->full_bus_master_tx) {	/* Boomerang bus master Tx. */
864     		vp->cur_tx = vp->dirty_tx = 0;
865     		outb(PKT_BUF_SZ >> 8, ioaddr + TxFreeThreshold);	/* Room for a packet. */
866     		/* Clear the Tx ring. */
867     		for (i = 0; i < TX_RING_SIZE; i++)
868     			vp->tx_skbuff[i] = 0;
869     		outl(0, ioaddr + DownListPtr);
870     	}
871     	/* Set receiver mode: presumably accept b-case and phys addr only. */
872     	set_rx_mode(dev);
873     	outw(StatsEnable, ioaddr + EL3_CMD);	/* Turn on statistics. */
874     
875     	netif_start_queue(dev);
876     
877     	outw(RxEnable, ioaddr + EL3_CMD);	/* Enable the receiver. */
878     	outw(TxEnable, ioaddr + EL3_CMD);	/* Enable transmitter. */
879     	/* Allow status bits to be seen. */
880     	outw(SetStatusEnb | AdapterFailure | IntReq | StatsFull |
881     	     (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
882     	     (vp->full_bus_master_rx ? UpComplete : RxComplete) |
883     	     (vp->bus_master ? DMADone : 0), ioaddr + EL3_CMD);
884     	/* Ack all pending events, and set active indicator mask. */
885     	outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
886     	     ioaddr + EL3_CMD);
887     	outw(SetIntrEnb | IntLatch | TxAvailable | RxComplete | StatsFull
888     	     | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete,
889     	     ioaddr + EL3_CMD);
890     
891     	return 0;
892     }
893     
894     static void corkscrew_timer(unsigned long data)
895     {
896     #ifdef AUTOMEDIA
897     	struct net_device *dev = (struct net_device *) data;
898     	struct corkscrew_private *vp =
899     	    (struct corkscrew_private *) dev->priv;
900     	int ioaddr = dev->base_addr;
901     	unsigned long flags;
902     	int ok = 0;
903     
904     	if (corkscrew_debug > 1)
905     		printk("%s: Media selection timer tick happened, %s.\n",
906     		       dev->name, media_tbl[dev->if_port].name);
907     
908     	save_flags(flags);
909     	cli(); {
910     		int old_window = inw(ioaddr + EL3_CMD) >> 13;
911     		int media_status;
912     		EL3WINDOW(4);
913     		media_status = inw(ioaddr + Wn4_Media);
914     		switch (dev->if_port) {
915     		case 0:
916     		case 4:
917     		case 5:	/* 10baseT, 100baseTX, 100baseFX  */
918     			if (media_status & Media_LnkBeat) {
919     				ok = 1;
920     				if (corkscrew_debug > 1)
921     					printk("%s: Media %s has link beat, %x.\n",
922     						dev->name,
923     						media_tbl[dev->if_port].name,
924     						media_status);
925     			} else if (corkscrew_debug > 1)
926     				printk("%s: Media %s is has no link beat, %x.\n",
927     					dev->name,
928     					media_tbl[dev->if_port].name,
929     					media_status);
930     
931     			break;
932     		default:	/* Other media types handled by Tx timeouts. */
933     			if (corkscrew_debug > 1)
934     				printk("%s: Media %s is has no indication, %x.\n",
935     					dev->name,
936     					media_tbl[dev->if_port].name,
937     					media_status);
938     			ok = 1;
939     		}
940     		if (!ok) {
941     			union wn3_config config;
942     
943     			do {
944     				dev->if_port =
945     				    media_tbl[dev->if_port].next;
946     			}
947     			while (!(vp->available_media & media_tbl[dev->if_port].mask));
948     			
949     			if (dev->if_port == 8) {	/* Go back to default. */
950     				dev->if_port = vp->default_media;
951     				if (corkscrew_debug > 1)
952     					printk("%s: Media selection failing, using default %s port.\n",
953     						dev->name,
954     						media_tbl[dev->if_port].name);
955     			} else {
956     				if (corkscrew_debug > 1)
957     					printk("%s: Media selection failed, now trying %s port.\n",
958     						dev->name,
959     						media_tbl[dev->if_port].name);
960     				vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
961     				add_timer(&vp->timer);
962     			}
963     			outw((media_status & ~(Media_10TP | Media_SQE)) |
964     			     media_tbl[dev->if_port].media_bits,
965     			     ioaddr + Wn4_Media);
966     
967     			EL3WINDOW(3);
968     			config.i = inl(ioaddr + Wn3_Config);
969     			config.u.xcvr = dev->if_port;
970     			outl(config.i, ioaddr + Wn3_Config);
971     
972     			outw(dev->if_port == 3 ? StartCoax : StopCoax,
973     			     ioaddr + EL3_CMD);
974     		}
975     		EL3WINDOW(old_window);
976     	}
977     	restore_flags(flags);
978     	if (corkscrew_debug > 1)
979     		printk("%s: Media selection timer finished, %s.\n",
980     		       dev->name, media_tbl[dev->if_port].name);
981     
982     #endif				/* AUTOMEDIA */
983     	return;
984     }
985     
986     static void corkscrew_timeout(struct net_device *dev)
987     {
988     	int i;
989     	struct corkscrew_private *vp =
990     	    (struct corkscrew_private *) dev->priv;
991     	int ioaddr = dev->base_addr;
992     
993     	printk(KERN_WARNING
994     	       "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
995     	       dev->name, inb(ioaddr + TxStatus),
996     	       inw(ioaddr + EL3_STATUS));
997     	/* Slight code bloat to be user friendly. */
998     	if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
999     		printk(KERN_WARNING
1000     		       "%s: Transmitter encountered 16 collisions -- network"
1001     		       " network cable problem?\n", dev->name);
1002     #ifndef final_version
1003     	printk("  Flags; bus-master %d, full %d; dirty %d current %d.\n",
1004     	       vp->full_bus_master_tx, vp->tx_full, vp->dirty_tx,
1005     	       vp->cur_tx);
1006     	printk("  Down list %8.8x vs. %p.\n", inl(ioaddr + DownListPtr),
1007     	       &vp->tx_ring[0]);
1008     	for (i = 0; i < TX_RING_SIZE; i++) {
1009     		printk("  %d: %p  length %8.8x status %8.8x\n", i,
1010     		       &vp->tx_ring[i],
1011     		       vp->tx_ring[i].length, vp->tx_ring[i].status);
1012     	}
1013     #endif
1014     	/* Issue TX_RESET and TX_START commands. */
1015     	outw(TxReset, ioaddr + EL3_CMD);
1016     	for (i = 20; i >= 0; i--)
1017     		if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
1018     			break;
1019     	outw(TxEnable, ioaddr + EL3_CMD);
1020     	dev->trans_start = jiffies;
1021     	vp->stats.tx_errors++;
1022     	vp->stats.tx_dropped++;
1023     	netif_wake_queue(dev);
1024     }
1025     
1026     static int corkscrew_start_xmit(struct sk_buff *skb,
1027     				struct net_device *dev)
1028     {
1029     	struct corkscrew_private *vp =
1030     	    (struct corkscrew_private *) dev->priv;
1031     	int ioaddr = dev->base_addr;
1032     
1033     	/* Block a timer-based transmit from overlapping. */
1034     
1035     	netif_stop_queue(dev);
1036     
1037     	if (vp->full_bus_master_tx) {	/* BOOMERANG bus-master */
1038     		/* Calculate the next Tx descriptor entry. */
1039     		int entry = vp->cur_tx % TX_RING_SIZE;
1040     		struct boom_tx_desc *prev_entry;
1041     		unsigned long flags, i;
1042     
1043     		if (vp->tx_full)	/* No room to transmit with */
1044     			return 1;
1045     		if (vp->cur_tx != 0)
1046     			prev_entry =
1047     			    &vp->tx_ring[(vp->cur_tx - 1) % TX_RING_SIZE];
1048     		else
1049     			prev_entry = NULL;
1050     		if (corkscrew_debug > 3)
1051     			printk("%s: Trying to send a packet, Tx index %d.\n",
1052     				dev->name, vp->cur_tx);
1053     		/* vp->tx_full = 1; */
1054     		vp->tx_skbuff[entry] = skb;
1055     		vp->tx_ring[entry].next = 0;
1056     		vp->tx_ring[entry].addr = virt_to_bus(skb->data);
1057     		vp->tx_ring[entry].length = skb->len | 0x80000000;
1058     		vp->tx_ring[entry].status = skb->len | 0x80000000;
1059     
1060     		save_flags(flags);
1061     		cli();
1062     		outw(DownStall, ioaddr + EL3_CMD);
1063     		/* Wait for the stall to complete. */
1064     		for (i = 20; i >= 0; i--)
1065     			if ((inw(ioaddr + EL3_STATUS) & CmdInProgress) ==
1066     			    0) break;
1067     		if (prev_entry)
1068     			prev_entry->next =
1069     			    virt_to_bus(&vp->tx_ring[entry]);
1070     		if (inl(ioaddr + DownListPtr) == 0) {
1071     			outl(virt_to_bus(&vp->tx_ring[entry]),
1072     			     ioaddr + DownListPtr);
1073     			queued_packet++;
1074     		}
1075     		outw(DownUnstall, ioaddr + EL3_CMD);
1076     		restore_flags(flags);
1077     
1078     		vp->cur_tx++;
1079     		if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1)
1080     			vp->tx_full = 1;
1081     		else {		/* Clear previous interrupt enable. */
1082     			if (prev_entry)
1083     				prev_entry->status &= ~0x80000000;
1084     			netif_wake_queue(dev);
1085     		}
1086     		dev->trans_start = jiffies;
1087     		return 0;
1088     	}
1089     	/* Put out the doubleword header... */
1090     	outl(skb->len, ioaddr + TX_FIFO);
1091     	vp->stats.tx_bytes += skb->len;
1092     #ifdef VORTEX_BUS_MASTER
1093     	if (vp->bus_master) {
1094     		/* Set the bus-master controller to transfer the packet. */
1095     		outl((int) (skb->data), ioaddr + Wn7_MasterAddr);
1096     		outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
1097     		vp->tx_skb = skb;
1098     		outw(StartDMADown, ioaddr + EL3_CMD);
1099     		/* queue will be woken at the DMADone interrupt. */
1100     	} else {
1101     		/* ... and the packet rounded to a doubleword. */
1102     		outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1103     		dev_kfree_skb(skb);
1104     		if (inw(ioaddr + TxFree) > 1536) {
1105     			netif_wake_queue(dev);
1106     		} else
1107     			/* Interrupt us when the FIFO has room for max-sized packet. */
1108     			outw(SetTxThreshold + (1536 >> 2),
1109     			     ioaddr + EL3_CMD);
1110     	}
1111     #else
1112     	/* ... and the packet rounded to a doubleword. */
1113     	outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
1114     	dev_kfree_skb(skb);
1115     	if (inw(ioaddr + TxFree) > 1536) {
1116     		netif_wake_queue(dev);
1117     	} else
1118     		/* Interrupt us when the FIFO has room for max-sized packet. */
1119     		outw(SetTxThreshold + (1536 >> 2), ioaddr + EL3_CMD);
1120     #endif				/* bus master */
1121     
1122     	dev->trans_start = jiffies;
1123     
1124     	/* Clear the Tx status stack. */
1125     	{
1126     		short tx_status;
1127     		int i = 4;
1128     
1129     		while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
1130     			if (tx_status & 0x3C) {	/* A Tx-disabling error occurred.  */
1131     				if (corkscrew_debug > 2)
1132     					printk("%s: Tx error, status %2.2x.\n",
1133     						dev->name, tx_status);
1134     				if (tx_status & 0x04)
1135     					vp->stats.tx_fifo_errors++;
1136     				if (tx_status & 0x38)
1137     					vp->stats.tx_aborted_errors++;
1138     				if (tx_status & 0x30) {
1139     					int j;
1140     					outw(TxReset, ioaddr + EL3_CMD);
1141     					for (j = 20; j >= 0; j--)
1142     						if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress)) 
1143     							break;
1144     				}
1145     				outw(TxEnable, ioaddr + EL3_CMD);
1146     			}
1147     			outb(0x00, ioaddr + TxStatus);	/* Pop the status stack. */
1148     		}
1149     	}
1150     	return 0;
1151     }
1152     
1153     /* The interrupt handler does all of the Rx thread work and cleans up
1154        after the Tx thread. */
1155     
1156     static void corkscrew_interrupt(int irq, void *dev_id,
1157     				    struct pt_regs *regs)
1158     {
1159     	/* Use the now-standard shared IRQ implementation. */
1160     	struct net_device *dev = dev_id;
1161     	struct corkscrew_private *lp;
1162     	int ioaddr, status;
1163     	int latency;
1164     	int i = max_interrupt_work;
1165     
1166     	ioaddr = dev->base_addr;
1167     	latency = inb(ioaddr + Timer);
1168     	lp = (struct corkscrew_private *) dev->priv;
1169     
1170     	status = inw(ioaddr + EL3_STATUS);
1171     
1172     	if (corkscrew_debug > 4)
1173     		printk("%s: interrupt, status %4.4x, timer %d.\n",
1174     			dev->name, status, latency);
1175     	if ((status & 0xE000) != 0xE000) {
1176     		static int donedidthis;
1177     		/* Some interrupt controllers store a bogus interrupt from boot-time.
1178     		   Ignore a single early interrupt, but don't hang the machine for
1179     		   other interrupt problems. */
1180     		if (donedidthis++ > 100) {
1181     			printk(KERN_ERR "%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1182     				   dev->name, status, netif_running(dev));
1183     			free_irq(dev->irq, dev);
1184     		}
1185     	}
1186     
1187     	do {
1188     		if (corkscrew_debug > 5)
1189     			printk("%s: In interrupt loop, status %4.4x.\n",
1190     			       dev->name, status);
1191     		if (status & RxComplete)
1192     			corkscrew_rx(dev);
1193     
1194     		if (status & TxAvailable) {
1195     			if (corkscrew_debug > 5)
1196     				printk
1197     				    ("	TX room bit was handled.\n");
1198     			/* There's room in the FIFO for a full-sized packet. */
1199     			outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
1200     			netif_wake_queue(dev);
1201     		}
1202     		if (status & DownComplete) {
1203     			unsigned int dirty_tx = lp->dirty_tx;
1204     
1205     			while (lp->cur_tx - dirty_tx > 0) {
1206     				int entry = dirty_tx % TX_RING_SIZE;
1207     				if (inl(ioaddr + DownListPtr) ==
1208     				    virt_to_bus(&lp->tx_ring[entry]))
1209     					break;	/* It still hasn't been processed. */
1210     				if (lp->tx_skbuff[entry]) {
1211     					dev_kfree_skb_irq(lp->
1212     							  tx_skbuff
1213     							  [entry]);
1214     					lp->tx_skbuff[entry] = 0;
1215     				}
1216     				dirty_tx++;
1217     			}
1218     			lp->dirty_tx = dirty_tx;
1219     			outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
1220     			if (lp->tx_full
1221     			    && (lp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
1222     				lp->tx_full = 0;
1223     				netif_wake_queue(dev);
1224     			}
1225     		}
1226     #ifdef VORTEX_BUS_MASTER
1227     		if (status & DMADone) {
1228     			outw(0x1000, ioaddr + Wn7_MasterStatus);	/* Ack the event. */
1229     			dev_kfree_skb_irq(lp->tx_skb);	/* Release the transferred buffer */
1230     			netif_wake_queue(dev);
1231     		}
1232     #endif
1233     		if (status & UpComplete) {
1234     			boomerang_rx(dev);
1235     			outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
1236     		}
1237     		if (status & (AdapterFailure | RxEarly | StatsFull)) {
1238     			/* Handle all uncommon interrupts at once. */
1239     			if (status & RxEarly) {	/* Rx early is unused. */
1240     				corkscrew_rx(dev);
1241     				outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
1242     			}
1243     			if (status & StatsFull) {	/* Empty statistics. */
1244     				static int DoneDidThat;
1245     				if (corkscrew_debug > 4)
1246     					printk("%s: Updating stats.\n",
1247     					       dev->name);
1248     				update_stats(ioaddr, dev);
1249     				/* DEBUG HACK: Disable statistics as an interrupt source. */
1250     				/* This occurs when we have the wrong media type! */
1251     				if (DoneDidThat == 0 &&
1252     				    inw(ioaddr + EL3_STATUS) & StatsFull) {
1253     					int win, reg;
1254     					printk("%s: Updating stats failed, disabling stats as an"
1255     					     " interrupt source.\n",
1256     					     dev->name);
1257     					for (win = 0; win < 8; win++) {
1258     						EL3WINDOW(win);
1259     						printk("\n Vortex window %d:", win);
1260     						for (reg = 0; reg < 16; reg++)
1261     							printk(" %2.2x",
1262     							       inb(ioaddr + reg));
1263     					}
1264     					EL3WINDOW(7);
1265     					outw(SetIntrEnb | TxAvailable |
1266     					     RxComplete | AdapterFailure |
1267     					     UpComplete | DownComplete |
1268     					     TxComplete, ioaddr + EL3_CMD);
1269     					DoneDidThat++;
1270     				}
1271     			}
1272     			if (status & AdapterFailure) {
1273     				/* Adapter failure requires Rx reset and reinit. */
1274     				outw(RxReset, ioaddr + EL3_CMD);
1275     				/* Set the Rx filter to the current state. */
1276     				set_rx_mode(dev);
1277     				outw(RxEnable, ioaddr + EL3_CMD);	/* Re-enable the receiver. */
1278     				outw(AckIntr | AdapterFailure,
1279     				     ioaddr + EL3_CMD);
1280     			}
1281     		}
1282     
1283     		if (--i < 0) {
1284     			printk(KERN_ERR "%s: Too much work in interrupt, status %4.4x.  "
1285     			     "Disabling functions (%4.4x).\n", dev->name,
1286     			     status, SetStatusEnb | ((~status) & 0x7FE));
1287     			/* Disable all pending interrupts. */
1288     			outw(SetStatusEnb | ((~status) & 0x7FE),
1289     			     ioaddr + EL3_CMD);
1290     			outw(AckIntr | 0x7FF, ioaddr + EL3_CMD);
1291     			break;
1292     		}
1293     		/* Acknowledge the IRQ. */
1294     		outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
1295     
1296     	} while ((status = inw(ioaddr + EL3_STATUS)) &
1297     		 (IntLatch | RxComplete));
1298     
1299     	if (corkscrew_debug > 4)
1300     		printk("%s: exiting interrupt, status %4.4x.\n", dev->name,
1301     		       status);
1302     }
1303     
1304     static int corkscrew_rx(struct net_device *dev)
1305     {
1306     	struct corkscrew_private *vp = (struct corkscrew_private *) dev->priv;
1307     	int ioaddr = dev->base_addr;
1308     	int i;
1309     	short rx_status;
1310     
1311     	if (corkscrew_debug > 5)
1312     		printk("   In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1313     		     inw(ioaddr + EL3_STATUS), inw(ioaddr + RxStatus));
1314     	while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
1315     		if (rx_status & 0x4000) {	/* Error, update stats. */
1316     			unsigned char rx_error = inb(ioaddr + RxErrors);
1317     			if (corkscrew_debug > 2)
1318     				printk(" Rx error: status %2.2x.\n",
1319     				       rx_error);
1320     			vp->stats.rx_errors++;
1321     			if (rx_error & 0x01)
1322     				vp->stats.rx_over_errors++;
1323     			if (rx_error & 0x02)
1324     				vp->stats.rx_length_errors++;
1325     			if (rx_error & 0x04)
1326     				vp->stats.rx_frame_errors++;
1327     			if (rx_error & 0x08)
1328     				vp->stats.rx_crc_errors++;
1329     			if (rx_error & 0x10)
1330     				vp->stats.rx_length_errors++;
1331     		} else {
1332     			/* The packet length: up to 4.5K!. */
1333     			short pkt_len = rx_status & 0x1fff;
1334     			struct sk_buff *skb;
1335     
1336     			skb = dev_alloc_skb(pkt_len + 5 + 2);
1337     			if (corkscrew_debug > 4)
1338     				printk("Receiving packet size %d status %4.4x.\n",
1339     				     pkt_len, rx_status);
1340     			if (skb != NULL) {
1341     				skb->dev = dev;
1342     				skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */
1343     				/* 'skb_put()' points to the start of sk_buff data area. */
1344     				insl(ioaddr + RX_FIFO,
1345     				     skb_put(skb, pkt_len),
1346     				     (pkt_len + 3) >> 2);
1347     				outw(RxDiscard, ioaddr + EL3_CMD);	/* Pop top Rx packet. */
1348     				skb->protocol = eth_type_trans(skb, dev);
1349     				netif_rx(skb);
1350     				dev->last_rx = jiffies;
1351     				vp->stats.rx_packets++;
1352     				vp->stats.rx_bytes += pkt_len;
1353     				/* Wait a limited time to go to next packet. */
1354     				for (i = 200; i >= 0; i--)
1355     					if (! (inw(ioaddr + EL3_STATUS) & CmdInProgress)) 
1356     						break;
1357     				continue;
1358     			} else if (corkscrew_debug)
1359     				printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, pkt_len);
1360     		}
1361     		outw(RxDiscard, ioaddr + EL3_CMD);
1362     		vp->stats.rx_dropped++;
1363     		/* Wait a limited time to skip this packet. */
1364     		for (i = 200; i >= 0; i--)
1365     			if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
1366     				break;
1367     	}
1368     	return 0;
1369     }
1370     
1371     static int boomerang_rx(struct net_device *dev)
1372     {
1373     	struct corkscrew_private *vp =
1374     	    (struct corkscrew_private *) dev->priv;
1375     	int entry = vp->cur_rx % RX_RING_SIZE;
1376     	int ioaddr = dev->base_addr;
1377     	int rx_status;
1378     
1379     	if (corkscrew_debug > 5)
1380     		printk("   In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1381     			inw(ioaddr + EL3_STATUS), inw(ioaddr + RxStatus));
1382     	while ((rx_status = vp->rx_ring[entry].status) & RxDComplete) {
1383     		if (rx_status & RxDError) {	/* Error, update stats. */
1384     			unsigned char rx_error = rx_status >> 16;
1385     			if (corkscrew_debug > 2)
1386     				printk(" Rx error: status %2.2x.\n",
1387     				       rx_error);
1388     			vp->stats.rx_errors++;
1389     			if (rx_error & 0x01)
1390     				vp->stats.rx_over_errors++;
1391     			if (rx_error & 0x02)
1392     				vp->stats.rx_length_errors++;
1393     			if (rx_error & 0x04)
1394     				vp->stats.rx_frame_errors++;
1395     			if (rx_error & 0x08)
1396     				vp->stats.rx_crc_errors++;
1397     			if (rx_error & 0x10)
1398     				vp->stats.rx_length_errors++;
1399     		} else {
1400     			/* The packet length: up to 4.5K!. */
1401     			short pkt_len = rx_status & 0x1fff;
1402     			struct sk_buff *skb;
1403     
1404     			vp->stats.rx_bytes += pkt_len;
1405     			if (corkscrew_debug > 4)
1406     				printk("Receiving packet size %d status %4.4x.\n",
1407     				     pkt_len, rx_status);
1408     
1409     			/* Check if the packet is long enough to just accept without
1410     			   copying to a properly sized skbuff. */
1411     			if (pkt_len < rx_copybreak
1412     			    && (skb = dev_alloc_skb(pkt_len + 4)) != 0) {
1413     				skb->dev = dev;
1414     				skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */
1415     				/* 'skb_put()' points to the start of sk_buff data area. */
1416     				memcpy(skb_put(skb, pkt_len),
1417     				       bus_to_virt(vp->rx_ring[entry].
1418     						   addr), pkt_len);
1419     				rx_copy++;
1420     			} else {
1421     				void *temp;
1422     				/* Pass up the skbuff already on the Rx ring. */
1423     				skb = vp->rx_skbuff[entry];
1424     				vp->rx_skbuff[entry] = NULL;
1425     				temp = skb_put(skb, pkt_len);
1426     				/* Remove this checking code for final release. */
1427     				if (bus_to_virt(vp->rx_ring[entry].addr) != temp)
1428     					    printk("%s: Warning -- the skbuff addresses do not match"
1429     					     " in boomerang_rx: %p vs. %p / %p.\n",
1430     					     dev->name,
1431     					     bus_to_virt(vp->
1432     							 rx_ring[entry].
1433     							 addr), skb->head,
1434     					     temp);
1435     				rx_nocopy++;
1436     			}
1437     			skb->protocol = eth_type_trans(skb, dev);
1438     			netif_rx(skb);
1439     			dev->last_rx = jiffies;
1440     			vp->stats.rx_packets++;
1441     		}
1442     		entry = (++vp->cur_rx) % RX_RING_SIZE;
1443     	}
1444     	/* Refill the Rx ring buffers. */
1445     	for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
1446     		struct sk_buff *skb;
1447     		entry = vp->dirty_rx % RX_RING_SIZE;
1448     		if (vp->rx_skbuff[entry] == NULL) {
1449     			skb = dev_alloc_skb(PKT_BUF_SZ);
1450     			if (skb == NULL)
1451     				break;	/* Bad news!  */
1452     			skb->dev = dev;	/* Mark as being used by this device. */
1453     			skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */
1454     			vp->rx_ring[entry].addr = virt_to_bus(skb->tail);
1455     			vp->rx_skbuff[entry] = skb;
1456     		}
1457     		vp->rx_ring[entry].status = 0;	/* Clear complete bit. */
1458     	}
1459     	return 0;
1460     }
1461     
1462     static int corkscrew_close(struct net_device *dev)
1463     {
1464     	struct corkscrew_private *vp =
1465     	    (struct corkscrew_private *) dev->priv;
1466     	int ioaddr = dev->base_addr;
1467     	int i;
1468     
1469     	netif_stop_queue(dev);
1470     
1471     	if (corkscrew_debug > 1) {
1472     		printk("%s: corkscrew_close() status %4.4x, Tx status %2.2x.\n",
1473     		     dev->name, inw(ioaddr + EL3_STATUS),
1474     		     inb(ioaddr + TxStatus));
1475     		printk("%s: corkscrew close stats: rx_nocopy %d rx_copy %d"
1476     		       " tx_queued %d.\n", dev->name, rx_nocopy, rx_copy,
1477     		       queued_packet);
1478     	}
1479     
1480     	del_timer(&vp->timer);
1481     
1482     	/* Turn off statistics ASAP.  We update lp->stats below. */
1483     	outw(StatsDisable, ioaddr + EL3_CMD);
1484     
1485     	/* Disable the receiver and transmitter. */
1486     	outw(RxDisable, ioaddr + EL3_CMD);
1487     	outw(TxDisable, ioaddr + EL3_CMD);
1488     
1489     	if (dev->if_port == XCVR_10base2)
1490     		/* Turn off thinnet power.  Green! */
1491     		outw(StopCoax, ioaddr + EL3_CMD);
1492     
1493     	free_irq(dev->irq, dev);
1494     
1495     	outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1496     
1497     	update_stats(ioaddr, dev);
1498     	if (vp->full_bus_master_rx) {	/* Free Boomerang bus master Rx buffers. */
1499     		outl(0, ioaddr + UpListPtr);
1500     		for (i = 0; i < RX_RING_SIZE; i++)
1501     			if (vp->rx_skbuff[i]) {
1502     				dev_kfree_skb(vp->rx_skbuff[i]);
1503     				vp->rx_skbuff[i] = 0;
1504     			}
1505     	}
1506     	if (vp->full_bus_master_tx) {	/* Free Boomerang bus master Tx buffers. */
1507     		outl(0, ioaddr + DownListPtr);
1508     		for (i = 0; i < TX_RING_SIZE; i++)
1509     			if (vp->tx_skbuff[i]) {
1510     				dev_kfree_skb(vp->tx_skbuff[i]);
1511     				vp->tx_skbuff[i] = 0;
1512     			}
1513     	}
1514     
1515     	return 0;
1516     }
1517     
1518     static struct net_device_stats *corkscrew_get_stats(struct net_device *dev)
1519     {
1520     	struct corkscrew_private *vp =
1521     	    (struct corkscrew_private *) dev->priv;
1522     	unsigned long flags;
1523     
1524     	if (netif_running(dev)) {
1525     		save_flags(flags);
1526     		cli();
1527     		update_stats(dev->base_addr, dev);
1528     		restore_flags(flags);
1529     	}
1530     	return &vp->stats;
1531     }
1532     
1533     /*  Update statistics.
1534     	Unlike with the EL3 we need not worry about interrupts changing
1535     	the window setting from underneath us, but we must still guard
1536     	against a race condition with a StatsUpdate interrupt updating the
1537     	table.  This is done by checking that the ASM (!) code generated uses
1538     	atomic updates with '+='.
1539     	*/
1540     static void update_stats(int ioaddr, struct net_device *dev)
1541     {
1542     	struct corkscrew_private *vp =
1543     	    (struct corkscrew_private *) dev->priv;
1544     
1545     	/* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1546     	/* Switch to the stats window, and read everything. */
1547     	EL3WINDOW(6);
1548     	vp->stats.tx_carrier_errors += inb(ioaddr + 0);
1549     	vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1550     	/* Multiple collisions. */ inb(ioaddr + 2);
1551     	vp->stats.collisions += inb(ioaddr + 3);
1552     	vp->stats.tx_window_errors += inb(ioaddr + 4);
1553     	vp->stats.rx_fifo_errors += inb(ioaddr + 5);
1554     	vp->stats.tx_packets += inb(ioaddr + 6);
1555     	vp->stats.tx_packets += (inb(ioaddr + 9) & 0x30) << 4;
1556     						/* Rx packets   */ inb(ioaddr + 7);
1557     						/* Must read to clear */
1558     	/* Tx deferrals */ inb(ioaddr + 8);
1559     	/* Don't bother with register 9, an extension of registers 6&7.
1560     	   If we do use the 6&7 values the atomic update assumption above
1561     	   is invalid. */
1562     	inw(ioaddr + 10);	/* Total Rx and Tx octets. */
1563     	inw(ioaddr + 12);
1564     	/* New: On the Vortex we must also clear the BadSSD counter. */
1565     	EL3WINDOW(4);
1566     	inb(ioaddr + 12);
1567     
1568     	/* We change back to window 7 (not 1) with the Vortex. */
1569     	EL3WINDOW(7);
1570     	return;
1571     }
1572     
1573     /* This new version of set_rx_mode() supports v1.4 kernels.
1574        The Vortex chip has no documented multicast filter, so the only
1575        multicast setting is to receive all multicast frames.  At least
1576        the chip has a very clean way to set the mode, unlike many others. */
1577     static void set_rx_mode(struct net_device *dev)
1578     {
1579     	int ioaddr = dev->base_addr;
1580     	short new_mode;
1581     
1582     	if (dev->flags & IFF_PROMISC) {
1583     		if (corkscrew_debug > 3)
1584     			printk("%s: Setting promiscuous mode.\n",
1585     			       dev->name);
1586     		new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast | RxProm;
1587     	} else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
1588     		new_mode = SetRxFilter | RxStation | RxMulticast | RxBroadcast;
1589     	} else
1590     		new_mode = SetRxFilter | RxStation | RxBroadcast;
1591     
1592     	outw(new_mode, ioaddr + EL3_CMD);
1593     }
1594     
1595     #ifdef MODULE
1596     void cleanup_module(void)
1597     {
1598     	struct net_device *next_dev;
1599     
1600     	/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1601     	while (root_corkscrew_dev) {
1602     		next_dev =
1603     		    ((struct corkscrew_private *) root_corkscrew_dev->
1604     		     priv)->next_module;
1605     		if (root_corkscrew_dev->dma)
1606     			free_dma(root_corkscrew_dev->dma);
1607     		unregister_netdev(root_corkscrew_dev);
1608     		outw(TotalReset, root_corkscrew_dev->base_addr + EL3_CMD);
1609     		release_region(root_corkscrew_dev->base_addr,
1610     			       CORKSCREW_TOTAL_SIZE);
1611     		kfree(root_corkscrew_dev);
1612     		root_corkscrew_dev = next_dev;
1613     	}
1614     }
1615     #endif				/* MODULE */
1616     
1617     /*
1618      * Local variables:
1619      *  compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c515.c"
1620      *  c-indent-level: 4
1621      *  tab-width: 4
1622      * End:
1623      */
1624