Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 - QLogic Corporation. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called "COPYING". |
| 22 | * |
| 23 | */ |
| 24 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 26 | #include <linux/vmalloc.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | |
| 29 | #include "qlcnic.h" |
| 30 | |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 31 | #include <linux/swab.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/if_vlan.h> |
| 34 | #include <net/ip.h> |
| 35 | #include <linux/ipv6.h> |
| 36 | #include <linux/inetdevice.h> |
| 37 | #include <linux/sysfs.h> |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 38 | #include <linux/aer.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 39 | |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 40 | MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 41 | MODULE_LICENSE("GPL"); |
| 42 | MODULE_VERSION(QLCNIC_LINUX_VERSIONID); |
| 43 | MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); |
| 44 | |
| 45 | char qlcnic_driver_name[] = "qlcnic"; |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 46 | static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " |
| 47 | "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 48 | |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 49 | static struct workqueue_struct *qlcnic_wq; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 50 | static int qlcnic_mac_learn; |
| 51 | module_param(qlcnic_mac_learn, int, 0644); |
| 52 | MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)"); |
| 53 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 54 | static int use_msi = 1; |
| 55 | module_param(use_msi, int, 0644); |
| 56 | MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); |
| 57 | |
| 58 | static int use_msi_x = 1; |
| 59 | module_param(use_msi_x, int, 0644); |
| 60 | MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); |
| 61 | |
| 62 | static int auto_fw_reset = AUTO_FW_RESET_ENABLED; |
| 63 | module_param(auto_fw_reset, int, 0644); |
| 64 | MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); |
| 65 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 66 | static int load_fw_file; |
| 67 | module_param(load_fw_file, int, 0644); |
| 68 | MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); |
| 69 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 70 | static int qlcnic_config_npars; |
| 71 | module_param(qlcnic_config_npars, int, 0644); |
| 72 | MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); |
| 73 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 74 | static int __devinit qlcnic_probe(struct pci_dev *pdev, |
| 75 | const struct pci_device_id *ent); |
| 76 | static void __devexit qlcnic_remove(struct pci_dev *pdev); |
| 77 | static int qlcnic_open(struct net_device *netdev); |
| 78 | static int qlcnic_close(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 79 | static void qlcnic_tx_timeout(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 80 | static void qlcnic_attach_work(struct work_struct *work); |
| 81 | static void qlcnic_fwinit_work(struct work_struct *work); |
| 82 | static void qlcnic_fw_poll_work(struct work_struct *work); |
| 83 | static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 84 | work_func_t func, int delay); |
| 85 | static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); |
| 86 | static int qlcnic_poll(struct napi_struct *napi, int budget); |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 87 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 88 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 89 | static void qlcnic_poll_controller(struct net_device *netdev); |
| 90 | #endif |
| 91 | |
| 92 | static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter); |
| 93 | static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter); |
| 94 | static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter); |
| 95 | static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); |
| 96 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 97 | static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 98 | static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 99 | static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); |
| 100 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 101 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 102 | static irqreturn_t qlcnic_intr(int irq, void *data); |
| 103 | static irqreturn_t qlcnic_msi_intr(int irq, void *data); |
| 104 | static irqreturn_t qlcnic_msix_intr(int irq, void *data); |
| 105 | |
| 106 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 107 | static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 108 | static int qlcnic_start_firmware(struct qlcnic_adapter *); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 109 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 110 | static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter); |
| 111 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 112 | static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 113 | static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); |
| 114 | static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); |
| 115 | static int qlcnicvf_start_firmware(struct qlcnic_adapter *); |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 116 | static void qlcnic_set_netdev_features(struct qlcnic_adapter *, |
| 117 | struct qlcnic_esw_func_cfg *); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 118 | /* PCI Device ID Table */ |
| 119 | #define ENTRY(device) \ |
| 120 | {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ |
| 121 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
| 122 | |
| 123 | #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 |
| 124 | |
Amit Kumar Salecha | 6a90288 | 2010-02-01 05:24:54 +0000 | [diff] [blame] | 125 | static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 126 | ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), |
| 127 | {0,} |
| 128 | }; |
| 129 | |
| 130 | MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); |
| 131 | |
| 132 | |
| 133 | void |
| 134 | qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, |
| 135 | struct qlcnic_host_tx_ring *tx_ring) |
| 136 | { |
| 137 | writel(tx_ring->producer, tx_ring->crb_cmd_producer); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static const u32 msi_tgt_status[8] = { |
| 141 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
| 142 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
| 143 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, |
| 144 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 |
| 145 | }; |
| 146 | |
| 147 | static const |
| 148 | struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; |
| 149 | |
| 150 | static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring) |
| 151 | { |
| 152 | writel(0, sds_ring->crb_intr_mask); |
| 153 | } |
| 154 | |
| 155 | static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring) |
| 156 | { |
| 157 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 158 | |
| 159 | writel(0x1, sds_ring->crb_intr_mask); |
| 160 | |
| 161 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) |
| 162 | writel(0xfbff, adapter->tgt_mask_reg); |
| 163 | } |
| 164 | |
| 165 | static int |
| 166 | qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) |
| 167 | { |
| 168 | int size = sizeof(struct qlcnic_host_sds_ring) * count; |
| 169 | |
| 170 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); |
| 171 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 172 | return recv_ctx->sds_rings == NULL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static void |
| 176 | qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) |
| 177 | { |
| 178 | if (recv_ctx->sds_rings != NULL) |
| 179 | kfree(recv_ctx->sds_rings); |
| 180 | |
| 181 | recv_ctx->sds_rings = NULL; |
| 182 | } |
| 183 | |
| 184 | static int |
| 185 | qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 186 | { |
| 187 | int ring; |
| 188 | struct qlcnic_host_sds_ring *sds_ring; |
| 189 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 190 | |
| 191 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
| 192 | return -ENOMEM; |
| 193 | |
| 194 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 195 | sds_ring = &recv_ctx->sds_rings[ring]; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 196 | |
| 197 | if (ring == adapter->max_sds_rings - 1) |
| 198 | netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll, |
| 199 | QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings); |
| 200 | else |
| 201 | netif_napi_add(netdev, &sds_ring->napi, |
| 202 | qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static void |
| 209 | qlcnic_napi_del(struct qlcnic_adapter *adapter) |
| 210 | { |
| 211 | int ring; |
| 212 | struct qlcnic_host_sds_ring *sds_ring; |
| 213 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 214 | |
| 215 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 216 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 217 | netif_napi_del(&sds_ring->napi); |
| 218 | } |
| 219 | |
| 220 | qlcnic_free_sds_rings(&adapter->recv_ctx); |
| 221 | } |
| 222 | |
| 223 | static void |
| 224 | qlcnic_napi_enable(struct qlcnic_adapter *adapter) |
| 225 | { |
| 226 | int ring; |
| 227 | struct qlcnic_host_sds_ring *sds_ring; |
| 228 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 229 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 230 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 231 | return; |
| 232 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 233 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 234 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 235 | napi_enable(&sds_ring->napi); |
| 236 | qlcnic_enable_int(sds_ring); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static void |
| 241 | qlcnic_napi_disable(struct qlcnic_adapter *adapter) |
| 242 | { |
| 243 | int ring; |
| 244 | struct qlcnic_host_sds_ring *sds_ring; |
| 245 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 246 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 247 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 248 | return; |
| 249 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 250 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 251 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 252 | qlcnic_disable_int(sds_ring); |
| 253 | napi_synchronize(&sds_ring->napi); |
| 254 | napi_disable(&sds_ring->napi); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | static void qlcnic_clear_stats(struct qlcnic_adapter *adapter) |
| 259 | { |
| 260 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 263 | static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable) |
| 264 | { |
| 265 | u32 control; |
| 266 | int pos; |
| 267 | |
| 268 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 269 | if (pos) { |
| 270 | pci_read_config_dword(pdev, pos, &control); |
| 271 | if (enable) |
| 272 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 273 | else |
| 274 | control = 0; |
| 275 | pci_write_config_dword(pdev, pos, control); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count) |
| 280 | { |
| 281 | int i; |
| 282 | |
| 283 | for (i = 0; i < count; i++) |
| 284 | adapter->msix_entries[i].entry = i; |
| 285 | } |
| 286 | |
| 287 | static int |
| 288 | qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) |
| 289 | { |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 290 | u8 mac_addr[ETH_ALEN]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 291 | struct net_device *netdev = adapter->netdev; |
| 292 | struct pci_dev *pdev = adapter->pdev; |
| 293 | |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 294 | if (qlcnic_get_mac_address(adapter, mac_addr) != 0) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 295 | return -EIO; |
| 296 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 297 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 298 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); |
| 299 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); |
| 300 | |
| 301 | /* set station address */ |
| 302 | |
| 303 | if (!is_valid_ether_addr(netdev->perm_addr)) |
| 304 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", |
| 305 | netdev->dev_addr); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int qlcnic_set_mac(struct net_device *netdev, void *p) |
| 311 | { |
| 312 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 313 | struct sockaddr *addr = p; |
| 314 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 315 | if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) |
| 316 | return -EOPNOTSUPP; |
| 317 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 318 | if (!is_valid_ether_addr(addr->sa_data)) |
| 319 | return -EINVAL; |
| 320 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 321 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 322 | netif_device_detach(netdev); |
| 323 | qlcnic_napi_disable(adapter); |
| 324 | } |
| 325 | |
| 326 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); |
| 327 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 328 | qlcnic_set_multi(adapter->netdev); |
| 329 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 330 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 331 | netif_device_attach(netdev); |
| 332 | qlcnic_napi_enable(adapter); |
| 333 | } |
| 334 | return 0; |
| 335 | } |
| 336 | |
Amit Kumar Salecha | d579066 | 2010-09-16 19:14:39 +0000 | [diff] [blame] | 337 | static void qlcnic_vlan_rx_register(struct net_device *netdev, |
| 338 | struct vlan_group *grp) |
| 339 | { |
| 340 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 341 | adapter->vlgrp = grp; |
| 342 | } |
| 343 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 344 | static const struct net_device_ops qlcnic_netdev_ops = { |
| 345 | .ndo_open = qlcnic_open, |
| 346 | .ndo_stop = qlcnic_close, |
| 347 | .ndo_start_xmit = qlcnic_xmit_frame, |
| 348 | .ndo_get_stats = qlcnic_get_stats, |
| 349 | .ndo_validate_addr = eth_validate_addr, |
| 350 | .ndo_set_multicast_list = qlcnic_set_multi, |
| 351 | .ndo_set_mac_address = qlcnic_set_mac, |
| 352 | .ndo_change_mtu = qlcnic_change_mtu, |
| 353 | .ndo_tx_timeout = qlcnic_tx_timeout, |
Amit Kumar Salecha | d579066 | 2010-09-16 19:14:39 +0000 | [diff] [blame] | 354 | .ndo_vlan_rx_register = qlcnic_vlan_rx_register, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 355 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 356 | .ndo_poll_controller = qlcnic_poll_controller, |
| 357 | #endif |
| 358 | }; |
| 359 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 360 | static struct qlcnic_nic_template qlcnic_ops = { |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 361 | .config_bridged_mode = qlcnic_config_bridged_mode, |
| 362 | .config_led = qlcnic_config_led, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 363 | .start_firmware = qlcnic_start_firmware |
| 364 | }; |
| 365 | |
| 366 | static struct qlcnic_nic_template qlcnic_vf_ops = { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 367 | .config_bridged_mode = qlcnicvf_config_bridged_mode, |
| 368 | .config_led = qlcnicvf_config_led, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 369 | .start_firmware = qlcnicvf_start_firmware |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 370 | }; |
| 371 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 372 | static void |
| 373 | qlcnic_setup_intr(struct qlcnic_adapter *adapter) |
| 374 | { |
| 375 | const struct qlcnic_legacy_intr_set *legacy_intrp; |
| 376 | struct pci_dev *pdev = adapter->pdev; |
| 377 | int err, num_msix; |
| 378 | |
| 379 | if (adapter->rss_supported) { |
| 380 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? |
| 381 | MSIX_ENTRIES_PER_ADAPTER : 2; |
| 382 | } else |
| 383 | num_msix = 1; |
| 384 | |
| 385 | adapter->max_sds_rings = 1; |
| 386 | |
| 387 | adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); |
| 388 | |
| 389 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; |
| 390 | |
| 391 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; |
| 392 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 393 | legacy_intrp->tgt_status_reg); |
| 394 | adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, |
| 395 | legacy_intrp->tgt_mask_reg); |
| 396 | adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); |
| 397 | |
| 398 | adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, |
| 399 | ISR_INT_STATE_REG); |
| 400 | |
| 401 | qlcnic_set_msix_bit(pdev, 0); |
| 402 | |
| 403 | if (adapter->msix_supported) { |
| 404 | |
| 405 | qlcnic_init_msix_entries(adapter, num_msix); |
| 406 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); |
| 407 | if (err == 0) { |
| 408 | adapter->flags |= QLCNIC_MSIX_ENABLED; |
| 409 | qlcnic_set_msix_bit(pdev, 1); |
| 410 | |
| 411 | if (adapter->rss_supported) |
| 412 | adapter->max_sds_rings = num_msix; |
| 413 | |
| 414 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | if (err > 0) |
| 419 | pci_disable_msix(pdev); |
| 420 | |
| 421 | /* fall through for msi */ |
| 422 | } |
| 423 | |
| 424 | if (use_msi && !pci_enable_msi(pdev)) { |
| 425 | adapter->flags |= QLCNIC_MSI_ENABLED; |
| 426 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 427 | msi_tgt_status[adapter->ahw.pci_func]); |
| 428 | dev_info(&pdev->dev, "using msi interrupts\n"); |
| 429 | adapter->msix_entries[0].vector = pdev->irq; |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 434 | adapter->msix_entries[0].vector = pdev->irq; |
| 435 | } |
| 436 | |
| 437 | static void |
| 438 | qlcnic_teardown_intr(struct qlcnic_adapter *adapter) |
| 439 | { |
| 440 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 441 | pci_disable_msix(adapter->pdev); |
| 442 | if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 443 | pci_disable_msi(adapter->pdev); |
| 444 | } |
| 445 | |
| 446 | static void |
| 447 | qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) |
| 448 | { |
| 449 | if (adapter->ahw.pci_base0 != NULL) |
| 450 | iounmap(adapter->ahw.pci_base0); |
| 451 | } |
| 452 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 453 | static int |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 454 | qlcnic_init_pci_info(struct qlcnic_adapter *adapter) |
| 455 | { |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 456 | struct qlcnic_pci_info *pci_info; |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 457 | int i, ret = 0; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 458 | u8 pfn; |
| 459 | |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 460 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
| 461 | if (!pci_info) |
| 462 | return -ENOMEM; |
| 463 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 464 | adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 465 | QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 466 | if (!adapter->npars) { |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 467 | ret = -ENOMEM; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 468 | goto err_pci_info; |
| 469 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 470 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 471 | adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 472 | QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); |
| 473 | if (!adapter->eswitch) { |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 474 | ret = -ENOMEM; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 475 | goto err_npars; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | ret = qlcnic_get_pci_info(adapter, pci_info); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 479 | if (ret) |
| 480 | goto err_eswitch; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 481 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 482 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 483 | pfn = pci_info[i].id; |
| 484 | if (pfn > QLCNIC_MAX_PCI_FUNC) |
| 485 | return QL_STATUS_INVALID_PARAM; |
Sucheta Chakraborty | a1c0c45 | 2010-10-04 04:20:14 +0000 | [diff] [blame] | 486 | adapter->npars[pfn].active = (u8)pci_info[i].active; |
| 487 | adapter->npars[pfn].type = (u8)pci_info[i].type; |
| 488 | adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 489 | adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; |
| 490 | adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 493 | for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) |
| 494 | adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; |
| 495 | |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 496 | kfree(pci_info); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 497 | return 0; |
| 498 | |
| 499 | err_eswitch: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 500 | kfree(adapter->eswitch); |
| 501 | adapter->eswitch = NULL; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 502 | err_npars: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 503 | kfree(adapter->npars); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 504 | adapter->npars = NULL; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 505 | err_pci_info: |
| 506 | kfree(pci_info); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 507 | |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | static int |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 512 | qlcnic_set_function_modes(struct qlcnic_adapter *adapter) |
| 513 | { |
| 514 | u8 id; |
| 515 | u32 ref_count; |
| 516 | int i, ret = 1; |
| 517 | u32 data = QLCNIC_MGMT_FUNC; |
| 518 | void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; |
| 519 | |
| 520 | /* If other drivers are not in use set their privilege level */ |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 521 | ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 522 | ret = qlcnic_api_lock(adapter); |
| 523 | if (ret) |
| 524 | goto err_lock; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 525 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 526 | if (qlcnic_config_npars) { |
| 527 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 528 | id = i; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 529 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC || |
| 530 | id == adapter->ahw.pci_func) |
| 531 | continue; |
| 532 | data |= (qlcnic_config_npars & |
| 533 | QLC_DEV_SET_DRV(0xf, id)); |
| 534 | } |
| 535 | } else { |
| 536 | data = readl(priv_op); |
| 537 | data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) | |
| 538 | (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, |
| 539 | adapter->ahw.pci_func)); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 540 | } |
| 541 | writel(data, priv_op); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 542 | qlcnic_api_unlock(adapter); |
| 543 | err_lock: |
| 544 | return ret; |
| 545 | } |
| 546 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 547 | static void |
| 548 | qlcnic_check_vf(struct qlcnic_adapter *adapter) |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 549 | { |
| 550 | void __iomem *msix_base_addr; |
| 551 | void __iomem *priv_op; |
| 552 | u32 func; |
| 553 | u32 msix_base; |
| 554 | u32 op_mode, priv_level; |
| 555 | |
| 556 | /* Determine FW API version */ |
| 557 | adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 558 | |
| 559 | /* Find PCI function number */ |
| 560 | pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); |
| 561 | msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE; |
| 562 | msix_base = readl(msix_base_addr); |
| 563 | func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; |
| 564 | adapter->ahw.pci_func = func; |
| 565 | |
| 566 | /* Determine function privilege level */ |
| 567 | priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; |
| 568 | op_mode = readl(priv_op); |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 569 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 570 | priv_level = QLCNIC_MGMT_FUNC; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 571 | else |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 572 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); |
| 573 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 574 | if (priv_level == QLCNIC_NON_PRIV_FUNC) { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 575 | adapter->op_mode = QLCNIC_NON_PRIV_FUNC; |
| 576 | dev_info(&adapter->pdev->dev, |
| 577 | "HAL Version: %d Non Privileged function\n", |
| 578 | adapter->fw_hal_version); |
| 579 | adapter->nic_ops = &qlcnic_vf_ops; |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 580 | } else |
| 581 | adapter->nic_ops = &qlcnic_ops; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 584 | static int |
| 585 | qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) |
| 586 | { |
| 587 | void __iomem *mem_ptr0 = NULL; |
| 588 | resource_size_t mem_base; |
| 589 | unsigned long mem_len, pci_len0 = 0; |
| 590 | |
| 591 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 592 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 593 | /* remap phys address */ |
| 594 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 595 | mem_len = pci_resource_len(pdev, 0); |
| 596 | |
| 597 | if (mem_len == QLCNIC_PCI_2MB_SIZE) { |
| 598 | |
| 599 | mem_ptr0 = pci_ioremap_bar(pdev, 0); |
| 600 | if (mem_ptr0 == NULL) { |
| 601 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); |
| 602 | return -EIO; |
| 603 | } |
| 604 | pci_len0 = mem_len; |
| 605 | } else { |
| 606 | return -EIO; |
| 607 | } |
| 608 | |
| 609 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); |
| 610 | |
| 611 | adapter->ahw.pci_base0 = mem_ptr0; |
| 612 | adapter->ahw.pci_len0 = pci_len0; |
| 613 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 614 | qlcnic_check_vf(adapter); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 615 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 616 | adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter, |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 617 | QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func))); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | static void get_brd_name(struct qlcnic_adapter *adapter, char *name) |
| 623 | { |
| 624 | struct pci_dev *pdev = adapter->pdev; |
| 625 | int i, found = 0; |
| 626 | |
| 627 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { |
| 628 | if (qlcnic_boards[i].vendor == pdev->vendor && |
| 629 | qlcnic_boards[i].device == pdev->device && |
| 630 | qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && |
| 631 | qlcnic_boards[i].sub_device == pdev->subsystem_device) { |
Sucheta Chakraborty | 02f6e46 | 2010-05-17 01:22:09 +0000 | [diff] [blame] | 632 | sprintf(name, "%pM: %s" , |
| 633 | adapter->mac_addr, |
| 634 | qlcnic_boards[i].short_name); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 635 | found = 1; |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | } |
| 640 | |
| 641 | if (!found) |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 642 | sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static void |
| 646 | qlcnic_check_options(struct qlcnic_adapter *adapter) |
| 647 | { |
| 648 | u32 fw_major, fw_minor, fw_build; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 649 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 650 | |
| 651 | fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); |
| 652 | fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); |
| 653 | fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); |
| 654 | |
| 655 | adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); |
| 656 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 657 | dev_info(&pdev->dev, "firmware v%d.%d.%d\n", |
| 658 | fw_major, fw_minor, fw_build); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 659 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 660 | if (adapter->ahw.port_type == QLCNIC_XGBE) { |
| 661 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; |
| 662 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
| 663 | } else if (adapter->ahw.port_type == QLCNIC_GBE) { |
| 664 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; |
| 665 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
| 666 | } |
| 667 | |
| 668 | adapter->msix_supported = !!use_msi_x; |
| 669 | adapter->rss_supported = !!use_msi_x; |
| 670 | |
| 671 | adapter->num_txd = MAX_CMD_DESCRIPTORS; |
| 672 | |
Sony Chacko | 251b036 | 2010-08-19 05:08:24 +0000 | [diff] [blame] | 673 | adapter->max_rds_rings = MAX_RDS_RINGS; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 676 | static int |
| 677 | qlcnic_initialize_nic(struct qlcnic_adapter *adapter) |
| 678 | { |
| 679 | int err; |
| 680 | struct qlcnic_info nic_info; |
| 681 | |
| 682 | err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func); |
| 683 | if (err) |
| 684 | return err; |
| 685 | |
Sucheta Chakraborty | a1c0c45 | 2010-10-04 04:20:14 +0000 | [diff] [blame] | 686 | adapter->physical_port = (u8)nic_info.phys_port; |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 687 | adapter->switch_mode = nic_info.switch_mode; |
| 688 | adapter->max_tx_ques = nic_info.max_tx_ques; |
| 689 | adapter->max_rx_ques = nic_info.max_rx_ques; |
| 690 | adapter->capabilities = nic_info.capabilities; |
| 691 | adapter->max_mac_filters = nic_info.max_mac_filters; |
| 692 | adapter->max_mtu = nic_info.max_mtu; |
| 693 | |
| 694 | if (adapter->capabilities & BIT_6) |
| 695 | adapter->flags |= QLCNIC_ESWITCH_ENABLED; |
| 696 | else |
| 697 | adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; |
| 698 | |
| 699 | return err; |
| 700 | } |
| 701 | |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 702 | static void |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 703 | qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, |
| 704 | struct qlcnic_esw_func_cfg *esw_cfg) |
| 705 | { |
| 706 | if (esw_cfg->discard_tagged) |
| 707 | adapter->flags &= ~QLCNIC_TAGGING_ENABLED; |
| 708 | else |
| 709 | adapter->flags |= QLCNIC_TAGGING_ENABLED; |
| 710 | |
| 711 | if (esw_cfg->vlan_id) |
| 712 | adapter->pvid = esw_cfg->vlan_id; |
| 713 | else |
| 714 | adapter->pvid = 0; |
| 715 | } |
| 716 | |
| 717 | static void |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 718 | qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, |
| 719 | struct qlcnic_esw_func_cfg *esw_cfg) |
| 720 | { |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 721 | adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | |
| 722 | QLCNIC_PROMISC_DISABLED); |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 723 | |
| 724 | if (esw_cfg->mac_anti_spoof) |
| 725 | adapter->flags |= QLCNIC_MACSPOOF; |
Sony Chacko | fe4d434 | 2010-08-19 05:08:27 +0000 | [diff] [blame] | 726 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 727 | if (!esw_cfg->mac_override) |
| 728 | adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; |
| 729 | |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 730 | if (!esw_cfg->promisc_mode) |
| 731 | adapter->flags |= QLCNIC_PROMISC_DISABLED; |
| 732 | |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 733 | qlcnic_set_netdev_features(adapter, esw_cfg); |
| 734 | } |
| 735 | |
| 736 | static int |
| 737 | qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) |
| 738 | { |
| 739 | struct qlcnic_esw_func_cfg esw_cfg; |
| 740 | |
| 741 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 742 | return 0; |
| 743 | |
| 744 | esw_cfg.pci_func = adapter->ahw.pci_func; |
| 745 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) |
| 746 | return -EIO; |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 747 | qlcnic_set_vlan_config(adapter, &esw_cfg); |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 748 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static void |
| 754 | qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, |
| 755 | struct qlcnic_esw_func_cfg *esw_cfg) |
| 756 | { |
| 757 | struct net_device *netdev = adapter->netdev; |
| 758 | unsigned long features, vlan_features; |
| 759 | |
| 760 | features = (NETIF_F_SG | NETIF_F_IP_CSUM | |
| 761 | NETIF_F_IPV6_CSUM | NETIF_F_GRO); |
| 762 | vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | |
| 763 | NETIF_F_IPV6_CSUM); |
| 764 | |
| 765 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { |
| 766 | features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 767 | vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 768 | } |
| 769 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
| 770 | features |= NETIF_F_LRO; |
| 771 | |
| 772 | if (esw_cfg->offload_flags & BIT_0) { |
| 773 | netdev->features |= features; |
| 774 | adapter->rx_csum = 1; |
| 775 | if (!(esw_cfg->offload_flags & BIT_1)) |
| 776 | netdev->features &= ~NETIF_F_TSO; |
| 777 | if (!(esw_cfg->offload_flags & BIT_2)) |
| 778 | netdev->features &= ~NETIF_F_TSO6; |
| 779 | } else { |
| 780 | netdev->features &= ~features; |
| 781 | adapter->rx_csum = 0; |
| 782 | } |
| 783 | |
| 784 | netdev->vlan_features = (features & vlan_features); |
| 785 | } |
| 786 | |
| 787 | static int |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 788 | qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) |
| 789 | { |
| 790 | void __iomem *priv_op; |
| 791 | u32 op_mode, priv_level; |
| 792 | int err = 0; |
| 793 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 794 | err = qlcnic_initialize_nic(adapter); |
| 795 | if (err) |
| 796 | return err; |
| 797 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 798 | if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) |
| 799 | return 0; |
| 800 | |
| 801 | priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; |
| 802 | op_mode = readl(priv_op); |
| 803 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); |
| 804 | |
| 805 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
| 806 | priv_level = QLCNIC_MGMT_FUNC; |
| 807 | else |
| 808 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); |
| 809 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 810 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 811 | if (priv_level == QLCNIC_MGMT_FUNC) { |
| 812 | adapter->op_mode = QLCNIC_MGMT_FUNC; |
| 813 | err = qlcnic_init_pci_info(adapter); |
| 814 | if (err) |
| 815 | return err; |
| 816 | /* Set privilege level for other functions */ |
| 817 | qlcnic_set_function_modes(adapter); |
| 818 | dev_info(&adapter->pdev->dev, |
| 819 | "HAL Version: %d, Management function\n", |
| 820 | adapter->fw_hal_version); |
| 821 | } else if (priv_level == QLCNIC_PRIV_FUNC) { |
| 822 | adapter->op_mode = QLCNIC_PRIV_FUNC; |
| 823 | dev_info(&adapter->pdev->dev, |
| 824 | "HAL Version: %d, Privileged function\n", |
| 825 | adapter->fw_hal_version); |
| 826 | } |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 827 | } |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 828 | |
| 829 | adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; |
| 830 | |
| 831 | return err; |
| 832 | } |
| 833 | |
| 834 | static int |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 835 | qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) |
| 836 | { |
| 837 | struct qlcnic_esw_func_cfg esw_cfg; |
| 838 | struct qlcnic_npar_info *npar; |
| 839 | u8 i; |
| 840 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 841 | if (adapter->need_fw_reset) |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 842 | return 0; |
| 843 | |
| 844 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 845 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) |
| 846 | continue; |
| 847 | memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); |
| 848 | esw_cfg.pci_func = i; |
| 849 | esw_cfg.offload_flags = BIT_0; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 850 | esw_cfg.mac_override = BIT_0; |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 851 | esw_cfg.promisc_mode = BIT_0; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 852 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) |
| 853 | esw_cfg.offload_flags |= (BIT_1 | BIT_2); |
| 854 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 855 | return -EIO; |
| 856 | npar = &adapter->npars[i]; |
| 857 | npar->pvid = esw_cfg.vlan_id; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 858 | npar->mac_override = esw_cfg.mac_override; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 859 | npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; |
| 860 | npar->discard_tagged = esw_cfg.discard_tagged; |
| 861 | npar->promisc_mode = esw_cfg.promisc_mode; |
| 862 | npar->offload_flags = esw_cfg.offload_flags; |
| 863 | } |
| 864 | |
| 865 | return 0; |
| 866 | } |
| 867 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 868 | static int |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 869 | qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, |
| 870 | struct qlcnic_npar_info *npar, int pci_func) |
| 871 | { |
| 872 | struct qlcnic_esw_func_cfg esw_cfg; |
| 873 | esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; |
| 874 | esw_cfg.pci_func = pci_func; |
| 875 | esw_cfg.vlan_id = npar->pvid; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 876 | esw_cfg.mac_override = npar->mac_override; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 877 | esw_cfg.discard_tagged = npar->discard_tagged; |
| 878 | esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; |
| 879 | esw_cfg.offload_flags = npar->offload_flags; |
| 880 | esw_cfg.promisc_mode = npar->promisc_mode; |
| 881 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 882 | return -EIO; |
| 883 | |
| 884 | esw_cfg.op_mode = QLCNIC_ADD_VLAN; |
| 885 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 886 | return -EIO; |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | static int |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 892 | qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) |
| 893 | { |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 894 | int i, err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 895 | struct qlcnic_npar_info *npar; |
| 896 | struct qlcnic_info nic_info; |
| 897 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 898 | if (!adapter->need_fw_reset) |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 899 | return 0; |
| 900 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 901 | /* Set the NPAR config data after FW reset */ |
| 902 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 903 | npar = &adapter->npars[i]; |
| 904 | if (npar->type != QLCNIC_TYPE_NIC) |
| 905 | continue; |
| 906 | err = qlcnic_get_nic_info(adapter, &nic_info, i); |
| 907 | if (err) |
| 908 | return err; |
| 909 | nic_info.min_tx_bw = npar->min_bw; |
| 910 | nic_info.max_tx_bw = npar->max_bw; |
| 911 | err = qlcnic_set_nic_info(adapter, &nic_info); |
| 912 | if (err) |
| 913 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 914 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 915 | if (npar->enable_pm) { |
| 916 | err = qlcnic_config_port_mirroring(adapter, |
| 917 | npar->dest_npar, 1, i); |
| 918 | if (err) |
| 919 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 920 | } |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 921 | err = qlcnic_reset_eswitch_config(adapter, npar, i); |
| 922 | if (err) |
| 923 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 924 | } |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 925 | return 0; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Amit Kumar Salecha | 78f84e1 | 2010-08-19 05:08:28 +0000 | [diff] [blame] | 928 | static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) |
| 929 | { |
| 930 | u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; |
| 931 | u32 npar_state; |
| 932 | |
| 933 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
| 934 | return 0; |
| 935 | |
| 936 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 937 | while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { |
| 938 | msleep(1000); |
| 939 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 940 | } |
| 941 | if (!npar_opt_timeo) { |
| 942 | dev_err(&adapter->pdev->dev, |
| 943 | "Waiting for NPAR state to opertional timeout\n"); |
| 944 | return -EIO; |
| 945 | } |
| 946 | return 0; |
| 947 | } |
| 948 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 949 | static int |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 950 | qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) |
| 951 | { |
| 952 | int err; |
| 953 | |
| 954 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || |
| 955 | adapter->op_mode != QLCNIC_MGMT_FUNC) |
| 956 | return 0; |
| 957 | |
| 958 | err = qlcnic_set_default_offload_settings(adapter); |
| 959 | if (err) |
| 960 | return err; |
| 961 | |
| 962 | err = qlcnic_reset_npar_config(adapter); |
| 963 | if (err) |
| 964 | return err; |
| 965 | |
| 966 | qlcnic_dev_set_npar_ready(adapter); |
| 967 | |
| 968 | return err; |
| 969 | } |
| 970 | |
| 971 | static int |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 972 | qlcnic_start_firmware(struct qlcnic_adapter *adapter) |
| 973 | { |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 974 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 975 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 976 | err = qlcnic_can_start_firmware(adapter); |
| 977 | if (err < 0) |
| 978 | return err; |
| 979 | else if (!err) |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 980 | goto check_fw_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 981 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 982 | if (load_fw_file) |
| 983 | qlcnic_request_firmware(adapter); |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 984 | else { |
Sony Chacko | 8cfdce0 | 2010-08-26 14:02:41 +0000 | [diff] [blame] | 985 | err = qlcnic_check_flash_fw_ver(adapter); |
| 986 | if (err) |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 987 | goto err_out; |
| 988 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 989 | adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 990 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 991 | |
| 992 | err = qlcnic_need_fw_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 993 | if (err == 0) |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 994 | goto check_fw_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 995 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 996 | err = qlcnic_pinit_from_rom(adapter); |
| 997 | if (err) |
| 998 | goto err_out; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 999 | |
| 1000 | err = qlcnic_load_firmware(adapter); |
| 1001 | if (err) |
| 1002 | goto err_out; |
| 1003 | |
| 1004 | qlcnic_release_firmware(adapter); |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 1005 | QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1006 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 1007 | check_fw_status: |
| 1008 | err = qlcnic_check_fw_status(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1009 | if (err) |
| 1010 | goto err_out; |
| 1011 | |
| 1012 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1013 | qlcnic_idc_debug_info(adapter, 1); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 1014 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 1015 | err = qlcnic_check_eswitch_mode(adapter); |
| 1016 | if (err) { |
| 1017 | dev_err(&adapter->pdev->dev, |
| 1018 | "Memory allocation failed for eswitch\n"); |
| 1019 | goto err_out; |
| 1020 | } |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 1021 | err = qlcnic_set_mgmt_operations(adapter); |
| 1022 | if (err) |
| 1023 | goto err_out; |
| 1024 | |
| 1025 | qlcnic_check_options(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1026 | adapter->need_fw_reset = 0; |
| 1027 | |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1028 | qlcnic_release_firmware(adapter); |
| 1029 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1030 | |
| 1031 | err_out: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1032 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 1033 | dev_err(&adapter->pdev->dev, "Device state set to failed\n"); |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 1034 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1035 | qlcnic_release_firmware(adapter); |
| 1036 | return err; |
| 1037 | } |
| 1038 | |
| 1039 | static int |
| 1040 | qlcnic_request_irq(struct qlcnic_adapter *adapter) |
| 1041 | { |
| 1042 | irq_handler_t handler; |
| 1043 | struct qlcnic_host_sds_ring *sds_ring; |
| 1044 | int err, ring; |
| 1045 | |
| 1046 | unsigned long flags = 0; |
| 1047 | struct net_device *netdev = adapter->netdev; |
| 1048 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1049 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1050 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1051 | handler = qlcnic_tmp_intr; |
| 1052 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) |
| 1053 | flags |= IRQF_SHARED; |
| 1054 | |
| 1055 | } else { |
| 1056 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 1057 | handler = qlcnic_msix_intr; |
| 1058 | else if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 1059 | handler = qlcnic_msi_intr; |
| 1060 | else { |
| 1061 | flags |= IRQF_SHARED; |
| 1062 | handler = qlcnic_intr; |
| 1063 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1064 | } |
| 1065 | adapter->irq = netdev->irq; |
| 1066 | |
| 1067 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1068 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1069 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
| 1070 | err = request_irq(sds_ring->irq, handler, |
| 1071 | flags, sds_ring->name, sds_ring); |
| 1072 | if (err) |
| 1073 | return err; |
| 1074 | } |
| 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | static void |
| 1080 | qlcnic_free_irq(struct qlcnic_adapter *adapter) |
| 1081 | { |
| 1082 | int ring; |
| 1083 | struct qlcnic_host_sds_ring *sds_ring; |
| 1084 | |
| 1085 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1086 | |
| 1087 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1088 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1089 | free_irq(sds_ring->irq, sds_ring); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | static void |
| 1094 | qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter) |
| 1095 | { |
| 1096 | adapter->coal.flags = QLCNIC_INTR_DEFAULT; |
| 1097 | adapter->coal.normal.data.rx_time_us = |
| 1098 | QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; |
| 1099 | adapter->coal.normal.data.rx_packets = |
| 1100 | QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; |
| 1101 | adapter->coal.normal.data.tx_time_us = |
| 1102 | QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US; |
| 1103 | adapter->coal.normal.data.tx_packets = |
| 1104 | QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS; |
| 1105 | } |
| 1106 | |
| 1107 | static int |
| 1108 | __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1109 | { |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1110 | int ring; |
| 1111 | struct qlcnic_host_rds_ring *rds_ring; |
| 1112 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1113 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1114 | return -EIO; |
| 1115 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1116 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1117 | return 0; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 1118 | if (qlcnic_set_eswitch_port_config(adapter)) |
| 1119 | return -EIO; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1120 | |
| 1121 | if (qlcnic_fw_create_ctx(adapter)) |
| 1122 | return -EIO; |
| 1123 | |
| 1124 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1125 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 1126 | qlcnic_post_rx_buffers(adapter, ring, rds_ring); |
| 1127 | } |
| 1128 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1129 | qlcnic_set_multi(netdev); |
| 1130 | qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); |
| 1131 | |
| 1132 | adapter->ahw.linkup = 0; |
| 1133 | |
| 1134 | if (adapter->max_sds_rings > 1) |
| 1135 | qlcnic_config_rss(adapter, 1); |
| 1136 | |
| 1137 | qlcnic_config_intr_coalesce(adapter); |
| 1138 | |
Sucheta Chakraborty | 24763d8 | 2010-08-17 00:34:25 +0000 | [diff] [blame] | 1139 | if (netdev->features & NETIF_F_LRO) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1140 | qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); |
| 1141 | |
| 1142 | qlcnic_napi_enable(adapter); |
| 1143 | |
| 1144 | qlcnic_linkevent_request(adapter, 1); |
| 1145 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1146 | adapter->reset_context = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1147 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | /* Usage: During resume and firmware recovery module.*/ |
| 1152 | |
| 1153 | static int |
| 1154 | qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1155 | { |
| 1156 | int err = 0; |
| 1157 | |
| 1158 | rtnl_lock(); |
| 1159 | if (netif_running(netdev)) |
| 1160 | err = __qlcnic_up(adapter, netdev); |
| 1161 | rtnl_unlock(); |
| 1162 | |
| 1163 | return err; |
| 1164 | } |
| 1165 | |
| 1166 | static void |
| 1167 | __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1168 | { |
| 1169 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1170 | return; |
| 1171 | |
| 1172 | if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1173 | return; |
| 1174 | |
| 1175 | smp_mb(); |
| 1176 | spin_lock(&adapter->tx_clean_lock); |
| 1177 | netif_carrier_off(netdev); |
| 1178 | netif_tx_disable(netdev); |
| 1179 | |
| 1180 | qlcnic_free_mac_list(adapter); |
| 1181 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1182 | if (adapter->fhash.fnum) |
| 1183 | qlcnic_delete_lb_filters(adapter); |
| 1184 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1185 | qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); |
| 1186 | |
| 1187 | qlcnic_napi_disable(adapter); |
| 1188 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1189 | qlcnic_fw_destroy_ctx(adapter); |
| 1190 | |
| 1191 | qlcnic_reset_rx_buffers_list(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1192 | qlcnic_release_tx_buffers(adapter); |
| 1193 | spin_unlock(&adapter->tx_clean_lock); |
| 1194 | } |
| 1195 | |
| 1196 | /* Usage: During suspend and firmware recovery module */ |
| 1197 | |
| 1198 | static void |
| 1199 | qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1200 | { |
| 1201 | rtnl_lock(); |
| 1202 | if (netif_running(netdev)) |
| 1203 | __qlcnic_down(adapter, netdev); |
| 1204 | rtnl_unlock(); |
| 1205 | |
| 1206 | } |
| 1207 | |
| 1208 | static int |
| 1209 | qlcnic_attach(struct qlcnic_adapter *adapter) |
| 1210 | { |
| 1211 | struct net_device *netdev = adapter->netdev; |
| 1212 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1213 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1214 | |
| 1215 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) |
| 1216 | return 0; |
| 1217 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1218 | err = qlcnic_napi_add(adapter, netdev); |
| 1219 | if (err) |
| 1220 | return err; |
| 1221 | |
| 1222 | err = qlcnic_alloc_sw_resources(adapter); |
| 1223 | if (err) { |
| 1224 | dev_err(&pdev->dev, "Error in setting sw resources\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1225 | goto err_out_napi_del; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | err = qlcnic_alloc_hw_resources(adapter); |
| 1229 | if (err) { |
| 1230 | dev_err(&pdev->dev, "Error in setting hw resources\n"); |
| 1231 | goto err_out_free_sw; |
| 1232 | } |
| 1233 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1234 | err = qlcnic_request_irq(adapter); |
| 1235 | if (err) { |
| 1236 | dev_err(&pdev->dev, "failed to setup interrupt\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1237 | goto err_out_free_hw; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | qlcnic_init_coalesce_defaults(adapter); |
| 1241 | |
| 1242 | qlcnic_create_sysfs_entries(adapter); |
| 1243 | |
| 1244 | adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; |
| 1245 | return 0; |
| 1246 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1247 | err_out_free_hw: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1248 | qlcnic_free_hw_resources(adapter); |
| 1249 | err_out_free_sw: |
| 1250 | qlcnic_free_sw_resources(adapter); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1251 | err_out_napi_del: |
| 1252 | qlcnic_napi_del(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1253 | return err; |
| 1254 | } |
| 1255 | |
| 1256 | static void |
| 1257 | qlcnic_detach(struct qlcnic_adapter *adapter) |
| 1258 | { |
| 1259 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1260 | return; |
| 1261 | |
| 1262 | qlcnic_remove_sysfs_entries(adapter); |
| 1263 | |
| 1264 | qlcnic_free_hw_resources(adapter); |
| 1265 | qlcnic_release_rx_buffers(adapter); |
| 1266 | qlcnic_free_irq(adapter); |
| 1267 | qlcnic_napi_del(adapter); |
| 1268 | qlcnic_free_sw_resources(adapter); |
| 1269 | |
| 1270 | adapter->is_up = 0; |
| 1271 | } |
| 1272 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1273 | void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) |
| 1274 | { |
| 1275 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1276 | struct qlcnic_host_sds_ring *sds_ring; |
| 1277 | int ring; |
| 1278 | |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1279 | clear_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1280 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1281 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1282 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; |
| 1283 | qlcnic_disable_int(sds_ring); |
| 1284 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1287 | qlcnic_fw_destroy_ctx(adapter); |
| 1288 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1289 | qlcnic_detach(adapter); |
| 1290 | |
| 1291 | adapter->diag_test = 0; |
| 1292 | adapter->max_sds_rings = max_sds_rings; |
| 1293 | |
| 1294 | if (qlcnic_attach(adapter)) |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1295 | goto out; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1296 | |
| 1297 | if (netif_running(netdev)) |
| 1298 | __qlcnic_up(adapter, netdev); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1299 | out: |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1300 | netif_device_attach(netdev); |
| 1301 | } |
| 1302 | |
| 1303 | int qlcnic_diag_alloc_res(struct net_device *netdev, int test) |
| 1304 | { |
| 1305 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1306 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1307 | struct qlcnic_host_rds_ring *rds_ring; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1308 | int ring; |
| 1309 | int ret; |
| 1310 | |
| 1311 | netif_device_detach(netdev); |
| 1312 | |
| 1313 | if (netif_running(netdev)) |
| 1314 | __qlcnic_down(adapter, netdev); |
| 1315 | |
| 1316 | qlcnic_detach(adapter); |
| 1317 | |
| 1318 | adapter->max_sds_rings = 1; |
| 1319 | adapter->diag_test = test; |
| 1320 | |
| 1321 | ret = qlcnic_attach(adapter); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1322 | if (ret) { |
| 1323 | netif_device_attach(netdev); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1324 | return ret; |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1325 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1326 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1327 | ret = qlcnic_fw_create_ctx(adapter); |
| 1328 | if (ret) { |
| 1329 | qlcnic_detach(adapter); |
Sony Chacko | 57e4624 | 2010-07-24 18:32:18 +0000 | [diff] [blame] | 1330 | netif_device_attach(netdev); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1331 | return ret; |
| 1332 | } |
| 1333 | |
| 1334 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1335 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 1336 | qlcnic_post_rx_buffers(adapter, ring, rds_ring); |
| 1337 | } |
| 1338 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1339 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1340 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1341 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; |
| 1342 | qlcnic_enable_int(sds_ring); |
| 1343 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1344 | } |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1345 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1350 | /* Reset context in hardware only */ |
| 1351 | static int |
| 1352 | qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) |
| 1353 | { |
| 1354 | struct net_device *netdev = adapter->netdev; |
| 1355 | |
| 1356 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1357 | return -EBUSY; |
| 1358 | |
| 1359 | netif_device_detach(netdev); |
| 1360 | |
| 1361 | qlcnic_down(adapter, netdev); |
| 1362 | |
| 1363 | qlcnic_up(adapter, netdev); |
| 1364 | |
| 1365 | netif_device_attach(netdev); |
| 1366 | |
| 1367 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1371 | int |
| 1372 | qlcnic_reset_context(struct qlcnic_adapter *adapter) |
| 1373 | { |
| 1374 | int err = 0; |
| 1375 | struct net_device *netdev = adapter->netdev; |
| 1376 | |
| 1377 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1378 | return -EBUSY; |
| 1379 | |
| 1380 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { |
| 1381 | |
| 1382 | netif_device_detach(netdev); |
| 1383 | |
| 1384 | if (netif_running(netdev)) |
| 1385 | __qlcnic_down(adapter, netdev); |
| 1386 | |
| 1387 | qlcnic_detach(adapter); |
| 1388 | |
| 1389 | if (netif_running(netdev)) { |
| 1390 | err = qlcnic_attach(adapter); |
| 1391 | if (!err) |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1392 | __qlcnic_up(adapter, netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | netif_device_attach(netdev); |
| 1396 | } |
| 1397 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1398 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1399 | return err; |
| 1400 | } |
| 1401 | |
| 1402 | static int |
| 1403 | qlcnic_setup_netdev(struct qlcnic_adapter *adapter, |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1404 | struct net_device *netdev, u8 pci_using_dac) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1405 | { |
| 1406 | int err; |
| 1407 | struct pci_dev *pdev = adapter->pdev; |
| 1408 | |
| 1409 | adapter->rx_csum = 1; |
| 1410 | adapter->mc_enabled = 0; |
| 1411 | adapter->max_mc_count = 38; |
| 1412 | |
| 1413 | netdev->netdev_ops = &qlcnic_netdev_ops; |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 1414 | netdev->watchdog_timeo = 5*HZ; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1415 | |
| 1416 | qlcnic_change_mtu(netdev, netdev->mtu); |
| 1417 | |
| 1418 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); |
| 1419 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1420 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
Amit Kumar Salecha | d579066 | 2010-09-16 19:14:39 +0000 | [diff] [blame] | 1421 | NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_HW_VLAN_RX); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1422 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
Anirban Chakraborty | ac8d0c4 | 2010-07-09 13:14:58 +0000 | [diff] [blame] | 1423 | NETIF_F_IPV6_CSUM); |
| 1424 | |
| 1425 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { |
| 1426 | netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 1427 | netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 1428 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1429 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1430 | if (pci_using_dac) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1431 | netdev->features |= NETIF_F_HIGHDMA; |
| 1432 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1433 | } |
| 1434 | |
| 1435 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) |
| 1436 | netdev->features |= (NETIF_F_HW_VLAN_TX); |
| 1437 | |
| 1438 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
| 1439 | netdev->features |= NETIF_F_LRO; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1440 | netdev->irq = adapter->msix_entries[0].vector; |
| 1441 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1442 | netif_carrier_off(netdev); |
| 1443 | netif_stop_queue(netdev); |
| 1444 | |
| 1445 | err = register_netdev(netdev); |
| 1446 | if (err) { |
| 1447 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1448 | return err; |
| 1449 | } |
| 1450 | |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1454 | static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) |
| 1455 | { |
| 1456 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 1457 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) |
| 1458 | *pci_using_dac = 1; |
| 1459 | else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && |
| 1460 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 1461 | *pci_using_dac = 0; |
| 1462 | else { |
| 1463 | dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); |
| 1464 | return -EIO; |
| 1465 | } |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1470 | static int __devinit |
| 1471 | qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1472 | { |
| 1473 | struct net_device *netdev = NULL; |
| 1474 | struct qlcnic_adapter *adapter = NULL; |
| 1475 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1476 | uint8_t revision_id; |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1477 | uint8_t pci_using_dac; |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 1478 | char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1479 | |
| 1480 | err = pci_enable_device(pdev); |
| 1481 | if (err) |
| 1482 | return err; |
| 1483 | |
| 1484 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1485 | err = -ENODEV; |
| 1486 | goto err_out_disable_pdev; |
| 1487 | } |
| 1488 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1489 | err = qlcnic_set_dma_mask(pdev, &pci_using_dac); |
| 1490 | if (err) |
| 1491 | goto err_out_disable_pdev; |
| 1492 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1493 | err = pci_request_regions(pdev, qlcnic_driver_name); |
| 1494 | if (err) |
| 1495 | goto err_out_disable_pdev; |
| 1496 | |
| 1497 | pci_set_master(pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 1498 | pci_enable_pcie_error_reporting(pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1499 | |
| 1500 | netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); |
| 1501 | if (!netdev) { |
| 1502 | dev_err(&pdev->dev, "failed to allocate net_device\n"); |
| 1503 | err = -ENOMEM; |
| 1504 | goto err_out_free_res; |
| 1505 | } |
| 1506 | |
| 1507 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1508 | |
| 1509 | adapter = netdev_priv(netdev); |
| 1510 | adapter->netdev = netdev; |
| 1511 | adapter->pdev = pdev; |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1512 | adapter->dev_rst_time = jiffies; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1513 | |
| 1514 | revision_id = pdev->revision; |
| 1515 | adapter->ahw.revision_id = revision_id; |
| 1516 | |
| 1517 | rwlock_init(&adapter->ahw.crb_lock); |
| 1518 | mutex_init(&adapter->ahw.mem_lock); |
| 1519 | |
| 1520 | spin_lock_init(&adapter->tx_clean_lock); |
| 1521 | INIT_LIST_HEAD(&adapter->mac_list); |
| 1522 | |
| 1523 | err = qlcnic_setup_pci_map(adapter); |
| 1524 | if (err) |
| 1525 | goto err_out_free_netdev; |
| 1526 | |
| 1527 | /* This will be reset for mezz cards */ |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1528 | adapter->portnum = adapter->ahw.pci_func; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1529 | |
| 1530 | err = qlcnic_get_board_info(adapter); |
| 1531 | if (err) { |
| 1532 | dev_err(&pdev->dev, "Error getting board config info.\n"); |
| 1533 | goto err_out_iounmap; |
| 1534 | } |
| 1535 | |
Sony Chacko | 8cfdce0 | 2010-08-26 14:02:41 +0000 | [diff] [blame] | 1536 | err = qlcnic_setup_idc_param(adapter); |
| 1537 | if (err) |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 1538 | goto err_out_iounmap; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1539 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1540 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1541 | if (err) { |
| 1542 | dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1543 | goto err_out_decr_ref; |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1544 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1545 | |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 1546 | if (qlcnic_read_mac_addr(adapter)) |
| 1547 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1548 | |
| 1549 | if (adapter->portnum == 0) { |
| 1550 | get_brd_name(adapter, brd_name); |
| 1551 | |
| 1552 | pr_info("%s: %s Board Chip rev 0x%x\n", |
| 1553 | module_name(THIS_MODULE), |
| 1554 | brd_name, adapter->ahw.revision_id); |
| 1555 | } |
| 1556 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1557 | qlcnic_clear_stats(adapter); |
| 1558 | |
| 1559 | qlcnic_setup_intr(adapter); |
| 1560 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1561 | err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1562 | if (err) |
| 1563 | goto err_out_disable_msi; |
| 1564 | |
| 1565 | pci_set_drvdata(pdev, adapter); |
| 1566 | |
| 1567 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1568 | |
| 1569 | switch (adapter->ahw.port_type) { |
| 1570 | case QLCNIC_GBE: |
| 1571 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1572 | adapter->netdev->name); |
| 1573 | break; |
| 1574 | case QLCNIC_XGBE: |
| 1575 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1576 | adapter->netdev->name); |
| 1577 | break; |
| 1578 | } |
| 1579 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1580 | qlcnic_alloc_lb_filters_mem(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1581 | qlcnic_create_diag_entries(adapter); |
| 1582 | |
| 1583 | return 0; |
| 1584 | |
| 1585 | err_out_disable_msi: |
| 1586 | qlcnic_teardown_intr(adapter); |
| 1587 | |
| 1588 | err_out_decr_ref: |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1589 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1590 | |
| 1591 | err_out_iounmap: |
| 1592 | qlcnic_cleanup_pci_map(adapter); |
| 1593 | |
| 1594 | err_out_free_netdev: |
| 1595 | free_netdev(netdev); |
| 1596 | |
| 1597 | err_out_free_res: |
| 1598 | pci_release_regions(pdev); |
| 1599 | |
| 1600 | err_out_disable_pdev: |
| 1601 | pci_set_drvdata(pdev, NULL); |
| 1602 | pci_disable_device(pdev); |
| 1603 | return err; |
| 1604 | } |
| 1605 | |
| 1606 | static void __devexit qlcnic_remove(struct pci_dev *pdev) |
| 1607 | { |
| 1608 | struct qlcnic_adapter *adapter; |
| 1609 | struct net_device *netdev; |
| 1610 | |
| 1611 | adapter = pci_get_drvdata(pdev); |
| 1612 | if (adapter == NULL) |
| 1613 | return; |
| 1614 | |
| 1615 | netdev = adapter->netdev; |
| 1616 | |
| 1617 | qlcnic_cancel_fw_work(adapter); |
| 1618 | |
| 1619 | unregister_netdev(netdev); |
| 1620 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1621 | qlcnic_detach(adapter); |
| 1622 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1623 | if (adapter->npars != NULL) |
| 1624 | kfree(adapter->npars); |
| 1625 | if (adapter->eswitch != NULL) |
| 1626 | kfree(adapter->eswitch); |
| 1627 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1628 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1629 | |
| 1630 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1631 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1632 | qlcnic_free_lb_filters_mem(adapter); |
| 1633 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1634 | qlcnic_teardown_intr(adapter); |
| 1635 | |
| 1636 | qlcnic_remove_diag_entries(adapter); |
| 1637 | |
| 1638 | qlcnic_cleanup_pci_map(adapter); |
| 1639 | |
| 1640 | qlcnic_release_firmware(adapter); |
| 1641 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 1642 | pci_disable_pcie_error_reporting(pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1643 | pci_release_regions(pdev); |
| 1644 | pci_disable_device(pdev); |
| 1645 | pci_set_drvdata(pdev, NULL); |
| 1646 | |
| 1647 | free_netdev(netdev); |
| 1648 | } |
| 1649 | static int __qlcnic_shutdown(struct pci_dev *pdev) |
| 1650 | { |
| 1651 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1652 | struct net_device *netdev = adapter->netdev; |
| 1653 | int retval; |
| 1654 | |
| 1655 | netif_device_detach(netdev); |
| 1656 | |
| 1657 | qlcnic_cancel_fw_work(adapter); |
| 1658 | |
| 1659 | if (netif_running(netdev)) |
| 1660 | qlcnic_down(adapter, netdev); |
| 1661 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1662 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1663 | |
| 1664 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1665 | |
| 1666 | retval = pci_save_state(pdev); |
| 1667 | if (retval) |
| 1668 | return retval; |
| 1669 | |
| 1670 | if (qlcnic_wol_supported(adapter)) { |
| 1671 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1672 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1673 | } |
| 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
| 1678 | static void qlcnic_shutdown(struct pci_dev *pdev) |
| 1679 | { |
| 1680 | if (__qlcnic_shutdown(pdev)) |
| 1681 | return; |
| 1682 | |
| 1683 | pci_disable_device(pdev); |
| 1684 | } |
| 1685 | |
| 1686 | #ifdef CONFIG_PM |
| 1687 | static int |
| 1688 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1689 | { |
| 1690 | int retval; |
| 1691 | |
| 1692 | retval = __qlcnic_shutdown(pdev); |
| 1693 | if (retval) |
| 1694 | return retval; |
| 1695 | |
| 1696 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
| 1700 | static int |
| 1701 | qlcnic_resume(struct pci_dev *pdev) |
| 1702 | { |
| 1703 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1704 | struct net_device *netdev = adapter->netdev; |
| 1705 | int err; |
| 1706 | |
| 1707 | err = pci_enable_device(pdev); |
| 1708 | if (err) |
| 1709 | return err; |
| 1710 | |
| 1711 | pci_set_power_state(pdev, PCI_D0); |
| 1712 | pci_set_master(pdev); |
| 1713 | pci_restore_state(pdev); |
| 1714 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1715 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1716 | if (err) { |
| 1717 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1718 | return err; |
| 1719 | } |
| 1720 | |
| 1721 | if (netif_running(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1722 | err = qlcnic_up(adapter, netdev); |
| 1723 | if (err) |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1724 | goto done; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1725 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 1726 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1727 | } |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1728 | done: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1729 | netif_device_attach(netdev); |
| 1730 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1731 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1732 | } |
| 1733 | #endif |
| 1734 | |
| 1735 | static int qlcnic_open(struct net_device *netdev) |
| 1736 | { |
| 1737 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1738 | int err; |
| 1739 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1740 | err = qlcnic_attach(adapter); |
| 1741 | if (err) |
| 1742 | return err; |
| 1743 | |
| 1744 | err = __qlcnic_up(adapter, netdev); |
| 1745 | if (err) |
| 1746 | goto err_out; |
| 1747 | |
| 1748 | netif_start_queue(netdev); |
| 1749 | |
| 1750 | return 0; |
| 1751 | |
| 1752 | err_out: |
| 1753 | qlcnic_detach(adapter); |
| 1754 | return err; |
| 1755 | } |
| 1756 | |
| 1757 | /* |
| 1758 | * qlcnic_close - Disables a network interface entry point |
| 1759 | */ |
| 1760 | static int qlcnic_close(struct net_device *netdev) |
| 1761 | { |
| 1762 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1763 | |
| 1764 | __qlcnic_down(adapter, netdev); |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | static void |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1769 | qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) |
| 1770 | { |
| 1771 | void *head; |
| 1772 | int i; |
| 1773 | |
| 1774 | if (!qlcnic_mac_learn) |
| 1775 | return; |
| 1776 | |
| 1777 | spin_lock_init(&adapter->mac_learn_lock); |
| 1778 | |
| 1779 | head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), |
| 1780 | GFP_KERNEL); |
| 1781 | if (!head) |
| 1782 | return; |
| 1783 | |
| 1784 | adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; |
| 1785 | adapter->fhash.fhead = (struct hlist_head *)head; |
| 1786 | |
| 1787 | for (i = 0; i < adapter->fhash.fmax; i++) |
| 1788 | INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); |
| 1789 | } |
| 1790 | |
| 1791 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) |
| 1792 | { |
| 1793 | if (adapter->fhash.fmax && adapter->fhash.fhead) |
| 1794 | kfree(adapter->fhash.fhead); |
| 1795 | |
| 1796 | adapter->fhash.fhead = NULL; |
| 1797 | adapter->fhash.fmax = 0; |
| 1798 | } |
| 1799 | |
| 1800 | static void qlcnic_change_filter(struct qlcnic_adapter *adapter, |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1801 | u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring) |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1802 | { |
| 1803 | struct cmd_desc_type0 *hwdesc; |
| 1804 | struct qlcnic_nic_req *req; |
| 1805 | struct qlcnic_mac_req *mac_req; |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1806 | struct qlcnic_vlan_req *vlan_req; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1807 | u32 producer; |
| 1808 | u64 word; |
| 1809 | |
| 1810 | producer = tx_ring->producer; |
| 1811 | hwdesc = &tx_ring->desc_head[tx_ring->producer]; |
| 1812 | |
| 1813 | req = (struct qlcnic_nic_req *)hwdesc; |
| 1814 | memset(req, 0, sizeof(struct qlcnic_nic_req)); |
| 1815 | req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23); |
| 1816 | |
| 1817 | word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16); |
| 1818 | req->req_hdr = cpu_to_le64(word); |
| 1819 | |
| 1820 | mac_req = (struct qlcnic_mac_req *)&(req->words[0]); |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1821 | mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1822 | memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN); |
| 1823 | |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1824 | vlan_req = (struct qlcnic_vlan_req *)&req->words[1]; |
| 1825 | vlan_req->vlan_id = vlan_id; |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1826 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1827 | tx_ring->producer = get_next_index(producer, tx_ring->num_desc); |
| 1828 | } |
| 1829 | |
| 1830 | #define QLCNIC_MAC_HASH(MAC)\ |
| 1831 | ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25)) |
| 1832 | |
| 1833 | static void |
| 1834 | qlcnic_send_filter(struct qlcnic_adapter *adapter, |
| 1835 | struct qlcnic_host_tx_ring *tx_ring, |
| 1836 | struct cmd_desc_type0 *first_desc, |
| 1837 | struct sk_buff *skb) |
| 1838 | { |
| 1839 | struct ethhdr *phdr = (struct ethhdr *)(skb->data); |
| 1840 | struct qlcnic_filter *fil, *tmp_fil; |
| 1841 | struct hlist_node *tmp_hnode, *n; |
| 1842 | struct hlist_head *head; |
| 1843 | u64 src_addr = 0; |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1844 | __le16 vlan_id = 0; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1845 | u8 hindex; |
| 1846 | |
| 1847 | if (!compare_ether_addr(phdr->h_source, adapter->mac_addr)) |
| 1848 | return; |
| 1849 | |
| 1850 | if (adapter->fhash.fnum >= adapter->fhash.fmax) |
| 1851 | return; |
| 1852 | |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1853 | /* Only NPAR capable devices support vlan based learning*/ |
| 1854 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) |
| 1855 | vlan_id = first_desc->vlan_TCI; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1856 | memcpy(&src_addr, phdr->h_source, ETH_ALEN); |
| 1857 | hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1); |
| 1858 | head = &(adapter->fhash.fhead[hindex]); |
| 1859 | |
| 1860 | hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) { |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1861 | if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) && |
| 1862 | tmp_fil->vlan_id == vlan_id) { |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1863 | tmp_fil->ftime = jiffies; |
| 1864 | return; |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC); |
| 1869 | if (!fil) |
| 1870 | return; |
| 1871 | |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1872 | qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring); |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1873 | |
| 1874 | fil->ftime = jiffies; |
Amit Kumar Salecha | 03c5d77 | 2010-08-31 17:17:52 +0000 | [diff] [blame] | 1875 | fil->vlan_id = vlan_id; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1876 | memcpy(fil->faddr, &src_addr, ETH_ALEN); |
| 1877 | spin_lock(&adapter->mac_learn_lock); |
| 1878 | hlist_add_head(&(fil->fnode), head); |
| 1879 | adapter->fhash.fnum++; |
| 1880 | spin_unlock(&adapter->mac_learn_lock); |
| 1881 | } |
| 1882 | |
| 1883 | static void |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1884 | qlcnic_tso_check(struct net_device *netdev, |
| 1885 | struct qlcnic_host_tx_ring *tx_ring, |
| 1886 | struct cmd_desc_type0 *first_desc, |
| 1887 | struct sk_buff *skb) |
| 1888 | { |
| 1889 | u8 opcode = TX_ETHER_PKT; |
| 1890 | __be16 protocol = skb->protocol; |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 1891 | u16 flags = 0; |
| 1892 | int copied, offset, copy_len, hdr_len = 0, tso = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1893 | struct cmd_desc_type0 *hwdesc; |
| 1894 | struct vlan_ethhdr *vh; |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1895 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1896 | u32 producer = tx_ring->producer; |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1897 | __le16 vlan_oob = first_desc->flags_opcode & |
| 1898 | cpu_to_le16(FLAGS_VLAN_OOB); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1899 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1900 | if (*(skb->data) & BIT_0) { |
| 1901 | flags |= BIT_0; |
| 1902 | memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); |
| 1903 | } |
| 1904 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1905 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
| 1906 | skb_shinfo(skb)->gso_size > 0) { |
| 1907 | |
| 1908 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1909 | |
| 1910 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 1911 | first_desc->total_hdr_length = hdr_len; |
| 1912 | if (vlan_oob) { |
| 1913 | first_desc->total_hdr_length += VLAN_HLEN; |
| 1914 | first_desc->tcp_hdr_offset = VLAN_HLEN; |
| 1915 | first_desc->ip_hdr_offset = VLAN_HLEN; |
| 1916 | /* Only in case of TSO on vlan device */ |
| 1917 | flags |= FLAGS_VLAN_TAGGED; |
| 1918 | } |
| 1919 | |
| 1920 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? |
| 1921 | TX_TCP_LSO6 : TX_TCP_LSO; |
| 1922 | tso = 1; |
| 1923 | |
| 1924 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 1925 | u8 l4proto; |
| 1926 | |
| 1927 | if (protocol == cpu_to_be16(ETH_P_IP)) { |
| 1928 | l4proto = ip_hdr(skb)->protocol; |
| 1929 | |
| 1930 | if (l4proto == IPPROTO_TCP) |
| 1931 | opcode = TX_TCP_PKT; |
| 1932 | else if (l4proto == IPPROTO_UDP) |
| 1933 | opcode = TX_UDP_PKT; |
| 1934 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { |
| 1935 | l4proto = ipv6_hdr(skb)->nexthdr; |
| 1936 | |
| 1937 | if (l4proto == IPPROTO_TCP) |
| 1938 | opcode = TX_TCPV6_PKT; |
| 1939 | else if (l4proto == IPPROTO_UDP) |
| 1940 | opcode = TX_UDPV6_PKT; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
| 1945 | first_desc->ip_hdr_offset += skb_network_offset(skb); |
| 1946 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); |
| 1947 | |
| 1948 | if (!tso) |
| 1949 | return; |
| 1950 | |
| 1951 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1952 | * the descriptor ring |
| 1953 | */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1954 | copied = 0; |
| 1955 | offset = 2; |
| 1956 | |
| 1957 | if (vlan_oob) { |
| 1958 | /* Create a TSO vlan header template for firmware */ |
| 1959 | |
| 1960 | hwdesc = &tx_ring->desc_head[producer]; |
| 1961 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1962 | |
| 1963 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1964 | hdr_len + VLAN_HLEN); |
| 1965 | |
| 1966 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); |
| 1967 | skb_copy_from_linear_data(skb, vh, 12); |
| 1968 | vh->h_vlan_proto = htons(ETH_P_8021Q); |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 1969 | vh->h_vlan_TCI = (__be16)swab16((u16)first_desc->vlan_TCI); |
| 1970 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1971 | skb_copy_from_linear_data_offset(skb, 12, |
| 1972 | (char *)vh + 16, copy_len - 16); |
| 1973 | |
| 1974 | copied = copy_len - VLAN_HLEN; |
| 1975 | offset = 0; |
| 1976 | |
| 1977 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1978 | } |
| 1979 | |
| 1980 | while (copied < hdr_len) { |
| 1981 | |
| 1982 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1983 | (hdr_len - copied)); |
| 1984 | |
| 1985 | hwdesc = &tx_ring->desc_head[producer]; |
| 1986 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1987 | |
| 1988 | skb_copy_from_linear_data_offset(skb, copied, |
| 1989 | (char *)hwdesc + offset, copy_len); |
| 1990 | |
| 1991 | copied += copy_len; |
| 1992 | offset = 0; |
| 1993 | |
| 1994 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1995 | } |
| 1996 | |
| 1997 | tx_ring->producer = producer; |
| 1998 | barrier(); |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1999 | adapter->stats.lso_frames++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | static int |
| 2003 | qlcnic_map_tx_skb(struct pci_dev *pdev, |
| 2004 | struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) |
| 2005 | { |
| 2006 | struct qlcnic_skb_frag *nf; |
| 2007 | struct skb_frag_struct *frag; |
| 2008 | int i, nr_frags; |
| 2009 | dma_addr_t map; |
| 2010 | |
| 2011 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 2012 | nf = &pbuf->frag_array[0]; |
| 2013 | |
| 2014 | map = pci_map_single(pdev, skb->data, |
| 2015 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 2016 | if (pci_dma_mapping_error(pdev, map)) |
| 2017 | goto out_err; |
| 2018 | |
| 2019 | nf->dma = map; |
| 2020 | nf->length = skb_headlen(skb); |
| 2021 | |
| 2022 | for (i = 0; i < nr_frags; i++) { |
| 2023 | frag = &skb_shinfo(skb)->frags[i]; |
| 2024 | nf = &pbuf->frag_array[i+1]; |
| 2025 | |
| 2026 | map = pci_map_page(pdev, frag->page, frag->page_offset, |
| 2027 | frag->size, PCI_DMA_TODEVICE); |
| 2028 | if (pci_dma_mapping_error(pdev, map)) |
| 2029 | goto unwind; |
| 2030 | |
| 2031 | nf->dma = map; |
| 2032 | nf->length = frag->size; |
| 2033 | } |
| 2034 | |
| 2035 | return 0; |
| 2036 | |
| 2037 | unwind: |
| 2038 | while (--i >= 0) { |
| 2039 | nf = &pbuf->frag_array[i+1]; |
| 2040 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); |
| 2041 | } |
| 2042 | |
| 2043 | nf = &pbuf->frag_array[0]; |
| 2044 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); |
| 2045 | |
| 2046 | out_err: |
| 2047 | return -ENOMEM; |
| 2048 | } |
| 2049 | |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 2050 | static int |
| 2051 | qlcnic_check_tx_tagging(struct qlcnic_adapter *adapter, |
| 2052 | struct sk_buff *skb, |
| 2053 | struct cmd_desc_type0 *first_desc) |
| 2054 | { |
| 2055 | u8 opcode = 0; |
| 2056 | u16 flags = 0; |
| 2057 | __be16 protocol = skb->protocol; |
| 2058 | struct vlan_ethhdr *vh; |
| 2059 | |
| 2060 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 2061 | vh = (struct vlan_ethhdr *)skb->data; |
| 2062 | protocol = vh->h_vlan_encapsulated_proto; |
| 2063 | flags = FLAGS_VLAN_TAGGED; |
| 2064 | qlcnic_set_tx_vlan_tci(first_desc, ntohs(vh->h_vlan_TCI)); |
| 2065 | } else if (vlan_tx_tag_present(skb)) { |
| 2066 | flags = FLAGS_VLAN_OOB; |
| 2067 | qlcnic_set_tx_vlan_tci(first_desc, vlan_tx_tag_get(skb)); |
| 2068 | } |
| 2069 | if (unlikely(adapter->pvid)) { |
| 2070 | if (first_desc->vlan_TCI && |
| 2071 | !(adapter->flags & QLCNIC_TAGGING_ENABLED)) |
| 2072 | return -EIO; |
| 2073 | if (first_desc->vlan_TCI && |
| 2074 | (adapter->flags & QLCNIC_TAGGING_ENABLED)) |
| 2075 | goto set_flags; |
| 2076 | |
| 2077 | flags = FLAGS_VLAN_OOB; |
| 2078 | qlcnic_set_tx_vlan_tci(first_desc, adapter->pvid); |
| 2079 | } |
| 2080 | set_flags: |
| 2081 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); |
| 2082 | return 0; |
| 2083 | } |
| 2084 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2085 | static inline void |
| 2086 | qlcnic_clear_cmddesc(u64 *desc) |
| 2087 | { |
| 2088 | desc[0] = 0ULL; |
| 2089 | desc[2] = 0ULL; |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 2090 | desc[7] = 0ULL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2091 | } |
| 2092 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 2093 | netdev_tx_t |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2094 | qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 2095 | { |
| 2096 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2097 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 2098 | struct qlcnic_cmd_buffer *pbuf; |
| 2099 | struct qlcnic_skb_frag *buffrag; |
| 2100 | struct cmd_desc_type0 *hwdesc, *first_desc; |
| 2101 | struct pci_dev *pdev; |
Rajesh Borundia | dcb50af | 2010-08-31 17:17:49 +0000 | [diff] [blame] | 2102 | struct ethhdr *phdr; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2103 | int i, k; |
| 2104 | |
| 2105 | u32 producer; |
| 2106 | int frag_count, no_of_desc; |
| 2107 | u32 num_txd = tx_ring->num_desc; |
| 2108 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 2109 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
| 2110 | netif_stop_queue(netdev); |
| 2111 | return NETDEV_TX_BUSY; |
| 2112 | } |
| 2113 | |
Sony Chacko | fe4d434 | 2010-08-19 05:08:27 +0000 | [diff] [blame] | 2114 | if (adapter->flags & QLCNIC_MACSPOOF) { |
Rajesh Borundia | dcb50af | 2010-08-31 17:17:49 +0000 | [diff] [blame] | 2115 | phdr = (struct ethhdr *)skb->data; |
| 2116 | if (compare_ether_addr(phdr->h_source, |
Sony Chacko | fe4d434 | 2010-08-19 05:08:27 +0000 | [diff] [blame] | 2117 | adapter->mac_addr)) |
| 2118 | goto drop_packet; |
| 2119 | } |
| 2120 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2121 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 2122 | |
| 2123 | /* 4 fragments per cmd des */ |
| 2124 | no_of_desc = (frag_count + 3) >> 2; |
| 2125 | |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 2126 | if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2127 | netif_stop_queue(netdev); |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 2128 | smp_mb(); |
| 2129 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) |
| 2130 | netif_start_queue(netdev); |
| 2131 | else { |
| 2132 | adapter->stats.xmit_off++; |
| 2133 | return NETDEV_TX_BUSY; |
| 2134 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | producer = tx_ring->producer; |
| 2138 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
| 2139 | |
| 2140 | pdev = adapter->pdev; |
| 2141 | |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 2142 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
| 2143 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 2144 | |
| 2145 | if (qlcnic_check_tx_tagging(adapter, skb, first_desc)) |
| 2146 | goto drop_packet; |
| 2147 | |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 2148 | if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { |
| 2149 | adapter->stats.tx_dma_map_error++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2150 | goto drop_packet; |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 2151 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2152 | |
| 2153 | pbuf->skb = skb; |
| 2154 | pbuf->frag_count = frag_count; |
| 2155 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2156 | qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); |
| 2157 | qlcnic_set_tx_port(first_desc, adapter->portnum); |
| 2158 | |
| 2159 | for (i = 0; i < frag_count; i++) { |
| 2160 | |
| 2161 | k = i % 4; |
| 2162 | |
| 2163 | if ((k == 0) && (i > 0)) { |
| 2164 | /* move to next desc.*/ |
| 2165 | producer = get_next_index(producer, num_txd); |
| 2166 | hwdesc = &tx_ring->desc_head[producer]; |
| 2167 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 2168 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 2169 | } |
| 2170 | |
| 2171 | buffrag = &pbuf->frag_array[i]; |
| 2172 | |
| 2173 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); |
| 2174 | switch (k) { |
| 2175 | case 0: |
| 2176 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 2177 | break; |
| 2178 | case 1: |
| 2179 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); |
| 2180 | break; |
| 2181 | case 2: |
| 2182 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); |
| 2183 | break; |
| 2184 | case 3: |
| 2185 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); |
| 2186 | break; |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | tx_ring->producer = get_next_index(producer, num_txd); |
| 2191 | |
| 2192 | qlcnic_tso_check(netdev, tx_ring, first_desc, skb); |
| 2193 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 2194 | if (qlcnic_mac_learn) |
| 2195 | qlcnic_send_filter(adapter, tx_ring, first_desc, skb); |
| 2196 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2197 | qlcnic_update_cmd_producer(adapter, tx_ring); |
| 2198 | |
| 2199 | adapter->stats.txbytes += skb->len; |
| 2200 | adapter->stats.xmitcalled++; |
| 2201 | |
| 2202 | return NETDEV_TX_OK; |
| 2203 | |
| 2204 | drop_packet: |
| 2205 | adapter->stats.txdropped++; |
| 2206 | dev_kfree_skb_any(skb); |
| 2207 | return NETDEV_TX_OK; |
| 2208 | } |
| 2209 | |
| 2210 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) |
| 2211 | { |
| 2212 | struct net_device *netdev = adapter->netdev; |
| 2213 | u32 temp, temp_state, temp_val; |
| 2214 | int rv = 0; |
| 2215 | |
| 2216 | temp = QLCRD32(adapter, CRB_TEMP_STATE); |
| 2217 | |
| 2218 | temp_state = qlcnic_get_temp_state(temp); |
| 2219 | temp_val = qlcnic_get_temp_val(temp); |
| 2220 | |
| 2221 | if (temp_state == QLCNIC_TEMP_PANIC) { |
| 2222 | dev_err(&netdev->dev, |
| 2223 | "Device temperature %d degrees C exceeds" |
| 2224 | " maximum allowed. Hardware has been shut down.\n", |
| 2225 | temp_val); |
| 2226 | rv = 1; |
| 2227 | } else if (temp_state == QLCNIC_TEMP_WARN) { |
| 2228 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { |
| 2229 | dev_err(&netdev->dev, |
| 2230 | "Device temperature %d degrees C " |
| 2231 | "exceeds operating range." |
| 2232 | " Immediate action needed.\n", |
| 2233 | temp_val); |
| 2234 | } |
| 2235 | } else { |
| 2236 | if (adapter->temp == QLCNIC_TEMP_WARN) { |
| 2237 | dev_info(&netdev->dev, |
| 2238 | "Device temperature is now %d degrees C" |
| 2239 | " in normal range.\n", temp_val); |
| 2240 | } |
| 2241 | } |
| 2242 | adapter->temp = temp_state; |
| 2243 | return rv; |
| 2244 | } |
| 2245 | |
| 2246 | void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) |
| 2247 | { |
| 2248 | struct net_device *netdev = adapter->netdev; |
| 2249 | |
| 2250 | if (adapter->ahw.linkup && !linkup) { |
Sony Chacko | 6932427 | 2010-08-17 00:34:23 +0000 | [diff] [blame] | 2251 | netdev_info(netdev, "NIC Link is down\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2252 | adapter->ahw.linkup = 0; |
| 2253 | if (netif_running(netdev)) { |
| 2254 | netif_carrier_off(netdev); |
| 2255 | netif_stop_queue(netdev); |
| 2256 | } |
| 2257 | } else if (!adapter->ahw.linkup && linkup) { |
Sony Chacko | 6932427 | 2010-08-17 00:34:23 +0000 | [diff] [blame] | 2258 | netdev_info(netdev, "NIC Link is up\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2259 | adapter->ahw.linkup = 1; |
| 2260 | if (netif_running(netdev)) { |
| 2261 | netif_carrier_on(netdev); |
| 2262 | netif_wake_queue(netdev); |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | static void qlcnic_tx_timeout(struct net_device *netdev) |
| 2268 | { |
| 2269 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2270 | |
| 2271 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2272 | return; |
| 2273 | |
| 2274 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2275 | |
| 2276 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 2277 | adapter->need_fw_reset = 1; |
| 2278 | else |
| 2279 | adapter->reset_context = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) |
| 2283 | { |
| 2284 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2285 | struct net_device_stats *stats = &netdev->stats; |
| 2286 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2287 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
| 2288 | stats->tx_packets = adapter->stats.xmitfinished; |
Sucheta Chakraborty | 7e38259 | 2010-05-17 01:22:10 +0000 | [diff] [blame] | 2289 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2290 | stats->tx_bytes = adapter->stats.txbytes; |
| 2291 | stats->rx_dropped = adapter->stats.rxdropped; |
| 2292 | stats->tx_dropped = adapter->stats.txdropped; |
| 2293 | |
| 2294 | return stats; |
| 2295 | } |
| 2296 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 2297 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2298 | { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2299 | u32 status; |
| 2300 | |
| 2301 | status = readl(adapter->isr_int_vec); |
| 2302 | |
| 2303 | if (!(status & adapter->int_vec_bit)) |
| 2304 | return IRQ_NONE; |
| 2305 | |
| 2306 | /* check interrupt state machine, to be sure */ |
| 2307 | status = readl(adapter->crb_int_state_reg); |
| 2308 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 2309 | return IRQ_NONE; |
| 2310 | |
| 2311 | writel(0xffffffff, adapter->tgt_status_reg); |
| 2312 | /* read twice to ensure write is flushed */ |
| 2313 | readl(adapter->isr_int_vec); |
| 2314 | readl(adapter->isr_int_vec); |
| 2315 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 2316 | return IRQ_HANDLED; |
| 2317 | } |
| 2318 | |
| 2319 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) |
| 2320 | { |
| 2321 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 2322 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2323 | |
| 2324 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 2325 | goto done; |
| 2326 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { |
| 2327 | writel(0xffffffff, adapter->tgt_status_reg); |
| 2328 | goto done; |
| 2329 | } |
| 2330 | |
| 2331 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 2332 | return IRQ_NONE; |
| 2333 | |
| 2334 | done: |
| 2335 | adapter->diag_cnt++; |
| 2336 | qlcnic_enable_int(sds_ring); |
| 2337 | return IRQ_HANDLED; |
| 2338 | } |
| 2339 | |
| 2340 | static irqreturn_t qlcnic_intr(int irq, void *data) |
| 2341 | { |
| 2342 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 2343 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2344 | |
| 2345 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 2346 | return IRQ_NONE; |
| 2347 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2348 | napi_schedule(&sds_ring->napi); |
| 2349 | |
| 2350 | return IRQ_HANDLED; |
| 2351 | } |
| 2352 | |
| 2353 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) |
| 2354 | { |
| 2355 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 2356 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2357 | |
| 2358 | /* clear interrupt */ |
| 2359 | writel(0xffffffff, adapter->tgt_status_reg); |
| 2360 | |
| 2361 | napi_schedule(&sds_ring->napi); |
| 2362 | return IRQ_HANDLED; |
| 2363 | } |
| 2364 | |
| 2365 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) |
| 2366 | { |
| 2367 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 2368 | |
| 2369 | napi_schedule(&sds_ring->napi); |
| 2370 | return IRQ_HANDLED; |
| 2371 | } |
| 2372 | |
| 2373 | static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) |
| 2374 | { |
| 2375 | u32 sw_consumer, hw_consumer; |
| 2376 | int count = 0, i; |
| 2377 | struct qlcnic_cmd_buffer *buffer; |
| 2378 | struct pci_dev *pdev = adapter->pdev; |
| 2379 | struct net_device *netdev = adapter->netdev; |
| 2380 | struct qlcnic_skb_frag *frag; |
| 2381 | int done; |
| 2382 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 2383 | |
| 2384 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 2385 | return 1; |
| 2386 | |
| 2387 | sw_consumer = tx_ring->sw_consumer; |
| 2388 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 2389 | |
| 2390 | while (sw_consumer != hw_consumer) { |
| 2391 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
| 2392 | if (buffer->skb) { |
| 2393 | frag = &buffer->frag_array[0]; |
| 2394 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 2395 | PCI_DMA_TODEVICE); |
| 2396 | frag->dma = 0ULL; |
| 2397 | for (i = 1; i < buffer->frag_count; i++) { |
| 2398 | frag++; |
| 2399 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 2400 | PCI_DMA_TODEVICE); |
| 2401 | frag->dma = 0ULL; |
| 2402 | } |
| 2403 | |
| 2404 | adapter->stats.xmitfinished++; |
| 2405 | dev_kfree_skb_any(buffer->skb); |
| 2406 | buffer->skb = NULL; |
| 2407 | } |
| 2408 | |
| 2409 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
| 2410 | if (++count >= MAX_STATUS_HANDLE) |
| 2411 | break; |
| 2412 | } |
| 2413 | |
| 2414 | if (count && netif_running(netdev)) { |
| 2415 | tx_ring->sw_consumer = sw_consumer; |
| 2416 | |
| 2417 | smp_mb(); |
| 2418 | |
| 2419 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2420 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { |
| 2421 | netif_wake_queue(netdev); |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 2422 | adapter->stats.xmit_on++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2423 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2424 | } |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 2425 | adapter->tx_timeo_cnt = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2426 | } |
| 2427 | /* |
| 2428 | * If everything is freed up to consumer then check if the ring is full |
| 2429 | * If the ring is full then check if more needs to be freed and |
| 2430 | * schedule the call back again. |
| 2431 | * |
| 2432 | * This happens when there are 2 CPUs. One could be freeing and the |
| 2433 | * other filling it. If the ring is full when we get out of here and |
| 2434 | * the card has already interrupted the host then the host can miss the |
| 2435 | * interrupt. |
| 2436 | * |
| 2437 | * There is still a possible race condition and the host could miss an |
| 2438 | * interrupt. The card has to take care of this. |
| 2439 | */ |
| 2440 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 2441 | done = (sw_consumer == hw_consumer); |
| 2442 | spin_unlock(&adapter->tx_clean_lock); |
| 2443 | |
| 2444 | return done; |
| 2445 | } |
| 2446 | |
| 2447 | static int qlcnic_poll(struct napi_struct *napi, int budget) |
| 2448 | { |
| 2449 | struct qlcnic_host_sds_ring *sds_ring = |
| 2450 | container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 2451 | |
| 2452 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2453 | |
| 2454 | int tx_complete; |
| 2455 | int work_done; |
| 2456 | |
| 2457 | tx_complete = qlcnic_process_cmd_ring(adapter); |
| 2458 | |
| 2459 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
| 2460 | |
| 2461 | if ((work_done < budget) && tx_complete) { |
| 2462 | napi_complete(&sds_ring->napi); |
| 2463 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 2464 | qlcnic_enable_int(sds_ring); |
| 2465 | } |
| 2466 | |
| 2467 | return work_done; |
| 2468 | } |
| 2469 | |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 2470 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget) |
| 2471 | { |
| 2472 | struct qlcnic_host_sds_ring *sds_ring = |
| 2473 | container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 2474 | |
| 2475 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2476 | int work_done; |
| 2477 | |
| 2478 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
| 2479 | |
| 2480 | if (work_done < budget) { |
| 2481 | napi_complete(&sds_ring->napi); |
| 2482 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 2483 | qlcnic_enable_int(sds_ring); |
| 2484 | } |
| 2485 | |
| 2486 | return work_done; |
| 2487 | } |
| 2488 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2489 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2490 | static void qlcnic_poll_controller(struct net_device *netdev) |
| 2491 | { |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 2492 | int ring; |
| 2493 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2494 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 2495 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 2496 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2497 | disable_irq(adapter->irq); |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 2498 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 2499 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 2500 | qlcnic_intr(adapter->irq, sds_ring); |
| 2501 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2502 | enable_irq(adapter->irq); |
| 2503 | } |
| 2504 | #endif |
| 2505 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2506 | static void |
| 2507 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) |
| 2508 | { |
| 2509 | u32 val; |
| 2510 | |
| 2511 | val = adapter->portnum & 0xf; |
| 2512 | val |= encoding << 7; |
| 2513 | val |= (jiffies - adapter->dev_rst_time) << 8; |
| 2514 | |
| 2515 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); |
| 2516 | adapter->dev_rst_time = jiffies; |
| 2517 | } |
| 2518 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2519 | static int |
| 2520 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2521 | { |
| 2522 | u32 val; |
| 2523 | |
| 2524 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && |
| 2525 | state != QLCNIC_DEV_NEED_QUISCENT); |
| 2526 | |
| 2527 | if (qlcnic_api_lock(adapter)) |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2528 | return -EIO; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2529 | |
| 2530 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2531 | |
| 2532 | if (state == QLCNIC_DEV_NEED_RESET) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2533 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2534 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2535 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2536 | |
| 2537 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2538 | |
| 2539 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2540 | |
| 2541 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2544 | static int |
| 2545 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) |
| 2546 | { |
| 2547 | u32 val; |
| 2548 | |
| 2549 | if (qlcnic_api_lock(adapter)) |
| 2550 | return -EBUSY; |
| 2551 | |
| 2552 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2553 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2554 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2555 | |
| 2556 | qlcnic_api_unlock(adapter); |
| 2557 | |
| 2558 | return 0; |
| 2559 | } |
| 2560 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2561 | static void |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2562 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2563 | { |
| 2564 | u32 val; |
| 2565 | |
| 2566 | if (qlcnic_api_lock(adapter)) |
| 2567 | goto err; |
| 2568 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2569 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2570 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2571 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2572 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2573 | if (failed) { |
| 2574 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 2575 | dev_info(&adapter->pdev->dev, |
| 2576 | "Device state set to Failed. Please Reboot\n"); |
| 2577 | } else if (!(val & 0x11111111)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2578 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); |
| 2579 | |
| 2580 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2581 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2582 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2583 | |
| 2584 | qlcnic_api_unlock(adapter); |
| 2585 | err: |
| 2586 | adapter->fw_fail_cnt = 0; |
| 2587 | clear_bit(__QLCNIC_START_FW, &adapter->state); |
| 2588 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2589 | } |
| 2590 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2591 | /* Grab api lock, before checking state */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2592 | static int |
| 2593 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) |
| 2594 | { |
| 2595 | int act, state; |
| 2596 | |
| 2597 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2598 | act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2599 | |
| 2600 | if (((state & 0x11111111) == (act & 0x11111111)) || |
| 2601 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) |
| 2602 | return 0; |
| 2603 | else |
| 2604 | return 1; |
| 2605 | } |
| 2606 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2607 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
| 2608 | { |
| 2609 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); |
| 2610 | |
| 2611 | if (val != QLCNIC_DRV_IDC_VER) { |
| 2612 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" |
| 2613 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); |
| 2614 | } |
| 2615 | |
| 2616 | return 0; |
| 2617 | } |
| 2618 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2619 | static int |
| 2620 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) |
| 2621 | { |
| 2622 | u32 val, prev_state; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2623 | u8 dev_init_timeo = adapter->dev_init_timeo; |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2624 | u8 portnum = adapter->portnum; |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2625 | u8 ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2626 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2627 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
| 2628 | return 1; |
| 2629 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2630 | if (qlcnic_api_lock(adapter)) |
| 2631 | return -1; |
| 2632 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2633 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2634 | if (!(val & (1 << (portnum * 4)))) { |
| 2635 | QLC_DEV_SET_REF_CNT(val, portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2636 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2640 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2641 | |
| 2642 | switch (prev_state) { |
| 2643 | case QLCNIC_DEV_COLD: |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2644 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2645 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2646 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2647 | qlcnic_api_unlock(adapter); |
| 2648 | return 1; |
| 2649 | |
| 2650 | case QLCNIC_DEV_READY: |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2651 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2652 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2653 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2654 | |
| 2655 | case QLCNIC_DEV_NEED_RESET: |
| 2656 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2657 | QLC_DEV_SET_RST_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2658 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2659 | break; |
| 2660 | |
| 2661 | case QLCNIC_DEV_NEED_QUISCENT: |
| 2662 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2663 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2664 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2665 | break; |
| 2666 | |
| 2667 | case QLCNIC_DEV_FAILED: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 2668 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2669 | qlcnic_api_unlock(adapter); |
| 2670 | return -1; |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2671 | |
| 2672 | case QLCNIC_DEV_INITIALIZING: |
| 2673 | case QLCNIC_DEV_QUISCENT: |
| 2674 | break; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2678 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2679 | do { |
| 2680 | msleep(1000); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2681 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2682 | |
| 2683 | if (prev_state == QLCNIC_DEV_QUISCENT) |
| 2684 | continue; |
| 2685 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2686 | |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2687 | if (!dev_init_timeo) { |
| 2688 | dev_err(&adapter->pdev->dev, |
| 2689 | "Waiting for device to initialize timeout\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2690 | return -1; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2691 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2692 | |
| 2693 | if (qlcnic_api_lock(adapter)) |
| 2694 | return -1; |
| 2695 | |
| 2696 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2697 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2698 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2699 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2700 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2701 | qlcnic_api_unlock(adapter); |
| 2702 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2703 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | static void |
| 2707 | qlcnic_fwinit_work(struct work_struct *work) |
| 2708 | { |
| 2709 | struct qlcnic_adapter *adapter = container_of(work, |
| 2710 | struct qlcnic_adapter, fw_work.work); |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2711 | u32 dev_state = 0xf; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2712 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2713 | if (qlcnic_api_lock(adapter)) |
| 2714 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2715 | |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2716 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2717 | if (dev_state == QLCNIC_DEV_QUISCENT || |
| 2718 | dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2719 | qlcnic_api_unlock(adapter); |
| 2720 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2721 | FW_POLL_DELAY * 2); |
| 2722 | return; |
| 2723 | } |
| 2724 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2725 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2726 | qlcnic_api_unlock(adapter); |
| 2727 | goto wait_npar; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2730 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
| 2731 | dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", |
| 2732 | adapter->reset_ack_timeo); |
| 2733 | goto skip_ack_check; |
| 2734 | } |
| 2735 | |
| 2736 | if (!qlcnic_check_drv_state(adapter)) { |
| 2737 | skip_ack_check: |
| 2738 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2739 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2740 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
| 2741 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2742 | QLCNIC_DEV_INITIALIZING); |
| 2743 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2744 | QLCDB(adapter, DRV, "Restarting fw\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2745 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2746 | } |
| 2747 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2748 | qlcnic_api_unlock(adapter); |
| 2749 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2750 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2751 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2752 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2753 | return; |
| 2754 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2755 | goto err_ret; |
| 2756 | } |
| 2757 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2758 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2759 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2760 | wait_npar: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2761 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2762 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2763 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2764 | switch (dev_state) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2765 | case QLCNIC_DEV_READY: |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2766 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2767 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2768 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2769 | return; |
| 2770 | } |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2771 | case QLCNIC_DEV_FAILED: |
| 2772 | break; |
| 2773 | default: |
| 2774 | qlcnic_schedule_work(adapter, |
| 2775 | qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2776 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | err_ret: |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2780 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
| 2781 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2782 | netif_device_attach(adapter->netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2783 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | static void |
| 2787 | qlcnic_detach_work(struct work_struct *work) |
| 2788 | { |
| 2789 | struct qlcnic_adapter *adapter = container_of(work, |
| 2790 | struct qlcnic_adapter, fw_work.work); |
| 2791 | struct net_device *netdev = adapter->netdev; |
| 2792 | u32 status; |
| 2793 | |
| 2794 | netif_device_detach(netdev); |
| 2795 | |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2796 | /* Dont grab rtnl lock during Quiscent mode */ |
| 2797 | if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
| 2798 | if (netif_running(netdev)) |
| 2799 | __qlcnic_down(adapter, netdev); |
| 2800 | } else |
| 2801 | qlcnic_down(adapter, netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2802 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2803 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
| 2804 | |
| 2805 | if (status & QLCNIC_RCODE_FATAL_ERROR) |
| 2806 | goto err_ret; |
| 2807 | |
| 2808 | if (adapter->temp == QLCNIC_TEMP_PANIC) |
| 2809 | goto err_ret; |
| 2810 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2811 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) |
| 2812 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2813 | |
| 2814 | adapter->fw_wait_cnt = 0; |
| 2815 | |
| 2816 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2817 | |
| 2818 | return; |
| 2819 | |
| 2820 | err_ret: |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2821 | dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n", |
| 2822 | status, adapter->temp); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2823 | netif_device_attach(netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2824 | qlcnic_clr_all_drv_state(adapter, 1); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2827 | /*Transit NPAR state to NON Operational */ |
| 2828 | static void |
| 2829 | qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) |
| 2830 | { |
| 2831 | u32 state; |
| 2832 | |
| 2833 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2834 | if (state == QLCNIC_DEV_NPAR_NON_OPER) |
| 2835 | return; |
| 2836 | |
| 2837 | if (qlcnic_api_lock(adapter)) |
| 2838 | return; |
| 2839 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
| 2840 | qlcnic_api_unlock(adapter); |
| 2841 | } |
| 2842 | |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2843 | /* Caller should held RESETTING bit. |
| 2844 | * This should be call in sync with qlcnic_request_quiscent_mode. |
| 2845 | */ |
| 2846 | void qlcnic_clear_quiscent_mode(struct qlcnic_adapter *adapter) |
| 2847 | { |
| 2848 | qlcnic_clr_drv_state(adapter); |
| 2849 | qlcnic_api_lock(adapter); |
| 2850 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); |
| 2851 | qlcnic_api_unlock(adapter); |
| 2852 | } |
| 2853 | |
| 2854 | /* Caller should held RESETTING bit. |
| 2855 | */ |
| 2856 | int qlcnic_request_quiscent_mode(struct qlcnic_adapter *adapter) |
| 2857 | { |
| 2858 | u8 timeo = adapter->dev_init_timeo / 2; |
| 2859 | u32 state; |
| 2860 | |
| 2861 | if (qlcnic_api_lock(adapter)) |
| 2862 | return -EIO; |
| 2863 | |
| 2864 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2865 | if (state != QLCNIC_DEV_READY) |
| 2866 | return -EIO; |
| 2867 | |
| 2868 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_QUISCENT); |
| 2869 | qlcnic_api_unlock(adapter); |
| 2870 | QLCDB(adapter, DRV, "NEED QUISCENT state set\n"); |
| 2871 | qlcnic_idc_debug_info(adapter, 0); |
| 2872 | |
| 2873 | qlcnic_set_drv_state(adapter, QLCNIC_DEV_NEED_QUISCENT); |
| 2874 | |
| 2875 | do { |
| 2876 | msleep(2000); |
| 2877 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2878 | if (state == QLCNIC_DEV_QUISCENT) |
| 2879 | return 0; |
| 2880 | if (!qlcnic_check_drv_state(adapter)) { |
| 2881 | if (qlcnic_api_lock(adapter)) |
| 2882 | return -EIO; |
| 2883 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2884 | QLCNIC_DEV_QUISCENT); |
| 2885 | qlcnic_api_unlock(adapter); |
| 2886 | QLCDB(adapter, DRV, "QUISCENT mode set\n"); |
| 2887 | return 0; |
| 2888 | } |
| 2889 | } while (--timeo); |
| 2890 | |
| 2891 | dev_err(&adapter->pdev->dev, "Failed to quiesce device, DRV_STATE=%08x" |
| 2892 | " DRV_ACTIVE=%08x\n", QLCRD32(adapter, QLCNIC_CRB_DRV_STATE), |
| 2893 | QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE)); |
| 2894 | qlcnic_clear_quiscent_mode(adapter); |
| 2895 | return -EIO; |
| 2896 | } |
| 2897 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2898 | /*Transit to RESET state from READY state only */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2899 | static void |
| 2900 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) |
| 2901 | { |
| 2902 | u32 state; |
| 2903 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 2904 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2905 | if (qlcnic_api_lock(adapter)) |
| 2906 | return; |
| 2907 | |
| 2908 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2909 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2910 | if (state == QLCNIC_DEV_READY) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2911 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2912 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2913 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2916 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2917 | qlcnic_api_unlock(adapter); |
| 2918 | } |
| 2919 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2920 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
| 2921 | static void |
| 2922 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) |
| 2923 | { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2924 | if (qlcnic_api_lock(adapter)) |
| 2925 | return; |
| 2926 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2927 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); |
| 2928 | QLCDB(adapter, DRV, "NPAR operational state set\n"); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2929 | |
| 2930 | qlcnic_api_unlock(adapter); |
| 2931 | } |
| 2932 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2933 | static void |
| 2934 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 2935 | work_func_t func, int delay) |
| 2936 | { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2937 | if (test_bit(__QLCNIC_AER, &adapter->state)) |
| 2938 | return; |
| 2939 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2940 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2941 | queue_delayed_work(qlcnic_wq, &adapter->fw_work, |
| 2942 | round_jiffies_relative(delay)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | static void |
| 2946 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) |
| 2947 | { |
| 2948 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2949 | msleep(10); |
| 2950 | |
| 2951 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2952 | } |
| 2953 | |
| 2954 | static void |
| 2955 | qlcnic_attach_work(struct work_struct *work) |
| 2956 | { |
| 2957 | struct qlcnic_adapter *adapter = container_of(work, |
| 2958 | struct qlcnic_adapter, fw_work.work); |
| 2959 | struct net_device *netdev = adapter->netdev; |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2960 | u32 npar_state; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2961 | |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2962 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) { |
| 2963 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2964 | if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) |
| 2965 | qlcnic_clr_all_drv_state(adapter, 0); |
| 2966 | else if (npar_state != QLCNIC_DEV_NPAR_OPER) |
| 2967 | qlcnic_schedule_work(adapter, qlcnic_attach_work, |
| 2968 | FW_POLL_DELAY); |
| 2969 | else |
| 2970 | goto attach; |
| 2971 | QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); |
| 2972 | return; |
| 2973 | } |
| 2974 | attach: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2975 | if (netif_running(netdev)) { |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 2976 | if (qlcnic_up(adapter, netdev)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2977 | goto done; |
| 2978 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2979 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2982 | done: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2983 | netif_device_attach(netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2984 | adapter->fw_fail_cnt = 0; |
| 2985 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2986 | |
| 2987 | if (!qlcnic_clr_drv_state(adapter)) |
| 2988 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2989 | FW_POLL_DELAY); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | static int |
| 2993 | qlcnic_check_health(struct qlcnic_adapter *adapter) |
| 2994 | { |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 2995 | u32 state = 0, heartbeat; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2996 | struct net_device *netdev = adapter->netdev; |
| 2997 | |
| 2998 | if (qlcnic_check_temp(adapter)) |
| 2999 | goto detach; |
| 3000 | |
Amit Kumar Salecha | 2372a5f | 2010-05-13 03:07:42 +0000 | [diff] [blame] | 3001 | if (adapter->need_fw_reset) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3002 | qlcnic_dev_request_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3003 | |
| 3004 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 3005 | if (state == QLCNIC_DEV_NEED_RESET) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 3006 | qlcnic_set_npar_non_operational(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3007 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 3008 | } else if (state == QLCNIC_DEV_NEED_QUISCENT) |
| 3009 | goto detach; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3010 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 3011 | heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 3012 | if (heartbeat != adapter->heartbeat) { |
| 3013 | adapter->heartbeat = heartbeat; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3014 | adapter->fw_fail_cnt = 0; |
| 3015 | if (adapter->need_fw_reset) |
| 3016 | goto detach; |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 3017 | |
Amit Kumar Salecha | 0df170b | 2010-07-13 20:33:32 +0000 | [diff] [blame] | 3018 | if (adapter->reset_context && |
| 3019 | auto_fw_reset == AUTO_FW_RESET_ENABLED) { |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 3020 | qlcnic_reset_hw_context(adapter); |
| 3021 | adapter->netdev->trans_start = jiffies; |
| 3022 | } |
| 3023 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3024 | return 0; |
| 3025 | } |
| 3026 | |
| 3027 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) |
| 3028 | return 0; |
| 3029 | |
| 3030 | qlcnic_dev_request_reset(adapter); |
| 3031 | |
Amit Kumar Salecha | 0df170b | 2010-07-13 20:33:32 +0000 | [diff] [blame] | 3032 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED)) |
| 3033 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3034 | |
| 3035 | dev_info(&netdev->dev, "firmware hang detected\n"); |
| 3036 | |
| 3037 | detach: |
| 3038 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : |
| 3039 | QLCNIC_DEV_NEED_RESET; |
| 3040 | |
| 3041 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 3042 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
| 3043 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3044 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 3045 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
| 3046 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3047 | |
| 3048 | return 1; |
| 3049 | } |
| 3050 | |
| 3051 | static void |
| 3052 | qlcnic_fw_poll_work(struct work_struct *work) |
| 3053 | { |
| 3054 | struct qlcnic_adapter *adapter = container_of(work, |
| 3055 | struct qlcnic_adapter, fw_work.work); |
| 3056 | |
| 3057 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 3058 | goto reschedule; |
| 3059 | |
| 3060 | |
| 3061 | if (qlcnic_check_health(adapter)) |
| 3062 | return; |
| 3063 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 3064 | if (adapter->fhash.fnum) |
| 3065 | qlcnic_prune_lb_filters(adapter); |
| 3066 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3067 | reschedule: |
| 3068 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 3069 | } |
| 3070 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3071 | static int qlcnic_is_first_func(struct pci_dev *pdev) |
| 3072 | { |
| 3073 | struct pci_dev *oth_pdev; |
| 3074 | int val = pdev->devfn; |
| 3075 | |
| 3076 | while (val-- > 0) { |
| 3077 | oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr |
| 3078 | (pdev->bus), pdev->bus->number, |
| 3079 | PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 3080 | if (!oth_pdev) |
| 3081 | continue; |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3082 | |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 3083 | if (oth_pdev->current_state != PCI_D3cold) { |
| 3084 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3085 | return 0; |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 3086 | } |
| 3087 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3088 | } |
| 3089 | return 1; |
| 3090 | } |
| 3091 | |
| 3092 | static int qlcnic_attach_func(struct pci_dev *pdev) |
| 3093 | { |
| 3094 | int err, first_func; |
| 3095 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 3096 | struct net_device *netdev = adapter->netdev; |
| 3097 | |
| 3098 | pdev->error_state = pci_channel_io_normal; |
| 3099 | |
| 3100 | err = pci_enable_device(pdev); |
| 3101 | if (err) |
| 3102 | return err; |
| 3103 | |
| 3104 | pci_set_power_state(pdev, PCI_D0); |
| 3105 | pci_set_master(pdev); |
| 3106 | pci_restore_state(pdev); |
| 3107 | |
| 3108 | first_func = qlcnic_is_first_func(pdev); |
| 3109 | |
| 3110 | if (qlcnic_api_lock(adapter)) |
| 3111 | return -EINVAL; |
| 3112 | |
Amit Kumar Salecha | 933fce12 | 2010-08-17 00:34:19 +0000 | [diff] [blame] | 3113 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3114 | adapter->need_fw_reset = 1; |
| 3115 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 3116 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
| 3117 | QLCDB(adapter, DRV, "Restarting fw\n"); |
| 3118 | } |
| 3119 | qlcnic_api_unlock(adapter); |
| 3120 | |
| 3121 | err = adapter->nic_ops->start_firmware(adapter); |
| 3122 | if (err) |
| 3123 | return err; |
| 3124 | |
| 3125 | qlcnic_clr_drv_state(adapter); |
| 3126 | qlcnic_setup_intr(adapter); |
| 3127 | |
| 3128 | if (netif_running(netdev)) { |
| 3129 | err = qlcnic_attach(adapter); |
| 3130 | if (err) { |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 3131 | qlcnic_clr_all_drv_state(adapter, 1); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3132 | clear_bit(__QLCNIC_AER, &adapter->state); |
| 3133 | netif_device_attach(netdev); |
| 3134 | return err; |
| 3135 | } |
| 3136 | |
| 3137 | err = qlcnic_up(adapter, netdev); |
| 3138 | if (err) |
| 3139 | goto done; |
| 3140 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 3141 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 3142 | } |
| 3143 | done: |
| 3144 | netif_device_attach(netdev); |
| 3145 | return err; |
| 3146 | } |
| 3147 | |
| 3148 | static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, |
| 3149 | pci_channel_state_t state) |
| 3150 | { |
| 3151 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 3152 | struct net_device *netdev = adapter->netdev; |
| 3153 | |
| 3154 | if (state == pci_channel_io_perm_failure) |
| 3155 | return PCI_ERS_RESULT_DISCONNECT; |
| 3156 | |
| 3157 | if (state == pci_channel_io_normal) |
| 3158 | return PCI_ERS_RESULT_RECOVERED; |
| 3159 | |
| 3160 | set_bit(__QLCNIC_AER, &adapter->state); |
| 3161 | netif_device_detach(netdev); |
| 3162 | |
| 3163 | cancel_delayed_work_sync(&adapter->fw_work); |
| 3164 | |
| 3165 | if (netif_running(netdev)) |
| 3166 | qlcnic_down(adapter, netdev); |
| 3167 | |
| 3168 | qlcnic_detach(adapter); |
| 3169 | qlcnic_teardown_intr(adapter); |
| 3170 | |
| 3171 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 3172 | |
| 3173 | pci_save_state(pdev); |
| 3174 | pci_disable_device(pdev); |
| 3175 | |
| 3176 | return PCI_ERS_RESULT_NEED_RESET; |
| 3177 | } |
| 3178 | |
| 3179 | static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) |
| 3180 | { |
| 3181 | return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : |
| 3182 | PCI_ERS_RESULT_RECOVERED; |
| 3183 | } |
| 3184 | |
| 3185 | static void qlcnic_io_resume(struct pci_dev *pdev) |
| 3186 | { |
| 3187 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 3188 | |
| 3189 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 3190 | |
| 3191 | if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && |
| 3192 | test_and_clear_bit(__QLCNIC_AER, &adapter->state)) |
| 3193 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 3194 | FW_POLL_DELAY); |
| 3195 | } |
| 3196 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 3197 | static int |
| 3198 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) |
| 3199 | { |
| 3200 | int err; |
| 3201 | |
| 3202 | err = qlcnic_can_start_firmware(adapter); |
| 3203 | if (err) |
| 3204 | return err; |
| 3205 | |
Amit Kumar Salecha | 78f84e1 | 2010-08-19 05:08:28 +0000 | [diff] [blame] | 3206 | err = qlcnic_check_npar_opertional(adapter); |
| 3207 | if (err) |
| 3208 | return err; |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 3209 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 3210 | err = qlcnic_initialize_nic(adapter); |
| 3211 | if (err) |
| 3212 | return err; |
| 3213 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 3214 | qlcnic_check_options(adapter); |
| 3215 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 3216 | err = qlcnic_set_eswitch_port_config(adapter); |
| 3217 | if (err) |
| 3218 | return err; |
| 3219 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 3220 | adapter->need_fw_reset = 0; |
| 3221 | |
| 3222 | return err; |
| 3223 | } |
| 3224 | |
| 3225 | static int |
| 3226 | qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) |
| 3227 | { |
| 3228 | return -EOPNOTSUPP; |
| 3229 | } |
| 3230 | |
| 3231 | static int |
| 3232 | qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) |
| 3233 | { |
| 3234 | return -EOPNOTSUPP; |
| 3235 | } |
| 3236 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3237 | static ssize_t |
| 3238 | qlcnic_store_bridged_mode(struct device *dev, |
| 3239 | struct device_attribute *attr, const char *buf, size_t len) |
| 3240 | { |
| 3241 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3242 | unsigned long new; |
| 3243 | int ret = -EINVAL; |
| 3244 | |
| 3245 | if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) |
| 3246 | goto err_out; |
| 3247 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 3248 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3249 | goto err_out; |
| 3250 | |
| 3251 | if (strict_strtoul(buf, 2, &new)) |
| 3252 | goto err_out; |
| 3253 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 3254 | if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3255 | ret = len; |
| 3256 | |
| 3257 | err_out: |
| 3258 | return ret; |
| 3259 | } |
| 3260 | |
| 3261 | static ssize_t |
| 3262 | qlcnic_show_bridged_mode(struct device *dev, |
| 3263 | struct device_attribute *attr, char *buf) |
| 3264 | { |
| 3265 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3266 | int bridged_mode = 0; |
| 3267 | |
| 3268 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 3269 | bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); |
| 3270 | |
| 3271 | return sprintf(buf, "%d\n", bridged_mode); |
| 3272 | } |
| 3273 | |
| 3274 | static struct device_attribute dev_attr_bridged_mode = { |
| 3275 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 3276 | .show = qlcnic_show_bridged_mode, |
| 3277 | .store = qlcnic_store_bridged_mode, |
| 3278 | }; |
| 3279 | |
| 3280 | static ssize_t |
| 3281 | qlcnic_store_diag_mode(struct device *dev, |
| 3282 | struct device_attribute *attr, const char *buf, size_t len) |
| 3283 | { |
| 3284 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3285 | unsigned long new; |
| 3286 | |
| 3287 | if (strict_strtoul(buf, 2, &new)) |
| 3288 | return -EINVAL; |
| 3289 | |
| 3290 | if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 3291 | adapter->flags ^= QLCNIC_DIAG_ENABLED; |
| 3292 | |
| 3293 | return len; |
| 3294 | } |
| 3295 | |
| 3296 | static ssize_t |
| 3297 | qlcnic_show_diag_mode(struct device *dev, |
| 3298 | struct device_attribute *attr, char *buf) |
| 3299 | { |
| 3300 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3301 | |
| 3302 | return sprintf(buf, "%d\n", |
| 3303 | !!(adapter->flags & QLCNIC_DIAG_ENABLED)); |
| 3304 | } |
| 3305 | |
| 3306 | static struct device_attribute dev_attr_diag_mode = { |
| 3307 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 3308 | .show = qlcnic_show_diag_mode, |
| 3309 | .store = qlcnic_store_diag_mode, |
| 3310 | }; |
| 3311 | |
| 3312 | static int |
| 3313 | qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, |
| 3314 | loff_t offset, size_t size) |
| 3315 | { |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3316 | size_t crb_size = 4; |
| 3317 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3318 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 3319 | return -EIO; |
| 3320 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3321 | if (offset < QLCNIC_PCI_CRBSPACE) { |
| 3322 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, |
| 3323 | QLCNIC_PCI_CAMQM_END)) |
| 3324 | crb_size = 8; |
| 3325 | else |
| 3326 | return -EINVAL; |
| 3327 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3328 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3329 | if ((size != crb_size) || (offset & (crb_size-1))) |
| 3330 | return -EINVAL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3331 | |
| 3332 | return 0; |
| 3333 | } |
| 3334 | |
| 3335 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3336 | qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, |
| 3337 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3338 | char *buf, loff_t offset, size_t size) |
| 3339 | { |
| 3340 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3341 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3342 | u32 data; |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3343 | u64 qmdata; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3344 | int ret; |
| 3345 | |
| 3346 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 3347 | if (ret != 0) |
| 3348 | return ret; |
| 3349 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3350 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
| 3351 | qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); |
| 3352 | memcpy(buf, &qmdata, size); |
| 3353 | } else { |
| 3354 | data = QLCRD32(adapter, offset); |
| 3355 | memcpy(buf, &data, size); |
| 3356 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3357 | return size; |
| 3358 | } |
| 3359 | |
| 3360 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3361 | qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, |
| 3362 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3363 | char *buf, loff_t offset, size_t size) |
| 3364 | { |
| 3365 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3366 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3367 | u32 data; |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3368 | u64 qmdata; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3369 | int ret; |
| 3370 | |
| 3371 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 3372 | if (ret != 0) |
| 3373 | return ret; |
| 3374 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 3375 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
| 3376 | memcpy(&qmdata, buf, size); |
| 3377 | qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); |
| 3378 | } else { |
| 3379 | memcpy(&data, buf, size); |
| 3380 | QLCWR32(adapter, offset, data); |
| 3381 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3382 | return size; |
| 3383 | } |
| 3384 | |
| 3385 | static int |
| 3386 | qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, |
| 3387 | loff_t offset, size_t size) |
| 3388 | { |
| 3389 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 3390 | return -EIO; |
| 3391 | |
| 3392 | if ((size != 8) || (offset & 0x7)) |
| 3393 | return -EIO; |
| 3394 | |
| 3395 | return 0; |
| 3396 | } |
| 3397 | |
| 3398 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3399 | qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, |
| 3400 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3401 | char *buf, loff_t offset, size_t size) |
| 3402 | { |
| 3403 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3404 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3405 | u64 data; |
| 3406 | int ret; |
| 3407 | |
| 3408 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 3409 | if (ret != 0) |
| 3410 | return ret; |
| 3411 | |
| 3412 | if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) |
| 3413 | return -EIO; |
| 3414 | |
| 3415 | memcpy(buf, &data, size); |
| 3416 | |
| 3417 | return size; |
| 3418 | } |
| 3419 | |
| 3420 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 3421 | qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, |
| 3422 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3423 | char *buf, loff_t offset, size_t size) |
| 3424 | { |
| 3425 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3426 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3427 | u64 data; |
| 3428 | int ret; |
| 3429 | |
| 3430 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 3431 | if (ret != 0) |
| 3432 | return ret; |
| 3433 | |
| 3434 | memcpy(&data, buf, size); |
| 3435 | |
| 3436 | if (qlcnic_pci_mem_write_2M(adapter, offset, data)) |
| 3437 | return -EIO; |
| 3438 | |
| 3439 | return size; |
| 3440 | } |
| 3441 | |
| 3442 | |
| 3443 | static struct bin_attribute bin_attr_crb = { |
| 3444 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, |
| 3445 | .size = 0, |
| 3446 | .read = qlcnic_sysfs_read_crb, |
| 3447 | .write = qlcnic_sysfs_write_crb, |
| 3448 | }; |
| 3449 | |
| 3450 | static struct bin_attribute bin_attr_mem = { |
| 3451 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, |
| 3452 | .size = 0, |
| 3453 | .read = qlcnic_sysfs_read_mem, |
| 3454 | .write = qlcnic_sysfs_write_mem, |
| 3455 | }; |
| 3456 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 3457 | static int |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3458 | validate_pm_config(struct qlcnic_adapter *adapter, |
| 3459 | struct qlcnic_pm_func_cfg *pm_cfg, int count) |
| 3460 | { |
| 3461 | |
| 3462 | u8 src_pci_func, s_esw_id, d_esw_id; |
| 3463 | u8 dest_pci_func; |
| 3464 | int i; |
| 3465 | |
| 3466 | for (i = 0; i < count; i++) { |
| 3467 | src_pci_func = pm_cfg[i].pci_func; |
| 3468 | dest_pci_func = pm_cfg[i].dest_npar; |
| 3469 | if (src_pci_func >= QLCNIC_MAX_PCI_FUNC |
| 3470 | || dest_pci_func >= QLCNIC_MAX_PCI_FUNC) |
| 3471 | return QL_STATUS_INVALID_PARAM; |
| 3472 | |
| 3473 | if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC) |
| 3474 | return QL_STATUS_INVALID_PARAM; |
| 3475 | |
| 3476 | if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC) |
| 3477 | return QL_STATUS_INVALID_PARAM; |
| 3478 | |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3479 | s_esw_id = adapter->npars[src_pci_func].phy_port; |
| 3480 | d_esw_id = adapter->npars[dest_pci_func].phy_port; |
| 3481 | |
| 3482 | if (s_esw_id != d_esw_id) |
| 3483 | return QL_STATUS_INVALID_PARAM; |
| 3484 | |
| 3485 | } |
| 3486 | return 0; |
| 3487 | |
| 3488 | } |
| 3489 | |
| 3490 | static ssize_t |
| 3491 | qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj, |
| 3492 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3493 | { |
| 3494 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3495 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3496 | struct qlcnic_pm_func_cfg *pm_cfg; |
| 3497 | u32 id, action, pci_func; |
| 3498 | int count, rem, i, ret; |
| 3499 | |
| 3500 | count = size / sizeof(struct qlcnic_pm_func_cfg); |
| 3501 | rem = size % sizeof(struct qlcnic_pm_func_cfg); |
| 3502 | if (rem) |
| 3503 | return QL_STATUS_INVALID_PARAM; |
| 3504 | |
| 3505 | pm_cfg = (struct qlcnic_pm_func_cfg *) buf; |
| 3506 | |
| 3507 | ret = validate_pm_config(adapter, pm_cfg, count); |
| 3508 | if (ret) |
| 3509 | return ret; |
| 3510 | for (i = 0; i < count; i++) { |
| 3511 | pci_func = pm_cfg[i].pci_func; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3512 | action = !!pm_cfg[i].action; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3513 | id = adapter->npars[pci_func].phy_port; |
| 3514 | ret = qlcnic_config_port_mirroring(adapter, id, |
| 3515 | action, pci_func); |
| 3516 | if (ret) |
| 3517 | return ret; |
| 3518 | } |
| 3519 | |
| 3520 | for (i = 0; i < count; i++) { |
| 3521 | pci_func = pm_cfg[i].pci_func; |
| 3522 | id = adapter->npars[pci_func].phy_port; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3523 | adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3524 | adapter->npars[pci_func].dest_npar = id; |
| 3525 | } |
| 3526 | return size; |
| 3527 | } |
| 3528 | |
| 3529 | static ssize_t |
| 3530 | qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj, |
| 3531 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3532 | { |
| 3533 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3534 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3535 | struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC]; |
| 3536 | int i; |
| 3537 | |
| 3538 | if (size != sizeof(pm_cfg)) |
| 3539 | return QL_STATUS_INVALID_PARAM; |
| 3540 | |
| 3541 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 3542 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) |
| 3543 | continue; |
| 3544 | pm_cfg[i].action = adapter->npars[i].enable_pm; |
| 3545 | pm_cfg[i].dest_npar = 0; |
| 3546 | pm_cfg[i].pci_func = i; |
| 3547 | } |
| 3548 | memcpy(buf, &pm_cfg, size); |
| 3549 | |
| 3550 | return size; |
| 3551 | } |
| 3552 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 3553 | static int |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3554 | validate_esw_config(struct qlcnic_adapter *adapter, |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3555 | struct qlcnic_esw_func_cfg *esw_cfg, int count) |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3556 | { |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 3557 | u32 op_mode; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3558 | u8 pci_func; |
| 3559 | int i; |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 3560 | |
| 3561 | op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE); |
| 3562 | |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3563 | for (i = 0; i < count; i++) { |
| 3564 | pci_func = esw_cfg[i].pci_func; |
| 3565 | if (pci_func >= QLCNIC_MAX_PCI_FUNC) |
| 3566 | return QL_STATUS_INVALID_PARAM; |
| 3567 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3568 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
| 3569 | if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3570 | return QL_STATUS_INVALID_PARAM; |
| 3571 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3572 | switch (esw_cfg[i].op_mode) { |
| 3573 | case QLCNIC_PORT_DEFAULTS: |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 3574 | if (QLC_DEV_GET_DRV(op_mode, pci_func) != |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 3575 | QLCNIC_NON_PRIV_FUNC) { |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 3576 | esw_cfg[i].mac_anti_spoof = 0; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 3577 | esw_cfg[i].mac_override = 1; |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 3578 | esw_cfg[i].promisc_mode = 1; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 3579 | } |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3580 | break; |
| 3581 | case QLCNIC_ADD_VLAN: |
| 3582 | if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) |
| 3583 | return QL_STATUS_INVALID_PARAM; |
| 3584 | if (!esw_cfg[i].op_type) |
| 3585 | return QL_STATUS_INVALID_PARAM; |
| 3586 | break; |
| 3587 | case QLCNIC_DEL_VLAN: |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3588 | if (!esw_cfg[i].op_type) |
| 3589 | return QL_STATUS_INVALID_PARAM; |
| 3590 | break; |
| 3591 | default: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3592 | return QL_STATUS_INVALID_PARAM; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3593 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3594 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3595 | return 0; |
| 3596 | } |
| 3597 | |
| 3598 | static ssize_t |
| 3599 | qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj, |
| 3600 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3601 | { |
| 3602 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3603 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3604 | struct qlcnic_esw_func_cfg *esw_cfg; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3605 | struct qlcnic_npar_info *npar; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3606 | int count, rem, i, ret; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 3607 | u8 pci_func, op_mode = 0; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3608 | |
| 3609 | count = size / sizeof(struct qlcnic_esw_func_cfg); |
| 3610 | rem = size % sizeof(struct qlcnic_esw_func_cfg); |
| 3611 | if (rem) |
| 3612 | return QL_STATUS_INVALID_PARAM; |
| 3613 | |
| 3614 | esw_cfg = (struct qlcnic_esw_func_cfg *) buf; |
| 3615 | ret = validate_esw_config(adapter, esw_cfg, count); |
| 3616 | if (ret) |
| 3617 | return ret; |
| 3618 | |
| 3619 | for (i = 0; i < count; i++) { |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 3620 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
| 3621 | if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) |
| 3622 | return QL_STATUS_INVALID_PARAM; |
Rajesh Borundia | e9a4770 | 2010-08-25 04:03:02 +0000 | [diff] [blame] | 3623 | |
| 3624 | if (adapter->ahw.pci_func != esw_cfg[i].pci_func) |
| 3625 | continue; |
| 3626 | |
| 3627 | op_mode = esw_cfg[i].op_mode; |
| 3628 | qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); |
| 3629 | esw_cfg[i].op_mode = op_mode; |
| 3630 | esw_cfg[i].pci_func = adapter->ahw.pci_func; |
| 3631 | |
| 3632 | switch (esw_cfg[i].op_mode) { |
| 3633 | case QLCNIC_PORT_DEFAULTS: |
| 3634 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]); |
| 3635 | break; |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 3636 | case QLCNIC_ADD_VLAN: |
| 3637 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); |
| 3638 | break; |
| 3639 | case QLCNIC_DEL_VLAN: |
| 3640 | esw_cfg[i].vlan_id = 0; |
| 3641 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); |
| 3642 | break; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 3643 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3644 | } |
| 3645 | |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 3646 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) |
| 3647 | goto out; |
Rajesh Borundia | e9a4770 | 2010-08-25 04:03:02 +0000 | [diff] [blame] | 3648 | |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3649 | for (i = 0; i < count; i++) { |
| 3650 | pci_func = esw_cfg[i].pci_func; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3651 | npar = &adapter->npars[pci_func]; |
| 3652 | switch (esw_cfg[i].op_mode) { |
| 3653 | case QLCNIC_PORT_DEFAULTS: |
| 3654 | npar->promisc_mode = esw_cfg[i].promisc_mode; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 3655 | npar->mac_override = esw_cfg[i].mac_override; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3656 | npar->offload_flags = esw_cfg[i].offload_flags; |
| 3657 | npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof; |
| 3658 | npar->discard_tagged = esw_cfg[i].discard_tagged; |
| 3659 | break; |
| 3660 | case QLCNIC_ADD_VLAN: |
| 3661 | npar->pvid = esw_cfg[i].vlan_id; |
| 3662 | break; |
| 3663 | case QLCNIC_DEL_VLAN: |
| 3664 | npar->pvid = 0; |
| 3665 | break; |
| 3666 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3667 | } |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 3668 | out: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3669 | return size; |
| 3670 | } |
| 3671 | |
| 3672 | static ssize_t |
| 3673 | qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj, |
| 3674 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3675 | { |
| 3676 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3677 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3678 | struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3679 | u8 i; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3680 | |
| 3681 | if (size != sizeof(esw_cfg)) |
| 3682 | return QL_STATUS_INVALID_PARAM; |
| 3683 | |
| 3684 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 3685 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) |
| 3686 | continue; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 3687 | esw_cfg[i].pci_func = i; |
| 3688 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i])) |
| 3689 | return QL_STATUS_INVALID_PARAM; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3690 | } |
| 3691 | memcpy(buf, &esw_cfg, size); |
| 3692 | |
| 3693 | return size; |
| 3694 | } |
| 3695 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 3696 | static int |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3697 | validate_npar_config(struct qlcnic_adapter *adapter, |
| 3698 | struct qlcnic_npar_func_cfg *np_cfg, int count) |
| 3699 | { |
| 3700 | u8 pci_func, i; |
| 3701 | |
| 3702 | for (i = 0; i < count; i++) { |
| 3703 | pci_func = np_cfg[i].pci_func; |
| 3704 | if (pci_func >= QLCNIC_MAX_PCI_FUNC) |
| 3705 | return QL_STATUS_INVALID_PARAM; |
| 3706 | |
| 3707 | if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC) |
| 3708 | return QL_STATUS_INVALID_PARAM; |
| 3709 | |
| 3710 | if (!IS_VALID_BW(np_cfg[i].min_bw) |
| 3711 | || !IS_VALID_BW(np_cfg[i].max_bw) |
| 3712 | || !IS_VALID_RX_QUEUES(np_cfg[i].max_rx_queues) |
| 3713 | || !IS_VALID_TX_QUEUES(np_cfg[i].max_tx_queues)) |
| 3714 | return QL_STATUS_INVALID_PARAM; |
| 3715 | } |
| 3716 | return 0; |
| 3717 | } |
| 3718 | |
| 3719 | static ssize_t |
| 3720 | qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj, |
| 3721 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3722 | { |
| 3723 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3724 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3725 | struct qlcnic_info nic_info; |
| 3726 | struct qlcnic_npar_func_cfg *np_cfg; |
| 3727 | int i, count, rem, ret; |
| 3728 | u8 pci_func; |
| 3729 | |
| 3730 | count = size / sizeof(struct qlcnic_npar_func_cfg); |
| 3731 | rem = size % sizeof(struct qlcnic_npar_func_cfg); |
| 3732 | if (rem) |
| 3733 | return QL_STATUS_INVALID_PARAM; |
| 3734 | |
| 3735 | np_cfg = (struct qlcnic_npar_func_cfg *) buf; |
| 3736 | ret = validate_npar_config(adapter, np_cfg, count); |
| 3737 | if (ret) |
| 3738 | return ret; |
| 3739 | |
| 3740 | for (i = 0; i < count ; i++) { |
| 3741 | pci_func = np_cfg[i].pci_func; |
| 3742 | ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func); |
| 3743 | if (ret) |
| 3744 | return ret; |
| 3745 | nic_info.pci_func = pci_func; |
| 3746 | nic_info.min_tx_bw = np_cfg[i].min_bw; |
| 3747 | nic_info.max_tx_bw = np_cfg[i].max_bw; |
| 3748 | ret = qlcnic_set_nic_info(adapter, &nic_info); |
| 3749 | if (ret) |
| 3750 | return ret; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 3751 | adapter->npars[i].min_bw = nic_info.min_tx_bw; |
| 3752 | adapter->npars[i].max_bw = nic_info.max_tx_bw; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | return size; |
| 3756 | |
| 3757 | } |
| 3758 | static ssize_t |
| 3759 | qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj, |
| 3760 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3761 | { |
| 3762 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3763 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3764 | struct qlcnic_info nic_info; |
| 3765 | struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC]; |
| 3766 | int i, ret; |
| 3767 | |
| 3768 | if (size != sizeof(np_cfg)) |
| 3769 | return QL_STATUS_INVALID_PARAM; |
| 3770 | |
| 3771 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { |
| 3772 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) |
| 3773 | continue; |
| 3774 | ret = qlcnic_get_nic_info(adapter, &nic_info, i); |
| 3775 | if (ret) |
| 3776 | return ret; |
| 3777 | |
| 3778 | np_cfg[i].pci_func = i; |
Sucheta Chakraborty | a1c0c45 | 2010-10-04 04:20:14 +0000 | [diff] [blame] | 3779 | np_cfg[i].op_mode = (u8)nic_info.op_mode; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3780 | np_cfg[i].port_num = nic_info.phys_port; |
| 3781 | np_cfg[i].fw_capab = nic_info.capabilities; |
| 3782 | np_cfg[i].min_bw = nic_info.min_tx_bw ; |
| 3783 | np_cfg[i].max_bw = nic_info.max_tx_bw; |
| 3784 | np_cfg[i].max_tx_queues = nic_info.max_tx_ques; |
| 3785 | np_cfg[i].max_rx_queues = nic_info.max_rx_ques; |
| 3786 | } |
| 3787 | memcpy(buf, &np_cfg, size); |
| 3788 | return size; |
| 3789 | } |
| 3790 | |
| 3791 | static ssize_t |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 3792 | qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj, |
| 3793 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3794 | { |
| 3795 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3796 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3797 | struct qlcnic_esw_statistics port_stats; |
| 3798 | int ret; |
| 3799 | |
| 3800 | if (size != sizeof(struct qlcnic_esw_statistics)) |
| 3801 | return QL_STATUS_INVALID_PARAM; |
| 3802 | |
| 3803 | if (offset >= QLCNIC_MAX_PCI_FUNC) |
| 3804 | return QL_STATUS_INVALID_PARAM; |
| 3805 | |
| 3806 | memset(&port_stats, 0, size); |
| 3807 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, |
| 3808 | &port_stats.rx); |
| 3809 | if (ret) |
| 3810 | return ret; |
| 3811 | |
| 3812 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, |
| 3813 | &port_stats.tx); |
| 3814 | if (ret) |
| 3815 | return ret; |
| 3816 | |
| 3817 | memcpy(buf, &port_stats, size); |
| 3818 | return size; |
| 3819 | } |
| 3820 | |
| 3821 | static ssize_t |
| 3822 | qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj, |
| 3823 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3824 | { |
| 3825 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3826 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3827 | struct qlcnic_esw_statistics esw_stats; |
| 3828 | int ret; |
| 3829 | |
| 3830 | if (size != sizeof(struct qlcnic_esw_statistics)) |
| 3831 | return QL_STATUS_INVALID_PARAM; |
| 3832 | |
| 3833 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) |
| 3834 | return QL_STATUS_INVALID_PARAM; |
| 3835 | |
| 3836 | memset(&esw_stats, 0, size); |
| 3837 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, |
| 3838 | &esw_stats.rx); |
| 3839 | if (ret) |
| 3840 | return ret; |
| 3841 | |
| 3842 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, |
| 3843 | &esw_stats.tx); |
| 3844 | if (ret) |
| 3845 | return ret; |
| 3846 | |
| 3847 | memcpy(buf, &esw_stats, size); |
| 3848 | return size; |
| 3849 | } |
| 3850 | |
| 3851 | static ssize_t |
| 3852 | qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj, |
| 3853 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3854 | { |
| 3855 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3856 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3857 | int ret; |
| 3858 | |
| 3859 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) |
| 3860 | return QL_STATUS_INVALID_PARAM; |
| 3861 | |
| 3862 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, |
| 3863 | QLCNIC_QUERY_RX_COUNTER); |
| 3864 | if (ret) |
| 3865 | return ret; |
| 3866 | |
| 3867 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, |
| 3868 | QLCNIC_QUERY_TX_COUNTER); |
| 3869 | if (ret) |
| 3870 | return ret; |
| 3871 | |
| 3872 | return size; |
| 3873 | } |
| 3874 | |
| 3875 | static ssize_t |
| 3876 | qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj, |
| 3877 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3878 | { |
| 3879 | |
| 3880 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3881 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3882 | int ret; |
| 3883 | |
| 3884 | if (offset >= QLCNIC_MAX_PCI_FUNC) |
| 3885 | return QL_STATUS_INVALID_PARAM; |
| 3886 | |
| 3887 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, |
| 3888 | QLCNIC_QUERY_RX_COUNTER); |
| 3889 | if (ret) |
| 3890 | return ret; |
| 3891 | |
| 3892 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, |
| 3893 | QLCNIC_QUERY_TX_COUNTER); |
| 3894 | if (ret) |
| 3895 | return ret; |
| 3896 | |
| 3897 | return size; |
| 3898 | } |
| 3899 | |
| 3900 | static ssize_t |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3901 | qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj, |
| 3902 | struct bin_attribute *attr, char *buf, loff_t offset, size_t size) |
| 3903 | { |
| 3904 | struct device *dev = container_of(kobj, struct device, kobj); |
| 3905 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 3906 | struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 3907 | struct qlcnic_pci_info *pci_info; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3908 | int i, ret; |
| 3909 | |
| 3910 | if (size != sizeof(pci_cfg)) |
| 3911 | return QL_STATUS_INVALID_PARAM; |
| 3912 | |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 3913 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
| 3914 | if (!pci_info) |
| 3915 | return -ENOMEM; |
| 3916 | |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3917 | ret = qlcnic_get_pci_info(adapter, pci_info); |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 3918 | if (ret) { |
| 3919 | kfree(pci_info); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3920 | return ret; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 3921 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3922 | |
| 3923 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { |
| 3924 | pci_cfg[i].pci_func = pci_info[i].id; |
| 3925 | pci_cfg[i].func_type = pci_info[i].type; |
| 3926 | pci_cfg[i].port_num = pci_info[i].default_port; |
| 3927 | pci_cfg[i].min_bw = pci_info[i].tx_min_bw; |
| 3928 | pci_cfg[i].max_bw = pci_info[i].tx_max_bw; |
| 3929 | memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); |
| 3930 | } |
| 3931 | memcpy(buf, &pci_cfg, size); |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 3932 | kfree(pci_info); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3933 | return size; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3934 | } |
| 3935 | static struct bin_attribute bin_attr_npar_config = { |
| 3936 | .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 3937 | .size = 0, |
| 3938 | .read = qlcnic_sysfs_read_npar_config, |
| 3939 | .write = qlcnic_sysfs_write_npar_config, |
| 3940 | }; |
| 3941 | |
| 3942 | static struct bin_attribute bin_attr_pci_config = { |
| 3943 | .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 3944 | .size = 0, |
| 3945 | .read = qlcnic_sysfs_read_pci_config, |
| 3946 | .write = NULL, |
| 3947 | }; |
| 3948 | |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 3949 | static struct bin_attribute bin_attr_port_stats = { |
| 3950 | .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)}, |
| 3951 | .size = 0, |
| 3952 | .read = qlcnic_sysfs_get_port_stats, |
| 3953 | .write = qlcnic_sysfs_clear_port_stats, |
| 3954 | }; |
| 3955 | |
| 3956 | static struct bin_attribute bin_attr_esw_stats = { |
| 3957 | .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)}, |
| 3958 | .size = 0, |
| 3959 | .read = qlcnic_sysfs_get_esw_stats, |
| 3960 | .write = qlcnic_sysfs_clear_esw_stats, |
| 3961 | }; |
| 3962 | |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 3963 | static struct bin_attribute bin_attr_esw_config = { |
| 3964 | .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 3965 | .size = 0, |
| 3966 | .read = qlcnic_sysfs_read_esw_config, |
| 3967 | .write = qlcnic_sysfs_write_esw_config, |
| 3968 | }; |
| 3969 | |
| 3970 | static struct bin_attribute bin_attr_pm_config = { |
| 3971 | .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 3972 | .size = 0, |
| 3973 | .read = qlcnic_sysfs_read_pm_config, |
| 3974 | .write = qlcnic_sysfs_write_pm_config, |
| 3975 | }; |
| 3976 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 3977 | static void |
| 3978 | qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) |
| 3979 | { |
| 3980 | struct device *dev = &adapter->pdev->dev; |
| 3981 | |
| 3982 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 3983 | if (device_create_file(dev, &dev_attr_bridged_mode)) |
| 3984 | dev_warn(dev, |
| 3985 | "failed to create bridged_mode sysfs entry\n"); |
| 3986 | } |
| 3987 | |
| 3988 | static void |
| 3989 | qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) |
| 3990 | { |
| 3991 | struct device *dev = &adapter->pdev->dev; |
| 3992 | |
| 3993 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 3994 | device_remove_file(dev, &dev_attr_bridged_mode); |
| 3995 | } |
| 3996 | |
| 3997 | static void |
| 3998 | qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) |
| 3999 | { |
| 4000 | struct device *dev = &adapter->pdev->dev; |
| 4001 | |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 4002 | if (device_create_bin_file(dev, &bin_attr_port_stats)) |
| 4003 | dev_info(dev, "failed to create port stats sysfs entry"); |
| 4004 | |
Anirban Chakraborty | 132ff00 | 2010-07-09 13:15:05 +0000 | [diff] [blame] | 4005 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) |
| 4006 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4007 | if (device_create_file(dev, &dev_attr_diag_mode)) |
| 4008 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); |
| 4009 | if (device_create_bin_file(dev, &bin_attr_crb)) |
| 4010 | dev_info(dev, "failed to create crb sysfs entry\n"); |
| 4011 | if (device_create_bin_file(dev, &bin_attr_mem)) |
| 4012 | dev_info(dev, "failed to create mem sysfs entry\n"); |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 4013 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 4014 | return; |
| 4015 | if (device_create_bin_file(dev, &bin_attr_esw_config)) |
| 4016 | dev_info(dev, "failed to create esw config sysfs entry"); |
| 4017 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 4018 | return; |
| 4019 | if (device_create_bin_file(dev, &bin_attr_pci_config)) |
| 4020 | dev_info(dev, "failed to create pci config sysfs entry"); |
| 4021 | if (device_create_bin_file(dev, &bin_attr_npar_config)) |
| 4022 | dev_info(dev, "failed to create npar config sysfs entry"); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 4023 | if (device_create_bin_file(dev, &bin_attr_pm_config)) |
| 4024 | dev_info(dev, "failed to create pm config sysfs entry"); |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 4025 | if (device_create_bin_file(dev, &bin_attr_esw_stats)) |
| 4026 | dev_info(dev, "failed to create eswitch stats sysfs entry"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4027 | } |
| 4028 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4029 | static void |
| 4030 | qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) |
| 4031 | { |
| 4032 | struct device *dev = &adapter->pdev->dev; |
| 4033 | |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 4034 | device_remove_bin_file(dev, &bin_attr_port_stats); |
| 4035 | |
Anirban Chakraborty | 132ff00 | 2010-07-09 13:15:05 +0000 | [diff] [blame] | 4036 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) |
| 4037 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4038 | device_remove_file(dev, &dev_attr_diag_mode); |
| 4039 | device_remove_bin_file(dev, &bin_attr_crb); |
| 4040 | device_remove_bin_file(dev, &bin_attr_mem); |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 4041 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 4042 | return; |
| 4043 | device_remove_bin_file(dev, &bin_attr_esw_config); |
| 4044 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 4045 | return; |
| 4046 | device_remove_bin_file(dev, &bin_attr_pci_config); |
| 4047 | device_remove_bin_file(dev, &bin_attr_npar_config); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 4048 | device_remove_bin_file(dev, &bin_attr_pm_config); |
Amit Kumar Salecha | b602121 | 2010-08-17 00:34:22 +0000 | [diff] [blame] | 4049 | device_remove_bin_file(dev, &bin_attr_esw_stats); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | #ifdef CONFIG_INET |
| 4053 | |
| 4054 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) |
| 4055 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4056 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4057 | qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, |
| 4058 | struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4059 | { |
| 4060 | struct in_device *indev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4061 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4062 | indev = in_dev_get(dev); |
| 4063 | if (!indev) |
| 4064 | return; |
| 4065 | |
| 4066 | for_ifa(indev) { |
| 4067 | switch (event) { |
| 4068 | case NETDEV_UP: |
| 4069 | qlcnic_config_ipaddr(adapter, |
| 4070 | ifa->ifa_address, QLCNIC_IP_UP); |
| 4071 | break; |
| 4072 | case NETDEV_DOWN: |
| 4073 | qlcnic_config_ipaddr(adapter, |
| 4074 | ifa->ifa_address, QLCNIC_IP_DOWN); |
| 4075 | break; |
| 4076 | default: |
| 4077 | break; |
| 4078 | } |
| 4079 | } endfor_ifa(indev); |
| 4080 | |
| 4081 | in_dev_put(indev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4084 | static void |
| 4085 | qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) |
| 4086 | { |
| 4087 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 4088 | struct net_device *dev; |
| 4089 | u16 vid; |
| 4090 | |
| 4091 | qlcnic_config_indev_addr(adapter, netdev, event); |
| 4092 | |
| 4093 | if (!adapter->vlgrp) |
| 4094 | return; |
| 4095 | |
Jesse Gross | b738127 | 2010-10-20 13:56:02 +0000 | [diff] [blame^] | 4096 | for (vid = 0; vid < VLAN_N_VID; vid++) { |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4097 | dev = vlan_group_get_device(adapter->vlgrp, vid); |
| 4098 | if (!dev) |
| 4099 | continue; |
| 4100 | |
| 4101 | qlcnic_config_indev_addr(adapter, dev, event); |
| 4102 | } |
| 4103 | } |
| 4104 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4105 | static int qlcnic_netdev_event(struct notifier_block *this, |
| 4106 | unsigned long event, void *ptr) |
| 4107 | { |
| 4108 | struct qlcnic_adapter *adapter; |
| 4109 | struct net_device *dev = (struct net_device *)ptr; |
| 4110 | |
| 4111 | recheck: |
| 4112 | if (dev == NULL) |
| 4113 | goto done; |
| 4114 | |
| 4115 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 4116 | dev = vlan_dev_real_dev(dev); |
| 4117 | goto recheck; |
| 4118 | } |
| 4119 | |
| 4120 | if (!is_qlcnic_netdev(dev)) |
| 4121 | goto done; |
| 4122 | |
| 4123 | adapter = netdev_priv(dev); |
| 4124 | |
| 4125 | if (!adapter) |
| 4126 | goto done; |
| 4127 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 4128 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4129 | goto done; |
| 4130 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4131 | qlcnic_config_indev_addr(adapter, dev, event); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4132 | done: |
| 4133 | return NOTIFY_DONE; |
| 4134 | } |
| 4135 | |
| 4136 | static int |
| 4137 | qlcnic_inetaddr_event(struct notifier_block *this, |
| 4138 | unsigned long event, void *ptr) |
| 4139 | { |
| 4140 | struct qlcnic_adapter *adapter; |
| 4141 | struct net_device *dev; |
| 4142 | |
| 4143 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 4144 | |
| 4145 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 4146 | |
| 4147 | recheck: |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4148 | if (dev == NULL) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4149 | goto done; |
| 4150 | |
| 4151 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 4152 | dev = vlan_dev_real_dev(dev); |
| 4153 | goto recheck; |
| 4154 | } |
| 4155 | |
| 4156 | if (!is_qlcnic_netdev(dev)) |
| 4157 | goto done; |
| 4158 | |
| 4159 | adapter = netdev_priv(dev); |
| 4160 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 4161 | if (!adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4162 | goto done; |
| 4163 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 4164 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4165 | goto done; |
| 4166 | |
| 4167 | switch (event) { |
| 4168 | case NETDEV_UP: |
| 4169 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); |
| 4170 | break; |
| 4171 | case NETDEV_DOWN: |
| 4172 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); |
| 4173 | break; |
| 4174 | default: |
| 4175 | break; |
| 4176 | } |
| 4177 | |
| 4178 | done: |
| 4179 | return NOTIFY_DONE; |
| 4180 | } |
| 4181 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4182 | static struct notifier_block qlcnic_netdev_cb = { |
| 4183 | .notifier_call = qlcnic_netdev_event, |
| 4184 | }; |
| 4185 | |
| 4186 | static struct notifier_block qlcnic_inetaddr_cb = { |
| 4187 | .notifier_call = qlcnic_inetaddr_event, |
| 4188 | }; |
| 4189 | #else |
| 4190 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 4191 | qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4192 | { } |
| 4193 | #endif |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 4194 | static struct pci_error_handlers qlcnic_err_handler = { |
| 4195 | .error_detected = qlcnic_io_error_detected, |
| 4196 | .slot_reset = qlcnic_io_slot_reset, |
| 4197 | .resume = qlcnic_io_resume, |
| 4198 | }; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4199 | |
| 4200 | static struct pci_driver qlcnic_driver = { |
| 4201 | .name = qlcnic_driver_name, |
| 4202 | .id_table = qlcnic_pci_tbl, |
| 4203 | .probe = qlcnic_probe, |
| 4204 | .remove = __devexit_p(qlcnic_remove), |
| 4205 | #ifdef CONFIG_PM |
| 4206 | .suspend = qlcnic_suspend, |
| 4207 | .resume = qlcnic_resume, |
| 4208 | #endif |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 4209 | .shutdown = qlcnic_shutdown, |
| 4210 | .err_handler = &qlcnic_err_handler |
| 4211 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4212 | }; |
| 4213 | |
| 4214 | static int __init qlcnic_init_module(void) |
| 4215 | { |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 4216 | int ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4217 | |
| 4218 | printk(KERN_INFO "%s\n", qlcnic_driver_string); |
| 4219 | |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 4220 | qlcnic_wq = create_singlethread_workqueue("qlcnic"); |
| 4221 | if (qlcnic_wq == NULL) { |
| 4222 | printk(KERN_ERR "qlcnic: cannot create workqueue\n"); |
| 4223 | return -ENOMEM; |
| 4224 | } |
| 4225 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4226 | #ifdef CONFIG_INET |
| 4227 | register_netdevice_notifier(&qlcnic_netdev_cb); |
| 4228 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 4229 | #endif |
| 4230 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 4231 | ret = pci_register_driver(&qlcnic_driver); |
| 4232 | if (ret) { |
| 4233 | #ifdef CONFIG_INET |
| 4234 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 4235 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 4236 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 4237 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 4238 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4239 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 4240 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | module_init(qlcnic_init_module); |
| 4244 | |
| 4245 | static void __exit qlcnic_exit_module(void) |
| 4246 | { |
| 4247 | |
| 4248 | pci_unregister_driver(&qlcnic_driver); |
| 4249 | |
| 4250 | #ifdef CONFIG_INET |
| 4251 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 4252 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 4253 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 4254 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | module_exit(qlcnic_exit_module); |