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
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>
47 #include <linux/slab.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>
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");
66 MODULE_VERSION(DRV_VERSION
);
69 int interrupt_mod_interval
= 0;
72 /* Interoperability */
74 module_param(mpa_version
, int, 0644);
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, 0644);
80 MODULE_PARM_DESC(disable_mpa_crc
, "Disable checking of MPA CRC");
82 unsigned int send_first
= 0;
83 module_param(send_first
, int, 0644);
84 MODULE_PARM_DESC(send_first
, "Send RDMA Message First on Active Connection");
87 unsigned int nes_drv_opt
= NES_DRV_OPT_DISABLE_INT_MOD
| NES_DRV_OPT_ENABLE_PAU
;
88 module_param(nes_drv_opt
, int, 0644);
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 unsigned int wqm_quanta
= 0x10000;
96 module_param(wqm_quanta
, int, 0644);
97 MODULE_PARM_DESC(wqm_quanta
, "WQM quanta");
99 static bool limit_maxrdreqsz
;
100 module_param(limit_maxrdreqsz
, bool, 0644);
101 MODULE_PARM_DESC(limit_maxrdreqsz
, "Limit max read request size to 256 Bytes");
103 LIST_HEAD(nes_adapter_list
);
104 static LIST_HEAD(nes_dev_list
);
106 atomic_t qps_destroyed
;
108 static unsigned int ee_flsh_adapter
;
109 static unsigned int sysfs_nonidx_addr
;
110 static unsigned int sysfs_idx_addr
;
112 static struct pci_device_id nes_pci_table
[] = {
113 { PCI_VDEVICE(NETEFFECT
, PCI_DEVICE_ID_NETEFFECT_NE020
), },
114 { PCI_VDEVICE(NETEFFECT
, PCI_DEVICE_ID_NETEFFECT_NE020_KR
), },
118 MODULE_DEVICE_TABLE(pci
, nes_pci_table
);
120 static int nes_inetaddr_event(struct notifier_block
*, unsigned long, void *);
121 static int nes_net_event(struct notifier_block
*, unsigned long, void *);
122 static int nes_notifiers_registered
;
125 static struct notifier_block nes_inetaddr_notifier
= {
126 .notifier_call
= nes_inetaddr_event
129 static struct notifier_block nes_net_notifier
= {
130 .notifier_call
= nes_net_event
136 static int nes_inetaddr_event(struct notifier_block
*notifier
,
137 unsigned long event
, void *ptr
)
139 struct in_ifaddr
*ifa
= ptr
;
140 struct net_device
*event_netdev
= ifa
->ifa_dev
->dev
;
141 struct nes_device
*nesdev
;
142 struct net_device
*netdev
;
143 struct nes_vnic
*nesvnic
;
144 unsigned int is_bonded
;
146 nes_debug(NES_DBG_NETDEV
, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
147 &ifa
->ifa_address
, &ifa
->ifa_mask
);
148 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
149 nes_debug(NES_DBG_NETDEV
, "Nesdev list entry = 0x%p. (%s)\n",
150 nesdev
, nesdev
->netdev
[0]->name
);
151 netdev
= nesdev
->netdev
[0];
152 nesvnic
= netdev_priv(netdev
);
153 is_bonded
= netif_is_bond_slave(netdev
) &&
154 (netdev
->master
== event_netdev
);
155 if ((netdev
== event_netdev
) || is_bonded
) {
156 if (nesvnic
->rdma_enabled
== 0) {
157 nes_debug(NES_DBG_NETDEV
, "Returning without processing event for %s since"
158 " RDMA is not enabled.\n",
162 /* we have ifa->ifa_address/mask here if we need it */
165 nes_debug(NES_DBG_NETDEV
, "event:DOWN\n");
166 nes_write_indexed(nesdev
,
167 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)), 0);
169 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
170 ntohl(nesvnic
->local_ipaddr
), NES_ARP_DELETE
);
171 nesvnic
->local_ipaddr
= 0;
178 nes_debug(NES_DBG_NETDEV
, "event:UP\n");
180 if (nesvnic
->local_ipaddr
!= 0) {
181 nes_debug(NES_DBG_NETDEV
, "Interface already has local_ipaddr\n");
185 case NETDEV_CHANGEADDR
:
186 /* Add the address to the IP table */
188 nesvnic
->local_ipaddr
=
189 ((struct in_device
*)netdev
->master
->ip_ptr
)->ifa_list
->ifa_address
;
191 nesvnic
->local_ipaddr
= ifa
->ifa_address
;
193 nes_write_indexed(nesdev
,
194 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)),
195 ntohl(nesvnic
->local_ipaddr
));
196 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
197 ntohl(nesvnic
->local_ipaddr
), NES_ARP_ADD
);
216 static int nes_net_event(struct notifier_block
*notifier
,
217 unsigned long event
, void *ptr
)
219 struct neighbour
*neigh
= ptr
;
220 struct nes_device
*nesdev
;
221 struct net_device
*netdev
;
222 struct nes_vnic
*nesvnic
;
225 case NETEVENT_NEIGH_UPDATE
:
226 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
227 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
228 netdev
= nesdev
->netdev
[0];
229 nesvnic
= netdev_priv(netdev
);
230 if (netdev
== neigh
->dev
) {
231 if (nesvnic
->rdma_enabled
== 0) {
232 nes_debug(NES_DBG_NETDEV
, "Skipping device %s since no RDMA\n",
235 if (neigh
->nud_state
& NUD_VALID
) {
236 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
237 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_ADD
);
239 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
240 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_DELETE
);
248 nes_debug(NES_DBG_NETDEV
, "NETEVENT_ %lu undefined\n", event
);
259 void nes_add_ref(struct ib_qp
*ibqp
)
261 struct nes_qp
*nesqp
;
263 nesqp
= to_nesqp(ibqp
);
264 nes_debug(NES_DBG_QP
, "Bumping refcount for QP%u. Pre-inc value = %u\n",
265 ibqp
->qp_num
, atomic_read(&nesqp
->refcount
));
266 atomic_inc(&nesqp
->refcount
);
269 static void nes_cqp_rem_ref_callback(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
272 struct nes_qp
*nesqp
= cqp_request
->cqp_callback_pointer
;
273 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
275 atomic_inc(&qps_destroyed
);
277 /* Free the control structures */
279 if (nesqp
->pbl_vbase
) {
280 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
281 nesqp
->hwqp
.q2_vbase
, nesqp
->hwqp
.q2_pbase
);
282 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
283 nesadapter
->free_256pbl
++;
284 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
285 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
286 nesqp
->pbl_vbase
= NULL
;
289 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
290 nesqp
->hwqp
.sq_vbase
, nesqp
->hwqp
.sq_pbase
);
292 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, nesqp
->hwqp
.qp_id
);
294 nesadapter
->qp_table
[nesqp
->hwqp
.qp_id
-NES_FIRST_QPN
] = NULL
;
295 kfree(nesqp
->allocated_buffer
);
302 void nes_rem_ref(struct ib_qp
*ibqp
)
305 struct nes_qp
*nesqp
;
306 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
307 struct nes_device
*nesdev
= nesvnic
->nesdev
;
308 struct nes_hw_cqp_wqe
*cqp_wqe
;
309 struct nes_cqp_request
*cqp_request
;
312 nesqp
= to_nesqp(ibqp
);
314 if (atomic_read(&nesqp
->refcount
) == 0) {
315 printk(KERN_INFO PFX
"%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
316 __func__
, ibqp
->qp_num
, nesqp
->last_aeq
);
320 if (atomic_dec_and_test(&nesqp
->refcount
)) {
322 nes_destroy_pau_qp(nesdev
, nesqp
);
325 cqp_request
= nes_get_cqp_request(nesdev
);
326 if (cqp_request
== NULL
) {
327 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
330 cqp_request
->waiting
= 0;
331 cqp_request
->callback
= 1;
332 cqp_request
->cqp_callback
= nes_cqp_rem_ref_callback
;
333 cqp_request
->cqp_callback_pointer
= nesqp
;
334 cqp_wqe
= &cqp_request
->cqp_wqe
;
336 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
337 opcode
= NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_IWARP
;
339 if (nesqp
->hte_added
) {
340 opcode
|= NES_CQP_QP_DEL_HTE
;
341 nesqp
->hte_added
= 0;
343 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
344 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
345 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
346 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
347 nes_post_cqp_request(nesdev
, cqp_request
);
355 struct ib_qp
*nes_get_qp(struct ib_device
*device
, int qpn
)
357 struct nes_vnic
*nesvnic
= to_nesvnic(device
);
358 struct nes_device
*nesdev
= nesvnic
->nesdev
;
359 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
361 if ((qpn
< NES_FIRST_QPN
) || (qpn
>= (NES_FIRST_QPN
+ nesadapter
->max_qp
)))
364 return &nesadapter
->qp_table
[qpn
- NES_FIRST_QPN
]->ibqp
;
371 static void nes_print_macaddr(struct net_device
*netdev
)
373 nes_debug(NES_DBG_INIT
, "%s: %pM, IRQ %u\n",
374 netdev
->name
, netdev
->dev_addr
, netdev
->irq
);
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 void __iomem
*mmio_regs
= NULL
;
460 assert(pcidev
!= NULL
);
463 printk(KERN_INFO PFX
"NetEffect RNIC driver v%s loading. (%s)\n",
464 DRV_VERSION
, pci_name(pcidev
));
466 ret
= pci_enable_device(pcidev
);
468 printk(KERN_ERR PFX
"Unable to enable PCI device. (%s)\n", pci_name(pcidev
));
472 nes_debug(NES_DBG_INIT
, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
473 (long unsigned int)pci_resource_start(pcidev
, BAR_0
),
474 (long unsigned int)pci_resource_len(pcidev
, BAR_0
));
475 nes_debug(NES_DBG_INIT
, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
476 (long unsigned int)pci_resource_start(pcidev
, BAR_1
),
477 (long unsigned int)pci_resource_len(pcidev
, BAR_1
));
479 /* Make sure PCI base addr are MMIO */
480 if (!(pci_resource_flags(pcidev
, BAR_0
) & IORESOURCE_MEM
) ||
481 !(pci_resource_flags(pcidev
, BAR_1
) & IORESOURCE_MEM
)) {
482 printk(KERN_ERR PFX
"PCI regions not an MMIO resource\n");
487 /* Reserve PCI I/O and memory resources */
488 ret
= pci_request_regions(pcidev
, DRV_NAME
);
490 printk(KERN_ERR PFX
"Unable to request regions. (%s)\n", pci_name(pcidev
));
494 if ((sizeof(dma_addr_t
) > 4)) {
495 ret
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(64));
497 printk(KERN_ERR PFX
"64b DMA mask configuration failed\n");
500 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64));
502 printk(KERN_ERR PFX
"64b DMA consistent mask configuration failed\n");
506 ret
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32));
508 printk(KERN_ERR PFX
"32b DMA mask configuration failed\n");
511 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
513 printk(KERN_ERR PFX
"32b DMA consistent mask configuration failed\n");
518 pci_set_master(pcidev
);
520 /* Allocate hardware structure */
521 nesdev
= kzalloc(sizeof(struct nes_device
), GFP_KERNEL
);
523 printk(KERN_ERR PFX
"%s: Unable to alloc hardware struct\n", pci_name(pcidev
));
528 nes_debug(NES_DBG_INIT
, "Allocated nes device at %p\n", nesdev
);
529 nesdev
->pcidev
= pcidev
;
530 pci_set_drvdata(pcidev
, nesdev
);
532 pci_read_config_byte(pcidev
, 0x0008, &hw_rev
);
533 nes_debug(NES_DBG_INIT
, "hw_rev=%u\n", hw_rev
);
535 spin_lock_init(&nesdev
->indexed_regs_lock
);
537 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
538 mmio_regs
= ioremap_nocache(pci_resource_start(pcidev
, BAR_0
),
539 pci_resource_len(pcidev
, BAR_0
));
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
;
576 nesdev
->nesadapter
->wqm_quanta
= wqm_quanta
;
578 /* nesdev->base_doorbell_index =
579 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
580 nesdev
->base_doorbell_index
= 1;
581 nesdev
->doorbell_start
= nesdev
->nesadapter
->doorbell_start
;
582 if (nesdev
->nesadapter
->phy_type
[0] == NES_PHY_TYPE_PUMA_1G
) {
583 switch (PCI_FUNC(nesdev
->pcidev
->devfn
) %
584 nesdev
->nesadapter
->port_count
) {
586 nesdev
->mac_index
= 2;
589 nesdev
->mac_index
= 1;
592 nesdev
->mac_index
= 3;
596 nesdev
->mac_index
= 0;
599 nesdev
->mac_index
= PCI_FUNC(nesdev
->pcidev
->devfn
) %
600 nesdev
->nesadapter
->port_count
;
603 if ((limit_maxrdreqsz
||
604 ((nesdev
->nesadapter
->phy_type
[0] == NES_PHY_TYPE_GLADIUS
) &&
605 (hw_rev
== NE020_REV1
))) &&
606 (pcie_get_readrq(pcidev
) > 256)) {
607 if (pcie_set_readrq(pcidev
, 256))
608 printk(KERN_ERR PFX
"Unable to set max read request"
611 nes_debug(NES_DBG_INIT
, "Max read request size set"
615 tasklet_init(&nesdev
->dpc_tasklet
, nes_dpc
, (unsigned long)nesdev
);
617 /* bring up the Control QP */
618 if (nes_init_cqp(nesdev
)) {
624 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
625 PCI_FUNC(nesdev
->pcidev
->devfn
));
626 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
628 /* Enable the interrupts */
629 nesdev
->int_req
= (0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
)) |
630 (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
631 if (PCI_FUNC(nesdev
->pcidev
->devfn
) < 4) {
632 nesdev
->int_req
|= (1 << (PCI_FUNC(nesdev
->mac_index
)+24));
635 /* TODO: This really should be the first driver to load, not function 0 */
636 if (PCI_FUNC(nesdev
->pcidev
->devfn
) == 0) {
637 /* pick up PCI and critical errors if the first driver to load */
638 nesdev
->intf_int_req
= NES_INTF_INT_PCIERR
| NES_INTF_INT_CRITERR
;
639 nesdev
->int_req
|= NES_INT_INTF
;
641 nesdev
->intf_int_req
= 0;
643 nesdev
->intf_int_req
|= (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
644 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS0
, 0);
645 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS1
, 0);
646 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS2
, 0x00001265);
647 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS4
, 0x18021804);
649 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS3
, 0x17801790);
651 /* deal with both periodic and one_shot */
652 nesdev
->timer_int_req
= 0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
);
653 nesdev
->nesadapter
->timer_int_req
|= nesdev
->timer_int_req
;
654 nes_debug(NES_DBG_INIT
, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
655 PCI_FUNC(nesdev
->pcidev
->devfn
),
656 nesdev
->timer_int_req
, nesdev
->nesadapter
->timer_int_req
);
658 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
660 list_add_tail(&nesdev
->list
, &nes_dev_list
);
662 /* Request an interrupt line for the driver */
663 ret
= request_irq(pcidev
->irq
, nes_interrupt
, IRQF_SHARED
, DRV_NAME
, nesdev
);
665 printk(KERN_ERR PFX
"%s: requested IRQ %u is busy\n",
666 pci_name(pcidev
), pcidev
->irq
);
670 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
672 if (nes_notifiers_registered
== 0) {
673 register_inetaddr_notifier(&nes_inetaddr_notifier
);
674 register_netevent_notifier(&nes_net_notifier
);
676 nes_notifiers_registered
++;
678 INIT_DELAYED_WORK(&nesdev
->work
, nes_recheck_link_status
);
680 /* Initialize network devices */
681 if ((netdev
= nes_netdev_init(nesdev
, mmio_regs
)) == NULL
)
684 /* Register network device */
685 ret
= register_netdev(netdev
);
687 printk(KERN_ERR PFX
"Unable to register netdev, ret = %d\n", ret
);
688 nes_netdev_destroy(netdev
);
692 nes_print_macaddr(netdev
);
694 nesdev
->netdev_count
++;
695 nesdev
->nesadapter
->netdev_count
++;
697 printk(KERN_INFO PFX
"%s: NetEffect RNIC driver successfully loaded.\n",
702 printk(KERN_ERR PFX
"bail7\n");
703 while (nesdev
->netdev_count
> 0) {
704 nesdev
->netdev_count
--;
705 nesdev
->nesadapter
->netdev_count
--;
707 unregister_netdev(nesdev
->netdev
[nesdev
->netdev_count
]);
708 nes_netdev_destroy(nesdev
->netdev
[nesdev
->netdev_count
]);
711 nes_debug(NES_DBG_INIT
, "netdev_count=%d, nesadapter->netdev_count=%d\n",
712 nesdev
->netdev_count
, nesdev
->nesadapter
->netdev_count
);
714 nes_notifiers_registered
--;
715 if (nes_notifiers_registered
== 0) {
716 unregister_netevent_notifier(&nes_net_notifier
);
717 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
720 list_del(&nesdev
->list
);
721 nes_destroy_cqp(nesdev
);
724 printk(KERN_ERR PFX
"bail65\n");
725 free_irq(pcidev
->irq
, nesdev
);
726 if (nesdev
->msi_enabled
) {
727 pci_disable_msi(pcidev
);
730 printk(KERN_ERR PFX
"bail6\n");
731 tasklet_kill(&nesdev
->dpc_tasklet
);
732 /* Deallocate the Adapter Structure */
733 nes_destroy_adapter(nesdev
->nesadapter
);
736 printk(KERN_ERR PFX
"bail5\n");
737 iounmap(nesdev
->regs
);
740 printk(KERN_ERR PFX
"bail3\n");
744 pci_release_regions(pcidev
);
747 pci_disable_device(pcidev
);
755 * nes_remove - unload from kernel
757 static void __devexit
nes_remove(struct pci_dev
*pcidev
)
759 struct nes_device
*nesdev
= pci_get_drvdata(pcidev
);
760 struct net_device
*netdev
;
761 int netdev_index
= 0;
764 if (nesdev
->netdev_count
) {
765 netdev
= nesdev
->netdev
[netdev_index
];
767 netif_stop_queue(netdev
);
768 unregister_netdev(netdev
);
769 nes_netdev_destroy(netdev
);
771 nesdev
->netdev
[netdev_index
] = NULL
;
772 nesdev
->netdev_count
--;
773 nesdev
->nesadapter
->netdev_count
--;
777 nes_notifiers_registered
--;
778 if (nes_notifiers_registered
== 0) {
779 unregister_netevent_notifier(&nes_net_notifier
);
780 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
783 list_del(&nesdev
->list
);
784 nes_destroy_cqp(nesdev
);
786 free_irq(pcidev
->irq
, nesdev
);
787 tasklet_kill(&nesdev
->dpc_tasklet
);
789 spin_lock_irqsave(&nesdev
->nesadapter
->phy_lock
, flags
);
790 if (nesdev
->link_recheck
) {
791 spin_unlock_irqrestore(&nesdev
->nesadapter
->phy_lock
, flags
);
792 cancel_delayed_work_sync(&nesdev
->work
);
794 spin_unlock_irqrestore(&nesdev
->nesadapter
->phy_lock
, flags
);
797 /* Deallocate the Adapter Structure */
798 nes_destroy_adapter(nesdev
->nesadapter
);
800 if (nesdev
->msi_enabled
) {
801 pci_disable_msi(pcidev
);
804 iounmap(nesdev
->regs
);
807 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
808 pci_release_regions(pcidev
);
809 pci_disable_device(pcidev
);
810 pci_set_drvdata(pcidev
, NULL
);
814 static struct pci_driver nes_pci_driver
= {
816 .id_table
= nes_pci_table
,
818 .remove
= __devexit_p(nes_remove
),
821 static ssize_t
nes_show_adapter(struct device_driver
*ddp
, char *buf
)
823 unsigned int devfn
= 0xffffffff;
824 unsigned char bus_number
= 0xff;
826 struct nes_device
*nesdev
;
828 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
829 if (i
== ee_flsh_adapter
) {
830 devfn
= nesdev
->pcidev
->devfn
;
831 bus_number
= nesdev
->pcidev
->bus
->number
;
837 return snprintf(buf
, PAGE_SIZE
, "%x:%x\n", bus_number
, devfn
);
840 static ssize_t
nes_store_adapter(struct device_driver
*ddp
,
841 const char *buf
, size_t count
)
843 char *p
= (char *)buf
;
845 ee_flsh_adapter
= simple_strtoul(p
, &p
, 10);
846 return strnlen(buf
, count
);
849 static ssize_t
nes_show_ee_cmd(struct device_driver
*ddp
, char *buf
)
851 u32 eeprom_cmd
= 0xdead;
853 struct nes_device
*nesdev
;
855 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
856 if (i
== ee_flsh_adapter
) {
857 eeprom_cmd
= nes_read32(nesdev
->regs
+ NES_EEPROM_COMMAND
);
862 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_cmd
);
865 static ssize_t
nes_store_ee_cmd(struct device_driver
*ddp
,
866 const char *buf
, size_t count
)
868 char *p
= (char *)buf
;
871 struct nes_device
*nesdev
;
873 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
874 val
= simple_strtoul(p
, &p
, 16);
875 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
876 if (i
== ee_flsh_adapter
) {
877 nes_write32(nesdev
->regs
+ NES_EEPROM_COMMAND
, val
);
883 return strnlen(buf
, count
);
886 static ssize_t
nes_show_ee_data(struct device_driver
*ddp
, char *buf
)
888 u32 eeprom_data
= 0xdead;
890 struct nes_device
*nesdev
;
892 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
893 if (i
== ee_flsh_adapter
) {
894 eeprom_data
= nes_read32(nesdev
->regs
+ NES_EEPROM_DATA
);
900 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_data
);
903 static ssize_t
nes_store_ee_data(struct device_driver
*ddp
,
904 const char *buf
, size_t count
)
906 char *p
= (char *)buf
;
909 struct nes_device
*nesdev
;
911 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
912 val
= simple_strtoul(p
, &p
, 16);
913 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
914 if (i
== ee_flsh_adapter
) {
915 nes_write32(nesdev
->regs
+ NES_EEPROM_DATA
, val
);
921 return strnlen(buf
, count
);
924 static ssize_t
nes_show_flash_cmd(struct device_driver
*ddp
, char *buf
)
926 u32 flash_cmd
= 0xdead;
928 struct nes_device
*nesdev
;
930 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
931 if (i
== ee_flsh_adapter
) {
932 flash_cmd
= nes_read32(nesdev
->regs
+ NES_FLASH_COMMAND
);
938 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_cmd
);
941 static ssize_t
nes_store_flash_cmd(struct device_driver
*ddp
,
942 const char *buf
, size_t count
)
944 char *p
= (char *)buf
;
947 struct nes_device
*nesdev
;
949 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
950 val
= simple_strtoul(p
, &p
, 16);
951 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
952 if (i
== ee_flsh_adapter
) {
953 nes_write32(nesdev
->regs
+ NES_FLASH_COMMAND
, val
);
959 return strnlen(buf
, count
);
962 static ssize_t
nes_show_flash_data(struct device_driver
*ddp
, char *buf
)
964 u32 flash_data
= 0xdead;
966 struct nes_device
*nesdev
;
968 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
969 if (i
== ee_flsh_adapter
) {
970 flash_data
= nes_read32(nesdev
->regs
+ NES_FLASH_DATA
);
976 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_data
);
979 static ssize_t
nes_store_flash_data(struct device_driver
*ddp
,
980 const char *buf
, size_t count
)
982 char *p
= (char *)buf
;
985 struct nes_device
*nesdev
;
987 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
988 val
= simple_strtoul(p
, &p
, 16);
989 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
990 if (i
== ee_flsh_adapter
) {
991 nes_write32(nesdev
->regs
+ NES_FLASH_DATA
, val
);
997 return strnlen(buf
, count
);
1000 static ssize_t
nes_show_nonidx_addr(struct device_driver
*ddp
, char *buf
)
1002 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_nonidx_addr
);
1005 static ssize_t
nes_store_nonidx_addr(struct device_driver
*ddp
,
1006 const char *buf
, size_t count
)
1008 char *p
= (char *)buf
;
1010 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
1011 sysfs_nonidx_addr
= simple_strtoul(p
, &p
, 16);
1013 return strnlen(buf
, count
);
1016 static ssize_t
nes_show_nonidx_data(struct device_driver
*ddp
, char *buf
)
1018 u32 nonidx_data
= 0xdead;
1020 struct nes_device
*nesdev
;
1022 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1023 if (i
== ee_flsh_adapter
) {
1024 nonidx_data
= nes_read32(nesdev
->regs
+ sysfs_nonidx_addr
);
1030 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", nonidx_data
);
1033 static ssize_t
nes_store_nonidx_data(struct device_driver
*ddp
,
1034 const char *buf
, size_t count
)
1036 char *p
= (char *)buf
;
1039 struct nes_device
*nesdev
;
1041 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1042 val
= simple_strtoul(p
, &p
, 16);
1043 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1044 if (i
== ee_flsh_adapter
) {
1045 nes_write32(nesdev
->regs
+ sysfs_nonidx_addr
, val
);
1051 return strnlen(buf
, count
);
1054 static ssize_t
nes_show_idx_addr(struct device_driver
*ddp
, char *buf
)
1056 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_idx_addr
);
1059 static ssize_t
nes_store_idx_addr(struct device_driver
*ddp
,
1060 const char *buf
, size_t count
)
1062 char *p
= (char *)buf
;
1064 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
1065 sysfs_idx_addr
= simple_strtoul(p
, &p
, 16);
1067 return strnlen(buf
, count
);
1070 static ssize_t
nes_show_idx_data(struct device_driver
*ddp
, char *buf
)
1072 u32 idx_data
= 0xdead;
1074 struct nes_device
*nesdev
;
1076 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1077 if (i
== ee_flsh_adapter
) {
1078 idx_data
= nes_read_indexed(nesdev
, sysfs_idx_addr
);
1084 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", idx_data
);
1087 static ssize_t
nes_store_idx_data(struct device_driver
*ddp
,
1088 const char *buf
, size_t count
)
1090 char *p
= (char *)buf
;
1093 struct nes_device
*nesdev
;
1095 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1096 val
= simple_strtoul(p
, &p
, 16);
1097 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1098 if (i
== ee_flsh_adapter
) {
1099 nes_write_indexed(nesdev
, sysfs_idx_addr
, val
);
1105 return strnlen(buf
, count
);
1110 * nes_show_wqm_quanta
1112 static ssize_t
nes_show_wqm_quanta(struct device_driver
*ddp
, char *buf
)
1114 u32 wqm_quanta_value
= 0xdead;
1116 struct nes_device
*nesdev
;
1118 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1119 if (i
== ee_flsh_adapter
) {
1120 wqm_quanta_value
= nesdev
->nesadapter
->wqm_quanta
;
1126 return snprintf(buf
, PAGE_SIZE
, "0x%X\n", wqm_quanta_value
);
1131 * nes_store_wqm_quanta
1133 static ssize_t
nes_store_wqm_quanta(struct device_driver
*ddp
,
1134 const char *buf
, size_t count
)
1136 unsigned long wqm_quanta_value
;
1139 struct nes_device
*nesdev
;
1141 if (kstrtoul(buf
, 0, &wqm_quanta_value
) < 0)
1144 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1145 if (i
== ee_flsh_adapter
) {
1146 nesdev
->nesadapter
->wqm_quanta
= wqm_quanta_value
;
1147 wqm_config1
= nes_read_indexed(nesdev
,
1148 NES_IDX_WQM_CONFIG1
);
1149 nes_write_indexed(nesdev
, NES_IDX_WQM_CONFIG1
,
1150 ((wqm_quanta_value
<< 1) |
1151 (wqm_config1
& 0x00000001)));
1156 return strnlen(buf
, count
);
1159 static DRIVER_ATTR(adapter
, S_IRUSR
| S_IWUSR
,
1160 nes_show_adapter
, nes_store_adapter
);
1161 static DRIVER_ATTR(eeprom_cmd
, S_IRUSR
| S_IWUSR
,
1162 nes_show_ee_cmd
, nes_store_ee_cmd
);
1163 static DRIVER_ATTR(eeprom_data
, S_IRUSR
| S_IWUSR
,
1164 nes_show_ee_data
, nes_store_ee_data
);
1165 static DRIVER_ATTR(flash_cmd
, S_IRUSR
| S_IWUSR
,
1166 nes_show_flash_cmd
, nes_store_flash_cmd
);
1167 static DRIVER_ATTR(flash_data
, S_IRUSR
| S_IWUSR
,
1168 nes_show_flash_data
, nes_store_flash_data
);
1169 static DRIVER_ATTR(nonidx_addr
, S_IRUSR
| S_IWUSR
,
1170 nes_show_nonidx_addr
, nes_store_nonidx_addr
);
1171 static DRIVER_ATTR(nonidx_data
, S_IRUSR
| S_IWUSR
,
1172 nes_show_nonidx_data
, nes_store_nonidx_data
);
1173 static DRIVER_ATTR(idx_addr
, S_IRUSR
| S_IWUSR
,
1174 nes_show_idx_addr
, nes_store_idx_addr
);
1175 static DRIVER_ATTR(idx_data
, S_IRUSR
| S_IWUSR
,
1176 nes_show_idx_data
, nes_store_idx_data
);
1177 static DRIVER_ATTR(wqm_quanta
, S_IRUSR
| S_IWUSR
,
1178 nes_show_wqm_quanta
, nes_store_wqm_quanta
);
1180 static int nes_create_driver_sysfs(struct pci_driver
*drv
)
1183 error
= driver_create_file(&drv
->driver
, &driver_attr_adapter
);
1184 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1185 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_data
);
1186 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_cmd
);
1187 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_data
);
1188 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1189 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_data
);
1190 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_addr
);
1191 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_data
);
1192 error
|= driver_create_file(&drv
->driver
, &driver_attr_wqm_quanta
);
1196 static void nes_remove_driver_sysfs(struct pci_driver
*drv
)
1198 driver_remove_file(&drv
->driver
, &driver_attr_adapter
);
1199 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1200 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_data
);
1201 driver_remove_file(&drv
->driver
, &driver_attr_flash_cmd
);
1202 driver_remove_file(&drv
->driver
, &driver_attr_flash_data
);
1203 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1204 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_data
);
1205 driver_remove_file(&drv
->driver
, &driver_attr_idx_addr
);
1206 driver_remove_file(&drv
->driver
, &driver_attr_idx_data
);
1207 driver_remove_file(&drv
->driver
, &driver_attr_wqm_quanta
);
1211 * nes_init_module - module initialization entry point
1213 static int __init
nes_init_module(void)
1218 retval
= nes_cm_start();
1220 printk(KERN_ERR PFX
"Unable to start NetEffect iWARP CM.\n");
1223 retval
= pci_register_driver(&nes_pci_driver
);
1225 retval1
= nes_create_driver_sysfs(&nes_pci_driver
);
1227 printk(KERN_ERR PFX
"Unable to create NetEffect sys files.\n");
1234 * nes_exit_module - module unload entry point
1236 static void __exit
nes_exit_module(void)
1239 nes_remove_driver_sysfs(&nes_pci_driver
);
1241 pci_unregister_driver(&nes_pci_driver
);
1245 module_init(nes_init_module
);
1246 module_exit(nes_exit_module
);