1 /* 2 * QLogic qlcnic NIC Driver 3 * Copyright (c) 2009-2013 QLogic Corporation 4 * 5 * See LICENSE.qlcnic for copyright and licensing details. 6 */ 7 8 #include <linux/vmalloc.h> 9 #include <linux/interrupt.h> 10 11 #include "qlcnic.h" 12 #include "qlcnic_sriov.h" 13 #include "qlcnic_hw.h" 14 15 #include <linux/swab.h> 16 #include <linux/dma-mapping.h> 17 #include <linux/if_vlan.h> 18 #include <net/ip.h> 19 #include <linux/ipv6.h> 20 #include <linux/inetdevice.h> 21 #include <linux/aer.h> 22 #include <linux/log2.h> 23 #include <linux/pci.h> 24 25 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); 26 MODULE_LICENSE("GPL"); 27 MODULE_VERSION(QLCNIC_LINUX_VERSIONID); 28 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); 29 30 char qlcnic_driver_name[] = "qlcnic"; 31 static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " 32 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; 33 34 static int qlcnic_mac_learn; 35 module_param(qlcnic_mac_learn, int, 0444); 36 MODULE_PARM_DESC(qlcnic_mac_learn, 37 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)"); 38 39 int qlcnic_use_msi = 1; 40 MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled)"); 41 module_param_named(use_msi, qlcnic_use_msi, int, 0444); 42 43 int qlcnic_use_msi_x = 1; 44 MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled)"); 45 module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444); 46 47 int qlcnic_auto_fw_reset = 1; 48 MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled)"); 49 module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644); 50 51 int qlcnic_load_fw_file; 52 MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file)"); 53 module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444); 54 55 static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 56 static void qlcnic_remove(struct pci_dev *pdev); 57 static int qlcnic_open(struct net_device *netdev); 58 static int qlcnic_close(struct net_device *netdev); 59 static void qlcnic_tx_timeout(struct net_device *netdev); 60 static void qlcnic_attach_work(struct work_struct *work); 61 static void qlcnic_fwinit_work(struct work_struct *work); 62 #ifdef CONFIG_NET_POLL_CONTROLLER 63 static void qlcnic_poll_controller(struct net_device *netdev); 64 #endif 65 66 static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); 67 static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); 68 69 static irqreturn_t qlcnic_tmp_intr(int irq, void *data); 70 static irqreturn_t qlcnic_intr(int irq, void *data); 71 static irqreturn_t qlcnic_msi_intr(int irq, void *data); 72 static irqreturn_t qlcnic_msix_intr(int irq, void *data); 73 static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data); 74 75 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); 76 static int qlcnic_start_firmware(struct qlcnic_adapter *); 77 78 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); 79 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); 80 static int qlcnicvf_start_firmware(struct qlcnic_adapter *); 81 static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16); 82 static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16); 83 84 static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter) 85 { 86 struct qlcnic_hardware_context *ahw = adapter->ahw; 87 88 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X) 89 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX; 90 else 91 return 1; 92 } 93 94 /* PCI Device ID Table */ 95 #define ENTRY(device) \ 96 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ 97 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} 98 99 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { 100 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), 101 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X), 102 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X), 103 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X), 104 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X), 105 {0,} 106 }; 107 108 MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); 109 110 111 inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring) 112 { 113 writel(tx_ring->producer, tx_ring->crb_cmd_producer); 114 } 115 116 static const u32 msi_tgt_status[8] = { 117 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, 118 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, 119 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, 120 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 121 }; 122 123 static const u32 qlcnic_reg_tbl[] = { 124 0x1B20A8, /* PEG_HALT_STAT1 */ 125 0x1B20AC, /* PEG_HALT_STAT2 */ 126 0x1B20B0, /* FW_HEARTBEAT */ 127 0x1B2100, /* LOCK ID */ 128 0x1B2128, /* FW_CAPABILITIES */ 129 0x1B2138, /* drv active */ 130 0x1B2140, /* dev state */ 131 0x1B2144, /* drv state */ 132 0x1B2148, /* drv scratch */ 133 0x1B214C, /* dev partition info */ 134 0x1B2174, /* drv idc ver */ 135 0x1B2150, /* fw version major */ 136 0x1B2154, /* fw version minor */ 137 0x1B2158, /* fw version sub */ 138 0x1B219C, /* npar state */ 139 0x1B21FC, /* FW_IMG_VALID */ 140 0x1B2250, /* CMD_PEG_STATE */ 141 0x1B233C, /* RCV_PEG_STATE */ 142 0x1B23B4, /* ASIC TEMP */ 143 0x1B216C, /* FW api */ 144 0x1B2170, /* drv op mode */ 145 0x13C010, /* flash lock */ 146 0x13C014, /* flash unlock */ 147 }; 148 149 static const struct qlcnic_board_info qlcnic_boards[] = { 150 { PCI_VENDOR_ID_QLOGIC, 151 PCI_DEVICE_ID_QLOGIC_QLE844X, 152 0x0, 153 0x0, 154 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" }, 155 { PCI_VENDOR_ID_QLOGIC, 156 PCI_DEVICE_ID_QLOGIC_QLE834X, 157 PCI_VENDOR_ID_QLOGIC, 158 0x24e, 159 "8300 Series Dual Port 10GbE Converged Network Adapter " 160 "(TCP/IP Networking)" }, 161 { PCI_VENDOR_ID_QLOGIC, 162 PCI_DEVICE_ID_QLOGIC_QLE834X, 163 PCI_VENDOR_ID_QLOGIC, 164 0x243, 165 "8300 Series Single Port 10GbE Converged Network Adapter " 166 "(TCP/IP Networking)" }, 167 { PCI_VENDOR_ID_QLOGIC, 168 PCI_DEVICE_ID_QLOGIC_QLE834X, 169 PCI_VENDOR_ID_QLOGIC, 170 0x24a, 171 "8300 Series Dual Port 10GbE Converged Network Adapter " 172 "(TCP/IP Networking)" }, 173 { PCI_VENDOR_ID_QLOGIC, 174 PCI_DEVICE_ID_QLOGIC_QLE834X, 175 PCI_VENDOR_ID_QLOGIC, 176 0x246, 177 "8300 Series Dual Port 10GbE Converged Network Adapter " 178 "(TCP/IP Networking)" }, 179 { PCI_VENDOR_ID_QLOGIC, 180 PCI_DEVICE_ID_QLOGIC_QLE834X, 181 PCI_VENDOR_ID_QLOGIC, 182 0x252, 183 "8300 Series Dual Port 10GbE Converged Network Adapter " 184 "(TCP/IP Networking)" }, 185 { PCI_VENDOR_ID_QLOGIC, 186 PCI_DEVICE_ID_QLOGIC_QLE834X, 187 PCI_VENDOR_ID_QLOGIC, 188 0x26e, 189 "8300 Series Dual Port 10GbE Converged Network Adapter " 190 "(TCP/IP Networking)" }, 191 { PCI_VENDOR_ID_QLOGIC, 192 PCI_DEVICE_ID_QLOGIC_QLE834X, 193 PCI_VENDOR_ID_QLOGIC, 194 0x260, 195 "8300 Series Dual Port 10GbE Converged Network Adapter " 196 "(TCP/IP Networking)" }, 197 { PCI_VENDOR_ID_QLOGIC, 198 PCI_DEVICE_ID_QLOGIC_QLE834X, 199 PCI_VENDOR_ID_QLOGIC, 200 0x266, 201 "8300 Series Single Port 10GbE Converged Network Adapter " 202 "(TCP/IP Networking)" }, 203 { PCI_VENDOR_ID_QLOGIC, 204 PCI_DEVICE_ID_QLOGIC_QLE834X, 205 PCI_VENDOR_ID_QLOGIC, 206 0x269, 207 "8300 Series Dual Port 10GbE Converged Network Adapter " 208 "(TCP/IP Networking)" }, 209 { PCI_VENDOR_ID_QLOGIC, 210 PCI_DEVICE_ID_QLOGIC_QLE834X, 211 PCI_VENDOR_ID_QLOGIC, 212 0x271, 213 "8300 Series Dual Port 10GbE Converged Network Adapter " 214 "(TCP/IP Networking)" }, 215 { PCI_VENDOR_ID_QLOGIC, 216 PCI_DEVICE_ID_QLOGIC_QLE834X, 217 0x0, 0x0, "8300 Series 1/10GbE Controller" }, 218 { PCI_VENDOR_ID_QLOGIC, 219 PCI_DEVICE_ID_QLOGIC_QLE824X, 220 PCI_VENDOR_ID_QLOGIC, 221 0x203, 222 "8200 Series Single Port 10GbE Converged Network Adapter" 223 "(TCP/IP Networking)" }, 224 { PCI_VENDOR_ID_QLOGIC, 225 PCI_DEVICE_ID_QLOGIC_QLE824X, 226 PCI_VENDOR_ID_QLOGIC, 227 0x207, 228 "8200 Series Dual Port 10GbE Converged Network Adapter" 229 "(TCP/IP Networking)" }, 230 { PCI_VENDOR_ID_QLOGIC, 231 PCI_DEVICE_ID_QLOGIC_QLE824X, 232 PCI_VENDOR_ID_QLOGIC, 233 0x20b, 234 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" }, 235 { PCI_VENDOR_ID_QLOGIC, 236 PCI_DEVICE_ID_QLOGIC_QLE824X, 237 PCI_VENDOR_ID_QLOGIC, 238 0x20c, 239 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" }, 240 { PCI_VENDOR_ID_QLOGIC, 241 PCI_DEVICE_ID_QLOGIC_QLE824X, 242 PCI_VENDOR_ID_QLOGIC, 243 0x20f, 244 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" }, 245 { PCI_VENDOR_ID_QLOGIC, 246 PCI_DEVICE_ID_QLOGIC_QLE824X, 247 0x103c, 0x3733, 248 "NC523SFP 10Gb 2-port Server Adapter" }, 249 { PCI_VENDOR_ID_QLOGIC, 250 PCI_DEVICE_ID_QLOGIC_QLE824X, 251 0x103c, 0x3346, 252 "CN1000Q Dual Port Converged Network Adapter" }, 253 { PCI_VENDOR_ID_QLOGIC, 254 PCI_DEVICE_ID_QLOGIC_QLE824X, 255 PCI_VENDOR_ID_QLOGIC, 256 0x210, 257 "QME8242-k 10GbE Dual Port Mezzanine Card" }, 258 { PCI_VENDOR_ID_QLOGIC, 259 PCI_DEVICE_ID_QLOGIC_QLE824X, 260 0x0, 0x0, "cLOM8214 1/10GbE Controller" }, 261 }; 262 263 #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards) 264 265 static const 266 struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; 267 268 int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) 269 { 270 int size = sizeof(struct qlcnic_host_sds_ring) * count; 271 272 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); 273 274 return recv_ctx->sds_rings == NULL; 275 } 276 277 void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) 278 { 279 if (recv_ctx->sds_rings != NULL) 280 kfree(recv_ctx->sds_rings); 281 282 recv_ctx->sds_rings = NULL; 283 } 284 285 int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) 286 { 287 struct net_device *netdev = adapter->netdev; 288 struct pci_dev *pdev = adapter->pdev; 289 u8 mac_addr[ETH_ALEN]; 290 int ret; 291 292 ret = qlcnic_get_mac_address(adapter, mac_addr, 293 adapter->ahw->pci_func); 294 if (ret) 295 return ret; 296 297 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); 298 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); 299 300 /* set station address */ 301 302 if (!is_valid_ether_addr(netdev->dev_addr)) 303 dev_warn(&pdev->dev, "Bad MAC address %pM.\n", 304 netdev->dev_addr); 305 306 return 0; 307 } 308 309 static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter) 310 { 311 struct qlcnic_mac_list_s *cur; 312 struct list_head *head; 313 314 list_for_each(head, &adapter->mac_list) { 315 cur = list_entry(head, struct qlcnic_mac_list_s, list); 316 if (!memcmp(adapter->mac_addr, cur->mac_addr, ETH_ALEN)) { 317 qlcnic_sre_macaddr_change(adapter, cur->mac_addr, 318 0, QLCNIC_MAC_DEL); 319 list_del(&cur->list); 320 kfree(cur); 321 return; 322 } 323 } 324 } 325 326 static int qlcnic_set_mac(struct net_device *netdev, void *p) 327 { 328 struct qlcnic_adapter *adapter = netdev_priv(netdev); 329 struct sockaddr *addr = p; 330 331 if (qlcnic_sriov_vf_check(adapter)) 332 return -EINVAL; 333 334 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) 335 return -EOPNOTSUPP; 336 337 if (!is_valid_ether_addr(addr->sa_data)) 338 return -EINVAL; 339 340 if (!memcmp(adapter->mac_addr, addr->sa_data, ETH_ALEN)) 341 return 0; 342 343 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 344 netif_device_detach(netdev); 345 qlcnic_napi_disable(adapter); 346 } 347 348 qlcnic_delete_adapter_mac(adapter); 349 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); 350 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 351 qlcnic_set_multi(adapter->netdev); 352 353 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 354 netif_device_attach(netdev); 355 qlcnic_napi_enable(adapter); 356 } 357 return 0; 358 } 359 360 static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], 361 struct net_device *netdev, const unsigned char *addr) 362 { 363 struct qlcnic_adapter *adapter = netdev_priv(netdev); 364 int err = -EOPNOTSUPP; 365 366 if (!adapter->fdb_mac_learn) 367 return ndo_dflt_fdb_del(ndm, tb, netdev, addr); 368 369 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 370 if (is_unicast_ether_addr(addr)) { 371 err = dev_uc_del(netdev, addr); 372 if (!err) 373 err = qlcnic_nic_del_mac(adapter, addr); 374 } else if (is_multicast_ether_addr(addr)) { 375 err = dev_mc_del(netdev, addr); 376 } else { 377 err = -EINVAL; 378 } 379 } 380 return err; 381 } 382 383 static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], 384 struct net_device *netdev, 385 const unsigned char *addr, u16 flags) 386 { 387 struct qlcnic_adapter *adapter = netdev_priv(netdev); 388 int err = 0; 389 390 if (!adapter->fdb_mac_learn) 391 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags); 392 393 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { 394 pr_info("%s: FDB e-switch is not enabled\n", __func__); 395 return -EOPNOTSUPP; 396 } 397 398 if (ether_addr_equal(addr, adapter->mac_addr)) 399 return err; 400 401 if (is_unicast_ether_addr(addr)) { 402 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count) 403 err = dev_uc_add_excl(netdev, addr); 404 else 405 err = -ENOMEM; 406 } else if (is_multicast_ether_addr(addr)) { 407 err = dev_mc_add_excl(netdev, addr); 408 } else { 409 err = -EINVAL; 410 } 411 412 return err; 413 } 414 415 static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb, 416 struct net_device *netdev, int idx) 417 { 418 struct qlcnic_adapter *adapter = netdev_priv(netdev); 419 420 if (!adapter->fdb_mac_learn) 421 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx); 422 423 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) 424 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx); 425 426 return idx; 427 } 428 429 static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter) 430 { 431 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 432 usleep_range(10000, 11000); 433 434 if (!adapter->fw_work.work.func) 435 return; 436 437 cancel_delayed_work_sync(&adapter->fw_work); 438 } 439 440 static int qlcnic_get_phys_port_id(struct net_device *netdev, 441 struct netdev_phys_port_id *ppid) 442 { 443 struct qlcnic_adapter *adapter = netdev_priv(netdev); 444 struct qlcnic_hardware_context *ahw = adapter->ahw; 445 446 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID)) 447 return -EOPNOTSUPP; 448 449 ppid->id_len = sizeof(ahw->phys_port_id); 450 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len); 451 452 return 0; 453 } 454 455 static const struct net_device_ops qlcnic_netdev_ops = { 456 .ndo_open = qlcnic_open, 457 .ndo_stop = qlcnic_close, 458 .ndo_start_xmit = qlcnic_xmit_frame, 459 .ndo_get_stats = qlcnic_get_stats, 460 .ndo_validate_addr = eth_validate_addr, 461 .ndo_set_rx_mode = qlcnic_set_multi, 462 .ndo_set_mac_address = qlcnic_set_mac, 463 .ndo_change_mtu = qlcnic_change_mtu, 464 .ndo_fix_features = qlcnic_fix_features, 465 .ndo_set_features = qlcnic_set_features, 466 .ndo_tx_timeout = qlcnic_tx_timeout, 467 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, 468 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, 469 .ndo_fdb_add = qlcnic_fdb_add, 470 .ndo_fdb_del = qlcnic_fdb_del, 471 .ndo_fdb_dump = qlcnic_fdb_dump, 472 .ndo_get_phys_port_id = qlcnic_get_phys_port_id, 473 #ifdef CONFIG_NET_POLL_CONTROLLER 474 .ndo_poll_controller = qlcnic_poll_controller, 475 #endif 476 #ifdef CONFIG_QLCNIC_SRIOV 477 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac, 478 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate, 479 .ndo_get_vf_config = qlcnic_sriov_get_vf_config, 480 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan, 481 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk, 482 #endif 483 }; 484 485 static const struct net_device_ops qlcnic_netdev_failed_ops = { 486 .ndo_open = qlcnic_open, 487 }; 488 489 static struct qlcnic_nic_template qlcnic_ops = { 490 .config_bridged_mode = qlcnic_config_bridged_mode, 491 .config_led = qlcnic_82xx_config_led, 492 .start_firmware = qlcnic_82xx_start_firmware, 493 .request_reset = qlcnic_82xx_dev_request_reset, 494 .cancel_idc_work = qlcnic_82xx_cancel_idc_work, 495 .napi_add = qlcnic_82xx_napi_add, 496 .napi_del = qlcnic_82xx_napi_del, 497 .config_ipaddr = qlcnic_82xx_config_ipaddr, 498 .shutdown = qlcnic_82xx_shutdown, 499 .resume = qlcnic_82xx_resume, 500 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr, 501 }; 502 503 struct qlcnic_nic_template qlcnic_vf_ops = { 504 .config_bridged_mode = qlcnicvf_config_bridged_mode, 505 .config_led = qlcnicvf_config_led, 506 .start_firmware = qlcnicvf_start_firmware 507 }; 508 509 static struct qlcnic_hardware_ops qlcnic_hw_ops = { 510 .read_crb = qlcnic_82xx_read_crb, 511 .write_crb = qlcnic_82xx_write_crb, 512 .read_reg = qlcnic_82xx_hw_read_wx_2M, 513 .write_reg = qlcnic_82xx_hw_write_wx_2M, 514 .get_mac_address = qlcnic_82xx_get_mac_address, 515 .setup_intr = qlcnic_82xx_setup_intr, 516 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args, 517 .mbx_cmd = qlcnic_82xx_issue_cmd, 518 .get_func_no = qlcnic_82xx_get_func_no, 519 .api_lock = qlcnic_82xx_api_lock, 520 .api_unlock = qlcnic_82xx_api_unlock, 521 .add_sysfs = qlcnic_82xx_add_sysfs, 522 .remove_sysfs = qlcnic_82xx_remove_sysfs, 523 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag, 524 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx, 525 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx, 526 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx, 527 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx, 528 .setup_link_event = qlcnic_82xx_linkevent_request, 529 .get_nic_info = qlcnic_82xx_get_nic_info, 530 .get_pci_info = qlcnic_82xx_get_pci_info, 531 .set_nic_info = qlcnic_82xx_set_nic_info, 532 .change_macvlan = qlcnic_82xx_sre_macaddr_change, 533 .napi_enable = qlcnic_82xx_napi_enable, 534 .napi_disable = qlcnic_82xx_napi_disable, 535 .config_intr_coal = qlcnic_82xx_config_intr_coalesce, 536 .config_rss = qlcnic_82xx_config_rss, 537 .config_hw_lro = qlcnic_82xx_config_hw_lro, 538 .config_loopback = qlcnic_82xx_set_lb_mode, 539 .clear_loopback = qlcnic_82xx_clear_lb_mode, 540 .config_promisc_mode = qlcnic_82xx_nic_set_promisc, 541 .change_l2_filter = qlcnic_82xx_change_filter, 542 .get_board_info = qlcnic_82xx_get_board_info, 543 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count, 544 .free_mac_list = qlcnic_82xx_free_mac_list, 545 .read_phys_port_id = qlcnic_82xx_read_phys_port_id, 546 .io_error_detected = qlcnic_82xx_io_error_detected, 547 .io_slot_reset = qlcnic_82xx_io_slot_reset, 548 .io_resume = qlcnic_82xx_io_resume, 549 }; 550 551 static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter *adapter) 552 { 553 struct qlcnic_hardware_context *ahw = adapter->ahw; 554 555 if (qlcnic_82xx_check(adapter) && 556 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) { 557 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state); 558 return 0; 559 } else { 560 return 1; 561 } 562 } 563 564 static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt, 565 int queue_type) 566 { 567 int num_rings, max_rings = QLCNIC_MAX_SDS_RINGS; 568 569 if (queue_type == QLCNIC_RX_QUEUE) 570 max_rings = adapter->max_sds_rings; 571 else if (queue_type == QLCNIC_TX_QUEUE) 572 max_rings = adapter->max_tx_rings; 573 574 num_rings = rounddown_pow_of_two(min_t(int, num_online_cpus(), 575 max_rings)); 576 577 if (ring_cnt > num_rings) 578 return num_rings; 579 else 580 return ring_cnt; 581 } 582 583 void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt) 584 { 585 /* 83xx adapter does not have max_tx_rings intialized in probe */ 586 if (adapter->max_tx_rings) 587 adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt, 588 QLCNIC_TX_QUEUE); 589 else 590 adapter->drv_tx_rings = tx_cnt; 591 592 dev_info(&adapter->pdev->dev, "Set %d Tx rings\n", 593 adapter->drv_tx_rings); 594 } 595 596 void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt) 597 { 598 /* 83xx adapter does not have max_sds_rings intialized in probe */ 599 if (adapter->max_sds_rings) 600 adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt, 601 QLCNIC_RX_QUEUE); 602 else 603 adapter->drv_sds_rings = rx_cnt; 604 605 dev_info(&adapter->pdev->dev, "Set %d SDS rings\n", 606 adapter->drv_sds_rings); 607 } 608 609 int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) 610 { 611 struct pci_dev *pdev = adapter->pdev; 612 int drv_tx_rings, drv_sds_rings, tx_vector; 613 int err = -1, i; 614 615 if (adapter->flags & QLCNIC_TX_INTR_SHARED) { 616 drv_tx_rings = 0; 617 tx_vector = 0; 618 } else { 619 drv_tx_rings = adapter->drv_tx_rings; 620 tx_vector = 1; 621 } 622 623 if (!adapter->msix_entries) { 624 adapter->msix_entries = kcalloc(num_msix, 625 sizeof(struct msix_entry), 626 GFP_KERNEL); 627 if (!adapter->msix_entries) 628 return -ENOMEM; 629 } 630 631 adapter->drv_sds_rings = QLCNIC_SINGLE_RING; 632 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); 633 634 if (adapter->ahw->msix_supported) { 635 enable_msix: 636 for (i = 0; i < num_msix; i++) 637 adapter->msix_entries[i].entry = i; 638 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); 639 if (err == 0) { 640 adapter->flags |= QLCNIC_MSIX_ENABLED; 641 if (qlcnic_83xx_check(adapter)) { 642 adapter->ahw->num_msix = num_msix; 643 /* subtract mail box and tx ring vectors */ 644 adapter->drv_sds_rings = num_msix - 645 drv_tx_rings - 1; 646 } else { 647 adapter->ahw->num_msix = num_msix; 648 if (qlcnic_check_multi_tx(adapter) && 649 !adapter->ahw->diag_test && 650 (adapter->drv_tx_rings > 1)) 651 drv_sds_rings = num_msix - drv_tx_rings; 652 else 653 drv_sds_rings = num_msix; 654 655 adapter->drv_sds_rings = drv_sds_rings; 656 } 657 dev_info(&pdev->dev, "using msi-x interrupts\n"); 658 return err; 659 } else if (err > 0) { 660 dev_info(&pdev->dev, 661 "Unable to allocate %d MSI-X interrupt vectors\n", 662 num_msix); 663 if (qlcnic_83xx_check(adapter)) { 664 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector)) 665 return err; 666 err -= drv_tx_rings + 1; 667 num_msix = rounddown_pow_of_two(err); 668 num_msix += drv_tx_rings + 1; 669 } else { 670 num_msix = rounddown_pow_of_two(err); 671 if (qlcnic_check_multi_tx(adapter)) 672 num_msix += drv_tx_rings; 673 } 674 675 if (num_msix) { 676 dev_info(&pdev->dev, 677 "Trying to allocate %d MSI-X interrupt vectors\n", 678 num_msix); 679 goto enable_msix; 680 } 681 } else { 682 dev_info(&pdev->dev, 683 "Unable to allocate %d MSI-X interrupt vectors\n", 684 num_msix); 685 } 686 } 687 688 return err; 689 } 690 691 static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) 692 { 693 int err = 0; 694 u32 offset, mask_reg; 695 const struct qlcnic_legacy_intr_set *legacy_intrp; 696 struct qlcnic_hardware_context *ahw = adapter->ahw; 697 struct pci_dev *pdev = adapter->pdev; 698 699 if (qlcnic_use_msi && !pci_enable_msi(pdev)) { 700 adapter->flags |= QLCNIC_MSI_ENABLED; 701 offset = msi_tgt_status[adapter->ahw->pci_func]; 702 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw, 703 offset); 704 dev_info(&pdev->dev, "using msi interrupts\n"); 705 adapter->msix_entries[0].vector = pdev->irq; 706 return err; 707 } 708 709 if (qlcnic_use_msi || qlcnic_use_msi_x) 710 return -EOPNOTSUPP; 711 712 legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; 713 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit; 714 offset = legacy_intrp->tgt_status_reg; 715 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset); 716 mask_reg = legacy_intrp->tgt_mask_reg; 717 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg); 718 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR); 719 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG); 720 dev_info(&pdev->dev, "using legacy interrupts\n"); 721 adapter->msix_entries[0].vector = pdev->irq; 722 return err; 723 } 724 725 int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter) 726 { 727 int num_msix, err = 0; 728 729 num_msix = adapter->drv_sds_rings; 730 731 if (qlcnic_check_multi_tx(adapter)) 732 num_msix += adapter->drv_tx_rings; 733 734 err = qlcnic_enable_msix(adapter, num_msix); 735 if (err == -ENOMEM) 736 return err; 737 738 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) { 739 qlcnic_disable_multi_tx(adapter); 740 741 err = qlcnic_enable_msi_legacy(adapter); 742 if (!err) 743 return err; 744 } 745 746 return 0; 747 } 748 749 int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type) 750 { 751 struct qlcnic_hardware_context *ahw = adapter->ahw; 752 int err, i; 753 754 if (qlcnic_check_multi_tx(adapter) && 755 !ahw->diag_test && 756 (adapter->flags & QLCNIC_MSIX_ENABLED)) { 757 ahw->intr_tbl = vzalloc(ahw->num_msix * 758 sizeof(struct qlcnic_intrpt_config)); 759 if (!ahw->intr_tbl) 760 return -ENOMEM; 761 762 for (i = 0; i < ahw->num_msix; i++) { 763 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX; 764 ahw->intr_tbl[i].id = i; 765 ahw->intr_tbl[i].src = 0; 766 } 767 768 err = qlcnic_82xx_config_intrpt(adapter, 1); 769 if (err) 770 dev_err(&adapter->pdev->dev, 771 "Failed to configure Interrupt for %d vector\n", 772 ahw->num_msix); 773 return err; 774 } 775 776 return 0; 777 } 778 779 void qlcnic_teardown_intr(struct qlcnic_adapter *adapter) 780 { 781 if (adapter->flags & QLCNIC_MSIX_ENABLED) 782 pci_disable_msix(adapter->pdev); 783 if (adapter->flags & QLCNIC_MSI_ENABLED) 784 pci_disable_msi(adapter->pdev); 785 786 kfree(adapter->msix_entries); 787 adapter->msix_entries = NULL; 788 789 if (adapter->ahw->intr_tbl) { 790 vfree(adapter->ahw->intr_tbl); 791 adapter->ahw->intr_tbl = NULL; 792 } 793 } 794 795 static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw) 796 { 797 if (ahw->pci_base0 != NULL) 798 iounmap(ahw->pci_base0); 799 } 800 801 static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter) 802 { 803 struct qlcnic_pci_info *pci_info; 804 int ret; 805 806 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { 807 switch (adapter->ahw->port_type) { 808 case QLCNIC_GBE: 809 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS; 810 break; 811 case QLCNIC_XGBE: 812 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS; 813 break; 814 } 815 return 0; 816 } 817 818 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 819 return 0; 820 821 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 822 if (!pci_info) 823 return -ENOMEM; 824 825 ret = qlcnic_get_pci_info(adapter, pci_info); 826 kfree(pci_info); 827 return ret; 828 } 829 830 static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter) 831 { 832 bool ret = false; 833 834 if (qlcnic_84xx_check(adapter)) { 835 ret = true; 836 } else if (qlcnic_83xx_check(adapter)) { 837 if (adapter->ahw->extra_capability[0] & 838 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG) 839 ret = true; 840 else 841 ret = false; 842 } 843 844 return ret; 845 } 846 847 int qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 848 { 849 struct qlcnic_pci_info *pci_info; 850 int i, id = 0, ret = 0, j = 0; 851 u16 act_pci_func; 852 u8 pfn; 853 854 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 855 if (!pci_info) 856 return -ENOMEM; 857 858 ret = qlcnic_get_pci_info(adapter, pci_info); 859 if (ret) 860 goto err_pci_info; 861 862 act_pci_func = adapter->ahw->act_pci_func; 863 864 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 865 act_pci_func, GFP_KERNEL); 866 if (!adapter->npars) { 867 ret = -ENOMEM; 868 goto err_pci_info; 869 } 870 871 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 872 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 873 if (!adapter->eswitch) { 874 ret = -ENOMEM; 875 goto err_npars; 876 } 877 878 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 879 pfn = pci_info[i].id; 880 881 if (pfn >= QLCNIC_MAX_PCI_FUNC) { 882 ret = QL_STATUS_INVALID_PARAM; 883 goto err_eswitch; 884 } 885 886 if (!pci_info[i].active || 887 (pci_info[i].type != QLCNIC_TYPE_NIC)) 888 continue; 889 890 if (qlcnic_port_eswitch_cfg_capability(adapter)) { 891 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn, 892 &id)) 893 adapter->npars[j].eswitch_status = true; 894 else 895 continue; 896 } else { 897 adapter->npars[j].eswitch_status = true; 898 } 899 900 adapter->npars[j].pci_func = pfn; 901 adapter->npars[j].active = (u8)pci_info[i].active; 902 adapter->npars[j].type = (u8)pci_info[i].type; 903 adapter->npars[j].phy_port = (u8)pci_info[i].default_port; 904 adapter->npars[j].min_bw = pci_info[i].tx_min_bw; 905 adapter->npars[j].max_bw = pci_info[i].tx_max_bw; 906 907 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN); 908 j++; 909 } 910 911 /* Update eSwitch status for adapters without per port eSwitch 912 * configuration capability 913 */ 914 if (!qlcnic_port_eswitch_cfg_capability(adapter)) { 915 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) 916 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; 917 } 918 919 kfree(pci_info); 920 return 0; 921 922 err_eswitch: 923 kfree(adapter->eswitch); 924 adapter->eswitch = NULL; 925 err_npars: 926 kfree(adapter->npars); 927 adapter->npars = NULL; 928 err_pci_info: 929 kfree(pci_info); 930 931 return ret; 932 } 933 934 static int 935 qlcnic_set_function_modes(struct qlcnic_adapter *adapter) 936 { 937 u8 id; 938 int ret; 939 u32 data = QLCNIC_MGMT_FUNC; 940 struct qlcnic_hardware_context *ahw = adapter->ahw; 941 942 ret = qlcnic_api_lock(adapter); 943 if (ret) 944 goto err_lock; 945 946 id = ahw->pci_func; 947 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 948 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) | 949 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id); 950 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data); 951 qlcnic_api_unlock(adapter); 952 err_lock: 953 return ret; 954 } 955 956 static void qlcnic_check_vf(struct qlcnic_adapter *adapter, 957 const struct pci_device_id *ent) 958 { 959 u32 op_mode, priv_level; 960 961 /* Determine FW API version */ 962 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter, 963 QLCNIC_FW_API); 964 965 /* Find PCI function number */ 966 qlcnic_get_func_no(adapter); 967 968 /* Determine function privilege level */ 969 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 970 if (op_mode == QLC_DEV_DRV_DEFAULT) 971 priv_level = QLCNIC_MGMT_FUNC; 972 else 973 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 974 975 if (priv_level == QLCNIC_NON_PRIV_FUNC) { 976 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC; 977 dev_info(&adapter->pdev->dev, 978 "HAL Version: %d Non Privileged function\n", 979 adapter->ahw->fw_hal_version); 980 adapter->nic_ops = &qlcnic_vf_ops; 981 } else 982 adapter->nic_ops = &qlcnic_ops; 983 } 984 985 #define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL 986 #define QLCNIC_83XX_BAR0_LENGTH 0x4000 987 static void qlcnic_get_bar_length(u32 dev_id, ulong *bar) 988 { 989 switch (dev_id) { 990 case PCI_DEVICE_ID_QLOGIC_QLE824X: 991 *bar = QLCNIC_82XX_BAR0_LENGTH; 992 break; 993 case PCI_DEVICE_ID_QLOGIC_QLE834X: 994 case PCI_DEVICE_ID_QLOGIC_QLE844X: 995 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X: 996 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X: 997 *bar = QLCNIC_83XX_BAR0_LENGTH; 998 break; 999 default: 1000 *bar = 0; 1001 } 1002 } 1003 1004 static int qlcnic_setup_pci_map(struct pci_dev *pdev, 1005 struct qlcnic_hardware_context *ahw) 1006 { 1007 u32 offset; 1008 void __iomem *mem_ptr0 = NULL; 1009 unsigned long mem_len, pci_len0 = 0, bar0_len; 1010 1011 /* remap phys address */ 1012 mem_len = pci_resource_len(pdev, 0); 1013 1014 qlcnic_get_bar_length(pdev->device, &bar0_len); 1015 if (mem_len >= bar0_len) { 1016 1017 mem_ptr0 = pci_ioremap_bar(pdev, 0); 1018 if (mem_ptr0 == NULL) { 1019 dev_err(&pdev->dev, "failed to map PCI bar 0\n"); 1020 return -EIO; 1021 } 1022 pci_len0 = mem_len; 1023 } else { 1024 return -EIO; 1025 } 1026 1027 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10)); 1028 1029 ahw->pci_base0 = mem_ptr0; 1030 ahw->pci_len0 = pci_len0; 1031 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func)); 1032 qlcnic_get_ioaddr(ahw, offset); 1033 1034 return 0; 1035 } 1036 1037 static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter, 1038 int index) 1039 { 1040 struct pci_dev *pdev = adapter->pdev; 1041 unsigned short subsystem_vendor; 1042 bool ret = true; 1043 1044 subsystem_vendor = pdev->subsystem_vendor; 1045 1046 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X || 1047 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) { 1048 if (qlcnic_boards[index].sub_vendor == subsystem_vendor && 1049 qlcnic_boards[index].sub_device == pdev->subsystem_device) 1050 ret = true; 1051 else 1052 ret = false; 1053 } 1054 1055 return ret; 1056 } 1057 1058 static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name) 1059 { 1060 struct pci_dev *pdev = adapter->pdev; 1061 int i, found = 0; 1062 1063 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { 1064 if (qlcnic_boards[i].vendor == pdev->vendor && 1065 qlcnic_boards[i].device == pdev->device && 1066 qlcnic_validate_subsystem_id(adapter, i)) { 1067 found = 1; 1068 break; 1069 } 1070 } 1071 1072 if (!found) 1073 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); 1074 else 1075 sprintf(name, "%pM: %s" , adapter->mac_addr, 1076 qlcnic_boards[i].short_name); 1077 } 1078 1079 static void 1080 qlcnic_check_options(struct qlcnic_adapter *adapter) 1081 { 1082 int err; 1083 u32 fw_major, fw_minor, fw_build, prev_fw_version; 1084 struct pci_dev *pdev = adapter->pdev; 1085 struct qlcnic_hardware_context *ahw = adapter->ahw; 1086 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump; 1087 1088 prev_fw_version = adapter->fw_version; 1089 1090 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR); 1091 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR); 1092 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB); 1093 1094 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); 1095 1096 err = qlcnic_get_board_info(adapter); 1097 if (err) { 1098 dev_err(&pdev->dev, "Error getting board config info.\n"); 1099 return; 1100 } 1101 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) { 1102 if (fw_dump->tmpl_hdr == NULL || 1103 adapter->fw_version > prev_fw_version) { 1104 if (fw_dump->tmpl_hdr) 1105 vfree(fw_dump->tmpl_hdr); 1106 if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) 1107 dev_info(&pdev->dev, 1108 "Supports FW dump capability\n"); 1109 } 1110 } 1111 1112 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n", 1113 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build); 1114 1115 if (adapter->ahw->port_type == QLCNIC_XGBE) { 1116 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 1117 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; 1118 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; 1119 } else { 1120 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; 1121 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; 1122 } 1123 1124 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 1125 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 1126 1127 } else if (adapter->ahw->port_type == QLCNIC_GBE) { 1128 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 1129 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 1130 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 1131 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; 1132 } 1133 1134 adapter->ahw->msix_supported = !!qlcnic_use_msi_x; 1135 1136 adapter->num_txd = MAX_CMD_DESCRIPTORS; 1137 1138 adapter->max_rds_rings = MAX_RDS_RINGS; 1139 } 1140 1141 static int 1142 qlcnic_initialize_nic(struct qlcnic_adapter *adapter) 1143 { 1144 struct qlcnic_info nic_info; 1145 int err = 0; 1146 1147 memset(&nic_info, 0, sizeof(struct qlcnic_info)); 1148 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); 1149 if (err) 1150 return err; 1151 1152 adapter->ahw->physical_port = (u8)nic_info.phys_port; 1153 adapter->ahw->switch_mode = nic_info.switch_mode; 1154 adapter->ahw->max_tx_ques = nic_info.max_tx_ques; 1155 adapter->ahw->max_rx_ques = nic_info.max_rx_ques; 1156 adapter->ahw->capabilities = nic_info.capabilities; 1157 1158 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 1159 u32 temp; 1160 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err); 1161 if (err == -EIO) 1162 return err; 1163 adapter->ahw->extra_capability[0] = temp; 1164 } else { 1165 adapter->ahw->extra_capability[0] = 0; 1166 } 1167 1168 adapter->ahw->max_mac_filters = nic_info.max_mac_filters; 1169 adapter->ahw->max_mtu = nic_info.max_mtu; 1170 1171 if (adapter->ahw->capabilities & BIT_6) { 1172 adapter->flags |= QLCNIC_ESWITCH_ENABLED; 1173 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE; 1174 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS; 1175 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS; 1176 1177 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n"); 1178 } else { 1179 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE; 1180 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS; 1181 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; 1182 } 1183 1184 return err; 1185 } 1186 1187 void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, 1188 struct qlcnic_esw_func_cfg *esw_cfg) 1189 { 1190 if (esw_cfg->discard_tagged) 1191 adapter->flags &= ~QLCNIC_TAGGING_ENABLED; 1192 else 1193 adapter->flags |= QLCNIC_TAGGING_ENABLED; 1194 1195 if (esw_cfg->vlan_id) { 1196 adapter->rx_pvid = esw_cfg->vlan_id; 1197 adapter->tx_pvid = esw_cfg->vlan_id; 1198 } else { 1199 adapter->rx_pvid = 0; 1200 adapter->tx_pvid = 0; 1201 } 1202 } 1203 1204 static int 1205 qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid) 1206 { 1207 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1208 int err; 1209 1210 if (qlcnic_sriov_vf_check(adapter)) { 1211 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1); 1212 if (err) { 1213 netdev_err(netdev, 1214 "Cannot add VLAN filter for VLAN id %d, err=%d", 1215 vid, err); 1216 return err; 1217 } 1218 } 1219 1220 set_bit(vid, adapter->vlans); 1221 return 0; 1222 } 1223 1224 static int 1225 qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid) 1226 { 1227 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1228 int err; 1229 1230 if (qlcnic_sriov_vf_check(adapter)) { 1231 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0); 1232 if (err) { 1233 netdev_err(netdev, 1234 "Cannot delete VLAN filter for VLAN id %d, err=%d", 1235 vid, err); 1236 return err; 1237 } 1238 } 1239 1240 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); 1241 clear_bit(vid, adapter->vlans); 1242 return 0; 1243 } 1244 1245 void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, 1246 struct qlcnic_esw_func_cfg *esw_cfg) 1247 { 1248 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | 1249 QLCNIC_PROMISC_DISABLED); 1250 1251 if (esw_cfg->mac_anti_spoof) 1252 adapter->flags |= QLCNIC_MACSPOOF; 1253 1254 if (!esw_cfg->mac_override) 1255 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; 1256 1257 if (!esw_cfg->promisc_mode) 1258 adapter->flags |= QLCNIC_PROMISC_DISABLED; 1259 } 1260 1261 int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) 1262 { 1263 struct qlcnic_esw_func_cfg esw_cfg; 1264 1265 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 1266 return 0; 1267 1268 esw_cfg.pci_func = adapter->ahw->pci_func; 1269 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 1270 return -EIO; 1271 qlcnic_set_vlan_config(adapter, &esw_cfg); 1272 qlcnic_set_eswitch_port_features(adapter, &esw_cfg); 1273 qlcnic_set_netdev_features(adapter, &esw_cfg); 1274 1275 return 0; 1276 } 1277 1278 void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, 1279 struct qlcnic_esw_func_cfg *esw_cfg) 1280 { 1281 struct net_device *netdev = adapter->netdev; 1282 1283 if (qlcnic_83xx_check(adapter)) 1284 return; 1285 1286 adapter->offload_flags = esw_cfg->offload_flags; 1287 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS; 1288 netdev_update_features(netdev); 1289 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS; 1290 } 1291 1292 static int 1293 qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) 1294 { 1295 u32 op_mode, priv_level; 1296 int err = 0; 1297 1298 err = qlcnic_initialize_nic(adapter); 1299 if (err) 1300 return err; 1301 1302 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 1303 return 0; 1304 1305 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 1306 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 1307 1308 if (op_mode == QLC_DEV_DRV_DEFAULT) 1309 priv_level = QLCNIC_MGMT_FUNC; 1310 else 1311 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 1312 1313 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 1314 if (priv_level == QLCNIC_MGMT_FUNC) { 1315 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC; 1316 err = qlcnic_init_pci_info(adapter); 1317 if (err) 1318 return err; 1319 /* Set privilege level for other functions */ 1320 qlcnic_set_function_modes(adapter); 1321 dev_info(&adapter->pdev->dev, 1322 "HAL Version: %d, Management function\n", 1323 adapter->ahw->fw_hal_version); 1324 } else if (priv_level == QLCNIC_PRIV_FUNC) { 1325 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC; 1326 dev_info(&adapter->pdev->dev, 1327 "HAL Version: %d, Privileged function\n", 1328 adapter->ahw->fw_hal_version); 1329 } 1330 } else { 1331 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE; 1332 } 1333 1334 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; 1335 1336 return err; 1337 } 1338 1339 int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) 1340 { 1341 struct qlcnic_esw_func_cfg esw_cfg; 1342 struct qlcnic_npar_info *npar; 1343 u8 i; 1344 1345 if (adapter->need_fw_reset) 1346 return 0; 1347 1348 for (i = 0; i < adapter->ahw->act_pci_func; i++) { 1349 if (!adapter->npars[i].eswitch_status) 1350 continue; 1351 1352 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); 1353 esw_cfg.pci_func = adapter->npars[i].pci_func; 1354 esw_cfg.mac_override = BIT_0; 1355 esw_cfg.promisc_mode = BIT_0; 1356 if (qlcnic_82xx_check(adapter)) { 1357 esw_cfg.offload_flags = BIT_0; 1358 if (QLCNIC_IS_TSO_CAPABLE(adapter)) 1359 esw_cfg.offload_flags |= (BIT_1 | BIT_2); 1360 } 1361 if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1362 return -EIO; 1363 npar = &adapter->npars[i]; 1364 npar->pvid = esw_cfg.vlan_id; 1365 npar->mac_override = esw_cfg.mac_override; 1366 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; 1367 npar->discard_tagged = esw_cfg.discard_tagged; 1368 npar->promisc_mode = esw_cfg.promisc_mode; 1369 npar->offload_flags = esw_cfg.offload_flags; 1370 } 1371 1372 return 0; 1373 } 1374 1375 1376 static int 1377 qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, 1378 struct qlcnic_npar_info *npar, int pci_func) 1379 { 1380 struct qlcnic_esw_func_cfg esw_cfg; 1381 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; 1382 esw_cfg.pci_func = pci_func; 1383 esw_cfg.vlan_id = npar->pvid; 1384 esw_cfg.mac_override = npar->mac_override; 1385 esw_cfg.discard_tagged = npar->discard_tagged; 1386 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; 1387 esw_cfg.offload_flags = npar->offload_flags; 1388 esw_cfg.promisc_mode = npar->promisc_mode; 1389 if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1390 return -EIO; 1391 1392 esw_cfg.op_mode = QLCNIC_ADD_VLAN; 1393 if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1394 return -EIO; 1395 1396 return 0; 1397 } 1398 1399 int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 1400 { 1401 int i, err; 1402 struct qlcnic_npar_info *npar; 1403 struct qlcnic_info nic_info; 1404 u8 pci_func; 1405 1406 if (qlcnic_82xx_check(adapter)) 1407 if (!adapter->need_fw_reset) 1408 return 0; 1409 1410 /* Set the NPAR config data after FW reset */ 1411 for (i = 0; i < adapter->ahw->act_pci_func; i++) { 1412 npar = &adapter->npars[i]; 1413 pci_func = npar->pci_func; 1414 if (!adapter->npars[i].eswitch_status) 1415 continue; 1416 1417 memset(&nic_info, 0, sizeof(struct qlcnic_info)); 1418 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func); 1419 if (err) 1420 return err; 1421 nic_info.min_tx_bw = npar->min_bw; 1422 nic_info.max_tx_bw = npar->max_bw; 1423 err = qlcnic_set_nic_info(adapter, &nic_info); 1424 if (err) 1425 return err; 1426 1427 if (npar->enable_pm) { 1428 err = qlcnic_config_port_mirroring(adapter, 1429 npar->dest_npar, 1, 1430 pci_func); 1431 if (err) 1432 return err; 1433 } 1434 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func); 1435 if (err) 1436 return err; 1437 } 1438 return 0; 1439 } 1440 1441 static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) 1442 { 1443 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; 1444 u32 npar_state; 1445 1446 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 1447 return 0; 1448 1449 npar_state = QLC_SHARED_REG_RD32(adapter, 1450 QLCNIC_CRB_DEV_NPAR_STATE); 1451 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { 1452 msleep(1000); 1453 npar_state = QLC_SHARED_REG_RD32(adapter, 1454 QLCNIC_CRB_DEV_NPAR_STATE); 1455 } 1456 if (!npar_opt_timeo) { 1457 dev_err(&adapter->pdev->dev, 1458 "Waiting for NPAR state to operational timeout\n"); 1459 return -EIO; 1460 } 1461 return 0; 1462 } 1463 1464 static int 1465 qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) 1466 { 1467 int err; 1468 1469 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 1470 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) 1471 return 0; 1472 1473 err = qlcnic_set_default_offload_settings(adapter); 1474 if (err) 1475 return err; 1476 1477 err = qlcnic_reset_npar_config(adapter); 1478 if (err) 1479 return err; 1480 1481 qlcnic_dev_set_npar_ready(adapter); 1482 1483 return err; 1484 } 1485 1486 int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter) 1487 { 1488 int err; 1489 1490 err = qlcnic_can_start_firmware(adapter); 1491 if (err < 0) 1492 return err; 1493 else if (!err) 1494 goto check_fw_status; 1495 1496 if (qlcnic_load_fw_file) 1497 qlcnic_request_firmware(adapter); 1498 else { 1499 err = qlcnic_check_flash_fw_ver(adapter); 1500 if (err) 1501 goto err_out; 1502 1503 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE; 1504 } 1505 1506 err = qlcnic_need_fw_reset(adapter); 1507 if (err == 0) 1508 goto check_fw_status; 1509 1510 err = qlcnic_pinit_from_rom(adapter); 1511 if (err) 1512 goto err_out; 1513 1514 err = qlcnic_load_firmware(adapter); 1515 if (err) 1516 goto err_out; 1517 1518 qlcnic_release_firmware(adapter); 1519 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); 1520 1521 check_fw_status: 1522 err = qlcnic_check_fw_status(adapter); 1523 if (err) 1524 goto err_out; 1525 1526 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1527 qlcnic_idc_debug_info(adapter, 1); 1528 err = qlcnic_check_eswitch_mode(adapter); 1529 if (err) { 1530 dev_err(&adapter->pdev->dev, 1531 "Memory allocation failed for eswitch\n"); 1532 goto err_out; 1533 } 1534 err = qlcnic_set_mgmt_operations(adapter); 1535 if (err) 1536 goto err_out; 1537 1538 qlcnic_check_options(adapter); 1539 adapter->need_fw_reset = 0; 1540 1541 qlcnic_release_firmware(adapter); 1542 return 0; 1543 1544 err_out: 1545 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1546 dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1547 1548 qlcnic_release_firmware(adapter); 1549 return err; 1550 } 1551 1552 static int 1553 qlcnic_request_irq(struct qlcnic_adapter *adapter) 1554 { 1555 irq_handler_t handler; 1556 struct qlcnic_host_sds_ring *sds_ring; 1557 struct qlcnic_host_tx_ring *tx_ring; 1558 int err, ring, num_sds_rings; 1559 1560 unsigned long flags = 0; 1561 struct net_device *netdev = adapter->netdev; 1562 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1563 1564 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1565 if (qlcnic_82xx_check(adapter)) 1566 handler = qlcnic_tmp_intr; 1567 else 1568 handler = qlcnic_83xx_tmp_intr; 1569 if (!QLCNIC_IS_MSI_FAMILY(adapter)) 1570 flags |= IRQF_SHARED; 1571 1572 } else { 1573 if (adapter->flags & QLCNIC_MSIX_ENABLED) 1574 handler = qlcnic_msix_intr; 1575 else if (adapter->flags & QLCNIC_MSI_ENABLED) 1576 handler = qlcnic_msi_intr; 1577 else { 1578 flags |= IRQF_SHARED; 1579 if (qlcnic_82xx_check(adapter)) 1580 handler = qlcnic_intr; 1581 else 1582 handler = qlcnic_83xx_intr; 1583 } 1584 } 1585 adapter->irq = netdev->irq; 1586 1587 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1588 if (qlcnic_82xx_check(adapter) || 1589 (qlcnic_83xx_check(adapter) && 1590 (adapter->flags & QLCNIC_MSIX_ENABLED))) { 1591 num_sds_rings = adapter->drv_sds_rings; 1592 for (ring = 0; ring < num_sds_rings; ring++) { 1593 sds_ring = &recv_ctx->sds_rings[ring]; 1594 if (qlcnic_82xx_check(adapter) && 1595 !qlcnic_check_multi_tx(adapter) && 1596 (ring == (num_sds_rings - 1))) { 1597 if (!(adapter->flags & 1598 QLCNIC_MSIX_ENABLED)) 1599 snprintf(sds_ring->name, 1600 sizeof(sds_ring->name), 1601 "qlcnic"); 1602 else 1603 snprintf(sds_ring->name, 1604 sizeof(sds_ring->name), 1605 "%s-tx-0-rx-%d", 1606 netdev->name, ring); 1607 } else { 1608 snprintf(sds_ring->name, 1609 sizeof(sds_ring->name), 1610 "%s-rx-%d", 1611 netdev->name, ring); 1612 } 1613 err = request_irq(sds_ring->irq, handler, flags, 1614 sds_ring->name, sds_ring); 1615 if (err) 1616 return err; 1617 } 1618 } 1619 if ((qlcnic_82xx_check(adapter) && 1620 qlcnic_check_multi_tx(adapter)) || 1621 (qlcnic_83xx_check(adapter) && 1622 (adapter->flags & QLCNIC_MSIX_ENABLED) && 1623 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) { 1624 handler = qlcnic_msix_tx_intr; 1625 for (ring = 0; ring < adapter->drv_tx_rings; 1626 ring++) { 1627 tx_ring = &adapter->tx_ring[ring]; 1628 snprintf(tx_ring->name, sizeof(tx_ring->name), 1629 "%s-tx-%d", netdev->name, ring); 1630 err = request_irq(tx_ring->irq, handler, flags, 1631 tx_ring->name, tx_ring); 1632 if (err) 1633 return err; 1634 } 1635 } 1636 } 1637 return 0; 1638 } 1639 1640 static void 1641 qlcnic_free_irq(struct qlcnic_adapter *adapter) 1642 { 1643 int ring; 1644 struct qlcnic_host_sds_ring *sds_ring; 1645 struct qlcnic_host_tx_ring *tx_ring; 1646 1647 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1648 1649 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1650 if (qlcnic_82xx_check(adapter) || 1651 (qlcnic_83xx_check(adapter) && 1652 (adapter->flags & QLCNIC_MSIX_ENABLED))) { 1653 for (ring = 0; ring < adapter->drv_sds_rings; ring++) { 1654 sds_ring = &recv_ctx->sds_rings[ring]; 1655 free_irq(sds_ring->irq, sds_ring); 1656 } 1657 } 1658 if ((qlcnic_83xx_check(adapter) && 1659 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) || 1660 (qlcnic_82xx_check(adapter) && 1661 qlcnic_check_multi_tx(adapter))) { 1662 for (ring = 0; ring < adapter->drv_tx_rings; 1663 ring++) { 1664 tx_ring = &adapter->tx_ring[ring]; 1665 if (tx_ring->irq) 1666 free_irq(tx_ring->irq, tx_ring); 1667 } 1668 } 1669 } 1670 } 1671 1672 static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter) 1673 { 1674 u32 capab = 0; 1675 1676 if (qlcnic_82xx_check(adapter)) { 1677 if (adapter->ahw->extra_capability[0] & 1678 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG) 1679 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP; 1680 } else { 1681 capab = adapter->ahw->capabilities; 1682 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab)) 1683 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP; 1684 } 1685 } 1686 1687 int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1688 { 1689 int ring; 1690 struct qlcnic_host_rds_ring *rds_ring; 1691 1692 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1693 return -EIO; 1694 1695 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1696 return 0; 1697 1698 if (qlcnic_set_eswitch_port_config(adapter)) 1699 return -EIO; 1700 1701 qlcnic_get_lro_mss_capability(adapter); 1702 1703 if (qlcnic_fw_create_ctx(adapter)) 1704 return -EIO; 1705 1706 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1707 rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1708 qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1709 } 1710 1711 qlcnic_set_multi(netdev); 1712 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1713 1714 adapter->ahw->linkup = 0; 1715 1716 if (adapter->drv_sds_rings > 1) 1717 qlcnic_config_rss(adapter, 1); 1718 1719 qlcnic_config_intr_coalesce(adapter); 1720 1721 if (netdev->features & NETIF_F_LRO) 1722 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1723 1724 set_bit(__QLCNIC_DEV_UP, &adapter->state); 1725 qlcnic_napi_enable(adapter); 1726 1727 qlcnic_linkevent_request(adapter, 1); 1728 1729 adapter->ahw->reset_context = 0; 1730 return 0; 1731 } 1732 1733 int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1734 { 1735 int err = 0; 1736 1737 rtnl_lock(); 1738 if (netif_running(netdev)) 1739 err = __qlcnic_up(adapter, netdev); 1740 rtnl_unlock(); 1741 1742 return err; 1743 } 1744 1745 void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1746 { 1747 int ring; 1748 1749 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1750 return; 1751 1752 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) 1753 return; 1754 1755 if (qlcnic_sriov_vf_check(adapter)) 1756 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc); 1757 smp_mb(); 1758 spin_lock(&adapter->tx_clean_lock); 1759 netif_carrier_off(netdev); 1760 adapter->ahw->linkup = 0; 1761 netif_tx_disable(netdev); 1762 1763 qlcnic_free_mac_list(adapter); 1764 1765 if (adapter->fhash.fnum) 1766 qlcnic_delete_lb_filters(adapter); 1767 1768 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1769 1770 qlcnic_napi_disable(adapter); 1771 1772 qlcnic_fw_destroy_ctx(adapter); 1773 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP; 1774 1775 qlcnic_reset_rx_buffers_list(adapter); 1776 1777 for (ring = 0; ring < adapter->drv_tx_rings; ring++) 1778 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]); 1779 spin_unlock(&adapter->tx_clean_lock); 1780 } 1781 1782 /* Usage: During suspend and firmware recovery module */ 1783 1784 void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1785 { 1786 rtnl_lock(); 1787 if (netif_running(netdev)) 1788 __qlcnic_down(adapter, netdev); 1789 rtnl_unlock(); 1790 1791 } 1792 1793 int 1794 qlcnic_attach(struct qlcnic_adapter *adapter) 1795 { 1796 struct net_device *netdev = adapter->netdev; 1797 struct pci_dev *pdev = adapter->pdev; 1798 int err; 1799 1800 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) 1801 return 0; 1802 1803 err = qlcnic_napi_add(adapter, netdev); 1804 if (err) 1805 return err; 1806 1807 err = qlcnic_alloc_sw_resources(adapter); 1808 if (err) { 1809 dev_err(&pdev->dev, "Error in setting sw resources\n"); 1810 goto err_out_napi_del; 1811 } 1812 1813 err = qlcnic_alloc_hw_resources(adapter); 1814 if (err) { 1815 dev_err(&pdev->dev, "Error in setting hw resources\n"); 1816 goto err_out_free_sw; 1817 } 1818 1819 err = qlcnic_request_irq(adapter); 1820 if (err) { 1821 dev_err(&pdev->dev, "failed to setup interrupt\n"); 1822 goto err_out_free_hw; 1823 } 1824 1825 qlcnic_create_sysfs_entries(adapter); 1826 1827 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; 1828 return 0; 1829 1830 err_out_free_hw: 1831 qlcnic_free_hw_resources(adapter); 1832 err_out_free_sw: 1833 qlcnic_free_sw_resources(adapter); 1834 err_out_napi_del: 1835 qlcnic_napi_del(adapter); 1836 return err; 1837 } 1838 1839 void qlcnic_detach(struct qlcnic_adapter *adapter) 1840 { 1841 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1842 return; 1843 1844 qlcnic_remove_sysfs_entries(adapter); 1845 1846 qlcnic_free_hw_resources(adapter); 1847 qlcnic_release_rx_buffers(adapter); 1848 qlcnic_free_irq(adapter); 1849 qlcnic_napi_del(adapter); 1850 qlcnic_free_sw_resources(adapter); 1851 1852 adapter->is_up = 0; 1853 } 1854 1855 void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings) 1856 { 1857 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1858 struct qlcnic_host_sds_ring *sds_ring; 1859 int drv_tx_rings = adapter->drv_tx_rings; 1860 int ring; 1861 1862 clear_bit(__QLCNIC_DEV_UP, &adapter->state); 1863 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1864 for (ring = 0; ring < adapter->drv_sds_rings; ring++) { 1865 sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1866 qlcnic_disable_int(sds_ring); 1867 } 1868 } 1869 1870 qlcnic_fw_destroy_ctx(adapter); 1871 1872 qlcnic_detach(adapter); 1873 1874 adapter->ahw->diag_test = 0; 1875 adapter->drv_sds_rings = drv_sds_rings; 1876 adapter->drv_tx_rings = drv_tx_rings; 1877 1878 if (qlcnic_attach(adapter)) 1879 goto out; 1880 1881 if (netif_running(netdev)) 1882 __qlcnic_up(adapter, netdev); 1883 out: 1884 netif_device_attach(netdev); 1885 } 1886 1887 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) 1888 { 1889 struct qlcnic_hardware_context *ahw = adapter->ahw; 1890 int err = 0; 1891 1892 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), 1893 GFP_KERNEL); 1894 if (!adapter->recv_ctx) { 1895 err = -ENOMEM; 1896 goto err_out; 1897 } 1898 /* Initialize interrupt coalesce parameters */ 1899 ahw->coal.flag = QLCNIC_INTR_DEFAULT; 1900 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX; 1901 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US; 1902 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS; 1903 if (qlcnic_83xx_check(adapter)) { 1904 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US; 1905 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS; 1906 } 1907 /* clear stats */ 1908 memset(&adapter->stats, 0, sizeof(adapter->stats)); 1909 err_out: 1910 return err; 1911 } 1912 1913 static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) 1914 { 1915 kfree(adapter->recv_ctx); 1916 adapter->recv_ctx = NULL; 1917 1918 if (adapter->ahw->fw_dump.tmpl_hdr) { 1919 vfree(adapter->ahw->fw_dump.tmpl_hdr); 1920 adapter->ahw->fw_dump.tmpl_hdr = NULL; 1921 } 1922 1923 kfree(adapter->ahw->reset.buff); 1924 adapter->ahw->fw_dump.tmpl_hdr = NULL; 1925 } 1926 1927 int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1928 { 1929 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1930 struct qlcnic_host_sds_ring *sds_ring; 1931 struct qlcnic_host_rds_ring *rds_ring; 1932 int ring; 1933 int ret; 1934 1935 netif_device_detach(netdev); 1936 1937 if (netif_running(netdev)) 1938 __qlcnic_down(adapter, netdev); 1939 1940 qlcnic_detach(adapter); 1941 1942 adapter->drv_sds_rings = QLCNIC_SINGLE_RING; 1943 adapter->drv_tx_rings = QLCNIC_SINGLE_RING; 1944 adapter->ahw->diag_test = test; 1945 adapter->ahw->linkup = 0; 1946 1947 ret = qlcnic_attach(adapter); 1948 if (ret) { 1949 netif_device_attach(netdev); 1950 return ret; 1951 } 1952 1953 ret = qlcnic_fw_create_ctx(adapter); 1954 if (ret) { 1955 qlcnic_detach(adapter); 1956 netif_device_attach(netdev); 1957 return ret; 1958 } 1959 1960 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1961 rds_ring = &adapter->recv_ctx->rds_rings[ring]; 1962 qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1963 } 1964 1965 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1966 for (ring = 0; ring < adapter->drv_sds_rings; ring++) { 1967 sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1968 qlcnic_enable_int(sds_ring); 1969 } 1970 } 1971 1972 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) { 1973 adapter->ahw->loopback_state = 0; 1974 qlcnic_linkevent_request(adapter, 1); 1975 } 1976 1977 set_bit(__QLCNIC_DEV_UP, &adapter->state); 1978 1979 return 0; 1980 } 1981 1982 /* Reset context in hardware only */ 1983 static int 1984 qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) 1985 { 1986 struct net_device *netdev = adapter->netdev; 1987 1988 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1989 return -EBUSY; 1990 1991 netif_device_detach(netdev); 1992 1993 qlcnic_down(adapter, netdev); 1994 1995 qlcnic_up(adapter, netdev); 1996 1997 netif_device_attach(netdev); 1998 1999 clear_bit(__QLCNIC_RESETTING, &adapter->state); 2000 dev_err(&adapter->pdev->dev, "%s:\n", __func__); 2001 return 0; 2002 } 2003 2004 int 2005 qlcnic_reset_context(struct qlcnic_adapter *adapter) 2006 { 2007 int err = 0; 2008 struct net_device *netdev = adapter->netdev; 2009 2010 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 2011 return -EBUSY; 2012 2013 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { 2014 2015 netif_device_detach(netdev); 2016 2017 if (netif_running(netdev)) 2018 __qlcnic_down(adapter, netdev); 2019 2020 qlcnic_detach(adapter); 2021 2022 if (netif_running(netdev)) { 2023 err = qlcnic_attach(adapter); 2024 if (!err) { 2025 __qlcnic_up(adapter, netdev); 2026 qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2027 } 2028 } 2029 2030 netif_device_attach(netdev); 2031 } 2032 2033 clear_bit(__QLCNIC_RESETTING, &adapter->state); 2034 return err; 2035 } 2036 2037 void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter) 2038 { 2039 struct qlcnic_hardware_context *ahw = adapter->ahw; 2040 u16 act_pci_fn = ahw->act_pci_func; 2041 u16 count; 2042 2043 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT; 2044 if (act_pci_fn <= 2) 2045 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) / 2046 act_pci_fn; 2047 else 2048 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) / 2049 act_pci_fn; 2050 ahw->max_uc_count = count; 2051 } 2052 2053 int 2054 qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev, 2055 int pci_using_dac) 2056 { 2057 int err; 2058 struct pci_dev *pdev = adapter->pdev; 2059 2060 adapter->rx_csum = 1; 2061 adapter->ahw->mc_enabled = 0; 2062 qlcnic_set_mac_filter_count(adapter); 2063 2064 netdev->netdev_ops = &qlcnic_netdev_ops; 2065 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ; 2066 2067 qlcnic_change_mtu(netdev, netdev->mtu); 2068 2069 if (qlcnic_sriov_vf_check(adapter)) 2070 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops); 2071 else 2072 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 2073 2074 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 2075 NETIF_F_IPV6_CSUM | NETIF_F_GRO | 2076 NETIF_F_HW_VLAN_CTAG_RX); 2077 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | 2078 NETIF_F_IPV6_CSUM); 2079 2080 if (QLCNIC_IS_TSO_CAPABLE(adapter)) { 2081 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6); 2082 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 2083 } 2084 2085 if (pci_using_dac) { 2086 netdev->features |= NETIF_F_HIGHDMA; 2087 netdev->vlan_features |= NETIF_F_HIGHDMA; 2088 } 2089 2090 if (qlcnic_vlan_tx_check(adapter)) 2091 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX); 2092 2093 if (qlcnic_sriov_vf_check(adapter)) 2094 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 2095 2096 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 2097 netdev->features |= NETIF_F_LRO; 2098 2099 netdev->hw_features = netdev->features; 2100 netdev->priv_flags |= IFF_UNICAST_FLT; 2101 netdev->irq = adapter->msix_entries[0].vector; 2102 2103 err = qlcnic_set_real_num_queues(adapter, netdev); 2104 if (err) 2105 return err; 2106 2107 err = register_netdev(netdev); 2108 if (err) { 2109 dev_err(&pdev->dev, "failed to register net device\n"); 2110 return err; 2111 } 2112 2113 qlcnic_dcb_init_dcbnl_ops(adapter->dcb); 2114 2115 return 0; 2116 } 2117 2118 static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac) 2119 { 2120 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && 2121 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) 2122 *pci_using_dac = 1; 2123 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && 2124 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) 2125 *pci_using_dac = 0; 2126 else { 2127 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); 2128 return -EIO; 2129 } 2130 2131 return 0; 2132 } 2133 2134 void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter) 2135 { 2136 int ring; 2137 struct qlcnic_host_tx_ring *tx_ring; 2138 2139 for (ring = 0; ring < adapter->drv_tx_rings; ring++) { 2140 tx_ring = &adapter->tx_ring[ring]; 2141 if (tx_ring && tx_ring->cmd_buf_arr != NULL) { 2142 vfree(tx_ring->cmd_buf_arr); 2143 tx_ring->cmd_buf_arr = NULL; 2144 } 2145 } 2146 if (adapter->tx_ring != NULL) 2147 kfree(adapter->tx_ring); 2148 } 2149 2150 int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter, 2151 struct net_device *netdev) 2152 { 2153 int ring, vector, index; 2154 struct qlcnic_host_tx_ring *tx_ring; 2155 struct qlcnic_cmd_buffer *cmd_buf_arr; 2156 2157 tx_ring = kcalloc(adapter->drv_tx_rings, 2158 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL); 2159 if (tx_ring == NULL) 2160 return -ENOMEM; 2161 2162 adapter->tx_ring = tx_ring; 2163 2164 for (ring = 0; ring < adapter->drv_tx_rings; ring++) { 2165 tx_ring = &adapter->tx_ring[ring]; 2166 tx_ring->num_desc = adapter->num_txd; 2167 tx_ring->txq = netdev_get_tx_queue(netdev, ring); 2168 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring)); 2169 if (cmd_buf_arr == NULL) { 2170 qlcnic_free_tx_rings(adapter); 2171 return -ENOMEM; 2172 } 2173 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); 2174 tx_ring->cmd_buf_arr = cmd_buf_arr; 2175 } 2176 2177 if (qlcnic_83xx_check(adapter) || 2178 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) { 2179 for (ring = 0; ring < adapter->drv_tx_rings; ring++) { 2180 tx_ring = &adapter->tx_ring[ring]; 2181 tx_ring->adapter = adapter; 2182 if (adapter->flags & QLCNIC_MSIX_ENABLED) { 2183 index = adapter->drv_sds_rings + ring; 2184 vector = adapter->msix_entries[index].vector; 2185 tx_ring->irq = vector; 2186 } 2187 } 2188 } 2189 2190 return 0; 2191 } 2192 2193 void qlcnic_set_drv_version(struct qlcnic_adapter *adapter) 2194 { 2195 struct qlcnic_hardware_context *ahw = adapter->ahw; 2196 u32 fw_cmd = 0; 2197 2198 if (qlcnic_82xx_check(adapter)) 2199 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER; 2200 else if (qlcnic_83xx_check(adapter)) 2201 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER; 2202 2203 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER) 2204 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd); 2205 } 2206 2207 static int 2208 qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 2209 { 2210 struct net_device *netdev = NULL; 2211 struct qlcnic_adapter *adapter = NULL; 2212 struct qlcnic_hardware_context *ahw; 2213 int err, pci_using_dac = -1; 2214 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */ 2215 struct qlcnic_dcb *dcb; 2216 2217 if (pdev->is_virtfn) 2218 return -ENODEV; 2219 2220 err = pci_enable_device(pdev); 2221 if (err) 2222 return err; 2223 2224 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 2225 err = -ENODEV; 2226 goto err_out_disable_pdev; 2227 } 2228 2229 err = qlcnic_set_dma_mask(pdev, &pci_using_dac); 2230 if (err) 2231 goto err_out_disable_pdev; 2232 2233 err = pci_request_regions(pdev, qlcnic_driver_name); 2234 if (err) 2235 goto err_out_disable_pdev; 2236 2237 pci_set_master(pdev); 2238 pci_enable_pcie_error_reporting(pdev); 2239 2240 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL); 2241 if (!ahw) { 2242 err = -ENOMEM; 2243 goto err_out_free_res; 2244 } 2245 2246 switch (ent->device) { 2247 case PCI_DEVICE_ID_QLOGIC_QLE824X: 2248 ahw->hw_ops = &qlcnic_hw_ops; 2249 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl; 2250 break; 2251 case PCI_DEVICE_ID_QLOGIC_QLE834X: 2252 case PCI_DEVICE_ID_QLOGIC_QLE844X: 2253 qlcnic_83xx_register_map(ahw); 2254 break; 2255 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X: 2256 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X: 2257 qlcnic_sriov_vf_register_map(ahw); 2258 break; 2259 default: 2260 goto err_out_free_hw_res; 2261 } 2262 2263 err = qlcnic_setup_pci_map(pdev, ahw); 2264 if (err) 2265 goto err_out_free_hw_res; 2266 2267 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter), 2268 QLCNIC_MAX_TX_RINGS); 2269 if (!netdev) { 2270 err = -ENOMEM; 2271 goto err_out_iounmap; 2272 } 2273 2274 SET_NETDEV_DEV(netdev, &pdev->dev); 2275 2276 adapter = netdev_priv(netdev); 2277 adapter->netdev = netdev; 2278 adapter->pdev = pdev; 2279 adapter->ahw = ahw; 2280 2281 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic"); 2282 if (adapter->qlcnic_wq == NULL) { 2283 err = -ENOMEM; 2284 dev_err(&pdev->dev, "Failed to create workqueue\n"); 2285 goto err_out_free_netdev; 2286 } 2287 2288 err = qlcnic_alloc_adapter_resources(adapter); 2289 if (err) 2290 goto err_out_free_wq; 2291 2292 adapter->dev_rst_time = jiffies; 2293 adapter->ahw->revision_id = pdev->revision; 2294 if (qlcnic_mac_learn == FDB_MAC_LEARN) 2295 adapter->fdb_mac_learn = true; 2296 else if (qlcnic_mac_learn == DRV_MAC_LEARN) 2297 adapter->drv_mac_learn = true; 2298 2299 rwlock_init(&adapter->ahw->crb_lock); 2300 mutex_init(&adapter->ahw->mem_lock); 2301 2302 spin_lock_init(&adapter->tx_clean_lock); 2303 INIT_LIST_HEAD(&adapter->mac_list); 2304 2305 qlcnic_register_dcb(adapter); 2306 2307 if (qlcnic_82xx_check(adapter)) { 2308 qlcnic_check_vf(adapter, ent); 2309 adapter->portnum = adapter->ahw->pci_func; 2310 err = qlcnic_start_firmware(adapter); 2311 if (err) { 2312 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n" 2313 "\t\tIf reboot doesn't help, try flashing the card\n"); 2314 goto err_out_maintenance_mode; 2315 } 2316 2317 /* compute and set default and max tx/sds rings */ 2318 if (adapter->ahw->msix_supported) { 2319 if (qlcnic_check_multi_tx_capability(adapter) == 1) 2320 qlcnic_set_tx_ring_count(adapter, 2321 QLCNIC_SINGLE_RING); 2322 else 2323 qlcnic_set_tx_ring_count(adapter, 2324 QLCNIC_DEF_TX_RINGS); 2325 qlcnic_set_sds_ring_count(adapter, 2326 QLCNIC_DEF_SDS_RINGS); 2327 } else { 2328 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING); 2329 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING); 2330 } 2331 2332 err = qlcnic_setup_idc_param(adapter); 2333 if (err) 2334 goto err_out_free_hw; 2335 2336 adapter->flags |= QLCNIC_NEED_FLR; 2337 2338 dcb = adapter->dcb; 2339 2340 if (dcb && qlcnic_dcb_attach(dcb)) 2341 qlcnic_clear_dcb_ops(dcb); 2342 } else if (qlcnic_83xx_check(adapter)) { 2343 qlcnic_83xx_check_vf(adapter, ent); 2344 adapter->portnum = adapter->ahw->pci_func; 2345 err = qlcnic_83xx_init(adapter, pci_using_dac); 2346 if (err) { 2347 switch (err) { 2348 case -ENOTRECOVERABLE: 2349 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware. Please reboot\n"); 2350 dev_err(&pdev->dev, "If reboot doesn't help, please replace the adapter with new one and return the faulty adapter for repair\n"); 2351 goto err_out_free_hw; 2352 case -ENOMEM: 2353 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n"); 2354 goto err_out_free_hw; 2355 default: 2356 dev_err(&pdev->dev, "Adapter initialization failed. A reboot may be required to recover from this failure\n"); 2357 dev_err(&pdev->dev, "If reboot does not help to recover from this failure, try a flash update of the adapter\n"); 2358 goto err_out_maintenance_mode; 2359 } 2360 } 2361 2362 if (qlcnic_sriov_vf_check(adapter)) 2363 return 0; 2364 } else { 2365 dev_err(&pdev->dev, 2366 "%s: failed. Please Reboot\n", __func__); 2367 goto err_out_free_hw; 2368 } 2369 2370 if (qlcnic_read_mac_addr(adapter)) 2371 dev_warn(&pdev->dev, "failed to read mac addr\n"); 2372 2373 qlcnic_read_phys_port_id(adapter); 2374 2375 if (adapter->portnum == 0) { 2376 qlcnic_get_board_name(adapter, board_name); 2377 2378 pr_info("%s: %s Board Chip rev 0x%x\n", 2379 module_name(THIS_MODULE), 2380 board_name, adapter->ahw->revision_id); 2381 } 2382 2383 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x && 2384 !!qlcnic_use_msi) 2385 dev_warn(&pdev->dev, 2386 "Device does not support MSI interrupts\n"); 2387 2388 if (qlcnic_82xx_check(adapter)) { 2389 err = qlcnic_setup_intr(adapter); 2390 if (err) { 2391 dev_err(&pdev->dev, "Failed to setup interrupt\n"); 2392 goto err_out_disable_msi; 2393 } 2394 } 2395 2396 err = qlcnic_get_act_pci_func(adapter); 2397 if (err) 2398 goto err_out_disable_mbx_intr; 2399 2400 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); 2401 if (err) 2402 goto err_out_disable_mbx_intr; 2403 2404 if (adapter->portnum == 0) 2405 qlcnic_set_drv_version(adapter); 2406 2407 pci_set_drvdata(pdev, adapter); 2408 2409 if (qlcnic_82xx_check(adapter)) 2410 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 2411 FW_POLL_DELAY); 2412 2413 switch (adapter->ahw->port_type) { 2414 case QLCNIC_GBE: 2415 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 2416 adapter->netdev->name); 2417 break; 2418 case QLCNIC_XGBE: 2419 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", 2420 adapter->netdev->name); 2421 break; 2422 } 2423 2424 if (adapter->drv_mac_learn) 2425 qlcnic_alloc_lb_filters_mem(adapter); 2426 2427 qlcnic_add_sysfs(adapter); 2428 2429 return 0; 2430 2431 err_out_disable_mbx_intr: 2432 if (qlcnic_83xx_check(adapter)) 2433 qlcnic_83xx_free_mbx_intr(adapter); 2434 2435 err_out_disable_msi: 2436 qlcnic_teardown_intr(adapter); 2437 qlcnic_cancel_idc_work(adapter); 2438 qlcnic_clr_all_drv_state(adapter, 0); 2439 2440 err_out_free_hw: 2441 qlcnic_free_adapter_resources(adapter); 2442 2443 err_out_free_wq: 2444 destroy_workqueue(adapter->qlcnic_wq); 2445 2446 err_out_free_netdev: 2447 free_netdev(netdev); 2448 2449 err_out_iounmap: 2450 qlcnic_cleanup_pci_map(ahw); 2451 2452 err_out_free_hw_res: 2453 kfree(ahw); 2454 2455 err_out_free_res: 2456 pci_release_regions(pdev); 2457 2458 err_out_disable_pdev: 2459 pci_disable_device(pdev); 2460 return err; 2461 2462 err_out_maintenance_mode: 2463 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state); 2464 netdev->netdev_ops = &qlcnic_netdev_failed_ops; 2465 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops); 2466 ahw->port_type = QLCNIC_XGBE; 2467 2468 if (qlcnic_83xx_check(adapter)) 2469 adapter->tgt_status_reg = NULL; 2470 else 2471 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS; 2472 2473 err = register_netdev(netdev); 2474 2475 if (err) { 2476 dev_err(&pdev->dev, "Failed to register net device\n"); 2477 qlcnic_clr_all_drv_state(adapter, 0); 2478 goto err_out_free_hw; 2479 } 2480 2481 pci_set_drvdata(pdev, adapter); 2482 qlcnic_add_sysfs(adapter); 2483 2484 return 0; 2485 } 2486 2487 static void qlcnic_remove(struct pci_dev *pdev) 2488 { 2489 struct qlcnic_adapter *adapter; 2490 struct net_device *netdev; 2491 struct qlcnic_hardware_context *ahw; 2492 2493 adapter = pci_get_drvdata(pdev); 2494 if (adapter == NULL) 2495 return; 2496 2497 netdev = adapter->netdev; 2498 qlcnic_sriov_pf_disable(adapter); 2499 2500 qlcnic_cancel_idc_work(adapter); 2501 ahw = adapter->ahw; 2502 2503 qlcnic_dcb_free(adapter->dcb); 2504 2505 unregister_netdev(netdev); 2506 qlcnic_sriov_cleanup(adapter); 2507 2508 if (qlcnic_83xx_check(adapter)) { 2509 qlcnic_83xx_register_nic_idc_func(adapter, 0); 2510 cancel_delayed_work_sync(&adapter->idc_aen_work); 2511 qlcnic_83xx_free_mbx_intr(adapter); 2512 qlcnic_83xx_detach_mailbox_work(adapter); 2513 qlcnic_83xx_free_mailbox(ahw->mailbox); 2514 kfree(ahw->fw_info); 2515 } 2516 2517 qlcnic_detach(adapter); 2518 2519 if (adapter->npars != NULL) 2520 kfree(adapter->npars); 2521 if (adapter->eswitch != NULL) 2522 kfree(adapter->eswitch); 2523 2524 if (qlcnic_82xx_check(adapter)) 2525 qlcnic_clr_all_drv_state(adapter, 0); 2526 2527 clear_bit(__QLCNIC_RESETTING, &adapter->state); 2528 2529 qlcnic_free_lb_filters_mem(adapter); 2530 2531 qlcnic_teardown_intr(adapter); 2532 2533 qlcnic_remove_sysfs(adapter); 2534 2535 qlcnic_cleanup_pci_map(adapter->ahw); 2536 2537 qlcnic_release_firmware(adapter); 2538 2539 pci_disable_pcie_error_reporting(pdev); 2540 pci_release_regions(pdev); 2541 pci_disable_device(pdev); 2542 2543 if (adapter->qlcnic_wq) { 2544 destroy_workqueue(adapter->qlcnic_wq); 2545 adapter->qlcnic_wq = NULL; 2546 } 2547 2548 qlcnic_free_adapter_resources(adapter); 2549 kfree(ahw); 2550 free_netdev(netdev); 2551 } 2552 2553 static void qlcnic_shutdown(struct pci_dev *pdev) 2554 { 2555 if (__qlcnic_shutdown(pdev)) 2556 return; 2557 2558 pci_disable_device(pdev); 2559 } 2560 2561 #ifdef CONFIG_PM 2562 static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) 2563 { 2564 int retval; 2565 2566 retval = __qlcnic_shutdown(pdev); 2567 if (retval) 2568 return retval; 2569 2570 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2571 return 0; 2572 } 2573 2574 static int qlcnic_resume(struct pci_dev *pdev) 2575 { 2576 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 2577 int err; 2578 2579 err = pci_enable_device(pdev); 2580 if (err) 2581 return err; 2582 2583 pci_set_power_state(pdev, PCI_D0); 2584 pci_set_master(pdev); 2585 pci_restore_state(pdev); 2586 2587 return __qlcnic_resume(adapter); 2588 } 2589 #endif 2590 2591 static int qlcnic_open(struct net_device *netdev) 2592 { 2593 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2594 int err; 2595 2596 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) { 2597 netdev_err(netdev, "%s: Device is in non-operational state\n", 2598 __func__); 2599 2600 return -EIO; 2601 } 2602 2603 netif_carrier_off(netdev); 2604 2605 err = qlcnic_attach(adapter); 2606 if (err) 2607 return err; 2608 2609 err = __qlcnic_up(adapter, netdev); 2610 if (err) 2611 goto err_out; 2612 2613 netif_tx_start_all_queues(netdev); 2614 2615 return 0; 2616 2617 err_out: 2618 qlcnic_detach(adapter); 2619 return err; 2620 } 2621 2622 /* 2623 * qlcnic_close - Disables a network interface entry point 2624 */ 2625 static int qlcnic_close(struct net_device *netdev) 2626 { 2627 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2628 2629 __qlcnic_down(adapter, netdev); 2630 2631 return 0; 2632 } 2633 2634 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) 2635 { 2636 void *head; 2637 int i; 2638 struct net_device *netdev = adapter->netdev; 2639 u32 filter_size = 0; 2640 u16 act_pci_func = 0; 2641 2642 if (adapter->fhash.fmax && adapter->fhash.fhead) 2643 return; 2644 2645 act_pci_func = adapter->ahw->act_pci_func; 2646 spin_lock_init(&adapter->mac_learn_lock); 2647 spin_lock_init(&adapter->rx_mac_learn_lock); 2648 2649 if (qlcnic_82xx_check(adapter)) { 2650 filter_size = QLCNIC_LB_MAX_FILTERS; 2651 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE; 2652 } else { 2653 filter_size = QLC_83XX_LB_MAX_FILTERS; 2654 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE; 2655 } 2656 2657 head = kcalloc(adapter->fhash.fbucket_size, 2658 sizeof(struct hlist_head), GFP_ATOMIC); 2659 2660 if (!head) 2661 return; 2662 2663 adapter->fhash.fmax = (filter_size / act_pci_func); 2664 adapter->fhash.fhead = head; 2665 2666 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n", 2667 act_pci_func, adapter->fhash.fmax); 2668 2669 for (i = 0; i < adapter->fhash.fbucket_size; i++) 2670 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); 2671 2672 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size; 2673 2674 head = kcalloc(adapter->rx_fhash.fbucket_size, 2675 sizeof(struct hlist_head), GFP_ATOMIC); 2676 2677 if (!head) 2678 return; 2679 2680 adapter->rx_fhash.fmax = (filter_size / act_pci_func); 2681 adapter->rx_fhash.fhead = head; 2682 2683 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++) 2684 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]); 2685 } 2686 2687 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) 2688 { 2689 if (adapter->fhash.fmax && adapter->fhash.fhead) 2690 kfree(adapter->fhash.fhead); 2691 2692 adapter->fhash.fhead = NULL; 2693 adapter->fhash.fmax = 0; 2694 2695 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead) 2696 kfree(adapter->rx_fhash.fhead); 2697 2698 adapter->rx_fhash.fmax = 0; 2699 adapter->rx_fhash.fhead = NULL; 2700 } 2701 2702 int qlcnic_check_temp(struct qlcnic_adapter *adapter) 2703 { 2704 struct net_device *netdev = adapter->netdev; 2705 u32 temp_state, temp_val, temp = 0; 2706 int rv = 0; 2707 2708 if (qlcnic_83xx_check(adapter)) 2709 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP); 2710 2711 if (qlcnic_82xx_check(adapter)) 2712 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP); 2713 2714 temp_state = qlcnic_get_temp_state(temp); 2715 temp_val = qlcnic_get_temp_val(temp); 2716 2717 if (temp_state == QLCNIC_TEMP_PANIC) { 2718 dev_err(&netdev->dev, 2719 "Device temperature %d degrees C exceeds" 2720 " maximum allowed. Hardware has been shut down.\n", 2721 temp_val); 2722 rv = 1; 2723 } else if (temp_state == QLCNIC_TEMP_WARN) { 2724 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) { 2725 dev_err(&netdev->dev, 2726 "Device temperature %d degrees C " 2727 "exceeds operating range." 2728 " Immediate action needed.\n", 2729 temp_val); 2730 } 2731 } else { 2732 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) { 2733 dev_info(&netdev->dev, 2734 "Device temperature is now %d degrees C" 2735 " in normal range.\n", temp_val); 2736 } 2737 } 2738 adapter->ahw->temp = temp_state; 2739 return rv; 2740 } 2741 2742 static void qlcnic_tx_timeout(struct net_device *netdev) 2743 { 2744 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2745 struct qlcnic_host_tx_ring *tx_ring; 2746 int ring; 2747 2748 if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2749 return; 2750 2751 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) { 2752 netdev_info(netdev, "Tx timeout, reset the adapter.\n"); 2753 if (qlcnic_82xx_check(adapter)) 2754 adapter->need_fw_reset = 1; 2755 else if (qlcnic_83xx_check(adapter)) 2756 qlcnic_83xx_idc_request_reset(adapter, 2757 QLCNIC_FORCE_FW_DUMP_KEY); 2758 } else { 2759 netdev_info(netdev, "Tx timeout, reset adapter context.\n"); 2760 for (ring = 0; ring < adapter->drv_tx_rings; ring++) { 2761 tx_ring = &adapter->tx_ring[ring]; 2762 netdev_info(netdev, "Tx ring=%d\n", ring); 2763 netdev_info(netdev, 2764 "crb_intr_mask=%d, producer=%d, sw_consumer=%d, hw_consumer=%d\n", 2765 readl(tx_ring->crb_intr_mask), 2766 readl(tx_ring->crb_cmd_producer), 2767 tx_ring->sw_consumer, 2768 le32_to_cpu(*(tx_ring->hw_consumer))); 2769 netdev_info(netdev, 2770 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n", 2771 tx_ring->tx_stats.xmit_finished, 2772 tx_ring->tx_stats.xmit_called, 2773 tx_ring->tx_stats.xmit_on, 2774 tx_ring->tx_stats.xmit_off); 2775 } 2776 adapter->ahw->reset_context = 1; 2777 } 2778 } 2779 2780 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) 2781 { 2782 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2783 struct net_device_stats *stats = &netdev->stats; 2784 2785 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; 2786 stats->tx_packets = adapter->stats.xmitfinished; 2787 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; 2788 stats->tx_bytes = adapter->stats.txbytes; 2789 stats->rx_dropped = adapter->stats.rxdropped; 2790 stats->tx_dropped = adapter->stats.txdropped; 2791 2792 return stats; 2793 } 2794 2795 irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter) 2796 { 2797 u32 status; 2798 2799 status = readl(adapter->isr_int_vec); 2800 2801 if (!(status & adapter->ahw->int_vec_bit)) 2802 return IRQ_NONE; 2803 2804 /* check interrupt state machine, to be sure */ 2805 status = readl(adapter->crb_int_state_reg); 2806 if (!ISR_LEGACY_INT_TRIGGERED(status)) 2807 return IRQ_NONE; 2808 2809 writel(0xffffffff, adapter->tgt_status_reg); 2810 /* read twice to ensure write is flushed */ 2811 readl(adapter->isr_int_vec); 2812 readl(adapter->isr_int_vec); 2813 2814 return IRQ_HANDLED; 2815 } 2816 2817 static irqreturn_t qlcnic_tmp_intr(int irq, void *data) 2818 { 2819 struct qlcnic_host_sds_ring *sds_ring = data; 2820 struct qlcnic_adapter *adapter = sds_ring->adapter; 2821 2822 if (adapter->flags & QLCNIC_MSIX_ENABLED) 2823 goto done; 2824 else if (adapter->flags & QLCNIC_MSI_ENABLED) { 2825 writel(0xffffffff, adapter->tgt_status_reg); 2826 goto done; 2827 } 2828 2829 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2830 return IRQ_NONE; 2831 2832 done: 2833 adapter->ahw->diag_cnt++; 2834 qlcnic_enable_int(sds_ring); 2835 return IRQ_HANDLED; 2836 } 2837 2838 static irqreturn_t qlcnic_intr(int irq, void *data) 2839 { 2840 struct qlcnic_host_sds_ring *sds_ring = data; 2841 struct qlcnic_adapter *adapter = sds_ring->adapter; 2842 2843 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2844 return IRQ_NONE; 2845 2846 napi_schedule(&sds_ring->napi); 2847 2848 return IRQ_HANDLED; 2849 } 2850 2851 static irqreturn_t qlcnic_msi_intr(int irq, void *data) 2852 { 2853 struct qlcnic_host_sds_ring *sds_ring = data; 2854 struct qlcnic_adapter *adapter = sds_ring->adapter; 2855 2856 /* clear interrupt */ 2857 writel(0xffffffff, adapter->tgt_status_reg); 2858 2859 napi_schedule(&sds_ring->napi); 2860 return IRQ_HANDLED; 2861 } 2862 2863 static irqreturn_t qlcnic_msix_intr(int irq, void *data) 2864 { 2865 struct qlcnic_host_sds_ring *sds_ring = data; 2866 2867 napi_schedule(&sds_ring->napi); 2868 return IRQ_HANDLED; 2869 } 2870 2871 static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data) 2872 { 2873 struct qlcnic_host_tx_ring *tx_ring = data; 2874 2875 napi_schedule(&tx_ring->napi); 2876 return IRQ_HANDLED; 2877 } 2878 2879 #ifdef CONFIG_NET_POLL_CONTROLLER 2880 static void qlcnic_poll_controller(struct net_device *netdev) 2881 { 2882 int ring; 2883 struct qlcnic_host_sds_ring *sds_ring; 2884 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2885 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 2886 2887 disable_irq(adapter->irq); 2888 for (ring = 0; ring < adapter->drv_sds_rings; ring++) { 2889 sds_ring = &recv_ctx->sds_rings[ring]; 2890 qlcnic_intr(adapter->irq, sds_ring); 2891 } 2892 enable_irq(adapter->irq); 2893 } 2894 #endif 2895 2896 static void 2897 qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) 2898 { 2899 u32 val; 2900 2901 val = adapter->portnum & 0xf; 2902 val |= encoding << 7; 2903 val |= (jiffies - adapter->dev_rst_time) << 8; 2904 2905 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); 2906 adapter->dev_rst_time = jiffies; 2907 } 2908 2909 static int 2910 qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) 2911 { 2912 u32 val; 2913 2914 WARN_ON(state != QLCNIC_DEV_NEED_RESET && 2915 state != QLCNIC_DEV_NEED_QUISCENT); 2916 2917 if (qlcnic_api_lock(adapter)) 2918 return -EIO; 2919 2920 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2921 2922 if (state == QLCNIC_DEV_NEED_RESET) 2923 QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2924 else if (state == QLCNIC_DEV_NEED_QUISCENT) 2925 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); 2926 2927 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2928 2929 qlcnic_api_unlock(adapter); 2930 2931 return 0; 2932 } 2933 2934 static int 2935 qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) 2936 { 2937 u32 val; 2938 2939 if (qlcnic_api_lock(adapter)) 2940 return -EBUSY; 2941 2942 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2943 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2944 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2945 2946 qlcnic_api_unlock(adapter); 2947 2948 return 0; 2949 } 2950 2951 void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) 2952 { 2953 u32 val; 2954 2955 if (qlcnic_api_lock(adapter)) 2956 goto err; 2957 2958 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2959 QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2960 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2961 2962 if (failed) { 2963 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2964 QLCNIC_DEV_FAILED); 2965 dev_info(&adapter->pdev->dev, 2966 "Device state set to Failed. Please Reboot\n"); 2967 } else if (!(val & 0x11111111)) 2968 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2969 QLCNIC_DEV_COLD); 2970 2971 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2972 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2973 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2974 2975 qlcnic_api_unlock(adapter); 2976 err: 2977 adapter->fw_fail_cnt = 0; 2978 adapter->flags &= ~QLCNIC_FW_HANG; 2979 clear_bit(__QLCNIC_START_FW, &adapter->state); 2980 clear_bit(__QLCNIC_RESETTING, &adapter->state); 2981 } 2982 2983 /* Grab api lock, before checking state */ 2984 static int 2985 qlcnic_check_drv_state(struct qlcnic_adapter *adapter) 2986 { 2987 int act, state, active_mask; 2988 struct qlcnic_hardware_context *ahw = adapter->ahw; 2989 2990 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2991 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2992 2993 if (adapter->flags & QLCNIC_FW_RESET_OWNER) { 2994 active_mask = (~(1 << (ahw->pci_func * 4))); 2995 act = act & active_mask; 2996 } 2997 2998 if (((state & 0x11111111) == (act & 0x11111111)) || 2999 ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 3000 return 0; 3001 else 3002 return 1; 3003 } 3004 3005 static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) 3006 { 3007 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER); 3008 3009 if (val != QLCNIC_DRV_IDC_VER) { 3010 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" 3011 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); 3012 } 3013 3014 return 0; 3015 } 3016 3017 static int 3018 qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) 3019 { 3020 u32 val, prev_state; 3021 u8 dev_init_timeo = adapter->dev_init_timeo; 3022 u8 portnum = adapter->portnum; 3023 u8 ret; 3024 3025 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) 3026 return 1; 3027 3028 if (qlcnic_api_lock(adapter)) 3029 return -1; 3030 3031 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 3032 if (!(val & (1 << (portnum * 4)))) { 3033 QLC_DEV_SET_REF_CNT(val, portnum); 3034 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 3035 } 3036 3037 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3038 QLCDB(adapter, HW, "Device state = %u\n", prev_state); 3039 3040 switch (prev_state) { 3041 case QLCNIC_DEV_COLD: 3042 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 3043 QLCNIC_DEV_INITIALIZING); 3044 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER, 3045 QLCNIC_DRV_IDC_VER); 3046 qlcnic_idc_debug_info(adapter, 0); 3047 qlcnic_api_unlock(adapter); 3048 return 1; 3049 3050 case QLCNIC_DEV_READY: 3051 ret = qlcnic_check_idc_ver(adapter); 3052 qlcnic_api_unlock(adapter); 3053 return ret; 3054 3055 case QLCNIC_DEV_NEED_RESET: 3056 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 3057 QLC_DEV_SET_RST_RDY(val, portnum); 3058 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 3059 break; 3060 3061 case QLCNIC_DEV_NEED_QUISCENT: 3062 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 3063 QLC_DEV_SET_QSCNT_RDY(val, portnum); 3064 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 3065 break; 3066 3067 case QLCNIC_DEV_FAILED: 3068 dev_err(&adapter->pdev->dev, "Device in failed state.\n"); 3069 qlcnic_api_unlock(adapter); 3070 return -1; 3071 3072 case QLCNIC_DEV_INITIALIZING: 3073 case QLCNIC_DEV_QUISCENT: 3074 break; 3075 } 3076 3077 qlcnic_api_unlock(adapter); 3078 3079 do { 3080 msleep(1000); 3081 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3082 3083 if (prev_state == QLCNIC_DEV_QUISCENT) 3084 continue; 3085 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); 3086 3087 if (!dev_init_timeo) { 3088 dev_err(&adapter->pdev->dev, 3089 "Waiting for device to initialize timeout\n"); 3090 return -1; 3091 } 3092 3093 if (qlcnic_api_lock(adapter)) 3094 return -1; 3095 3096 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 3097 QLC_DEV_CLR_RST_QSCNT(val, portnum); 3098 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 3099 3100 ret = qlcnic_check_idc_ver(adapter); 3101 qlcnic_api_unlock(adapter); 3102 3103 return ret; 3104 } 3105 3106 static void 3107 qlcnic_fwinit_work(struct work_struct *work) 3108 { 3109 struct qlcnic_adapter *adapter = container_of(work, 3110 struct qlcnic_adapter, fw_work.work); 3111 u32 dev_state = 0xf; 3112 u32 val; 3113 3114 if (qlcnic_api_lock(adapter)) 3115 goto err_ret; 3116 3117 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3118 if (dev_state == QLCNIC_DEV_QUISCENT || 3119 dev_state == QLCNIC_DEV_NEED_QUISCENT) { 3120 qlcnic_api_unlock(adapter); 3121 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, 3122 FW_POLL_DELAY * 2); 3123 return; 3124 } 3125 3126 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) { 3127 qlcnic_api_unlock(adapter); 3128 goto wait_npar; 3129 } 3130 3131 if (dev_state == QLCNIC_DEV_INITIALIZING || 3132 dev_state == QLCNIC_DEV_READY) { 3133 dev_info(&adapter->pdev->dev, "Detected state change from " 3134 "DEV_NEED_RESET, skipping ack check\n"); 3135 goto skip_ack_check; 3136 } 3137 3138 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 3139 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", 3140 adapter->reset_ack_timeo); 3141 goto skip_ack_check; 3142 } 3143 3144 if (!qlcnic_check_drv_state(adapter)) { 3145 skip_ack_check: 3146 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3147 3148 if (dev_state == QLCNIC_DEV_NEED_RESET) { 3149 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 3150 QLCNIC_DEV_INITIALIZING); 3151 set_bit(__QLCNIC_START_FW, &adapter->state); 3152 QLCDB(adapter, DRV, "Restarting fw\n"); 3153 qlcnic_idc_debug_info(adapter, 0); 3154 val = QLC_SHARED_REG_RD32(adapter, 3155 QLCNIC_CRB_DRV_STATE); 3156 QLC_DEV_SET_RST_RDY(val, adapter->portnum); 3157 QLC_SHARED_REG_WR32(adapter, 3158 QLCNIC_CRB_DRV_STATE, val); 3159 } 3160 3161 qlcnic_api_unlock(adapter); 3162 3163 rtnl_lock(); 3164 if (qlcnic_check_fw_dump_state(adapter) && 3165 (adapter->flags & QLCNIC_FW_RESET_OWNER)) { 3166 QLCDB(adapter, DRV, "Take FW dump\n"); 3167 qlcnic_dump_fw(adapter); 3168 adapter->flags |= QLCNIC_FW_HANG; 3169 } 3170 rtnl_unlock(); 3171 3172 adapter->flags &= ~QLCNIC_FW_RESET_OWNER; 3173 if (!adapter->nic_ops->start_firmware(adapter)) { 3174 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 3175 adapter->fw_wait_cnt = 0; 3176 return; 3177 } 3178 goto err_ret; 3179 } 3180 3181 qlcnic_api_unlock(adapter); 3182 3183 wait_npar: 3184 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3185 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 3186 3187 switch (dev_state) { 3188 case QLCNIC_DEV_READY: 3189 if (!qlcnic_start_firmware(adapter)) { 3190 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 3191 adapter->fw_wait_cnt = 0; 3192 return; 3193 } 3194 case QLCNIC_DEV_FAILED: 3195 break; 3196 default: 3197 qlcnic_schedule_work(adapter, 3198 qlcnic_fwinit_work, FW_POLL_DELAY); 3199 return; 3200 } 3201 3202 err_ret: 3203 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 3204 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 3205 netif_device_attach(adapter->netdev); 3206 qlcnic_clr_all_drv_state(adapter, 0); 3207 } 3208 3209 static void 3210 qlcnic_detach_work(struct work_struct *work) 3211 { 3212 struct qlcnic_adapter *adapter = container_of(work, 3213 struct qlcnic_adapter, fw_work.work); 3214 struct net_device *netdev = adapter->netdev; 3215 u32 status; 3216 3217 netif_device_detach(netdev); 3218 3219 /* Dont grab rtnl lock during Quiscent mode */ 3220 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { 3221 if (netif_running(netdev)) 3222 __qlcnic_down(adapter, netdev); 3223 } else 3224 qlcnic_down(adapter, netdev); 3225 3226 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 3227 3228 if (status & QLCNIC_RCODE_FATAL_ERROR) { 3229 dev_err(&adapter->pdev->dev, 3230 "Detaching the device: peg halt status1=0x%x\n", 3231 status); 3232 3233 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { 3234 dev_err(&adapter->pdev->dev, 3235 "On board active cooling fan failed. " 3236 "Device has been halted.\n"); 3237 dev_err(&adapter->pdev->dev, 3238 "Replace the adapter.\n"); 3239 } 3240 3241 goto err_ret; 3242 } 3243 3244 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) { 3245 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", 3246 adapter->ahw->temp); 3247 goto err_ret; 3248 } 3249 3250 /* Dont ack if this instance is the reset owner */ 3251 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { 3252 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { 3253 dev_err(&adapter->pdev->dev, 3254 "Failed to set driver state," 3255 "detaching the device.\n"); 3256 goto err_ret; 3257 } 3258 } 3259 3260 adapter->fw_wait_cnt = 0; 3261 3262 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); 3263 3264 return; 3265 3266 err_ret: 3267 netif_device_attach(netdev); 3268 qlcnic_clr_all_drv_state(adapter, 1); 3269 } 3270 3271 /*Transit NPAR state to NON Operational */ 3272 static void 3273 qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) 3274 { 3275 u32 state; 3276 3277 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 3278 if (state == QLCNIC_DEV_NPAR_NON_OPER) 3279 return; 3280 3281 if (qlcnic_api_lock(adapter)) 3282 return; 3283 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 3284 QLCNIC_DEV_NPAR_NON_OPER); 3285 qlcnic_api_unlock(adapter); 3286 } 3287 3288 void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key) 3289 { 3290 u32 state, xg_val = 0, gb_val = 0; 3291 3292 qlcnic_xg_set_xg0_mask(xg_val); 3293 qlcnic_xg_set_xg1_mask(xg_val); 3294 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); 3295 qlcnic_gb_set_gb0_mask(gb_val); 3296 qlcnic_gb_set_gb1_mask(gb_val); 3297 qlcnic_gb_set_gb2_mask(gb_val); 3298 qlcnic_gb_set_gb3_mask(gb_val); 3299 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); 3300 dev_info(&adapter->pdev->dev, "Pause control frames disabled" 3301 " on all ports\n"); 3302 adapter->need_fw_reset = 1; 3303 3304 if (qlcnic_api_lock(adapter)) 3305 return; 3306 3307 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3308 3309 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) { 3310 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n", 3311 __func__); 3312 qlcnic_api_unlock(adapter); 3313 3314 return; 3315 } 3316 3317 if (state == QLCNIC_DEV_READY) { 3318 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 3319 QLCNIC_DEV_NEED_RESET); 3320 adapter->flags |= QLCNIC_FW_RESET_OWNER; 3321 QLCDB(adapter, DRV, "NEED_RESET state set\n"); 3322 qlcnic_idc_debug_info(adapter, 0); 3323 } 3324 3325 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 3326 QLCNIC_DEV_NPAR_NON_OPER); 3327 qlcnic_api_unlock(adapter); 3328 } 3329 3330 /* Transit to NPAR READY state from NPAR NOT READY state */ 3331 static void 3332 qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 3333 { 3334 if (qlcnic_api_lock(adapter)) 3335 return; 3336 3337 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 3338 QLCNIC_DEV_NPAR_OPER); 3339 QLCDB(adapter, DRV, "NPAR operational state set\n"); 3340 3341 qlcnic_api_unlock(adapter); 3342 } 3343 3344 void qlcnic_schedule_work(struct qlcnic_adapter *adapter, 3345 work_func_t func, int delay) 3346 { 3347 if (test_bit(__QLCNIC_AER, &adapter->state)) 3348 return; 3349 3350 INIT_DELAYED_WORK(&adapter->fw_work, func); 3351 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work, 3352 round_jiffies_relative(delay)); 3353 } 3354 3355 static void 3356 qlcnic_attach_work(struct work_struct *work) 3357 { 3358 struct qlcnic_adapter *adapter = container_of(work, 3359 struct qlcnic_adapter, fw_work.work); 3360 struct net_device *netdev = adapter->netdev; 3361 u32 npar_state; 3362 3363 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) { 3364 npar_state = QLC_SHARED_REG_RD32(adapter, 3365 QLCNIC_CRB_DEV_NPAR_STATE); 3366 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) 3367 qlcnic_clr_all_drv_state(adapter, 0); 3368 else if (npar_state != QLCNIC_DEV_NPAR_OPER) 3369 qlcnic_schedule_work(adapter, qlcnic_attach_work, 3370 FW_POLL_DELAY); 3371 else 3372 goto attach; 3373 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); 3374 return; 3375 } 3376 attach: 3377 qlcnic_dcb_get_info(adapter->dcb); 3378 3379 if (netif_running(netdev)) { 3380 if (qlcnic_up(adapter, netdev)) 3381 goto done; 3382 3383 qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3384 } 3385 3386 done: 3387 netif_device_attach(netdev); 3388 adapter->fw_fail_cnt = 0; 3389 adapter->flags &= ~QLCNIC_FW_HANG; 3390 clear_bit(__QLCNIC_RESETTING, &adapter->state); 3391 if (adapter->portnum == 0) 3392 qlcnic_set_drv_version(adapter); 3393 3394 if (!qlcnic_clr_drv_state(adapter)) 3395 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3396 FW_POLL_DELAY); 3397 } 3398 3399 static int 3400 qlcnic_check_health(struct qlcnic_adapter *adapter) 3401 { 3402 struct qlcnic_hardware_context *ahw = adapter->ahw; 3403 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump; 3404 u32 state = 0, heartbeat; 3405 u32 peg_status; 3406 int err = 0; 3407 3408 if (qlcnic_check_temp(adapter)) 3409 goto detach; 3410 3411 if (adapter->need_fw_reset) 3412 qlcnic_dev_request_reset(adapter, 0); 3413 3414 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3415 if (state == QLCNIC_DEV_NEED_RESET) { 3416 qlcnic_set_npar_non_operational(adapter); 3417 adapter->need_fw_reset = 1; 3418 } else if (state == QLCNIC_DEV_NEED_QUISCENT) 3419 goto detach; 3420 3421 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 3422 if (heartbeat != adapter->heartbeat) { 3423 adapter->heartbeat = heartbeat; 3424 adapter->fw_fail_cnt = 0; 3425 if (adapter->need_fw_reset) 3426 goto detach; 3427 3428 if (ahw->reset_context && qlcnic_auto_fw_reset) 3429 qlcnic_reset_hw_context(adapter); 3430 3431 return 0; 3432 } 3433 3434 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) 3435 return 0; 3436 3437 adapter->flags |= QLCNIC_FW_HANG; 3438 3439 qlcnic_dev_request_reset(adapter, 0); 3440 3441 if (qlcnic_auto_fw_reset) 3442 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); 3443 3444 dev_err(&adapter->pdev->dev, "firmware hang detected\n"); 3445 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 3446 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" 3447 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" 3448 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" 3449 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" 3450 "PEG_NET_4_PC: 0x%x\n", 3451 peg_status, 3452 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2), 3453 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err), 3454 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err), 3455 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err), 3456 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err), 3457 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err)); 3458 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) 3459 dev_err(&adapter->pdev->dev, 3460 "Firmware aborted with error code 0x00006700. " 3461 "Device is being reset.\n"); 3462 detach: 3463 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : 3464 QLCNIC_DEV_NEED_RESET; 3465 3466 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING, 3467 &adapter->state)) { 3468 3469 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); 3470 QLCDB(adapter, DRV, "fw recovery scheduled.\n"); 3471 } else if (!qlcnic_auto_fw_reset && fw_dump->enable && 3472 adapter->flags & QLCNIC_FW_RESET_OWNER) { 3473 qlcnic_dump_fw(adapter); 3474 } 3475 3476 return 1; 3477 } 3478 3479 void qlcnic_fw_poll_work(struct work_struct *work) 3480 { 3481 struct qlcnic_adapter *adapter = container_of(work, 3482 struct qlcnic_adapter, fw_work.work); 3483 3484 if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3485 goto reschedule; 3486 3487 3488 if (qlcnic_check_health(adapter)) 3489 return; 3490 3491 if (adapter->fhash.fnum) 3492 qlcnic_prune_lb_filters(adapter); 3493 3494 reschedule: 3495 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 3496 } 3497 3498 static int qlcnic_is_first_func(struct pci_dev *pdev) 3499 { 3500 struct pci_dev *oth_pdev; 3501 int val = pdev->devfn; 3502 3503 while (val-- > 0) { 3504 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr 3505 (pdev->bus), pdev->bus->number, 3506 PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); 3507 if (!oth_pdev) 3508 continue; 3509 3510 if (oth_pdev->current_state != PCI_D3cold) { 3511 pci_dev_put(oth_pdev); 3512 return 0; 3513 } 3514 pci_dev_put(oth_pdev); 3515 } 3516 return 1; 3517 } 3518 3519 static int qlcnic_attach_func(struct pci_dev *pdev) 3520 { 3521 int err, first_func; 3522 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3523 struct net_device *netdev = adapter->netdev; 3524 3525 pdev->error_state = pci_channel_io_normal; 3526 3527 err = pci_enable_device(pdev); 3528 if (err) 3529 return err; 3530 3531 pci_set_master(pdev); 3532 pci_restore_state(pdev); 3533 3534 first_func = qlcnic_is_first_func(pdev); 3535 3536 if (qlcnic_api_lock(adapter)) 3537 return -EINVAL; 3538 3539 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { 3540 adapter->need_fw_reset = 1; 3541 set_bit(__QLCNIC_START_FW, &adapter->state); 3542 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 3543 QLCNIC_DEV_INITIALIZING); 3544 QLCDB(adapter, DRV, "Restarting fw\n"); 3545 } 3546 qlcnic_api_unlock(adapter); 3547 3548 err = qlcnic_start_firmware(adapter); 3549 if (err) 3550 return err; 3551 3552 qlcnic_clr_drv_state(adapter); 3553 kfree(adapter->msix_entries); 3554 adapter->msix_entries = NULL; 3555 err = qlcnic_setup_intr(adapter); 3556 3557 if (err) { 3558 kfree(adapter->msix_entries); 3559 netdev_err(netdev, "failed to setup interrupt\n"); 3560 return err; 3561 } 3562 3563 if (netif_running(netdev)) { 3564 err = qlcnic_attach(adapter); 3565 if (err) { 3566 qlcnic_clr_all_drv_state(adapter, 1); 3567 clear_bit(__QLCNIC_AER, &adapter->state); 3568 netif_device_attach(netdev); 3569 return err; 3570 } 3571 3572 err = qlcnic_up(adapter, netdev); 3573 if (err) 3574 goto done; 3575 3576 qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3577 } 3578 done: 3579 netif_device_attach(netdev); 3580 return err; 3581 } 3582 3583 pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev, 3584 pci_channel_state_t state) 3585 { 3586 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3587 struct net_device *netdev = adapter->netdev; 3588 3589 if (state == pci_channel_io_perm_failure) 3590 return PCI_ERS_RESULT_DISCONNECT; 3591 3592 if (state == pci_channel_io_normal) 3593 return PCI_ERS_RESULT_RECOVERED; 3594 3595 set_bit(__QLCNIC_AER, &adapter->state); 3596 netif_device_detach(netdev); 3597 3598 cancel_delayed_work_sync(&adapter->fw_work); 3599 3600 if (netif_running(netdev)) 3601 qlcnic_down(adapter, netdev); 3602 3603 qlcnic_detach(adapter); 3604 qlcnic_teardown_intr(adapter); 3605 3606 clear_bit(__QLCNIC_RESETTING, &adapter->state); 3607 3608 pci_save_state(pdev); 3609 pci_disable_device(pdev); 3610 3611 return PCI_ERS_RESULT_NEED_RESET; 3612 } 3613 3614 pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev) 3615 { 3616 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : 3617 PCI_ERS_RESULT_RECOVERED; 3618 } 3619 3620 void qlcnic_82xx_io_resume(struct pci_dev *pdev) 3621 { 3622 u32 state; 3623 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3624 3625 pci_cleanup_aer_uncorrect_error_status(pdev); 3626 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3627 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER, 3628 &adapter->state)) 3629 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3630 FW_POLL_DELAY); 3631 } 3632 3633 static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, 3634 pci_channel_state_t state) 3635 { 3636 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3637 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops; 3638 3639 if (hw_ops->io_error_detected) { 3640 return hw_ops->io_error_detected(pdev, state); 3641 } else { 3642 dev_err(&pdev->dev, "AER error_detected handler not registered.\n"); 3643 return PCI_ERS_RESULT_DISCONNECT; 3644 } 3645 } 3646 3647 static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) 3648 { 3649 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3650 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops; 3651 3652 if (hw_ops->io_slot_reset) { 3653 return hw_ops->io_slot_reset(pdev); 3654 } else { 3655 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n"); 3656 return PCI_ERS_RESULT_DISCONNECT; 3657 } 3658 } 3659 3660 static void qlcnic_io_resume(struct pci_dev *pdev) 3661 { 3662 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3663 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops; 3664 3665 if (hw_ops->io_resume) 3666 hw_ops->io_resume(pdev); 3667 else 3668 dev_err(&pdev->dev, "AER resume handler not registered.\n"); 3669 } 3670 3671 3672 static int 3673 qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3674 { 3675 int err; 3676 3677 err = qlcnic_can_start_firmware(adapter); 3678 if (err) 3679 return err; 3680 3681 err = qlcnic_check_npar_opertional(adapter); 3682 if (err) 3683 return err; 3684 3685 err = qlcnic_initialize_nic(adapter); 3686 if (err) 3687 return err; 3688 3689 qlcnic_check_options(adapter); 3690 3691 err = qlcnic_set_eswitch_port_config(adapter); 3692 if (err) 3693 return err; 3694 3695 adapter->need_fw_reset = 0; 3696 3697 return err; 3698 } 3699 3700 int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt, 3701 int queue_type) 3702 { 3703 struct net_device *netdev = adapter->netdev; 3704 u8 max_hw_rings = 0; 3705 char buf[8]; 3706 int cur_rings; 3707 3708 if (queue_type == QLCNIC_RX_QUEUE) { 3709 max_hw_rings = adapter->max_sds_rings; 3710 cur_rings = adapter->drv_sds_rings; 3711 strcpy(buf, "SDS"); 3712 } else if (queue_type == QLCNIC_TX_QUEUE) { 3713 max_hw_rings = adapter->max_tx_rings; 3714 cur_rings = adapter->drv_tx_rings; 3715 strcpy(buf, "Tx"); 3716 } 3717 3718 if (!qlcnic_use_msi_x && !qlcnic_use_msi) { 3719 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n"); 3720 return -EINVAL; 3721 } 3722 3723 if (adapter->flags & QLCNIC_MSI_ENABLED) { 3724 netdev_err(netdev, "No RSS/TSS support in MSI mode\n"); 3725 return -EINVAL; 3726 } 3727 3728 if (ring_cnt < 2) { 3729 netdev_err(netdev, 3730 "%s rings value should not be lower than 2\n", buf); 3731 return -EINVAL; 3732 } 3733 3734 if (!is_power_of_2(ring_cnt)) { 3735 netdev_err(netdev, "%s rings value should be a power of 2\n", 3736 buf); 3737 return -EINVAL; 3738 } 3739 3740 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) && 3741 !qlcnic_check_multi_tx(adapter)) { 3742 netdev_err(netdev, "No Multi Tx queue support\n"); 3743 return -EINVAL; 3744 } 3745 3746 if (ring_cnt > num_online_cpus()) { 3747 netdev_err(netdev, 3748 "%s value[%u] should not be higher than, number of online CPUs\n", 3749 buf, num_online_cpus()); 3750 return -EINVAL; 3751 } 3752 3753 return 0; 3754 } 3755 3756 int qlcnic_setup_rings(struct qlcnic_adapter *adapter, u8 rx_cnt, u8 tx_cnt) 3757 { 3758 struct net_device *netdev = adapter->netdev; 3759 int err; 3760 3761 if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3762 return -EBUSY; 3763 3764 netif_device_detach(netdev); 3765 if (netif_running(netdev)) 3766 __qlcnic_down(adapter, netdev); 3767 3768 qlcnic_detach(adapter); 3769 3770 if (qlcnic_83xx_check(adapter)) { 3771 qlcnic_83xx_free_mbx_intr(adapter); 3772 qlcnic_83xx_enable_mbx_poll(adapter); 3773 } 3774 3775 qlcnic_teardown_intr(adapter); 3776 3777 /* compute and set default and max tx/sds rings */ 3778 qlcnic_set_tx_ring_count(adapter, tx_cnt); 3779 qlcnic_set_sds_ring_count(adapter, rx_cnt); 3780 3781 netif_set_real_num_tx_queues(netdev, adapter->drv_tx_rings); 3782 3783 err = qlcnic_setup_intr(adapter); 3784 if (err) { 3785 kfree(adapter->msix_entries); 3786 netdev_err(netdev, "failed to setup interrupt\n"); 3787 return err; 3788 } 3789 3790 if (qlcnic_83xx_check(adapter)) { 3791 /* register for NIC IDC AEN Events */ 3792 qlcnic_83xx_register_nic_idc_func(adapter, 1); 3793 err = qlcnic_83xx_setup_mbx_intr(adapter); 3794 qlcnic_83xx_disable_mbx_poll(adapter); 3795 if (err) { 3796 dev_err(&adapter->pdev->dev, 3797 "failed to setup mbx interrupt\n"); 3798 goto done; 3799 } 3800 } 3801 3802 if (netif_running(netdev)) { 3803 err = qlcnic_attach(adapter); 3804 if (err) 3805 goto done; 3806 err = __qlcnic_up(adapter, netdev); 3807 if (err) 3808 goto done; 3809 qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3810 } 3811 done: 3812 netif_device_attach(netdev); 3813 clear_bit(__QLCNIC_RESETTING, &adapter->state); 3814 return err; 3815 } 3816 3817 #ifdef CONFIG_INET 3818 3819 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 3820 3821 static void 3822 qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, 3823 struct net_device *dev, unsigned long event) 3824 { 3825 struct in_device *indev; 3826 3827 indev = in_dev_get(dev); 3828 if (!indev) 3829 return; 3830 3831 for_ifa(indev) { 3832 switch (event) { 3833 case NETDEV_UP: 3834 qlcnic_config_ipaddr(adapter, 3835 ifa->ifa_address, QLCNIC_IP_UP); 3836 break; 3837 case NETDEV_DOWN: 3838 qlcnic_config_ipaddr(adapter, 3839 ifa->ifa_address, QLCNIC_IP_DOWN); 3840 break; 3841 default: 3842 break; 3843 } 3844 } endfor_ifa(indev); 3845 3846 in_dev_put(indev); 3847 } 3848 3849 void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) 3850 { 3851 struct qlcnic_adapter *adapter = netdev_priv(netdev); 3852 struct net_device *dev; 3853 u16 vid; 3854 3855 qlcnic_config_indev_addr(adapter, netdev, event); 3856 3857 rcu_read_lock(); 3858 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { 3859 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid); 3860 if (!dev) 3861 continue; 3862 qlcnic_config_indev_addr(adapter, dev, event); 3863 } 3864 rcu_read_unlock(); 3865 } 3866 3867 static int qlcnic_netdev_event(struct notifier_block *this, 3868 unsigned long event, void *ptr) 3869 { 3870 struct qlcnic_adapter *adapter; 3871 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 3872 3873 recheck: 3874 if (dev == NULL) 3875 goto done; 3876 3877 if (dev->priv_flags & IFF_802_1Q_VLAN) { 3878 dev = vlan_dev_real_dev(dev); 3879 goto recheck; 3880 } 3881 3882 if (!is_qlcnic_netdev(dev)) 3883 goto done; 3884 3885 adapter = netdev_priv(dev); 3886 3887 if (!adapter) 3888 goto done; 3889 3890 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3891 goto done; 3892 3893 qlcnic_config_indev_addr(adapter, dev, event); 3894 done: 3895 return NOTIFY_DONE; 3896 } 3897 3898 static int 3899 qlcnic_inetaddr_event(struct notifier_block *this, 3900 unsigned long event, void *ptr) 3901 { 3902 struct qlcnic_adapter *adapter; 3903 struct net_device *dev; 3904 3905 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 3906 3907 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 3908 3909 recheck: 3910 if (dev == NULL) 3911 goto done; 3912 3913 if (dev->priv_flags & IFF_802_1Q_VLAN) { 3914 dev = vlan_dev_real_dev(dev); 3915 goto recheck; 3916 } 3917 3918 if (!is_qlcnic_netdev(dev)) 3919 goto done; 3920 3921 adapter = netdev_priv(dev); 3922 3923 if (!adapter) 3924 goto done; 3925 3926 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3927 goto done; 3928 3929 switch (event) { 3930 case NETDEV_UP: 3931 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); 3932 3933 break; 3934 case NETDEV_DOWN: 3935 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); 3936 3937 break; 3938 default: 3939 break; 3940 } 3941 3942 done: 3943 return NOTIFY_DONE; 3944 } 3945 3946 static struct notifier_block qlcnic_netdev_cb = { 3947 .notifier_call = qlcnic_netdev_event, 3948 }; 3949 3950 static struct notifier_block qlcnic_inetaddr_cb = { 3951 .notifier_call = qlcnic_inetaddr_event, 3952 }; 3953 #else 3954 void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) 3955 { } 3956 #endif 3957 static const struct pci_error_handlers qlcnic_err_handler = { 3958 .error_detected = qlcnic_io_error_detected, 3959 .slot_reset = qlcnic_io_slot_reset, 3960 .resume = qlcnic_io_resume, 3961 }; 3962 3963 static struct pci_driver qlcnic_driver = { 3964 .name = qlcnic_driver_name, 3965 .id_table = qlcnic_pci_tbl, 3966 .probe = qlcnic_probe, 3967 .remove = qlcnic_remove, 3968 #ifdef CONFIG_PM 3969 .suspend = qlcnic_suspend, 3970 .resume = qlcnic_resume, 3971 #endif 3972 .shutdown = qlcnic_shutdown, 3973 .err_handler = &qlcnic_err_handler, 3974 #ifdef CONFIG_QLCNIC_SRIOV 3975 .sriov_configure = qlcnic_pci_sriov_configure, 3976 #endif 3977 3978 }; 3979 3980 static int __init qlcnic_init_module(void) 3981 { 3982 int ret; 3983 3984 printk(KERN_INFO "%s\n", qlcnic_driver_string); 3985 3986 #ifdef CONFIG_INET 3987 register_netdevice_notifier(&qlcnic_netdev_cb); 3988 register_inetaddr_notifier(&qlcnic_inetaddr_cb); 3989 #endif 3990 3991 ret = pci_register_driver(&qlcnic_driver); 3992 if (ret) { 3993 #ifdef CONFIG_INET 3994 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 3995 unregister_netdevice_notifier(&qlcnic_netdev_cb); 3996 #endif 3997 } 3998 3999 return ret; 4000 } 4001 4002 module_init(qlcnic_init_module); 4003 4004 static void __exit qlcnic_exit_module(void) 4005 { 4006 pci_unregister_driver(&qlcnic_driver); 4007 4008 #ifdef CONFIG_INET 4009 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 4010 unregister_netdevice_notifier(&qlcnic_netdev_cb); 4011 #endif 4012 } 4013 4014 module_exit(qlcnic_exit_module); 4015