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