Version:  2.0.40 2.2.26 2.4.37 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 3.16

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

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