Version:  2.0.40 2.2.26 2.4.37 2.6.39 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15

Linux/drivers/infiniband/hw/nes/nes.c

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us