1aa43c215SJeff Kirsher /* 2aa43c215SJeff Kirsher * QLogic qlcnic NIC Driver 3577ae39dSJitendra Kalsaria * Copyright (c) 2009-2013 QLogic Corporation 4aa43c215SJeff Kirsher * 5aa43c215SJeff Kirsher * See LICENSE.qlcnic for copyright and licensing details. 6aa43c215SJeff Kirsher */ 7aa43c215SJeff Kirsher 8aa43c215SJeff Kirsher #include <linux/vmalloc.h> 9aa43c215SJeff Kirsher #include <linux/interrupt.h> 10aa43c215SJeff Kirsher 11aa43c215SJeff Kirsher #include "qlcnic.h" 12a15ebd37SHimanshu Madhani #include "qlcnic_hw.h" 13aa43c215SJeff Kirsher 14aa43c215SJeff Kirsher #include <linux/swab.h> 15aa43c215SJeff Kirsher #include <linux/dma-mapping.h> 1613159183SSony Chacko #include <linux/if_vlan.h> 17aa43c215SJeff Kirsher #include <net/ip.h> 18aa43c215SJeff Kirsher #include <linux/ipv6.h> 19aa43c215SJeff Kirsher #include <linux/inetdevice.h> 20aa43c215SJeff Kirsher #include <linux/aer.h> 21aa43c215SJeff Kirsher #include <linux/log2.h> 2247caf255SStephen Rothwell #include <linux/pci.h> 23aa43c215SJeff Kirsher 24aa43c215SJeff Kirsher MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); 25aa43c215SJeff Kirsher MODULE_LICENSE("GPL"); 26aa43c215SJeff Kirsher MODULE_VERSION(QLCNIC_LINUX_VERSIONID); 27aa43c215SJeff Kirsher MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); 28aa43c215SJeff Kirsher 29aa43c215SJeff Kirsher char qlcnic_driver_name[] = "qlcnic"; 30aa43c215SJeff Kirsher static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " 31aa43c215SJeff Kirsher "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; 32aa43c215SJeff Kirsher 33aa43c215SJeff Kirsher static int qlcnic_mac_learn; 34aa43c215SJeff Kirsher module_param(qlcnic_mac_learn, int, 0444); 35fe1adc6bSJitendra Kalsaria MODULE_PARM_DESC(qlcnic_mac_learn, 36fe1adc6bSJitendra Kalsaria "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)"); 37aa43c215SJeff Kirsher 38629263acSSony Chacko int qlcnic_use_msi = 1; 39aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); 40099f7aa7SSony Chacko module_param_named(use_msi, qlcnic_use_msi, int, 0444); 41aa43c215SJeff Kirsher 42629263acSSony Chacko int qlcnic_use_msi_x = 1; 43aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); 44099f7aa7SSony Chacko module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444); 45aa43c215SJeff Kirsher 46629263acSSony Chacko int qlcnic_auto_fw_reset = 1; 47aa43c215SJeff Kirsher MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); 48099f7aa7SSony Chacko module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644); 49aa43c215SJeff Kirsher 50629263acSSony Chacko int qlcnic_load_fw_file; 51aa43c215SJeff Kirsher MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); 52099f7aa7SSony Chacko module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444); 53aa43c215SJeff Kirsher 54629263acSSony Chacko int qlcnic_config_npars; 55aa43c215SJeff Kirsher module_param(qlcnic_config_npars, int, 0444); 56aa43c215SJeff Kirsher MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); 57aa43c215SJeff Kirsher 581dd06ae8SGreg Kroah-Hartman static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 596bb58bb0SBill Pemberton static void qlcnic_remove(struct pci_dev *pdev); 60aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev); 61aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev); 62aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev); 63aa43c215SJeff Kirsher static void qlcnic_attach_work(struct work_struct *work); 64aa43c215SJeff Kirsher static void qlcnic_fwinit_work(struct work_struct *work); 65aa43c215SJeff Kirsher static void qlcnic_fw_poll_work(struct work_struct *work); 66aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 67aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev); 68aa43c215SJeff Kirsher #endif 69aa43c215SJeff Kirsher 70aa43c215SJeff Kirsher static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); 71aa43c215SJeff Kirsher static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); 72aa43c215SJeff Kirsher static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); 73aa43c215SJeff Kirsher 74aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data); 75aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data); 76aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data); 77aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data); 7813159183SSony Chacko static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data); 79aa43c215SJeff Kirsher 80aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); 81aa43c215SJeff Kirsher static int qlcnic_start_firmware(struct qlcnic_adapter *); 82aa43c215SJeff Kirsher 83aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); 84aa43c215SJeff Kirsher static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); 85aa43c215SJeff Kirsher static int qlcnicvf_start_firmware(struct qlcnic_adapter *); 86aa43c215SJeff Kirsher static void qlcnic_set_netdev_features(struct qlcnic_adapter *, 87aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *); 888e586137SJiri Pirko static int qlcnic_vlan_rx_add(struct net_device *, u16); 898e586137SJiri Pirko static int qlcnic_vlan_rx_del(struct net_device *, u16); 90aa43c215SJeff Kirsher 91bff57d8eSSony Chacko #define QLCNIC_IS_TSO_CAPABLE(adapter) \ 92bff57d8eSSony Chacko ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO) 93bff57d8eSSony Chacko 9413159183SSony Chacko static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter) 9513159183SSony Chacko { 9613159183SSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 9713159183SSony Chacko 9813159183SSony Chacko if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X) 9913159183SSony Chacko return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX; 10013159183SSony Chacko else 10113159183SSony Chacko return 1; 10213159183SSony Chacko } 10313159183SSony Chacko 104aa43c215SJeff Kirsher /* PCI Device ID Table */ 105aa43c215SJeff Kirsher #define ENTRY(device) \ 106aa43c215SJeff Kirsher {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ 107aa43c215SJeff Kirsher .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} 108aa43c215SJeff Kirsher 109aa43c215SJeff Kirsher static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { 110aa43c215SJeff Kirsher ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), 11113159183SSony Chacko ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X), 112aa43c215SJeff Kirsher {0,} 113aa43c215SJeff Kirsher }; 114aa43c215SJeff Kirsher 115aa43c215SJeff Kirsher MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); 116aa43c215SJeff Kirsher 117aa43c215SJeff Kirsher 1185ad6ff9dSSony Chacko inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring) 119aa43c215SJeff Kirsher { 120aa43c215SJeff Kirsher writel(tx_ring->producer, tx_ring->crb_cmd_producer); 121aa43c215SJeff Kirsher } 122aa43c215SJeff Kirsher 123aa43c215SJeff Kirsher static const u32 msi_tgt_status[8] = { 124aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, 125aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, 126aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, 127aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 128aa43c215SJeff Kirsher }; 129aa43c215SJeff Kirsher 1307e2cf4feSSony Chacko static const u32 qlcnic_reg_tbl[] = { 1317e2cf4feSSony Chacko 0x1B20A8, /* PEG_HALT_STAT1 */ 1327e2cf4feSSony Chacko 0x1B20AC, /* PEG_HALT_STAT2 */ 1337e2cf4feSSony Chacko 0x1B20B0, /* FW_HEARTBEAT */ 1347e2cf4feSSony Chacko 0x1B2100, /* LOCK ID */ 1357e2cf4feSSony Chacko 0x1B2128, /* FW_CAPABILITIES */ 1367e2cf4feSSony Chacko 0x1B2138, /* drv active */ 1377e2cf4feSSony Chacko 0x1B2140, /* dev state */ 1387e2cf4feSSony Chacko 0x1B2144, /* drv state */ 1397e2cf4feSSony Chacko 0x1B2148, /* drv scratch */ 1407e2cf4feSSony Chacko 0x1B214C, /* dev partition info */ 1417e2cf4feSSony Chacko 0x1B2174, /* drv idc ver */ 1427e2cf4feSSony Chacko 0x1B2150, /* fw version major */ 1437e2cf4feSSony Chacko 0x1B2154, /* fw version minor */ 1447e2cf4feSSony Chacko 0x1B2158, /* fw version sub */ 1457e2cf4feSSony Chacko 0x1B219C, /* npar state */ 1467e2cf4feSSony Chacko 0x1B21FC, /* FW_IMG_VALID */ 1477e2cf4feSSony Chacko 0x1B2250, /* CMD_PEG_STATE */ 1487e2cf4feSSony Chacko 0x1B233C, /* RCV_PEG_STATE */ 1497e2cf4feSSony Chacko 0x1B23B4, /* ASIC TEMP */ 1507e2cf4feSSony Chacko 0x1B216C, /* FW api */ 1517e2cf4feSSony Chacko 0x1B2170, /* drv op mode */ 1527e2cf4feSSony Chacko 0x13C010, /* flash lock */ 1537e2cf4feSSony Chacko 0x13C014, /* flash unlock */ 1547e2cf4feSSony Chacko }; 1557e2cf4feSSony Chacko 15622999798SSony Chacko static const struct qlcnic_board_info qlcnic_boards[] = { 15722999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x203, 15822999798SSony Chacko "8200 Series Single Port 10GbE Converged Network Adapter" 15922999798SSony Chacko "(TCP/IP Networking)"}, 16022999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x207, 16122999798SSony Chacko "8200 Series Dual Port 10GbE Converged Network Adapter" 16222999798SSony Chacko "(TCP/IP Networking)"}, 16322999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20b, 16422999798SSony Chacko "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"}, 16522999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20c, 16622999798SSony Chacko "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"}, 16722999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20f, 16822999798SSony Chacko "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"}, 16922999798SSony Chacko {0x1077, 0x8020, 0x103c, 0x3733, 17022999798SSony Chacko "NC523SFP 10Gb 2-port Server Adapter"}, 17122999798SSony Chacko {0x1077, 0x8020, 0x103c, 0x3346, 17222999798SSony Chacko "CN1000Q Dual Port Converged Network Adapter"}, 17322999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x210, 17422999798SSony Chacko "QME8242-k 10GbE Dual Port Mezzanine Card"}, 17522999798SSony Chacko {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"}, 17622999798SSony Chacko }; 17722999798SSony Chacko 17822999798SSony Chacko #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards) 179319ecf12SSony Chacko #define QLC_MAX_SDS_RINGS 8 18022999798SSony Chacko 181aa43c215SJeff Kirsher static const 182aa43c215SJeff Kirsher struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; 183aa43c215SJeff Kirsher 184c70001a9SSony Chacko int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) 185aa43c215SJeff Kirsher { 186aa43c215SJeff Kirsher int size = sizeof(struct qlcnic_host_sds_ring) * count; 187aa43c215SJeff Kirsher 188aa43c215SJeff Kirsher recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); 189aa43c215SJeff Kirsher 190aa43c215SJeff Kirsher return recv_ctx->sds_rings == NULL; 191aa43c215SJeff Kirsher } 192aa43c215SJeff Kirsher 193c70001a9SSony Chacko void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) 194aa43c215SJeff Kirsher { 195aa43c215SJeff Kirsher if (recv_ctx->sds_rings != NULL) 196aa43c215SJeff Kirsher kfree(recv_ctx->sds_rings); 197aa43c215SJeff Kirsher 198aa43c215SJeff Kirsher recv_ctx->sds_rings = NULL; 199aa43c215SJeff Kirsher } 200aa43c215SJeff Kirsher 201aa43c215SJeff Kirsher static int 202aa43c215SJeff Kirsher qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) 203aa43c215SJeff Kirsher { 204aa43c215SJeff Kirsher u8 mac_addr[ETH_ALEN]; 205aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 206aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 207aa43c215SJeff Kirsher 208aa43c215SJeff Kirsher if (qlcnic_get_mac_address(adapter, mac_addr) != 0) 209aa43c215SJeff Kirsher return -EIO; 210aa43c215SJeff Kirsher 211aa43c215SJeff Kirsher memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); 212aa43c215SJeff Kirsher memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); 213aa43c215SJeff Kirsher 214aa43c215SJeff Kirsher /* set station address */ 215aa43c215SJeff Kirsher 216aaeb6cdfSJiri Pirko if (!is_valid_ether_addr(netdev->dev_addr)) 217aa43c215SJeff Kirsher dev_warn(&pdev->dev, "Bad MAC address %pM.\n", 218aa43c215SJeff Kirsher netdev->dev_addr); 219aa43c215SJeff Kirsher 220aa43c215SJeff Kirsher return 0; 221aa43c215SJeff Kirsher } 222aa43c215SJeff Kirsher 223aa43c215SJeff Kirsher static int qlcnic_set_mac(struct net_device *netdev, void *p) 224aa43c215SJeff Kirsher { 225aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 226aa43c215SJeff Kirsher struct sockaddr *addr = p; 227aa43c215SJeff Kirsher 228aa43c215SJeff Kirsher if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) 229aa43c215SJeff Kirsher return -EOPNOTSUPP; 230aa43c215SJeff Kirsher 231aa43c215SJeff Kirsher if (!is_valid_ether_addr(addr->sa_data)) 23213159183SSony Chacko return -EINVAL; 233aa43c215SJeff Kirsher 234aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 235aa43c215SJeff Kirsher netif_device_detach(netdev); 236aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 237aa43c215SJeff Kirsher } 238aa43c215SJeff Kirsher 239aa43c215SJeff Kirsher memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); 240aa43c215SJeff Kirsher memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 241aa43c215SJeff Kirsher qlcnic_set_multi(adapter->netdev); 242aa43c215SJeff Kirsher 243aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 244aa43c215SJeff Kirsher netif_device_attach(netdev); 245aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 246aa43c215SJeff Kirsher } 247aa43c215SJeff Kirsher return 0; 248aa43c215SJeff Kirsher } 249aa43c215SJeff Kirsher 2501690be63SVlad Yasevich static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], 2511690be63SVlad Yasevich struct net_device *netdev, const unsigned char *addr) 252fe1adc6bSJitendra Kalsaria { 253fe1adc6bSJitendra Kalsaria struct qlcnic_adapter *adapter = netdev_priv(netdev); 254fe1adc6bSJitendra Kalsaria int err = -EOPNOTSUPP; 255fe1adc6bSJitendra Kalsaria 256fe1adc6bSJitendra Kalsaria if (!adapter->fdb_mac_learn) { 257fe1adc6bSJitendra Kalsaria pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n", 258fe1adc6bSJitendra Kalsaria __func__); 259fe1adc6bSJitendra Kalsaria return err; 260fe1adc6bSJitendra Kalsaria } 261fe1adc6bSJitendra Kalsaria 262fe1adc6bSJitendra Kalsaria if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 263fe1adc6bSJitendra Kalsaria if (is_unicast_ether_addr(addr)) 264fe1adc6bSJitendra Kalsaria err = qlcnic_nic_del_mac(adapter, addr); 265fe1adc6bSJitendra Kalsaria else if (is_multicast_ether_addr(addr)) 266fe1adc6bSJitendra Kalsaria err = dev_mc_del(netdev, addr); 267fe1adc6bSJitendra Kalsaria else 268fe1adc6bSJitendra Kalsaria err = -EINVAL; 269fe1adc6bSJitendra Kalsaria } 270fe1adc6bSJitendra Kalsaria return err; 271fe1adc6bSJitendra Kalsaria } 272fe1adc6bSJitendra Kalsaria 273fe1adc6bSJitendra Kalsaria static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], 274fe1adc6bSJitendra Kalsaria struct net_device *netdev, 275fe1adc6bSJitendra Kalsaria const unsigned char *addr, u16 flags) 276fe1adc6bSJitendra Kalsaria { 277fe1adc6bSJitendra Kalsaria struct qlcnic_adapter *adapter = netdev_priv(netdev); 278fe1adc6bSJitendra Kalsaria int err = 0; 279fe1adc6bSJitendra Kalsaria 280fe1adc6bSJitendra Kalsaria if (!adapter->fdb_mac_learn) { 281fe1adc6bSJitendra Kalsaria pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n", 282fe1adc6bSJitendra Kalsaria __func__); 283fe1adc6bSJitendra Kalsaria return -EOPNOTSUPP; 284fe1adc6bSJitendra Kalsaria } 285fe1adc6bSJitendra Kalsaria 286fe1adc6bSJitendra Kalsaria if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { 287fe1adc6bSJitendra Kalsaria pr_info("%s: FDB e-switch is not enabled\n", __func__); 288fe1adc6bSJitendra Kalsaria return -EOPNOTSUPP; 289fe1adc6bSJitendra Kalsaria } 290fe1adc6bSJitendra Kalsaria 291fe1adc6bSJitendra Kalsaria if (ether_addr_equal(addr, adapter->mac_addr)) 292fe1adc6bSJitendra Kalsaria return err; 293fe1adc6bSJitendra Kalsaria 294fe1adc6bSJitendra Kalsaria if (is_unicast_ether_addr(addr)) 295fe1adc6bSJitendra Kalsaria err = qlcnic_nic_add_mac(adapter, addr); 296fe1adc6bSJitendra Kalsaria else if (is_multicast_ether_addr(addr)) 297fe1adc6bSJitendra Kalsaria err = dev_mc_add_excl(netdev, addr); 298fe1adc6bSJitendra Kalsaria else 299fe1adc6bSJitendra Kalsaria err = -EINVAL; 300fe1adc6bSJitendra Kalsaria 301fe1adc6bSJitendra Kalsaria return err; 302fe1adc6bSJitendra Kalsaria } 303fe1adc6bSJitendra Kalsaria 304fe1adc6bSJitendra Kalsaria static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb, 305fe1adc6bSJitendra Kalsaria struct net_device *netdev, int idx) 306fe1adc6bSJitendra Kalsaria { 307fe1adc6bSJitendra Kalsaria struct qlcnic_adapter *adapter = netdev_priv(netdev); 308fe1adc6bSJitendra Kalsaria 309fe1adc6bSJitendra Kalsaria if (!adapter->fdb_mac_learn) { 310fe1adc6bSJitendra Kalsaria pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n", 311fe1adc6bSJitendra Kalsaria __func__); 312fe1adc6bSJitendra Kalsaria return -EOPNOTSUPP; 313fe1adc6bSJitendra Kalsaria } 314fe1adc6bSJitendra Kalsaria 315fe1adc6bSJitendra Kalsaria if (adapter->flags & QLCNIC_ESWITCH_ENABLED) 316fe1adc6bSJitendra Kalsaria idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx); 317fe1adc6bSJitendra Kalsaria 318fe1adc6bSJitendra Kalsaria return idx; 319fe1adc6bSJitendra Kalsaria } 320fe1adc6bSJitendra Kalsaria 3217e2cf4feSSony Chacko static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter) 3227e2cf4feSSony Chacko { 3237e2cf4feSSony Chacko while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 3247e2cf4feSSony Chacko usleep_range(10000, 11000); 3257e2cf4feSSony Chacko 3267e2cf4feSSony Chacko cancel_delayed_work_sync(&adapter->fw_work); 3277e2cf4feSSony Chacko } 3287e2cf4feSSony Chacko 329aa43c215SJeff Kirsher static const struct net_device_ops qlcnic_netdev_ops = { 330aa43c215SJeff Kirsher .ndo_open = qlcnic_open, 331aa43c215SJeff Kirsher .ndo_stop = qlcnic_close, 332aa43c215SJeff Kirsher .ndo_start_xmit = qlcnic_xmit_frame, 333aa43c215SJeff Kirsher .ndo_get_stats = qlcnic_get_stats, 334aa43c215SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 335afc4b13dSJiri Pirko .ndo_set_rx_mode = qlcnic_set_multi, 336aa43c215SJeff Kirsher .ndo_set_mac_address = qlcnic_set_mac, 337aa43c215SJeff Kirsher .ndo_change_mtu = qlcnic_change_mtu, 338aa43c215SJeff Kirsher .ndo_fix_features = qlcnic_fix_features, 339aa43c215SJeff Kirsher .ndo_set_features = qlcnic_set_features, 340aa43c215SJeff Kirsher .ndo_tx_timeout = qlcnic_tx_timeout, 341aa43c215SJeff Kirsher .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, 342aa43c215SJeff Kirsher .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, 343fe1adc6bSJitendra Kalsaria .ndo_fdb_add = qlcnic_fdb_add, 344fe1adc6bSJitendra Kalsaria .ndo_fdb_del = qlcnic_fdb_del, 345fe1adc6bSJitendra Kalsaria .ndo_fdb_dump = qlcnic_fdb_dump, 346aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 347aa43c215SJeff Kirsher .ndo_poll_controller = qlcnic_poll_controller, 348aa43c215SJeff Kirsher #endif 349aa43c215SJeff Kirsher }; 350aa43c215SJeff Kirsher 351b43e5ee7SSucheta Chakraborty static const struct net_device_ops qlcnic_netdev_failed_ops = { 352b43e5ee7SSucheta Chakraborty .ndo_open = qlcnic_open, 353b43e5ee7SSucheta Chakraborty }; 354b43e5ee7SSucheta Chakraborty 355aa43c215SJeff Kirsher static struct qlcnic_nic_template qlcnic_ops = { 356aa43c215SJeff Kirsher .config_bridged_mode = qlcnic_config_bridged_mode, 3577e2cf4feSSony Chacko .config_led = qlcnic_82xx_config_led, 3587e2cf4feSSony Chacko .start_firmware = qlcnic_82xx_start_firmware, 3597e2cf4feSSony Chacko .request_reset = qlcnic_82xx_dev_request_reset, 3607e2cf4feSSony Chacko .cancel_idc_work = qlcnic_82xx_cancel_idc_work, 3617e2cf4feSSony Chacko .napi_add = qlcnic_82xx_napi_add, 3624be41e92SSony Chacko .napi_del = qlcnic_82xx_napi_del, 3637e2cf4feSSony Chacko .config_ipaddr = qlcnic_82xx_config_ipaddr, 3647e2cf4feSSony Chacko .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr, 365aa43c215SJeff Kirsher }; 366aa43c215SJeff Kirsher 3677e2cf4feSSony Chacko struct qlcnic_nic_template qlcnic_vf_ops = { 368aa43c215SJeff Kirsher .config_bridged_mode = qlcnicvf_config_bridged_mode, 369aa43c215SJeff Kirsher .config_led = qlcnicvf_config_led, 370aa43c215SJeff Kirsher .start_firmware = qlcnicvf_start_firmware 371aa43c215SJeff Kirsher }; 372aa43c215SJeff Kirsher 3737e2cf4feSSony Chacko static struct qlcnic_hardware_ops qlcnic_hw_ops = { 3747e2cf4feSSony Chacko .read_crb = qlcnic_82xx_read_crb, 3757e2cf4feSSony Chacko .write_crb = qlcnic_82xx_write_crb, 3767e2cf4feSSony Chacko .read_reg = qlcnic_82xx_hw_read_wx_2M, 3777e2cf4feSSony Chacko .write_reg = qlcnic_82xx_hw_write_wx_2M, 3787e2cf4feSSony Chacko .get_mac_address = qlcnic_82xx_get_mac_address, 3797e2cf4feSSony Chacko .setup_intr = qlcnic_82xx_setup_intr, 3807e2cf4feSSony Chacko .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args, 3817e2cf4feSSony Chacko .mbx_cmd = qlcnic_82xx_issue_cmd, 3827e2cf4feSSony Chacko .get_func_no = qlcnic_82xx_get_func_no, 3837e2cf4feSSony Chacko .api_lock = qlcnic_82xx_api_lock, 3847e2cf4feSSony Chacko .api_unlock = qlcnic_82xx_api_unlock, 3857e2cf4feSSony Chacko .add_sysfs = qlcnic_82xx_add_sysfs, 3867e2cf4feSSony Chacko .remove_sysfs = qlcnic_82xx_remove_sysfs, 3877e2cf4feSSony Chacko .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag, 3887e2cf4feSSony Chacko .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx, 3897e2cf4feSSony Chacko .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx, 3907e2cf4feSSony Chacko .setup_link_event = qlcnic_82xx_linkevent_request, 3917e2cf4feSSony Chacko .get_nic_info = qlcnic_82xx_get_nic_info, 3927e2cf4feSSony Chacko .get_pci_info = qlcnic_82xx_get_pci_info, 3937e2cf4feSSony Chacko .set_nic_info = qlcnic_82xx_set_nic_info, 3947e2cf4feSSony Chacko .change_macvlan = qlcnic_82xx_sre_macaddr_change, 3957e2cf4feSSony Chacko .napi_enable = qlcnic_82xx_napi_enable, 3967e2cf4feSSony Chacko .napi_disable = qlcnic_82xx_napi_disable, 3977e2cf4feSSony Chacko .config_intr_coal = qlcnic_82xx_config_intr_coalesce, 3987e2cf4feSSony Chacko .config_rss = qlcnic_82xx_config_rss, 3997e2cf4feSSony Chacko .config_hw_lro = qlcnic_82xx_config_hw_lro, 4007e2cf4feSSony Chacko .config_loopback = qlcnic_82xx_set_lb_mode, 4017e2cf4feSSony Chacko .clear_loopback = qlcnic_82xx_clear_lb_mode, 4027e2cf4feSSony Chacko .config_promisc_mode = qlcnic_82xx_nic_set_promisc, 4037e2cf4feSSony Chacko .change_l2_filter = qlcnic_82xx_change_filter, 4047e2cf4feSSony Chacko .get_board_info = qlcnic_82xx_get_board_info, 4057e2cf4feSSony Chacko }; 4067e2cf4feSSony Chacko 4077f966452SSony Chacko int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) 408aa43c215SJeff Kirsher { 409aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 41013159183SSony Chacko int err = -1, i; 41113159183SSony Chacko int max_tx_rings; 41213159183SSony Chacko 41313159183SSony Chacko if (!adapter->msix_entries) { 41413159183SSony Chacko adapter->msix_entries = kcalloc(num_msix, 41513159183SSony Chacko sizeof(struct msix_entry), 41613159183SSony Chacko GFP_KERNEL); 417b2adaca9SJoe Perches if (!adapter->msix_entries) 41813159183SSony Chacko return -ENOMEM; 41913159183SSony Chacko } 420aa43c215SJeff Kirsher 421aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 422aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); 423aa43c215SJeff Kirsher 42479788450SSony Chacko if (adapter->ahw->msix_supported) { 425aa43c215SJeff Kirsher enable_msix: 42613159183SSony Chacko for (i = 0; i < num_msix; i++) 42713159183SSony Chacko adapter->msix_entries[i].entry = i; 428aa43c215SJeff Kirsher err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); 429aa43c215SJeff Kirsher if (err == 0) { 430aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSIX_ENABLED; 43113159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 43213159183SSony Chacko adapter->ahw->num_msix = num_msix; 43313159183SSony Chacko /* subtract mail box and tx ring vectors */ 43413159183SSony Chacko max_tx_rings = adapter->max_drv_tx_rings; 43513159183SSony Chacko adapter->max_sds_rings = num_msix - 43613159183SSony Chacko max_tx_rings - 1; 43713159183SSony Chacko } else { 438aa43c215SJeff Kirsher adapter->max_sds_rings = num_msix; 43913159183SSony Chacko } 440aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi-x interrupts\n"); 441aa43c215SJeff Kirsher return err; 44213159183SSony Chacko } else if (err > 0) { 44313159183SSony Chacko dev_info(&pdev->dev, 44413159183SSony Chacko "Unable to allocate %d MSI-X interrupt vectors\n", 44513159183SSony Chacko num_msix); 44613159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 44713159183SSony Chacko if (err < QLC_83XX_MINIMUM_VECTOR) 44813159183SSony Chacko return err; 44913159183SSony Chacko err -= (adapter->max_drv_tx_rings + 1); 450aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(err); 45113159183SSony Chacko num_msix += (adapter->max_drv_tx_rings + 1); 45213159183SSony Chacko } else { 45313159183SSony Chacko num_msix = rounddown_pow_of_two(err); 45413159183SSony Chacko } 45513159183SSony Chacko 45613159183SSony Chacko if (num_msix) { 45713159183SSony Chacko dev_info(&pdev->dev, 458dce056cbSManish Chopra "Trying to allocate %d MSI-X interrupt vectors\n", 45913159183SSony Chacko num_msix); 460aa43c215SJeff Kirsher goto enable_msix; 461aa43c215SJeff Kirsher } 46213159183SSony Chacko } else { 463dce056cbSManish Chopra dev_info(&pdev->dev, 464dce056cbSManish Chopra "Unable to allocate %d MSI-X interrupt vectors\n", 46513159183SSony Chacko num_msix); 466aa43c215SJeff Kirsher } 46713159183SSony Chacko } 46813159183SSony Chacko 469aa43c215SJeff Kirsher return err; 470aa43c215SJeff Kirsher } 471aa43c215SJeff Kirsher 4729a97e705SManish chopra static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) 473aa43c215SJeff Kirsher { 4749a97e705SManish chopra int err = 0; 47515087c2bSSony Chacko u32 offset, mask_reg; 476aa43c215SJeff Kirsher const struct qlcnic_legacy_intr_set *legacy_intrp; 47715087c2bSSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 478aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 479aa43c215SJeff Kirsher 480099f7aa7SSony Chacko if (qlcnic_use_msi && !pci_enable_msi(pdev)) { 481aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSI_ENABLED; 48215087c2bSSony Chacko offset = msi_tgt_status[adapter->ahw->pci_func]; 48315087c2bSSony Chacko adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw, 48415087c2bSSony Chacko offset); 485aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi interrupts\n"); 486aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 4879a97e705SManish chopra return err; 488aa43c215SJeff Kirsher } 4899a97e705SManish chopra if (qlcnic_use_msi || qlcnic_use_msi_x) 4909a97e705SManish chopra return -EOPNOTSUPP; 491aa43c215SJeff Kirsher 492aa43c215SJeff Kirsher legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; 49379788450SSony Chacko adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit; 49415087c2bSSony Chacko offset = legacy_intrp->tgt_status_reg; 49515087c2bSSony Chacko adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset); 49615087c2bSSony Chacko mask_reg = legacy_intrp->tgt_mask_reg; 49715087c2bSSony Chacko adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg); 49815087c2bSSony Chacko adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR); 49915087c2bSSony Chacko adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG); 500aa43c215SJeff Kirsher dev_info(&pdev->dev, "using legacy interrupts\n"); 501aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 5029a97e705SManish chopra return err; 503aa43c215SJeff Kirsher } 504aa43c215SJeff Kirsher 5057e2cf4feSSony Chacko int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr) 506aa43c215SJeff Kirsher { 5079a97e705SManish chopra int num_msix, err = 0; 508aa43c215SJeff Kirsher 5097e2cf4feSSony Chacko if (!num_intr) 5107e2cf4feSSony Chacko num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS; 5117e2cf4feSSony Chacko 5127e2cf4feSSony Chacko if (adapter->ahw->msix_supported) 513aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(), 5147e2cf4feSSony Chacko num_intr)); 5157e2cf4feSSony Chacko else 516aa43c215SJeff Kirsher num_msix = 1; 517aa43c215SJeff Kirsher 5187e2cf4feSSony Chacko err = qlcnic_enable_msix(adapter, num_msix); 5197e2cf4feSSony Chacko if (err == -ENOMEM || !err) 5207e2cf4feSSony Chacko return err; 521aa43c215SJeff Kirsher 5229a97e705SManish chopra err = qlcnic_enable_msi_legacy(adapter); 5239a97e705SManish chopra if (!err) 5249a97e705SManish chopra return err; 5259a97e705SManish chopra 5269a97e705SManish chopra return -EIO; 527aa43c215SJeff Kirsher } 52813159183SSony Chacko 529319ecf12SSony Chacko void qlcnic_teardown_intr(struct qlcnic_adapter *adapter) 530aa43c215SJeff Kirsher { 531aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 532aa43c215SJeff Kirsher pci_disable_msix(adapter->pdev); 533aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSI_ENABLED) 534aa43c215SJeff Kirsher pci_disable_msi(adapter->pdev); 53513159183SSony Chacko 53613159183SSony Chacko kfree(adapter->msix_entries); 53713159183SSony Chacko adapter->msix_entries = NULL; 53813159183SSony Chacko 53913159183SSony Chacko if (adapter->ahw->intr_tbl) { 54013159183SSony Chacko vfree(adapter->ahw->intr_tbl); 54113159183SSony Chacko adapter->ahw->intr_tbl = NULL; 54213159183SSony Chacko } 543aa43c215SJeff Kirsher } 544aa43c215SJeff Kirsher 545aa43c215SJeff Kirsher static void 546aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) 547aa43c215SJeff Kirsher { 548aa43c215SJeff Kirsher if (adapter->ahw->pci_base0 != NULL) 549aa43c215SJeff Kirsher iounmap(adapter->ahw->pci_base0); 550aa43c215SJeff Kirsher } 551aa43c215SJeff Kirsher 5527e2cf4feSSony Chacko static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter) 5537e2cf4feSSony Chacko { 5547e2cf4feSSony Chacko struct qlcnic_pci_info *pci_info; 5557e2cf4feSSony Chacko int ret; 5567e2cf4feSSony Chacko 5577e2cf4feSSony Chacko if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { 5587e2cf4feSSony Chacko switch (adapter->ahw->port_type) { 5597e2cf4feSSony Chacko case QLCNIC_GBE: 5607e2cf4feSSony Chacko adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS; 5617e2cf4feSSony Chacko break; 5627e2cf4feSSony Chacko case QLCNIC_XGBE: 5637e2cf4feSSony Chacko adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS; 5647e2cf4feSSony Chacko break; 5657e2cf4feSSony Chacko } 5667e2cf4feSSony Chacko return 0; 5677e2cf4feSSony Chacko } 5687e2cf4feSSony Chacko 5697e2cf4feSSony Chacko if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 5707e2cf4feSSony Chacko return 0; 5717e2cf4feSSony Chacko 5727e2cf4feSSony Chacko pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 5737e2cf4feSSony Chacko if (!pci_info) 5747e2cf4feSSony Chacko return -ENOMEM; 5757e2cf4feSSony Chacko 5767e2cf4feSSony Chacko ret = qlcnic_get_pci_info(adapter, pci_info); 5777e2cf4feSSony Chacko kfree(pci_info); 5787e2cf4feSSony Chacko return ret; 5797e2cf4feSSony Chacko } 580d71170fbSSony Chacko 581d71170fbSSony Chacko int qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 582aa43c215SJeff Kirsher { 583aa43c215SJeff Kirsher struct qlcnic_pci_info *pci_info; 584bff57d8eSSony Chacko int i, ret = 0, j = 0; 585bff57d8eSSony Chacko u16 act_pci_func; 586aa43c215SJeff Kirsher u8 pfn; 587aa43c215SJeff Kirsher 588aa43c215SJeff Kirsher pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 589aa43c215SJeff Kirsher if (!pci_info) 590aa43c215SJeff Kirsher return -ENOMEM; 591aa43c215SJeff Kirsher 592bff57d8eSSony Chacko ret = qlcnic_get_pci_info(adapter, pci_info); 593bff57d8eSSony Chacko if (ret) 594bff57d8eSSony Chacko goto err_pci_info; 595bff57d8eSSony Chacko 596bff57d8eSSony Chacko act_pci_func = adapter->ahw->act_pci_func; 597bff57d8eSSony Chacko 598aa43c215SJeff Kirsher adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 599bff57d8eSSony Chacko act_pci_func, GFP_KERNEL); 600aa43c215SJeff Kirsher if (!adapter->npars) { 601aa43c215SJeff Kirsher ret = -ENOMEM; 602aa43c215SJeff Kirsher goto err_pci_info; 603aa43c215SJeff Kirsher } 604aa43c215SJeff Kirsher 605aa43c215SJeff Kirsher adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 606aa43c215SJeff Kirsher QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 607aa43c215SJeff Kirsher if (!adapter->eswitch) { 608aa43c215SJeff Kirsher ret = -ENOMEM; 609aa43c215SJeff Kirsher goto err_npars; 610aa43c215SJeff Kirsher } 611aa43c215SJeff Kirsher 612aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 613aa43c215SJeff Kirsher pfn = pci_info[i].id; 614bff57d8eSSony Chacko 6150f6efff9SDan Carpenter if (pfn >= QLCNIC_MAX_PCI_FUNC) { 616aa43c215SJeff Kirsher ret = QL_STATUS_INVALID_PARAM; 617aa43c215SJeff Kirsher goto err_eswitch; 618aa43c215SJeff Kirsher } 619bff57d8eSSony Chacko 620bff57d8eSSony Chacko if (!pci_info[i].active || 621bff57d8eSSony Chacko (pci_info[i].type != QLCNIC_TYPE_NIC)) 622bff57d8eSSony Chacko continue; 623bff57d8eSSony Chacko 624bff57d8eSSony Chacko adapter->npars[j].pci_func = pfn; 625bff57d8eSSony Chacko adapter->npars[j].active = (u8)pci_info[i].active; 626bff57d8eSSony Chacko adapter->npars[j].type = (u8)pci_info[i].type; 627bff57d8eSSony Chacko adapter->npars[j].phy_port = (u8)pci_info[i].default_port; 628bff57d8eSSony Chacko adapter->npars[j].min_bw = pci_info[i].tx_min_bw; 629bff57d8eSSony Chacko adapter->npars[j].max_bw = pci_info[i].tx_max_bw; 630bff57d8eSSony Chacko j++; 631aa43c215SJeff Kirsher } 632aa43c215SJeff Kirsher 63313159183SSony Chacko for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) { 634aa43c215SJeff Kirsher adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; 63513159183SSony Chacko if (qlcnic_83xx_check(adapter)) 63613159183SSony Chacko qlcnic_enable_eswitch(adapter, i, 1); 63713159183SSony Chacko } 638aa43c215SJeff Kirsher 639aa43c215SJeff Kirsher kfree(pci_info); 640aa43c215SJeff Kirsher return 0; 641aa43c215SJeff Kirsher 642aa43c215SJeff Kirsher err_eswitch: 643aa43c215SJeff Kirsher kfree(adapter->eswitch); 644aa43c215SJeff Kirsher adapter->eswitch = NULL; 645aa43c215SJeff Kirsher err_npars: 646aa43c215SJeff Kirsher kfree(adapter->npars); 647aa43c215SJeff Kirsher adapter->npars = NULL; 648aa43c215SJeff Kirsher err_pci_info: 649aa43c215SJeff Kirsher kfree(pci_info); 650aa43c215SJeff Kirsher 651aa43c215SJeff Kirsher return ret; 652aa43c215SJeff Kirsher } 653aa43c215SJeff Kirsher 654aa43c215SJeff Kirsher static int 655aa43c215SJeff Kirsher qlcnic_set_function_modes(struct qlcnic_adapter *adapter) 656aa43c215SJeff Kirsher { 657aa43c215SJeff Kirsher u8 id; 658aa43c215SJeff Kirsher int i, ret = 1; 659aa43c215SJeff Kirsher u32 data = QLCNIC_MGMT_FUNC; 660bff57d8eSSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 661aa43c215SJeff Kirsher 662aa43c215SJeff Kirsher ret = qlcnic_api_lock(adapter); 663aa43c215SJeff Kirsher if (ret) 664aa43c215SJeff Kirsher goto err_lock; 665aa43c215SJeff Kirsher 666aa43c215SJeff Kirsher if (qlcnic_config_npars) { 667bff57d8eSSony Chacko for (i = 0; i < ahw->act_pci_func; i++) { 668bff57d8eSSony Chacko id = adapter->npars[i].pci_func; 669bff57d8eSSony Chacko if (id == ahw->pci_func) 670aa43c215SJeff Kirsher continue; 671aa43c215SJeff Kirsher data |= (qlcnic_config_npars & 672aa43c215SJeff Kirsher QLC_DEV_SET_DRV(0xf, id)); 673aa43c215SJeff Kirsher } 674aa43c215SJeff Kirsher } else { 675a15ebd37SHimanshu Madhani data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 676bff57d8eSSony Chacko data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) | 677aa43c215SJeff Kirsher (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, 678bff57d8eSSony Chacko ahw->pci_func)); 679aa43c215SJeff Kirsher } 680a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data); 681aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 682aa43c215SJeff Kirsher err_lock: 683aa43c215SJeff Kirsher return ret; 684aa43c215SJeff Kirsher } 685aa43c215SJeff Kirsher 68613159183SSony Chacko static void qlcnic_check_vf(struct qlcnic_adapter *adapter, 68713159183SSony Chacko const struct pci_device_id *ent) 688aa43c215SJeff Kirsher { 689aa43c215SJeff Kirsher u32 op_mode, priv_level; 690aa43c215SJeff Kirsher 691aa43c215SJeff Kirsher /* Determine FW API version */ 69213159183SSony Chacko adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter, 693aa43c215SJeff Kirsher QLCNIC_FW_API); 694aa43c215SJeff Kirsher 695aa43c215SJeff Kirsher /* Find PCI function number */ 69613159183SSony Chacko qlcnic_get_func_no(adapter); 697aa43c215SJeff Kirsher 698aa43c215SJeff Kirsher /* Determine function privilege level */ 69913159183SSony Chacko op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 700aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 701aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 702aa43c215SJeff Kirsher else 703aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 704aa43c215SJeff Kirsher 705aa43c215SJeff Kirsher if (priv_level == QLCNIC_NON_PRIV_FUNC) { 70679788450SSony Chacko adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC; 707aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 708aa43c215SJeff Kirsher "HAL Version: %d Non Privileged function\n", 70979788450SSony Chacko adapter->ahw->fw_hal_version); 710aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_vf_ops; 711aa43c215SJeff Kirsher } else 712aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_ops; 713aa43c215SJeff Kirsher } 714aa43c215SJeff Kirsher 71515087c2bSSony Chacko #define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL 71613159183SSony Chacko #define QLCNIC_83XX_BAR0_LENGTH 0x4000 71715087c2bSSony Chacko static void qlcnic_get_bar_length(u32 dev_id, ulong *bar) 718aa43c215SJeff Kirsher { 71915087c2bSSony Chacko switch (dev_id) { 72015087c2bSSony Chacko case PCI_DEVICE_ID_QLOGIC_QLE824X: 72115087c2bSSony Chacko *bar = QLCNIC_82XX_BAR0_LENGTH; 72215087c2bSSony Chacko break; 72313159183SSony Chacko case PCI_DEVICE_ID_QLOGIC_QLE834X: 72413159183SSony Chacko *bar = QLCNIC_83XX_BAR0_LENGTH; 72513159183SSony Chacko break; 72615087c2bSSony Chacko default: 72715087c2bSSony Chacko *bar = 0; 72815087c2bSSony Chacko } 72915087c2bSSony Chacko } 73015087c2bSSony Chacko 73115087c2bSSony Chacko static int qlcnic_setup_pci_map(struct pci_dev *pdev, 73215087c2bSSony Chacko struct qlcnic_hardware_context *ahw) 73315087c2bSSony Chacko { 73415087c2bSSony Chacko u32 offset; 735aa43c215SJeff Kirsher void __iomem *mem_ptr0 = NULL; 73615087c2bSSony Chacko unsigned long mem_len, pci_len0 = 0, bar0_len; 737aa43c215SJeff Kirsher 738aa43c215SJeff Kirsher /* remap phys address */ 739aa43c215SJeff Kirsher mem_len = pci_resource_len(pdev, 0); 740aa43c215SJeff Kirsher 74115087c2bSSony Chacko qlcnic_get_bar_length(pdev->device, &bar0_len); 74215087c2bSSony Chacko if (mem_len >= bar0_len) { 743aa43c215SJeff Kirsher 744aa43c215SJeff Kirsher mem_ptr0 = pci_ioremap_bar(pdev, 0); 745aa43c215SJeff Kirsher if (mem_ptr0 == NULL) { 746aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to map PCI bar 0\n"); 747aa43c215SJeff Kirsher return -EIO; 748aa43c215SJeff Kirsher } 749aa43c215SJeff Kirsher pci_len0 = mem_len; 750aa43c215SJeff Kirsher } else { 751aa43c215SJeff Kirsher return -EIO; 752aa43c215SJeff Kirsher } 753aa43c215SJeff Kirsher 754aa43c215SJeff Kirsher dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); 7557e2cf4feSSony Chacko 75615087c2bSSony Chacko ahw->pci_base0 = mem_ptr0; 75715087c2bSSony Chacko ahw->pci_len0 = pci_len0; 75815087c2bSSony Chacko offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func)); 75915087c2bSSony Chacko qlcnic_get_ioaddr(ahw, offset); 760aa43c215SJeff Kirsher 761aa43c215SJeff Kirsher return 0; 762aa43c215SJeff Kirsher } 763aa43c215SJeff Kirsher 76422999798SSony Chacko static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name) 765aa43c215SJeff Kirsher { 766aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 767aa43c215SJeff Kirsher int i, found = 0; 768aa43c215SJeff Kirsher 769aa43c215SJeff Kirsher for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { 770aa43c215SJeff Kirsher if (qlcnic_boards[i].vendor == pdev->vendor && 771aa43c215SJeff Kirsher qlcnic_boards[i].device == pdev->device && 772aa43c215SJeff Kirsher qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && 773aa43c215SJeff Kirsher qlcnic_boards[i].sub_device == pdev->subsystem_device) { 774aa43c215SJeff Kirsher sprintf(name, "%pM: %s" , 775aa43c215SJeff Kirsher adapter->mac_addr, 776aa43c215SJeff Kirsher qlcnic_boards[i].short_name); 777aa43c215SJeff Kirsher found = 1; 778aa43c215SJeff Kirsher break; 779aa43c215SJeff Kirsher } 780aa43c215SJeff Kirsher 781aa43c215SJeff Kirsher } 782aa43c215SJeff Kirsher 783aa43c215SJeff Kirsher if (!found) 784aa43c215SJeff Kirsher sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); 785aa43c215SJeff Kirsher } 786aa43c215SJeff Kirsher 787aa43c215SJeff Kirsher static void 788aa43c215SJeff Kirsher qlcnic_check_options(struct qlcnic_adapter *adapter) 789aa43c215SJeff Kirsher { 790a15ebd37SHimanshu Madhani int err; 791aa43c215SJeff Kirsher u32 fw_major, fw_minor, fw_build, prev_fw_version; 792aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 793a15ebd37SHimanshu Madhani struct qlcnic_hardware_context *ahw = adapter->ahw; 794a15ebd37SHimanshu Madhani struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump; 795aa43c215SJeff Kirsher 796aa43c215SJeff Kirsher prev_fw_version = adapter->fw_version; 797aa43c215SJeff Kirsher 798a15ebd37SHimanshu Madhani fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR); 799a15ebd37SHimanshu Madhani fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR); 800a15ebd37SHimanshu Madhani fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB); 801aa43c215SJeff Kirsher 802aa43c215SJeff Kirsher adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); 803aa43c215SJeff Kirsher 804a15ebd37SHimanshu Madhani err = qlcnic_get_board_info(adapter); 805a15ebd37SHimanshu Madhani if (err) { 806a15ebd37SHimanshu Madhani dev_err(&pdev->dev, "Error getting board config info.\n"); 807a15ebd37SHimanshu Madhani return; 808a15ebd37SHimanshu Madhani } 809a15ebd37SHimanshu Madhani if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) { 810aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr == NULL || 811aa43c215SJeff Kirsher adapter->fw_version > prev_fw_version) { 812aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr) 813aa43c215SJeff Kirsher vfree(fw_dump->tmpl_hdr); 814aa43c215SJeff Kirsher if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) 815aa43c215SJeff Kirsher dev_info(&pdev->dev, 816aa43c215SJeff Kirsher "Supports FW dump capability\n"); 817aa43c215SJeff Kirsher } 818aa43c215SJeff Kirsher } 819aa43c215SJeff Kirsher 82013159183SSony Chacko dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n", 82113159183SSony Chacko QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build); 82213159183SSony Chacko 823aa43c215SJeff Kirsher if (adapter->ahw->port_type == QLCNIC_XGBE) { 824aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 825aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; 826aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; 827aa43c215SJeff Kirsher } else { 828aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; 829aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; 830aa43c215SJeff Kirsher } 831aa43c215SJeff Kirsher 832aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 833aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 834aa43c215SJeff Kirsher 835aa43c215SJeff Kirsher } else if (adapter->ahw->port_type == QLCNIC_GBE) { 836aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 837aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 838aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 839aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; 840aa43c215SJeff Kirsher } 841aa43c215SJeff Kirsher 842099f7aa7SSony Chacko adapter->ahw->msix_supported = !!qlcnic_use_msi_x; 843aa43c215SJeff Kirsher 844aa43c215SJeff Kirsher adapter->num_txd = MAX_CMD_DESCRIPTORS; 845aa43c215SJeff Kirsher 846aa43c215SJeff Kirsher adapter->max_rds_rings = MAX_RDS_RINGS; 847aa43c215SJeff Kirsher } 848aa43c215SJeff Kirsher 849aa43c215SJeff Kirsher static int 850aa43c215SJeff Kirsher qlcnic_initialize_nic(struct qlcnic_adapter *adapter) 851aa43c215SJeff Kirsher { 852aa43c215SJeff Kirsher int err; 853aa43c215SJeff Kirsher struct qlcnic_info nic_info; 854aa43c215SJeff Kirsher 855bff57d8eSSony Chacko memset(&nic_info, 0, sizeof(struct qlcnic_info)); 856aa43c215SJeff Kirsher err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); 857aa43c215SJeff Kirsher if (err) 858aa43c215SJeff Kirsher return err; 859aa43c215SJeff Kirsher 86079788450SSony Chacko adapter->ahw->physical_port = (u8)nic_info.phys_port; 86179788450SSony Chacko adapter->ahw->switch_mode = nic_info.switch_mode; 86279788450SSony Chacko adapter->ahw->max_tx_ques = nic_info.max_tx_ques; 86379788450SSony Chacko adapter->ahw->max_rx_ques = nic_info.max_rx_ques; 86479788450SSony Chacko adapter->ahw->capabilities = nic_info.capabilities; 865776e7bdeSShahed Shaikh 866776e7bdeSShahed Shaikh if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 867776e7bdeSShahed Shaikh u32 temp; 868776e7bdeSShahed Shaikh temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); 869776e7bdeSShahed Shaikh adapter->ahw->capabilities2 = temp; 870776e7bdeSShahed Shaikh } 87179788450SSony Chacko adapter->ahw->max_mac_filters = nic_info.max_mac_filters; 87279788450SSony Chacko adapter->ahw->max_mtu = nic_info.max_mtu; 873aa43c215SJeff Kirsher 87413159183SSony Chacko /* Disable NPAR for 83XX */ 87513159183SSony Chacko if (qlcnic_83xx_check(adapter)) 87613159183SSony Chacko return err; 87713159183SSony Chacko 87879788450SSony Chacko if (adapter->ahw->capabilities & BIT_6) 879aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ESWITCH_ENABLED; 880aa43c215SJeff Kirsher else 881aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; 882aa43c215SJeff Kirsher 883aa43c215SJeff Kirsher return err; 884aa43c215SJeff Kirsher } 885aa43c215SJeff Kirsher 886ec079a07SSony Chacko void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, 887aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 888aa43c215SJeff Kirsher { 889aa43c215SJeff Kirsher if (esw_cfg->discard_tagged) 890aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_TAGGING_ENABLED; 891aa43c215SJeff Kirsher else 892aa43c215SJeff Kirsher adapter->flags |= QLCNIC_TAGGING_ENABLED; 893aa43c215SJeff Kirsher 894aa43c215SJeff Kirsher if (esw_cfg->vlan_id) 895aa43c215SJeff Kirsher adapter->pvid = esw_cfg->vlan_id; 896aa43c215SJeff Kirsher else 897aa43c215SJeff Kirsher adapter->pvid = 0; 898aa43c215SJeff Kirsher } 899aa43c215SJeff Kirsher 9008e586137SJiri Pirko static int 901aa43c215SJeff Kirsher qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid) 902aa43c215SJeff Kirsher { 903aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 904aa43c215SJeff Kirsher set_bit(vid, adapter->vlans); 9058e586137SJiri Pirko return 0; 906aa43c215SJeff Kirsher } 907aa43c215SJeff Kirsher 9088e586137SJiri Pirko static int 909aa43c215SJeff Kirsher qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) 910aa43c215SJeff Kirsher { 911aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 912aa43c215SJeff Kirsher 913aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); 914aa43c215SJeff Kirsher clear_bit(vid, adapter->vlans); 9158e586137SJiri Pirko return 0; 916aa43c215SJeff Kirsher } 917aa43c215SJeff Kirsher 918ec079a07SSony Chacko void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, 919aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 920aa43c215SJeff Kirsher { 921aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | 922aa43c215SJeff Kirsher QLCNIC_PROMISC_DISABLED); 923aa43c215SJeff Kirsher 924aa43c215SJeff Kirsher if (esw_cfg->mac_anti_spoof) 925aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MACSPOOF; 926aa43c215SJeff Kirsher 927aa43c215SJeff Kirsher if (!esw_cfg->mac_override) 928aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; 929aa43c215SJeff Kirsher 930aa43c215SJeff Kirsher if (!esw_cfg->promisc_mode) 931aa43c215SJeff Kirsher adapter->flags |= QLCNIC_PROMISC_DISABLED; 932aa43c215SJeff Kirsher 933aa43c215SJeff Kirsher qlcnic_set_netdev_features(adapter, esw_cfg); 934aa43c215SJeff Kirsher } 935aa43c215SJeff Kirsher 936d71170fbSSony Chacko int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) 937aa43c215SJeff Kirsher { 938aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 939aa43c215SJeff Kirsher 940aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 941aa43c215SJeff Kirsher return 0; 942aa43c215SJeff Kirsher 943aa43c215SJeff Kirsher esw_cfg.pci_func = adapter->ahw->pci_func; 944aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 945aa43c215SJeff Kirsher return -EIO; 946aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg); 947aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg); 948aa43c215SJeff Kirsher 949aa43c215SJeff Kirsher return 0; 950aa43c215SJeff Kirsher } 951aa43c215SJeff Kirsher 952aa43c215SJeff Kirsher static void 953aa43c215SJeff Kirsher qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, 954aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 955aa43c215SJeff Kirsher { 956aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 95713159183SSony Chacko unsigned long features, vlan_features; 958aa43c215SJeff Kirsher 95913159183SSony Chacko if (qlcnic_83xx_check(adapter)) 96013159183SSony Chacko return; 96113159183SSony Chacko 9627e38d04bSSony Chacko features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 963aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_GRO); 964aa43c215SJeff Kirsher vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | 96513159183SSony Chacko NETIF_F_IPV6_CSUM); 966aa43c215SJeff Kirsher 96713159183SSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) { 968aa43c215SJeff Kirsher features |= (NETIF_F_TSO | NETIF_F_TSO6); 969aa43c215SJeff Kirsher vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 970aa43c215SJeff Kirsher } 971aa43c215SJeff Kirsher 972aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 973aa43c215SJeff Kirsher features |= NETIF_F_LRO; 974aa43c215SJeff Kirsher 975aa43c215SJeff Kirsher if (esw_cfg->offload_flags & BIT_0) { 976aa43c215SJeff Kirsher netdev->features |= features; 97713159183SSony Chacko adapter->rx_csum = 1; 9787e38d04bSSony Chacko if (!(esw_cfg->offload_flags & BIT_1)) { 979aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO; 9807e38d04bSSony Chacko features &= ~NETIF_F_TSO; 9817e38d04bSSony Chacko } 9827e38d04bSSony Chacko if (!(esw_cfg->offload_flags & BIT_2)) { 983aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO6; 9847e38d04bSSony Chacko features &= ~NETIF_F_TSO6; 9857e38d04bSSony Chacko } 986aa43c215SJeff Kirsher } else { 987aa43c215SJeff Kirsher netdev->features &= ~features; 9887e38d04bSSony Chacko features &= ~features; 98913159183SSony Chacko adapter->rx_csum = 0; 990aa43c215SJeff Kirsher } 991aa43c215SJeff Kirsher 992aa43c215SJeff Kirsher netdev->vlan_features = (features & vlan_features); 993aa43c215SJeff Kirsher } 994aa43c215SJeff Kirsher 995aa43c215SJeff Kirsher static int 996aa43c215SJeff Kirsher qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) 997aa43c215SJeff Kirsher { 998aa43c215SJeff Kirsher u32 op_mode, priv_level; 999aa43c215SJeff Kirsher int err = 0; 1000aa43c215SJeff Kirsher 1001aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 1002aa43c215SJeff Kirsher if (err) 1003aa43c215SJeff Kirsher return err; 1004aa43c215SJeff Kirsher 1005aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 1006aa43c215SJeff Kirsher return 0; 1007aa43c215SJeff Kirsher 100813159183SSony Chacko op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 1009aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 1010aa43c215SJeff Kirsher 1011aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 1012aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 1013aa43c215SJeff Kirsher else 1014aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 1015aa43c215SJeff Kirsher 1016aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 1017aa43c215SJeff Kirsher if (priv_level == QLCNIC_MGMT_FUNC) { 101879788450SSony Chacko adapter->ahw->op_mode = QLCNIC_MGMT_FUNC; 1019aa43c215SJeff Kirsher err = qlcnic_init_pci_info(adapter); 1020aa43c215SJeff Kirsher if (err) 1021aa43c215SJeff Kirsher return err; 1022aa43c215SJeff Kirsher /* Set privilege level for other functions */ 1023aa43c215SJeff Kirsher qlcnic_set_function_modes(adapter); 1024aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 1025aa43c215SJeff Kirsher "HAL Version: %d, Management function\n", 102679788450SSony Chacko adapter->ahw->fw_hal_version); 1027aa43c215SJeff Kirsher } else if (priv_level == QLCNIC_PRIV_FUNC) { 102879788450SSony Chacko adapter->ahw->op_mode = QLCNIC_PRIV_FUNC; 1029aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 1030aa43c215SJeff Kirsher "HAL Version: %d, Privileged function\n", 103179788450SSony Chacko adapter->ahw->fw_hal_version); 1032aa43c215SJeff Kirsher } 1033aa43c215SJeff Kirsher } 1034aa43c215SJeff Kirsher 1035aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; 1036aa43c215SJeff Kirsher 1037aa43c215SJeff Kirsher return err; 1038aa43c215SJeff Kirsher } 1039aa43c215SJeff Kirsher 1040d71170fbSSony Chacko int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) 1041aa43c215SJeff Kirsher { 1042aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 1043aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 1044aa43c215SJeff Kirsher u8 i; 1045aa43c215SJeff Kirsher 1046aa43c215SJeff Kirsher if (adapter->need_fw_reset) 1047aa43c215SJeff Kirsher return 0; 1048aa43c215SJeff Kirsher 1049bff57d8eSSony Chacko for (i = 0; i < adapter->ahw->act_pci_func; i++) { 1050aa43c215SJeff Kirsher memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); 1051bff57d8eSSony Chacko esw_cfg.pci_func = adapter->npars[i].pci_func; 1052aa43c215SJeff Kirsher esw_cfg.mac_override = BIT_0; 1053aa43c215SJeff Kirsher esw_cfg.promisc_mode = BIT_0; 1054bff57d8eSSony Chacko if (qlcnic_82xx_check(adapter)) { 1055bff57d8eSSony Chacko esw_cfg.offload_flags = BIT_0; 1056bff57d8eSSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) 1057aa43c215SJeff Kirsher esw_cfg.offload_flags |= (BIT_1 | BIT_2); 1058bff57d8eSSony Chacko } 1059aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1060aa43c215SJeff Kirsher return -EIO; 1061aa43c215SJeff Kirsher npar = &adapter->npars[i]; 1062aa43c215SJeff Kirsher npar->pvid = esw_cfg.vlan_id; 1063aa43c215SJeff Kirsher npar->mac_override = esw_cfg.mac_override; 1064aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; 1065aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg.discard_tagged; 1066aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg.promisc_mode; 1067aa43c215SJeff Kirsher npar->offload_flags = esw_cfg.offload_flags; 1068aa43c215SJeff Kirsher } 1069aa43c215SJeff Kirsher 1070aa43c215SJeff Kirsher return 0; 1071aa43c215SJeff Kirsher } 1072aa43c215SJeff Kirsher 107313159183SSony Chacko 1074aa43c215SJeff Kirsher static int 1075aa43c215SJeff Kirsher qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, 1076aa43c215SJeff Kirsher struct qlcnic_npar_info *npar, int pci_func) 1077aa43c215SJeff Kirsher { 1078aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 1079aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; 1080aa43c215SJeff Kirsher esw_cfg.pci_func = pci_func; 1081aa43c215SJeff Kirsher esw_cfg.vlan_id = npar->pvid; 1082aa43c215SJeff Kirsher esw_cfg.mac_override = npar->mac_override; 1083aa43c215SJeff Kirsher esw_cfg.discard_tagged = npar->discard_tagged; 1084aa43c215SJeff Kirsher esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; 1085aa43c215SJeff Kirsher esw_cfg.offload_flags = npar->offload_flags; 1086aa43c215SJeff Kirsher esw_cfg.promisc_mode = npar->promisc_mode; 1087aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1088aa43c215SJeff Kirsher return -EIO; 1089aa43c215SJeff Kirsher 1090aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_ADD_VLAN; 1091aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1092aa43c215SJeff Kirsher return -EIO; 1093aa43c215SJeff Kirsher 1094aa43c215SJeff Kirsher return 0; 1095aa43c215SJeff Kirsher } 1096aa43c215SJeff Kirsher 1097d71170fbSSony Chacko int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 1098aa43c215SJeff Kirsher { 1099aa43c215SJeff Kirsher int i, err; 1100aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 1101aa43c215SJeff Kirsher struct qlcnic_info nic_info; 1102bff57d8eSSony Chacko u8 pci_func; 1103aa43c215SJeff Kirsher 1104bff57d8eSSony Chacko if (qlcnic_82xx_check(adapter)) 1105aa43c215SJeff Kirsher if (!adapter->need_fw_reset) 1106aa43c215SJeff Kirsher return 0; 1107aa43c215SJeff Kirsher 1108aa43c215SJeff Kirsher /* Set the NPAR config data after FW reset */ 1109bff57d8eSSony Chacko for (i = 0; i < adapter->ahw->act_pci_func; i++) { 1110aa43c215SJeff Kirsher npar = &adapter->npars[i]; 1111bff57d8eSSony Chacko pci_func = npar->pci_func; 1112bff57d8eSSony Chacko memset(&nic_info, 0, sizeof(struct qlcnic_info)); 111313159183SSony Chacko err = qlcnic_get_nic_info(adapter, &nic_info, pci_func); 1114aa43c215SJeff Kirsher if (err) 1115aa43c215SJeff Kirsher return err; 1116aa43c215SJeff Kirsher nic_info.min_tx_bw = npar->min_bw; 1117aa43c215SJeff Kirsher nic_info.max_tx_bw = npar->max_bw; 1118aa43c215SJeff Kirsher err = qlcnic_set_nic_info(adapter, &nic_info); 1119aa43c215SJeff Kirsher if (err) 1120aa43c215SJeff Kirsher return err; 1121aa43c215SJeff Kirsher 1122aa43c215SJeff Kirsher if (npar->enable_pm) { 1123aa43c215SJeff Kirsher err = qlcnic_config_port_mirroring(adapter, 1124bff57d8eSSony Chacko npar->dest_npar, 1, 1125bff57d8eSSony Chacko pci_func); 1126aa43c215SJeff Kirsher if (err) 1127aa43c215SJeff Kirsher return err; 1128aa43c215SJeff Kirsher } 1129bff57d8eSSony Chacko err = qlcnic_reset_eswitch_config(adapter, npar, pci_func); 1130aa43c215SJeff Kirsher if (err) 1131aa43c215SJeff Kirsher return err; 1132aa43c215SJeff Kirsher } 1133aa43c215SJeff Kirsher return 0; 1134aa43c215SJeff Kirsher } 1135aa43c215SJeff Kirsher 1136aa43c215SJeff Kirsher static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) 1137aa43c215SJeff Kirsher { 1138aa43c215SJeff Kirsher u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; 1139aa43c215SJeff Kirsher u32 npar_state; 1140aa43c215SJeff Kirsher 114179788450SSony Chacko if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 1142aa43c215SJeff Kirsher return 0; 1143aa43c215SJeff Kirsher 1144a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 1145a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 1146aa43c215SJeff Kirsher while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { 1147aa43c215SJeff Kirsher msleep(1000); 1148a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 1149a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 1150aa43c215SJeff Kirsher } 1151aa43c215SJeff Kirsher if (!npar_opt_timeo) { 1152aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1153aa43c215SJeff Kirsher "Waiting for NPAR state to opertional timeout\n"); 1154aa43c215SJeff Kirsher return -EIO; 1155aa43c215SJeff Kirsher } 1156aa43c215SJeff Kirsher return 0; 1157aa43c215SJeff Kirsher } 1158aa43c215SJeff Kirsher 1159aa43c215SJeff Kirsher static int 1160aa43c215SJeff Kirsher qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) 1161aa43c215SJeff Kirsher { 1162aa43c215SJeff Kirsher int err; 1163aa43c215SJeff Kirsher 1164aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 116579788450SSony Chacko adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) 1166aa43c215SJeff Kirsher return 0; 1167aa43c215SJeff Kirsher 1168aa43c215SJeff Kirsher err = qlcnic_set_default_offload_settings(adapter); 1169aa43c215SJeff Kirsher if (err) 1170aa43c215SJeff Kirsher return err; 1171aa43c215SJeff Kirsher 1172aa43c215SJeff Kirsher err = qlcnic_reset_npar_config(adapter); 1173aa43c215SJeff Kirsher if (err) 1174aa43c215SJeff Kirsher return err; 1175aa43c215SJeff Kirsher 1176aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(adapter); 1177aa43c215SJeff Kirsher 1178aa43c215SJeff Kirsher return err; 1179aa43c215SJeff Kirsher } 1180aa43c215SJeff Kirsher 11817e2cf4feSSony Chacko int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter) 1182aa43c215SJeff Kirsher { 1183aa43c215SJeff Kirsher int err; 1184aa43c215SJeff Kirsher 1185aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 1186aa43c215SJeff Kirsher if (err < 0) 1187aa43c215SJeff Kirsher return err; 1188aa43c215SJeff Kirsher else if (!err) 1189aa43c215SJeff Kirsher goto check_fw_status; 1190aa43c215SJeff Kirsher 1191099f7aa7SSony Chacko if (qlcnic_load_fw_file) 1192aa43c215SJeff Kirsher qlcnic_request_firmware(adapter); 1193aa43c215SJeff Kirsher else { 1194aa43c215SJeff Kirsher err = qlcnic_check_flash_fw_ver(adapter); 1195aa43c215SJeff Kirsher if (err) 1196aa43c215SJeff Kirsher goto err_out; 1197aa43c215SJeff Kirsher 119879788450SSony Chacko adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE; 1199aa43c215SJeff Kirsher } 1200aa43c215SJeff Kirsher 1201aa43c215SJeff Kirsher err = qlcnic_need_fw_reset(adapter); 1202aa43c215SJeff Kirsher if (err == 0) 1203aa43c215SJeff Kirsher goto check_fw_status; 1204aa43c215SJeff Kirsher 1205aa43c215SJeff Kirsher err = qlcnic_pinit_from_rom(adapter); 1206aa43c215SJeff Kirsher if (err) 1207aa43c215SJeff Kirsher goto err_out; 1208aa43c215SJeff Kirsher 1209aa43c215SJeff Kirsher err = qlcnic_load_firmware(adapter); 1210aa43c215SJeff Kirsher if (err) 1211aa43c215SJeff Kirsher goto err_out; 1212aa43c215SJeff Kirsher 1213aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1214aa43c215SJeff Kirsher QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); 1215aa43c215SJeff Kirsher 1216aa43c215SJeff Kirsher check_fw_status: 1217aa43c215SJeff Kirsher err = qlcnic_check_fw_status(adapter); 1218aa43c215SJeff Kirsher if (err) 1219aa43c215SJeff Kirsher goto err_out; 1220aa43c215SJeff Kirsher 1221a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1222aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 1); 1223aa43c215SJeff Kirsher err = qlcnic_check_eswitch_mode(adapter); 1224aa43c215SJeff Kirsher if (err) { 1225aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1226aa43c215SJeff Kirsher "Memory allocation failed for eswitch\n"); 1227aa43c215SJeff Kirsher goto err_out; 1228aa43c215SJeff Kirsher } 1229aa43c215SJeff Kirsher err = qlcnic_set_mgmt_operations(adapter); 1230aa43c215SJeff Kirsher if (err) 1231aa43c215SJeff Kirsher goto err_out; 1232aa43c215SJeff Kirsher 1233aa43c215SJeff Kirsher qlcnic_check_options(adapter); 1234aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 1235aa43c215SJeff Kirsher 1236aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1237aa43c215SJeff Kirsher return 0; 1238aa43c215SJeff Kirsher 1239aa43c215SJeff Kirsher err_out: 1240a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1241aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1242aa43c215SJeff Kirsher 1243aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1244aa43c215SJeff Kirsher return err; 1245aa43c215SJeff Kirsher } 1246aa43c215SJeff Kirsher 1247aa43c215SJeff Kirsher static int 1248aa43c215SJeff Kirsher qlcnic_request_irq(struct qlcnic_adapter *adapter) 1249aa43c215SJeff Kirsher { 1250aa43c215SJeff Kirsher irq_handler_t handler; 1251aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 125213159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 1253aa43c215SJeff Kirsher int err, ring; 1254aa43c215SJeff Kirsher 1255aa43c215SJeff Kirsher unsigned long flags = 0; 1256aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1257aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1258aa43c215SJeff Kirsher 125979788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 126013159183SSony Chacko if (qlcnic_82xx_check(adapter)) 1261aa43c215SJeff Kirsher handler = qlcnic_tmp_intr; 1262aa43c215SJeff Kirsher if (!QLCNIC_IS_MSI_FAMILY(adapter)) 1263aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1264aa43c215SJeff Kirsher 1265aa43c215SJeff Kirsher } else { 1266aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 1267aa43c215SJeff Kirsher handler = qlcnic_msix_intr; 1268aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) 1269aa43c215SJeff Kirsher handler = qlcnic_msi_intr; 1270aa43c215SJeff Kirsher else { 1271aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1272aa43c215SJeff Kirsher handler = qlcnic_intr; 1273aa43c215SJeff Kirsher } 1274aa43c215SJeff Kirsher } 1275aa43c215SJeff Kirsher adapter->irq = netdev->irq; 1276aa43c215SJeff Kirsher 127713159183SSony Chacko if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1278aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1279aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 128013159183SSony Chacko snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ, 128113159183SSony Chacko "%s[%d]", netdev->name, ring); 128213159183SSony Chacko err = request_irq(sds_ring->irq, handler, flags, 128313159183SSony Chacko sds_ring->name, sds_ring); 1284aa43c215SJeff Kirsher if (err) 1285aa43c215SJeff Kirsher return err; 1286aa43c215SJeff Kirsher } 128713159183SSony Chacko if (qlcnic_83xx_check(adapter) && 128813159183SSony Chacko (adapter->flags & QLCNIC_MSIX_ENABLED)) { 128913159183SSony Chacko handler = qlcnic_msix_tx_intr; 129013159183SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; 129113159183SSony Chacko ring++) { 129213159183SSony Chacko tx_ring = &adapter->tx_ring[ring]; 129313159183SSony Chacko snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ, 129413159183SSony Chacko "%s[%d]", netdev->name, 129513159183SSony Chacko adapter->max_sds_rings + ring); 129613159183SSony Chacko err = request_irq(tx_ring->irq, handler, flags, 129713159183SSony Chacko tx_ring->name, tx_ring); 129813159183SSony Chacko if (err) 129913159183SSony Chacko return err; 130013159183SSony Chacko } 130113159183SSony Chacko } 130213159183SSony Chacko } 1303aa43c215SJeff Kirsher return 0; 1304aa43c215SJeff Kirsher } 1305aa43c215SJeff Kirsher 1306aa43c215SJeff Kirsher static void 1307aa43c215SJeff Kirsher qlcnic_free_irq(struct qlcnic_adapter *adapter) 1308aa43c215SJeff Kirsher { 1309aa43c215SJeff Kirsher int ring; 1310aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 131113159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 1312aa43c215SJeff Kirsher 1313aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1314aa43c215SJeff Kirsher 131513159183SSony Chacko if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1316aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1317aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1318aa43c215SJeff Kirsher free_irq(sds_ring->irq, sds_ring); 1319aa43c215SJeff Kirsher } 132013159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 132113159183SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; 132213159183SSony Chacko ring++) { 132313159183SSony Chacko tx_ring = &adapter->tx_ring[ring]; 132413159183SSony Chacko if (tx_ring->irq) 132513159183SSony Chacko free_irq(tx_ring->irq, tx_ring); 132613159183SSony Chacko } 132713159183SSony Chacko } 132813159183SSony Chacko } 1329aa43c215SJeff Kirsher } 1330aa43c215SJeff Kirsher 1331319ecf12SSony Chacko int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1332aa43c215SJeff Kirsher { 1333aa43c215SJeff Kirsher int ring; 1334cae82d49SRajesh Borundia u32 capab2; 1335cae82d49SRajesh Borundia 1336aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1337aa43c215SJeff Kirsher 1338aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1339aa43c215SJeff Kirsher return -EIO; 1340aa43c215SJeff Kirsher 1341aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1342aa43c215SJeff Kirsher return 0; 1343aa43c215SJeff Kirsher if (qlcnic_set_eswitch_port_config(adapter)) 1344aa43c215SJeff Kirsher return -EIO; 1345aa43c215SJeff Kirsher 134679788450SSony Chacko if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 1347cae82d49SRajesh Borundia capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); 1348cae82d49SRajesh Borundia if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG) 1349cae82d49SRajesh Borundia adapter->flags |= QLCNIC_FW_LRO_MSS_CAP; 1350cae82d49SRajesh Borundia } 1351cae82d49SRajesh Borundia 1352aa43c215SJeff Kirsher if (qlcnic_fw_create_ctx(adapter)) 1353aa43c215SJeff Kirsher return -EIO; 1354aa43c215SJeff Kirsher 1355aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1356aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 13574be41e92SSony Chacko qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1358aa43c215SJeff Kirsher } 1359aa43c215SJeff Kirsher 1360aa43c215SJeff Kirsher qlcnic_set_multi(netdev); 1361aa43c215SJeff Kirsher qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1362aa43c215SJeff Kirsher 1363aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 1364aa43c215SJeff Kirsher 1365aa43c215SJeff Kirsher if (adapter->max_sds_rings > 1) 1366aa43c215SJeff Kirsher qlcnic_config_rss(adapter, 1); 1367aa43c215SJeff Kirsher 1368aa43c215SJeff Kirsher qlcnic_config_intr_coalesce(adapter); 1369aa43c215SJeff Kirsher 1370aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 1371aa43c215SJeff Kirsher qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1372aa43c215SJeff Kirsher 1373aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 1374aa43c215SJeff Kirsher 1375aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1376aa43c215SJeff Kirsher 137779788450SSony Chacko adapter->ahw->reset_context = 0; 1378aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1379aa43c215SJeff Kirsher return 0; 1380aa43c215SJeff Kirsher } 1381aa43c215SJeff Kirsher 1382629263acSSony Chacko int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1383aa43c215SJeff Kirsher { 1384aa43c215SJeff Kirsher int err = 0; 1385aa43c215SJeff Kirsher 1386aa43c215SJeff Kirsher rtnl_lock(); 1387aa43c215SJeff Kirsher if (netif_running(netdev)) 1388aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1389aa43c215SJeff Kirsher rtnl_unlock(); 1390aa43c215SJeff Kirsher 1391aa43c215SJeff Kirsher return err; 1392aa43c215SJeff Kirsher } 1393aa43c215SJeff Kirsher 1394319ecf12SSony Chacko void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1395aa43c215SJeff Kirsher { 1396aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1397aa43c215SJeff Kirsher return; 1398aa43c215SJeff Kirsher 1399aa43c215SJeff Kirsher if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) 1400aa43c215SJeff Kirsher return; 1401aa43c215SJeff Kirsher 1402aa43c215SJeff Kirsher smp_mb(); 1403aa43c215SJeff Kirsher spin_lock(&adapter->tx_clean_lock); 1404aa43c215SJeff Kirsher netif_carrier_off(netdev); 1405aa43c215SJeff Kirsher netif_tx_disable(netdev); 1406aa43c215SJeff Kirsher 1407aa43c215SJeff Kirsher qlcnic_free_mac_list(adapter); 1408aa43c215SJeff Kirsher 1409aa43c215SJeff Kirsher if (adapter->fhash.fnum) 1410aa43c215SJeff Kirsher qlcnic_delete_lb_filters(adapter); 1411aa43c215SJeff Kirsher 1412aa43c215SJeff Kirsher qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1413aa43c215SJeff Kirsher 1414aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 1415aa43c215SJeff Kirsher 1416aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1417cae82d49SRajesh Borundia adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP; 1418aa43c215SJeff Kirsher 1419aa43c215SJeff Kirsher qlcnic_reset_rx_buffers_list(adapter); 1420aa43c215SJeff Kirsher qlcnic_release_tx_buffers(adapter); 1421aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 1422aa43c215SJeff Kirsher } 1423aa43c215SJeff Kirsher 1424aa43c215SJeff Kirsher /* Usage: During suspend and firmware recovery module */ 1425aa43c215SJeff Kirsher 1426629263acSSony Chacko void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1427aa43c215SJeff Kirsher { 1428aa43c215SJeff Kirsher rtnl_lock(); 1429aa43c215SJeff Kirsher if (netif_running(netdev)) 1430aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1431aa43c215SJeff Kirsher rtnl_unlock(); 1432aa43c215SJeff Kirsher 1433aa43c215SJeff Kirsher } 1434aa43c215SJeff Kirsher 1435319ecf12SSony Chacko int 1436aa43c215SJeff Kirsher qlcnic_attach(struct qlcnic_adapter *adapter) 1437aa43c215SJeff Kirsher { 1438aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1439aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1440aa43c215SJeff Kirsher int err; 1441aa43c215SJeff Kirsher 1442aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) 1443aa43c215SJeff Kirsher return 0; 1444aa43c215SJeff Kirsher 1445aa43c215SJeff Kirsher err = qlcnic_napi_add(adapter, netdev); 1446aa43c215SJeff Kirsher if (err) 1447aa43c215SJeff Kirsher return err; 1448aa43c215SJeff Kirsher 1449aa43c215SJeff Kirsher err = qlcnic_alloc_sw_resources(adapter); 1450aa43c215SJeff Kirsher if (err) { 1451aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting sw resources\n"); 1452aa43c215SJeff Kirsher goto err_out_napi_del; 1453aa43c215SJeff Kirsher } 1454aa43c215SJeff Kirsher 1455aa43c215SJeff Kirsher err = qlcnic_alloc_hw_resources(adapter); 1456aa43c215SJeff Kirsher if (err) { 1457aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting hw resources\n"); 1458aa43c215SJeff Kirsher goto err_out_free_sw; 1459aa43c215SJeff Kirsher } 1460aa43c215SJeff Kirsher 1461aa43c215SJeff Kirsher err = qlcnic_request_irq(adapter); 1462aa43c215SJeff Kirsher if (err) { 1463aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to setup interrupt\n"); 1464aa43c215SJeff Kirsher goto err_out_free_hw; 1465aa43c215SJeff Kirsher } 1466aa43c215SJeff Kirsher 1467aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(adapter); 1468aa43c215SJeff Kirsher 1469aa43c215SJeff Kirsher adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; 1470aa43c215SJeff Kirsher return 0; 1471aa43c215SJeff Kirsher 1472aa43c215SJeff Kirsher err_out_free_hw: 1473aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1474aa43c215SJeff Kirsher err_out_free_sw: 1475aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1476aa43c215SJeff Kirsher err_out_napi_del: 1477aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1478aa43c215SJeff Kirsher return err; 1479aa43c215SJeff Kirsher } 1480aa43c215SJeff Kirsher 1481319ecf12SSony Chacko void qlcnic_detach(struct qlcnic_adapter *adapter) 1482aa43c215SJeff Kirsher { 1483aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1484aa43c215SJeff Kirsher return; 1485aa43c215SJeff Kirsher 1486aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(adapter); 1487aa43c215SJeff Kirsher 1488aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1489aa43c215SJeff Kirsher qlcnic_release_rx_buffers(adapter); 1490aa43c215SJeff Kirsher qlcnic_free_irq(adapter); 1491aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1492aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1493aa43c215SJeff Kirsher 1494aa43c215SJeff Kirsher adapter->is_up = 0; 1495aa43c215SJeff Kirsher } 1496aa43c215SJeff Kirsher 1497aa43c215SJeff Kirsher void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) 1498aa43c215SJeff Kirsher { 1499aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1500aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1501aa43c215SJeff Kirsher int ring; 1502aa43c215SJeff Kirsher 1503aa43c215SJeff Kirsher clear_bit(__QLCNIC_DEV_UP, &adapter->state); 150479788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1505aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1506aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1507aa43c215SJeff Kirsher qlcnic_disable_int(sds_ring); 1508aa43c215SJeff Kirsher } 1509aa43c215SJeff Kirsher } 1510aa43c215SJeff Kirsher 1511aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1512aa43c215SJeff Kirsher 1513aa43c215SJeff Kirsher qlcnic_detach(adapter); 1514aa43c215SJeff Kirsher 151579788450SSony Chacko adapter->ahw->diag_test = 0; 1516aa43c215SJeff Kirsher adapter->max_sds_rings = max_sds_rings; 1517aa43c215SJeff Kirsher 1518aa43c215SJeff Kirsher if (qlcnic_attach(adapter)) 1519aa43c215SJeff Kirsher goto out; 1520aa43c215SJeff Kirsher 1521aa43c215SJeff Kirsher if (netif_running(netdev)) 1522aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 1523aa43c215SJeff Kirsher out: 1524aa43c215SJeff Kirsher netif_device_attach(netdev); 1525aa43c215SJeff Kirsher } 1526aa43c215SJeff Kirsher 1527aa43c215SJeff Kirsher static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) 1528aa43c215SJeff Kirsher { 1529aa43c215SJeff Kirsher int err = 0; 1530aa43c215SJeff Kirsher adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), 1531aa43c215SJeff Kirsher GFP_KERNEL); 1532aa43c215SJeff Kirsher if (!adapter->recv_ctx) { 1533aa43c215SJeff Kirsher err = -ENOMEM; 1534aa43c215SJeff Kirsher goto err_out; 1535aa43c215SJeff Kirsher } 1536aa43c215SJeff Kirsher /* Initialize interrupt coalesce parameters */ 1537aa43c215SJeff Kirsher adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; 1538aa43c215SJeff Kirsher adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; 1539aa43c215SJeff Kirsher adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; 15404be41e92SSony Chacko /* clear stats */ 15414be41e92SSony Chacko memset(&adapter->stats, 0, sizeof(adapter->stats)); 1542aa43c215SJeff Kirsher err_out: 1543aa43c215SJeff Kirsher return err; 1544aa43c215SJeff Kirsher } 1545aa43c215SJeff Kirsher 1546aa43c215SJeff Kirsher static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) 1547aa43c215SJeff Kirsher { 1548aa43c215SJeff Kirsher kfree(adapter->recv_ctx); 1549aa43c215SJeff Kirsher adapter->recv_ctx = NULL; 1550aa43c215SJeff Kirsher 1551aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.tmpl_hdr) { 1552aa43c215SJeff Kirsher vfree(adapter->ahw->fw_dump.tmpl_hdr); 1553aa43c215SJeff Kirsher adapter->ahw->fw_dump.tmpl_hdr = NULL; 1554aa43c215SJeff Kirsher } 15554be41e92SSony Chacko 155681d0aeb0SSony Chacko kfree(adapter->ahw->reset.buff); 15574be41e92SSony Chacko adapter->ahw->fw_dump.tmpl_hdr = NULL; 1558aa43c215SJeff Kirsher } 1559aa43c215SJeff Kirsher 1560aa43c215SJeff Kirsher int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1561aa43c215SJeff Kirsher { 1562aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1563aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1564aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1565aa43c215SJeff Kirsher int ring; 1566aa43c215SJeff Kirsher int ret; 1567aa43c215SJeff Kirsher 1568aa43c215SJeff Kirsher netif_device_detach(netdev); 1569aa43c215SJeff Kirsher 1570aa43c215SJeff Kirsher if (netif_running(netdev)) 1571aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1572aa43c215SJeff Kirsher 1573aa43c215SJeff Kirsher qlcnic_detach(adapter); 1574aa43c215SJeff Kirsher 1575aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 157679788450SSony Chacko adapter->ahw->diag_test = test; 15774be41e92SSony Chacko adapter->ahw->linkup = 0; 1578aa43c215SJeff Kirsher 1579aa43c215SJeff Kirsher ret = qlcnic_attach(adapter); 1580aa43c215SJeff Kirsher if (ret) { 1581aa43c215SJeff Kirsher netif_device_attach(netdev); 1582aa43c215SJeff Kirsher return ret; 1583aa43c215SJeff Kirsher } 1584aa43c215SJeff Kirsher 1585aa43c215SJeff Kirsher ret = qlcnic_fw_create_ctx(adapter); 1586aa43c215SJeff Kirsher if (ret) { 1587aa43c215SJeff Kirsher qlcnic_detach(adapter); 1588aa43c215SJeff Kirsher netif_device_attach(netdev); 1589aa43c215SJeff Kirsher return ret; 1590aa43c215SJeff Kirsher } 1591aa43c215SJeff Kirsher 1592aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1593aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 15944be41e92SSony Chacko qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1595aa43c215SJeff Kirsher } 1596aa43c215SJeff Kirsher 159779788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1598aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1599aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 1600aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 1601aa43c215SJeff Kirsher } 1602aa43c215SJeff Kirsher } 1603aa43c215SJeff Kirsher 160479788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) { 1605aa43c215SJeff Kirsher adapter->ahw->loopback_state = 0; 1606aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1607aa43c215SJeff Kirsher } 1608aa43c215SJeff Kirsher 1609aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1610aa43c215SJeff Kirsher 1611aa43c215SJeff Kirsher return 0; 1612aa43c215SJeff Kirsher } 1613aa43c215SJeff Kirsher 1614aa43c215SJeff Kirsher /* Reset context in hardware only */ 1615aa43c215SJeff Kirsher static int 1616aa43c215SJeff Kirsher qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) 1617aa43c215SJeff Kirsher { 1618aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1619aa43c215SJeff Kirsher 1620aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1621aa43c215SJeff Kirsher return -EBUSY; 1622aa43c215SJeff Kirsher 1623aa43c215SJeff Kirsher netif_device_detach(netdev); 1624aa43c215SJeff Kirsher 1625aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1626aa43c215SJeff Kirsher 1627aa43c215SJeff Kirsher qlcnic_up(adapter, netdev); 1628aa43c215SJeff Kirsher 1629aa43c215SJeff Kirsher netif_device_attach(netdev); 1630aa43c215SJeff Kirsher 1631aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 163213159183SSony Chacko dev_err(&adapter->pdev->dev, "%s:\n", __func__); 1633aa43c215SJeff Kirsher return 0; 1634aa43c215SJeff Kirsher } 1635aa43c215SJeff Kirsher 1636aa43c215SJeff Kirsher int 1637aa43c215SJeff Kirsher qlcnic_reset_context(struct qlcnic_adapter *adapter) 1638aa43c215SJeff Kirsher { 1639aa43c215SJeff Kirsher int err = 0; 1640aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1641aa43c215SJeff Kirsher 1642aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1643aa43c215SJeff Kirsher return -EBUSY; 1644aa43c215SJeff Kirsher 1645aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { 1646aa43c215SJeff Kirsher 1647aa43c215SJeff Kirsher netif_device_detach(netdev); 1648aa43c215SJeff Kirsher 1649aa43c215SJeff Kirsher if (netif_running(netdev)) 1650aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1651aa43c215SJeff Kirsher 1652aa43c215SJeff Kirsher qlcnic_detach(adapter); 1653aa43c215SJeff Kirsher 1654aa43c215SJeff Kirsher if (netif_running(netdev)) { 1655aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 16561d5c88e3SAnirban Chakraborty if (!err) { 1657aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 16581d5c88e3SAnirban Chakraborty qlcnic_restore_indev_addr(netdev, NETDEV_UP); 16591d5c88e3SAnirban Chakraborty } 1660aa43c215SJeff Kirsher } 1661aa43c215SJeff Kirsher 1662aa43c215SJeff Kirsher netif_device_attach(netdev); 1663aa43c215SJeff Kirsher } 1664aa43c215SJeff Kirsher 1665aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1666aa43c215SJeff Kirsher return err; 1667aa43c215SJeff Kirsher } 1668aa43c215SJeff Kirsher 1669aa43c215SJeff Kirsher static int 16705ad6ff9dSSony Chacko qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev, 16715ad6ff9dSSony Chacko int pci_using_dac) 1672aa43c215SJeff Kirsher { 1673aa43c215SJeff Kirsher int err; 1674aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1675aa43c215SJeff Kirsher 167613159183SSony Chacko adapter->rx_csum = 1; 167779788450SSony Chacko adapter->ahw->mc_enabled = 0; 167813159183SSony Chacko adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT; 1679aa43c215SJeff Kirsher 1680aa43c215SJeff Kirsher netdev->netdev_ops = &qlcnic_netdev_ops; 168113159183SSony Chacko netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ; 1682aa43c215SJeff Kirsher 1683aa43c215SJeff Kirsher qlcnic_change_mtu(netdev, netdev->mtu); 1684aa43c215SJeff Kirsher 1685aa43c215SJeff Kirsher SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 1686aa43c215SJeff Kirsher 16877e38d04bSSony Chacko netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 168813159183SSony Chacko NETIF_F_IPV6_CSUM | NETIF_F_GRO | 168913159183SSony Chacko NETIF_F_HW_VLAN_RX); 169013159183SSony Chacko netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | 169113159183SSony Chacko NETIF_F_IPV6_CSUM); 1692aa43c215SJeff Kirsher 169313159183SSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) { 169413159183SSony Chacko netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6); 169513159183SSony Chacko netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 169613159183SSony Chacko } 1697aa43c215SJeff Kirsher 169813159183SSony Chacko if (pci_using_dac) { 169913159183SSony Chacko netdev->features |= NETIF_F_HIGHDMA; 170013159183SSony Chacko netdev->vlan_features |= NETIF_F_HIGHDMA; 170113159183SSony Chacko } 1702aa43c215SJeff Kirsher 170313159183SSony Chacko if (qlcnic_vlan_tx_check(adapter)) 170413159183SSony Chacko netdev->features |= (NETIF_F_HW_VLAN_TX); 170513159183SSony Chacko 170679788450SSony Chacko if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 170713159183SSony Chacko netdev->features |= NETIF_F_LRO; 1708aa43c215SJeff Kirsher 17097e38d04bSSony Chacko netdev->hw_features = netdev->features; 1710aa43c215SJeff Kirsher netdev->irq = adapter->msix_entries[0].vector; 1711aa43c215SJeff Kirsher 1712aa43c215SJeff Kirsher err = register_netdev(netdev); 1713aa43c215SJeff Kirsher if (err) { 1714aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to register net device\n"); 1715aa43c215SJeff Kirsher return err; 1716aa43c215SJeff Kirsher } 1717aa43c215SJeff Kirsher 1718aa43c215SJeff Kirsher return 0; 1719aa43c215SJeff Kirsher } 1720aa43c215SJeff Kirsher 17215ad6ff9dSSony Chacko static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac) 1722aa43c215SJeff Kirsher { 1723aa43c215SJeff Kirsher if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && 1724aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) 1725aa43c215SJeff Kirsher *pci_using_dac = 1; 1726aa43c215SJeff Kirsher else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && 1727aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) 1728aa43c215SJeff Kirsher *pci_using_dac = 0; 1729aa43c215SJeff Kirsher else { 1730aa43c215SJeff Kirsher dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); 1731aa43c215SJeff Kirsher return -EIO; 1732aa43c215SJeff Kirsher } 1733aa43c215SJeff Kirsher 1734aa43c215SJeff Kirsher return 0; 1735aa43c215SJeff Kirsher } 1736aa43c215SJeff Kirsher 17374be41e92SSony Chacko void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter) 17384be41e92SSony Chacko { 17394be41e92SSony Chacko int ring; 17404be41e92SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 17414be41e92SSony Chacko 17424be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 17434be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 17444be41e92SSony Chacko if (tx_ring && tx_ring->cmd_buf_arr != NULL) { 17454be41e92SSony Chacko vfree(tx_ring->cmd_buf_arr); 17464be41e92SSony Chacko tx_ring->cmd_buf_arr = NULL; 17474be41e92SSony Chacko } 17484be41e92SSony Chacko } 17494be41e92SSony Chacko if (adapter->tx_ring != NULL) 17504be41e92SSony Chacko kfree(adapter->tx_ring); 17514be41e92SSony Chacko } 17524be41e92SSony Chacko 17534be41e92SSony Chacko int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter, 17544be41e92SSony Chacko struct net_device *netdev) 17554be41e92SSony Chacko { 1756b2adaca9SJoe Perches int ring, vector, index; 17574be41e92SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 17584be41e92SSony Chacko struct qlcnic_cmd_buffer *cmd_buf_arr; 17594be41e92SSony Chacko 1760b2adaca9SJoe Perches tx_ring = kcalloc(adapter->max_drv_tx_rings, 1761b2adaca9SJoe Perches sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL); 1762b2adaca9SJoe Perches if (tx_ring == NULL) 17634be41e92SSony Chacko return -ENOMEM; 1764b2adaca9SJoe Perches 17654be41e92SSony Chacko adapter->tx_ring = tx_ring; 17664be41e92SSony Chacko 17674be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 17684be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 17694be41e92SSony Chacko tx_ring->num_desc = adapter->num_txd; 17704be41e92SSony Chacko tx_ring->txq = netdev_get_tx_queue(netdev, ring); 17714be41e92SSony Chacko cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring)); 17724be41e92SSony Chacko if (cmd_buf_arr == NULL) { 17734be41e92SSony Chacko qlcnic_free_tx_rings(adapter); 17744be41e92SSony Chacko return -ENOMEM; 17754be41e92SSony Chacko } 17764be41e92SSony Chacko memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); 17774be41e92SSony Chacko tx_ring->cmd_buf_arr = cmd_buf_arr; 17784be41e92SSony Chacko } 17794be41e92SSony Chacko 17804be41e92SSony Chacko if (qlcnic_83xx_check(adapter)) { 17814be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 17824be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 17834be41e92SSony Chacko tx_ring->adapter = adapter; 17844be41e92SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) { 17854be41e92SSony Chacko index = adapter->max_sds_rings + ring; 17864be41e92SSony Chacko vector = adapter->msix_entries[index].vector; 17874be41e92SSony Chacko tx_ring->irq = vector; 17884be41e92SSony Chacko } 17894be41e92SSony Chacko } 17904be41e92SSony Chacko } 17914be41e92SSony Chacko return 0; 17924be41e92SSony Chacko } 17934be41e92SSony Chacko 17946bb58bb0SBill Pemberton static int 1795aa43c215SJeff Kirsher qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1796aa43c215SJeff Kirsher { 1797aa43c215SJeff Kirsher struct net_device *netdev = NULL; 1798aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = NULL; 17997e2cf4feSSony Chacko struct qlcnic_hardware_context *ahw; 18005ad6ff9dSSony Chacko int err, pci_using_dac = -1; 1801c84e340aSSritej Velaga u32 capab2; 18027bc48646SDan Carpenter char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */ 1803aa43c215SJeff Kirsher 1804aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1805aa43c215SJeff Kirsher if (err) 1806aa43c215SJeff Kirsher return err; 1807aa43c215SJeff Kirsher 1808aa43c215SJeff Kirsher if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 1809aa43c215SJeff Kirsher err = -ENODEV; 1810aa43c215SJeff Kirsher goto err_out_disable_pdev; 1811aa43c215SJeff Kirsher } 1812aa43c215SJeff Kirsher 1813aa43c215SJeff Kirsher err = qlcnic_set_dma_mask(pdev, &pci_using_dac); 1814aa43c215SJeff Kirsher if (err) 1815aa43c215SJeff Kirsher goto err_out_disable_pdev; 1816aa43c215SJeff Kirsher 1817aa43c215SJeff Kirsher err = pci_request_regions(pdev, qlcnic_driver_name); 1818aa43c215SJeff Kirsher if (err) 1819aa43c215SJeff Kirsher goto err_out_disable_pdev; 1820aa43c215SJeff Kirsher 1821aa43c215SJeff Kirsher pci_set_master(pdev); 1822aa43c215SJeff Kirsher pci_enable_pcie_error_reporting(pdev); 1823aa43c215SJeff Kirsher 18247e2cf4feSSony Chacko ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL); 18257e2cf4feSSony Chacko if (!ahw) 18267e2cf4feSSony Chacko goto err_out_free_res; 18277e2cf4feSSony Chacko 18287e2cf4feSSony Chacko if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE824X) { 18297e2cf4feSSony Chacko ahw->hw_ops = &qlcnic_hw_ops; 18307e2cf4feSSony Chacko ahw->reg_tbl = (u32 *)qlcnic_reg_tbl; 183113159183SSony Chacko } else if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE834X) { 183213159183SSony Chacko qlcnic_83xx_register_map(ahw); 183313159183SSony Chacko } else { 183413159183SSony Chacko goto err_out_free_hw_res; 18357e2cf4feSSony Chacko } 18367e2cf4feSSony Chacko 18377e2cf4feSSony Chacko err = qlcnic_setup_pci_map(pdev, ahw); 18387e2cf4feSSony Chacko if (err) 18397e2cf4feSSony Chacko goto err_out_free_hw_res; 18407e2cf4feSSony Chacko 1841aa43c215SJeff Kirsher netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); 1842aa43c215SJeff Kirsher if (!netdev) { 1843aa43c215SJeff Kirsher err = -ENOMEM; 18447e2cf4feSSony Chacko goto err_out_iounmap; 1845aa43c215SJeff Kirsher } 1846aa43c215SJeff Kirsher 1847aa43c215SJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev); 1848aa43c215SJeff Kirsher 1849aa43c215SJeff Kirsher adapter = netdev_priv(netdev); 1850aa43c215SJeff Kirsher adapter->netdev = netdev; 1851aa43c215SJeff Kirsher adapter->pdev = pdev; 185213159183SSony Chacko adapter->ahw = ahw; 185313159183SSony Chacko 185413159183SSony Chacko adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic"); 185513159183SSony Chacko if (adapter->qlcnic_wq == NULL) { 185613159183SSony Chacko dev_err(&pdev->dev, "Failed to create workqueue\n"); 185713159183SSony Chacko goto err_out_free_netdev; 185813159183SSony Chacko } 1859aa43c215SJeff Kirsher 18602dfc9671SPeter Senna Tschudin err = qlcnic_alloc_adapter_resources(adapter); 18612dfc9671SPeter Senna Tschudin if (err) 1862aa43c215SJeff Kirsher goto err_out_free_netdev; 1863aa43c215SJeff Kirsher 1864aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 18657e2cf4feSSony Chacko adapter->ahw->revision_id = pdev->revision; 1866fe1adc6bSJitendra Kalsaria if (qlcnic_mac_learn == FDB_MAC_LEARN) 1867fe1adc6bSJitendra Kalsaria adapter->fdb_mac_learn = true; 1868fe1adc6bSJitendra Kalsaria else if (qlcnic_mac_learn == DRV_MAC_LEARN) 1869fe1adc6bSJitendra Kalsaria adapter->drv_mac_learn = true; 18707e2cf4feSSony Chacko adapter->max_drv_tx_rings = 1; 1871aa43c215SJeff Kirsher 1872aa43c215SJeff Kirsher rwlock_init(&adapter->ahw->crb_lock); 1873aa43c215SJeff Kirsher mutex_init(&adapter->ahw->mem_lock); 1874aa43c215SJeff Kirsher 1875aa43c215SJeff Kirsher spin_lock_init(&adapter->tx_clean_lock); 1876aa43c215SJeff Kirsher INIT_LIST_HEAD(&adapter->mac_list); 1877aa43c215SJeff Kirsher 18787e2cf4feSSony Chacko if (qlcnic_82xx_check(adapter)) { 187913159183SSony Chacko qlcnic_check_vf(adapter, ent); 1880aa43c215SJeff Kirsher adapter->portnum = adapter->ahw->pci_func; 18817e2cf4feSSony Chacko err = qlcnic_start_firmware(adapter); 1882aa43c215SJeff Kirsher if (err) { 18837e2cf4feSSony Chacko dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); 18847e2cf4feSSony Chacko goto err_out_free_hw; 1885aa43c215SJeff Kirsher } 1886aa43c215SJeff Kirsher 1887aa43c215SJeff Kirsher err = qlcnic_setup_idc_param(adapter); 1888aa43c215SJeff Kirsher if (err) 18897e2cf4feSSony Chacko goto err_out_free_hw; 1890aa43c215SJeff Kirsher 1891aa43c215SJeff Kirsher adapter->flags |= QLCNIC_NEED_FLR; 189213159183SSony Chacko } else if (qlcnic_83xx_check(adapter)) { 189313159183SSony Chacko qlcnic_83xx_check_vf(adapter, ent); 189413159183SSony Chacko adapter->portnum = adapter->ahw->pci_func; 1895629263acSSony Chacko err = qlcnic_83xx_init(adapter); 1896629263acSSony Chacko if (err) { 1897629263acSSony Chacko dev_err(&pdev->dev, "%s: failed\n", __func__); 1898629263acSSony Chacko goto err_out_free_hw; 1899629263acSSony Chacko } 190013159183SSony Chacko } else { 190113159183SSony Chacko dev_err(&pdev->dev, 190213159183SSony Chacko "%s: failed. Please Reboot\n", __func__); 190313159183SSony Chacko goto err_out_free_hw; 1904aa43c215SJeff Kirsher } 1905aa43c215SJeff Kirsher 1906aa43c215SJeff Kirsher if (qlcnic_read_mac_addr(adapter)) 1907aa43c215SJeff Kirsher dev_warn(&pdev->dev, "failed to read mac addr\n"); 1908aa43c215SJeff Kirsher 1909aa43c215SJeff Kirsher if (adapter->portnum == 0) { 191022999798SSony Chacko qlcnic_get_board_name(adapter, board_name); 191113159183SSony Chacko 1912aa43c215SJeff Kirsher pr_info("%s: %s Board Chip rev 0x%x\n", 1913aa43c215SJeff Kirsher module_name(THIS_MODULE), 191422999798SSony Chacko board_name, adapter->ahw->revision_id); 1915aa43c215SJeff Kirsher } 19167e2cf4feSSony Chacko err = qlcnic_setup_intr(adapter, 0); 19179a97e705SManish chopra if (err) { 19189a97e705SManish chopra dev_err(&pdev->dev, "Failed to setup interrupt\n"); 19197e2cf4feSSony Chacko goto err_out_disable_msi; 19209a97e705SManish chopra } 19217e2cf4feSSony Chacko 192213159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 192313159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 192413159183SSony Chacko if (err) 192513159183SSony Chacko goto err_out_disable_msi; 192613159183SSony Chacko } 1927aa43c215SJeff Kirsher 1928aa43c215SJeff Kirsher err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); 1929aa43c215SJeff Kirsher if (err) 19307e2cf4feSSony Chacko goto err_out_disable_mbx_intr; 1931aa43c215SJeff Kirsher 1932c84e340aSSritej Velaga if (qlcnic_82xx_check(adapter)) { 1933c84e340aSSritej Velaga if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 1934c84e340aSSritej Velaga capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); 1935c84e340aSSritej Velaga if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB) 1936c84e340aSSritej Velaga qlcnic_fw_cmd_set_drv_version(adapter); 1937c84e340aSSritej Velaga } 1938c84e340aSSritej Velaga } 1939c84e340aSSritej Velaga 1940aa43c215SJeff Kirsher pci_set_drvdata(pdev, adapter); 1941aa43c215SJeff Kirsher 194297ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 194397ee45ebSSony Chacko qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 194497ee45ebSSony Chacko FW_POLL_DELAY); 1945aa43c215SJeff Kirsher 1946aa43c215SJeff Kirsher switch (adapter->ahw->port_type) { 1947aa43c215SJeff Kirsher case QLCNIC_GBE: 1948aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 1949aa43c215SJeff Kirsher adapter->netdev->name); 1950aa43c215SJeff Kirsher break; 1951aa43c215SJeff Kirsher case QLCNIC_XGBE: 1952aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", 1953aa43c215SJeff Kirsher adapter->netdev->name); 1954aa43c215SJeff Kirsher break; 1955aa43c215SJeff Kirsher } 1956aa43c215SJeff Kirsher 19577e2cf4feSSony Chacko if (qlcnic_get_act_pci_func(adapter)) 19587e2cf4feSSony Chacko goto err_out_disable_mbx_intr; 19597e2cf4feSSony Chacko 1960fe1adc6bSJitendra Kalsaria if (adapter->drv_mac_learn) 1961aa43c215SJeff Kirsher qlcnic_alloc_lb_filters_mem(adapter); 1962aa43c215SJeff Kirsher 19637e2cf4feSSony Chacko qlcnic_add_sysfs(adapter); 1964aa43c215SJeff Kirsher 1965aa43c215SJeff Kirsher return 0; 1966aa43c215SJeff Kirsher 19677e2cf4feSSony Chacko err_out_disable_mbx_intr: 19687dd90cf1SSucheta Chakraborty if (qlcnic_83xx_check(adapter)) 196913159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 19707e2cf4feSSony Chacko 1971aa43c215SJeff Kirsher err_out_disable_msi: 1972aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 19737e2cf4feSSony Chacko qlcnic_cancel_idc_work(adapter); 1974aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1975aa43c215SJeff Kirsher 1976aa43c215SJeff Kirsher err_out_free_hw: 1977aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1978aa43c215SJeff Kirsher 1979aa43c215SJeff Kirsher err_out_free_netdev: 1980aa43c215SJeff Kirsher free_netdev(netdev); 1981aa43c215SJeff Kirsher 19827e2cf4feSSony Chacko err_out_iounmap: 19837e2cf4feSSony Chacko qlcnic_cleanup_pci_map(adapter); 19847e2cf4feSSony Chacko 19857e2cf4feSSony Chacko err_out_free_hw_res: 19867e2cf4feSSony Chacko kfree(ahw); 19877e2cf4feSSony Chacko 1988aa43c215SJeff Kirsher err_out_free_res: 1989aa43c215SJeff Kirsher pci_release_regions(pdev); 1990aa43c215SJeff Kirsher 1991aa43c215SJeff Kirsher err_out_disable_pdev: 1992aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1993aa43c215SJeff Kirsher pci_disable_device(pdev); 1994aa43c215SJeff Kirsher return err; 1995aa43c215SJeff Kirsher } 1996aa43c215SJeff Kirsher 19976bb58bb0SBill Pemberton static void qlcnic_remove(struct pci_dev *pdev) 1998aa43c215SJeff Kirsher { 1999aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 2000aa43c215SJeff Kirsher struct net_device *netdev; 200113159183SSony Chacko struct qlcnic_hardware_context *ahw; 2002aa43c215SJeff Kirsher 2003aa43c215SJeff Kirsher adapter = pci_get_drvdata(pdev); 2004aa43c215SJeff Kirsher if (adapter == NULL) 2005aa43c215SJeff Kirsher return; 2006aa43c215SJeff Kirsher 2007aa43c215SJeff Kirsher netdev = adapter->netdev; 2008aa43c215SJeff Kirsher 200913159183SSony Chacko qlcnic_cancel_idc_work(adapter); 201013159183SSony Chacko ahw = adapter->ahw; 2011aa43c215SJeff Kirsher 2012aa43c215SJeff Kirsher unregister_netdev(netdev); 2013aa43c215SJeff Kirsher 201413159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 201513159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 20163d73b5fdSJitendra Kalsaria qlcnic_83xx_register_nic_idc_func(adapter, 0); 20173d73b5fdSJitendra Kalsaria cancel_delayed_work_sync(&adapter->idc_aen_work); 201813159183SSony Chacko } 201913159183SSony Chacko 2020aa43c215SJeff Kirsher qlcnic_detach(adapter); 2021aa43c215SJeff Kirsher 2022aa43c215SJeff Kirsher if (adapter->npars != NULL) 2023aa43c215SJeff Kirsher kfree(adapter->npars); 2024aa43c215SJeff Kirsher if (adapter->eswitch != NULL) 2025aa43c215SJeff Kirsher kfree(adapter->eswitch); 2026aa43c215SJeff Kirsher 202797ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 2028aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2029aa43c215SJeff Kirsher 2030aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2031aa43c215SJeff Kirsher 2032aa43c215SJeff Kirsher qlcnic_free_lb_filters_mem(adapter); 2033aa43c215SJeff Kirsher 2034aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 2035aa43c215SJeff Kirsher 203613159183SSony Chacko qlcnic_remove_sysfs(adapter); 2037aa43c215SJeff Kirsher 2038aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 2039aa43c215SJeff Kirsher 2040aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 2041aa43c215SJeff Kirsher 2042aa43c215SJeff Kirsher pci_disable_pcie_error_reporting(pdev); 2043aa43c215SJeff Kirsher pci_release_regions(pdev); 2044aa43c215SJeff Kirsher pci_disable_device(pdev); 2045aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 2046aa43c215SJeff Kirsher 204713159183SSony Chacko if (adapter->qlcnic_wq) { 204813159183SSony Chacko destroy_workqueue(adapter->qlcnic_wq); 204913159183SSony Chacko adapter->qlcnic_wq = NULL; 205013159183SSony Chacko } 2051aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 205213159183SSony Chacko kfree(ahw); 2053aa43c215SJeff Kirsher free_netdev(netdev); 2054aa43c215SJeff Kirsher } 2055aa43c215SJeff Kirsher static int __qlcnic_shutdown(struct pci_dev *pdev) 2056aa43c215SJeff Kirsher { 2057aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 2058aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2059aa43c215SJeff Kirsher int retval; 2060aa43c215SJeff Kirsher 2061aa43c215SJeff Kirsher netif_device_detach(netdev); 2062aa43c215SJeff Kirsher 206313159183SSony Chacko qlcnic_cancel_idc_work(adapter); 2064aa43c215SJeff Kirsher 2065aa43c215SJeff Kirsher if (netif_running(netdev)) 2066aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 2067aa43c215SJeff Kirsher 206897ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 2069aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2070aa43c215SJeff Kirsher 2071aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2072aa43c215SJeff Kirsher 2073aa43c215SJeff Kirsher retval = pci_save_state(pdev); 2074aa43c215SJeff Kirsher if (retval) 2075aa43c215SJeff Kirsher return retval; 207697ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) { 2077aa43c215SJeff Kirsher if (qlcnic_wol_supported(adapter)) { 2078aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3cold, 1); 2079aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3hot, 1); 2080aa43c215SJeff Kirsher } 208197ee45ebSSony Chacko } 2082aa43c215SJeff Kirsher 2083aa43c215SJeff Kirsher return 0; 2084aa43c215SJeff Kirsher } 2085aa43c215SJeff Kirsher 2086aa43c215SJeff Kirsher static void qlcnic_shutdown(struct pci_dev *pdev) 2087aa43c215SJeff Kirsher { 2088aa43c215SJeff Kirsher if (__qlcnic_shutdown(pdev)) 2089aa43c215SJeff Kirsher return; 2090aa43c215SJeff Kirsher 2091aa43c215SJeff Kirsher pci_disable_device(pdev); 2092aa43c215SJeff Kirsher } 2093aa43c215SJeff Kirsher 2094aa43c215SJeff Kirsher #ifdef CONFIG_PM 2095aa43c215SJeff Kirsher static int 2096aa43c215SJeff Kirsher qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) 2097aa43c215SJeff Kirsher { 2098aa43c215SJeff Kirsher int retval; 2099aa43c215SJeff Kirsher 2100aa43c215SJeff Kirsher retval = __qlcnic_shutdown(pdev); 2101aa43c215SJeff Kirsher if (retval) 2102aa43c215SJeff Kirsher return retval; 2103aa43c215SJeff Kirsher 2104aa43c215SJeff Kirsher pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2105aa43c215SJeff Kirsher return 0; 2106aa43c215SJeff Kirsher } 2107aa43c215SJeff Kirsher 2108aa43c215SJeff Kirsher static int 2109aa43c215SJeff Kirsher qlcnic_resume(struct pci_dev *pdev) 2110aa43c215SJeff Kirsher { 2111aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 2112aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2113aa43c215SJeff Kirsher int err; 2114aa43c215SJeff Kirsher 2115aa43c215SJeff Kirsher err = pci_enable_device(pdev); 2116aa43c215SJeff Kirsher if (err) 2117aa43c215SJeff Kirsher return err; 2118aa43c215SJeff Kirsher 2119aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 2120aa43c215SJeff Kirsher pci_set_master(pdev); 2121aa43c215SJeff Kirsher pci_restore_state(pdev); 2122aa43c215SJeff Kirsher 212313159183SSony Chacko err = qlcnic_start_firmware(adapter); 2124aa43c215SJeff Kirsher if (err) { 2125aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to start firmware\n"); 2126aa43c215SJeff Kirsher return err; 2127aa43c215SJeff Kirsher } 2128aa43c215SJeff Kirsher 2129aa43c215SJeff Kirsher if (netif_running(netdev)) { 2130aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 2131aa43c215SJeff Kirsher if (err) 2132aa43c215SJeff Kirsher goto done; 2133aa43c215SJeff Kirsher 2134aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2135aa43c215SJeff Kirsher } 2136aa43c215SJeff Kirsher done: 2137aa43c215SJeff Kirsher netif_device_attach(netdev); 2138aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 2139aa43c215SJeff Kirsher return 0; 2140aa43c215SJeff Kirsher } 2141aa43c215SJeff Kirsher #endif 2142aa43c215SJeff Kirsher 2143aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev) 2144aa43c215SJeff Kirsher { 2145aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2146aa43c215SJeff Kirsher int err; 2147aa43c215SJeff Kirsher 2148aa43c215SJeff Kirsher netif_carrier_off(netdev); 2149aa43c215SJeff Kirsher 2150aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 2151aa43c215SJeff Kirsher if (err) 2152aa43c215SJeff Kirsher return err; 2153aa43c215SJeff Kirsher 2154aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 2155aa43c215SJeff Kirsher if (err) 2156aa43c215SJeff Kirsher goto err_out; 2157aa43c215SJeff Kirsher 2158aa43c215SJeff Kirsher netif_start_queue(netdev); 2159aa43c215SJeff Kirsher 2160aa43c215SJeff Kirsher return 0; 2161aa43c215SJeff Kirsher 2162aa43c215SJeff Kirsher err_out: 2163aa43c215SJeff Kirsher qlcnic_detach(adapter); 2164aa43c215SJeff Kirsher return err; 2165aa43c215SJeff Kirsher } 2166aa43c215SJeff Kirsher 2167aa43c215SJeff Kirsher /* 2168aa43c215SJeff Kirsher * qlcnic_close - Disables a network interface entry point 2169aa43c215SJeff Kirsher */ 2170aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev) 2171aa43c215SJeff Kirsher { 2172aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2173aa43c215SJeff Kirsher 2174aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 217513159183SSony Chacko 2176aa43c215SJeff Kirsher return 0; 2177aa43c215SJeff Kirsher } 2178aa43c215SJeff Kirsher 2179aa43c215SJeff Kirsher void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) 2180aa43c215SJeff Kirsher { 2181aa43c215SJeff Kirsher void *head; 2182aa43c215SJeff Kirsher int i; 218313159183SSony Chacko struct net_device *netdev = adapter->netdev; 218413159183SSony Chacko u32 filter_size = 0; 218513159183SSony Chacko u16 act_pci_func = 0; 2186aa43c215SJeff Kirsher 2187aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 2188aa43c215SJeff Kirsher return; 2189aa43c215SJeff Kirsher 219013159183SSony Chacko act_pci_func = adapter->ahw->act_pci_func; 2191aa43c215SJeff Kirsher spin_lock_init(&adapter->mac_learn_lock); 2192aa43c215SJeff Kirsher 219313159183SSony Chacko if (qlcnic_82xx_check(adapter)) { 219413159183SSony Chacko filter_size = QLCNIC_LB_MAX_FILTERS; 219513159183SSony Chacko adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE; 219613159183SSony Chacko } else { 219713159183SSony Chacko filter_size = QLC_83XX_LB_MAX_FILTERS; 219813159183SSony Chacko adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE; 219913159183SSony Chacko } 220013159183SSony Chacko 220113159183SSony Chacko head = kcalloc(adapter->fhash.fbucket_size, 22021d9219ddSJitendra Kalsaria sizeof(struct hlist_head), GFP_ATOMIC); 220313159183SSony Chacko 2204aa43c215SJeff Kirsher if (!head) 2205aa43c215SJeff Kirsher return; 2206aa43c215SJeff Kirsher 220713159183SSony Chacko adapter->fhash.fmax = (filter_size / act_pci_func); 2208aa43c215SJeff Kirsher adapter->fhash.fhead = head; 2209aa43c215SJeff Kirsher 221013159183SSony Chacko netdev_info(netdev, "active nic func = %d, mac filter size=%d\n", 221113159183SSony Chacko act_pci_func, adapter->fhash.fmax); 221213159183SSony Chacko 221313159183SSony Chacko for (i = 0; i < adapter->fhash.fbucket_size; i++) 2214aa43c215SJeff Kirsher INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); 2215aa43c215SJeff Kirsher } 2216aa43c215SJeff Kirsher 2217aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) 2218aa43c215SJeff Kirsher { 2219aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 2220aa43c215SJeff Kirsher kfree(adapter->fhash.fhead); 2221aa43c215SJeff Kirsher 2222aa43c215SJeff Kirsher adapter->fhash.fhead = NULL; 2223aa43c215SJeff Kirsher adapter->fhash.fmax = 0; 2224aa43c215SJeff Kirsher } 2225aa43c215SJeff Kirsher 2226629263acSSony Chacko int qlcnic_check_temp(struct qlcnic_adapter *adapter) 2227aa43c215SJeff Kirsher { 2228aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 222997ee45ebSSony Chacko u32 temp_state, temp_val, temp = 0; 2230aa43c215SJeff Kirsher int rv = 0; 2231aa43c215SJeff Kirsher 223213159183SSony Chacko if (qlcnic_83xx_check(adapter)) 223313159183SSony Chacko temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP); 223413159183SSony Chacko 223597ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 2236a15ebd37SHimanshu Madhani temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP); 2237aa43c215SJeff Kirsher 2238aa43c215SJeff Kirsher temp_state = qlcnic_get_temp_state(temp); 2239aa43c215SJeff Kirsher temp_val = qlcnic_get_temp_val(temp); 2240aa43c215SJeff Kirsher 2241aa43c215SJeff Kirsher if (temp_state == QLCNIC_TEMP_PANIC) { 2242aa43c215SJeff Kirsher dev_err(&netdev->dev, 2243aa43c215SJeff Kirsher "Device temperature %d degrees C exceeds" 2244aa43c215SJeff Kirsher " maximum allowed. Hardware has been shut down.\n", 2245aa43c215SJeff Kirsher temp_val); 2246aa43c215SJeff Kirsher rv = 1; 2247aa43c215SJeff Kirsher } else if (temp_state == QLCNIC_TEMP_WARN) { 224879788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) { 2249aa43c215SJeff Kirsher dev_err(&netdev->dev, 2250aa43c215SJeff Kirsher "Device temperature %d degrees C " 2251aa43c215SJeff Kirsher "exceeds operating range." 2252aa43c215SJeff Kirsher " Immediate action needed.\n", 2253aa43c215SJeff Kirsher temp_val); 2254aa43c215SJeff Kirsher } 2255aa43c215SJeff Kirsher } else { 225679788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_WARN) { 2257aa43c215SJeff Kirsher dev_info(&netdev->dev, 2258aa43c215SJeff Kirsher "Device temperature is now %d degrees C" 2259aa43c215SJeff Kirsher " in normal range.\n", temp_val); 2260aa43c215SJeff Kirsher } 2261aa43c215SJeff Kirsher } 226279788450SSony Chacko adapter->ahw->temp = temp_state; 2263aa43c215SJeff Kirsher return rv; 2264aa43c215SJeff Kirsher } 2265aa43c215SJeff Kirsher 2266aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev) 2267aa43c215SJeff Kirsher { 2268aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2269aa43c215SJeff Kirsher 2270aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2271aa43c215SJeff Kirsher return; 2272aa43c215SJeff Kirsher 2273aa43c215SJeff Kirsher dev_err(&netdev->dev, "transmit timeout, resetting.\n"); 2274aa43c215SJeff Kirsher 2275aa43c215SJeff Kirsher if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) 2276aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2277aa43c215SJeff Kirsher else 227879788450SSony Chacko adapter->ahw->reset_context = 1; 2279aa43c215SJeff Kirsher } 2280aa43c215SJeff Kirsher 2281aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) 2282aa43c215SJeff Kirsher { 2283aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2284aa43c215SJeff Kirsher struct net_device_stats *stats = &netdev->stats; 2285aa43c215SJeff Kirsher 2286aa43c215SJeff Kirsher stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; 2287aa43c215SJeff Kirsher stats->tx_packets = adapter->stats.xmitfinished; 2288aa43c215SJeff Kirsher stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; 2289aa43c215SJeff Kirsher stats->tx_bytes = adapter->stats.txbytes; 2290aa43c215SJeff Kirsher stats->rx_dropped = adapter->stats.rxdropped; 2291aa43c215SJeff Kirsher stats->tx_dropped = adapter->stats.txdropped; 2292aa43c215SJeff Kirsher 2293aa43c215SJeff Kirsher return stats; 2294aa43c215SJeff Kirsher } 2295aa43c215SJeff Kirsher 22967e2cf4feSSony Chacko irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter) 2297aa43c215SJeff Kirsher { 2298aa43c215SJeff Kirsher u32 status; 2299aa43c215SJeff Kirsher 2300aa43c215SJeff Kirsher status = readl(adapter->isr_int_vec); 2301aa43c215SJeff Kirsher 230279788450SSony Chacko if (!(status & adapter->ahw->int_vec_bit)) 2303aa43c215SJeff Kirsher return IRQ_NONE; 2304aa43c215SJeff Kirsher 2305aa43c215SJeff Kirsher /* check interrupt state machine, to be sure */ 2306aa43c215SJeff Kirsher status = readl(adapter->crb_int_state_reg); 2307aa43c215SJeff Kirsher if (!ISR_LEGACY_INT_TRIGGERED(status)) 2308aa43c215SJeff Kirsher return IRQ_NONE; 2309aa43c215SJeff Kirsher 2310aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2311aa43c215SJeff Kirsher /* read twice to ensure write is flushed */ 2312aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2313aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2314aa43c215SJeff Kirsher 2315aa43c215SJeff Kirsher return IRQ_HANDLED; 2316aa43c215SJeff Kirsher } 2317aa43c215SJeff Kirsher 2318aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data) 2319aa43c215SJeff Kirsher { 2320aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2321aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2322aa43c215SJeff Kirsher 2323aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 2324aa43c215SJeff Kirsher goto done; 2325aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) { 2326aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2327aa43c215SJeff Kirsher goto done; 2328aa43c215SJeff Kirsher } 2329aa43c215SJeff Kirsher 2330aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2331aa43c215SJeff Kirsher return IRQ_NONE; 2332aa43c215SJeff Kirsher 2333aa43c215SJeff Kirsher done: 233479788450SSony Chacko adapter->ahw->diag_cnt++; 2335aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2336aa43c215SJeff Kirsher return IRQ_HANDLED; 2337aa43c215SJeff Kirsher } 2338aa43c215SJeff Kirsher 2339aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data) 2340aa43c215SJeff Kirsher { 2341aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2342aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2343aa43c215SJeff Kirsher 2344aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2345aa43c215SJeff Kirsher return IRQ_NONE; 2346aa43c215SJeff Kirsher 2347aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2348aa43c215SJeff Kirsher 2349aa43c215SJeff Kirsher return IRQ_HANDLED; 2350aa43c215SJeff Kirsher } 2351aa43c215SJeff Kirsher 2352aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data) 2353aa43c215SJeff Kirsher { 2354aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2355aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2356aa43c215SJeff Kirsher 2357aa43c215SJeff Kirsher /* clear interrupt */ 2358aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2359aa43c215SJeff Kirsher 2360aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2361aa43c215SJeff Kirsher return IRQ_HANDLED; 2362aa43c215SJeff Kirsher } 2363aa43c215SJeff Kirsher 2364aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data) 2365aa43c215SJeff Kirsher { 2366aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2367aa43c215SJeff Kirsher 2368aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2369aa43c215SJeff Kirsher return IRQ_HANDLED; 2370aa43c215SJeff Kirsher } 2371aa43c215SJeff Kirsher 237213159183SSony Chacko static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data) 237313159183SSony Chacko { 237413159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring = data; 237513159183SSony Chacko 237613159183SSony Chacko napi_schedule(&tx_ring->napi); 237713159183SSony Chacko return IRQ_HANDLED; 237813159183SSony Chacko } 237913159183SSony Chacko 2380aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2381aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev) 2382aa43c215SJeff Kirsher { 2383aa43c215SJeff Kirsher int ring; 2384aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 2385aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2386aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 2387aa43c215SJeff Kirsher 2388aa43c215SJeff Kirsher disable_irq(adapter->irq); 2389aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 2390aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 2391aa43c215SJeff Kirsher qlcnic_intr(adapter->irq, sds_ring); 2392aa43c215SJeff Kirsher } 2393aa43c215SJeff Kirsher enable_irq(adapter->irq); 2394aa43c215SJeff Kirsher } 2395aa43c215SJeff Kirsher #endif 2396aa43c215SJeff Kirsher 2397aa43c215SJeff Kirsher static void 2398aa43c215SJeff Kirsher qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) 2399aa43c215SJeff Kirsher { 2400aa43c215SJeff Kirsher u32 val; 2401aa43c215SJeff Kirsher 2402aa43c215SJeff Kirsher val = adapter->portnum & 0xf; 2403aa43c215SJeff Kirsher val |= encoding << 7; 2404aa43c215SJeff Kirsher val |= (jiffies - adapter->dev_rst_time) << 8; 2405aa43c215SJeff Kirsher 2406a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); 2407aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 2408aa43c215SJeff Kirsher } 2409aa43c215SJeff Kirsher 2410aa43c215SJeff Kirsher static int 2411aa43c215SJeff Kirsher qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) 2412aa43c215SJeff Kirsher { 2413aa43c215SJeff Kirsher u32 val; 2414aa43c215SJeff Kirsher 2415aa43c215SJeff Kirsher WARN_ON(state != QLCNIC_DEV_NEED_RESET && 2416aa43c215SJeff Kirsher state != QLCNIC_DEV_NEED_QUISCENT); 2417aa43c215SJeff Kirsher 2418aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2419aa43c215SJeff Kirsher return -EIO; 2420aa43c215SJeff Kirsher 2421a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2422aa43c215SJeff Kirsher 2423aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) 2424aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2425aa43c215SJeff Kirsher else if (state == QLCNIC_DEV_NEED_QUISCENT) 2426aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); 2427aa43c215SJeff Kirsher 2428a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2429aa43c215SJeff Kirsher 2430aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2431aa43c215SJeff Kirsher 2432aa43c215SJeff Kirsher return 0; 2433aa43c215SJeff Kirsher } 2434aa43c215SJeff Kirsher 2435aa43c215SJeff Kirsher static int 2436aa43c215SJeff Kirsher qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) 2437aa43c215SJeff Kirsher { 2438aa43c215SJeff Kirsher u32 val; 2439aa43c215SJeff Kirsher 2440aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2441aa43c215SJeff Kirsher return -EBUSY; 2442aa43c215SJeff Kirsher 2443a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2444aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2445a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2446aa43c215SJeff Kirsher 2447aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2448aa43c215SJeff Kirsher 2449aa43c215SJeff Kirsher return 0; 2450aa43c215SJeff Kirsher } 2451aa43c215SJeff Kirsher 2452aa43c215SJeff Kirsher static void 2453aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) 2454aa43c215SJeff Kirsher { 2455aa43c215SJeff Kirsher u32 val; 2456aa43c215SJeff Kirsher 2457aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2458aa43c215SJeff Kirsher goto err; 2459aa43c215SJeff Kirsher 2460a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2461aa43c215SJeff Kirsher QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2462a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2463aa43c215SJeff Kirsher 2464aa43c215SJeff Kirsher if (failed) { 2465a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2466a15ebd37SHimanshu Madhani QLCNIC_DEV_FAILED); 2467aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 2468aa43c215SJeff Kirsher "Device state set to Failed. Please Reboot\n"); 2469aa43c215SJeff Kirsher } else if (!(val & 0x11111111)) 2470a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2471a15ebd37SHimanshu Madhani QLCNIC_DEV_COLD); 2472aa43c215SJeff Kirsher 2473a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2474aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2475a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2476aa43c215SJeff Kirsher 2477aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2478aa43c215SJeff Kirsher err: 2479aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2480aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2481aa43c215SJeff Kirsher clear_bit(__QLCNIC_START_FW, &adapter->state); 2482aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2483aa43c215SJeff Kirsher } 2484aa43c215SJeff Kirsher 2485aa43c215SJeff Kirsher /* Grab api lock, before checking state */ 2486aa43c215SJeff Kirsher static int 2487aa43c215SJeff Kirsher qlcnic_check_drv_state(struct qlcnic_adapter *adapter) 2488aa43c215SJeff Kirsher { 2489aa43c215SJeff Kirsher int act, state, active_mask; 2490a15ebd37SHimanshu Madhani struct qlcnic_hardware_context *ahw = adapter->ahw; 2491aa43c215SJeff Kirsher 2492a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2493a15ebd37SHimanshu Madhani act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2494aa43c215SJeff Kirsher 2495aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_FW_RESET_OWNER) { 2496a15ebd37SHimanshu Madhani active_mask = (~(1 << (ahw->pci_func * 4))); 2497aa43c215SJeff Kirsher act = act & active_mask; 2498aa43c215SJeff Kirsher } 2499aa43c215SJeff Kirsher 2500aa43c215SJeff Kirsher if (((state & 0x11111111) == (act & 0x11111111)) || 2501aa43c215SJeff Kirsher ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 2502aa43c215SJeff Kirsher return 0; 2503aa43c215SJeff Kirsher else 2504aa43c215SJeff Kirsher return 1; 2505aa43c215SJeff Kirsher } 2506aa43c215SJeff Kirsher 2507aa43c215SJeff Kirsher static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) 2508aa43c215SJeff Kirsher { 2509a15ebd37SHimanshu Madhani u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER); 2510aa43c215SJeff Kirsher 2511aa43c215SJeff Kirsher if (val != QLCNIC_DRV_IDC_VER) { 2512aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" 2513aa43c215SJeff Kirsher " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); 2514aa43c215SJeff Kirsher } 2515aa43c215SJeff Kirsher 2516aa43c215SJeff Kirsher return 0; 2517aa43c215SJeff Kirsher } 2518aa43c215SJeff Kirsher 2519aa43c215SJeff Kirsher static int 2520aa43c215SJeff Kirsher qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) 2521aa43c215SJeff Kirsher { 2522aa43c215SJeff Kirsher u32 val, prev_state; 2523aa43c215SJeff Kirsher u8 dev_init_timeo = adapter->dev_init_timeo; 2524aa43c215SJeff Kirsher u8 portnum = adapter->portnum; 2525aa43c215SJeff Kirsher u8 ret; 2526aa43c215SJeff Kirsher 2527aa43c215SJeff Kirsher if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) 2528aa43c215SJeff Kirsher return 1; 2529aa43c215SJeff Kirsher 2530aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2531aa43c215SJeff Kirsher return -1; 2532aa43c215SJeff Kirsher 2533a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2534aa43c215SJeff Kirsher if (!(val & (1 << (portnum * 4)))) { 2535aa43c215SJeff Kirsher QLC_DEV_SET_REF_CNT(val, portnum); 2536a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2537aa43c215SJeff Kirsher } 2538aa43c215SJeff Kirsher 2539a15ebd37SHimanshu Madhani prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2540aa43c215SJeff Kirsher QLCDB(adapter, HW, "Device state = %u\n", prev_state); 2541aa43c215SJeff Kirsher 2542aa43c215SJeff Kirsher switch (prev_state) { 2543aa43c215SJeff Kirsher case QLCNIC_DEV_COLD: 2544a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2545a15ebd37SHimanshu Madhani QLCNIC_DEV_INITIALIZING); 2546a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER, 2547a15ebd37SHimanshu Madhani QLCNIC_DRV_IDC_VER); 2548aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2549aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2550aa43c215SJeff Kirsher return 1; 2551aa43c215SJeff Kirsher 2552aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2553aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2554aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2555aa43c215SJeff Kirsher return ret; 2556aa43c215SJeff Kirsher 2557aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_RESET: 2558a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2559aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, portnum); 2560a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2561aa43c215SJeff Kirsher break; 2562aa43c215SJeff Kirsher 2563aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_QUISCENT: 2564a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2565aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, portnum); 2566a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2567aa43c215SJeff Kirsher break; 2568aa43c215SJeff Kirsher 2569aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2570aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device in failed state.\n"); 2571aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2572aa43c215SJeff Kirsher return -1; 2573aa43c215SJeff Kirsher 2574aa43c215SJeff Kirsher case QLCNIC_DEV_INITIALIZING: 2575aa43c215SJeff Kirsher case QLCNIC_DEV_QUISCENT: 2576aa43c215SJeff Kirsher break; 2577aa43c215SJeff Kirsher } 2578aa43c215SJeff Kirsher 2579aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2580aa43c215SJeff Kirsher 2581aa43c215SJeff Kirsher do { 2582aa43c215SJeff Kirsher msleep(1000); 2583a15ebd37SHimanshu Madhani prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2584aa43c215SJeff Kirsher 2585aa43c215SJeff Kirsher if (prev_state == QLCNIC_DEV_QUISCENT) 2586aa43c215SJeff Kirsher continue; 2587aa43c215SJeff Kirsher } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); 2588aa43c215SJeff Kirsher 2589aa43c215SJeff Kirsher if (!dev_init_timeo) { 2590aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 2591aa43c215SJeff Kirsher "Waiting for device to initialize timeout\n"); 2592aa43c215SJeff Kirsher return -1; 2593aa43c215SJeff Kirsher } 2594aa43c215SJeff Kirsher 2595aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2596aa43c215SJeff Kirsher return -1; 2597aa43c215SJeff Kirsher 2598a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2599aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, portnum); 2600a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2601aa43c215SJeff Kirsher 2602aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2603aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2604aa43c215SJeff Kirsher 2605aa43c215SJeff Kirsher return ret; 2606aa43c215SJeff Kirsher } 2607aa43c215SJeff Kirsher 2608aa43c215SJeff Kirsher static void 2609aa43c215SJeff Kirsher qlcnic_fwinit_work(struct work_struct *work) 2610aa43c215SJeff Kirsher { 2611aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2612aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2613aa43c215SJeff Kirsher u32 dev_state = 0xf; 2614aa43c215SJeff Kirsher u32 val; 2615aa43c215SJeff Kirsher 2616aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2617aa43c215SJeff Kirsher goto err_ret; 2618aa43c215SJeff Kirsher 2619a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2620aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_QUISCENT || 2621aa43c215SJeff Kirsher dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2622aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2623aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, 2624aa43c215SJeff Kirsher FW_POLL_DELAY * 2); 2625aa43c215SJeff Kirsher return; 2626aa43c215SJeff Kirsher } 2627aa43c215SJeff Kirsher 262879788450SSony Chacko if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) { 2629aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2630aa43c215SJeff Kirsher goto wait_npar; 2631aa43c215SJeff Kirsher } 2632aa43c215SJeff Kirsher 263316e3cf73SSritej Velaga if (dev_state == QLCNIC_DEV_INITIALIZING || 263416e3cf73SSritej Velaga dev_state == QLCNIC_DEV_READY) { 263516e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Detected state change from " 263616e3cf73SSritej Velaga "DEV_NEED_RESET, skipping ack check\n"); 263716e3cf73SSritej Velaga goto skip_ack_check; 263816e3cf73SSritej Velaga } 263916e3cf73SSritej Velaga 2640aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 264116e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", 2642aa43c215SJeff Kirsher adapter->reset_ack_timeo); 2643aa43c215SJeff Kirsher goto skip_ack_check; 2644aa43c215SJeff Kirsher } 2645aa43c215SJeff Kirsher 2646aa43c215SJeff Kirsher if (!qlcnic_check_drv_state(adapter)) { 2647aa43c215SJeff Kirsher skip_ack_check: 2648a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2649aa43c215SJeff Kirsher 2650aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_NEED_RESET) { 2651a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2652aa43c215SJeff Kirsher QLCNIC_DEV_INITIALIZING); 2653aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 2654aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 2655aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2656a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, 2657a15ebd37SHimanshu Madhani QLCNIC_CRB_DRV_STATE); 2658aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2659a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, 2660a15ebd37SHimanshu Madhani QLCNIC_CRB_DRV_STATE, val); 2661aa43c215SJeff Kirsher } 2662aa43c215SJeff Kirsher 2663aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2664aa43c215SJeff Kirsher 2665aa43c215SJeff Kirsher rtnl_lock(); 2666aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.enable && 2667aa43c215SJeff Kirsher (adapter->flags & QLCNIC_FW_RESET_OWNER)) { 2668aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Take FW dump\n"); 2669aa43c215SJeff Kirsher qlcnic_dump_fw(adapter); 2670aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2671aa43c215SJeff Kirsher } 2672aa43c215SJeff Kirsher rtnl_unlock(); 2673aa43c215SJeff Kirsher 2674aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_RESET_OWNER; 2675aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2676aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2677aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2678aa43c215SJeff Kirsher return; 2679aa43c215SJeff Kirsher } 2680aa43c215SJeff Kirsher goto err_ret; 2681aa43c215SJeff Kirsher } 2682aa43c215SJeff Kirsher 2683aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2684aa43c215SJeff Kirsher 2685aa43c215SJeff Kirsher wait_npar: 2686a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2687aa43c215SJeff Kirsher QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 2688aa43c215SJeff Kirsher 2689aa43c215SJeff Kirsher switch (dev_state) { 2690aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 26917e2cf4feSSony Chacko if (!qlcnic_start_firmware(adapter)) { 2692aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2693aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2694aa43c215SJeff Kirsher return; 2695aa43c215SJeff Kirsher } 2696aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2697aa43c215SJeff Kirsher break; 2698aa43c215SJeff Kirsher default: 2699aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, 2700aa43c215SJeff Kirsher qlcnic_fwinit_work, FW_POLL_DELAY); 2701aa43c215SJeff Kirsher return; 2702aa43c215SJeff Kirsher } 2703aa43c215SJeff Kirsher 2704aa43c215SJeff Kirsher err_ret: 2705aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 2706aa43c215SJeff Kirsher "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 2707aa43c215SJeff Kirsher netif_device_attach(adapter->netdev); 2708aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2709aa43c215SJeff Kirsher } 2710aa43c215SJeff Kirsher 2711aa43c215SJeff Kirsher static void 2712aa43c215SJeff Kirsher qlcnic_detach_work(struct work_struct *work) 2713aa43c215SJeff Kirsher { 2714aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2715aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2716aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2717aa43c215SJeff Kirsher u32 status; 2718aa43c215SJeff Kirsher 2719aa43c215SJeff Kirsher netif_device_detach(netdev); 2720aa43c215SJeff Kirsher 2721aa43c215SJeff Kirsher /* Dont grab rtnl lock during Quiscent mode */ 2722aa43c215SJeff Kirsher if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2723aa43c215SJeff Kirsher if (netif_running(netdev)) 2724aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 2725aa43c215SJeff Kirsher } else 2726aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 2727aa43c215SJeff Kirsher 2728a15ebd37SHimanshu Madhani status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2729aa43c215SJeff Kirsher 273044f65b29SSony Chacko if (status & QLCNIC_RCODE_FATAL_ERROR) { 273144f65b29SSony Chacko dev_err(&adapter->pdev->dev, 273244f65b29SSony Chacko "Detaching the device: peg halt status1=0x%x\n", 273344f65b29SSony Chacko status); 2734aa43c215SJeff Kirsher 273544f65b29SSony Chacko if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { 273644f65b29SSony Chacko dev_err(&adapter->pdev->dev, 273744f65b29SSony Chacko "On board active cooling fan failed. " 273844f65b29SSony Chacko "Device has been halted.\n"); 273944f65b29SSony Chacko dev_err(&adapter->pdev->dev, 274044f65b29SSony Chacko "Replace the adapter.\n"); 274144f65b29SSony Chacko } 274244f65b29SSony Chacko 2743aa43c215SJeff Kirsher goto err_ret; 274444f65b29SSony Chacko } 274544f65b29SSony Chacko 274679788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) { 274744f65b29SSony Chacko dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", 274879788450SSony Chacko adapter->ahw->temp); 274944f65b29SSony Chacko goto err_ret; 275044f65b29SSony Chacko } 275144f65b29SSony Chacko 2752aa43c215SJeff Kirsher /* Dont ack if this instance is the reset owner */ 2753aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { 275444f65b29SSony Chacko if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { 275544f65b29SSony Chacko dev_err(&adapter->pdev->dev, 275644f65b29SSony Chacko "Failed to set driver state," 275744f65b29SSony Chacko "detaching the device.\n"); 2758aa43c215SJeff Kirsher goto err_ret; 2759aa43c215SJeff Kirsher } 276044f65b29SSony Chacko } 2761aa43c215SJeff Kirsher 2762aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2763aa43c215SJeff Kirsher 2764aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); 2765aa43c215SJeff Kirsher 2766aa43c215SJeff Kirsher return; 2767aa43c215SJeff Kirsher 2768aa43c215SJeff Kirsher err_ret: 2769aa43c215SJeff Kirsher netif_device_attach(netdev); 2770aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 2771aa43c215SJeff Kirsher } 2772aa43c215SJeff Kirsher 2773aa43c215SJeff Kirsher /*Transit NPAR state to NON Operational */ 2774aa43c215SJeff Kirsher static void 2775aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) 2776aa43c215SJeff Kirsher { 2777aa43c215SJeff Kirsher u32 state; 2778aa43c215SJeff Kirsher 2779a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2780aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NPAR_NON_OPER) 2781aa43c215SJeff Kirsher return; 2782aa43c215SJeff Kirsher 2783aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2784aa43c215SJeff Kirsher return; 2785a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 2786a15ebd37SHimanshu Madhani QLCNIC_DEV_NPAR_NON_OPER); 2787aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2788aa43c215SJeff Kirsher } 2789aa43c215SJeff Kirsher 27907e2cf4feSSony Chacko void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key) 2791aa43c215SJeff Kirsher { 2792646779f1SSritej Velaga u32 state, xg_val = 0, gb_val = 0; 2793aa43c215SJeff Kirsher 2794646779f1SSritej Velaga qlcnic_xg_set_xg0_mask(xg_val); 2795646779f1SSritej Velaga qlcnic_xg_set_xg1_mask(xg_val); 2796646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); 2797646779f1SSritej Velaga qlcnic_gb_set_gb0_mask(gb_val); 2798646779f1SSritej Velaga qlcnic_gb_set_gb1_mask(gb_val); 2799646779f1SSritej Velaga qlcnic_gb_set_gb2_mask(gb_val); 2800646779f1SSritej Velaga qlcnic_gb_set_gb3_mask(gb_val); 2801646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); 2802646779f1SSritej Velaga dev_info(&adapter->pdev->dev, "Pause control frames disabled" 2803646779f1SSritej Velaga " on all ports\n"); 2804aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 280513159183SSony Chacko 2806aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2807aa43c215SJeff Kirsher return; 2808aa43c215SJeff Kirsher 280913159183SSony Chacko state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2810aa43c215SJeff Kirsher 2811aa43c215SJeff Kirsher if (state == QLCNIC_DEV_READY) { 281213159183SSony Chacko QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 281313159183SSony Chacko QLCNIC_DEV_NEED_RESET); 2814aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_RESET_OWNER; 2815aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NEED_RESET state set\n"); 2816aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2817aa43c215SJeff Kirsher } 2818aa43c215SJeff Kirsher 281913159183SSony Chacko QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 282013159183SSony Chacko QLCNIC_DEV_NPAR_NON_OPER); 2821aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2822aa43c215SJeff Kirsher } 2823aa43c215SJeff Kirsher 2824aa43c215SJeff Kirsher /* Transit to NPAR READY state from NPAR NOT READY state */ 2825aa43c215SJeff Kirsher static void 2826aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 2827aa43c215SJeff Kirsher { 2828aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2829aa43c215SJeff Kirsher return; 2830aa43c215SJeff Kirsher 2831a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 2832a15ebd37SHimanshu Madhani QLCNIC_DEV_NPAR_OPER); 2833aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NPAR operational state set\n"); 2834aa43c215SJeff Kirsher 2835aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2836aa43c215SJeff Kirsher } 2837aa43c215SJeff Kirsher 283813159183SSony Chacko void qlcnic_schedule_work(struct qlcnic_adapter *adapter, 2839aa43c215SJeff Kirsher work_func_t func, int delay) 2840aa43c215SJeff Kirsher { 2841aa43c215SJeff Kirsher if (test_bit(__QLCNIC_AER, &adapter->state)) 2842aa43c215SJeff Kirsher return; 2843aa43c215SJeff Kirsher 2844aa43c215SJeff Kirsher INIT_DELAYED_WORK(&adapter->fw_work, func); 284513159183SSony Chacko queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work, 2846aa43c215SJeff Kirsher round_jiffies_relative(delay)); 2847aa43c215SJeff Kirsher } 2848aa43c215SJeff Kirsher 2849aa43c215SJeff Kirsher static void 2850aa43c215SJeff Kirsher qlcnic_attach_work(struct work_struct *work) 2851aa43c215SJeff Kirsher { 2852aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2853aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2854aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2855aa43c215SJeff Kirsher u32 npar_state; 2856aa43c215SJeff Kirsher 285779788450SSony Chacko if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) { 2858a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 2859a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 2860aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) 2861aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2862aa43c215SJeff Kirsher else if (npar_state != QLCNIC_DEV_NPAR_OPER) 2863aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 2864aa43c215SJeff Kirsher FW_POLL_DELAY); 2865aa43c215SJeff Kirsher else 2866aa43c215SJeff Kirsher goto attach; 2867aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); 2868aa43c215SJeff Kirsher return; 2869aa43c215SJeff Kirsher } 2870aa43c215SJeff Kirsher attach: 2871aa43c215SJeff Kirsher if (netif_running(netdev)) { 2872aa43c215SJeff Kirsher if (qlcnic_up(adapter, netdev)) 2873aa43c215SJeff Kirsher goto done; 2874aa43c215SJeff Kirsher 2875aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2876aa43c215SJeff Kirsher } 2877aa43c215SJeff Kirsher 2878aa43c215SJeff Kirsher done: 2879aa43c215SJeff Kirsher netif_device_attach(netdev); 2880aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2881aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2882aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2883aa43c215SJeff Kirsher 2884aa43c215SJeff Kirsher if (!qlcnic_clr_drv_state(adapter)) 2885aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 2886aa43c215SJeff Kirsher FW_POLL_DELAY); 2887aa43c215SJeff Kirsher } 2888aa43c215SJeff Kirsher 2889aa43c215SJeff Kirsher static int 2890aa43c215SJeff Kirsher qlcnic_check_health(struct qlcnic_adapter *adapter) 2891aa43c215SJeff Kirsher { 2892aa43c215SJeff Kirsher u32 state = 0, heartbeat; 2893853d4bcaSAmeen Rahman u32 peg_status; 2894aa43c215SJeff Kirsher 2895aa43c215SJeff Kirsher if (qlcnic_check_temp(adapter)) 2896aa43c215SJeff Kirsher goto detach; 2897aa43c215SJeff Kirsher 2898aa43c215SJeff Kirsher if (adapter->need_fw_reset) 28997e2cf4feSSony Chacko qlcnic_dev_request_reset(adapter, 0); 2900aa43c215SJeff Kirsher 2901a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2902aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) { 2903aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(adapter); 2904aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2905aa43c215SJeff Kirsher } else if (state == QLCNIC_DEV_NEED_QUISCENT) 2906aa43c215SJeff Kirsher goto detach; 2907aa43c215SJeff Kirsher 2908a15ebd37SHimanshu Madhani heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 2909aa43c215SJeff Kirsher if (heartbeat != adapter->heartbeat) { 2910aa43c215SJeff Kirsher adapter->heartbeat = heartbeat; 2911aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2912aa43c215SJeff Kirsher if (adapter->need_fw_reset) 2913aa43c215SJeff Kirsher goto detach; 2914aa43c215SJeff Kirsher 2915099f7aa7SSony Chacko if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) { 2916aa43c215SJeff Kirsher qlcnic_reset_hw_context(adapter); 2917aa43c215SJeff Kirsher adapter->netdev->trans_start = jiffies; 2918aa43c215SJeff Kirsher } 2919aa43c215SJeff Kirsher 2920aa43c215SJeff Kirsher return 0; 2921aa43c215SJeff Kirsher } 2922aa43c215SJeff Kirsher 2923aa43c215SJeff Kirsher if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) 2924aa43c215SJeff Kirsher return 0; 2925aa43c215SJeff Kirsher 2926aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2927aa43c215SJeff Kirsher 29287e2cf4feSSony Chacko qlcnic_dev_request_reset(adapter, 0); 2929aa43c215SJeff Kirsher 2930099f7aa7SSony Chacko if (qlcnic_auto_fw_reset) 2931aa43c215SJeff Kirsher clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); 2932aa43c215SJeff Kirsher 2933853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "firmware hang detected\n"); 2934a15ebd37SHimanshu Madhani peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2935853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" 2936aa43c215SJeff Kirsher "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" 2937aa43c215SJeff Kirsher "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" 2938aa43c215SJeff Kirsher "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" 2939aa43c215SJeff Kirsher "PEG_NET_4_PC: 0x%x\n", 2940a15ebd37SHimanshu Madhani peg_status, 2941a15ebd37SHimanshu Madhani QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2), 2942aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), 2943aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), 2944aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), 2945aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), 2946aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); 294797048a1fSSritej Velaga if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) 2948853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, 2949853d4bcaSAmeen Rahman "Firmware aborted with error code 0x00006700. " 2950853d4bcaSAmeen Rahman "Device is being reset.\n"); 2951aa43c215SJeff Kirsher detach: 2952aa43c215SJeff Kirsher adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : 2953aa43c215SJeff Kirsher QLCNIC_DEV_NEED_RESET; 2954aa43c215SJeff Kirsher 2955099f7aa7SSony Chacko if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING, 2956099f7aa7SSony Chacko &adapter->state)) { 2957aa43c215SJeff Kirsher 2958aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); 2959aa43c215SJeff Kirsher QLCDB(adapter, DRV, "fw recovery scheduled.\n"); 2960aa43c215SJeff Kirsher } 2961aa43c215SJeff Kirsher 2962aa43c215SJeff Kirsher return 1; 2963aa43c215SJeff Kirsher } 2964aa43c215SJeff Kirsher 2965aa43c215SJeff Kirsher static void 2966aa43c215SJeff Kirsher qlcnic_fw_poll_work(struct work_struct *work) 2967aa43c215SJeff Kirsher { 2968aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2969aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2970aa43c215SJeff Kirsher 2971aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2972aa43c215SJeff Kirsher goto reschedule; 2973aa43c215SJeff Kirsher 2974aa43c215SJeff Kirsher 2975aa43c215SJeff Kirsher if (qlcnic_check_health(adapter)) 2976aa43c215SJeff Kirsher return; 2977aa43c215SJeff Kirsher 2978aa43c215SJeff Kirsher if (adapter->fhash.fnum) 2979aa43c215SJeff Kirsher qlcnic_prune_lb_filters(adapter); 2980aa43c215SJeff Kirsher 2981aa43c215SJeff Kirsher reschedule: 2982aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 2983aa43c215SJeff Kirsher } 2984aa43c215SJeff Kirsher 2985aa43c215SJeff Kirsher static int qlcnic_is_first_func(struct pci_dev *pdev) 2986aa43c215SJeff Kirsher { 2987aa43c215SJeff Kirsher struct pci_dev *oth_pdev; 2988aa43c215SJeff Kirsher int val = pdev->devfn; 2989aa43c215SJeff Kirsher 2990aa43c215SJeff Kirsher while (val-- > 0) { 2991aa43c215SJeff Kirsher oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr 2992aa43c215SJeff Kirsher (pdev->bus), pdev->bus->number, 2993aa43c215SJeff Kirsher PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); 2994aa43c215SJeff Kirsher if (!oth_pdev) 2995aa43c215SJeff Kirsher continue; 2996aa43c215SJeff Kirsher 2997aa43c215SJeff Kirsher if (oth_pdev->current_state != PCI_D3cold) { 2998aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 2999aa43c215SJeff Kirsher return 0; 3000aa43c215SJeff Kirsher } 3001aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 3002aa43c215SJeff Kirsher } 3003aa43c215SJeff Kirsher return 1; 3004aa43c215SJeff Kirsher } 3005aa43c215SJeff Kirsher 3006aa43c215SJeff Kirsher static int qlcnic_attach_func(struct pci_dev *pdev) 3007aa43c215SJeff Kirsher { 3008aa43c215SJeff Kirsher int err, first_func; 3009aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3010aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3011aa43c215SJeff Kirsher 3012aa43c215SJeff Kirsher pdev->error_state = pci_channel_io_normal; 3013aa43c215SJeff Kirsher 3014aa43c215SJeff Kirsher err = pci_enable_device(pdev); 3015aa43c215SJeff Kirsher if (err) 3016aa43c215SJeff Kirsher return err; 3017aa43c215SJeff Kirsher 3018aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 3019aa43c215SJeff Kirsher pci_set_master(pdev); 3020aa43c215SJeff Kirsher pci_restore_state(pdev); 3021aa43c215SJeff Kirsher 3022aa43c215SJeff Kirsher first_func = qlcnic_is_first_func(pdev); 3023aa43c215SJeff Kirsher 3024aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 3025aa43c215SJeff Kirsher return -EINVAL; 3026aa43c215SJeff Kirsher 302779788450SSony Chacko if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { 3028aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 3029aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 3030a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 3031a15ebd37SHimanshu Madhani QLCNIC_DEV_INITIALIZING); 3032aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 3033aa43c215SJeff Kirsher } 3034aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 3035aa43c215SJeff Kirsher 303613159183SSony Chacko err = qlcnic_start_firmware(adapter); 3037aa43c215SJeff Kirsher if (err) 3038aa43c215SJeff Kirsher return err; 3039aa43c215SJeff Kirsher 3040aa43c215SJeff Kirsher qlcnic_clr_drv_state(adapter); 304113159183SSony Chacko kfree(adapter->msix_entries); 304213159183SSony Chacko adapter->msix_entries = NULL; 304313159183SSony Chacko err = qlcnic_setup_intr(adapter, 0); 304413159183SSony Chacko 30459a97e705SManish chopra if (err) { 30469a97e705SManish chopra kfree(adapter->msix_entries); 30479a97e705SManish chopra netdev_err(netdev, "failed to setup interrupt\n"); 30489a97e705SManish chopra return err; 30499a97e705SManish chopra } 30509a97e705SManish chopra 305113159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 3052d5fcff04SHimanshu Madhani /* register for NIC IDC AEN Events */ 3053d5fcff04SHimanshu Madhani qlcnic_83xx_register_nic_idc_func(adapter, 1); 305413159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 305513159183SSony Chacko if (err) { 305613159183SSony Chacko dev_err(&adapter->pdev->dev, 305713159183SSony Chacko "failed to setup mbx interrupt\n"); 305813159183SSony Chacko qlcnic_clr_all_drv_state(adapter, 1); 305913159183SSony Chacko clear_bit(__QLCNIC_AER, &adapter->state); 306013159183SSony Chacko goto done; 306113159183SSony Chacko } 306213159183SSony Chacko } 3063aa43c215SJeff Kirsher 3064aa43c215SJeff Kirsher if (netif_running(netdev)) { 3065aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3066aa43c215SJeff Kirsher if (err) { 3067aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 3068aa43c215SJeff Kirsher clear_bit(__QLCNIC_AER, &adapter->state); 3069aa43c215SJeff Kirsher netif_device_attach(netdev); 3070aa43c215SJeff Kirsher return err; 3071aa43c215SJeff Kirsher } 3072aa43c215SJeff Kirsher 3073aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 3074aa43c215SJeff Kirsher if (err) 3075aa43c215SJeff Kirsher goto done; 3076aa43c215SJeff Kirsher 3077aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3078aa43c215SJeff Kirsher } 3079aa43c215SJeff Kirsher done: 3080aa43c215SJeff Kirsher netif_device_attach(netdev); 3081aa43c215SJeff Kirsher return err; 3082aa43c215SJeff Kirsher } 3083aa43c215SJeff Kirsher 3084aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, 3085aa43c215SJeff Kirsher pci_channel_state_t state) 3086aa43c215SJeff Kirsher { 3087aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3088aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3089aa43c215SJeff Kirsher 3090aa43c215SJeff Kirsher if (state == pci_channel_io_perm_failure) 3091aa43c215SJeff Kirsher return PCI_ERS_RESULT_DISCONNECT; 3092aa43c215SJeff Kirsher 3093aa43c215SJeff Kirsher if (state == pci_channel_io_normal) 3094aa43c215SJeff Kirsher return PCI_ERS_RESULT_RECOVERED; 3095aa43c215SJeff Kirsher 3096aa43c215SJeff Kirsher set_bit(__QLCNIC_AER, &adapter->state); 3097aa43c215SJeff Kirsher netif_device_detach(netdev); 3098aa43c215SJeff Kirsher 3099aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3100aa43c215SJeff Kirsher 3101aa43c215SJeff Kirsher if (netif_running(netdev)) 3102aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 3103aa43c215SJeff Kirsher 310413159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 310513159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 31063d73b5fdSJitendra Kalsaria qlcnic_83xx_register_nic_idc_func(adapter, 0); 31073d73b5fdSJitendra Kalsaria cancel_delayed_work_sync(&adapter->idc_aen_work); 310813159183SSony Chacko } 310913159183SSony Chacko 3110aa43c215SJeff Kirsher qlcnic_detach(adapter); 3111aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3112aa43c215SJeff Kirsher 3113aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3114aa43c215SJeff Kirsher 3115aa43c215SJeff Kirsher pci_save_state(pdev); 3116aa43c215SJeff Kirsher pci_disable_device(pdev); 3117aa43c215SJeff Kirsher 3118aa43c215SJeff Kirsher return PCI_ERS_RESULT_NEED_RESET; 3119aa43c215SJeff Kirsher } 3120aa43c215SJeff Kirsher 3121aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) 3122aa43c215SJeff Kirsher { 3123aa43c215SJeff Kirsher return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : 3124aa43c215SJeff Kirsher PCI_ERS_RESULT_RECOVERED; 3125aa43c215SJeff Kirsher } 3126aa43c215SJeff Kirsher 3127aa43c215SJeff Kirsher static void qlcnic_io_resume(struct pci_dev *pdev) 3128aa43c215SJeff Kirsher { 3129a15ebd37SHimanshu Madhani u32 state; 3130aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3131aa43c215SJeff Kirsher 3132aa43c215SJeff Kirsher pci_cleanup_aer_uncorrect_error_status(pdev); 3133a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3134a15ebd37SHimanshu Madhani if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER, 3135a15ebd37SHimanshu Madhani &adapter->state)) 3136aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3137aa43c215SJeff Kirsher FW_POLL_DELAY); 3138aa43c215SJeff Kirsher } 3139aa43c215SJeff Kirsher 3140aa43c215SJeff Kirsher static int 3141aa43c215SJeff Kirsher qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3142aa43c215SJeff Kirsher { 3143aa43c215SJeff Kirsher int err; 3144aa43c215SJeff Kirsher 3145aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 3146aa43c215SJeff Kirsher if (err) 3147aa43c215SJeff Kirsher return err; 3148aa43c215SJeff Kirsher 3149aa43c215SJeff Kirsher err = qlcnic_check_npar_opertional(adapter); 3150aa43c215SJeff Kirsher if (err) 3151aa43c215SJeff Kirsher return err; 3152aa43c215SJeff Kirsher 3153aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 3154aa43c215SJeff Kirsher if (err) 3155aa43c215SJeff Kirsher return err; 3156aa43c215SJeff Kirsher 3157aa43c215SJeff Kirsher qlcnic_check_options(adapter); 3158aa43c215SJeff Kirsher 3159aa43c215SJeff Kirsher err = qlcnic_set_eswitch_port_config(adapter); 3160aa43c215SJeff Kirsher if (err) 3161aa43c215SJeff Kirsher return err; 3162aa43c215SJeff Kirsher 3163aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 3164aa43c215SJeff Kirsher 3165aa43c215SJeff Kirsher return err; 3166aa43c215SJeff Kirsher } 3167aa43c215SJeff Kirsher 3168319ecf12SSony Chacko int qlcnic_validate_max_rss(u8 max_hw, u8 val) 3169aa43c215SJeff Kirsher { 3170319ecf12SSony Chacko u32 max_allowed; 3171319ecf12SSony Chacko 3172319ecf12SSony Chacko if (max_hw > QLC_MAX_SDS_RINGS) { 3173319ecf12SSony Chacko max_hw = QLC_MAX_SDS_RINGS; 3174319ecf12SSony Chacko pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS); 3175aa43c215SJeff Kirsher } 3176aa43c215SJeff Kirsher 3177319ecf12SSony Chacko max_allowed = rounddown_pow_of_two(min_t(int, max_hw, 3178319ecf12SSony Chacko num_online_cpus())); 3179319ecf12SSony Chacko if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) { 3180319ecf12SSony Chacko pr_info("rss_ring valid range [2 - %x] in powers of 2\n", 3181319ecf12SSony Chacko max_allowed); 3182aa43c215SJeff Kirsher return -EINVAL; 3183aa43c215SJeff Kirsher } 3184aa43c215SJeff Kirsher return 0; 3185aa43c215SJeff Kirsher } 3186aa43c215SJeff Kirsher 3187319ecf12SSony Chacko int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len) 3188aa43c215SJeff Kirsher { 318913159183SSony Chacko int err; 3190aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3191aa43c215SJeff Kirsher 3192319ecf12SSony Chacko if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3193319ecf12SSony Chacko return -EBUSY; 3194319ecf12SSony Chacko 3195aa43c215SJeff Kirsher netif_device_detach(netdev); 3196aa43c215SJeff Kirsher if (netif_running(netdev)) 3197aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 319813159183SSony Chacko 3199aa43c215SJeff Kirsher qlcnic_detach(adapter); 32007dd90cf1SSucheta Chakraborty 32017dd90cf1SSucheta Chakraborty if (qlcnic_83xx_check(adapter)) 32027dd90cf1SSucheta Chakraborty qlcnic_83xx_free_mbx_intr(adapter); 32037dd90cf1SSucheta Chakraborty 3204aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3205319ecf12SSony Chacko err = qlcnic_setup_intr(adapter, data); 32069a97e705SManish chopra if (err) { 32079a97e705SManish chopra kfree(adapter->msix_entries); 32089a97e705SManish chopra netdev_err(netdev, "failed to setup interrupt\n"); 32099a97e705SManish chopra return err; 32109a97e705SManish chopra } 3211aa43c215SJeff Kirsher 321213159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 3213d5fcff04SHimanshu Madhani /* register for NIC IDC AEN Events */ 3214d5fcff04SHimanshu Madhani qlcnic_83xx_register_nic_idc_func(adapter, 1); 321513159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 321613159183SSony Chacko if (err) { 321713159183SSony Chacko dev_err(&adapter->pdev->dev, 321813159183SSony Chacko "failed to setup mbx interrupt\n"); 321913159183SSony Chacko goto done; 322013159183SSony Chacko } 3221aa43c215SJeff Kirsher } 3222aa43c215SJeff Kirsher 3223aa43c215SJeff Kirsher if (netif_running(netdev)) { 3224aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3225aa43c215SJeff Kirsher if (err) 3226aa43c215SJeff Kirsher goto done; 3227aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 3228aa43c215SJeff Kirsher if (err) 3229aa43c215SJeff Kirsher goto done; 3230aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3231aa43c215SJeff Kirsher } 3232319ecf12SSony Chacko err = len; 3233aa43c215SJeff Kirsher done: 3234aa43c215SJeff Kirsher netif_device_attach(netdev); 3235aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3236aa43c215SJeff Kirsher return err; 3237aa43c215SJeff Kirsher } 3238aa43c215SJeff Kirsher 3239aa43c215SJeff Kirsher #ifdef CONFIG_INET 3240aa43c215SJeff Kirsher 3241aa43c215SJeff Kirsher #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 3242aa43c215SJeff Kirsher 3243aa43c215SJeff Kirsher static void 3244aa43c215SJeff Kirsher qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, 3245aa43c215SJeff Kirsher struct net_device *dev, unsigned long event) 3246aa43c215SJeff Kirsher { 3247aa43c215SJeff Kirsher struct in_device *indev; 3248aa43c215SJeff Kirsher 3249aa43c215SJeff Kirsher indev = in_dev_get(dev); 3250aa43c215SJeff Kirsher if (!indev) 3251aa43c215SJeff Kirsher return; 3252aa43c215SJeff Kirsher 3253aa43c215SJeff Kirsher for_ifa(indev) { 3254aa43c215SJeff Kirsher switch (event) { 3255aa43c215SJeff Kirsher case NETDEV_UP: 3256aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 3257aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_UP); 3258aa43c215SJeff Kirsher break; 3259aa43c215SJeff Kirsher case NETDEV_DOWN: 3260aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 3261aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_DOWN); 3262aa43c215SJeff Kirsher break; 3263aa43c215SJeff Kirsher default: 3264aa43c215SJeff Kirsher break; 3265aa43c215SJeff Kirsher } 3266aa43c215SJeff Kirsher } endfor_ifa(indev); 3267aa43c215SJeff Kirsher 3268aa43c215SJeff Kirsher in_dev_put(indev); 3269aa43c215SJeff Kirsher } 3270aa43c215SJeff Kirsher 3271319ecf12SSony Chacko void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) 3272aa43c215SJeff Kirsher { 3273aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 3274aa43c215SJeff Kirsher struct net_device *dev; 3275aa43c215SJeff Kirsher u16 vid; 3276aa43c215SJeff Kirsher 3277aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, netdev, event); 3278aa43c215SJeff Kirsher 327943c00a75SJiri Pirko rcu_read_lock(); 3280aa43c215SJeff Kirsher for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { 3281aa43c215SJeff Kirsher dev = __vlan_find_dev_deep(netdev, vid); 3282aa43c215SJeff Kirsher if (!dev) 3283aa43c215SJeff Kirsher continue; 3284aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 3285aa43c215SJeff Kirsher } 328643c00a75SJiri Pirko rcu_read_unlock(); 3287aa43c215SJeff Kirsher } 3288aa43c215SJeff Kirsher 3289aa43c215SJeff Kirsher static int qlcnic_netdev_event(struct notifier_block *this, 3290aa43c215SJeff Kirsher unsigned long event, void *ptr) 3291aa43c215SJeff Kirsher { 3292aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 3293aa43c215SJeff Kirsher struct net_device *dev = (struct net_device *)ptr; 3294aa43c215SJeff Kirsher 3295aa43c215SJeff Kirsher recheck: 3296aa43c215SJeff Kirsher if (dev == NULL) 3297aa43c215SJeff Kirsher goto done; 3298aa43c215SJeff Kirsher 3299aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 3300aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 3301aa43c215SJeff Kirsher goto recheck; 3302aa43c215SJeff Kirsher } 3303aa43c215SJeff Kirsher 3304aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 3305aa43c215SJeff Kirsher goto done; 3306aa43c215SJeff Kirsher 3307aa43c215SJeff Kirsher adapter = netdev_priv(dev); 3308aa43c215SJeff Kirsher 3309aa43c215SJeff Kirsher if (!adapter) 3310aa43c215SJeff Kirsher goto done; 3311aa43c215SJeff Kirsher 3312aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3313aa43c215SJeff Kirsher goto done; 3314aa43c215SJeff Kirsher 3315aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 3316aa43c215SJeff Kirsher done: 3317aa43c215SJeff Kirsher return NOTIFY_DONE; 3318aa43c215SJeff Kirsher } 3319aa43c215SJeff Kirsher 3320aa43c215SJeff Kirsher static int 3321aa43c215SJeff Kirsher qlcnic_inetaddr_event(struct notifier_block *this, 3322aa43c215SJeff Kirsher unsigned long event, void *ptr) 3323aa43c215SJeff Kirsher { 3324aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 3325aa43c215SJeff Kirsher struct net_device *dev; 3326aa43c215SJeff Kirsher 3327aa43c215SJeff Kirsher struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 3328aa43c215SJeff Kirsher 3329aa43c215SJeff Kirsher dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 3330aa43c215SJeff Kirsher 3331aa43c215SJeff Kirsher recheck: 3332aa43c215SJeff Kirsher if (dev == NULL) 3333aa43c215SJeff Kirsher goto done; 3334aa43c215SJeff Kirsher 3335aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 3336aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 3337aa43c215SJeff Kirsher goto recheck; 3338aa43c215SJeff Kirsher } 3339aa43c215SJeff Kirsher 3340aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 3341aa43c215SJeff Kirsher goto done; 3342aa43c215SJeff Kirsher 3343aa43c215SJeff Kirsher adapter = netdev_priv(dev); 3344aa43c215SJeff Kirsher 3345aa43c215SJeff Kirsher if (!adapter) 3346aa43c215SJeff Kirsher goto done; 3347aa43c215SJeff Kirsher 3348aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3349aa43c215SJeff Kirsher goto done; 3350aa43c215SJeff Kirsher 3351aa43c215SJeff Kirsher switch (event) { 3352aa43c215SJeff Kirsher case NETDEV_UP: 3353aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); 335413159183SSony Chacko 3355aa43c215SJeff Kirsher break; 3356aa43c215SJeff Kirsher case NETDEV_DOWN: 3357aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); 335813159183SSony Chacko 3359aa43c215SJeff Kirsher break; 3360aa43c215SJeff Kirsher default: 3361aa43c215SJeff Kirsher break; 3362aa43c215SJeff Kirsher } 3363aa43c215SJeff Kirsher 3364aa43c215SJeff Kirsher done: 3365aa43c215SJeff Kirsher return NOTIFY_DONE; 3366aa43c215SJeff Kirsher } 3367aa43c215SJeff Kirsher 3368aa43c215SJeff Kirsher static struct notifier_block qlcnic_netdev_cb = { 3369aa43c215SJeff Kirsher .notifier_call = qlcnic_netdev_event, 3370aa43c215SJeff Kirsher }; 3371aa43c215SJeff Kirsher 3372aa43c215SJeff Kirsher static struct notifier_block qlcnic_inetaddr_cb = { 3373aa43c215SJeff Kirsher .notifier_call = qlcnic_inetaddr_event, 3374aa43c215SJeff Kirsher }; 3375aa43c215SJeff Kirsher #else 3376f8ca2b6fSSony Chacko void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) 3377aa43c215SJeff Kirsher { } 3378aa43c215SJeff Kirsher #endif 3379fec9dd15SStephen Hemminger static const struct pci_error_handlers qlcnic_err_handler = { 3380aa43c215SJeff Kirsher .error_detected = qlcnic_io_error_detected, 3381aa43c215SJeff Kirsher .slot_reset = qlcnic_io_slot_reset, 3382aa43c215SJeff Kirsher .resume = qlcnic_io_resume, 3383aa43c215SJeff Kirsher }; 3384aa43c215SJeff Kirsher 3385aa43c215SJeff Kirsher static struct pci_driver qlcnic_driver = { 3386aa43c215SJeff Kirsher .name = qlcnic_driver_name, 3387aa43c215SJeff Kirsher .id_table = qlcnic_pci_tbl, 3388aa43c215SJeff Kirsher .probe = qlcnic_probe, 33896bb58bb0SBill Pemberton .remove = qlcnic_remove, 3390aa43c215SJeff Kirsher #ifdef CONFIG_PM 3391aa43c215SJeff Kirsher .suspend = qlcnic_suspend, 3392aa43c215SJeff Kirsher .resume = qlcnic_resume, 3393aa43c215SJeff Kirsher #endif 3394aa43c215SJeff Kirsher .shutdown = qlcnic_shutdown, 3395aa43c215SJeff Kirsher .err_handler = &qlcnic_err_handler 3396aa43c215SJeff Kirsher 3397aa43c215SJeff Kirsher }; 3398aa43c215SJeff Kirsher 3399aa43c215SJeff Kirsher static int __init qlcnic_init_module(void) 3400aa43c215SJeff Kirsher { 3401aa43c215SJeff Kirsher int ret; 3402aa43c215SJeff Kirsher 3403aa43c215SJeff Kirsher printk(KERN_INFO "%s\n", qlcnic_driver_string); 3404aa43c215SJeff Kirsher 3405aa43c215SJeff Kirsher #ifdef CONFIG_INET 3406aa43c215SJeff Kirsher register_netdevice_notifier(&qlcnic_netdev_cb); 3407aa43c215SJeff Kirsher register_inetaddr_notifier(&qlcnic_inetaddr_cb); 3408aa43c215SJeff Kirsher #endif 3409aa43c215SJeff Kirsher 3410aa43c215SJeff Kirsher ret = pci_register_driver(&qlcnic_driver); 3411aa43c215SJeff Kirsher if (ret) { 3412aa43c215SJeff Kirsher #ifdef CONFIG_INET 3413aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 3414aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 3415aa43c215SJeff Kirsher #endif 3416aa43c215SJeff Kirsher } 3417aa43c215SJeff Kirsher 3418aa43c215SJeff Kirsher return ret; 3419aa43c215SJeff Kirsher } 3420aa43c215SJeff Kirsher 3421aa43c215SJeff Kirsher module_init(qlcnic_init_module); 3422aa43c215SJeff Kirsher 3423aa43c215SJeff Kirsher static void __exit qlcnic_exit_module(void) 3424aa43c215SJeff Kirsher { 3425aa43c215SJeff Kirsher pci_unregister_driver(&qlcnic_driver); 3426aa43c215SJeff Kirsher 3427aa43c215SJeff Kirsher #ifdef CONFIG_INET 3428aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 3429aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 3430aa43c215SJeff Kirsher #endif 3431aa43c215SJeff Kirsher } 3432aa43c215SJeff Kirsher 3433aa43c215SJeff Kirsher module_exit(qlcnic_exit_module); 3434