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