blob: 13de1192927cc50da063562fdc8a47e8a4336422 [file] [log] [blame]
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001/*
Chien Tungfa6c87d2009-12-09 15:21:56 -08002 * Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved.
Glenn Streiff3c2d7742008-02-04 20:20:45 -08003 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Glenn Streiff3c2d7742008-02-04 20:20:45 -080048#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
63MODULE_AUTHOR("NetEffect");
64MODULE_DESCRIPTION("NetEffect RNIC Low-level iWARP Driver");
65MODULE_LICENSE("Dual BSD/GPL");
66MODULE_VERSION(DRV_VERSION);
67
68int max_mtu = 9000;
Glenn Streiff3c2d7742008-02-04 20:20:45 -080069int interrupt_mod_interval = 0;
70
71
72/* Interoperability */
73int mpa_version = 1;
Chien Tungde182142008-09-26 15:08:10 -050074module_param(mpa_version, int, 0644);
Glenn Streiff3c2d7742008-02-04 20:20:45 -080075MODULE_PARM_DESC(mpa_version, "MPA version to be used int MPA Req/Resp (0 or 1)");
76
77/* Interoperability */
78int disable_mpa_crc = 0;
Chien Tungde182142008-09-26 15:08:10 -050079module_param(disable_mpa_crc, int, 0644);
Glenn Streiff3c2d7742008-02-04 20:20:45 -080080MODULE_PARM_DESC(disable_mpa_crc, "Disable checking of MPA CRC");
81
82unsigned int send_first = 0;
Chien Tungde182142008-09-26 15:08:10 -050083module_param(send_first, int, 0644);
Glenn Streiff3c2d7742008-02-04 20:20:45 -080084MODULE_PARM_DESC(send_first, "Send RDMA Message First on Active Connection");
85
86
87unsigned int nes_drv_opt = 0;
Chien Tungde182142008-09-26 15:08:10 -050088module_param(nes_drv_opt, int, 0644);
Glenn Streiff3c2d7742008-02-04 20:20:45 -080089MODULE_PARM_DESC(nes_drv_opt, "Driver option parameters");
90
91unsigned int nes_debug_level = 0;
92module_param_named(debug_level, nes_debug_level, uint, 0644);
93MODULE_PARM_DESC(debug_level, "Enable debug output level");
94
Chien Tung2b537c22008-09-26 15:08:10 -050095unsigned int wqm_quanta = 0x10000;
96module_param(wqm_quanta, int, 0644);
97MODULE_PARM_DESC(wqm_quanta, "WQM quanta");
98
Chien Tung63369362008-11-02 21:40:55 -080099static unsigned int limit_maxrdreqsz;
100module_param(limit_maxrdreqsz, bool, 0644);
101MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
102
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800103LIST_HEAD(nes_adapter_list);
Roland Dreier1a855fb2008-04-16 21:01:09 -0700104static LIST_HEAD(nes_dev_list);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800105
106atomic_t qps_destroyed;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800107
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800108static unsigned int ee_flsh_adapter;
109static unsigned int sysfs_nonidx_addr;
110static unsigned int sysfs_idx_addr;
111
112static struct pci_device_id nes_pci_table[] = {
Peter Huewe33085bb2010-07-15 19:01:21 +0000113 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020), },
114 { PCI_VDEVICE(NETEFFECT, PCI_DEVICE_ID_NETEFFECT_NE020_KR), },
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800115 {0}
116};
117
118MODULE_DEVICE_TABLE(pci, nes_pci_table);
119
120static int nes_inetaddr_event(struct notifier_block *, unsigned long, void *);
121static int nes_net_event(struct notifier_block *, unsigned long, void *);
122static int nes_notifiers_registered;
123
124
125static struct notifier_block nes_inetaddr_notifier = {
126 .notifier_call = nes_inetaddr_event
127};
128
129static struct notifier_block nes_net_notifier = {
130 .notifier_call = nes_net_event
131};
132
133
134
135
136/**
137 * nes_inetaddr_event
138 */
139static int nes_inetaddr_event(struct notifier_block *notifier,
140 unsigned long event, void *ptr)
141{
142 struct in_ifaddr *ifa = ptr;
143 struct net_device *event_netdev = ifa->ifa_dev->dev;
144 struct nes_device *nesdev;
145 struct net_device *netdev;
146 struct nes_vnic *nesvnic;
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000147 unsigned int is_bonded;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800148
Harvey Harrison8cf14e32008-10-29 22:43:33 -0700149 nes_debug(NES_DBG_NETDEV, "nes_inetaddr_event: ip address %pI4, netmask %pI4.\n",
150 &ifa->ifa_address, &ifa->ifa_mask);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800151 list_for_each_entry(nesdev, &nes_dev_list, list) {
152 nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p. (%s)\n",
153 nesdev, nesdev->netdev[0]->name);
154 netdev = nesdev->netdev[0];
155 nesvnic = netdev_priv(netdev);
Jiri Pirko1765a572011-02-12 06:48:36 +0000156 is_bonded = netif_is_bond_slave(netdev) &&
157 (netdev->master == event_netdev);
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000158 if ((netdev == event_netdev) || is_bonded) {
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800159 if (nesvnic->rdma_enabled == 0) {
160 nes_debug(NES_DBG_NETDEV, "Returning without processing event for %s since"
161 " RDMA is not enabled.\n",
162 netdev->name);
163 return NOTIFY_OK;
164 }
165 /* we have ifa->ifa_address/mask here if we need it */
166 switch (event) {
167 case NETDEV_DOWN:
168 nes_debug(NES_DBG_NETDEV, "event:DOWN\n");
169 nes_write_indexed(nesdev,
170 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)), 0);
171
172 nes_manage_arp_cache(netdev, netdev->dev_addr,
173 ntohl(nesvnic->local_ipaddr), NES_ARP_DELETE);
174 nesvnic->local_ipaddr = 0;
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000175 if (is_bonded)
176 continue;
177 else
178 return NOTIFY_OK;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800179 break;
180 case NETDEV_UP:
181 nes_debug(NES_DBG_NETDEV, "event:UP\n");
182
183 if (nesvnic->local_ipaddr != 0) {
184 nes_debug(NES_DBG_NETDEV, "Interface already has local_ipaddr\n");
185 return NOTIFY_OK;
186 }
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000187 /* fall through */
188 case NETDEV_CHANGEADDR:
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800189 /* Add the address to the IP table */
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000190 if (netdev->master)
191 nesvnic->local_ipaddr =
192 ((struct in_device *)netdev->master->ip_ptr)->ifa_list->ifa_address;
193 else
194 nesvnic->local_ipaddr = ifa->ifa_address;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800195
196 nes_write_indexed(nesdev,
197 NES_IDX_DST_IP_ADDR+(0x10*PCI_FUNC(nesdev->pcidev->devfn)),
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000198 ntohl(nesvnic->local_ipaddr));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800199 nes_manage_arp_cache(netdev, netdev->dev_addr,
200 ntohl(nesvnic->local_ipaddr), NES_ARP_ADD);
Maciej Sosnowski2a4c97e2010-11-24 17:29:30 +0000201 if (is_bonded)
202 continue;
203 else
204 return NOTIFY_OK;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800205 break;
206 default:
207 break;
208 }
209 }
210 }
211
212 return NOTIFY_DONE;
213}
214
215
216/**
217 * nes_net_event
218 */
219static int nes_net_event(struct notifier_block *notifier,
220 unsigned long event, void *ptr)
221{
222 struct neighbour *neigh = ptr;
223 struct nes_device *nesdev;
224 struct net_device *netdev;
225 struct nes_vnic *nesvnic;
226
227 switch (event) {
228 case NETEVENT_NEIGH_UPDATE:
229 list_for_each_entry(nesdev, &nes_dev_list, list) {
230 /* nes_debug(NES_DBG_NETDEV, "Nesdev list entry = 0x%p.\n", nesdev); */
231 netdev = nesdev->netdev[0];
232 nesvnic = netdev_priv(netdev);
233 if (netdev == neigh->dev) {
234 if (nesvnic->rdma_enabled == 0) {
235 nes_debug(NES_DBG_NETDEV, "Skipping device %s since no RDMA\n",
236 netdev->name);
237 } else {
238 if (neigh->nud_state & NUD_VALID) {
239 nes_manage_arp_cache(neigh->dev, neigh->ha,
240 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_ADD);
241 } else {
242 nes_manage_arp_cache(neigh->dev, neigh->ha,
243 ntohl(*(__be32 *)neigh->primary_key), NES_ARP_DELETE);
244 }
245 }
246 return NOTIFY_OK;
247 }
248 }
249 break;
250 default:
251 nes_debug(NES_DBG_NETDEV, "NETEVENT_ %lu undefined\n", event);
252 break;
253 }
254
255 return NOTIFY_DONE;
256}
257
258
259/**
260 * nes_add_ref
261 */
262void nes_add_ref(struct ib_qp *ibqp)
263{
264 struct nes_qp *nesqp;
265
266 nesqp = to_nesqp(ibqp);
267 nes_debug(NES_DBG_QP, "Bumping refcount for QP%u. Pre-inc value = %u\n",
268 ibqp->qp_num, atomic_read(&nesqp->refcount));
269 atomic_inc(&nesqp->refcount);
270}
271
272static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_request *cqp_request)
273{
274 unsigned long flags;
275 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
276 struct nes_adapter *nesadapter = nesdev->nesadapter;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800277
278 atomic_inc(&qps_destroyed);
279
280 /* Free the control structures */
281
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800282 if (nesqp->pbl_vbase) {
283 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
284 nesqp->hwqp.q2_vbase, nesqp->hwqp.q2_pbase);
285 spin_lock_irqsave(&nesadapter->pbl_lock, flags);
286 nesadapter->free_256pbl++;
287 spin_unlock_irqrestore(&nesadapter->pbl_lock, flags);
288 pci_free_consistent(nesdev->pcidev, 256, nesqp->pbl_vbase, nesqp->pbl_pbase);
289 nesqp->pbl_vbase = NULL;
290
291 } else {
292 pci_free_consistent(nesdev->pcidev, nesqp->qp_mem_size,
293 nesqp->hwqp.sq_vbase, nesqp->hwqp.sq_pbase);
294 }
295 nes_free_resource(nesadapter, nesadapter->allocated_qps, nesqp->hwqp.qp_id);
296
Faisal Latif6492cdf2008-07-24 20:50:45 -0700297 nesadapter->qp_table[nesqp->hwqp.qp_id-NES_FIRST_QPN] = NULL;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800298 kfree(nesqp->allocated_buffer);
299
300}
301
302/**
303 * nes_rem_ref
304 */
305void nes_rem_ref(struct ib_qp *ibqp)
306{
307 u64 u64temp;
308 struct nes_qp *nesqp;
309 struct nes_vnic *nesvnic = to_nesvnic(ibqp->device);
310 struct nes_device *nesdev = nesvnic->nesdev;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800311 struct nes_hw_cqp_wqe *cqp_wqe;
312 struct nes_cqp_request *cqp_request;
313 u32 opcode;
314
315 nesqp = to_nesqp(ibqp);
316
317 if (atomic_read(&nesqp->refcount) == 0) {
318 printk(KERN_INFO PFX "%s: Reference count already 0 for QP%d, last aeq = 0x%04X.\n",
Harvey Harrison33718362008-04-16 21:01:10 -0700319 __func__, ibqp->qp_num, nesqp->last_aeq);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800320 BUG();
321 }
322
323 if (atomic_dec_and_test(&nesqp->refcount)) {
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800324 /* Destroy the QP */
325 cqp_request = nes_get_cqp_request(nesdev);
326 if (cqp_request == NULL) {
327 nes_debug(NES_DBG_QP, "Failed to get a cqp_request.\n");
328 return;
329 }
330 cqp_request->waiting = 0;
331 cqp_request->callback = 1;
332 cqp_request->cqp_callback = nes_cqp_rem_ref_callback;
333 cqp_request->cqp_callback_pointer = nesqp;
334 cqp_wqe = &cqp_request->cqp_wqe;
335
336 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
337 opcode = NES_CQP_DESTROY_QP | NES_CQP_QP_TYPE_IWARP;
338
339 if (nesqp->hte_added) {
340 opcode |= NES_CQP_QP_DEL_HTE;
341 nesqp->hte_added = 0;
342 }
343 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_OPCODE_IDX, opcode);
344 set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_WQE_ID_IDX, nesqp->hwqp.qp_id);
345 u64temp = (u64)nesqp->nesqp_context_pbase;
346 set_wqe_64bit_value(cqp_wqe->wqe_words, NES_CQP_QP_WQE_CONTEXT_LOW_IDX, u64temp);
Roland Dreier8294f292008-07-14 23:48:49 -0700347 nes_post_cqp_request(nesdev, cqp_request);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800348 }
349}
350
351
352/**
353 * nes_get_qp
354 */
355struct ib_qp *nes_get_qp(struct ib_device *device, int qpn)
356{
357 struct nes_vnic *nesvnic = to_nesvnic(device);
358 struct nes_device *nesdev = nesvnic->nesdev;
359 struct nes_adapter *nesadapter = nesdev->nesadapter;
360
361 if ((qpn < NES_FIRST_QPN) || (qpn >= (NES_FIRST_QPN + nesadapter->max_qp)))
362 return NULL;
363
364 return &nesadapter->qp_table[qpn - NES_FIRST_QPN]->ibqp;
365}
366
367
368/**
369 * nes_print_macaddr
370 */
371static void nes_print_macaddr(struct net_device *netdev)
372{
Johannes Berge1749612008-10-27 15:59:26 -0700373 nes_debug(NES_DBG_INIT, "%s: %pM, IRQ %u\n",
374 netdev->name, netdev->dev_addr, netdev->irq);
Roland Dreier2bd01c52008-04-23 11:52:18 -0700375}
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800376
377/**
378 * nes_interrupt - handle interrupts
379 */
380static irqreturn_t nes_interrupt(int irq, void *dev_id)
381{
382 struct nes_device *nesdev = (struct nes_device *)dev_id;
383 int handled = 0;
384 u32 int_mask;
385 u32 int_req;
386 u32 int_stat;
387 u32 intf_int_stat;
388 u32 timer_stat;
389
390 if (nesdev->msi_enabled) {
391 /* No need to read the interrupt pending register if msi is enabled */
392 handled = 1;
393 } else {
394 if (unlikely(nesdev->nesadapter->hw_rev == NE020_REV)) {
395 /* Master interrupt enable provides synchronization for kicking off bottom half
396 when interrupt sharing is going on */
397 int_mask = nes_read32(nesdev->regs + NES_INT_MASK);
398 if (int_mask & 0x80000000) {
399 /* Check interrupt status to see if this might be ours */
400 int_stat = nes_read32(nesdev->regs + NES_INT_STAT);
401 int_req = nesdev->int_req;
402 if (int_stat&int_req) {
403 /* if interesting CEQ or AEQ is pending, claim the interrupt */
404 if ((int_stat&int_req) & (~(NES_INT_TIMER|NES_INT_INTF))) {
405 handled = 1;
406 } else {
407 if (((int_stat & int_req) & NES_INT_TIMER) == NES_INT_TIMER) {
408 /* Timer might be running but might be for another function */
409 timer_stat = nes_read32(nesdev->regs + NES_TIMER_STAT);
410 if ((timer_stat & nesdev->timer_int_req) != 0) {
411 handled = 1;
412 }
413 }
414 if ((((int_stat & int_req) & NES_INT_INTF) == NES_INT_INTF) &&
415 (handled == 0)) {
416 intf_int_stat = nes_read32(nesdev->regs+NES_INTF_INT_STAT);
417 if ((intf_int_stat & nesdev->intf_int_req) != 0) {
418 handled = 1;
419 }
420 }
421 }
422 if (handled) {
423 nes_write32(nesdev->regs+NES_INT_MASK, int_mask & (~0x80000000));
424 int_mask = nes_read32(nesdev->regs+NES_INT_MASK);
425 /* Save off the status to save an additional read */
426 nesdev->int_stat = int_stat;
427 nesdev->napi_isr_ran = 1;
428 }
429 }
430 }
431 } else {
432 handled = nes_read32(nesdev->regs+NES_INT_PENDING);
433 }
434 }
435
436 if (handled) {
437
438 if (nes_napi_isr(nesdev) == 0) {
439 tasklet_schedule(&nesdev->dpc_tasklet);
440
441 }
442 return IRQ_HANDLED;
443 } else {
444 return IRQ_NONE;
445 }
446}
447
448
449/**
450 * nes_probe - Device initialization
451 */
452static int __devinit nes_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
453{
454 struct net_device *netdev = NULL;
455 struct nes_device *nesdev = NULL;
456 int ret = 0;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800457 void __iomem *mmio_regs = NULL;
458 u8 hw_rev;
459
460 assert(pcidev != NULL);
461 assert(ent != NULL);
462
463 printk(KERN_INFO PFX "NetEffect RNIC driver v%s loading. (%s)\n",
464 DRV_VERSION, pci_name(pcidev));
465
466 ret = pci_enable_device(pcidev);
467 if (ret) {
468 printk(KERN_ERR PFX "Unable to enable PCI device. (%s)\n", pci_name(pcidev));
469 goto bail0;
470 }
471
472 nes_debug(NES_DBG_INIT, "BAR0 (@0x%08lX) size = 0x%lX bytes\n",
473 (long unsigned int)pci_resource_start(pcidev, BAR_0),
474 (long unsigned int)pci_resource_len(pcidev, BAR_0));
475 nes_debug(NES_DBG_INIT, "BAR1 (@0x%08lX) size = 0x%lX bytes\n",
476 (long unsigned int)pci_resource_start(pcidev, BAR_1),
477 (long unsigned int)pci_resource_len(pcidev, BAR_1));
478
479 /* Make sure PCI base addr are MMIO */
480 if (!(pci_resource_flags(pcidev, BAR_0) & IORESOURCE_MEM) ||
481 !(pci_resource_flags(pcidev, BAR_1) & IORESOURCE_MEM)) {
482 printk(KERN_ERR PFX "PCI regions not an MMIO resource\n");
483 ret = -ENODEV;
484 goto bail1;
485 }
486
487 /* Reserve PCI I/O and memory resources */
488 ret = pci_request_regions(pcidev, DRV_NAME);
489 if (ret) {
490 printk(KERN_ERR PFX "Unable to request regions. (%s)\n", pci_name(pcidev));
491 goto bail1;
492 }
493
494 if ((sizeof(dma_addr_t) > 4)) {
Yang Hongyang6a355282009-04-06 19:01:13 -0700495 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800496 if (ret < 0) {
497 printk(KERN_ERR PFX "64b DMA mask configuration failed\n");
498 goto bail2;
499 }
Yang Hongyang6a355282009-04-06 19:01:13 -0700500 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800501 if (ret) {
502 printk(KERN_ERR PFX "64b DMA consistent mask configuration failed\n");
503 goto bail2;
504 }
505 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -0700506 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800507 if (ret < 0) {
508 printk(KERN_ERR PFX "32b DMA mask configuration failed\n");
509 goto bail2;
510 }
Yang Hongyang284901a2009-04-06 19:01:15 -0700511 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800512 if (ret) {
513 printk(KERN_ERR PFX "32b DMA consistent mask configuration failed\n");
514 goto bail2;
515 }
516 }
517
518 pci_set_master(pcidev);
519
520 /* Allocate hardware structure */
521 nesdev = kzalloc(sizeof(struct nes_device), GFP_KERNEL);
522 if (!nesdev) {
523 printk(KERN_ERR PFX "%s: Unable to alloc hardware struct\n", pci_name(pcidev));
524 ret = -ENOMEM;
525 goto bail2;
526 }
527
528 nes_debug(NES_DBG_INIT, "Allocated nes device at %p\n", nesdev);
529 nesdev->pcidev = pcidev;
530 pci_set_drvdata(pcidev, nesdev);
531
532 pci_read_config_byte(pcidev, 0x0008, &hw_rev);
533 nes_debug(NES_DBG_INIT, "hw_rev=%u\n", hw_rev);
534
535 spin_lock_init(&nesdev->indexed_regs_lock);
536
537 /* Remap the PCI registers in adapter BAR0 to kernel VA space */
Julia Lawalld85ddd82009-12-09 15:21:57 -0800538 mmio_regs = ioremap_nocache(pci_resource_start(pcidev, BAR_0),
539 pci_resource_len(pcidev, BAR_0));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800540 if (mmio_regs == NULL) {
541 printk(KERN_ERR PFX "Unable to remap BAR0\n");
542 ret = -EIO;
543 goto bail3;
544 }
545 nesdev->regs = mmio_regs;
546 nesdev->index_reg = 0x50 + (PCI_FUNC(pcidev->devfn)*8) + mmio_regs;
547
548 /* Ensure interrupts are disabled */
549 nes_write32(nesdev->regs+NES_INT_MASK, 0x7fffffff);
550
551 if (nes_drv_opt & NES_DRV_OPT_ENABLE_MSI) {
552 if (!pci_enable_msi(nesdev->pcidev)) {
553 nesdev->msi_enabled = 1;
554 nes_debug(NES_DBG_INIT, "MSI is enabled for device %s\n",
555 pci_name(pcidev));
556 } else {
557 nes_debug(NES_DBG_INIT, "MSI is disabled by linux for device %s\n",
558 pci_name(pcidev));
559 }
560 } else {
561 nes_debug(NES_DBG_INIT, "MSI not requested due to driver options for device %s\n",
562 pci_name(pcidev));
563 }
564
565 nesdev->csr_start = pci_resource_start(nesdev->pcidev, BAR_0);
566 nesdev->doorbell_region = pci_resource_start(nesdev->pcidev, BAR_1);
567
568 /* Init the adapter */
569 nesdev->nesadapter = nes_init_adapter(nesdev, hw_rev);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800570 if (!nesdev->nesadapter) {
571 printk(KERN_ERR PFX "Unable to initialize adapter.\n");
572 ret = -ENOMEM;
573 goto bail5;
574 }
Adrian Bunka4435fe2008-02-21 08:13:47 -0600575 nesdev->nesadapter->et_rx_coalesce_usecs_irq = interrupt_mod_interval;
Chien Tung2b537c22008-09-26 15:08:10 -0500576 nesdev->nesadapter->wqm_quanta = wqm_quanta;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800577
578 /* nesdev->base_doorbell_index =
579 nesdev->nesadapter->pd_config_base[PCI_FUNC(nesdev->pcidev->devfn)]; */
580 nesdev->base_doorbell_index = 1;
581 nesdev->doorbell_start = nesdev->nesadapter->doorbell_start;
Chien Tungfcb7ad32008-09-30 14:49:44 -0700582 if (nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_PUMA_1G) {
583 switch (PCI_FUNC(nesdev->pcidev->devfn) %
584 nesdev->nesadapter->port_count) {
585 case 1:
586 nesdev->mac_index = 2;
587 break;
588 case 2:
589 nesdev->mac_index = 1;
590 break;
591 case 3:
592 nesdev->mac_index = 3;
593 break;
594 case 0:
595 default:
596 nesdev->mac_index = 0;
597 }
598 } else {
599 nesdev->mac_index = PCI_FUNC(nesdev->pcidev->devfn) %
600 nesdev->nesadapter->port_count;
601 }
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800602
Chien Tung63369362008-11-02 21:40:55 -0800603 if ((limit_maxrdreqsz ||
604 ((nesdev->nesadapter->phy_type[0] == NES_PHY_TYPE_GLADIUS) &&
605 (hw_rev == NE020_REV1))) &&
606 (pcie_get_readrq(pcidev) > 256)) {
607 if (pcie_set_readrq(pcidev, 256))
608 printk(KERN_ERR PFX "Unable to set max read request"
609 " to 256 bytes\n");
610 else
611 nes_debug(NES_DBG_INIT, "Max read request size set"
612 " to 256 bytes\n");
613 }
614
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800615 tasklet_init(&nesdev->dpc_tasklet, nes_dpc, (unsigned long)nesdev);
616
617 /* bring up the Control QP */
618 if (nes_init_cqp(nesdev)) {
619 ret = -ENODEV;
620 goto bail6;
621 }
622
623 /* Arm the CCQ */
624 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
625 PCI_FUNC(nesdev->pcidev->devfn));
626 nes_read32(nesdev->regs+NES_CQE_ALLOC);
627
628 /* Enable the interrupts */
629 nesdev->int_req = (0x101 << PCI_FUNC(nesdev->pcidev->devfn)) |
630 (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
631 if (PCI_FUNC(nesdev->pcidev->devfn) < 4) {
Chien Tungfcb7ad32008-09-30 14:49:44 -0700632 nesdev->int_req |= (1 << (PCI_FUNC(nesdev->mac_index)+24));
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800633 }
634
635 /* TODO: This really should be the first driver to load, not function 0 */
636 if (PCI_FUNC(nesdev->pcidev->devfn) == 0) {
637 /* pick up PCI and critical errors if the first driver to load */
638 nesdev->intf_int_req = NES_INTF_INT_PCIERR | NES_INTF_INT_CRITERR;
639 nesdev->int_req |= NES_INT_INTF;
640 } else {
641 nesdev->intf_int_req = 0;
642 }
643 nesdev->intf_int_req |= (1 << (PCI_FUNC(nesdev->pcidev->devfn)+16));
644 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS0, 0);
645 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS1, 0);
646 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS2, 0x00001265);
647 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS4, 0x18021804);
648
649 nes_write_indexed(nesdev, NES_IDX_DEBUG_ERROR_MASKS3, 0x17801790);
650
651 /* deal with both periodic and one_shot */
652 nesdev->timer_int_req = 0x101 << PCI_FUNC(nesdev->pcidev->devfn);
653 nesdev->nesadapter->timer_int_req |= nesdev->timer_int_req;
654 nes_debug(NES_DBG_INIT, "setting int_req for function %u, nesdev = 0x%04X, adapter = 0x%04X\n",
655 PCI_FUNC(nesdev->pcidev->devfn),
656 nesdev->timer_int_req, nesdev->nesadapter->timer_int_req);
657
658 nes_write32(nesdev->regs+NES_INTF_INT_MASK, ~(nesdev->intf_int_req));
659
660 list_add_tail(&nesdev->list, &nes_dev_list);
661
662 /* Request an interrupt line for the driver */
663 ret = request_irq(pcidev->irq, nes_interrupt, IRQF_SHARED, DRV_NAME, nesdev);
664 if (ret) {
665 printk(KERN_ERR PFX "%s: requested IRQ %u is busy\n",
666 pci_name(pcidev), pcidev->irq);
667 goto bail65;
668 }
669
670 nes_write32(nesdev->regs+NES_INT_MASK, ~nesdev->int_req);
671
672 if (nes_notifiers_registered == 0) {
673 register_inetaddr_notifier(&nes_inetaddr_notifier);
674 register_netevent_notifier(&nes_net_notifier);
675 }
676 nes_notifiers_registered++;
677
Maciej Sosnowski5f61b2c2010-11-24 17:29:46 +0000678 INIT_DELAYED_WORK(&nesdev->work, nes_recheck_link_status);
679
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800680 /* Initialize network devices */
Roland Dreierb2a899e2010-08-04 14:29:31 -0700681 if ((netdev = nes_netdev_init(nesdev, mmio_regs)) == NULL)
682 goto bail7;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800683
Roland Dreierb2a899e2010-08-04 14:29:31 -0700684 /* 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 }
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800691
Roland Dreierb2a899e2010-08-04 14:29:31 -0700692 nes_print_macaddr(netdev);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800693
Roland Dreierb2a899e2010-08-04 14:29:31 -0700694 nesdev->netdev_count++;
695 nesdev->nesadapter->netdev_count++;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800696
Roland Dreier748bfd92011-03-18 08:52:30 -0700697 printk(KERN_INFO PFX "%s: NetEffect RNIC driver successfully loaded.\n",
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800698 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 */
757static void __devexit 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;
Maciej Sosnowski5f61b2c2010-11-24 17:29:46 +0000762 unsigned long flags;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800763
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);
Roland Dreier4cd1e5e2008-04-16 21:09:34 -0700785
786 free_irq(pcidev->irq, nesdev);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800787 tasklet_kill(&nesdev->dpc_tasklet);
788
Maciej Sosnowski5f61b2c2010-11-24 17:29:46 +0000789 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
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800797 /* Deallocate the Adapter Structure */
798 nes_destroy_adapter(nesdev->nesadapter);
799
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800800 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
814static struct pci_driver nes_pci_driver = {
815 .name = DRV_NAME,
816 .id_table = nes_pci_table,
817 .probe = nes_probe,
818 .remove = __devexit_p(nes_remove),
819};
820
821static 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) {
Chien Tungfcb7ad32008-09-30 14:49:44 -0700830 devfn = nesdev->pcidev->devfn;
831 bus_number = nesdev->pcidev->bus->number;
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800832 break;
833 }
834 i++;
835 }
836
Chien Tungfcb7ad32008-09-30 14:49:44 -0700837 return snprintf(buf, PAGE_SIZE, "%x:%x\n", bus_number, devfn);
Glenn Streiff3c2d7742008-02-04 20:20:45 -0800838}
839
840static 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
849static 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
865static 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
886static 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
903static 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
924static 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
941static 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
962static 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
979static 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
1000static 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
1005static 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
1016static 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
1033static 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
1054static 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
1059static 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
1070static 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
1087static 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
Chien Tung2b537c22008-09-26 15:08:10 -05001108
1109/**
1110 * nes_show_wqm_quanta
1111 */
1112static 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
Roland Dreierdf924f82010-08-04 14:27:01 -07001126 return snprintf(buf, PAGE_SIZE, "0x%X\n", wqm_quanta_value);
Chien Tung2b537c22008-09-26 15:08:10 -05001127}
1128
1129
1130/**
1131 * nes_store_wqm_quanta
1132 */
1133static 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 strict_strtoul(buf, 0, &wqm_quanta_value);
1142 list_for_each_entry(nesdev, &nes_dev_list, list) {
1143 if (i == ee_flsh_adapter) {
1144 nesdev->nesadapter->wqm_quanta = wqm_quanta_value;
1145 wqm_config1 = nes_read_indexed(nesdev,
1146 NES_IDX_WQM_CONFIG1);
1147 nes_write_indexed(nesdev, NES_IDX_WQM_CONFIG1,
1148 ((wqm_quanta_value << 1) |
1149 (wqm_config1 & 0x00000001)));
1150 break;
1151 }
1152 i++;
1153 }
1154 return strnlen(buf, count);
1155}
1156
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001157static DRIVER_ATTR(adapter, S_IRUSR | S_IWUSR,
1158 nes_show_adapter, nes_store_adapter);
1159static DRIVER_ATTR(eeprom_cmd, S_IRUSR | S_IWUSR,
1160 nes_show_ee_cmd, nes_store_ee_cmd);
1161static DRIVER_ATTR(eeprom_data, S_IRUSR | S_IWUSR,
1162 nes_show_ee_data, nes_store_ee_data);
1163static DRIVER_ATTR(flash_cmd, S_IRUSR | S_IWUSR,
1164 nes_show_flash_cmd, nes_store_flash_cmd);
1165static DRIVER_ATTR(flash_data, S_IRUSR | S_IWUSR,
1166 nes_show_flash_data, nes_store_flash_data);
1167static DRIVER_ATTR(nonidx_addr, S_IRUSR | S_IWUSR,
1168 nes_show_nonidx_addr, nes_store_nonidx_addr);
1169static DRIVER_ATTR(nonidx_data, S_IRUSR | S_IWUSR,
1170 nes_show_nonidx_data, nes_store_nonidx_data);
1171static DRIVER_ATTR(idx_addr, S_IRUSR | S_IWUSR,
1172 nes_show_idx_addr, nes_store_idx_addr);
1173static DRIVER_ATTR(idx_data, S_IRUSR | S_IWUSR,
1174 nes_show_idx_data, nes_store_idx_data);
Chien Tung2b537c22008-09-26 15:08:10 -05001175static DRIVER_ATTR(wqm_quanta, S_IRUSR | S_IWUSR,
1176 nes_show_wqm_quanta, nes_store_wqm_quanta);
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001177
1178static int nes_create_driver_sysfs(struct pci_driver *drv)
1179{
1180 int error;
1181 error = driver_create_file(&drv->driver, &driver_attr_adapter);
1182 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_cmd);
1183 error |= driver_create_file(&drv->driver, &driver_attr_eeprom_data);
1184 error |= driver_create_file(&drv->driver, &driver_attr_flash_cmd);
1185 error |= driver_create_file(&drv->driver, &driver_attr_flash_data);
1186 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_addr);
1187 error |= driver_create_file(&drv->driver, &driver_attr_nonidx_data);
1188 error |= driver_create_file(&drv->driver, &driver_attr_idx_addr);
1189 error |= driver_create_file(&drv->driver, &driver_attr_idx_data);
Chien Tung2b537c22008-09-26 15:08:10 -05001190 error |= driver_create_file(&drv->driver, &driver_attr_wqm_quanta);
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001191 return error;
1192}
1193
1194static void nes_remove_driver_sysfs(struct pci_driver *drv)
1195{
1196 driver_remove_file(&drv->driver, &driver_attr_adapter);
1197 driver_remove_file(&drv->driver, &driver_attr_eeprom_cmd);
1198 driver_remove_file(&drv->driver, &driver_attr_eeprom_data);
1199 driver_remove_file(&drv->driver, &driver_attr_flash_cmd);
1200 driver_remove_file(&drv->driver, &driver_attr_flash_data);
1201 driver_remove_file(&drv->driver, &driver_attr_nonidx_addr);
1202 driver_remove_file(&drv->driver, &driver_attr_nonidx_data);
1203 driver_remove_file(&drv->driver, &driver_attr_idx_addr);
1204 driver_remove_file(&drv->driver, &driver_attr_idx_data);
Chien Tung2b537c22008-09-26 15:08:10 -05001205 driver_remove_file(&drv->driver, &driver_attr_wqm_quanta);
Glenn Streiff3c2d7742008-02-04 20:20:45 -08001206}
1207
1208/**
1209 * nes_init_module - module initialization entry point
1210 */
1211static int __init nes_init_module(void)
1212{
1213 int retval;
1214 int retval1;
1215
1216 retval = nes_cm_start();
1217 if (retval) {
1218 printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");
1219 return retval;
1220 }
1221 retval = pci_register_driver(&nes_pci_driver);
1222 if (retval >= 0) {
1223 retval1 = nes_create_driver_sysfs(&nes_pci_driver);
1224 if (retval1 < 0)
1225 printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n");
1226 }
1227 return retval;
1228}
1229
1230
1231/**
1232 * nes_exit_module - module unload entry point
1233 */
1234static void __exit nes_exit_module(void)
1235{
1236 nes_cm_stop();
1237 nes_remove_driver_sysfs(&nes_pci_driver);
1238
1239 pci_unregister_driver(&nes_pci_driver);
1240}
1241
1242
1243module_init(nes_init_module);
1244module_exit(nes_exit_module);