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