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, 0644);
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, 0644);
79 MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
81 unsigned int send_first = 0;
82 module_param(send_first, int, 0644);
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, 0644);
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 unsigned int wqm_quanta = 0x10000;
95 module_param(wqm_quanta, int, 0644);
96 MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
98 LIST_HEAD(nes_adapter_list);
99 static LIST_HEAD(nes_dev_list);
101 atomic_t qps_destroyed;
103 static unsigned int ee_flsh_adapter;
104 static unsigned int sysfs_nonidx_addr;
105 static unsigned int sysfs_idx_addr;
107 static struct pci_device_id nes_pci_table[] = {
108 {PCI_VENDOR_ID_NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020, PCI_ANY_ID, PCI_ANY_ID},
112 MODULE_DEVICE_TABLE(pci, nes_pci_table);
114 static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
115 static int nes_net_event(struct notifier_block *, unsigned long, void *);
116 static int nes_notifiers_registered;
119 static struct notifier_block nes_inetaddr_notifier = {
120 .notifier_call = nes_inetaddr_event
123 static struct notifier_block nes_net_notifier = {
124 .notifier_call = nes_net_event
133 static int nes_inetaddr_event(struct notifier_block *notifier,
134 unsigned long event, void *ptr)
136 struct in_ifaddr *ifa = ptr;
137 struct net_device *event_netdev = ifa->ifa_dev->dev;
138 struct nes_device *nesdev;
139 struct net_device *netdev;
140 struct nes_vnic *nesvnic;
144 addr = ntohl(ifa->ifa_address);
145 mask = ntohl(ifa->ifa_mask);
146 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address " NIPQUAD_FMT
147 ", netmask " NIPQUAD_FMT ".\n",
148 HIPQUAD(addr), HIPQUAD(mask));
149 list_for_each_entry(nesdev, &nes_dev_list, list) {
150 nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
151 nesdev, nesdev->netdev[0]->name);
152 netdev = nesdev->netdev[0];
153 nesvnic = netdev_priv(netdev);
154 if (netdev == event_netdev) {
155 if (nesvnic->rdma_enabled == 0) {
156 nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
157 " RDMA is not enabled.\n",
161 /* we have ifa->ifa_address/mask here if we need it */
164 nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
165 nes_write_indexed(nesdev,
166 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
168 nes_manage_arp_cache(netdev, netdev->dev_addr,
169 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
170 nesvnic->local_ipaddr = 0;
174 nes_debug(NES_DBG_NETDEV, "event:UP\n");
176 if (nesvnic->local_ipaddr != 0) {
177 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
180 /* Add the address to the IP table */
181 nesvnic->local_ipaddr = ifa->ifa_address;
183 nes_write_indexed(nesdev,
184 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
185 ntohl(ifa->ifa_address));
186 nes_manage_arp_cache(netdev, netdev->dev_addr,
187 ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
203 static int nes_net_event(struct notifier_block *notifier,
204 unsigned long event, void *ptr)
206 struct neighbour *neigh = ptr;
207 struct nes_device *nesdev;
208 struct net_device *netdev;
209 struct nes_vnic *nesvnic;
212 case NETEVENT_NEIGH_UPDATE:
213 list_for_each_entry(nesdev, &nes_dev_list, list) {
214 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
215 netdev = nesdev->netdev[0];
216 nesvnic = netdev_priv(netdev);
217 if (netdev == neigh->dev) {
218 if (nesvnic->rdma_enabled == 0) {
219 nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
222 if (neigh->nud_state & NUD_VALID) {
223 nes_manage_arp_cache(neigh->dev, neigh->ha,
224 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
226 nes_manage_arp_cache(neigh->dev, neigh->ha,
227 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
235 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
246 void nes_add_ref(struct ib_qp *ibqp)
248 struct nes_qp *nesqp;
250 nesqp = to_nesqp(ibqp);
251 nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
252 ibqp->qp_num, atomic_read(&nesqp->refcount));
253 atomic_inc(&nesqp->refcount);
256 static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
259 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
260 struct nes_adapter *nesadapter = nesdev->nesadapter;
263 atomic_inc(&qps_destroyed);
265 /* Free the control structures */
267 qp_id = nesqp->hwqp.qp_id;
268 if (nesqp->pbl_vbase) {
269 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
270 nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
271 spin_lock_irqsave(&nesadapter->pbl_lock, flags);
272 nesadapter->free_256pbl++;
273 spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
274 pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
275 nesqp->pbl_vbase = NULL;
278 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
279 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
281 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
283 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
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_hw_cqp_wqe *cqp_wqe;
298 struct nes_cqp_request *cqp_request;
301 nesqp = to_nesqp(ibqp);
303 if (atomic_read(&nesqp->refcount) == 0) {
304 printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
305 __func__, ibqp->qp_num, nesqp->last_aeq);
309 if (atomic_dec_and_test(&nesqp->refcount)) {
311 cqp_request = nes_get_cqp_request(nesdev);
312 if (cqp_request == NULL) {
313 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
316 cqp_request->waiting = 0;
317 cqp_request->callback = 1;
318 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
319 cqp_request->cqp_callback_pointer = nesqp;
320 cqp_wqe = &cqp_request->cqp_wqe;
322 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
323 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
325 if (nesqp->hte_added) {
326 opcode |= NES_CQP_QP_DEL_HTE;
327 nesqp->hte_added = 0;
329 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
330 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
331 u64temp = (u64)nesqp->nesqp_context_pbase;
332 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
333 nes_post_cqp_request(nesdev, cqp_request);
341 struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
343 struct nes_vnic *nesvnic = to_nesvnic(device);
344 struct nes_device *nesdev = nesvnic->nesdev;
345 struct nes_adapter *nesadapter = nesdev->nesadapter;
347 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
350 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
357 static void nes_print_macaddr(struct net_device *netdev)
359 DECLARE_MAC_BUF(mac);
361 nes_debug(NES_DBG_INIT, "%s: %s, IRQ %u\n",
362 netdev->name, print_mac(mac, netdev->dev_addr), netdev->irq);
366 * nes_interrupt - handle interrupts
368 static irqreturn_t nes_interrupt(int irq, void *dev_id)
370 struct nes_device *nesdev = (struct nes_device *)dev_id;
378 if (nesdev->msi_enabled) {
379 /* No need to read the interrupt pending register if msi is enabled */
382 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
383 /* Master interrupt enable provides synchronization for kicking off bottom half
384 when interrupt sharing is going on */
385 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
386 if (int_mask & 0x80000000) {
387 /* Check interrupt status to see if this might be ours */
388 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
389 int_req = nesdev->int_req;
390 if (int_stat&int_req) {
391 /* if interesting CEQ or AEQ is pending, claim the interrupt */
392 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
395 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
396 /* Timer might be running but might be for another function */
397 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
398 if ((timer_stat & nesdev->timer_int_req) != 0) {
402 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
404 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
405 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
411 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
412 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
413 /* Save off the status to save an additional read */
414 nesdev->int_stat = int_stat;
415 nesdev->napi_isr_ran = 1;
420 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
426 if (nes_napi_isr(nesdev) == 0) {
427 tasklet_schedule(&nesdev->dpc_tasklet);
438 * nes_probe - Device initialization
440 static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
442 struct net_device *netdev = NULL;
443 struct nes_device *nesdev = NULL;
445 struct nes_vnic *nesvnic = NULL;
446 void __iomem *mmio_regs = NULL;
449 assert(pcidev != NULL);
452 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
453 DRV_VERSION, pci_name(pcidev));
455 ret = pci_enable_device(pcidev);
457 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
461 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
462 (long unsigned int)pci_resource_start(pcidev, BAR_0),
463 (long unsigned int)pci_resource_len(pcidev, BAR_0));
464 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
465 (long unsigned int)pci_resource_start(pcidev, BAR_1),
466 (long unsigned int)pci_resource_len(pcidev, BAR_1));
468 /* Make sure PCI base addr are MMIO */
469 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
470 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
471 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
476 /* Reserve PCI I/O and memory resources */
477 ret = pci_request_regions(pcidev, DRV_NAME);
479 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
483 if ((sizeof(dma_addr_t) > 4)) {
484 ret = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
486 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
489 ret = pci_set_consistent_dma_mask(pcidev, DMA_64BIT_MASK);
491 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
495 ret = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
497 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
500 ret = pci_set_consistent_dma_mask(pcidev, DMA_32BIT_MASK);
502 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
507 pci_set_master(pcidev);
509 /* Allocate hardware structure */
510 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
512 printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
517 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
518 nesdev->pcidev = pcidev;
519 pci_set_drvdata(pcidev, nesdev);
521 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
522 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
524 spin_lock_init(&nesdev->indexed_regs_lock);
526 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
527 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0), sizeof(mmio_regs));
528 if (mmio_regs == NULL) {
529 printk(KERN_ERR PFX "Unable to remap BAR0\n");
533 nesdev->regs = mmio_regs;
534 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
536 /* Ensure interrupts are disabled */
537 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
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",
545 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
549 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
553 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
554 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
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");
563 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
564 nesdev->nesadapter->wqm_quanta = wqm_quanta;
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) {
574 nesdev->mac_index = 2;
577 nesdev->mac_index = 1;
580 nesdev->mac_index = 3;
584 nesdev->mac_index = 0;
587 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
588 nesdev->nesadapter->port_count;
591 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
593 /* bring up the Control QP */
594 if (nes_init_cqp(nesdev)) {
600 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
601 PCI_FUNC(nesdev->pcidev->devfn));
602 nes_read32(nesdev->regs+NES_CQE_ALLOC);
604 /* Enable the interrupts */
605 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
606 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
607 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
608 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
611 /* TODO: This really should be the first driver to load, not function 0 */
612 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
613 /* pick up PCI and critical errors if the first driver to load */
614 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
615 nesdev->int_req |= NES_INT_INTF;
617 nesdev->intf_int_req = 0;
619 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
620 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
621 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
622 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
623 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
625 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
627 /* deal with both periodic and one_shot */
628 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
629 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
630 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
631 PCI_FUNC(nesdev->pcidev->devfn),
632 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
634 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
636 list_add_tail(&nesdev->list, &nes_dev_list);
638 /* Request an interrupt line for the driver */
639 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
641 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
642 pci_name(pcidev), pcidev->irq);
646 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
648 if (nes_notifiers_registered == 0) {
649 register_inetaddr_notifier(&nes_inetaddr_notifier);
650 register_netevent_notifier(&nes_net_notifier);
652 nes_notifiers_registered++;
654 /* Initialize network devices */
655 if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL) {
659 /* Register network device */
660 ret = register_netdev(netdev);
662 printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
663 nes_netdev_destroy(netdev);
667 nes_print_macaddr(netdev);
668 /* create a CM core for this netdev */
669 nesvnic = netdev_priv(netdev);
671 nesdev->netdev_count++;
672 nesdev->nesadapter->netdev_count++;
675 printk(KERN_ERR PFX "%s: NetEffect RNIC driver successfully loaded.\n",
680 printk(KERN_ERR PFX "bail7\n");
681 while (nesdev->netdev_count > 0) {
682 nesdev->netdev_count--;
683 nesdev->nesadapter->netdev_count--;
685 unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
686 nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
689 nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
690 nesdev->netdev_count, nesdev->nesadapter->netdev_count);
692 nes_notifiers_registered--;
693 if (nes_notifiers_registered == 0) {
694 unregister_netevent_notifier(&nes_net_notifier);
695 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
698 list_del(&nesdev->list);
699 nes_destroy_cqp(nesdev);
702 printk(KERN_ERR PFX "bail65\n");
703 free_irq(pcidev->irq, nesdev);
704 if (nesdev->msi_enabled) {
705 pci_disable_msi(pcidev);
708 printk(KERN_ERR PFX "bail6\n");
709 tasklet_kill(&nesdev->dpc_tasklet);
710 /* Deallocate the Adapter Structure */
711 nes_destroy_adapter(nesdev->nesadapter);
714 printk(KERN_ERR PFX "bail5\n");
715 iounmap(nesdev->regs);
718 printk(KERN_ERR PFX "bail3\n");
722 pci_release_regions(pcidev);
725 pci_disable_device(pcidev);
733 * nes_remove - unload from kernel
735 static void __devexit nes_remove(struct pci_dev *pcidev)
737 struct nes_device *nesdev = pci_get_drvdata(pcidev);
738 struct net_device *netdev;
739 int netdev_index = 0;
741 if (nesdev->netdev_count) {
742 netdev = nesdev->netdev[netdev_index];
744 netif_stop_queue(netdev);
745 unregister_netdev(netdev);
746 nes_netdev_destroy(netdev);
748 nesdev->netdev[netdev_index] = NULL;
749 nesdev->netdev_count--;
750 nesdev->nesadapter->netdev_count--;
754 nes_notifiers_registered--;
755 if (nes_notifiers_registered == 0) {
756 unregister_netevent_notifier(&nes_net_notifier);
757 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
760 list_del(&nesdev->list);
761 nes_destroy_cqp(nesdev);
763 free_irq(pcidev->irq, nesdev);
764 tasklet_kill(&nesdev->dpc_tasklet);
766 /* Deallocate the Adapter Structure */
767 nes_destroy_adapter(nesdev->nesadapter);
769 if (nesdev->msi_enabled) {
770 pci_disable_msi(pcidev);
773 iounmap(nesdev->regs);
776 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
777 pci_release_regions(pcidev);
778 pci_disable_device(pcidev);
779 pci_set_drvdata(pcidev, NULL);
783 static struct pci_driver nes_pci_driver = {
785 .id_table = nes_pci_table,
787 .remove = __devexit_p(nes_remove),
790 static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
792 unsigned int devfn = 0xffffffff;
793 unsigned char bus_number = 0xff;
795 struct nes_device *nesdev;
797 list_for_each_entry(nesdev, &nes_dev_list, list) {
798 if (i == ee_flsh_adapter) {
799 devfn = nesdev->pcidev->devfn;
800 bus_number = nesdev->pcidev->bus->number;
806 return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
809 static ssize_t nes_store_adapter(struct device_driver *ddp,
810 const char *buf, size_t count)
812 char *p = (char *)buf;
814 ee_flsh_adapter = simple_strtoul(p, &p, 10);
815 return strnlen(buf, count);
818 static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
820 u32 eeprom_cmd = 0xdead;
822 struct nes_device *nesdev;
824 list_for_each_entry(nesdev, &nes_dev_list, list) {
825 if (i == ee_flsh_adapter) {
826 eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
831 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
834 static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
835 const char *buf, size_t count)
837 char *p = (char *)buf;
840 struct nes_device *nesdev;
842 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
843 val = simple_strtoul(p, &p, 16);
844 list_for_each_entry(nesdev, &nes_dev_list, list) {
845 if (i == ee_flsh_adapter) {
846 nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
852 return strnlen(buf, count);
855 static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
857 u32 eeprom_data = 0xdead;
859 struct nes_device *nesdev;
861 list_for_each_entry(nesdev, &nes_dev_list, list) {
862 if (i == ee_flsh_adapter) {
863 eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
869 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
872 static ssize_t nes_store_ee_data(struct device_driver *ddp,
873 const char *buf, size_t count)
875 char *p = (char *)buf;
878 struct nes_device *nesdev;
880 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
881 val = simple_strtoul(p, &p, 16);
882 list_for_each_entry(nesdev, &nes_dev_list, list) {
883 if (i == ee_flsh_adapter) {
884 nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
890 return strnlen(buf, count);
893 static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
895 u32 flash_cmd = 0xdead;
897 struct nes_device *nesdev;
899 list_for_each_entry(nesdev, &nes_dev_list, list) {
900 if (i == ee_flsh_adapter) {
901 flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
907 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
910 static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
911 const char *buf, size_t count)
913 char *p = (char *)buf;
916 struct nes_device *nesdev;
918 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
919 val = simple_strtoul(p, &p, 16);
920 list_for_each_entry(nesdev, &nes_dev_list, list) {
921 if (i == ee_flsh_adapter) {
922 nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
928 return strnlen(buf, count);
931 static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
933 u32 flash_data = 0xdead;
935 struct nes_device *nesdev;
937 list_for_each_entry(nesdev, &nes_dev_list, list) {
938 if (i == ee_flsh_adapter) {
939 flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
945 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
948 static ssize_t nes_store_flash_data(struct device_driver *ddp,
949 const char *buf, size_t count)
951 char *p = (char *)buf;
954 struct nes_device *nesdev;
956 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
957 val = simple_strtoul(p, &p, 16);
958 list_for_each_entry(nesdev, &nes_dev_list, list) {
959 if (i == ee_flsh_adapter) {
960 nes_write32(nesdev->regs + NES_FLASH_DATA, val);
966 return strnlen(buf, count);
969 static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
971 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
974 static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
975 const char *buf, size_t count)
977 char *p = (char *)buf;
979 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
980 sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
982 return strnlen(buf, count);
985 static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
987 u32 nonidx_data = 0xdead;
989 struct nes_device *nesdev;
991 list_for_each_entry(nesdev, &nes_dev_list, list) {
992 if (i == ee_flsh_adapter) {
993 nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
999 return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
1002 static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
1003 const char *buf, size_t count)
1005 char *p = (char *)buf;
1008 struct nes_device *nesdev;
1010 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1011 val = simple_strtoul(p, &p, 16);
1012 list_for_each_entry(nesdev, &nes_dev_list, list) {
1013 if (i == ee_flsh_adapter) {
1014 nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1020 return strnlen(buf, count);
1023 static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
1025 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1028 static ssize_t nes_store_idx_addr(struct device_driver *ddp,
1029 const char *buf, size_t count)
1031 char *p = (char *)buf;
1033 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1034 sysfs_idx_addr = simple_strtoul(p, &p, 16);
1036 return strnlen(buf, count);
1039 static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
1041 u32 idx_data = 0xdead;
1043 struct nes_device *nesdev;
1045 list_for_each_entry(nesdev, &nes_dev_list, list) {
1046 if (i == ee_flsh_adapter) {
1047 idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1053 return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1056 static ssize_t nes_store_idx_data(struct device_driver *ddp,
1057 const char *buf, size_t count)
1059 char *p = (char *)buf;
1062 struct nes_device *nesdev;
1064 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1065 val = simple_strtoul(p, &p, 16);
1066 list_for_each_entry(nesdev, &nes_dev_list, list) {
1067 if (i == ee_flsh_adapter) {
1068 nes_write_indexed(nesdev, sysfs_idx_addr, val);
1074 return strnlen(buf, count);
1079 * nes_show_wqm_quanta
1081 static ssize_t nes_show_wqm_quanta(struct device_driver *ddp, char *buf)
1083 u32 wqm_quanta_value = 0xdead;
1085 struct nes_device *nesdev;
1087 list_for_each_entry(nesdev, &nes_dev_list, list) {
1088 if (i == ee_flsh_adapter) {
1089 wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
1095 return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta);
1100 * nes_store_wqm_quanta
1102 static ssize_t nes_store_wqm_quanta(struct device_driver *ddp,
1103 const char *buf, size_t count)
1105 unsigned long wqm_quanta_value;
1108 struct nes_device *nesdev;
1110 strict_strtoul(buf, 0, &wqm_quanta_value);
1111 list_for_each_entry(nesdev, &nes_dev_list, list) {
1112 if (i == ee_flsh_adapter) {
1113 nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1114 wqm_config1 = nes_read_indexed(nesdev,
1115 NES_IDX_WQM_CONFIG1);
1116 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1117 ((wqm_quanta_value << 1) |
1118 (wqm_config1 & 0x00000001)));
1123 return strnlen(buf, count);
1126 static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
1127 nes_show_adapter, nes_store_adapter);
1128 static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
1129 nes_show_ee_cmd, nes_store_ee_cmd);
1130 static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
1131 nes_show_ee_data, nes_store_ee_data);
1132 static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
1133 nes_show_flash_cmd, nes_store_flash_cmd);
1134 static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
1135 nes_show_flash_data, nes_store_flash_data);
1136 static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
1137 nes_show_nonidx_addr, nes_store_nonidx_addr);
1138 static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
1139 nes_show_nonidx_data, nes_store_nonidx_data);
1140 static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
1141 nes_show_idx_addr, nes_store_idx_addr);
1142 static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
1143 nes_show_idx_data, nes_store_idx_data);
1144 static DRIVER_ATTR(wqm_quanta, S_IRUSR | S_IWUSR,
1145 nes_show_wqm_quanta, nes_store_wqm_quanta);
1147 static int nes_create_driver_sysfs(struct pci_driver *drv)
1150 error = driver_create_file(&drv->driver, &driver_attr_adapter);
1151 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
1152 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
1153 error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
1154 error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
1155 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
1156 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
1157 error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
1158 error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
1159 error |= driver_create_file(&drv->driver, &driver_attr_wqm_quanta);
1163 static void nes_remove_driver_sysfs(struct pci_driver *drv)
1165 driver_remove_file(&drv->driver, &driver_attr_adapter);
1166 driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
1167 driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
1168 driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
1169 driver_remove_file(&drv->driver, &driver_attr_flash_data);
1170 driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
1171 driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
1172 driver_remove_file(&drv->driver, &driver_attr_idx_addr);
1173 driver_remove_file(&drv->driver, &driver_attr_idx_data);
1174 driver_remove_file(&drv->driver, &driver_attr_wqm_quanta);
1178 * nes_init_module - module initialization entry point
1180 static int __init nes_init_module(void)
1185 retval = nes_cm_start();
1187 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1190 retval = pci_register_driver(&nes_pci_driver);
1192 retval1 = nes_create_driver_sysfs(&nes_pci_driver);
1194 printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
1201 * nes_exit_module - module unload entry point
1203 static void __exit nes_exit_module(void)
1206 nes_remove_driver_sysfs(&nes_pci_driver);
1208 pci_unregister_driver(&nes_pci_driver);
1212 module_init(nes_init_module);
1213 module_exit(nes_exit_module);