1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/netdevice.h>
37#include <linux/etherdevice.h>
38#include <linux/ethtool.h>
39#include <linux/mii.h>
40#include <linux/if_vlan.h>
41#include <linux/crc32.h>
42#include <linux/in.h>
43#include <linux/fs.h>
44#include <linux/init.h>
45#include <linux/if_arp.h>
46#include <linux/highmem.h>
47#include <linux/slab.h>
48#include <asm/io.h>
49#include <asm/irq.h>
50#include <asm/byteorder.h>
51#include <rdma/ib_smi.h>
52#include <rdma/ib_verbs.h>
53#include <rdma/ib_pack.h>
54#include <rdma/iw_cm.h>
55
56#include "nes.h"
57
58#include <net/netevent.h>
59#include <net/neighbour.h>
60#include <linux/route.h>
61#include <net/ip_fib.h>
62
63MODULE_AUTHOR("NetEffect");
64MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
65MODULE_LICENSE("Dual BSD/GPL");
66
67int interrupt_mod_interval = 0;
68
69
70int mpa_version = 1;
71module_param(mpa_version, int, 0644);
72MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
73
74
75int disable_mpa_crc = 0;
76module_param(disable_mpa_crc, int, 0644);
77MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
78
79unsigned int nes_drv_opt = NES_DRV_OPT_DISABLE_INT_MOD | NES_DRV_OPT_ENABLE_PAU;
80module_param(nes_drv_opt, int, 0644);
81MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
82
83unsigned int nes_debug_level = 0;
84module_param_named(debug_level, nes_debug_level, uint, 0644);
85MODULE_PARM_DESC(debug_level, "Enable debug output level");
86
87unsigned int wqm_quanta = 0x10000;
88module_param(wqm_quanta, int, 0644);
89MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
90
91static bool limit_maxrdreqsz;
92module_param(limit_maxrdreqsz, bool, 0644);
93MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
94
95LIST_HEAD(nes_adapter_list);
96static LIST_HEAD(nes_dev_list);
97
98atomic_t qps_destroyed;
99
100static unsigned int ee_flsh_adapter;
101static unsigned int sysfs_nonidx_addr;
102static unsigned int sysfs_idx_addr;
103
104static const struct pci_device_id nes_pci_table[] = {
105 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020), },
106 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020_KR), },
107 {0}
108};
109
110MODULE_DEVICE_TABLE(pci, nes_pci_table);
111
112static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
113static int nes_net_event(struct notifier_block *, unsigned long, void *);
114static int nes_notifiers_registered;
115
116
117static struct notifier_block nes_inetaddr_notifier = {
118 .notifier_call = nes_inetaddr_event
119};
120
121static struct notifier_block nes_net_notifier = {
122 .notifier_call = nes_net_event
123};
124
125
126
127
128static int nes_inetaddr_event(struct notifier_block *notifier,
129 unsigned long event, void *ptr)
130{
131 struct in_ifaddr *ifa = ptr;
132 struct net_device *event_netdev = ifa->ifa_dev->dev;
133 struct nes_device *nesdev;
134 struct net_device *netdev;
135 struct net_device *upper_dev;
136 struct nes_vnic *nesvnic;
137 unsigned int is_bonded;
138
139 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
140 &ifa->ifa_address, &ifa->ifa_mask);
141 list_for_each_entry(nesdev, &nes_dev_list, list) {
142 nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
143 nesdev, nesdev->netdev[0]->name);
144 netdev = nesdev->netdev[0];
145 nesvnic = netdev_priv(netdev);
146 upper_dev = netdev_master_upper_dev_get(netdev);
147 is_bonded = netif_is_bond_slave(netdev) &&
148 (upper_dev == event_netdev);
149 if ((netdev == event_netdev) || is_bonded) {
150 if (nesvnic->rdma_enabled == 0) {
151 nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
152 " RDMA is not enabled.\n",
153 netdev->name);
154 return NOTIFY_OK;
155 }
156
157 switch (event) {
158 case NETDEV_DOWN:
159 nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
160 nes_write_indexed(nesdev,
161 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
162
163 nes_manage_arp_cache(netdev, netdev->dev_addr,
164 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
165 nesvnic->local_ipaddr = 0;
166 if (is_bonded)
167 continue;
168 else
169 return NOTIFY_OK;
170 break;
171 case NETDEV_UP:
172 nes_debug(NES_DBG_NETDEV, "event:UP\n");
173
174 if (nesvnic->local_ipaddr != 0) {
175 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
176 return NOTIFY_OK;
177 }
178
179 case NETDEV_CHANGEADDR:
180
181 if (upper_dev)
182 nesvnic->local_ipaddr =
183 ((struct in_device *)upper_dev->ip_ptr)->ifa_list->ifa_address;
184 else
185 nesvnic->local_ipaddr = ifa->ifa_address;
186
187 nes_write_indexed(nesdev,
188 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
189 ntohl(nesvnic->local_ipaddr));
190 nes_manage_arp_cache(netdev, netdev->dev_addr,
191 ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
192 if (is_bonded)
193 continue;
194 else
195 return NOTIFY_OK;
196 break;
197 default:
198 break;
199 }
200 }
201 }
202
203 return NOTIFY_DONE;
204}
205
206
207
208
209
210static int nes_net_event(struct notifier_block *notifier,
211 unsigned long event, void *ptr)
212{
213 struct neighbour *neigh = ptr;
214 struct nes_device *nesdev;
215 struct net_device *netdev;
216 struct nes_vnic *nesvnic;
217
218 switch (event) {
219 case NETEVENT_NEIGH_UPDATE:
220 list_for_each_entry(nesdev, &nes_dev_list, list) {
221
222 netdev = nesdev->netdev[0];
223 nesvnic = netdev_priv(netdev);
224 if (netdev == neigh->dev) {
225 if (nesvnic->rdma_enabled == 0) {
226 nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
227 netdev->name);
228 } else {
229 if (neigh->nud_state & NUD_VALID) {
230 nes_manage_arp_cache(neigh->dev, neigh->ha,
231 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
232 } else {
233 nes_manage_arp_cache(neigh->dev, neigh->ha,
234 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
235 }
236 }
237 return NOTIFY_OK;
238 }
239 }
240 break;
241 default:
242 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
243 break;
244 }
245
246 return NOTIFY_DONE;
247}
248
249
250
251
252
253void nes_add_ref(struct ib_qp *ibqp)
254{
255 struct nes_qp *nesqp;
256
257 nesqp = to_nesqp(ibqp);
258 nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
259 ibqp->qp_num, atomic_read(&nesqp->refcount));
260 atomic_inc(&nesqp->refcount);
261}
262
263static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
264{
265 unsigned long flags;
266 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
267 struct nes_adapter *nesadapter = nesdev->nesadapter;
268
269 atomic_inc(&qps_destroyed);
270
271
272
273 if (nesqp->pbl_vbase) {
274 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
275 nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
276 spin_lock_irqsave(&nesadapter->pbl_lock, flags);
277 nesadapter->free_256pbl++;
278 spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
279 pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
280 nesqp->pbl_vbase = NULL;
281
282 } else {
283 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
284 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
285 }
286 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
287
288 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
289 kfree(nesqp->allocated_buffer);
290
291}
292
293
294
295
296void nes_rem_ref(struct ib_qp *ibqp)
297{
298 u64 u64temp;
299 struct nes_qp *nesqp;
300 struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
301 struct nes_device *nesdev = nesvnic->nesdev;
302 struct nes_hw_cqp_wqe *cqp_wqe;
303 struct nes_cqp_request *cqp_request;
304 u32 opcode;
305
306 nesqp = to_nesqp(ibqp);
307
308 if (atomic_read(&nesqp->refcount) == 0) {
309 printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
310 __func__, ibqp->qp_num, nesqp->last_aeq);
311 BUG();
312 }
313
314 if (atomic_dec_and_test(&nesqp->refcount)) {
315 if (nesqp->pau_mode)
316 nes_destroy_pau_qp(nesdev, nesqp);
317
318
319 cqp_request = nes_get_cqp_request(nesdev);
320 if (cqp_request == NULL) {
321 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
322 return;
323 }
324 cqp_request->waiting = 0;
325 cqp_request->callback = 1;
326 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
327 cqp_request->cqp_callback_pointer = nesqp;
328 cqp_wqe = &cqp_request->cqp_wqe;
329
330 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
331 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
332
333 if (nesqp->hte_added) {
334 opcode |= NES_CQP_QP_DEL_HTE;
335 nesqp->hte_added = 0;
336 }
337 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
338 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
339 u64temp = (u64)nesqp->nesqp_context_pbase;
340 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
341 nes_post_cqp_request(nesdev, cqp_request);
342 }
343}
344
345
346
347
348
349struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
350{
351 struct nes_vnic *nesvnic = to_nesvnic(device);
352 struct nes_device *nesdev = nesvnic->nesdev;
353 struct nes_adapter *nesadapter = nesdev->nesadapter;
354
355 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
356 return NULL;
357
358 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
359}
360
361
362
363
364
365static void nes_print_macaddr(struct net_device *netdev)
366{
367 nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
368 netdev->name, netdev->dev_addr, netdev->irq);
369}
370
371
372
373
374static irqreturn_t nes_interrupt(int irq, void *dev_id)
375{
376 struct nes_device *nesdev = (struct nes_device *)dev_id;
377 int handled = 0;
378 u32 int_mask;
379 u32 int_req;
380 u32 int_stat;
381 u32 intf_int_stat;
382 u32 timer_stat;
383
384 if (nesdev->msi_enabled) {
385
386 handled = 1;
387 } else {
388 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
389
390
391 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
392 if (int_mask & 0x80000000) {
393
394 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
395 int_req = nesdev->int_req;
396 if (int_stat&int_req) {
397
398 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
399 handled = 1;
400 } else {
401 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
402
403 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
404 if ((timer_stat & nesdev->timer_int_req) != 0) {
405 handled = 1;
406 }
407 }
408 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
409 (handled == 0)) {
410 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
411 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
412 handled = 1;
413 }
414 }
415 }
416 if (handled) {
417 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
418 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
419
420 nesdev->int_stat = int_stat;
421 nesdev->napi_isr_ran = 1;
422 }
423 }
424 }
425 } else {
426 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
427 }
428 }
429
430 if (handled) {
431
432 if (nes_napi_isr(nesdev) == 0) {
433 tasklet_schedule(&nesdev->dpc_tasklet);
434
435 }
436 return IRQ_HANDLED;
437 } else {
438 return IRQ_NONE;
439 }
440}
441
442
443
444
445
446static int nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
447{
448 struct net_device *netdev = NULL;
449 struct nes_device *nesdev = NULL;
450 int ret = 0;
451 void __iomem *mmio_regs = NULL;
452 u8 hw_rev;
453
454 assert(pcidev != NULL);
455 assert(ent != NULL);
456
457 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
458 DRV_VERSION, pci_name(pcidev));
459
460 ret = pci_enable_device(pcidev);
461 if (ret) {
462 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
463 goto bail0;
464 }
465
466 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
467 (long unsigned int)pci_resource_start(pcidev, BAR_0),
468 (long unsigned int)pci_resource_len(pcidev, BAR_0));
469 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
470 (long unsigned int)pci_resource_start(pcidev, BAR_1),
471 (long unsigned int)pci_resource_len(pcidev, BAR_1));
472
473
474 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
475 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
476 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
477 ret = -ENODEV;
478 goto bail1;
479 }
480
481
482 ret = pci_request_regions(pcidev, DRV_NAME);
483 if (ret) {
484 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
485 goto bail1;
486 }
487
488 if ((sizeof(dma_addr_t) > 4)) {
489 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
490 if (ret < 0) {
491 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
492 goto bail2;
493 }
494 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
495 if (ret) {
496 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
497 goto bail2;
498 }
499 } else {
500 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
501 if (ret < 0) {
502 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
503 goto bail2;
504 }
505 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
506 if (ret) {
507 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
508 goto bail2;
509 }
510 }
511
512 pci_set_master(pcidev);
513
514
515 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
516 if (!nesdev) {
517 ret = -ENOMEM;
518 goto bail2;
519 }
520
521 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
522 nesdev->pcidev = pcidev;
523 pci_set_drvdata(pcidev, nesdev);
524
525 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
526 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
527
528 spin_lock_init(&nesdev->indexed_regs_lock);
529
530
531 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0),
532 pci_resource_len(pcidev, BAR_0));
533 if (mmio_regs == NULL) {
534 printk(KERN_ERR PFX "Unable to remap BAR0\n");
535 ret = -EIO;
536 goto bail3;
537 }
538 nesdev->regs = mmio_regs;
539 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
540
541
542 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
543
544 if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
545 if (!pci_enable_msi(nesdev->pcidev)) {
546 nesdev->msi_enabled = 1;
547 nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
548 pci_name(pcidev));
549 } else {
550 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
551 pci_name(pcidev));
552 }
553 } else {
554 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
555 pci_name(pcidev));
556 }
557
558 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
559 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
560
561
562 nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
563 if (!nesdev->nesadapter) {
564 printk(KERN_ERR PFX "Unable to initialize adapter.\n");
565 ret = -ENOMEM;
566 goto bail5;
567 }
568 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
569 nesdev->nesadapter->wqm_quanta = wqm_quanta;
570
571
572
573 nesdev->base_doorbell_index = 1;
574 nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
575 if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
576 switch (PCI_FUNC(nesdev->pcidev->devfn) %
577 nesdev->nesadapter->port_count) {
578 case 1:
579 nesdev->mac_index = 2;
580 break;
581 case 2:
582 nesdev->mac_index = 1;
583 break;
584 case 3:
585 nesdev->mac_index = 3;
586 break;
587 case 0:
588 default:
589 nesdev->mac_index = 0;
590 }
591 } else {
592 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
593 nesdev->nesadapter->port_count;
594 }
595
596 if ((limit_maxrdreqsz ||
597 ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
598 (hw_rev == NE020_REV1))) &&
599 (pcie_get_readrq(pcidev) > 256)) {
600 if (pcie_set_readrq(pcidev, 256))
601 printk(KERN_ERR PFX "Unable to set max read request"
602 " to 256 bytes\n");
603 else
604 nes_debug(NES_DBG_INIT, "Max read request size set"
605 " to 256 bytes\n");
606 }
607
608 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
609
610
611 if (nes_init_cqp(nesdev)) {
612 ret = -ENODEV;
613 goto bail6;
614 }
615
616
617 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
618 PCI_FUNC(nesdev->pcidev->devfn));
619 nes_read32(nesdev->regs+NES_CQE_ALLOC);
620
621
622 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
623 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
624 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
625 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
626 }
627
628
629 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
630
631 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
632 nesdev->int_req |= NES_INT_INTF;
633 } else {
634 nesdev->intf_int_req = 0;
635 }
636 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
637 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
638 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
639 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
640 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
641
642 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
643
644
645 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
646 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
647 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
648 PCI_FUNC(nesdev->pcidev->devfn),
649 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
650
651 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
652
653 list_add_tail(&nesdev->list, &nes_dev_list);
654
655
656 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
657 if (ret) {
658 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
659 pci_name(pcidev), pcidev->irq);
660 goto bail65;
661 }
662
663 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
664
665 if (nes_notifiers_registered == 0) {
666 register_inetaddr_notifier(&nes_inetaddr_notifier);
667 register_netevent_notifier(&nes_net_notifier);
668 }
669 nes_notifiers_registered++;
670
671 INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
672
673
674 netdev = nes_netdev_init(nesdev, mmio_regs);
675 if (netdev == NULL) {
676 ret = -ENOMEM;
677 goto bail7;
678 }
679
680
681 ret = register_netdev(netdev);
682 if (ret) {
683 printk(KERN_ERR PFX "Unable to register netdev, ret = %d\n", ret);
684 nes_netdev_destroy(netdev);
685 goto bail7;
686 }
687
688 nes_print_macaddr(netdev);
689
690 nesdev->netdev_count++;
691 nesdev->nesadapter->netdev_count++;
692
693 printk(KERN_INFO PFX "%s: NetEffect RNIC driver successfully loaded.\n",
694 pci_name(pcidev));
695 return 0;
696
697 bail7:
698 printk(KERN_ERR PFX "bail7\n");
699 while (nesdev->netdev_count > 0) {
700 nesdev->netdev_count--;
701 nesdev->nesadapter->netdev_count--;
702
703 unregister_netdev(nesdev->netdev[nesdev->netdev_count]);
704 nes_netdev_destroy(nesdev->netdev[nesdev->netdev_count]);
705 }
706
707 nes_debug(NES_DBG_INIT, "netdev_count=%d, nesadapter->netdev_count=%d\n",
708 nesdev->netdev_count, nesdev->nesadapter->netdev_count);
709
710 nes_notifiers_registered--;
711 if (nes_notifiers_registered == 0) {
712 unregister_netevent_notifier(&nes_net_notifier);
713 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
714 }
715
716 list_del(&nesdev->list);
717 nes_destroy_cqp(nesdev);
718
719 bail65:
720 printk(KERN_ERR PFX "bail65\n");
721 free_irq(pcidev->irq, nesdev);
722 if (nesdev->msi_enabled) {
723 pci_disable_msi(pcidev);
724 }
725 bail6:
726 printk(KERN_ERR PFX "bail6\n");
727 tasklet_kill(&nesdev->dpc_tasklet);
728
729 nes_destroy_adapter(nesdev->nesadapter);
730
731 bail5:
732 printk(KERN_ERR PFX "bail5\n");
733 iounmap(nesdev->regs);
734
735 bail3:
736 printk(KERN_ERR PFX "bail3\n");
737 kfree(nesdev);
738
739 bail2:
740 pci_release_regions(pcidev);
741
742 bail1:
743 pci_disable_device(pcidev);
744
745 bail0:
746 return ret;
747}
748
749
750
751
752
753static void nes_remove(struct pci_dev *pcidev)
754{
755 struct nes_device *nesdev = pci_get_drvdata(pcidev);
756 struct net_device *netdev;
757 int netdev_index = 0;
758 unsigned long flags;
759
760 if (nesdev->netdev_count) {
761 netdev = nesdev->netdev[netdev_index];
762 if (netdev) {
763 netif_stop_queue(netdev);
764 unregister_netdev(netdev);
765 nes_netdev_destroy(netdev);
766
767 nesdev->netdev[netdev_index] = NULL;
768 nesdev->netdev_count--;
769 nesdev->nesadapter->netdev_count--;
770 }
771 }
772
773 nes_notifiers_registered--;
774 if (nes_notifiers_registered == 0) {
775 unregister_netevent_notifier(&nes_net_notifier);
776 unregister_inetaddr_notifier(&nes_inetaddr_notifier);
777 }
778
779 list_del(&nesdev->list);
780 nes_destroy_cqp(nesdev);
781
782 free_irq(pcidev->irq, nesdev);
783 tasklet_kill(&nesdev->dpc_tasklet);
784
785 spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
786 if (nesdev->link_recheck) {
787 spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
788 cancel_delayed_work_sync(&nesdev->work);
789 } else {
790 spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
791 }
792
793
794 nes_destroy_adapter(nesdev->nesadapter);
795
796 if (nesdev->msi_enabled) {
797 pci_disable_msi(pcidev);
798 }
799
800 iounmap(nesdev->regs);
801 kfree(nesdev);
802
803
804 pci_release_regions(pcidev);
805 pci_disable_device(pcidev);
806 pci_set_drvdata(pcidev, NULL);
807}
808
809
810static ssize_t adapter_show(struct device_driver *ddp, char *buf)
811{
812 unsigned int devfn = 0xffffffff;
813 unsigned char bus_number = 0xff;
814 unsigned int i = 0;
815 struct nes_device *nesdev;
816
817 list_for_each_entry(nesdev, &nes_dev_list, list) {
818 if (i == ee_flsh_adapter) {
819 devfn = nesdev->pcidev->devfn;
820 bus_number = nesdev->pcidev->bus->number;
821 break;
822 }
823 i++;
824 }
825
826 return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
827}
828
829static ssize_t adapter_store(struct device_driver *ddp,
830 const char *buf, size_t count)
831{
832 char *p = (char *)buf;
833
834 ee_flsh_adapter = simple_strtoul(p, &p, 10);
835 return strnlen(buf, count);
836}
837
838static ssize_t eeprom_cmd_show(struct device_driver *ddp, char *buf)
839{
840 u32 eeprom_cmd = 0xdead;
841 u32 i = 0;
842 struct nes_device *nesdev;
843
844 list_for_each_entry(nesdev, &nes_dev_list, list) {
845 if (i == ee_flsh_adapter) {
846 eeprom_cmd = nes_read32(nesdev->regs + NES_EEPROM_COMMAND);
847 break;
848 }
849 i++;
850 }
851 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_cmd);
852}
853
854static ssize_t eeprom_cmd_store(struct device_driver *ddp,
855 const char *buf, size_t count)
856{
857 char *p = (char *)buf;
858 u32 val;
859 u32 i = 0;
860 struct nes_device *nesdev;
861
862 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
863 val = simple_strtoul(p, &p, 16);
864 list_for_each_entry(nesdev, &nes_dev_list, list) {
865 if (i == ee_flsh_adapter) {
866 nes_write32(nesdev->regs + NES_EEPROM_COMMAND, val);
867 break;
868 }
869 i++;
870 }
871 }
872 return strnlen(buf, count);
873}
874
875static ssize_t eeprom_data_show(struct device_driver *ddp, char *buf)
876{
877 u32 eeprom_data = 0xdead;
878 u32 i = 0;
879 struct nes_device *nesdev;
880
881 list_for_each_entry(nesdev, &nes_dev_list, list) {
882 if (i == ee_flsh_adapter) {
883 eeprom_data = nes_read32(nesdev->regs + NES_EEPROM_DATA);
884 break;
885 }
886 i++;
887 }
888
889 return snprintf(buf, PAGE_SIZE, "0x%x\n", eeprom_data);
890}
891
892static ssize_t eeprom_data_store(struct device_driver *ddp,
893 const char *buf, size_t count)
894{
895 char *p = (char *)buf;
896 u32 val;
897 u32 i = 0;
898 struct nes_device *nesdev;
899
900 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
901 val = simple_strtoul(p, &p, 16);
902 list_for_each_entry(nesdev, &nes_dev_list, list) {
903 if (i == ee_flsh_adapter) {
904 nes_write32(nesdev->regs + NES_EEPROM_DATA, val);
905 break;
906 }
907 i++;
908 }
909 }
910 return strnlen(buf, count);
911}
912
913static ssize_t flash_cmd_show(struct device_driver *ddp, char *buf)
914{
915 u32 flash_cmd = 0xdead;
916 u32 i = 0;
917 struct nes_device *nesdev;
918
919 list_for_each_entry(nesdev, &nes_dev_list, list) {
920 if (i == ee_flsh_adapter) {
921 flash_cmd = nes_read32(nesdev->regs + NES_FLASH_COMMAND);
922 break;
923 }
924 i++;
925 }
926
927 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_cmd);
928}
929
930static ssize_t flash_cmd_store(struct device_driver *ddp,
931 const char *buf, size_t count)
932{
933 char *p = (char *)buf;
934 u32 val;
935 u32 i = 0;
936 struct nes_device *nesdev;
937
938 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
939 val = simple_strtoul(p, &p, 16);
940 list_for_each_entry(nesdev, &nes_dev_list, list) {
941 if (i == ee_flsh_adapter) {
942 nes_write32(nesdev->regs + NES_FLASH_COMMAND, val);
943 break;
944 }
945 i++;
946 }
947 }
948 return strnlen(buf, count);
949}
950
951static ssize_t flash_data_show(struct device_driver *ddp, char *buf)
952{
953 u32 flash_data = 0xdead;
954 u32 i = 0;
955 struct nes_device *nesdev;
956
957 list_for_each_entry(nesdev, &nes_dev_list, list) {
958 if (i == ee_flsh_adapter) {
959 flash_data = nes_read32(nesdev->regs + NES_FLASH_DATA);
960 break;
961 }
962 i++;
963 }
964
965 return snprintf(buf, PAGE_SIZE, "0x%x\n", flash_data);
966}
967
968static ssize_t flash_data_store(struct device_driver *ddp,
969 const char *buf, size_t count)
970{
971 char *p = (char *)buf;
972 u32 val;
973 u32 i = 0;
974 struct nes_device *nesdev;
975
976 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
977 val = simple_strtoul(p, &p, 16);
978 list_for_each_entry(nesdev, &nes_dev_list, list) {
979 if (i == ee_flsh_adapter) {
980 nes_write32(nesdev->regs + NES_FLASH_DATA, val);
981 break;
982 }
983 i++;
984 }
985 }
986 return strnlen(buf, count);
987}
988
989static ssize_t nonidx_addr_show(struct device_driver *ddp, char *buf)
990{
991 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_nonidx_addr);
992}
993
994static ssize_t nonidx_addr_store(struct device_driver *ddp,
995 const char *buf, size_t count)
996{
997 char *p = (char *)buf;
998
999 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1000 sysfs_nonidx_addr = simple_strtoul(p, &p, 16);
1001
1002 return strnlen(buf, count);
1003}
1004
1005static ssize_t nonidx_data_show(struct device_driver *ddp, char *buf)
1006{
1007 u32 nonidx_data = 0xdead;
1008 u32 i = 0;
1009 struct nes_device *nesdev;
1010
1011 list_for_each_entry(nesdev, &nes_dev_list, list) {
1012 if (i == ee_flsh_adapter) {
1013 nonidx_data = nes_read32(nesdev->regs + sysfs_nonidx_addr);
1014 break;
1015 }
1016 i++;
1017 }
1018
1019 return snprintf(buf, PAGE_SIZE, "0x%x\n", nonidx_data);
1020}
1021
1022static ssize_t nonidx_data_store(struct device_driver *ddp,
1023 const char *buf, size_t count)
1024{
1025 char *p = (char *)buf;
1026 u32 val;
1027 u32 i = 0;
1028 struct nes_device *nesdev;
1029
1030 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1031 val = simple_strtoul(p, &p, 16);
1032 list_for_each_entry(nesdev, &nes_dev_list, list) {
1033 if (i == ee_flsh_adapter) {
1034 nes_write32(nesdev->regs + sysfs_nonidx_addr, val);
1035 break;
1036 }
1037 i++;
1038 }
1039 }
1040 return strnlen(buf, count);
1041}
1042
1043static ssize_t idx_addr_show(struct device_driver *ddp, char *buf)
1044{
1045 return snprintf(buf, PAGE_SIZE, "0x%x\n", sysfs_idx_addr);
1046}
1047
1048static ssize_t idx_addr_store(struct device_driver *ddp,
1049 const char *buf, size_t count)
1050{
1051 char *p = (char *)buf;
1052
1053 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X')
1054 sysfs_idx_addr = simple_strtoul(p, &p, 16);
1055
1056 return strnlen(buf, count);
1057}
1058
1059static ssize_t idx_data_show(struct device_driver *ddp, char *buf)
1060{
1061 u32 idx_data = 0xdead;
1062 u32 i = 0;
1063 struct nes_device *nesdev;
1064
1065 list_for_each_entry(nesdev, &nes_dev_list, list) {
1066 if (i == ee_flsh_adapter) {
1067 idx_data = nes_read_indexed(nesdev, sysfs_idx_addr);
1068 break;
1069 }
1070 i++;
1071 }
1072
1073 return snprintf(buf, PAGE_SIZE, "0x%x\n", idx_data);
1074}
1075
1076static ssize_t idx_data_store(struct device_driver *ddp,
1077 const char *buf, size_t count)
1078{
1079 char *p = (char *)buf;
1080 u32 val;
1081 u32 i = 0;
1082 struct nes_device *nesdev;
1083
1084 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1085 val = simple_strtoul(p, &p, 16);
1086 list_for_each_entry(nesdev, &nes_dev_list, list) {
1087 if (i == ee_flsh_adapter) {
1088 nes_write_indexed(nesdev, sysfs_idx_addr, val);
1089 break;
1090 }
1091 i++;
1092 }
1093 }
1094 return strnlen(buf, count);
1095}
1096
1097static ssize_t wqm_quanta_show(struct device_driver *ddp, char *buf)
1098{
1099 u32 wqm_quanta_value = 0xdead;
1100 u32 i = 0;
1101 struct nes_device *nesdev;
1102
1103 list_for_each_entry(nesdev, &nes_dev_list, list) {
1104 if (i == ee_flsh_adapter) {
1105 wqm_quanta_value = nesdev->nesadapter->wqm_quanta;
1106 break;
1107 }
1108 i++;
1109 }
1110
1111 return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta_value);
1112}
1113
1114static ssize_t wqm_quanta_store(struct device_driver *ddp, const char *buf,
1115 size_t count)
1116{
1117 unsigned long wqm_quanta_value;
1118 u32 wqm_config1;
1119 u32 i = 0;
1120 struct nes_device *nesdev;
1121
1122 if (kstrtoul(buf, 0, &wqm_quanta_value) < 0)
1123 return -EINVAL;
1124
1125 list_for_each_entry(nesdev, &nes_dev_list, list) {
1126 if (i == ee_flsh_adapter) {
1127 nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1128 wqm_config1 = nes_read_indexed(nesdev,
1129 NES_IDX_WQM_CONFIG1);
1130 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1131 ((wqm_quanta_value << 1) |
1132 (wqm_config1 & 0x00000001)));
1133 break;
1134 }
1135 i++;
1136 }
1137 return strnlen(buf, count);
1138}
1139
1140static DRIVER_ATTR_RW(adapter);
1141static DRIVER_ATTR_RW(eeprom_cmd);
1142static DRIVER_ATTR_RW(eeprom_data);
1143static DRIVER_ATTR_RW(flash_cmd);
1144static DRIVER_ATTR_RW(flash_data);
1145static DRIVER_ATTR_RW(nonidx_addr);
1146static DRIVER_ATTR_RW(nonidx_data);
1147static DRIVER_ATTR_RW(idx_addr);
1148static DRIVER_ATTR_RW(idx_data);
1149static DRIVER_ATTR_RW(wqm_quanta);
1150
1151static struct attribute *nes_attrs[] = {
1152 &driver_attr_adapter.attr,
1153 &driver_attr_eeprom_cmd.attr,
1154 &driver_attr_eeprom_data.attr,
1155 &driver_attr_flash_cmd.attr,
1156 &driver_attr_flash_data.attr,
1157 &driver_attr_nonidx_addr.attr,
1158 &driver_attr_nonidx_data.attr,
1159 &driver_attr_idx_addr.attr,
1160 &driver_attr_idx_data.attr,
1161 &driver_attr_wqm_quanta.attr,
1162 NULL,
1163};
1164ATTRIBUTE_GROUPS(nes);
1165
1166static struct pci_driver nes_pci_driver = {
1167 .name = DRV_NAME,
1168 .id_table = nes_pci_table,
1169 .probe = nes_probe,
1170 .remove = nes_remove,
1171 .groups = nes_groups,
1172};
1173
1174
1175
1176
1177
1178static int __init nes_init_module(void)
1179{
1180 int retval;
1181
1182 retval = nes_cm_start();
1183 if (retval) {
1184 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1185 return retval;
1186 }
1187 return pci_register_driver(&nes_pci_driver);
1188}
1189
1190
1191
1192
1193
1194static void __exit nes_exit_module(void)
1195{
1196 nes_cm_stop();
1197
1198 pci_unregister_driver(&nes_pci_driver);
1199}
1200
1201
1202module_init(nes_init_module);
1203module_exit(nes_exit_module);
1204