Merge branch 'omap2-clock' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind...
[linux-2.6] / drivers / net / tokenring / lanstreamer.c
1 /*
2  *   lanstreamer.c -- driver for the IBM Auto LANStreamer PCI Adapter
3  *
4  *  Written By: Mike Sullivan, IBM Corporation
5  *
6  *  Copyright (C) 1999 IBM Corporation
7  *
8  *  Linux driver for IBM PCI tokenring cards based on the LanStreamer MPC
9  *  chipset. 
10  *
11  *  This driver is based on the olympic driver for IBM PCI TokenRing cards (Pit/Pit-Phy/Olympic
12  *  chipsets) written  by:
13  *      1999 Peter De Schrijver All Rights Reserved
14  *      1999 Mike Phillips (phillim@amtrak.com)
15  *
16  *  Base Driver Skeleton:
17  *      Written 1993-94 by Donald Becker.
18  *
19  *      Copyright 1993 United States Government as represented by the
20  *      Director, National Security Agency.
21  *
22  * This program is free software; you can redistribute it and/or modify      
23  * it under the terms of the GNU General Public License as published by      
24  * the Free Software Foundation; either version 2 of the License, or         
25  * (at your option) any later version.                                       
26  *                                                                           
27  * This program is distributed in the hope that it will be useful,           
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of            
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             
30  * GNU General Public License for more details.                              
31  *                                                                           
32  * NO WARRANTY                                                               
33  * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR        
34  * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT      
35  * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,      
36  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    
37  * solely responsible for determining the appropriateness of using and       
38  * distributing the Program and assumes all risks associated with its        
39  * exercise of rights under this Agreement, including but not limited to     
40  * the risks and costs of program errors, damage to or loss of data,         
41  * programs or equipment, and unavailability or interruption of operations.  
42  *                                                                           
43  * DISCLAIMER OF LIABILITY                                                   
44  * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY   
45  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL        
46  * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND   
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR     
48  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    
49  * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED  
50  * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES             
51  *                                                                           
52  * You should have received a copy of the GNU General Public License         
53  * along with this program; if not, write to the Free Software               
54  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
55  *                                                                           
56  * 
57  *  12/10/99 - Alpha Release 0.1.0
58  *            First release to the public
59  *  03/03/00 - Merged to kernel, indented -kr -i8 -bri0, fixed some missing
60  *              malloc free checks, reviewed code. <alan@redhat.com>
61  *  03/13/00 - Added spinlocks for smp
62  *  03/08/01 - Added support for module_init() and module_exit()
63  *  08/15/01 - Added ioctl() functionality for debugging, changed netif_*_queue
64  *             calls and other incorrectness - Kent Yoder <yoder1@us.ibm.com>
65  *  11/05/01 - Restructured the interrupt function, added delays, reduced the 
66  *             the number of TX descriptors to 1, which together can prevent 
67  *             the card from locking up the box - <yoder1@us.ibm.com>
68  *  09/27/02 - New PCI interface + bug fix. - <yoder1@us.ibm.com>
69  *  11/13/02 - Removed free_irq calls which could cause a hang, added
70  *             netif_carrier_{on|off} - <yoder1@us.ibm.com>
71  *  
72  *  To Do:
73  *
74  *
75  *  If Problems do Occur
76  *  Most problems can be rectified by either closing and opening the interface
77  *  (ifconfig down and up) or rmmod and insmod'ing the driver (a bit difficult
78  *  if compiled into the kernel).
79  */
80
81 /* Change STREAMER_DEBUG to 1 to get verbose, and I mean really verbose, messages */
82
83 #define STREAMER_DEBUG 0
84 #define STREAMER_DEBUG_PACKETS 0
85
86 /* Change STREAMER_NETWORK_MONITOR to receive mac frames through the arb channel.
87  * Will also create a /proc/net/streamer_tr entry if proc_fs is compiled into the
88  * kernel.
89  * Intended to be used to create a ring-error reporting network module 
90  * i.e. it will give you the source address of beaconers on the ring 
91  */
92
93 #define STREAMER_NETWORK_MONITOR 0
94
95 /* #define CONFIG_PROC_FS */
96
97 /*
98  *  Allow or disallow ioctl's for debugging
99  */
100
101 #define STREAMER_IOCTL 0
102
103 #include <linux/module.h>
104 #include <linux/kernel.h>
105 #include <linux/errno.h>
106 #include <linux/timer.h>
107 #include <linux/in.h>
108 #include <linux/ioport.h>
109 #include <linux/string.h>
110 #include <linux/proc_fs.h>
111 #include <linux/ptrace.h>
112 #include <linux/skbuff.h>
113 #include <linux/interrupt.h>
114 #include <linux/delay.h>
115 #include <linux/netdevice.h>
116 #include <linux/trdevice.h>
117 #include <linux/stddef.h>
118 #include <linux/init.h>
119 #include <linux/pci.h>
120 #include <linux/dma-mapping.h>
121 #include <linux/spinlock.h>
122 #include <linux/bitops.h>
123 #include <linux/jiffies.h>
124
125 #include <net/net_namespace.h>
126 #include <net/checksum.h>
127
128 #include <asm/io.h>
129 #include <asm/system.h>
130
131 #include "lanstreamer.h"
132
133 #if (BITS_PER_LONG == 64)
134 #error broken on 64-bit: stores pointer to rx_ring->buffer in 32-bit int
135 #endif
136
137
138 /* I've got to put some intelligence into the version number so that Peter and I know
139  * which version of the code somebody has got. 
140  * Version Number = a.b.c.d  where a.b.c is the level of code and d is the latest author.
141  * So 0.0.1.pds = Peter, 0.0.1.mlp = Mike
142  * 
143  * Official releases will only have an a.b.c version number format.
144  */
145
146 static char version[] = "LanStreamer.c v0.4.0 03/08/01 - Mike Sullivan\n"
147                         "              v0.5.3 11/13/02 - Kent Yoder";
148
149 static struct pci_device_id streamer_pci_tbl[] = {
150         { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_TR, PCI_ANY_ID, PCI_ANY_ID,},
151         {}      /* terminating entry */
152 };
153 MODULE_DEVICE_TABLE(pci,streamer_pci_tbl);
154
155
156 static char *open_maj_error[] = {
157         "No error", "Lobe Media Test", "Physical Insertion",
158         "Address Verification", "Neighbor Notification (Ring Poll)",
159         "Request Parameters", "FDX Registration Request",
160         "FDX Lobe Media Test", "FDX Duplicate Address Check",
161         "Unknown stage"
162 };
163
164 static char *open_min_error[] = {
165         "No error", "Function Failure", "Signal Lost", "Wire Fault",
166         "Ring Speed Mismatch", "Timeout", "Ring Failure", "Ring Beaconing",
167         "Duplicate Node Address", "Request Parameters", "Remove Received",
168         "Reserved", "Reserved", "No Monitor Detected for RPL",
169         "Monitor Contention failer for RPL", "FDX Protocol Error"
170 };
171
172 /* Module paramters */
173
174 /* Ring Speed 0,4,16
175  * 0 = Autosense         
176  * 4,16 = Selected speed only, no autosense
177  * This allows the card to be the first on the ring
178  * and become the active monitor.
179  *
180  * WARNING: Some hubs will allow you to insert
181  * at the wrong speed
182  */
183
184 static int ringspeed[STREAMER_MAX_ADAPTERS] = { 0, };
185
186 module_param_array(ringspeed, int, NULL, 0);
187
188 /* Packet buffer size */
189
190 static int pkt_buf_sz[STREAMER_MAX_ADAPTERS] = { 0, };
191
192 module_param_array(pkt_buf_sz, int, NULL, 0);
193
194 /* Message Level */
195
196 static int message_level[STREAMER_MAX_ADAPTERS] = { 1, };
197
198 module_param_array(message_level, int, NULL, 0);
199
200 #if STREAMER_IOCTL
201 static int streamer_ioctl(struct net_device *, struct ifreq *, int);
202 #endif
203
204 static int streamer_reset(struct net_device *dev);
205 static int streamer_open(struct net_device *dev);
206 static int streamer_xmit(struct sk_buff *skb, struct net_device *dev);
207 static int streamer_close(struct net_device *dev);
208 static void streamer_set_rx_mode(struct net_device *dev);
209 static irqreturn_t streamer_interrupt(int irq, void *dev_id);
210 static struct net_device_stats *streamer_get_stats(struct net_device *dev);
211 static int streamer_set_mac_address(struct net_device *dev, void *addr);
212 static void streamer_arb_cmd(struct net_device *dev);
213 static int streamer_change_mtu(struct net_device *dev, int mtu);
214 static void streamer_srb_bh(struct net_device *dev);
215 static void streamer_asb_bh(struct net_device *dev);
216 #if STREAMER_NETWORK_MONITOR
217 #ifdef CONFIG_PROC_FS
218 static int streamer_proc_info(char *buffer, char **start, off_t offset,
219                               int length, int *eof, void *data);
220 static int sprintf_info(char *buffer, struct net_device *dev);
221 struct streamer_private *dev_streamer=NULL;
222 #endif
223 #endif
224
225 static int __devinit streamer_init_one(struct pci_dev *pdev,
226                                        const struct pci_device_id *ent)
227 {
228         struct net_device *dev;
229         struct streamer_private *streamer_priv;
230         unsigned long pio_start, pio_end, pio_flags, pio_len;
231         unsigned long mmio_start, mmio_end, mmio_flags, mmio_len;
232         int rc = 0;
233         static int card_no=-1;
234         u16 pcr;
235
236 #if STREAMER_DEBUG
237         printk("lanstreamer::streamer_init_one, entry pdev %p\n",pdev);
238 #endif
239
240         card_no++;
241         dev = alloc_trdev(sizeof(*streamer_priv));
242         if (dev==NULL) {
243                 printk(KERN_ERR "lanstreamer: out of memory.\n");
244                 return -ENOMEM;
245         }
246
247         streamer_priv = netdev_priv(dev);
248
249 #if STREAMER_NETWORK_MONITOR
250 #ifdef CONFIG_PROC_FS
251         if (!dev_streamer)
252                 create_proc_read_entry("streamer_tr", 0, init_net.proc_net,
253                                         streamer_proc_info, NULL); 
254         streamer_priv->next = dev_streamer;
255         dev_streamer = streamer_priv;
256 #endif
257 #endif
258
259         rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
260         if (rc) {
261                 printk(KERN_ERR "%s: No suitable PCI mapping available.\n",
262                                 dev->name);
263                 rc = -ENODEV;
264                 goto err_out;
265         }
266
267         rc = pci_enable_device(pdev);
268         if (rc) {
269                 printk(KERN_ERR "lanstreamer: unable to enable pci device\n");
270                 rc=-EIO;
271                 goto err_out;
272         }
273
274         pci_set_master(pdev);
275
276         rc = pci_set_mwi(pdev);
277         if (rc) {
278                 printk(KERN_ERR "lanstreamer: unable to enable MWI on pci device\n");
279                 goto err_out_disable;
280         }
281
282         pio_start = pci_resource_start(pdev, 0);
283         pio_end = pci_resource_end(pdev, 0);
284         pio_flags = pci_resource_flags(pdev, 0);
285         pio_len = pci_resource_len(pdev, 0);
286
287         mmio_start = pci_resource_start(pdev, 1);
288         mmio_end = pci_resource_end(pdev, 1);
289         mmio_flags = pci_resource_flags(pdev, 1);
290         mmio_len = pci_resource_len(pdev, 1);
291
292 #if STREAMER_DEBUG
293         printk("lanstreamer: pio_start %x pio_end %x pio_len %x pio_flags %x\n",
294                 pio_start, pio_end, pio_len, pio_flags);
295         printk("lanstreamer: mmio_start %x mmio_end %x mmio_len %x mmio_flags %x\n",
296                 mmio_start, mmio_end, mmio_flags, mmio_len);
297 #endif
298
299         if (!request_region(pio_start, pio_len, "lanstreamer")) {
300                 printk(KERN_ERR "lanstreamer: unable to get pci io addr %lx\n",
301                         pio_start);
302                 rc= -EBUSY;
303                 goto err_out_mwi;
304         }
305
306         if (!request_mem_region(mmio_start, mmio_len, "lanstreamer")) {
307                 printk(KERN_ERR "lanstreamer: unable to get pci mmio addr %lx\n",
308                         mmio_start);
309                 rc= -EBUSY;
310                 goto err_out_free_pio;
311         }
312
313         streamer_priv->streamer_mmio=ioremap(mmio_start, mmio_len);
314         if (streamer_priv->streamer_mmio == NULL) {
315                 printk(KERN_ERR "lanstreamer: unable to remap MMIO %lx\n",
316                         mmio_start);
317                 rc= -EIO;
318                 goto err_out_free_mmio;
319         }
320
321         init_waitqueue_head(&streamer_priv->srb_wait);
322         init_waitqueue_head(&streamer_priv->trb_wait);
323
324         dev->open = &streamer_open;
325         dev->hard_start_xmit = &streamer_xmit;
326         dev->change_mtu = &streamer_change_mtu;
327         dev->stop = &streamer_close;
328 #if STREAMER_IOCTL
329         dev->do_ioctl = &streamer_ioctl;
330 #else
331         dev->do_ioctl = NULL;
332 #endif
333         dev->set_multicast_list = &streamer_set_rx_mode;
334         dev->get_stats = &streamer_get_stats;
335         dev->set_mac_address = &streamer_set_mac_address;
336         dev->irq = pdev->irq;
337         dev->base_addr=pio_start;
338         SET_NETDEV_DEV(dev, &pdev->dev);
339
340         streamer_priv->streamer_card_name = (char *)pdev->resource[0].name;
341         streamer_priv->pci_dev = pdev;
342
343         if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000))
344                 streamer_priv->pkt_buf_sz = PKT_BUF_SZ;
345         else
346                 streamer_priv->pkt_buf_sz = pkt_buf_sz[card_no];
347
348         streamer_priv->streamer_ring_speed = ringspeed[card_no];
349         streamer_priv->streamer_message_level = message_level[card_no];
350
351         pci_set_drvdata(pdev, dev);
352
353         spin_lock_init(&streamer_priv->streamer_lock);
354
355         pci_read_config_word (pdev, PCI_COMMAND, &pcr);
356         pcr |= PCI_COMMAND_SERR;
357         pci_write_config_word (pdev, PCI_COMMAND, pcr);
358
359         printk("%s \n", version);
360         printk("%s: %s. I/O at %hx, MMIO at %p, using irq %d\n",dev->name,
361                 streamer_priv->streamer_card_name,
362                 (unsigned int) dev->base_addr,
363                 streamer_priv->streamer_mmio, 
364                 dev->irq);
365
366         if (streamer_reset(dev))
367                 goto err_out_unmap;
368
369         rc = register_netdev(dev);
370         if (rc)
371                 goto err_out_unmap;
372         return 0;
373
374 err_out_unmap:
375         iounmap(streamer_priv->streamer_mmio);
376 err_out_free_mmio:
377         release_mem_region(mmio_start, mmio_len);
378 err_out_free_pio:
379         release_region(pio_start, pio_len);
380 err_out_mwi:
381         pci_clear_mwi(pdev);
382 err_out_disable:
383         pci_disable_device(pdev);
384 err_out:
385         free_netdev(dev);
386 #if STREAMER_DEBUG
387         printk("lanstreamer: Exit error %x\n",rc);
388 #endif
389         return rc;
390 }
391
392 static void __devexit streamer_remove_one(struct pci_dev *pdev)
393 {
394         struct net_device *dev=pci_get_drvdata(pdev);
395         struct streamer_private *streamer_priv;
396
397 #if STREAMER_DEBUG
398         printk("lanstreamer::streamer_remove_one entry pdev %p\n",pdev);
399 #endif
400
401         if (dev == NULL) {
402                 printk(KERN_ERR "lanstreamer::streamer_remove_one, ERROR dev is NULL\n");
403                 return;
404         }
405
406         streamer_priv=netdev_priv(dev);
407         if (streamer_priv == NULL) {
408                 printk(KERN_ERR "lanstreamer::streamer_remove_one, ERROR dev->priv is NULL\n");
409                 return;
410         }
411
412 #if STREAMER_NETWORK_MONITOR
413 #ifdef CONFIG_PROC_FS
414         {
415                 struct streamer_private **p, **next;
416
417                 for (p = &dev_streamer; *p; p = next) {
418                         next = &(*p)->next;
419                         if (*p == streamer_priv) {
420                                 *p = *next;
421                                 break;
422                         }
423                 }
424                 if (!dev_streamer)
425                         remove_proc_entry("streamer_tr", init_net.proc_net);
426         }
427 #endif
428 #endif
429
430         unregister_netdev(dev);
431         iounmap(streamer_priv->streamer_mmio);
432         release_mem_region(pci_resource_start(pdev, 1), pci_resource_len(pdev,1));
433         release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev,0));
434         pci_clear_mwi(pdev);
435         pci_disable_device(pdev);
436         free_netdev(dev);
437         pci_set_drvdata(pdev, NULL);
438 }
439
440
441 static int streamer_reset(struct net_device *dev)
442 {
443         struct streamer_private *streamer_priv;
444         __u8 __iomem *streamer_mmio;
445         unsigned long t;
446         unsigned int uaa_addr;
447         struct sk_buff *skb = NULL;
448         __u16 misr;
449 #if STREAMER_DEBUG
450         DECLARE_MAC_BUF(mac);
451 #endif
452
453         streamer_priv = netdev_priv(dev);
454         streamer_mmio = streamer_priv->streamer_mmio;
455
456         writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL);
457         t = jiffies;
458         /* Hold soft reset bit for a while */
459         ssleep(1);
460         
461         writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET,
462                streamer_mmio + BCTL);
463
464 #if STREAMER_DEBUG
465         printk("BCTL: %x\n", readw(streamer_mmio + BCTL));
466         printk("GPR: %x\n", readw(streamer_mmio + GPR));
467         printk("SISRMASK: %x\n", readw(streamer_mmio + SISR_MASK));
468 #endif
469         writew(readw(streamer_mmio + BCTL) | (BCTL_RX_FIFO_8 | BCTL_TX_FIFO_8), streamer_mmio + BCTL );
470
471         if (streamer_priv->streamer_ring_speed == 0) {  /* Autosense */
472                 writew(readw(streamer_mmio + GPR) | GPR_AUTOSENSE,
473                        streamer_mmio + GPR);
474                 if (streamer_priv->streamer_message_level)
475                         printk(KERN_INFO "%s: Ringspeed autosense mode on\n",
476                                dev->name);
477         } else if (streamer_priv->streamer_ring_speed == 16) {
478                 if (streamer_priv->streamer_message_level)
479                         printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n",
480                                dev->name);
481                 writew(GPR_16MBPS, streamer_mmio + GPR);
482         } else if (streamer_priv->streamer_ring_speed == 4) {
483                 if (streamer_priv->streamer_message_level)
484                         printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n",
485                                dev->name);
486                 writew(0, streamer_mmio + GPR);
487         }
488
489         skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
490         if (!skb) {
491                 printk(KERN_INFO "%s: skb allocation for diagnostics failed...proceeding\n",
492                        dev->name);
493         } else {
494                 struct streamer_rx_desc *rx_ring;
495                 u8 *data;
496
497                 rx_ring=(struct streamer_rx_desc *)skb->data;
498                 data=((u8 *)skb->data)+sizeof(struct streamer_rx_desc);
499                 rx_ring->forward=0;
500                 rx_ring->status=0;
501                 rx_ring->buffer=cpu_to_le32(pci_map_single(streamer_priv->pci_dev, data, 
502                                                         512, PCI_DMA_FROMDEVICE));
503                 rx_ring->framelen_buflen=512; 
504                 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, rx_ring, 512, PCI_DMA_FROMDEVICE)),
505                         streamer_mmio+RXBDA);
506         }
507
508 #if STREAMER_DEBUG
509         printk("GPR = %x\n", readw(streamer_mmio + GPR));
510 #endif
511         /* start solo init */
512         writew(SISR_MI, streamer_mmio + SISR_MASK_SUM);
513
514         while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) {
515                 msleep_interruptible(100);
516                 if (time_after(jiffies, t + 40 * HZ)) {
517                         printk(KERN_ERR
518                                "IBM PCI tokenring card not responding\n");
519                         release_region(dev->base_addr, STREAMER_IO_SPACE);
520                         if (skb)
521                                 dev_kfree_skb(skb);
522                         return -1;
523                 }
524         }
525         writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM);
526         misr = readw(streamer_mmio + MISR_RUM);
527         writew(~misr, streamer_mmio + MISR_RUM);
528
529         if (skb)
530                 dev_kfree_skb(skb);     /* release skb used for diagnostics */
531
532 #if STREAMER_DEBUG
533         printk("LAPWWO: %x, LAPA: %x LAPE:  %x\n",
534                readw(streamer_mmio + LAPWWO), readw(streamer_mmio + LAPA),
535                readw(streamer_mmio + LAPE));
536 #endif
537
538 #if STREAMER_DEBUG
539         {
540                 int i;
541                 writew(readw(streamer_mmio + LAPWWO),
542                        streamer_mmio + LAPA);
543                 printk("initialization response srb dump: ");
544                 for (i = 0; i < 10; i++)
545                         printk("%x:",
546                                ntohs(readw(streamer_mmio + LAPDINC)));
547                 printk("\n");
548         }
549 #endif
550
551         writew(readw(streamer_mmio + LAPWWO) + 6, streamer_mmio + LAPA);
552         if (readw(streamer_mmio + LAPD)) {
553                 printk(KERN_INFO "tokenring card initialization failed. errorcode : %x\n",
554                        ntohs(readw(streamer_mmio + LAPD)));
555                 release_region(dev->base_addr, STREAMER_IO_SPACE);
556                 return -1;
557         }
558
559         writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA);
560         uaa_addr = ntohs(readw(streamer_mmio + LAPDINC));
561         readw(streamer_mmio + LAPDINC); /* skip over Level.Addr field */
562         streamer_priv->streamer_addr_table_addr = ntohs(readw(streamer_mmio + LAPDINC));
563         streamer_priv->streamer_parms_addr = ntohs(readw(streamer_mmio + LAPDINC));
564
565 #if STREAMER_DEBUG
566         printk("UAA resides at %x\n", uaa_addr);
567 #endif
568
569         /* setup uaa area for access with LAPD */
570         {
571                 int i;
572                 __u16 addr;
573                 writew(uaa_addr, streamer_mmio + LAPA);
574                 for (i = 0; i < 6; i += 2) {
575                         addr=ntohs(readw(streamer_mmio+LAPDINC));
576                         dev->dev_addr[i]= (addr >> 8) & 0xff;
577                         dev->dev_addr[i+1]= addr & 0xff;
578                 }
579 #if STREAMER_DEBUG
580                 printk("Adapter address: %s\n",
581                        print_mac(mac, dev->dev_addr));
582 #endif
583         }
584         return 0;
585 }
586
587 static int streamer_open(struct net_device *dev)
588 {
589         struct streamer_private *streamer_priv = netdev_priv(dev);
590         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
591         unsigned long flags;
592         char open_error[255];
593         int i, open_finished = 1;
594         __u16 srb_word;
595         __u16 srb_open;
596         int rc;
597
598         if (readw(streamer_mmio+BMCTL_SUM) & BMCTL_RX_ENABLED) {
599                 rc=streamer_reset(dev);
600         }
601
602         if (request_irq(dev->irq, &streamer_interrupt, IRQF_SHARED, "lanstreamer", dev)) {
603                 return -EAGAIN;
604         }
605 #if STREAMER_DEBUG
606         printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM));
607         printk("pending ints: %x\n", readw(streamer_mmio + SISR));
608 #endif
609
610         writew(SISR_MI | SISR_SRB_REPLY, streamer_mmio + SISR_MASK);    /* more ints later, doesn't stop arb cmd interrupt */
611         writew(LISR_LIE, streamer_mmio + LISR); /* more ints later */
612
613         /* adapter is closed, so SRB is pointed to by LAPWWO */
614         writew(readw(streamer_mmio + LAPWWO), streamer_mmio + LAPA);
615
616 #if STREAMER_DEBUG
617         printk("LAPWWO: %x, LAPA: %x\n", readw(streamer_mmio + LAPWWO),
618                readw(streamer_mmio + LAPA));
619         printk("LAPE: %x\n", readw(streamer_mmio + LAPE));
620         printk("SISR Mask = %04x\n", readw(streamer_mmio + SISR_MASK));
621 #endif
622         do {
623                 int i;
624
625                 for (i = 0; i < SRB_COMMAND_SIZE; i += 2) {
626                         writew(0, streamer_mmio + LAPDINC);
627                 }
628
629                 writew(readw(streamer_mmio+LAPWWO),streamer_mmio+LAPA);
630                 writew(htons(SRB_OPEN_ADAPTER<<8),streamer_mmio+LAPDINC) ;      /* open */
631                 writew(htons(STREAMER_CLEAR_RET_CODE<<8),streamer_mmio+LAPDINC);
632                 writew(STREAMER_CLEAR_RET_CODE, streamer_mmio + LAPDINC);
633
634                 writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA);
635 #if STREAMER_NETWORK_MONITOR
636                 /* If Network Monitor, instruct card to copy MAC frames through the ARB */
637                 writew(htons(OPEN_ADAPTER_ENABLE_FDX | OPEN_ADAPTER_PASS_ADC_MAC | OPEN_ADAPTER_PASS_ATT_MAC | OPEN_ADAPTER_PASS_BEACON), streamer_mmio + LAPDINC);     /* offset 8 word contains open options */
638 #else
639                 writew(htons(OPEN_ADAPTER_ENABLE_FDX), streamer_mmio + LAPDINC);        /* Offset 8 word contains Open.Options */
640 #endif
641
642                 if (streamer_priv->streamer_laa[0]) {
643                         writew(readw(streamer_mmio + LAPWWO) + 12, streamer_mmio + LAPA);
644                         writew(htons((streamer_priv->streamer_laa[0] << 8) | 
645                                      streamer_priv->streamer_laa[1]),streamer_mmio+LAPDINC);
646                         writew(htons((streamer_priv->streamer_laa[2] << 8) | 
647                                      streamer_priv->streamer_laa[3]),streamer_mmio+LAPDINC);
648                         writew(htons((streamer_priv->streamer_laa[4] << 8) | 
649                                      streamer_priv->streamer_laa[5]),streamer_mmio+LAPDINC);
650                         memcpy(dev->dev_addr, streamer_priv->streamer_laa, dev->addr_len);
651                 }
652
653                 /* save off srb open offset */
654                 srb_open = readw(streamer_mmio + LAPWWO);
655 #if STREAMER_DEBUG
656                 writew(readw(streamer_mmio + LAPWWO),
657                        streamer_mmio + LAPA);
658                 printk("srb open request: \n");
659                 for (i = 0; i < 16; i++) {
660                         printk("%x:", ntohs(readw(streamer_mmio + LAPDINC)));
661                 }
662                 printk("\n");
663 #endif
664                 spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
665                 streamer_priv->srb_queued = 1;
666
667                 /* signal solo that SRB command has been issued */
668                 writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
669                 spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags);
670
671                 while (streamer_priv->srb_queued) {
672                         interruptible_sleep_on_timeout(&streamer_priv->srb_wait, 5 * HZ);
673                         if (signal_pending(current)) {
674                                 printk(KERN_WARNING "%s: SRB timed out.\n", dev->name);
675                                 printk(KERN_WARNING "SISR=%x MISR=%x, LISR=%x\n",
676                                        readw(streamer_mmio + SISR),
677                                        readw(streamer_mmio + MISR_RUM),
678                                        readw(streamer_mmio + LISR));
679                                 streamer_priv->srb_queued = 0;
680                                 break;
681                         }
682                 }
683
684 #if STREAMER_DEBUG
685                 printk("SISR_MASK: %x\n", readw(streamer_mmio + SISR_MASK));
686                 printk("srb open response:\n");
687                 writew(srb_open, streamer_mmio + LAPA);
688                 for (i = 0; i < 10; i++) {
689                         printk("%x:",
690                                ntohs(readw(streamer_mmio + LAPDINC)));
691                 }
692 #endif
693
694                 /* If we get the same return response as we set, the interrupt wasn't raised and the open
695                  * timed out.
696                  */
697                 writew(srb_open + 2, streamer_mmio + LAPA);
698                 srb_word = ntohs(readw(streamer_mmio + LAPD)) >> 8;
699                 if (srb_word == STREAMER_CLEAR_RET_CODE) {
700                         printk(KERN_WARNING "%s: Adapter Open time out or error.\n",
701                                dev->name);
702                         return -EIO;
703                 }
704
705                 if (srb_word != 0) {
706                         if (srb_word == 0x07) {
707                                 if (!streamer_priv->streamer_ring_speed && open_finished) {     /* Autosense , first time around */
708                                         printk(KERN_WARNING "%s: Retrying at different ring speed \n",
709                                                dev->name);
710                                         open_finished = 0;
711                                 } else {
712                                         __u16 error_code;
713
714                                         writew(srb_open + 6, streamer_mmio + LAPA);
715                                         error_code = ntohs(readw(streamer_mmio + LAPD));
716                                         strcpy(open_error, open_maj_error[(error_code & 0xf0) >> 4]);
717                                         strcat(open_error, " - ");
718                                         strcat(open_error, open_min_error[(error_code & 0x0f)]);
719
720                                         if (!streamer_priv->streamer_ring_speed
721                                             && ((error_code & 0x0f) == 0x0d)) 
722                                         {
723                                                 printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors present\n", dev->name);
724                                                 printk(KERN_WARNING "%s: Please try again with a specified ring speed \n", dev->name);
725                                                 free_irq(dev->irq, dev);
726                                                 return -EIO;
727                                         }
728
729                                         printk(KERN_WARNING "%s: %s\n",
730                                                dev->name, open_error);
731                                         free_irq(dev->irq, dev);
732                                         return -EIO;
733
734                                 }       /* if autosense && open_finished */
735                         } else {
736                                 printk(KERN_WARNING "%s: Bad OPEN response: %x\n",
737                                        dev->name, srb_word);
738                                 free_irq(dev->irq, dev);
739                                 return -EIO;
740                         }
741                 } else
742                         open_finished = 1;
743         } while (!(open_finished));     /* Will only loop if ring speed mismatch re-open attempted && autosense is on */
744
745         writew(srb_open + 18, streamer_mmio + LAPA);
746         srb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8;
747         if (srb_word & (1 << 3))
748                 if (streamer_priv->streamer_message_level)
749                         printk(KERN_INFO "%s: Opened in FDX Mode\n", dev->name);
750
751         if (srb_word & 1)
752                 streamer_priv->streamer_ring_speed = 16;
753         else
754                 streamer_priv->streamer_ring_speed = 4;
755
756         if (streamer_priv->streamer_message_level)
757                 printk(KERN_INFO "%s: Opened in %d Mbps mode\n", 
758                         dev->name,
759                         streamer_priv->streamer_ring_speed);
760
761         writew(srb_open + 8, streamer_mmio + LAPA);
762         streamer_priv->asb = ntohs(readw(streamer_mmio + LAPDINC));
763         streamer_priv->srb = ntohs(readw(streamer_mmio + LAPDINC));
764         streamer_priv->arb = ntohs(readw(streamer_mmio + LAPDINC));
765         readw(streamer_mmio + LAPDINC); /* offset 14 word is rsvd */
766         streamer_priv->trb = ntohs(readw(streamer_mmio + LAPDINC));
767
768         streamer_priv->streamer_receive_options = 0x00;
769         streamer_priv->streamer_copy_all_options = 0;
770
771         /* setup rx ring */
772         /* enable rx channel */
773         writew(~BMCTL_RX_DIS, streamer_mmio + BMCTL_RUM);
774
775         /* setup rx descriptors */
776         streamer_priv->streamer_rx_ring=
777             kmalloc( sizeof(struct streamer_rx_desc)*
778                      STREAMER_RX_RING_SIZE,GFP_KERNEL);
779         if (!streamer_priv->streamer_rx_ring) {
780             printk(KERN_WARNING "%s ALLOC of streamer rx ring FAILED!!\n",dev->name);
781             return -EIO;
782         }
783
784         for (i = 0; i < STREAMER_RX_RING_SIZE; i++) {
785                 struct sk_buff *skb;
786
787                 skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
788                 if (skb == NULL)
789                         break;
790
791                 skb->dev = dev;
792
793                 streamer_priv->streamer_rx_ring[i].forward = 
794                         cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[i + 1],
795                                         sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE));
796                 streamer_priv->streamer_rx_ring[i].status = 0;
797                 streamer_priv->streamer_rx_ring[i].buffer = 
798                         cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data,
799                                               streamer_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
800                 streamer_priv->streamer_rx_ring[i].framelen_buflen = streamer_priv->pkt_buf_sz;
801                 streamer_priv->rx_ring_skb[i] = skb;
802         }
803         streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1].forward =
804                                 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0],
805                                                 sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE));
806
807         if (i == 0) {
808                 printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled\n", dev->name);
809                 free_irq(dev->irq, dev);
810                 return -EIO;
811         }
812
813         streamer_priv->rx_ring_last_received = STREAMER_RX_RING_SIZE - 1;       /* last processed rx status */
814
815         writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0],
816                                 sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)), 
817                 streamer_mmio + RXBDA);
818         writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1],
819                                 sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)), 
820                 streamer_mmio + RXLBDA);
821
822         /* set bus master interrupt event mask */
823         writew(MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK);
824
825
826         /* setup tx ring */
827         streamer_priv->streamer_tx_ring=kmalloc(sizeof(struct streamer_tx_desc)*
828                                                 STREAMER_TX_RING_SIZE,GFP_KERNEL);
829         if (!streamer_priv->streamer_tx_ring) {
830             printk(KERN_WARNING "%s ALLOC of streamer_tx_ring FAILED\n",dev->name);
831             return -EIO;
832         }
833
834         writew(~BMCTL_TX2_DIS, streamer_mmio + BMCTL_RUM);      /* Enables TX channel 2 */
835         for (i = 0; i < STREAMER_TX_RING_SIZE; i++) {
836                 streamer_priv->streamer_tx_ring[i].forward = cpu_to_le32(pci_map_single(streamer_priv->pci_dev, 
837                                                                                 &streamer_priv->streamer_tx_ring[i + 1],
838                                                                                 sizeof(struct streamer_tx_desc),
839                                                                                 PCI_DMA_TODEVICE));
840                 streamer_priv->streamer_tx_ring[i].status = 0;
841                 streamer_priv->streamer_tx_ring[i].bufcnt_framelen = 0;
842                 streamer_priv->streamer_tx_ring[i].buffer = 0;
843                 streamer_priv->streamer_tx_ring[i].buflen = 0;
844                 streamer_priv->streamer_tx_ring[i].rsvd1 = 0;
845                 streamer_priv->streamer_tx_ring[i].rsvd2 = 0;
846                 streamer_priv->streamer_tx_ring[i].rsvd3 = 0;
847         }
848         streamer_priv->streamer_tx_ring[STREAMER_TX_RING_SIZE - 1].forward =
849                                         cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_tx_ring[0],
850                                                         sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE));
851
852         streamer_priv->free_tx_ring_entries = STREAMER_TX_RING_SIZE;
853         streamer_priv->tx_ring_free = 0;        /* next entry in tx ring to use */
854         streamer_priv->tx_ring_last_status = STREAMER_TX_RING_SIZE - 1;
855
856         /* set Busmaster interrupt event mask (handle receives on interrupt only */
857         writew(MISR_TX2_EOF | MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK);
858         /* set system event interrupt mask */
859         writew(SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE, streamer_mmio + SISR_MASK_SUM);
860
861 #if STREAMER_DEBUG
862         printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM));
863         printk("SISR MASK: %x\n", readw(streamer_mmio + SISR_MASK));
864 #endif
865
866 #if STREAMER_NETWORK_MONITOR
867
868         writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA);
869         printk("%s: Node Address: %04x:%04x:%04x\n", dev->name,
870                 ntohs(readw(streamer_mmio + LAPDINC)),
871                 ntohs(readw(streamer_mmio + LAPDINC)),
872                 ntohs(readw(streamer_mmio + LAPDINC)));
873         readw(streamer_mmio + LAPDINC);
874         readw(streamer_mmio + LAPDINC);
875         printk("%s: Functional Address: %04x:%04x\n", dev->name,
876                 ntohs(readw(streamer_mmio + LAPDINC)),
877                 ntohs(readw(streamer_mmio + LAPDINC)));
878
879         writew(streamer_priv->streamer_parms_addr + 4,
880                 streamer_mmio + LAPA);
881         printk("%s: NAUN Address: %04x:%04x:%04x\n", dev->name,
882                 ntohs(readw(streamer_mmio + LAPDINC)),
883                 ntohs(readw(streamer_mmio + LAPDINC)),
884                 ntohs(readw(streamer_mmio + LAPDINC)));
885 #endif
886
887         netif_start_queue(dev);
888         netif_carrier_on(dev);
889         return 0;
890 }
891
892 /*
893  *      When we enter the rx routine we do not know how many frames have been 
894  *      queued on the rx channel.  Therefore we start at the next rx status
895  *      position and travel around the receive ring until we have completed
896  *      all the frames.
897  *
898  *      This means that we may process the frame before we receive the end
899  *      of frame interrupt. This is why we always test the status instead
900  *      of blindly processing the next frame.
901  *      
902  */
903 static void streamer_rx(struct net_device *dev)
904 {
905         struct streamer_private *streamer_priv =
906             netdev_priv(dev);
907         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
908         struct streamer_rx_desc *rx_desc;
909         int rx_ring_last_received, length, frame_length, buffer_cnt = 0;
910         struct sk_buff *skb, *skb2;
911
912         /* setup the next rx descriptor to be received */
913         rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)];
914         rx_ring_last_received = streamer_priv->rx_ring_last_received;
915
916         while (rx_desc->status & 0x01000000) {  /* While processed descriptors are available */
917                 if (rx_ring_last_received != streamer_priv->rx_ring_last_received) 
918                 {
919                         printk(KERN_WARNING "RX Error 1 rx_ring_last_received not the same %x %x\n",
920                                 rx_ring_last_received, streamer_priv->rx_ring_last_received);
921                 }
922                 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
923                 rx_ring_last_received = streamer_priv->rx_ring_last_received;
924
925                 length = rx_desc->framelen_buflen & 0xffff;     /* buffer length */
926                 frame_length = (rx_desc->framelen_buflen >> 16) & 0xffff;
927
928                 if (rx_desc->status & 0x7E830000) {     /* errors */
929                         if (streamer_priv->streamer_message_level) {
930                                 printk(KERN_WARNING "%s: Rx Error %x \n",
931                                        dev->name, rx_desc->status);
932                         }
933                 } else {        /* received without errors */
934                         if (rx_desc->status & 0x80000000) {     /* frame complete */
935                                 buffer_cnt = 1;
936                                 skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
937                         } else {
938                                 skb = dev_alloc_skb(frame_length);
939                         }
940
941                         if (skb == NULL) 
942                         {
943                                 printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers. \n", dev->name);
944                                 streamer_priv->streamer_stats.rx_dropped++;
945                         } else {        /* we allocated an skb OK */
946                                 if (buffer_cnt == 1) {
947                                         /* release the DMA mapping */
948                                         pci_unmap_single(streamer_priv->pci_dev, 
949                                                 le32_to_cpu(streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer),
950                                                 streamer_priv->pkt_buf_sz, 
951                                                 PCI_DMA_FROMDEVICE);
952                                         skb2 = streamer_priv->rx_ring_skb[rx_ring_last_received];
953 #if STREAMER_DEBUG_PACKETS
954                                         {
955                                                 int i;
956                                                 printk("streamer_rx packet print: skb->data2 %p  skb->head %p\n", skb2->data, skb2->head);
957                                                 for (i = 0; i < frame_length; i++) 
958                                                 {
959                                                         printk("%x:", skb2->data[i]);
960                                                         if (((i + 1) % 16) == 0)
961                                                                 printk("\n");
962                                                 }
963                                                 printk("\n");
964                                         }
965 #endif
966                                         skb_put(skb2, length);
967                                         skb2->protocol = tr_type_trans(skb2, dev);
968                                         /* recycle this descriptor */
969                                         streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0;
970                                         streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz;
971                                         streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer = 
972                                                 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, streamer_priv->pkt_buf_sz,
973                                                                 PCI_DMA_FROMDEVICE));
974                                         streamer_priv->rx_ring_skb[rx_ring_last_received] = skb;
975                                         /* place recycled descriptor back on the adapter */
976                                         writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, 
977                                                                         &streamer_priv->streamer_rx_ring[rx_ring_last_received],
978                                                                         sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE)),
979                                                 streamer_mmio + RXLBDA);
980                                         /* pass the received skb up to the protocol */
981                                         netif_rx(skb2);
982                                 } else {
983                                         do {    /* Walk the buffers */
984                                                 pci_unmap_single(streamer_priv->pci_dev, le32_to_cpu(rx_desc->buffer), length, PCI_DMA_FROMDEVICE), 
985                                                 memcpy(skb_put(skb, length), (void *)rx_desc->buffer, length);  /* copy this fragment */
986                                                 streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0;
987                                                 streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz;
988                                                 
989                                                 /* give descriptor back to the adapter */
990                                                 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, 
991                                                                         &streamer_priv->streamer_rx_ring[rx_ring_last_received],
992                                                                         length, PCI_DMA_FROMDEVICE)), 
993                                                         streamer_mmio + RXLBDA);
994
995                                                 if (rx_desc->status & 0x80000000)
996                                                         break;  /* this descriptor completes the frame */
997
998                                                 /* else get the next pending descriptor */
999                                                 if (rx_ring_last_received!= streamer_priv->rx_ring_last_received)
1000                                                 {
1001                                                         printk("RX Error rx_ring_last_received not the same %x %x\n",
1002                                                                 rx_ring_last_received,
1003                                                                 streamer_priv->rx_ring_last_received);
1004                                                 }
1005                                                 rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE-1)];
1006
1007                                                 length = rx_desc->framelen_buflen & 0xffff;     /* buffer length */
1008                                                 streamer_priv->rx_ring_last_received =  (streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE - 1);
1009                                                 rx_ring_last_received = streamer_priv->rx_ring_last_received;
1010                                         } while (1);
1011
1012                                         skb->protocol = tr_type_trans(skb, dev);
1013                                         /* send up to the protocol */
1014                                         netif_rx(skb);
1015                                 }
1016                                 dev->last_rx = jiffies;
1017                                 streamer_priv->streamer_stats.rx_packets++;
1018                                 streamer_priv->streamer_stats.rx_bytes += length;
1019                         }       /* if skb == null */
1020                 }               /* end received without errors */
1021
1022                 /* try the next one */
1023                 rx_desc = &streamer_priv->streamer_rx_ring[(rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)];
1024         }                       /* end for all completed rx descriptors */
1025 }
1026
1027 static irqreturn_t streamer_interrupt(int irq, void *dev_id)
1028 {
1029         struct net_device *dev = (struct net_device *) dev_id;
1030         struct streamer_private *streamer_priv =
1031             netdev_priv(dev);
1032         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1033         __u16 sisr;
1034         __u16 misr;
1035         u8 max_intr = MAX_INTR;
1036
1037         spin_lock(&streamer_priv->streamer_lock);
1038         sisr = readw(streamer_mmio + SISR);
1039
1040         while((sisr & (SISR_MI | SISR_SRB_REPLY | SISR_ADAPTER_CHECK | SISR_ASB_FREE | 
1041                        SISR_ARB_CMD | SISR_TRB_REPLY | SISR_PAR_ERR | SISR_SERR_ERR))
1042                && (max_intr > 0)) {
1043
1044                 if(sisr & SISR_PAR_ERR) {
1045                         writew(~SISR_PAR_ERR, streamer_mmio + SISR_RUM);
1046                         (void)readw(streamer_mmio + SISR_RUM);
1047                 }
1048
1049                 else if(sisr & SISR_SERR_ERR) {
1050                         writew(~SISR_SERR_ERR, streamer_mmio + SISR_RUM);
1051                         (void)readw(streamer_mmio + SISR_RUM);
1052                 }
1053
1054                 else if(sisr & SISR_MI) {
1055                         misr = readw(streamer_mmio + MISR_RUM);
1056
1057                 if (misr & MISR_TX2_EOF) {
1058                                 while(streamer_priv->streamer_tx_ring[(streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1)].status) {
1059                                 streamer_priv->tx_ring_last_status = (streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1);
1060                                 streamer_priv->free_tx_ring_entries++;
1061                                 streamer_priv->streamer_stats.tx_bytes += streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]->len;
1062                                 streamer_priv->streamer_stats.tx_packets++;
1063                                 dev_kfree_skb_irq(streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]);
1064                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buffer = 0xdeadbeef;
1065                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].status = 0;
1066                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].bufcnt_framelen = 0;
1067                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buflen = 0;
1068                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd1 = 0;
1069                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd2 = 0;
1070                                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd3 = 0;
1071                         }
1072                         netif_wake_queue(dev);
1073                 }
1074
1075                 if (misr & MISR_RX_EOF) {
1076                         streamer_rx(dev);
1077                 }
1078                 /* MISR_RX_EOF */
1079
1080                         if (misr & MISR_RX_NOBUF) {
1081                                 /* According to the documentation, we don't have to do anything,  
1082                                  * but trapping it keeps it out of /var/log/messages.  
1083                                  */
1084                         }               /* SISR_RX_NOBUF */
1085
1086                         writew(~misr, streamer_mmio + MISR_RUM);
1087                         (void)readw(streamer_mmio + MISR_RUM);
1088                 }
1089
1090                 else if (sisr & SISR_SRB_REPLY) {
1091                         if (streamer_priv->srb_queued == 1) {
1092                                 wake_up_interruptible(&streamer_priv->srb_wait);
1093                         } else if (streamer_priv->srb_queued == 2) {
1094                                 streamer_srb_bh(dev);
1095                         }
1096                         streamer_priv->srb_queued = 0;
1097
1098                         writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM);
1099                         (void)readw(streamer_mmio + SISR_RUM);
1100                 }
1101
1102                 else if (sisr & SISR_ADAPTER_CHECK) {
1103                         printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:\n", dev->name);
1104                         writel(readl(streamer_mmio + LAPWWO), streamer_mmio + LAPA);
1105                         printk(KERN_WARNING "%s: Words %x:%x:%x:%x:\n",
1106                                dev->name, readw(streamer_mmio + LAPDINC),
1107                                ntohs(readw(streamer_mmio + LAPDINC)),
1108                                ntohs(readw(streamer_mmio + LAPDINC)),
1109                                ntohs(readw(streamer_mmio + LAPDINC)));
1110                         netif_stop_queue(dev);
1111                         netif_carrier_off(dev);
1112                         printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name);
1113                 }
1114
1115                 /* SISR_ADAPTER_CHECK */
1116                 else if (sisr & SISR_ASB_FREE) {
1117                         /* Wake up anything that is waiting for the asb response */
1118                         if (streamer_priv->asb_queued) {
1119                                 streamer_asb_bh(dev);
1120                         }
1121                         writew(~SISR_ASB_FREE, streamer_mmio + SISR_RUM);
1122                         (void)readw(streamer_mmio + SISR_RUM);
1123                 }
1124                 /* SISR_ASB_FREE */
1125                 else if (sisr & SISR_ARB_CMD) {
1126                         streamer_arb_cmd(dev);
1127                         writew(~SISR_ARB_CMD, streamer_mmio + SISR_RUM);
1128                         (void)readw(streamer_mmio + SISR_RUM);
1129                 }
1130                 /* SISR_ARB_CMD */
1131                 else if (sisr & SISR_TRB_REPLY) {
1132                         /* Wake up anything that is waiting for the trb response */
1133                         if (streamer_priv->trb_queued) {
1134                                 wake_up_interruptible(&streamer_priv->
1135                                                       trb_wait);
1136                         }
1137                         streamer_priv->trb_queued = 0;
1138                         writew(~SISR_TRB_REPLY, streamer_mmio + SISR_RUM);
1139                         (void)readw(streamer_mmio + SISR_RUM);
1140                 }
1141                 /* SISR_TRB_REPLY */
1142
1143                 sisr = readw(streamer_mmio + SISR);
1144                 max_intr--;
1145         } /* while() */         
1146
1147         spin_unlock(&streamer_priv->streamer_lock) ; 
1148         return IRQ_HANDLED;
1149 }
1150
1151 static int streamer_xmit(struct sk_buff *skb, struct net_device *dev)
1152 {
1153         struct streamer_private *streamer_priv =
1154             netdev_priv(dev);
1155         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1156         unsigned long flags ;
1157
1158         spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
1159
1160         if (streamer_priv->free_tx_ring_entries) {
1161                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].status = 0;
1162                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].bufcnt_framelen = 0x00020000 | skb->len;
1163                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buffer = 
1164                         cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE));
1165                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd1 = skb->len;
1166                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd2 = 0;
1167                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd3 = 0;
1168                 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buflen = skb->len;
1169
1170                 streamer_priv->tx_ring_skb[streamer_priv->tx_ring_free] = skb;
1171                 streamer_priv->free_tx_ring_entries--;
1172 #if STREAMER_DEBUG_PACKETS
1173                 {
1174                         int i;
1175                         printk("streamer_xmit packet print:\n");
1176                         for (i = 0; i < skb->len; i++) {
1177                                 printk("%x:", skb->data[i]);
1178                                 if (((i + 1) % 16) == 0)
1179                                         printk("\n");
1180                         }
1181                         printk("\n");
1182                 }
1183 #endif
1184
1185                 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, 
1186                                         &streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free],
1187                                         sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE)),
1188                         streamer_mmio + TX2LFDA);
1189                 (void)readl(streamer_mmio + TX2LFDA);
1190
1191                 streamer_priv->tx_ring_free = (streamer_priv->tx_ring_free + 1) & (STREAMER_TX_RING_SIZE - 1);
1192                 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
1193                 return 0;
1194         } else {
1195                 netif_stop_queue(dev);
1196                 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
1197                 return 1;
1198         }
1199 }
1200
1201
1202 static int streamer_close(struct net_device *dev)
1203 {
1204         struct streamer_private *streamer_priv =
1205             netdev_priv(dev);
1206         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1207         unsigned long flags;
1208         int i;
1209
1210         netif_stop_queue(dev);
1211         netif_carrier_off(dev);
1212         writew(streamer_priv->srb, streamer_mmio + LAPA);
1213         writew(htons(SRB_CLOSE_ADAPTER << 8),streamer_mmio+LAPDINC);
1214         writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1215
1216         spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
1217
1218         streamer_priv->srb_queued = 1;
1219         writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1220
1221         spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags);
1222
1223         while (streamer_priv->srb_queued) 
1224         {
1225                 interruptible_sleep_on_timeout(&streamer_priv->srb_wait,
1226                                                jiffies + 60 * HZ);
1227                 if (signal_pending(current)) 
1228                 {
1229                         printk(KERN_WARNING "%s: SRB timed out.\n", dev->name);
1230                         printk(KERN_WARNING "SISR=%x MISR=%x LISR=%x\n",
1231                                readw(streamer_mmio + SISR),
1232                                readw(streamer_mmio + MISR_RUM),
1233                                readw(streamer_mmio + LISR));
1234                         streamer_priv->srb_queued = 0;
1235                         break;
1236                 }
1237         }
1238
1239         streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
1240
1241         for (i = 0; i < STREAMER_RX_RING_SIZE; i++) {
1242                 if (streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]) {
1243                         dev_kfree_skb(streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]);
1244                 } 
1245                 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
1246         }
1247
1248         /* reset tx/rx fifo's and busmaster logic */
1249
1250         /* TBD. Add graceful way to reset the LLC channel without doing a soft reset. 
1251            writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL);
1252            udelay(1);
1253            writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL);
1254          */
1255
1256 #if STREAMER_DEBUG
1257         writew(streamer_priv->srb, streamer_mmio + LAPA);
1258         printk("srb): ");
1259         for (i = 0; i < 2; i++) {
1260                 printk("%x ", ntohs(readw(streamer_mmio + LAPDINC)));
1261         }
1262         printk("\n");
1263 #endif
1264         free_irq(dev->irq, dev);
1265         return 0;
1266 }
1267
1268 static void streamer_set_rx_mode(struct net_device *dev)
1269 {
1270         struct streamer_private *streamer_priv =
1271             netdev_priv(dev);
1272         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1273         __u8 options = 0;
1274         struct dev_mc_list *dmi;
1275         unsigned char dev_mc_address[5];
1276         int i;
1277
1278         writel(streamer_priv->srb, streamer_mmio + LAPA);
1279         options = streamer_priv->streamer_copy_all_options;
1280
1281         if (dev->flags & IFF_PROMISC)
1282                 options |= (3 << 5);    /* All LLC and MAC frames, all through the main rx channel */
1283         else
1284                 options &= ~(3 << 5);
1285
1286         /* Only issue the srb if there is a change in options */
1287
1288         if ((options ^ streamer_priv->streamer_copy_all_options)) 
1289         {
1290                 /* Now to issue the srb command to alter the copy.all.options */
1291                 writew(htons(SRB_MODIFY_RECEIVE_OPTIONS << 8), streamer_mmio+LAPDINC);
1292                 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1293                 writew(htons((streamer_priv->streamer_receive_options << 8) | options),streamer_mmio+LAPDINC);
1294                 writew(htons(0x4a41),streamer_mmio+LAPDINC);
1295                 writew(htons(0x4d45),streamer_mmio+LAPDINC);
1296                 writew(htons(0x5320),streamer_mmio+LAPDINC);
1297                 writew(0x2020, streamer_mmio + LAPDINC);
1298
1299                 streamer_priv->srb_queued = 2;  /* Can't sleep, use srb_bh */
1300
1301                 writel(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1302
1303                 streamer_priv->streamer_copy_all_options = options;
1304                 return;
1305         }
1306
1307         /* Set the functional addresses we need for multicast */
1308         writel(streamer_priv->srb,streamer_mmio+LAPA);
1309         dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ; 
1310   
1311         for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) 
1312         { 
1313                 dev_mc_address[0] |= dmi->dmi_addr[2] ; 
1314                 dev_mc_address[1] |= dmi->dmi_addr[3] ; 
1315                 dev_mc_address[2] |= dmi->dmi_addr[4] ; 
1316                 dev_mc_address[3] |= dmi->dmi_addr[5] ; 
1317         }
1318   
1319         writew(htons(SRB_SET_FUNC_ADDRESS << 8),streamer_mmio+LAPDINC);
1320         writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1321         writew(0,streamer_mmio+LAPDINC);
1322         writew(htons( (dev_mc_address[0] << 8) | dev_mc_address[1]),streamer_mmio+LAPDINC);
1323         writew(htons( (dev_mc_address[2] << 8) | dev_mc_address[3]),streamer_mmio+LAPDINC);
1324         streamer_priv->srb_queued = 2 ; 
1325         writel(LISR_SRB_CMD,streamer_mmio+LISR_SUM);
1326 }
1327
1328 static void streamer_srb_bh(struct net_device *dev)
1329 {
1330         struct streamer_private *streamer_priv = netdev_priv(dev);
1331         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1332         __u16 srb_word;
1333
1334         writew(streamer_priv->srb, streamer_mmio + LAPA);
1335         srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1336
1337         switch (srb_word) {
1338
1339                 /* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous) 
1340                  * At some point we should do something if we get an error, such as
1341                  * resetting the IFF_PROMISC flag in dev
1342                  */
1343
1344         case SRB_MODIFY_RECEIVE_OPTIONS:
1345                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1346
1347                 switch (srb_word) {
1348                 case 0x01:
1349                         printk(KERN_WARNING "%s: Unrecognized srb command\n", dev->name);
1350                         break;
1351                 case 0x04:
1352                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1353                         break;
1354                 default:
1355                         if (streamer_priv->streamer_message_level)
1356                                 printk(KERN_WARNING "%s: Receive Options Modified to %x,%x\n",
1357                                        dev->name,
1358                                        streamer_priv->streamer_copy_all_options,
1359                                        streamer_priv->streamer_receive_options);
1360                         break;
1361                 }               /* switch srb[2] */
1362                 break;
1363
1364
1365                 /* SRB_SET_GROUP_ADDRESS - Multicast group setting 
1366                  */
1367         case SRB_SET_GROUP_ADDRESS:
1368                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1369                 switch (srb_word) {
1370                 case 0x00:
1371                         break;
1372                 case 0x01:
1373                         printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name);
1374                         break;
1375                 case 0x04:
1376                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1377                         break;
1378                 case 0x3c:
1379                         printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctly\n", dev->name);
1380                         break;
1381                 case 0x3e:      /* If we ever implement individual multicast addresses, will need to deal with this */
1382                         printk(KERN_WARNING "%s: Group address registers full\n", dev->name);
1383                         break;
1384                 case 0x55:
1385                         printk(KERN_INFO "%s: Group Address already set.\n", dev->name);
1386                         break;
1387                 default:
1388                         break;
1389                 }               /* switch srb[2] */
1390                 break;
1391
1392
1393                 /* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list
1394                  */
1395         case SRB_RESET_GROUP_ADDRESS:
1396                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1397                 switch (srb_word) {
1398                 case 0x00:
1399                         break;
1400                 case 0x01:
1401                         printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1402                         break;
1403                 case 0x04:
1404                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1405                         break;
1406                 case 0x39:      /* Must deal with this if individual multicast addresses used */
1407                         printk(KERN_INFO "%s: Group address not found \n", dev->name);
1408                         break;
1409                 default:
1410                         break;
1411                 }               /* switch srb[2] */
1412                 break;
1413
1414
1415                 /* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode 
1416                  */
1417
1418         case SRB_SET_FUNC_ADDRESS:
1419                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1420                 switch (srb_word) {
1421                 case 0x00:
1422                         if (streamer_priv->streamer_message_level)
1423                                 printk(KERN_INFO "%s: Functional Address Mask Set \n", dev->name);
1424                         break;
1425                 case 0x01:
1426                         printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1427                         break;
1428                 case 0x04:
1429                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1430                         break;
1431                 default:
1432                         break;
1433                 }               /* switch srb[2] */
1434                 break;
1435
1436                 /* SRB_READ_LOG - Read and reset the adapter error counters
1437                  */
1438
1439         case SRB_READ_LOG:
1440                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1441                 switch (srb_word) {
1442                 case 0x00:
1443                         {
1444                                 int i;
1445                                 if (streamer_priv->streamer_message_level)
1446                                         printk(KERN_INFO "%s: Read Log command complete\n", dev->name);
1447                                 printk("Read Log statistics: ");
1448                                 writew(streamer_priv->srb + 6,
1449                                        streamer_mmio + LAPA);
1450                                 for (i = 0; i < 5; i++) {
1451                                         printk("%x:", ntohs(readw(streamer_mmio + LAPDINC)));
1452                                 }
1453                                 printk("\n");
1454                         }
1455                         break;
1456                 case 0x01:
1457                         printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1458                         break;
1459                 case 0x04:
1460                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1461                         break;
1462
1463                 }               /* switch srb[2] */
1464                 break;
1465
1466                 /* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */
1467
1468         case SRB_READ_SR_COUNTERS:
1469                 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1470                 switch (srb_word) {
1471                 case 0x00:
1472                         if (streamer_priv->streamer_message_level)
1473                                 printk(KERN_INFO "%s: Read Source Routing Counters issued\n", dev->name);
1474                         break;
1475                 case 0x01:
1476                         printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1477                         break;
1478                 case 0x04:
1479                         printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1480                         break;
1481                 default:
1482                         break;
1483                 }               /* switch srb[2] */
1484                 break;
1485
1486         default:
1487                 printk(KERN_WARNING "%s: Unrecognized srb bh return value.\n", dev->name);
1488                 break;
1489         }                       /* switch srb[0] */
1490 }
1491
1492 static struct net_device_stats *streamer_get_stats(struct net_device *dev)
1493 {
1494         struct streamer_private *streamer_priv;
1495         streamer_priv = netdev_priv(dev);
1496         return (struct net_device_stats *) &streamer_priv->streamer_stats;
1497 }
1498
1499 static int streamer_set_mac_address(struct net_device *dev, void *addr)
1500 {
1501         struct sockaddr *saddr = addr;
1502         struct streamer_private *streamer_priv = netdev_priv(dev);
1503
1504         if (netif_running(dev)) 
1505         {
1506                 printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name);
1507                 return -EIO;
1508         }
1509
1510         memcpy(streamer_priv->streamer_laa, saddr->sa_data, dev->addr_len);
1511
1512         if (streamer_priv->streamer_message_level) {
1513                 printk(KERN_INFO "%s: MAC/LAA Set to  = %x.%x.%x.%x.%x.%x\n",
1514                        dev->name, streamer_priv->streamer_laa[0],
1515                        streamer_priv->streamer_laa[1],
1516                        streamer_priv->streamer_laa[2],
1517                        streamer_priv->streamer_laa[3],
1518                        streamer_priv->streamer_laa[4],
1519                        streamer_priv->streamer_laa[5]);
1520         }
1521         return 0;
1522 }
1523
1524 static void streamer_arb_cmd(struct net_device *dev)
1525 {
1526         struct streamer_private *streamer_priv =
1527             netdev_priv(dev);
1528         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1529         __u8 header_len;
1530         __u16 frame_len, buffer_len;
1531         struct sk_buff *mac_frame;
1532         __u8 frame_data[256];
1533         __u16 buff_off;
1534         __u16 lan_status = 0, lan_status_diff;  /* Initialize to stop compiler warning */
1535         __u8 fdx_prot_error;
1536         __u16 next_ptr;
1537         __u16 arb_word;
1538
1539 #if STREAMER_NETWORK_MONITOR
1540         struct trh_hdr *mac_hdr;
1541         DECLARE_MAC_BUF(mac);
1542 #endif
1543
1544         writew(streamer_priv->arb, streamer_mmio + LAPA);
1545         arb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8;
1546         
1547         if (arb_word == ARB_RECEIVE_DATA) {     /* Receive.data, MAC frames */
1548                 writew(streamer_priv->arb + 6, streamer_mmio + LAPA);
1549                 streamer_priv->mac_rx_buffer = buff_off = ntohs(readw(streamer_mmio + LAPDINC));
1550                 header_len=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; /* 802.5 Token-Ring Header Length */
1551                 frame_len = ntohs(readw(streamer_mmio + LAPDINC));
1552
1553 #if STREAMER_DEBUG
1554                 {
1555                         int i;
1556                         __u16 next;
1557                         __u8 status;
1558                         __u16 len;
1559
1560                         writew(ntohs(buff_off), streamer_mmio + LAPA);  /*setup window to frame data */
1561                         next = htons(readw(streamer_mmio + LAPDINC));
1562                         status =
1563                             ntohs(readw(streamer_mmio + LAPDINC)) & 0xff;
1564                         len = ntohs(readw(streamer_mmio + LAPDINC));
1565
1566                         /* print out 1st 14 bytes of frame data */
1567                         for (i = 0; i < 7; i++) {
1568                                 printk("Loc %d = %04x\n", i,
1569                                        ntohs(readw
1570                                              (streamer_mmio + LAPDINC)));
1571                         }
1572
1573                         printk("next %04x, fs %02x, len %04x \n", next,
1574                                status, len);
1575                 }
1576 #endif
1577                 if (!(mac_frame = dev_alloc_skb(frame_len))) {
1578                         printk(KERN_WARNING "%s: Memory squeeze, dropping frame.\n",
1579                                dev->name);
1580                         goto drop_frame;
1581                 }
1582                 /* Walk the buffer chain, creating the frame */
1583
1584                 do {
1585                         int i;
1586                         __u16 rx_word;
1587
1588                         writew(htons(buff_off), streamer_mmio + LAPA);  /* setup window to frame data */
1589                         next_ptr = ntohs(readw(streamer_mmio + LAPDINC));
1590                         readw(streamer_mmio + LAPDINC); /* read thru status word */
1591                         buffer_len = ntohs(readw(streamer_mmio + LAPDINC));
1592
1593                         if (buffer_len > 256)
1594                                 break;
1595
1596                         i = 0;
1597                         while (i < buffer_len) {
1598                                 rx_word=ntohs(readw(streamer_mmio+LAPDINC));
1599                                 frame_data[i]=rx_word >> 8;
1600                                 frame_data[i+1]=rx_word & 0xff;
1601                                 i += 2;
1602                         }
1603
1604                         memcpy(skb_put(mac_frame, buffer_len),
1605                                       frame_data, buffer_len);
1606                 } while (next_ptr && (buff_off = next_ptr));
1607
1608                 mac_frame->protocol = tr_type_trans(mac_frame, dev);
1609 #if STREAMER_NETWORK_MONITOR
1610                 printk(KERN_WARNING "%s: Received MAC Frame, details: \n",
1611                        dev->name);
1612                 mac_hdr = tr_hdr(mac_frame);
1613                 printk(KERN_WARNING
1614                        "%s: MAC Frame Dest. Addr: %s\n",
1615                        dev->name, print_mac(mac, mac_hdr->daddr));
1616                 printk(KERN_WARNING
1617                        "%s: MAC Frame Srce. Addr: %s\n",
1618                        dev->name, DEV->ADDR6(mac_hdr->saddr));
1619 #endif
1620                 netif_rx(mac_frame);
1621
1622                 /* Now tell the card we have dealt with the received frame */
1623 drop_frame:
1624                 /* Set LISR Bit 1 */
1625                 writel(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM);
1626
1627                 /* Is the ASB free ? */
1628
1629                 if (!(readl(streamer_priv->streamer_mmio + SISR) & SISR_ASB_FREE)) 
1630                 {
1631                         streamer_priv->asb_queued = 1;
1632                         writel(LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1633                         return;
1634                         /* Drop out and wait for the bottom half to be run */
1635                 }
1636
1637
1638                 writew(streamer_priv->asb, streamer_mmio + LAPA);
1639                 writew(htons(ASB_RECEIVE_DATA << 8), streamer_mmio+LAPDINC);
1640                 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1641                 writew(0, streamer_mmio + LAPDINC);
1642                 writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD);
1643
1644                 writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1645
1646                 streamer_priv->asb_queued = 2;
1647                 return;
1648
1649         } else if (arb_word == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */
1650                 writew(streamer_priv->arb + 6, streamer_mmio + LAPA);
1651                 lan_status = ntohs(readw(streamer_mmio + LAPDINC));
1652                 fdx_prot_error = ntohs(readw(streamer_mmio+LAPD)) >> 8;
1653                 
1654                 /* Issue ARB Free */
1655                 writew(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM);
1656
1657                 lan_status_diff = (streamer_priv->streamer_lan_status ^ lan_status) & 
1658                     lan_status; 
1659
1660                 if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR)) 
1661                 {
1662                         if (lan_status_diff & LSC_LWF)
1663                                 printk(KERN_WARNING "%s: Short circuit detected on the lobe\n", dev->name);
1664                         if (lan_status_diff & LSC_ARW)
1665                                 printk(KERN_WARNING "%s: Auto removal error\n", dev->name);
1666                         if (lan_status_diff & LSC_FPE)
1667                                 printk(KERN_WARNING "%s: FDX Protocol Error\n", dev->name);
1668                         if (lan_status_diff & LSC_RR)
1669                                 printk(KERN_WARNING "%s: Force remove MAC frame received\n", dev->name);
1670
1671                         /* Adapter has been closed by the hardware */
1672
1673                         /* reset tx/rx fifo's and busmaster logic */
1674
1675                         /* @TBD. no llc reset on autostreamer writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL);
1676                            udelay(1);
1677                            writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL); */
1678
1679                         netif_stop_queue(dev);
1680                         netif_carrier_off(dev);
1681                         printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name);
1682                 }
1683                 /* If serious error */
1684                 if (streamer_priv->streamer_message_level) {
1685                         if (lan_status_diff & LSC_SIG_LOSS)
1686                                 printk(KERN_WARNING "%s: No receive signal detected \n", dev->name);
1687                         if (lan_status_diff & LSC_HARD_ERR) 
1688                                 printk(KERN_INFO "%s: Beaconing \n", dev->name);
1689                         if (lan_status_diff & LSC_SOFT_ERR)
1690                                 printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n", dev->name);
1691                         if (lan_status_diff & LSC_TRAN_BCN)
1692                                 printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n", dev->name);
1693                         if (lan_status_diff & LSC_SS)
1694                                 printk(KERN_INFO "%s: Single Station on the ring \n", dev->name);
1695                         if (lan_status_diff & LSC_RING_REC)
1696                                 printk(KERN_INFO "%s: Ring recovery ongoing\n", dev->name);
1697                         if (lan_status_diff & LSC_FDX_MODE)
1698                                 printk(KERN_INFO "%s: Operating in FDX mode\n", dev->name);
1699                 }
1700
1701                 if (lan_status_diff & LSC_CO) {
1702                         if (streamer_priv->streamer_message_level)
1703                                 printk(KERN_INFO "%s: Counter Overflow \n", dev->name);
1704
1705                         /* Issue READ.LOG command */
1706
1707                         writew(streamer_priv->srb, streamer_mmio + LAPA);
1708                         writew(htons(SRB_READ_LOG << 8),streamer_mmio+LAPDINC);
1709                         writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1710                         writew(0, streamer_mmio + LAPDINC);
1711                         streamer_priv->srb_queued = 2;  /* Can't sleep, use srb_bh */
1712
1713                         writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1714                 }
1715
1716                 if (lan_status_diff & LSC_SR_CO) {
1717                         if (streamer_priv->streamer_message_level)
1718                                 printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name);
1719
1720                         /* Issue a READ.SR.COUNTERS */
1721                         writew(streamer_priv->srb, streamer_mmio + LAPA);
1722                         writew(htons(SRB_READ_SR_COUNTERS << 8),
1723                                streamer_mmio+LAPDINC);
1724                         writew(htons(STREAMER_CLEAR_RET_CODE << 8),
1725                                streamer_mmio+LAPDINC);
1726                         streamer_priv->srb_queued = 2;  /* Can't sleep, use srb_bh */
1727                         writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1728
1729                 }
1730                 streamer_priv->streamer_lan_status = lan_status;
1731         } /* Lan.change.status */
1732         else
1733                 printk(KERN_WARNING "%s: Unknown arb command \n", dev->name);
1734 }
1735
1736 static void streamer_asb_bh(struct net_device *dev)
1737 {
1738         struct streamer_private *streamer_priv =
1739             netdev_priv(dev);
1740         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1741
1742         if (streamer_priv->asb_queued == 1) 
1743         {
1744                 /* Dropped through the first time */
1745
1746                 writew(streamer_priv->asb, streamer_mmio + LAPA);
1747                 writew(htons(ASB_RECEIVE_DATA << 8),streamer_mmio+LAPDINC);
1748                 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1749                 writew(0, streamer_mmio + LAPDINC);
1750                 writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD);
1751
1752                 writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1753                 streamer_priv->asb_queued = 2;
1754
1755                 return;
1756         }
1757
1758         if (streamer_priv->asb_queued == 2) {
1759                 __u8 rc;
1760                 writew(streamer_priv->asb + 2, streamer_mmio + LAPA);
1761                 rc=ntohs(readw(streamer_mmio+LAPD)) >> 8;
1762                 switch (rc) {
1763                 case 0x01:
1764                         printk(KERN_WARNING "%s: Unrecognized command code \n", dev->name);
1765                         break;
1766                 case 0x26:
1767                         printk(KERN_WARNING "%s: Unrecognized buffer address \n", dev->name);
1768                         break;
1769                 case 0xFF:
1770                         /* Valid response, everything should be ok again */
1771                         break;
1772                 default:
1773                         printk(KERN_WARNING "%s: Invalid return code in asb\n", dev->name);
1774                         break;
1775                 }
1776         }
1777         streamer_priv->asb_queued = 0;
1778 }
1779
1780 static int streamer_change_mtu(struct net_device *dev, int mtu)
1781 {
1782         struct streamer_private *streamer_priv =
1783             netdev_priv(dev);
1784         __u16 max_mtu;
1785
1786         if (streamer_priv->streamer_ring_speed == 4)
1787                 max_mtu = 4500;
1788         else
1789                 max_mtu = 18000;
1790
1791         if (mtu > max_mtu)
1792                 return -EINVAL;
1793         if (mtu < 100)
1794                 return -EINVAL;
1795
1796         dev->mtu = mtu;
1797         streamer_priv->pkt_buf_sz = mtu + TR_HLEN;
1798
1799         return 0;
1800 }
1801
1802 #if STREAMER_NETWORK_MONITOR
1803 #ifdef CONFIG_PROC_FS
1804 static int streamer_proc_info(char *buffer, char **start, off_t offset,
1805                               int length, int *eof, void *data)
1806 {
1807   struct streamer_private *sdev=NULL;
1808         struct pci_dev *pci_device = NULL;
1809         int len = 0;
1810         off_t begin = 0;
1811         off_t pos = 0;
1812         int size;
1813
1814   struct net_device *dev;
1815
1816         size = sprintf(buffer, "IBM LanStreamer/MPC Chipset Token Ring Adapters\n");
1817
1818         pos += size;
1819         len += size;
1820
1821   for(sdev=dev_streamer; sdev; sdev=sdev->next) {
1822     pci_device=sdev->pci_dev;
1823     dev=pci_get_drvdata(pci_device);
1824
1825                                 size = sprintf_info(buffer + len, dev);
1826                                 len += size;
1827                                 pos = begin + len;
1828
1829                                 if (pos < offset) {
1830                                         len = 0;
1831                                         begin = pos;
1832                                 }
1833                                 if (pos > offset + length)
1834                                         break;
1835                 }               /* for */
1836
1837         *start = buffer + (offset - begin);     /* Start of wanted data */
1838         len -= (offset - begin);        /* Start slop */
1839         if (len > length)
1840                 len = length;   /* Ending slop */
1841         return len;
1842 }
1843
1844 static int sprintf_info(char *buffer, struct net_device *dev)
1845 {
1846         struct streamer_private *streamer_priv =
1847             netdev_priv(dev);
1848         __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1849         struct streamer_adapter_addr_table sat;
1850         struct streamer_parameters_table spt;
1851         int size = 0;
1852         int i;
1853         DECLARE_MAC_BUF(mac);
1854         DECLARE_MAC_BUF(mac2);
1855
1856         writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA);
1857         for (i = 0; i < 14; i += 2) {
1858                 __u16 io_word;
1859                 __u8 *datap = (__u8 *) & sat;
1860                 io_word=ntohs(readw(streamer_mmio+LAPDINC));
1861                 datap[size]=io_word >> 8;
1862                 datap[size+1]=io_word & 0xff;
1863         }
1864         writew(streamer_priv->streamer_parms_addr, streamer_mmio + LAPA);
1865         for (i = 0; i < 68; i += 2) {
1866                 __u16 io_word;
1867                 __u8 *datap = (__u8 *) & spt;
1868                 io_word=ntohs(readw(streamer_mmio+LAPDINC));
1869                 datap[size]=io_word >> 8;
1870                 datap[size+1]=io_word & 0xff;
1871         }
1872
1873         size = sprintf(buffer, "\n%6s: Adapter Address   : Node Address      : Functional Addr\n", dev->name);
1874
1875         size += sprintf(buffer + size,
1876                         "%6s: %s : %s : %02x:%02x:%02x:%02x\n",
1877                         dev->name, print_mac(mac, dev->dev_addr),
1878                         print_mac(mac2, sat.node_addr),
1879                         sat.func_addr[0], sat.func_addr[1],
1880                         sat.func_addr[2], sat.func_addr[3]);
1881
1882         size += sprintf(buffer + size, "\n%6s: Token Ring Parameters Table:\n", dev->name);
1883
1884         size += sprintf(buffer + size, "%6s: Physical Addr : Up Node Address   : Poll Address      : AccPri : Auth Src : Att Code :\n", dev->name);
1885
1886         size += sprintf(buffer + size,
1887                     "%6s: %02x:%02x:%02x:%02x   : %s : %s : %04x   : %04x     :  %04x    :\n",
1888                     dev->name, spt.phys_addr[0], spt.phys_addr[1],
1889                     spt.phys_addr[2], spt.phys_addr[3],
1890                     print_mac(mac, spt.up_node_addr),
1891                     print_mac(mac2, spt.poll_addr),
1892                     ntohs(spt.acc_priority), ntohs(spt.auth_source_class),
1893                     ntohs(spt.att_code));
1894
1895         size += sprintf(buffer + size, "%6s: Source Address    : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : \n", dev->name);
1896
1897         size += sprintf(buffer + size,
1898                     "%6s: %s : %04x  : %04x   : %04x   : %04x   : %04x    :     %04x     : \n",
1899                     dev->name, print_mac(mac, spt.source_addr),
1900                     ntohs(spt.beacon_type), ntohs(spt.major_vector),
1901                     ntohs(spt.lan_status), ntohs(spt.local_ring),
1902                     ntohs(spt.mon_error), ntohs(spt.frame_correl));
1903
1904         size += sprintf(buffer + size, "%6s: Beacon Details :  Tx  :  Rx  : NAUN Node Address : NAUN Node Phys : \n",
1905                     dev->name);
1906
1907         size += sprintf(buffer + size,
1908                     "%6s:                :  %02x  :  %02x  : %s : %02x:%02x:%02x:%02x    : \n",
1909                     dev->name, ntohs(spt.beacon_transmit),
1910                     ntohs(spt.beacon_receive),
1911                     print_mac(mac, spt.beacon_naun),
1912                     spt.beacon_phys[0], spt.beacon_phys[1],
1913                     spt.beacon_phys[2], spt.beacon_phys[3]);
1914         return size;
1915 }
1916 #endif
1917 #endif
1918
1919 static struct pci_driver streamer_pci_driver = {
1920   .name     = "lanstreamer",
1921   .id_table = streamer_pci_tbl,
1922   .probe    = streamer_init_one,
1923   .remove   = __devexit_p(streamer_remove_one),
1924 };
1925
1926 static int __init streamer_init_module(void) {
1927   return pci_register_driver(&streamer_pci_driver);
1928 }
1929
1930 static void __exit streamer_cleanup_module(void) {
1931   pci_unregister_driver(&streamer_pci_driver);
1932 }
1933
1934 module_init(streamer_init_module);
1935 module_exit(streamer_cleanup_module);
1936 MODULE_LICENSE("GPL");