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