2 * Copyright (c) 2006 - 2009 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
= 0;
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 unsigned int 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
139 static int nes_inetaddr_event(struct notifier_block
*notifier
,
140 unsigned long event
, void *ptr
)
142 struct in_ifaddr
*ifa
= ptr
;
143 struct net_device
*event_netdev
= ifa
->ifa_dev
->dev
;
144 struct nes_device
*nesdev
;
145 struct net_device
*netdev
;
146 struct nes_vnic
*nesvnic
;
148 nes_debug(NES_DBG_NETDEV
, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
149 &ifa
->ifa_address
, &ifa
->ifa_mask
);
150 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
151 nes_debug(NES_DBG_NETDEV
, "Nesdev list entry = 0x%p. (%s)\n",
152 nesdev
, nesdev
->netdev
[0]->name
);
153 netdev
= nesdev
->netdev
[0];
154 nesvnic
= netdev_priv(netdev
);
155 if (netdev
== event_netdev
) {
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;
175 nes_debug(NES_DBG_NETDEV
, "event:UP\n");
177 if (nesvnic
->local_ipaddr
!= 0) {
178 nes_debug(NES_DBG_NETDEV
, "Interface already has local_ipaddr\n");
181 /* Add the address to the IP table */
182 nesvnic
->local_ipaddr
= ifa
->ifa_address
;
184 nes_write_indexed(nesdev
,
185 NES_IDX_DST_IP_ADDR
+(0x10*PCI_FUNC(nesdev
->pcidev
->devfn
)),
186 ntohl(ifa
->ifa_address
));
187 nes_manage_arp_cache(netdev
, netdev
->dev_addr
,
188 ntohl(nesvnic
->local_ipaddr
), NES_ARP_ADD
);
204 static int nes_net_event(struct notifier_block
*notifier
,
205 unsigned long event
, void *ptr
)
207 struct neighbour
*neigh
= ptr
;
208 struct nes_device
*nesdev
;
209 struct net_device
*netdev
;
210 struct nes_vnic
*nesvnic
;
213 case NETEVENT_NEIGH_UPDATE
:
214 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
215 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
216 netdev
= nesdev
->netdev
[0];
217 nesvnic
= netdev_priv(netdev
);
218 if (netdev
== neigh
->dev
) {
219 if (nesvnic
->rdma_enabled
== 0) {
220 nes_debug(NES_DBG_NETDEV
, "Skipping device %s since no RDMA\n",
223 if (neigh
->nud_state
& NUD_VALID
) {
224 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
225 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_ADD
);
227 nes_manage_arp_cache(neigh
->dev
, neigh
->ha
,
228 ntohl(*(__be32
*)neigh
->primary_key
), NES_ARP_DELETE
);
236 nes_debug(NES_DBG_NETDEV
, "NETEVENT_ %lu undefined\n", event
);
247 void nes_add_ref(struct ib_qp
*ibqp
)
249 struct nes_qp
*nesqp
;
251 nesqp
= to_nesqp(ibqp
);
252 nes_debug(NES_DBG_QP
, "Bumping refcount for QP%u. Pre-inc value = %u\n",
253 ibqp
->qp_num
, atomic_read(&nesqp
->refcount
));
254 atomic_inc(&nesqp
->refcount
);
257 static void nes_cqp_rem_ref_callback(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
260 struct nes_qp
*nesqp
= cqp_request
->cqp_callback_pointer
;
261 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
263 atomic_inc(&qps_destroyed
);
265 /* Free the control structures */
267 if (nesqp
->pbl_vbase
) {
268 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
269 nesqp
->hwqp
.q2_vbase
, nesqp
->hwqp
.q2_pbase
);
270 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
271 nesadapter
->free_256pbl
++;
272 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
273 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
274 nesqp
->pbl_vbase
= NULL
;
277 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
278 nesqp
->hwqp
.sq_vbase
, nesqp
->hwqp
.sq_pbase
);
280 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, nesqp
->hwqp
.qp_id
);
282 nesadapter
->qp_table
[nesqp
->hwqp
.qp_id
-NES_FIRST_QPN
] = NULL
;
283 kfree(nesqp
->allocated_buffer
);
290 void nes_rem_ref(struct ib_qp
*ibqp
)
293 struct nes_qp
*nesqp
;
294 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
295 struct nes_device
*nesdev
= nesvnic
->nesdev
;
296 struct nes_hw_cqp_wqe
*cqp_wqe
;
297 struct nes_cqp_request
*cqp_request
;
300 nesqp
= to_nesqp(ibqp
);
302 if (atomic_read(&nesqp
->refcount
) == 0) {
303 printk(KERN_INFO PFX
"%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
304 __func__
, ibqp
->qp_num
, nesqp
->last_aeq
);
308 if (atomic_dec_and_test(&nesqp
->refcount
)) {
310 cqp_request
= nes_get_cqp_request(nesdev
);
311 if (cqp_request
== NULL
) {
312 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request.\n");
315 cqp_request
->waiting
= 0;
316 cqp_request
->callback
= 1;
317 cqp_request
->cqp_callback
= nes_cqp_rem_ref_callback
;
318 cqp_request
->cqp_callback_pointer
= nesqp
;
319 cqp_wqe
= &cqp_request
->cqp_wqe
;
321 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
322 opcode
= NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_IWARP
;
324 if (nesqp
->hte_added
) {
325 opcode
|= NES_CQP_QP_DEL_HTE
;
326 nesqp
->hte_added
= 0;
328 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
329 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
330 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
331 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
332 nes_post_cqp_request(nesdev
, cqp_request
);
340 struct ib_qp
*nes_get_qp(struct ib_device
*device
, int qpn
)
342 struct nes_vnic
*nesvnic
= to_nesvnic(device
);
343 struct nes_device
*nesdev
= nesvnic
->nesdev
;
344 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
346 if ((qpn
< NES_FIRST_QPN
) || (qpn
>= (NES_FIRST_QPN
+ nesadapter
->max_qp
)))
349 return &nesadapter
->qp_table
[qpn
- NES_FIRST_QPN
]->ibqp
;
356 static void nes_print_macaddr(struct net_device
*netdev
)
358 nes_debug(NES_DBG_INIT
, "%s: %pM, IRQ %u\n",
359 netdev
->name
, netdev
->dev_addr
, netdev
->irq
);
363 * nes_interrupt - handle interrupts
365 static irqreturn_t
nes_interrupt(int irq
, void *dev_id
)
367 struct nes_device
*nesdev
= (struct nes_device
*)dev_id
;
375 if (nesdev
->msi_enabled
) {
376 /* No need to read the interrupt pending register if msi is enabled */
379 if (unlikely(nesdev
->nesadapter
->hw_rev
== NE020_REV
)) {
380 /* Master interrupt enable provides synchronization for kicking off bottom half
381 when interrupt sharing is going on */
382 int_mask
= nes_read32(nesdev
->regs
+ NES_INT_MASK
);
383 if (int_mask
& 0x80000000) {
384 /* Check interrupt status to see if this might be ours */
385 int_stat
= nes_read32(nesdev
->regs
+ NES_INT_STAT
);
386 int_req
= nesdev
->int_req
;
387 if (int_stat
&int_req
) {
388 /* if interesting CEQ or AEQ is pending, claim the interrupt */
389 if ((int_stat
&int_req
) & (~(NES_INT_TIMER
|NES_INT_INTF
))) {
392 if (((int_stat
& int_req
) & NES_INT_TIMER
) == NES_INT_TIMER
) {
393 /* Timer might be running but might be for another function */
394 timer_stat
= nes_read32(nesdev
->regs
+ NES_TIMER_STAT
);
395 if ((timer_stat
& nesdev
->timer_int_req
) != 0) {
399 if ((((int_stat
& int_req
) & NES_INT_INTF
) == NES_INT_INTF
) &&
401 intf_int_stat
= nes_read32(nesdev
->regs
+NES_INTF_INT_STAT
);
402 if ((intf_int_stat
& nesdev
->intf_int_req
) != 0) {
408 nes_write32(nesdev
->regs
+NES_INT_MASK
, int_mask
& (~0x80000000));
409 int_mask
= nes_read32(nesdev
->regs
+NES_INT_MASK
);
410 /* Save off the status to save an additional read */
411 nesdev
->int_stat
= int_stat
;
412 nesdev
->napi_isr_ran
= 1;
417 handled
= nes_read32(nesdev
->regs
+NES_INT_PENDING
);
423 if (nes_napi_isr(nesdev
) == 0) {
424 tasklet_schedule(&nesdev
->dpc_tasklet
);
435 * nes_probe - Device initialization
437 static int __devinit
nes_probe(struct pci_dev
*pcidev
, const struct pci_device_id
*ent
)
439 struct net_device
*netdev
= NULL
;
440 struct nes_device
*nesdev
= NULL
;
442 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_BIT_MASK(64));
482 printk(KERN_ERR PFX
"64b DMA mask configuration failed\n");
485 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64));
487 printk(KERN_ERR PFX
"64b DMA consistent mask configuration failed\n");
491 ret
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32));
493 printk(KERN_ERR PFX
"32b DMA mask configuration failed\n");
496 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
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
),
524 pci_resource_len(pcidev
, BAR_0
));
525 if (mmio_regs
== NULL
) {
526 printk(KERN_ERR PFX
"Unable to remap BAR0\n");
530 nesdev
->regs
= mmio_regs
;
531 nesdev
->index_reg
= 0x50 + (PCI_FUNC(pcidev
->devfn
)*8) + mmio_regs
;
533 /* Ensure interrupts are disabled */
534 nes_write32(nesdev
->regs
+NES_INT_MASK
, 0x7fffffff);
536 if (nes_drv_opt
& NES_DRV_OPT_ENABLE_MSI
) {
537 if (!pci_enable_msi(nesdev
->pcidev
)) {
538 nesdev
->msi_enabled
= 1;
539 nes_debug(NES_DBG_INIT
, "MSI is enabled for device %s\n",
542 nes_debug(NES_DBG_INIT
, "MSI is disabled by linux for device %s\n",
546 nes_debug(NES_DBG_INIT
, "MSI not requested due to driver options for device %s\n",
550 nesdev
->csr_start
= pci_resource_start(nesdev
->pcidev
, BAR_0
);
551 nesdev
->doorbell_region
= pci_resource_start(nesdev
->pcidev
, BAR_1
);
553 /* Init the adapter */
554 nesdev
->nesadapter
= nes_init_adapter(nesdev
, hw_rev
);
555 if (!nesdev
->nesadapter
) {
556 printk(KERN_ERR PFX
"Unable to initialize adapter.\n");
560 nesdev
->nesadapter
->et_rx_coalesce_usecs_irq
= interrupt_mod_interval
;
561 nesdev
->nesadapter
->wqm_quanta
= wqm_quanta
;
563 /* nesdev->base_doorbell_index =
564 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
565 nesdev
->base_doorbell_index
= 1;
566 nesdev
->doorbell_start
= nesdev
->nesadapter
->doorbell_start
;
567 if (nesdev
->nesadapter
->phy_type
[0] == NES_PHY_TYPE_PUMA_1G
) {
568 switch (PCI_FUNC(nesdev
->pcidev
->devfn
) %
569 nesdev
->nesadapter
->port_count
) {
571 nesdev
->mac_index
= 2;
574 nesdev
->mac_index
= 1;
577 nesdev
->mac_index
= 3;
581 nesdev
->mac_index
= 0;
584 nesdev
->mac_index
= PCI_FUNC(nesdev
->pcidev
->devfn
) %
585 nesdev
->nesadapter
->port_count
;
588 if ((limit_maxrdreqsz
||
589 ((nesdev
->nesadapter
->phy_type
[0] == NES_PHY_TYPE_GLADIUS
) &&
590 (hw_rev
== NE020_REV1
))) &&
591 (pcie_get_readrq(pcidev
) > 256)) {
592 if (pcie_set_readrq(pcidev
, 256))
593 printk(KERN_ERR PFX
"Unable to set max read request"
596 nes_debug(NES_DBG_INIT
, "Max read request size set"
600 tasklet_init(&nesdev
->dpc_tasklet
, nes_dpc
, (unsigned long)nesdev
);
602 /* bring up the Control QP */
603 if (nes_init_cqp(nesdev
)) {
609 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
610 PCI_FUNC(nesdev
->pcidev
->devfn
));
611 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
613 /* Enable the interrupts */
614 nesdev
->int_req
= (0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
)) |
615 (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
616 if (PCI_FUNC(nesdev
->pcidev
->devfn
) < 4) {
617 nesdev
->int_req
|= (1 << (PCI_FUNC(nesdev
->mac_index
)+24));
620 /* TODO: This really should be the first driver to load, not function 0 */
621 if (PCI_FUNC(nesdev
->pcidev
->devfn
) == 0) {
622 /* pick up PCI and critical errors if the first driver to load */
623 nesdev
->intf_int_req
= NES_INTF_INT_PCIERR
| NES_INTF_INT_CRITERR
;
624 nesdev
->int_req
|= NES_INT_INTF
;
626 nesdev
->intf_int_req
= 0;
628 nesdev
->intf_int_req
|= (1 << (PCI_FUNC(nesdev
->pcidev
->devfn
)+16));
629 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS0
, 0);
630 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS1
, 0);
631 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS2
, 0x00001265);
632 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS4
, 0x18021804);
634 nes_write_indexed(nesdev
, NES_IDX_DEBUG_ERROR_MASKS3
, 0x17801790);
636 /* deal with both periodic and one_shot */
637 nesdev
->timer_int_req
= 0x101 << PCI_FUNC(nesdev
->pcidev
->devfn
);
638 nesdev
->nesadapter
->timer_int_req
|= nesdev
->timer_int_req
;
639 nes_debug(NES_DBG_INIT
, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
640 PCI_FUNC(nesdev
->pcidev
->devfn
),
641 nesdev
->timer_int_req
, nesdev
->nesadapter
->timer_int_req
);
643 nes_write32(nesdev
->regs
+NES_INTF_INT_MASK
, ~(nesdev
->intf_int_req
));
645 list_add_tail(&nesdev
->list
, &nes_dev_list
);
647 /* Request an interrupt line for the driver */
648 ret
= request_irq(pcidev
->irq
, nes_interrupt
, IRQF_SHARED
, DRV_NAME
, nesdev
);
650 printk(KERN_ERR PFX
"%s: requested IRQ %u is busy\n",
651 pci_name(pcidev
), pcidev
->irq
);
655 nes_write32(nesdev
->regs
+NES_INT_MASK
, ~nesdev
->int_req
);
657 if (nes_notifiers_registered
== 0) {
658 register_inetaddr_notifier(&nes_inetaddr_notifier
);
659 register_netevent_notifier(&nes_net_notifier
);
661 nes_notifiers_registered
++;
663 /* Initialize network devices */
664 if ((netdev
= nes_netdev_init(nesdev
, mmio_regs
)) == NULL
)
667 /* Register network device */
668 ret
= register_netdev(netdev
);
670 printk(KERN_ERR PFX
"Unable to register netdev, ret = %d\n", ret
);
671 nes_netdev_destroy(netdev
);
675 nes_print_macaddr(netdev
);
677 nesdev
->netdev_count
++;
678 nesdev
->nesadapter
->netdev_count
++;
680 printk(KERN_ERR PFX
"%s: NetEffect RNIC driver successfully loaded.\n",
685 printk(KERN_ERR PFX
"bail7\n");
686 while (nesdev
->netdev_count
> 0) {
687 nesdev
->netdev_count
--;
688 nesdev
->nesadapter
->netdev_count
--;
690 unregister_netdev(nesdev
->netdev
[nesdev
->netdev_count
]);
691 nes_netdev_destroy(nesdev
->netdev
[nesdev
->netdev_count
]);
694 nes_debug(NES_DBG_INIT
, "netdev_count=%d, nesadapter->netdev_count=%d\n",
695 nesdev
->netdev_count
, nesdev
->nesadapter
->netdev_count
);
697 nes_notifiers_registered
--;
698 if (nes_notifiers_registered
== 0) {
699 unregister_netevent_notifier(&nes_net_notifier
);
700 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
703 list_del(&nesdev
->list
);
704 nes_destroy_cqp(nesdev
);
707 printk(KERN_ERR PFX
"bail65\n");
708 free_irq(pcidev
->irq
, nesdev
);
709 if (nesdev
->msi_enabled
) {
710 pci_disable_msi(pcidev
);
713 printk(KERN_ERR PFX
"bail6\n");
714 tasklet_kill(&nesdev
->dpc_tasklet
);
715 /* Deallocate the Adapter Structure */
716 nes_destroy_adapter(nesdev
->nesadapter
);
719 printk(KERN_ERR PFX
"bail5\n");
720 iounmap(nesdev
->regs
);
723 printk(KERN_ERR PFX
"bail3\n");
727 pci_release_regions(pcidev
);
730 pci_disable_device(pcidev
);
738 * nes_remove - unload from kernel
740 static void __devexit
nes_remove(struct pci_dev
*pcidev
)
742 struct nes_device
*nesdev
= pci_get_drvdata(pcidev
);
743 struct net_device
*netdev
;
744 int netdev_index
= 0;
746 if (nesdev
->netdev_count
) {
747 netdev
= nesdev
->netdev
[netdev_index
];
749 netif_stop_queue(netdev
);
750 unregister_netdev(netdev
);
751 nes_netdev_destroy(netdev
);
753 nesdev
->netdev
[netdev_index
] = NULL
;
754 nesdev
->netdev_count
--;
755 nesdev
->nesadapter
->netdev_count
--;
759 nes_notifiers_registered
--;
760 if (nes_notifiers_registered
== 0) {
761 unregister_netevent_notifier(&nes_net_notifier
);
762 unregister_inetaddr_notifier(&nes_inetaddr_notifier
);
765 list_del(&nesdev
->list
);
766 nes_destroy_cqp(nesdev
);
768 free_irq(pcidev
->irq
, nesdev
);
769 tasklet_kill(&nesdev
->dpc_tasklet
);
771 /* Deallocate the Adapter Structure */
772 nes_destroy_adapter(nesdev
->nesadapter
);
774 if (nesdev
->msi_enabled
) {
775 pci_disable_msi(pcidev
);
778 iounmap(nesdev
->regs
);
781 /* nes_debug(NES_DBG_SHUTDOWN, "calling pci_release_regions.\n"); */
782 pci_release_regions(pcidev
);
783 pci_disable_device(pcidev
);
784 pci_set_drvdata(pcidev
, NULL
);
788 static struct pci_driver nes_pci_driver
= {
790 .id_table
= nes_pci_table
,
792 .remove
= __devexit_p(nes_remove
),
795 static ssize_t
nes_show_adapter(struct device_driver
*ddp
, char *buf
)
797 unsigned int devfn
= 0xffffffff;
798 unsigned char bus_number
= 0xff;
800 struct nes_device
*nesdev
;
802 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
803 if (i
== ee_flsh_adapter
) {
804 devfn
= nesdev
->pcidev
->devfn
;
805 bus_number
= nesdev
->pcidev
->bus
->number
;
811 return snprintf(buf
, PAGE_SIZE
, "%x:%x\n", bus_number
, devfn
);
814 static ssize_t
nes_store_adapter(struct device_driver
*ddp
,
815 const char *buf
, size_t count
)
817 char *p
= (char *)buf
;
819 ee_flsh_adapter
= simple_strtoul(p
, &p
, 10);
820 return strnlen(buf
, count
);
823 static ssize_t
nes_show_ee_cmd(struct device_driver
*ddp
, char *buf
)
825 u32 eeprom_cmd
= 0xdead;
827 struct nes_device
*nesdev
;
829 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
830 if (i
== ee_flsh_adapter
) {
831 eeprom_cmd
= nes_read32(nesdev
->regs
+ NES_EEPROM_COMMAND
);
836 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_cmd
);
839 static ssize_t
nes_store_ee_cmd(struct device_driver
*ddp
,
840 const char *buf
, size_t count
)
842 char *p
= (char *)buf
;
845 struct nes_device
*nesdev
;
847 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
848 val
= simple_strtoul(p
, &p
, 16);
849 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
850 if (i
== ee_flsh_adapter
) {
851 nes_write32(nesdev
->regs
+ NES_EEPROM_COMMAND
, val
);
857 return strnlen(buf
, count
);
860 static ssize_t
nes_show_ee_data(struct device_driver
*ddp
, char *buf
)
862 u32 eeprom_data
= 0xdead;
864 struct nes_device
*nesdev
;
866 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
867 if (i
== ee_flsh_adapter
) {
868 eeprom_data
= nes_read32(nesdev
->regs
+ NES_EEPROM_DATA
);
874 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", eeprom_data
);
877 static ssize_t
nes_store_ee_data(struct device_driver
*ddp
,
878 const char *buf
, size_t count
)
880 char *p
= (char *)buf
;
883 struct nes_device
*nesdev
;
885 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
886 val
= simple_strtoul(p
, &p
, 16);
887 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
888 if (i
== ee_flsh_adapter
) {
889 nes_write32(nesdev
->regs
+ NES_EEPROM_DATA
, val
);
895 return strnlen(buf
, count
);
898 static ssize_t
nes_show_flash_cmd(struct device_driver
*ddp
, char *buf
)
900 u32 flash_cmd
= 0xdead;
902 struct nes_device
*nesdev
;
904 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
905 if (i
== ee_flsh_adapter
) {
906 flash_cmd
= nes_read32(nesdev
->regs
+ NES_FLASH_COMMAND
);
912 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_cmd
);
915 static ssize_t
nes_store_flash_cmd(struct device_driver
*ddp
,
916 const char *buf
, size_t count
)
918 char *p
= (char *)buf
;
921 struct nes_device
*nesdev
;
923 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
924 val
= simple_strtoul(p
, &p
, 16);
925 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
926 if (i
== ee_flsh_adapter
) {
927 nes_write32(nesdev
->regs
+ NES_FLASH_COMMAND
, val
);
933 return strnlen(buf
, count
);
936 static ssize_t
nes_show_flash_data(struct device_driver
*ddp
, char *buf
)
938 u32 flash_data
= 0xdead;
940 struct nes_device
*nesdev
;
942 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
943 if (i
== ee_flsh_adapter
) {
944 flash_data
= nes_read32(nesdev
->regs
+ NES_FLASH_DATA
);
950 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", flash_data
);
953 static ssize_t
nes_store_flash_data(struct device_driver
*ddp
,
954 const char *buf
, size_t count
)
956 char *p
= (char *)buf
;
959 struct nes_device
*nesdev
;
961 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
962 val
= simple_strtoul(p
, &p
, 16);
963 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
964 if (i
== ee_flsh_adapter
) {
965 nes_write32(nesdev
->regs
+ NES_FLASH_DATA
, val
);
971 return strnlen(buf
, count
);
974 static ssize_t
nes_show_nonidx_addr(struct device_driver
*ddp
, char *buf
)
976 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_nonidx_addr
);
979 static ssize_t
nes_store_nonidx_addr(struct device_driver
*ddp
,
980 const char *buf
, size_t count
)
982 char *p
= (char *)buf
;
984 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
985 sysfs_nonidx_addr
= simple_strtoul(p
, &p
, 16);
987 return strnlen(buf
, count
);
990 static ssize_t
nes_show_nonidx_data(struct device_driver
*ddp
, char *buf
)
992 u32 nonidx_data
= 0xdead;
994 struct nes_device
*nesdev
;
996 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
997 if (i
== ee_flsh_adapter
) {
998 nonidx_data
= nes_read32(nesdev
->regs
+ sysfs_nonidx_addr
);
1004 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", nonidx_data
);
1007 static ssize_t
nes_store_nonidx_data(struct device_driver
*ddp
,
1008 const char *buf
, size_t count
)
1010 char *p
= (char *)buf
;
1013 struct nes_device
*nesdev
;
1015 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1016 val
= simple_strtoul(p
, &p
, 16);
1017 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1018 if (i
== ee_flsh_adapter
) {
1019 nes_write32(nesdev
->regs
+ sysfs_nonidx_addr
, val
);
1025 return strnlen(buf
, count
);
1028 static ssize_t
nes_show_idx_addr(struct device_driver
*ddp
, char *buf
)
1030 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", sysfs_idx_addr
);
1033 static ssize_t
nes_store_idx_addr(struct device_driver
*ddp
,
1034 const char *buf
, size_t count
)
1036 char *p
= (char *)buf
;
1038 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X')
1039 sysfs_idx_addr
= simple_strtoul(p
, &p
, 16);
1041 return strnlen(buf
, count
);
1044 static ssize_t
nes_show_idx_data(struct device_driver
*ddp
, char *buf
)
1046 u32 idx_data
= 0xdead;
1048 struct nes_device
*nesdev
;
1050 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1051 if (i
== ee_flsh_adapter
) {
1052 idx_data
= nes_read_indexed(nesdev
, sysfs_idx_addr
);
1058 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", idx_data
);
1061 static ssize_t
nes_store_idx_data(struct device_driver
*ddp
,
1062 const char *buf
, size_t count
)
1064 char *p
= (char *)buf
;
1067 struct nes_device
*nesdev
;
1069 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1070 val
= simple_strtoul(p
, &p
, 16);
1071 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1072 if (i
== ee_flsh_adapter
) {
1073 nes_write_indexed(nesdev
, sysfs_idx_addr
, val
);
1079 return strnlen(buf
, count
);
1084 * nes_show_wqm_quanta
1086 static ssize_t
nes_show_wqm_quanta(struct device_driver
*ddp
, char *buf
)
1088 u32 wqm_quanta_value
= 0xdead;
1090 struct nes_device
*nesdev
;
1092 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1093 if (i
== ee_flsh_adapter
) {
1094 wqm_quanta_value
= nesdev
->nesadapter
->wqm_quanta
;
1100 return snprintf(buf
, PAGE_SIZE
, "0x%X\n", wqm_quanta_value
);
1105 * nes_store_wqm_quanta
1107 static ssize_t
nes_store_wqm_quanta(struct device_driver
*ddp
,
1108 const char *buf
, size_t count
)
1110 unsigned long wqm_quanta_value
;
1113 struct nes_device
*nesdev
;
1115 strict_strtoul(buf
, 0, &wqm_quanta_value
);
1116 list_for_each_entry(nesdev
, &nes_dev_list
, list
) {
1117 if (i
== ee_flsh_adapter
) {
1118 nesdev
->nesadapter
->wqm_quanta
= wqm_quanta_value
;
1119 wqm_config1
= nes_read_indexed(nesdev
,
1120 NES_IDX_WQM_CONFIG1
);
1121 nes_write_indexed(nesdev
, NES_IDX_WQM_CONFIG1
,
1122 ((wqm_quanta_value
<< 1) |
1123 (wqm_config1
& 0x00000001)));
1128 return strnlen(buf
, count
);
1131 static DRIVER_ATTR(adapter
, S_IRUSR
| S_IWUSR
,
1132 nes_show_adapter
, nes_store_adapter
);
1133 static DRIVER_ATTR(eeprom_cmd
, S_IRUSR
| S_IWUSR
,
1134 nes_show_ee_cmd
, nes_store_ee_cmd
);
1135 static DRIVER_ATTR(eeprom_data
, S_IRUSR
| S_IWUSR
,
1136 nes_show_ee_data
, nes_store_ee_data
);
1137 static DRIVER_ATTR(flash_cmd
, S_IRUSR
| S_IWUSR
,
1138 nes_show_flash_cmd
, nes_store_flash_cmd
);
1139 static DRIVER_ATTR(flash_data
, S_IRUSR
| S_IWUSR
,
1140 nes_show_flash_data
, nes_store_flash_data
);
1141 static DRIVER_ATTR(nonidx_addr
, S_IRUSR
| S_IWUSR
,
1142 nes_show_nonidx_addr
, nes_store_nonidx_addr
);
1143 static DRIVER_ATTR(nonidx_data
, S_IRUSR
| S_IWUSR
,
1144 nes_show_nonidx_data
, nes_store_nonidx_data
);
1145 static DRIVER_ATTR(idx_addr
, S_IRUSR
| S_IWUSR
,
1146 nes_show_idx_addr
, nes_store_idx_addr
);
1147 static DRIVER_ATTR(idx_data
, S_IRUSR
| S_IWUSR
,
1148 nes_show_idx_data
, nes_store_idx_data
);
1149 static DRIVER_ATTR(wqm_quanta
, S_IRUSR
| S_IWUSR
,
1150 nes_show_wqm_quanta
, nes_store_wqm_quanta
);
1152 static int nes_create_driver_sysfs(struct pci_driver
*drv
)
1155 error
= driver_create_file(&drv
->driver
, &driver_attr_adapter
);
1156 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1157 error
|= driver_create_file(&drv
->driver
, &driver_attr_eeprom_data
);
1158 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_cmd
);
1159 error
|= driver_create_file(&drv
->driver
, &driver_attr_flash_data
);
1160 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1161 error
|= driver_create_file(&drv
->driver
, &driver_attr_nonidx_data
);
1162 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_addr
);
1163 error
|= driver_create_file(&drv
->driver
, &driver_attr_idx_data
);
1164 error
|= driver_create_file(&drv
->driver
, &driver_attr_wqm_quanta
);
1168 static void nes_remove_driver_sysfs(struct pci_driver
*drv
)
1170 driver_remove_file(&drv
->driver
, &driver_attr_adapter
);
1171 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_cmd
);
1172 driver_remove_file(&drv
->driver
, &driver_attr_eeprom_data
);
1173 driver_remove_file(&drv
->driver
, &driver_attr_flash_cmd
);
1174 driver_remove_file(&drv
->driver
, &driver_attr_flash_data
);
1175 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_addr
);
1176 driver_remove_file(&drv
->driver
, &driver_attr_nonidx_data
);
1177 driver_remove_file(&drv
->driver
, &driver_attr_idx_addr
);
1178 driver_remove_file(&drv
->driver
, &driver_attr_idx_data
);
1179 driver_remove_file(&drv
->driver
, &driver_attr_wqm_quanta
);
1183 * nes_init_module - module initialization entry point
1185 static int __init
nes_init_module(void)
1190 retval
= nes_cm_start();
1192 printk(KERN_ERR PFX
"Unable to start NetEffect iWARP CM.\n");
1195 retval
= pci_register_driver(&nes_pci_driver
);
1197 retval1
= nes_create_driver_sysfs(&nes_pci_driver
);
1199 printk(KERN_ERR PFX
"Unable to create NetEffect sys files.\n");
1206 * nes_exit_module - module unload entry point
1208 static void __exit
nes_exit_module(void)
1211 nes_remove_driver_sysfs(&nes_pci_driver
);
1213 pci_unregister_driver(&nes_pci_driver
);
1217 module_init(nes_init_module
);
1218 module_exit(nes_exit_module
);