linux-bk/drivers/net/defxx.c
<<
>>
Prefs
   1/*
   2 * File Name:
   3 *   defxx.c
   4 *
   5 * Copyright Information:
   6 *   Copyright Digital Equipment Corporation 1996.
   7 *
   8 *   This software may be used and distributed according to the terms of
   9 *   the GNU General Public License, incorporated herein by reference.
  10 *
  11 * Abstract:
  12 *   A Linux device driver supporting the Digital Equipment Corporation
  13 *   FDDI EISA and PCI controller families.  Supported adapters include:
  14 *
  15 *              DEC FDDIcontroller/EISA (DEFEA)
  16 *              DEC FDDIcontroller/PCI  (DEFPA)
  17 *
  18 * Maintainers:
  19 *   LVS        Lawrence V. Stefani
  20 *
  21 * Contact:
  22 *       The author may be reached at:
  23 *
  24 *              Inet: stefani@lkg.dec.com
  25 *              (NOTE! this address no longer works -jgarzik)
  26 *
  27 *              Mail: Digital Equipment Corporation
  28 *                        550 King Street
  29 *                        M/S: LKG1-3/M07
  30 *                        Littleton, MA  01460
  31 *
  32 * Credits:
  33 *   I'd like to thank Patricia Cross for helping me get started with
  34 *   Linux, David Davies for a lot of help upgrading and configuring
  35 *   my development system and for answering many OS and driver
  36 *   development questions, and Alan Cox for recommendations and
  37 *   integration help on getting FDDI support into Linux.  LVS
  38 *
  39 * Driver Architecture:
  40 *   The driver architecture is largely based on previous driver work
  41 *   for other operating systems.  The upper edge interface and
  42 *   functions were largely taken from existing Linux device drivers
  43 *   such as David Davies' DE4X5.C driver and Donald Becker's TULIP.C
  44 *   driver.
  45 *
  46 *   Adapter Probe -
  47 *              The driver scans for supported EISA adapters by reading the
  48 *              SLOT ID register for each EISA slot and making a match
  49 *              against the expected value.
  50 *
  51 *   Bus-Specific Initialization -
  52 *              This driver currently supports both EISA and PCI controller
  53 *              families.  While the custom DMA chip and FDDI logic is similar
  54 *              or identical, the bus logic is very different.  After
  55 *              initialization, the     only bus-specific differences is in how the
  56 *              driver enables and disables interrupts.  Other than that, the
  57 *              run-time critical code behaves the same on both families.
  58 *              It's important to note that both adapter families are configured
  59 *              to I/O map, rather than memory map, the adapter registers.
  60 *
  61 *   Driver Open/Close -
  62 *              In the driver open routine, the driver ISR (interrupt service
  63 *              routine) is registered and the adapter is brought to an
  64 *              operational state.  In the driver close routine, the opposite
  65 *              occurs; the driver ISR is deregistered and the adapter is
  66 *              brought to a safe, but closed state.  Users may use consecutive
  67 *              commands to bring the adapter up and down as in the following
  68 *              example:
  69 *                                      ifconfig fddi0 up
  70 *                                      ifconfig fddi0 down
  71 *                                      ifconfig fddi0 up
  72 *
  73 *   Driver Shutdown -
  74 *              Apparently, there is no shutdown or halt routine support under
  75 *              Linux.  This routine would be called during "reboot" or
  76 *              "shutdown" to allow the driver to place the adapter in a safe
  77 *              state before a warm reboot occurs.  To be really safe, the user
  78 *              should close the adapter before shutdown (eg. ifconfig fddi0 down)
  79 *              to ensure that the adapter DMA engine is taken off-line.  However,
  80 *              the current driver code anticipates this problem and always issues
  81 *              a soft reset of the adapter     at the beginning of driver initialization.
  82 *              A future driver enhancement in this area may occur in 2.1.X where
  83 *              Alan indicated that a shutdown handler may be implemented.
  84 *
  85 *   Interrupt Service Routine -
  86 *              The driver supports shared interrupts, so the ISR is registered for
  87 *              each board with the appropriate flag and the pointer to that board's
  88 *              device structure.  This provides the context during interrupt
  89 *              processing to support shared interrupts and multiple boards.
  90 *
  91 *              Interrupt enabling/disabling can occur at many levels.  At the host
  92 *              end, you can disable system interrupts, or disable interrupts at the
  93 *              PIC (on Intel systems).  Across the bus, both EISA and PCI adapters
  94 *              have a bus-logic chip interrupt enable/disable as well as a DMA
  95 *              controller interrupt enable/disable.
  96 *
  97 *              The driver currently enables and disables adapter interrupts at the
  98 *              bus-logic chip and assumes that Linux will take care of clearing or
  99 *              acknowledging any host-based interrupt chips.
 100 *
 101 *   Control Functions -
 102 *              Control functions are those used to support functions such as adding
 103 *              or deleting multicast addresses, enabling or disabling packet
 104 *              reception filters, or other custom/proprietary commands.  Presently,
 105 *              the driver supports the "get statistics", "set multicast list", and
 106 *              "set mac address" functions defined by Linux.  A list of possible
 107 *              enhancements include:
 108 *
 109 *                              - Custom ioctl interface for executing port interface commands
 110 *                              - Custom ioctl interface for adding unicast addresses to
 111 *                                adapter CAM (to support bridge functions).
 112 *                              - Custom ioctl interface for supporting firmware upgrades.
 113 *
 114 *   Hardware (port interface) Support Routines -
 115 *              The driver function names that start with "dfx_hw_" represent
 116 *              low-level port interface routines that are called frequently.  They
 117 *              include issuing a DMA or port control command to the adapter,
 118 *              resetting the adapter, or reading the adapter state.  Since the
 119 *              driver initialization and run-time code must make calls into the
 120 *              port interface, these routines were written to be as generic and
 121 *              usable as possible.
 122 *
 123 *   Receive Path -
 124 *              The adapter DMA engine supports a 256 entry receive descriptor block
 125 *              of which up to 255 entries can be used at any given time.  The
 126 *              architecture is a standard producer, consumer, completion model in
 127 *              which the driver "produces" receive buffers to the adapter, the
 128 *              adapter "consumes" the receive buffers by DMAing incoming packet data,
 129 *              and the driver "completes" the receive buffers by servicing the
 130 *              incoming packet, then "produces" a new buffer and starts the cycle
 131 *              again.  Receive buffers can be fragmented in up to 16 fragments
 132 *              (descriptor     entries).  For simplicity, this driver posts
 133 *              single-fragment receive buffers of 4608 bytes, then allocates a
 134 *              sk_buff, copies the data, then reposts the buffer.  To reduce CPU
 135 *              utilization, a better approach would be to pass up the receive
 136 *              buffer (no extra copy) then allocate and post a replacement buffer.
 137 *              This is a performance enhancement that should be looked into at
 138 *              some point.
 139 *
 140 *   Transmit Path -
 141 *              Like the receive path, the adapter DMA engine supports a 256 entry
 142 *              transmit descriptor block of which up to 255 entries can be used at
 143 *              any     given time.  Transmit buffers can be fragmented in up to 255
 144 *              fragments (descriptor entries).  This driver always posts one
 145 *              fragment per transmit packet request.
 146 *
 147 *              The fragment contains the entire packet from FC to end of data.
 148 *              Before posting the buffer to the adapter, the driver sets a three-byte
 149 *              packet request header (PRH) which is required by the Motorola MAC chip
 150 *              used on the adapters.  The PRH tells the MAC the type of token to
 151 *              receive/send, whether or not to generate and append the CRC, whether
 152 *              synchronous or asynchronous framing is used, etc.  Since the PRH
 153 *              definition is not necessarily consistent across all FDDI chipsets,
 154 *              the driver, rather than the common FDDI packet handler routines,
 155 *              sets these bytes.
 156 *
 157 *              To reduce the amount of descriptor fetches needed per transmit request,
 158 *              the driver takes advantage of the fact that there are at least three
 159 *              bytes available before the skb->data field on the outgoing transmit
 160 *              request.  This is guaranteed by having fddi_setup() in net_init.c set
 161 *              dev->hard_header_len to 24 bytes.  21 bytes accounts for the largest
 162 *              header in an 802.2 SNAP frame.  The other 3 bytes are the extra "pad"
 163 *              bytes which we'll use to store the PRH.
 164 *
 165 *              There's a subtle advantage to adding these pad bytes to the
 166 *              hard_header_len, it ensures that the data portion of the packet for
 167 *              an 802.2 SNAP frame is longword aligned.  Other FDDI driver
 168 *              implementations may not need the extra padding and can start copying
 169 *              or DMAing directly from the FC byte which starts at skb->data.  Should
 170 *              another driver implementation need ADDITIONAL padding, the net_init.c
 171 *              module should be updated and dev->hard_header_len should be increased.
 172 *              NOTE: To maintain the alignment on the data portion of the packet,
 173 *              dev->hard_header_len should always be evenly divisible by 4 and at
 174 *              least 24 bytes in size.
 175 *
 176 * Modification History:
 177 *              Date            Name    Description
 178 *              16-Aug-96       LVS             Created.
 179 *              20-Aug-96       LVS             Updated dfx_probe so that version information
 180 *                                                      string is only displayed if 1 or more cards are
 181 *                                                      found.  Changed dfx_rcv_queue_process to copy
 182 *                                                      3 NULL bytes before FC to ensure that data is
 183 *                                                      longword aligned in receive buffer.
 184 *              09-Sep-96       LVS             Updated dfx_ctl_set_multicast_list to enable
 185 *                                                      LLC group promiscuous mode if multicast list
 186 *                                                      is too large.  LLC individual/group promiscuous
 187 *                                                      mode is now disabled if IFF_PROMISC flag not set.
 188 *                                                      dfx_xmt_queue_pkt no longer checks for NULL skb
 189 *                                                      on Alan Cox recommendation.  Added node address
 190 *                                                      override support.
 191 *              12-Sep-96       LVS             Reset current address to factory address during
 192 *                                                      device open.  Updated transmit path to post a
 193 *                                                      single fragment which includes PRH->end of data.
 194 *              Mar 2000        AC              Did various cleanups for 2.3.x
 195 *              Jun 2000        jgarzik         PCI and resource alloc cleanups
 196 *              Jul 2000        tjeerd          Much cleanup and some bug fixes
 197 *              Sep 2000        tjeerd          Fix leak on unload, cosmetic code cleanup
 198 *              Feb 2001                        Skb allocation fixes
 199 *              Feb 2001        davej           PCI enable cleanups.
 200 */
 201
 202#error Please convert me to Documentation/DMA-mapping.txt
 203
 204/* Include files */
 205
 206#include <linux/module.h>
 207
 208#include <linux/kernel.h>
 209#include <linux/sched.h>
 210#include <linux/string.h>
 211#include <linux/errno.h>
 212#include <linux/ioport.h>
 213#include <linux/slab.h>
 214#include <linux/interrupt.h>
 215#include <linux/pci.h>
 216#include <linux/delay.h>
 217#include <linux/init.h>
 218#include <linux/netdevice.h>
 219#include <asm/byteorder.h>
 220#include <asm/bitops.h>
 221#include <asm/io.h>
 222
 223#include <linux/fddidevice.h>
 224#include <linux/skbuff.h>
 225
 226#include "defxx.h"
 227
 228/* Version information string - should be updated prior to each new release!!! */
 229
 230static char version[] __devinitdata =
 231        "defxx.c:v1.05e 2001/02/03  Lawrence V. Stefani and others\n";
 232
 233#define DYNAMIC_BUFFERS 1
 234
 235#define SKBUFF_RX_COPYBREAK 200
 236/*
 237 * NEW_SKB_SIZE = PI_RCV_DATA_K_SIZE_MAX+128 to allow 128 byte
 238 * alignment for compatibility with old EISA boards.
 239 */
 240#define NEW_SKB_SIZE (PI_RCV_DATA_K_SIZE_MAX+128)
 241
 242/* Define module-wide (static) routines */
 243
 244static void             dfx_bus_init(struct net_device *dev);
 245static void             dfx_bus_config_check(DFX_board_t *bp);
 246
 247static int              dfx_driver_init(struct net_device *dev);
 248static int              dfx_adap_init(DFX_board_t *bp, int get_buffers);
 249
 250static int              dfx_open(struct net_device *dev);
 251static int              dfx_close(struct net_device *dev);
 252
 253static void             dfx_int_pr_halt_id(DFX_board_t *bp);
 254static void             dfx_int_type_0_process(DFX_board_t *bp);
 255static void             dfx_int_common(struct net_device *dev);
 256static void             dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 257
 258static struct           net_device_stats *dfx_ctl_get_stats(struct net_device *dev);
 259static void             dfx_ctl_set_multicast_list(struct net_device *dev);
 260static int              dfx_ctl_set_mac_address(struct net_device *dev, void *addr);
 261static int              dfx_ctl_update_cam(DFX_board_t *bp);
 262static int              dfx_ctl_update_filters(DFX_board_t *bp);
 263
 264static int              dfx_hw_dma_cmd_req(DFX_board_t *bp);
 265static int              dfx_hw_port_ctrl_req(DFX_board_t *bp, PI_UINT32 command, PI_UINT32 data_a, PI_UINT32 data_b, PI_UINT32 *host_data);
 266static void             dfx_hw_adap_reset(DFX_board_t *bp, PI_UINT32 type);
 267static int              dfx_hw_adap_state_rd(DFX_board_t *bp);
 268static int              dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type);
 269
 270static int              dfx_rcv_init(DFX_board_t *bp, int get_buffers);
 271static void             dfx_rcv_queue_process(DFX_board_t *bp);
 272static void             dfx_rcv_flush(DFX_board_t *bp);
 273
 274static int              dfx_xmt_queue_pkt(struct sk_buff *skb, struct net_device *dev);
 275static int              dfx_xmt_done(DFX_board_t *bp);
 276static void             dfx_xmt_flush(DFX_board_t *bp);
 277
 278/* Define module-wide (static) variables */
 279
 280static struct net_device *root_dfx_eisa_dev;
 281
 282
 283/*
 284 * =======================
 285 * = dfx_port_write_byte =
 286 * = dfx_port_read_byte  =
 287 * = dfx_port_write_long =
 288 * = dfx_port_read_long  =
 289 * =======================
 290 *   
 291 * Overview:
 292 *   Routines for reading and writing values from/to adapter
 293 *  
 294 * Returns:
 295 *   None
 296 *       
 297 * Arguments:
 298 *   bp     - pointer to board information
 299 *   offset - register offset from base I/O address
 300 *   data   - for dfx_port_write_byte and dfx_port_write_long, this
 301 *                        is a value to write.
 302 *                        for dfx_port_read_byte and dfx_port_read_byte, this
 303 *                        is a pointer to store the read value.
 304 *
 305 * Functional Description:
 306 *   These routines perform the correct operation to read or write
 307 *   the adapter register.
 308 *   
 309 *   EISA port block base addresses are based on the slot number in which the
 310 *   controller is installed.  For example, if the EISA controller is installed
 311 *   in slot 4, the port block base address is 0x4000.  If the controller is
 312 *   installed in slot 2, the port block base address is 0x2000, and so on.
 313 *   This port block can be used to access PDQ, ESIC, and DEFEA on-board
 314 *   registers using the register offsets defined in DEFXX.H.
 315 *
 316 *   PCI port block base addresses are assigned by the PCI BIOS or system
 317 *       firmware.  There is one 128 byte port block which can be accessed.  It
 318 *   allows for I/O mapping of both PDQ and PFI registers using the register
 319 *   offsets defined in DEFXX.H.
 320 *
 321 * Return Codes:
 322 *   None
 323 *
 324 * Assumptions:
 325 *   bp->base_addr is a valid base I/O address for this adapter.
 326 *   offset is a valid register offset for this adapter.
 327 *
 328 * Side Effects:
 329 *   Rather than produce macros for these functions, these routines
 330 *   are defined using "inline" to ensure that the compiler will
 331 *   generate inline code and not waste a procedure call and return.
 332 *   This provides all the benefits of macros, but with the
 333 *   advantage of strict data type checking.
 334 */
 335
 336static inline void dfx_port_write_byte(
 337        DFX_board_t     *bp,
 338        int                     offset,
 339        u8                      data
 340        )
 341
 342        {
 343        u16 port = bp->base_addr + offset;
 344
 345        outb(data, port);
 346        }
 347
 348static inline void dfx_port_read_byte(
 349        DFX_board_t     *bp,
 350        int                     offset,
 351        u8                      *data
 352        )
 353
 354        {
 355        u16 port = bp->base_addr + offset;
 356
 357        *data = inb(port);
 358        }
 359
 360static inline void dfx_port_write_long(
 361        DFX_board_t     *bp,
 362        int                     offset,
 363        u32                     data
 364        )
 365
 366        {
 367        u16 port = bp->base_addr + offset;
 368
 369        outl(data, port);
 370        }
 371
 372static inline void dfx_port_read_long(
 373        DFX_board_t     *bp,
 374        int                     offset,
 375        u32                     *data
 376        )
 377
 378        {
 379        u16 port = bp->base_addr + offset;
 380
 381        *data = inl(port);
 382        }
 383
 384
 385/*
 386 * =============
 387 * = dfx_init_one_pci_or_eisa =
 388 * =============
 389 *   
 390 * Overview:
 391 *   Initializes a supported FDDI EISA or PCI controller
 392 *  
 393 * Returns:
 394 *   Condition code
 395 *       
 396 * Arguments:
 397 *   pdev - pointer to pci device information (NULL for EISA)
 398 *   ioaddr - pointer to port (NULL for PCI)
 399 *
 400 * Functional Description:
 401 *
 402 * Return Codes:
 403 *   0           - This device (fddi0, fddi1, etc) configured successfully
 404 *   -EBUSY      - Failed to get resources, or dfx_driver_init failed.
 405 *
 406 * Assumptions:
 407 *   It compiles so it should work :-( (PCI cards do :-)
 408 *
 409 * Side Effects:
 410 *   Device structures for FDDI adapters (fddi0, fddi1, etc) are
 411 *   initialized and the board resources are read and stored in
 412 *   the device structure.
 413 */
 414static int __devinit dfx_init_one_pci_or_eisa(struct pci_dev *pdev, long ioaddr)
 415{
 416        struct net_device *dev;
 417        DFX_board_t       *bp;                  /* board pointer */
 418        int err;
 419
 420#ifndef MODULE
 421        static int version_disp;
 422
 423        if (!version_disp)      /* display version info if adapter is found */
 424        {
 425                version_disp = 1;       /* set display flag to TRUE so that */
 426                printk(version);        /* we only display this string ONCE */
 427        }
 428#endif
 429
 430        /*
 431         * init_fddidev() allocates a device structure with private data, clears the device structure and private data,
 432         * and  calls fddi_setup() and register_netdev(). Not much left to do for us here.
 433         */
 434        dev = init_fddidev(NULL, sizeof(*bp));
 435        if (!dev) {
 436                printk (KERN_ERR "defxx: unable to allocate fddidev, aborting\n");
 437                return -ENOMEM;
 438        }
 439
 440        /* Enable PCI device. */
 441        if (pdev != NULL) {
 442                err = pci_enable_device (pdev);
 443                if (err) goto err_out;
 444                ioaddr = pci_resource_start (pdev, 1);
 445        }
 446
 447        SET_MODULE_OWNER(dev);
 448
 449        bp = dev->priv;
 450
 451        if (!request_region (ioaddr, pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN, dev->name)) {
 452                printk (KERN_ERR "%s: Cannot reserve I/O resource 0x%x @ 0x%lx, aborting\n",
 453                        dev->name, PFI_K_CSR_IO_LEN, ioaddr);
 454                err = -EBUSY;
 455                goto err_out;
 456        }
 457
 458        /* Initialize new device structure */
 459
 460        dev->base_addr                  = ioaddr; /* save port (I/O) base address */
 461
 462        dev->get_stats                  = dfx_ctl_get_stats;
 463        dev->open                       = dfx_open;
 464        dev->stop                       = dfx_close;
 465        dev->hard_start_xmit            = dfx_xmt_queue_pkt;
 466        dev->set_multicast_list         = dfx_ctl_set_multicast_list;
 467        dev->set_mac_address            = dfx_ctl_set_mac_address;
 468
 469        if (pdev == NULL) {
 470                /* EISA board */
 471                bp->bus_type = DFX_BUS_TYPE_EISA;
 472                bp->next = root_dfx_eisa_dev;
 473                root_dfx_eisa_dev = dev;
 474        } else {
 475                /* PCI board */
 476                bp->bus_type = DFX_BUS_TYPE_PCI;
 477                bp->pci_dev = pdev;
 478                pci_set_drvdata (pdev, dev);
 479                pci_set_master (pdev);
 480        }
 481
 482        if (dfx_driver_init(dev) != DFX_K_SUCCESS) {
 483                err = -ENODEV;
 484                goto err_out_region;
 485        }
 486
 487        return 0;
 488
 489err_out_region:
 490        release_region(ioaddr, pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN);
 491err_out:
 492        unregister_netdev(dev);
 493        kfree(dev);
 494        return err;
 495}
 496
 497static int __devinit dfx_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 498{
 499        return dfx_init_one_pci_or_eisa(pdev, 0);
 500}
 501
 502static int __init dfx_eisa_init(void)
 503{
 504        int rc = -ENODEV;
 505        int i;                  /* used in for loops */
 506        u16 port;               /* temporary I/O (port) address */
 507        u32 slot_id;            /* EISA hardware (slot) ID read from adapter */
 508
 509        DBG_printk("In dfx_eisa_init...\n");
 510
 511        /* Scan for FDDI EISA controllers */
 512
 513        for (i=0; i < DFX_MAX_EISA_SLOTS; i++)          /* only scan for up to 16 EISA slots */
 514        {
 515                port = (i << 12) + PI_ESIC_K_SLOT_ID;   /* port = I/O address for reading slot ID */
 516                slot_id = inl(port);                                    /* read EISA HW (slot) ID */
 517                if ((slot_id & 0xF0FFFFFF) == DEFEA_PRODUCT_ID)
 518                {
 519                        port = (i << 12);                                       /* recalc base addr */
 520
 521                        if (dfx_init_one_pci_or_eisa(NULL, port) == 0) rc = 0;
 522                }
 523        }
 524        return rc;
 525}
 526
 527/*
 528 * ================
 529 * = dfx_bus_init =
 530 * ================
 531 *   
 532 * Overview:
 533 *   Initializes EISA and PCI controller bus-specific logic.
 534 *  
 535 * Returns:
 536 *   None
 537 *       
 538 * Arguments:
 539 *   dev - pointer to device information
 540 *
 541 * Functional Description:
 542 *   Determine and save adapter IRQ in device table,
 543 *   then perform bus-specific logic initialization.
 544 *
 545 * Return Codes:
 546 *   None
 547 *
 548 * Assumptions:
 549 *   dev->base_addr has already been set with the proper
 550 *       base I/O address for this device.
 551 *
 552 * Side Effects:
 553 *   Interrupts are enabled at the adapter bus-specific logic.
 554 *   Note:  Interrupts at the DMA engine (PDQ chip) are not
 555 *   enabled yet.
 556 */
 557
 558static void __devinit dfx_bus_init(struct net_device *dev)
 559{
 560        DFX_board_t *bp = dev->priv;
 561        u8                      val;    /* used for I/O read/writes */
 562
 563        DBG_printk("In dfx_bus_init...\n");
 564
 565        /*
 566         * Initialize base I/O address field in bp structure
 567         *
 568         * Note: bp->base_addr is the same as dev->base_addr.
 569         *               It's useful because often we'll need to read
 570         *               or write registers where we already have the
 571         *               bp pointer instead of the dev pointer.  Having
 572         *               the base address in the bp structure will
 573         *               save a pointer dereference.
 574         *
 575         *               IMPORTANT!! This field must be defined before
 576         *               any of the dfx_port_* inline functions are
 577         *               called.
 578         */
 579
 580        bp->base_addr = dev->base_addr;
 581
 582        /* And a pointer back to the net_device struct */
 583        bp->dev = dev;
 584
 585        /* Initialize adapter based on bus type */
 586
 587        if (bp->bus_type == DFX_BUS_TYPE_EISA)
 588                {
 589                /* Get the interrupt level from the ESIC chip */
 590
 591                dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &val);
 592                switch ((val & PI_CONFIG_STAT_0_M_IRQ) >> PI_CONFIG_STAT_0_V_IRQ)
 593                        {
 594                        case PI_CONFIG_STAT_0_IRQ_K_9:
 595                                dev->irq = 9;
 596                                break;
 597
 598                        case PI_CONFIG_STAT_0_IRQ_K_10:
 599                                dev->irq = 10;
 600                                break;
 601
 602                        case PI_CONFIG_STAT_0_IRQ_K_11:
 603                                dev->irq = 11;
 604                                break;
 605
 606                        case PI_CONFIG_STAT_0_IRQ_K_15:
 607                                dev->irq = 15;
 608                                break;
 609                        }
 610
 611                /* Enable access to I/O on the board by writing 0x03 to Function Control Register */
 612
 613                dfx_port_write_byte(bp, PI_ESIC_K_FUNCTION_CNTRL, PI_ESIC_K_FUNCTION_CNTRL_IO_ENB);
 614
 615                /* Set the I/O decode range of the board */
 616
 617                val = ((dev->base_addr >> 12) << PI_IO_CMP_V_SLOT);
 618                dfx_port_write_byte(bp, PI_ESIC_K_IO_CMP_0_1, val);
 619                dfx_port_write_byte(bp, PI_ESIC_K_IO_CMP_1_1, val);
 620
 621                /* Enable access to rest of module (including PDQ and packet memory) */
 622
 623                dfx_port_write_byte(bp, PI_ESIC_K_SLOT_CNTRL, PI_SLOT_CNTRL_M_ENB);
 624
 625                /*
 626                 * Map PDQ registers into I/O space.  This is done by clearing a bit
 627                 * in Burst Holdoff register.
 628                 */
 629
 630                dfx_port_read_byte(bp, PI_ESIC_K_BURST_HOLDOFF, &val);
 631                dfx_port_write_byte(bp, PI_ESIC_K_BURST_HOLDOFF, (val & ~PI_BURST_HOLDOFF_M_MEM_MAP));
 632
 633                /* Enable interrupts at EISA bus interface chip (ESIC) */
 634
 635                dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &val);
 636                dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, (val | PI_CONFIG_STAT_0_M_INT_ENB));
 637                }
 638        else
 639                {
 640                struct pci_dev *pdev = bp->pci_dev;
 641
 642                /* Get the interrupt level from the PCI Configuration Table */
 643
 644                dev->irq = pdev->irq;
 645
 646                /* Check Latency Timer and set if less than minimal */
 647
 648                pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &val);
 649                if (val < PFI_K_LAT_TIMER_MIN)  /* if less than min, override with default */
 650                        {
 651                        val = PFI_K_LAT_TIMER_DEF;
 652                        pci_write_config_byte(pdev, PCI_LATENCY_TIMER, val);
 653                        }
 654
 655                /* Enable interrupts at PCI bus interface chip (PFI) */
 656
 657                dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, (PFI_MODE_M_PDQ_INT_ENB | PFI_MODE_M_DMA_ENB));
 658                }
 659        }
 660
 661
 662/*
 663 * ========================
 664 * = dfx_bus_config_check =
 665 * ========================
 666 *   
 667 * Overview:
 668 *   Checks the configuration (burst size, full-duplex, etc.)  If any parameters
 669 *   are illegal, then this routine will set new defaults.
 670 *  
 671 * Returns:
 672 *   None
 673 *       
 674 * Arguments:
 675 *   bp - pointer to board information
 676 *
 677 * Functional Description:
 678 *   For Revision 1 FDDI EISA, Revision 2 or later FDDI EISA with rev E or later
 679 *   PDQ, and all FDDI PCI controllers, all values are legal.
 680 *
 681 * Return Codes:
 682 *   None
 683 *
 684 * Assumptions:
 685 *   dfx_adap_init has NOT been called yet so burst size and other items have
 686 *   not been set.
 687 *
 688 * Side Effects:
 689 *   None
 690 */
 691
 692static void __devinit dfx_bus_config_check(DFX_board_t *bp)
 693{
 694        int     status;                         /* return code from adapter port control call */
 695        u32     slot_id;                        /* EISA-bus hardware id (DEC3001, DEC3002,...) */
 696        u32     host_data;                      /* LW data returned from port control call */
 697
 698        DBG_printk("In dfx_bus_config_check...\n");
 699
 700        /* Configuration check only valid for EISA adapter */
 701
 702        if (bp->bus_type == DFX_BUS_TYPE_EISA)
 703                {
 704                dfx_port_read_long(bp, PI_ESIC_K_SLOT_ID, &slot_id);
 705
 706                /*
 707                 * First check if revision 2 EISA controller.  Rev. 1 cards used
 708                 * PDQ revision B, so no workaround needed in this case.  Rev. 3
 709                 * cards used PDQ revision E, so no workaround needed in this
 710                 * case, either.  Only Rev. 2 cards used either Rev. D or E
 711                 * chips, so we must verify the chip revision on Rev. 2 cards.
 712                 */
 713
 714                if (slot_id == DEFEA_PROD_ID_2)
 715                        {
 716                        /*
 717                         * Revision 2 FDDI EISA controller found, so let's check PDQ
 718                         * revision of adapter.
 719                         */
 720
 721                        status = dfx_hw_port_ctrl_req(bp,
 722                                                                                        PI_PCTRL_M_SUB_CMD,
 723                                                                                        PI_SUB_CMD_K_PDQ_REV_GET,
 724                                                                                        0,
 725                                                                                        &host_data);
 726                        if ((status != DFX_K_SUCCESS) || (host_data == 2))
 727                                {
 728                                /*
 729                                 * Either we couldn't determine the PDQ revision, or
 730                                 * we determined that it is at revision D.  In either case,
 731                                 * we need to implement the workaround.
 732                                 */
 733
 734                                /* Ensure that the burst size is set to 8 longwords or less */
 735
 736                                switch (bp->burst_size)
 737                                        {
 738                                        case PI_PDATA_B_DMA_BURST_SIZE_32:
 739                                        case PI_PDATA_B_DMA_BURST_SIZE_16:
 740                                                bp->burst_size = PI_PDATA_B_DMA_BURST_SIZE_8;
 741                                                break;
 742
 743                                        default:
 744                                                break;
 745                                        }
 746
 747                                /* Ensure that full-duplex mode is not enabled */
 748
 749                                bp->full_duplex_enb = PI_SNMP_K_FALSE;
 750                                }
 751                        }
 752                }
 753        }
 754
 755
 756/*
 757 * ===================
 758 * = dfx_driver_init =
 759 * ===================
 760 *   
 761 * Overview:
 762 *   Initializes remaining adapter board structure information
 763 *   and makes sure adapter is in a safe state prior to dfx_open().
 764 *  
 765 * Returns:
 766 *   Condition code
 767 *       
 768 * Arguments:
 769 *   dev - pointer to device information
 770 *
 771 * Functional Description:
 772 *   This function allocates additional resources such as the host memory
 773 *   blocks needed by the adapter (eg. descriptor and consumer blocks).
 774 *       Remaining bus initialization steps are also completed.  The adapter
 775 *   is also reset so that it is in the DMA_UNAVAILABLE state.  The OS
 776 *   must call dfx_open() to open the adapter and bring it on-line.
 777 *
 778 * Return Codes:
 779 *   DFX_K_SUCCESS      - initialization succeeded
 780 *   DFX_K_FAILURE      - initialization failed - could not allocate memory
 781 *                                              or read adapter MAC address
 782 *
 783 * Assumptions:
 784 *   Memory allocated from kmalloc() call is physically contiguous, locked
 785 *   memory whose physical address equals its virtual address.
 786 *
 787 * Side Effects:
 788 *   Adapter is reset and should be in DMA_UNAVAILABLE state before
 789 *   returning from this routine.
 790 */
 791
 792static int __devinit dfx_driver_init(struct net_device *dev)
 793{
 794        DFX_board_t *bp = dev->priv;
 795        int                     alloc_size;                     /* total buffer size needed */
 796        char            *top_v, *curr_v;        /* virtual addrs into memory block */
 797        u32                     top_p, curr_p;          /* physical addrs into memory block */
 798        u32                     data;                           /* host data register value */
 799
 800        DBG_printk("In dfx_driver_init...\n");
 801
 802        /* Initialize bus-specific hardware registers */
 803
 804        dfx_bus_init(dev);
 805
 806        /*
 807         * Initialize default values for configurable parameters
 808         *
 809         * Note: All of these parameters are ones that a user may
 810         *       want to customize.  It'd be nice to break these
 811         *               out into Space.c or someplace else that's more
 812         *               accessible/understandable than this file.
 813         */
 814
 815        bp->full_duplex_enb             = PI_SNMP_K_FALSE;
 816        bp->req_ttrt                    = 8 * 12500;            /* 8ms in 80 nanosec units */
 817        bp->burst_size                  = PI_PDATA_B_DMA_BURST_SIZE_DEF;
 818        bp->rcv_bufs_to_post    = RCV_BUFS_DEF;
 819
 820        /*
 821         * Ensure that HW configuration is OK
 822         *
 823         * Note: Depending on the hardware revision, we may need to modify
 824         *       some of the configurable parameters to workaround hardware
 825         *       limitations.  We'll perform this configuration check AFTER
 826         *       setting the parameters to their default values.
 827         */
 828
 829        dfx_bus_config_check(bp);
 830
 831        /* Disable PDQ interrupts first */
 832
 833        dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
 834
 835        /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
 836
 837        (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
 838
 839        /*  Read the factory MAC address from the adapter then save it */
 840
 841        if (dfx_hw_port_ctrl_req(bp,
 842                                                        PI_PCTRL_M_MLA,
 843                                                        PI_PDATA_A_MLA_K_LO,
 844                                                        0,
 845                                                        &data) != DFX_K_SUCCESS)
 846                {
 847                printk("%s: Could not read adapter factory MAC address!\n", dev->name);
 848                return(DFX_K_FAILURE);
 849                }
 850        memcpy(&bp->factory_mac_addr[0], &data, sizeof(u32));
 851
 852        if (dfx_hw_port_ctrl_req(bp,
 853                                                        PI_PCTRL_M_MLA,
 854                                                        PI_PDATA_A_MLA_K_HI,
 855                                                        0,
 856                                                        &data) != DFX_K_SUCCESS)
 857                {
 858                printk("%s: Could not read adapter factory MAC address!\n", dev->name);
 859                return(DFX_K_FAILURE);
 860                }
 861        memcpy(&bp->factory_mac_addr[4], &data, sizeof(u16));
 862
 863        /*
 864         * Set current address to factory address
 865         *
 866         * Note: Node address override support is handled through
 867         *       dfx_ctl_set_mac_address.
 868         */
 869
 870        memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
 871        if (bp->bus_type == DFX_BUS_TYPE_EISA)
 872                printk("%s: DEFEA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n",
 873                                dev->name,
 874                                dev->base_addr,
 875                                dev->irq,
 876                                dev->dev_addr[0],
 877                                dev->dev_addr[1],
 878                                dev->dev_addr[2],
 879                                dev->dev_addr[3],
 880                                dev->dev_addr[4],
 881                                dev->dev_addr[5]);
 882        else
 883                printk("%s: DEFPA at I/O addr = 0x%lX, IRQ = %d, Hardware addr = %02X-%02X-%02X-%02X-%02X-%02X\n",
 884                                dev->name,
 885                                dev->base_addr,
 886                                dev->irq,
 887                                dev->dev_addr[0],
 888                                dev->dev_addr[1],
 889                                dev->dev_addr[2],
 890                                dev->dev_addr[3],
 891                                dev->dev_addr[4],
 892                                dev->dev_addr[5]);
 893
 894        /*
 895         * Get memory for descriptor block, consumer block, and other buffers
 896         * that need to be DMA read or written to by the adapter.
 897         */
 898
 899        alloc_size = sizeof(PI_DESCR_BLOCK) +
 900                                        PI_CMD_REQ_K_SIZE_MAX +
 901                                        PI_CMD_RSP_K_SIZE_MAX +
 902#ifndef DYNAMIC_BUFFERS
 903                                        (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX) +
 904#endif
 905                                        sizeof(PI_CONSUMER_BLOCK) +
 906                                        (PI_ALIGN_K_DESC_BLK - 1);
 907        bp->kmalloced = top_v = (char *) kmalloc(alloc_size, GFP_KERNEL);
 908        if (top_v == NULL)
 909                {
 910                printk("%s: Could not allocate memory for host buffers and structures!\n", dev->name);
 911                return(DFX_K_FAILURE);
 912                }
 913        memset(top_v, 0, alloc_size);   /* zero out memory before continuing */
 914        top_p = virt_to_bus(top_v);             /* get physical address of buffer */
 915
 916        /*
 917         *  To guarantee the 8K alignment required for the descriptor block, 8K - 1
 918         *  plus the amount of memory needed was allocated.  The physical address
 919         *      is now 8K aligned.  By carving up the memory in a specific order,
 920         *  we'll guarantee the alignment requirements for all other structures.
 921         *
 922         *  Note: If the assumptions change regarding the non-paged, non-cached,
 923         *                physically contiguous nature of the memory block or the address
 924         *                alignments, then we'll need to implement a different algorithm
 925         *                for allocating the needed memory.
 926         */
 927
 928        curr_p = (u32) (ALIGN(top_p, PI_ALIGN_K_DESC_BLK));
 929        curr_v = top_v + (curr_p - top_p);
 930
 931        /* Reserve space for descriptor block */
 932
 933        bp->descr_block_virt = (PI_DESCR_BLOCK *) curr_v;
 934        bp->descr_block_phys = curr_p;
 935        curr_v += sizeof(PI_DESCR_BLOCK);
 936        curr_p += sizeof(PI_DESCR_BLOCK);
 937
 938        /* Reserve space for command request buffer */
 939
 940        bp->cmd_req_virt = (PI_DMA_CMD_REQ *) curr_v;
 941        bp->cmd_req_phys = curr_p;
 942        curr_v += PI_CMD_REQ_K_SIZE_MAX;
 943        curr_p += PI_CMD_REQ_K_SIZE_MAX;
 944
 945        /* Reserve space for command response buffer */
 946
 947        bp->cmd_rsp_virt = (PI_DMA_CMD_RSP *) curr_v;
 948        bp->cmd_rsp_phys = curr_p;
 949        curr_v += PI_CMD_RSP_K_SIZE_MAX;
 950        curr_p += PI_CMD_RSP_K_SIZE_MAX;
 951
 952        /* Reserve space for the LLC host receive queue buffers */
 953
 954        bp->rcv_block_virt = curr_v;
 955        bp->rcv_block_phys = curr_p;
 956
 957#ifndef DYNAMIC_BUFFERS
 958        curr_v += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
 959        curr_p += (bp->rcv_bufs_to_post * PI_RCV_DATA_K_SIZE_MAX);
 960#endif
 961
 962        /* Reserve space for the consumer block */
 963
 964        bp->cons_block_virt = (PI_CONSUMER_BLOCK *) curr_v;
 965        bp->cons_block_phys = curr_p;
 966
 967        /* Display virtual and physical addresses if debug driver */
 968
 969        DBG_printk("%s: Descriptor block virt = %0lX, phys = %0X\n",                            dev->name, (long)bp->descr_block_virt,  bp->descr_block_phys);
 970        DBG_printk("%s: Command Request buffer virt = %0lX, phys = %0X\n",                      dev->name, (long)bp->cmd_req_virt,              bp->cmd_req_phys);
 971        DBG_printk("%s: Command Response buffer virt = %0lX, phys = %0X\n",                     dev->name, (long)bp->cmd_rsp_virt,              bp->cmd_rsp_phys);
 972        DBG_printk("%s: Receive buffer block virt = %0lX, phys = %0X\n",                        dev->name, (long)bp->rcv_block_virt,    bp->rcv_block_phys);
 973        DBG_printk("%s: Consumer block virt = %0lX, phys = %0X\n",                              dev->name, (long)bp->cons_block_virt,   bp->cons_block_phys);
 974
 975        return(DFX_K_SUCCESS);
 976        }
 977
 978
 979/*
 980 * =================
 981 * = dfx_adap_init =
 982 * =================
 983 *   
 984 * Overview:
 985 *   Brings the adapter to the link avail/link unavailable state.
 986 *  
 987 * Returns:
 988 *   Condition code
 989 *       
 990 * Arguments:
 991 *   bp - pointer to board information
 992 *   get_buffers - non-zero if buffers to be allocated
 993 *
 994 * Functional Description:
 995 *   Issues the low-level firmware/hardware calls necessary to bring
 996 *   the adapter up, or to properly reset and restore adapter during
 997 *   run-time.
 998 *
 999 * Return Codes:
1000 *   DFX_K_SUCCESS - Adapter brought up successfully
1001 *   DFX_K_FAILURE - Adapter initialization failed
1002 *
1003 * Assumptions:
1004 *   bp->reset_type should be set to a valid reset type value before
1005 *   calling this routine.
1006 *
1007 * Side Effects:
1008 *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1009 *   upon a successful return of this routine.
1010 */
1011
1012static int dfx_adap_init(DFX_board_t *bp, int get_buffers)
1013        {
1014        DBG_printk("In dfx_adap_init...\n");
1015
1016        /* Disable PDQ interrupts first */
1017
1018        dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1019
1020        /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1021
1022        if (dfx_hw_dma_uninit(bp, bp->reset_type) != DFX_K_SUCCESS)
1023                {
1024                printk("%s: Could not uninitialize/reset adapter!\n", bp->dev->name);
1025                return(DFX_K_FAILURE);
1026                }
1027
1028        /*
1029         * When the PDQ is reset, some false Type 0 interrupts may be pending,
1030         * so we'll acknowledge all Type 0 interrupts now before continuing.
1031         */
1032
1033        dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, PI_HOST_INT_K_ACK_ALL_TYPE_0);
1034
1035        /*
1036         * Clear Type 1 and Type 2 registers before going to DMA_AVAILABLE state
1037         *
1038         * Note: We only need to clear host copies of these registers.  The PDQ reset
1039         *       takes care of the on-board register values.
1040         */
1041
1042        bp->cmd_req_reg.lword   = 0;
1043        bp->cmd_rsp_reg.lword   = 0;
1044        bp->rcv_xmt_reg.lword   = 0;
1045
1046        /* Clear consumer block before going to DMA_AVAILABLE state */
1047
1048        memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1049
1050        /* Initialize the DMA Burst Size */
1051
1052        if (dfx_hw_port_ctrl_req(bp,
1053                                                        PI_PCTRL_M_SUB_CMD,
1054                                                        PI_SUB_CMD_K_BURST_SIZE_SET,
1055                                                        bp->burst_size,
1056                                                        NULL) != DFX_K_SUCCESS)
1057                {
1058                printk("%s: Could not set adapter burst size!\n", bp->dev->name);
1059                return(DFX_K_FAILURE);
1060                }
1061
1062        /*
1063         * Set base address of Consumer Block
1064         *
1065         * Assumption: 32-bit physical address of consumer block is 64 byte
1066         *                         aligned.  That is, bits 0-5 of the address must be zero.
1067         */
1068
1069        if (dfx_hw_port_ctrl_req(bp,
1070                                                        PI_PCTRL_M_CONS_BLOCK,
1071                                                        bp->cons_block_phys,
1072                                                        0,
1073                                                        NULL) != DFX_K_SUCCESS)
1074                {
1075                printk("%s: Could not set consumer block address!\n", bp->dev->name);
1076                return(DFX_K_FAILURE);
1077                }
1078
1079        /*
1080         * Set base address of Descriptor Block and bring adapter to DMA_AVAILABLE state
1081         *
1082         * Note: We also set the literal and data swapping requirements in this
1083         *           command.  Since this driver presently runs on Intel platforms
1084         *               which are Little Endian, we'll tell the adapter to byte swap
1085         *               data only.  This code will need to change when we support
1086         *               Big Endian systems (eg. PowerPC).
1087         *
1088         * Assumption: 32-bit physical address of descriptor block is 8Kbyte
1089         *             aligned.  That is, bits 0-12 of the address must be zero.
1090         */
1091
1092        if (dfx_hw_port_ctrl_req(bp,
1093                                                        PI_PCTRL_M_INIT,
1094                                                        (u32) (bp->descr_block_phys | PI_PDATA_A_INIT_M_BSWAP_DATA),
1095                                                        0,
1096                                                        NULL) != DFX_K_SUCCESS)
1097                {
1098                printk("%s: Could not set descriptor block address!\n", bp->dev->name);
1099                return(DFX_K_FAILURE);
1100                }
1101
1102        /* Set transmit flush timeout value */
1103
1104        bp->cmd_req_virt->cmd_type = PI_CMD_K_CHARS_SET;
1105        bp->cmd_req_virt->char_set.item[0].item_code    = PI_ITEM_K_FLUSH_TIME;
1106        bp->cmd_req_virt->char_set.item[0].value                = 3;    /* 3 seconds */
1107        bp->cmd_req_virt->char_set.item[0].item_index   = 0;
1108        bp->cmd_req_virt->char_set.item[1].item_code    = PI_ITEM_K_EOL;
1109        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1110                {
1111                printk("%s: DMA command request failed!\n", bp->dev->name);
1112                return(DFX_K_FAILURE);
1113                }
1114
1115        /* Set the initial values for eFDXEnable and MACTReq MIB objects */
1116
1117        bp->cmd_req_virt->cmd_type = PI_CMD_K_SNMP_SET;
1118        bp->cmd_req_virt->snmp_set.item[0].item_code    = PI_ITEM_K_FDX_ENB_DIS;
1119        bp->cmd_req_virt->snmp_set.item[0].value                = bp->full_duplex_enb;
1120        bp->cmd_req_virt->snmp_set.item[0].item_index   = 0;
1121        bp->cmd_req_virt->snmp_set.item[1].item_code    = PI_ITEM_K_MAC_T_REQ;
1122        bp->cmd_req_virt->snmp_set.item[1].value                = bp->req_ttrt;
1123        bp->cmd_req_virt->snmp_set.item[1].item_index   = 0;
1124        bp->cmd_req_virt->snmp_set.item[2].item_code    = PI_ITEM_K_EOL;
1125        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1126                {
1127                printk("%s: DMA command request failed!\n", bp->dev->name);
1128                return(DFX_K_FAILURE);
1129                }
1130
1131        /* Initialize adapter CAM */
1132
1133        if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
1134                {
1135                printk("%s: Adapter CAM update failed!\n", bp->dev->name);
1136                return(DFX_K_FAILURE);
1137                }
1138
1139        /* Initialize adapter filters */
1140
1141        if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
1142                {
1143                printk("%s: Adapter filters update failed!\n", bp->dev->name);
1144                return(DFX_K_FAILURE);
1145                }
1146
1147        /*
1148         * Remove any existing dynamic buffers (i.e. if the adapter is being
1149         * reinitialized)
1150         */
1151
1152        if (get_buffers)
1153                dfx_rcv_flush(bp);
1154
1155        /* Initialize receive descriptor block and produce buffers */
1156
1157        if (dfx_rcv_init(bp, get_buffers))
1158                {
1159                printk("%s: Receive buffer allocation failed\n", bp->dev->name);
1160                if (get_buffers)
1161                        dfx_rcv_flush(bp);
1162                return(DFX_K_FAILURE);
1163                }
1164
1165        /* Issue START command and bring adapter to LINK_(UN)AVAILABLE state */
1166
1167        bp->cmd_req_virt->cmd_type = PI_CMD_K_START;
1168        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1169                {
1170                printk("%s: Start command failed\n", bp->dev->name);
1171                if (get_buffers)
1172                        dfx_rcv_flush(bp);
1173                return(DFX_K_FAILURE);
1174                }
1175
1176        /* Initialization succeeded, reenable PDQ interrupts */
1177
1178        dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_ENABLE_DEF_INTS);
1179        return(DFX_K_SUCCESS);
1180        }
1181
1182
1183/*
1184 * ============
1185 * = dfx_open =
1186 * ============
1187 *   
1188 * Overview:
1189 *   Opens the adapter
1190 *  
1191 * Returns:
1192 *   Condition code
1193 *       
1194 * Arguments:
1195 *   dev - pointer to device information
1196 *
1197 * Functional Description:
1198 *   This function brings the adapter to an operational state.
1199 *
1200 * Return Codes:
1201 *   0           - Adapter was successfully opened
1202 *   -EAGAIN - Could not register IRQ or adapter initialization failed
1203 *
1204 * Assumptions:
1205 *   This routine should only be called for a device that was
1206 *   initialized successfully.
1207 *
1208 * Side Effects:
1209 *   Adapter should be in LINK_AVAILABLE or LINK_UNAVAILABLE state
1210 *   if the open is successful.
1211 */
1212
1213static int dfx_open(struct net_device *dev)
1214{
1215        int ret;
1216        DFX_board_t     *bp = dev->priv;
1217
1218        DBG_printk("In dfx_open...\n");
1219        
1220        /* Register IRQ - support shared interrupts by passing device ptr */
1221
1222        ret = request_irq(dev->irq, (void *)dfx_interrupt, SA_SHIRQ, dev->name, dev);
1223        if (ret) {
1224                printk(KERN_ERR "%s: Requested IRQ %d is busy\n", dev->name, dev->irq);
1225                return ret;
1226        }
1227
1228        /*
1229         * Set current address to factory MAC address
1230         *
1231         * Note: We've already done this step in dfx_driver_init.
1232         *       However, it's possible that a user has set a node
1233         *               address override, then closed and reopened the
1234         *               adapter.  Unless we reset the device address field
1235         *               now, we'll continue to use the existing modified
1236         *               address.
1237         */
1238
1239        memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
1240
1241        /* Clear local unicast/multicast address tables and counts */
1242
1243        memset(bp->uc_table, 0, sizeof(bp->uc_table));
1244        memset(bp->mc_table, 0, sizeof(bp->mc_table));
1245        bp->uc_count = 0;
1246        bp->mc_count = 0;
1247
1248        /* Disable promiscuous filter settings */
1249
1250        bp->ind_group_prom      = PI_FSTATE_K_BLOCK;
1251        bp->group_prom          = PI_FSTATE_K_BLOCK;
1252
1253        spin_lock_init(&bp->lock);
1254
1255        /* Reset and initialize adapter */
1256
1257        bp->reset_type = PI_PDATA_A_RESET_M_SKIP_ST;    /* skip self-test */
1258        if (dfx_adap_init(bp, 1) != DFX_K_SUCCESS)
1259        {
1260                printk(KERN_ERR "%s: Adapter open failed!\n", dev->name);
1261                free_irq(dev->irq, dev);
1262                return -EAGAIN;
1263        }
1264
1265        /* Set device structure info */
1266        netif_start_queue(dev);
1267        return(0);
1268}
1269
1270
1271/*
1272 * =============
1273 * = dfx_close =
1274 * =============
1275 *   
1276 * Overview:
1277 *   Closes the device/module.
1278 *  
1279 * Returns:
1280 *   Condition code
1281 *       
1282 * Arguments:
1283 *   dev - pointer to device information
1284 *
1285 * Functional Description:
1286 *   This routine closes the adapter and brings it to a safe state.
1287 *   The interrupt service routine is deregistered with the OS.
1288 *   The adapter can be opened again with another call to dfx_open().
1289 *
1290 * Return Codes:
1291 *   Always return 0.
1292 *
1293 * Assumptions:
1294 *   No further requests for this adapter are made after this routine is
1295 *   called.  dfx_open() can be called to reset and reinitialize the
1296 *   adapter.
1297 *
1298 * Side Effects:
1299 *   Adapter should be in DMA_UNAVAILABLE state upon completion of this
1300 *   routine.
1301 */
1302
1303static int dfx_close(struct net_device *dev)
1304{
1305        DFX_board_t     *bp = dev->priv;
1306
1307        DBG_printk("In dfx_close...\n");
1308
1309        /* Disable PDQ interrupts first */
1310
1311        dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1312
1313        /* Place adapter in DMA_UNAVAILABLE state by resetting adapter */
1314
1315        (void) dfx_hw_dma_uninit(bp, PI_PDATA_A_RESET_M_SKIP_ST);
1316
1317        /*
1318         * Flush any pending transmit buffers
1319         *
1320         * Note: It's important that we flush the transmit buffers
1321         *               BEFORE we clear our copy of the Type 2 register.
1322         *               Otherwise, we'll have no idea how many buffers
1323         *               we need to free.
1324         */
1325
1326        dfx_xmt_flush(bp);
1327
1328        /*
1329         * Clear Type 1 and Type 2 registers after adapter reset
1330         *
1331         * Note: Even though we're closing the adapter, it's
1332         *       possible that an interrupt will occur after
1333         *               dfx_close is called.  Without some assurance to
1334         *               the contrary we want to make sure that we don't
1335         *               process receive and transmit LLC frames and update
1336         *               the Type 2 register with bad information.
1337         */
1338
1339        bp->cmd_req_reg.lword   = 0;
1340        bp->cmd_rsp_reg.lword   = 0;
1341        bp->rcv_xmt_reg.lword   = 0;
1342
1343        /* Clear consumer block for the same reason given above */
1344
1345        memset(bp->cons_block_virt, 0, sizeof(PI_CONSUMER_BLOCK));
1346
1347        /* Release all dynamically allocate skb in the receive ring. */
1348
1349        dfx_rcv_flush(bp);
1350
1351        /* Clear device structure flags */
1352
1353        netif_stop_queue(dev);
1354        
1355        /* Deregister (free) IRQ */
1356
1357        free_irq(dev->irq, dev);
1358        
1359        return(0);
1360}
1361
1362
1363/*
1364 * ======================
1365 * = dfx_int_pr_halt_id =
1366 * ======================
1367 *   
1368 * Overview:
1369 *   Displays halt id's in string form.
1370 *  
1371 * Returns:
1372 *   None
1373 *       
1374 * Arguments:
1375 *   bp - pointer to board information
1376 *
1377 * Functional Description:
1378 *   Determine current halt id and display appropriate string.
1379 *
1380 * Return Codes:
1381 *   None
1382 *
1383 * Assumptions:
1384 *   None
1385 *
1386 * Side Effects:
1387 *   None
1388 */
1389
1390static void dfx_int_pr_halt_id(DFX_board_t      *bp)
1391        {
1392        PI_UINT32       port_status;                    /* PDQ port status register value */
1393        PI_UINT32       halt_id;                                /* PDQ port status halt ID */
1394
1395        /* Read the latest port status */
1396
1397        dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1398
1399        /* Display halt state transition information */
1400
1401        halt_id = (port_status & PI_PSTATUS_M_HALT_ID) >> PI_PSTATUS_V_HALT_ID;
1402        switch (halt_id)
1403                {
1404                case PI_HALT_ID_K_SELFTEST_TIMEOUT:
1405                        printk("%s: Halt ID: Selftest Timeout\n", bp->dev->name);
1406                        break;
1407
1408                case PI_HALT_ID_K_PARITY_ERROR:
1409                        printk("%s: Halt ID: Host Bus Parity Error\n", bp->dev->name);
1410                        break;
1411
1412                case PI_HALT_ID_K_HOST_DIR_HALT:
1413                        printk("%s: Halt ID: Host-Directed Halt\n", bp->dev->name);
1414                        break;
1415
1416                case PI_HALT_ID_K_SW_FAULT:
1417                        printk("%s: Halt ID: Adapter Software Fault\n", bp->dev->name);
1418                        break;
1419
1420                case PI_HALT_ID_K_HW_FAULT:
1421                        printk("%s: Halt ID: Adapter Hardware Fault\n", bp->dev->name);
1422                        break;
1423
1424                case PI_HALT_ID_K_PC_TRACE:
1425                        printk("%s: Halt ID: FDDI Network PC Trace Path Test\n", bp->dev->name);
1426                        break;
1427
1428                case PI_HALT_ID_K_DMA_ERROR:
1429                        printk("%s: Halt ID: Adapter DMA Error\n", bp->dev->name);
1430                        break;
1431
1432                case PI_HALT_ID_K_IMAGE_CRC_ERROR:
1433                        printk("%s: Halt ID: Firmware Image CRC Error\n", bp->dev->name);
1434                        break;
1435
1436                case PI_HALT_ID_K_BUS_EXCEPTION:
1437                        printk("%s: Halt ID: 68000 Bus Exception\n", bp->dev->name);
1438                        break;
1439
1440                default:
1441                        printk("%s: Halt ID: Unknown (code = %X)\n", bp->dev->name, halt_id);
1442                        break;
1443                }
1444        }
1445
1446
1447/*
1448 * ==========================
1449 * = dfx_int_type_0_process =
1450 * ==========================
1451 *   
1452 * Overview:
1453 *   Processes Type 0 interrupts.
1454 *  
1455 * Returns:
1456 *   None
1457 *       
1458 * Arguments:
1459 *   bp - pointer to board information
1460 *
1461 * Functional Description:
1462 *   Processes all enabled Type 0 interrupts.  If the reason for the interrupt
1463 *   is a serious fault on the adapter, then an error message is displayed
1464 *   and the adapter is reset.
1465 *
1466 *   One tricky potential timing window is the rapid succession of "link avail"
1467 *   "link unavail" state change interrupts.  The acknowledgement of the Type 0
1468 *   interrupt must be done before reading the state from the Port Status
1469 *   register.  This is true because a state change could occur after reading
1470 *   the data, but before acknowledging the interrupt.  If this state change
1471 *   does happen, it would be lost because the driver is using the old state,
1472 *   and it will never know about the new state because it subsequently
1473 *   acknowledges the state change interrupt.
1474 *
1475 *          INCORRECT                                      CORRECT
1476 *      read type 0 int reasons                   read type 0 int reasons
1477 *      read adapter state                        ack type 0 interrupts
1478 *      ack type 0 interrupts                     read adapter state
1479 *      ... process interrupt ...                 ... process interrupt ...
1480 *
1481 * Return Codes:
1482 *   None
1483 *
1484 * Assumptions:
1485 *   None
1486 *
1487 * Side Effects:
1488 *   An adapter reset may occur if the adapter has any Type 0 error interrupts
1489 *   or if the port status indicates that the adapter is halted.  The driver
1490 *   is responsible for reinitializing the adapter with the current CAM
1491 *   contents and adapter filter settings.
1492 */
1493
1494static void dfx_int_type_0_process(DFX_board_t  *bp)
1495
1496        {
1497        PI_UINT32       type_0_status;          /* Host Interrupt Type 0 register */
1498        PI_UINT32       state;                          /* current adap state (from port status) */
1499
1500        /*
1501         * Read host interrupt Type 0 register to determine which Type 0
1502         * interrupts are pending.  Immediately write it back out to clear
1503         * those interrupts.
1504         */
1505
1506        dfx_port_read_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, &type_0_status);
1507        dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_0_STATUS, type_0_status);
1508
1509        /* Check for Type 0 error interrupts */
1510
1511        if (type_0_status & (PI_TYPE_0_STAT_M_NXM |
1512                                                        PI_TYPE_0_STAT_M_PM_PAR_ERR |
1513                                                        PI_TYPE_0_STAT_M_BUS_PAR_ERR))
1514                {
1515                /* Check for Non-Existent Memory error */
1516
1517                if (type_0_status & PI_TYPE_0_STAT_M_NXM)
1518                        printk("%s: Non-Existent Memory Access Error\n", bp->dev->name);
1519
1520                /* Check for Packet Memory Parity error */
1521
1522                if (type_0_status & PI_TYPE_0_STAT_M_PM_PAR_ERR)
1523                        printk("%s: Packet Memory Parity Error\n", bp->dev->name);
1524
1525                /* Check for Host Bus Parity error */
1526
1527                if (type_0_status & PI_TYPE_0_STAT_M_BUS_PAR_ERR)
1528                        printk("%s: Host Bus Parity Error\n", bp->dev->name);
1529
1530                /* Reset adapter and bring it back on-line */
1531
1532                bp->link_available = PI_K_FALSE;        /* link is no longer available */
1533                bp->reset_type = 0;                                     /* rerun on-board diagnostics */
1534                printk("%s: Resetting adapter...\n", bp->dev->name);
1535                if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1536                        {
1537                        printk("%s: Adapter reset failed!  Disabling adapter interrupts.\n", bp->dev->name);
1538                        dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1539                        return;
1540                        }
1541                printk("%s: Adapter reset successful!\n", bp->dev->name);
1542                return;
1543                }
1544
1545        /* Check for transmit flush interrupt */
1546
1547        if (type_0_status & PI_TYPE_0_STAT_M_XMT_FLUSH)
1548                {
1549                /* Flush any pending xmt's and acknowledge the flush interrupt */
1550
1551                bp->link_available = PI_K_FALSE;                /* link is no longer available */
1552                dfx_xmt_flush(bp);                                              /* flush any outstanding packets */
1553                (void) dfx_hw_port_ctrl_req(bp,
1554                                                                        PI_PCTRL_M_XMT_DATA_FLUSH_DONE,
1555                                                                        0,
1556                                                                        0,
1557                                                                        NULL);
1558                }
1559
1560        /* Check for adapter state change */
1561
1562        if (type_0_status & PI_TYPE_0_STAT_M_STATE_CHANGE)
1563                {                     
1564                /* Get latest adapter state */
1565
1566                state = dfx_hw_adap_state_rd(bp);       /* get adapter state */
1567                if (state == PI_STATE_K_HALTED)
1568                        {
1569                        /*
1570                         * Adapter has transitioned to HALTED state, try to reset
1571                         * adapter to bring it back on-line.  If reset fails,
1572                         * leave the adapter in the broken state.
1573                         */
1574
1575                        printk("%s: Controller has transitioned to HALTED state!\n", bp->dev->name);
1576                        dfx_int_pr_halt_id(bp);                 /* display halt id as string */
1577
1578                        /* Reset adapter and bring it back on-line */
1579
1580                        bp->link_available = PI_K_FALSE;        /* link is no longer available */
1581                        bp->reset_type = 0;                                     /* rerun on-board diagnostics */
1582                        printk("%s: Resetting adapter...\n", bp->dev->name);
1583                        if (dfx_adap_init(bp, 0) != DFX_K_SUCCESS)
1584                                {
1585                                printk("%s: Adapter reset failed!  Disabling adapter interrupts.\n", bp->dev->name);
1586                                dfx_port_write_long(bp, PI_PDQ_K_REG_HOST_INT_ENB, PI_HOST_INT_K_DISABLE_ALL_INTS);
1587                                return;
1588                                }
1589                        printk("%s: Adapter reset successful!\n", bp->dev->name);
1590                        }
1591                else if (state == PI_STATE_K_LINK_AVAIL)
1592                        {
1593                        bp->link_available = PI_K_TRUE;         /* set link available flag */
1594                        }
1595                }
1596        }
1597
1598
1599/*
1600 * ==================
1601 * = dfx_int_common =
1602 * ==================
1603 *   
1604 * Overview:
1605 *   Interrupt service routine (ISR)
1606 *  
1607 * Returns:
1608 *   None
1609 *       
1610 * Arguments:
1611 *   bp - pointer to board information
1612 *
1613 * Functional Description:
1614 *   This is the ISR which processes incoming adapter interrupts.
1615 *
1616 * Return Codes:
1617 *   None
1618 *
1619 * Assumptions:
1620 *   This routine assumes PDQ interrupts have not been disabled.
1621 *   When interrupts are disabled at the PDQ, the Port Status register
1622 *   is automatically cleared.  This routine uses the Port Status
1623 *   register value to determine whether a Type 0 interrupt occurred,
1624 *   so it's important that adapter interrupts are not normally
1625 *   enabled/disabled at the PDQ.
1626 *
1627 *   It's vital that this routine is NOT reentered for the
1628 *   same board and that the OS is not in another section of
1629 *   code (eg. dfx_xmt_queue_pkt) for the same board on a
1630 *   different thread.
1631 *
1632 * Side Effects:
1633 *   Pending interrupts are serviced.  Depending on the type of
1634 *   interrupt, acknowledging and clearing the interrupt at the
1635 *   PDQ involves writing a register to clear the interrupt bit
1636 *   or updating completion indices.
1637 */
1638
1639static void dfx_int_common(struct net_device *dev)
1640{
1641        DFX_board_t     *bp = dev->priv;
1642        PI_UINT32       port_status;            /* Port Status register */
1643
1644        /* Process xmt interrupts - frequent case, so always call this routine */
1645
1646        if(dfx_xmt_done(bp))                            /* free consumed xmt packets */
1647                netif_wake_queue(dev);
1648
1649        /* Process rcv interrupts - frequent case, so always call this routine */
1650
1651        dfx_rcv_queue_process(bp);              /* service received LLC frames */
1652
1653        /*
1654         * Transmit and receive producer and completion indices are updated on the
1655         * adapter by writing to the Type 2 Producer register.  Since the frequent
1656         * case is that we'll be processing either LLC transmit or receive buffers,
1657         * we'll optimize I/O writes by doing a single register write here.
1658         */
1659
1660        dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
1661
1662        /* Read PDQ Port Status register to find out which interrupts need processing */
1663
1664        dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
1665
1666        /* Process Type 0 interrupts (if any) - infrequent, so only call when needed */
1667
1668        if (port_status & PI_PSTATUS_M_TYPE_0_PENDING)
1669                dfx_int_type_0_process(bp);     /* process Type 0 interrupts */
1670        }
1671
1672
1673/*
1674 * =================
1675 * = dfx_interrupt =
1676 * =================
1677 *   
1678 * Overview:
1679 *   Interrupt processing routine
1680 *  
1681 * Returns:
1682 *   None
1683 *       
1684 * Arguments:
1685 *   irq        - interrupt vector
1686 *   dev_id     - pointer to device information
1687 *       regs   - pointer to registers structure
1688 *
1689 * Functional Description:
1690 *   This routine calls the interrupt processing routine for this adapter.  It
1691 *   disables and reenables adapter interrupts, as appropriate.  We can support
1692 *   shared interrupts since the incoming dev_id pointer provides our device
1693 *   structure context.
1694 *
1695 * Return Codes:
1696 *   None
1697 *
1698 * Assumptions:
1699 *   The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
1700 *   on Intel-based systems) is done by the operating system outside this
1701 *   routine.
1702 *
1703 *       System interrupts are enabled through this call.
1704 *
1705 * Side Effects:
1706 *   Interrupts are disabled, then reenabled at the adapter.
1707 */
1708
1709static void dfx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1710        {
1711        struct net_device       *dev = dev_id;
1712        DFX_board_t             *bp;    /* private board structure pointer */
1713        u8                              tmp;    /* used for disabling/enabling ints */
1714
1715        /* Get board pointer only if device structure is valid */
1716
1717        bp = dev->priv;
1718
1719        spin_lock(&bp->lock);
1720        
1721        /* See if we're already servicing an interrupt */
1722
1723        /* Service adapter interrupts */
1724
1725        if (bp->bus_type == DFX_BUS_TYPE_PCI)
1726                {
1727                /* Disable PDQ-PFI interrupts at PFI */
1728
1729                dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL, PFI_MODE_M_DMA_ENB);
1730
1731                /* Call interrupt service routine for this adapter */
1732
1733                dfx_int_common(dev);
1734
1735                /* Clear PDQ interrupt status bit and reenable interrupts */
1736
1737                dfx_port_write_long(bp, PFI_K_REG_STATUS, PFI_STATUS_M_PDQ_INT);
1738                dfx_port_write_long(bp, PFI_K_REG_MODE_CTRL,
1739                                        (PFI_MODE_M_PDQ_INT_ENB + PFI_MODE_M_DMA_ENB));
1740                }
1741        else
1742                {
1743                /* Disable interrupts at the ESIC */
1744
1745                dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp);
1746                tmp &= ~PI_CONFIG_STAT_0_M_INT_ENB;
1747                dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1748
1749                /* Call interrupt service routine for this adapter */
1750
1751                dfx_int_common(dev);
1752
1753                /* Reenable interrupts at the ESIC */
1754
1755                dfx_port_read_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, &tmp);
1756                tmp |= PI_CONFIG_STAT_0_M_INT_ENB;
1757                dfx_port_write_byte(bp, PI_ESIC_K_IO_CONFIG_STAT_0, tmp);
1758                }
1759
1760        spin_unlock(&bp->lock);
1761        }
1762
1763
1764/*
1765 * =====================
1766 * = dfx_ctl_get_stats =
1767 * =====================
1768 *   
1769 * Overview:
1770 *   Get statistics for FDDI adapter
1771 *  
1772 * Returns:
1773 *   Pointer to FDDI statistics structure
1774 *       
1775 * Arguments:
1776 *   dev - pointer to device information
1777 *
1778 * Functional Description:
1779 *   Gets current MIB objects from adapter, then
1780 *   returns FDDI statistics structure as defined
1781 *   in if_fddi.h.
1782 *
1783 *   Note: Since the FDDI statistics structure is
1784 *   still new and the device structure doesn't
1785 *   have an FDDI-specific get statistics handler,
1786 *   we'll return the FDDI statistics structure as
1787 *   a pointer to an Ethernet statistics structure.
1788 *   That way, at least the first part of the statistics
1789 *   structure can be decoded properly, and it allows
1790 *   "smart" applications to perform a second cast to
1791 *   decode the FDDI-specific statistics.
1792 *
1793 *   We'll have to pay attention to this routine as the
1794 *   device structure becomes more mature and LAN media
1795 *   independent.
1796 *
1797 * Return Codes:
1798 *   None
1799 *
1800 * Assumptions:
1801 *   None
1802 *
1803 * Side Effects:
1804 *   None
1805 */
1806
1807static struct net_device_stats *dfx_ctl_get_stats(struct net_device *dev)
1808        {
1809        DFX_board_t     *bp = dev->priv;
1810
1811        /* Fill the bp->stats structure with driver-maintained counters */
1812
1813        bp->stats.rx_packets                    = bp->rcv_total_frames;
1814        bp->stats.tx_packets                    = bp->xmt_total_frames;
1815        bp->stats.rx_bytes                      = bp->rcv_total_bytes;
1816        bp->stats.tx_bytes                      = bp->xmt_total_bytes;
1817        bp->stats.rx_errors                             = (u32)(bp->rcv_crc_errors + bp->rcv_frame_status_errors + bp->rcv_length_errors);
1818        bp->stats.tx_errors                             = bp->xmt_length_errors;
1819        bp->stats.rx_dropped                    = bp->rcv_discards;
1820        bp->stats.tx_dropped                    = bp->xmt_discards;
1821        bp->stats.multicast                             = bp->rcv_multicast_frames;
1822        bp->stats.transmit_collision    = 0;    /* always zero (0) for FDDI */
1823
1824        /* Get FDDI SMT MIB objects */
1825
1826        bp->cmd_req_virt->cmd_type = PI_CMD_K_SMT_MIB_GET;
1827        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1828                return((struct net_device_stats *) &bp->stats);
1829
1830        /* Fill the bp->stats structure with the SMT MIB object values */
1831
1832        memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
1833        bp->stats.smt_op_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
1834        bp->stats.smt_hi_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
1835        bp->stats.smt_lo_version_id                                     = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
1836        memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
1837        bp->stats.smt_mib_version_id                            = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
1838        bp->stats.smt_mac_cts                                           = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
1839        bp->stats.smt_non_master_cts                            = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
1840        bp->stats.smt_master_cts                                        = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
1841        bp->stats.smt_available_paths                           = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
1842        bp->stats.smt_config_capabilities                       = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
1843        bp->stats.smt_config_policy                                     = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
1844        bp->stats.smt_connection_policy                         = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
1845        bp->stats.smt_t_notify                                          = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
1846        bp->stats.smt_stat_rpt_policy                           = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
1847        bp->stats.smt_trace_max_expiration                      = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
1848        bp->stats.smt_bypass_present                            = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
1849        bp->stats.smt_ecm_state                                         = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
1850        bp->stats.smt_cf_state                                          = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
1851        bp->stats.smt_remote_disconnect_flag            = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
1852        bp->stats.smt_station_status                            = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
1853        bp->stats.smt_peer_wrap_flag                            = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
1854        bp->stats.smt_time_stamp                                        = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
1855        bp->stats.smt_transition_time_stamp                     = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
1856        bp->stats.mac_frame_status_functions            = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
1857        bp->stats.mac_t_max_capability                          = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
1858        bp->stats.mac_tvx_capability                            = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
1859        bp->stats.mac_available_paths                           = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
1860        bp->stats.mac_current_path                                      = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
1861        memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
1862        memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
1863        memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
1864        memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
1865        bp->stats.mac_dup_address_test                          = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
1866        bp->stats.mac_requested_paths                           = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
1867        bp->stats.mac_downstream_port_type                      = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
1868        memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
1869        bp->stats.mac_t_req                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
1870        bp->stats.mac_t_neg                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
1871        bp->stats.mac_t_max                                                     = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
1872        bp->stats.mac_tvx_value                                         = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
1873        bp->stats.mac_frame_error_threshold                     = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
1874        bp->stats.mac_frame_error_ratio                         = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
1875        bp->stats.mac_rmt_state                                         = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
1876        bp->stats.mac_da_flag                                           = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
1877        bp->stats.mac_una_da_flag                                       = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
1878        bp->stats.mac_frame_error_flag                          = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
1879        bp->stats.mac_ma_unitdata_available                     = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
1880        bp->stats.mac_hardware_present                          = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
1881        bp->stats.mac_ma_unitdata_enable                        = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
1882        bp->stats.path_tvx_lower_bound                          = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
1883        bp->stats.path_t_max_lower_bound                        = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
1884        bp->stats.path_max_t_req                                        = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
1885        memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
1886        bp->stats.port_my_type[0]                                       = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
1887        bp->stats.port_my_type[1]                                       = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
1888        bp->stats.port_neighbor_type[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
1889        bp->stats.port_neighbor_type[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
1890        bp->stats.port_connection_policies[0]           = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
1891        bp->stats.port_connection_policies[1]           = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
1892        bp->stats.port_mac_indicated[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
1893        bp->stats.port_mac_indicated[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
1894        bp->stats.port_current_path[0]                          = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
1895        bp->stats.port_current_path[1]                          = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
1896        memcpy(&bp->stats.port_requested_paths[0*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
1897        memcpy(&bp->stats.port_requested_paths[1*3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
1898        bp->stats.port_mac_placement[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
1899        bp->stats.port_mac_placement[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
1900        bp->stats.port_available_paths[0]                       = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
1901        bp->stats.port_available_paths[1]                       = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
1902        bp->stats.port_pmd_class[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
1903        bp->stats.port_pmd_class[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
1904        bp->stats.port_connection_capabilities[0]       = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
1905        bp->stats.port_connection_capabilities[1]       = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
1906        bp->stats.port_bs_flag[0]                                       = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
1907        bp->stats.port_bs_flag[1]                                       = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
1908        bp->stats.port_ler_estimate[0]                          = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
1909        bp->stats.port_ler_estimate[1]                          = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
1910        bp->stats.port_ler_cutoff[0]                            = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
1911        bp->stats.port_ler_cutoff[1]                            = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
1912        bp->stats.port_ler_alarm[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
1913        bp->stats.port_ler_alarm[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
1914        bp->stats.port_connect_state[0]                         = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
1915        bp->stats.port_connect_state[1]                         = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
1916        bp->stats.port_pcm_state[0]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
1917        bp->stats.port_pcm_state[1]                                     = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
1918        bp->stats.port_pc_withhold[0]                           = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
1919        bp->stats.port_pc_withhold[1]                           = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
1920        bp->stats.port_ler_flag[0]                                      = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
1921        bp->stats.port_ler_flag[1]                                      = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
1922        bp->stats.port_hardware_present[0]                      = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
1923        bp->stats.port_hardware_present[1]                      = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
1924
1925        /* Get FDDI counters */
1926
1927        bp->cmd_req_virt->cmd_type = PI_CMD_K_CNTRS_GET;
1928        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
1929                return((struct net_device_stats *) &bp->stats);
1930
1931        /* Fill the bp->stats structure with the FDDI counter values */
1932
1933        bp->stats.mac_frame_cts                         = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
1934        bp->stats.mac_copied_cts                        = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
1935        bp->stats.mac_transmit_cts                      = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
1936        bp->stats.mac_error_cts                         = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
1937        bp->stats.mac_lost_cts                          = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
1938        bp->stats.port_lct_fail_cts[0]          = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
1939        bp->stats.port_lct_fail_cts[1]          = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
1940        bp->stats.port_lem_reject_cts[0]        = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
1941        bp->stats.port_lem_reject_cts[1]        = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
1942        bp->stats.port_lem_cts[0]                       = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
1943        bp->stats.port_lem_cts[1]                       = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
1944
1945        return((struct net_device_stats *) &bp->stats);
1946        }
1947
1948
1949/*
1950 * ==============================
1951 * = dfx_ctl_set_multicast_list =
1952 * ==============================
1953 *   
1954 * Overview:
1955 *   Enable/Disable LLC frame promiscuous mode reception
1956 *   on the adapter and/or update multicast address table.
1957 *  
1958 * Returns:
1959 *   None
1960 *       
1961 * Arguments:
1962 *   dev - pointer to device information
1963 *
1964 * Functional Description:
1965 *   This routine follows a fairly simple algorithm for setting the
1966 *   adapter filters and CAM:
1967 *
1968 *              if IFF_PROMISC flag is set
1969 *                      enable LLC individual/group promiscuous mode
1970 *              else
1971 *                      disable LLC individual/group promiscuous mode
1972 *                      if number of incoming multicast addresses >
1973 *                                      (CAM max size - number of unicast addresses in CAM)
1974 *                              enable LLC group promiscuous mode
1975 *                              set driver-maintained multicast address count to zero
1976 *                      else
1977 *                              disable LLC group promiscuous mode
1978 *                              set driver-maintained multicast address count to incoming count
1979 *                      update adapter CAM
1980 *              update adapter filters
1981 *
1982 * Return Codes:
1983 *   None
1984 *
1985 * Assumptions:
1986 *   Multicast addresses are presented in canonical (LSB) format.
1987 *
1988 * Side Effects:
1989 *   On-board adapter CAM and filters are updated.
1990 */
1991
1992static void dfx_ctl_set_multicast_list(struct net_device *dev)
1993        {
1994        DFX_board_t                     *bp = dev->priv;
1995        int                                     i;                      /* used as index in for loop */
1996        struct dev_mc_list      *dmi;           /* ptr to multicast addr entry */
1997
1998        /* Enable LLC frame promiscuous mode, if necessary */
1999
2000        if (dev->flags & IFF_PROMISC)
2001                bp->ind_group_prom = PI_FSTATE_K_PASS;          /* Enable LLC ind/group prom mode */
2002
2003        /* Else, update multicast address table */
2004
2005        else
2006                {
2007                bp->ind_group_prom = PI_FSTATE_K_BLOCK;         /* Disable LLC ind/group prom mode */
2008                /*
2009                 * Check whether incoming multicast address count exceeds table size
2010                 *
2011                 * Note: The adapters utilize an on-board 64 entry CAM for
2012                 *       supporting perfect filtering of multicast packets
2013                 *               and bridge functions when adding unicast addresses.
2014                 *               There is no hash function available.  To support
2015                 *               additional multicast addresses, the all multicast
2016                 *               filter (LLC group promiscuous mode) must be enabled.
2017                 *
2018                 *               The firmware reserves two CAM entries for SMT-related
2019                 *               multicast addresses, which leaves 62 entries available.
2020                 *               The following code ensures that we're not being asked
2021                 *               to add more than 62 addresses to the CAM.  If we are,
2022                 *               the driver will enable the all multicast filter.
2023                 *               Should the number of multicast addresses drop below
2024                 *               the high water mark, the filter will be disabled and
2025                 *               perfect filtering will be used.
2026                 */
2027
2028                if (dev->mc_count > (PI_CMD_ADDR_FILTER_K_SIZE - bp->uc_count))
2029                        {
2030                        bp->group_prom  = PI_FSTATE_K_PASS;             /* Enable LLC group prom mode */
2031                        bp->mc_count    = 0;                                    /* Don't add mc addrs to CAM */
2032                        }
2033                else
2034                        {
2035                        bp->group_prom  = PI_FSTATE_K_BLOCK;    /* Disable LLC group prom mode */
2036                        bp->mc_count    = dev->mc_count;                /* Add mc addrs to CAM */
2037                        }
2038
2039                /* Copy addresses to multicast address table, then update adapter CAM */
2040
2041                dmi = dev->mc_list;                             /* point to first multicast addr */
2042                for (i=0; i < bp->mc_count; i++)
2043                        {
2044                        memcpy(&bp->mc_table[i*FDDI_K_ALEN], dmi->dmi_addr, FDDI_K_ALEN);
2045                        dmi = dmi->next;                        /* point to next multicast addr */
2046                        }
2047                if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2048                        {
2049                        DBG_printk("%s: Could not update multicast address table!\n", dev->name);
2050                        }
2051                else
2052                        {
2053                        DBG_printk("%s: Multicast address table updated!  Added %d addresses.\n", dev->name, bp->mc_count);
2054                        }
2055                }
2056
2057        /* Update adapter filters */
2058
2059        if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2060                {
2061                DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2062                }
2063        else
2064                {
2065                DBG_printk("%s: Adapter filters updated!\n", dev->name);
2066                }
2067        }
2068
2069
2070/*
2071 * ===========================
2072 * = dfx_ctl_set_mac_address =
2073 * ===========================
2074 *   
2075 * Overview:
2076 *   Add node address override (unicast address) to adapter
2077 *   CAM and update dev_addr field in device table.
2078 *  
2079 * Returns:
2080 *   None
2081 *       
2082 * Arguments:
2083 *   dev  - pointer to device information
2084 *   addr - pointer to sockaddr structure containing unicast address to add
2085 *
2086 * Functional Description:
2087 *   The adapter supports node address overrides by adding one or more
2088 *   unicast addresses to the adapter CAM.  This is similar to adding
2089 *   multicast addresses.  In this routine we'll update the driver and
2090 *   device structures with the new address, then update the adapter CAM
2091 *   to ensure that the adapter will copy and strip frames destined and
2092 *   sourced by that address.
2093 *
2094 * Return Codes:
2095 *   Always returns zero.
2096 *
2097 * Assumptions:
2098 *   The address pointed to by addr->sa_data is a valid unicast
2099 *   address and is presented in canonical (LSB) format.
2100 *
2101 * Side Effects:
2102 *   On-board adapter CAM is updated.  On-board adapter filters
2103 *   may be updated.
2104 */
2105
2106static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)
2107        {
2108        DFX_board_t             *bp = dev->priv;
2109        struct sockaddr *p_sockaddr = (struct sockaddr *)addr;
2110
2111        /* Copy unicast address to driver-maintained structs and update count */
2112
2113        memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);        /* update device struct */
2114        memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN);     /* update driver struct */
2115        bp->uc_count = 1;
2116
2117        /*
2118         * Verify we're not exceeding the CAM size by adding unicast address
2119         *
2120         * Note: It's possible that before entering this routine we've
2121         *       already filled the CAM with 62 multicast addresses.
2122         *               Since we need to place the node address override into
2123         *               the CAM, we have to check to see that we're not
2124         *               exceeding the CAM size.  If we are, we have to enable
2125         *               the LLC group (multicast) promiscuous mode filter as
2126         *               in dfx_ctl_set_multicast_list.
2127         */
2128
2129        if ((bp->uc_count + bp->mc_count) > PI_CMD_ADDR_FILTER_K_SIZE)
2130                {
2131                bp->group_prom  = PI_FSTATE_K_PASS;             /* Enable LLC group prom mode */
2132                bp->mc_count    = 0;                                    /* Don't add mc addrs to CAM */
2133
2134                /* Update adapter filters */
2135
2136                if (dfx_ctl_update_filters(bp) != DFX_K_SUCCESS)
2137                        {
2138                        DBG_printk("%s: Could not update adapter filters!\n", dev->name);
2139                        }
2140                else
2141                        {
2142                        DBG_printk("%s: Adapter filters updated!\n", dev->name);
2143                        }
2144                }
2145
2146        /* Update adapter CAM with new unicast address */
2147
2148        if (dfx_ctl_update_cam(bp) != DFX_K_SUCCESS)
2149                {
2150                DBG_printk("%s: Could not set new MAC address!\n", dev->name);
2151                }
2152        else
2153                {
2154                DBG_printk("%s: Adapter CAM updated with new MAC address\n", dev->name);
2155                }
2156        return(0);                      /* always return zero */
2157        }
2158
2159
2160/*
2161 * ======================
2162 * = dfx_ctl_update_cam =
2163 * ======================
2164 *
2165 * Overview:
2166 *   Procedure to update adapter CAM (Content Addressable Memory)
2167 *   with desired unicast and multicast address entries.
2168 *
2169 * Returns:
2170 *   Condition code
2171 *
2172 * Arguments:
2173 *   bp - pointer to board information
2174 *
2175 * Functional Description:
2176 *   Updates adapter CAM with current contents of board structure
2177 *   unicast and multicast address tables.  Since there are only 62
2178 *   free entries in CAM, this routine ensures that the command
2179 *   request buffer is not overrun.
2180 *
2181 * Return Codes:
2182 *   DFX_K_SUCCESS - Request succeeded
2183 *   DFX_K_FAILURE - Request failed
2184 *
2185 * Assumptions:
2186 *   All addresses being added (unicast and multicast) are in canonical
2187 *   order.
2188 *
2189 * Side Effects:
2190 *   On-board adapter CAM is updated.
2191 */
2192
2193static int dfx_ctl_update_cam(DFX_board_t *bp)
2194        {
2195        int                     i;                              /* used as index */
2196        PI_LAN_ADDR     *p_addr;                /* pointer to CAM entry */
2197
2198        /*
2199         * Fill in command request information
2200         *
2201         * Note: Even though both the unicast and multicast address
2202         *       table entries are stored as contiguous 6 byte entries,
2203         *               the firmware address filter set command expects each
2204         *               entry to be two longwords (8 bytes total).  We must be
2205         *               careful to only copy the six bytes of each unicast and
2206         *               multicast table entry into each command entry.  This
2207         *               is also why we must first clear the entire command
2208         *               request buffer.
2209         */
2210
2211        memset(bp->cmd_req_virt, 0, PI_CMD_REQ_K_SIZE_MAX);     /* first clear buffer */
2212        bp->cmd_req_virt->cmd_type = PI_CMD_K_ADDR_FILTER_SET;
2213        p_addr = &bp->cmd_req_virt->addr_filter_set.entry[0];
2214
2215        /* Now add unicast addresses to command request buffer, if any */
2216
2217        for (i=0; i < (int)bp->uc_count; i++)
2218                {
2219                if (i < PI_CMD_ADDR_FILTER_K_SIZE)
2220                        {
2221                        memcpy(p_addr, &bp->uc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2222                        p_addr++;                       /* point to next command entry */
2223                        }
2224                }
2225
2226        /* Now add multicast addresses to command request buffer, if any */
2227
2228        for (i=0; i < (int)bp->mc_count; i++)
2229                {
2230                if ((i + bp->uc_count) < PI_CMD_ADDR_FILTER_K_SIZE)
2231                        {
2232                        memcpy(p_addr, &bp->mc_table[i*FDDI_K_ALEN], FDDI_K_ALEN);
2233                        p_addr++;                       /* point to next command entry */
2234                        }
2235                }
2236
2237        /* Issue command to update adapter CAM, then return */
2238
2239        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2240                return(DFX_K_FAILURE);
2241        return(DFX_K_SUCCESS);
2242        }
2243
2244
2245/*
2246 * ==========================
2247 * = dfx_ctl_update_filters =
2248 * ==========================
2249 *
2250 * Overview:
2251 *   Procedure to update adapter filters with desired
2252 *   filter settings.
2253 *  
2254 * Returns:
2255 *   Condition code
2256 *       
2257 * Arguments:
2258 *   bp - pointer to board information
2259 *
2260 * Functional Description:
2261 *   Enables or disables filter using current filter settings.
2262 *
2263 * Return Codes:
2264 *   DFX_K_SUCCESS - Request succeeded.
2265 *   DFX_K_FAILURE - Request failed.
2266 *
2267 * Assumptions:
2268 *   We must always pass up packets destined to the broadcast
2269 *   address (FF-FF-FF-FF-FF-FF), so we'll always keep the
2270 *   broadcast filter enabled.
2271 *
2272 * Side Effects:
2273 *   On-board adapter filters are updated.
2274 */
2275
2276static int dfx_ctl_update_filters(DFX_board_t *bp)
2277        {
2278        int     i = 0;                                  /* used as index */
2279
2280        /* Fill in command request information */
2281
2282        bp->cmd_req_virt->cmd_type = PI_CMD_K_FILTERS_SET;
2283
2284        /* Initialize Broadcast filter - * ALWAYS ENABLED * */
2285
2286        bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_BROADCAST;
2287        bp->cmd_req_virt->filter_set.item[i++].value    = PI_FSTATE_K_PASS;
2288
2289        /* Initialize LLC Individual/Group Promiscuous filter */
2290
2291        bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_IND_GROUP_PROM;
2292        bp->cmd_req_virt->filter_set.item[i++].value    = bp->ind_group_prom;
2293
2294        /* Initialize LLC Group Promiscuous filter */
2295
2296        bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_GROUP_PROM;
2297        bp->cmd_req_virt->filter_set.item[i++].value    = bp->group_prom;
2298
2299        /* Terminate the item code list */
2300
2301        bp->cmd_req_virt->filter_set.item[i].item_code  = PI_ITEM_K_EOL;
2302
2303        /* Issue command to update adapter filters, then return */
2304
2305        if (dfx_hw_dma_cmd_req(bp) != DFX_K_SUCCESS)
2306                return(DFX_K_FAILURE);
2307        return(DFX_K_SUCCESS);
2308        }
2309
2310
2311/*
2312 * ======================
2313 * = dfx_hw_dma_cmd_req =
2314 * ======================
2315 *   
2316 * Overview:
2317 *   Sends PDQ DMA command to adapter firmware
2318 *  
2319 * Returns:
2320 *   Condition code
2321 *       
2322 * Arguments:
2323 *   bp - pointer to board information
2324 *
2325 * Functional Description:
2326 *   The command request and response buffers are posted to the adapter in the manner
2327 *   described in the PDQ Port Specification:
2328 *
2329 *              1. Command Response Buffer is posted to adapter.
2330 *              2. Command Request Buffer is posted to adapter.
2331 *              3. Command Request consumer index is polled until it indicates that request
2332 *         buffer has been DMA'd to adapter.
2333 *              4. Command Response consumer index is polled until it indicates that response
2334 *         buffer has been DMA'd from adapter.
2335 *
2336 *   This ordering ensures that a response buffer is already available for the firmware
2337 *   to use once it's done processing the request buffer.
2338 *
2339 * Return Codes:
2340 *   DFX_K_SUCCESS        - DMA command succeeded
2341 *       DFX_K_OUTSTATE   - Adapter is NOT in proper state
2342 *   DFX_K_HW_TIMEOUT - DMA command timed out
2343 *
2344 * Assumptions:
2345 *   Command request buffer has already been filled with desired DMA command.
2346 *
2347 * Side Effects:
2348 *   None
2349 */
2350
2351static int dfx_hw_dma_cmd_req(DFX_board_t *bp)
2352        {
2353        int status;                     /* adapter status */
2354        int timeout_cnt;        /* used in for loops */
2355        
2356        /* Make sure the adapter is in a state that we can issue the DMA command in */
2357        
2358        status = dfx_hw_adap_state_rd(bp);
2359        if ((status == PI_STATE_K_RESET)                ||
2360                (status == PI_STATE_K_HALTED)           ||
2361                (status == PI_STATE_K_DMA_UNAVAIL)      ||
2362                (status == PI_STATE_K_UPGRADE))
2363                return(DFX_K_OUTSTATE);
2364
2365        /* Put response buffer on the command response queue */
2366
2367        bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2368                        ((PI_CMD_RSP_K_SIZE_MAX / PI_ALIGN_K_CMD_RSP_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2369        bp->descr_block_virt->cmd_rsp[bp->cmd_rsp_reg.index.prod].long_1 = bp->cmd_rsp_phys;
2370
2371        /* Bump (and wrap) the producer index and write out to register */
2372
2373        bp->cmd_rsp_reg.index.prod += 1;
2374        bp->cmd_rsp_reg.index.prod &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2375        dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2376
2377        /* Put request buffer on the command request queue */
2378        
2379        bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_0 = (u32) (PI_XMT_DESCR_M_SOP |
2380                        PI_XMT_DESCR_M_EOP | (PI_CMD_REQ_K_SIZE_MAX << PI_XMT_DESCR_V_SEG_LEN));
2381        bp->descr_block_virt->cmd_req[bp->cmd_req_reg.index.prod].long_1 = bp->cmd_req_phys;
2382
2383        /* Bump (and wrap) the producer index and write out to register */
2384
2385        bp->cmd_req_reg.index.prod += 1;
2386        bp->cmd_req_reg.index.prod &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2387        dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2388
2389        /*
2390         * Here we wait for the command request consumer index to be equal
2391         * to the producer, indicating that the adapter has DMAed the request.
2392         */
2393
2394        for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2395                {
2396                if (bp->cmd_req_reg.index.prod == (u8)(bp->cons_block_virt->cmd_req))
2397                        break;
2398                udelay(100);                    /* wait for 100 microseconds */
2399                }
2400        if (timeout_cnt == 0) 
2401                return(DFX_K_HW_TIMEOUT);
2402
2403        /* Bump (and wrap) the completion index and write out to register */
2404
2405        bp->cmd_req_reg.index.comp += 1;
2406        bp->cmd_req_reg.index.comp &= PI_CMD_REQ_K_NUM_ENTRIES-1;
2407        dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_REQ_PROD, bp->cmd_req_reg.lword);
2408
2409        /*
2410         * Here we wait for the command response consumer index to be equal
2411         * to the producer, indicating that the adapter has DMAed the response.
2412         */
2413
2414        for (timeout_cnt = 20000; timeout_cnt > 0; timeout_cnt--)
2415                {
2416                if (bp->cmd_rsp_reg.index.prod == (u8)(bp->cons_block_virt->cmd_rsp))
2417                        break;
2418                udelay(100);                    /* wait for 100 microseconds */
2419                }
2420        if (timeout_cnt == 0) 
2421                return(DFX_K_HW_TIMEOUT);
2422
2423        /* Bump (and wrap) the completion index and write out to register */
2424
2425        bp->cmd_rsp_reg.index.comp += 1;
2426        bp->cmd_rsp_reg.index.comp &= PI_CMD_RSP_K_NUM_ENTRIES-1;
2427        dfx_port_write_long(bp, PI_PDQ_K_REG_CMD_RSP_PROD, bp->cmd_rsp_reg.lword);
2428        return(DFX_K_SUCCESS);
2429        }
2430
2431
2432/*
2433 * ========================
2434 * = dfx_hw_port_ctrl_req =
2435 * ========================
2436 *   
2437 * Overview:
2438 *   Sends PDQ port control command to adapter firmware
2439 *  
2440 * Returns:
2441 *   Host data register value in host_data if ptr is not NULL
2442 *       
2443 * Arguments:
2444 *   bp                 - pointer to board information
2445 *       command        - port control command
2446 *       data_a         - port data A register value
2447 *       data_b         - port data B register value
2448 *       host_data      - ptr to host data register value
2449 *
2450 * Functional Description:
2451 *   Send generic port control command to adapter by writing
2452 *   to various PDQ port registers, then polling for completion.
2453 *
2454 * Return Codes:
2455 *   DFX_K_SUCCESS        - port control command succeeded
2456 *   DFX_K_HW_TIMEOUT - port control command timed out
2457 *
2458 * Assumptions:
2459 *   None
2460 *
2461 * Side Effects:
2462 *   None
2463 */
2464
2465static int dfx_hw_port_ctrl_req(
2466        DFX_board_t     *bp,
2467        PI_UINT32       command,
2468        PI_UINT32       data_a,
2469        PI_UINT32       data_b,
2470        PI_UINT32       *host_data
2471        )
2472
2473        {
2474        PI_UINT32       port_cmd;               /* Port Control command register value */
2475        int                     timeout_cnt;    /* used in for loops */
2476
2477        /* Set Command Error bit in command longword */
2478        
2479        port_cmd = (PI_UINT32) (command | PI_PCTRL_M_CMD_ERROR);
2480
2481        /* Issue port command to the adapter */
2482
2483        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, data_a);
2484        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_B, data_b);
2485        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_CTRL, port_cmd);
2486
2487        /* Now wait for command to complete */
2488
2489        if (command == PI_PCTRL_M_BLAST_FLASH)
2490                timeout_cnt = 600000;   /* set command timeout count to 60 seconds */
2491        else
2492                timeout_cnt = 20000;    /* set command timeout count to 2 seconds */
2493
2494        for (; timeout_cnt > 0; timeout_cnt--)
2495                {
2496                dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_CTRL, &port_cmd);
2497                if (!(port_cmd & PI_PCTRL_M_CMD_ERROR))
2498                        break;
2499                udelay(100);                    /* wait for 100 microseconds */
2500                }
2501        if (timeout_cnt == 0) 
2502                return(DFX_K_HW_TIMEOUT);
2503
2504        /*
2505         * If the address of host_data is non-zero, assume caller has supplied a  
2506         * non NULL pointer, and return the contents of the HOST_DATA register in 
2507         * it.
2508         */
2509
2510        if (host_data != NULL)
2511                dfx_port_read_long(bp, PI_PDQ_K_REG_HOST_DATA, host_data);
2512        return(DFX_K_SUCCESS);
2513        }
2514
2515
2516/*
2517 * =====================
2518 * = dfx_hw_adap_reset =
2519 * =====================
2520 *   
2521 * Overview:
2522 *   Resets adapter
2523 *  
2524 * Returns:
2525 *   None
2526 *       
2527 * Arguments:
2528 *   bp   - pointer to board information
2529 *   type - type of reset to perform
2530 *
2531 * Functional Description:
2532 *   Issue soft reset to adapter by writing to PDQ Port Reset
2533 *   register.  Use incoming reset type to tell adapter what
2534 *   kind of reset operation to perform.
2535 *
2536 * Return Codes:
2537 *   None
2538 *
2539 * Assumptions:
2540 *   This routine merely issues a soft reset to the adapter.
2541 *   It is expected that after this routine returns, the caller
2542 *   will appropriately poll the Port Status register for the
2543 *   adapter to enter the proper state.
2544 *
2545 * Side Effects:
2546 *   Internal adapter registers are cleared.
2547 */
2548
2549static void dfx_hw_adap_reset(
2550        DFX_board_t     *bp,
2551        PI_UINT32       type
2552        )
2553
2554        {
2555        /* Set Reset type and assert reset */
2556
2557        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_DATA_A, type);        /* tell adapter type of reset */
2558        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, PI_RESET_M_ASSERT_RESET);
2559
2560        /* Wait for at least 1 Microsecond according to the spec. We wait 20 just to be safe */
2561
2562        udelay(20);
2563
2564        /* Deassert reset */
2565
2566        dfx_port_write_long(bp, PI_PDQ_K_REG_PORT_RESET, 0);
2567        }
2568
2569
2570/*
2571 * ========================
2572 * = dfx_hw_adap_state_rd =
2573 * ========================
2574 *   
2575 * Overview:
2576 *   Returns current adapter state
2577 *  
2578 * Returns:
2579 *   Adapter state per PDQ Port Specification
2580 *       
2581 * Arguments:
2582 *   bp - pointer to board information
2583 *
2584 * Functional Description:
2585 *   Reads PDQ Port Status register and returns adapter state.
2586 *
2587 * Return Codes:
2588 *   None
2589 *
2590 * Assumptions:
2591 *   None
2592 *
2593 * Side Effects:
2594 *   None
2595 */
2596
2597static int dfx_hw_adap_state_rd(DFX_board_t *bp)
2598        {
2599        PI_UINT32 port_status;          /* Port Status register value */
2600
2601        dfx_port_read_long(bp, PI_PDQ_K_REG_PORT_STATUS, &port_status);
2602        return((port_status & PI_PSTATUS_M_STATE) >> PI_PSTATUS_V_STATE);
2603        }
2604
2605
2606/*
2607 * =====================
2608 * = dfx_hw_dma_uninit =
2609 * =====================
2610 *   
2611 * Overview:
2612 *   Brings adapter to DMA_UNAVAILABLE state
2613 *  
2614 * Returns:
2615 *   Condition code
2616 *       
2617 * Arguments:
2618 *   bp   - pointer to board information
2619 *   type - type of reset to perform
2620 *
2621 * Functional Description:
2622 *   Bring adapter to DMA_UNAVAILABLE state by performing the following:
2623 *              1. Set reset type bit in Port Data A Register then reset adapter.
2624 *              2. Check that adapter is in DMA_UNAVAILABLE state.
2625 *
2626 * Return Codes:
2627 *   DFX_K_SUCCESS        - adapter is in DMA_UNAVAILABLE state
2628 *   DFX_K_HW_TIMEOUT - adapter did not reset properly
2629 *
2630 * Assumptions:
2631 *   None
2632 *
2633 * Side Effects:
2634 *   Internal adapter registers are cleared.
2635 */
2636
2637static int dfx_hw_dma_uninit(DFX_board_t *bp, PI_UINT32 type)
2638        {
2639        int timeout_cnt;        /* used in for loops */
2640
2641        /* Set reset type bit and reset adapter */
2642
2643        dfx_hw_adap_reset(bp, type);
2644
2645        /* Now wait for adapter to enter DMA_UNAVAILABLE state */
2646
2647        for (timeout_cnt = 100000; timeout_cnt > 0; timeout_cnt--)
2648                {
2649                if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_DMA_UNAVAIL)
2650                        break;
2651                udelay(100);                                    /* wait for 100 microseconds */
2652                }
2653        if (timeout_cnt == 0) 
2654                return(DFX_K_HW_TIMEOUT);
2655        return(DFX_K_SUCCESS);
2656        }
2657
2658/*
2659 *      Align an sk_buff to a boundary power of 2
2660 *
2661 */
2662 
2663static void my_skb_align(struct sk_buff *skb, int n)
2664{
2665        u32 x=(u32)skb->data;   /* We only want the low bits .. */
2666        u32 v;
2667        
2668        v=(x+n-1)&~(n-1);       /* Where we want to be */
2669        
2670        skb_reserve(skb, v-x);
2671}
2672
2673
2674/*
2675 * ================
2676 * = dfx_rcv_init =
2677 * ================
2678 *   
2679 * Overview:
2680 *   Produces buffers to adapter LLC Host receive descriptor block
2681 *  
2682 * Returns:
2683 *   None
2684 *       
2685 * Arguments:
2686 *   bp - pointer to board information
2687 *   get_buffers - non-zero if buffers to be allocated
2688 *
2689 * Functional Description:
2690 *   This routine can be called during dfx_adap_init() or during an adapter
2691 *       reset.  It initializes the descriptor block and produces all allocated
2692 *   LLC Host queue receive buffers.
2693 *
2694 * Return Codes:
2695 *   Return 0 on success or -ENOMEM if buffer allocation failed (when using
2696 *   dynamic buffer allocation). If the buffer allocation failed, the
2697 *   already allocated buffers will not be released and the caller should do
2698 *   this.
2699 *
2700 * Assumptions:
2701 *   The PDQ has been reset and the adapter and driver maintained Type 2
2702 *   register indices are cleared.
2703 *
2704 * Side Effects:
2705 *   Receive buffers are posted to the adapter LLC queue and the adapter
2706 *   is notified.
2707 */
2708
2709static int dfx_rcv_init(DFX_board_t *bp, int get_buffers)
2710        {
2711        int     i, j;                                   /* used in for loop */
2712
2713        /*
2714         *  Since each receive buffer is a single fragment of same length, initialize
2715         *  first longword in each receive descriptor for entire LLC Host descriptor
2716         *  block.  Also initialize second longword in each receive descriptor with
2717         *  physical address of receive buffer.  We'll always allocate receive
2718         *  buffers in powers of 2 so that we can easily fill the 256 entry descriptor
2719         *  block and produce new receive buffers by simply updating the receive
2720         *  producer index.
2721         *
2722         *      Assumptions:
2723         *              To support all shipping versions of PDQ, the receive buffer size
2724         *              must be mod 128 in length and the physical address must be 128 byte
2725         *              aligned.  In other words, bits 0-6 of the length and address must
2726         *              be zero for the following descriptor field entries to be correct on
2727         *              all PDQ-based boards.  We guaranteed both requirements during
2728         *              driver initialization when we allocated memory for the receive buffers.
2729         */
2730
2731        if (get_buffers) {
2732#ifdef DYNAMIC_BUFFERS
2733        for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
2734                for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2735                {
2736                        struct sk_buff *newskb = __dev_alloc_skb(NEW_SKB_SIZE, GFP_NOIO);
2737                        if (!newskb)
2738                                return -ENOMEM;
2739                        bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2740                                ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2741                        /*
2742                         * align to 128 bytes for compatibility with
2743                         * the old EISA boards.
2744                         */
2745                         
2746                        my_skb_align(newskb, 128);
2747                        bp->descr_block_virt->rcv_data[i+j].long_1 = virt_to_bus(newskb->data);
2748                        /*
2749                         * p_rcv_buff_va is only used inside the
2750                         * kernel so we put the skb pointer here.
2751                         */
2752                        bp->p_rcv_buff_va[i+j] = (char *) newskb;
2753                }
2754#else
2755        for (i=0; i < (int)(bp->rcv_bufs_to_post); i++)
2756                for (j=0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
2757                        {
2758                        bp->descr_block_virt->rcv_data[i+j].long_0 = (u32) (PI_RCV_DESCR_M_SOP |
2759                                ((PI_RCV_DATA_K_SIZE_MAX / PI_ALIGN_K_RCV_DATA_BUFF) << PI_RCV_DESCR_V_SEG_LEN));
2760                        bp->descr_block_virt->rcv_data[i+j].long_1 = (u32) (bp->rcv_block_phys + (i * PI_RCV_DATA_K_SIZE_MAX));
2761                        bp->p_rcv_buff_va[i+j] = (char *) (bp->rcv_block_virt + (i * PI_RCV_DATA_K_SIZE_MAX));
2762                        }
2763#endif
2764        }
2765
2766        /* Update receive producer and Type 2 register */
2767
2768        bp->rcv_xmt_reg.index.rcv_prod = bp->rcv_bufs_to_post;
2769        dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
2770        return 0;
2771        }
2772
2773
2774/*
2775 * =========================
2776 * = dfx_rcv_queue_process =
2777 * =========================
2778 *   
2779 * Overview:
2780 *   Process received LLC frames.
2781 *  
2782 * Returns:
2783 *   None
2784 *       
2785 * Arguments:
2786 *   bp - pointer to board information
2787 *
2788 * Functional Description:
2789 *   Received LLC frames are processed until there are no more consumed frames.
2790 *   Once all frames are processed, the receive buffers are returned to the
2791 *   adapter.  Note that this algorithm fixes the length of time that can be spent
2792 *   in this routine, because there are a fixed number of receive buffers to
2793 *   process and buffers are not produced until this routine exits and returns
2794 *   to the ISR.
2795 *
2796 * Return Codes:
2797 *   None
2798 *
2799 * Assumptions:
2800 *   None
2801 *
2802 * Side Effects:
2803 *   None
2804 */
2805
2806static void dfx_rcv_queue_process(
2807        DFX_board_t *bp
2808        )
2809
2810        {
2811        PI_TYPE_2_CONSUMER      *p_type_2_cons;         /* ptr to rcv/xmt consumer block register */
2812        char                            *p_buff;                        /* ptr to start of packet receive buffer (FMC descriptor) */
2813        u32                                     descr, pkt_len;         /* FMC descriptor field and packet length */
2814        struct sk_buff          *skb;                           /* pointer to a sk_buff to hold incoming packet data */
2815
2816        /* Service all consumed LLC receive frames */
2817
2818        p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
2819        while (bp->rcv_xmt_reg.index.rcv_comp != p_type_2_cons->index.rcv_cons)
2820                {
2821                /* Process any errors */
2822
2823                int entry;
2824
2825                entry = bp->rcv_xmt_reg.index.rcv_comp;
2826#ifdef DYNAMIC_BUFFERS
2827                p_buff = (char *) (((struct sk_buff *)bp->p_rcv_buff_va[entry])->data);
2828#else
2829                p_buff = (char *) bp->p_rcv_buff_va[entry];
2830#endif
2831                memcpy(&descr, p_buff + RCV_BUFF_K_DESCR, sizeof(u32));
2832
2833                if (descr & PI_FMC_DESCR_M_RCC_FLUSH)
2834                        {
2835                        if (descr & PI_FMC_DESCR_M_RCC_CRC)
2836                                bp->rcv_crc_errors++;
2837                        else
2838                                bp->rcv_frame_status_errors++;
2839                        }
2840                else
2841                {
2842                        int rx_in_place = 0;
2843
2844                        /* The frame was received without errors - verify packet length */
2845
2846                        pkt_len = (u32)((descr & PI_FMC_DESCR_M_LEN) >> PI_FMC_DESCR_V_LEN);
2847                        pkt_len -= 4;                           /* subtract 4 byte CRC */
2848                        if (!IN_RANGE(pkt_len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
2849                                bp->rcv_length_errors++;
2850                        else{
2851#ifdef DYNAMIC_BUFFERS
2852                                if (pkt_len > SKBUFF_RX_COPYBREAK) {
2853                                        struct sk_buff *newskb;
2854
2855                                        newskb = dev_alloc_skb(NEW_SKB_SIZE);
2856                                        if (newskb){
2857                                                rx_in_place = 1;
2858                                                
2859                                                my_skb_align(newskb, 128);
2860                                                skb = (struct sk_buff *)bp->p_rcv_buff_va[entry];
2861                                                skb_reserve(skb, RCV_BUFF_K_PADDING);
2862                                                bp->p_rcv_buff_va[entry] = (char *)newskb;
2863                                                bp->descr_block_virt->rcv_data[entry].long_1 = virt_to_bus(newskb->data);
2864                                        } else
2865                                                skb = NULL;
2866                                } else
2867#endif
2868                                        skb = dev_alloc_skb(pkt_len+3); /* alloc new buffer to pass up, add room for PRH */
2869                                if (skb == NULL)
2870                                        {
2871                                        printk("%s: Could not allocate receive buffer.  Dropping packet.\n", bp->dev->name);
2872                                        bp->rcv_discards++;
2873                                        break;
2874                                        }
2875                                else {
2876#ifndef DYNAMIC_BUFFERS
2877                                        if (! rx_in_place)
2878#endif
2879                                        {
2880                                                /* Receive buffer allocated, pass receive packet up */
2881
2882                                                memcpy(skb->data, p_buff + RCV_BUFF_K_PADDING, pkt_len+3);
2883                                        }
2884                                        
2885                                        skb_reserve(skb,3);             /* adjust data field so that it points to FC byte */
2886                                        skb_put(skb, pkt_len);          /* pass up packet length, NOT including CRC */
2887                                        skb->dev = bp->dev;             /* pass up device pointer */
2888
2889                                        skb->protocol = fddi_type_trans(skb, bp->dev);
2890                                        bp->rcv_total_bytes += skb->len;
2891                                        netif_rx(skb);
2892
2893                                        /* Update the rcv counters */
2894                                        bp->dev->last_rx = jiffies;
2895                                        bp->rcv_total_frames++;
2896                                        if (*(p_buff + RCV_BUFF_K_DA) & 0x01)
2897                                                bp->rcv_multicast_frames++;
2898                                }
2899                        }
2900                        }
2901
2902                /*
2903                 * Advance the producer (for recycling) and advance the completion
2904                 * (for servicing received frames).  Note that it is okay to
2905                 * advance the producer without checking that it passes the
2906                 * completion index because they are both advanced at the same
2907                 * rate.
2908                 */
2909
2910                bp->rcv_xmt_reg.index.rcv_prod += 1;
2911                bp->rcv_xmt_reg.index.rcv_comp += 1;
2912                }
2913        }
2914
2915
2916/*
2917 * =====================
2918 * = dfx_xmt_queue_pkt =
2919 * =====================
2920 *   
2921 * Overview:
2922 *   Queues packets for transmission
2923 *  
2924 * Returns:
2925 *   Condition code
2926 *       
2927 * Arguments:
2928 *   skb - pointer to sk_buff to queue for transmission
2929 *   dev - pointer to device information
2930 *
2931 * Functional Description:
2932 *   Here we assume that an incoming skb transmit request
2933 *   is contained in a single physically contiguous buffer
2934 *   in which the virtual address of the start of packet
2935 *   (skb->data) can be converted to a physical address
2936 *   by using virt_to_bus().
2937 *
2938 *   Since the adapter architecture requires a three byte
2939 *   packet request header to prepend the start of packet,
2940 *   we'll write the three byte field immediately prior to
2941 *   the FC byte.  This assumption is valid because we've
2942 *   ensured that dev->hard_header_len includes three pad
2943 *   bytes.  By posting a single fragment to the adapter,
2944 *   we'll reduce the number of descriptor fetches and
2945 *   bus traffic needed to send the request.
2946 *
2947 *   Also, we can't free the skb until after it's been DMA'd
2948 *   out by the adapter, so we'll queue it in the driver and
2949 *   return it in dfx_xmt_done.
2950 *
2951 * Return Codes:
2952 *   0 - driver queued packet, link is unavailable, or skbuff was bad
2953 *       1 - caller should requeue the sk_buff for later transmission
2954 *
2955 * Assumptions:
2956 *       First and foremost, we assume the incoming skb pointer
2957 *   is NOT NULL and is pointing to a valid sk_buff structure.
2958 *
2959 *   The outgoing packet is complete, starting with the
2960 *   frame control byte including the last byte of data,
2961 *   but NOT including the 4 byte CRC.  We'll let the
2962 *   adapter hardware generate and append the CRC.
2963 *
2964 *   The entire packet is stored in one physically
2965 *   contiguous buffer which is not cached and whose
2966 *   32-bit physical address can be determined.
2967 *
2968 *   It's vital that this routine is NOT reentered for the
2969 *   same board and that the OS is not in another section of
2970 *   code (eg. dfx_int_common) for the same board on a
2971 *   different thread.
2972 *
2973 * Side Effects:
2974 *   None
2975 */
2976
2977static int dfx_xmt_queue_pkt(
2978        struct sk_buff  *skb,
2979        struct net_device       *dev
2980        )
2981
2982        {
2983        DFX_board_t             *bp = dev->priv;
2984        u8                      prod;                           /* local transmit producer index */
2985        PI_XMT_DESCR            *p_xmt_descr;           /* ptr to transmit descriptor block entry */
2986        XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
2987        unsigned long           flags;
2988
2989        netif_stop_queue(dev);
2990        
2991        /*
2992         * Verify that incoming transmit request is OK
2993         *
2994         * Note: The packet size check is consistent with other
2995         *               Linux device drivers, although the correct packet
2996         *               size should be verified before calling the
2997         *               transmit routine.
2998         */
2999
3000        if (!IN_RANGE(skb->len, FDDI_K_LLC_ZLEN, FDDI_K_LLC_LEN))
3001        {
3002                printk("%s: Invalid packet length - %u bytes\n", 
3003                        dev->name, skb->len);
3004                bp->xmt_length_errors++;                /* bump error counter */
3005                netif_wake_queue(dev);
3006                dev_kfree_skb(skb);
3007                return(0);                              /* return "success" */
3008        }
3009        /*
3010         * See if adapter link is available, if not, free buffer
3011         *
3012         * Note: If the link isn't available, free buffer and return 0
3013         *               rather than tell the upper layer to requeue the packet.
3014         *               The methodology here is that by the time the link
3015         *               becomes available, the packet to be sent will be
3016         *               fairly stale.  By simply dropping the packet, the
3017         *               higher layer protocols will eventually time out
3018         *               waiting for response packets which it won't receive.
3019         */
3020
3021        if (bp->link_available == PI_K_FALSE)
3022                {
3023                if (dfx_hw_adap_state_rd(bp) == PI_STATE_K_LINK_AVAIL)  /* is link really available? */
3024                        bp->link_available = PI_K_TRUE;         /* if so, set flag and continue */
3025                else
3026                        {
3027                        bp->xmt_discards++;                                     /* bump error counter */
3028                        dev_kfree_skb(skb);             /* free sk_buff now */
3029                        netif_wake_queue(dev);
3030                        return(0);                                                      /* return "success" */
3031                        }
3032                }
3033
3034        spin_lock_irqsave(&bp->lock, flags);
3035        
3036        /* Get the current producer and the next free xmt data descriptor */
3037
3038        prod            = bp->rcv_xmt_reg.index.xmt_prod;
3039        p_xmt_descr = &(bp->descr_block_virt->xmt_data[prod]);
3040
3041        /*
3042         * Get pointer to auxiliary queue entry to contain information
3043         * for this packet.
3044         *
3045         * Note: The current xmt producer index will become the
3046         *       current xmt completion index when we complete this
3047         *       packet later on.  So, we'll get the pointer to the
3048         *       next auxiliary queue entry now before we bump the
3049         *       producer index.
3050         */
3051
3052        p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[prod++]);     /* also bump producer index */
3053
3054        /* Write the three PRH bytes immediately before the FC byte */
3055
3056        skb_push(skb,3);
3057        skb->data[0] = DFX_PRH0_BYTE;   /* these byte values are defined */
3058        skb->data[1] = DFX_PRH1_BYTE;   /* in the Motorola FDDI MAC chip */
3059        skb->data[2] = DFX_PRH2_BYTE;   /* specification */
3060
3061        /*
3062         * Write the descriptor with buffer info and bump producer
3063         *
3064         * Note: Since we need to start DMA from the packet request
3065         *               header, we'll add 3 bytes to the DMA buffer length,
3066         *               and we'll determine the physical address of the
3067         *               buffer from the PRH, not skb->data.
3068         *
3069         * Assumptions:
3070         *               1. Packet starts with the frame control (FC) byte
3071         *                  at skb->data.
3072         *               2. The 4-byte CRC is not appended to the buffer or
3073         *                      included in the length.
3074         *               3. Packet length (skb->len) is from FC to end of
3075         *                      data, inclusive.
3076         *               4. The packet length does not exceed the maximum
3077         *                      FDDI LLC frame length of 4491 bytes.
3078         *               5. The entire packet is contained in a physically
3079         *                      contiguous, non-cached, locked memory space
3080         *                      comprised of a single buffer pointed to by
3081         *                      skb->data.
3082         *               6. The physical address of the start of packet
3083         *                      can be determined from the virtual address
3084         *                      by using virt_to_bus() and is only 32-bits
3085         *                      wide.
3086         */
3087
3088        p_xmt_descr->long_0     = (u32) (PI_XMT_DESCR_M_SOP | PI_XMT_DESCR_M_EOP | ((skb->len) << PI_XMT_DESCR_V_SEG_LEN));
3089        p_xmt_descr->long_1 = (u32) virt_to_bus(skb->data);
3090
3091        /*
3092         * Verify that descriptor is actually available
3093         *
3094         * Note: If descriptor isn't available, return 1 which tells
3095         *       the upper layer to requeue the packet for later
3096         *       transmission.
3097         *
3098         *       We need to ensure that the producer never reaches the
3099         *       completion, except to indicate that the queue is empty.
3100         */
3101
3102        if (prod == bp->rcv_xmt_reg.index.xmt_comp)
3103        {
3104                skb_pull(skb,3);
3105                spin_unlock_irqrestore(&bp->lock, flags);
3106                return(1);                      /* requeue packet for later */
3107        }
3108
3109        /*
3110         * Save info for this packet for xmt done indication routine
3111         *
3112         * Normally, we'd save the producer index in the p_xmt_drv_descr
3113         * structure so that we'd have it handy when we complete this
3114         * packet later (in dfx_xmt_done).  However, since the current
3115         * transmit architecture guarantees a single fragment for the
3116         * entire packet, we can simply bump the completion index by
3117         * one (1) for each completed packet.
3118         *
3119         * Note: If this assumption changes and we're presented with
3120         *       an inconsistent number of transmit fragments for packet
3121         *       data, we'll need to modify this code to save the current
3122         *       transmit producer index.
3123         */
3124
3125        p_xmt_drv_descr->p_skb = skb;
3126
3127        /* Update Type 2 register */
3128
3129        bp->rcv_xmt_reg.index.xmt_prod = prod;
3130        dfx_port_write_long(bp, PI_PDQ_K_REG_TYPE_2_PROD, bp->rcv_xmt_reg.lword);
3131        spin_unlock_irqrestore(&bp->lock, flags);
3132        netif_wake_queue(dev);
3133        return(0);                                                      /* packet queued to adapter */
3134        }
3135
3136
3137/*
3138 * ================
3139 * = dfx_xmt_done =
3140 * ================
3141 *   
3142 * Overview:
3143 *   Processes all frames that have been transmitted.
3144 *  
3145 * Returns:
3146 *   None
3147 *       
3148 * Arguments:
3149 *   bp - pointer to board information
3150 *
3151 * Functional Description:
3152 *   For all consumed transmit descriptors that have not
3153 *   yet been completed, we'll free the skb we were holding
3154 *   onto using dev_kfree_skb and bump the appropriate
3155 *   counters.
3156 *
3157 * Return Codes:
3158 *   None
3159 *
3160 * Assumptions:
3161 *   The Type 2 register is not updated in this routine.  It is
3162 *   assumed that it will be updated in the ISR when dfx_xmt_done
3163 *   returns.
3164 *
3165 * Side Effects:
3166 *   None
3167 */
3168
3169static int dfx_xmt_done(DFX_board_t *bp)
3170        {
3171        XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
3172        PI_TYPE_2_CONSUMER      *p_type_2_cons;         /* ptr to rcv/xmt consumer block register */
3173        int                     freed = 0;              /* buffers freed */
3174
3175        /* Service all consumed transmit frames */
3176
3177        p_type_2_cons = (PI_TYPE_2_CONSUMER *)(&bp->cons_block_virt->xmt_rcv_data);
3178        while (bp->rcv_xmt_reg.index.xmt_comp != p_type_2_cons->index.xmt_cons)
3179                {
3180                /* Get pointer to the transmit driver descriptor block information */
3181
3182                p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3183
3184                /* Increment transmit counters */
3185
3186                bp->xmt_total_frames++;
3187                bp->xmt_total_bytes += p_xmt_drv_descr->p_skb->len;
3188
3189                /* Return skb to operating system */
3190
3191                dev_kfree_skb_irq(p_xmt_drv_descr->p_skb);
3192
3193                /*
3194                 * Move to start of next packet by updating completion index
3195                 *
3196                 * Here we assume that a transmit packet request is always
3197                 * serviced by posting one fragment.  We can therefore
3198                 * simplify the completion code by incrementing the
3199                 * completion index by one.  This code will need to be
3200                 * modified if this assumption changes.  See comments
3201                 * in dfx_xmt_queue_pkt for more details.
3202                 */
3203
3204                bp->rcv_xmt_reg.index.xmt_comp += 1;
3205                freed++;
3206                }
3207        return freed;
3208        }
3209
3210
3211/*
3212 * =================
3213 * = dfx_rcv_flush =
3214 * =================
3215 *   
3216 * Overview:
3217 *   Remove all skb's in the receive ring.
3218 *  
3219 * Returns:
3220 *   None
3221 *       
3222 * Arguments:
3223 *   bp - pointer to board information
3224 *
3225 * Functional Description:
3226 *   Free's all the dynamically allocated skb's that are
3227 *   currently attached to the device receive ring. This
3228 *   function is typically only used when the device is
3229 *   initialized or reinitialized.
3230 *
3231 * Return Codes:
3232 *   None
3233 *
3234 * Side Effects:
3235 *   None
3236 */
3237#ifdef DYNAMIC_BUFFERS
3238static void dfx_rcv_flush( DFX_board_t *bp )
3239        {
3240        int i, j;
3241
3242        for (i = 0; i < (int)(bp->rcv_bufs_to_post); i++)
3243                for (j = 0; (i + j) < (int)PI_RCV_DATA_K_NUM_ENTRIES; j += bp->rcv_bufs_to_post)
3244                {
3245                        struct sk_buff *skb;
3246                        skb = (struct sk_buff *)bp->p_rcv_buff_va[i+j];
3247                        if (skb)
3248                                dev_kfree_skb(skb);
3249                        bp->p_rcv_buff_va[i+j] = NULL;
3250                }
3251
3252        }
3253#else
3254static inline void dfx_rcv_flush( DFX_board_t *bp )
3255{
3256}
3257#endif /* DYNAMIC_BUFFERS */
3258
3259/*
3260 * =================
3261 * = dfx_xmt_flush =
3262 * =================
3263 *   
3264 * Overview:
3265 *   Processes all frames whether they've been transmitted
3266 *   or not.
3267 *  
3268 * Returns:
3269 *   None
3270 *       
3271 * Arguments:
3272 *   bp - pointer to board information
3273 *
3274 * Functional Description:
3275 *   For all produced transmit descriptors that have not
3276 *   yet been completed, we'll free the skb we were holding
3277 *   onto using dev_kfree_skb and bump the appropriate
3278 *   counters.  Of course, it's possible that some of
3279 *   these transmit requests actually did go out, but we
3280 *   won't make that distinction here.  Finally, we'll
3281 *   update the consumer index to match the producer.
3282 *
3283 * Return Codes:
3284 *   None
3285 *
3286 * Assumptions:
3287 *   This routine does NOT update the Type 2 register.  It
3288 *   is assumed that this routine is being called during a
3289 *   transmit flush interrupt, or a shutdown or close routine.
3290 *
3291 * Side Effects:
3292 *   None
3293 */
3294
3295static void dfx_xmt_flush( DFX_board_t *bp )
3296        {
3297        u32                     prod_cons;              /* rcv/xmt consumer block longword */
3298        XMT_DRIVER_DESCR        *p_xmt_drv_descr;       /* ptr to transmit driver descriptor */
3299
3300        /* Flush all outstanding transmit frames */
3301
3302        while (bp->rcv_xmt_reg.index.xmt_comp != bp->rcv_xmt_reg.index.xmt_prod)
3303                {
3304                /* Get pointer to the transmit driver descriptor block information */
3305
3306                p_xmt_drv_descr = &(bp->xmt_drv_descr_blk[bp->rcv_xmt_reg.index.xmt_comp]);
3307
3308                /* Return skb to operating system */
3309
3310                dev_kfree_skb(p_xmt_drv_descr->p_skb);
3311
3312                /* Increment transmit error counter */
3313
3314                bp->xmt_discards++;
3315
3316                /*
3317                 * Move to start of next packet by updating completion index
3318                 *
3319                 * Here we assume that a transmit packet request is always
3320                 * serviced by posting one fragment.  We can therefore
3321                 * simplify the completion code by incrementing the
3322                 * completion index by one.  This code will need to be
3323                 * modified if this assumption changes.  See comments
3324                 * in dfx_xmt_queue_pkt for more details.
3325                 */
3326
3327                bp->rcv_xmt_reg.index.xmt_comp += 1;
3328                }
3329
3330        /* Update the transmit consumer index in the consumer block */
3331
3332        prod_cons = (u32)(bp->cons_block_virt->xmt_rcv_data & ~PI_CONS_M_XMT_INDEX);
3333        prod_cons |= (u32)(bp->rcv_xmt_reg.index.xmt_prod << PI_CONS_V_XMT_INDEX);
3334        bp->cons_block_virt->xmt_rcv_data = prod_cons;
3335        }
3336
3337static void __devexit dfx_remove_one_pci_or_eisa(struct pci_dev *pdev, struct net_device *dev)
3338{
3339        DFX_board_t       *bp = dev->priv;
3340
3341        unregister_netdev(dev);
3342        release_region(dev->base_addr,  pdev ? PFI_K_CSR_IO_LEN : PI_ESIC_K_CSR_IO_LEN );
3343        if (bp->kmalloced) kfree(bp->kmalloced);
3344        kfree(dev);
3345}
3346
3347static void __devexit dfx_remove_one (struct pci_dev *pdev)
3348{
3349        struct net_device *dev = pci_get_drvdata(pdev);
3350
3351        dfx_remove_one_pci_or_eisa(pdev, dev);
3352        pci_set_drvdata(pdev, NULL);
3353}
3354
3355static struct pci_device_id dfx_pci_tbl[] __devinitdata = {
3356        { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_FDDI, PCI_ANY_ID, PCI_ANY_ID, },
3357        { 0, }
3358};
3359MODULE_DEVICE_TABLE(pci, dfx_pci_tbl);
3360
3361static struct pci_driver dfx_driver = {
3362        .name           = "defxx",
3363        .probe          = dfx_init_one,
3364        .remove         = __devexit_p(dfx_remove_one),
3365        .id_table       = dfx_pci_tbl,
3366};
3367
3368static int dfx_have_pci;
3369static int dfx_have_eisa;
3370
3371
3372static void __exit dfx_eisa_cleanup(void)
3373{
3374        struct net_device *dev = root_dfx_eisa_dev;
3375
3376        while (dev)
3377        {
3378                struct net_device *tmp;
3379                DFX_board_t *bp;
3380
3381                bp = (DFX_board_t*)dev->priv;
3382                tmp = bp->next;
3383                dfx_remove_one_pci_or_eisa(NULL, dev);
3384                dev = tmp;
3385        }
3386}
3387
3388static int __init dfx_init(void)
3389{
3390        int rc_pci, rc_eisa;
3391
3392/* when a module, this is printed whether or not devices are found in probe */
3393#ifdef MODULE
3394        printk(version);
3395#endif
3396
3397        rc_pci = pci_module_init(&dfx_driver);
3398        if (rc_pci >= 0) dfx_have_pci = 1;
3399        
3400        rc_eisa = dfx_eisa_init();
3401        if (rc_eisa >= 0) dfx_have_eisa = 1;
3402
3403        return ((rc_eisa < 0) ? 0 : rc_eisa)  + ((rc_pci < 0) ? 0 : rc_pci); 
3404}
3405
3406static void __exit dfx_cleanup(void)
3407{
3408        if (dfx_have_pci)
3409                pci_unregister_driver(&dfx_driver);
3410        if (dfx_have_eisa)
3411                dfx_eisa_cleanup();
3412                
3413}       
3414
3415module_init(dfx_init);
3416module_exit(dfx_cleanup);
3417MODULE_LICENSE("GPL");
3418
3419
3420/*
3421 * Local variables:
3422 * kernel-compile-command: "gcc -D__KERNEL__ -I/root/linux/include -Wall -Wstrict-prototypes -O2 -pipe -fomit-frame-pointer -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -c defxx.c"
3423 * End:
3424 */
3425
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.