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