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