linux/drivers/infiniband/hw/nes/nes.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2006 - 2011 Intel Corporation.  All rights reserved.
   3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
   4 *
   5 * This software is available to you under a choice of one of two
   6 * licenses.  You may choose to be licensed under the terms of the GNU
   7 * General Public License (GPL) Version 2, available from the file
   8 * COPYING in the main directory of this source tree, or the
   9 * OpenIB.org BSD license below:
  10 *
  11 *     Redistribution and use in source and binary forms, with or
  12 *     without modification, are permitted provided that the following
  13 *     conditions are met:
  14 *
  15 *      - Redistributions of source code must retain the above
  16 *        copyright notice, this list of conditions and the following
  17 *        disclaimer.
  18 *
  19 *      - Redistributions in binary form must reproduce the above
  20 *        copyright notice, this list of conditions and the following
  21 *        disclaimer in the documentation and/or other materials
  22 *        provided with the distribution.
  23 *
  24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31 * SOFTWARE.
  32 */
  33
  34#include <linux/module.h>
  35#include <linux/moduleparam.h>
  36#include <linux/netdevice.h>
  37#include <linux/etherdevice.h>
  38#include <linux/ethtool.h>
  39#include <linux/mii.h>
  40#include <linux/if_vlan.h>
  41#include <linux/crc32.h>
  42#include <linux/in.h>
  43#include <linux/fs.h>
  44#include <linux/init.h>
  45#include <linux/if_arp.h>
  46#include <linux/highmem.h>
  47#include <linux/slab.h>
  48#include <asm/io.h>
  49#include <asm/irq.h>
  50#include <asm/byteorder.h>
  51#include <rdma/ib_smi.h>
  52#include <rdma/ib_verbs.h>
  53#include <rdma/ib_pack.h>
  54#include <rdma/iw_cm.h>
  55
  56#include "nes.h"
  57
  58#include <net/netevent.h>
  59#include <net/neighbour.h>
  60#include <linux/route.h>
  61#include <net/ip_fib.h>
  62
  63MODULE_AUTHOR("NetEffect");
  64MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
  65MODULE_LICENSE("Dual BSD/GPL");
  66MODULE_VERSION(DRV_VERSION);
  67
  68int max_mtu = 9000;
  69int interrupt_mod_interval = 0;
  70
  71
  72/* Interoperability */
  73int mpa_version = 1;
  74module_param(mpa_version, int, 0644);
  75MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
  76
  77/* Interoperability */
  78int disable_mpa_crc = 0;
  79module_param(disable_mpa_crc, int, 0644);
  80MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
  81
  82unsigned int send_first = 0;
  83module_param(send_first, int, 0644);
  84MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
  85
  86
  87unsigned int nes_drv_opt = NES_DRV_OPT_DISABLE_INT_MOD | NES_DRV_OPT_ENABLE_PAU;
  88module_param(nes_drv_opt, int, 0644);
  89MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
  90
  91unsigned int nes_debug_level = 0;
  92module_param_named(debug_level, nes_debug_level, uint, 0644);
  93MODULE_PARM_DESC(debug_level, "Enable debug output level");
  94
  95unsigned int wqm_quanta = 0x10000;
  96module_param(wqm_quanta, int, 0644);
  97MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
  98
  99static bool limit_maxrdreqsz;
 100module_param(limit_maxrdreqsz, bool, 0644);
 101MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
 102
 103LIST_HEAD(nes_adapter_list);
 104static LIST_HEAD(nes_dev_list);
 105
 106atomic_t qps_destroyed;
 107
 108static unsigned int ee_flsh_adapter;
 109static unsigned int sysfs_nonidx_addr;
 110static unsigned int sysfs_idx_addr;
 111
 112static struct pci_device_id nes_pci_table[] = {
 113        { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020), },
 114        { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020_KR), },
 115        {0}
 116};
 117
 118MODULE_DEVICE_TABLE(pci, nes_pci_table);
 119
 120static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
 121static int nes_net_event(struct notifier_block *, unsigned long, void *);
 122static int nes_notifiers_registered;
 123
 124
 125static struct notifier_block nes_inetaddr_notifier = {
 126        .notifier_call = nes_inetaddr_event
 127};
 128
 129static struct notifier_block nes_net_notifier = {
 130        .notifier_call = nes_net_event
 131};
 132
 133/**
 134 * nes_inetaddr_event
 135 */
 136static int nes_inetaddr_event(struct notifier_block *notifier,
 137                unsigned long event, void *ptr)
 138{
 139        struct in_ifaddr *ifa = ptr;
 140        struct net_device *event_netdev = ifa->ifa_dev->dev;
 141        struct nes_device *nesdev;
 142        struct net_device *netdev;
 143        struct nes_vnic *nesvnic;
 144        unsigned int is_bonded;
 145
 146        nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
 147                  &ifa->ifa_address, &ifa->ifa_mask);
 148        list_for_each_entry(nesdev, &nes_dev_list, list) {
 149                nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
 150                                nesdev, nesdev->netdev[0]->name);
 151                netdev = nesdev->netdev[0];
 152                nesvnic = netdev_priv(netdev);
 153                is_bonded = netif_is_bond_slave(netdev) &&
 154                            (netdev->master == event_netdev);
 155                if ((netdev == event_netdev) || is_bonded) {
 156                        if (nesvnic->rdma_enabled == 0) {
 157                                nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
 158                                                " RDMA is not enabled.\n",
 159                                                netdev->name);
 160                                return NOTIFY_OK;
 161                        }
 162                        /* we have ifa->ifa_address/mask here if we need it */
 163                        switch (event) {
 164                                case NETDEV_DOWN:
 165                                        nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
 166                                        nes_write_indexed(nesdev,
 167                                                        NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
 168
 169                                        nes_manage_arp_cache(netdev, netdev->dev_addr,
 170                                                        ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
 171                                        nesvnic->local_ipaddr = 0;
 172                                        if (is_bonded)
 173                                                continue;
 174                                        else
 175                                                return NOTIFY_OK;
 176                                        break;
 177                                case NETDEV_UP:
 178                                        nes_debug(NES_DBG_NETDEV, "event:UP\n");
 179
 180                                        if (nesvnic->local_ipaddr != 0) {
 181                                                nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
 182                                                return NOTIFY_OK;
 183                                        }
 184                                        /* fall through */
 185                                case NETDEV_CHANGEADDR:
 186                                        /* Add the address to the IP table */
 187                                        if (netdev->master)
 188                                                nesvnic->local_ipaddr =
 189                                                        ((struct in_device *)netdev->master->ip_ptr)->ifa_list->ifa_address;
 190                                        else
 191                                                nesvnic->local_ipaddr = ifa->ifa_address;
 192
 193                                        nes_write_indexed(nesdev,
 194                                                        NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
 195                                                        ntohl(nesvnic->local_ipaddr));
 196                                        nes_manage_arp_cache(netdev, netdev->dev_addr,
 197                                                        ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
 198                                        if (is_bonded)
 199                                                continue;
 200                                        else
 201                                                return NOTIFY_OK;
 202                                        break;
 203                                default:
 204                                        break;
 205                        }
 206                }
 207        }
 208
 209        return NOTIFY_DONE;
 210}
 211
 212
 213/**
 214 * nes_net_event
 215 */
 216static int nes_net_event(struct notifier_block *notifier,
 217                unsigned long event, void *ptr)
 218{
 219        struct neighbour *neigh = ptr;
 220        struct nes_device *nesdev;
 221        struct net_device *netdev;
 222        struct nes_vnic *nesvnic;
 223
 224        switch (event) {
 225                case NETEVENT_NEIGH_UPDATE:
 226                        list_for_each_entry(nesdev, &nes_dev_list, list) {
 227                                /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
 228                                netdev = nesdev->netdev[0];
 229                                nesvnic = netdev_priv(netdev);
 230                                if (netdev == neigh->dev) {
 231                                        if (nesvnic->rdma_enabled == 0) {
 232                                                nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
 233                                                                netdev->name);
 234                                        } else {
 235                                                if (neigh->nud_state & NUD_VALID) {
 236                                                        nes_manage_arp_cache(neigh->dev, neigh->ha,
 237                                                                        ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
 238                                                } else {
 239                                                        nes_manage_arp_cache(neigh->dev, neigh->ha,
 240                                                                        ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
 241                                                }
 242                                        }
 243                                        return NOTIFY_OK;
 244                                }
 245                        }
 246                        break;
 247                default:
 248                        nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
 249                        break;
 250        }
 251
 252        return NOTIFY_DONE;
 253}
 254
 255
 256/**
 257 * nes_add_ref
 258 */
 259void nes_add_ref(struct ib_qp *ibqp)
 260{
 261        struct nes_qp *nesqp;
 262
 263        nesqp = to_nesqp(ibqp);
 264        nes_debug(NES_DBG_QP, "Bumping refcount for QP%u.  Pre-inc value = %u\n",
 265                        ibqp->qp_num, atomic_read(&nesqp->refcount));
 266        atomic_inc(&nesqp->refcount);
 267}
 268
 269static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
 270{
 271        unsigned long flags;
 272        struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
 273        struct nes_adapter *nesadapter = nesdev->nesadapter;
 274
 275        atomic_inc(&qps_destroyed);
 276
 277        /* Free the control structures */
 278
 279        if (nesqp->pbl_vbase) {
 280                pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
 281                                nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
 282                spin_lock_irqsave(&nesadapter->pbl_lock, flags);
 283                nesadapter->free_256pbl++;
 284                spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
 285                pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
 286                nesqp->pbl_vbase = NULL;
 287
 288        } else {
 289                pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
 290                                nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
 291        }
 292        nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
 293
 294        nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
 295        kfree(nesqp->allocated_buffer);
 296
 297}
 298
 299/**
 300 * nes_rem_ref
 301 */
 302void nes_rem_ref(struct ib_qp *ibqp)
 303{
 304        u64 u64temp;
 305        struct nes_qp *nesqp;
 306        struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
 307        struct nes_device *nesdev = nesvnic->nesdev;
 308        struct nes_hw_cqp_wqe *cqp_wqe;
 309        struct nes_cqp_request *cqp_request;
 310        u32 opcode;
 311
 312        nesqp = to_nesqp(ibqp);
 313
 314        if (atomic_read(&nesqp->refcount) == 0) {
 315                printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
 316                                __func__, ibqp->qp_num, nesqp->last_aeq);
 317                BUG();
 318        }
 319
 320        if (atomic_dec_and_test(&nesqp->refcount)) {
 321                if (nesqp->pau_mode)
 322                        nes_destroy_pau_qp(nesdev, nesqp);
 323
 324                /* Destroy the QP */
 325                cqp_request = nes_get_cqp_request(nesdev);
 326                if (cqp_request == NULL) {
 327                        nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
 328                        return;
 329                }
 330                cqp_request->waiting = 0;
 331                cqp_request->callback = 1;
 332                cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
 333                cqp_request->cqp_callback_pointer = nesqp;
 334                cqp_wqe = &cqp_request->cqp_wqe;
 335
 336                nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
 337                opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
 338
 339                if (nesqp->hte_added) {
 340                        opcode  |= NES_CQP_QP_DEL_HTE;
 341                        nesqp->hte_added = 0;
 342                }
 343                set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
 344                set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
 345                u64temp = (u64)nesqp->nesqp_context_pbase;
 346                set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
 347                nes_post_cqp_request(nesdev, cqp_request);
 348        }
 349}
 350
 351
 352/**
 353 * nes_get_qp
 354 */
 355struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
 356{
 357        struct nes_vnic *nesvnic = to_nesvnic(device);
 358        struct nes_device *nesdev = nesvnic->nesdev;
 359        struct nes_adapter *nesadapter = nesdev->nesadapter;
 360
 361        if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
 362                return NULL;
 363
 364        return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
 365}
 366
 367
 368/**
 369 * nes_print_macaddr
 370 */
 371static void nes_print_macaddr(struct net_device *netdev)
 372{
 373        nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
 374                  netdev->name, netdev->dev_addr, netdev->irq);
 375}
 376
 377/**
 378 * nes_interrupt - handle interrupts
 379 */
 380static irqreturn_t nes_interrupt(int irq, void *dev_id)
 381{
 382        struct nes_device *nesdev = (struct nes_device *)dev_id;
 383        int handled = 0;
 384        u32 int_mask;
 385        u32 int_req;
 386        u32 int_stat;
 387        u32 intf_int_stat;
 388        u32 timer_stat;
 389
 390        if (nesdev->msi_enabled) {
 391                /* No need to read the interrupt pending register if msi is enabled */
 392                handled = 1;
 393        } else {
 394                if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
 395                        /* Master interrupt enable provides synchronization for kicking off bottom half
 396                          when interrupt sharing is going on */
 397                        int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
 398                        if (int_mask & 0x80000000) {
 399                                /* Check interrupt status to see if this might be ours */
 400                                int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
 401                                int_req = nesdev->int_req;
 402                                if (int_stat&int_req) {
 403                                        /* if interesting CEQ or AEQ is pending, claim the interrupt */
 404                                        if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
 405                                                handled = 1;
 406                                        } else {
 407                                                if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
 408                                                        /* Timer might be running but might be for another function */
 409                                                        timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
 410                                                        if ((timer_stat & nesdev->timer_int_req) != 0) {
 411                                                                handled = 1;
 412                                                        }
 413                                                }
 414                                                if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
 415                                                                (handled == 0)) {
 416                                                        intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
 417                                                        if ((intf_int_stat & nesdev->intf_int_req) != 0) {
 418                                                                handled = 1;
 419                                                        }
 420                                                }
 421                                        }
 422                                        if (handled) {
 423                                                nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
 424                                                int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
 425                                                /* Save off the status to save an additional read */
 426                                                nesdev->int_stat = int_stat;
 427                                                nesdev->napi_isr_ran = 1;
 428                                        }
 429                                }
 430                        }
 431                } else {
 432                        handled = nes_read32(nesdev->regs+NES_INT_PENDING);
 433                }
 434        }
 435
 436        if (handled) {
 437
 438                if (nes_napi_isr(nesdev) == 0) {
 439                        tasklet_schedule(&nesdev->dpc_tasklet);
 440
 441                }
 442                return IRQ_HANDLED;
 443        } else {
 444                return IRQ_NONE;
 445        }
 446}
 447
 448
 449/**
 450 * nes_probe - Device initialization
 451 */
 452static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
 453{
 454        struct net_device *netdev = NULL;
 455        struct nes_device *nesdev = NULL;
 456        int ret = 0;
 457        void __iomem *mmio_regs = NULL;
 458        u8 hw_rev;
 459
 460        assert(pcidev != NULL);
 461        assert(ent != NULL);
 462
 463        printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
 464                        DRV_VERSION, pci_name(pcidev));
 465
 466        ret = pci_enable_device(pcidev);
 467        if (ret) {
 468                printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
 469                goto bail0;
 470        }
 471
 472        nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
 473                        (long unsigned int)pci_resource_start(pcidev, BAR_0),
 474                        (long unsigned int)pci_resource_len(pcidev, BAR_0));
 475        nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
 476                        (long unsigned int)pci_resource_start(pcidev, BAR_1),
 477                        (long unsigned int)pci_resource_len(pcidev, BAR_1));
 478
 479        /* Make sure PCI base addr are MMIO */
 480        if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
 481                        !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
 482                printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
 483                ret = -ENODEV;
 484                goto bail1;
 485        }
 486
 487        /* Reserve PCI I/O and memory resources */
 488        ret = pci_request_regions(pcidev, DRV_NAME);
 489        if (ret) {
 490                printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
 491                goto bail1;
 492        }
 493
 494        if ((sizeof(dma_addr_t) > 4)) {
 495                ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
 496                if (ret < 0) {
 497                        printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
 498                        goto bail2;
 499                }
 500                ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
 501                if (ret) {
 502                        printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
 503                        goto bail2;
 504                }
 505        } else {
 506                ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
 507                if (ret < 0) {
 508                        printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
 509                        goto bail2;
 510                }
 511                ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
 512                if (ret) {
 513                        printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
 514                        goto bail2;
 515                }
 516        }
 517
 518        pci_set_master(pcidev);
 519
 520        /* Allocate hardware structure */
 521        nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
 522        if (!nesdev) {
 523                printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
 524                ret = -ENOMEM;
 525                goto bail2;
 526        }
 527
 528        nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
 529        nesdev->pcidev = pcidev;
 530        pci_set_drvdata(pcidev, nesdev);
 531
 532        pci_read_config_byte(pcidev, 0x0008, &hw_rev);
 533        nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
 534
 535        spin_lock_init(&nesdev->indexed_regs_lock);
 536
 537        /* Remap the PCI registers in adapter BAR0 to kernel VA space */
 538        mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0),
 539                                    pci_resource_len(pcidev, BAR_0));
 540        if (mmio_regs == NULL) {
 541                printk(KERN_ERR PFX "Unable to remap BAR0\n");
 542                ret = -EIO;
 543                goto bail3;
 544        }
 545        nesdev->regs = mmio_regs;
 546        nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
 547
 548        /* Ensure interrupts are disabled */
 549        nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
 550
 551        if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
 552                if (!pci_enable_msi(nesdev->pcidev)) {
 553                        nesdev->msi_enabled = 1;
 554                        nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
 555                                        pci_name(pcidev));
 556                } else {
 557                        nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
 558                                        pci_name(pcidev));
 559                }
 560        } else {
 561                nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
 562                                pci_name(pcidev));
 563        }
 564
 565        nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
 566        nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
 567
 568        /* Init the adapter */
 569        nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
 570        if (!nesdev->nesadapter) {
 571                printk(KERN_ERR PFX "Unable to initialize adapter.\n");
 572                ret = -ENOMEM;
 573                goto bail5;
 574        }
 575        nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
 576        nesdev->nesadapter->wqm_quanta = wqm_quanta;
 577
 578        /* nesdev->base_doorbell_index =
 579                        nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
 580        nesdev->base_doorbell_index = 1;
 581        nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
 582        if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
 583                switch (PCI_FUNC(nesdev->pcidev->devfn) %
 584                        nesdev->nesadapter->port_count) {
 585                case 1:
 586                        nesdev->mac_index = 2;
 587                        break;
 588                case 2:
 589                        nesdev->mac_index = 1;
 590                        break;
 591                case 3:
 592                        nesdev->mac_index = 3;
 593                        break;
 594                case 0:
 595                default:
 596                        nesdev->mac_index = 0;
 597                }
 598        } else {
 599                nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
 600                                                nesdev->nesadapter->port_count;
 601        }
 602
 603        if ((limit_maxrdreqsz ||
 604             ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
 605              (hw_rev == NE020_REV1))) &&
 606            (pcie_get_readrq(pcidev) > 256)) {
 607                if (pcie_set_readrq(pcidev, 256))
 608                        printk(KERN_ERR PFX "Unable to set max read request"
 609                                " to 256 bytes\n");
 610                else
 611                        nes_debug(NES_DBG_INIT, "Max read request size set"
 612                                " to 256 bytes\n");
 613        }
 614
 615        tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
 616
 617        /* bring up the Control QP */
 618        if (nes_init_cqp(nesdev)) {
 619                ret = -ENODEV;
 620                goto bail6;
 621        }
 622
 623        /* Arm the CCQ */
 624        nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
 625                        PCI_FUNC(nesdev->pcidev->devfn));
 626        nes_read32(nesdev->regs+NES_CQE_ALLOC);
 627
 628        /* Enable the interrupts */
 629        nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
 630                        (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
 631        if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
 632                nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
 633        }
 634
 635        /* TODO: This really should be the first driver to load, not function 0 */
 636        if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
 637                /* pick up PCI and critical errors if the first driver to load */
 638                nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
 639                nesdev->int_req |= NES_INT_INTF;
 640        } else {
 641                nesdev->intf_int_req = 0;
 642        }
 643        nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
 644        nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
 645        nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
 646        nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
 647        nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
 648
 649        nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
 650
 651        /* deal with both periodic and one_shot */
 652        nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
 653        nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
 654        nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
 655                        PCI_FUNC(nesdev->pcidev->devfn),
 656                        nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
 657
 658        nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
 659
 660        list_add_tail(&nesdev->list, &nes_dev_list);
 661
 662        /* Request an interrupt line for the driver */
 663        ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
 664        if (ret) {
 665                printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
 666                                pci_name(pcidev), pcidev->irq);
 667                goto bail65;
 668        }
 669
 670        nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
 671
 672        if (nes_notifiers_registered == 0) {
 673                register_inetaddr_notifier(&nes_inetaddr_notifier);
 674                register_netevent_notifier(&nes_net_notifier);
 675        }
 676        nes_notifiers_registered++;
 677
 678        INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
 679
 680        /* Initialize network devices */
 681        if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL)
 682                goto bail7;
 683
 684        /* Register network device */
 685        ret = register_netdev(netdev);
 686        if (ret) {
 687                printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
 688                nes_netdev_destroy(netdev);
 689                goto bail7;
 690        }
 691
 692        nes_print_macaddr(netdev);
 693
 694        nesdev->netdev_count++;
 695        nesdev->nesadapter->netdev_count++;
 696
 697        printk(KERN_INFO PFX "%s: NetEffect RNIC driver successfully loaded.\n",
 698                        pci_name(pcidev));
 699        return 0;
 700
 701        bail7:
 702        printk(KERN_ERR PFX "bail7\n");
 703        while (nesdev->netdev_count > 0) {
 704                nesdev->netdev_count--;
 705                nesdev->nesadapter->netdev_count--;
 706
 707                unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
 708                nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
 709        }
 710
 711        nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
 712                        nesdev->netdev_count, nesdev->nesadapter->netdev_count);
 713
 714        nes_notifiers_registered--;
 715        if (nes_notifiers_registered == 0) {
 716                unregister_netevent_notifier(&nes_net_notifier);
 717                unregister_inetaddr_notifier(&nes_inetaddr_notifier);
 718        }
 719
 720        list_del(&nesdev->list);
 721        nes_destroy_cqp(nesdev);
 722
 723        bail65:
 724        printk(KERN_ERR PFX "bail65\n");
 725        free_irq(pcidev->irq, nesdev);
 726        if (nesdev->msi_enabled) {
 727                pci_disable_msi(pcidev);
 728        }
 729        bail6:
 730        printk(KERN_ERR PFX "bail6\n");
 731        tasklet_kill(&nesdev->dpc_tasklet);
 732        /* Deallocate the Adapter Structure */
 733        nes_destroy_adapter(nesdev->nesadapter);
 734
 735        bail5:
 736        printk(KERN_ERR PFX "bail5\n");
 737        iounmap(nesdev->regs);
 738
 739        bail3:
 740        printk(KERN_ERR PFX "bail3\n");
 741        kfree(nesdev);
 742
 743        bail2:
 744        pci_release_regions(pcidev);
 745
 746        bail1:
 747        pci_disable_device(pcidev);
 748
 749        bail0:
 750        return ret;
 751}
 752
 753
 754/**
 755 * nes_remove - unload from kernel
 756 */
 757static void __devexit nes_remove(struct pci_dev *pcidev)
 758{
 759        struct nes_device *nesdev = pci_get_drvdata(pcidev);
 760        struct net_device *netdev;
 761        int netdev_index = 0;
 762        unsigned long flags;
 763
 764                if (nesdev->netdev_count) {
 765                        netdev = nesdev->netdev[netdev_index];
 766                        if (netdev) {
 767                                netif_stop_queue(netdev);
 768                                unregister_netdev(netdev);
 769                                nes_netdev_destroy(netdev);
 770
 771                                nesdev->netdev[netdev_index] = NULL;
 772                                nesdev->netdev_count--;
 773                                nesdev->nesadapter->netdev_count--;
 774                        }
 775                }
 776
 777        nes_notifiers_registered--;
 778        if (nes_notifiers_registered == 0) {
 779                unregister_netevent_notifier(&nes_net_notifier);
 780                unregister_inetaddr_notifier(&nes_inetaddr_notifier);
 781        }
 782
 783        list_del(&nesdev->list);
 784        nes_destroy_cqp(nesdev);
 785
 786        free_irq(pcidev->irq, nesdev);
 787        tasklet_kill(&nesdev->dpc_tasklet);
 788
 789        spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
 790        if (nesdev->link_recheck) {
 791                spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
 792                cancel_delayed_work_sync(&nesdev->work);
 793        } else {
 794                spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
 795        }
 796
 797        /* Deallocate the Adapter Structure */
 798        nes_destroy_adapter(nesdev->nesadapter);
 799
 800        if (nesdev->msi_enabled) {
 801                pci_disable_msi(pcidev);
 802        }
 803
 804        iounmap(nesdev->regs);
 805        kfree(nesdev);
 806
 807        /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
 808        pci_release_regions(pcidev);
 809        pci_disable_device(pcidev);
 810        pci_set_drvdata(pcidev, NULL);
 811}
 812
 813
 814static struct pci_driver nes_pci_driver = {
 815        .name = DRV_NAME,
 816        .id_table = nes_pci_table,
 817        .probe = nes_probe,
 818        .remove = __devexit_p(nes_remove),
 819};
 820
 821static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
 822{
 823        unsigned int  devfn = 0xffffffff;
 824        unsigned char bus_number = 0xff;
 825        unsigned int  i = 0;
 826        struct nes_device *nesdev;
 827
 828        list_for_each_entry(nesdev, &nes_dev_list, list) {
 829                if (i == ee_flsh_adapter) {
 830                        devfn = nesdev->pcidev->devfn;
 831                        bus_number = nesdev->pcidev->bus->number;
 832                        break;
 833                }
 834                i++;
 835        }
 836
 837        return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
 838}
 839
 840static ssize_t nes_store_adapter(struct device_driver *ddp,
 841        const char *buf, size_t count)
 842{
 843        char *p = (char *)buf;
 844
 845        ee_flsh_adapter = simple_strtoul(p, &p, 10);
 846        return strnlen(buf, count);
 847}
 848
 849static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
 850{
 851        u32 eeprom_cmd = 0xdead;
 852        u32 i = 0;
 853        struct nes_device *nesdev;
 854
 855        list_for_each_entry(nesdev, &nes_dev_list, list) {
 856                if (i == ee_flsh_adapter) {
 857                        eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
 858                        break;
 859                }
 860                i++;
 861        }
 862        return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
 863}
 864
 865static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
 866        const char *buf, size_t count)
 867{
 868        char *p = (char *)buf;
 869        u32 val;
 870        u32 i = 0;
 871        struct nes_device *nesdev;
 872
 873        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
 874                val = simple_strtoul(p, &p, 16);
 875                list_for_each_entry(nesdev, &nes_dev_list, list) {
 876                        if (i == ee_flsh_adapter) {
 877                                nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
 878                                break;
 879                        }
 880                        i++;
 881                }
 882        }
 883        return strnlen(buf, count);
 884}
 885
 886static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
 887{
 888        u32 eeprom_data = 0xdead;
 889        u32 i = 0;
 890        struct nes_device *nesdev;
 891
 892        list_for_each_entry(nesdev, &nes_dev_list, list) {
 893                if (i == ee_flsh_adapter) {
 894                        eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
 895                        break;
 896                }
 897                i++;
 898        }
 899
 900        return  snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
 901}
 902
 903static ssize_t nes_store_ee_data(struct device_driver *ddp,
 904        const char *buf, size_t count)
 905{
 906        char *p = (char *)buf;
 907        u32 val;
 908        u32 i = 0;
 909        struct nes_device *nesdev;
 910
 911        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
 912                val = simple_strtoul(p, &p, 16);
 913                list_for_each_entry(nesdev, &nes_dev_list, list) {
 914                        if (i == ee_flsh_adapter) {
 915                                nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
 916                                break;
 917                        }
 918                        i++;
 919                }
 920        }
 921        return strnlen(buf, count);
 922}
 923
 924static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
 925{
 926        u32 flash_cmd = 0xdead;
 927        u32 i = 0;
 928        struct nes_device *nesdev;
 929
 930        list_for_each_entry(nesdev, &nes_dev_list, list) {
 931                if (i == ee_flsh_adapter) {
 932                        flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
 933                        break;
 934                }
 935                i++;
 936        }
 937
 938        return  snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
 939}
 940
 941static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
 942        const char *buf, size_t count)
 943{
 944        char *p = (char *)buf;
 945        u32 val;
 946        u32 i = 0;
 947        struct nes_device *nesdev;
 948
 949        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
 950                val = simple_strtoul(p, &p, 16);
 951                list_for_each_entry(nesdev, &nes_dev_list, list) {
 952                        if (i == ee_flsh_adapter) {
 953                                nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
 954                                break;
 955                        }
 956                        i++;
 957                }
 958        }
 959        return strnlen(buf, count);
 960}
 961
 962static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
 963{
 964        u32 flash_data = 0xdead;
 965        u32 i = 0;
 966        struct nes_device *nesdev;
 967
 968        list_for_each_entry(nesdev, &nes_dev_list, list) {
 969                if (i == ee_flsh_adapter) {
 970                        flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
 971                        break;
 972                }
 973                i++;
 974        }
 975
 976        return  snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
 977}
 978
 979static ssize_t nes_store_flash_data(struct device_driver *ddp,
 980        const char *buf, size_t count)
 981{
 982        char *p = (char *)buf;
 983        u32 val;
 984        u32 i = 0;
 985        struct nes_device *nesdev;
 986
 987        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
 988                val = simple_strtoul(p, &p, 16);
 989                list_for_each_entry(nesdev, &nes_dev_list, list) {
 990                        if (i == ee_flsh_adapter) {
 991                                nes_write32(nesdev->regs + NES_FLASH_DATA, val);
 992                                break;
 993                        }
 994                        i++;
 995                }
 996        }
 997        return strnlen(buf, count);
 998}
 999
