blob: bd70e818212a32e653aaf4b002162e37f6cb4554 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#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>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400120#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#include <linux/bitops.h>
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800123#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200125#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#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
146static char version[] = "LanStreamer.c v0.4.0 03/08/01 - Mike Sullivan\n"
147 " v0.5.3 11/13/02 - Kent Yoder";
148
149static 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};
153MODULE_DEVICE_TABLE(pci,streamer_pci_tbl);
154
155
156static 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
164static 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
184static int ringspeed[STREAMER_MAX_ADAPTERS] = { 0, };
185
186module_param_array(ringspeed, int, NULL, 0);
187
188/* Packet buffer size */
189
190static int pkt_buf_sz[STREAMER_MAX_ADAPTERS] = { 0, };
191
192module_param_array(pkt_buf_sz, int, NULL, 0);
193
194/* Message Level */
195
196static int message_level[STREAMER_MAX_ADAPTERS] = { 1, };
197
198module_param_array(message_level, int, NULL, 0);
199
200#if STREAMER_IOCTL
201static int streamer_ioctl(struct net_device *, struct ifreq *, int);
202#endif
203
204static int streamer_reset(struct net_device *dev);
205static int streamer_open(struct net_device *dev);
206static int streamer_xmit(struct sk_buff *skb, struct net_device *dev);
207static int streamer_close(struct net_device *dev);
208static void streamer_set_rx_mode(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100209static irqreturn_t streamer_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static struct net_device_stats *streamer_get_stats(struct net_device *dev);
211static int streamer_set_mac_address(struct net_device *dev, void *addr);
212static void streamer_arb_cmd(struct net_device *dev);
213static int streamer_change_mtu(struct net_device *dev, int mtu);
214static void streamer_srb_bh(struct net_device *dev);
215static void streamer_asb_bh(struct net_device *dev);
216#if STREAMER_NETWORK_MONITOR
217#ifdef CONFIG_PROC_FS
218static int streamer_proc_info(char *buffer, char **start, off_t offset,
219 int length, int *eof, void *data);
220static int sprintf_info(char *buffer, struct net_device *dev);
221struct streamer_private *dev_streamer=NULL;
222#endif
223#endif
224
225static 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
Yoann Padioleaueda10532007-07-23 15:18:21 +0200247 streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249#if STREAMER_NETWORK_MONITOR
250#ifdef CONFIG_PROC_FS
251 if (!dev_streamer)
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200252 create_proc_read_entry("streamer_tr", 0, init_net.proc_net,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 streamer_proc_info, NULL);
254 streamer_priv->next = dev_streamer;
255 dev_streamer = streamer_priv;
256#endif
257#endif
258
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400259 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 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
374err_out_unmap:
375 iounmap(streamer_priv->streamer_mmio);
376err_out_free_mmio:
377 release_mem_region(mmio_start, mmio_len);
378err_out_free_pio:
379 release_region(pio_start, pio_len);
380err_out_mwi:
381 pci_clear_mwi(pdev);
382err_out_disable:
383 pci_disable_device(pdev);
384err_out:
385 free_netdev(dev);
386#if STREAMER_DEBUG
387 printk("lanstreamer: Exit error %x\n",rc);
388#endif
389 return rc;
390}
391
392static 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
Yoann Padioleaueda10532007-07-23 15:18:21 +0200406 streamer_priv=netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 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)
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200425 remove_proc_entry("streamer_tr", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
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
441static 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
Yoann Padioleaueda10532007-07-23 15:18:21 +0200450 streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 streamer_mmio = streamer_priv->streamer_mmio;
452
453 writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL);
454 t = jiffies;
455 /* Hold soft reset bit for a while */
Nishanth Aravamudan4f2ad812005-06-20 23:53:40 +0200456 ssleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET,
459 streamer_mmio + BCTL);
460
461#if STREAMER_DEBUG
462 printk("BCTL: %x\n", readw(streamer_mmio + BCTL));
463 printk("GPR: %x\n", readw(streamer_mmio + GPR));
464 printk("SISRMASK: %x\n", readw(streamer_mmio + SISR_MASK));
465#endif
466 writew(readw(streamer_mmio + BCTL) | (BCTL_RX_FIFO_8 | BCTL_TX_FIFO_8), streamer_mmio + BCTL );
467
468 if (streamer_priv->streamer_ring_speed == 0) { /* Autosense */
469 writew(readw(streamer_mmio + GPR) | GPR_AUTOSENSE,
470 streamer_mmio + GPR);
471 if (streamer_priv->streamer_message_level)
472 printk(KERN_INFO "%s: Ringspeed autosense mode on\n",
473 dev->name);
474 } else if (streamer_priv->streamer_ring_speed == 16) {
475 if (streamer_priv->streamer_message_level)
476 printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n",
477 dev->name);
478 writew(GPR_16MBPS, streamer_mmio + GPR);
479 } else if (streamer_priv->streamer_ring_speed == 4) {
480 if (streamer_priv->streamer_message_level)
481 printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n",
482 dev->name);
483 writew(0, streamer_mmio + GPR);
484 }
485
486 skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
487 if (!skb) {
488 printk(KERN_INFO "%s: skb allocation for diagnostics failed...proceeding\n",
489 dev->name);
490 } else {
491 struct streamer_rx_desc *rx_ring;
492 u8 *data;
493
494 rx_ring=(struct streamer_rx_desc *)skb->data;
495 data=((u8 *)skb->data)+sizeof(struct streamer_rx_desc);
496 rx_ring->forward=0;
497 rx_ring->status=0;
498 rx_ring->buffer=cpu_to_le32(pci_map_single(streamer_priv->pci_dev, data,
499 512, PCI_DMA_FROMDEVICE));
500 rx_ring->framelen_buflen=512;
501 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, rx_ring, 512, PCI_DMA_FROMDEVICE)),
502 streamer_mmio+RXBDA);
503 }
504
505#if STREAMER_DEBUG
506 printk("GPR = %x\n", readw(streamer_mmio + GPR));
507#endif
508 /* start solo init */
509 writew(SISR_MI, streamer_mmio + SISR_MASK_SUM);
510
511 while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) {
Nishanth Aravamudan4f2ad812005-06-20 23:53:40 +0200512 msleep_interruptible(100);
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800513 if (time_after(jiffies, t + 40 * HZ)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 printk(KERN_ERR
515 "IBM PCI tokenring card not responding\n");
516 release_region(dev->base_addr, STREAMER_IO_SPACE);
517 if (skb)
518 dev_kfree_skb(skb);
519 return -1;
520 }
521 }
522 writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM);
523 misr = readw(streamer_mmio + MISR_RUM);
524 writew(~misr, streamer_mmio + MISR_RUM);
525
526 if (skb)
527 dev_kfree_skb(skb); /* release skb used for diagnostics */
528
529#if STREAMER_DEBUG
530 printk("LAPWWO: %x, LAPA: %x LAPE: %x\n",
531 readw(streamer_mmio + LAPWWO), readw(streamer_mmio + LAPA),
532 readw(streamer_mmio + LAPE));
533#endif
534
535#if STREAMER_DEBUG
536 {
537 int i;
538 writew(readw(streamer_mmio + LAPWWO),
539 streamer_mmio + LAPA);
540 printk("initialization response srb dump: ");
541 for (i = 0; i < 10; i++)
542 printk("%x:",
543 ntohs(readw(streamer_mmio + LAPDINC)));
544 printk("\n");
545 }
546#endif
547
548 writew(readw(streamer_mmio + LAPWWO) + 6, streamer_mmio + LAPA);
549 if (readw(streamer_mmio + LAPD)) {
550 printk(KERN_INFO "tokenring card initialization failed. errorcode : %x\n",
551 ntohs(readw(streamer_mmio + LAPD)));
552 release_region(dev->base_addr, STREAMER_IO_SPACE);
553 return -1;
554 }
555
556 writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA);
557 uaa_addr = ntohs(readw(streamer_mmio + LAPDINC));
558 readw(streamer_mmio + LAPDINC); /* skip over Level.Addr field */
559 streamer_priv->streamer_addr_table_addr = ntohs(readw(streamer_mmio + LAPDINC));
560 streamer_priv->streamer_parms_addr = ntohs(readw(streamer_mmio + LAPDINC));
561
562#if STREAMER_DEBUG
563 printk("UAA resides at %x\n", uaa_addr);
564#endif
565
566 /* setup uaa area for access with LAPD */
567 {
568 int i;
569 __u16 addr;
570 writew(uaa_addr, streamer_mmio + LAPA);
571 for (i = 0; i < 6; i += 2) {
572 addr=ntohs(readw(streamer_mmio+LAPDINC));
573 dev->dev_addr[i]= (addr >> 8) & 0xff;
574 dev->dev_addr[i+1]= addr & 0xff;
575 }
576#if STREAMER_DEBUG
Johannes Berge1749612008-10-27 15:59:26 -0700577 printk("Adapter address: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#endif
579 }
580 return 0;
581}
582
583static int streamer_open(struct net_device *dev)
584{
Yoann Padioleaueda10532007-07-23 15:18:21 +0200585 struct streamer_private *streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
587 unsigned long flags;
588 char open_error[255];
589 int i, open_finished = 1;
590 __u16 srb_word;
591 __u16 srb_open;
592 int rc;
593
594 if (readw(streamer_mmio+BMCTL_SUM) & BMCTL_RX_ENABLED) {
595 rc=streamer_reset(dev);
596 }
597
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700598 if (request_irq(dev->irq, &streamer_interrupt, IRQF_SHARED, "lanstreamer", dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return -EAGAIN;
600 }
601#if STREAMER_DEBUG
602 printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM));
603 printk("pending ints: %x\n", readw(streamer_mmio + SISR));
604#endif
605
606 writew(SISR_MI | SISR_SRB_REPLY, streamer_mmio + SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */
607 writew(LISR_LIE, streamer_mmio + LISR); /* more ints later */
608
609 /* adapter is closed, so SRB is pointed to by LAPWWO */
610 writew(readw(streamer_mmio + LAPWWO), streamer_mmio + LAPA);
611
612#if STREAMER_DEBUG
613 printk("LAPWWO: %x, LAPA: %x\n", readw(streamer_mmio + LAPWWO),
614 readw(streamer_mmio + LAPA));
615 printk("LAPE: %x\n", readw(streamer_mmio + LAPE));
616 printk("SISR Mask = %04x\n", readw(streamer_mmio + SISR_MASK));
617#endif
618 do {
619 int i;
620
621 for (i = 0; i < SRB_COMMAND_SIZE; i += 2) {
622 writew(0, streamer_mmio + LAPDINC);
623 }
624
625 writew(readw(streamer_mmio+LAPWWO),streamer_mmio+LAPA);
626 writew(htons(SRB_OPEN_ADAPTER<<8),streamer_mmio+LAPDINC) ; /* open */
627 writew(htons(STREAMER_CLEAR_RET_CODE<<8),streamer_mmio+LAPDINC);
628 writew(STREAMER_CLEAR_RET_CODE, streamer_mmio + LAPDINC);
629
630 writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA);
631#if STREAMER_NETWORK_MONITOR
632 /* If Network Monitor, instruct card to copy MAC frames through the ARB */
633 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 */
634#else
635 writew(htons(OPEN_ADAPTER_ENABLE_FDX), streamer_mmio + LAPDINC); /* Offset 8 word contains Open.Options */
636#endif
637
638 if (streamer_priv->streamer_laa[0]) {
639 writew(readw(streamer_mmio + LAPWWO) + 12, streamer_mmio + LAPA);
640 writew(htons((streamer_priv->streamer_laa[0] << 8) |
641 streamer_priv->streamer_laa[1]),streamer_mmio+LAPDINC);
642 writew(htons((streamer_priv->streamer_laa[2] << 8) |
643 streamer_priv->streamer_laa[3]),streamer_mmio+LAPDINC);
644 writew(htons((streamer_priv->streamer_laa[4] << 8) |
645 streamer_priv->streamer_laa[5]),streamer_mmio+LAPDINC);
646 memcpy(dev->dev_addr, streamer_priv->streamer_laa, dev->addr_len);
647 }
648
649 /* save off srb open offset */
650 srb_open = readw(streamer_mmio + LAPWWO);
651#if STREAMER_DEBUG
652 writew(readw(streamer_mmio + LAPWWO),
653 streamer_mmio + LAPA);
654 printk("srb open request: \n");
655 for (i = 0; i < 16; i++) {
656 printk("%x:", ntohs(readw(streamer_mmio + LAPDINC)));
657 }
658 printk("\n");
659#endif
660 spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
661 streamer_priv->srb_queued = 1;
662
663 /* signal solo that SRB command has been issued */
664 writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
665 spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags);
666
667 while (streamer_priv->srb_queued) {
668 interruptible_sleep_on_timeout(&streamer_priv->srb_wait, 5 * HZ);
669 if (signal_pending(current)) {
670 printk(KERN_WARNING "%s: SRB timed out.\n", dev->name);
671 printk(KERN_WARNING "SISR=%x MISR=%x, LISR=%x\n",
672 readw(streamer_mmio + SISR),
673 readw(streamer_mmio + MISR_RUM),
674 readw(streamer_mmio + LISR));
675 streamer_priv->srb_queued = 0;
676 break;
677 }
678 }
679
680#if STREAMER_DEBUG
681 printk("SISR_MASK: %x\n", readw(streamer_mmio + SISR_MASK));
682 printk("srb open response:\n");
683 writew(srb_open, streamer_mmio + LAPA);
684 for (i = 0; i < 10; i++) {
685 printk("%x:",
686 ntohs(readw(streamer_mmio + LAPDINC)));
687 }
688#endif
689
690 /* If we get the same return response as we set, the interrupt wasn't raised and the open
691 * timed out.
692 */
693 writew(srb_open + 2, streamer_mmio + LAPA);
694 srb_word = ntohs(readw(streamer_mmio + LAPD)) >> 8;
695 if (srb_word == STREAMER_CLEAR_RET_CODE) {
696 printk(KERN_WARNING "%s: Adapter Open time out or error.\n",
697 dev->name);
698 return -EIO;
699 }
700
701 if (srb_word != 0) {
702 if (srb_word == 0x07) {
703 if (!streamer_priv->streamer_ring_speed && open_finished) { /* Autosense , first time around */
704 printk(KERN_WARNING "%s: Retrying at different ring speed \n",
705 dev->name);
706 open_finished = 0;
707 } else {
708 __u16 error_code;
709
710 writew(srb_open + 6, streamer_mmio + LAPA);
711 error_code = ntohs(readw(streamer_mmio + LAPD));
712 strcpy(open_error, open_maj_error[(error_code & 0xf0) >> 4]);
713 strcat(open_error, " - ");
714 strcat(open_error, open_min_error[(error_code & 0x0f)]);
715
716 if (!streamer_priv->streamer_ring_speed
717 && ((error_code & 0x0f) == 0x0d))
718 {
719 printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors present\n", dev->name);
720 printk(KERN_WARNING "%s: Please try again with a specified ring speed \n", dev->name);
721 free_irq(dev->irq, dev);
722 return -EIO;
723 }
724
725 printk(KERN_WARNING "%s: %s\n",
726 dev->name, open_error);
727 free_irq(dev->irq, dev);
728 return -EIO;
729
730 } /* if autosense && open_finished */
731 } else {
732 printk(KERN_WARNING "%s: Bad OPEN response: %x\n",
733 dev->name, srb_word);
734 free_irq(dev->irq, dev);
735 return -EIO;
736 }
737 } else
738 open_finished = 1;
739 } while (!(open_finished)); /* Will only loop if ring speed mismatch re-open attempted && autosense is on */
740
741 writew(srb_open + 18, streamer_mmio + LAPA);
742 srb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8;
743 if (srb_word & (1 << 3))
744 if (streamer_priv->streamer_message_level)
745 printk(KERN_INFO "%s: Opened in FDX Mode\n", dev->name);
746
747 if (srb_word & 1)
748 streamer_priv->streamer_ring_speed = 16;
749 else
750 streamer_priv->streamer_ring_speed = 4;
751
752 if (streamer_priv->streamer_message_level)
753 printk(KERN_INFO "%s: Opened in %d Mbps mode\n",
754 dev->name,
755 streamer_priv->streamer_ring_speed);
756
757 writew(srb_open + 8, streamer_mmio + LAPA);
758 streamer_priv->asb = ntohs(readw(streamer_mmio + LAPDINC));
759 streamer_priv->srb = ntohs(readw(streamer_mmio + LAPDINC));
760 streamer_priv->arb = ntohs(readw(streamer_mmio + LAPDINC));
761 readw(streamer_mmio + LAPDINC); /* offset 14 word is rsvd */
762 streamer_priv->trb = ntohs(readw(streamer_mmio + LAPDINC));
763
764 streamer_priv->streamer_receive_options = 0x00;
765 streamer_priv->streamer_copy_all_options = 0;
766
767 /* setup rx ring */
768 /* enable rx channel */
769 writew(~BMCTL_RX_DIS, streamer_mmio + BMCTL_RUM);
770
771 /* setup rx descriptors */
772 streamer_priv->streamer_rx_ring=
773 kmalloc( sizeof(struct streamer_rx_desc)*
774 STREAMER_RX_RING_SIZE,GFP_KERNEL);
775 if (!streamer_priv->streamer_rx_ring) {
776 printk(KERN_WARNING "%s ALLOC of streamer rx ring FAILED!!\n",dev->name);
777 return -EIO;
778 }
779
780 for (i = 0; i < STREAMER_RX_RING_SIZE; i++) {
781 struct sk_buff *skb;
782
783 skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
784 if (skb == NULL)
785 break;
786
787 skb->dev = dev;
788
789 streamer_priv->streamer_rx_ring[i].forward =
790 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[i + 1],
791 sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE));
792 streamer_priv->streamer_rx_ring[i].status = 0;
793 streamer_priv->streamer_rx_ring[i].buffer =
794 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data,
795 streamer_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
796 streamer_priv->streamer_rx_ring[i].framelen_buflen = streamer_priv->pkt_buf_sz;
797 streamer_priv->rx_ring_skb[i] = skb;
798 }
799 streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1].forward =
800 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0],
801 sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE));
802
803 if (i == 0) {
804 printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled\n", dev->name);
805 free_irq(dev->irq, dev);
806 return -EIO;
807 }
808
809 streamer_priv->rx_ring_last_received = STREAMER_RX_RING_SIZE - 1; /* last processed rx status */
810
811 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0],
812 sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)),
813 streamer_mmio + RXBDA);
814 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1],
815 sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)),
816 streamer_mmio + RXLBDA);
817
818 /* set bus master interrupt event mask */
819 writew(MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK);
820
821
822 /* setup tx ring */
823 streamer_priv->streamer_tx_ring=kmalloc(sizeof(struct streamer_tx_desc)*
824 STREAMER_TX_RING_SIZE,GFP_KERNEL);
825 if (!streamer_priv->streamer_tx_ring) {
826 printk(KERN_WARNING "%s ALLOC of streamer_tx_ring FAILED\n",dev->name);
827 return -EIO;
828 }
829
830 writew(~BMCTL_TX2_DIS, streamer_mmio + BMCTL_RUM); /* Enables TX channel 2 */
831 for (i = 0; i < STREAMER_TX_RING_SIZE; i++) {
832 streamer_priv->streamer_tx_ring[i].forward = cpu_to_le32(pci_map_single(streamer_priv->pci_dev,
833 &streamer_priv->streamer_tx_ring[i + 1],
834 sizeof(struct streamer_tx_desc),
835 PCI_DMA_TODEVICE));
836 streamer_priv->streamer_tx_ring[i].status = 0;
837 streamer_priv->streamer_tx_ring[i].bufcnt_framelen = 0;
838 streamer_priv->streamer_tx_ring[i].buffer = 0;
839 streamer_priv->streamer_tx_ring[i].buflen = 0;
840 streamer_priv->streamer_tx_ring[i].rsvd1 = 0;
841 streamer_priv->streamer_tx_ring[i].rsvd2 = 0;
842 streamer_priv->streamer_tx_ring[i].rsvd3 = 0;
843 }
844 streamer_priv->streamer_tx_ring[STREAMER_TX_RING_SIZE - 1].forward =
845 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_tx_ring[0],
846 sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE));
847
848 streamer_priv->free_tx_ring_entries = STREAMER_TX_RING_SIZE;
849 streamer_priv->tx_ring_free = 0; /* next entry in tx ring to use */
850 streamer_priv->tx_ring_last_status = STREAMER_TX_RING_SIZE - 1;
851
852 /* set Busmaster interrupt event mask (handle receives on interrupt only */
853 writew(MISR_TX2_EOF | MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK);
854 /* set system event interrupt mask */
855 writew(SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE, streamer_mmio + SISR_MASK_SUM);
856
857#if STREAMER_DEBUG
858 printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM));
859 printk("SISR MASK: %x\n", readw(streamer_mmio + SISR_MASK));
860#endif
861
862#if STREAMER_NETWORK_MONITOR
863
864 writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA);
865 printk("%s: Node Address: %04x:%04x:%04x\n", dev->name,
866 ntohs(readw(streamer_mmio + LAPDINC)),
867 ntohs(readw(streamer_mmio + LAPDINC)),
868 ntohs(readw(streamer_mmio + LAPDINC)));
869 readw(streamer_mmio + LAPDINC);
870 readw(streamer_mmio + LAPDINC);
871 printk("%s: Functional Address: %04x:%04x\n", dev->name,
872 ntohs(readw(streamer_mmio + LAPDINC)),
873 ntohs(readw(streamer_mmio + LAPDINC)));
874
875 writew(streamer_priv->streamer_parms_addr + 4,
876 streamer_mmio + LAPA);
877 printk("%s: NAUN Address: %04x:%04x:%04x\n", dev->name,
878 ntohs(readw(streamer_mmio + LAPDINC)),
879 ntohs(readw(streamer_mmio + LAPDINC)),
880 ntohs(readw(streamer_mmio + LAPDINC)));
881#endif
882
883 netif_start_queue(dev);
884 netif_carrier_on(dev);
885 return 0;
886}
887
888/*
889 * When we enter the rx routine we do not know how many frames have been
890 * queued on the rx channel. Therefore we start at the next rx status
891 * position and travel around the receive ring until we have completed
892 * all the frames.
893 *
894 * This means that we may process the frame before we receive the end
895 * of frame interrupt. This is why we always test the status instead
896 * of blindly processing the next frame.
897 *
898 */
899static void streamer_rx(struct net_device *dev)
900{
901 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +0200902 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
904 struct streamer_rx_desc *rx_desc;
905 int rx_ring_last_received, length, frame_length, buffer_cnt = 0;
906 struct sk_buff *skb, *skb2;
907
908 /* setup the next rx descriptor to be received */
909 rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)];
910 rx_ring_last_received = streamer_priv->rx_ring_last_received;
911
912 while (rx_desc->status & 0x01000000) { /* While processed descriptors are available */
913 if (rx_ring_last_received != streamer_priv->rx_ring_last_received)
914 {
915 printk(KERN_WARNING "RX Error 1 rx_ring_last_received not the same %x %x\n",
916 rx_ring_last_received, streamer_priv->rx_ring_last_received);
917 }
918 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
919 rx_ring_last_received = streamer_priv->rx_ring_last_received;
920
921 length = rx_desc->framelen_buflen & 0xffff; /* buffer length */
922 frame_length = (rx_desc->framelen_buflen >> 16) & 0xffff;
923
924 if (rx_desc->status & 0x7E830000) { /* errors */
925 if (streamer_priv->streamer_message_level) {
926 printk(KERN_WARNING "%s: Rx Error %x \n",
927 dev->name, rx_desc->status);
928 }
929 } else { /* received without errors */
930 if (rx_desc->status & 0x80000000) { /* frame complete */
931 buffer_cnt = 1;
932 skb = dev_alloc_skb(streamer_priv->pkt_buf_sz);
933 } else {
934 skb = dev_alloc_skb(frame_length);
935 }
936
937 if (skb == NULL)
938 {
939 printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers. \n", dev->name);
940 streamer_priv->streamer_stats.rx_dropped++;
941 } else { /* we allocated an skb OK */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 if (buffer_cnt == 1) {
943 /* release the DMA mapping */
944 pci_unmap_single(streamer_priv->pci_dev,
945 le32_to_cpu(streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer),
946 streamer_priv->pkt_buf_sz,
947 PCI_DMA_FROMDEVICE);
948 skb2 = streamer_priv->rx_ring_skb[rx_ring_last_received];
949#if STREAMER_DEBUG_PACKETS
950 {
951 int i;
952 printk("streamer_rx packet print: skb->data2 %p skb->head %p\n", skb2->data, skb2->head);
953 for (i = 0; i < frame_length; i++)
954 {
955 printk("%x:", skb2->data[i]);
956 if (((i + 1) % 16) == 0)
957 printk("\n");
958 }
959 printk("\n");
960 }
961#endif
962 skb_put(skb2, length);
963 skb2->protocol = tr_type_trans(skb2, dev);
964 /* recycle this descriptor */
965 streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0;
966 streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz;
967 streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer =
968 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, streamer_priv->pkt_buf_sz,
969 PCI_DMA_FROMDEVICE));
970 streamer_priv->rx_ring_skb[rx_ring_last_received] = skb;
971 /* place recycled descriptor back on the adapter */
972 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev,
973 &streamer_priv->streamer_rx_ring[rx_ring_last_received],
974 sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE)),
975 streamer_mmio + RXLBDA);
976 /* pass the received skb up to the protocol */
977 netif_rx(skb2);
978 } else {
979 do { /* Walk the buffers */
980 pci_unmap_single(streamer_priv->pci_dev, le32_to_cpu(rx_desc->buffer), length, PCI_DMA_FROMDEVICE),
981 memcpy(skb_put(skb, length), (void *)rx_desc->buffer, length); /* copy this fragment */
982 streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0;
983 streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz;
984
985 /* give descriptor back to the adapter */
986 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev,
987 &streamer_priv->streamer_rx_ring[rx_ring_last_received],
988 length, PCI_DMA_FROMDEVICE)),
989 streamer_mmio + RXLBDA);
990
991 if (rx_desc->status & 0x80000000)
992 break; /* this descriptor completes the frame */
993
994 /* else get the next pending descriptor */
995 if (rx_ring_last_received!= streamer_priv->rx_ring_last_received)
996 {
997 printk("RX Error rx_ring_last_received not the same %x %x\n",
998 rx_ring_last_received,
999 streamer_priv->rx_ring_last_received);
1000 }
1001 rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE-1)];
1002
1003 length = rx_desc->framelen_buflen & 0xffff; /* buffer length */
1004 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE - 1);
1005 rx_ring_last_received = streamer_priv->rx_ring_last_received;
1006 } while (1);
1007
1008 skb->protocol = tr_type_trans(skb, dev);
1009 /* send up to the protocol */
1010 netif_rx(skb);
1011 }
1012 dev->last_rx = jiffies;
1013 streamer_priv->streamer_stats.rx_packets++;
1014 streamer_priv->streamer_stats.rx_bytes += length;
1015 } /* if skb == null */
1016 } /* end received without errors */
1017
1018 /* try the next one */
1019 rx_desc = &streamer_priv->streamer_rx_ring[(rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)];
1020 } /* end for all completed rx descriptors */
1021}
1022
David Howells7d12e782006-10-05 14:55:46 +01001023static irqreturn_t streamer_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024{
1025 struct net_device *dev = (struct net_device *) dev_id;
1026 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001027 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1029 __u16 sisr;
1030 __u16 misr;
1031 u8 max_intr = MAX_INTR;
1032
1033 spin_lock(&streamer_priv->streamer_lock);
1034 sisr = readw(streamer_mmio + SISR);
1035
1036 while((sisr & (SISR_MI | SISR_SRB_REPLY | SISR_ADAPTER_CHECK | SISR_ASB_FREE |
1037 SISR_ARB_CMD | SISR_TRB_REPLY | SISR_PAR_ERR | SISR_SERR_ERR))
1038 && (max_intr > 0)) {
1039
1040 if(sisr & SISR_PAR_ERR) {
1041 writew(~SISR_PAR_ERR, streamer_mmio + SISR_RUM);
1042 (void)readw(streamer_mmio + SISR_RUM);
1043 }
1044
1045 else if(sisr & SISR_SERR_ERR) {
1046 writew(~SISR_SERR_ERR, streamer_mmio + SISR_RUM);
1047 (void)readw(streamer_mmio + SISR_RUM);
1048 }
1049
1050 else if(sisr & SISR_MI) {
1051 misr = readw(streamer_mmio + MISR_RUM);
1052
1053 if (misr & MISR_TX2_EOF) {
1054 while(streamer_priv->streamer_tx_ring[(streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1)].status) {
1055 streamer_priv->tx_ring_last_status = (streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1);
1056 streamer_priv->free_tx_ring_entries++;
1057 streamer_priv->streamer_stats.tx_bytes += streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]->len;
1058 streamer_priv->streamer_stats.tx_packets++;
1059 dev_kfree_skb_irq(streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]);
1060 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buffer = 0xdeadbeef;
1061 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].status = 0;
1062 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].bufcnt_framelen = 0;
1063 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buflen = 0;
1064 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd1 = 0;
1065 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd2 = 0;
1066 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd3 = 0;
1067 }
1068 netif_wake_queue(dev);
1069 }
1070
1071 if (misr & MISR_RX_EOF) {
1072 streamer_rx(dev);
1073 }
1074 /* MISR_RX_EOF */
1075
1076 if (misr & MISR_RX_NOBUF) {
1077 /* According to the documentation, we don't have to do anything,
1078 * but trapping it keeps it out of /var/log/messages.
1079 */
1080 } /* SISR_RX_NOBUF */
1081
1082 writew(~misr, streamer_mmio + MISR_RUM);
1083 (void)readw(streamer_mmio + MISR_RUM);
1084 }
1085
1086 else if (sisr & SISR_SRB_REPLY) {
1087 if (streamer_priv->srb_queued == 1) {
1088 wake_up_interruptible(&streamer_priv->srb_wait);
1089 } else if (streamer_priv->srb_queued == 2) {
1090 streamer_srb_bh(dev);
1091 }
1092 streamer_priv->srb_queued = 0;
1093
1094 writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM);
1095 (void)readw(streamer_mmio + SISR_RUM);
1096 }
1097
1098 else if (sisr & SISR_ADAPTER_CHECK) {
1099 printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:\n", dev->name);
1100 writel(readl(streamer_mmio + LAPWWO), streamer_mmio + LAPA);
1101 printk(KERN_WARNING "%s: Words %x:%x:%x:%x:\n",
1102 dev->name, readw(streamer_mmio + LAPDINC),
1103 ntohs(readw(streamer_mmio + LAPDINC)),
1104 ntohs(readw(streamer_mmio + LAPDINC)),
1105 ntohs(readw(streamer_mmio + LAPDINC)));
1106 netif_stop_queue(dev);
1107 netif_carrier_off(dev);
1108 printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name);
1109 }
1110
1111 /* SISR_ADAPTER_CHECK */
1112 else if (sisr & SISR_ASB_FREE) {
1113 /* Wake up anything that is waiting for the asb response */
1114 if (streamer_priv->asb_queued) {
1115 streamer_asb_bh(dev);
1116 }
1117 writew(~SISR_ASB_FREE, streamer_mmio + SISR_RUM);
1118 (void)readw(streamer_mmio + SISR_RUM);
1119 }
1120 /* SISR_ASB_FREE */
1121 else if (sisr & SISR_ARB_CMD) {
1122 streamer_arb_cmd(dev);
1123 writew(~SISR_ARB_CMD, streamer_mmio + SISR_RUM);
1124 (void)readw(streamer_mmio + SISR_RUM);
1125 }
1126 /* SISR_ARB_CMD */
1127 else if (sisr & SISR_TRB_REPLY) {
1128 /* Wake up anything that is waiting for the trb response */
1129 if (streamer_priv->trb_queued) {
1130 wake_up_interruptible(&streamer_priv->
1131 trb_wait);
1132 }
1133 streamer_priv->trb_queued = 0;
1134 writew(~SISR_TRB_REPLY, streamer_mmio + SISR_RUM);
1135 (void)readw(streamer_mmio + SISR_RUM);
1136 }
1137 /* SISR_TRB_REPLY */
1138
1139 sisr = readw(streamer_mmio + SISR);
1140 max_intr--;
1141 } /* while() */
1142
1143 spin_unlock(&streamer_priv->streamer_lock) ;
1144 return IRQ_HANDLED;
1145}
1146
1147static int streamer_xmit(struct sk_buff *skb, struct net_device *dev)
1148{
1149 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001150 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1152 unsigned long flags ;
1153
1154 spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
1155
1156 if (streamer_priv->free_tx_ring_entries) {
1157 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].status = 0;
1158 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].bufcnt_framelen = 0x00020000 | skb->len;
1159 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buffer =
1160 cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE));
1161 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd1 = skb->len;
1162 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd2 = 0;
1163 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd3 = 0;
1164 streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buflen = skb->len;
1165
1166 streamer_priv->tx_ring_skb[streamer_priv->tx_ring_free] = skb;
1167 streamer_priv->free_tx_ring_entries--;
1168#if STREAMER_DEBUG_PACKETS
1169 {
1170 int i;
1171 printk("streamer_xmit packet print:\n");
1172 for (i = 0; i < skb->len; i++) {
1173 printk("%x:", skb->data[i]);
1174 if (((i + 1) % 16) == 0)
1175 printk("\n");
1176 }
1177 printk("\n");
1178 }
1179#endif
1180
1181 writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev,
1182 &streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free],
1183 sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE)),
1184 streamer_mmio + TX2LFDA);
1185 (void)readl(streamer_mmio + TX2LFDA);
1186
1187 streamer_priv->tx_ring_free = (streamer_priv->tx_ring_free + 1) & (STREAMER_TX_RING_SIZE - 1);
1188 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
1189 return 0;
1190 } else {
1191 netif_stop_queue(dev);
1192 spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags);
1193 return 1;
1194 }
1195}
1196
1197
1198static int streamer_close(struct net_device *dev)
1199{
1200 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001201 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1203 unsigned long flags;
1204 int i;
1205
1206 netif_stop_queue(dev);
1207 netif_carrier_off(dev);
1208 writew(streamer_priv->srb, streamer_mmio + LAPA);
1209 writew(htons(SRB_CLOSE_ADAPTER << 8),streamer_mmio+LAPDINC);
1210 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1211
1212 spin_lock_irqsave(&streamer_priv->streamer_lock, flags);
1213
1214 streamer_priv->srb_queued = 1;
1215 writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1216
1217 spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags);
1218
1219 while (streamer_priv->srb_queued)
1220 {
1221 interruptible_sleep_on_timeout(&streamer_priv->srb_wait,
1222 jiffies + 60 * HZ);
1223 if (signal_pending(current))
1224 {
1225 printk(KERN_WARNING "%s: SRB timed out.\n", dev->name);
1226 printk(KERN_WARNING "SISR=%x MISR=%x LISR=%x\n",
1227 readw(streamer_mmio + SISR),
1228 readw(streamer_mmio + MISR_RUM),
1229 readw(streamer_mmio + LISR));
1230 streamer_priv->srb_queued = 0;
1231 break;
1232 }
1233 }
1234
1235 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
1236
1237 for (i = 0; i < STREAMER_RX_RING_SIZE; i++) {
1238 if (streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]) {
1239 dev_kfree_skb(streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]);
1240 }
1241 streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1);
1242 }
1243
1244 /* reset tx/rx fifo's and busmaster logic */
1245
1246 /* TBD. Add graceful way to reset the LLC channel without doing a soft reset.
1247 writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL);
1248 udelay(1);
1249 writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL);
1250 */
1251
1252#if STREAMER_DEBUG
1253 writew(streamer_priv->srb, streamer_mmio + LAPA);
1254 printk("srb): ");
1255 for (i = 0; i < 2; i++) {
1256 printk("%x ", ntohs(readw(streamer_mmio + LAPDINC)));
1257 }
1258 printk("\n");
1259#endif
1260 free_irq(dev->irq, dev);
1261 return 0;
1262}
1263
1264static void streamer_set_rx_mode(struct net_device *dev)
1265{
1266 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001267 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1269 __u8 options = 0;
1270 struct dev_mc_list *dmi;
1271 unsigned char dev_mc_address[5];
1272 int i;
1273
1274 writel(streamer_priv->srb, streamer_mmio + LAPA);
1275 options = streamer_priv->streamer_copy_all_options;
1276
1277 if (dev->flags & IFF_PROMISC)
1278 options |= (3 << 5); /* All LLC and MAC frames, all through the main rx channel */
1279 else
1280 options &= ~(3 << 5);
1281
1282 /* Only issue the srb if there is a change in options */
1283
1284 if ((options ^ streamer_priv->streamer_copy_all_options))
1285 {
1286 /* Now to issue the srb command to alter the copy.all.options */
1287 writew(htons(SRB_MODIFY_RECEIVE_OPTIONS << 8), streamer_mmio+LAPDINC);
1288 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1289 writew(htons((streamer_priv->streamer_receive_options << 8) | options),streamer_mmio+LAPDINC);
1290 writew(htons(0x4a41),streamer_mmio+LAPDINC);
1291 writew(htons(0x4d45),streamer_mmio+LAPDINC);
1292 writew(htons(0x5320),streamer_mmio+LAPDINC);
1293 writew(0x2020, streamer_mmio + LAPDINC);
1294
1295 streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */
1296
1297 writel(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1298
1299 streamer_priv->streamer_copy_all_options = options;
1300 return;
1301 }
1302
1303 /* Set the functional addresses we need for multicast */
1304 writel(streamer_priv->srb,streamer_mmio+LAPA);
1305 dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ;
1306
1307 for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next)
1308 {
1309 dev_mc_address[0] |= dmi->dmi_addr[2] ;
1310 dev_mc_address[1] |= dmi->dmi_addr[3] ;
1311 dev_mc_address[2] |= dmi->dmi_addr[4] ;
1312 dev_mc_address[3] |= dmi->dmi_addr[5] ;
1313 }
1314
1315 writew(htons(SRB_SET_FUNC_ADDRESS << 8),streamer_mmio+LAPDINC);
1316 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1317 writew(0,streamer_mmio+LAPDINC);
1318 writew(htons( (dev_mc_address[0] << 8) | dev_mc_address[1]),streamer_mmio+LAPDINC);
1319 writew(htons( (dev_mc_address[2] << 8) | dev_mc_address[3]),streamer_mmio+LAPDINC);
1320 streamer_priv->srb_queued = 2 ;
1321 writel(LISR_SRB_CMD,streamer_mmio+LISR_SUM);
1322}
1323
1324static void streamer_srb_bh(struct net_device *dev)
1325{
Yoann Padioleaueda10532007-07-23 15:18:21 +02001326 struct streamer_private *streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1328 __u16 srb_word;
1329
1330 writew(streamer_priv->srb, streamer_mmio + LAPA);
1331 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1332
1333 switch (srb_word) {
1334
1335 /* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous)
1336 * At some point we should do something if we get an error, such as
1337 * resetting the IFF_PROMISC flag in dev
1338 */
1339
1340 case SRB_MODIFY_RECEIVE_OPTIONS:
1341 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1342
1343 switch (srb_word) {
1344 case 0x01:
1345 printk(KERN_WARNING "%s: Unrecognized srb command\n", dev->name);
1346 break;
1347 case 0x04:
1348 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1349 break;
1350 default:
1351 if (streamer_priv->streamer_message_level)
1352 printk(KERN_WARNING "%s: Receive Options Modified to %x,%x\n",
1353 dev->name,
1354 streamer_priv->streamer_copy_all_options,
1355 streamer_priv->streamer_receive_options);
1356 break;
1357 } /* switch srb[2] */
1358 break;
1359
1360
1361 /* SRB_SET_GROUP_ADDRESS - Multicast group setting
1362 */
1363 case SRB_SET_GROUP_ADDRESS:
1364 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1365 switch (srb_word) {
1366 case 0x00:
1367 break;
1368 case 0x01:
1369 printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name);
1370 break;
1371 case 0x04:
1372 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1373 break;
1374 case 0x3c:
1375 printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctly\n", dev->name);
1376 break;
1377 case 0x3e: /* If we ever implement individual multicast addresses, will need to deal with this */
1378 printk(KERN_WARNING "%s: Group address registers full\n", dev->name);
1379 break;
1380 case 0x55:
1381 printk(KERN_INFO "%s: Group Address already set.\n", dev->name);
1382 break;
1383 default:
1384 break;
1385 } /* switch srb[2] */
1386 break;
1387
1388
1389 /* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list
1390 */
1391 case SRB_RESET_GROUP_ADDRESS:
1392 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1393 switch (srb_word) {
1394 case 0x00:
1395 break;
1396 case 0x01:
1397 printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1398 break;
1399 case 0x04:
1400 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1401 break;
1402 case 0x39: /* Must deal with this if individual multicast addresses used */
1403 printk(KERN_INFO "%s: Group address not found \n", dev->name);
1404 break;
1405 default:
1406 break;
1407 } /* switch srb[2] */
1408 break;
1409
1410
1411 /* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode
1412 */
1413
1414 case SRB_SET_FUNC_ADDRESS:
1415 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1416 switch (srb_word) {
1417 case 0x00:
1418 if (streamer_priv->streamer_message_level)
1419 printk(KERN_INFO "%s: Functional Address Mask Set \n", dev->name);
1420 break;
1421 case 0x01:
1422 printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1423 break;
1424 case 0x04:
1425 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1426 break;
1427 default:
1428 break;
1429 } /* switch srb[2] */
1430 break;
1431
1432 /* SRB_READ_LOG - Read and reset the adapter error counters
1433 */
1434
1435 case SRB_READ_LOG:
1436 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1437 switch (srb_word) {
1438 case 0x00:
1439 {
1440 int i;
1441 if (streamer_priv->streamer_message_level)
1442 printk(KERN_INFO "%s: Read Log command complete\n", dev->name);
1443 printk("Read Log statistics: ");
1444 writew(streamer_priv->srb + 6,
1445 streamer_mmio + LAPA);
1446 for (i = 0; i < 5; i++) {
1447 printk("%x:", ntohs(readw(streamer_mmio + LAPDINC)));
1448 }
1449 printk("\n");
1450 }
1451 break;
1452 case 0x01:
1453 printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1454 break;
1455 case 0x04:
1456 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1457 break;
1458
1459 } /* switch srb[2] */
1460 break;
1461
1462 /* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */
1463
1464 case SRB_READ_SR_COUNTERS:
1465 srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8;
1466 switch (srb_word) {
1467 case 0x00:
1468 if (streamer_priv->streamer_message_level)
1469 printk(KERN_INFO "%s: Read Source Routing Counters issued\n", dev->name);
1470 break;
1471 case 0x01:
1472 printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name);
1473 break;
1474 case 0x04:
1475 printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name);
1476 break;
1477 default:
1478 break;
1479 } /* switch srb[2] */
1480 break;
1481
1482 default:
1483 printk(KERN_WARNING "%s: Unrecognized srb bh return value.\n", dev->name);
1484 break;
1485 } /* switch srb[0] */
1486}
1487
1488static struct net_device_stats *streamer_get_stats(struct net_device *dev)
1489{
1490 struct streamer_private *streamer_priv;
Yoann Padioleaueda10532007-07-23 15:18:21 +02001491 streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 return (struct net_device_stats *) &streamer_priv->streamer_stats;
1493}
1494
1495static int streamer_set_mac_address(struct net_device *dev, void *addr)
1496{
1497 struct sockaddr *saddr = addr;
Yoann Padioleaueda10532007-07-23 15:18:21 +02001498 struct streamer_private *streamer_priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
1500 if (netif_running(dev))
1501 {
1502 printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name);
1503 return -EIO;
1504 }
1505
1506 memcpy(streamer_priv->streamer_laa, saddr->sa_data, dev->addr_len);
1507
1508 if (streamer_priv->streamer_message_level) {
1509 printk(KERN_INFO "%s: MAC/LAA Set to = %x.%x.%x.%x.%x.%x\n",
1510 dev->name, streamer_priv->streamer_laa[0],
1511 streamer_priv->streamer_laa[1],
1512 streamer_priv->streamer_laa[2],
1513 streamer_priv->streamer_laa[3],
1514 streamer_priv->streamer_laa[4],
1515 streamer_priv->streamer_laa[5]);
1516 }
1517 return 0;
1518}
1519
1520static void streamer_arb_cmd(struct net_device *dev)
1521{
1522 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001523 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1525 __u8 header_len;
1526 __u16 frame_len, buffer_len;
1527 struct sk_buff *mac_frame;
1528 __u8 frame_data[256];
1529 __u16 buff_off;
1530 __u16 lan_status = 0, lan_status_diff; /* Initialize to stop compiler warning */
1531 __u8 fdx_prot_error;
1532 __u16 next_ptr;
1533 __u16 arb_word;
1534
1535#if STREAMER_NETWORK_MONITOR
1536 struct trh_hdr *mac_hdr;
1537#endif
1538
1539 writew(streamer_priv->arb, streamer_mmio + LAPA);
1540 arb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8;
1541
1542 if (arb_word == ARB_RECEIVE_DATA) { /* Receive.data, MAC frames */
1543 writew(streamer_priv->arb + 6, streamer_mmio + LAPA);
1544 streamer_priv->mac_rx_buffer = buff_off = ntohs(readw(streamer_mmio + LAPDINC));
1545 header_len=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; /* 802.5 Token-Ring Header Length */
1546 frame_len = ntohs(readw(streamer_mmio + LAPDINC));
1547
1548#if STREAMER_DEBUG
1549 {
1550 int i;
1551 __u16 next;
1552 __u8 status;
1553 __u16 len;
1554
1555 writew(ntohs(buff_off), streamer_mmio + LAPA); /*setup window to frame data */
1556 next = htons(readw(streamer_mmio + LAPDINC));
1557 status =
1558 ntohs(readw(streamer_mmio + LAPDINC)) & 0xff;
1559 len = ntohs(readw(streamer_mmio + LAPDINC));
1560
1561 /* print out 1st 14 bytes of frame data */
1562 for (i = 0; i < 7; i++) {
1563 printk("Loc %d = %04x\n", i,
1564 ntohs(readw
1565 (streamer_mmio + LAPDINC)));
1566 }
1567
1568 printk("next %04x, fs %02x, len %04x \n", next,
1569 status, len);
1570 }
1571#endif
1572 if (!(mac_frame = dev_alloc_skb(frame_len))) {
1573 printk(KERN_WARNING "%s: Memory squeeze, dropping frame.\n",
1574 dev->name);
1575 goto drop_frame;
1576 }
1577 /* Walk the buffer chain, creating the frame */
1578
1579 do {
1580 int i;
1581 __u16 rx_word;
1582
1583 writew(htons(buff_off), streamer_mmio + LAPA); /* setup window to frame data */
1584 next_ptr = ntohs(readw(streamer_mmio + LAPDINC));
1585 readw(streamer_mmio + LAPDINC); /* read thru status word */
1586 buffer_len = ntohs(readw(streamer_mmio + LAPDINC));
1587
1588 if (buffer_len > 256)
1589 break;
1590
1591 i = 0;
1592 while (i < buffer_len) {
1593 rx_word=ntohs(readw(streamer_mmio+LAPDINC));
1594 frame_data[i]=rx_word >> 8;
1595 frame_data[i+1]=rx_word & 0xff;
1596 i += 2;
1597 }
1598
1599 memcpy(skb_put(mac_frame, buffer_len),
1600 frame_data, buffer_len);
1601 } while (next_ptr && (buff_off = next_ptr));
1602
Arnaldo Carvalho de Meloc1a4b862007-03-19 15:27:07 -07001603 mac_frame->protocol = tr_type_trans(mac_frame, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604#if STREAMER_NETWORK_MONITOR
1605 printk(KERN_WARNING "%s: Received MAC Frame, details: \n",
1606 dev->name);
Arnaldo Carvalho de Meloc1a4b862007-03-19 15:27:07 -07001607 mac_hdr = tr_hdr(mac_frame);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 printk(KERN_WARNING
Johannes Berge1749612008-10-27 15:59:26 -07001609 "%s: MAC Frame Dest. Addr: %pM\n",
1610 dev->name, mac_hdr->daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 printk(KERN_WARNING
Johannes Berge1749612008-10-27 15:59:26 -07001612 "%s: MAC Frame Srce. Addr: %pM\n",
1613 dev->name, mac_hdr->saddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 netif_rx(mac_frame);
1616
1617 /* Now tell the card we have dealt with the received frame */
1618drop_frame:
1619 /* Set LISR Bit 1 */
1620 writel(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM);
1621
1622 /* Is the ASB free ? */
1623
1624 if (!(readl(streamer_priv->streamer_mmio + SISR) & SISR_ASB_FREE))
1625 {
1626 streamer_priv->asb_queued = 1;
1627 writel(LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1628 return;
1629 /* Drop out and wait for the bottom half to be run */
1630 }
1631
1632
1633 writew(streamer_priv->asb, streamer_mmio + LAPA);
1634 writew(htons(ASB_RECEIVE_DATA << 8), streamer_mmio+LAPDINC);
1635 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1636 writew(0, streamer_mmio + LAPDINC);
1637 writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD);
1638
1639 writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1640
1641 streamer_priv->asb_queued = 2;
1642 return;
1643
1644 } else if (arb_word == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */
1645 writew(streamer_priv->arb + 6, streamer_mmio + LAPA);
1646 lan_status = ntohs(readw(streamer_mmio + LAPDINC));
1647 fdx_prot_error = ntohs(readw(streamer_mmio+LAPD)) >> 8;
1648
1649 /* Issue ARB Free */
1650 writew(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM);
1651
1652 lan_status_diff = (streamer_priv->streamer_lan_status ^ lan_status) &
1653 lan_status;
1654
1655 if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR))
1656 {
1657 if (lan_status_diff & LSC_LWF)
1658 printk(KERN_WARNING "%s: Short circuit detected on the lobe\n", dev->name);
1659 if (lan_status_diff & LSC_ARW)
1660 printk(KERN_WARNING "%s: Auto removal error\n", dev->name);
1661 if (lan_status_diff & LSC_FPE)
1662 printk(KERN_WARNING "%s: FDX Protocol Error\n", dev->name);
1663 if (lan_status_diff & LSC_RR)
1664 printk(KERN_WARNING "%s: Force remove MAC frame received\n", dev->name);
1665
1666 /* Adapter has been closed by the hardware */
1667
1668 /* reset tx/rx fifo's and busmaster logic */
1669
1670 /* @TBD. no llc reset on autostreamer writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL);
1671 udelay(1);
1672 writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL); */
1673
1674 netif_stop_queue(dev);
1675 netif_carrier_off(dev);
1676 printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name);
1677 }
1678 /* If serious error */
1679 if (streamer_priv->streamer_message_level) {
1680 if (lan_status_diff & LSC_SIG_LOSS)
1681 printk(KERN_WARNING "%s: No receive signal detected \n", dev->name);
1682 if (lan_status_diff & LSC_HARD_ERR)
1683 printk(KERN_INFO "%s: Beaconing \n", dev->name);
1684 if (lan_status_diff & LSC_SOFT_ERR)
1685 printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n", dev->name);
1686 if (lan_status_diff & LSC_TRAN_BCN)
1687 printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n", dev->name);
1688 if (lan_status_diff & LSC_SS)
1689 printk(KERN_INFO "%s: Single Station on the ring \n", dev->name);
1690 if (lan_status_diff & LSC_RING_REC)
1691 printk(KERN_INFO "%s: Ring recovery ongoing\n", dev->name);
1692 if (lan_status_diff & LSC_FDX_MODE)
1693 printk(KERN_INFO "%s: Operating in FDX mode\n", dev->name);
1694 }
1695
1696 if (lan_status_diff & LSC_CO) {
1697 if (streamer_priv->streamer_message_level)
1698 printk(KERN_INFO "%s: Counter Overflow \n", dev->name);
1699
1700 /* Issue READ.LOG command */
1701
1702 writew(streamer_priv->srb, streamer_mmio + LAPA);
1703 writew(htons(SRB_READ_LOG << 8),streamer_mmio+LAPDINC);
1704 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1705 writew(0, streamer_mmio + LAPDINC);
1706 streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */
1707
1708 writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1709 }
1710
1711 if (lan_status_diff & LSC_SR_CO) {
1712 if (streamer_priv->streamer_message_level)
1713 printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name);
1714
1715 /* Issue a READ.SR.COUNTERS */
1716 writew(streamer_priv->srb, streamer_mmio + LAPA);
1717 writew(htons(SRB_READ_SR_COUNTERS << 8),
1718 streamer_mmio+LAPDINC);
1719 writew(htons(STREAMER_CLEAR_RET_CODE << 8),
1720 streamer_mmio+LAPDINC);
1721 streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */
1722 writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM);
1723
1724 }
1725 streamer_priv->streamer_lan_status = lan_status;
1726 } /* Lan.change.status */
1727 else
1728 printk(KERN_WARNING "%s: Unknown arb command \n", dev->name);
1729}
1730
1731static void streamer_asb_bh(struct net_device *dev)
1732{
1733 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001734 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1736
1737 if (streamer_priv->asb_queued == 1)
1738 {
1739 /* Dropped through the first time */
1740
1741 writew(streamer_priv->asb, streamer_mmio + LAPA);
1742 writew(htons(ASB_RECEIVE_DATA << 8),streamer_mmio+LAPDINC);
1743 writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC);
1744 writew(0, streamer_mmio + LAPDINC);
1745 writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD);
1746
1747 writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM);
1748 streamer_priv->asb_queued = 2;
1749
1750 return;
1751 }
1752
1753 if (streamer_priv->asb_queued == 2) {
1754 __u8 rc;
1755 writew(streamer_priv->asb + 2, streamer_mmio + LAPA);
1756 rc=ntohs(readw(streamer_mmio+LAPD)) >> 8;
1757 switch (rc) {
1758 case 0x01:
1759 printk(KERN_WARNING "%s: Unrecognized command code \n", dev->name);
1760 break;
1761 case 0x26:
1762 printk(KERN_WARNING "%s: Unrecognized buffer address \n", dev->name);
1763 break;
1764 case 0xFF:
1765 /* Valid response, everything should be ok again */
1766 break;
1767 default:
1768 printk(KERN_WARNING "%s: Invalid return code in asb\n", dev->name);
1769 break;
1770 }
1771 }
1772 streamer_priv->asb_queued = 0;
1773}
1774
1775static int streamer_change_mtu(struct net_device *dev, int mtu)
1776{
1777 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001778 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 __u16 max_mtu;
1780
1781 if (streamer_priv->streamer_ring_speed == 4)
1782 max_mtu = 4500;
1783 else
1784 max_mtu = 18000;
1785
1786 if (mtu > max_mtu)
1787 return -EINVAL;
1788 if (mtu < 100)
1789 return -EINVAL;
1790
1791 dev->mtu = mtu;
1792 streamer_priv->pkt_buf_sz = mtu + TR_HLEN;
1793
1794 return 0;
1795}
1796
1797#if STREAMER_NETWORK_MONITOR
1798#ifdef CONFIG_PROC_FS
1799static int streamer_proc_info(char *buffer, char **start, off_t offset,
1800 int length, int *eof, void *data)
1801{
1802 struct streamer_private *sdev=NULL;
1803 struct pci_dev *pci_device = NULL;
1804 int len = 0;
1805 off_t begin = 0;
1806 off_t pos = 0;
1807 int size;
1808
1809 struct net_device *dev;
1810
1811 size = sprintf(buffer, "IBM LanStreamer/MPC Chipset Token Ring Adapters\n");
1812
1813 pos += size;
1814 len += size;
1815
1816 for(sdev=dev_streamer; sdev; sdev=sdev->next) {
1817 pci_device=sdev->pci_dev;
1818 dev=pci_get_drvdata(pci_device);
1819
1820 size = sprintf_info(buffer + len, dev);
1821 len += size;
1822 pos = begin + len;
1823
1824 if (pos < offset) {
1825 len = 0;
1826 begin = pos;
1827 }
1828 if (pos > offset + length)
1829 break;
1830 } /* for */
1831
1832 *start = buffer + (offset - begin); /* Start of wanted data */
1833 len -= (offset - begin); /* Start slop */
1834 if (len > length)
1835 len = length; /* Ending slop */
1836 return len;
1837}
1838
1839static int sprintf_info(char *buffer, struct net_device *dev)
1840{
1841 struct streamer_private *streamer_priv =
Yoann Padioleaueda10532007-07-23 15:18:21 +02001842 netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio;
1844 struct streamer_adapter_addr_table sat;
1845 struct streamer_parameters_table spt;
1846 int size = 0;
1847 int i;
1848
1849 writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA);
1850 for (i = 0; i < 14; i += 2) {
1851 __u16 io_word;
1852 __u8 *datap = (__u8 *) & sat;
1853 io_word=ntohs(readw(streamer_mmio+LAPDINC));
1854 datap[size]=io_word >> 8;
1855 datap[size+1]=io_word & 0xff;
1856 }
1857 writew(streamer_priv->streamer_parms_addr, streamer_mmio + LAPA);
1858 for (i = 0; i < 68; i += 2) {
1859 __u16 io_word;
1860 __u8 *datap = (__u8 *) & spt;
1861 io_word=ntohs(readw(streamer_mmio+LAPDINC));
1862 datap[size]=io_word >> 8;
1863 datap[size+1]=io_word & 0xff;
1864 }
1865
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 size = sprintf(buffer, "\n%6s: Adapter Address : Node Address : Functional Addr\n", dev->name);
1867
1868 size += sprintf(buffer + size,
Johannes Berge1749612008-10-27 15:59:26 -07001869 "%6s: %pM : %pM : %02x:%02x:%02x:%02x\n",
1870 dev->name, dev->dev_addr, sat.node_addr,
Joe Perches0795af52007-10-03 17:59:30 -07001871 sat.func_addr[0], sat.func_addr[1],
1872 sat.func_addr[2], sat.func_addr[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
1874 size += sprintf(buffer + size, "\n%6s: Token Ring Parameters Table:\n", dev->name);
1875
1876 size += sprintf(buffer + size, "%6s: Physical Addr : Up Node Address : Poll Address : AccPri : Auth Src : Att Code :\n", dev->name);
1877
1878 size += sprintf(buffer + size,
Johannes Berge1749612008-10-27 15:59:26 -07001879 "%6s: %02x:%02x:%02x:%02x : %pM : %pM : %04x : %04x : %04x :\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 dev->name, spt.phys_addr[0], spt.phys_addr[1],
1881 spt.phys_addr[2], spt.phys_addr[3],
Johannes Berge1749612008-10-27 15:59:26 -07001882 spt.up_node_addr, spt.poll_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 ntohs(spt.acc_priority), ntohs(spt.auth_source_class),
1884 ntohs(spt.att_code));
1885
1886 size += sprintf(buffer + size, "%6s: Source Address : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : \n", dev->name);
1887
1888 size += sprintf(buffer + size,
Johannes Berge1749612008-10-27 15:59:26 -07001889 "%6s: %pM : %04x : %04x : %04x : %04x : %04x : %04x : \n",
1890 dev->name, spt.source_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 ntohs(spt.beacon_type), ntohs(spt.major_vector),
1892 ntohs(spt.lan_status), ntohs(spt.local_ring),
1893 ntohs(spt.mon_error), ntohs(spt.frame_correl));
1894
1895 size += sprintf(buffer + size, "%6s: Beacon Details : Tx : Rx : NAUN Node Address : NAUN Node Phys : \n",
1896 dev->name);
1897
1898 size += sprintf(buffer + size,
Johannes Berge1749612008-10-27 15:59:26 -07001899 "%6s: : %02x : %02x : %pM : %02x:%02x:%02x:%02x : \n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 dev->name, ntohs(spt.beacon_transmit),
Joe Perches0795af52007-10-03 17:59:30 -07001901 ntohs(spt.beacon_receive),
Johannes Berge1749612008-10-27 15:59:26 -07001902 spt.beacon_naun,
Joe Perches0795af52007-10-03 17:59:30 -07001903 spt.beacon_phys[0], spt.beacon_phys[1],
1904 spt.beacon_phys[2], spt.beacon_phys[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 return size;
1906}
1907#endif
1908#endif
1909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910static struct pci_driver streamer_pci_driver = {
1911 .name = "lanstreamer",
1912 .id_table = streamer_pci_tbl,
1913 .probe = streamer_init_one,
1914 .remove = __devexit_p(streamer_remove_one),
1915};
1916
1917static int __init streamer_init_module(void) {
Jeff Garzik29917622006-08-19 17:48:59 -04001918 return pci_register_driver(&streamer_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921static void __exit streamer_cleanup_module(void) {
1922 pci_unregister_driver(&streamer_pci_driver);
1923}
1924
1925module_init(streamer_init_module);
1926module_exit(streamer_cleanup_module);
1927MODULE_LICENSE("GPL");