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