File: /usr/src/linux/drivers/net/tokenring/olympic.c

1     /*
2      *   olympic.c (c) 1999 Peter De Schrijver All Rights Reserved
3      *		   1999/2000 Mike Phillips (mikep@linuxtr.net)
4      *
5      *  Linux driver for IBM PCI tokenring cards based on the Pit/Pit-Phy/Olympic
6      *  chipset. 
7      *
8      *  Base Driver Skeleton:
9      *      Written 1993-94 by Donald Becker.
10      *
11      *      Copyright 1993 United States Government as represented by the
12      *      Director, National Security Agency.
13      *
14      *  Thanks to Erik De Cock, Adrian Bridgett and Frank Fiene for their 
15      *  assistance and perserverance with the testing of this driver.
16      *
17      *  This software may be used and distributed according to the terms
18      *  of the GNU General Public License, incorporated herein by reference.
19      * 
20      *  4/27/99 - Alpha Release 0.1.0
21      *            First release to the public
22      *
23      *  6/8/99  - Official Release 0.2.0   
24      *            Merged into the kernel code 
25      *  8/18/99 - Updated driver for 2.3.13 kernel to use new pci
26      *	      resource. Driver also reports the card name returned by
27      *            the pci resource.
28      *  1/11/00 - Added spinlocks for smp
29      *  2/23/00 - Updated to dev_kfree_irq 
30      *  3/10/00 - Fixed FDX enable which triggered other bugs also 
31      *            squashed.
32      *  5/20/00 - Changes to handle Olympic on LinuxPPC. Endian changes.
33      *            The odd thing about the changes is that the fix for
34      *            endian issues with the big-endian data in the arb, asb...
35      *            was to always swab() the bytes, no matter what CPU.
36      *            That's because the read[wl]() functions always swap the
37      *            bytes on the way in on PPC.
38      *            Fixing the hardware descriptors was another matter,
39      *            because they weren't going through read[wl](), there all
40      *            the results had to be in memory in le32 values. kdaaker
41      *
42      * 12/23/00 - Added minimal Cardbus support (Thanks Donald).
43      *
44      * 03/09/01 - Add new pci api, dev_base_lock, general clean up. 
45      *
46      * 03/27/01 - Add new dma pci (Thanks to Kyle Lucke) and alloc_trdev
47      *	      Change proc_fs behaviour, now one entry per adapter.
48      *
49      * 04/09/01 - Couple of bug fixes to the dma unmaps and ejecting the
50      *	      adapter when live does not take the system down with it.
51      * 
52      * 06/02/01 - Clean up, copy skb for small packets
53      *
54      *  To Do:
55      *
56      *	     Complete full Cardbus / hot-swap support.
57      *	     Wake on lan	
58      * 
59      *  If Problems do Occur
60      *  Most problems can be rectified by either closing and opening the interface
61      *  (ifconfig down and up) or rmmod and insmod'ing the driver (a bit difficult
62      *  if compiled into the kernel).
63      */
64     
65     /* Change OLYMPIC_DEBUG to 1 to get verbose, and I mean really verbose, messages */
66     
67     #define OLYMPIC_DEBUG 0
68     
69     
70     #include <linux/config.h>
71     #include <linux/module.h>
72     
73     #include <linux/kernel.h>
74     #include <linux/sched.h>
75     #include <linux/errno.h>
76     #include <linux/timer.h>
77     #include <linux/in.h>
78     #include <linux/ioport.h>
79     #include <linux/string.h>
80     #include <linux/proc_fs.h>
81     #include <linux/ptrace.h>
82     #include <linux/skbuff.h>
83     #include <linux/interrupt.h>
84     #include <linux/delay.h>
85     #include <linux/netdevice.h>
86     #include <linux/trdevice.h>
87     #include <linux/stddef.h>
88     #include <linux/init.h>
89     #include <linux/pci.h>
90     #include <linux/spinlock.h>
91     #include <net/checksum.h>
92     
93     #include <asm/io.h>
94     #include <asm/system.h>
95     #include <asm/bitops.h>
96     
97     #include "olympic.h"
98     
99     /* I've got to put some intelligence into the version number so that Peter and I know
100      * which version of the code somebody has got. 
101      * Version Number = a.b.c.d  where a.b.c is the level of code and d is the latest author.
102      * So 0.0.1.pds = Peter, 0.0.1.mlp = Mike
103      * 
104      * Official releases will only have an a.b.c version number format. 
105      */
106     
107     static char version[] __devinitdata = 
108     "Olympic.c v0.9.7 6/02/01 - Peter De Schrijver & Mike Phillips" ; 
109     
110     static char *open_maj_error[]  = {"No error", "Lobe Media Test", "Physical Insertion",
111     				   "Address Verification", "Neighbor Notification (Ring Poll)",
112     				   "Request Parameters","FDX Registration Request",
113     				   "FDX Duplicate Address Check", "Station registration Query Wait",
114     				   "Unknown stage"};
115     
116     static char *open_min_error[] = {"No error", "Function Failure", "Signal Lost", "Wire Fault",
117     				   "Ring Speed Mismatch", "Timeout","Ring Failure","Ring Beaconing",
118     				   "Duplicate Node Address","Request Parameters","Remove Received",
119     				   "Reserved", "Reserved", "No Monitor Detected for RPL", 
120     				   "Monitor Contention failer for RPL", "FDX Protocol Error"};
121     
122     /* Module paramters */
123     
124     MODULE_AUTHOR("Mike Phillips <mikep@linuxtr.net>") ; 
125     MODULE_DESCRIPTION("Olympic PCI/Cardbus Chipset Driver \n") ; 
126     
127     /* Ring Speed 0,4,16,100 
128      * 0 = Autosense         
129      * 4,16 = Selected speed only, no autosense
130      * This allows the card to be the first on the ring
131      * and become the active monitor.
132      * 100 = Nothing at present, 100mbps is autodetected
133      * if FDX is turned on. May be implemented in the future to 
134      * fail if 100mpbs is not detected.
135      *
136      * WARNING: Some hubs will allow you to insert
137      * at the wrong speed
138      */
139     
140     static int ringspeed[OLYMPIC_MAX_ADAPTERS] = {0,} ;
141     MODULE_PARM(ringspeed, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i");
142     
143     /* Packet buffer size */
144     
145     static int pkt_buf_sz[OLYMPIC_MAX_ADAPTERS] = {0,} ;
146     MODULE_PARM(pkt_buf_sz, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i") ; 
147     
148     /* Message Level */
149     
150     static int message_level[OLYMPIC_MAX_ADAPTERS] = {0,} ; 
151     MODULE_PARM(message_level, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i") ; 
152     
153     /* Change network_monitor to receive mac frames through the arb channel.
154      * Will also create a /proc/net/olympic_tr%d entry, where %d is the tr
155      * device, i.e. tr0, tr1 etc. 
156      * Intended to be used to create a ring-error reporting network module 
157      * i.e. it will give you the source address of beaconers on the ring 
158      */
159     static int network_monitor[OLYMPIC_MAX_ADAPTERS] = {0,};
160     MODULE_PARM(network_monitor, "1-" __MODULE_STRING(OLYMPIC_MAX_ADAPTERS) "i");
161     
162     static struct pci_device_id olympic_pci_tbl[] __devinitdata = {
163     	{PCI_VENDOR_ID_IBM,PCI_DEVICE_ID_IBM_TR_WAKE,PCI_ANY_ID,PCI_ANY_ID,},
164     	{ } 	/* Terminating Entry */
165     };
166     MODULE_DEVICE_TABLE(pci,olympic_pci_tbl) ; 
167     
168     
169     static int olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 
170     static int olympic_init(struct net_device *dev);
171     static int olympic_open(struct net_device *dev);
172     static int olympic_xmit(struct sk_buff *skb, struct net_device *dev);
173     static int olympic_close(struct net_device *dev);
174     static void olympic_set_rx_mode(struct net_device *dev);
175     static void olympic_interrupt(int irq, void *dev_id, struct pt_regs *regs);
176     static struct net_device_stats * olympic_get_stats(struct net_device *dev);
177     static int olympic_set_mac_address(struct net_device *dev, void *addr) ; 
178     static void olympic_arb_cmd(struct net_device *dev);
179     static int olympic_change_mtu(struct net_device *dev, int mtu);
180     static void olympic_srb_bh(struct net_device *dev) ; 
181     static void olympic_asb_bh(struct net_device *dev) ; 
182     static int olympic_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data) ; 
183     
184     static int __devinit olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
185     {
186     	struct net_device *dev ; 
187     	struct olympic_private *olympic_priv;
188     	static int card_no = -1 ;
189     	int i ; 
190     
191     	card_no++ ; 
192     
193     	if ((i = pci_enable_device(pdev))) {
194     		return i ; 
195     	}
196     
197     	pci_set_master(pdev);
198     
199     	if ((i = pci_request_regions(pdev,"olympic"))) { 
200     		return i ; 
201     	} ; 
202      
203     	dev = alloc_trdev(sizeof(struct olympic_private)) ; 
204     
205     	if (!dev) {
206     		pci_release_regions(pdev) ; 
207     		return -ENOMEM ; 
208     	}
209     
210     	olympic_priv = dev->priv ;
211     	
212     	init_waitqueue_head(&olympic_priv->srb_wait);
213     	init_waitqueue_head(&olympic_priv->trb_wait);
214     #if OLYMPIC_DEBUG  
215     	printk(KERN_INFO "pci_device: %p, dev:%p, dev->priv: %p\n", pdev, dev, dev->priv);
216     #endif
217     	dev->irq=pdev->irq;
218     	dev->base_addr=pci_resource_start(pdev, 0);
219     	dev->init=NULL; /* Must be NULL otherwise we get called twice */
220     	olympic_priv->olympic_card_name = (char *)pdev->name ; 
221     	olympic_priv->olympic_mmio = ioremap(pci_resource_start(pdev,1),256);
222     	olympic_priv->olympic_lap = ioremap(pci_resource_start(pdev,2),2048);
223     	olympic_priv->pdev = pdev ; 
224     				
225     	if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) )
226     		olympic_priv->pkt_buf_sz = PKT_BUF_SZ ; 
227     	else
228     		olympic_priv->pkt_buf_sz = pkt_buf_sz[card_no] ; 
229     
230     	dev->mtu = olympic_priv->pkt_buf_sz - TR_HLEN ; 
231     	olympic_priv->olympic_ring_speed = ringspeed[card_no] ; 
232     	olympic_priv->olympic_message_level = message_level[card_no] ; 
233     	olympic_priv->olympic_network_monitor = network_monitor[card_no];
234     	
235     	if((i = olympic_init(dev))) {
236     		iounmap(olympic_priv->olympic_mmio) ; 
237     		iounmap(olympic_priv->olympic_lap) ; 
238     		kfree(dev) ; 
239     		pci_release_regions(pdev) ; 
240     		return i ; 
241     	}				
242     
243     	dev->open=&olympic_open;
244     	dev->hard_start_xmit=&olympic_xmit;
245     	dev->change_mtu=&olympic_change_mtu;
246     	dev->stop=&olympic_close;
247     	dev->do_ioctl=NULL;
248     	dev->set_multicast_list=&olympic_set_rx_mode;
249     	dev->get_stats=&olympic_get_stats ;
250     	dev->set_mac_address=&olympic_set_mac_address ;  
251     	SET_MODULE_OWNER(dev) ; 
252     
253     	pci_set_drvdata(pdev,dev) ; 
254     	register_netdev(dev) ; 
255     	printk("Olympic: %s registered as: %s\n",olympic_priv->olympic_card_name,dev->name);
256     	if (olympic_priv->olympic_network_monitor) { /* Must go after register_netdev as we need the device name */ 
257     		char proc_name[20] ; 
258     		strcpy(proc_name,"net/olympic_") ; 
259     		strcat(proc_name,dev->name) ; 
260     		create_proc_read_entry(proc_name,0,0,olympic_proc_info,(void *)dev) ; 
261     		printk("Olympic: Network Monitor information: /proc/%s\n",proc_name); 
262     	}
263     	return  0 ;
264     }
265     
266     static int __devinit olympic_init(struct net_device *dev)
267     {
268         	struct olympic_private *olympic_priv;
269     	u8 *olympic_mmio, *init_srb,*adapter_addr;
270     	unsigned long t; 
271     	unsigned int uaa_addr;
272     
273         	olympic_priv=(struct olympic_private *)dev->priv;
274     	olympic_mmio=olympic_priv->olympic_mmio;
275     
276     	printk("%s \n", version);
277     	printk("%s. I/O at %hx, MMIO at %p, LAP at %p, using irq %d\n", olympic_priv->olympic_card_name, (unsigned int) dev->base_addr,olympic_priv->olympic_mmio, olympic_priv->olympic_lap, dev->irq);
278     
279     	writel(readl(olympic_mmio+BCTL) | BCTL_SOFTRESET,olympic_mmio+BCTL);
280     	t=jiffies;
281     	while((readl(olympic_mmio+BCTL)) & BCTL_SOFTRESET) {
282     		schedule();		
283     		if(jiffies-t > 40*HZ) {
284     			printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
285     			return -ENODEV;
286     		}
287     	}
288     
289     	spin_lock_init(&olympic_priv->olympic_lock) ; 
290     
291     	/* Needed for cardbus */
292     	if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR))
293     		writel(readl(olympic_priv->olympic_mmio+FERMASK)|FERMASK_INT_BIT, olympic_mmio+FERMASK);
294     
295     #if OLYMPIC_DEBUG
296     	printk("BCTL: %x\n",readl(olympic_mmio+BCTL));
297     	printk("GPR: %x\n",readw(olympic_mmio+GPR));
298     	printk("SISRMASK: %x\n",readl(olympic_mmio+SISR_MASK));
299     #endif
300     	/* Aaaahhh, You have got to be real careful setting GPR, the card
301     	   holds the previous values from flash memory, including autosense 
302                and ring speed */
303     
304     	writel(readl(olympic_mmio+BCTL)|BCTL_MIMREB,olympic_mmio+BCTL);
305     	
306     	if (olympic_priv->olympic_ring_speed  == 0) { /* Autosense */
307     		writel(readl(olympic_mmio+GPR)|GPR_AUTOSENSE,olympic_mmio+GPR);
308     		if (olympic_priv->olympic_message_level) 
309     			printk(KERN_INFO "%s: Ringspeed autosense mode on\n",olympic_priv->olympic_card_name);
310     	} else if (olympic_priv->olympic_ring_speed == 16) {
311     		if (olympic_priv->olympic_message_level) 
312     			printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n", olympic_priv->olympic_card_name);
313     		writel(GPR_16MBPS, olympic_mmio+GPR);
314     	} else if (olympic_priv->olympic_ring_speed == 4) {
315     		if (olympic_priv->olympic_message_level) 
316     			printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n", olympic_priv->olympic_card_name) ; 
317     		writel(0, olympic_mmio+GPR);
318     	} 
319     	
320     	writel(readl(olympic_mmio+GPR)|GPR_NEPTUNE_BF,olympic_mmio+GPR);
321     
322     #if OLYMPIC_DEBUG
323     	printk("GPR = %x\n",readw(olympic_mmio + GPR) ) ; 
324     #endif
325     	/* start solo init */
326     	writel((1<<15),olympic_mmio+SISR_MASK_SUM);
327     
328     	t=jiffies;
329     	while(!((readl(olympic_mmio+SISR_RR)) & SISR_SRB_REPLY)) {
330     		schedule();		
331     		if(jiffies-t > 15*HZ) {
332     			printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
333     			return -ENODEV;
334     		}
335     	}
336     	
337     	writel(readl(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
338     
339     #if OLYMPIC_DEBUG
340     	printk("LAPWWO: %x, LAPA: %x\n",readl(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
341     #endif
342     
343     	init_srb=olympic_priv->olympic_lap + ((readl(olympic_mmio+LAPWWO)) & (~0xf800));
344     
345     #if OLYMPIC_DEBUG		
346     {
347     	int i;
348     	printk("init_srb(%p): ",init_srb);
349     	for(i=0;i<20;i++)
350     		printk("%x ",readb(init_srb+i));
351     	printk("\n");
352     }
353     #endif	
354     	if(readw(init_srb+6)) {
355     		printk(KERN_INFO "tokenring card intialization failed. errorcode : %x\n",readw(init_srb+6));
356     		return -ENODEV;
357     	}
358     
359     	if (olympic_priv->olympic_message_level) {
360     		if ( readb(init_srb +2) & 0x40) { 
361     			printk(KERN_INFO "Olympic: Adapter is FDX capable.\n") ;
362     		} else { 
363     			printk(KERN_INFO "Olympic: Adapter cannot do FDX.\n");
364     		}
365     	}
366       
367     	uaa_addr=swab16(readw(init_srb+8));
368     
369     #if OLYMPIC_DEBUG
370     	printk("UAA resides at %x\n",uaa_addr);
371     #endif
372     
373     	writel(uaa_addr,olympic_mmio+LAPA);
374     	adapter_addr=olympic_priv->olympic_lap + (uaa_addr & (~0xf800));
375     
376     #if OLYMPIC_DEBUG
377     	printk("adapter address: %02x:%02x:%02x:%02x:%02x:%02x\n",
378     			readb(adapter_addr), readb(adapter_addr+1),readb(adapter_addr+2),
379     			readb(adapter_addr+3),readb(adapter_addr+4),readb(adapter_addr+5));
380     #endif
381     
382     	memcpy_fromio(&dev->dev_addr[0], adapter_addr,6);
383     
384     	olympic_priv->olympic_addr_table_addr = swab16(readw(init_srb + 12)); 
385     	olympic_priv->olympic_parms_addr = swab16(readw(init_srb + 14)); 
386     
387     	return 0;
388     
389     }
390     
391     static int olympic_open(struct net_device *dev) 
392     {
393     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
394     	u8 *olympic_mmio=olympic_priv->olympic_mmio,*init_srb;
395     	unsigned long flags, t;
396     	char open_error[255] ; 
397     	int i, open_finished = 1 ;
398     
399     	if(request_irq(dev->irq, &olympic_interrupt, SA_SHIRQ , "olympic", dev)) {
400     		return -EAGAIN;
401     	}
402     
403     #if OLYMPIC_DEBUG
404     	printk("BMCTL: %x\n",readl(olympic_mmio+BMCTL_SUM));
405     	printk("pending ints: %x\n",readl(olympic_mmio+SISR_RR));
406     #endif
407     
408     	writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
409     
410     	writel(SISR_MI | SISR_SRB_REPLY, olympic_mmio+SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */
411     
412     	writel(LISR_LIE,olympic_mmio+LISR); /* more ints later */
413     
414     	/* adapter is closed, so SRB is pointed to by LAPWWO */
415     
416     	writel(readl(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
417     	init_srb=olympic_priv->olympic_lap + ((readl(olympic_mmio+LAPWWO)) & (~0xf800));
418     	
419     #if OLYMPIC_DEBUG
420     	printk("LAPWWO: %x, LAPA: %x\n",readl(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
421     	printk("SISR Mask = %04x\n", readl(olympic_mmio+SISR_MASK));
422     	printk("Before the open command \n");
423     #endif	
424     	do {
425     		int i;
426     
427     		save_flags(flags);
428     		cli();
429     		for(i=0;i<SRB_COMMAND_SIZE;i+=4)
430     			writel(0,init_srb+i);
431     		if(SRB_COMMAND_SIZE & 2)
432     			writew(0,init_srb+(SRB_COMMAND_SIZE & ~3));
433     		if(SRB_COMMAND_SIZE & 1)
434     			writeb(0,init_srb+(SRB_COMMAND_SIZE & ~1));
435     
436     		writeb(SRB_OPEN_ADAPTER,init_srb) ; 	/* open */
437     		writeb(OLYMPIC_CLEAR_RET_CODE,init_srb+2);
438     
439     		/* If Network Monitor, instruct card to copy MAC frames through the ARB */
440     		if (olympic_priv->olympic_network_monitor) 
441     			writew(swab16(OPEN_ADAPTER_ENABLE_FDX | OPEN_ADAPTER_PASS_ADC_MAC | OPEN_ADAPTER_PASS_ATT_MAC | OPEN_ADAPTER_PASS_BEACON), init_srb+8);
442     		else
443     			writew(swab16(OPEN_ADAPTER_ENABLE_FDX), init_srb+8);
444     
445     		if (olympic_priv->olympic_laa[0]) {
446     			writeb(olympic_priv->olympic_laa[0],init_srb+12);
447     			writeb(olympic_priv->olympic_laa[1],init_srb+13);
448     			writeb(olympic_priv->olympic_laa[2],init_srb+14);
449     			writeb(olympic_priv->olympic_laa[3],init_srb+15);
450     			writeb(olympic_priv->olympic_laa[4],init_srb+16);
451     			writeb(olympic_priv->olympic_laa[5],init_srb+17);
452     			memcpy(dev->dev_addr,olympic_priv->olympic_laa,dev->addr_len) ;  
453     		} 	
454     		writeb(1,init_srb+30);
455     	
456     		olympic_priv->srb_queued=1;
457     
458     		writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
459     
460     		t = jiffies ; 
461      		while(olympic_priv->srb_queued) {        
462             		interruptible_sleep_on_timeout(&olympic_priv->srb_wait, 60*HZ);
463             		if(signal_pending(current))	{            
464     				printk(KERN_WARNING "%s: Signal received in open.\n",
465                     			dev->name);
466                 			printk(KERN_WARNING "SISR=%x LISR=%x\n",
467                     			readl(olympic_mmio+SISR),
468                     			readl(olympic_mmio+LISR));
469                 			olympic_priv->srb_queued=0;
470                 			break;
471             		}
472     			if ((jiffies-t) > 60*HZ) { 
473     				printk(KERN_WARNING "%s: SRB timed out. \n",dev->name) ; 
474     				olympic_priv->srb_queued=0;
475     				break ; 
476     			} 
477         		}
478     		restore_flags(flags);
479     #if OLYMPIC_DEBUG
480     		printk("init_srb(%p): ",init_srb);
481     		for(i=0;i<20;i++)
482     			printk("%02x ",readb(init_srb+i));
483     		printk("\n");
484     #endif
485     		
486     		/* If we get the same return response as we set, the interrupt wasn't raised and the open
487                      * timed out.
488     		 */
489     
490     		if(readb(init_srb+2)== OLYMPIC_CLEAR_RET_CODE) {
491     			printk(KERN_WARNING "%s: Adapter Open time out or error.\n", dev->name) ; 
492     			return -EIO ; 
493     		}	
494     
495     		if(readb(init_srb+2)!=0) {
496     			if (readb(init_srb+2) == 0x07) {  
497     				if (!olympic_priv->olympic_ring_speed && open_finished) { /* Autosense , first time around */
498     					printk(KERN_WARNING "%s: Retrying at different ring speed \n", dev->name); 
499     					open_finished = 0 ;  
500     				} else {
501     
502     					strcpy(open_error, open_maj_error[(readb(init_srb+7) & 0xf0) >> 4]) ; 
503     					strcat(open_error," - ") ; 
504     					strcat(open_error, open_min_error[(readb(init_srb+7) & 0x0f)]) ;
505     
506     					if (!olympic_priv->olympic_ring_speed && ((readb(init_srb+7) & 0x0f) == 0x0d)) { 
507     						printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors present\n",dev->name);
508     						printk(KERN_WARNING "%s: Please try again with a specified ring speed \n",dev->name);
509     						free_irq(dev->irq, dev);
510     						return -EIO ;
511     					}
512     
513     					printk(KERN_WARNING "%s: %s\n",dev->name,open_error);
514     					free_irq(dev->irq,dev) ; 
515     					return -EIO ; 
516      
517     				}	/* if autosense && open_finished */
518     			} else {  
519     				printk(KERN_WARNING "%s: Bad OPEN response: %x\n", dev->name,init_srb[2]);
520     				free_irq(dev->irq, dev);
521     				return -EIO;
522     			} 
523     		} else 
524     			open_finished = 1 ; 
525     	} while (!(open_finished)) ; /* Will only loop if ring speed mismatch re-open attempted && autosense is on */	
526     
527     	if (readb(init_srb+18) & (1<<3)) 
528     		if (olympic_priv->olympic_message_level) 
529     			printk(KERN_INFO "%s: Opened in FDX Mode\n",dev->name);
530     
531     	if (readb(init_srb+18) & (1<<1))
532     		olympic_priv->olympic_ring_speed = 100 ; 
533     	else if (readb(init_srb+18) & 1)
534     		olympic_priv->olympic_ring_speed = 16 ; 
535     	else
536     		olympic_priv->olympic_ring_speed = 4 ; 
537     
538     	if (olympic_priv->olympic_message_level) 
539     		printk(KERN_INFO "%s: Opened in %d Mbps mode\n",dev->name, olympic_priv->olympic_ring_speed);
540     
541     	olympic_priv->asb = swab16(readw(init_srb+8));
542     	olympic_priv->srb = swab16(readw(init_srb+10));
543     	olympic_priv->arb = swab16(readw(init_srb+12));
544     	olympic_priv->trb = swab16(readw(init_srb+16));
545     
546     	olympic_priv->olympic_receive_options = 0x01 ; 
547     	olympic_priv->olympic_copy_all_options = 0 ; 
548     	
549     	/* setup rx ring */
550     	
551     	writel((3<<16),olympic_mmio+BMCTL_RWM); /* Ensure end of frame generated interrupts */ 
552     
553     	writel(BMCTL_RX_DIS|3,olympic_mmio+BMCTL_RWM); /* Yes, this the enables RX channel */
554     
555     	for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
556     
557     		struct sk_buff *skb;
558     		
559     		skb=dev_alloc_skb(olympic_priv->pkt_buf_sz);
560     		if(skb == NULL)
561     			break;
562     
563     		skb->dev = dev;
564     
565     		olympic_priv->olympic_rx_ring[i].buffer = cpu_to_le32(pci_map_single(olympic_priv->pdev, 
566     							  skb->data,olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)) ; 
567     		olympic_priv->olympic_rx_ring[i].res_length = cpu_to_le32(olympic_priv->pkt_buf_sz); 
568     		olympic_priv->rx_ring_skb[i]=skb;
569     	}
570     
571     	if (i==0) {
572     		printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled\n",dev->name);
573     		free_irq(dev->irq, dev);
574     		return -EIO;
575     	}
576     
577     	olympic_priv->rx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_rx_ring, 
578     					 sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
579     	writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXDESCQ);
580     	writel(olympic_priv->rx_ring_dma_addr, olympic_mmio+RXCDA);
581     	writew(i, olympic_mmio+RXDESCQCNT);
582     		
583     	olympic_priv->rx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_rx_status_ring, 
584     						sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
585     	writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXSTATQ);
586     	writel(olympic_priv->rx_status_ring_dma_addr, olympic_mmio+RXCSA);
587     	
588      	olympic_priv->rx_ring_last_received = OLYMPIC_RX_RING_SIZE - 1;	/* last processed rx status */
589     	olympic_priv->rx_status_last_received = OLYMPIC_RX_RING_SIZE - 1;  
590     
591     	writew(i, olympic_mmio+RXSTATQCNT);
592     
593     #if OLYMPIC_DEBUG 
594     	printk("# of rx buffers: %d, RXENQ: %x\n",i, readw(olympic_mmio+RXENQ));
595     	printk("RXCSA: %x, rx_status_ring[0]: %p\n",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
596     	printk(" stat_ring[1]: %p, stat_ring[2]: %p, stat_ring[3]: %p\n", &(olympic_priv->olympic_rx_status_ring[1]), &(olympic_priv->olympic_rx_status_ring[2]), &(olympic_priv->olympic_rx_status_ring[3]) );
597     	printk(" stat_ring[4]: %p, stat_ring[5]: %p, stat_ring[6]: %p\n", &(olympic_priv->olympic_rx_status_ring[4]), &(olympic_priv->olympic_rx_status_ring[5]), &(olympic_priv->olympic_rx_status_ring[6]) );
598     	printk(" stat_ring[7]: %p\n", &(olympic_priv->olympic_rx_status_ring[7])  );
599     
600     	printk("RXCDA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
601     	printk("Rx_ring_dma_addr = %08x, rx_status_dma_addr =
602     %08x\n",olympic_priv->rx_ring_dma_addr,olympic_priv->rx_status_ring_dma_addr) ; 
603     #endif
604     
605     	writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) | i,olympic_mmio+RXENQ);
606     
607     #if OLYMPIC_DEBUG 
608     	printk("# of rx buffers: %d, RXENQ: %x\n",i, readw(olympic_mmio+RXENQ));
609     	printk("RXCSA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCSA),&olympic_priv->olympic_rx_status_ring[0]);
610     	printk("RXCDA: %x, rx_ring[0]: %p\n",readl(olympic_mmio+RXCDA),&olympic_priv->olympic_rx_ring[0]);
611     #endif 
612     
613     	writel(SISR_RX_STATUS | SISR_RX_NOBUF,olympic_mmio+SISR_MASK_SUM);
614     
615     	/* setup tx ring */
616     
617     	writel(BMCTL_TX1_DIS,olympic_mmio+BMCTL_RWM); /* Yes, this enables TX channel 1 */
618     	for(i=0;i<OLYMPIC_TX_RING_SIZE;i++) 
619     		olympic_priv->olympic_tx_ring[i].buffer=0xdeadbeef;
620     
621     	olympic_priv->free_tx_ring_entries=OLYMPIC_TX_RING_SIZE;
622     	olympic_priv->tx_ring_dma_addr = pci_map_single(olympic_priv->pdev,olympic_priv->olympic_tx_ring,
623     					 sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE,PCI_DMA_TODEVICE) ; 
624     	writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXDESCQ_1);
625     	writel(olympic_priv->tx_ring_dma_addr, olympic_mmio+TXCDA_1);
626     	writew(OLYMPIC_TX_RING_SIZE, olympic_mmio+TXDESCQCNT_1);
627     	
628     	olympic_priv->tx_status_ring_dma_addr = pci_map_single(olympic_priv->pdev, olympic_priv->olympic_tx_status_ring,
629     						sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
630     	writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXSTATQ_1);
631     	writel(olympic_priv->tx_status_ring_dma_addr,olympic_mmio+TXCSA_1);
632     	writew(OLYMPIC_TX_RING_SIZE,olympic_mmio+TXSTATQCNT_1);
633     		
634     	olympic_priv->tx_ring_free=0; /* next entry in tx ring to use */
635     	olympic_priv->tx_ring_last_status=OLYMPIC_TX_RING_SIZE-1; /* last processed tx status */
636     
637     	writel(SISR_TX1_EOF | SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE,olympic_mmio+SISR_MASK_SUM);
638     
639     #if OLYMPIC_DEBUG 
640     	printk("BMCTL: %x\n",readl(olympic_mmio+BMCTL_SUM));
641     	printk("SISR MASK: %x\n",readl(olympic_mmio+SISR_MASK));
642     #endif
643     
644     	if (olympic_priv->olympic_network_monitor) { 
645     		u8 *oat ; 
646     		u8 *opt ; 
647     		oat = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr) ; 
648     		opt = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr) ; 
649     
650     		printk("%s: Node Address: %02x:%02x:%02x:%02x:%02x:%02x\n",dev->name, 
651     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)), 
652     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+1),
653     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+2),
654     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+3),
655     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+4),
656     			readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+5));
657     		printk("%s: Functional Address: %02x:%02x:%02x:%02x\n",dev->name, 
658     			readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)), 
659     			readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
660     			readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
661     			readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
662     		printk("%s: NAUN Address: %02x:%02x:%02x:%02x:%02x:%02x\n",dev->name, 
663     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)),
664     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+1),
665     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+2),
666     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+3),
667     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+4),
668     			readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+5));
669     	}
670     	
671     	netif_start_queue(dev);
672     	return 0;
673     	
674     }	
675     
676     /*
677      *	When we enter the rx routine we do not know how many frames have been 
678      *	queued on the rx channel.  Therefore we start at the next rx status
679      *	position and travel around the receive ring until we have completed
680      *	all the frames.
681      *
682      *	This means that we may process the frame before we receive the end
683      *	of frame interrupt. This is why we always test the status instead
684      *	of blindly processing the next frame.
685      *
686      *	We also remove the last 4 bytes from the packet as well, these are
687      *	just token ring trailer info and upset protocols that don't check 
688      *	their own length, i.e. SNA. 
689      *	
690      */
691     static void olympic_rx(struct net_device *dev)
692     {
693     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
694     	u8 *olympic_mmio=olympic_priv->olympic_mmio;
695     	struct olympic_rx_status *rx_status;
696     	struct olympic_rx_desc *rx_desc ; 
697     	int rx_ring_last_received,length, buffer_cnt, cpy_length, frag_len;
698     	struct sk_buff *skb, *skb2;
699     	int i;
700     
701     	rx_status=&(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received + 1) & (OLYMPIC_RX_RING_SIZE - 1)]) ; 
702      
703     	while (rx_status->status_buffercnt) { 
704                     u32 l_status_buffercnt;
705     
706     		olympic_priv->rx_status_last_received++ ;
707     		olympic_priv->rx_status_last_received &= (OLYMPIC_RX_RING_SIZE -1);
708     #if OLYMPIC_DEBUG
709     		printk("rx status: %x rx len: %x \n", le32_to_cpu(rx_status->status_buffercnt), le32_to_cpu(rx_status->fragmentcnt_framelen));
710     #endif
711     		length = le32_to_cpu(rx_status->fragmentcnt_framelen) & 0xffff;
712     		buffer_cnt = le32_to_cpu(rx_status->status_buffercnt) & 0xffff; 
713     		i = buffer_cnt ; /* Need buffer_cnt later for rxenq update */ 
714     		frag_len = le32_to_cpu(rx_status->fragmentcnt_framelen) >> 16; 
715     
716     #if OLYMPIC_DEBUG 
717     		printk("length: %x, frag_len: %x, buffer_cnt: %x\n", length, frag_len, buffer_cnt);
718     #endif
719                     l_status_buffercnt = le32_to_cpu(rx_status->status_buffercnt);
720     		if(l_status_buffercnt & 0xC0000000) {
721     			if (l_status_buffercnt & 0x3B000000) {
722     				if (olympic_priv->olympic_message_level) {
723     					if (l_status_buffercnt & (1<<29))  /* Rx Frame Truncated */
724     						printk(KERN_WARNING "%s: Rx Frame Truncated \n",dev->name);
725     					if (l_status_buffercnt & (1<<28)) /*Rx receive overrun */
726     						printk(KERN_WARNING "%s: Rx Frame Receive overrun \n",dev->name);
727     					if (l_status_buffercnt & (1<<27)) /* No receive buffers */
728     						printk(KERN_WARNING "%s: No receive buffers \n",dev->name);
729     					if (l_status_buffercnt & (1<<25)) /* Receive frame error detect */
730     						printk(KERN_WARNING "%s: Receive frame error detect \n",dev->name);
731     					if (l_status_buffercnt & (1<<24)) /* Received Error Detect */
732     						printk(KERN_WARNING "%s: Received Error Detect \n",dev->name);
733     				} 
734     				olympic_priv->rx_ring_last_received += i ; 
735     				olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ; 
736     				olympic_priv->olympic_stats.rx_errors++;	 
737     			} else {	
738     			
739     				if (buffer_cnt == 1) {
740     					skb = dev_alloc_skb(olympic_priv->pkt_buf_sz) ; 
741     				} else {
742     					skb = dev_alloc_skb(length) ; 
743     				}
744     
745     				if (skb == NULL) {
746     					printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers. \n",dev->name) ;
747     					olympic_priv->olympic_stats.rx_dropped++ ; 
748     					/* Update counters even though we don't transfer the frame */
749     					olympic_priv->rx_ring_last_received += i ; 
750     					olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1) ;  
751     				} else  {
752     					skb->dev = dev ; 
753     
754     					/* Optimise based upon number of buffers used. 
755     			   	   	   If only one buffer is used we can simply swap the buffers around.
756     			   	   	   If more than one then we must use the new buffer and copy the information
757     			   	   	   first. Ideally all frames would be in a single buffer, this can be tuned by
758                                    	   	   altering the buffer size. If the length of the packet is less than
759     					   1500 bytes we're going to copy it over anyway to stop packets getting
760     					   dropped from sockets with buffers small than our pkt_buf_sz. */
761     				
762      					if (buffer_cnt==1) {
763     						olympic_priv->rx_ring_last_received++ ; 
764     						olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
765     						rx_ring_last_received = olympic_priv->rx_ring_last_received ;
766     						if (length > 1500) { 
767     							skb2=olympic_priv->rx_ring_skb[rx_ring_last_received] ; 
768     							/* unmap buffer */
769     							pci_unmap_single(olympic_priv->pdev,
770     								le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer), 
771     								olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 
772     							skb_put(skb2,length-4);
773     							skb2->protocol = tr_type_trans(skb2,dev);
774     							olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer = 
775     								cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data, 
776     								olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
777     							olympic_priv->olympic_rx_ring[rx_ring_last_received].res_length = 
778     								cpu_to_le32(olympic_priv->pkt_buf_sz); 
779     							olympic_priv->rx_ring_skb[rx_ring_last_received] = skb ; 
780     							netif_rx(skb2) ; 
781     						} else { 
782     							pci_dma_sync_single(olympic_priv->pdev,
783     								le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
784     								olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 
785     							memcpy(skb_put(skb,length-4),olympic_priv->rx_ring_skb[rx_ring_last_received]->data,length-4) ; 
786     							skb->protocol = tr_type_trans(skb,dev) ; 
787     							netif_rx(skb) ; 
788     						} 
789     					} else {
790     						do { /* Walk the buffers */ 
791     							olympic_priv->rx_ring_last_received++ ; 
792     							olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE -1);
793     							rx_ring_last_received = olympic_priv->rx_ring_last_received ; 
794     							pci_dma_sync_single(olympic_priv->pdev,
795     								le32_to_cpu(olympic_priv->olympic_rx_ring[rx_ring_last_received].buffer),
796     								olympic_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 
797     							rx_desc = &(olympic_priv->olympic_rx_ring[rx_ring_last_received]);
798     							cpy_length = (i == 1 ? frag_len : le32_to_cpu(rx_desc->res_length)); 
799     							memcpy(skb_put(skb, cpy_length), olympic_priv->rx_ring_skb[rx_ring_last_received]->data, cpy_length) ;
800     						} while (--i) ; 
801     						skb_trim(skb,skb->len-4) ; 
802     						skb->protocol = tr_type_trans(skb,dev);
803     						netif_rx(skb) ; 
804     					} 
805     					dev->last_rx = jiffies ; 
806     					olympic_priv->olympic_stats.rx_packets++ ; 
807     					olympic_priv->olympic_stats.rx_bytes += length ; 
808     				} /* if skb == null */
809     			} /* If status & 0x3b */
810     
811     		} else { /*if buffercnt & 0xC */
812     			olympic_priv->rx_ring_last_received += i ; 
813     			olympic_priv->rx_ring_last_received &= (OLYMPIC_RX_RING_SIZE - 1) ; 
814     		} 
815     
816     		rx_status->fragmentcnt_framelen = 0 ; 
817     		rx_status->status_buffercnt = 0 ; 
818     		rx_status = &(olympic_priv->olympic_rx_status_ring[(olympic_priv->rx_status_last_received+1) & (OLYMPIC_RX_RING_SIZE -1) ]);
819     
820     		writew((((readw(olympic_mmio+RXENQ)) & 0x8000) ^ 0x8000) |  buffer_cnt , olympic_mmio+RXENQ); 
821     	} /* while */
822     
823     }
824     
825     static void olympic_interrupt(int irq, void *dev_id, struct pt_regs *regs) 
826     {
827     	struct net_device *dev= (struct net_device *)dev_id;
828     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
829     	u8 *olympic_mmio=olympic_priv->olympic_mmio;
830     	u32 sisr;
831     	u8 *adapter_check_area ; 
832     	
833     	/* 
834     	 *  Read sisr but don't reset it yet. 
835     	 *  The indication bit may have been set but the interrupt latch
836     	 *  bit may not be set, so we'd lose the interrupt later. 
837     	 */ 
838     	sisr=readl(olympic_mmio+SISR) ; 
839     	if (!(sisr & SISR_MI)) /* Interrupt isn't for us */ 
840     		return ;
841     	sisr=readl(olympic_mmio+SISR_RR) ;  /* Read & Reset sisr */ 
842     
843     	spin_lock(&olympic_priv->olympic_lock);
844     
845     	if (sisr & (SISR_SRB_REPLY | SISR_TX1_EOF | SISR_RX_STATUS | SISR_ADAPTER_CHECK |  
846     			SISR_ASB_FREE | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_RX_NOBUF)) {  
847     	
848     		if(sisr & SISR_SRB_REPLY) {
849     			if(olympic_priv->srb_queued==1) {
850     				wake_up_interruptible(&olympic_priv->srb_wait);
851     			} else if (olympic_priv->srb_queued==2) { 
852     				olympic_srb_bh(dev) ; 
853     			}
854     			olympic_priv->srb_queued=0;
855     		} /* SISR_SRB_REPLY */
856     
857     		/* We shouldn't ever miss the Tx interrupt, but the you never know, hence the loop to ensure
858     		   we get all tx completions. */
859     		if (sisr & SISR_TX1_EOF) {
860     			while(olympic_priv->olympic_tx_status_ring[(olympic_priv->tx_ring_last_status + 1) & (OLYMPIC_TX_RING_SIZE-1)].status) { 
861     				olympic_priv->tx_ring_last_status++;
862     				olympic_priv->tx_ring_last_status &= (OLYMPIC_TX_RING_SIZE-1);
863     				olympic_priv->free_tx_ring_entries++;
864     				olympic_priv->olympic_stats.tx_bytes += olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len;
865     				olympic_priv->olympic_stats.tx_packets++ ; 
866     				pci_unmap_single(olympic_priv->pdev, 
867     					le32_to_cpu(olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer), 
868     					olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]->len,PCI_DMA_TODEVICE);
869     				dev_kfree_skb_irq(olympic_priv->tx_ring_skb[olympic_priv->tx_ring_last_status]);
870     				olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_last_status].buffer=0xdeadbeef;
871     				olympic_priv->olympic_tx_status_ring[olympic_priv->tx_ring_last_status].status=0;
872     			}
873     			netif_wake_queue(dev);
874     		} /* SISR_TX1_EOF */
875     	
876     		if (sisr & SISR_RX_STATUS) {
877     			olympic_rx(dev);
878     		} /* SISR_RX_STATUS */
879     	
880     		if (sisr & SISR_ADAPTER_CHECK) {
881     			int i ; 
882     			netif_stop_queue(dev);
883     			printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:\n", dev->name);
884     			writel(readl(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
885     			adapter_check_area = (u8 *)(olympic_mmio+LAPWWO) ; 
886     			printk(KERN_WARNING "%s: Bytes %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",dev->name, readb(adapter_check_area+0), readb(adapter_check_area+1), readb(adapter_check_area+2), readb(adapter_check_area+3), readb(adapter_check_area+4), readb(adapter_check_area+5), readb(adapter_check_area+6), readb(adapter_check_area+7)) ; 
887     			/* The adapter is effectively dead, clean up and exit */
888     			for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
889     				dev_kfree_skb_irq(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
890     				if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != 0xdeadbeef) {
891     					pci_unmap_single(olympic_priv->pdev, 
892     						le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
893     						olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
894     				}
895     				olympic_priv->rx_status_last_received++;
896     				olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
897     			}
898     			/* unmap rings */
899     			pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr, 
900     				sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
901     			pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
902     				sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
903     
904     			pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr, 
905     				sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
906     			pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr, 
907     				sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
908     
909     			free_irq(dev->irq, dev) ;
910     			dev->stop = NULL ;  
911     			spin_unlock(&olympic_priv->olympic_lock) ; 
912     			return ; 
913     		} /* SISR_ADAPTER_CHECK */
914     	
915     		if (sisr & SISR_ASB_FREE) {
916     			/* Wake up anything that is waiting for the asb response */  
917     			if (olympic_priv->asb_queued) {
918     				olympic_asb_bh(dev) ; 
919     			}
920     		} /* SISR_ASB_FREE */
921     	
922     		if (sisr & SISR_ARB_CMD) {
923     			olympic_arb_cmd(dev) ; 
924     		} /* SISR_ARB_CMD */
925     	
926     		if (sisr & SISR_TRB_REPLY) {
927     			/* Wake up anything that is waiting for the trb response */
928     			if (olympic_priv->trb_queued) {
929     				wake_up_interruptible(&olympic_priv->trb_wait);
930     			}
931     			olympic_priv->trb_queued = 0 ; 
932     		} /* SISR_TRB_REPLY */	
933     	
934     		if (sisr & SISR_RX_NOBUF) {
935     			/* According to the documentation, we don't have to do anything, but trapping it keeps it out of
936                       	   	   /var/log/messages.  */
937     		} /* SISR_RX_NOBUF */
938     	} else { 
939     		printk(KERN_WARNING "%s: Unexpected interrupt: %x\n",dev->name, sisr);
940     		printk(KERN_WARNING "%s: SISR_MASK: %x\n",dev->name, readl(olympic_mmio+SISR_MASK)) ;
941     	} /* One if the interrupts we want */
942     	writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);
943     	
944     	spin_unlock(&olympic_priv->olympic_lock) ; 
945     }	
946     
947     static int olympic_xmit(struct sk_buff *skb, struct net_device *dev) 
948     {
949     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
950     	u8 *olympic_mmio=olympic_priv->olympic_mmio;
951     	unsigned long flags ; 
952     
953     	spin_lock_irqsave(&olympic_priv->olympic_lock, flags);
954     
955     	netif_stop_queue(dev);
956     	
957     	if(olympic_priv->free_tx_ring_entries) {
958     		olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].buffer = 
959     			cpu_to_le32(pci_map_single(olympic_priv->pdev, skb->data, skb->len,PCI_DMA_TODEVICE));
960     		olympic_priv->olympic_tx_ring[olympic_priv->tx_ring_free].status_length = cpu_to_le32(skb->len | (0x80000000));
961     		olympic_priv->tx_ring_skb[olympic_priv->tx_ring_free]=skb;
962     		olympic_priv->free_tx_ring_entries--;
963     
964             	olympic_priv->tx_ring_free++;
965             	olympic_priv->tx_ring_free &= (OLYMPIC_TX_RING_SIZE-1);
966     		writew((((readw(olympic_mmio+TXENQ_1)) & 0x8000) ^ 0x8000) | 1,olympic_mmio+TXENQ_1);
967     		netif_wake_queue(dev);
968     		spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
969     		return 0;
970     	} else {
971     		spin_unlock_irqrestore(&olympic_priv->olympic_lock,flags);
972     		return 1;
973     	} 
974     
975     }
976     	
977     
978     static int olympic_close(struct net_device *dev) 
979     {
980     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
981         	u8 *olympic_mmio=olympic_priv->olympic_mmio,*srb;
982     	unsigned long t,flags;
983     	int i;
984     
985     	netif_stop_queue(dev);
986     	
987     	writel(olympic_priv->srb,olympic_mmio+LAPA);
988     	srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
989     	
990         	writeb(SRB_CLOSE_ADAPTER,srb+0);
991     	writeb(0,srb+1);
992     	writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
993     
994     	save_flags(flags);
995     	cli();	
996     
997     	olympic_priv->srb_queued=1;
998     
999     	writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
1000     	
1001     	t = jiffies ; 
1002     	while(olympic_priv->srb_queued) {
1003     	        interruptible_sleep_on_timeout(&olympic_priv->srb_wait, jiffies+60*HZ);
1004             	if(signal_pending(current))	{            
1005     			printk(KERN_WARNING "%s: SRB timed out.\n",dev->name);
1006                 		printk(KERN_WARNING "SISR=%x MISR=%x\n",readl(olympic_mmio+SISR),readl(olympic_mmio+LISR));
1007                 		olympic_priv->srb_queued=0;
1008                 		break;
1009             	}
1010     		if ((jiffies-t) > 60*HZ) { 
1011     			printk(KERN_WARNING "%s: SRB timed out. May not be fatal. \n",dev->name) ; 
1012     			olympic_priv->srb_queued=0;
1013     			break ; 
1014     		} 
1015         	}
1016     
1017     	restore_flags(flags) ; 
1018     	olympic_priv->rx_status_last_received++;
1019     	olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
1020     	
1021     	for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
1022     		dev_kfree_skb(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
1023     		if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != 0xdeadbeef) {
1024     			pci_unmap_single(olympic_priv->pdev, 
1025     				le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
1026     				olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
1027     		}
1028     		olympic_priv->rx_status_last_received++;
1029     		olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
1030     	}
1031     	/* unmap rings */
1032     	pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr, 
1033     		sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
1034     	pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
1035     		sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
1036     
1037     	pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr, 
1038     		sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
1039     	pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr, 
1040     		sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
1041     
1042     	/* reset tx/rx fifo's and busmaster logic */
1043     
1044     	writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
1045     	udelay(1);
1046     	writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
1047     
1048     #if OLYMPIC_DEBUG
1049     	printk("srb(%p): ",srb);
1050     	for(i=0;i<4;i++)
1051     		printk("%x ",readb(srb+i));
1052     	printk("\n");
1053     #endif
1054     	free_irq(dev->irq,dev);
1055     
1056     	return 0;
1057     	
1058     }
1059     
1060     static void olympic_set_rx_mode(struct net_device *dev) 
1061     {
1062     	struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
1063        	u8 *olympic_mmio = olympic_priv->olympic_mmio ; 
1064     	u8 options = 0; 
1065     	u8 *srb;
1066     	struct dev_mc_list *dmi ; 
1067     	unsigned char dev_mc_address[4] ; 
1068     	int i ; 
1069     
1070     	writel(olympic_priv->srb,olympic_mmio+LAPA);
1071     	srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
1072     	options = olympic_priv->olympic_copy_all_options; 
1073     
1074     	if (dev->flags&IFF_PROMISC)  
1075     		options |= 0x61 ;
1076     	else
1077     		options &= ~0x61 ; 
1078     
1079     	/* Only issue the srb if there is a change in options */
1080     
1081     	if ((options ^ olympic_priv->olympic_copy_all_options)) { 
1082     	
1083     		/* Now to issue the srb command to alter the copy.all.options */
1084     	
1085     		writeb(SRB_MODIFY_RECEIVE_OPTIONS,srb);
1086     		writeb(0,srb+1);
1087     		writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
1088     		writeb(0,srb+3);
1089     		writeb(olympic_priv->olympic_receive_options,srb+4);
1090     		writeb(options,srb+5);
1091     
1092     		olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
1093     
1094     		writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
1095     
1096     		olympic_priv->olympic_copy_all_options = options ;
1097     		
1098     		return ;  
1099     	} 
1100     
1101     	/* Set the functional addresses we need for multicast */
1102     
1103     	dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ; 
1104     
1105     	for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) { 
1106     		dev_mc_address[0] |= dmi->dmi_addr[2] ; 
1107     		dev_mc_address[1] |= dmi->dmi_addr[3] ; 
1108     		dev_mc_address[2] |= dmi->dmi_addr[4] ; 
1109     		dev_mc_address[3] |= dmi->dmi_addr[5] ; 
1110     	}
1111     
1112     	writeb(SRB_SET_FUNC_ADDRESS,srb+0);
1113     	writeb(0,srb+1);
1114     	writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
1115     	writeb(0,srb+3);
1116     	writeb(0,srb+4);
1117     	writeb(0,srb+5);
1118     	writeb(dev_mc_address[0],srb+6);
1119     	writeb(dev_mc_address[1],srb+7);
1120     	writeb(dev_mc_address[2],srb+8);
1121     	writeb(dev_mc_address[3],srb+9);
1122     
1123     	olympic_priv->srb_queued = 2 ;
1124     	writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
1125     
1126     }
1127     
1128     static void olympic_srb_bh(struct net_device *dev) 
1129     { 
1130     	struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
1131        	u8 *olympic_mmio = olympic_priv->olympic_mmio ; 
1132     	u8 *srb;
1133     
1134     	writel(olympic_priv->srb,olympic_mmio+LAPA);
1135     	srb=olympic_priv->olympic_lap + (olympic_priv->srb & (~0xf800));
1136     
1137     	switch (readb(srb)) { 
1138     
1139     		/* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous) 
1140                      * At some point we should do something if we get an error, such as
1141                      * resetting the IFF_PROMISC flag in dev
1142     		 */
1143     
1144     		case SRB_MODIFY_RECEIVE_OPTIONS:
1145     			switch (readb(srb+2)) { 
1146     				case 0x01:
1147     					printk(KERN_WARNING "%s: Unrecognized srb command\n",dev->name) ; 
1148     					break ; 
1149     				case 0x04:
1150     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name);
1151     					break ; 
1152     				default:
1153     					if (olympic_priv->olympic_message_level) 
1154     						printk(KERN_WARNING "%s: Receive Options Modified to %x,%x\n",dev->name,olympic_priv->olympic_copy_all_options, olympic_priv->olympic_receive_options) ; 
1155     					break ; 	
1156     			} /* switch srb[2] */ 
1157     			break ;
1158     		
1159     		/* SRB_SET_GROUP_ADDRESS - Multicast group setting 
1160                      */
1161     
1162     		case SRB_SET_GROUP_ADDRESS:
1163     			switch (readb(srb+2)) { 
1164     				case 0x00:
1165     					break ; 
1166     				case 0x01:
1167     					printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name) ; 
1168     					break ;
1169     				case 0x04:
1170     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name); 
1171     					break ;
1172     				case 0x3c:
1173     					printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctly\n",dev->name) ; 
1174     					break ;
1175     				case 0x3e: /* If we ever implement individual multicast addresses, will need to deal with this */
1176     					printk(KERN_WARNING "%s: Group address registers full\n",dev->name) ; 
1177     					break ;  
1178     				case 0x55:
1179     					printk(KERN_INFO "%s: Group Address already set.\n",dev->name) ; 
1180     					break ;
1181     				default:
1182     					break ; 
1183     			} /* switch srb[2] */ 
1184     			break ; 
1185     
1186     		/* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list
1187      		 */
1188     
1189     		case SRB_RESET_GROUP_ADDRESS:
1190     			switch (readb(srb+2)) { 
1191     				case 0x00:
1192     					break ; 
1193     				case 0x01:
1194     					printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name) ; 
1195     					break ; 
1196     				case 0x04:
1197     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ; 
1198     					break ; 
1199     				case 0x39: /* Must deal with this if individual multicast addresses used */
1200     					printk(KERN_INFO "%s: Group address not found \n",dev->name); 
1201     					break ;
1202     				default:
1203     					break ; 
1204     			} /* switch srb[2] */
1205     			break ; 
1206     
1207     		
1208     		/* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode 
1209     		 */
1210     
1211     		case SRB_SET_FUNC_ADDRESS:
1212     			switch (readb(srb+2)) { 
1213     				case 0x00:
1214     					if (olympic_priv->olympic_message_level)
1215     						printk(KERN_INFO "%s: Functional Address Mask Set \n",dev->name) ; 
1216     					break ;
1217     				case 0x01:
1218     					printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name) ; 
1219     					break ; 
1220     				case 0x04:
1221     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ; 
1222     					break ; 
1223     				default:
1224     					break ; 
1225     			} /* switch srb[2] */
1226     			break ; 
1227     	
1228     		/* SRB_READ_LOG - Read and reset the adapter error counters
1229      		 */
1230     
1231     		case SRB_READ_LOG:
1232     			switch (readb(srb+2)) { 
1233     				case 0x00: 
1234     					if (olympic_priv->olympic_message_level) 
1235     						printk(KERN_INFO "%s: Read Log issued\n",dev->name) ; 
1236     					break ; 
1237     				case 0x01:
1238     					printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name) ; 
1239     					break ; 
1240     				case 0x04:
1241     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ; 
1242     					break ; 
1243     			
1244     			} /* switch srb[2] */
1245     			break ; 
1246     		
1247     		/* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */
1248     
1249     		case SRB_READ_SR_COUNTERS:
1250     			switch (readb(srb+2)) { 
1251     				case 0x00: 
1252     					if (olympic_priv->olympic_message_level) 
1253     						printk(KERN_INFO "%s: Read Source Routing Counters issued\n",dev->name) ; 
1254     					break ; 
1255     				case 0x01:
1256     					printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name) ; 
1257     					break ; 
1258     				case 0x04:
1259     					printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n",dev->name) ; 
1260     					break ; 
1261     				default:
1262     					break ; 
1263     			} /* switch srb[2] */
1264     			break ;
1265      
1266     		default:
1267     			printk(KERN_WARNING "%s: Unrecognized srb bh return value.\n",dev->name);
1268     			break ; 
1269     	} /* switch srb[0] */
1270     
1271     } 
1272     
1273     static struct net_device_stats * olympic_get_stats(struct net_device *dev)
1274     {
1275     	struct olympic_private *olympic_priv ;
1276     	olympic_priv=(struct olympic_private *) dev->priv;
1277     	return (struct net_device_stats *) &olympic_priv->olympic_stats; 
1278     }
1279     
1280     static int olympic_set_mac_address (struct net_device *dev, void *addr) 
1281     {
1282     	struct sockaddr *saddr = addr ; 
1283     	struct olympic_private *olympic_priv = (struct olympic_private *)dev->priv ; 
1284     
1285     	if (netif_running(dev)) { 
1286     		printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name) ; 
1287     		return -EIO ; 
1288     	}
1289     
1290     	memcpy(olympic_priv->olympic_laa, saddr->sa_data,dev->addr_len) ; 
1291     	
1292     	if (olympic_priv->olympic_message_level) { 
1293      		printk(KERN_INFO "%s: MAC/LAA Set to  = %x.%x.%x.%x.%x.%x\n",dev->name, olympic_priv->olympic_laa[0],
1294     		olympic_priv->olympic_laa[1], olympic_priv->olympic_laa[2],
1295     		olympic_priv->olympic_laa[3], olympic_priv->olympic_laa[4],
1296     		olympic_priv->olympic_laa[5]);
1297     	} 
1298     
1299     	return 0 ; 
1300     }
1301     
1302     static void olympic_arb_cmd(struct net_device *dev)
1303     {
1304     	struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv;
1305         	u8 *olympic_mmio=olympic_priv->olympic_mmio;
1306     	u8 *arb_block, *asb_block, *srb  ; 
1307     	u8 header_len ; 
1308     	u16 frame_len, buffer_len ;
1309     	struct sk_buff *mac_frame ;  
1310     	u8 *buf_ptr ;
1311     	u8 *frame_data ;  
1312     	u16 buff_off ; 
1313     	u16 lan_status = 0, lan_status_diff  ; /* Initialize to stop compiler warning */
1314     	u8 fdx_prot_error ; 
1315     	u16 next_ptr;
1316     	int i ; 
1317     
1318     	arb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->arb) ; 
1319     	asb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->asb) ; 
1320     	srb = (u8 *)(olympic_priv->olympic_lap + olympic_priv->srb) ; 
1321     	writel(readl(olympic_mmio+LAPA),olympic_mmio+LAPWWO);
1322     
1323     	if (readb(arb_block+0) == ARB_RECEIVE_DATA) { /* Receive.data, MAC frames */
1324     
1325     		header_len = readb(arb_block+8) ; /* 802.5 Token-Ring Header Length */	
1326     		frame_len = swab16(readw(arb_block + 10)) ; 
1327     
1328     		buff_off = swab16(readw(arb_block + 6)) ;
1329     		
1330     		buf_ptr = olympic_priv->olympic_lap + buff_off ; 
1331     
1332     #if OLYMPIC_DEBUG
1333     {
1334     		int i;
1335     		frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ; 
1336     
1337     		for (i=0 ;  i < 14 ; i++) { 
1338     			printk("Loc %d = %02x\n",i,readb(frame_data + i)); 
1339     		}
1340     
1341     		printk("next %04x, fs %02x, len %04x \n",readw(buf_ptr+offsetof(struct mac_receive_buffer,next)), readb(buf_ptr+offsetof(struct mac_receive_buffer,frame_status)), readw(buf_ptr+offsetof(struct mac_receive_buffer,buffer_length))); 
1342     }
1343     #endif 
1344     		mac_frame = dev_alloc_skb(frame_len) ; 
1345     		if (!mac_frame) {
1346     			printk(KERN_WARNING "%s: Memory squeeze, dropping frame.\n", dev->name);
1347     			goto drop_frame;
1348     		}
1349     
1350     		/* Walk the buffer chain, creating the frame */
1351     
1352     		do {
1353     			frame_data = buf_ptr+offsetof(struct mac_receive_buffer,frame_data) ; 
1354     			buffer_len = swab16(readw(buf_ptr+offsetof(struct mac_receive_buffer,buffer_length))); 
1355     			memcpy_fromio(skb_put(mac_frame, buffer_len), frame_data , buffer_len ) ;
1356     			next_ptr=readw(buf_ptr+offsetof(struct mac_receive_buffer,next)); 
1357     		} while (next_ptr && (buf_ptr=olympic_priv->olympic_lap + ntohs(next_ptr)));
1358     
1359     		if (olympic_priv->olympic_network_monitor) { 
1360     			struct trh_hdr *mac_hdr ; 
1361     			printk(KERN_WARNING "%s: Received MAC Frame, details: \n",dev->name) ;
1362     			mac_hdr = (struct trh_hdr *)mac_frame->data ; 
1363     			printk(KERN_WARNING "%s: MAC Frame Dest. Addr: %02x:%02x:%02x:%02x:%02x:%02x \n", dev->name , mac_hdr->daddr[0], mac_hdr->daddr[1], mac_hdr->daddr[2], mac_hdr->daddr[3], mac_hdr->daddr[4], mac_hdr->daddr[5]) ; 
1364     			printk(KERN_WARNING "%s: MAC Frame Srce. Addr: %02x:%02x:%02x:%02x:%02x:%02x \n", dev->name , mac_hdr->saddr[0], mac_hdr->saddr[1], mac_hdr->saddr[2], mac_hdr->saddr[3], mac_hdr->saddr[4], mac_hdr->saddr[5]) ; 
1365     		}
1366     		mac_frame->dev = dev ; 
1367     		mac_frame->protocol = tr_type_trans(mac_frame,dev);
1368     		netif_rx(mac_frame) ; 	
1369     		dev->last_rx = jiffies;
1370     
1371     drop_frame:
1372     		/* Now tell the card we have dealt with the received frame */
1373     
1374     		/* Set LISR Bit 1 */
1375     		writel(LISR_ARB_FREE,olympic_priv->olympic_lap + LISR_SUM);
1376     
1377     		/* Is the ASB free ? */ 	
1378     		
1379     		if (readb(asb_block + 2) != 0xff) { 
1380     			olympic_priv->asb_queued = 1 ; 
1381     			writel(LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM); 
1382     			return ; 	
1383     			/* Drop out and wait for the bottom half to be run */
1384     		}
1385     		
1386     		writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
1387     		writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
1388     		writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
1389     		writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */		
1390     
1391     		writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
1392     		
1393     		olympic_priv->asb_queued = 2 ; 
1394     	
1395     		return ; 	
1396     		
1397     	} else if (readb(arb_block) == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */
1398     		lan_status = swab16(readw(arb_block+6));
1399     		fdx_prot_error = readb(arb_block+8) ; 
1400     		
1401     		/* Issue ARB Free */
1402     		writel(LISR_ARB_FREE,olympic_priv->olympic_mmio+LISR_SUM);
1403     
1404     		lan_status_diff = olympic_priv->olympic_lan_status ^ lan_status ; 
1405     
1406     		if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR) ) { 
1407     			if (lan_status_diff & LSC_LWF) 
1408     					printk(KERN_WARNING "%s: Short circuit detected on the lobe\n",dev->name);
1409     			if (lan_status_diff & LSC_ARW) 
1410     					printk(KERN_WARNING "%s: Auto removal error\n",dev->name);
1411     			if (lan_status_diff & LSC_FPE)
1412     					printk(KERN_WARNING "%s: FDX Protocol Error\n",dev->name);
1413     			if (lan_status_diff & LSC_RR) 
1414     					printk(KERN_WARNING "%s: Force remove MAC frame received\n",dev->name);
1415     		
1416     			/* Adapter has been closed by the hardware */
1417     		
1418     			/* reset tx/rx fifo's and busmaster logic */
1419     
1420     			writel(readl(olympic_mmio+BCTL)|(3<<13),olympic_mmio+BCTL);
1421     			udelay(1);
1422     			writel(readl(olympic_mmio+BCTL)&~(3<<13),olympic_mmio+BCTL);
1423     			netif_stop_queue(dev);
1424     			olympic_priv->srb = readw(olympic_priv->olympic_lap + LAPWWO) ; 
1425     			for(i=0;i<OLYMPIC_RX_RING_SIZE;i++) {
1426     				dev_kfree_skb_irq(olympic_priv->rx_ring_skb[olympic_priv->rx_status_last_received]);
1427     				if (olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer != 0xdeadbeef) {
1428     					pci_unmap_single(olympic_priv->pdev, 
1429     						le32_to_cpu(olympic_priv->olympic_rx_ring[olympic_priv->rx_status_last_received].buffer),
1430     						olympic_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
1431     				}
1432     				olympic_priv->rx_status_last_received++;
1433     				olympic_priv->rx_status_last_received&=OLYMPIC_RX_RING_SIZE-1;
1434     			}
1435     			/* unmap rings */
1436     			pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_status_ring_dma_addr, 
1437     				sizeof(struct olympic_rx_status) * OLYMPIC_RX_RING_SIZE, PCI_DMA_FROMDEVICE);
1438     			pci_unmap_single(olympic_priv->pdev, olympic_priv->rx_ring_dma_addr,
1439     				sizeof(struct olympic_rx_desc) * OLYMPIC_RX_RING_SIZE, PCI_DMA_TODEVICE);
1440     
1441     			pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_status_ring_dma_addr, 
1442     				sizeof(struct olympic_tx_status) * OLYMPIC_TX_RING_SIZE, PCI_DMA_FROMDEVICE);
1443     			pci_unmap_single(olympic_priv->pdev, olympic_priv->tx_ring_dma_addr, 
1444     				sizeof(struct olympic_tx_desc) * OLYMPIC_TX_RING_SIZE, PCI_DMA_TODEVICE);
1445     
1446     			free_irq(dev->irq,dev);
1447     			dev->stop=NULL;
1448     			printk(KERN_WARNING "%s: Adapter has been closed \n", dev->name) ; 
1449     		} /* If serious error */
1450     		
1451     		if (olympic_priv->olympic_message_level) { 
1452     			if (lan_status_diff & LSC_SIG_LOSS) 
1453     					printk(KERN_WARNING "%s: No receive signal detected \n", dev->name) ; 
1454     			if (lan_status_diff & LSC_HARD_ERR)
1455     					printk(KERN_INFO "%s: Beaconing \n",dev->name);
1456     			if (lan_status_diff & LSC_SOFT_ERR)
1457     					printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n",dev->name);
1458     			if (lan_status_diff & LSC_TRAN_BCN) 
1459     					printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n",dev->name);
1460     			if (lan_status_diff & LSC_SS) 
1461     					printk(KERN_INFO "%s: Single Station on the ring \n", dev->name);
1462     			if (lan_status_diff & LSC_RING_REC)
1463     					printk(KERN_INFO "%s: Ring recovery ongoing\n",dev->name);
1464     			if (lan_status_diff & LSC_FDX_MODE)
1465     					printk(KERN_INFO "%s: Operating in FDX mode\n",dev->name);
1466     		} 	
1467     		
1468     		if (lan_status_diff & LSC_CO) { 
1469     					
1470     				if (olympic_priv->olympic_message_level) 
1471     					printk(KERN_INFO "%s: Counter Overflow \n", dev->name);
1472     					
1473     				/* Issue READ.LOG command */
1474     
1475     				writeb(SRB_READ_LOG, srb);
1476     				writeb(0,srb+1);
1477     				writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
1478     				writeb(0,srb+3);
1479     				writeb(0,srb+4);
1480     				writeb(0,srb+5);
1481     					
1482     				olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
1483     
1484     				writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
1485     					
1486     		}
1487     
1488     		if (lan_status_diff & LSC_SR_CO) { 
1489     
1490     				if (olympic_priv->olympic_message_level)
1491     					printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name);
1492     
1493     				/* Issue a READ.SR.COUNTERS */
1494     				
1495     				writeb(SRB_READ_SR_COUNTERS,srb);
1496     				writeb(0,srb+1);
1497     				writeb(OLYMPIC_CLEAR_RET_CODE,srb+2);
1498     				writeb(0,srb+3);
1499     				
1500     				olympic_priv->srb_queued=2; /* Can't sleep, use srb_bh */
1501     
1502     				writel(LISR_SRB_CMD,olympic_mmio+LISR_SUM);
1503     
1504     		}
1505     
1506     		olympic_priv->olympic_lan_status = lan_status ; 
1507     	
1508     	}  /* Lan.change.status */
1509     	else
1510     		printk(KERN_WARNING "%s: Unknown arb command \n", dev->name);
1511     }
1512     
1513     static void olympic_asb_bh(struct net_device *dev) 
1514     {
1515     	struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv ; 
1516     	u8 *arb_block, *asb_block ; 
1517     
1518     	arb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->arb) ; 
1519     	asb_block = (u8 *)(olympic_priv->olympic_lap + olympic_priv->asb) ; 
1520     
1521     	if (olympic_priv->asb_queued == 1) {   /* Dropped through the first time */
1522     
1523     		writeb(ASB_RECEIVE_DATA,asb_block); /* Receive data */
1524     		writeb(OLYMPIC_CLEAR_RET_CODE,asb_block+2); /* Necessary ?? */
1525     		writeb(readb(arb_block+6),asb_block+6); /* Must send the address back to the adapter */
1526     		writeb(readb(arb_block+7),asb_block+7); /* To let it know we have dealt with the data */		
1527     
1528     		writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ,olympic_priv->olympic_mmio+LISR_SUM);
1529     		olympic_priv->asb_queued = 2 ; 
1530     
1531     		return ; 
1532     	}
1533     
1534     	if (olympic_priv->asb_queued == 2) { 
1535     		switch (readb(asb_block+2)) {
1536     			case 0x01:
1537     				printk(KERN_WARNING "%s: Unrecognized command code \n", dev->name);
1538     				break ;
1539     			case 0x26:
1540     				printk(KERN_WARNING "%s: Unrecognized buffer address \n", dev->name);
1541     				break ;
1542     			case 0xFF:
1543     				/* Valid response, everything should be ok again */
1544     				break ;
1545     			default:
1546     				printk(KERN_WARNING "%s: Invalid return code in asb\n",dev->name);
1547     				break ;
1548     		}
1549     	}
1550     	olympic_priv->asb_queued = 0 ; 
1551     }
1552      
1553     static int olympic_change_mtu(struct net_device *dev, int mtu) 
1554     {
1555     	struct olympic_private *olympic_priv = (struct olympic_private *) dev->priv;
1556     	u16 max_mtu ; 
1557     
1558     	if (olympic_priv->olympic_ring_speed == 4)
1559     		max_mtu = 4500 ; 
1560     	else
1561     		max_mtu = 18000 ; 
1562     	
1563     	if (mtu > max_mtu)
1564     		return -EINVAL ; 
1565     	if (mtu < 100) 
1566     		return -EINVAL ; 
1567     
1568     	dev->mtu = mtu ; 
1569     	olympic_priv->pkt_buf_sz = mtu + TR_HLEN ; 
1570     
1571     	return 0 ; 
1572     }
1573     
1574     static int olympic_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
1575     {
1576     	struct net_device *dev = (struct net_device *)data ; 
1577     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
1578     	u8 *oat = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_addr_table_addr) ; 
1579     	u8 *opt = (u8 *)(olympic_priv->olympic_lap + olympic_priv->olympic_parms_addr) ; 
1580     	int size = 0 ; 
1581     	int len=0;
1582     	off_t begin=0;
1583     	off_t pos=0;
1584     	
1585     	size = sprintf(buffer, 
1586     		"IBM Pit/Pit-Phy/Olympic Chipset Token Ring Adapter %s\n",dev->name);
1587     	size += sprintf(buffer+size, "\n%6s: Adapter Address   : Node Address      : Functional Addr\n",
1588      	   dev->name); 
1589     
1590     	size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x\n",
1591     	   dev->name,
1592                dev->dev_addr[0],
1593     	   dev->dev_addr[1],
1594     	   dev->dev_addr[2],
1595      	   dev->dev_addr[3],
1596     	   dev->dev_addr[4],
1597     	   dev->dev_addr[5],
1598     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)), 
1599     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+1),
1600     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+2),
1601     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+3),
1602     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+4),
1603     	   readb(oat+offsetof(struct olympic_adapter_addr_table,node_addr)+5),
1604     	   readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)), 
1605     	   readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+1),
1606     	   readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+2),
1607     	   readb(oat+offsetof(struct olympic_adapter_addr_table,func_addr)+3));
1608     	 
1609     	size += sprintf(buffer+size, "\n%6s: Token Ring Parameters Table:\n", dev->name);
1610     
1611     	size += sprintf(buffer+size, "%6s: Physical Addr : Up Node Address   : Poll Address      : AccPri : Auth Src : Att Code :\n",
1612     	  dev->name) ; 
1613     	   
1614     	size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x   : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %04x   : %04x     :  %04x    :\n",
1615     	  dev->name,
1616     	  readb(opt+offsetof(struct olympic_parameters_table, phys_addr)),
1617     	  readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+1),
1618     	  readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+2),
1619     	  readb(opt+offsetof(struct olympic_parameters_table, phys_addr)+3),
1620     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)),
1621     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+1),
1622     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+2),
1623     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+3),
1624     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+4),
1625     	  readb(opt+offsetof(struct olympic_parameters_table, up_node_addr)+5),
1626     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)),
1627     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+1),
1628     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+2),
1629     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+3),
1630     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+4),
1631     	  readb(opt+offsetof(struct olympic_parameters_table, poll_addr)+5),
1632     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, acc_priority))),
1633     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, auth_source_class))),
1634     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, att_code))));
1635     
1636     	size += sprintf(buffer+size, "%6s: Source Address    : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : \n",
1637     	  dev->name) ; 
1638     	
1639     	size += sprintf(buffer+size, "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %04x  : %04x   : %04x   : %04x   : %04x    :     %04x     : \n",
1640     	  dev->name,
1641     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)),
1642     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)+1),
1643     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)+2),
1644     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)+3),
1645     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)+4),
1646     	  readb(opt+offsetof(struct olympic_parameters_table, source_addr)+5),
1647     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_type))),
1648     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, major_vector))),
1649     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, lan_status))),
1650     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, local_ring))),
1651     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, mon_error))),
1652     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, frame_correl))));
1653     
1654     	size += sprintf(buffer+size, "%6s: Beacon Details :  Tx  :  Rx  : NAUN Node Address : NAUN Node Phys : \n",
1655     	  dev->name) ; 
1656     
1657     	size += sprintf(buffer+size, "%6s:                :  %02x  :  %02x  : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x    : \n",
1658     	  dev->name,
1659     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_transmit))),
1660     	  swab16(readw(opt+offsetof(struct olympic_parameters_table, beacon_receive))),
1661     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)),
1662     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+1),
1663     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+2),
1664     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+3),
1665     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+4),
1666     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_naun)+5),
1667     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)),
1668     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+1),
1669     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+2),
1670     	  readb(opt+offsetof(struct olympic_parameters_table, beacon_phys)+3));
1671     
1672     	len=size;
1673     	pos=begin+size;
1674     	if (pos<offset) {
1675     		len=0;
1676     		begin=pos;
1677     	}
1678     	*start=buffer+(offset-begin);	/* Start of wanted data */
1679     	len-=(offset-begin);		/* Start slop */
1680     	if(len>length)
1681     		len=length;		/* Ending slop */
1682     	return len;
1683     }
1684     
1685     static void __devexit olympic_remove_one(struct pci_dev *pdev) 
1686     {
1687     	struct net_device *dev = pdev->driver_data ; 
1688     	struct olympic_private *olympic_priv=(struct olympic_private *)dev->priv;
1689     
1690     	if (olympic_priv->olympic_network_monitor) { 
1691     		char proc_name[20] ; 
1692     		strcpy(proc_name,"net/olympic_") ; 
1693     		strcat(proc_name,dev->name) ;
1694     		remove_proc_entry(proc_name,NULL); 
1695     	}
1696     	unregister_trdev(dev) ; 
1697     	iounmap(olympic_priv->olympic_mmio) ; 
1698     	iounmap(olympic_priv->olympic_lap) ; 
1699     	pci_release_regions(pdev) ;
1700     	pci_set_drvdata(pdev,NULL) ;  	
1701     	kfree(dev) ; 
1702     }
1703     
1704     static struct pci_driver olympic_driver = { 
1705     	name:		"olympic",
1706     	id_table:	olympic_pci_tbl,
1707     	probe:		olympic_probe,
1708     	remove:		olympic_remove_one
1709     };
1710     
1711     static int __init olympic_pci_init(void) 
1712     {
1713     	return pci_module_init (&olympic_driver) ; 
1714     }
1715     
1716     static void __exit olympic_pci_cleanup(void)
1717     {
1718     	return pci_unregister_driver(&olympic_driver) ; 
1719     }	
1720     
1721     
1722     module_init(olympic_pci_init) ; 
1723     module_exit(olympic_pci_cleanup) ; 
1724     
1725     MODULE_LICENSE("GPL");
1726