2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
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>
44 #include <linux/init.h>
45 #include <linux/if_arp.h>
46 #include <linux/highmem.h>
49 #include <asm/byteorder.h>
50 #include <rdma/ib_smi.h>
51 #include <rdma/ib_verbs.h>
52 #include <rdma/ib_pack.h>
53 #include <rdma/iw_cm.h>
57 #include <net/netevent.h>
58 #include <net/neighbour.h>
59 #include <linux/route.h>
60 #include <net/ip_fib.h>
62 MODULE_AUTHOR("NetEffect");
63 MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
64 MODULE_LICENSE("Dual BSD/GPL");
65 MODULE_VERSION(DRV_VERSION);
68 int interrupt_mod_interval = 0;
71 /* Interoperability */
73 module_param(mpa_version, int, 0);
74 MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
76 /* Interoperability */
77 int disable_mpa_crc = 0;
78 module_param(disable_mpa_crc, int, 0);
79 MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
81 unsigned int send_first = 0;
82 module_param(send_first, int, 0);
83 MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
86 unsigned int nes_drv_opt = 0;
87 module_param(nes_drv_opt, int, 0);
88 MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
90 unsigned int nes_debug_level = 0;
91 module_param_named(debug_level, nes_debug_level, uint, 0644);
92 MODULE_PARM_DESC(debug_level, "Enable debug output level");
94 LIST_HEAD(nes_adapter_list);
95 static LIST_HEAD(nes_dev_list);
97 atomic_t qps_destroyed;
99 static void nes_print_macaddr(struct net_device *netdev);
100 static irqreturn_t nes_interrupt(int, void *);
101 static int __devinit nes_probe(struct pci_dev *, const struct pci_device_id *);
102 static void __devexit nes_remove(struct pci_dev *);
103 static int __init nes_init_module(void);
104 static void __exit nes_exit_module(void);
105 static unsigned int ee_flsh_adapter;
106 static unsigned int sysfs_nonidx_addr;
107 static unsigned int sysfs_idx_addr;
109 static struct pci_device_id nes_pci_table[] = {
110 {PCI_VENDOR_ID_NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020, PCI_ANY_ID, PCI_ANY_ID},
114 MODULE_DEVICE_TABLE(pci, nes_pci_table);
116 static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
117 static int nes_net_event(struct notifier_block *, unsigned long, void *);
118 static int nes_notifiers_registered;
121 static struct notifier_block nes_inetaddr_notifier = {
122 .notifier_call = nes_inetaddr_event
125 static struct notifier_block nes_net_notifier = {
126 .notifier_call = nes_net_event
135 static int nes_inetaddr_event(struct notifier_block *notifier,
136 unsigned long event, void *ptr)
138 struct in_ifaddr *ifa = ptr;
139 struct net_device *event_netdev = ifa->ifa_dev->dev;
140 struct nes_device *nesdev;
141 struct net_device *netdev;
142 struct nes_vnic *nesvnic;
146 addr = ntohl(ifa->ifa_address);
147 mask = ntohl(ifa->ifa_mask);
148 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %08X, netmask %08X.\n",
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",
162 /* we have ifa->ifa_address/mask here if we need it */
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);
169 nes_manage_arp_cache(netdev, netdev->dev_addr,
170 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
171 nesvnic->local_ipaddr = 0;
175 nes_debug(NES_DBG_NETDEV, "event:UP\n");
177 if (nesvnic->local_ipaddr != 0) {
178 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
181 /* Add the address to the IP table */
182 nesvnic->local_ipaddr = ifa->ifa_address;
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);
204 static int nes_net_event(struct notifier_block *notifier,
205 unsigned long event, void *ptr)
207 struct neighbour *neigh = ptr;
208 struct nes_device *nesdev;
209 struct net_device *netdev;
210 struct nes_vnic *nesvnic;
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",
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);
227 nes_manage_arp_cache(neigh->dev, neigh->ha,
228 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
236 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
247 void nes_add_ref(struct ib_qp *ibqp)
249 struct nes_qp *nesqp;
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);
257 static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
260 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
261 struct nes_adapter *nesadapter = nesdev->nesadapter;
264 atomic_inc(&qps_destroyed);
266 /* Free the control structures */
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;
279 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
280 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
282 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
284 kfree(nesqp->allocated_buffer);
291 void nes_rem_ref(struct ib_qp *ibqp)
294 struct nes_qp *nesqp;
295 struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
296 struct nes_device *nesdev = nesvnic->nesdev;
297 struct nes_adapter *nesadapter = nesdev->nesadapter;
298 struct nes_hw_cqp_wqe *cqp_wqe;
299 struct nes_cqp_request *cqp_request;
302 nesqp = to_nesqp(ibqp);
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);
310 if (atomic_dec_and_test(&nesqp->refcount)) {
311 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
314 cqp_request = nes_get_cqp_request(nesdev);
315 if (cqp_request == NULL) {
316 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
319 cqp_request->waiting = 0;
320 cqp_request->callback = 1;
321 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
322 cqp_request->cqp_callback_pointer = nesqp;
323 cqp_wqe = &cqp_request->cqp_wqe;
325 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
326 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
328 if (nesqp->hte_added) {
329 opcode |= NES_CQP_QP_DEL_HTE;
330 nesqp->hte_added = 0;
332 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
333 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
334 u64temp = (u64)nesqp->nesqp_context_pbase;
335 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
336 nes_post_cqp_request(nesdev, cqp_request, NES_CQP_REQUEST_RING_DOORBELL);
344 struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
346 struct nes_vnic *nesvnic = to_nesvnic(device);
347 struct nes_device *nesdev = nesvnic->nesdev;
348 struct nes_adapter *nesadapter = nesdev->nesadapter;
350 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
353 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
360 static void nes_print_macaddr(struct net_device *netdev)
362 nes_debug(NES_DBG_INIT, "%s: MAC %02X:%02X:%02X:%02X:%02X:%02X, IRQ %u\n",
364 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
365 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5],
371 * nes_interrupt - handle interrupts
373 static irqreturn_t nes_interrupt(int irq, void *dev_id)
375 struct nes_device *nesdev = (struct nes_device *)dev_id;
383 if (nesdev->msi_enabled) {
384 /* No need to read the interrupt pending register if msi is enabled */
387 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
388 /* Master interrupt enable provides synchronization for kicking off bottom half
389 when interrupt sharing is going on */
390 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
391 if (int_mask & 0x80000000) {
392 /* Check interrupt status to see if this might be ours */
393 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
394 int_req = nesdev->int_req;
395 if (int_stat&int_req) {
396 /* if interesting CEQ or AEQ is pending, claim the interrupt */
397 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
400 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
401 /* Timer might be running but might be for another function */
402 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
403 if ((timer_stat & nesdev->timer_int_req) != 0) {
407 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
409 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
410 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
416 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
417 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
418 /* Save off the status to save an additional read */
419 nesdev->int_stat = int_stat;
420 nesdev->napi_isr_ran = 1;
425 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
431 if (nes_napi_isr(nesdev) == 0) {
432 tasklet_schedule(&nesdev->dpc_tasklet);
443 * nes_probe - Device initialization
445 static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
447 struct net_device *netdev = NULL;
448 struct nes_device *nesdev = NULL;
450 struct nes_vnic *nesvnic = NULL;
451 void __iomem *mmio_regs = NULL;
454 assert(pcidev != NULL);
457 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
458 DRV_VERSION, pci_name(pcidev));
460 ret = pci_enable_device(pcidev);
462 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
466 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
467 (long unsigned int)pci_resource_start(pcidev, BAR_0),
468 (long unsigned int)pci_resource_len(pcidev, BAR_0));
469 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
470 (long unsigned int)pci_resource_start(pcidev, BAR_1),
471 (long unsigned int)pci_resource_len(pcidev, BAR_1));
473 /* Make sure PCI base addr are MMIO */
474 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
475 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
476 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
481 /* Reserve PCI I/O and memory resources */
482 ret = pci_request_regions(pcidev, DRV_NAME);
484 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
488 if ((sizeof(dma_addr_t) > 4)) {
489 ret = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
491 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
494 ret = pci_set_consistent_dma_mask(pcidev, DMA_64BIT_MASK);
496 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
500 ret = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
502 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
505 ret = pci_set_consistent_dma_mask(pcidev, DMA_32BIT_MASK);
507 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
512 pci_set_master(pcidev);
514 /* Allocate hardware structure */
515 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
517 printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
522 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
523 nesdev->pcidev = pcidev;
524 pci_set_drvdata(pcidev, nesdev);
526 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
527 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
529 spin_lock_init(&nesdev->indexed_regs_lock);
531 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
532 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0), sizeof(mmio_regs));
533 if (mmio_regs == NULL) {
534 printk(KERN_ERR PFX "Unable to remap BAR0\n");
538 nesdev->regs = mmio_regs;
539 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
541 /* Ensure interrupts are disabled */
542 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
544 if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
545 if (!pci_enable_msi(nesdev->pcidev)) {
546 nesdev->msi_enabled = 1;
547 nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
550 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
554 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
558 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
559 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
561 /* Init the adapter */
562 nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
563 if (!nesdev->nesadapter) {
564 printk(KERN_ERR PFX "Unable to initialize adapter.\n");
568 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
570 /* nesdev->base_doorbell_index =
571 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
572 nesdev->base_doorbell_index = 1;
573 nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
574 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) % nesdev->nesadapter->port_count;
576 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
578 /* bring up the Control QP */
579 if (nes_init_cqp(nesdev)) {
585 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
586 PCI_FUNC(nesdev->pcidev->devfn));
587 nes_read32(nesdev->regs+NES_CQE_ALLOC);
589 /* Enable the interrupts */
590 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
591 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
592 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
593 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+24));
596 /* TODO: This really should be the first driver to load, not function 0 */
597 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
598 /* pick up PCI and critical errors if the first driver to load */
599 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
600 nesdev->int_req |= NES_INT_INTF;
602 nesdev->intf_int_req = 0;
604 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
605 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
606 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
607 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
608 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
610 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
612 /* deal with both periodic and one_shot */
613 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
614 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
615 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
616 PCI_FUNC(nesdev->pcidev->devfn),
617 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
619 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
621 list_add_tail(&nesdev->list, &nes_dev_list);
623 /* Request an interrupt line for the driver */
624 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
626 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
627 pci_name(pcidev), pcidev->irq);
631 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
633 if (nes_notifiers_registered == 0) {
634 register_inetaddr_notifier(&nes_inetaddr_notifier);
635 register_netevent_notifier(&nes_net_notifier);
637 nes_notifiers_registered++;
639 /* Initialize network devices */
640 if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL) {
644 /* Register network device */
645 ret = register_netdev(netdev);
647 printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
648 nes_netdev_destroy(netdev);
652 nes_print_macaddr(netdev);
653 /* create a CM core for this netdev */
654 nesvnic = netdev_priv(netdev);
656 nesdev->netdev_count++;
657 nesdev->nesadapter->netdev_count++;
660 printk(KERN_ERR PFX "%s: NetEffect RNIC driver successfully loaded.\n",
665 printk(KERN_ERR PFX "bail7\n");
666 while (nesdev->netdev_count > 0) {
667 nesdev->netdev_count--;
668 nesdev->nesadapter->netdev_count--;
670 unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
671 nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
674 nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
675 nesdev->netdev_count, nesdev->nesadapter->netdev_count);
677 nes_notifiers_registered--;
678 if (nes_notifiers_registered == 0) {
679 unregister_netevent_notifier(&nes_net_notifier);
680 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
683 list_del(&nesdev->list);
684 nes_destroy_cqp(nesdev);
687 printk(KERN_ERR PFX "bail65\n");
688 free_irq(pcidev->irq, nesdev);
689 if (nesdev->msi_enabled) {
690 pci_disable_msi(pcidev);
693 printk(KERN_ERR PFX "bail6\n");
694 tasklet_kill(&nesdev->dpc_tasklet);
695 /* Deallocate the Adapter Structure */
696 nes_destroy_adapter(nesdev->nesadapter);
699 printk(KERN_ERR PFX "bail5\n");
700 iounmap(nesdev->regs);
703 printk(KERN_ERR PFX "bail3\n");
707 pci_release_regions(pcidev);
710 pci_disable_device(pcidev);
718 * nes_remove - unload from kernel
720 static void __devexit nes_remove(struct pci_dev *pcidev)
722 struct nes_device *nesdev = pci_get_drvdata(pcidev);
723 struct net_device *netdev;
724 int netdev_index = 0;
726 if (nesdev->netdev_count) {
727 netdev = nesdev->netdev[netdev_index];
729 netif_stop_queue(netdev);
730 unregister_netdev(netdev);
731 nes_netdev_destroy(netdev);
733 nesdev->netdev[netdev_index] = NULL;
734 nesdev->netdev_count--;
735 nesdev->nesadapter->netdev_count--;
739 nes_notifiers_registered--;
740 if (nes_notifiers_registered == 0) {
741 unregister_netevent_notifier(&nes_net_notifier);
742 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
745 list_del(&nesdev->list);
746 nes_destroy_cqp(nesdev);
748 free_irq(pcidev->irq, nesdev);
749 tasklet_kill(&nesdev->dpc_tasklet);
751 /* Deallocate the Adapter Structure */
752 nes_destroy_adapter(nesdev->nesadapter);
754 if (nesdev->msi_enabled) {
755 pci_disable_msi(pcidev);
758 iounmap(nesdev->regs);
761 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
762 pci_release_regions(pcidev);
763 pci_disable_device(pcidev);
764 pci_set_drvdata(pcidev, NULL);
768 static struct pci_driver nes_pci_driver = {
770 .id_table = nes_pci_table,
772 .remove = __devexit_p(nes_remove),
775 static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
777 unsigned int devfn = 0xffffffff;
778 unsigned char bus_number = 0xff;
780 struct nes_device *nesdev;
782 list_for_each_entry(nesdev, &nes_dev_list, list) {
783 if (i == ee_flsh_adapter) {
784 devfn = nesdev->nesadapter->devfn;
785 bus_number = nesdev->nesadapter->bus_number;
791 return snprintf(buf, PAGE_SIZE, "%x:%x", bus_number, devfn);
794 static ssize_t nes_store_adapter(struct device_driver *ddp,
795 const char *buf, size_t count)
797 char *p = (char *)buf;
799 ee_flsh_adapter = simple_strtoul(p, &p, 10);
800 return strnlen(buf, count);
803 static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
805 u32 eeprom_cmd = 0xdead;
807 struct nes_device *nesdev;
809 list_for_each_entry(nesdev, &nes_dev_list, list) {
810 if (i == ee_flsh_adapter) {
811 eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
816 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
819 static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
820 const char *buf, size_t count)
822 char *p = (char *)buf;
825 struct nes_device *nesdev;
827 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
828 val = simple_strtoul(p, &p, 16);
829 list_for_each_entry(nesdev, &nes_dev_list, list) {
830 if (i == ee_flsh_adapter) {
831 nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
837 return strnlen(buf, count);
840 static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
842 u32 eeprom_data = 0xdead;
844 struct nes_device *nesdev;
846 list_for_each_entry(nesdev, &nes_dev_list, list) {
847 if (i == ee_flsh_adapter) {
848 eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
854 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
857 static ssize_t nes_store_ee_data(struct device_driver *ddp,
858 const char *buf, size_t count)
860 char *p = (char *)buf;
863 struct nes_device *nesdev;
865 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
866 val = simple_strtoul(p, &p, 16);
867 list_for_each_entry(nesdev, &nes_dev_list, list) {
868 if (i == ee_flsh_adapter) {
869 nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
875 return strnlen(buf, count);
878 static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
880 u32 flash_cmd = 0xdead;
882 struct nes_device *nesdev;
884 list_for_each_entry(nesdev, &nes_dev_list, list) {
885 if (i == ee_flsh_adapter) {
886 flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
892 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
895 static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
896 const char *buf, size_t count)
898 char *p = (char *)buf;
901 struct nes_device *nesdev;
903 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
904 val = simple_strtoul(p, &p, 16);
905 list_for_each_entry(nesdev, &nes_dev_list, list) {
906 if (i == ee_flsh_adapter) {
907 nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
913 return strnlen(buf, count);
916 static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
918 u32 flash_data = 0xdead;
920 struct nes_device *nesdev;
922 list_for_each_entry(nesdev, &nes_dev_list, list) {
923 if (i == ee_flsh_adapter) {
924 flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
930 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
933 static ssize_t nes_store_flash_data(struct device_driver *ddp,
934 const char *buf, size_t count)
936 char *p = (char *)buf;
939 struct nes_device *nesdev;
941 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
942 val = simple_strtoul(p, &p, 16);
943 list_for_each_entry(nesdev, &nes_dev_list, list) {
944 if (i == ee_flsh_adapter) {
945 nes_write32(nesdev->regs + NES_FLASH_DATA, val);
951 return strnlen(buf, count);
954 static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
956 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
959 static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
960 const char *buf, size_t count)
962 char *p = (char *)buf;
964 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
965 sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
967 return strnlen(buf, count);
970 static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
972 u32 nonidx_data = 0xdead;
974 struct nes_device *nesdev;
976 list_for_each_entry(nesdev, &nes_dev_list, list) {
977 if (i == ee_flsh_adapter) {
978 nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
984 return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
987 static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
988 const char *buf, size_t count)
990 char *p = (char *)buf;
993 struct nes_device *nesdev;
995 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
996 val = simple_strtoul(p, &p, 16);
997 list_for_each_entry(nesdev, &nes_dev_list, list) {
998 if (i == ee_flsh_adapter) {
999 nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1005 return strnlen(buf, count);
1008 static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
1010 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1013 static ssize_t nes_store_idx_addr(struct device_driver *ddp,
1014 const char *buf, size_t count)
1016 char *p = (char *)buf;
1018 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1019 sysfs_idx_addr = simple_strtoul(p, &p, 16);
1021 return strnlen(buf, count);
1024 static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
1026 u32 idx_data = 0xdead;
1028 struct nes_device *nesdev;
1030 list_for_each_entry(nesdev, &nes_dev_list, list) {
1031 if (i == ee_flsh_adapter) {
1032 idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1038 return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1041 static ssize_t nes_store_idx_data(struct device_driver *ddp,
1042 const char *buf, size_t count)
1044 char *p = (char *)buf;
1047 struct nes_device *nesdev;
1049 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1050 val = simple_strtoul(p, &p, 16);
1051 list_for_each_entry(nesdev, &nes_dev_list, list) {
1052 if (i == ee_flsh_adapter) {
1053 nes_write_indexed(nesdev, sysfs_idx_addr, val);
1059 return strnlen(buf, count);
1062 static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
1063 nes_show_adapter, nes_store_adapter);
1064 static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
1065 nes_show_ee_cmd, nes_store_ee_cmd);
1066 static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
1067 nes_show_ee_data, nes_store_ee_data);
1068 static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
1069 nes_show_flash_cmd, nes_store_flash_cmd);
1070 static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
1071 nes_show_flash_data, nes_store_flash_data);
1072 static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
1073 nes_show_nonidx_addr, nes_store_nonidx_addr);
1074 static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
1075 nes_show_nonidx_data, nes_store_nonidx_data);
1076 static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
1077 nes_show_idx_addr, nes_store_idx_addr);
1078 static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
1079 nes_show_idx_data, nes_store_idx_data);
1081 static int nes_create_driver_sysfs(struct pci_driver *drv)
1084 error = driver_create_file(&drv->driver, &driver_attr_adapter);
1085 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
1086 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
1087 error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
1088 error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
1089 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
1090 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
1091 error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
1092 error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
1096 static void nes_remove_driver_sysfs(struct pci_driver *drv)
1098 driver_remove_file(&drv->driver, &driver_attr_adapter);
1099 driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
1100 driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
1101 driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
1102 driver_remove_file(&drv->driver, &driver_attr_flash_data);
1103 driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
1104 driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
1105 driver_remove_file(&drv->driver, &driver_attr_idx_addr);
1106 driver_remove_file(&drv->driver, &driver_attr_idx_data);
1110 * nes_init_module - module initialization entry point
1112 static int __init nes_init_module(void)
1117 retval = nes_cm_start();
1119 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1122 retval = pci_register_driver(&nes_pci_driver);
1124 retval1 = nes_create_driver_sysfs(&nes_pci_driver);
1126 printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
1133 * nes_exit_module - module unload entry point
1135 static void __exit nes_exit_module(void)
1138 nes_remove_driver_sysfs(&nes_pci_driver);
1140 pci_unregister_driver(&nes_pci_driver);
1144 module_init(nes_init_module);
1145 module_exit(nes_exit_module);