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