1000static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
1001{
1002        return  snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
1003}
1004
1005static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
1006        const char *buf, size_t count)
1007{
1008        char *p = (char *)buf;
1009
1010        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1011                sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
1012
1013        return strnlen(buf, count);
1014}
1015
1016static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
1017{
1018        u32 nonidx_data = 0xdead;
1019        u32 i = 0;
1020        struct nes_device *nesdev;
1021
1022        list_for_each_entry(nesdev, &nes_dev_list, list) {
1023                if (i == ee_flsh_adapter) {
1024                        nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
1025                        break;
1026                }
1027                i++;
1028        }
1029
1030        return  snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
1031}
1032
1033static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
1034        const char *buf, size_t count)
1035{
1036        char *p = (char *)buf;
1037        u32 val;
1038        u32 i = 0;
1039        struct nes_device *nesdev;
1040
1041        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1042                val = simple_strtoul(p, &p, 16);
1043                list_for_each_entry(nesdev, &nes_dev_list, list) {
1044                        if (i == ee_flsh_adapter) {
1045                                nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1046                                break;
1047                        }
1048                        i++;
1049                }
1050        }
1051        return strnlen(buf, count);
1052}
1053
1054static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
1055{
1056        return  snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1057}
1058
1059static ssize_t nes_store_idx_addr(struct device_driver *ddp,
1060        const char *buf, size_t count)
1061{
1062        char *p = (char *)buf;
1063
1064        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1065                sysfs_idx_addr = simple_strtoul(p, &p, 16);
1066
1067        return strnlen(buf, count);
1068}
1069
1070static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
1071{
1072        u32 idx_data = 0xdead;
1073        u32 i = 0;
1074        struct nes_device *nesdev;
1075
1076        list_for_each_entry(nesdev, &nes_dev_list, list) {
1077                if (i == ee_flsh_adapter) {
1078                        idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1079                        break;
1080                }
1081                i++;
1082        }
1083
1084        return  snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1085}
1086
1087static ssize_t nes_store_idx_data(struct device_driver *ddp,
1088        const char *buf, size_t count)
1089{
1090        char *p = (char *)buf;
1091        u32 val;
1092        u32 i = 0;
1093        struct nes_device *nesdev;
1094
1095        if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1096                val = simple_strtoul(p, &p, 16);
1097                list_for_each_entry(nesdev, &nes_dev_list, list) {
1098                        if (i == ee_flsh_adapter) {
1099                                nes_write_indexed(nesdev, sysfs_idx_addr, val);
1100                                break;
1101                        }
1102                        i++;
1103                }
1104        }
1105        return strnlen(buf, count);
1106}
1107
1108
1109/**
1110 * nes_show_wqm_quanta
1111 */
1112static ssize_t nes_show_wqm_quanta(struct device_driver *ddp, char *buf)
1113{
1114        u32 wqm_quanta_value = 0xdead;
1115        u32 i = 0;
1116        struct nes_device *nesdev;
1117
1118        list_for_each_entry(nesdev, &nes_dev_list, list) {
1119                if (i == ee_flsh_adapter) {
1120                        wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
1121                        break;
1122                }
1123                i++;
1124        }
1125
1126        return  snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta_value);
1127}
1128
1129
1130/**
1131 * nes_store_wqm_quanta
1132 */
1133static ssize_t nes_store_wqm_quanta(struct device_driver *ddp,
1134                                        const char *buf, size_t count)
1135{
1136        unsigned long wqm_quanta_value;
1137        u32 wqm_config1;
1138        u32 i = 0;
1139        struct nes_device *nesdev;
1140
1141        if (kstrtoul(buf, 0, &wqm_quanta_value) < 0)
1142                return -EINVAL;
1143
1144        list_for_each_entry(nesdev, &nes_dev_list, list) {
1145                if (i == ee_flsh_adapter) {
1146                        nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1147                        wqm_config1 = nes_read_indexed(nesdev,
1148                                                NES_IDX_WQM_CONFIG1);
1149                        nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1150                                        ((wqm_quanta_value << 1) |
1151                                        (wqm_config1 & 0x00000001)));
1152                        break;
1153                }
1154                i++;
1155        }
1156        return strnlen(buf, count);
1157}
1158
1159static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
1160                   nes_show_adapter, nes_store_adapter);
1161static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
1162                   nes_show_ee_cmd, nes_store_ee_cmd);
1163static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
1164                   nes_show_ee_data, nes_store_ee_data);
1165static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
1166                   nes_show_flash_cmd, nes_store_flash_cmd);
1167static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
1168                   nes_show_flash_data, nes_store_flash_data);
1169static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
1170                   nes_show_nonidx_addr, nes_store_nonidx_addr);
1171static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
1172                   nes_show_nonidx_data, nes_store_nonidx_data);
1173static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
1174                   nes_show_idx_addr, nes_store_idx_addr);
1175static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
1176                   nes_show_idx_data, nes_store_idx_data);
1177static DRIVER_ATTR(wqm_quanta, S_IRUSR | S_IWUSR,
1178                   nes_show_wqm_quanta, nes_store_wqm_quanta);
1179
1180static int nes_create_driver_sysfs(struct pci_driver *drv)
1181{
1182        int error;
1183        error  = driver_create_file(&drv->driver, &driver_attr_adapter);
1184        error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
1185        error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
1186        error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
1187        error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
1188        error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
1189        error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
1190        error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
1191        error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
1192        error |= driver_create_file(&drv->driver, &driver_attr_wqm_quanta);
1193        return error;
1194}
1195
1196static void nes_remove_driver_sysfs(struct pci_driver *drv)
1197{
1198        driver_remove_file(&drv->driver, &driver_attr_adapter);
1199        driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
1200        driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
1201        driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
1202        driver_remove_file(&drv->driver, &driver_attr_flash_data);
1203        driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
1204        driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
1205        driver_remove_file(&drv->driver, &driver_attr_idx_addr);
1206        driver_remove_file(&drv->driver, &driver_attr_idx_data);
1207        driver_remove_file(&drv->driver, &driver_attr_wqm_quanta);
1208}
1209
1210/**
1211 * nes_init_module - module initialization entry point
1212 */
1213static int __init nes_init_module(void)
1214{
1215        int retval;
1216        int retval1;
1217
1218        retval = nes_cm_start();
1219        if (retval) {
1220                printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1221                return retval;
1222        }
1223        retval = pci_register_driver(&nes_pci_driver);
1224        if (retval >= 0) {
1225                retval1 = nes_create_driver_sysfs(&nes_pci_driver);
1226                if (retval1 < 0)
1227                        printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
1228        }
1229        return retval;
1230}
1231
1232
1233/**
1234 * nes_exit_module - module unload entry point
1235 */
1236static void __exit nes_exit_module(void)
1237{
1238        nes_cm_stop();
1239        nes_remove_driver_sysfs(&nes_pci_driver);
1240
1241        pci_unregister_driver(&nes_pci_driver);
1242}
1243
1244
1245module_init(nes_init_module);
1246module_exit(nes_exit_module);
1247