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 nics_per_function
= 1;
69 int interrupt_mod_interval
= 0;
72 /* Interoperability */
74 module_param(mpa_version
, int, 0);
75 MODULE_PARM_DESC(mpa_version
, "MPA version to be used int MPA Req/Resp (0 or 1)");
77 /* Interoperability */
78 int disable_mpa_crc
= 0;
79 module_param(disable_mpa_crc
, int, 0);
80 MODULE_PARM_DESC(disable_mpa_crc
, "Disable checking of MPA CRC");
82 unsigned int send_first
= 0;
83 module_param(send_first
, int, 0);
84 MODULE_PARM_DESC(send_first
, "Send RDMA Message First on Active Connection");
87 unsigned int nes_drv_opt
= 0;
88 module_param(nes_drv_opt
, int, 0);
89 MODULE_PARM_DESC(nes_drv_opt
, "Driver option parameters");
91 unsigned int nes_debug_level
= 0;
92 module_param_named(debug_level
, nes_debug_level
, uint
, 0644);
93 MODULE_PARM_DESC(debug_level
, "Enable debug output level");
95 LIST_HEAD(nes_adapter_list
);
96 LIST_HEAD(nes_dev_list
);
98 atomic_t qps_destroyed
;
99 atomic_t cqp_reqs_allocated
;
100 atomic_t cqp_reqs_freed
;
101 atomic_t cqp_reqs_dynallocated
;
102 atomic_t cqp_reqs_dynfreed
;
103 atomic_t cqp_reqs_queued
;
104 atomic_t cqp_reqs_redriven
;
106 static void nes_print_macaddr(struct net_device
*netdev
);
107 static irqreturn_t
nes_interrupt(int, void *);
108 static int __devinit
nes_probe(struct pci_dev
*, const struct pci_device_id
*);
109 static void __devexit
nes_remove(struct pci_dev
*);
110 static int __init
nes_init_module(void);
111 static void __exit
nes_exit_module(void);
112 static unsigned int ee_flsh_adapter
;
113 static unsigned int sysfs_nonidx_addr
;
114 static unsigned int sysfs_idx_addr
;
116 static struct pci_device_id nes_pci_table
[] = {
117 {PCI_VENDOR_ID_NETEFFECT
, PCI_DEVICE_ID_NETEFFECT_NE020
, PCI_ANY_ID
, PCI_ANY_ID
},
121 MODULE_DEVICE_TABLE(pci
, nes_pci_table
);
123 static int nes_inetaddr_event(struct notifier_block
*, unsigned long, void *);
124 static int nes_net_event(struct notifier_block
*, unsigned long, void *);
125 static int nes_notifiers_registered
;
128 static struct notifier_block nes_inetaddr_notifier
= {
129 .notifier_call
= nes_inetaddr_event
132 static struct notifier_block nes_net_notifier
= {
133 .notifier_call
= nes_net_event
142 static int nes_inetaddr_event(struct notifier_block
*notifier
,
143 unsigned long event
, void *ptr
)
145 struct in_ifaddr
*ifa
= ptr
;
146 struct net_device
*event_netdev
= ifa
->ifa_dev
->dev
;
147 struct nes_device
*nesdev
;
148 struct net_device
*netdev
;
149 struct nes_vnic
*nesvnic
;
153 addr
= ntohl(ifa
->ifa_address
);
154 mask
= ntohl(ifa
->ifa_mask
);
155 nes_debug(NES_DBG_NETDEV
, "nes_inetaddr_event: ip address %08X, netmask %08X.\n",
157 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
158 nes_debug(NES_DBG_NETDEV
, "Nesdev list entry = 0x%p. (%s)\n",
159 nesdev
, nesdev
->netdev
[0]->name
);
160 netdev
= nesdev
->netdev
[0];
161 nesvnic
= netdev_priv(netdev
);
162 if (netdev
== event_netdev
) {
163 if (nesvnic
->rdma_enabled
== 0) {
164 nes_debug(NES_DBG_NETDEV
, "Returning without processing event for %s since"
165 " RDMA is not enabled.\n",
169 /* we have ifa->ifa_address/mask here if we need it */
172 nes_debug(NES_DBG_NETDEV
, "event:DOWN\n");
173 nes_write_indexed(nesdev
,
174 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)), 0);
176 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
177 ntohl(nesvnic
->local_ipaddr
), NES_ARP_DELETE
);
178 nesvnic
->local_ipaddr
= 0;
182 nes_debug(NES_DBG_NETDEV
, "event:UP\n");
184 if (nesvnic
->local_ipaddr
!= 0) {
185 nes_debug(NES_DBG_NETDEV
, "Interface already has local_ipaddr\n");
188 /* Add the address to the IP table */
189 nesvnic
->local_ipaddr
= ifa
->ifa_address
;
191 nes_write_indexed(nesdev
,
192 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)),
193 ntohl(ifa
->ifa_address
));
194 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
195 ntohl(nesvnic
->local_ipaddr
), NES_ARP_ADD
);
211 static int nes_net_event(struct notifier_block
*notifier
,
212 unsigned long event
, void *ptr
)
214 struct neighbour
*neigh
= ptr
;
215 struct nes_device
*nesdev
;
216 struct net_device
*netdev
;
217 struct nes_vnic
*nesvnic
;
220 case NETEVENT_NEIGH_UPDATE
:
221 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
222 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
223 netdev
= nesdev
->netdev
[0];
224 nesvnic
= netdev_priv(netdev
);
225 if (netdev
== neigh
->dev
) {
226 if (nesvnic
->rdma_enabled
== 0) {
227 nes_debug(NES_DBG_NETDEV
, "Skipping device %s since no RDMA\n",
230 if (neigh
->nud_state
& NUD_VALID
) {
231 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
232 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_ADD
);
234 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
235 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_DELETE
);
243 nes_debug(NES_DBG_NETDEV
, "NETEVENT_ %lu undefined\n", event
);
254 void nes_add_ref(struct ib_qp
*ibqp
)
256 struct nes_qp
*nesqp
;
258 nesqp
= to_nesqp(ibqp
);
259 nes_debug(NES_DBG_QP
, "Bumping refcount for QP%u. Pre-inc value = %u\n",
260 ibqp
->qp_num
, atomic_read(&nesqp
->refcount
));
261 atomic_inc(&nesqp
->refcount
);
264 static void nes_cqp_rem_ref_callback(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
267 struct nes_qp
*nesqp
= cqp_request
->cqp_callback_pointer
;
268 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
271 atomic_inc(&qps_destroyed
);
273 /* Free the control structures */
275 qp_id
= nesqp
->hwqp
.qp_id
;
276 if (nesqp
->pbl_vbase
) {
277 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
278 nesqp
->hwqp
.q2_vbase
, nesqp
->hwqp
.q2_pbase
);
279 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
280 nesadapter
->free_256pbl
++;
281 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
282 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
283 nesqp
->pbl_vbase
= NULL
;
286 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
287 nesqp
->hwqp
.sq_vbase
, nesqp
->hwqp
.sq_pbase
);
289 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, nesqp
->hwqp
.qp_id
);
291 kfree(nesqp
->allocated_buffer
);
298 void nes_rem_ref(struct ib_qp
*ibqp
)
301 struct nes_qp
*nesqp
;
302 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
303 struct nes_device
*nesdev
= nesvnic
->nesdev
;
304 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
305 struct nes_hw_cqp_wqe
*cqp_wqe
;
306 struct nes_cqp_request
*cqp_request
;
309 nesqp
= to_nesqp(ibqp
);
311 if (atomic_read(&nesqp
->refcount
) == 0) {
312 printk(KERN_INFO PFX
"%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
313 __FUNCTION__
, ibqp
->qp_num
, nesqp
->last_aeq
);
317 if (atomic_dec_and_test(&nesqp
->refcount
)) {
318 nesadapter
->qp_table
[nesqp
->hwqp
.qp_id
-NES_FIRST_QPN
] = NULL
;
321 cqp_request
= nes_get_cqp_request(nesdev
);
322 if (cqp_request
== NULL
) {
323 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
326 cqp_request
->waiting
= 0;
327 cqp_request
->callback
= 1;
328 cqp_request
->cqp_callback
= nes_cqp_rem_ref_callback
;
329 cqp_request
->cqp_callback_pointer
= nesqp
;
330 cqp_wqe
= &cqp_request
->cqp_wqe
;
332 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
333 opcode
= NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_IWARP
;
335 if (nesqp
->hte_added
) {
336 opcode
|= NES_CQP_QP_DEL_HTE
;
337 nesqp
->hte_added
= 0;
339 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
340 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
341 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
342 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
343 nes_post_cqp_request(nesdev
, cqp_request
, NES_CQP_REQUEST_RING_DOORBELL
);
351 struct ib_qp
*nes_get_qp(struct ib_device
*device
, int qpn
)
353 struct nes_vnic
*nesvnic
= to_nesvnic(device
);
354 struct nes_device
*nesdev
= nesvnic
->nesdev
;
355 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
357 if ((qpn
< NES_FIRST_QPN
) || (qpn
>= (NES_FIRST_QPN
+ nesadapter
->max_qp
)))
360 return &nesadapter
->qp_table
[qpn
- NES_FIRST_QPN
]->ibqp
;
367 static void nes_print_macaddr(struct net_device
*netdev
)
369 nes_debug(NES_DBG_INIT
, "%s: MAC %02X:%02X:%02X:%02X:%02X:%02X, IRQ %u\n",
371 netdev
->dev_addr
[0], netdev
->dev_addr
[1], netdev
->dev_addr
[2],
372 netdev
->dev_addr
[3], netdev
->dev_addr
[4], netdev
->dev_addr
[5],
378 * nes_interrupt - handle interrupts
380 static irqreturn_t
nes_interrupt(int irq
, void *dev_id
)
382 struct nes_device
*nesdev
= (struct nes_device
*)dev_id
;
390 if (nesdev
->msi_enabled
) {
391 /* No need to read the interrupt pending register if msi is enabled */
394 if (unlikely(nesdev
->nesadapter
->hw_rev
== NE020_REV
)) {
395 /* Master interrupt enable provides synchronization for kicking off bottom half
396 when interrupt sharing is going on */
397 int_mask
= nes_read32(nesdev
->regs
+ NES_INT_MASK
);
398 if (int_mask
& 0x80000000) {
399 /* Check interrupt status to see if this might be ours */
400 int_stat
= nes_read32(nesdev
->regs
+ NES_INT_STAT
);
401 int_req
= nesdev
->int_req
;
402 if (int_stat
&int_req
) {
403 /* if interesting CEQ or AEQ is pending, claim the interrupt */
404 if ((int_stat
&int_req
) & (~(NES_INT_TIMER
|NES_INT_INTF
))) {
407 if (((int_stat
& int_req
) & NES_INT_TIMER
) == NES_INT_TIMER
) {
408 /* Timer might be running but might be for another function */
409 timer_stat
= nes_read32(nesdev
->regs
+ NES_TIMER_STAT
);
410 if ((timer_stat
& nesdev
->timer_int_req
) != 0) {
414 if ((((int_stat
& int_req
) & NES_INT_INTF
) == NES_INT_INTF
) &&
416 intf_int_stat
= nes_read32(nesdev
->regs
+NES_INTF_INT_STAT
);
417 if ((intf_int_stat
& nesdev
->intf_int_req
) != 0) {
423 nes_write32(nesdev
->regs
+NES_INT_MASK
, int_mask
& (~0x80000000));
424 int_mask
= nes_read32(nesdev
->regs
+NES_INT_MASK
);
425 /* Save off the status to save an additional read */
426 nesdev
->int_stat
= int_stat
;
427 nesdev
->napi_isr_ran
= 1;
432 handled
= nes_read32(nesdev
->regs
+NES_INT_PENDING
);
438 if (nes_napi_isr(nesdev
) == 0) {
439 tasklet_schedule(&nesdev
->dpc_tasklet
);
450 * nes_probe - Device initialization
452 static int __devinit
nes_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*ent
)
454 struct net_device
*netdev
= NULL
;
455 struct nes_device
*nesdev
= NULL
;
457 struct nes_vnic
*nesvnic
= NULL
;
458 void __iomem
*mmio_regs
= NULL
;
461 assert(pcidev
!= NULL
);
464 printk(KERN_INFO PFX
"NetEffect RNIC driver v%s loading. (%s)\n",
465 DRV_VERSION
, pci_name(pcidev
));
467 ret
= pci_enable_device(pcidev
);
469 printk(KERN_ERR PFX
"Unable to enable PCI device. (%s)\n", pci_name(pcidev
));
473 nes_debug(NES_DBG_INIT
, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
474 (long unsigned int)pci_resource_start(pcidev
, BAR_0
),
475 (long unsigned int)pci_resource_len(pcidev
, BAR_0
));
476 nes_debug(NES_DBG_INIT
, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
477 (long unsigned int)pci_resource_start(pcidev
, BAR_1
),
478 (long unsigned int)pci_resource_len(pcidev
, BAR_1
));
480 /* Make sure PCI base addr are MMIO */
481 if (!(pci_resource_flags(pcidev
, BAR_0
) & IORESOURCE_MEM
) ||
482 !(pci_resource_flags(pcidev
, BAR_1
) & IORESOURCE_MEM
)) {
483 printk(KERN_ERR PFX
"PCI regions not an MMIO resource\n");
488 /* Reserve PCI I/O and memory resources */
489 ret
= pci_request_regions(pcidev
, DRV_NAME
);
491 printk(KERN_ERR PFX
"Unable to request regions. (%s)\n", pci_name(pcidev
));
495 if ((sizeof(dma_addr_t
) > 4)) {
496 ret
= pci_set_dma_mask(pcidev
, DMA_64BIT_MASK
);
498 printk(KERN_ERR PFX
"64b DMA mask configuration failed\n");
501 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_64BIT_MASK
);
503 printk(KERN_ERR PFX
"64b DMA consistent mask configuration failed\n");
507 ret
= pci_set_dma_mask(pcidev
, DMA_32BIT_MASK
);
509 printk(KERN_ERR PFX
"32b DMA mask configuration failed\n");
512 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_32BIT_MASK
);
514 printk(KERN_ERR PFX
"32b DMA consistent mask configuration failed\n");
519 pci_set_master(pcidev
);
521 /* Allocate hardware structure */
522 nesdev
= kzalloc(sizeof(struct nes_device
), GFP_KERNEL
);
524 printk(KERN_ERR PFX
"%s: Unable to alloc hardware struct\n", pci_name(pcidev
));
529 nes_debug(NES_DBG_INIT
, "Allocated nes device at %p\n", nesdev
);
530 nesdev
->pcidev
= pcidev
;
531 pci_set_drvdata(pcidev
, nesdev
);
533 pci_read_config_byte(pcidev
, 0x0008, &hw_rev
);
534 nes_debug(NES_DBG_INIT
, "hw_rev=%u\n", hw_rev
);
536 spin_lock_init(&nesdev
->indexed_regs_lock
);
538 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
539 mmio_regs
= ioremap_nocache(pci_resource_start(pcidev
, BAR_0
), sizeof(mmio_regs
));
540 if (mmio_regs
== NULL
) {
541 printk(KERN_ERR PFX
"Unable to remap BAR0\n");
545 nesdev
->regs
= mmio_regs
;
546 nesdev
->index_reg
= 0x50 + (PCI_FUNC(pcidev
->devfn
)*8) + mmio_regs
;
548 /* Ensure interrupts are disabled */
549 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x7fffffff);
551 if (nes_drv_opt
& NES_DRV_OPT_ENABLE_MSI
) {
552 if (!pci_enable_msi(nesdev
->pcidev
)) {
553 nesdev
->msi_enabled
= 1;
554 nes_debug(NES_DBG_INIT
, "MSI is enabled for device %s\n",
557 nes_debug(NES_DBG_INIT
, "MSI is disabled by linux for device %s\n",
561 nes_debug(NES_DBG_INIT
, "MSI not requested due to driver options for device %s\n",
565 nesdev
->csr_start
= pci_resource_start(nesdev
->pcidev
, BAR_0
);
566 nesdev
->doorbell_region
= pci_resource_start(nesdev
->pcidev
, BAR_1
);
568 /* Init the adapter */
569 nesdev
->nesadapter
= nes_init_adapter(nesdev
, hw_rev
);
570 if (!nesdev
->nesadapter
) {
571 printk(KERN_ERR PFX
"Unable to initialize adapter.\n");
575 nesdev
->nesadapter
->et_rx_coalesce_usecs_irq
= interrupt_mod_interval
;
577 /* nesdev->base_doorbell_index =
578 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
579 nesdev
->base_doorbell_index
= 1;
580 nesdev
->doorbell_start
= nesdev
->nesadapter
->doorbell_start
;
581 nesdev
->mac_index
= PCI_FUNC(nesdev
->pcidev
->devfn
) % nesdev
->nesadapter
->port_count
;
583 tasklet_init(&nesdev
->dpc_tasklet
, nes_dpc
, (unsigned long)nesdev
);
585 /* bring up the Control QP */
586 if (nes_init_cqp(nesdev
)) {
592 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
593 PCI_FUNC(nesdev
->pcidev
->devfn
));
594 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
596 /* Enable the interrupts */
597 nesdev
->int_req
= (0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
)) |
598 (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
599 if (PCI_FUNC(nesdev
->pcidev
->devfn
) < 4) {
600 nesdev
->int_req
|= (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+24));
603 /* TODO: This really should be the first driver to load, not function 0 */
604 if (PCI_FUNC(nesdev
->pcidev
->devfn
) == 0) {
605 /* pick up PCI and critical errors if the first driver to load */
606 nesdev
->intf_int_req
= NES_INTF_INT_PCIERR
| NES_INTF_INT_CRITERR
;
607 nesdev
->int_req
|= NES_INT_INTF
;
609 nesdev
->intf_int_req
= 0;
611 nesdev
->intf_int_req
|= (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
612 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS0
, 0);
613 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS1
, 0);
614 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS2
, 0x00001265);
615 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS4
, 0x18021804);
617 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS3
, 0x17801790);
619 /* deal with both periodic and one_shot */
620 nesdev
->timer_int_req
= 0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
);
621 nesdev
->nesadapter
->timer_int_req
|= nesdev
->timer_int_req
;
622 nes_debug(NES_DBG_INIT
, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
623 PCI_FUNC(nesdev
->pcidev
->devfn
),
624 nesdev
->timer_int_req
, nesdev
->nesadapter
->timer_int_req
);
626 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
628 list_add_tail(&nesdev
->list
, &nes_dev_list
);
630 /* Request an interrupt line for the driver */
631 ret
= request_irq(pcidev
->irq
, nes_interrupt
, IRQF_SHARED
, DRV_NAME
, nesdev
);
633 printk(KERN_ERR PFX
"%s: requested IRQ %u is busy\n",
634 pci_name(pcidev
), pcidev
->irq
);
638 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
640 if (nes_notifiers_registered
== 0) {
641 register_inetaddr_notifier(&nes_inetaddr_notifier
);
642 register_netevent_notifier(&nes_net_notifier
);
644 nes_notifiers_registered
++;
646 /* Initialize network devices */
647 if ((netdev
= nes_netdev_init(nesdev
, mmio_regs
)) == NULL
) {
651 /* Register network device */
652 ret
= register_netdev(netdev
);
654 printk(KERN_ERR PFX
"Unable to register netdev, ret = %d\n", ret
);
655 nes_netdev_destroy(netdev
);
659 nes_print_macaddr(netdev
);
660 /* create a CM core for this netdev */
661 nesvnic
= netdev_priv(netdev
);
663 nesdev
->netdev_count
++;
664 nesdev
->nesadapter
->netdev_count
++;
667 printk(KERN_ERR PFX
"%s: NetEffect RNIC driver successfully loaded.\n",
672 printk(KERN_ERR PFX
"bail7\n");
673 while (nesdev
->netdev_count
> 0) {
674 nesdev
->netdev_count
--;
675 nesdev
->nesadapter
->netdev_count
--;
677 unregister_netdev(nesdev
->netdev
[nesdev
->netdev_count
]);
678 nes_netdev_destroy(nesdev
->netdev
[nesdev
->netdev_count
]);
681 nes_debug(NES_DBG_INIT
, "netdev_count=%d, nesadapter->netdev_count=%d\n",
682 nesdev
->netdev_count
, nesdev
->nesadapter
->netdev_count
);
684 nes_notifiers_registered
--;
685 if (nes_notifiers_registered
== 0) {
686 unregister_netevent_notifier(&nes_net_notifier
);
687 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
690 list_del(&nesdev
->list
);
691 nes_destroy_cqp(nesdev
);
694 printk(KERN_ERR PFX
"bail65\n");
695 free_irq(pcidev
->irq
, nesdev
);
696 if (nesdev
->msi_enabled
) {
697 pci_disable_msi(pcidev
);
700 printk(KERN_ERR PFX
"bail6\n");
701 tasklet_kill(&nesdev
->dpc_tasklet
);
702 /* Deallocate the Adapter Structure */
703 nes_destroy_adapter(nesdev
->nesadapter
);
706 printk(KERN_ERR PFX
"bail5\n");
707 iounmap(nesdev
->regs
);
710 printk(KERN_ERR PFX
"bail3\n");
714 pci_release_regions(pcidev
);
717 pci_disable_device(pcidev
);
725 * nes_remove - unload from kernel
727 static void __devexit
nes_remove(struct pci_dev
*pcidev
)
729 struct nes_device
*nesdev
= pci_get_drvdata(pcidev
);
730 struct net_device
*netdev
;
731 int netdev_index
= 0;
733 if (nesdev
->netdev_count
) {
734 netdev
= nesdev
->netdev
[netdev_index
];
736 netif_stop_queue(netdev
);
737 unregister_netdev(netdev
);
738 nes_netdev_destroy(netdev
);
740 nesdev
->netdev
[netdev_index
] = NULL
;
741 nesdev
->netdev_count
--;
742 nesdev
->nesadapter
->netdev_count
--;
746 nes_notifiers_registered
--;
747 if (nes_notifiers_registered
== 0) {
748 unregister_netevent_notifier(&nes_net_notifier
);
749 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
752 list_del(&nesdev
->list
);
753 nes_destroy_cqp(nesdev
);
754 tasklet_kill(&nesdev
->dpc_tasklet
);
756 /* Deallocate the Adapter Structure */
757 nes_destroy_adapter(nesdev
->nesadapter
);
759 free_irq(pcidev
->irq
, nesdev
);
761 if (nesdev
->msi_enabled
) {
762 pci_disable_msi(pcidev
);
765 iounmap(nesdev
->regs
);
768 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
769 pci_release_regions(pcidev
);
770 pci_disable_device(pcidev
);
771 pci_set_drvdata(pcidev
, NULL
);
775 static struct pci_driver nes_pci_driver
= {
777 .id_table
= nes_pci_table
,
779 .remove
= __devexit_p(nes_remove
),
782 static ssize_t
nes_show_adapter(struct device_driver
*ddp
, char *buf
)
784 unsigned int devfn
= 0xffffffff;
785 unsigned char bus_number
= 0xff;
787 struct nes_device
*nesdev
;
789 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
790 if (i
== ee_flsh_adapter
) {
791 devfn
= nesdev
->nesadapter
->devfn
;
792 bus_number
= nesdev
->nesadapter
->bus_number
;
798 return snprintf(buf
, PAGE_SIZE
, "%x:%x", bus_number
, devfn
);
801 static ssize_t
nes_store_adapter(struct device_driver
*ddp
,
802 const char *buf
, size_t count
)
804 char *p
= (char *)buf
;
806 ee_flsh_adapter
= simple_strtoul(p
, &p
, 10);
807 return strnlen(buf
, count
);
810 static ssize_t
nes_show_ee_cmd(struct device_driver
*ddp
, char *buf
)
812 u32 eeprom_cmd
= 0xdead;
814 struct nes_device
*nesdev
;
816 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
817 if (i
== ee_flsh_adapter
) {
818 eeprom_cmd
= nes_read32(nesdev
->regs
+ NES_EEPROM_COMMAND
);
823 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_cmd
);
826 static ssize_t
nes_store_ee_cmd(struct device_driver
*ddp
,
827 const char *buf
, size_t count
)
829 char *p
= (char *)buf
;
832 struct nes_device
*nesdev
;
834 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
835 val
= simple_strtoul(p
, &p
, 16);
836 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
837 if (i
== ee_flsh_adapter
) {
838 nes_write32(nesdev
->regs
+ NES_EEPROM_COMMAND
, val
);
844 return strnlen(buf
, count
);
847 static ssize_t
nes_show_ee_data(struct device_driver
*ddp
, char *buf
)
849 u32 eeprom_data
= 0xdead;
851 struct nes_device
*nesdev
;
853 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
854 if (i
== ee_flsh_adapter
) {
855 eeprom_data
= nes_read32(nesdev
->regs
+ NES_EEPROM_DATA
);
861 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_data
);
864 static ssize_t
nes_store_ee_data(struct device_driver
*ddp
,
865 const char *buf
, size_t count
)
867 char *p
= (char *)buf
;
870 struct nes_device
*nesdev
;
872 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
873 val
= simple_strtoul(p
, &p
, 16);
874 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
875 if (i
== ee_flsh_adapter
) {
876 nes_write32(nesdev
->regs
+ NES_EEPROM_DATA
, val
);
882 return strnlen(buf
, count
);
885 static ssize_t
nes_show_flash_cmd(struct device_driver
*ddp
, char *buf
)
887 u32 flash_cmd
= 0xdead;
889 struct nes_device
*nesdev
;
891 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
892 if (i
== ee_flsh_adapter
) {
893 flash_cmd
= nes_read32(nesdev
->regs
+ NES_FLASH_COMMAND
);
899 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_cmd
);
902 static ssize_t
nes_store_flash_cmd(struct device_driver
*ddp
,
903 const char *buf
, size_t count
)
905 char *p
= (char *)buf
;
908 struct nes_device
*nesdev
;
910 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
911 val
= simple_strtoul(p
, &p
, 16);
912 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
913 if (i
== ee_flsh_adapter
) {
914 nes_write32(nesdev
->regs
+ NES_FLASH_COMMAND
, val
);
920 return strnlen(buf
, count
);
923 static ssize_t
nes_show_flash_data(struct device_driver
*ddp
, char *buf
)
925 u32 flash_data
= 0xdead;
927 struct nes_device
*nesdev
;
929 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
930 if (i
== ee_flsh_adapter
) {
931 flash_data
= nes_read32(nesdev
->regs
+ NES_FLASH_DATA
);
937 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_data
);
940 static ssize_t
nes_store_flash_data(struct device_driver
*ddp
,
941 const char *buf
, size_t count
)
943 char *p
= (char *)buf
;
946 struct nes_device
*nesdev
;
948 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
949 val
= simple_strtoul(p
, &p
, 16);
950 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
951 if (i
== ee_flsh_adapter
) {
952 nes_write32(nesdev
->regs
+ NES_FLASH_DATA
, val
);
958 return strnlen(buf
, count
);
961 static ssize_t
nes_show_nonidx_addr(struct device_driver
*ddp
, char *buf
)
963 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_nonidx_addr
);
966 static ssize_t
nes_store_nonidx_addr(struct device_driver
*ddp
,
967 const char *buf
, size_t count
)
969 char *p
= (char *)buf
;
971 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
972 sysfs_nonidx_addr
= simple_strtoul(p
, &p
, 16);
974 return strnlen(buf
, count
);
977 static ssize_t
nes_show_nonidx_data(struct device_driver
*ddp
, char *buf
)
979 u32 nonidx_data
= 0xdead;
981 struct nes_device
*nesdev
;
983 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
984 if (i
== ee_flsh_adapter
) {
985 nonidx_data
= nes_read32(nesdev
->regs
+ sysfs_nonidx_addr
);
991 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", nonidx_data
);
994 static ssize_t
nes_store_nonidx_data(struct device_driver
*ddp
,
995 const char *buf
, size_t count
)
997 char *p
= (char *)buf
;
1000 struct nes_device
*nesdev
;
1002 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1003 val
= simple_strtoul(p
, &p
, 16);
1004 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1005 if (i
== ee_flsh_adapter
) {
1006 nes_write32(nesdev
->regs
+ sysfs_nonidx_addr
, val
);
1012 return strnlen(buf
, count
);
1015 static ssize_t
nes_show_idx_addr(struct device_driver
*ddp
, char *buf
)
1017 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_idx_addr
);
1020 static ssize_t
nes_store_idx_addr(struct device_driver
*ddp
,
1021 const char *buf
, size_t count
)
1023 char *p
= (char *)buf
;
1025 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
1026 sysfs_idx_addr
= simple_strtoul(p
, &p
, 16);
1028 return strnlen(buf
, count
);
1031 static ssize_t
nes_show_idx_data(struct device_driver
*ddp
, char *buf
)
1033 u32 idx_data
= 0xdead;
1035 struct nes_device
*nesdev
;
1037 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1038 if (i
== ee_flsh_adapter
) {
1039 idx_data
= nes_read_indexed(nesdev
, sysfs_idx_addr
);
1045 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", idx_data
);
1048 static ssize_t
nes_store_idx_data(struct device_driver
*ddp
,
1049 const char *buf
, size_t count
)
1051 char *p
= (char *)buf
;
1054 struct nes_device
*nesdev
;
1056 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1057 val
= simple_strtoul(p
, &p
, 16);
1058 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1059 if (i
== ee_flsh_adapter
) {
1060 nes_write_indexed(nesdev
, sysfs_idx_addr
, val
);
1066 return strnlen(buf
, count
);
1069 static DRIVER_ATTR(adapter
, S_IRUSR
| S_IWUSR
,
1070 nes_show_adapter
, nes_store_adapter
);
1071 static DRIVER_ATTR(eeprom_cmd
, S_IRUSR
| S_IWUSR
,
1072 nes_show_ee_cmd
, nes_store_ee_cmd
);
1073 static DRIVER_ATTR(eeprom_data
, S_IRUSR
| S_IWUSR
,
1074 nes_show_ee_data
, nes_store_ee_data
);
1075 static DRIVER_ATTR(flash_cmd
, S_IRUSR
| S_IWUSR
,
1076 nes_show_flash_cmd
, nes_store_flash_cmd
);
1077 static DRIVER_ATTR(flash_data
, S_IRUSR
| S_IWUSR
,
1078 nes_show_flash_data
, nes_store_flash_data
);
1079 static DRIVER_ATTR(nonidx_addr
, S_IRUSR
| S_IWUSR
,
1080 nes_show_nonidx_addr
, nes_store_nonidx_addr
);
1081 static DRIVER_ATTR(nonidx_data
, S_IRUSR
| S_IWUSR
,
1082 nes_show_nonidx_data
, nes_store_nonidx_data
);
1083 static DRIVER_ATTR(idx_addr
, S_IRUSR
| S_IWUSR
,
1084 nes_show_idx_addr
, nes_store_idx_addr
);
1085 static DRIVER_ATTR(idx_data
, S_IRUSR
| S_IWUSR
,
1086 nes_show_idx_data
, nes_store_idx_data
);
1088 static int nes_create_driver_sysfs(struct pci_driver
*drv
)
1091 error
= driver_create_file(&drv
->driver
, &driver_attr_adapter
);
1092 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1093 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_data
);
1094 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_cmd
);
1095 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_data
);
1096 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1097 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_data
);
1098 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_addr
);
1099 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_data
);
1103 static void nes_remove_driver_sysfs(struct pci_driver
*drv
)
1105 driver_remove_file(&drv
->driver
, &driver_attr_adapter
);
1106 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1107 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_data
);
1108 driver_remove_file(&drv
->driver
, &driver_attr_flash_cmd
);
1109 driver_remove_file(&drv
->driver
, &driver_attr_flash_data
);
1110 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1111 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_data
);
1112 driver_remove_file(&drv
->driver
, &driver_attr_idx_addr
);
1113 driver_remove_file(&drv
->driver
, &driver_attr_idx_data
);
1117 * nes_init_module - module initialization entry point
1119 static int __init
nes_init_module(void)
1124 retval
= nes_cm_start();
1126 printk(KERN_ERR PFX
"Unable to start NetEffect iWARP CM.\n");
1129 retval
= pci_register_driver(&nes_pci_driver
);
1131 retval1
= nes_create_driver_sysfs(&nes_pci_driver
);
1133 printk(KERN_ERR PFX
"Unable to create NetEffect sys files.\n");
1140 * nes_exit_module - module unload entry point
1142 static void __exit
nes_exit_module(void)
1145 nes_remove_driver_sysfs(&nes_pci_driver
);
1147 pci_unregister_driver(&nes_pci_driver
);
1151 module_init(nes_init_module
);
1152 module_exit(nes_exit_module
);