perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / infiniband / hw / nes / nes.c
blobe00add6d78ec77178444fc4628d69f36e577676e
1 /*
2 * Copyright (c) 2006 - 2011 Intel Corporation. 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
13 * conditions are met:
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
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
31 * SOFTWARE.
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>
56 #include "nes.h"
58 #include <net/netevent.h>
59 #include <net/neighbour.h>
60 #include <linux/route.h>
61 #include <net/ip_fib.h>
63 MODULE_AUTHOR("NetEffect");
64 MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
65 MODULE_LICENSE("Dual BSD/GPL");
67 int interrupt_mod_interval = 0;
69 /* Interoperability */
70 int mpa_version = 1;
71 module_param(mpa_version, int, 0644);
72 MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
74 /* Interoperability */
75 int disable_mpa_crc = 0;
76 module_param(disable_mpa_crc, int, 0644);
77 MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
79 unsigned int nes_drv_opt = NES_DRV_OPT_DISABLE_INT_MOD | NES_DRV_OPT_ENABLE_PAU;
80 module_param(nes_drv_opt, int, 0644);
81 MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
83 unsigned int nes_debug_level = 0;
84 module_param_named(debug_level, nes_debug_level, uint, 0644);
85 MODULE_PARM_DESC(debug_level, "Enable debug output level");
87 unsigned int wqm_quanta = 0x10000;
88 module_param(wqm_quanta, int, 0644);
89 MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
91 static bool limit_maxrdreqsz;
92 module_param(limit_maxrdreqsz, bool, 0644);
93 MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
95 LIST_HEAD(nes_adapter_list);
96 static LIST_HEAD(nes_dev_list);
98 atomic_t qps_destroyed;
100 static unsigned int ee_flsh_adapter;
101 static unsigned int sysfs_nonidx_addr;
102 static unsigned int sysfs_idx_addr;
104 static const struct pci_device_id nes_pci_table[] = {
105 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020), },
106 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020_KR), },
110 MODULE_DEVICE_TABLE(pci, nes_pci_table);
112 static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
113 static int nes_net_event(struct notifier_block *, unsigned long, void *);
114 static int nes_notifiers_registered;
117 static struct notifier_block nes_inetaddr_notifier = {
118 .notifier_call = nes_inetaddr_event
121 static struct notifier_block nes_net_notifier = {
122 .notifier_call = nes_net_event
126 * nes_inetaddr_event
128 static int nes_inetaddr_event(struct notifier_block *notifier,
129 unsigned long event, void *ptr)
131 struct in_ifaddr *ifa = ptr;
132 struct net_device *event_netdev = ifa->ifa_dev->dev;
133 struct nes_device *nesdev;
134 struct net_device *netdev;
135 struct net_device *upper_dev;
136 struct nes_vnic *nesvnic;
137 unsigned int is_bonded;
139 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
140 &ifa->ifa_address, &ifa->ifa_mask);
141 list_for_each_entry(nesdev, &nes_dev_list, list) {
142 nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
143 nesdev, nesdev->netdev[0]->name);
144 netdev = nesdev->netdev[0];
145 nesvnic = netdev_priv(netdev);
146 upper_dev = netdev_master_upper_dev_get(netdev);
147 is_bonded = netif_is_bond_slave(netdev) &&
148 (upper_dev == event_netdev);
149 if ((netdev == event_netdev) || is_bonded) {
150 if (nesvnic->rdma_enabled == 0) {
151 nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
152 " RDMA is not enabled.\n",
153 netdev->name);
154 return NOTIFY_OK;
156 /* we have ifa->ifa_address/mask here if we need it */
157 switch (event) {
158 case NETDEV_DOWN:
159 nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
160 nes_write_indexed(nesdev,
161 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
163 nes_manage_arp_cache(netdev, netdev->dev_addr,
164 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
165 nesvnic->local_ipaddr = 0;
166 if (is_bonded)
167 continue;
168 else
169 return NOTIFY_OK;
170 break;
171 case NETDEV_UP:
172 nes_debug(NES_DBG_NETDEV, "event:UP\n");
174 if (nesvnic->local_ipaddr != 0) {
175 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
176 return NOTIFY_OK;
178 /* fall through */
179 case NETDEV_CHANGEADDR:
180 /* Add the address to the IP table */
181 if (upper_dev) {
182 struct in_device *in;
184 rcu_read_lock();
185 in = __in_dev_get_rcu(upper_dev);
186 nesvnic->local_ipaddr = in->ifa_list->ifa_address;
187 rcu_read_unlock();
188 } else {
189 nesvnic->local_ipaddr = ifa->ifa_address;
192 nes_write_indexed(nesdev,
193 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
194 ntohl(nesvnic->local_ipaddr));
195 nes_manage_arp_cache(netdev, netdev->dev_addr,
196 ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
197 if (is_bonded)
198 continue;
199 else
200 return NOTIFY_OK;
201 break;
202 default:
203 break;
208 return NOTIFY_DONE;
213 * nes_net_event
215 static int nes_net_event(struct notifier_block *notifier,
216 unsigned long event, void *ptr)
218 struct neighbour *neigh = ptr;
219 struct nes_device *nesdev;
220 struct net_device *netdev;
221 struct nes_vnic *nesvnic;
223 switch (event) {
224 case NETEVENT_NEIGH_UPDATE:
225 list_for_each_entry(nesdev, &nes_dev_list, list) {
226 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
227 netdev = nesdev->netdev[0];
228 nesvnic = netdev_priv(netdev);
229 if (netdev == neigh->dev) {
230 if (nesvnic->rdma_enabled == 0) {
231 nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
232 netdev->name);
233 } else {
234 if (neigh->nud_state & NUD_VALID) {
235 nes_manage_arp_cache(neigh->dev, neigh->ha,
236 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
237 } else {
238 nes_manage_arp_cache(neigh->dev, neigh->ha,
239 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
242 return NOTIFY_OK;
245 break;
246 default:
247 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
248 break;
251 return NOTIFY_DONE;
256 * nes_add_ref
258 void nes_add_ref(struct ib_qp *ibqp)
260 struct nes_qp *nesqp;
262 nesqp = to_nesqp(ibqp);
263 nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
264 ibqp->qp_num, atomic_read(&nesqp->refcount));
265 atomic_inc(&nesqp->refcount);
268 static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
270 unsigned long flags;
271 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
272 struct nes_adapter *nesadapter = nesdev->nesadapter;
274 atomic_inc(&qps_destroyed);
276 /* Free the control structures */
278 if (nesqp->pbl_vbase) {
279 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
280 nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
281 spin_lock_irqsave(&nesadapter->pbl_lock, flags);
282 nesadapter->free_256pbl++;
283 spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
284 pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
285 nesqp->pbl_vbase = NULL;
287 } else {
288 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
289 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
291 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
293 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
294 kfree(nesqp->allocated_buffer);
299 * nes_rem_ref
301 void nes_rem_ref(struct ib_qp *ibqp)
303 u64 u64temp;
304 struct nes_qp *nesqp;
305 struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
306 struct nes_device *nesdev = nesvnic->nesdev;
307 struct nes_hw_cqp_wqe *cqp_wqe;
308 struct nes_cqp_request *cqp_request;
309 u32 opcode;
311 nesqp = to_nesqp(ibqp);
313 if (atomic_read(&nesqp->refcount) == 0) {
314 printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
315 __func__, ibqp->qp_num, nesqp->last_aeq);
316 BUG();
319 if (atomic_dec_and_test(&nesqp->refcount)) {
320 if (nesqp->pau_mode)
321 nes_destroy_pau_qp(nesdev, nesqp);
323 /* Destroy the QP */
324 cqp_request = nes_get_cqp_request(nesdev);
325 if (cqp_request == NULL) {
326 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
327 return;
329 cqp_request->waiting = 0;
330 cqp_request->callback = 1;
331 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
332 cqp_request->cqp_callback_pointer = nesqp;
333 cqp_wqe = &cqp_request->cqp_wqe;
335 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
336 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
338 if (nesqp->hte_added) {
339 opcode |= NES_CQP_QP_DEL_HTE;
340 nesqp->hte_added = 0;
342 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
343 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
344 u64temp = (u64)nesqp->nesqp_context_pbase;
345 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
346 nes_post_cqp_request(nesdev, cqp_request);
352 * nes_get_qp
354 struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
356 struct nes_vnic *nesvnic = to_nesvnic(device);
357 struct nes_device *nesdev = nesvnic->nesdev;
358 struct nes_adapter *nesadapter = nesdev->nesadapter;
360 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
361 return NULL;
363 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
368 * nes_print_macaddr
370 static void nes_print_macaddr(struct net_device *netdev)
372 nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
373 netdev->name, netdev->dev_addr, netdev->irq);
377 * nes_interrupt - handle interrupts
379 static irqreturn_t nes_interrupt(int irq, void *dev_id)
381 struct nes_device *nesdev = (struct nes_device *)dev_id;
382 int handled = 0;
383 u32 int_mask;
384 u32 int_req;
385 u32 int_stat;
386 u32 intf_int_stat;
387 u32 timer_stat;
389 if (nesdev->msi_enabled) {
390 /* No need to read the interrupt pending register if msi is enabled */
391 handled = 1;
392 } else {
393 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
394 /* Master interrupt enable provides synchronization for kicking off bottom half
395 when interrupt sharing is going on */
396 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
397 if (int_mask & 0x80000000) {
398 /* Check interrupt status to see if this might be ours */
399 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
400 int_req = nesdev->int_req;
401 if (int_stat&int_req) {
402 /* if interesting CEQ or AEQ is pending, claim the interrupt */
403 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
404 handled = 1;
405 } else {
406 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
407 /* Timer might be running but might be for another function */
408 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
409 if ((timer_stat & nesdev->timer_int_req) != 0) {
410 handled = 1;
413 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
414 (handled == 0)) {
415 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
416 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
417 handled = 1;
421 if (handled) {
422 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
423 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
424 /* Save off the status to save an additional read */
425 nesdev->int_stat = int_stat;
426 nesdev->napi_isr_ran = 1;
430 } else {
431 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
435 if (handled) {
437 if (nes_napi_isr(nesdev) == 0) {
438 tasklet_schedule(&nesdev->dpc_tasklet);
441 return IRQ_HANDLED;
442 } else {
443 return IRQ_NONE;
449 * nes_probe - Device initialization
451 static int nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
453 struct net_device *netdev = NULL;
454 struct nes_device *nesdev = NULL;
455 int ret = 0;
456 void __iomem *mmio_regs = NULL;
457 u8 hw_rev;
459 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
460 DRV_VERSION, pci_name(pcidev));
462 ret = pci_enable_device(pcidev);
463 if (ret) {
464 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
465 goto bail0;
468 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
469 (long unsigned int)pci_resource_start(pcidev, BAR_0),
470 (long unsigned int)pci_resource_len(pcidev, BAR_0));
471 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
472 (long unsigned int)pci_resource_start(pcidev, BAR_1),
473 (long unsigned int)pci_resource_len(pcidev, BAR_1));
475 /* Make sure PCI base addr are MMIO */
476 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
477 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
478 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
479 ret = -ENODEV;
480 goto bail1;
483 /* Reserve PCI I/O and memory resources */
484 ret = pci_request_regions(pcidev, DRV_NAME);
485 if (ret) {
486 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
487 goto bail1;
490 if ((sizeof(dma_addr_t) > 4)) {
491 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
492 if (ret < 0) {
493 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
494 goto bail2;
496 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
497 if (ret) {
498 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
499 goto bail2;
501 } else {
502 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
503 if (ret < 0) {
504 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
505 goto bail2;
507 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
508 if (ret) {
509 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
510 goto bail2;
514 pci_set_master(pcidev);
516 /* Allocate hardware structure */
517 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
518 if (!nesdev) {
519 ret = -ENOMEM;
520 goto bail2;
523 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
524 nesdev->pcidev = pcidev;
525 pci_set_drvdata(pcidev, nesdev);
527 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
528 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
530 spin_lock_init(&nesdev->indexed_regs_lock);
532 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
533 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0),
534 pci_resource_len(pcidev, BAR_0));
535 if (mmio_regs == NULL) {
536 printk(KERN_ERR PFX "Unable to remap BAR0\n");
537 ret = -EIO;
538 goto bail3;
540 nesdev->regs = mmio_regs;
541 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
543 /* Ensure interrupts are disabled */
544 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
546 if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
547 if (!pci_enable_msi(nesdev->pcidev)) {
548 nesdev->msi_enabled = 1;
549 nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
550 pci_name(pcidev));
551 } else {
552 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
553 pci_name(pcidev));
555 } else {
556 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
557 pci_name(pcidev));
560 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
561 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
563 /* Init the adapter */
564 nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
565 if (!nesdev->nesadapter) {
566 printk(KERN_ERR PFX "Unable to initialize adapter.\n");
567 ret = -ENOMEM;
568 goto bail5;
570 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
571 nesdev->nesadapter->wqm_quanta = wqm_quanta;
573 /* nesdev->base_doorbell_index =
574 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
575 nesdev->base_doorbell_index = 1;
576 nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
577 if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
578 switch (PCI_FUNC(nesdev->pcidev->devfn) %
579 nesdev->nesadapter->port_count) {
580 case 1:
581 nesdev->mac_index = 2;
582 break;
583 case 2:
584 nesdev->mac_index = 1;
585 break;
586 case 3:
587 nesdev->mac_index = 3;
588 break;
589 case 0:
590 default:
591 nesdev->mac_index = 0;
593 } else {
594 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
595 nesdev->nesadapter->port_count;
598 if ((limit_maxrdreqsz ||
599 ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
600 (hw_rev == NE020_REV1))) &&
601 (pcie_get_readrq(pcidev) > 256)) {
602 if (pcie_set_readrq(pcidev, 256))
603 printk(KERN_ERR PFX "Unable to set max read request"
604 " to 256 bytes\n");
605 else
606 nes_debug(NES_DBG_INIT, "Max read request size set"
607 " to 256 bytes\n");
610 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
612 /* bring up the Control QP */
613 if (nes_init_cqp(nesdev)) {
614 ret = -ENODEV;
615 goto bail6;
618 /* Arm the CCQ */
619 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
620 PCI_FUNC(nesdev->pcidev->devfn));
621 nes_read32(nesdev->regs+NES_CQE_ALLOC);
623 /* Enable the interrupts */
624 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
625 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
626 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
627 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
630 /* TODO: This really should be the first driver to load, not function 0 */
631 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
632 /* pick up PCI and critical errors if the first driver to load */
633 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
634 nesdev->int_req |= NES_INT_INTF;
635 } else {
636 nesdev->intf_int_req = 0;
638 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
639 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
640 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
641 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
642 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
644 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
646 /* deal with both periodic and one_shot */
647 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
648 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
649 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
650 PCI_FUNC(nesdev->pcidev->devfn),
651 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
653 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
655 list_add_tail(&nesdev->list, &nes_dev_list);
657 /* Request an interrupt line for the driver */
658 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
659 if (ret) {
660 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
661 pci_name(pcidev), pcidev->irq);
662 goto bail65;
665 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
667 if (nes_notifiers_registered == 0) {
668 register_inetaddr_notifier(&nes_inetaddr_notifier);
669 register_netevent_notifier(&nes_net_notifier);
671 nes_notifiers_registered++;
673 INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
675 /* Initialize network devices */
676 netdev = nes_netdev_init(nesdev, mmio_regs);
677 if (netdev == NULL) {
678 ret = -ENOMEM;
679 goto bail7;
682 /* Register network device */
683 ret = register_netdev(netdev);
684 if (ret) {
685 printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
686 nes_netdev_destroy(netdev);
687 goto bail7;
690 nes_print_macaddr(netdev);
692 nesdev->netdev_count++;
693 nesdev->nesadapter->netdev_count++;
695 printk(KERN_INFO PFX "%s: NetEffect RNIC driver successfully loaded.\n",
696 pci_name(pcidev));
697 return 0;
699 bail7:
700 printk(KERN_ERR PFX "bail7\n");
701 while (nesdev->netdev_count > 0) {
702 nesdev->netdev_count--;
703 nesdev->nesadapter->netdev_count--;
705 unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
706 nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
709 nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
710 nesdev->netdev_count, nesdev->nesadapter->netdev_count);
712 nes_notifiers_registered--;
713 if (nes_notifiers_registered == 0) {
714 unregister_netevent_notifier(&nes_net_notifier);
715 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
718 list_del(&nesdev->list);
719 nes_destroy_cqp(nesdev);
721 bail65:
722 printk(KERN_ERR PFX "bail65\n");
723 free_irq(pcidev->irq, nesdev);
724 if (nesdev->msi_enabled) {
725 pci_disable_msi(pcidev);
727 bail6:
728 printk(KERN_ERR PFX "bail6\n");
729 tasklet_kill(&nesdev->dpc_tasklet);
730 /* Deallocate the Adapter Structure */
731 nes_destroy_adapter(nesdev->nesadapter);
733 bail5:
734 printk(KERN_ERR PFX "bail5\n");
735 iounmap(nesdev->regs);
737 bail3:
738 printk(KERN_ERR PFX "bail3\n");
739 kfree(nesdev);
741 bail2:
742 pci_release_regions(pcidev);
744 bail1:
745 pci_disable_device(pcidev);
747 bail0:
748 return ret;
753 * nes_remove - unload from kernel
755 static void nes_remove(struct pci_dev *pcidev)
757 struct nes_device *nesdev = pci_get_drvdata(pcidev);
758 struct net_device *netdev;
759 int netdev_index = 0;
760 unsigned long flags;
762 if (nesdev->netdev_count) {
763 netdev = nesdev->netdev[netdev_index];
764 if (netdev) {
765 netif_stop_queue(netdev);
766 unregister_netdev(netdev);
767 nes_netdev_destroy(netdev);
769 nesdev->netdev[netdev_index] = NULL;
770 nesdev->netdev_count--;
771 nesdev->nesadapter->netdev_count--;
775 nes_notifiers_registered--;
776 if (nes_notifiers_registered == 0) {
777 unregister_netevent_notifier(&nes_net_notifier);
778 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
781 list_del(&nesdev->list);
782 nes_destroy_cqp(nesdev);
784 free_irq(pcidev->irq, nesdev);
785 tasklet_kill(&nesdev->dpc_tasklet);
787 spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
788 if (nesdev->link_recheck) {
789 spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
790 cancel_delayed_work_sync(&nesdev->work);
791 } else {
792 spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
795 /* Deallocate the Adapter Structure */
796 nes_destroy_adapter(nesdev->nesadapter);
798 if (nesdev->msi_enabled) {
799 pci_disable_msi(pcidev);
802 iounmap(nesdev->regs);
803 kfree(nesdev);
805 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
806 pci_release_regions(pcidev);
807 pci_disable_device(pcidev);
808 pci_set_drvdata(pcidev, NULL);
812 static ssize_t adapter_show(struct device_driver *ddp, char *buf)
814 unsigned int devfn = 0xffffffff;
815 unsigned char bus_number = 0xff;
816 unsigned int i = 0;
817 struct nes_device *nesdev;
819 list_for_each_entry(nesdev, &nes_dev_list, list) {
820 if (i == ee_flsh_adapter) {
821 devfn = nesdev->pcidev->devfn;
822 bus_number = nesdev->pcidev->bus->number;
823 break;
825 i++;
828 return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
831 static ssize_t adapter_store(struct device_driver *ddp,
832 const char *buf, size_t count)
834 char *p = (char *)buf;
836 ee_flsh_adapter = simple_strtoul(p, &p, 10);
837 return strnlen(buf, count);
840 static ssize_t eeprom_cmd_show(struct device_driver *ddp, char *buf)
842 u32 eeprom_cmd = 0xdead;
843 u32 i = 0;
844 struct nes_device *nesdev;
846 list_for_each_entry(nesdev, &nes_dev_list, list) {
847 if (i == ee_flsh_adapter) {
848 eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
849 break;
851 i++;
853 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
856 static ssize_t eeprom_cmd_store(struct device_driver *ddp,
857 const char *buf, size_t count)
859 char *p = (char *)buf;
860 u32 val;
861 u32 i = 0;
862 struct nes_device *nesdev;
864 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
865 val = simple_strtoul(p, &p, 16);
866 list_for_each_entry(nesdev, &nes_dev_list, list) {
867 if (i == ee_flsh_adapter) {
868 nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
869 break;
871 i++;
874 return strnlen(buf, count);
877 static ssize_t eeprom_data_show(struct device_driver *ddp, char *buf)
879 u32 eeprom_data = 0xdead;
880 u32 i = 0;
881 struct nes_device *nesdev;
883 list_for_each_entry(nesdev, &nes_dev_list, list) {
884 if (i == ee_flsh_adapter) {
885 eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
886 break;
888 i++;
891 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
894 static ssize_t eeprom_data_store(struct device_driver *ddp,
895 const char *buf, size_t count)
897 char *p = (char *)buf;
898 u32 val;
899 u32 i = 0;
900 struct nes_device *nesdev;
902 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
903 val = simple_strtoul(p, &p, 16);
904 list_for_each_entry(nesdev, &nes_dev_list, list) {
905 if (i == ee_flsh_adapter) {
906 nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
907 break;
909 i++;
912 return strnlen(buf, count);
915 static ssize_t flash_cmd_show(struct device_driver *ddp, char *buf)
917 u32 flash_cmd = 0xdead;
918 u32 i = 0;
919 struct nes_device *nesdev;
921 list_for_each_entry(nesdev, &nes_dev_list, list) {
922 if (i == ee_flsh_adapter) {
923 flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
924 break;
926 i++;
929 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
932 static ssize_t flash_cmd_store(struct device_driver *ddp,
933 const char *buf, size_t count)
935 char *p = (char *)buf;
936 u32 val;
937 u32 i = 0;
938 struct nes_device *nesdev;
940 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
941 val = simple_strtoul(p, &p, 16);
942 list_for_each_entry(nesdev, &nes_dev_list, list) {
943 if (i == ee_flsh_adapter) {
944 nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
945 break;
947 i++;
950 return strnlen(buf, count);
953 static ssize_t flash_data_show(struct device_driver *ddp, char *buf)
955 u32 flash_data = 0xdead;
956 u32 i = 0;
957 struct nes_device *nesdev;
959 list_for_each_entry(nesdev, &nes_dev_list, list) {
960 if (i == ee_flsh_adapter) {
961 flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
962 break;
964 i++;
967 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
970 static ssize_t flash_data_store(struct device_driver *ddp,
971 const char *buf, size_t count)
973 char *p = (char *)buf;
974 u32 val;
975 u32 i = 0;
976 struct nes_device *nesdev;
978 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
979 val = simple_strtoul(p, &p, 16);
980 list_for_each_entry(nesdev, &nes_dev_list, list) {
981 if (i == ee_flsh_adapter) {
982 nes_write32(nesdev->regs + NES_FLASH_DATA, val);
983 break;
985 i++;
988 return strnlen(buf, count);
991 static ssize_t nonidx_addr_show(struct device_driver *ddp, char *buf)
993 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
996 static ssize_t nonidx_addr_store(struct device_driver *ddp,
997 const char *buf, size_t count)
999 char *p = (char *)buf;
1001 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1002 sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
1004 return strnlen(buf, count);
1007 static ssize_t nonidx_data_show(struct device_driver *ddp, char *buf)
1009 u32 nonidx_data = 0xdead;
1010 u32 i = 0;
1011 struct nes_device *nesdev;
1013 list_for_each_entry(nesdev, &nes_dev_list, list) {
1014 if (i == ee_flsh_adapter) {
1015 nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
1016 break;
1018 i++;
1021 return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
1024 static ssize_t nonidx_data_store(struct device_driver *ddp,
1025 const char *buf, size_t count)
1027 char *p = (char *)buf;
1028 u32 val;
1029 u32 i = 0;
1030 struct nes_device *nesdev;
1032 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1033 val = simple_strtoul(p, &p, 16);
1034 list_for_each_entry(nesdev, &nes_dev_list, list) {
1035 if (i == ee_flsh_adapter) {
1036 nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1037 break;
1039 i++;
1042 return strnlen(buf, count);
1045 static ssize_t idx_addr_show(struct device_driver *ddp, char *buf)
1047 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1050 static ssize_t idx_addr_store(struct device_driver *ddp,
1051 const char *buf, size_t count)
1053 char *p = (char *)buf;
1055 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1056 sysfs_idx_addr = simple_strtoul(p, &p, 16);
1058 return strnlen(buf, count);
1061 static ssize_t idx_data_show(struct device_driver *ddp, char *buf)
1063 u32 idx_data = 0xdead;
1064 u32 i = 0;
1065 struct nes_device *nesdev;
1067 list_for_each_entry(nesdev, &nes_dev_list, list) {
1068 if (i == ee_flsh_adapter) {
1069 idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1070 break;
1072 i++;
1075 return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1078 static ssize_t idx_data_store(struct device_driver *ddp,
1079 const char *buf, size_t count)
1081 char *p = (char *)buf;
1082 u32 val;
1083 u32 i = 0;
1084 struct nes_device *nesdev;
1086 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1087 val = simple_strtoul(p, &p, 16);
1088 list_for_each_entry(nesdev, &nes_dev_list, list) {
1089 if (i == ee_flsh_adapter) {
1090 nes_write_indexed(nesdev, sysfs_idx_addr, val);
1091 break;
1093 i++;
1096 return strnlen(buf, count);
1099 static ssize_t wqm_quanta_show(struct device_driver *ddp, char *buf)
1101 u32 wqm_quanta_value = 0xdead;
1102 u32 i = 0;
1103 struct nes_device *nesdev;
1105 list_for_each_entry(nesdev, &nes_dev_list, list) {
1106 if (i == ee_flsh_adapter) {
1107 wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
1108 break;
1110 i++;
1113 return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta_value);
1116 static ssize_t wqm_quanta_store(struct device_driver *ddp, const char *buf,
1117 size_t count)
1119 unsigned long wqm_quanta_value;
1120 u32 wqm_config1;
1121 u32 i = 0;
1122 struct nes_device *nesdev;
1124 if (kstrtoul(buf, 0, &wqm_quanta_value) < 0)
1125 return -EINVAL;
1127 list_for_each_entry(nesdev, &nes_dev_list, list) {
1128 if (i == ee_flsh_adapter) {
1129 nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1130 wqm_config1 = nes_read_indexed(nesdev,
1131 NES_IDX_WQM_CONFIG1);
1132 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1133 ((wqm_quanta_value << 1) |
1134 (wqm_config1 & 0x00000001)));
1135 break;
1137 i++;
1139 return strnlen(buf, count);
1142 static DRIVER_ATTR_RW(adapter);
1143 static DRIVER_ATTR_RW(eeprom_cmd);
1144 static DRIVER_ATTR_RW(eeprom_data);
1145 static DRIVER_ATTR_RW(flash_cmd);
1146 static DRIVER_ATTR_RW(flash_data);
1147 static DRIVER_ATTR_RW(nonidx_addr);
1148 static DRIVER_ATTR_RW(nonidx_data);
1149 static DRIVER_ATTR_RW(idx_addr);
1150 static DRIVER_ATTR_RW(idx_data);
1151 static DRIVER_ATTR_RW(wqm_quanta);
1153 static struct attribute *nes_attrs[] = {
1154 &driver_attr_adapter.attr,
1155 &driver_attr_eeprom_cmd.attr,
1156 &driver_attr_eeprom_data.attr,
1157 &driver_attr_flash_cmd.attr,
1158 &driver_attr_flash_data.attr,
1159 &driver_attr_nonidx_addr.attr,
1160 &driver_attr_nonidx_data.attr,
1161 &driver_attr_idx_addr.attr,
1162 &driver_attr_idx_data.attr,
1163 &driver_attr_wqm_quanta.attr,
1164 NULL,
1166 ATTRIBUTE_GROUPS(nes);
1168 static struct pci_driver nes_pci_driver = {
1169 .name = DRV_NAME,
1170 .id_table = nes_pci_table,
1171 .probe = nes_probe,
1172 .remove = nes_remove,
1173 .groups = nes_groups,
1178 * nes_init_module - module initialization entry point
1180 static int __init nes_init_module(void)
1182 int retval;
1184 retval = nes_cm_start();
1185 if (retval) {
1186 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1187 return retval;
1189 return pci_register_driver(&nes_pci_driver);
1194 * nes_exit_module - module unload entry point
1196 static void __exit nes_exit_module(void)
1198 nes_cm_stop();
1200 pci_unregister_driver(&nes_pci_driver);
1204 module_init(nes_init_module);
1205 module_exit(nes_exit_module);