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