2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
40 #include <linux/if_vlan.h>
41 #include <linux/crc32.h>
44 #include <linux/init.h>
45 #include <linux/if_arp.h>
46 #include <linux/highmem.h>
49 #include <asm/byteorder.h>
50 #include <rdma/ib_smi.h>
51 #include <rdma/ib_verbs.h>
52 #include <rdma/ib_pack.h>
53 #include <rdma/iw_cm.h>
57 #include <net/netevent.h>
58 #include <net/neighbour.h>
59 #include <linux/route.h>
60 #include <net/ip_fib.h>
62 MODULE_AUTHOR("NetEffect");
63 MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
64 MODULE_LICENSE("Dual BSD/GPL");
65 MODULE_VERSION(DRV_VERSION
);
68 int interrupt_mod_interval
= 0;
71 /* Interoperability */
73 module_param(mpa_version
, int, 0644);
74 MODULE_PARM_DESC(mpa_version
, "MPA version to be used int MPA Req/Resp (0 or 1)");
76 /* Interoperability */
77 int disable_mpa_crc
= 0;
78 module_param(disable_mpa_crc
, int, 0644);
79 MODULE_PARM_DESC(disable_mpa_crc
, "Disable checking of MPA CRC");
81 unsigned int send_first
= 0;
82 module_param(send_first
, int, 0644);
83 MODULE_PARM_DESC(send_first
, "Send RDMA Message First on Active Connection");
86 unsigned int nes_drv_opt
= 0;
87 module_param(nes_drv_opt
, int, 0644);
88 MODULE_PARM_DESC(nes_drv_opt
, "Driver option parameters");
90 unsigned int nes_debug_level
= 0;
91 module_param_named(debug_level
, nes_debug_level
, uint
, 0644);
92 MODULE_PARM_DESC(debug_level
, "Enable debug output level");
94 LIST_HEAD(nes_adapter_list
);
95 static LIST_HEAD(nes_dev_list
);
97 atomic_t qps_destroyed
;
99 static unsigned int ee_flsh_adapter
;
100 static unsigned int sysfs_nonidx_addr
;
101 static unsigned int sysfs_idx_addr
;
103 static struct pci_device_id nes_pci_table
[] = {
104 {PCI_VENDOR_ID_NETEFFECT
, PCI_DEVICE_ID_NETEFFECT_NE020
, PCI_ANY_ID
, PCI_ANY_ID
},
108 MODULE_DEVICE_TABLE(pci
, nes_pci_table
);
110 static int nes_inetaddr_event(struct notifier_block
*, unsigned long, void *);
111 static int nes_net_event(struct notifier_block
*, unsigned long, void *);
112 static int nes_notifiers_registered
;
115 static struct notifier_block nes_inetaddr_notifier
= {
116 .notifier_call
= nes_inetaddr_event
119 static struct notifier_block nes_net_notifier
= {
120 .notifier_call
= nes_net_event
129 static int nes_inetaddr_event(struct notifier_block
*notifier
,
130 unsigned long event
, void *ptr
)
132 struct in_ifaddr
*ifa
= ptr
;
133 struct net_device
*event_netdev
= ifa
->ifa_dev
->dev
;
134 struct nes_device
*nesdev
;
135 struct net_device
*netdev
;
136 struct nes_vnic
*nesvnic
;
140 addr
= ntohl(ifa
->ifa_address
);
141 mask
= ntohl(ifa
->ifa_mask
);
142 nes_debug(NES_DBG_NETDEV
, "nes_inetaddr_event: ip address " NIPQUAD_FMT
143 ", netmask " NIPQUAD_FMT
".\n",
144 HIPQUAD(addr
), HIPQUAD(mask
));
145 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
146 nes_debug(NES_DBG_NETDEV
, "Nesdev list entry = 0x%p. (%s)\n",
147 nesdev
, nesdev
->netdev
[0]->name
);
148 netdev
= nesdev
->netdev
[0];
149 nesvnic
= netdev_priv(netdev
);
150 if (netdev
== event_netdev
) {
151 if (nesvnic
->rdma_enabled
== 0) {
152 nes_debug(NES_DBG_NETDEV
, "Returning without processing event for %s since"
153 " RDMA is not enabled.\n",
157 /* we have ifa->ifa_address/mask here if we need it */
160 nes_debug(NES_DBG_NETDEV
, "event:DOWN\n");
161 nes_write_indexed(nesdev
,
162 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)), 0);
164 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
165 ntohl(nesvnic
->local_ipaddr
), NES_ARP_DELETE
);
166 nesvnic
->local_ipaddr
= 0;
170 nes_debug(NES_DBG_NETDEV
, "event:UP\n");
172 if (nesvnic
->local_ipaddr
!= 0) {
173 nes_debug(NES_DBG_NETDEV
, "Interface already has local_ipaddr\n");
176 /* Add the address to the IP table */
177 nesvnic
->local_ipaddr
= ifa
->ifa_address
;
179 nes_write_indexed(nesdev
,
180 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)),
181 ntohl(ifa
->ifa_address
));
182 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
183 ntohl(nesvnic
->local_ipaddr
), NES_ARP_ADD
);
199 static int nes_net_event(struct notifier_block
*notifier
,
200 unsigned long event
, void *ptr
)
202 struct neighbour
*neigh
= ptr
;
203 struct nes_device
*nesdev
;
204 struct net_device
*netdev
;
205 struct nes_vnic
*nesvnic
;
208 case NETEVENT_NEIGH_UPDATE
:
209 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
210 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
211 netdev
= nesdev
->netdev
[0];
212 nesvnic
= netdev_priv(netdev
);
213 if (netdev
== neigh
->dev
) {
214 if (nesvnic
->rdma_enabled
== 0) {
215 nes_debug(NES_DBG_NETDEV
, "Skipping device %s since no RDMA\n",
218 if (neigh
->nud_state
& NUD_VALID
) {
219 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
220 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_ADD
);
222 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
223 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_DELETE
);
231 nes_debug(NES_DBG_NETDEV
, "NETEVENT_ %lu undefined\n", event
);
242 void nes_add_ref(struct ib_qp
*ibqp
)
244 struct nes_qp
*nesqp
;
246 nesqp
= to_nesqp(ibqp
);
247 nes_debug(NES_DBG_QP
, "Bumping refcount for QP%u. Pre-inc value = %u\n",
248 ibqp
->qp_num
, atomic_read(&nesqp
->refcount
));
249 atomic_inc(&nesqp
->refcount
);
252 static void nes_cqp_rem_ref_callback(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
255 struct nes_qp
*nesqp
= cqp_request
->cqp_callback_pointer
;
256 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
259 atomic_inc(&qps_destroyed
);
261 /* Free the control structures */
263 qp_id
= nesqp
->hwqp
.qp_id
;
264 if (nesqp
->pbl_vbase
) {
265 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
266 nesqp
->hwqp
.q2_vbase
, nesqp
->hwqp
.q2_pbase
);
267 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
268 nesadapter
->free_256pbl
++;
269 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
270 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
271 nesqp
->pbl_vbase
= NULL
;
274 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
275 nesqp
->hwqp
.sq_vbase
, nesqp
->hwqp
.sq_pbase
);
277 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, nesqp
->hwqp
.qp_id
);
279 nesadapter
->qp_table
[nesqp
->hwqp
.qp_id
-NES_FIRST_QPN
] = NULL
;
280 kfree(nesqp
->allocated_buffer
);
287 void nes_rem_ref(struct ib_qp
*ibqp
)
290 struct nes_qp
*nesqp
;
291 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
292 struct nes_device
*nesdev
= nesvnic
->nesdev
;
293 struct nes_hw_cqp_wqe
*cqp_wqe
;
294 struct nes_cqp_request
*cqp_request
;
297 nesqp
= to_nesqp(ibqp
);
299 if (atomic_read(&nesqp
->refcount
) == 0) {
300 printk(KERN_INFO PFX
"%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
301 __func__
, ibqp
->qp_num
, nesqp
->last_aeq
);
305 if (atomic_dec_and_test(&nesqp
->refcount
)) {
307 cqp_request
= nes_get_cqp_request(nesdev
);
308 if (cqp_request
== NULL
) {
309 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
312 cqp_request
->waiting
= 0;
313 cqp_request
->callback
= 1;
314 cqp_request
->cqp_callback
= nes_cqp_rem_ref_callback
;
315 cqp_request
->cqp_callback_pointer
= nesqp
;
316 cqp_wqe
= &cqp_request
->cqp_wqe
;
318 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
319 opcode
= NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_IWARP
;
321 if (nesqp
->hte_added
) {
322 opcode
|= NES_CQP_QP_DEL_HTE
;
323 nesqp
->hte_added
= 0;
325 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
326 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
327 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
328 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
329 nes_post_cqp_request(nesdev
, cqp_request
);
337 struct ib_qp
*nes_get_qp(struct ib_device
*device
, int qpn
)
339 struct nes_vnic
*nesvnic
= to_nesvnic(device
);
340 struct nes_device
*nesdev
= nesvnic
->nesdev
;
341 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
343 if ((qpn
< NES_FIRST_QPN
) || (qpn
>= (NES_FIRST_QPN
+ nesadapter
->max_qp
)))
346 return &nesadapter
->qp_table
[qpn
- NES_FIRST_QPN
]->ibqp
;
353 static void nes_print_macaddr(struct net_device
*netdev
)
355 DECLARE_MAC_BUF(mac
);
357 nes_debug(NES_DBG_INIT
, "%s: %s, IRQ %u\n",
358 netdev
->name
, print_mac(mac
, netdev
->dev_addr
), netdev
->irq
);
362 * nes_interrupt - handle interrupts
364 static irqreturn_t
nes_interrupt(int irq
, void *dev_id
)
366 struct nes_device
*nesdev
= (struct nes_device
*)dev_id
;
374 if (nesdev
->msi_enabled
) {
375 /* No need to read the interrupt pending register if msi is enabled */
378 if (unlikely(nesdev
->nesadapter
->hw_rev
== NE020_REV
)) {
379 /* Master interrupt enable provides synchronization for kicking off bottom half
380 when interrupt sharing is going on */
381 int_mask
= nes_read32(nesdev
->regs
+ NES_INT_MASK
);
382 if (int_mask
& 0x80000000) {
383 /* Check interrupt status to see if this might be ours */
384 int_stat
= nes_read32(nesdev
->regs
+ NES_INT_STAT
);
385 int_req
= nesdev
->int_req
;
386 if (int_stat
&int_req
) {
387 /* if interesting CEQ or AEQ is pending, claim the interrupt */
388 if ((int_stat
&int_req
) & (~(NES_INT_TIMER
|NES_INT_INTF
))) {
391 if (((int_stat
& int_req
) & NES_INT_TIMER
) == NES_INT_TIMER
) {
392 /* Timer might be running but might be for another function */
393 timer_stat
= nes_read32(nesdev
->regs
+ NES_TIMER_STAT
);
394 if ((timer_stat
& nesdev
->timer_int_req
) != 0) {
398 if ((((int_stat
& int_req
) & NES_INT_INTF
) == NES_INT_INTF
) &&
400 intf_int_stat
= nes_read32(nesdev
->regs
+NES_INTF_INT_STAT
);
401 if ((intf_int_stat
& nesdev
->intf_int_req
) != 0) {
407 nes_write32(nesdev
->regs
+NES_INT_MASK
, int_mask
& (~0x80000000));
408 int_mask
= nes_read32(nesdev
->regs
+NES_INT_MASK
);
409 /* Save off the status to save an additional read */
410 nesdev
->int_stat
= int_stat
;
411 nesdev
->napi_isr_ran
= 1;
416 handled
= nes_read32(nesdev
->regs
+NES_INT_PENDING
);
422 if (nes_napi_isr(nesdev
) == 0) {
423 tasklet_schedule(&nesdev
->dpc_tasklet
);
434 * nes_probe - Device initialization
436 static int __devinit
nes_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*ent
)
438 struct net_device
*netdev
= NULL
;
439 struct nes_device
*nesdev
= NULL
;
441 struct nes_vnic
*nesvnic
= NULL
;
442 void __iomem
*mmio_regs
= NULL
;
445 assert(pcidev
!= NULL
);
448 printk(KERN_INFO PFX
"NetEffect RNIC driver v%s loading. (%s)\n",
449 DRV_VERSION
, pci_name(pcidev
));
451 ret
= pci_enable_device(pcidev
);
453 printk(KERN_ERR PFX
"Unable to enable PCI device. (%s)\n", pci_name(pcidev
));
457 nes_debug(NES_DBG_INIT
, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
458 (long unsigned int)pci_resource_start(pcidev
, BAR_0
),
459 (long unsigned int)pci_resource_len(pcidev
, BAR_0
));
460 nes_debug(NES_DBG_INIT
, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
461 (long unsigned int)pci_resource_start(pcidev
, BAR_1
),
462 (long unsigned int)pci_resource_len(pcidev
, BAR_1
));
464 /* Make sure PCI base addr are MMIO */
465 if (!(pci_resource_flags(pcidev
, BAR_0
) & IORESOURCE_MEM
) ||
466 !(pci_resource_flags(pcidev
, BAR_1
) & IORESOURCE_MEM
)) {
467 printk(KERN_ERR PFX
"PCI regions not an MMIO resource\n");
472 /* Reserve PCI I/O and memory resources */
473 ret
= pci_request_regions(pcidev
, DRV_NAME
);
475 printk(KERN_ERR PFX
"Unable to request regions. (%s)\n", pci_name(pcidev
));
479 if ((sizeof(dma_addr_t
) > 4)) {
480 ret
= pci_set_dma_mask(pcidev
, DMA_64BIT_MASK
);
482 printk(KERN_ERR PFX
"64b DMA mask configuration failed\n");
485 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_64BIT_MASK
);
487 printk(KERN_ERR PFX
"64b DMA consistent mask configuration failed\n");
491 ret
= pci_set_dma_mask(pcidev
, DMA_32BIT_MASK
);
493 printk(KERN_ERR PFX
"32b DMA mask configuration failed\n");
496 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_32BIT_MASK
);
498 printk(KERN_ERR PFX
"32b DMA consistent mask configuration failed\n");
503 pci_set_master(pcidev
);
505 /* Allocate hardware structure */
506 nesdev
= kzalloc(sizeof(struct nes_device
), GFP_KERNEL
);
508 printk(KERN_ERR PFX
"%s: Unable to alloc hardware struct\n", pci_name(pcidev
));
513 nes_debug(NES_DBG_INIT
, "Allocated nes device at %p\n", nesdev
);
514 nesdev
->pcidev
= pcidev
;
515 pci_set_drvdata(pcidev
, nesdev
);
517 pci_read_config_byte(pcidev
, 0x0008, &hw_rev
);
518 nes_debug(NES_DBG_INIT
, "hw_rev=%u\n", hw_rev
);
520 spin_lock_init(&nesdev
->indexed_regs_lock
);
522 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
523 mmio_regs
= ioremap_nocache(pci_resource_start(pcidev
, BAR_0
), sizeof(mmio_regs
));
524 if (mmio_regs
== NULL
) {
525 printk(KERN_ERR PFX
"Unable to remap BAR0\n");
529 nesdev
->regs
= mmio_regs
;
530 nesdev
->index_reg
= 0x50 + (PCI_FUNC(pcidev
->devfn
)*8) + mmio_regs
;
532 /* Ensure interrupts are disabled */
533 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x7fffffff);
535 if (nes_drv_opt
& NES_DRV_OPT_ENABLE_MSI
) {
536 if (!pci_enable_msi(nesdev
->pcidev
)) {
537 nesdev
->msi_enabled
= 1;
538 nes_debug(NES_DBG_INIT
, "MSI is enabled for device %s\n",
541 nes_debug(NES_DBG_INIT
, "MSI is disabled by linux for device %s\n",
545 nes_debug(NES_DBG_INIT
, "MSI not requested due to driver options for device %s\n",
549 nesdev
->csr_start
= pci_resource_start(nesdev
->pcidev
, BAR_0
);
550 nesdev
->doorbell_region
= pci_resource_start(nesdev
->pcidev
, BAR_1
);
552 /* Init the adapter */
553 nesdev
->nesadapter
= nes_init_adapter(nesdev
, hw_rev
);
554 if (!nesdev
->nesadapter
) {
555 printk(KERN_ERR PFX
"Unable to initialize adapter.\n");
559 nesdev
->nesadapter
->et_rx_coalesce_usecs_irq
= interrupt_mod_interval
;
561 /* nesdev->base_doorbell_index =
562 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
563 nesdev
->base_doorbell_index
= 1;
564 nesdev
->doorbell_start
= nesdev
->nesadapter
->doorbell_start
;
565 if (nesdev
->nesadapter
->phy_type
[0] == NES_PHY_TYPE_PUMA_1G
) {
566 switch (PCI_FUNC(nesdev
->pcidev
->devfn
) %
567 nesdev
->nesadapter
->port_count
) {
569 nesdev
->mac_index
= 2;
572 nesdev
->mac_index
= 1;
575 nesdev
->mac_index
= 3;
579 nesdev
->mac_index
= 0;
582 nesdev
->mac_index
= PCI_FUNC(nesdev
->pcidev
->devfn
) %
583 nesdev
->nesadapter
->port_count
;
586 tasklet_init(&nesdev
->dpc_tasklet
, nes_dpc
, (unsigned long)nesdev
);
588 /* bring up the Control QP */
589 if (nes_init_cqp(nesdev
)) {
595 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
596 PCI_FUNC(nesdev
->pcidev
->devfn
));
597 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
599 /* Enable the interrupts */
600 nesdev
->int_req
= (0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
)) |
601 (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
602 if (PCI_FUNC(nesdev
->pcidev
->devfn
) < 4) {
603 nesdev
->int_req
|= (1 << (PCI_FUNC(nesdev
->mac_index
)+24));
606 /* TODO: This really should be the first driver to load, not function 0 */
607 if (PCI_FUNC(nesdev
->pcidev
->devfn
) == 0) {
608 /* pick up PCI and critical errors if the first driver to load */
609 nesdev
->intf_int_req
= NES_INTF_INT_PCIERR
| NES_INTF_INT_CRITERR
;
610 nesdev
->int_req
|= NES_INT_INTF
;
612 nesdev
->intf_int_req
= 0;
614 nesdev
->intf_int_req
|= (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
615 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS0
, 0);
616 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS1
, 0);
617 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS2
, 0x00001265);
618 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS4
, 0x18021804);
620 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS3
, 0x17801790);
622 /* deal with both periodic and one_shot */
623 nesdev
->timer_int_req
= 0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
);
624 nesdev
->nesadapter
->timer_int_req
|= nesdev
->timer_int_req
;
625 nes_debug(NES_DBG_INIT
, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
626 PCI_FUNC(nesdev
->pcidev
->devfn
),
627 nesdev
->timer_int_req
, nesdev
->nesadapter
->timer_int_req
);
629 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
631 list_add_tail(&nesdev
->list
, &nes_dev_list
);
633 /* Request an interrupt line for the driver */
634 ret
= request_irq(pcidev
->irq
, nes_interrupt
, IRQF_SHARED
, DRV_NAME
, nesdev
);
636 printk(KERN_ERR PFX
"%s: requested IRQ %u is busy\n",
637 pci_name(pcidev
), pcidev
->irq
);
641 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
643 if (nes_notifiers_registered
== 0) {
644 register_inetaddr_notifier(&nes_inetaddr_notifier
);
645 register_netevent_notifier(&nes_net_notifier
);
647 nes_notifiers_registered
++;
649 /* Initialize network devices */
650 if ((netdev
= nes_netdev_init(nesdev
, mmio_regs
)) == NULL
) {
654 /* Register network device */
655 ret
= register_netdev(netdev
);
657 printk(KERN_ERR PFX
"Unable to register netdev, ret = %d\n", ret
);
658 nes_netdev_destroy(netdev
);
662 nes_print_macaddr(netdev
);
663 /* create a CM core for this netdev */
664 nesvnic
= netdev_priv(netdev
);
666 nesdev
->netdev_count
++;
667 nesdev
->nesadapter
->netdev_count
++;
670 printk(KERN_ERR PFX
"%s: NetEffect RNIC driver successfully loaded.\n",
675 printk(KERN_ERR PFX
"bail7\n");
676 while (nesdev
->netdev_count
> 0) {
677 nesdev
->netdev_count
--;
678 nesdev
->nesadapter
->netdev_count
--;
680 unregister_netdev(nesdev
->netdev
[nesdev
->netdev_count
]);
681 nes_netdev_destroy(nesdev
->netdev
[nesdev
->netdev_count
]);
684 nes_debug(NES_DBG_INIT
, "netdev_count=%d, nesadapter->netdev_count=%d\n",
685 nesdev
->netdev_count
, nesdev
->nesadapter
->netdev_count
);
687 nes_notifiers_registered
--;
688 if (nes_notifiers_registered
== 0) {
689 unregister_netevent_notifier(&nes_net_notifier
);
690 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
693 list_del(&nesdev
->list
);
694 nes_destroy_cqp(nesdev
);
697 printk(KERN_ERR PFX
"bail65\n");
698 free_irq(pcidev
->irq
, nesdev
);
699 if (nesdev
->msi_enabled
) {
700 pci_disable_msi(pcidev
);
703 printk(KERN_ERR PFX
"bail6\n");
704 tasklet_kill(&nesdev
->dpc_tasklet
);
705 /* Deallocate the Adapter Structure */
706 nes_destroy_adapter(nesdev
->nesadapter
);
709 printk(KERN_ERR PFX
"bail5\n");
710 iounmap(nesdev
->regs
);
713 printk(KERN_ERR PFX
"bail3\n");
717 pci_release_regions(pcidev
);
720 pci_disable_device(pcidev
);
728 * nes_remove - unload from kernel
730 static void __devexit
nes_remove(struct pci_dev
*pcidev
)
732 struct nes_device
*nesdev
= pci_get_drvdata(pcidev
);
733 struct net_device
*netdev
;
734 int netdev_index
= 0;
736 if (nesdev
->netdev_count
) {
737 netdev
= nesdev
->netdev
[netdev_index
];
739 netif_stop_queue(netdev
);
740 unregister_netdev(netdev
);
741 nes_netdev_destroy(netdev
);
743 nesdev
->netdev
[netdev_index
] = NULL
;
744 nesdev
->netdev_count
--;
745 nesdev
->nesadapter
->netdev_count
--;
749 nes_notifiers_registered
--;
750 if (nes_notifiers_registered
== 0) {
751 unregister_netevent_notifier(&nes_net_notifier
);
752 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
755 list_del(&nesdev
->list
);
756 nes_destroy_cqp(nesdev
);
758 free_irq(pcidev
->irq
, nesdev
);
759 tasklet_kill(&nesdev
->dpc_tasklet
);
761 /* Deallocate the Adapter Structure */
762 nes_destroy_adapter(nesdev
->nesadapter
);
764 if (nesdev
->msi_enabled
) {
765 pci_disable_msi(pcidev
);
768 iounmap(nesdev
->regs
);
771 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
772 pci_release_regions(pcidev
);
773 pci_disable_device(pcidev
);
774 pci_set_drvdata(pcidev
, NULL
);
778 static struct pci_driver nes_pci_driver
= {
780 .id_table
= nes_pci_table
,
782 .remove
= __devexit_p(nes_remove
),
785 static ssize_t
nes_show_adapter(struct device_driver
*ddp
, char *buf
)
787 unsigned int devfn
= 0xffffffff;
788 unsigned char bus_number
= 0xff;
790 struct nes_device
*nesdev
;
792 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
793 if (i
== ee_flsh_adapter
) {
794 devfn
= nesdev
->pcidev
->devfn
;
795 bus_number
= nesdev
->pcidev
->bus
->number
;
801 return snprintf(buf
, PAGE_SIZE
, "%x:%x\n", bus_number
, devfn
);
804 static ssize_t
nes_store_adapter(struct device_driver
*ddp
,
805 const char *buf
, size_t count
)
807 char *p
= (char *)buf
;
809 ee_flsh_adapter
= simple_strtoul(p
, &p
, 10);
810 return strnlen(buf
, count
);
813 static ssize_t
nes_show_ee_cmd(struct device_driver
*ddp
, char *buf
)
815 u32 eeprom_cmd
= 0xdead;
817 struct nes_device
*nesdev
;
819 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
820 if (i
== ee_flsh_adapter
) {
821 eeprom_cmd
= nes_read32(nesdev
->regs
+ NES_EEPROM_COMMAND
);
826 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_cmd
);
829 static ssize_t
nes_store_ee_cmd(struct device_driver
*ddp
,
830 const char *buf
, size_t count
)
832 char *p
= (char *)buf
;
835 struct nes_device
*nesdev
;
837 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
838 val
= simple_strtoul(p
, &p
, 16);
839 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
840 if (i
== ee_flsh_adapter
) {
841 nes_write32(nesdev
->regs
+ NES_EEPROM_COMMAND
, val
);
847 return strnlen(buf
, count
);
850 static ssize_t
nes_show_ee_data(struct device_driver
*ddp
, char *buf
)
852 u32 eeprom_data
= 0xdead;
854 struct nes_device
*nesdev
;
856 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
857 if (i
== ee_flsh_adapter
) {
858 eeprom_data
= nes_read32(nesdev
->regs
+ NES_EEPROM_DATA
);
864 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_data
);
867 static ssize_t
nes_store_ee_data(struct device_driver
*ddp
,
868 const char *buf
, size_t count
)
870 char *p
= (char *)buf
;
873 struct nes_device
*nesdev
;
875 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
876 val
= simple_strtoul(p
, &p
, 16);
877 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
878 if (i
== ee_flsh_adapter
) {
879 nes_write32(nesdev
->regs
+ NES_EEPROM_DATA
, val
);
885 return strnlen(buf
, count
);
888 static ssize_t
nes_show_flash_cmd(struct device_driver
*ddp
, char *buf
)
890 u32 flash_cmd
= 0xdead;
892 struct nes_device
*nesdev
;
894 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
895 if (i
== ee_flsh_adapter
) {
896 flash_cmd
= nes_read32(nesdev
->regs
+ NES_FLASH_COMMAND
);
902 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_cmd
);
905 static ssize_t
nes_store_flash_cmd(struct device_driver
*ddp
,
906 const char *buf
, size_t count
)
908 char *p
= (char *)buf
;
911 struct nes_device
*nesdev
;
913 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
914 val
= simple_strtoul(p
, &p
, 16);
915 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
916 if (i
== ee_flsh_adapter
) {
917 nes_write32(nesdev
->regs
+ NES_FLASH_COMMAND
, val
);
923 return strnlen(buf
, count
);
926 static ssize_t
nes_show_flash_data(struct device_driver
*ddp
, char *buf
)
928 u32 flash_data
= 0xdead;
930 struct nes_device
*nesdev
;
932 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
933 if (i
== ee_flsh_adapter
) {
934 flash_data
= nes_read32(nesdev
->regs
+ NES_FLASH_DATA
);
940 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_data
);
943 static ssize_t
nes_store_flash_data(struct device_driver
*ddp
,
944 const char *buf
, size_t count
)
946 char *p
= (char *)buf
;
949 struct nes_device
*nesdev
;
951 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
952 val
= simple_strtoul(p
, &p
, 16);
953 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
954 if (i
== ee_flsh_adapter
) {
955 nes_write32(nesdev
->regs
+ NES_FLASH_DATA
, val
);
961 return strnlen(buf
, count
);
964 static ssize_t
nes_show_nonidx_addr(struct device_driver
*ddp
, char *buf
)
966 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_nonidx_addr
);
969 static ssize_t
nes_store_nonidx_addr(struct device_driver
*ddp
,
970 const char *buf
, size_t count
)
972 char *p
= (char *)buf
;
974 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
975 sysfs_nonidx_addr
= simple_strtoul(p
, &p
, 16);
977 return strnlen(buf
, count
);
980 static ssize_t
nes_show_nonidx_data(struct device_driver
*ddp
, char *buf
)
982 u32 nonidx_data
= 0xdead;
984 struct nes_device
*nesdev
;
986 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
987 if (i
== ee_flsh_adapter
) {
988 nonidx_data
= nes_read32(nesdev
->regs
+ sysfs_nonidx_addr
);
994 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", nonidx_data
);
997 static ssize_t
nes_store_nonidx_data(struct device_driver
*ddp
,
998 const char *buf
, size_t count
)
1000 char *p
= (char *)buf
;
1003 struct nes_device
*nesdev
;
1005 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1006 val
= simple_strtoul(p
, &p
, 16);
1007 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1008 if (i
== ee_flsh_adapter
) {
1009 nes_write32(nesdev
->regs
+ sysfs_nonidx_addr
, val
);
1015 return strnlen(buf
, count
);
1018 static ssize_t
nes_show_idx_addr(struct device_driver
*ddp
, char *buf
)
1020 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_idx_addr
);
1023 static ssize_t
nes_store_idx_addr(struct device_driver
*ddp
,
1024 const char *buf
, size_t count
)
1026 char *p
= (char *)buf
;
1028 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
1029 sysfs_idx_addr
= simple_strtoul(p
, &p
, 16);
1031 return strnlen(buf
, count
);
1034 static ssize_t
nes_show_idx_data(struct device_driver
*ddp
, char *buf
)
1036 u32 idx_data
= 0xdead;
1038 struct nes_device
*nesdev
;
1040 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1041 if (i
== ee_flsh_adapter
) {
1042 idx_data
= nes_read_indexed(nesdev
, sysfs_idx_addr
);
1048 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", idx_data
);
1051 static ssize_t
nes_store_idx_data(struct device_driver
*ddp
,
1052 const char *buf
, size_t count
)
1054 char *p
= (char *)buf
;
1057 struct nes_device
*nesdev
;
1059 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1060 val
= simple_strtoul(p
, &p
, 16);
1061 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1062 if (i
== ee_flsh_adapter
) {
1063 nes_write_indexed(nesdev
, sysfs_idx_addr
, val
);
1069 return strnlen(buf
, count
);
1072 static DRIVER_ATTR(adapter
, S_IRUSR
| S_IWUSR
,
1073 nes_show_adapter
, nes_store_adapter
);
1074 static DRIVER_ATTR(eeprom_cmd
, S_IRUSR
| S_IWUSR
,
1075 nes_show_ee_cmd
, nes_store_ee_cmd
);
1076 static DRIVER_ATTR(eeprom_data
, S_IRUSR
| S_IWUSR
,
1077 nes_show_ee_data
, nes_store_ee_data
);
1078 static DRIVER_ATTR(flash_cmd
, S_IRUSR
| S_IWUSR
,
1079 nes_show_flash_cmd
, nes_store_flash_cmd
);
1080 static DRIVER_ATTR(flash_data
, S_IRUSR
| S_IWUSR
,
1081 nes_show_flash_data
, nes_store_flash_data
);
1082 static DRIVER_ATTR(nonidx_addr
, S_IRUSR
| S_IWUSR
,
1083 nes_show_nonidx_addr
, nes_store_nonidx_addr
);
1084 static DRIVER_ATTR(nonidx_data
, S_IRUSR
| S_IWUSR
,
1085 nes_show_nonidx_data
, nes_store_nonidx_data
);
1086 static DRIVER_ATTR(idx_addr
, S_IRUSR
| S_IWUSR
,
1087 nes_show_idx_addr
, nes_store_idx_addr
);
1088 static DRIVER_ATTR(idx_data
, S_IRUSR
| S_IWUSR
,
1089 nes_show_idx_data
, nes_store_idx_data
);
1091 static int nes_create_driver_sysfs(struct pci_driver
*drv
)
1094 error
= driver_create_file(&drv
->driver
, &driver_attr_adapter
);
1095 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1096 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_data
);
1097 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_cmd
);
1098 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_data
);
1099 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1100 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_data
);
1101 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_addr
);
1102 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_data
);
1106 static void nes_remove_driver_sysfs(struct pci_driver
*drv
)
1108 driver_remove_file(&drv
->driver
, &driver_attr_adapter
);
1109 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1110 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_data
);
1111 driver_remove_file(&drv
->driver
, &driver_attr_flash_cmd
);
1112 driver_remove_file(&drv
->driver
, &driver_attr_flash_data
);
1113 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1114 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_data
);
1115 driver_remove_file(&drv
->driver
, &driver_attr_idx_addr
);
1116 driver_remove_file(&drv
->driver
, &driver_attr_idx_data
);
1120 * nes_init_module - module initialization entry point
1122 static int __init
nes_init_module(void)
1127 retval
= nes_cm_start();
1129 printk(KERN_ERR PFX
"Unable to start NetEffect iWARP CM.\n");
1132 retval
= pci_register_driver(&nes_pci_driver
);
1134 retval1
= nes_create_driver_sysfs(&nes_pci_driver
);
1136 printk(KERN_ERR PFX
"Unable to create NetEffect sys files.\n");
1143 * nes_exit_module - module unload entry point
1145 static void __exit
nes_exit_module(void)
1148 nes_remove_driver_sysfs(&nes_pci_driver
);
1150 pci_unregister_driver(&nes_pci_driver
);
1154 module_init(nes_init_module
);
1155 module_exit(nes_exit_module
);