PageRenderTime 204ms CodeModel.GetById 60ms app.highlight 118ms RepoModel.GetById 13ms app.codeStats 1ms

/drivers/infiniband/hw/nes/nes.c

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