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