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 | |
| 31 | #include <linux/dma-mapping.h> |
| 32 | #include <linux/if_vlan.h> |
| 33 | #include <net/ip.h> |
| 34 | #include <linux/ipv6.h> |
| 35 | #include <linux/inetdevice.h> |
| 36 | #include <linux/sysfs.h> |
| 37 | |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 38 | MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 39 | MODULE_LICENSE("GPL"); |
| 40 | MODULE_VERSION(QLCNIC_LINUX_VERSIONID); |
| 41 | MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); |
| 42 | |
| 43 | char qlcnic_driver_name[] = "qlcnic"; |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 44 | static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " |
| 45 | "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 46 | |
| 47 | static int port_mode = QLCNIC_PORT_MODE_AUTO_NEG; |
| 48 | |
| 49 | /* Default to restricted 1G auto-neg mode */ |
| 50 | static int wol_port_mode = 5; |
| 51 | |
| 52 | static int use_msi = 1; |
| 53 | module_param(use_msi, int, 0644); |
| 54 | MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); |
| 55 | |
| 56 | static int use_msi_x = 1; |
| 57 | module_param(use_msi_x, int, 0644); |
| 58 | MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); |
| 59 | |
| 60 | static int auto_fw_reset = AUTO_FW_RESET_ENABLED; |
| 61 | module_param(auto_fw_reset, int, 0644); |
| 62 | MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); |
| 63 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 64 | static int load_fw_file; |
| 65 | module_param(load_fw_file, int, 0644); |
| 66 | MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); |
| 67 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 68 | static int qlcnic_config_npars; |
| 69 | module_param(qlcnic_config_npars, int, 0644); |
| 70 | MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); |
| 71 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 72 | static int __devinit qlcnic_probe(struct pci_dev *pdev, |
| 73 | const struct pci_device_id *ent); |
| 74 | static void __devexit qlcnic_remove(struct pci_dev *pdev); |
| 75 | static int qlcnic_open(struct net_device *netdev); |
| 76 | static int qlcnic_close(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 77 | static void qlcnic_tx_timeout(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 78 | static void qlcnic_attach_work(struct work_struct *work); |
| 79 | static void qlcnic_fwinit_work(struct work_struct *work); |
| 80 | static void qlcnic_fw_poll_work(struct work_struct *work); |
| 81 | static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 82 | work_func_t func, int delay); |
| 83 | static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); |
| 84 | static int qlcnic_poll(struct napi_struct *napi, int budget); |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 85 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 86 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 87 | static void qlcnic_poll_controller(struct net_device *netdev); |
| 88 | #endif |
| 89 | |
| 90 | static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter); |
| 91 | static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter); |
| 92 | static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter); |
| 93 | static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); |
| 94 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 95 | static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 96 | static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter); |
| 97 | static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); |
| 98 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 99 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 100 | static irqreturn_t qlcnic_intr(int irq, void *data); |
| 101 | static irqreturn_t qlcnic_msi_intr(int irq, void *data); |
| 102 | static irqreturn_t qlcnic_msix_intr(int irq, void *data); |
| 103 | |
| 104 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); |
| 105 | static void qlcnic_config_indev_addr(struct net_device *dev, unsigned long); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 106 | static int qlcnic_start_firmware(struct qlcnic_adapter *); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 107 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 108 | static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); |
| 109 | static void qlcnicvf_clear_ilb_mode(struct qlcnic_adapter *); |
| 110 | static int qlcnicvf_set_ilb_mode(struct qlcnic_adapter *); |
| 111 | static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); |
| 112 | static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); |
| 113 | static int qlcnicvf_start_firmware(struct qlcnic_adapter *); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 114 | /* PCI Device ID Table */ |
| 115 | #define ENTRY(device) \ |
| 116 | {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ |
| 117 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
| 118 | |
| 119 | #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 |
| 120 | |
Amit Kumar Salecha | 6a90288 | 2010-02-01 05:24:54 +0000 | [diff] [blame] | 121 | static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 122 | ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), |
| 123 | {0,} |
| 124 | }; |
| 125 | |
| 126 | MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); |
| 127 | |
| 128 | |
| 129 | void |
| 130 | qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, |
| 131 | struct qlcnic_host_tx_ring *tx_ring) |
| 132 | { |
| 133 | writel(tx_ring->producer, tx_ring->crb_cmd_producer); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static const u32 msi_tgt_status[8] = { |
| 137 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
| 138 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
| 139 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, |
| 140 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 |
| 141 | }; |
| 142 | |
| 143 | static const |
| 144 | struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; |
| 145 | |
| 146 | static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring) |
| 147 | { |
| 148 | writel(0, sds_ring->crb_intr_mask); |
| 149 | } |
| 150 | |
| 151 | static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring) |
| 152 | { |
| 153 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 154 | |
| 155 | writel(0x1, sds_ring->crb_intr_mask); |
| 156 | |
| 157 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) |
| 158 | writel(0xfbff, adapter->tgt_mask_reg); |
| 159 | } |
| 160 | |
| 161 | static int |
| 162 | qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) |
| 163 | { |
| 164 | int size = sizeof(struct qlcnic_host_sds_ring) * count; |
| 165 | |
| 166 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); |
| 167 | |
| 168 | return (recv_ctx->sds_rings == NULL); |
| 169 | } |
| 170 | |
| 171 | static void |
| 172 | qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) |
| 173 | { |
| 174 | if (recv_ctx->sds_rings != NULL) |
| 175 | kfree(recv_ctx->sds_rings); |
| 176 | |
| 177 | recv_ctx->sds_rings = NULL; |
| 178 | } |
| 179 | |
| 180 | static int |
| 181 | qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 182 | { |
| 183 | int ring; |
| 184 | struct qlcnic_host_sds_ring *sds_ring; |
| 185 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 186 | |
| 187 | if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) |
| 188 | return -ENOMEM; |
| 189 | |
| 190 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 191 | sds_ring = &recv_ctx->sds_rings[ring]; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 192 | |
| 193 | if (ring == adapter->max_sds_rings - 1) |
| 194 | netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll, |
| 195 | QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings); |
| 196 | else |
| 197 | netif_napi_add(netdev, &sds_ring->napi, |
| 198 | qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static void |
| 205 | qlcnic_napi_del(struct qlcnic_adapter *adapter) |
| 206 | { |
| 207 | int ring; |
| 208 | struct qlcnic_host_sds_ring *sds_ring; |
| 209 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 210 | |
| 211 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 212 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 213 | netif_napi_del(&sds_ring->napi); |
| 214 | } |
| 215 | |
| 216 | qlcnic_free_sds_rings(&adapter->recv_ctx); |
| 217 | } |
| 218 | |
| 219 | static void |
| 220 | qlcnic_napi_enable(struct qlcnic_adapter *adapter) |
| 221 | { |
| 222 | int ring; |
| 223 | struct qlcnic_host_sds_ring *sds_ring; |
| 224 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 225 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 226 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 227 | return; |
| 228 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 229 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 230 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 231 | napi_enable(&sds_ring->napi); |
| 232 | qlcnic_enable_int(sds_ring); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static void |
| 237 | qlcnic_napi_disable(struct qlcnic_adapter *adapter) |
| 238 | { |
| 239 | int ring; |
| 240 | struct qlcnic_host_sds_ring *sds_ring; |
| 241 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 242 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 243 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 244 | return; |
| 245 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 246 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 247 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 248 | qlcnic_disable_int(sds_ring); |
| 249 | napi_synchronize(&sds_ring->napi); |
| 250 | napi_disable(&sds_ring->napi); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | static void qlcnic_clear_stats(struct qlcnic_adapter *adapter) |
| 255 | { |
| 256 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 259 | static void qlcnic_set_port_mode(struct qlcnic_adapter *adapter) |
| 260 | { |
| 261 | u32 val, data; |
| 262 | |
| 263 | val = adapter->ahw.board_type; |
| 264 | if ((val == QLCNIC_BRDTYPE_P3_HMEZ) || |
| 265 | (val == QLCNIC_BRDTYPE_P3_XG_LOM)) { |
| 266 | if (port_mode == QLCNIC_PORT_MODE_802_3_AP) { |
| 267 | data = QLCNIC_PORT_MODE_802_3_AP; |
| 268 | QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data); |
| 269 | } else if (port_mode == QLCNIC_PORT_MODE_XG) { |
| 270 | data = QLCNIC_PORT_MODE_XG; |
| 271 | QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data); |
| 272 | } else if (port_mode == QLCNIC_PORT_MODE_AUTO_NEG_1G) { |
| 273 | data = QLCNIC_PORT_MODE_AUTO_NEG_1G; |
| 274 | QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data); |
| 275 | } else if (port_mode == QLCNIC_PORT_MODE_AUTO_NEG_XG) { |
| 276 | data = QLCNIC_PORT_MODE_AUTO_NEG_XG; |
| 277 | QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data); |
| 278 | } else { |
| 279 | data = QLCNIC_PORT_MODE_AUTO_NEG; |
| 280 | QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data); |
| 281 | } |
| 282 | |
| 283 | if ((wol_port_mode != QLCNIC_PORT_MODE_802_3_AP) && |
| 284 | (wol_port_mode != QLCNIC_PORT_MODE_XG) && |
| 285 | (wol_port_mode != QLCNIC_PORT_MODE_AUTO_NEG_1G) && |
| 286 | (wol_port_mode != QLCNIC_PORT_MODE_AUTO_NEG_XG)) { |
| 287 | wol_port_mode = QLCNIC_PORT_MODE_AUTO_NEG; |
| 288 | } |
| 289 | QLCWR32(adapter, QLCNIC_WOL_PORT_MODE, wol_port_mode); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable) |
| 294 | { |
| 295 | u32 control; |
| 296 | int pos; |
| 297 | |
| 298 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 299 | if (pos) { |
| 300 | pci_read_config_dword(pdev, pos, &control); |
| 301 | if (enable) |
| 302 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 303 | else |
| 304 | control = 0; |
| 305 | pci_write_config_dword(pdev, pos, control); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count) |
| 310 | { |
| 311 | int i; |
| 312 | |
| 313 | for (i = 0; i < count; i++) |
| 314 | adapter->msix_entries[i].entry = i; |
| 315 | } |
| 316 | |
| 317 | static int |
| 318 | qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) |
| 319 | { |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 320 | u8 mac_addr[ETH_ALEN]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 321 | struct net_device *netdev = adapter->netdev; |
| 322 | struct pci_dev *pdev = adapter->pdev; |
| 323 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 324 | if (adapter->nic_ops->get_mac_addr(adapter, mac_addr) != 0) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 325 | return -EIO; |
| 326 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 327 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 328 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); |
| 329 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); |
| 330 | |
| 331 | /* set station address */ |
| 332 | |
| 333 | if (!is_valid_ether_addr(netdev->perm_addr)) |
| 334 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", |
| 335 | netdev->dev_addr); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int qlcnic_set_mac(struct net_device *netdev, void *p) |
| 341 | { |
| 342 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 343 | struct sockaddr *addr = p; |
| 344 | |
| 345 | if (!is_valid_ether_addr(addr->sa_data)) |
| 346 | return -EINVAL; |
| 347 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 348 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 349 | netif_device_detach(netdev); |
| 350 | qlcnic_napi_disable(adapter); |
| 351 | } |
| 352 | |
| 353 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); |
| 354 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 355 | qlcnic_set_multi(adapter->netdev); |
| 356 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 357 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 358 | netif_device_attach(netdev); |
| 359 | qlcnic_napi_enable(adapter); |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static const struct net_device_ops qlcnic_netdev_ops = { |
| 365 | .ndo_open = qlcnic_open, |
| 366 | .ndo_stop = qlcnic_close, |
| 367 | .ndo_start_xmit = qlcnic_xmit_frame, |
| 368 | .ndo_get_stats = qlcnic_get_stats, |
| 369 | .ndo_validate_addr = eth_validate_addr, |
| 370 | .ndo_set_multicast_list = qlcnic_set_multi, |
| 371 | .ndo_set_mac_address = qlcnic_set_mac, |
| 372 | .ndo_change_mtu = qlcnic_change_mtu, |
| 373 | .ndo_tx_timeout = qlcnic_tx_timeout, |
| 374 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 375 | .ndo_poll_controller = qlcnic_poll_controller, |
| 376 | #endif |
| 377 | }; |
| 378 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 379 | static struct qlcnic_nic_template qlcnic_ops = { |
| 380 | .get_mac_addr = qlcnic_get_mac_addr, |
| 381 | .config_bridged_mode = qlcnic_config_bridged_mode, |
| 382 | .config_led = qlcnic_config_led, |
| 383 | .set_ilb_mode = qlcnic_set_ilb_mode, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 384 | .clear_ilb_mode = qlcnic_clear_ilb_mode, |
| 385 | .start_firmware = qlcnic_start_firmware |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | static struct qlcnic_nic_template qlcnic_pf_ops = { |
| 389 | .get_mac_addr = qlcnic_get_mac_address, |
| 390 | .config_bridged_mode = qlcnic_config_bridged_mode, |
| 391 | .config_led = qlcnic_config_led, |
| 392 | .set_ilb_mode = qlcnic_set_ilb_mode, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 393 | .clear_ilb_mode = qlcnic_clear_ilb_mode, |
| 394 | .start_firmware = qlcnic_start_firmware |
| 395 | }; |
| 396 | |
| 397 | static struct qlcnic_nic_template qlcnic_vf_ops = { |
| 398 | .get_mac_addr = qlcnic_get_mac_address, |
| 399 | .config_bridged_mode = qlcnicvf_config_bridged_mode, |
| 400 | .config_led = qlcnicvf_config_led, |
| 401 | .set_ilb_mode = qlcnicvf_set_ilb_mode, |
| 402 | .clear_ilb_mode = qlcnicvf_clear_ilb_mode, |
| 403 | .start_firmware = qlcnicvf_start_firmware |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 404 | }; |
| 405 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 406 | static void |
| 407 | qlcnic_setup_intr(struct qlcnic_adapter *adapter) |
| 408 | { |
| 409 | const struct qlcnic_legacy_intr_set *legacy_intrp; |
| 410 | struct pci_dev *pdev = adapter->pdev; |
| 411 | int err, num_msix; |
| 412 | |
| 413 | if (adapter->rss_supported) { |
| 414 | num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? |
| 415 | MSIX_ENTRIES_PER_ADAPTER : 2; |
| 416 | } else |
| 417 | num_msix = 1; |
| 418 | |
| 419 | adapter->max_sds_rings = 1; |
| 420 | |
| 421 | adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); |
| 422 | |
| 423 | legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; |
| 424 | |
| 425 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; |
| 426 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 427 | legacy_intrp->tgt_status_reg); |
| 428 | adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, |
| 429 | legacy_intrp->tgt_mask_reg); |
| 430 | adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); |
| 431 | |
| 432 | adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, |
| 433 | ISR_INT_STATE_REG); |
| 434 | |
| 435 | qlcnic_set_msix_bit(pdev, 0); |
| 436 | |
| 437 | if (adapter->msix_supported) { |
| 438 | |
| 439 | qlcnic_init_msix_entries(adapter, num_msix); |
| 440 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); |
| 441 | if (err == 0) { |
| 442 | adapter->flags |= QLCNIC_MSIX_ENABLED; |
| 443 | qlcnic_set_msix_bit(pdev, 1); |
| 444 | |
| 445 | if (adapter->rss_supported) |
| 446 | adapter->max_sds_rings = num_msix; |
| 447 | |
| 448 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | if (err > 0) |
| 453 | pci_disable_msix(pdev); |
| 454 | |
| 455 | /* fall through for msi */ |
| 456 | } |
| 457 | |
| 458 | if (use_msi && !pci_enable_msi(pdev)) { |
| 459 | adapter->flags |= QLCNIC_MSI_ENABLED; |
| 460 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 461 | msi_tgt_status[adapter->ahw.pci_func]); |
| 462 | dev_info(&pdev->dev, "using msi interrupts\n"); |
| 463 | adapter->msix_entries[0].vector = pdev->irq; |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 468 | adapter->msix_entries[0].vector = pdev->irq; |
| 469 | } |
| 470 | |
| 471 | static void |
| 472 | qlcnic_teardown_intr(struct qlcnic_adapter *adapter) |
| 473 | { |
| 474 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 475 | pci_disable_msix(adapter->pdev); |
| 476 | if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 477 | pci_disable_msi(adapter->pdev); |
| 478 | } |
| 479 | |
| 480 | static void |
| 481 | qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) |
| 482 | { |
| 483 | if (adapter->ahw.pci_base0 != NULL) |
| 484 | iounmap(adapter->ahw.pci_base0); |
| 485 | } |
| 486 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 487 | static int |
| 488 | qlcnic_set_function_modes(struct qlcnic_adapter *adapter) |
| 489 | { |
| 490 | u8 id; |
| 491 | u32 ref_count; |
| 492 | int i, ret = 1; |
| 493 | u32 data = QLCNIC_MGMT_FUNC; |
| 494 | void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; |
| 495 | |
| 496 | /* If other drivers are not in use set their privilege level */ |
| 497 | ref_count = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); |
| 498 | ret = qlcnic_api_lock(adapter); |
| 499 | if (ret) |
| 500 | goto err_lock; |
| 501 | if (QLC_DEV_CLR_REF_CNT(ref_count, adapter->ahw.pci_func)) |
| 502 | goto err_npar; |
| 503 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 504 | if (qlcnic_config_npars) { |
| 505 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 506 | id = adapter->npars[i].id; |
| 507 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC || |
| 508 | id == adapter->ahw.pci_func) |
| 509 | continue; |
| 510 | data |= (qlcnic_config_npars & |
| 511 | QLC_DEV_SET_DRV(0xf, id)); |
| 512 | } |
| 513 | } else { |
| 514 | data = readl(priv_op); |
| 515 | data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) | |
| 516 | (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, |
| 517 | adapter->ahw.pci_func)); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 518 | } |
| 519 | writel(data, priv_op); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 520 | err_npar: |
| 521 | qlcnic_api_unlock(adapter); |
| 522 | err_lock: |
| 523 | return ret; |
| 524 | } |
| 525 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 526 | static u32 |
| 527 | qlcnic_get_driver_mode(struct qlcnic_adapter *adapter) |
| 528 | { |
| 529 | void __iomem *msix_base_addr; |
| 530 | void __iomem *priv_op; |
| 531 | u32 func; |
| 532 | u32 msix_base; |
| 533 | u32 op_mode, priv_level; |
| 534 | |
| 535 | /* Determine FW API version */ |
| 536 | adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API); |
| 537 | if (adapter->fw_hal_version == ~0) { |
| 538 | adapter->nic_ops = &qlcnic_ops; |
| 539 | adapter->fw_hal_version = QLCNIC_FW_BASE; |
| 540 | adapter->ahw.pci_func = PCI_FUNC(adapter->pdev->devfn); |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 541 | adapter->capabilities = QLCRD32(adapter, CRB_FW_CAPABILITIES_1); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 542 | dev_info(&adapter->pdev->dev, |
| 543 | "FW does not support nic partion\n"); |
| 544 | return adapter->fw_hal_version; |
| 545 | } |
| 546 | |
| 547 | /* Find PCI function number */ |
| 548 | pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); |
| 549 | msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE; |
| 550 | msix_base = readl(msix_base_addr); |
| 551 | func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; |
| 552 | adapter->ahw.pci_func = func; |
| 553 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 554 | qlcnic_get_nic_info(adapter, adapter->ahw.pci_func); |
| 555 | |
| 556 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { |
| 557 | adapter->nic_ops = &qlcnic_ops; |
| 558 | return adapter->fw_hal_version; |
| 559 | } |
| 560 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 561 | /* Determine function privilege level */ |
| 562 | priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; |
| 563 | op_mode = readl(priv_op); |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 564 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 565 | priv_level = QLCNIC_MGMT_FUNC; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 566 | else |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 567 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); |
| 568 | |
| 569 | switch (priv_level) { |
| 570 | case QLCNIC_MGMT_FUNC: |
| 571 | adapter->op_mode = QLCNIC_MGMT_FUNC; |
| 572 | adapter->nic_ops = &qlcnic_pf_ops; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 573 | qlcnic_get_pci_info(adapter); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 574 | /* Set privilege level for other functions */ |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 575 | qlcnic_set_function_modes(adapter); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 576 | dev_info(&adapter->pdev->dev, |
| 577 | "HAL Version: %d, Management function\n", |
| 578 | adapter->fw_hal_version); |
| 579 | break; |
| 580 | case QLCNIC_PRIV_FUNC: |
| 581 | adapter->op_mode = QLCNIC_PRIV_FUNC; |
| 582 | dev_info(&adapter->pdev->dev, |
| 583 | "HAL Version: %d, Privileged function\n", |
| 584 | adapter->fw_hal_version); |
| 585 | adapter->nic_ops = &qlcnic_pf_ops; |
| 586 | break; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 587 | case QLCNIC_NON_PRIV_FUNC: |
| 588 | adapter->op_mode = QLCNIC_NON_PRIV_FUNC; |
| 589 | dev_info(&adapter->pdev->dev, |
| 590 | "HAL Version: %d Non Privileged function\n", |
| 591 | adapter->fw_hal_version); |
| 592 | adapter->nic_ops = &qlcnic_vf_ops; |
| 593 | break; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 594 | default: |
| 595 | dev_info(&adapter->pdev->dev, "Unknown function mode: %d\n", |
| 596 | priv_level); |
| 597 | return 0; |
| 598 | } |
| 599 | return adapter->fw_hal_version; |
| 600 | } |
| 601 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 602 | static int |
| 603 | qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) |
| 604 | { |
| 605 | void __iomem *mem_ptr0 = NULL; |
| 606 | resource_size_t mem_base; |
| 607 | unsigned long mem_len, pci_len0 = 0; |
| 608 | |
| 609 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 610 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 611 | /* remap phys address */ |
| 612 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 613 | mem_len = pci_resource_len(pdev, 0); |
| 614 | |
| 615 | if (mem_len == QLCNIC_PCI_2MB_SIZE) { |
| 616 | |
| 617 | mem_ptr0 = pci_ioremap_bar(pdev, 0); |
| 618 | if (mem_ptr0 == NULL) { |
| 619 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); |
| 620 | return -EIO; |
| 621 | } |
| 622 | pci_len0 = mem_len; |
| 623 | } else { |
| 624 | return -EIO; |
| 625 | } |
| 626 | |
| 627 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); |
| 628 | |
| 629 | adapter->ahw.pci_base0 = mem_ptr0; |
| 630 | adapter->ahw.pci_len0 = pci_len0; |
| 631 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 632 | if (!qlcnic_get_driver_mode(adapter)) { |
| 633 | iounmap(adapter->ahw.pci_base0); |
| 634 | return -EIO; |
| 635 | } |
| 636 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 637 | adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter, |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 638 | 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] | 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static void get_brd_name(struct qlcnic_adapter *adapter, char *name) |
| 644 | { |
| 645 | struct pci_dev *pdev = adapter->pdev; |
| 646 | int i, found = 0; |
| 647 | |
| 648 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { |
| 649 | if (qlcnic_boards[i].vendor == pdev->vendor && |
| 650 | qlcnic_boards[i].device == pdev->device && |
| 651 | qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && |
| 652 | qlcnic_boards[i].sub_device == pdev->subsystem_device) { |
Sucheta Chakraborty | 02f6e46 | 2010-05-17 01:22:09 +0000 | [diff] [blame] | 653 | sprintf(name, "%pM: %s" , |
| 654 | adapter->mac_addr, |
| 655 | qlcnic_boards[i].short_name); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 656 | found = 1; |
| 657 | break; |
| 658 | } |
| 659 | |
| 660 | } |
| 661 | |
| 662 | if (!found) |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 663 | sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static void |
| 667 | qlcnic_check_options(struct qlcnic_adapter *adapter) |
| 668 | { |
| 669 | u32 fw_major, fw_minor, fw_build; |
| 670 | char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; |
| 671 | char serial_num[32]; |
| 672 | int i, offset, val; |
| 673 | int *ptr32; |
| 674 | struct pci_dev *pdev = adapter->pdev; |
| 675 | |
| 676 | adapter->driver_mismatch = 0; |
| 677 | |
| 678 | ptr32 = (int *)&serial_num; |
| 679 | offset = QLCNIC_FW_SERIAL_NUM_OFFSET; |
| 680 | for (i = 0; i < 8; i++) { |
| 681 | if (qlcnic_rom_fast_read(adapter, offset, &val) == -1) { |
| 682 | dev_err(&pdev->dev, "error reading board info\n"); |
| 683 | adapter->driver_mismatch = 1; |
| 684 | return; |
| 685 | } |
| 686 | ptr32[i] = cpu_to_le32(val); |
| 687 | offset += sizeof(u32); |
| 688 | } |
| 689 | |
| 690 | fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); |
| 691 | fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); |
| 692 | fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); |
| 693 | |
| 694 | adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); |
| 695 | |
| 696 | if (adapter->portnum == 0) { |
| 697 | get_brd_name(adapter, brd_name); |
| 698 | |
| 699 | pr_info("%s: %s Board Chip rev 0x%x\n", |
| 700 | module_name(THIS_MODULE), |
| 701 | brd_name, adapter->ahw.revision_id); |
| 702 | } |
| 703 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 704 | dev_info(&pdev->dev, "firmware v%d.%d.%d\n", |
| 705 | fw_major, fw_minor, fw_build); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 706 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 707 | adapter->flags &= ~QLCNIC_LRO_ENABLED; |
| 708 | |
| 709 | if (adapter->ahw.port_type == QLCNIC_XGBE) { |
| 710 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; |
| 711 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
| 712 | } else if (adapter->ahw.port_type == QLCNIC_GBE) { |
| 713 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; |
| 714 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
| 715 | } |
| 716 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 717 | qlcnic_get_nic_info(adapter, adapter->ahw.pci_func); |
| 718 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 719 | adapter->msix_supported = !!use_msi_x; |
| 720 | adapter->rss_supported = !!use_msi_x; |
| 721 | |
| 722 | adapter->num_txd = MAX_CMD_DESCRIPTORS; |
| 723 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 724 | adapter->max_rds_rings = 2; |
| 725 | } |
| 726 | |
| 727 | static int |
| 728 | qlcnic_start_firmware(struct qlcnic_adapter *adapter) |
| 729 | { |
| 730 | int val, err, first_boot; |
| 731 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 732 | err = qlcnic_can_start_firmware(adapter); |
| 733 | if (err < 0) |
| 734 | return err; |
| 735 | else if (!err) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 736 | goto wait_init; |
| 737 | |
| 738 | first_boot = QLCRD32(adapter, QLCNIC_CAM_RAM(0x1fc)); |
| 739 | if (first_boot == 0x55555555) |
| 740 | /* This is the first boot after power up */ |
| 741 | QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC); |
| 742 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 743 | if (load_fw_file) |
| 744 | qlcnic_request_firmware(adapter); |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 745 | else { |
| 746 | if (qlcnic_check_flash_fw_ver(adapter)) |
| 747 | goto err_out; |
| 748 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 749 | adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 750 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 751 | |
| 752 | err = qlcnic_need_fw_reset(adapter); |
| 753 | if (err < 0) |
| 754 | goto err_out; |
| 755 | if (err == 0) |
| 756 | goto wait_init; |
| 757 | |
| 758 | if (first_boot != 0x55555555) { |
| 759 | QLCWR32(adapter, CRB_CMDPEG_STATE, 0); |
Amit Kumar Salecha | 900c6cf | 2010-06-22 03:18:59 +0000 | [diff] [blame] | 760 | QLCWR32(adapter, CRB_RCVPEG_STATE, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 761 | qlcnic_pinit_from_rom(adapter); |
| 762 | msleep(1); |
| 763 | } |
| 764 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 765 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0); |
| 766 | QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0); |
| 767 | |
| 768 | qlcnic_set_port_mode(adapter); |
| 769 | |
| 770 | err = qlcnic_load_firmware(adapter); |
| 771 | if (err) |
| 772 | goto err_out; |
| 773 | |
| 774 | qlcnic_release_firmware(adapter); |
| 775 | |
| 776 | val = (_QLCNIC_LINUX_MAJOR << 16) |
| 777 | | ((_QLCNIC_LINUX_MINOR << 8)) |
| 778 | | (_QLCNIC_LINUX_SUBVERSION); |
| 779 | QLCWR32(adapter, CRB_DRIVER_VERSION, val); |
| 780 | |
| 781 | wait_init: |
| 782 | /* Handshake with the card before we register the devices. */ |
Amit Kumar Salecha | 900c6cf | 2010-06-22 03:18:59 +0000 | [diff] [blame] | 783 | err = qlcnic_init_firmware(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 784 | if (err) |
| 785 | goto err_out; |
| 786 | |
| 787 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 788 | qlcnic_idc_debug_info(adapter, 1); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 789 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 790 | qlcnic_check_options(adapter); |
| 791 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 792 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED && |
| 793 | adapter->op_mode != QLCNIC_NON_PRIV_FUNC) |
| 794 | qlcnic_dev_set_npar_ready(adapter); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 795 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 796 | adapter->need_fw_reset = 0; |
| 797 | |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 798 | qlcnic_release_firmware(adapter); |
| 799 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 800 | |
| 801 | err_out: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 802 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 803 | dev_err(&adapter->pdev->dev, "Device state set to failed\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 804 | qlcnic_release_firmware(adapter); |
| 805 | return err; |
| 806 | } |
| 807 | |
| 808 | static int |
| 809 | qlcnic_request_irq(struct qlcnic_adapter *adapter) |
| 810 | { |
| 811 | irq_handler_t handler; |
| 812 | struct qlcnic_host_sds_ring *sds_ring; |
| 813 | int err, ring; |
| 814 | |
| 815 | unsigned long flags = 0; |
| 816 | struct net_device *netdev = adapter->netdev; |
| 817 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 818 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 819 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 820 | handler = qlcnic_tmp_intr; |
| 821 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) |
| 822 | flags |= IRQF_SHARED; |
| 823 | |
| 824 | } else { |
| 825 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 826 | handler = qlcnic_msix_intr; |
| 827 | else if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 828 | handler = qlcnic_msi_intr; |
| 829 | else { |
| 830 | flags |= IRQF_SHARED; |
| 831 | handler = qlcnic_intr; |
| 832 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 833 | } |
| 834 | adapter->irq = netdev->irq; |
| 835 | |
| 836 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 837 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 838 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
| 839 | err = request_irq(sds_ring->irq, handler, |
| 840 | flags, sds_ring->name, sds_ring); |
| 841 | if (err) |
| 842 | return err; |
| 843 | } |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static void |
| 849 | qlcnic_free_irq(struct qlcnic_adapter *adapter) |
| 850 | { |
| 851 | int ring; |
| 852 | struct qlcnic_host_sds_ring *sds_ring; |
| 853 | |
| 854 | struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; |
| 855 | |
| 856 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 857 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 858 | free_irq(sds_ring->irq, sds_ring); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | static void |
| 863 | qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter) |
| 864 | { |
| 865 | adapter->coal.flags = QLCNIC_INTR_DEFAULT; |
| 866 | adapter->coal.normal.data.rx_time_us = |
| 867 | QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; |
| 868 | adapter->coal.normal.data.rx_packets = |
| 869 | QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; |
| 870 | adapter->coal.normal.data.tx_time_us = |
| 871 | QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US; |
| 872 | adapter->coal.normal.data.tx_packets = |
| 873 | QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS; |
| 874 | } |
| 875 | |
| 876 | static int |
| 877 | __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 878 | { |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 879 | int ring; |
| 880 | struct qlcnic_host_rds_ring *rds_ring; |
| 881 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 882 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 883 | return -EIO; |
| 884 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 885 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 886 | return 0; |
| 887 | |
| 888 | if (qlcnic_fw_create_ctx(adapter)) |
| 889 | return -EIO; |
| 890 | |
| 891 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 892 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 893 | qlcnic_post_rx_buffers(adapter, ring, rds_ring); |
| 894 | } |
| 895 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 896 | qlcnic_set_multi(netdev); |
| 897 | qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); |
| 898 | |
| 899 | adapter->ahw.linkup = 0; |
| 900 | |
| 901 | if (adapter->max_sds_rings > 1) |
| 902 | qlcnic_config_rss(adapter, 1); |
| 903 | |
| 904 | qlcnic_config_intr_coalesce(adapter); |
| 905 | |
| 906 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
| 907 | qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); |
| 908 | |
| 909 | qlcnic_napi_enable(adapter); |
| 910 | |
| 911 | qlcnic_linkevent_request(adapter, 1); |
| 912 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame^] | 913 | adapter->reset_context = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 914 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | /* Usage: During resume and firmware recovery module.*/ |
| 919 | |
| 920 | static int |
| 921 | qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 922 | { |
| 923 | int err = 0; |
| 924 | |
| 925 | rtnl_lock(); |
| 926 | if (netif_running(netdev)) |
| 927 | err = __qlcnic_up(adapter, netdev); |
| 928 | rtnl_unlock(); |
| 929 | |
| 930 | return err; |
| 931 | } |
| 932 | |
| 933 | static void |
| 934 | __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 935 | { |
| 936 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 937 | return; |
| 938 | |
| 939 | if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 940 | return; |
| 941 | |
| 942 | smp_mb(); |
| 943 | spin_lock(&adapter->tx_clean_lock); |
| 944 | netif_carrier_off(netdev); |
| 945 | netif_tx_disable(netdev); |
| 946 | |
| 947 | qlcnic_free_mac_list(adapter); |
| 948 | |
| 949 | qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); |
| 950 | |
| 951 | qlcnic_napi_disable(adapter); |
| 952 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 953 | qlcnic_fw_destroy_ctx(adapter); |
| 954 | |
| 955 | qlcnic_reset_rx_buffers_list(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 956 | qlcnic_release_tx_buffers(adapter); |
| 957 | spin_unlock(&adapter->tx_clean_lock); |
| 958 | } |
| 959 | |
| 960 | /* Usage: During suspend and firmware recovery module */ |
| 961 | |
| 962 | static void |
| 963 | qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 964 | { |
| 965 | rtnl_lock(); |
| 966 | if (netif_running(netdev)) |
| 967 | __qlcnic_down(adapter, netdev); |
| 968 | rtnl_unlock(); |
| 969 | |
| 970 | } |
| 971 | |
| 972 | static int |
| 973 | qlcnic_attach(struct qlcnic_adapter *adapter) |
| 974 | { |
| 975 | struct net_device *netdev = adapter->netdev; |
| 976 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 977 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 978 | |
| 979 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) |
| 980 | return 0; |
| 981 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 982 | err = qlcnic_napi_add(adapter, netdev); |
| 983 | if (err) |
| 984 | return err; |
| 985 | |
| 986 | err = qlcnic_alloc_sw_resources(adapter); |
| 987 | if (err) { |
| 988 | dev_err(&pdev->dev, "Error in setting sw resources\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 989 | goto err_out_napi_del; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | err = qlcnic_alloc_hw_resources(adapter); |
| 993 | if (err) { |
| 994 | dev_err(&pdev->dev, "Error in setting hw resources\n"); |
| 995 | goto err_out_free_sw; |
| 996 | } |
| 997 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 998 | err = qlcnic_request_irq(adapter); |
| 999 | if (err) { |
| 1000 | dev_err(&pdev->dev, "failed to setup interrupt\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1001 | goto err_out_free_hw; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | qlcnic_init_coalesce_defaults(adapter); |
| 1005 | |
| 1006 | qlcnic_create_sysfs_entries(adapter); |
| 1007 | |
| 1008 | adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; |
| 1009 | return 0; |
| 1010 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1011 | err_out_free_hw: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1012 | qlcnic_free_hw_resources(adapter); |
| 1013 | err_out_free_sw: |
| 1014 | qlcnic_free_sw_resources(adapter); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1015 | err_out_napi_del: |
| 1016 | qlcnic_napi_del(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1017 | return err; |
| 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | qlcnic_detach(struct qlcnic_adapter *adapter) |
| 1022 | { |
| 1023 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1024 | return; |
| 1025 | |
| 1026 | qlcnic_remove_sysfs_entries(adapter); |
| 1027 | |
| 1028 | qlcnic_free_hw_resources(adapter); |
| 1029 | qlcnic_release_rx_buffers(adapter); |
| 1030 | qlcnic_free_irq(adapter); |
| 1031 | qlcnic_napi_del(adapter); |
| 1032 | qlcnic_free_sw_resources(adapter); |
| 1033 | |
| 1034 | adapter->is_up = 0; |
| 1035 | } |
| 1036 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1037 | void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) |
| 1038 | { |
| 1039 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1040 | struct qlcnic_host_sds_ring *sds_ring; |
| 1041 | int ring; |
| 1042 | |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1043 | clear_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1044 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1045 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1046 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; |
| 1047 | qlcnic_disable_int(sds_ring); |
| 1048 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1051 | qlcnic_fw_destroy_ctx(adapter); |
| 1052 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1053 | qlcnic_detach(adapter); |
| 1054 | |
| 1055 | adapter->diag_test = 0; |
| 1056 | adapter->max_sds_rings = max_sds_rings; |
| 1057 | |
| 1058 | if (qlcnic_attach(adapter)) |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1059 | goto out; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1060 | |
| 1061 | if (netif_running(netdev)) |
| 1062 | __qlcnic_up(adapter, netdev); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1063 | out: |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1064 | netif_device_attach(netdev); |
| 1065 | } |
| 1066 | |
| 1067 | int qlcnic_diag_alloc_res(struct net_device *netdev, int test) |
| 1068 | { |
| 1069 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1070 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1071 | struct qlcnic_host_rds_ring *rds_ring; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1072 | int ring; |
| 1073 | int ret; |
| 1074 | |
| 1075 | netif_device_detach(netdev); |
| 1076 | |
| 1077 | if (netif_running(netdev)) |
| 1078 | __qlcnic_down(adapter, netdev); |
| 1079 | |
| 1080 | qlcnic_detach(adapter); |
| 1081 | |
| 1082 | adapter->max_sds_rings = 1; |
| 1083 | adapter->diag_test = test; |
| 1084 | |
| 1085 | ret = qlcnic_attach(adapter); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1086 | if (ret) { |
| 1087 | netif_device_attach(netdev); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1088 | return ret; |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1089 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1090 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1091 | ret = qlcnic_fw_create_ctx(adapter); |
| 1092 | if (ret) { |
| 1093 | qlcnic_detach(adapter); |
| 1094 | return ret; |
| 1095 | } |
| 1096 | |
| 1097 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1098 | rds_ring = &adapter->recv_ctx.rds_rings[ring]; |
| 1099 | qlcnic_post_rx_buffers(adapter, ring, rds_ring); |
| 1100 | } |
| 1101 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1102 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1103 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1104 | sds_ring = &adapter->recv_ctx.sds_rings[ring]; |
| 1105 | qlcnic_enable_int(sds_ring); |
| 1106 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1107 | } |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1108 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1109 | |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame^] | 1113 | /* Reset context in hardware only */ |
| 1114 | static int |
| 1115 | qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) |
| 1116 | { |
| 1117 | struct net_device *netdev = adapter->netdev; |
| 1118 | |
| 1119 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1120 | return -EBUSY; |
| 1121 | |
| 1122 | netif_device_detach(netdev); |
| 1123 | |
| 1124 | qlcnic_down(adapter, netdev); |
| 1125 | |
| 1126 | qlcnic_up(adapter, netdev); |
| 1127 | |
| 1128 | netif_device_attach(netdev); |
| 1129 | |
| 1130 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1134 | int |
| 1135 | qlcnic_reset_context(struct qlcnic_adapter *adapter) |
| 1136 | { |
| 1137 | int err = 0; |
| 1138 | struct net_device *netdev = adapter->netdev; |
| 1139 | |
| 1140 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1141 | return -EBUSY; |
| 1142 | |
| 1143 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { |
| 1144 | |
| 1145 | netif_device_detach(netdev); |
| 1146 | |
| 1147 | if (netif_running(netdev)) |
| 1148 | __qlcnic_down(adapter, netdev); |
| 1149 | |
| 1150 | qlcnic_detach(adapter); |
| 1151 | |
| 1152 | if (netif_running(netdev)) { |
| 1153 | err = qlcnic_attach(adapter); |
| 1154 | if (!err) |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1155 | __qlcnic_up(adapter, netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | netif_device_attach(netdev); |
| 1159 | } |
| 1160 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1161 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | static int |
| 1166 | qlcnic_setup_netdev(struct qlcnic_adapter *adapter, |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1167 | struct net_device *netdev, u8 pci_using_dac) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1168 | { |
| 1169 | int err; |
| 1170 | struct pci_dev *pdev = adapter->pdev; |
| 1171 | |
| 1172 | adapter->rx_csum = 1; |
| 1173 | adapter->mc_enabled = 0; |
| 1174 | adapter->max_mc_count = 38; |
| 1175 | |
| 1176 | netdev->netdev_ops = &qlcnic_netdev_ops; |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 1177 | netdev->watchdog_timeo = 5*HZ; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1178 | |
| 1179 | qlcnic_change_mtu(netdev, netdev->mtu); |
| 1180 | |
| 1181 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); |
| 1182 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1183 | netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
| 1184 | NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1185 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1186 | netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | |
| 1187 | NETIF_F_IPV6_CSUM | NETIF_F_TSO | NETIF_F_TSO6); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1188 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1189 | if (pci_using_dac) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1190 | netdev->features |= NETIF_F_HIGHDMA; |
| 1191 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1192 | } |
| 1193 | |
| 1194 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) |
| 1195 | netdev->features |= (NETIF_F_HW_VLAN_TX); |
| 1196 | |
| 1197 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
| 1198 | netdev->features |= NETIF_F_LRO; |
| 1199 | |
| 1200 | netdev->irq = adapter->msix_entries[0].vector; |
| 1201 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1202 | if (qlcnic_read_mac_addr(adapter)) |
| 1203 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1204 | |
| 1205 | netif_carrier_off(netdev); |
| 1206 | netif_stop_queue(netdev); |
| 1207 | |
| 1208 | err = register_netdev(netdev); |
| 1209 | if (err) { |
| 1210 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1211 | return err; |
| 1212 | } |
| 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1217 | static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac) |
| 1218 | { |
| 1219 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 1220 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) |
| 1221 | *pci_using_dac = 1; |
| 1222 | else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && |
| 1223 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 1224 | *pci_using_dac = 0; |
| 1225 | else { |
| 1226 | dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); |
| 1227 | return -EIO; |
| 1228 | } |
| 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1233 | static int __devinit |
| 1234 | qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1235 | { |
| 1236 | struct net_device *netdev = NULL; |
| 1237 | struct qlcnic_adapter *adapter = NULL; |
| 1238 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1239 | uint8_t revision_id; |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1240 | uint8_t pci_using_dac; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1241 | |
| 1242 | err = pci_enable_device(pdev); |
| 1243 | if (err) |
| 1244 | return err; |
| 1245 | |
| 1246 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1247 | err = -ENODEV; |
| 1248 | goto err_out_disable_pdev; |
| 1249 | } |
| 1250 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1251 | err = qlcnic_set_dma_mask(pdev, &pci_using_dac); |
| 1252 | if (err) |
| 1253 | goto err_out_disable_pdev; |
| 1254 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1255 | err = pci_request_regions(pdev, qlcnic_driver_name); |
| 1256 | if (err) |
| 1257 | goto err_out_disable_pdev; |
| 1258 | |
| 1259 | pci_set_master(pdev); |
| 1260 | |
| 1261 | netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); |
| 1262 | if (!netdev) { |
| 1263 | dev_err(&pdev->dev, "failed to allocate net_device\n"); |
| 1264 | err = -ENOMEM; |
| 1265 | goto err_out_free_res; |
| 1266 | } |
| 1267 | |
| 1268 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1269 | |
| 1270 | adapter = netdev_priv(netdev); |
| 1271 | adapter->netdev = netdev; |
| 1272 | adapter->pdev = pdev; |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1273 | adapter->dev_rst_time = jiffies; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1274 | |
| 1275 | revision_id = pdev->revision; |
| 1276 | adapter->ahw.revision_id = revision_id; |
| 1277 | |
| 1278 | rwlock_init(&adapter->ahw.crb_lock); |
| 1279 | mutex_init(&adapter->ahw.mem_lock); |
| 1280 | |
| 1281 | spin_lock_init(&adapter->tx_clean_lock); |
| 1282 | INIT_LIST_HEAD(&adapter->mac_list); |
| 1283 | |
| 1284 | err = qlcnic_setup_pci_map(adapter); |
| 1285 | if (err) |
| 1286 | goto err_out_free_netdev; |
| 1287 | |
| 1288 | /* This will be reset for mezz cards */ |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1289 | adapter->portnum = adapter->ahw.pci_func; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1290 | |
| 1291 | err = qlcnic_get_board_info(adapter); |
| 1292 | if (err) { |
| 1293 | dev_err(&pdev->dev, "Error getting board config info.\n"); |
| 1294 | goto err_out_iounmap; |
| 1295 | } |
| 1296 | |
Sucheta Chakraborty | 02f6e46 | 2010-05-17 01:22:09 +0000 | [diff] [blame] | 1297 | if (qlcnic_read_mac_addr(adapter)) |
| 1298 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1299 | |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 1300 | if (qlcnic_setup_idc_param(adapter)) |
| 1301 | goto err_out_iounmap; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1302 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1303 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1304 | if (err) { |
| 1305 | dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1306 | goto err_out_decr_ref; |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1307 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1308 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1309 | qlcnic_clear_stats(adapter); |
| 1310 | |
| 1311 | qlcnic_setup_intr(adapter); |
| 1312 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1313 | err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1314 | if (err) |
| 1315 | goto err_out_disable_msi; |
| 1316 | |
| 1317 | pci_set_drvdata(pdev, adapter); |
| 1318 | |
| 1319 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1320 | |
| 1321 | switch (adapter->ahw.port_type) { |
| 1322 | case QLCNIC_GBE: |
| 1323 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1324 | adapter->netdev->name); |
| 1325 | break; |
| 1326 | case QLCNIC_XGBE: |
| 1327 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1328 | adapter->netdev->name); |
| 1329 | break; |
| 1330 | } |
| 1331 | |
| 1332 | qlcnic_create_diag_entries(adapter); |
| 1333 | |
| 1334 | return 0; |
| 1335 | |
| 1336 | err_out_disable_msi: |
| 1337 | qlcnic_teardown_intr(adapter); |
| 1338 | |
| 1339 | err_out_decr_ref: |
| 1340 | qlcnic_clr_all_drv_state(adapter); |
| 1341 | |
| 1342 | err_out_iounmap: |
| 1343 | qlcnic_cleanup_pci_map(adapter); |
| 1344 | |
| 1345 | err_out_free_netdev: |
| 1346 | free_netdev(netdev); |
| 1347 | |
| 1348 | err_out_free_res: |
| 1349 | pci_release_regions(pdev); |
| 1350 | |
| 1351 | err_out_disable_pdev: |
| 1352 | pci_set_drvdata(pdev, NULL); |
| 1353 | pci_disable_device(pdev); |
| 1354 | return err; |
| 1355 | } |
| 1356 | |
| 1357 | static void __devexit qlcnic_remove(struct pci_dev *pdev) |
| 1358 | { |
| 1359 | struct qlcnic_adapter *adapter; |
| 1360 | struct net_device *netdev; |
| 1361 | |
| 1362 | adapter = pci_get_drvdata(pdev); |
| 1363 | if (adapter == NULL) |
| 1364 | return; |
| 1365 | |
| 1366 | netdev = adapter->netdev; |
| 1367 | |
| 1368 | qlcnic_cancel_fw_work(adapter); |
| 1369 | |
| 1370 | unregister_netdev(netdev); |
| 1371 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1372 | qlcnic_detach(adapter); |
| 1373 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1374 | if (adapter->npars != NULL) |
| 1375 | kfree(adapter->npars); |
| 1376 | if (adapter->eswitch != NULL) |
| 1377 | kfree(adapter->eswitch); |
| 1378 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1379 | qlcnic_clr_all_drv_state(adapter); |
| 1380 | |
| 1381 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1382 | |
| 1383 | qlcnic_teardown_intr(adapter); |
| 1384 | |
| 1385 | qlcnic_remove_diag_entries(adapter); |
| 1386 | |
| 1387 | qlcnic_cleanup_pci_map(adapter); |
| 1388 | |
| 1389 | qlcnic_release_firmware(adapter); |
| 1390 | |
| 1391 | pci_release_regions(pdev); |
| 1392 | pci_disable_device(pdev); |
| 1393 | pci_set_drvdata(pdev, NULL); |
| 1394 | |
| 1395 | free_netdev(netdev); |
| 1396 | } |
| 1397 | static int __qlcnic_shutdown(struct pci_dev *pdev) |
| 1398 | { |
| 1399 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1400 | struct net_device *netdev = adapter->netdev; |
| 1401 | int retval; |
| 1402 | |
| 1403 | netif_device_detach(netdev); |
| 1404 | |
| 1405 | qlcnic_cancel_fw_work(adapter); |
| 1406 | |
| 1407 | if (netif_running(netdev)) |
| 1408 | qlcnic_down(adapter, netdev); |
| 1409 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1410 | qlcnic_clr_all_drv_state(adapter); |
| 1411 | |
| 1412 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1413 | |
| 1414 | retval = pci_save_state(pdev); |
| 1415 | if (retval) |
| 1416 | return retval; |
| 1417 | |
| 1418 | if (qlcnic_wol_supported(adapter)) { |
| 1419 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1420 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1421 | } |
| 1422 | |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
| 1426 | static void qlcnic_shutdown(struct pci_dev *pdev) |
| 1427 | { |
| 1428 | if (__qlcnic_shutdown(pdev)) |
| 1429 | return; |
| 1430 | |
| 1431 | pci_disable_device(pdev); |
| 1432 | } |
| 1433 | |
| 1434 | #ifdef CONFIG_PM |
| 1435 | static int |
| 1436 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1437 | { |
| 1438 | int retval; |
| 1439 | |
| 1440 | retval = __qlcnic_shutdown(pdev); |
| 1441 | if (retval) |
| 1442 | return retval; |
| 1443 | |
| 1444 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
| 1448 | static int |
| 1449 | qlcnic_resume(struct pci_dev *pdev) |
| 1450 | { |
| 1451 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1452 | struct net_device *netdev = adapter->netdev; |
| 1453 | int err; |
| 1454 | |
| 1455 | err = pci_enable_device(pdev); |
| 1456 | if (err) |
| 1457 | return err; |
| 1458 | |
| 1459 | pci_set_power_state(pdev, PCI_D0); |
| 1460 | pci_set_master(pdev); |
| 1461 | pci_restore_state(pdev); |
| 1462 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1463 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1464 | if (err) { |
| 1465 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1466 | return err; |
| 1467 | } |
| 1468 | |
| 1469 | if (netif_running(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1470 | err = qlcnic_up(adapter, netdev); |
| 1471 | if (err) |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1472 | goto done; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1473 | |
| 1474 | qlcnic_config_indev_addr(netdev, NETDEV_UP); |
| 1475 | } |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1476 | done: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1477 | netif_device_attach(netdev); |
| 1478 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1479 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1480 | } |
| 1481 | #endif |
| 1482 | |
| 1483 | static int qlcnic_open(struct net_device *netdev) |
| 1484 | { |
| 1485 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1486 | int err; |
| 1487 | |
| 1488 | if (adapter->driver_mismatch) |
| 1489 | return -EIO; |
| 1490 | |
| 1491 | err = qlcnic_attach(adapter); |
| 1492 | if (err) |
| 1493 | return err; |
| 1494 | |
| 1495 | err = __qlcnic_up(adapter, netdev); |
| 1496 | if (err) |
| 1497 | goto err_out; |
| 1498 | |
| 1499 | netif_start_queue(netdev); |
| 1500 | |
| 1501 | return 0; |
| 1502 | |
| 1503 | err_out: |
| 1504 | qlcnic_detach(adapter); |
| 1505 | return err; |
| 1506 | } |
| 1507 | |
| 1508 | /* |
| 1509 | * qlcnic_close - Disables a network interface entry point |
| 1510 | */ |
| 1511 | static int qlcnic_close(struct net_device *netdev) |
| 1512 | { |
| 1513 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1514 | |
| 1515 | __qlcnic_down(adapter, netdev); |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | static void |
| 1520 | qlcnic_tso_check(struct net_device *netdev, |
| 1521 | struct qlcnic_host_tx_ring *tx_ring, |
| 1522 | struct cmd_desc_type0 *first_desc, |
| 1523 | struct sk_buff *skb) |
| 1524 | { |
| 1525 | u8 opcode = TX_ETHER_PKT; |
| 1526 | __be16 protocol = skb->protocol; |
| 1527 | u16 flags = 0, vid = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1528 | int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; |
| 1529 | struct cmd_desc_type0 *hwdesc; |
| 1530 | struct vlan_ethhdr *vh; |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1531 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1532 | u32 producer = tx_ring->producer; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1533 | |
| 1534 | if (protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 1535 | |
| 1536 | vh = (struct vlan_ethhdr *)skb->data; |
| 1537 | protocol = vh->h_vlan_encapsulated_proto; |
| 1538 | flags = FLAGS_VLAN_TAGGED; |
| 1539 | |
| 1540 | } else if (vlan_tx_tag_present(skb)) { |
| 1541 | |
| 1542 | flags = FLAGS_VLAN_OOB; |
| 1543 | vid = vlan_tx_tag_get(skb); |
| 1544 | qlcnic_set_tx_vlan_tci(first_desc, vid); |
| 1545 | vlan_oob = 1; |
| 1546 | } |
| 1547 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1548 | if (*(skb->data) & BIT_0) { |
| 1549 | flags |= BIT_0; |
| 1550 | memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN); |
| 1551 | } |
| 1552 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1553 | if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) && |
| 1554 | skb_shinfo(skb)->gso_size > 0) { |
| 1555 | |
| 1556 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 1557 | |
| 1558 | first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 1559 | first_desc->total_hdr_length = hdr_len; |
| 1560 | if (vlan_oob) { |
| 1561 | first_desc->total_hdr_length += VLAN_HLEN; |
| 1562 | first_desc->tcp_hdr_offset = VLAN_HLEN; |
| 1563 | first_desc->ip_hdr_offset = VLAN_HLEN; |
| 1564 | /* Only in case of TSO on vlan device */ |
| 1565 | flags |= FLAGS_VLAN_TAGGED; |
| 1566 | } |
| 1567 | |
| 1568 | opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ? |
| 1569 | TX_TCP_LSO6 : TX_TCP_LSO; |
| 1570 | tso = 1; |
| 1571 | |
| 1572 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 1573 | u8 l4proto; |
| 1574 | |
| 1575 | if (protocol == cpu_to_be16(ETH_P_IP)) { |
| 1576 | l4proto = ip_hdr(skb)->protocol; |
| 1577 | |
| 1578 | if (l4proto == IPPROTO_TCP) |
| 1579 | opcode = TX_TCP_PKT; |
| 1580 | else if (l4proto == IPPROTO_UDP) |
| 1581 | opcode = TX_UDP_PKT; |
| 1582 | } else if (protocol == cpu_to_be16(ETH_P_IPV6)) { |
| 1583 | l4proto = ipv6_hdr(skb)->nexthdr; |
| 1584 | |
| 1585 | if (l4proto == IPPROTO_TCP) |
| 1586 | opcode = TX_TCPV6_PKT; |
| 1587 | else if (l4proto == IPPROTO_UDP) |
| 1588 | opcode = TX_UDPV6_PKT; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | first_desc->tcp_hdr_offset += skb_transport_offset(skb); |
| 1593 | first_desc->ip_hdr_offset += skb_network_offset(skb); |
| 1594 | qlcnic_set_tx_flags_opcode(first_desc, flags, opcode); |
| 1595 | |
| 1596 | if (!tso) |
| 1597 | return; |
| 1598 | |
| 1599 | /* For LSO, we need to copy the MAC/IP/TCP headers into |
| 1600 | * the descriptor ring |
| 1601 | */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1602 | copied = 0; |
| 1603 | offset = 2; |
| 1604 | |
| 1605 | if (vlan_oob) { |
| 1606 | /* Create a TSO vlan header template for firmware */ |
| 1607 | |
| 1608 | hwdesc = &tx_ring->desc_head[producer]; |
| 1609 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1610 | |
| 1611 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1612 | hdr_len + VLAN_HLEN); |
| 1613 | |
| 1614 | vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); |
| 1615 | skb_copy_from_linear_data(skb, vh, 12); |
| 1616 | vh->h_vlan_proto = htons(ETH_P_8021Q); |
| 1617 | vh->h_vlan_TCI = htons(vid); |
| 1618 | skb_copy_from_linear_data_offset(skb, 12, |
| 1619 | (char *)vh + 16, copy_len - 16); |
| 1620 | |
| 1621 | copied = copy_len - VLAN_HLEN; |
| 1622 | offset = 0; |
| 1623 | |
| 1624 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1625 | } |
| 1626 | |
| 1627 | while (copied < hdr_len) { |
| 1628 | |
| 1629 | copy_len = min((int)sizeof(struct cmd_desc_type0) - offset, |
| 1630 | (hdr_len - copied)); |
| 1631 | |
| 1632 | hwdesc = &tx_ring->desc_head[producer]; |
| 1633 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1634 | |
| 1635 | skb_copy_from_linear_data_offset(skb, copied, |
| 1636 | (char *)hwdesc + offset, copy_len); |
| 1637 | |
| 1638 | copied += copy_len; |
| 1639 | offset = 0; |
| 1640 | |
| 1641 | producer = get_next_index(producer, tx_ring->num_desc); |
| 1642 | } |
| 1643 | |
| 1644 | tx_ring->producer = producer; |
| 1645 | barrier(); |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 1646 | adapter->stats.lso_frames++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | static int |
| 1650 | qlcnic_map_tx_skb(struct pci_dev *pdev, |
| 1651 | struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf) |
| 1652 | { |
| 1653 | struct qlcnic_skb_frag *nf; |
| 1654 | struct skb_frag_struct *frag; |
| 1655 | int i, nr_frags; |
| 1656 | dma_addr_t map; |
| 1657 | |
| 1658 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1659 | nf = &pbuf->frag_array[0]; |
| 1660 | |
| 1661 | map = pci_map_single(pdev, skb->data, |
| 1662 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 1663 | if (pci_dma_mapping_error(pdev, map)) |
| 1664 | goto out_err; |
| 1665 | |
| 1666 | nf->dma = map; |
| 1667 | nf->length = skb_headlen(skb); |
| 1668 | |
| 1669 | for (i = 0; i < nr_frags; i++) { |
| 1670 | frag = &skb_shinfo(skb)->frags[i]; |
| 1671 | nf = &pbuf->frag_array[i+1]; |
| 1672 | |
| 1673 | map = pci_map_page(pdev, frag->page, frag->page_offset, |
| 1674 | frag->size, PCI_DMA_TODEVICE); |
| 1675 | if (pci_dma_mapping_error(pdev, map)) |
| 1676 | goto unwind; |
| 1677 | |
| 1678 | nf->dma = map; |
| 1679 | nf->length = frag->size; |
| 1680 | } |
| 1681 | |
| 1682 | return 0; |
| 1683 | |
| 1684 | unwind: |
| 1685 | while (--i >= 0) { |
| 1686 | nf = &pbuf->frag_array[i+1]; |
| 1687 | pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE); |
| 1688 | } |
| 1689 | |
| 1690 | nf = &pbuf->frag_array[0]; |
| 1691 | pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE); |
| 1692 | |
| 1693 | out_err: |
| 1694 | return -ENOMEM; |
| 1695 | } |
| 1696 | |
| 1697 | static inline void |
| 1698 | qlcnic_clear_cmddesc(u64 *desc) |
| 1699 | { |
| 1700 | desc[0] = 0ULL; |
| 1701 | desc[2] = 0ULL; |
| 1702 | } |
| 1703 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1704 | netdev_tx_t |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1705 | qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 1706 | { |
| 1707 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1708 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 1709 | struct qlcnic_cmd_buffer *pbuf; |
| 1710 | struct qlcnic_skb_frag *buffrag; |
| 1711 | struct cmd_desc_type0 *hwdesc, *first_desc; |
| 1712 | struct pci_dev *pdev; |
| 1713 | int i, k; |
| 1714 | |
| 1715 | u32 producer; |
| 1716 | int frag_count, no_of_desc; |
| 1717 | u32 num_txd = tx_ring->num_desc; |
| 1718 | |
Amit Kumar Salecha | 780ab79 | 2010-04-22 02:51:41 +0000 | [diff] [blame] | 1719 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
| 1720 | netif_stop_queue(netdev); |
| 1721 | return NETDEV_TX_BUSY; |
| 1722 | } |
| 1723 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1724 | frag_count = skb_shinfo(skb)->nr_frags + 1; |
| 1725 | |
| 1726 | /* 4 fragments per cmd des */ |
| 1727 | no_of_desc = (frag_count + 3) >> 2; |
| 1728 | |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 1729 | if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1730 | netif_stop_queue(netdev); |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 1731 | smp_mb(); |
| 1732 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) |
| 1733 | netif_start_queue(netdev); |
| 1734 | else { |
| 1735 | adapter->stats.xmit_off++; |
| 1736 | return NETDEV_TX_BUSY; |
| 1737 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | producer = tx_ring->producer; |
| 1741 | pbuf = &tx_ring->cmd_buf_arr[producer]; |
| 1742 | |
| 1743 | pdev = adapter->pdev; |
| 1744 | |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 1745 | if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { |
| 1746 | adapter->stats.tx_dma_map_error++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1747 | goto drop_packet; |
Amit Kumar Salecha | 8ae6df9 | 2010-04-22 02:51:35 +0000 | [diff] [blame] | 1748 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1749 | |
| 1750 | pbuf->skb = skb; |
| 1751 | pbuf->frag_count = frag_count; |
| 1752 | |
| 1753 | first_desc = hwdesc = &tx_ring->desc_head[producer]; |
| 1754 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 1755 | |
| 1756 | qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); |
| 1757 | qlcnic_set_tx_port(first_desc, adapter->portnum); |
| 1758 | |
| 1759 | for (i = 0; i < frag_count; i++) { |
| 1760 | |
| 1761 | k = i % 4; |
| 1762 | |
| 1763 | if ((k == 0) && (i > 0)) { |
| 1764 | /* move to next desc.*/ |
| 1765 | producer = get_next_index(producer, num_txd); |
| 1766 | hwdesc = &tx_ring->desc_head[producer]; |
| 1767 | qlcnic_clear_cmddesc((u64 *)hwdesc); |
| 1768 | tx_ring->cmd_buf_arr[producer].skb = NULL; |
| 1769 | } |
| 1770 | |
| 1771 | buffrag = &pbuf->frag_array[i]; |
| 1772 | |
| 1773 | hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length); |
| 1774 | switch (k) { |
| 1775 | case 0: |
| 1776 | hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma); |
| 1777 | break; |
| 1778 | case 1: |
| 1779 | hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma); |
| 1780 | break; |
| 1781 | case 2: |
| 1782 | hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma); |
| 1783 | break; |
| 1784 | case 3: |
| 1785 | hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma); |
| 1786 | break; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | tx_ring->producer = get_next_index(producer, num_txd); |
| 1791 | |
| 1792 | qlcnic_tso_check(netdev, tx_ring, first_desc, skb); |
| 1793 | |
| 1794 | qlcnic_update_cmd_producer(adapter, tx_ring); |
| 1795 | |
| 1796 | adapter->stats.txbytes += skb->len; |
| 1797 | adapter->stats.xmitcalled++; |
| 1798 | |
| 1799 | return NETDEV_TX_OK; |
| 1800 | |
| 1801 | drop_packet: |
| 1802 | adapter->stats.txdropped++; |
| 1803 | dev_kfree_skb_any(skb); |
| 1804 | return NETDEV_TX_OK; |
| 1805 | } |
| 1806 | |
| 1807 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) |
| 1808 | { |
| 1809 | struct net_device *netdev = adapter->netdev; |
| 1810 | u32 temp, temp_state, temp_val; |
| 1811 | int rv = 0; |
| 1812 | |
| 1813 | temp = QLCRD32(adapter, CRB_TEMP_STATE); |
| 1814 | |
| 1815 | temp_state = qlcnic_get_temp_state(temp); |
| 1816 | temp_val = qlcnic_get_temp_val(temp); |
| 1817 | |
| 1818 | if (temp_state == QLCNIC_TEMP_PANIC) { |
| 1819 | dev_err(&netdev->dev, |
| 1820 | "Device temperature %d degrees C exceeds" |
| 1821 | " maximum allowed. Hardware has been shut down.\n", |
| 1822 | temp_val); |
| 1823 | rv = 1; |
| 1824 | } else if (temp_state == QLCNIC_TEMP_WARN) { |
| 1825 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { |
| 1826 | dev_err(&netdev->dev, |
| 1827 | "Device temperature %d degrees C " |
| 1828 | "exceeds operating range." |
| 1829 | " Immediate action needed.\n", |
| 1830 | temp_val); |
| 1831 | } |
| 1832 | } else { |
| 1833 | if (adapter->temp == QLCNIC_TEMP_WARN) { |
| 1834 | dev_info(&netdev->dev, |
| 1835 | "Device temperature is now %d degrees C" |
| 1836 | " in normal range.\n", temp_val); |
| 1837 | } |
| 1838 | } |
| 1839 | adapter->temp = temp_state; |
| 1840 | return rv; |
| 1841 | } |
| 1842 | |
| 1843 | void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup) |
| 1844 | { |
| 1845 | struct net_device *netdev = adapter->netdev; |
| 1846 | |
| 1847 | if (adapter->ahw.linkup && !linkup) { |
| 1848 | dev_info(&netdev->dev, "NIC Link is down\n"); |
| 1849 | adapter->ahw.linkup = 0; |
| 1850 | if (netif_running(netdev)) { |
| 1851 | netif_carrier_off(netdev); |
| 1852 | netif_stop_queue(netdev); |
| 1853 | } |
| 1854 | } else if (!adapter->ahw.linkup && linkup) { |
| 1855 | dev_info(&netdev->dev, "NIC Link is up\n"); |
| 1856 | adapter->ahw.linkup = 1; |
| 1857 | if (netif_running(netdev)) { |
| 1858 | netif_carrier_on(netdev); |
| 1859 | netif_wake_queue(netdev); |
| 1860 | } |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | static void qlcnic_tx_timeout(struct net_device *netdev) |
| 1865 | { |
| 1866 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1867 | |
| 1868 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1869 | return; |
| 1870 | |
| 1871 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1872 | |
| 1873 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame^] | 1874 | adapter->need_fw_reset = 1; |
| 1875 | else |
| 1876 | adapter->reset_context = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) |
| 1880 | { |
| 1881 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1882 | struct net_device_stats *stats = &netdev->stats; |
| 1883 | |
| 1884 | memset(stats, 0, sizeof(*stats)); |
| 1885 | |
| 1886 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
| 1887 | stats->tx_packets = adapter->stats.xmitfinished; |
Sucheta Chakraborty | 7e38259 | 2010-05-17 01:22:10 +0000 | [diff] [blame] | 1888 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1889 | stats->tx_bytes = adapter->stats.txbytes; |
| 1890 | stats->rx_dropped = adapter->stats.rxdropped; |
| 1891 | stats->tx_dropped = adapter->stats.txdropped; |
| 1892 | |
| 1893 | return stats; |
| 1894 | } |
| 1895 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1896 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1897 | { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1898 | u32 status; |
| 1899 | |
| 1900 | status = readl(adapter->isr_int_vec); |
| 1901 | |
| 1902 | if (!(status & adapter->int_vec_bit)) |
| 1903 | return IRQ_NONE; |
| 1904 | |
| 1905 | /* check interrupt state machine, to be sure */ |
| 1906 | status = readl(adapter->crb_int_state_reg); |
| 1907 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 1908 | return IRQ_NONE; |
| 1909 | |
| 1910 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1911 | /* read twice to ensure write is flushed */ |
| 1912 | readl(adapter->isr_int_vec); |
| 1913 | readl(adapter->isr_int_vec); |
| 1914 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1915 | return IRQ_HANDLED; |
| 1916 | } |
| 1917 | |
| 1918 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) |
| 1919 | { |
| 1920 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1921 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1922 | |
| 1923 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 1924 | goto done; |
| 1925 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { |
| 1926 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1927 | goto done; |
| 1928 | } |
| 1929 | |
| 1930 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1931 | return IRQ_NONE; |
| 1932 | |
| 1933 | done: |
| 1934 | adapter->diag_cnt++; |
| 1935 | qlcnic_enable_int(sds_ring); |
| 1936 | return IRQ_HANDLED; |
| 1937 | } |
| 1938 | |
| 1939 | static irqreturn_t qlcnic_intr(int irq, void *data) |
| 1940 | { |
| 1941 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1942 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1943 | |
| 1944 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1945 | return IRQ_NONE; |
| 1946 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1947 | napi_schedule(&sds_ring->napi); |
| 1948 | |
| 1949 | return IRQ_HANDLED; |
| 1950 | } |
| 1951 | |
| 1952 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) |
| 1953 | { |
| 1954 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1955 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1956 | |
| 1957 | /* clear interrupt */ |
| 1958 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1959 | |
| 1960 | napi_schedule(&sds_ring->napi); |
| 1961 | return IRQ_HANDLED; |
| 1962 | } |
| 1963 | |
| 1964 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) |
| 1965 | { |
| 1966 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1967 | |
| 1968 | napi_schedule(&sds_ring->napi); |
| 1969 | return IRQ_HANDLED; |
| 1970 | } |
| 1971 | |
| 1972 | static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter) |
| 1973 | { |
| 1974 | u32 sw_consumer, hw_consumer; |
| 1975 | int count = 0, i; |
| 1976 | struct qlcnic_cmd_buffer *buffer; |
| 1977 | struct pci_dev *pdev = adapter->pdev; |
| 1978 | struct net_device *netdev = adapter->netdev; |
| 1979 | struct qlcnic_skb_frag *frag; |
| 1980 | int done; |
| 1981 | struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring; |
| 1982 | |
| 1983 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 1984 | return 1; |
| 1985 | |
| 1986 | sw_consumer = tx_ring->sw_consumer; |
| 1987 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 1988 | |
| 1989 | while (sw_consumer != hw_consumer) { |
| 1990 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
| 1991 | if (buffer->skb) { |
| 1992 | frag = &buffer->frag_array[0]; |
| 1993 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 1994 | PCI_DMA_TODEVICE); |
| 1995 | frag->dma = 0ULL; |
| 1996 | for (i = 1; i < buffer->frag_count; i++) { |
| 1997 | frag++; |
| 1998 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 1999 | PCI_DMA_TODEVICE); |
| 2000 | frag->dma = 0ULL; |
| 2001 | } |
| 2002 | |
| 2003 | adapter->stats.xmitfinished++; |
| 2004 | dev_kfree_skb_any(buffer->skb); |
| 2005 | buffer->skb = NULL; |
| 2006 | } |
| 2007 | |
| 2008 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
| 2009 | if (++count >= MAX_STATUS_HANDLE) |
| 2010 | break; |
| 2011 | } |
| 2012 | |
| 2013 | if (count && netif_running(netdev)) { |
| 2014 | tx_ring->sw_consumer = sw_consumer; |
| 2015 | |
| 2016 | smp_mb(); |
| 2017 | |
| 2018 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2019 | if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) { |
| 2020 | netif_wake_queue(netdev); |
Sucheta Chakraborty | 8bfe8b9 | 2010-03-08 00:14:46 +0000 | [diff] [blame] | 2021 | adapter->stats.xmit_on++; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2022 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2023 | } |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 2024 | adapter->tx_timeo_cnt = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2025 | } |
| 2026 | /* |
| 2027 | * If everything is freed up to consumer then check if the ring is full |
| 2028 | * If the ring is full then check if more needs to be freed and |
| 2029 | * schedule the call back again. |
| 2030 | * |
| 2031 | * This happens when there are 2 CPUs. One could be freeing and the |
| 2032 | * other filling it. If the ring is full when we get out of here and |
| 2033 | * the card has already interrupted the host then the host can miss the |
| 2034 | * interrupt. |
| 2035 | * |
| 2036 | * There is still a possible race condition and the host could miss an |
| 2037 | * interrupt. The card has to take care of this. |
| 2038 | */ |
| 2039 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 2040 | done = (sw_consumer == hw_consumer); |
| 2041 | spin_unlock(&adapter->tx_clean_lock); |
| 2042 | |
| 2043 | return done; |
| 2044 | } |
| 2045 | |
| 2046 | static int qlcnic_poll(struct napi_struct *napi, int budget) |
| 2047 | { |
| 2048 | struct qlcnic_host_sds_ring *sds_ring = |
| 2049 | container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 2050 | |
| 2051 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2052 | |
| 2053 | int tx_complete; |
| 2054 | int work_done; |
| 2055 | |
| 2056 | tx_complete = qlcnic_process_cmd_ring(adapter); |
| 2057 | |
| 2058 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
| 2059 | |
| 2060 | if ((work_done < budget) && tx_complete) { |
| 2061 | napi_complete(&sds_ring->napi); |
| 2062 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 2063 | qlcnic_enable_int(sds_ring); |
| 2064 | } |
| 2065 | |
| 2066 | return work_done; |
| 2067 | } |
| 2068 | |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 2069 | static int qlcnic_rx_poll(struct napi_struct *napi, int budget) |
| 2070 | { |
| 2071 | struct qlcnic_host_sds_ring *sds_ring = |
| 2072 | container_of(napi, struct qlcnic_host_sds_ring, napi); |
| 2073 | |
| 2074 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 2075 | int work_done; |
| 2076 | |
| 2077 | work_done = qlcnic_process_rcv_ring(sds_ring, budget); |
| 2078 | |
| 2079 | if (work_done < budget) { |
| 2080 | napi_complete(&sds_ring->napi); |
| 2081 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 2082 | qlcnic_enable_int(sds_ring); |
| 2083 | } |
| 2084 | |
| 2085 | return work_done; |
| 2086 | } |
| 2087 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2088 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2089 | static void qlcnic_poll_controller(struct net_device *netdev) |
| 2090 | { |
| 2091 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2092 | disable_irq(adapter->irq); |
| 2093 | qlcnic_intr(adapter->irq, adapter); |
| 2094 | enable_irq(adapter->irq); |
| 2095 | } |
| 2096 | #endif |
| 2097 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2098 | static void |
| 2099 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) |
| 2100 | { |
| 2101 | u32 val; |
| 2102 | |
| 2103 | val = adapter->portnum & 0xf; |
| 2104 | val |= encoding << 7; |
| 2105 | val |= (jiffies - adapter->dev_rst_time) << 8; |
| 2106 | |
| 2107 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); |
| 2108 | adapter->dev_rst_time = jiffies; |
| 2109 | } |
| 2110 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2111 | static int |
| 2112 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2113 | { |
| 2114 | u32 val; |
| 2115 | |
| 2116 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && |
| 2117 | state != QLCNIC_DEV_NEED_QUISCENT); |
| 2118 | |
| 2119 | if (qlcnic_api_lock(adapter)) |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2120 | return -EIO; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2121 | |
| 2122 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2123 | |
| 2124 | if (state == QLCNIC_DEV_NEED_RESET) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2125 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2126 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2127 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2128 | |
| 2129 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2130 | |
| 2131 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2132 | |
| 2133 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2136 | static int |
| 2137 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) |
| 2138 | { |
| 2139 | u32 val; |
| 2140 | |
| 2141 | if (qlcnic_api_lock(adapter)) |
| 2142 | return -EBUSY; |
| 2143 | |
| 2144 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2145 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2146 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2147 | |
| 2148 | qlcnic_api_unlock(adapter); |
| 2149 | |
| 2150 | return 0; |
| 2151 | } |
| 2152 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2153 | static void |
| 2154 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter) |
| 2155 | { |
| 2156 | u32 val; |
| 2157 | |
| 2158 | if (qlcnic_api_lock(adapter)) |
| 2159 | goto err; |
| 2160 | |
| 2161 | val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2162 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2163 | QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); |
| 2164 | |
| 2165 | if (!(val & 0x11111111)) |
| 2166 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); |
| 2167 | |
| 2168 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2169 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2170 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2171 | |
| 2172 | qlcnic_api_unlock(adapter); |
| 2173 | err: |
| 2174 | adapter->fw_fail_cnt = 0; |
| 2175 | clear_bit(__QLCNIC_START_FW, &adapter->state); |
| 2176 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2177 | } |
| 2178 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2179 | /* Grab api lock, before checking state */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2180 | static int |
| 2181 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) |
| 2182 | { |
| 2183 | int act, state; |
| 2184 | |
| 2185 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2186 | act = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); |
| 2187 | |
| 2188 | if (((state & 0x11111111) == (act & 0x11111111)) || |
| 2189 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) |
| 2190 | return 0; |
| 2191 | else |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2195 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
| 2196 | { |
| 2197 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); |
| 2198 | |
| 2199 | if (val != QLCNIC_DRV_IDC_VER) { |
| 2200 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" |
| 2201 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); |
| 2202 | } |
| 2203 | |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2207 | static int |
| 2208 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) |
| 2209 | { |
| 2210 | u32 val, prev_state; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2211 | u8 dev_init_timeo = adapter->dev_init_timeo; |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2212 | u8 portnum = adapter->portnum; |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2213 | u8 ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2214 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2215 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
| 2216 | return 1; |
| 2217 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2218 | if (qlcnic_api_lock(adapter)) |
| 2219 | return -1; |
| 2220 | |
| 2221 | val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2222 | if (!(val & (1 << (portnum * 4)))) { |
| 2223 | QLC_DEV_SET_REF_CNT(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2224 | QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2228 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2229 | |
| 2230 | switch (prev_state) { |
| 2231 | case QLCNIC_DEV_COLD: |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2232 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2233 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2234 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2235 | qlcnic_api_unlock(adapter); |
| 2236 | return 1; |
| 2237 | |
| 2238 | case QLCNIC_DEV_READY: |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2239 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2240 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2241 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2242 | |
| 2243 | case QLCNIC_DEV_NEED_RESET: |
| 2244 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2245 | QLC_DEV_SET_RST_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2246 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2247 | break; |
| 2248 | |
| 2249 | case QLCNIC_DEV_NEED_QUISCENT: |
| 2250 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2251 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2252 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2253 | break; |
| 2254 | |
| 2255 | case QLCNIC_DEV_FAILED: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 2256 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2257 | qlcnic_api_unlock(adapter); |
| 2258 | return -1; |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2259 | |
| 2260 | case QLCNIC_DEV_INITIALIZING: |
| 2261 | case QLCNIC_DEV_QUISCENT: |
| 2262 | break; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2266 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2267 | do { |
| 2268 | msleep(1000); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2269 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2270 | |
| 2271 | if (prev_state == QLCNIC_DEV_QUISCENT) |
| 2272 | continue; |
| 2273 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2274 | |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2275 | if (!dev_init_timeo) { |
| 2276 | dev_err(&adapter->pdev->dev, |
| 2277 | "Waiting for device to initialize timeout\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2278 | return -1; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2279 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2280 | |
| 2281 | if (qlcnic_api_lock(adapter)) |
| 2282 | return -1; |
| 2283 | |
| 2284 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2285 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2286 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2287 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2288 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2289 | qlcnic_api_unlock(adapter); |
| 2290 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2291 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | static void |
| 2295 | qlcnic_fwinit_work(struct work_struct *work) |
| 2296 | { |
| 2297 | struct qlcnic_adapter *adapter = container_of(work, |
| 2298 | struct qlcnic_adapter, fw_work.work); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2299 | u32 dev_state = 0xf, npar_state; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2300 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2301 | if (qlcnic_api_lock(adapter)) |
| 2302 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2303 | |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2304 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2305 | if (dev_state == QLCNIC_DEV_QUISCENT) { |
| 2306 | qlcnic_api_unlock(adapter); |
| 2307 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2308 | FW_POLL_DELAY * 2); |
| 2309 | return; |
| 2310 | } |
| 2311 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2312 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
| 2313 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2314 | if (npar_state == QLCNIC_DEV_NPAR_RDY) { |
| 2315 | qlcnic_api_unlock(adapter); |
| 2316 | goto wait_npar; |
| 2317 | } else { |
| 2318 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2319 | FW_POLL_DELAY); |
| 2320 | qlcnic_api_unlock(adapter); |
| 2321 | return; |
| 2322 | } |
| 2323 | } |
| 2324 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2325 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
| 2326 | dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", |
| 2327 | adapter->reset_ack_timeo); |
| 2328 | goto skip_ack_check; |
| 2329 | } |
| 2330 | |
| 2331 | if (!qlcnic_check_drv_state(adapter)) { |
| 2332 | skip_ack_check: |
| 2333 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2334 | |
| 2335 | if (dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
| 2336 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2337 | QLCNIC_DEV_QUISCENT); |
| 2338 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2339 | FW_POLL_DELAY * 2); |
| 2340 | QLCDB(adapter, DRV, "Quiscing the driver\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2341 | qlcnic_idc_debug_info(adapter, 0); |
| 2342 | |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2343 | qlcnic_api_unlock(adapter); |
| 2344 | return; |
| 2345 | } |
| 2346 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2347 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
| 2348 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2349 | QLCNIC_DEV_INITIALIZING); |
| 2350 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2351 | QLCDB(adapter, DRV, "Restarting fw\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2352 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2355 | qlcnic_api_unlock(adapter); |
| 2356 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2357 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2358 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
| 2359 | return; |
| 2360 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2361 | goto err_ret; |
| 2362 | } |
| 2363 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2364 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2365 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2366 | wait_npar: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2367 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2368 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2369 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2370 | switch (dev_state) { |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2371 | case QLCNIC_DEV_QUISCENT: |
| 2372 | case QLCNIC_DEV_NEED_QUISCENT: |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2373 | case QLCNIC_DEV_NEED_RESET: |
| 2374 | qlcnic_schedule_work(adapter, |
| 2375 | qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2376 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2377 | case QLCNIC_DEV_FAILED: |
| 2378 | break; |
| 2379 | |
| 2380 | default: |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2381 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2382 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
| 2383 | return; |
| 2384 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | err_ret: |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2388 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
| 2389 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2390 | netif_device_attach(adapter->netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2391 | qlcnic_clr_all_drv_state(adapter); |
| 2392 | } |
| 2393 | |
| 2394 | static void |
| 2395 | qlcnic_detach_work(struct work_struct *work) |
| 2396 | { |
| 2397 | struct qlcnic_adapter *adapter = container_of(work, |
| 2398 | struct qlcnic_adapter, fw_work.work); |
| 2399 | struct net_device *netdev = adapter->netdev; |
| 2400 | u32 status; |
| 2401 | |
| 2402 | netif_device_detach(netdev); |
| 2403 | |
| 2404 | qlcnic_down(adapter, netdev); |
| 2405 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2406 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
| 2407 | |
| 2408 | if (status & QLCNIC_RCODE_FATAL_ERROR) |
| 2409 | goto err_ret; |
| 2410 | |
| 2411 | if (adapter->temp == QLCNIC_TEMP_PANIC) |
| 2412 | goto err_ret; |
| 2413 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2414 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) |
| 2415 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2416 | |
| 2417 | adapter->fw_wait_cnt = 0; |
| 2418 | |
| 2419 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2420 | |
| 2421 | return; |
| 2422 | |
| 2423 | err_ret: |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2424 | dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n", |
| 2425 | status, adapter->temp); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2426 | netif_device_attach(netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2427 | qlcnic_clr_all_drv_state(adapter); |
| 2428 | |
| 2429 | } |
| 2430 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2431 | /*Transit to RESET state from READY state only */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2432 | static void |
| 2433 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) |
| 2434 | { |
| 2435 | u32 state; |
| 2436 | |
| 2437 | if (qlcnic_api_lock(adapter)) |
| 2438 | return; |
| 2439 | |
| 2440 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2441 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2442 | if (state == QLCNIC_DEV_READY) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2443 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2444 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2445 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | qlcnic_api_unlock(adapter); |
| 2449 | } |
| 2450 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2451 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
| 2452 | static void |
| 2453 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) |
| 2454 | { |
| 2455 | u32 state; |
| 2456 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2457 | if (qlcnic_api_lock(adapter)) |
| 2458 | return; |
| 2459 | |
| 2460 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2461 | |
| 2462 | if (state != QLCNIC_DEV_NPAR_RDY) { |
| 2463 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, |
| 2464 | QLCNIC_DEV_NPAR_RDY); |
| 2465 | QLCDB(adapter, DRV, "NPAR READY state set\n"); |
| 2466 | } |
| 2467 | |
| 2468 | qlcnic_api_unlock(adapter); |
| 2469 | } |
| 2470 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2471 | static void |
| 2472 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 2473 | work_func_t func, int delay) |
| 2474 | { |
| 2475 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
| 2476 | schedule_delayed_work(&adapter->fw_work, round_jiffies_relative(delay)); |
| 2477 | } |
| 2478 | |
| 2479 | static void |
| 2480 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) |
| 2481 | { |
| 2482 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2483 | msleep(10); |
| 2484 | |
| 2485 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2486 | } |
| 2487 | |
| 2488 | static void |
| 2489 | qlcnic_attach_work(struct work_struct *work) |
| 2490 | { |
| 2491 | struct qlcnic_adapter *adapter = container_of(work, |
| 2492 | struct qlcnic_adapter, fw_work.work); |
| 2493 | struct net_device *netdev = adapter->netdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2494 | |
| 2495 | if (netif_running(netdev)) { |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 2496 | if (qlcnic_up(adapter, netdev)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2497 | goto done; |
| 2498 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2499 | qlcnic_config_indev_addr(netdev, NETDEV_UP); |
| 2500 | } |
| 2501 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2502 | done: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2503 | netif_device_attach(netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2504 | adapter->fw_fail_cnt = 0; |
| 2505 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2506 | |
| 2507 | if (!qlcnic_clr_drv_state(adapter)) |
| 2508 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2509 | FW_POLL_DELAY); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | static int |
| 2513 | qlcnic_check_health(struct qlcnic_adapter *adapter) |
| 2514 | { |
| 2515 | u32 state = 0, heartbit; |
| 2516 | struct net_device *netdev = adapter->netdev; |
| 2517 | |
| 2518 | if (qlcnic_check_temp(adapter)) |
| 2519 | goto detach; |
| 2520 | |
Amit Kumar Salecha | 2372a5f | 2010-05-13 03:07:42 +0000 | [diff] [blame] | 2521 | if (adapter->need_fw_reset) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2522 | qlcnic_dev_request_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2523 | |
| 2524 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2525 | if (state == QLCNIC_DEV_NEED_RESET || state == QLCNIC_DEV_NEED_QUISCENT) |
| 2526 | adapter->need_fw_reset = 1; |
| 2527 | |
| 2528 | heartbit = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 2529 | if (heartbit != adapter->heartbit) { |
| 2530 | adapter->heartbit = heartbit; |
| 2531 | adapter->fw_fail_cnt = 0; |
| 2532 | if (adapter->need_fw_reset) |
| 2533 | goto detach; |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame^] | 2534 | |
| 2535 | if (adapter->reset_context) { |
| 2536 | qlcnic_reset_hw_context(adapter); |
| 2537 | adapter->netdev->trans_start = jiffies; |
| 2538 | } |
| 2539 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2540 | return 0; |
| 2541 | } |
| 2542 | |
| 2543 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) |
| 2544 | return 0; |
| 2545 | |
| 2546 | qlcnic_dev_request_reset(adapter); |
| 2547 | |
| 2548 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); |
| 2549 | |
| 2550 | dev_info(&netdev->dev, "firmware hang detected\n"); |
| 2551 | |
| 2552 | detach: |
| 2553 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : |
| 2554 | QLCNIC_DEV_NEED_RESET; |
| 2555 | |
| 2556 | if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) && |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2557 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
| 2558 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2559 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2560 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
| 2561 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2562 | |
| 2563 | return 1; |
| 2564 | } |
| 2565 | |
| 2566 | static void |
| 2567 | qlcnic_fw_poll_work(struct work_struct *work) |
| 2568 | { |
| 2569 | struct qlcnic_adapter *adapter = container_of(work, |
| 2570 | struct qlcnic_adapter, fw_work.work); |
| 2571 | |
| 2572 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2573 | goto reschedule; |
| 2574 | |
| 2575 | |
| 2576 | if (qlcnic_check_health(adapter)) |
| 2577 | return; |
| 2578 | |
| 2579 | reschedule: |
| 2580 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 2581 | } |
| 2582 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2583 | static int |
| 2584 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) |
| 2585 | { |
| 2586 | int err; |
| 2587 | |
| 2588 | err = qlcnic_can_start_firmware(adapter); |
| 2589 | if (err) |
| 2590 | return err; |
| 2591 | |
| 2592 | qlcnic_check_options(adapter); |
| 2593 | |
| 2594 | adapter->need_fw_reset = 0; |
| 2595 | |
| 2596 | return err; |
| 2597 | } |
| 2598 | |
| 2599 | static int |
| 2600 | qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) |
| 2601 | { |
| 2602 | return -EOPNOTSUPP; |
| 2603 | } |
| 2604 | |
| 2605 | static int |
| 2606 | qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) |
| 2607 | { |
| 2608 | return -EOPNOTSUPP; |
| 2609 | } |
| 2610 | |
| 2611 | static int |
| 2612 | qlcnicvf_set_ilb_mode(struct qlcnic_adapter *adapter) |
| 2613 | { |
| 2614 | return -EOPNOTSUPP; |
| 2615 | } |
| 2616 | |
| 2617 | static void |
| 2618 | qlcnicvf_clear_ilb_mode(struct qlcnic_adapter *adapter) |
| 2619 | { |
| 2620 | return; |
| 2621 | } |
| 2622 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2623 | static ssize_t |
| 2624 | qlcnic_store_bridged_mode(struct device *dev, |
| 2625 | struct device_attribute *attr, const char *buf, size_t len) |
| 2626 | { |
| 2627 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2628 | unsigned long new; |
| 2629 | int ret = -EINVAL; |
| 2630 | |
| 2631 | if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)) |
| 2632 | goto err_out; |
| 2633 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2634 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2635 | goto err_out; |
| 2636 | |
| 2637 | if (strict_strtoul(buf, 2, &new)) |
| 2638 | goto err_out; |
| 2639 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 2640 | if (!adapter->nic_ops->config_bridged_mode(adapter, !!new)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2641 | ret = len; |
| 2642 | |
| 2643 | err_out: |
| 2644 | return ret; |
| 2645 | } |
| 2646 | |
| 2647 | static ssize_t |
| 2648 | qlcnic_show_bridged_mode(struct device *dev, |
| 2649 | struct device_attribute *attr, char *buf) |
| 2650 | { |
| 2651 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2652 | int bridged_mode = 0; |
| 2653 | |
| 2654 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 2655 | bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); |
| 2656 | |
| 2657 | return sprintf(buf, "%d\n", bridged_mode); |
| 2658 | } |
| 2659 | |
| 2660 | static struct device_attribute dev_attr_bridged_mode = { |
| 2661 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 2662 | .show = qlcnic_show_bridged_mode, |
| 2663 | .store = qlcnic_store_bridged_mode, |
| 2664 | }; |
| 2665 | |
| 2666 | static ssize_t |
| 2667 | qlcnic_store_diag_mode(struct device *dev, |
| 2668 | struct device_attribute *attr, const char *buf, size_t len) |
| 2669 | { |
| 2670 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2671 | unsigned long new; |
| 2672 | |
| 2673 | if (strict_strtoul(buf, 2, &new)) |
| 2674 | return -EINVAL; |
| 2675 | |
| 2676 | if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 2677 | adapter->flags ^= QLCNIC_DIAG_ENABLED; |
| 2678 | |
| 2679 | return len; |
| 2680 | } |
| 2681 | |
| 2682 | static ssize_t |
| 2683 | qlcnic_show_diag_mode(struct device *dev, |
| 2684 | struct device_attribute *attr, char *buf) |
| 2685 | { |
| 2686 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2687 | |
| 2688 | return sprintf(buf, "%d\n", |
| 2689 | !!(adapter->flags & QLCNIC_DIAG_ENABLED)); |
| 2690 | } |
| 2691 | |
| 2692 | static struct device_attribute dev_attr_diag_mode = { |
| 2693 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 2694 | .show = qlcnic_show_diag_mode, |
| 2695 | .store = qlcnic_store_diag_mode, |
| 2696 | }; |
| 2697 | |
| 2698 | static int |
| 2699 | qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, |
| 2700 | loff_t offset, size_t size) |
| 2701 | { |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2702 | size_t crb_size = 4; |
| 2703 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2704 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 2705 | return -EIO; |
| 2706 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2707 | if (offset < QLCNIC_PCI_CRBSPACE) { |
| 2708 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, |
| 2709 | QLCNIC_PCI_CAMQM_END)) |
| 2710 | crb_size = 8; |
| 2711 | else |
| 2712 | return -EINVAL; |
| 2713 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2714 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2715 | if ((size != crb_size) || (offset & (crb_size-1))) |
| 2716 | return -EINVAL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2717 | |
| 2718 | return 0; |
| 2719 | } |
| 2720 | |
| 2721 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2722 | qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, |
| 2723 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2724 | char *buf, loff_t offset, size_t size) |
| 2725 | { |
| 2726 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2727 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2728 | u32 data; |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2729 | u64 qmdata; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2730 | int ret; |
| 2731 | |
| 2732 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 2733 | if (ret != 0) |
| 2734 | return ret; |
| 2735 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2736 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
| 2737 | qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata); |
| 2738 | memcpy(buf, &qmdata, size); |
| 2739 | } else { |
| 2740 | data = QLCRD32(adapter, offset); |
| 2741 | memcpy(buf, &data, size); |
| 2742 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2743 | return size; |
| 2744 | } |
| 2745 | |
| 2746 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2747 | qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, |
| 2748 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2749 | char *buf, loff_t offset, size_t size) |
| 2750 | { |
| 2751 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2752 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2753 | u32 data; |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2754 | u64 qmdata; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2755 | int ret; |
| 2756 | |
| 2757 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 2758 | if (ret != 0) |
| 2759 | return ret; |
| 2760 | |
Dhananjay Phadke | 897e8c7 | 2010-04-01 19:01:29 +0000 | [diff] [blame] | 2761 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) { |
| 2762 | memcpy(&qmdata, buf, size); |
| 2763 | qlcnic_pci_camqm_write_2M(adapter, offset, qmdata); |
| 2764 | } else { |
| 2765 | memcpy(&data, buf, size); |
| 2766 | QLCWR32(adapter, offset, data); |
| 2767 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2768 | return size; |
| 2769 | } |
| 2770 | |
| 2771 | static int |
| 2772 | qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, |
| 2773 | loff_t offset, size_t size) |
| 2774 | { |
| 2775 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 2776 | return -EIO; |
| 2777 | |
| 2778 | if ((size != 8) || (offset & 0x7)) |
| 2779 | return -EIO; |
| 2780 | |
| 2781 | return 0; |
| 2782 | } |
| 2783 | |
| 2784 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2785 | qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, |
| 2786 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2787 | char *buf, loff_t offset, size_t size) |
| 2788 | { |
| 2789 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2790 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2791 | u64 data; |
| 2792 | int ret; |
| 2793 | |
| 2794 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 2795 | if (ret != 0) |
| 2796 | return ret; |
| 2797 | |
| 2798 | if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) |
| 2799 | return -EIO; |
| 2800 | |
| 2801 | memcpy(buf, &data, size); |
| 2802 | |
| 2803 | return size; |
| 2804 | } |
| 2805 | |
| 2806 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 2807 | qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, |
| 2808 | struct bin_attribute *attr, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2809 | char *buf, loff_t offset, size_t size) |
| 2810 | { |
| 2811 | struct device *dev = container_of(kobj, struct device, kobj); |
| 2812 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 2813 | u64 data; |
| 2814 | int ret; |
| 2815 | |
| 2816 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 2817 | if (ret != 0) |
| 2818 | return ret; |
| 2819 | |
| 2820 | memcpy(&data, buf, size); |
| 2821 | |
| 2822 | if (qlcnic_pci_mem_write_2M(adapter, offset, data)) |
| 2823 | return -EIO; |
| 2824 | |
| 2825 | return size; |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | static struct bin_attribute bin_attr_crb = { |
| 2830 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, |
| 2831 | .size = 0, |
| 2832 | .read = qlcnic_sysfs_read_crb, |
| 2833 | .write = qlcnic_sysfs_write_crb, |
| 2834 | }; |
| 2835 | |
| 2836 | static struct bin_attribute bin_attr_mem = { |
| 2837 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, |
| 2838 | .size = 0, |
| 2839 | .read = qlcnic_sysfs_read_mem, |
| 2840 | .write = qlcnic_sysfs_write_mem, |
| 2841 | }; |
| 2842 | |
| 2843 | static void |
| 2844 | qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) |
| 2845 | { |
| 2846 | struct device *dev = &adapter->pdev->dev; |
| 2847 | |
| 2848 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 2849 | if (device_create_file(dev, &dev_attr_bridged_mode)) |
| 2850 | dev_warn(dev, |
| 2851 | "failed to create bridged_mode sysfs entry\n"); |
| 2852 | } |
| 2853 | |
| 2854 | static void |
| 2855 | qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) |
| 2856 | { |
| 2857 | struct device *dev = &adapter->pdev->dev; |
| 2858 | |
| 2859 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
| 2860 | device_remove_file(dev, &dev_attr_bridged_mode); |
| 2861 | } |
| 2862 | |
| 2863 | static void |
| 2864 | qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) |
| 2865 | { |
| 2866 | struct device *dev = &adapter->pdev->dev; |
| 2867 | |
| 2868 | if (device_create_file(dev, &dev_attr_diag_mode)) |
| 2869 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); |
| 2870 | if (device_create_bin_file(dev, &bin_attr_crb)) |
| 2871 | dev_info(dev, "failed to create crb sysfs entry\n"); |
| 2872 | if (device_create_bin_file(dev, &bin_attr_mem)) |
| 2873 | dev_info(dev, "failed to create mem sysfs entry\n"); |
| 2874 | } |
| 2875 | |
| 2876 | |
| 2877 | static void |
| 2878 | qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) |
| 2879 | { |
| 2880 | struct device *dev = &adapter->pdev->dev; |
| 2881 | |
| 2882 | device_remove_file(dev, &dev_attr_diag_mode); |
| 2883 | device_remove_bin_file(dev, &bin_attr_crb); |
| 2884 | device_remove_bin_file(dev, &bin_attr_mem); |
| 2885 | } |
| 2886 | |
| 2887 | #ifdef CONFIG_INET |
| 2888 | |
| 2889 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) |
| 2890 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2891 | static void |
| 2892 | qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) |
| 2893 | { |
| 2894 | struct in_device *indev; |
| 2895 | struct qlcnic_adapter *adapter = netdev_priv(dev); |
| 2896 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2897 | indev = in_dev_get(dev); |
| 2898 | if (!indev) |
| 2899 | return; |
| 2900 | |
| 2901 | for_ifa(indev) { |
| 2902 | switch (event) { |
| 2903 | case NETDEV_UP: |
| 2904 | qlcnic_config_ipaddr(adapter, |
| 2905 | ifa->ifa_address, QLCNIC_IP_UP); |
| 2906 | break; |
| 2907 | case NETDEV_DOWN: |
| 2908 | qlcnic_config_ipaddr(adapter, |
| 2909 | ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2910 | break; |
| 2911 | default: |
| 2912 | break; |
| 2913 | } |
| 2914 | } endfor_ifa(indev); |
| 2915 | |
| 2916 | in_dev_put(indev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | static int qlcnic_netdev_event(struct notifier_block *this, |
| 2920 | unsigned long event, void *ptr) |
| 2921 | { |
| 2922 | struct qlcnic_adapter *adapter; |
| 2923 | struct net_device *dev = (struct net_device *)ptr; |
| 2924 | |
| 2925 | recheck: |
| 2926 | if (dev == NULL) |
| 2927 | goto done; |
| 2928 | |
| 2929 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2930 | dev = vlan_dev_real_dev(dev); |
| 2931 | goto recheck; |
| 2932 | } |
| 2933 | |
| 2934 | if (!is_qlcnic_netdev(dev)) |
| 2935 | goto done; |
| 2936 | |
| 2937 | adapter = netdev_priv(dev); |
| 2938 | |
| 2939 | if (!adapter) |
| 2940 | goto done; |
| 2941 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2942 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2943 | goto done; |
| 2944 | |
| 2945 | qlcnic_config_indev_addr(dev, event); |
| 2946 | done: |
| 2947 | return NOTIFY_DONE; |
| 2948 | } |
| 2949 | |
| 2950 | static int |
| 2951 | qlcnic_inetaddr_event(struct notifier_block *this, |
| 2952 | unsigned long event, void *ptr) |
| 2953 | { |
| 2954 | struct qlcnic_adapter *adapter; |
| 2955 | struct net_device *dev; |
| 2956 | |
| 2957 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 2958 | |
| 2959 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 2960 | |
| 2961 | recheck: |
| 2962 | if (dev == NULL || !netif_running(dev)) |
| 2963 | goto done; |
| 2964 | |
| 2965 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2966 | dev = vlan_dev_real_dev(dev); |
| 2967 | goto recheck; |
| 2968 | } |
| 2969 | |
| 2970 | if (!is_qlcnic_netdev(dev)) |
| 2971 | goto done; |
| 2972 | |
| 2973 | adapter = netdev_priv(dev); |
| 2974 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 2975 | if (!adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2976 | goto done; |
| 2977 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2978 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2979 | goto done; |
| 2980 | |
| 2981 | switch (event) { |
| 2982 | case NETDEV_UP: |
| 2983 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); |
| 2984 | break; |
| 2985 | case NETDEV_DOWN: |
| 2986 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2987 | break; |
| 2988 | default: |
| 2989 | break; |
| 2990 | } |
| 2991 | |
| 2992 | done: |
| 2993 | return NOTIFY_DONE; |
| 2994 | } |
| 2995 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2996 | static struct notifier_block qlcnic_netdev_cb = { |
| 2997 | .notifier_call = qlcnic_netdev_event, |
| 2998 | }; |
| 2999 | |
| 3000 | static struct notifier_block qlcnic_inetaddr_cb = { |
| 3001 | .notifier_call = qlcnic_inetaddr_event, |
| 3002 | }; |
| 3003 | #else |
| 3004 | static void |
| 3005 | qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) |
| 3006 | { } |
| 3007 | #endif |
| 3008 | |
| 3009 | static struct pci_driver qlcnic_driver = { |
| 3010 | .name = qlcnic_driver_name, |
| 3011 | .id_table = qlcnic_pci_tbl, |
| 3012 | .probe = qlcnic_probe, |
| 3013 | .remove = __devexit_p(qlcnic_remove), |
| 3014 | #ifdef CONFIG_PM |
| 3015 | .suspend = qlcnic_suspend, |
| 3016 | .resume = qlcnic_resume, |
| 3017 | #endif |
| 3018 | .shutdown = qlcnic_shutdown |
| 3019 | }; |
| 3020 | |
| 3021 | static int __init qlcnic_init_module(void) |
| 3022 | { |
| 3023 | |
| 3024 | printk(KERN_INFO "%s\n", qlcnic_driver_string); |
| 3025 | |
| 3026 | #ifdef CONFIG_INET |
| 3027 | register_netdevice_notifier(&qlcnic_netdev_cb); |
| 3028 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 3029 | #endif |
| 3030 | |
| 3031 | |
| 3032 | return pci_register_driver(&qlcnic_driver); |
| 3033 | } |
| 3034 | |
| 3035 | module_init(qlcnic_init_module); |
| 3036 | |
| 3037 | static void __exit qlcnic_exit_module(void) |
| 3038 | { |
| 3039 | |
| 3040 | pci_unregister_driver(&qlcnic_driver); |
| 3041 | |
| 3042 | #ifdef CONFIG_INET |
| 3043 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 3044 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 3045 | #endif |
| 3046 | } |
| 3047 | |
| 3048 | module_exit(qlcnic_exit_module); |