2 * Copyright (c) 2006 - 2009 Intel-NE, 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 static unsigned int limit_maxrdreqsz;
99 module_param(limit_maxrdreqsz, bool, 0644);
100 MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
102 LIST_HEAD(nes_adapter_list);
103 static LIST_HEAD(nes_dev_list);
105 atomic_t qps_destroyed;
107 static unsigned int ee_flsh_adapter;
108 static unsigned int sysfs_nonidx_addr;
109 static unsigned int sysfs_idx_addr;
111 static struct pci_device_id nes_pci_table[] = {
112 {PCI_VENDOR_ID_NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020, PCI_ANY_ID, PCI_ANY_ID},
116 MODULE_DEVICE_TABLE(pci, nes_pci_table);
118 static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
119 static int nes_net_event(struct notifier_block *, unsigned long, void *);
120 static int nes_notifiers_registered;
123 static struct notifier_block nes_inetaddr_notifier = {
124 .notifier_call = nes_inetaddr_event
127 static struct notifier_block nes_net_notifier = {
128 .notifier_call = nes_net_event
137 static int nes_inetaddr_event(struct notifier_block *notifier,
138 unsigned long event, void *ptr)
140 struct in_ifaddr *ifa = ptr;
141 struct net_device *event_netdev = ifa->ifa_dev->dev;
142 struct nes_device *nesdev;
143 struct net_device *netdev;
144 struct nes_vnic *nesvnic;
146 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
147 &ifa->ifa_address, &ifa->ifa_mask);
148 list_for_each_entry(nesdev, &nes_dev_list, list) {
149 nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
150 nesdev, nesdev->netdev[0]->name);
151 netdev = nesdev->netdev[0];
152 nesvnic = netdev_priv(netdev);
153 if (netdev == event_netdev) {
154 if (nesvnic->rdma_enabled == 0) {
155 nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
156 " RDMA is not enabled.\n",
160 /* we have ifa->ifa_address/mask here if we need it */
163 nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
164 nes_write_indexed(nesdev,
165 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
167 nes_manage_arp_cache(netdev, netdev->dev_addr,
168 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
169 nesvnic->local_ipaddr = 0;
173 nes_debug(NES_DBG_NETDEV, "event:UP\n");
175 if (nesvnic->local_ipaddr != 0) {
176 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
179 /* Add the address to the IP table */
180 nesvnic->local_ipaddr = ifa->ifa_address;
182 nes_write_indexed(nesdev,
183 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
184 ntohl(ifa->ifa_address));
185 nes_manage_arp_cache(netdev, netdev->dev_addr,
186 ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
202 static int nes_net_event(struct notifier_block *notifier,
203 unsigned long event, void *ptr)
205 struct neighbour *neigh = ptr;
206 struct nes_device *nesdev;
207 struct net_device *netdev;
208 struct nes_vnic *nesvnic;
211 case NETEVENT_NEIGH_UPDATE:
212 list_for_each_entry(nesdev, &nes_dev_list, list) {
213 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
214 netdev = nesdev->netdev[0];
215 nesvnic = netdev_priv(netdev);
216 if (netdev == neigh->dev) {
217 if (nesvnic->rdma_enabled == 0) {
218 nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
221 if (neigh->nud_state & NUD_VALID) {
222 nes_manage_arp_cache(neigh->dev, neigh->ha,
223 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
225 nes_manage_arp_cache(neigh->dev, neigh->ha,
226 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
234 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
245 void nes_add_ref(struct ib_qp *ibqp)
247 struct nes_qp *nesqp;
249 nesqp = to_nesqp(ibqp);
250 nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
251 ibqp->qp_num, atomic_read(&nesqp->refcount));
252 atomic_inc(&nesqp->refcount);
255 static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
258 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
259 struct nes_adapter *nesadapter = nesdev->nesadapter;
262 atomic_inc(&qps_destroyed);
264 /* Free the control structures */
266 qp_id = nesqp->hwqp.qp_id;
267 if (nesqp->pbl_vbase) {
268 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
269 nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
270 spin_lock_irqsave(&nesadapter->pbl_lock, flags);
271 nesadapter->free_256pbl++;
272 spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
273 pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
274 nesqp->pbl_vbase = NULL;
277 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
278 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
280 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
282 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
283 kfree(nesqp->allocated_buffer);
290 void nes_rem_ref(struct ib_qp *ibqp)
293 struct nes_qp *nesqp;
294 struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
295 struct nes_device *nesdev = nesvnic->nesdev;
296 struct nes_hw_cqp_wqe *cqp_wqe;
297 struct nes_cqp_request *cqp_request;
300 nesqp = to_nesqp(ibqp);
302 if (atomic_read(&nesqp->refcount) == 0) {
303 printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
304 __func__, ibqp->qp_num, nesqp->last_aeq);
308 if (atomic_dec_and_test(&nesqp->refcount)) {
310 cqp_request = nes_get_cqp_request(nesdev);
311 if (cqp_request == NULL) {
312 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
315 cqp_request->waiting = 0;
316 cqp_request->callback = 1;
317 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
318 cqp_request->cqp_callback_pointer = nesqp;
319 cqp_wqe = &cqp_request->cqp_wqe;
321 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
322 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
324 if (nesqp->hte_added) {
325 opcode |= NES_CQP_QP_DEL_HTE;
326 nesqp->hte_added = 0;
328 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
329 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
330 u64temp = (u64)nesqp->nesqp_context_pbase;
331 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
332 nes_post_cqp_request(nesdev, cqp_request);
340 struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
342 struct nes_vnic *nesvnic = to_nesvnic(device);
343 struct nes_device *nesdev = nesvnic->nesdev;
344 struct nes_adapter *nesadapter = nesdev->nesadapter;
346 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
349 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
356 static void nes_print_macaddr(struct net_device *netdev)
358 nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
359 netdev->name, netdev->dev_addr, netdev->irq);
363 * nes_interrupt - handle interrupts
365 static irqreturn_t nes_interrupt(int irq, void *dev_id)
367 struct nes_device *nesdev = (struct nes_device *)dev_id;
375 if (nesdev->msi_enabled) {
376 /* No need to read the interrupt pending register if msi is enabled */
379 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
380 /* Master interrupt enable provides synchronization for kicking off bottom half
381 when interrupt sharing is going on */
382 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
383 if (int_mask & 0x80000000) {
384 /* Check interrupt status to see if this might be ours */
385 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
386 int_req = nesdev->int_req;
387 if (int_stat&int_req) {
388 /* if interesting CEQ or AEQ is pending, claim the interrupt */
389 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
392 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
393 /* Timer might be running but might be for another function */
394 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
395 if ((timer_stat & nesdev->timer_int_req) != 0) {
399 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
401 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
402 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
408 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
409 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
410 /* Save off the status to save an additional read */
411 nesdev->int_stat = int_stat;
412 nesdev->napi_isr_ran = 1;
417 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
423 if (nes_napi_isr(nesdev) == 0) {
424 tasklet_schedule(&nesdev->dpc_tasklet);
435 * nes_probe - Device initialization
437 static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
439 struct net_device *netdev = NULL;
440 struct nes_device *nesdev = NULL;
442 struct nes_vnic *nesvnic = NULL;
443 void __iomem *mmio_regs = NULL;
446 assert(pcidev != NULL);
449 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
450 DRV_VERSION, pci_name(pcidev));
452 ret = pci_enable_device(pcidev);
454 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
458 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
459 (long unsigned int)pci_resource_start(pcidev, BAR_0),
460 (long unsigned int)pci_resource_len(pcidev, BAR_0));
461 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
462 (long unsigned int)pci_resource_start(pcidev, BAR_1),
463 (long unsigned int)pci_resource_len(pcidev, BAR_1));
465 /* Make sure PCI base addr are MMIO */
466 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
467 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
468 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
473 /* Reserve PCI I/O and memory resources */
474 ret = pci_request_regions(pcidev, DRV_NAME);
476 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
480 if ((sizeof(dma_addr_t) > 4)) {
481 ret = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
483 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
486 ret = pci_set_consistent_dma_mask(pcidev, DMA_64BIT_MASK);
488 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
492 ret = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
494 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
497 ret = pci_set_consistent_dma_mask(pcidev, DMA_32BIT_MASK);
499 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
504 pci_set_master(pcidev);
506 /* Allocate hardware structure */
507 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
509 printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
514 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
515 nesdev->pcidev = pcidev;
516 pci_set_drvdata(pcidev, nesdev);
518 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
519 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
521 spin_lock_init(&nesdev->indexed_regs_lock);
523 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
524 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0), sizeof(mmio_regs));
525 if (mmio_regs == NULL) {
526 printk(KERN_ERR PFX "Unable to remap BAR0\n");
530 nesdev->regs = mmio_regs;
531 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
533 /* Ensure interrupts are disabled */
534 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
536 if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
537 if (!pci_enable_msi(nesdev->pcidev)) {
538 nesdev->msi_enabled = 1;
539 nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
542 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
546 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
550 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
551 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
553 /* Init the adapter */
554 nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
555 if (!nesdev->nesadapter) {
556 printk(KERN_ERR PFX "Unable to initialize adapter.\n");
560 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
561 nesdev->nesadapter->wqm_quanta = wqm_quanta;
563 /* nesdev->base_doorbell_index =
564 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
565 nesdev->base_doorbell_index = 1;
566 nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
567 if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
568 switch (PCI_FUNC(nesdev->pcidev->devfn) %
569 nesdev->nesadapter->port_count) {
571 nesdev->mac_index = 2;
574 nesdev->mac_index = 1;
577 nesdev->mac_index = 3;
581 nesdev->mac_index = 0;
584 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
585 nesdev->nesadapter->port_count;
588 if ((limit_maxrdreqsz ||
589 ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
590 (hw_rev == NE020_REV1))) &&
591 (pcie_get_readrq(pcidev) > 256)) {
592 if (pcie_set_readrq(pcidev, 256))
593 printk(KERN_ERR PFX "Unable to set max read request"
596 nes_debug(NES_DBG_INIT, "Max read request size set"
600 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
602 /* bring up the Control QP */
603 if (nes_init_cqp(nesdev)) {
609 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
610 PCI_FUNC(nesdev->pcidev->devfn));
611 nes_read32(nesdev->regs+NES_CQE_ALLOC);
613 /* Enable the interrupts */
614 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
615 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
616 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
617 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
620 /* TODO: This really should be the first driver to load, not function 0 */
621 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
622 /* pick up PCI and critical errors if the first driver to load */
623 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
624 nesdev->int_req |= NES_INT_INTF;
626 nesdev->intf_int_req = 0;
628 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
629 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
630 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
631 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
632 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
634 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
636 /* deal with both periodic and one_shot */
637 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
638 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
639 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
640 PCI_FUNC(nesdev->pcidev->devfn),
641 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
643 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
645 list_add_tail(&nesdev->list, &nes_dev_list);
647 /* Request an interrupt line for the driver */
648 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
650 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
651 pci_name(pcidev), pcidev->irq);
655 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
657 if (nes_notifiers_registered == 0) {
658 register_inetaddr_notifier(&nes_inetaddr_notifier);
659 register_netevent_notifier(&nes_net_notifier);
661 nes_notifiers_registered++;
663 /* Initialize network devices */
664 if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL) {
668 /* Register network device */
669 ret = register_netdev(netdev);
671 printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
672 nes_netdev_destroy(netdev);
676 nes_print_macaddr(netdev);
677 /* create a CM core for this netdev */
678 nesvnic = netdev_priv(netdev);
680 nesdev->netdev_count++;
681 nesdev->nesadapter->netdev_count++;
684 printk(KERN_ERR PFX "%s: NetEffect RNIC driver successfully loaded.\n",
689 printk(KERN_ERR PFX "bail7\n");
690 while (nesdev->netdev_count > 0) {
691 nesdev->netdev_count--;
692 nesdev->nesadapter->netdev_count--;
694 unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
695 nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
698 nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
699 nesdev->netdev_count, nesdev->nesadapter->netdev_count);
701 nes_notifiers_registered--;
702 if (nes_notifiers_registered == 0) {
703 unregister_netevent_notifier(&nes_net_notifier);
704 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
707 list_del(&nesdev->list);
708 nes_destroy_cqp(nesdev);
711 printk(KERN_ERR PFX "bail65\n");
712 free_irq(pcidev->irq, nesdev);
713 if (nesdev->msi_enabled) {
714 pci_disable_msi(pcidev);
717 printk(KERN_ERR PFX "bail6\n");
718 tasklet_kill(&nesdev->dpc_tasklet);
719 /* Deallocate the Adapter Structure */
720 nes_destroy_adapter(nesdev->nesadapter);
723 printk(KERN_ERR PFX "bail5\n");
724 iounmap(nesdev->regs);
727 printk(KERN_ERR PFX "bail3\n");
731 pci_release_regions(pcidev);
734 pci_disable_device(pcidev);
742 * nes_remove - unload from kernel
744 static void __devexit nes_remove(struct pci_dev *pcidev)
746 struct nes_device *nesdev = pci_get_drvdata(pcidev);
747 struct net_device *netdev;
748 int netdev_index = 0;
750 if (nesdev->netdev_count) {
751 netdev = nesdev->netdev[netdev_index];
753 netif_stop_queue(netdev);
754 unregister_netdev(netdev);
755 nes_netdev_destroy(netdev);
757 nesdev->netdev[netdev_index] = NULL;
758 nesdev->netdev_count--;
759 nesdev->nesadapter->netdev_count--;
763 nes_notifiers_registered--;
764 if (nes_notifiers_registered == 0) {
765 unregister_netevent_notifier(&nes_net_notifier);
766 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
769 list_del(&nesdev->list);
770 nes_destroy_cqp(nesdev);
772 free_irq(pcidev->irq, nesdev);
773 tasklet_kill(&nesdev->dpc_tasklet);
775 /* Deallocate the Adapter Structure */
776 nes_destroy_adapter(nesdev->nesadapter);
778 if (nesdev->msi_enabled) {
779 pci_disable_msi(pcidev);
782 iounmap(nesdev->regs);
785 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
786 pci_release_regions(pcidev);
787 pci_disable_device(pcidev);
788 pci_set_drvdata(pcidev, NULL);
792 static struct pci_driver nes_pci_driver = {
794 .id_table = nes_pci_table,
796 .remove = __devexit_p(nes_remove),
799 static ssize_t nes_show_adapter(struct device_driver *ddp, char *buf)
801 unsigned int devfn = 0xffffffff;
802 unsigned char bus_number = 0xff;
804 struct nes_device *nesdev;
806 list_for_each_entry(nesdev, &nes_dev_list, list) {
807 if (i == ee_flsh_adapter) {
808 devfn = nesdev->pcidev->devfn;
809 bus_number = nesdev->pcidev->bus->number;
815 return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
818 static ssize_t nes_store_adapter(struct device_driver *ddp,
819 const char *buf, size_t count)
821 char *p = (char *)buf;
823 ee_flsh_adapter = simple_strtoul(p, &p, 10);
824 return strnlen(buf, count);
827 static ssize_t nes_show_ee_cmd(struct device_driver *ddp, char *buf)
829 u32 eeprom_cmd = 0xdead;
831 struct nes_device *nesdev;
833 list_for_each_entry(nesdev, &nes_dev_list, list) {
834 if (i == ee_flsh_adapter) {
835 eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
840 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
843 static ssize_t nes_store_ee_cmd(struct device_driver *ddp,
844 const char *buf, size_t count)
846 char *p = (char *)buf;
849 struct nes_device *nesdev;
851 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
852 val = simple_strtoul(p, &p, 16);
853 list_for_each_entry(nesdev, &nes_dev_list, list) {
854 if (i == ee_flsh_adapter) {
855 nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
861 return strnlen(buf, count);
864 static ssize_t nes_show_ee_data(struct device_driver *ddp, char *buf)
866 u32 eeprom_data = 0xdead;
868 struct nes_device *nesdev;
870 list_for_each_entry(nesdev, &nes_dev_list, list) {
871 if (i == ee_flsh_adapter) {
872 eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
878 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
881 static ssize_t nes_store_ee_data(struct device_driver *ddp,
882 const char *buf, size_t count)
884 char *p = (char *)buf;
887 struct nes_device *nesdev;
889 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
890 val = simple_strtoul(p, &p, 16);
891 list_for_each_entry(nesdev, &nes_dev_list, list) {
892 if (i == ee_flsh_adapter) {
893 nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
899 return strnlen(buf, count);
902 static ssize_t nes_show_flash_cmd(struct device_driver *ddp, char *buf)
904 u32 flash_cmd = 0xdead;
906 struct nes_device *nesdev;
908 list_for_each_entry(nesdev, &nes_dev_list, list) {
909 if (i == ee_flsh_adapter) {
910 flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
916 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
919 static ssize_t nes_store_flash_cmd(struct device_driver *ddp,
920 const char *buf, size_t count)
922 char *p = (char *)buf;
925 struct nes_device *nesdev;
927 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
928 val = simple_strtoul(p, &p, 16);
929 list_for_each_entry(nesdev, &nes_dev_list, list) {
930 if (i == ee_flsh_adapter) {
931 nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
937 return strnlen(buf, count);
940 static ssize_t nes_show_flash_data(struct device_driver *ddp, char *buf)
942 u32 flash_data = 0xdead;
944 struct nes_device *nesdev;
946 list_for_each_entry(nesdev, &nes_dev_list, list) {
947 if (i == ee_flsh_adapter) {
948 flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
954 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
957 static ssize_t nes_store_flash_data(struct device_driver *ddp,
958 const char *buf, size_t count)
960 char *p = (char *)buf;
963 struct nes_device *nesdev;
965 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
966 val = simple_strtoul(p, &p, 16);
967 list_for_each_entry(nesdev, &nes_dev_list, list) {
968 if (i == ee_flsh_adapter) {
969 nes_write32(nesdev->regs + NES_FLASH_DATA, val);
975 return strnlen(buf, count);
978 static ssize_t nes_show_nonidx_addr(struct device_driver *ddp, char *buf)
980 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
983 static ssize_t nes_store_nonidx_addr(struct device_driver *ddp,
984 const char *buf, size_t count)
986 char *p = (char *)buf;
988 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
989 sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
991 return strnlen(buf, count);
994 static ssize_t nes_show_nonidx_data(struct device_driver *ddp, char *buf)
996 u32 nonidx_data = 0xdead;
998 struct nes_device *nesdev;
1000 list_for_each_entry(nesdev, &nes_dev_list, list) {
1001 if (i == ee_flsh_adapter) {
1002 nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
1008 return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
1011 static ssize_t nes_store_nonidx_data(struct device_driver *ddp,
1012 const char *buf, size_t count)
1014 char *p = (char *)buf;
1017 struct nes_device *nesdev;
1019 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1020 val = simple_strtoul(p, &p, 16);
1021 list_for_each_entry(nesdev, &nes_dev_list, list) {
1022 if (i == ee_flsh_adapter) {
1023 nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1029 return strnlen(buf, count);
1032 static ssize_t nes_show_idx_addr(struct device_driver *ddp, char *buf)
1034 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1037 static ssize_t nes_store_idx_addr(struct device_driver *ddp,
1038 const char *buf, size_t count)
1040 char *p = (char *)buf;
1042 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1043 sysfs_idx_addr = simple_strtoul(p, &p, 16);
1045 return strnlen(buf, count);
1048 static ssize_t nes_show_idx_data(struct device_driver *ddp, char *buf)
1050 u32 idx_data = 0xdead;
1052 struct nes_device *nesdev;
1054 list_for_each_entry(nesdev, &nes_dev_list, list) {
1055 if (i == ee_flsh_adapter) {
1056 idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1062 return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1065 static ssize_t nes_store_idx_data(struct device_driver *ddp,
1066 const char *buf, size_t count)
1068 char *p = (char *)buf;
1071 struct nes_device *nesdev;
1073 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1074 val = simple_strtoul(p, &p, 16);
1075 list_for_each_entry(nesdev, &nes_dev_list, list) {
1076 if (i == ee_flsh_adapter) {
1077 nes_write_indexed(nesdev, sysfs_idx_addr, val);
1083 return strnlen(buf, count);
1088 * nes_show_wqm_quanta
1090 static ssize_t nes_show_wqm_quanta(struct device_driver *ddp, char *buf)
1092 u32 wqm_quanta_value = 0xdead;
1094 struct nes_device *nesdev;
1096 list_for_each_entry(nesdev, &nes_dev_list, list) {
1097 if (i == ee_flsh_adapter) {
1098 wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
1104 return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta);
1109 * nes_store_wqm_quanta
1111 static ssize_t nes_store_wqm_quanta(struct device_driver *ddp,
1112 const char *buf, size_t count)
1114 unsigned long wqm_quanta_value;
1117 struct nes_device *nesdev;
1119 strict_strtoul(buf, 0, &wqm_quanta_value);
1120 list_for_each_entry(nesdev, &nes_dev_list, list) {
1121 if (i == ee_flsh_adapter) {
1122 nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1123 wqm_config1 = nes_read_indexed(nesdev,
1124 NES_IDX_WQM_CONFIG1);
1125 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1126 ((wqm_quanta_value << 1) |
1127 (wqm_config1 & 0x00000001)));
1132 return strnlen(buf, count);
1135 static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
1136 nes_show_adapter, nes_store_adapter);
1137 static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
1138 nes_show_ee_cmd, nes_store_ee_cmd);
1139 static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
1140 nes_show_ee_data, nes_store_ee_data);
1141 static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
1142 nes_show_flash_cmd, nes_store_flash_cmd);
1143 static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
1144 nes_show_flash_data, nes_store_flash_data);
1145 static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
1146 nes_show_nonidx_addr, nes_store_nonidx_addr);
1147 static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
1148 nes_show_nonidx_data, nes_store_nonidx_data);
1149 static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
1150 nes_show_idx_addr, nes_store_idx_addr);
1151 static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
1152 nes_show_idx_data, nes_store_idx_data);
1153 static DRIVER_ATTR(wqm_quanta, S_IRUSR | S_IWUSR,
1154 nes_show_wqm_quanta, nes_store_wqm_quanta);
1156 static int nes_create_driver_sysfs(struct pci_driver *drv)
1159 error = driver_create_file(&drv->driver, &driver_attr_adapter);
1160 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
1161 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
1162 error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
1163 error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
1164 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
1165 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
1166 error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
1167 error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
1168 error |= driver_create_file(&drv->driver, &driver_attr_wqm_quanta);
1172 static void nes_remove_driver_sysfs(struct pci_driver *drv)
1174 driver_remove_file(&drv->driver, &driver_attr_adapter);
1175 driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
1176 driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
1177 driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
1178 driver_remove_file(&drv->driver, &driver_attr_flash_data);
1179 driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
1180 driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
1181 driver_remove_file(&drv->driver, &driver_attr_idx_addr);
1182 driver_remove_file(&drv->driver, &driver_attr_idx_data);
1183 driver_remove_file(&drv->driver, &driver_attr_wqm_quanta);
1187 * nes_init_module - module initialization entry point
1189 static int __init nes_init_module(void)
1194 retval = nes_cm_start();
1196 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1199 retval = pci_register_driver(&nes_pci_driver);
1201 retval1 = nes_create_driver_sysfs(&nes_pci_driver);
1203 printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
1210 * nes_exit_module - module unload entry point
1212 static void __exit nes_exit_module(void)
1215 nes_remove_driver_sysfs(&nes_pci_driver);
1217 pci_unregister_driver(&nes_pci_driver);
1221 module_init(nes_init_module);
1222 module_exit(nes_exit_module);