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