1aa43c215SJeff Kirsher /* 2aa43c215SJeff Kirsher * QLogic qlcnic NIC Driver 3aa43c215SJeff Kirsher * Copyright (c) 2009-2010 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); 35aa43c215SJeff Kirsher MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)"); 36aa43c215SJeff Kirsher 37629263acSSony Chacko int qlcnic_use_msi = 1; 38aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); 39099f7aa7SSony Chacko module_param_named(use_msi, qlcnic_use_msi, int, 0444); 40aa43c215SJeff Kirsher 41629263acSSony Chacko int qlcnic_use_msi_x = 1; 42aa43c215SJeff Kirsher MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); 43099f7aa7SSony Chacko module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444); 44aa43c215SJeff Kirsher 45629263acSSony Chacko int qlcnic_auto_fw_reset = 1; 46aa43c215SJeff Kirsher MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); 47099f7aa7SSony Chacko module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644); 48aa43c215SJeff Kirsher 49629263acSSony Chacko int qlcnic_load_fw_file; 50aa43c215SJeff Kirsher MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); 51099f7aa7SSony Chacko module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444); 52aa43c215SJeff Kirsher 53629263acSSony Chacko int qlcnic_config_npars; 54aa43c215SJeff Kirsher module_param(qlcnic_config_npars, int, 0444); 55aa43c215SJeff Kirsher MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); 56aa43c215SJeff Kirsher 571dd06ae8SGreg Kroah-Hartman static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 586bb58bb0SBill Pemberton static void qlcnic_remove(struct pci_dev *pdev); 59aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev); 60aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev); 61aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev); 62aa43c215SJeff Kirsher static void qlcnic_attach_work(struct work_struct *work); 63aa43c215SJeff Kirsher static void qlcnic_fwinit_work(struct work_struct *work); 64aa43c215SJeff Kirsher static void qlcnic_fw_poll_work(struct work_struct *work); 65aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 66aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev); 67aa43c215SJeff Kirsher #endif 68aa43c215SJeff Kirsher 69aa43c215SJeff Kirsher static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); 70aa43c215SJeff Kirsher static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); 71aa43c215SJeff Kirsher static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); 72aa43c215SJeff Kirsher 73aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data); 74aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data); 75aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data); 76aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data); 7713159183SSony Chacko static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data); 78aa43c215SJeff Kirsher 79aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); 80aa43c215SJeff Kirsher static int qlcnic_start_firmware(struct qlcnic_adapter *); 81aa43c215SJeff Kirsher 82aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); 83aa43c215SJeff Kirsher static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); 84aa43c215SJeff Kirsher static int qlcnicvf_start_firmware(struct qlcnic_adapter *); 85aa43c215SJeff Kirsher static void qlcnic_set_netdev_features(struct qlcnic_adapter *, 86aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *); 878e586137SJiri Pirko static int qlcnic_vlan_rx_add(struct net_device *, u16); 888e586137SJiri Pirko static int qlcnic_vlan_rx_del(struct net_device *, u16); 89aa43c215SJeff Kirsher 90bff57d8eSSony Chacko #define QLCNIC_IS_TSO_CAPABLE(adapter) \ 91bff57d8eSSony Chacko ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO) 92bff57d8eSSony Chacko 9313159183SSony Chacko static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter) 9413159183SSony Chacko { 9513159183SSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 9613159183SSony Chacko 9713159183SSony Chacko if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X) 9813159183SSony Chacko return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX; 9913159183SSony Chacko else 10013159183SSony Chacko return 1; 10113159183SSony Chacko } 10213159183SSony Chacko 103aa43c215SJeff Kirsher /* PCI Device ID Table */ 104aa43c215SJeff Kirsher #define ENTRY(device) \ 105aa43c215SJeff Kirsher {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ 106aa43c215SJeff Kirsher .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} 107aa43c215SJeff Kirsher 108aa43c215SJeff Kirsher static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { 109aa43c215SJeff Kirsher ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), 11013159183SSony Chacko ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X), 111aa43c215SJeff Kirsher {0,} 112aa43c215SJeff Kirsher }; 113aa43c215SJeff Kirsher 114aa43c215SJeff Kirsher MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); 115aa43c215SJeff Kirsher 116aa43c215SJeff Kirsher 1175ad6ff9dSSony Chacko inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring) 118aa43c215SJeff Kirsher { 119aa43c215SJeff Kirsher writel(tx_ring->producer, tx_ring->crb_cmd_producer); 120aa43c215SJeff Kirsher } 121aa43c215SJeff Kirsher 122aa43c215SJeff Kirsher static const u32 msi_tgt_status[8] = { 123aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, 124aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, 125aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, 126aa43c215SJeff Kirsher ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 127aa43c215SJeff Kirsher }; 128aa43c215SJeff Kirsher 1297e2cf4feSSony Chacko static const u32 qlcnic_reg_tbl[] = { 1307e2cf4feSSony Chacko 0x1B20A8, /* PEG_HALT_STAT1 */ 1317e2cf4feSSony Chacko 0x1B20AC, /* PEG_HALT_STAT2 */ 1327e2cf4feSSony Chacko 0x1B20B0, /* FW_HEARTBEAT */ 1337e2cf4feSSony Chacko 0x1B2100, /* LOCK ID */ 1347e2cf4feSSony Chacko 0x1B2128, /* FW_CAPABILITIES */ 1357e2cf4feSSony Chacko 0x1B2138, /* drv active */ 1367e2cf4feSSony Chacko 0x1B2140, /* dev state */ 1377e2cf4feSSony Chacko 0x1B2144, /* drv state */ 1387e2cf4feSSony Chacko 0x1B2148, /* drv scratch */ 1397e2cf4feSSony Chacko 0x1B214C, /* dev partition info */ 1407e2cf4feSSony Chacko 0x1B2174, /* drv idc ver */ 1417e2cf4feSSony Chacko 0x1B2150, /* fw version major */ 1427e2cf4feSSony Chacko 0x1B2154, /* fw version minor */ 1437e2cf4feSSony Chacko 0x1B2158, /* fw version sub */ 1447e2cf4feSSony Chacko 0x1B219C, /* npar state */ 1457e2cf4feSSony Chacko 0x1B21FC, /* FW_IMG_VALID */ 1467e2cf4feSSony Chacko 0x1B2250, /* CMD_PEG_STATE */ 1477e2cf4feSSony Chacko 0x1B233C, /* RCV_PEG_STATE */ 1487e2cf4feSSony Chacko 0x1B23B4, /* ASIC TEMP */ 1497e2cf4feSSony Chacko 0x1B216C, /* FW api */ 1507e2cf4feSSony Chacko 0x1B2170, /* drv op mode */ 1517e2cf4feSSony Chacko 0x13C010, /* flash lock */ 1527e2cf4feSSony Chacko 0x13C014, /* flash unlock */ 1537e2cf4feSSony Chacko }; 1547e2cf4feSSony Chacko 15522999798SSony Chacko static const struct qlcnic_board_info qlcnic_boards[] = { 15622999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x203, 15722999798SSony Chacko "8200 Series Single Port 10GbE Converged Network Adapter" 15822999798SSony Chacko "(TCP/IP Networking)"}, 15922999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x207, 16022999798SSony Chacko "8200 Series Dual Port 10GbE Converged Network Adapter" 16122999798SSony Chacko "(TCP/IP Networking)"}, 16222999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20b, 16322999798SSony Chacko "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"}, 16422999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20c, 16522999798SSony Chacko "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"}, 16622999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x20f, 16722999798SSony Chacko "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"}, 16822999798SSony Chacko {0x1077, 0x8020, 0x103c, 0x3733, 16922999798SSony Chacko "NC523SFP 10Gb 2-port Server Adapter"}, 17022999798SSony Chacko {0x1077, 0x8020, 0x103c, 0x3346, 17122999798SSony Chacko "CN1000Q Dual Port Converged Network Adapter"}, 17222999798SSony Chacko {0x1077, 0x8020, 0x1077, 0x210, 17322999798SSony Chacko "QME8242-k 10GbE Dual Port Mezzanine Card"}, 17422999798SSony Chacko {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"}, 17522999798SSony Chacko }; 17622999798SSony Chacko 17722999798SSony Chacko #define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards) 178319ecf12SSony Chacko #define QLC_MAX_SDS_RINGS 8 17922999798SSony Chacko 180aa43c215SJeff Kirsher static const 181aa43c215SJeff Kirsher struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; 182aa43c215SJeff Kirsher 183c70001a9SSony Chacko int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) 184aa43c215SJeff Kirsher { 185aa43c215SJeff Kirsher int size = sizeof(struct qlcnic_host_sds_ring) * count; 186aa43c215SJeff Kirsher 187aa43c215SJeff Kirsher recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); 188aa43c215SJeff Kirsher 189aa43c215SJeff Kirsher return recv_ctx->sds_rings == NULL; 190aa43c215SJeff Kirsher } 191aa43c215SJeff Kirsher 192c70001a9SSony Chacko void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) 193aa43c215SJeff Kirsher { 194aa43c215SJeff Kirsher if (recv_ctx->sds_rings != NULL) 195aa43c215SJeff Kirsher kfree(recv_ctx->sds_rings); 196aa43c215SJeff Kirsher 197aa43c215SJeff Kirsher recv_ctx->sds_rings = NULL; 198aa43c215SJeff Kirsher } 199aa43c215SJeff Kirsher 200aa43c215SJeff Kirsher static int 201aa43c215SJeff Kirsher qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) 202aa43c215SJeff Kirsher { 203aa43c215SJeff Kirsher u8 mac_addr[ETH_ALEN]; 204aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 205aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 206aa43c215SJeff Kirsher 207aa43c215SJeff Kirsher if (qlcnic_get_mac_address(adapter, mac_addr) != 0) 208aa43c215SJeff Kirsher return -EIO; 209aa43c215SJeff Kirsher 210aa43c215SJeff Kirsher memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); 211aa43c215SJeff Kirsher memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); 212aa43c215SJeff Kirsher 213aa43c215SJeff Kirsher /* set station address */ 214aa43c215SJeff Kirsher 215aaeb6cdfSJiri Pirko if (!is_valid_ether_addr(netdev->dev_addr)) 216aa43c215SJeff Kirsher dev_warn(&pdev->dev, "Bad MAC address %pM.\n", 217aa43c215SJeff Kirsher netdev->dev_addr); 218aa43c215SJeff Kirsher 219aa43c215SJeff Kirsher return 0; 220aa43c215SJeff Kirsher } 221aa43c215SJeff Kirsher 222aa43c215SJeff Kirsher static int qlcnic_set_mac(struct net_device *netdev, void *p) 223aa43c215SJeff Kirsher { 224aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 225aa43c215SJeff Kirsher struct sockaddr *addr = p; 226aa43c215SJeff Kirsher 227aa43c215SJeff Kirsher if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) 228aa43c215SJeff Kirsher return -EOPNOTSUPP; 229aa43c215SJeff Kirsher 230aa43c215SJeff Kirsher if (!is_valid_ether_addr(addr->sa_data)) 23113159183SSony Chacko return -EINVAL; 232aa43c215SJeff Kirsher 233aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 234aa43c215SJeff Kirsher netif_device_detach(netdev); 235aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 236aa43c215SJeff Kirsher } 237aa43c215SJeff Kirsher 238aa43c215SJeff Kirsher memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); 239aa43c215SJeff Kirsher memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); 240aa43c215SJeff Kirsher qlcnic_set_multi(adapter->netdev); 241aa43c215SJeff Kirsher 242aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { 243aa43c215SJeff Kirsher netif_device_attach(netdev); 244aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 245aa43c215SJeff Kirsher } 246aa43c215SJeff Kirsher return 0; 247aa43c215SJeff Kirsher } 248aa43c215SJeff Kirsher 2497e2cf4feSSony Chacko static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter) 2507e2cf4feSSony Chacko { 2517e2cf4feSSony Chacko while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 2527e2cf4feSSony Chacko usleep_range(10000, 11000); 2537e2cf4feSSony Chacko 2547e2cf4feSSony Chacko cancel_delayed_work_sync(&adapter->fw_work); 2557e2cf4feSSony Chacko } 2567e2cf4feSSony Chacko 257aa43c215SJeff Kirsher static const struct net_device_ops qlcnic_netdev_ops = { 258aa43c215SJeff Kirsher .ndo_open = qlcnic_open, 259aa43c215SJeff Kirsher .ndo_stop = qlcnic_close, 260aa43c215SJeff Kirsher .ndo_start_xmit = qlcnic_xmit_frame, 261aa43c215SJeff Kirsher .ndo_get_stats = qlcnic_get_stats, 262aa43c215SJeff Kirsher .ndo_validate_addr = eth_validate_addr, 263afc4b13dSJiri Pirko .ndo_set_rx_mode = qlcnic_set_multi, 264aa43c215SJeff Kirsher .ndo_set_mac_address = qlcnic_set_mac, 265aa43c215SJeff Kirsher .ndo_change_mtu = qlcnic_change_mtu, 266aa43c215SJeff Kirsher .ndo_fix_features = qlcnic_fix_features, 267aa43c215SJeff Kirsher .ndo_set_features = qlcnic_set_features, 268aa43c215SJeff Kirsher .ndo_tx_timeout = qlcnic_tx_timeout, 269aa43c215SJeff Kirsher .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, 270aa43c215SJeff Kirsher .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, 271aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 272aa43c215SJeff Kirsher .ndo_poll_controller = qlcnic_poll_controller, 273aa43c215SJeff Kirsher #endif 274aa43c215SJeff Kirsher }; 275aa43c215SJeff Kirsher 276b43e5ee7SSucheta Chakraborty static const struct net_device_ops qlcnic_netdev_failed_ops = { 277b43e5ee7SSucheta Chakraborty .ndo_open = qlcnic_open, 278b43e5ee7SSucheta Chakraborty }; 279b43e5ee7SSucheta Chakraborty 280aa43c215SJeff Kirsher static struct qlcnic_nic_template qlcnic_ops = { 281aa43c215SJeff Kirsher .config_bridged_mode = qlcnic_config_bridged_mode, 2827e2cf4feSSony Chacko .config_led = qlcnic_82xx_config_led, 2837e2cf4feSSony Chacko .start_firmware = qlcnic_82xx_start_firmware, 2847e2cf4feSSony Chacko .request_reset = qlcnic_82xx_dev_request_reset, 2857e2cf4feSSony Chacko .cancel_idc_work = qlcnic_82xx_cancel_idc_work, 2867e2cf4feSSony Chacko .napi_add = qlcnic_82xx_napi_add, 2874be41e92SSony Chacko .napi_del = qlcnic_82xx_napi_del, 2887e2cf4feSSony Chacko .config_ipaddr = qlcnic_82xx_config_ipaddr, 2897e2cf4feSSony Chacko .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr, 290aa43c215SJeff Kirsher }; 291aa43c215SJeff Kirsher 2927e2cf4feSSony Chacko struct qlcnic_nic_template qlcnic_vf_ops = { 293aa43c215SJeff Kirsher .config_bridged_mode = qlcnicvf_config_bridged_mode, 294aa43c215SJeff Kirsher .config_led = qlcnicvf_config_led, 295aa43c215SJeff Kirsher .start_firmware = qlcnicvf_start_firmware 296aa43c215SJeff Kirsher }; 297aa43c215SJeff Kirsher 2987e2cf4feSSony Chacko static struct qlcnic_hardware_ops qlcnic_hw_ops = { 2997e2cf4feSSony Chacko .read_crb = qlcnic_82xx_read_crb, 3007e2cf4feSSony Chacko .write_crb = qlcnic_82xx_write_crb, 3017e2cf4feSSony Chacko .read_reg = qlcnic_82xx_hw_read_wx_2M, 3027e2cf4feSSony Chacko .write_reg = qlcnic_82xx_hw_write_wx_2M, 3037e2cf4feSSony Chacko .get_mac_address = qlcnic_82xx_get_mac_address, 3047e2cf4feSSony Chacko .setup_intr = qlcnic_82xx_setup_intr, 3057e2cf4feSSony Chacko .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args, 3067e2cf4feSSony Chacko .mbx_cmd = qlcnic_82xx_issue_cmd, 3077e2cf4feSSony Chacko .get_func_no = qlcnic_82xx_get_func_no, 3087e2cf4feSSony Chacko .api_lock = qlcnic_82xx_api_lock, 3097e2cf4feSSony Chacko .api_unlock = qlcnic_82xx_api_unlock, 3107e2cf4feSSony Chacko .add_sysfs = qlcnic_82xx_add_sysfs, 3117e2cf4feSSony Chacko .remove_sysfs = qlcnic_82xx_remove_sysfs, 3127e2cf4feSSony Chacko .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag, 3137e2cf4feSSony Chacko .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx, 3147e2cf4feSSony Chacko .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx, 3157e2cf4feSSony Chacko .setup_link_event = qlcnic_82xx_linkevent_request, 3167e2cf4feSSony Chacko .get_nic_info = qlcnic_82xx_get_nic_info, 3177e2cf4feSSony Chacko .get_pci_info = qlcnic_82xx_get_pci_info, 3187e2cf4feSSony Chacko .set_nic_info = qlcnic_82xx_set_nic_info, 3197e2cf4feSSony Chacko .change_macvlan = qlcnic_82xx_sre_macaddr_change, 3207e2cf4feSSony Chacko .napi_enable = qlcnic_82xx_napi_enable, 3217e2cf4feSSony Chacko .napi_disable = qlcnic_82xx_napi_disable, 3227e2cf4feSSony Chacko .config_intr_coal = qlcnic_82xx_config_intr_coalesce, 3237e2cf4feSSony Chacko .config_rss = qlcnic_82xx_config_rss, 3247e2cf4feSSony Chacko .config_hw_lro = qlcnic_82xx_config_hw_lro, 3257e2cf4feSSony Chacko .config_loopback = qlcnic_82xx_set_lb_mode, 3267e2cf4feSSony Chacko .clear_loopback = qlcnic_82xx_clear_lb_mode, 3277e2cf4feSSony Chacko .config_promisc_mode = qlcnic_82xx_nic_set_promisc, 3287e2cf4feSSony Chacko .change_l2_filter = qlcnic_82xx_change_filter, 3297e2cf4feSSony Chacko .get_board_info = qlcnic_82xx_get_board_info, 3307e2cf4feSSony Chacko }; 3317e2cf4feSSony Chacko 3327f966452SSony Chacko int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) 333aa43c215SJeff Kirsher { 334aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 33513159183SSony Chacko int err = -1, i; 33613159183SSony Chacko int max_tx_rings; 33713159183SSony Chacko 33813159183SSony Chacko if (!adapter->msix_entries) { 33913159183SSony Chacko adapter->msix_entries = kcalloc(num_msix, 34013159183SSony Chacko sizeof(struct msix_entry), 34113159183SSony Chacko GFP_KERNEL); 34213159183SSony Chacko if (!adapter->msix_entries) { 34313159183SSony Chacko dev_err(&pdev->dev, "failed allocating msix_entries\n"); 34413159183SSony Chacko return -ENOMEM; 34513159183SSony Chacko } 34613159183SSony Chacko } 347aa43c215SJeff Kirsher 348aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 349aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); 350aa43c215SJeff Kirsher 35179788450SSony Chacko if (adapter->ahw->msix_supported) { 352aa43c215SJeff Kirsher enable_msix: 35313159183SSony Chacko for (i = 0; i < num_msix; i++) 35413159183SSony Chacko adapter->msix_entries[i].entry = i; 355aa43c215SJeff Kirsher err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); 356aa43c215SJeff Kirsher if (err == 0) { 357aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSIX_ENABLED; 35813159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 35913159183SSony Chacko adapter->ahw->num_msix = num_msix; 36013159183SSony Chacko /* subtract mail box and tx ring vectors */ 36113159183SSony Chacko max_tx_rings = adapter->max_drv_tx_rings; 36213159183SSony Chacko adapter->max_sds_rings = num_msix - 36313159183SSony Chacko max_tx_rings - 1; 36413159183SSony Chacko } else { 365aa43c215SJeff Kirsher adapter->max_sds_rings = num_msix; 36613159183SSony Chacko } 367aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi-x interrupts\n"); 368aa43c215SJeff Kirsher return err; 36913159183SSony Chacko } else if (err > 0) { 37013159183SSony Chacko dev_info(&pdev->dev, 37113159183SSony Chacko "Unable to allocate %d MSI-X interrupt vectors\n", 37213159183SSony Chacko num_msix); 37313159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 37413159183SSony Chacko if (err < QLC_83XX_MINIMUM_VECTOR) 37513159183SSony Chacko return err; 37613159183SSony Chacko err -= (adapter->max_drv_tx_rings + 1); 377aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(err); 37813159183SSony Chacko num_msix += (adapter->max_drv_tx_rings + 1); 37913159183SSony Chacko } else { 38013159183SSony Chacko num_msix = rounddown_pow_of_two(err); 38113159183SSony Chacko } 38213159183SSony Chacko 38313159183SSony Chacko if (num_msix) { 38413159183SSony Chacko dev_info(&pdev->dev, 38513159183SSony Chacko "Trying %d MSI-X interrupt vectors\n", 38613159183SSony Chacko num_msix); 387aa43c215SJeff Kirsher goto enable_msix; 388aa43c215SJeff Kirsher } 38913159183SSony Chacko } else { 39013159183SSony Chacko dev_info(&pdev->dev, "Failed to get %d vectors\n", 39113159183SSony Chacko num_msix); 392aa43c215SJeff Kirsher } 39313159183SSony Chacko } 39413159183SSony Chacko 395aa43c215SJeff Kirsher return err; 396aa43c215SJeff Kirsher } 397aa43c215SJeff Kirsher 398aa43c215SJeff Kirsher static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) 399aa43c215SJeff Kirsher { 40015087c2bSSony Chacko u32 offset, mask_reg; 401aa43c215SJeff Kirsher const struct qlcnic_legacy_intr_set *legacy_intrp; 40215087c2bSSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 403aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 404aa43c215SJeff Kirsher 405099f7aa7SSony Chacko if (qlcnic_use_msi && !pci_enable_msi(pdev)) { 406aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MSI_ENABLED; 40715087c2bSSony Chacko offset = msi_tgt_status[adapter->ahw->pci_func]; 40815087c2bSSony Chacko adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw, 40915087c2bSSony Chacko offset); 410aa43c215SJeff Kirsher dev_info(&pdev->dev, "using msi interrupts\n"); 411aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 412aa43c215SJeff Kirsher return; 413aa43c215SJeff Kirsher } 414aa43c215SJeff Kirsher 415aa43c215SJeff Kirsher legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; 41679788450SSony Chacko adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit; 41715087c2bSSony Chacko offset = legacy_intrp->tgt_status_reg; 41815087c2bSSony Chacko adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset); 41915087c2bSSony Chacko mask_reg = legacy_intrp->tgt_mask_reg; 42015087c2bSSony Chacko adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg); 42115087c2bSSony Chacko adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR); 42215087c2bSSony Chacko adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG); 423aa43c215SJeff Kirsher dev_info(&pdev->dev, "using legacy interrupts\n"); 424aa43c215SJeff Kirsher adapter->msix_entries[0].vector = pdev->irq; 425aa43c215SJeff Kirsher } 426aa43c215SJeff Kirsher 4277e2cf4feSSony Chacko int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr) 428aa43c215SJeff Kirsher { 4297e2cf4feSSony Chacko int num_msix, err; 430aa43c215SJeff Kirsher 4317e2cf4feSSony Chacko if (!num_intr) 4327e2cf4feSSony Chacko num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS; 4337e2cf4feSSony Chacko 4347e2cf4feSSony Chacko if (adapter->ahw->msix_supported) 435aa43c215SJeff Kirsher num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(), 4367e2cf4feSSony Chacko num_intr)); 4377e2cf4feSSony Chacko else 438aa43c215SJeff Kirsher num_msix = 1; 439aa43c215SJeff Kirsher 4407e2cf4feSSony Chacko err = qlcnic_enable_msix(adapter, num_msix); 4417e2cf4feSSony Chacko if (err == -ENOMEM || !err) 4427e2cf4feSSony Chacko return err; 443aa43c215SJeff Kirsher 444aa43c215SJeff Kirsher qlcnic_enable_msi_legacy(adapter); 4457e2cf4feSSony Chacko return 0; 446aa43c215SJeff Kirsher } 44713159183SSony Chacko 448319ecf12SSony Chacko void qlcnic_teardown_intr(struct qlcnic_adapter *adapter) 449aa43c215SJeff Kirsher { 450aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 451aa43c215SJeff Kirsher pci_disable_msix(adapter->pdev); 452aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSI_ENABLED) 453aa43c215SJeff Kirsher pci_disable_msi(adapter->pdev); 45413159183SSony Chacko 45513159183SSony Chacko kfree(adapter->msix_entries); 45613159183SSony Chacko adapter->msix_entries = NULL; 45713159183SSony Chacko 45813159183SSony Chacko if (adapter->ahw->intr_tbl) { 45913159183SSony Chacko vfree(adapter->ahw->intr_tbl); 46013159183SSony Chacko adapter->ahw->intr_tbl = NULL; 46113159183SSony Chacko } 462aa43c215SJeff Kirsher } 463aa43c215SJeff Kirsher 464aa43c215SJeff Kirsher static void 465aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) 466aa43c215SJeff Kirsher { 467aa43c215SJeff Kirsher if (adapter->ahw->pci_base0 != NULL) 468aa43c215SJeff Kirsher iounmap(adapter->ahw->pci_base0); 469aa43c215SJeff Kirsher } 470aa43c215SJeff Kirsher 4717e2cf4feSSony Chacko static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter) 4727e2cf4feSSony Chacko { 4737e2cf4feSSony Chacko struct qlcnic_pci_info *pci_info; 4747e2cf4feSSony Chacko int ret; 4757e2cf4feSSony Chacko 4767e2cf4feSSony Chacko if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) { 4777e2cf4feSSony Chacko switch (adapter->ahw->port_type) { 4787e2cf4feSSony Chacko case QLCNIC_GBE: 4797e2cf4feSSony Chacko adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS; 4807e2cf4feSSony Chacko break; 4817e2cf4feSSony Chacko case QLCNIC_XGBE: 4827e2cf4feSSony Chacko adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS; 4837e2cf4feSSony Chacko break; 4847e2cf4feSSony Chacko } 4857e2cf4feSSony Chacko return 0; 4867e2cf4feSSony Chacko } 4877e2cf4feSSony Chacko 4887e2cf4feSSony Chacko if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 4897e2cf4feSSony Chacko return 0; 4907e2cf4feSSony Chacko 4917e2cf4feSSony Chacko pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 4927e2cf4feSSony Chacko if (!pci_info) 4937e2cf4feSSony Chacko return -ENOMEM; 4947e2cf4feSSony Chacko 4957e2cf4feSSony Chacko ret = qlcnic_get_pci_info(adapter, pci_info); 4967e2cf4feSSony Chacko kfree(pci_info); 4977e2cf4feSSony Chacko return ret; 4987e2cf4feSSony Chacko } 499d71170fbSSony Chacko 500d71170fbSSony Chacko int qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 501aa43c215SJeff Kirsher { 502aa43c215SJeff Kirsher struct qlcnic_pci_info *pci_info; 503bff57d8eSSony Chacko int i, ret = 0, j = 0; 504bff57d8eSSony Chacko u16 act_pci_func; 505aa43c215SJeff Kirsher u8 pfn; 506aa43c215SJeff Kirsher 507aa43c215SJeff Kirsher pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 508aa43c215SJeff Kirsher if (!pci_info) 509aa43c215SJeff Kirsher return -ENOMEM; 510aa43c215SJeff Kirsher 511bff57d8eSSony Chacko ret = qlcnic_get_pci_info(adapter, pci_info); 512bff57d8eSSony Chacko if (ret) 513bff57d8eSSony Chacko goto err_pci_info; 514bff57d8eSSony Chacko 515bff57d8eSSony Chacko act_pci_func = adapter->ahw->act_pci_func; 516bff57d8eSSony Chacko 517aa43c215SJeff Kirsher adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 518bff57d8eSSony Chacko act_pci_func, GFP_KERNEL); 519aa43c215SJeff Kirsher if (!adapter->npars) { 520aa43c215SJeff Kirsher ret = -ENOMEM; 521aa43c215SJeff Kirsher goto err_pci_info; 522aa43c215SJeff Kirsher } 523aa43c215SJeff Kirsher 524aa43c215SJeff Kirsher adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 525aa43c215SJeff Kirsher QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 526aa43c215SJeff Kirsher if (!adapter->eswitch) { 527aa43c215SJeff Kirsher ret = -ENOMEM; 528aa43c215SJeff Kirsher goto err_npars; 529aa43c215SJeff Kirsher } 530aa43c215SJeff Kirsher 531aa43c215SJeff Kirsher for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 532aa43c215SJeff Kirsher pfn = pci_info[i].id; 533bff57d8eSSony Chacko 5340f6efff9SDan Carpenter if (pfn >= QLCNIC_MAX_PCI_FUNC) { 535aa43c215SJeff Kirsher ret = QL_STATUS_INVALID_PARAM; 536aa43c215SJeff Kirsher goto err_eswitch; 537aa43c215SJeff Kirsher } 538bff57d8eSSony Chacko 539bff57d8eSSony Chacko if (!pci_info[i].active || 540bff57d8eSSony Chacko (pci_info[i].type != QLCNIC_TYPE_NIC)) 541bff57d8eSSony Chacko continue; 542bff57d8eSSony Chacko 543bff57d8eSSony Chacko adapter->npars[j].pci_func = pfn; 544bff57d8eSSony Chacko adapter->npars[j].active = (u8)pci_info[i].active; 545bff57d8eSSony Chacko adapter->npars[j].type = (u8)pci_info[i].type; 546bff57d8eSSony Chacko adapter->npars[j].phy_port = (u8)pci_info[i].default_port; 547bff57d8eSSony Chacko adapter->npars[j].min_bw = pci_info[i].tx_min_bw; 548bff57d8eSSony Chacko adapter->npars[j].max_bw = pci_info[i].tx_max_bw; 549bff57d8eSSony Chacko j++; 550aa43c215SJeff Kirsher } 551aa43c215SJeff Kirsher 55213159183SSony Chacko for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) { 553aa43c215SJeff Kirsher adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; 55413159183SSony Chacko if (qlcnic_83xx_check(adapter)) 55513159183SSony Chacko qlcnic_enable_eswitch(adapter, i, 1); 55613159183SSony Chacko } 557aa43c215SJeff Kirsher 558aa43c215SJeff Kirsher kfree(pci_info); 559aa43c215SJeff Kirsher return 0; 560aa43c215SJeff Kirsher 561aa43c215SJeff Kirsher err_eswitch: 562aa43c215SJeff Kirsher kfree(adapter->eswitch); 563aa43c215SJeff Kirsher adapter->eswitch = NULL; 564aa43c215SJeff Kirsher err_npars: 565aa43c215SJeff Kirsher kfree(adapter->npars); 566aa43c215SJeff Kirsher adapter->npars = NULL; 567aa43c215SJeff Kirsher err_pci_info: 568aa43c215SJeff Kirsher kfree(pci_info); 569aa43c215SJeff Kirsher 570aa43c215SJeff Kirsher return ret; 571aa43c215SJeff Kirsher } 572aa43c215SJeff Kirsher 573aa43c215SJeff Kirsher static int 574aa43c215SJeff Kirsher qlcnic_set_function_modes(struct qlcnic_adapter *adapter) 575aa43c215SJeff Kirsher { 576aa43c215SJeff Kirsher u8 id; 577aa43c215SJeff Kirsher int i, ret = 1; 578aa43c215SJeff Kirsher u32 data = QLCNIC_MGMT_FUNC; 579bff57d8eSSony Chacko struct qlcnic_hardware_context *ahw = adapter->ahw; 580aa43c215SJeff Kirsher 581aa43c215SJeff Kirsher ret = qlcnic_api_lock(adapter); 582aa43c215SJeff Kirsher if (ret) 583aa43c215SJeff Kirsher goto err_lock; 584aa43c215SJeff Kirsher 585aa43c215SJeff Kirsher if (qlcnic_config_npars) { 586bff57d8eSSony Chacko for (i = 0; i < ahw->act_pci_func; i++) { 587bff57d8eSSony Chacko id = adapter->npars[i].pci_func; 588bff57d8eSSony Chacko if (id == ahw->pci_func) 589aa43c215SJeff Kirsher continue; 590aa43c215SJeff Kirsher data |= (qlcnic_config_npars & 591aa43c215SJeff Kirsher QLC_DEV_SET_DRV(0xf, id)); 592aa43c215SJeff Kirsher } 593aa43c215SJeff Kirsher } else { 594a15ebd37SHimanshu Madhani data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 595bff57d8eSSony Chacko data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) | 596aa43c215SJeff Kirsher (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, 597bff57d8eSSony Chacko ahw->pci_func)); 598aa43c215SJeff Kirsher } 599a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data); 600aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 601aa43c215SJeff Kirsher err_lock: 602aa43c215SJeff Kirsher return ret; 603aa43c215SJeff Kirsher } 604aa43c215SJeff Kirsher 60513159183SSony Chacko static void qlcnic_check_vf(struct qlcnic_adapter *adapter, 60613159183SSony Chacko const struct pci_device_id *ent) 607aa43c215SJeff Kirsher { 608aa43c215SJeff Kirsher u32 op_mode, priv_level; 609aa43c215SJeff Kirsher 610aa43c215SJeff Kirsher /* Determine FW API version */ 61113159183SSony Chacko adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter, 612aa43c215SJeff Kirsher QLCNIC_FW_API); 613aa43c215SJeff Kirsher 614aa43c215SJeff Kirsher /* Find PCI function number */ 61513159183SSony Chacko qlcnic_get_func_no(adapter); 616aa43c215SJeff Kirsher 617aa43c215SJeff Kirsher /* Determine function privilege level */ 61813159183SSony Chacko op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 619aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 620aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 621aa43c215SJeff Kirsher else 622aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 623aa43c215SJeff Kirsher 624aa43c215SJeff Kirsher if (priv_level == QLCNIC_NON_PRIV_FUNC) { 62579788450SSony Chacko adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC; 626aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 627aa43c215SJeff Kirsher "HAL Version: %d Non Privileged function\n", 62879788450SSony Chacko adapter->ahw->fw_hal_version); 629aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_vf_ops; 630aa43c215SJeff Kirsher } else 631aa43c215SJeff Kirsher adapter->nic_ops = &qlcnic_ops; 632aa43c215SJeff Kirsher } 633aa43c215SJeff Kirsher 63415087c2bSSony Chacko #define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL 63513159183SSony Chacko #define QLCNIC_83XX_BAR0_LENGTH 0x4000 63615087c2bSSony Chacko static void qlcnic_get_bar_length(u32 dev_id, ulong *bar) 637aa43c215SJeff Kirsher { 63815087c2bSSony Chacko switch (dev_id) { 63915087c2bSSony Chacko case PCI_DEVICE_ID_QLOGIC_QLE824X: 64015087c2bSSony Chacko *bar = QLCNIC_82XX_BAR0_LENGTH; 64115087c2bSSony Chacko break; 64213159183SSony Chacko case PCI_DEVICE_ID_QLOGIC_QLE834X: 64313159183SSony Chacko *bar = QLCNIC_83XX_BAR0_LENGTH; 64413159183SSony Chacko break; 64515087c2bSSony Chacko default: 64615087c2bSSony Chacko *bar = 0; 64715087c2bSSony Chacko } 64815087c2bSSony Chacko } 64915087c2bSSony Chacko 65015087c2bSSony Chacko static int qlcnic_setup_pci_map(struct pci_dev *pdev, 65115087c2bSSony Chacko struct qlcnic_hardware_context *ahw) 65215087c2bSSony Chacko { 65315087c2bSSony Chacko u32 offset; 654aa43c215SJeff Kirsher void __iomem *mem_ptr0 = NULL; 65515087c2bSSony Chacko unsigned long mem_len, pci_len0 = 0, bar0_len; 656aa43c215SJeff Kirsher 657aa43c215SJeff Kirsher /* remap phys address */ 658aa43c215SJeff Kirsher mem_len = pci_resource_len(pdev, 0); 659aa43c215SJeff Kirsher 66015087c2bSSony Chacko qlcnic_get_bar_length(pdev->device, &bar0_len); 66115087c2bSSony Chacko if (mem_len >= bar0_len) { 662aa43c215SJeff Kirsher 663aa43c215SJeff Kirsher mem_ptr0 = pci_ioremap_bar(pdev, 0); 664aa43c215SJeff Kirsher if (mem_ptr0 == NULL) { 665aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to map PCI bar 0\n"); 666aa43c215SJeff Kirsher return -EIO; 667aa43c215SJeff Kirsher } 668aa43c215SJeff Kirsher pci_len0 = mem_len; 669aa43c215SJeff Kirsher } else { 670aa43c215SJeff Kirsher return -EIO; 671aa43c215SJeff Kirsher } 672aa43c215SJeff Kirsher 673aa43c215SJeff Kirsher dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); 6747e2cf4feSSony Chacko 67515087c2bSSony Chacko ahw->pci_base0 = mem_ptr0; 67615087c2bSSony Chacko ahw->pci_len0 = pci_len0; 67715087c2bSSony Chacko offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func)); 67815087c2bSSony Chacko qlcnic_get_ioaddr(ahw, offset); 679aa43c215SJeff Kirsher 680aa43c215SJeff Kirsher return 0; 681aa43c215SJeff Kirsher } 682aa43c215SJeff Kirsher 68322999798SSony Chacko static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name) 684aa43c215SJeff Kirsher { 685aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 686aa43c215SJeff Kirsher int i, found = 0; 687aa43c215SJeff Kirsher 688aa43c215SJeff Kirsher for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { 689aa43c215SJeff Kirsher if (qlcnic_boards[i].vendor == pdev->vendor && 690aa43c215SJeff Kirsher qlcnic_boards[i].device == pdev->device && 691aa43c215SJeff Kirsher qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && 692aa43c215SJeff Kirsher qlcnic_boards[i].sub_device == pdev->subsystem_device) { 693aa43c215SJeff Kirsher sprintf(name, "%pM: %s" , 694aa43c215SJeff Kirsher adapter->mac_addr, 695aa43c215SJeff Kirsher qlcnic_boards[i].short_name); 696aa43c215SJeff Kirsher found = 1; 697aa43c215SJeff Kirsher break; 698aa43c215SJeff Kirsher } 699aa43c215SJeff Kirsher 700aa43c215SJeff Kirsher } 701aa43c215SJeff Kirsher 702aa43c215SJeff Kirsher if (!found) 703aa43c215SJeff Kirsher sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); 704aa43c215SJeff Kirsher } 705aa43c215SJeff Kirsher 706aa43c215SJeff Kirsher static void 707aa43c215SJeff Kirsher qlcnic_check_options(struct qlcnic_adapter *adapter) 708aa43c215SJeff Kirsher { 709a15ebd37SHimanshu Madhani int err; 710aa43c215SJeff Kirsher u32 fw_major, fw_minor, fw_build, prev_fw_version; 711aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 712a15ebd37SHimanshu Madhani struct qlcnic_hardware_context *ahw = adapter->ahw; 713a15ebd37SHimanshu Madhani struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump; 714aa43c215SJeff Kirsher 715aa43c215SJeff Kirsher prev_fw_version = adapter->fw_version; 716aa43c215SJeff Kirsher 717a15ebd37SHimanshu Madhani fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR); 718a15ebd37SHimanshu Madhani fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR); 719a15ebd37SHimanshu Madhani fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB); 720aa43c215SJeff Kirsher 721aa43c215SJeff Kirsher adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); 722aa43c215SJeff Kirsher 723a15ebd37SHimanshu Madhani err = qlcnic_get_board_info(adapter); 724a15ebd37SHimanshu Madhani if (err) { 725a15ebd37SHimanshu Madhani dev_err(&pdev->dev, "Error getting board config info.\n"); 726a15ebd37SHimanshu Madhani return; 727a15ebd37SHimanshu Madhani } 728a15ebd37SHimanshu Madhani if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) { 729aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr == NULL || 730aa43c215SJeff Kirsher adapter->fw_version > prev_fw_version) { 731aa43c215SJeff Kirsher if (fw_dump->tmpl_hdr) 732aa43c215SJeff Kirsher vfree(fw_dump->tmpl_hdr); 733aa43c215SJeff Kirsher if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) 734aa43c215SJeff Kirsher dev_info(&pdev->dev, 735aa43c215SJeff Kirsher "Supports FW dump capability\n"); 736aa43c215SJeff Kirsher } 737aa43c215SJeff Kirsher } 738aa43c215SJeff Kirsher 73913159183SSony Chacko dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n", 74013159183SSony Chacko QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build); 74113159183SSony Chacko 742aa43c215SJeff Kirsher if (adapter->ahw->port_type == QLCNIC_XGBE) { 743aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 744aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; 745aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; 746aa43c215SJeff Kirsher } else { 747aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; 748aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; 749aa43c215SJeff Kirsher } 750aa43c215SJeff Kirsher 751aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 752aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 753aa43c215SJeff Kirsher 754aa43c215SJeff Kirsher } else if (adapter->ahw->port_type == QLCNIC_GBE) { 755aa43c215SJeff Kirsher adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 756aa43c215SJeff Kirsher adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 757aa43c215SJeff Kirsher adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 758aa43c215SJeff Kirsher adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; 759aa43c215SJeff Kirsher } 760aa43c215SJeff Kirsher 761099f7aa7SSony Chacko adapter->ahw->msix_supported = !!qlcnic_use_msi_x; 762aa43c215SJeff Kirsher 763aa43c215SJeff Kirsher adapter->num_txd = MAX_CMD_DESCRIPTORS; 764aa43c215SJeff Kirsher 765aa43c215SJeff Kirsher adapter->max_rds_rings = MAX_RDS_RINGS; 766aa43c215SJeff Kirsher } 767aa43c215SJeff Kirsher 768aa43c215SJeff Kirsher static int 769aa43c215SJeff Kirsher qlcnic_initialize_nic(struct qlcnic_adapter *adapter) 770aa43c215SJeff Kirsher { 771aa43c215SJeff Kirsher int err; 772aa43c215SJeff Kirsher struct qlcnic_info nic_info; 773aa43c215SJeff Kirsher 774bff57d8eSSony Chacko memset(&nic_info, 0, sizeof(struct qlcnic_info)); 775aa43c215SJeff Kirsher err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); 776aa43c215SJeff Kirsher if (err) 777aa43c215SJeff Kirsher return err; 778aa43c215SJeff Kirsher 77979788450SSony Chacko adapter->ahw->physical_port = (u8)nic_info.phys_port; 78079788450SSony Chacko adapter->ahw->switch_mode = nic_info.switch_mode; 78179788450SSony Chacko adapter->ahw->max_tx_ques = nic_info.max_tx_ques; 78279788450SSony Chacko adapter->ahw->max_rx_ques = nic_info.max_rx_ques; 78379788450SSony Chacko adapter->ahw->capabilities = nic_info.capabilities; 78479788450SSony Chacko adapter->ahw->max_mac_filters = nic_info.max_mac_filters; 78579788450SSony Chacko adapter->ahw->max_mtu = nic_info.max_mtu; 786aa43c215SJeff Kirsher 78713159183SSony Chacko /* Disable NPAR for 83XX */ 78813159183SSony Chacko if (qlcnic_83xx_check(adapter)) 78913159183SSony Chacko return err; 79013159183SSony Chacko 79179788450SSony Chacko if (adapter->ahw->capabilities & BIT_6) 792aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ESWITCH_ENABLED; 793aa43c215SJeff Kirsher else 794aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; 795aa43c215SJeff Kirsher 796aa43c215SJeff Kirsher return err; 797aa43c215SJeff Kirsher } 798aa43c215SJeff Kirsher 799ec079a07SSony Chacko void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, 800aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 801aa43c215SJeff Kirsher { 802aa43c215SJeff Kirsher if (esw_cfg->discard_tagged) 803aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_TAGGING_ENABLED; 804aa43c215SJeff Kirsher else 805aa43c215SJeff Kirsher adapter->flags |= QLCNIC_TAGGING_ENABLED; 806aa43c215SJeff Kirsher 807aa43c215SJeff Kirsher if (esw_cfg->vlan_id) 808aa43c215SJeff Kirsher adapter->pvid = esw_cfg->vlan_id; 809aa43c215SJeff Kirsher else 810aa43c215SJeff Kirsher adapter->pvid = 0; 811aa43c215SJeff Kirsher } 812aa43c215SJeff Kirsher 8138e586137SJiri Pirko static int 814aa43c215SJeff Kirsher qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid) 815aa43c215SJeff Kirsher { 816aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 817aa43c215SJeff Kirsher set_bit(vid, adapter->vlans); 8188e586137SJiri Pirko return 0; 819aa43c215SJeff Kirsher } 820aa43c215SJeff Kirsher 8218e586137SJiri Pirko static int 822aa43c215SJeff Kirsher qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) 823aa43c215SJeff Kirsher { 824aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 825aa43c215SJeff Kirsher 826aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); 827aa43c215SJeff Kirsher clear_bit(vid, adapter->vlans); 8288e586137SJiri Pirko return 0; 829aa43c215SJeff Kirsher } 830aa43c215SJeff Kirsher 831ec079a07SSony Chacko void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, 832aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 833aa43c215SJeff Kirsher { 834aa43c215SJeff Kirsher adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | 835aa43c215SJeff Kirsher QLCNIC_PROMISC_DISABLED); 836aa43c215SJeff Kirsher 837aa43c215SJeff Kirsher if (esw_cfg->mac_anti_spoof) 838aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MACSPOOF; 839aa43c215SJeff Kirsher 840aa43c215SJeff Kirsher if (!esw_cfg->mac_override) 841aa43c215SJeff Kirsher adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; 842aa43c215SJeff Kirsher 843aa43c215SJeff Kirsher if (!esw_cfg->promisc_mode) 844aa43c215SJeff Kirsher adapter->flags |= QLCNIC_PROMISC_DISABLED; 845aa43c215SJeff Kirsher 846aa43c215SJeff Kirsher qlcnic_set_netdev_features(adapter, esw_cfg); 847aa43c215SJeff Kirsher } 848aa43c215SJeff Kirsher 849d71170fbSSony Chacko int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) 850aa43c215SJeff Kirsher { 851aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 852aa43c215SJeff Kirsher 853aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 854aa43c215SJeff Kirsher return 0; 855aa43c215SJeff Kirsher 856aa43c215SJeff Kirsher esw_cfg.pci_func = adapter->ahw->pci_func; 857aa43c215SJeff Kirsher if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 858aa43c215SJeff Kirsher return -EIO; 859aa43c215SJeff Kirsher qlcnic_set_vlan_config(adapter, &esw_cfg); 860aa43c215SJeff Kirsher qlcnic_set_eswitch_port_features(adapter, &esw_cfg); 861aa43c215SJeff Kirsher 862aa43c215SJeff Kirsher return 0; 863aa43c215SJeff Kirsher } 864aa43c215SJeff Kirsher 865aa43c215SJeff Kirsher static void 866aa43c215SJeff Kirsher qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, 867aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg *esw_cfg) 868aa43c215SJeff Kirsher { 869aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 87013159183SSony Chacko unsigned long features, vlan_features; 871aa43c215SJeff Kirsher 87213159183SSony Chacko if (qlcnic_83xx_check(adapter)) 87313159183SSony Chacko return; 87413159183SSony Chacko 8757e38d04bSSony Chacko features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 876aa43c215SJeff Kirsher NETIF_F_IPV6_CSUM | NETIF_F_GRO); 877aa43c215SJeff Kirsher vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | 87813159183SSony Chacko NETIF_F_IPV6_CSUM); 879aa43c215SJeff Kirsher 88013159183SSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) { 881aa43c215SJeff Kirsher features |= (NETIF_F_TSO | NETIF_F_TSO6); 882aa43c215SJeff Kirsher vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 883aa43c215SJeff Kirsher } 884aa43c215SJeff Kirsher 885aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 886aa43c215SJeff Kirsher features |= NETIF_F_LRO; 887aa43c215SJeff Kirsher 888aa43c215SJeff Kirsher if (esw_cfg->offload_flags & BIT_0) { 889aa43c215SJeff Kirsher netdev->features |= features; 89013159183SSony Chacko adapter->rx_csum = 1; 8917e38d04bSSony Chacko if (!(esw_cfg->offload_flags & BIT_1)) { 892aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO; 8937e38d04bSSony Chacko features &= ~NETIF_F_TSO; 8947e38d04bSSony Chacko } 8957e38d04bSSony Chacko if (!(esw_cfg->offload_flags & BIT_2)) { 896aa43c215SJeff Kirsher netdev->features &= ~NETIF_F_TSO6; 8977e38d04bSSony Chacko features &= ~NETIF_F_TSO6; 8987e38d04bSSony Chacko } 899aa43c215SJeff Kirsher } else { 900aa43c215SJeff Kirsher netdev->features &= ~features; 9017e38d04bSSony Chacko features &= ~features; 90213159183SSony Chacko adapter->rx_csum = 0; 903aa43c215SJeff Kirsher } 904aa43c215SJeff Kirsher 905aa43c215SJeff Kirsher netdev->vlan_features = (features & vlan_features); 906aa43c215SJeff Kirsher } 907aa43c215SJeff Kirsher 908aa43c215SJeff Kirsher static int 909aa43c215SJeff Kirsher qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) 910aa43c215SJeff Kirsher { 911aa43c215SJeff Kirsher u32 op_mode, priv_level; 912aa43c215SJeff Kirsher int err = 0; 913aa43c215SJeff Kirsher 914aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 915aa43c215SJeff Kirsher if (err) 916aa43c215SJeff Kirsher return err; 917aa43c215SJeff Kirsher 918aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 919aa43c215SJeff Kirsher return 0; 920aa43c215SJeff Kirsher 92113159183SSony Chacko op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE); 922aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 923aa43c215SJeff Kirsher 924aa43c215SJeff Kirsher if (op_mode == QLC_DEV_DRV_DEFAULT) 925aa43c215SJeff Kirsher priv_level = QLCNIC_MGMT_FUNC; 926aa43c215SJeff Kirsher else 927aa43c215SJeff Kirsher priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); 928aa43c215SJeff Kirsher 929aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 930aa43c215SJeff Kirsher if (priv_level == QLCNIC_MGMT_FUNC) { 93179788450SSony Chacko adapter->ahw->op_mode = QLCNIC_MGMT_FUNC; 932aa43c215SJeff Kirsher err = qlcnic_init_pci_info(adapter); 933aa43c215SJeff Kirsher if (err) 934aa43c215SJeff Kirsher return err; 935aa43c215SJeff Kirsher /* Set privilege level for other functions */ 936aa43c215SJeff Kirsher qlcnic_set_function_modes(adapter); 937aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 938aa43c215SJeff Kirsher "HAL Version: %d, Management function\n", 93979788450SSony Chacko adapter->ahw->fw_hal_version); 940aa43c215SJeff Kirsher } else if (priv_level == QLCNIC_PRIV_FUNC) { 94179788450SSony Chacko adapter->ahw->op_mode = QLCNIC_PRIV_FUNC; 942aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 943aa43c215SJeff Kirsher "HAL Version: %d, Privileged function\n", 94479788450SSony Chacko adapter->ahw->fw_hal_version); 945aa43c215SJeff Kirsher } 946aa43c215SJeff Kirsher } 947aa43c215SJeff Kirsher 948aa43c215SJeff Kirsher adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; 949aa43c215SJeff Kirsher 950aa43c215SJeff Kirsher return err; 951aa43c215SJeff Kirsher } 952aa43c215SJeff Kirsher 953d71170fbSSony Chacko int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) 954aa43c215SJeff Kirsher { 955aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 956aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 957aa43c215SJeff Kirsher u8 i; 958aa43c215SJeff Kirsher 959aa43c215SJeff Kirsher if (adapter->need_fw_reset) 960aa43c215SJeff Kirsher return 0; 961aa43c215SJeff Kirsher 962bff57d8eSSony Chacko for (i = 0; i < adapter->ahw->act_pci_func; i++) { 963aa43c215SJeff Kirsher memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); 964bff57d8eSSony Chacko esw_cfg.pci_func = adapter->npars[i].pci_func; 965aa43c215SJeff Kirsher esw_cfg.mac_override = BIT_0; 966aa43c215SJeff Kirsher esw_cfg.promisc_mode = BIT_0; 967bff57d8eSSony Chacko if (qlcnic_82xx_check(adapter)) { 968bff57d8eSSony Chacko esw_cfg.offload_flags = BIT_0; 969bff57d8eSSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) 970aa43c215SJeff Kirsher esw_cfg.offload_flags |= (BIT_1 | BIT_2); 971bff57d8eSSony Chacko } 972aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 973aa43c215SJeff Kirsher return -EIO; 974aa43c215SJeff Kirsher npar = &adapter->npars[i]; 975aa43c215SJeff Kirsher npar->pvid = esw_cfg.vlan_id; 976aa43c215SJeff Kirsher npar->mac_override = esw_cfg.mac_override; 977aa43c215SJeff Kirsher npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; 978aa43c215SJeff Kirsher npar->discard_tagged = esw_cfg.discard_tagged; 979aa43c215SJeff Kirsher npar->promisc_mode = esw_cfg.promisc_mode; 980aa43c215SJeff Kirsher npar->offload_flags = esw_cfg.offload_flags; 981aa43c215SJeff Kirsher } 982aa43c215SJeff Kirsher 983aa43c215SJeff Kirsher return 0; 984aa43c215SJeff Kirsher } 985aa43c215SJeff Kirsher 98613159183SSony Chacko 987aa43c215SJeff Kirsher static int 988aa43c215SJeff Kirsher qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, 989aa43c215SJeff Kirsher struct qlcnic_npar_info *npar, int pci_func) 990aa43c215SJeff Kirsher { 991aa43c215SJeff Kirsher struct qlcnic_esw_func_cfg esw_cfg; 992aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; 993aa43c215SJeff Kirsher esw_cfg.pci_func = pci_func; 994aa43c215SJeff Kirsher esw_cfg.vlan_id = npar->pvid; 995aa43c215SJeff Kirsher esw_cfg.mac_override = npar->mac_override; 996aa43c215SJeff Kirsher esw_cfg.discard_tagged = npar->discard_tagged; 997aa43c215SJeff Kirsher esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; 998aa43c215SJeff Kirsher esw_cfg.offload_flags = npar->offload_flags; 999aa43c215SJeff Kirsher esw_cfg.promisc_mode = npar->promisc_mode; 1000aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1001aa43c215SJeff Kirsher return -EIO; 1002aa43c215SJeff Kirsher 1003aa43c215SJeff Kirsher esw_cfg.op_mode = QLCNIC_ADD_VLAN; 1004aa43c215SJeff Kirsher if (qlcnic_config_switch_port(adapter, &esw_cfg)) 1005aa43c215SJeff Kirsher return -EIO; 1006aa43c215SJeff Kirsher 1007aa43c215SJeff Kirsher return 0; 1008aa43c215SJeff Kirsher } 1009aa43c215SJeff Kirsher 1010d71170fbSSony Chacko int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 1011aa43c215SJeff Kirsher { 1012aa43c215SJeff Kirsher int i, err; 1013aa43c215SJeff Kirsher struct qlcnic_npar_info *npar; 1014aa43c215SJeff Kirsher struct qlcnic_info nic_info; 1015bff57d8eSSony Chacko u8 pci_func; 1016aa43c215SJeff Kirsher 1017bff57d8eSSony Chacko if (qlcnic_82xx_check(adapter)) 1018aa43c215SJeff Kirsher if (!adapter->need_fw_reset) 1019aa43c215SJeff Kirsher return 0; 1020aa43c215SJeff Kirsher 1021aa43c215SJeff Kirsher /* Set the NPAR config data after FW reset */ 1022bff57d8eSSony Chacko for (i = 0; i < adapter->ahw->act_pci_func; i++) { 1023aa43c215SJeff Kirsher npar = &adapter->npars[i]; 1024bff57d8eSSony Chacko pci_func = npar->pci_func; 1025bff57d8eSSony Chacko memset(&nic_info, 0, sizeof(struct qlcnic_info)); 102613159183SSony Chacko err = qlcnic_get_nic_info(adapter, &nic_info, pci_func); 1027aa43c215SJeff Kirsher if (err) 1028aa43c215SJeff Kirsher return err; 1029aa43c215SJeff Kirsher nic_info.min_tx_bw = npar->min_bw; 1030aa43c215SJeff Kirsher nic_info.max_tx_bw = npar->max_bw; 1031aa43c215SJeff Kirsher err = qlcnic_set_nic_info(adapter, &nic_info); 1032aa43c215SJeff Kirsher if (err) 1033aa43c215SJeff Kirsher return err; 1034aa43c215SJeff Kirsher 1035aa43c215SJeff Kirsher if (npar->enable_pm) { 1036aa43c215SJeff Kirsher err = qlcnic_config_port_mirroring(adapter, 1037bff57d8eSSony Chacko npar->dest_npar, 1, 1038bff57d8eSSony Chacko pci_func); 1039aa43c215SJeff Kirsher if (err) 1040aa43c215SJeff Kirsher return err; 1041aa43c215SJeff Kirsher } 1042bff57d8eSSony Chacko err = qlcnic_reset_eswitch_config(adapter, npar, pci_func); 1043aa43c215SJeff Kirsher if (err) 1044aa43c215SJeff Kirsher return err; 1045aa43c215SJeff Kirsher } 1046aa43c215SJeff Kirsher return 0; 1047aa43c215SJeff Kirsher } 1048aa43c215SJeff Kirsher 1049aa43c215SJeff Kirsher static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) 1050aa43c215SJeff Kirsher { 1051aa43c215SJeff Kirsher u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; 1052aa43c215SJeff Kirsher u32 npar_state; 1053aa43c215SJeff Kirsher 105479788450SSony Chacko if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) 1055aa43c215SJeff Kirsher return 0; 1056aa43c215SJeff Kirsher 1057a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 1058a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 1059aa43c215SJeff Kirsher while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { 1060aa43c215SJeff Kirsher msleep(1000); 1061a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 1062a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 1063aa43c215SJeff Kirsher } 1064aa43c215SJeff Kirsher if (!npar_opt_timeo) { 1065aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1066aa43c215SJeff Kirsher "Waiting for NPAR state to opertional timeout\n"); 1067aa43c215SJeff Kirsher return -EIO; 1068aa43c215SJeff Kirsher } 1069aa43c215SJeff Kirsher return 0; 1070aa43c215SJeff Kirsher } 1071aa43c215SJeff Kirsher 1072aa43c215SJeff Kirsher static int 1073aa43c215SJeff Kirsher qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) 1074aa43c215SJeff Kirsher { 1075aa43c215SJeff Kirsher int err; 1076aa43c215SJeff Kirsher 1077aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 107879788450SSony Chacko adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) 1079aa43c215SJeff Kirsher return 0; 1080aa43c215SJeff Kirsher 1081aa43c215SJeff Kirsher err = qlcnic_set_default_offload_settings(adapter); 1082aa43c215SJeff Kirsher if (err) 1083aa43c215SJeff Kirsher return err; 1084aa43c215SJeff Kirsher 1085aa43c215SJeff Kirsher err = qlcnic_reset_npar_config(adapter); 1086aa43c215SJeff Kirsher if (err) 1087aa43c215SJeff Kirsher return err; 1088aa43c215SJeff Kirsher 1089aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(adapter); 1090aa43c215SJeff Kirsher 109113159183SSony Chacko if (qlcnic_83xx_check(adapter)) 109213159183SSony Chacko qlcnic_83xx_register_nic_idc_func(adapter, 1); 1093aa43c215SJeff Kirsher return err; 1094aa43c215SJeff Kirsher } 1095aa43c215SJeff Kirsher 10967e2cf4feSSony Chacko int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter) 1097aa43c215SJeff Kirsher { 1098aa43c215SJeff Kirsher int err; 1099aa43c215SJeff Kirsher 1100aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 1101aa43c215SJeff Kirsher if (err < 0) 1102aa43c215SJeff Kirsher return err; 1103aa43c215SJeff Kirsher else if (!err) 1104aa43c215SJeff Kirsher goto check_fw_status; 1105aa43c215SJeff Kirsher 1106099f7aa7SSony Chacko if (qlcnic_load_fw_file) 1107aa43c215SJeff Kirsher qlcnic_request_firmware(adapter); 1108aa43c215SJeff Kirsher else { 1109aa43c215SJeff Kirsher err = qlcnic_check_flash_fw_ver(adapter); 1110aa43c215SJeff Kirsher if (err) 1111aa43c215SJeff Kirsher goto err_out; 1112aa43c215SJeff Kirsher 111379788450SSony Chacko adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE; 1114aa43c215SJeff Kirsher } 1115aa43c215SJeff Kirsher 1116aa43c215SJeff Kirsher err = qlcnic_need_fw_reset(adapter); 1117aa43c215SJeff Kirsher if (err == 0) 1118aa43c215SJeff Kirsher goto check_fw_status; 1119aa43c215SJeff Kirsher 1120aa43c215SJeff Kirsher err = qlcnic_pinit_from_rom(adapter); 1121aa43c215SJeff Kirsher if (err) 1122aa43c215SJeff Kirsher goto err_out; 1123aa43c215SJeff Kirsher 1124aa43c215SJeff Kirsher err = qlcnic_load_firmware(adapter); 1125aa43c215SJeff Kirsher if (err) 1126aa43c215SJeff Kirsher goto err_out; 1127aa43c215SJeff Kirsher 1128aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1129aa43c215SJeff Kirsher QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); 1130aa43c215SJeff Kirsher 1131aa43c215SJeff Kirsher check_fw_status: 1132aa43c215SJeff Kirsher err = qlcnic_check_fw_status(adapter); 1133aa43c215SJeff Kirsher if (err) 1134aa43c215SJeff Kirsher goto err_out; 1135aa43c215SJeff Kirsher 1136a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1137aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 1); 1138aa43c215SJeff Kirsher err = qlcnic_check_eswitch_mode(adapter); 1139aa43c215SJeff Kirsher if (err) { 1140aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1141aa43c215SJeff Kirsher "Memory allocation failed for eswitch\n"); 1142aa43c215SJeff Kirsher goto err_out; 1143aa43c215SJeff Kirsher } 1144aa43c215SJeff Kirsher err = qlcnic_set_mgmt_operations(adapter); 1145aa43c215SJeff Kirsher if (err) 1146aa43c215SJeff Kirsher goto err_out; 1147aa43c215SJeff Kirsher 1148aa43c215SJeff Kirsher qlcnic_check_options(adapter); 1149aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 1150aa43c215SJeff Kirsher 1151aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1152aa43c215SJeff Kirsher return 0; 1153aa43c215SJeff Kirsher 1154aa43c215SJeff Kirsher err_out: 1155a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1156aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1157aa43c215SJeff Kirsher 1158aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1159aa43c215SJeff Kirsher return err; 1160aa43c215SJeff Kirsher } 1161aa43c215SJeff Kirsher 1162aa43c215SJeff Kirsher static int 1163aa43c215SJeff Kirsher qlcnic_request_irq(struct qlcnic_adapter *adapter) 1164aa43c215SJeff Kirsher { 1165aa43c215SJeff Kirsher irq_handler_t handler; 1166aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 116713159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 1168aa43c215SJeff Kirsher int err, ring; 1169aa43c215SJeff Kirsher 1170aa43c215SJeff Kirsher unsigned long flags = 0; 1171aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1172aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1173aa43c215SJeff Kirsher 117479788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 117513159183SSony Chacko if (qlcnic_82xx_check(adapter)) 1176aa43c215SJeff Kirsher handler = qlcnic_tmp_intr; 1177aa43c215SJeff Kirsher if (!QLCNIC_IS_MSI_FAMILY(adapter)) 1178aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1179aa43c215SJeff Kirsher 1180aa43c215SJeff Kirsher } else { 1181aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 1182aa43c215SJeff Kirsher handler = qlcnic_msix_intr; 1183aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) 1184aa43c215SJeff Kirsher handler = qlcnic_msi_intr; 1185aa43c215SJeff Kirsher else { 1186aa43c215SJeff Kirsher flags |= IRQF_SHARED; 1187aa43c215SJeff Kirsher handler = qlcnic_intr; 1188aa43c215SJeff Kirsher } 1189aa43c215SJeff Kirsher } 1190aa43c215SJeff Kirsher adapter->irq = netdev->irq; 1191aa43c215SJeff Kirsher 119213159183SSony Chacko if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1193aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1194aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 119513159183SSony Chacko snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ, 119613159183SSony Chacko "%s[%d]", netdev->name, ring); 119713159183SSony Chacko err = request_irq(sds_ring->irq, handler, flags, 119813159183SSony Chacko sds_ring->name, sds_ring); 1199aa43c215SJeff Kirsher if (err) 1200aa43c215SJeff Kirsher return err; 1201aa43c215SJeff Kirsher } 120213159183SSony Chacko if (qlcnic_83xx_check(adapter) && 120313159183SSony Chacko (adapter->flags & QLCNIC_MSIX_ENABLED)) { 120413159183SSony Chacko handler = qlcnic_msix_tx_intr; 120513159183SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; 120613159183SSony Chacko ring++) { 120713159183SSony Chacko tx_ring = &adapter->tx_ring[ring]; 120813159183SSony Chacko snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ, 120913159183SSony Chacko "%s[%d]", netdev->name, 121013159183SSony Chacko adapter->max_sds_rings + ring); 121113159183SSony Chacko err = request_irq(tx_ring->irq, handler, flags, 121213159183SSony Chacko tx_ring->name, tx_ring); 121313159183SSony Chacko if (err) 121413159183SSony Chacko return err; 121513159183SSony Chacko } 121613159183SSony Chacko } 121713159183SSony Chacko } 1218aa43c215SJeff Kirsher return 0; 1219aa43c215SJeff Kirsher } 1220aa43c215SJeff Kirsher 1221aa43c215SJeff Kirsher static void 1222aa43c215SJeff Kirsher qlcnic_free_irq(struct qlcnic_adapter *adapter) 1223aa43c215SJeff Kirsher { 1224aa43c215SJeff Kirsher int ring; 1225aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 122613159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 1227aa43c215SJeff Kirsher 1228aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 1229aa43c215SJeff Kirsher 123013159183SSony Chacko if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) { 1231aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1232aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 1233aa43c215SJeff Kirsher free_irq(sds_ring->irq, sds_ring); 1234aa43c215SJeff Kirsher } 123513159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 123613159183SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; 123713159183SSony Chacko ring++) { 123813159183SSony Chacko tx_ring = &adapter->tx_ring[ring]; 123913159183SSony Chacko if (tx_ring->irq) 124013159183SSony Chacko free_irq(tx_ring->irq, tx_ring); 124113159183SSony Chacko } 124213159183SSony Chacko } 124313159183SSony Chacko } 1244aa43c215SJeff Kirsher } 1245aa43c215SJeff Kirsher 1246319ecf12SSony Chacko int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1247aa43c215SJeff Kirsher { 1248aa43c215SJeff Kirsher int ring; 1249cae82d49SRajesh Borundia u32 capab2; 1250cae82d49SRajesh Borundia 1251aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1252aa43c215SJeff Kirsher 1253aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1254aa43c215SJeff Kirsher return -EIO; 1255aa43c215SJeff Kirsher 1256aa43c215SJeff Kirsher if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1257aa43c215SJeff Kirsher return 0; 1258aa43c215SJeff Kirsher if (qlcnic_set_eswitch_port_config(adapter)) 1259aa43c215SJeff Kirsher return -EIO; 1260aa43c215SJeff Kirsher 126179788450SSony Chacko if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 1262cae82d49SRajesh Borundia capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); 1263cae82d49SRajesh Borundia if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG) 1264cae82d49SRajesh Borundia adapter->flags |= QLCNIC_FW_LRO_MSS_CAP; 1265cae82d49SRajesh Borundia } 1266cae82d49SRajesh Borundia 1267aa43c215SJeff Kirsher if (qlcnic_fw_create_ctx(adapter)) 1268aa43c215SJeff Kirsher return -EIO; 1269aa43c215SJeff Kirsher 1270aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1271aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 12724be41e92SSony Chacko qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1273aa43c215SJeff Kirsher } 1274aa43c215SJeff Kirsher 1275aa43c215SJeff Kirsher qlcnic_set_multi(netdev); 1276aa43c215SJeff Kirsher qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1277aa43c215SJeff Kirsher 1278aa43c215SJeff Kirsher adapter->ahw->linkup = 0; 1279aa43c215SJeff Kirsher 1280aa43c215SJeff Kirsher if (adapter->max_sds_rings > 1) 1281aa43c215SJeff Kirsher qlcnic_config_rss(adapter, 1); 1282aa43c215SJeff Kirsher 1283aa43c215SJeff Kirsher qlcnic_config_intr_coalesce(adapter); 1284aa43c215SJeff Kirsher 1285aa43c215SJeff Kirsher if (netdev->features & NETIF_F_LRO) 1286aa43c215SJeff Kirsher qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1287aa43c215SJeff Kirsher 1288aa43c215SJeff Kirsher qlcnic_napi_enable(adapter); 1289aa43c215SJeff Kirsher 1290aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1291aa43c215SJeff Kirsher 129279788450SSony Chacko adapter->ahw->reset_context = 0; 1293aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1294aa43c215SJeff Kirsher return 0; 1295aa43c215SJeff Kirsher } 1296aa43c215SJeff Kirsher 1297629263acSSony Chacko int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) 1298aa43c215SJeff Kirsher { 1299aa43c215SJeff Kirsher int err = 0; 1300aa43c215SJeff Kirsher 1301aa43c215SJeff Kirsher rtnl_lock(); 1302aa43c215SJeff Kirsher if (netif_running(netdev)) 1303aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 1304aa43c215SJeff Kirsher rtnl_unlock(); 1305aa43c215SJeff Kirsher 1306aa43c215SJeff Kirsher return err; 1307aa43c215SJeff Kirsher } 1308aa43c215SJeff Kirsher 1309319ecf12SSony Chacko void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1310aa43c215SJeff Kirsher { 1311aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1312aa43c215SJeff Kirsher return; 1313aa43c215SJeff Kirsher 1314aa43c215SJeff Kirsher if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) 1315aa43c215SJeff Kirsher return; 1316aa43c215SJeff Kirsher 1317aa43c215SJeff Kirsher smp_mb(); 1318aa43c215SJeff Kirsher spin_lock(&adapter->tx_clean_lock); 1319aa43c215SJeff Kirsher netif_carrier_off(netdev); 1320aa43c215SJeff Kirsher netif_tx_disable(netdev); 1321aa43c215SJeff Kirsher 1322aa43c215SJeff Kirsher qlcnic_free_mac_list(adapter); 1323aa43c215SJeff Kirsher 1324aa43c215SJeff Kirsher if (adapter->fhash.fnum) 1325aa43c215SJeff Kirsher qlcnic_delete_lb_filters(adapter); 1326aa43c215SJeff Kirsher 1327aa43c215SJeff Kirsher qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1328aa43c215SJeff Kirsher 1329aa43c215SJeff Kirsher qlcnic_napi_disable(adapter); 1330aa43c215SJeff Kirsher 1331aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1332cae82d49SRajesh Borundia adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP; 1333aa43c215SJeff Kirsher 1334aa43c215SJeff Kirsher qlcnic_reset_rx_buffers_list(adapter); 1335aa43c215SJeff Kirsher qlcnic_release_tx_buffers(adapter); 1336aa43c215SJeff Kirsher spin_unlock(&adapter->tx_clean_lock); 1337aa43c215SJeff Kirsher } 1338aa43c215SJeff Kirsher 1339aa43c215SJeff Kirsher /* Usage: During suspend and firmware recovery module */ 1340aa43c215SJeff Kirsher 1341629263acSSony Chacko void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) 1342aa43c215SJeff Kirsher { 1343aa43c215SJeff Kirsher rtnl_lock(); 1344aa43c215SJeff Kirsher if (netif_running(netdev)) 1345aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1346aa43c215SJeff Kirsher rtnl_unlock(); 1347aa43c215SJeff Kirsher 1348aa43c215SJeff Kirsher } 1349aa43c215SJeff Kirsher 1350319ecf12SSony Chacko int 1351aa43c215SJeff Kirsher qlcnic_attach(struct qlcnic_adapter *adapter) 1352aa43c215SJeff Kirsher { 1353aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1354aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1355aa43c215SJeff Kirsher int err; 1356aa43c215SJeff Kirsher 1357aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) 1358aa43c215SJeff Kirsher return 0; 1359aa43c215SJeff Kirsher 1360aa43c215SJeff Kirsher err = qlcnic_napi_add(adapter, netdev); 1361aa43c215SJeff Kirsher if (err) 1362aa43c215SJeff Kirsher return err; 1363aa43c215SJeff Kirsher 1364aa43c215SJeff Kirsher err = qlcnic_alloc_sw_resources(adapter); 1365aa43c215SJeff Kirsher if (err) { 1366aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting sw resources\n"); 1367aa43c215SJeff Kirsher goto err_out_napi_del; 1368aa43c215SJeff Kirsher } 1369aa43c215SJeff Kirsher 1370aa43c215SJeff Kirsher err = qlcnic_alloc_hw_resources(adapter); 1371aa43c215SJeff Kirsher if (err) { 1372aa43c215SJeff Kirsher dev_err(&pdev->dev, "Error in setting hw resources\n"); 1373aa43c215SJeff Kirsher goto err_out_free_sw; 1374aa43c215SJeff Kirsher } 1375aa43c215SJeff Kirsher 1376aa43c215SJeff Kirsher err = qlcnic_request_irq(adapter); 1377aa43c215SJeff Kirsher if (err) { 1378aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to setup interrupt\n"); 1379aa43c215SJeff Kirsher goto err_out_free_hw; 1380aa43c215SJeff Kirsher } 1381aa43c215SJeff Kirsher 1382aa43c215SJeff Kirsher qlcnic_create_sysfs_entries(adapter); 1383aa43c215SJeff Kirsher 1384aa43c215SJeff Kirsher adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; 1385aa43c215SJeff Kirsher return 0; 1386aa43c215SJeff Kirsher 1387aa43c215SJeff Kirsher err_out_free_hw: 1388aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1389aa43c215SJeff Kirsher err_out_free_sw: 1390aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1391aa43c215SJeff Kirsher err_out_napi_del: 1392aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1393aa43c215SJeff Kirsher return err; 1394aa43c215SJeff Kirsher } 1395aa43c215SJeff Kirsher 1396319ecf12SSony Chacko void qlcnic_detach(struct qlcnic_adapter *adapter) 1397aa43c215SJeff Kirsher { 1398aa43c215SJeff Kirsher if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 1399aa43c215SJeff Kirsher return; 1400aa43c215SJeff Kirsher 1401aa43c215SJeff Kirsher qlcnic_remove_sysfs_entries(adapter); 1402aa43c215SJeff Kirsher 1403aa43c215SJeff Kirsher qlcnic_free_hw_resources(adapter); 1404aa43c215SJeff Kirsher qlcnic_release_rx_buffers(adapter); 1405aa43c215SJeff Kirsher qlcnic_free_irq(adapter); 1406aa43c215SJeff Kirsher qlcnic_napi_del(adapter); 1407aa43c215SJeff Kirsher qlcnic_free_sw_resources(adapter); 1408aa43c215SJeff Kirsher 1409aa43c215SJeff Kirsher adapter->is_up = 0; 1410aa43c215SJeff Kirsher } 1411aa43c215SJeff Kirsher 1412aa43c215SJeff Kirsher void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) 1413aa43c215SJeff Kirsher { 1414aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1415aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1416aa43c215SJeff Kirsher int ring; 1417aa43c215SJeff Kirsher 1418aa43c215SJeff Kirsher clear_bit(__QLCNIC_DEV_UP, &adapter->state); 141979788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1420aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1421aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 142213159183SSony Chacko if (qlcnic_83xx_check(adapter)) 142313159183SSony Chacko writel(1, sds_ring->crb_intr_mask); 142413159183SSony Chacko else 1425aa43c215SJeff Kirsher qlcnic_disable_int(sds_ring); 1426aa43c215SJeff Kirsher } 1427aa43c215SJeff Kirsher } 1428aa43c215SJeff Kirsher 1429aa43c215SJeff Kirsher qlcnic_fw_destroy_ctx(adapter); 1430aa43c215SJeff Kirsher 1431aa43c215SJeff Kirsher qlcnic_detach(adapter); 1432aa43c215SJeff Kirsher 143379788450SSony Chacko adapter->ahw->diag_test = 0; 1434aa43c215SJeff Kirsher adapter->max_sds_rings = max_sds_rings; 1435aa43c215SJeff Kirsher 1436aa43c215SJeff Kirsher if (qlcnic_attach(adapter)) 1437aa43c215SJeff Kirsher goto out; 1438aa43c215SJeff Kirsher 1439aa43c215SJeff Kirsher if (netif_running(netdev)) 1440aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 1441aa43c215SJeff Kirsher out: 1442aa43c215SJeff Kirsher netif_device_attach(netdev); 1443aa43c215SJeff Kirsher } 1444aa43c215SJeff Kirsher 1445aa43c215SJeff Kirsher static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) 1446aa43c215SJeff Kirsher { 1447aa43c215SJeff Kirsher int err = 0; 1448aa43c215SJeff Kirsher adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), 1449aa43c215SJeff Kirsher GFP_KERNEL); 1450aa43c215SJeff Kirsher if (!adapter->recv_ctx) { 1451aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1452aa43c215SJeff Kirsher "Failed to allocate recv ctx resources for adapter\n"); 1453aa43c215SJeff Kirsher err = -ENOMEM; 1454aa43c215SJeff Kirsher goto err_out; 1455aa43c215SJeff Kirsher } 1456aa43c215SJeff Kirsher /* Initialize interrupt coalesce parameters */ 1457aa43c215SJeff Kirsher adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; 1458aa43c215SJeff Kirsher adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; 1459aa43c215SJeff Kirsher adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; 14604be41e92SSony Chacko /* clear stats */ 14614be41e92SSony Chacko memset(&adapter->stats, 0, sizeof(adapter->stats)); 1462aa43c215SJeff Kirsher err_out: 1463aa43c215SJeff Kirsher return err; 1464aa43c215SJeff Kirsher } 1465aa43c215SJeff Kirsher 1466aa43c215SJeff Kirsher static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) 1467aa43c215SJeff Kirsher { 1468aa43c215SJeff Kirsher kfree(adapter->recv_ctx); 1469aa43c215SJeff Kirsher adapter->recv_ctx = NULL; 1470aa43c215SJeff Kirsher 1471aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.tmpl_hdr) { 1472aa43c215SJeff Kirsher vfree(adapter->ahw->fw_dump.tmpl_hdr); 1473aa43c215SJeff Kirsher adapter->ahw->fw_dump.tmpl_hdr = NULL; 1474aa43c215SJeff Kirsher } 14754be41e92SSony Chacko 147681d0aeb0SSony Chacko kfree(adapter->ahw->reset.buff); 14774be41e92SSony Chacko adapter->ahw->fw_dump.tmpl_hdr = NULL; 1478aa43c215SJeff Kirsher } 1479aa43c215SJeff Kirsher 1480aa43c215SJeff Kirsher int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1481aa43c215SJeff Kirsher { 1482aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 1483aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 1484aa43c215SJeff Kirsher struct qlcnic_host_rds_ring *rds_ring; 1485aa43c215SJeff Kirsher int ring; 1486aa43c215SJeff Kirsher int ret; 1487aa43c215SJeff Kirsher 1488aa43c215SJeff Kirsher netif_device_detach(netdev); 1489aa43c215SJeff Kirsher 1490aa43c215SJeff Kirsher if (netif_running(netdev)) 1491aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1492aa43c215SJeff Kirsher 1493aa43c215SJeff Kirsher qlcnic_detach(adapter); 1494aa43c215SJeff Kirsher 1495aa43c215SJeff Kirsher adapter->max_sds_rings = 1; 149679788450SSony Chacko adapter->ahw->diag_test = test; 14974be41e92SSony Chacko adapter->ahw->linkup = 0; 1498aa43c215SJeff Kirsher 1499aa43c215SJeff Kirsher ret = qlcnic_attach(adapter); 1500aa43c215SJeff Kirsher if (ret) { 1501aa43c215SJeff Kirsher netif_device_attach(netdev); 1502aa43c215SJeff Kirsher return ret; 1503aa43c215SJeff Kirsher } 1504aa43c215SJeff Kirsher 1505aa43c215SJeff Kirsher ret = qlcnic_fw_create_ctx(adapter); 1506aa43c215SJeff Kirsher if (ret) { 1507aa43c215SJeff Kirsher qlcnic_detach(adapter); 1508aa43c215SJeff Kirsher netif_device_attach(netdev); 1509aa43c215SJeff Kirsher return ret; 1510aa43c215SJeff Kirsher } 1511aa43c215SJeff Kirsher 1512aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1513aa43c215SJeff Kirsher rds_ring = &adapter->recv_ctx->rds_rings[ring]; 15144be41e92SSony Chacko qlcnic_post_rx_buffers(adapter, rds_ring, ring); 1515aa43c215SJeff Kirsher } 1516aa43c215SJeff Kirsher 151779788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) { 1518aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1519aa43c215SJeff Kirsher sds_ring = &adapter->recv_ctx->sds_rings[ring]; 15207e38d04bSSony Chacko if (qlcnic_82xx_check(adapter)) 1521aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 15227e38d04bSSony Chacko else 15237e38d04bSSony Chacko qlcnic_83xx_enable_intr(adapter, sds_ring); 1524aa43c215SJeff Kirsher } 1525aa43c215SJeff Kirsher } 1526aa43c215SJeff Kirsher 152779788450SSony Chacko if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) { 1528aa43c215SJeff Kirsher adapter->ahw->loopback_state = 0; 1529aa43c215SJeff Kirsher qlcnic_linkevent_request(adapter, 1); 1530aa43c215SJeff Kirsher } 1531aa43c215SJeff Kirsher 1532aa43c215SJeff Kirsher set_bit(__QLCNIC_DEV_UP, &adapter->state); 1533aa43c215SJeff Kirsher 1534aa43c215SJeff Kirsher return 0; 1535aa43c215SJeff Kirsher } 1536aa43c215SJeff Kirsher 1537aa43c215SJeff Kirsher /* Reset context in hardware only */ 1538aa43c215SJeff Kirsher static int 1539aa43c215SJeff Kirsher qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) 1540aa43c215SJeff Kirsher { 1541aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1542aa43c215SJeff Kirsher 1543aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1544aa43c215SJeff Kirsher return -EBUSY; 1545aa43c215SJeff Kirsher 1546aa43c215SJeff Kirsher netif_device_detach(netdev); 1547aa43c215SJeff Kirsher 1548aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1549aa43c215SJeff Kirsher 1550aa43c215SJeff Kirsher qlcnic_up(adapter, netdev); 1551aa43c215SJeff Kirsher 1552aa43c215SJeff Kirsher netif_device_attach(netdev); 1553aa43c215SJeff Kirsher 1554aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 155513159183SSony Chacko dev_err(&adapter->pdev->dev, "%s:\n", __func__); 1556aa43c215SJeff Kirsher return 0; 1557aa43c215SJeff Kirsher } 1558aa43c215SJeff Kirsher 1559aa43c215SJeff Kirsher int 1560aa43c215SJeff Kirsher qlcnic_reset_context(struct qlcnic_adapter *adapter) 1561aa43c215SJeff Kirsher { 1562aa43c215SJeff Kirsher int err = 0; 1563aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1564aa43c215SJeff Kirsher 1565aa43c215SJeff Kirsher if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) 1566aa43c215SJeff Kirsher return -EBUSY; 1567aa43c215SJeff Kirsher 1568aa43c215SJeff Kirsher if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { 1569aa43c215SJeff Kirsher 1570aa43c215SJeff Kirsher netif_device_detach(netdev); 1571aa43c215SJeff Kirsher 1572aa43c215SJeff Kirsher if (netif_running(netdev)) 1573aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 1574aa43c215SJeff Kirsher 1575aa43c215SJeff Kirsher qlcnic_detach(adapter); 1576aa43c215SJeff Kirsher 1577aa43c215SJeff Kirsher if (netif_running(netdev)) { 1578aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 15791d5c88e3SAnirban Chakraborty if (!err) { 1580aa43c215SJeff Kirsher __qlcnic_up(adapter, netdev); 15811d5c88e3SAnirban Chakraborty qlcnic_restore_indev_addr(netdev, NETDEV_UP); 15821d5c88e3SAnirban Chakraborty } 1583aa43c215SJeff Kirsher } 1584aa43c215SJeff Kirsher 1585aa43c215SJeff Kirsher netif_device_attach(netdev); 1586aa43c215SJeff Kirsher } 1587aa43c215SJeff Kirsher 1588aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1589aa43c215SJeff Kirsher return err; 1590aa43c215SJeff Kirsher } 1591aa43c215SJeff Kirsher 1592aa43c215SJeff Kirsher static int 15935ad6ff9dSSony Chacko qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev, 15945ad6ff9dSSony Chacko int pci_using_dac) 1595aa43c215SJeff Kirsher { 1596aa43c215SJeff Kirsher int err; 1597aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1598aa43c215SJeff Kirsher 159913159183SSony Chacko adapter->rx_csum = 1; 160079788450SSony Chacko adapter->ahw->mc_enabled = 0; 160113159183SSony Chacko adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT; 1602aa43c215SJeff Kirsher 1603aa43c215SJeff Kirsher netdev->netdev_ops = &qlcnic_netdev_ops; 160413159183SSony Chacko netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ; 1605aa43c215SJeff Kirsher 1606aa43c215SJeff Kirsher qlcnic_change_mtu(netdev, netdev->mtu); 1607aa43c215SJeff Kirsher 1608aa43c215SJeff Kirsher SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 1609aa43c215SJeff Kirsher 16107e38d04bSSony Chacko netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | 161113159183SSony Chacko NETIF_F_IPV6_CSUM | NETIF_F_GRO | 161213159183SSony Chacko NETIF_F_HW_VLAN_RX); 161313159183SSony Chacko netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | 161413159183SSony Chacko NETIF_F_IPV6_CSUM); 1615aa43c215SJeff Kirsher 161613159183SSony Chacko if (QLCNIC_IS_TSO_CAPABLE(adapter)) { 161713159183SSony Chacko netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6); 161813159183SSony Chacko netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); 161913159183SSony Chacko } 1620aa43c215SJeff Kirsher 162113159183SSony Chacko if (pci_using_dac) { 162213159183SSony Chacko netdev->features |= NETIF_F_HIGHDMA; 162313159183SSony Chacko netdev->vlan_features |= NETIF_F_HIGHDMA; 162413159183SSony Chacko } 1625aa43c215SJeff Kirsher 162613159183SSony Chacko if (qlcnic_vlan_tx_check(adapter)) 162713159183SSony Chacko netdev->features |= (NETIF_F_HW_VLAN_TX); 162813159183SSony Chacko 162979788450SSony Chacko if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 163013159183SSony Chacko netdev->features |= NETIF_F_LRO; 1631aa43c215SJeff Kirsher 16327e38d04bSSony Chacko netdev->hw_features = netdev->features; 1633aa43c215SJeff Kirsher netdev->irq = adapter->msix_entries[0].vector; 1634aa43c215SJeff Kirsher 1635aa43c215SJeff Kirsher err = register_netdev(netdev); 1636aa43c215SJeff Kirsher if (err) { 1637aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to register net device\n"); 1638aa43c215SJeff Kirsher return err; 1639aa43c215SJeff Kirsher } 1640aa43c215SJeff Kirsher 1641aa43c215SJeff Kirsher return 0; 1642aa43c215SJeff Kirsher } 1643aa43c215SJeff Kirsher 16445ad6ff9dSSony Chacko static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac) 1645aa43c215SJeff Kirsher { 1646aa43c215SJeff Kirsher if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && 1647aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) 1648aa43c215SJeff Kirsher *pci_using_dac = 1; 1649aa43c215SJeff Kirsher else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && 1650aa43c215SJeff Kirsher !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) 1651aa43c215SJeff Kirsher *pci_using_dac = 0; 1652aa43c215SJeff Kirsher else { 1653aa43c215SJeff Kirsher dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); 1654aa43c215SJeff Kirsher return -EIO; 1655aa43c215SJeff Kirsher } 1656aa43c215SJeff Kirsher 1657aa43c215SJeff Kirsher return 0; 1658aa43c215SJeff Kirsher } 1659aa43c215SJeff Kirsher 16604be41e92SSony Chacko void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter) 16614be41e92SSony Chacko { 16624be41e92SSony Chacko int ring; 16634be41e92SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 16644be41e92SSony Chacko 16654be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 16664be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 16674be41e92SSony Chacko if (tx_ring && tx_ring->cmd_buf_arr != NULL) { 16684be41e92SSony Chacko vfree(tx_ring->cmd_buf_arr); 16694be41e92SSony Chacko tx_ring->cmd_buf_arr = NULL; 16704be41e92SSony Chacko } 16714be41e92SSony Chacko } 16724be41e92SSony Chacko if (adapter->tx_ring != NULL) 16734be41e92SSony Chacko kfree(adapter->tx_ring); 16744be41e92SSony Chacko } 16754be41e92SSony Chacko 16764be41e92SSony Chacko int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter, 16774be41e92SSony Chacko struct net_device *netdev) 16784be41e92SSony Chacko { 16794be41e92SSony Chacko int ring, size, vector, index; 16804be41e92SSony Chacko struct qlcnic_host_tx_ring *tx_ring; 16814be41e92SSony Chacko struct qlcnic_cmd_buffer *cmd_buf_arr; 16824be41e92SSony Chacko 16834be41e92SSony Chacko size = adapter->max_drv_tx_rings * sizeof(struct qlcnic_host_tx_ring); 16844be41e92SSony Chacko tx_ring = kzalloc(size, GFP_KERNEL); 16854be41e92SSony Chacko if (tx_ring == NULL) { 16864be41e92SSony Chacko dev_err(&netdev->dev, "failed to allocate tx rings\n"); 16874be41e92SSony Chacko return -ENOMEM; 16884be41e92SSony Chacko } 16894be41e92SSony Chacko adapter->tx_ring = tx_ring; 16904be41e92SSony Chacko 16914be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 16924be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 16934be41e92SSony Chacko tx_ring->num_desc = adapter->num_txd; 16944be41e92SSony Chacko tx_ring->txq = netdev_get_tx_queue(netdev, ring); 16954be41e92SSony Chacko cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring)); 16964be41e92SSony Chacko if (cmd_buf_arr == NULL) { 16974be41e92SSony Chacko dev_err(&netdev->dev, 16984be41e92SSony Chacko "failed to allocate cmd buffer ring\n"); 16994be41e92SSony Chacko qlcnic_free_tx_rings(adapter); 17004be41e92SSony Chacko return -ENOMEM; 17014be41e92SSony Chacko } 17024be41e92SSony Chacko memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); 17034be41e92SSony Chacko tx_ring->cmd_buf_arr = cmd_buf_arr; 17044be41e92SSony Chacko } 17054be41e92SSony Chacko 17064be41e92SSony Chacko if (qlcnic_83xx_check(adapter)) { 17074be41e92SSony Chacko for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) { 17084be41e92SSony Chacko tx_ring = &adapter->tx_ring[ring]; 17094be41e92SSony Chacko tx_ring->adapter = adapter; 17104be41e92SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) { 17114be41e92SSony Chacko index = adapter->max_sds_rings + ring; 17124be41e92SSony Chacko vector = adapter->msix_entries[index].vector; 17134be41e92SSony Chacko tx_ring->irq = vector; 17144be41e92SSony Chacko } 17154be41e92SSony Chacko } 17164be41e92SSony Chacko } 17174be41e92SSony Chacko return 0; 17184be41e92SSony Chacko } 17194be41e92SSony Chacko 17206bb58bb0SBill Pemberton static int 1721aa43c215SJeff Kirsher qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1722aa43c215SJeff Kirsher { 1723aa43c215SJeff Kirsher struct net_device *netdev = NULL; 1724aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = NULL; 17257e2cf4feSSony Chacko struct qlcnic_hardware_context *ahw; 17265ad6ff9dSSony Chacko int err, pci_using_dac = -1; 1727c84e340aSSritej Velaga u32 capab2; 172822999798SSony Chacko char board_name[QLCNIC_MAX_BOARD_NAME_LEN]; 1729aa43c215SJeff Kirsher 1730aa43c215SJeff Kirsher err = pci_enable_device(pdev); 1731aa43c215SJeff Kirsher if (err) 1732aa43c215SJeff Kirsher return err; 1733aa43c215SJeff Kirsher 1734aa43c215SJeff Kirsher if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 1735aa43c215SJeff Kirsher err = -ENODEV; 1736aa43c215SJeff Kirsher goto err_out_disable_pdev; 1737aa43c215SJeff Kirsher } 1738aa43c215SJeff Kirsher 1739aa43c215SJeff Kirsher err = qlcnic_set_dma_mask(pdev, &pci_using_dac); 1740aa43c215SJeff Kirsher if (err) 1741aa43c215SJeff Kirsher goto err_out_disable_pdev; 1742aa43c215SJeff Kirsher 1743aa43c215SJeff Kirsher err = pci_request_regions(pdev, qlcnic_driver_name); 1744aa43c215SJeff Kirsher if (err) 1745aa43c215SJeff Kirsher goto err_out_disable_pdev; 1746aa43c215SJeff Kirsher 1747aa43c215SJeff Kirsher pci_set_master(pdev); 1748aa43c215SJeff Kirsher pci_enable_pcie_error_reporting(pdev); 1749aa43c215SJeff Kirsher 17507e2cf4feSSony Chacko ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL); 17517e2cf4feSSony Chacko if (!ahw) 17527e2cf4feSSony Chacko goto err_out_free_res; 17537e2cf4feSSony Chacko 17547e2cf4feSSony Chacko if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE824X) { 17557e2cf4feSSony Chacko ahw->hw_ops = &qlcnic_hw_ops; 17567e2cf4feSSony Chacko ahw->reg_tbl = (u32 *)qlcnic_reg_tbl; 175713159183SSony Chacko } else if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE834X) { 175813159183SSony Chacko qlcnic_83xx_register_map(ahw); 175913159183SSony Chacko } else { 176013159183SSony Chacko goto err_out_free_hw_res; 17617e2cf4feSSony Chacko } 17627e2cf4feSSony Chacko 17637e2cf4feSSony Chacko err = qlcnic_setup_pci_map(pdev, ahw); 17647e2cf4feSSony Chacko if (err) 17657e2cf4feSSony Chacko goto err_out_free_hw_res; 17667e2cf4feSSony Chacko 1767aa43c215SJeff Kirsher netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); 1768aa43c215SJeff Kirsher if (!netdev) { 1769aa43c215SJeff Kirsher err = -ENOMEM; 17707e2cf4feSSony Chacko goto err_out_iounmap; 1771aa43c215SJeff Kirsher } 1772aa43c215SJeff Kirsher 1773aa43c215SJeff Kirsher SET_NETDEV_DEV(netdev, &pdev->dev); 1774aa43c215SJeff Kirsher 1775aa43c215SJeff Kirsher adapter = netdev_priv(netdev); 1776aa43c215SJeff Kirsher adapter->netdev = netdev; 1777aa43c215SJeff Kirsher adapter->pdev = pdev; 177813159183SSony Chacko adapter->ahw = ahw; 177913159183SSony Chacko 178013159183SSony Chacko adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic"); 178113159183SSony Chacko if (adapter->qlcnic_wq == NULL) { 178213159183SSony Chacko dev_err(&pdev->dev, "Failed to create workqueue\n"); 178313159183SSony Chacko goto err_out_free_netdev; 178413159183SSony Chacko } 1785aa43c215SJeff Kirsher 17862dfc9671SPeter Senna Tschudin err = qlcnic_alloc_adapter_resources(adapter); 17872dfc9671SPeter Senna Tschudin if (err) 1788aa43c215SJeff Kirsher goto err_out_free_netdev; 1789aa43c215SJeff Kirsher 1790aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 17917e2cf4feSSony Chacko adapter->ahw->revision_id = pdev->revision; 1792aa43c215SJeff Kirsher adapter->mac_learn = qlcnic_mac_learn; 17937e2cf4feSSony Chacko adapter->max_drv_tx_rings = 1; 1794aa43c215SJeff Kirsher 1795aa43c215SJeff Kirsher rwlock_init(&adapter->ahw->crb_lock); 1796aa43c215SJeff Kirsher mutex_init(&adapter->ahw->mem_lock); 1797aa43c215SJeff Kirsher 1798aa43c215SJeff Kirsher spin_lock_init(&adapter->tx_clean_lock); 1799aa43c215SJeff Kirsher INIT_LIST_HEAD(&adapter->mac_list); 1800aa43c215SJeff Kirsher 18017e2cf4feSSony Chacko if (qlcnic_82xx_check(adapter)) { 180213159183SSony Chacko qlcnic_check_vf(adapter, ent); 1803aa43c215SJeff Kirsher adapter->portnum = adapter->ahw->pci_func; 18047e2cf4feSSony Chacko err = qlcnic_start_firmware(adapter); 1805aa43c215SJeff Kirsher if (err) { 18067e2cf4feSSony Chacko dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"); 18077e2cf4feSSony Chacko goto err_out_free_hw; 1808aa43c215SJeff Kirsher } 1809aa43c215SJeff Kirsher 1810aa43c215SJeff Kirsher err = qlcnic_setup_idc_param(adapter); 1811aa43c215SJeff Kirsher if (err) 18127e2cf4feSSony Chacko goto err_out_free_hw; 1813aa43c215SJeff Kirsher 1814aa43c215SJeff Kirsher adapter->flags |= QLCNIC_NEED_FLR; 181513159183SSony Chacko } else if (qlcnic_83xx_check(adapter)) { 181613159183SSony Chacko qlcnic_83xx_check_vf(adapter, ent); 181713159183SSony Chacko adapter->portnum = adapter->ahw->pci_func; 1818629263acSSony Chacko err = qlcnic_83xx_init(adapter); 1819629263acSSony Chacko if (err) { 1820629263acSSony Chacko dev_err(&pdev->dev, "%s: failed\n", __func__); 1821629263acSSony Chacko goto err_out_free_hw; 1822629263acSSony Chacko } 182313159183SSony Chacko } else { 182413159183SSony Chacko dev_err(&pdev->dev, 182513159183SSony Chacko "%s: failed. Please Reboot\n", __func__); 182613159183SSony Chacko goto err_out_free_hw; 1827aa43c215SJeff Kirsher } 1828aa43c215SJeff Kirsher 1829aa43c215SJeff Kirsher if (qlcnic_read_mac_addr(adapter)) 1830aa43c215SJeff Kirsher dev_warn(&pdev->dev, "failed to read mac addr\n"); 1831aa43c215SJeff Kirsher 1832aa43c215SJeff Kirsher if (adapter->portnum == 0) { 183322999798SSony Chacko qlcnic_get_board_name(adapter, board_name); 183413159183SSony Chacko 1835aa43c215SJeff Kirsher pr_info("%s: %s Board Chip rev 0x%x\n", 1836aa43c215SJeff Kirsher module_name(THIS_MODULE), 183722999798SSony Chacko board_name, adapter->ahw->revision_id); 1838aa43c215SJeff Kirsher } 18397e2cf4feSSony Chacko err = qlcnic_setup_intr(adapter, 0); 18407e2cf4feSSony Chacko if (err) 18417e2cf4feSSony Chacko goto err_out_disable_msi; 18427e2cf4feSSony Chacko 184313159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 184413159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 184513159183SSony Chacko if (err) 184613159183SSony Chacko goto err_out_disable_msi; 184713159183SSony Chacko } 1848aa43c215SJeff Kirsher 1849aa43c215SJeff Kirsher err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); 1850aa43c215SJeff Kirsher if (err) 18517e2cf4feSSony Chacko goto err_out_disable_mbx_intr; 1852aa43c215SJeff Kirsher 1853c84e340aSSritej Velaga if (qlcnic_82xx_check(adapter)) { 1854c84e340aSSritej Velaga if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { 1855c84e340aSSritej Velaga capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); 1856c84e340aSSritej Velaga if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB) 1857c84e340aSSritej Velaga qlcnic_fw_cmd_set_drv_version(adapter); 1858c84e340aSSritej Velaga } 1859c84e340aSSritej Velaga } 1860c84e340aSSritej Velaga 1861aa43c215SJeff Kirsher pci_set_drvdata(pdev, adapter); 1862aa43c215SJeff Kirsher 186397ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 186497ee45ebSSony Chacko qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 186597ee45ebSSony Chacko FW_POLL_DELAY); 1866aa43c215SJeff Kirsher 1867aa43c215SJeff Kirsher switch (adapter->ahw->port_type) { 1868aa43c215SJeff Kirsher case QLCNIC_GBE: 1869aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 1870aa43c215SJeff Kirsher adapter->netdev->name); 1871aa43c215SJeff Kirsher break; 1872aa43c215SJeff Kirsher case QLCNIC_XGBE: 1873aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", 1874aa43c215SJeff Kirsher adapter->netdev->name); 1875aa43c215SJeff Kirsher break; 1876aa43c215SJeff Kirsher } 1877aa43c215SJeff Kirsher 18787e2cf4feSSony Chacko if (qlcnic_get_act_pci_func(adapter)) 18797e2cf4feSSony Chacko goto err_out_disable_mbx_intr; 18807e2cf4feSSony Chacko 1881aa43c215SJeff Kirsher if (adapter->mac_learn) 1882aa43c215SJeff Kirsher qlcnic_alloc_lb_filters_mem(adapter); 1883aa43c215SJeff Kirsher 18847e2cf4feSSony Chacko qlcnic_add_sysfs(adapter); 1885aa43c215SJeff Kirsher 1886aa43c215SJeff Kirsher return 0; 1887aa43c215SJeff Kirsher 18887e2cf4feSSony Chacko err_out_disable_mbx_intr: 188913159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 189013159183SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) 189113159183SSony Chacko qlcnic_83xx_config_intrpt(adapter, 0); 189213159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 189313159183SSony Chacko } 18947e2cf4feSSony Chacko 1895aa43c215SJeff Kirsher err_out_disable_msi: 1896aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 18977e2cf4feSSony Chacko qlcnic_cancel_idc_work(adapter); 1898aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1899aa43c215SJeff Kirsher 1900aa43c215SJeff Kirsher err_out_free_hw: 1901aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 1902aa43c215SJeff Kirsher 1903aa43c215SJeff Kirsher err_out_free_netdev: 1904aa43c215SJeff Kirsher free_netdev(netdev); 1905aa43c215SJeff Kirsher 19067e2cf4feSSony Chacko err_out_iounmap: 19077e2cf4feSSony Chacko qlcnic_cleanup_pci_map(adapter); 19087e2cf4feSSony Chacko 19097e2cf4feSSony Chacko err_out_free_hw_res: 19107e2cf4feSSony Chacko kfree(ahw); 19117e2cf4feSSony Chacko 1912aa43c215SJeff Kirsher err_out_free_res: 1913aa43c215SJeff Kirsher pci_release_regions(pdev); 1914aa43c215SJeff Kirsher 1915aa43c215SJeff Kirsher err_out_disable_pdev: 1916aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1917aa43c215SJeff Kirsher pci_disable_device(pdev); 1918aa43c215SJeff Kirsher return err; 1919aa43c215SJeff Kirsher } 1920aa43c215SJeff Kirsher 19216bb58bb0SBill Pemberton static void qlcnic_remove(struct pci_dev *pdev) 1922aa43c215SJeff Kirsher { 1923aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 1924aa43c215SJeff Kirsher struct net_device *netdev; 192513159183SSony Chacko struct qlcnic_hardware_context *ahw; 1926aa43c215SJeff Kirsher 1927aa43c215SJeff Kirsher adapter = pci_get_drvdata(pdev); 1928aa43c215SJeff Kirsher if (adapter == NULL) 1929aa43c215SJeff Kirsher return; 1930aa43c215SJeff Kirsher 1931aa43c215SJeff Kirsher netdev = adapter->netdev; 1932aa43c215SJeff Kirsher 193313159183SSony Chacko qlcnic_cancel_idc_work(adapter); 193413159183SSony Chacko ahw = adapter->ahw; 1935aa43c215SJeff Kirsher 1936aa43c215SJeff Kirsher unregister_netdev(netdev); 1937aa43c215SJeff Kirsher 193813159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 193913159183SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) 194013159183SSony Chacko qlcnic_83xx_config_intrpt(adapter, 0); 194113159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 194213159183SSony Chacko } 194313159183SSony Chacko 1944aa43c215SJeff Kirsher qlcnic_detach(adapter); 1945aa43c215SJeff Kirsher 1946aa43c215SJeff Kirsher if (adapter->npars != NULL) 1947aa43c215SJeff Kirsher kfree(adapter->npars); 1948aa43c215SJeff Kirsher if (adapter->eswitch != NULL) 1949aa43c215SJeff Kirsher kfree(adapter->eswitch); 1950aa43c215SJeff Kirsher 195197ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 1952aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1953aa43c215SJeff Kirsher 1954aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1955aa43c215SJeff Kirsher 1956aa43c215SJeff Kirsher qlcnic_free_lb_filters_mem(adapter); 1957aa43c215SJeff Kirsher 1958aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 1959aa43c215SJeff Kirsher 196013159183SSony Chacko qlcnic_remove_sysfs(adapter); 1961aa43c215SJeff Kirsher 1962aa43c215SJeff Kirsher qlcnic_cleanup_pci_map(adapter); 1963aa43c215SJeff Kirsher 1964aa43c215SJeff Kirsher qlcnic_release_firmware(adapter); 1965aa43c215SJeff Kirsher 1966aa43c215SJeff Kirsher pci_disable_pcie_error_reporting(pdev); 1967aa43c215SJeff Kirsher pci_release_regions(pdev); 1968aa43c215SJeff Kirsher pci_disable_device(pdev); 1969aa43c215SJeff Kirsher pci_set_drvdata(pdev, NULL); 1970aa43c215SJeff Kirsher 197113159183SSony Chacko if (adapter->qlcnic_wq) { 197213159183SSony Chacko destroy_workqueue(adapter->qlcnic_wq); 197313159183SSony Chacko adapter->qlcnic_wq = NULL; 197413159183SSony Chacko } 1975aa43c215SJeff Kirsher qlcnic_free_adapter_resources(adapter); 197613159183SSony Chacko kfree(ahw); 1977aa43c215SJeff Kirsher free_netdev(netdev); 1978aa43c215SJeff Kirsher } 1979aa43c215SJeff Kirsher static int __qlcnic_shutdown(struct pci_dev *pdev) 1980aa43c215SJeff Kirsher { 1981aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 1982aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 1983aa43c215SJeff Kirsher int retval; 1984aa43c215SJeff Kirsher 1985aa43c215SJeff Kirsher netif_device_detach(netdev); 1986aa43c215SJeff Kirsher 198713159183SSony Chacko qlcnic_cancel_idc_work(adapter); 1988aa43c215SJeff Kirsher 1989aa43c215SJeff Kirsher if (netif_running(netdev)) 1990aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 1991aa43c215SJeff Kirsher 199297ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 1993aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 1994aa43c215SJeff Kirsher 1995aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 1996aa43c215SJeff Kirsher 1997aa43c215SJeff Kirsher retval = pci_save_state(pdev); 1998aa43c215SJeff Kirsher if (retval) 1999aa43c215SJeff Kirsher return retval; 200097ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) { 2001aa43c215SJeff Kirsher if (qlcnic_wol_supported(adapter)) { 2002aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3cold, 1); 2003aa43c215SJeff Kirsher pci_enable_wake(pdev, PCI_D3hot, 1); 2004aa43c215SJeff Kirsher } 200597ee45ebSSony Chacko } 2006aa43c215SJeff Kirsher 2007aa43c215SJeff Kirsher return 0; 2008aa43c215SJeff Kirsher } 2009aa43c215SJeff Kirsher 2010aa43c215SJeff Kirsher static void qlcnic_shutdown(struct pci_dev *pdev) 2011aa43c215SJeff Kirsher { 2012aa43c215SJeff Kirsher if (__qlcnic_shutdown(pdev)) 2013aa43c215SJeff Kirsher return; 2014aa43c215SJeff Kirsher 2015aa43c215SJeff Kirsher pci_disable_device(pdev); 2016aa43c215SJeff Kirsher } 2017aa43c215SJeff Kirsher 2018aa43c215SJeff Kirsher #ifdef CONFIG_PM 2019aa43c215SJeff Kirsher static int 2020aa43c215SJeff Kirsher qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) 2021aa43c215SJeff Kirsher { 2022aa43c215SJeff Kirsher int retval; 2023aa43c215SJeff Kirsher 2024aa43c215SJeff Kirsher retval = __qlcnic_shutdown(pdev); 2025aa43c215SJeff Kirsher if (retval) 2026aa43c215SJeff Kirsher return retval; 2027aa43c215SJeff Kirsher 2028aa43c215SJeff Kirsher pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2029aa43c215SJeff Kirsher return 0; 2030aa43c215SJeff Kirsher } 2031aa43c215SJeff Kirsher 2032aa43c215SJeff Kirsher static int 2033aa43c215SJeff Kirsher qlcnic_resume(struct pci_dev *pdev) 2034aa43c215SJeff Kirsher { 2035aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 2036aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2037aa43c215SJeff Kirsher int err; 2038aa43c215SJeff Kirsher 2039aa43c215SJeff Kirsher err = pci_enable_device(pdev); 2040aa43c215SJeff Kirsher if (err) 2041aa43c215SJeff Kirsher return err; 2042aa43c215SJeff Kirsher 2043aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 2044aa43c215SJeff Kirsher pci_set_master(pdev); 2045aa43c215SJeff Kirsher pci_restore_state(pdev); 2046aa43c215SJeff Kirsher 204713159183SSony Chacko err = qlcnic_start_firmware(adapter); 2048aa43c215SJeff Kirsher if (err) { 2049aa43c215SJeff Kirsher dev_err(&pdev->dev, "failed to start firmware\n"); 2050aa43c215SJeff Kirsher return err; 2051aa43c215SJeff Kirsher } 2052aa43c215SJeff Kirsher 2053aa43c215SJeff Kirsher if (netif_running(netdev)) { 2054aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 2055aa43c215SJeff Kirsher if (err) 2056aa43c215SJeff Kirsher goto done; 2057aa43c215SJeff Kirsher 2058aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2059aa43c215SJeff Kirsher } 2060aa43c215SJeff Kirsher done: 2061aa43c215SJeff Kirsher netif_device_attach(netdev); 2062aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 2063aa43c215SJeff Kirsher return 0; 2064aa43c215SJeff Kirsher } 2065aa43c215SJeff Kirsher #endif 2066aa43c215SJeff Kirsher 2067aa43c215SJeff Kirsher static int qlcnic_open(struct net_device *netdev) 2068aa43c215SJeff Kirsher { 2069aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2070aa43c215SJeff Kirsher int err; 2071aa43c215SJeff Kirsher 2072aa43c215SJeff Kirsher netif_carrier_off(netdev); 2073aa43c215SJeff Kirsher 2074aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 2075aa43c215SJeff Kirsher if (err) 2076aa43c215SJeff Kirsher return err; 2077aa43c215SJeff Kirsher 2078aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 2079aa43c215SJeff Kirsher if (err) 2080aa43c215SJeff Kirsher goto err_out; 2081aa43c215SJeff Kirsher 2082aa43c215SJeff Kirsher netif_start_queue(netdev); 2083aa43c215SJeff Kirsher 2084aa43c215SJeff Kirsher return 0; 2085aa43c215SJeff Kirsher 2086aa43c215SJeff Kirsher err_out: 2087aa43c215SJeff Kirsher qlcnic_detach(adapter); 2088aa43c215SJeff Kirsher return err; 2089aa43c215SJeff Kirsher } 2090aa43c215SJeff Kirsher 2091aa43c215SJeff Kirsher /* 2092aa43c215SJeff Kirsher * qlcnic_close - Disables a network interface entry point 2093aa43c215SJeff Kirsher */ 2094aa43c215SJeff Kirsher static int qlcnic_close(struct net_device *netdev) 2095aa43c215SJeff Kirsher { 2096aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2097aa43c215SJeff Kirsher 2098aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 209913159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 210013159183SSony Chacko qlcnic_83xx_register_nic_idc_func(adapter, 0); 210113159183SSony Chacko cancel_delayed_work_sync(&adapter->idc_aen_work); 210213159183SSony Chacko } 210313159183SSony Chacko 2104aa43c215SJeff Kirsher return 0; 2105aa43c215SJeff Kirsher } 2106aa43c215SJeff Kirsher 2107aa43c215SJeff Kirsher void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) 2108aa43c215SJeff Kirsher { 2109aa43c215SJeff Kirsher void *head; 2110aa43c215SJeff Kirsher int i; 211113159183SSony Chacko struct net_device *netdev = adapter->netdev; 211213159183SSony Chacko u32 filter_size = 0; 211313159183SSony Chacko u16 act_pci_func = 0; 2114aa43c215SJeff Kirsher 2115aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 2116aa43c215SJeff Kirsher return; 2117aa43c215SJeff Kirsher 211813159183SSony Chacko act_pci_func = adapter->ahw->act_pci_func; 2119aa43c215SJeff Kirsher spin_lock_init(&adapter->mac_learn_lock); 2120aa43c215SJeff Kirsher 212113159183SSony Chacko if (qlcnic_82xx_check(adapter)) { 212213159183SSony Chacko filter_size = QLCNIC_LB_MAX_FILTERS; 212313159183SSony Chacko adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE; 212413159183SSony Chacko } else { 212513159183SSony Chacko filter_size = QLC_83XX_LB_MAX_FILTERS; 212613159183SSony Chacko adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE; 212713159183SSony Chacko } 212813159183SSony Chacko 212913159183SSony Chacko head = kcalloc(adapter->fhash.fbucket_size, 213013159183SSony Chacko sizeof(struct hlist_head), GFP_KERNEL); 213113159183SSony Chacko 2132aa43c215SJeff Kirsher if (!head) 2133aa43c215SJeff Kirsher return; 2134aa43c215SJeff Kirsher 213513159183SSony Chacko adapter->fhash.fmax = (filter_size / act_pci_func); 2136aa43c215SJeff Kirsher adapter->fhash.fhead = head; 2137aa43c215SJeff Kirsher 213813159183SSony Chacko netdev_info(netdev, "active nic func = %d, mac filter size=%d\n", 213913159183SSony Chacko act_pci_func, adapter->fhash.fmax); 214013159183SSony Chacko 214113159183SSony Chacko for (i = 0; i < adapter->fhash.fbucket_size; i++) 2142aa43c215SJeff Kirsher INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); 2143aa43c215SJeff Kirsher } 2144aa43c215SJeff Kirsher 2145aa43c215SJeff Kirsher static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) 2146aa43c215SJeff Kirsher { 2147aa43c215SJeff Kirsher if (adapter->fhash.fmax && adapter->fhash.fhead) 2148aa43c215SJeff Kirsher kfree(adapter->fhash.fhead); 2149aa43c215SJeff Kirsher 2150aa43c215SJeff Kirsher adapter->fhash.fhead = NULL; 2151aa43c215SJeff Kirsher adapter->fhash.fmax = 0; 2152aa43c215SJeff Kirsher } 2153aa43c215SJeff Kirsher 2154629263acSSony Chacko int qlcnic_check_temp(struct qlcnic_adapter *adapter) 2155aa43c215SJeff Kirsher { 2156aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 215797ee45ebSSony Chacko u32 temp_state, temp_val, temp = 0; 2158aa43c215SJeff Kirsher int rv = 0; 2159aa43c215SJeff Kirsher 216013159183SSony Chacko if (qlcnic_83xx_check(adapter)) 216113159183SSony Chacko temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP); 216213159183SSony Chacko 216397ee45ebSSony Chacko if (qlcnic_82xx_check(adapter)) 2164a15ebd37SHimanshu Madhani temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP); 2165aa43c215SJeff Kirsher 2166aa43c215SJeff Kirsher temp_state = qlcnic_get_temp_state(temp); 2167aa43c215SJeff Kirsher temp_val = qlcnic_get_temp_val(temp); 2168aa43c215SJeff Kirsher 2169aa43c215SJeff Kirsher if (temp_state == QLCNIC_TEMP_PANIC) { 2170aa43c215SJeff Kirsher dev_err(&netdev->dev, 2171aa43c215SJeff Kirsher "Device temperature %d degrees C exceeds" 2172aa43c215SJeff Kirsher " maximum allowed. Hardware has been shut down.\n", 2173aa43c215SJeff Kirsher temp_val); 2174aa43c215SJeff Kirsher rv = 1; 2175aa43c215SJeff Kirsher } else if (temp_state == QLCNIC_TEMP_WARN) { 217679788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) { 2177aa43c215SJeff Kirsher dev_err(&netdev->dev, 2178aa43c215SJeff Kirsher "Device temperature %d degrees C " 2179aa43c215SJeff Kirsher "exceeds operating range." 2180aa43c215SJeff Kirsher " Immediate action needed.\n", 2181aa43c215SJeff Kirsher temp_val); 2182aa43c215SJeff Kirsher } 2183aa43c215SJeff Kirsher } else { 218479788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_WARN) { 2185aa43c215SJeff Kirsher dev_info(&netdev->dev, 2186aa43c215SJeff Kirsher "Device temperature is now %d degrees C" 2187aa43c215SJeff Kirsher " in normal range.\n", temp_val); 2188aa43c215SJeff Kirsher } 2189aa43c215SJeff Kirsher } 219079788450SSony Chacko adapter->ahw->temp = temp_state; 2191aa43c215SJeff Kirsher return rv; 2192aa43c215SJeff Kirsher } 2193aa43c215SJeff Kirsher 2194aa43c215SJeff Kirsher static void qlcnic_tx_timeout(struct net_device *netdev) 2195aa43c215SJeff Kirsher { 2196aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2197aa43c215SJeff Kirsher 2198aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2199aa43c215SJeff Kirsher return; 2200aa43c215SJeff Kirsher 2201aa43c215SJeff Kirsher dev_err(&netdev->dev, "transmit timeout, resetting.\n"); 2202aa43c215SJeff Kirsher 2203aa43c215SJeff Kirsher if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) 2204aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2205aa43c215SJeff Kirsher else 220679788450SSony Chacko adapter->ahw->reset_context = 1; 2207aa43c215SJeff Kirsher } 2208aa43c215SJeff Kirsher 2209aa43c215SJeff Kirsher static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) 2210aa43c215SJeff Kirsher { 2211aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2212aa43c215SJeff Kirsher struct net_device_stats *stats = &netdev->stats; 2213aa43c215SJeff Kirsher 2214aa43c215SJeff Kirsher stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; 2215aa43c215SJeff Kirsher stats->tx_packets = adapter->stats.xmitfinished; 2216aa43c215SJeff Kirsher stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; 2217aa43c215SJeff Kirsher stats->tx_bytes = adapter->stats.txbytes; 2218aa43c215SJeff Kirsher stats->rx_dropped = adapter->stats.rxdropped; 2219aa43c215SJeff Kirsher stats->tx_dropped = adapter->stats.txdropped; 2220aa43c215SJeff Kirsher 2221aa43c215SJeff Kirsher return stats; 2222aa43c215SJeff Kirsher } 2223aa43c215SJeff Kirsher 22247e2cf4feSSony Chacko irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter) 2225aa43c215SJeff Kirsher { 2226aa43c215SJeff Kirsher u32 status; 2227aa43c215SJeff Kirsher 2228aa43c215SJeff Kirsher status = readl(adapter->isr_int_vec); 2229aa43c215SJeff Kirsher 223079788450SSony Chacko if (!(status & adapter->ahw->int_vec_bit)) 2231aa43c215SJeff Kirsher return IRQ_NONE; 2232aa43c215SJeff Kirsher 2233aa43c215SJeff Kirsher /* check interrupt state machine, to be sure */ 2234aa43c215SJeff Kirsher status = readl(adapter->crb_int_state_reg); 2235aa43c215SJeff Kirsher if (!ISR_LEGACY_INT_TRIGGERED(status)) 2236aa43c215SJeff Kirsher return IRQ_NONE; 2237aa43c215SJeff Kirsher 2238aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2239aa43c215SJeff Kirsher /* read twice to ensure write is flushed */ 2240aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2241aa43c215SJeff Kirsher readl(adapter->isr_int_vec); 2242aa43c215SJeff Kirsher 2243aa43c215SJeff Kirsher return IRQ_HANDLED; 2244aa43c215SJeff Kirsher } 2245aa43c215SJeff Kirsher 2246aa43c215SJeff Kirsher static irqreturn_t qlcnic_tmp_intr(int irq, void *data) 2247aa43c215SJeff Kirsher { 2248aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2249aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2250aa43c215SJeff Kirsher 2251aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_MSIX_ENABLED) 2252aa43c215SJeff Kirsher goto done; 2253aa43c215SJeff Kirsher else if (adapter->flags & QLCNIC_MSI_ENABLED) { 2254aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2255aa43c215SJeff Kirsher goto done; 2256aa43c215SJeff Kirsher } 2257aa43c215SJeff Kirsher 2258aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2259aa43c215SJeff Kirsher return IRQ_NONE; 2260aa43c215SJeff Kirsher 2261aa43c215SJeff Kirsher done: 226279788450SSony Chacko adapter->ahw->diag_cnt++; 2263aa43c215SJeff Kirsher qlcnic_enable_int(sds_ring); 2264aa43c215SJeff Kirsher return IRQ_HANDLED; 2265aa43c215SJeff Kirsher } 2266aa43c215SJeff Kirsher 2267aa43c215SJeff Kirsher static irqreturn_t qlcnic_intr(int irq, void *data) 2268aa43c215SJeff Kirsher { 2269aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2270aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2271aa43c215SJeff Kirsher 2272aa43c215SJeff Kirsher if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) 2273aa43c215SJeff Kirsher return IRQ_NONE; 2274aa43c215SJeff Kirsher 2275aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2276aa43c215SJeff Kirsher 2277aa43c215SJeff Kirsher return IRQ_HANDLED; 2278aa43c215SJeff Kirsher } 2279aa43c215SJeff Kirsher 2280aa43c215SJeff Kirsher static irqreturn_t qlcnic_msi_intr(int irq, void *data) 2281aa43c215SJeff Kirsher { 2282aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2283aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = sds_ring->adapter; 2284aa43c215SJeff Kirsher 2285aa43c215SJeff Kirsher /* clear interrupt */ 2286aa43c215SJeff Kirsher writel(0xffffffff, adapter->tgt_status_reg); 2287aa43c215SJeff Kirsher 2288aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2289aa43c215SJeff Kirsher return IRQ_HANDLED; 2290aa43c215SJeff Kirsher } 2291aa43c215SJeff Kirsher 2292aa43c215SJeff Kirsher static irqreturn_t qlcnic_msix_intr(int irq, void *data) 2293aa43c215SJeff Kirsher { 2294aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring = data; 2295aa43c215SJeff Kirsher 2296aa43c215SJeff Kirsher napi_schedule(&sds_ring->napi); 2297aa43c215SJeff Kirsher return IRQ_HANDLED; 2298aa43c215SJeff Kirsher } 2299aa43c215SJeff Kirsher 230013159183SSony Chacko static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data) 230113159183SSony Chacko { 230213159183SSony Chacko struct qlcnic_host_tx_ring *tx_ring = data; 230313159183SSony Chacko 230413159183SSony Chacko napi_schedule(&tx_ring->napi); 230513159183SSony Chacko return IRQ_HANDLED; 230613159183SSony Chacko } 230713159183SSony Chacko 2308aa43c215SJeff Kirsher #ifdef CONFIG_NET_POLL_CONTROLLER 2309aa43c215SJeff Kirsher static void qlcnic_poll_controller(struct net_device *netdev) 2310aa43c215SJeff Kirsher { 2311aa43c215SJeff Kirsher int ring; 2312aa43c215SJeff Kirsher struct qlcnic_host_sds_ring *sds_ring; 2313aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 2314aa43c215SJeff Kirsher struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; 2315aa43c215SJeff Kirsher 2316aa43c215SJeff Kirsher disable_irq(adapter->irq); 2317aa43c215SJeff Kirsher for (ring = 0; ring < adapter->max_sds_rings; ring++) { 2318aa43c215SJeff Kirsher sds_ring = &recv_ctx->sds_rings[ring]; 2319aa43c215SJeff Kirsher qlcnic_intr(adapter->irq, sds_ring); 2320aa43c215SJeff Kirsher } 2321aa43c215SJeff Kirsher enable_irq(adapter->irq); 2322aa43c215SJeff Kirsher } 2323aa43c215SJeff Kirsher #endif 2324aa43c215SJeff Kirsher 2325aa43c215SJeff Kirsher static void 2326aa43c215SJeff Kirsher qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) 2327aa43c215SJeff Kirsher { 2328aa43c215SJeff Kirsher u32 val; 2329aa43c215SJeff Kirsher 2330aa43c215SJeff Kirsher val = adapter->portnum & 0xf; 2331aa43c215SJeff Kirsher val |= encoding << 7; 2332aa43c215SJeff Kirsher val |= (jiffies - adapter->dev_rst_time) << 8; 2333aa43c215SJeff Kirsher 2334a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); 2335aa43c215SJeff Kirsher adapter->dev_rst_time = jiffies; 2336aa43c215SJeff Kirsher } 2337aa43c215SJeff Kirsher 2338aa43c215SJeff Kirsher static int 2339aa43c215SJeff Kirsher qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) 2340aa43c215SJeff Kirsher { 2341aa43c215SJeff Kirsher u32 val; 2342aa43c215SJeff Kirsher 2343aa43c215SJeff Kirsher WARN_ON(state != QLCNIC_DEV_NEED_RESET && 2344aa43c215SJeff Kirsher state != QLCNIC_DEV_NEED_QUISCENT); 2345aa43c215SJeff Kirsher 2346aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2347aa43c215SJeff Kirsher return -EIO; 2348aa43c215SJeff Kirsher 2349a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2350aa43c215SJeff Kirsher 2351aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) 2352aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2353aa43c215SJeff Kirsher else if (state == QLCNIC_DEV_NEED_QUISCENT) 2354aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); 2355aa43c215SJeff Kirsher 2356a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2357aa43c215SJeff Kirsher 2358aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2359aa43c215SJeff Kirsher 2360aa43c215SJeff Kirsher return 0; 2361aa43c215SJeff Kirsher } 2362aa43c215SJeff Kirsher 2363aa43c215SJeff Kirsher static int 2364aa43c215SJeff Kirsher qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) 2365aa43c215SJeff Kirsher { 2366aa43c215SJeff Kirsher u32 val; 2367aa43c215SJeff Kirsher 2368aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2369aa43c215SJeff Kirsher return -EBUSY; 2370aa43c215SJeff Kirsher 2371a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2372aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2373a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2374aa43c215SJeff Kirsher 2375aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2376aa43c215SJeff Kirsher 2377aa43c215SJeff Kirsher return 0; 2378aa43c215SJeff Kirsher } 2379aa43c215SJeff Kirsher 2380aa43c215SJeff Kirsher static void 2381aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) 2382aa43c215SJeff Kirsher { 2383aa43c215SJeff Kirsher u32 val; 2384aa43c215SJeff Kirsher 2385aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2386aa43c215SJeff Kirsher goto err; 2387aa43c215SJeff Kirsher 2388a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2389aa43c215SJeff Kirsher QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2390a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2391aa43c215SJeff Kirsher 2392aa43c215SJeff Kirsher if (failed) { 2393a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2394a15ebd37SHimanshu Madhani QLCNIC_DEV_FAILED); 2395aa43c215SJeff Kirsher dev_info(&adapter->pdev->dev, 2396aa43c215SJeff Kirsher "Device state set to Failed. Please Reboot\n"); 2397aa43c215SJeff Kirsher } else if (!(val & 0x11111111)) 2398a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2399a15ebd37SHimanshu Madhani QLCNIC_DEV_COLD); 2400aa43c215SJeff Kirsher 2401a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2402aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); 2403a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2404aa43c215SJeff Kirsher 2405aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2406aa43c215SJeff Kirsher err: 2407aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2408aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2409aa43c215SJeff Kirsher clear_bit(__QLCNIC_START_FW, &adapter->state); 2410aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2411aa43c215SJeff Kirsher } 2412aa43c215SJeff Kirsher 2413aa43c215SJeff Kirsher /* Grab api lock, before checking state */ 2414aa43c215SJeff Kirsher static int 2415aa43c215SJeff Kirsher qlcnic_check_drv_state(struct qlcnic_adapter *adapter) 2416aa43c215SJeff Kirsher { 2417aa43c215SJeff Kirsher int act, state, active_mask; 2418a15ebd37SHimanshu Madhani struct qlcnic_hardware_context *ahw = adapter->ahw; 2419aa43c215SJeff Kirsher 2420a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2421a15ebd37SHimanshu Madhani act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2422aa43c215SJeff Kirsher 2423aa43c215SJeff Kirsher if (adapter->flags & QLCNIC_FW_RESET_OWNER) { 2424a15ebd37SHimanshu Madhani active_mask = (~(1 << (ahw->pci_func * 4))); 2425aa43c215SJeff Kirsher act = act & active_mask; 2426aa43c215SJeff Kirsher } 2427aa43c215SJeff Kirsher 2428aa43c215SJeff Kirsher if (((state & 0x11111111) == (act & 0x11111111)) || 2429aa43c215SJeff Kirsher ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 2430aa43c215SJeff Kirsher return 0; 2431aa43c215SJeff Kirsher else 2432aa43c215SJeff Kirsher return 1; 2433aa43c215SJeff Kirsher } 2434aa43c215SJeff Kirsher 2435aa43c215SJeff Kirsher static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) 2436aa43c215SJeff Kirsher { 2437a15ebd37SHimanshu Madhani u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER); 2438aa43c215SJeff Kirsher 2439aa43c215SJeff Kirsher if (val != QLCNIC_DRV_IDC_VER) { 2440aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" 2441aa43c215SJeff Kirsher " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); 2442aa43c215SJeff Kirsher } 2443aa43c215SJeff Kirsher 2444aa43c215SJeff Kirsher return 0; 2445aa43c215SJeff Kirsher } 2446aa43c215SJeff Kirsher 2447aa43c215SJeff Kirsher static int 2448aa43c215SJeff Kirsher qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) 2449aa43c215SJeff Kirsher { 2450aa43c215SJeff Kirsher u32 val, prev_state; 2451aa43c215SJeff Kirsher u8 dev_init_timeo = adapter->dev_init_timeo; 2452aa43c215SJeff Kirsher u8 portnum = adapter->portnum; 2453aa43c215SJeff Kirsher u8 ret; 2454aa43c215SJeff Kirsher 2455aa43c215SJeff Kirsher if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) 2456aa43c215SJeff Kirsher return 1; 2457aa43c215SJeff Kirsher 2458aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2459aa43c215SJeff Kirsher return -1; 2460aa43c215SJeff Kirsher 2461a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 2462aa43c215SJeff Kirsher if (!(val & (1 << (portnum * 4)))) { 2463aa43c215SJeff Kirsher QLC_DEV_SET_REF_CNT(val, portnum); 2464a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); 2465aa43c215SJeff Kirsher } 2466aa43c215SJeff Kirsher 2467a15ebd37SHimanshu Madhani prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2468aa43c215SJeff Kirsher QLCDB(adapter, HW, "Device state = %u\n", prev_state); 2469aa43c215SJeff Kirsher 2470aa43c215SJeff Kirsher switch (prev_state) { 2471aa43c215SJeff Kirsher case QLCNIC_DEV_COLD: 2472a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2473a15ebd37SHimanshu Madhani QLCNIC_DEV_INITIALIZING); 2474a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER, 2475a15ebd37SHimanshu Madhani QLCNIC_DRV_IDC_VER); 2476aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2477aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2478aa43c215SJeff Kirsher return 1; 2479aa43c215SJeff Kirsher 2480aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 2481aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2482aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2483aa43c215SJeff Kirsher return ret; 2484aa43c215SJeff Kirsher 2485aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_RESET: 2486a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2487aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, portnum); 2488a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2489aa43c215SJeff Kirsher break; 2490aa43c215SJeff Kirsher 2491aa43c215SJeff Kirsher case QLCNIC_DEV_NEED_QUISCENT: 2492a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2493aa43c215SJeff Kirsher QLC_DEV_SET_QSCNT_RDY(val, portnum); 2494a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2495aa43c215SJeff Kirsher break; 2496aa43c215SJeff Kirsher 2497aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2498aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Device in failed state.\n"); 2499aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2500aa43c215SJeff Kirsher return -1; 2501aa43c215SJeff Kirsher 2502aa43c215SJeff Kirsher case QLCNIC_DEV_INITIALIZING: 2503aa43c215SJeff Kirsher case QLCNIC_DEV_QUISCENT: 2504aa43c215SJeff Kirsher break; 2505aa43c215SJeff Kirsher } 2506aa43c215SJeff Kirsher 2507aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2508aa43c215SJeff Kirsher 2509aa43c215SJeff Kirsher do { 2510aa43c215SJeff Kirsher msleep(1000); 2511a15ebd37SHimanshu Madhani prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2512aa43c215SJeff Kirsher 2513aa43c215SJeff Kirsher if (prev_state == QLCNIC_DEV_QUISCENT) 2514aa43c215SJeff Kirsher continue; 2515aa43c215SJeff Kirsher } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); 2516aa43c215SJeff Kirsher 2517aa43c215SJeff Kirsher if (!dev_init_timeo) { 2518aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 2519aa43c215SJeff Kirsher "Waiting for device to initialize timeout\n"); 2520aa43c215SJeff Kirsher return -1; 2521aa43c215SJeff Kirsher } 2522aa43c215SJeff Kirsher 2523aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2524aa43c215SJeff Kirsher return -1; 2525aa43c215SJeff Kirsher 2526a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE); 2527aa43c215SJeff Kirsher QLC_DEV_CLR_RST_QSCNT(val, portnum); 2528a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val); 2529aa43c215SJeff Kirsher 2530aa43c215SJeff Kirsher ret = qlcnic_check_idc_ver(adapter); 2531aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2532aa43c215SJeff Kirsher 2533aa43c215SJeff Kirsher return ret; 2534aa43c215SJeff Kirsher } 2535aa43c215SJeff Kirsher 2536aa43c215SJeff Kirsher static void 2537aa43c215SJeff Kirsher qlcnic_fwinit_work(struct work_struct *work) 2538aa43c215SJeff Kirsher { 2539aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2540aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2541aa43c215SJeff Kirsher u32 dev_state = 0xf; 2542aa43c215SJeff Kirsher u32 val; 2543aa43c215SJeff Kirsher 2544aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2545aa43c215SJeff Kirsher goto err_ret; 2546aa43c215SJeff Kirsher 2547a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2548aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_QUISCENT || 2549aa43c215SJeff Kirsher dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2550aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2551aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, 2552aa43c215SJeff Kirsher FW_POLL_DELAY * 2); 2553aa43c215SJeff Kirsher return; 2554aa43c215SJeff Kirsher } 2555aa43c215SJeff Kirsher 255679788450SSony Chacko if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) { 2557aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2558aa43c215SJeff Kirsher goto wait_npar; 2559aa43c215SJeff Kirsher } 2560aa43c215SJeff Kirsher 256116e3cf73SSritej Velaga if (dev_state == QLCNIC_DEV_INITIALIZING || 256216e3cf73SSritej Velaga dev_state == QLCNIC_DEV_READY) { 256316e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Detected state change from " 256416e3cf73SSritej Velaga "DEV_NEED_RESET, skipping ack check\n"); 256516e3cf73SSritej Velaga goto skip_ack_check; 256616e3cf73SSritej Velaga } 256716e3cf73SSritej Velaga 2568aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 256916e3cf73SSritej Velaga dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", 2570aa43c215SJeff Kirsher adapter->reset_ack_timeo); 2571aa43c215SJeff Kirsher goto skip_ack_check; 2572aa43c215SJeff Kirsher } 2573aa43c215SJeff Kirsher 2574aa43c215SJeff Kirsher if (!qlcnic_check_drv_state(adapter)) { 2575aa43c215SJeff Kirsher skip_ack_check: 2576a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2577aa43c215SJeff Kirsher 2578aa43c215SJeff Kirsher if (dev_state == QLCNIC_DEV_NEED_RESET) { 2579a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2580aa43c215SJeff Kirsher QLCNIC_DEV_INITIALIZING); 2581aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 2582aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 2583aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2584a15ebd37SHimanshu Madhani val = QLC_SHARED_REG_RD32(adapter, 2585a15ebd37SHimanshu Madhani QLCNIC_CRB_DRV_STATE); 2586aa43c215SJeff Kirsher QLC_DEV_SET_RST_RDY(val, adapter->portnum); 2587a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, 2588a15ebd37SHimanshu Madhani QLCNIC_CRB_DRV_STATE, val); 2589aa43c215SJeff Kirsher } 2590aa43c215SJeff Kirsher 2591aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2592aa43c215SJeff Kirsher 2593aa43c215SJeff Kirsher rtnl_lock(); 2594aa43c215SJeff Kirsher if (adapter->ahw->fw_dump.enable && 2595aa43c215SJeff Kirsher (adapter->flags & QLCNIC_FW_RESET_OWNER)) { 2596aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Take FW dump\n"); 2597aa43c215SJeff Kirsher qlcnic_dump_fw(adapter); 2598aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2599aa43c215SJeff Kirsher } 2600aa43c215SJeff Kirsher rtnl_unlock(); 2601aa43c215SJeff Kirsher 2602aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_RESET_OWNER; 2603aa43c215SJeff Kirsher if (!adapter->nic_ops->start_firmware(adapter)) { 2604aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2605aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2606aa43c215SJeff Kirsher return; 2607aa43c215SJeff Kirsher } 2608aa43c215SJeff Kirsher goto err_ret; 2609aa43c215SJeff Kirsher } 2610aa43c215SJeff Kirsher 2611aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2612aa43c215SJeff Kirsher 2613aa43c215SJeff Kirsher wait_npar: 2614a15ebd37SHimanshu Madhani dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2615aa43c215SJeff Kirsher QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 2616aa43c215SJeff Kirsher 2617aa43c215SJeff Kirsher switch (dev_state) { 2618aa43c215SJeff Kirsher case QLCNIC_DEV_READY: 26197e2cf4feSSony Chacko if (!qlcnic_start_firmware(adapter)) { 2620aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2621aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2622aa43c215SJeff Kirsher return; 2623aa43c215SJeff Kirsher } 2624aa43c215SJeff Kirsher case QLCNIC_DEV_FAILED: 2625aa43c215SJeff Kirsher break; 2626aa43c215SJeff Kirsher default: 2627aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, 2628aa43c215SJeff Kirsher qlcnic_fwinit_work, FW_POLL_DELAY); 2629aa43c215SJeff Kirsher return; 2630aa43c215SJeff Kirsher } 2631aa43c215SJeff Kirsher 2632aa43c215SJeff Kirsher err_ret: 2633aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 2634aa43c215SJeff Kirsher "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 2635aa43c215SJeff Kirsher netif_device_attach(adapter->netdev); 2636aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2637aa43c215SJeff Kirsher } 2638aa43c215SJeff Kirsher 2639aa43c215SJeff Kirsher static void 2640aa43c215SJeff Kirsher qlcnic_detach_work(struct work_struct *work) 2641aa43c215SJeff Kirsher { 2642aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2643aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2644aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2645aa43c215SJeff Kirsher u32 status; 2646aa43c215SJeff Kirsher 2647aa43c215SJeff Kirsher netif_device_detach(netdev); 2648aa43c215SJeff Kirsher 2649aa43c215SJeff Kirsher /* Dont grab rtnl lock during Quiscent mode */ 2650aa43c215SJeff Kirsher if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { 2651aa43c215SJeff Kirsher if (netif_running(netdev)) 2652aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 2653aa43c215SJeff Kirsher } else 2654aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 2655aa43c215SJeff Kirsher 2656a15ebd37SHimanshu Madhani status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2657aa43c215SJeff Kirsher 265844f65b29SSony Chacko if (status & QLCNIC_RCODE_FATAL_ERROR) { 265944f65b29SSony Chacko dev_err(&adapter->pdev->dev, 266044f65b29SSony Chacko "Detaching the device: peg halt status1=0x%x\n", 266144f65b29SSony Chacko status); 2662aa43c215SJeff Kirsher 266344f65b29SSony Chacko if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { 266444f65b29SSony Chacko dev_err(&adapter->pdev->dev, 266544f65b29SSony Chacko "On board active cooling fan failed. " 266644f65b29SSony Chacko "Device has been halted.\n"); 266744f65b29SSony Chacko dev_err(&adapter->pdev->dev, 266844f65b29SSony Chacko "Replace the adapter.\n"); 266944f65b29SSony Chacko } 267044f65b29SSony Chacko 2671aa43c215SJeff Kirsher goto err_ret; 267244f65b29SSony Chacko } 267344f65b29SSony Chacko 267479788450SSony Chacko if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) { 267544f65b29SSony Chacko dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", 267679788450SSony Chacko adapter->ahw->temp); 267744f65b29SSony Chacko goto err_ret; 267844f65b29SSony Chacko } 267944f65b29SSony Chacko 2680aa43c215SJeff Kirsher /* Dont ack if this instance is the reset owner */ 2681aa43c215SJeff Kirsher if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { 268244f65b29SSony Chacko if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { 268344f65b29SSony Chacko dev_err(&adapter->pdev->dev, 268444f65b29SSony Chacko "Failed to set driver state," 268544f65b29SSony Chacko "detaching the device.\n"); 2686aa43c215SJeff Kirsher goto err_ret; 2687aa43c215SJeff Kirsher } 268844f65b29SSony Chacko } 2689aa43c215SJeff Kirsher 2690aa43c215SJeff Kirsher adapter->fw_wait_cnt = 0; 2691aa43c215SJeff Kirsher 2692aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); 2693aa43c215SJeff Kirsher 2694aa43c215SJeff Kirsher return; 2695aa43c215SJeff Kirsher 2696aa43c215SJeff Kirsher err_ret: 2697aa43c215SJeff Kirsher netif_device_attach(netdev); 2698aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 2699aa43c215SJeff Kirsher } 2700aa43c215SJeff Kirsher 2701aa43c215SJeff Kirsher /*Transit NPAR state to NON Operational */ 2702aa43c215SJeff Kirsher static void 2703aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) 2704aa43c215SJeff Kirsher { 2705aa43c215SJeff Kirsher u32 state; 2706aa43c215SJeff Kirsher 2707a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2708aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NPAR_NON_OPER) 2709aa43c215SJeff Kirsher return; 2710aa43c215SJeff Kirsher 2711aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2712aa43c215SJeff Kirsher return; 2713a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 2714a15ebd37SHimanshu Madhani QLCNIC_DEV_NPAR_NON_OPER); 2715aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2716aa43c215SJeff Kirsher } 2717aa43c215SJeff Kirsher 27187e2cf4feSSony Chacko void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key) 2719aa43c215SJeff Kirsher { 2720646779f1SSritej Velaga u32 state, xg_val = 0, gb_val = 0; 2721aa43c215SJeff Kirsher 2722646779f1SSritej Velaga qlcnic_xg_set_xg0_mask(xg_val); 2723646779f1SSritej Velaga qlcnic_xg_set_xg1_mask(xg_val); 2724646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); 2725646779f1SSritej Velaga qlcnic_gb_set_gb0_mask(gb_val); 2726646779f1SSritej Velaga qlcnic_gb_set_gb1_mask(gb_val); 2727646779f1SSritej Velaga qlcnic_gb_set_gb2_mask(gb_val); 2728646779f1SSritej Velaga qlcnic_gb_set_gb3_mask(gb_val); 2729646779f1SSritej Velaga QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); 2730646779f1SSritej Velaga dev_info(&adapter->pdev->dev, "Pause control frames disabled" 2731646779f1SSritej Velaga " on all ports\n"); 2732aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 273313159183SSony Chacko 2734aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2735aa43c215SJeff Kirsher return; 2736aa43c215SJeff Kirsher 273713159183SSony Chacko state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2738aa43c215SJeff Kirsher 2739aa43c215SJeff Kirsher if (state == QLCNIC_DEV_READY) { 274013159183SSony Chacko QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 274113159183SSony Chacko QLCNIC_DEV_NEED_RESET); 2742aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_RESET_OWNER; 2743aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NEED_RESET state set\n"); 2744aa43c215SJeff Kirsher qlcnic_idc_debug_info(adapter, 0); 2745aa43c215SJeff Kirsher } 2746aa43c215SJeff Kirsher 274713159183SSony Chacko QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 274813159183SSony Chacko QLCNIC_DEV_NPAR_NON_OPER); 2749aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2750aa43c215SJeff Kirsher } 2751aa43c215SJeff Kirsher 2752aa43c215SJeff Kirsher /* Transit to NPAR READY state from NPAR NOT READY state */ 2753aa43c215SJeff Kirsher static void 2754aa43c215SJeff Kirsher qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 2755aa43c215SJeff Kirsher { 2756aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2757aa43c215SJeff Kirsher return; 2758aa43c215SJeff Kirsher 2759a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, 2760a15ebd37SHimanshu Madhani QLCNIC_DEV_NPAR_OPER); 2761aa43c215SJeff Kirsher QLCDB(adapter, DRV, "NPAR operational state set\n"); 2762aa43c215SJeff Kirsher 2763aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2764aa43c215SJeff Kirsher } 2765aa43c215SJeff Kirsher 276613159183SSony Chacko void qlcnic_schedule_work(struct qlcnic_adapter *adapter, 2767aa43c215SJeff Kirsher work_func_t func, int delay) 2768aa43c215SJeff Kirsher { 2769aa43c215SJeff Kirsher if (test_bit(__QLCNIC_AER, &adapter->state)) 2770aa43c215SJeff Kirsher return; 2771aa43c215SJeff Kirsher 2772aa43c215SJeff Kirsher INIT_DELAYED_WORK(&adapter->fw_work, func); 277313159183SSony Chacko queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work, 2774aa43c215SJeff Kirsher round_jiffies_relative(delay)); 2775aa43c215SJeff Kirsher } 2776aa43c215SJeff Kirsher 2777aa43c215SJeff Kirsher static void 2778aa43c215SJeff Kirsher qlcnic_attach_work(struct work_struct *work) 2779aa43c215SJeff Kirsher { 2780aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2781aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2782aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2783aa43c215SJeff Kirsher u32 npar_state; 2784aa43c215SJeff Kirsher 278579788450SSony Chacko if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) { 2786a15ebd37SHimanshu Madhani npar_state = QLC_SHARED_REG_RD32(adapter, 2787a15ebd37SHimanshu Madhani QLCNIC_CRB_DEV_NPAR_STATE); 2788aa43c215SJeff Kirsher if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) 2789aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 0); 2790aa43c215SJeff Kirsher else if (npar_state != QLCNIC_DEV_NPAR_OPER) 2791aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_attach_work, 2792aa43c215SJeff Kirsher FW_POLL_DELAY); 2793aa43c215SJeff Kirsher else 2794aa43c215SJeff Kirsher goto attach; 2795aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); 2796aa43c215SJeff Kirsher return; 2797aa43c215SJeff Kirsher } 2798aa43c215SJeff Kirsher attach: 2799aa43c215SJeff Kirsher if (netif_running(netdev)) { 2800aa43c215SJeff Kirsher if (qlcnic_up(adapter, netdev)) 2801aa43c215SJeff Kirsher goto done; 2802aa43c215SJeff Kirsher 2803aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2804aa43c215SJeff Kirsher } 2805aa43c215SJeff Kirsher 2806aa43c215SJeff Kirsher done: 2807aa43c215SJeff Kirsher netif_device_attach(netdev); 2808aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2809aa43c215SJeff Kirsher adapter->flags &= ~QLCNIC_FW_HANG; 2810aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 2811aa43c215SJeff Kirsher 2812aa43c215SJeff Kirsher if (!qlcnic_clr_drv_state(adapter)) 2813aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 2814aa43c215SJeff Kirsher FW_POLL_DELAY); 2815aa43c215SJeff Kirsher } 2816aa43c215SJeff Kirsher 2817aa43c215SJeff Kirsher static int 2818aa43c215SJeff Kirsher qlcnic_check_health(struct qlcnic_adapter *adapter) 2819aa43c215SJeff Kirsher { 2820aa43c215SJeff Kirsher u32 state = 0, heartbeat; 2821853d4bcaSAmeen Rahman u32 peg_status; 2822aa43c215SJeff Kirsher 2823aa43c215SJeff Kirsher if (qlcnic_check_temp(adapter)) 2824aa43c215SJeff Kirsher goto detach; 2825aa43c215SJeff Kirsher 2826aa43c215SJeff Kirsher if (adapter->need_fw_reset) 28277e2cf4feSSony Chacko qlcnic_dev_request_reset(adapter, 0); 2828aa43c215SJeff Kirsher 2829a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 2830aa43c215SJeff Kirsher if (state == QLCNIC_DEV_NEED_RESET) { 2831aa43c215SJeff Kirsher qlcnic_set_npar_non_operational(adapter); 2832aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2833aa43c215SJeff Kirsher } else if (state == QLCNIC_DEV_NEED_QUISCENT) 2834aa43c215SJeff Kirsher goto detach; 2835aa43c215SJeff Kirsher 2836a15ebd37SHimanshu Madhani heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 2837aa43c215SJeff Kirsher if (heartbeat != adapter->heartbeat) { 2838aa43c215SJeff Kirsher adapter->heartbeat = heartbeat; 2839aa43c215SJeff Kirsher adapter->fw_fail_cnt = 0; 2840aa43c215SJeff Kirsher if (adapter->need_fw_reset) 2841aa43c215SJeff Kirsher goto detach; 2842aa43c215SJeff Kirsher 2843099f7aa7SSony Chacko if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) { 2844aa43c215SJeff Kirsher qlcnic_reset_hw_context(adapter); 2845aa43c215SJeff Kirsher adapter->netdev->trans_start = jiffies; 2846aa43c215SJeff Kirsher } 2847aa43c215SJeff Kirsher 2848aa43c215SJeff Kirsher return 0; 2849aa43c215SJeff Kirsher } 2850aa43c215SJeff Kirsher 2851aa43c215SJeff Kirsher if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) 2852aa43c215SJeff Kirsher return 0; 2853aa43c215SJeff Kirsher 2854aa43c215SJeff Kirsher adapter->flags |= QLCNIC_FW_HANG; 2855aa43c215SJeff Kirsher 28567e2cf4feSSony Chacko qlcnic_dev_request_reset(adapter, 0); 2857aa43c215SJeff Kirsher 2858099f7aa7SSony Chacko if (qlcnic_auto_fw_reset) 2859aa43c215SJeff Kirsher clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); 2860aa43c215SJeff Kirsher 2861853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "firmware hang detected\n"); 2862a15ebd37SHimanshu Madhani peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1); 2863853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" 2864aa43c215SJeff Kirsher "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" 2865aa43c215SJeff Kirsher "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" 2866aa43c215SJeff Kirsher "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" 2867aa43c215SJeff Kirsher "PEG_NET_4_PC: 0x%x\n", 2868a15ebd37SHimanshu Madhani peg_status, 2869a15ebd37SHimanshu Madhani QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2), 2870aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), 2871aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), 2872aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), 2873aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), 2874aa43c215SJeff Kirsher QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); 287597048a1fSSritej Velaga if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) 2876853d4bcaSAmeen Rahman dev_err(&adapter->pdev->dev, 2877853d4bcaSAmeen Rahman "Firmware aborted with error code 0x00006700. " 2878853d4bcaSAmeen Rahman "Device is being reset.\n"); 2879aa43c215SJeff Kirsher detach: 2880aa43c215SJeff Kirsher adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : 2881aa43c215SJeff Kirsher QLCNIC_DEV_NEED_RESET; 2882aa43c215SJeff Kirsher 2883099f7aa7SSony Chacko if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING, 2884099f7aa7SSony Chacko &adapter->state)) { 2885aa43c215SJeff Kirsher 2886aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); 2887aa43c215SJeff Kirsher QLCDB(adapter, DRV, "fw recovery scheduled.\n"); 2888aa43c215SJeff Kirsher } 2889aa43c215SJeff Kirsher 2890aa43c215SJeff Kirsher return 1; 2891aa43c215SJeff Kirsher } 2892aa43c215SJeff Kirsher 2893aa43c215SJeff Kirsher static void 2894aa43c215SJeff Kirsher qlcnic_fw_poll_work(struct work_struct *work) 2895aa43c215SJeff Kirsher { 2896aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = container_of(work, 2897aa43c215SJeff Kirsher struct qlcnic_adapter, fw_work.work); 2898aa43c215SJeff Kirsher 2899aa43c215SJeff Kirsher if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 2900aa43c215SJeff Kirsher goto reschedule; 2901aa43c215SJeff Kirsher 2902aa43c215SJeff Kirsher 2903aa43c215SJeff Kirsher if (qlcnic_check_health(adapter)) 2904aa43c215SJeff Kirsher return; 2905aa43c215SJeff Kirsher 2906aa43c215SJeff Kirsher if (adapter->fhash.fnum) 2907aa43c215SJeff Kirsher qlcnic_prune_lb_filters(adapter); 2908aa43c215SJeff Kirsher 2909aa43c215SJeff Kirsher reschedule: 2910aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 2911aa43c215SJeff Kirsher } 2912aa43c215SJeff Kirsher 2913aa43c215SJeff Kirsher static int qlcnic_is_first_func(struct pci_dev *pdev) 2914aa43c215SJeff Kirsher { 2915aa43c215SJeff Kirsher struct pci_dev *oth_pdev; 2916aa43c215SJeff Kirsher int val = pdev->devfn; 2917aa43c215SJeff Kirsher 2918aa43c215SJeff Kirsher while (val-- > 0) { 2919aa43c215SJeff Kirsher oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr 2920aa43c215SJeff Kirsher (pdev->bus), pdev->bus->number, 2921aa43c215SJeff Kirsher PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); 2922aa43c215SJeff Kirsher if (!oth_pdev) 2923aa43c215SJeff Kirsher continue; 2924aa43c215SJeff Kirsher 2925aa43c215SJeff Kirsher if (oth_pdev->current_state != PCI_D3cold) { 2926aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 2927aa43c215SJeff Kirsher return 0; 2928aa43c215SJeff Kirsher } 2929aa43c215SJeff Kirsher pci_dev_put(oth_pdev); 2930aa43c215SJeff Kirsher } 2931aa43c215SJeff Kirsher return 1; 2932aa43c215SJeff Kirsher } 2933aa43c215SJeff Kirsher 2934aa43c215SJeff Kirsher static int qlcnic_attach_func(struct pci_dev *pdev) 2935aa43c215SJeff Kirsher { 2936aa43c215SJeff Kirsher int err, first_func; 2937aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 2938aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 2939aa43c215SJeff Kirsher 2940aa43c215SJeff Kirsher pdev->error_state = pci_channel_io_normal; 2941aa43c215SJeff Kirsher 2942aa43c215SJeff Kirsher err = pci_enable_device(pdev); 2943aa43c215SJeff Kirsher if (err) 2944aa43c215SJeff Kirsher return err; 2945aa43c215SJeff Kirsher 2946aa43c215SJeff Kirsher pci_set_power_state(pdev, PCI_D0); 2947aa43c215SJeff Kirsher pci_set_master(pdev); 2948aa43c215SJeff Kirsher pci_restore_state(pdev); 2949aa43c215SJeff Kirsher 2950aa43c215SJeff Kirsher first_func = qlcnic_is_first_func(pdev); 2951aa43c215SJeff Kirsher 2952aa43c215SJeff Kirsher if (qlcnic_api_lock(adapter)) 2953aa43c215SJeff Kirsher return -EINVAL; 2954aa43c215SJeff Kirsher 295579788450SSony Chacko if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { 2956aa43c215SJeff Kirsher adapter->need_fw_reset = 1; 2957aa43c215SJeff Kirsher set_bit(__QLCNIC_START_FW, &adapter->state); 2958a15ebd37SHimanshu Madhani QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, 2959a15ebd37SHimanshu Madhani QLCNIC_DEV_INITIALIZING); 2960aa43c215SJeff Kirsher QLCDB(adapter, DRV, "Restarting fw\n"); 2961aa43c215SJeff Kirsher } 2962aa43c215SJeff Kirsher qlcnic_api_unlock(adapter); 2963aa43c215SJeff Kirsher 296413159183SSony Chacko err = qlcnic_start_firmware(adapter); 2965aa43c215SJeff Kirsher if (err) 2966aa43c215SJeff Kirsher return err; 2967aa43c215SJeff Kirsher 2968aa43c215SJeff Kirsher qlcnic_clr_drv_state(adapter); 296913159183SSony Chacko kfree(adapter->msix_entries); 297013159183SSony Chacko adapter->msix_entries = NULL; 297113159183SSony Chacko err = qlcnic_setup_intr(adapter, 0); 297213159183SSony Chacko 297313159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 297413159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 297513159183SSony Chacko if (err) { 297613159183SSony Chacko dev_err(&adapter->pdev->dev, 297713159183SSony Chacko "failed to setup mbx interrupt\n"); 297813159183SSony Chacko qlcnic_clr_all_drv_state(adapter, 1); 297913159183SSony Chacko clear_bit(__QLCNIC_AER, &adapter->state); 298013159183SSony Chacko goto done; 298113159183SSony Chacko } 298213159183SSony Chacko } 2983aa43c215SJeff Kirsher 2984aa43c215SJeff Kirsher if (netif_running(netdev)) { 2985aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 2986aa43c215SJeff Kirsher if (err) { 2987aa43c215SJeff Kirsher qlcnic_clr_all_drv_state(adapter, 1); 2988aa43c215SJeff Kirsher clear_bit(__QLCNIC_AER, &adapter->state); 2989aa43c215SJeff Kirsher netif_device_attach(netdev); 2990aa43c215SJeff Kirsher return err; 2991aa43c215SJeff Kirsher } 2992aa43c215SJeff Kirsher 2993aa43c215SJeff Kirsher err = qlcnic_up(adapter, netdev); 2994aa43c215SJeff Kirsher if (err) 2995aa43c215SJeff Kirsher goto done; 2996aa43c215SJeff Kirsher 2997aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 2998aa43c215SJeff Kirsher } 2999aa43c215SJeff Kirsher done: 3000aa43c215SJeff Kirsher netif_device_attach(netdev); 3001aa43c215SJeff Kirsher return err; 3002aa43c215SJeff Kirsher } 3003aa43c215SJeff Kirsher 3004aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, 3005aa43c215SJeff Kirsher pci_channel_state_t state) 3006aa43c215SJeff Kirsher { 3007aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3008aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3009aa43c215SJeff Kirsher 3010aa43c215SJeff Kirsher if (state == pci_channel_io_perm_failure) 3011aa43c215SJeff Kirsher return PCI_ERS_RESULT_DISCONNECT; 3012aa43c215SJeff Kirsher 3013aa43c215SJeff Kirsher if (state == pci_channel_io_normal) 3014aa43c215SJeff Kirsher return PCI_ERS_RESULT_RECOVERED; 3015aa43c215SJeff Kirsher 3016aa43c215SJeff Kirsher set_bit(__QLCNIC_AER, &adapter->state); 3017aa43c215SJeff Kirsher netif_device_detach(netdev); 3018aa43c215SJeff Kirsher 3019aa43c215SJeff Kirsher cancel_delayed_work_sync(&adapter->fw_work); 3020aa43c215SJeff Kirsher 3021aa43c215SJeff Kirsher if (netif_running(netdev)) 3022aa43c215SJeff Kirsher qlcnic_down(adapter, netdev); 3023aa43c215SJeff Kirsher 302413159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 302513159183SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) 302613159183SSony Chacko qlcnic_83xx_config_intrpt(adapter, 0); 302713159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 302813159183SSony Chacko } 302913159183SSony Chacko 3030aa43c215SJeff Kirsher qlcnic_detach(adapter); 3031aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3032aa43c215SJeff Kirsher 3033aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3034aa43c215SJeff Kirsher 3035aa43c215SJeff Kirsher pci_save_state(pdev); 3036aa43c215SJeff Kirsher pci_disable_device(pdev); 3037aa43c215SJeff Kirsher 3038aa43c215SJeff Kirsher return PCI_ERS_RESULT_NEED_RESET; 3039aa43c215SJeff Kirsher } 3040aa43c215SJeff Kirsher 3041aa43c215SJeff Kirsher static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) 3042aa43c215SJeff Kirsher { 3043aa43c215SJeff Kirsher return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : 3044aa43c215SJeff Kirsher PCI_ERS_RESULT_RECOVERED; 3045aa43c215SJeff Kirsher } 3046aa43c215SJeff Kirsher 3047aa43c215SJeff Kirsher static void qlcnic_io_resume(struct pci_dev *pdev) 3048aa43c215SJeff Kirsher { 3049a15ebd37SHimanshu Madhani u32 state; 3050aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); 3051aa43c215SJeff Kirsher 3052aa43c215SJeff Kirsher pci_cleanup_aer_uncorrect_error_status(pdev); 3053a15ebd37SHimanshu Madhani state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE); 3054a15ebd37SHimanshu Madhani if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER, 3055a15ebd37SHimanshu Madhani &adapter->state)) 3056aa43c215SJeff Kirsher qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, 3057aa43c215SJeff Kirsher FW_POLL_DELAY); 3058aa43c215SJeff Kirsher } 3059aa43c215SJeff Kirsher 3060aa43c215SJeff Kirsher static int 3061aa43c215SJeff Kirsher qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3062aa43c215SJeff Kirsher { 3063aa43c215SJeff Kirsher int err; 3064aa43c215SJeff Kirsher 3065aa43c215SJeff Kirsher err = qlcnic_can_start_firmware(adapter); 3066aa43c215SJeff Kirsher if (err) 3067aa43c215SJeff Kirsher return err; 3068aa43c215SJeff Kirsher 3069aa43c215SJeff Kirsher err = qlcnic_check_npar_opertional(adapter); 3070aa43c215SJeff Kirsher if (err) 3071aa43c215SJeff Kirsher return err; 3072aa43c215SJeff Kirsher 3073aa43c215SJeff Kirsher err = qlcnic_initialize_nic(adapter); 3074aa43c215SJeff Kirsher if (err) 3075aa43c215SJeff Kirsher return err; 3076aa43c215SJeff Kirsher 3077aa43c215SJeff Kirsher qlcnic_check_options(adapter); 3078aa43c215SJeff Kirsher 3079aa43c215SJeff Kirsher err = qlcnic_set_eswitch_port_config(adapter); 3080aa43c215SJeff Kirsher if (err) 3081aa43c215SJeff Kirsher return err; 3082aa43c215SJeff Kirsher 3083aa43c215SJeff Kirsher adapter->need_fw_reset = 0; 3084aa43c215SJeff Kirsher 3085aa43c215SJeff Kirsher return err; 3086aa43c215SJeff Kirsher } 3087aa43c215SJeff Kirsher 3088319ecf12SSony Chacko int qlcnic_validate_max_rss(u8 max_hw, u8 val) 3089aa43c215SJeff Kirsher { 3090319ecf12SSony Chacko u32 max_allowed; 3091319ecf12SSony Chacko 3092319ecf12SSony Chacko if (max_hw > QLC_MAX_SDS_RINGS) { 3093319ecf12SSony Chacko max_hw = QLC_MAX_SDS_RINGS; 3094319ecf12SSony Chacko pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS); 3095aa43c215SJeff Kirsher } 3096aa43c215SJeff Kirsher 3097319ecf12SSony Chacko max_allowed = rounddown_pow_of_two(min_t(int, max_hw, 3098319ecf12SSony Chacko num_online_cpus())); 3099319ecf12SSony Chacko if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) { 3100319ecf12SSony Chacko pr_info("rss_ring valid range [2 - %x] in powers of 2\n", 3101319ecf12SSony Chacko max_allowed); 3102aa43c215SJeff Kirsher return -EINVAL; 3103aa43c215SJeff Kirsher } 3104aa43c215SJeff Kirsher return 0; 3105aa43c215SJeff Kirsher } 3106aa43c215SJeff Kirsher 3107319ecf12SSony Chacko int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len) 3108aa43c215SJeff Kirsher { 310913159183SSony Chacko int err; 3110aa43c215SJeff Kirsher struct net_device *netdev = adapter->netdev; 3111aa43c215SJeff Kirsher 3112319ecf12SSony Chacko if (test_bit(__QLCNIC_RESETTING, &adapter->state)) 3113319ecf12SSony Chacko return -EBUSY; 3114319ecf12SSony Chacko 3115aa43c215SJeff Kirsher netif_device_detach(netdev); 3116aa43c215SJeff Kirsher if (netif_running(netdev)) 3117aa43c215SJeff Kirsher __qlcnic_down(adapter, netdev); 311813159183SSony Chacko 3119319ecf12SSony Chacko if (qlcnic_82xx_check(adapter)) { 312013159183SSony Chacko if (adapter->flags & QLCNIC_MSIX_ENABLED) 312113159183SSony Chacko qlcnic_83xx_config_intrpt(adapter, 0); 312213159183SSony Chacko qlcnic_83xx_free_mbx_intr(adapter); 312313159183SSony Chacko } 312413159183SSony Chacko 3125aa43c215SJeff Kirsher qlcnic_detach(adapter); 3126aa43c215SJeff Kirsher qlcnic_teardown_intr(adapter); 3127319ecf12SSony Chacko err = qlcnic_setup_intr(adapter, data); 312813159183SSony Chacko if (err) 312913159183SSony Chacko dev_err(&adapter->pdev->dev, 313013159183SSony Chacko "failed setting max_rss; rss disabled\n"); 3131aa43c215SJeff Kirsher 313213159183SSony Chacko if (qlcnic_83xx_check(adapter)) { 313313159183SSony Chacko err = qlcnic_83xx_setup_mbx_intr(adapter); 313413159183SSony Chacko if (err) { 313513159183SSony Chacko dev_err(&adapter->pdev->dev, 313613159183SSony Chacko "failed to setup mbx interrupt\n"); 313713159183SSony Chacko goto done; 313813159183SSony Chacko } 3139aa43c215SJeff Kirsher } 3140aa43c215SJeff Kirsher 3141aa43c215SJeff Kirsher if (netif_running(netdev)) { 3142aa43c215SJeff Kirsher err = qlcnic_attach(adapter); 3143aa43c215SJeff Kirsher if (err) 3144aa43c215SJeff Kirsher goto done; 3145aa43c215SJeff Kirsher err = __qlcnic_up(adapter, netdev); 3146aa43c215SJeff Kirsher if (err) 3147aa43c215SJeff Kirsher goto done; 3148aa43c215SJeff Kirsher qlcnic_restore_indev_addr(netdev, NETDEV_UP); 3149aa43c215SJeff Kirsher } 3150319ecf12SSony Chacko err = len; 3151aa43c215SJeff Kirsher done: 3152aa43c215SJeff Kirsher netif_device_attach(netdev); 3153aa43c215SJeff Kirsher clear_bit(__QLCNIC_RESETTING, &adapter->state); 3154aa43c215SJeff Kirsher return err; 3155aa43c215SJeff Kirsher } 3156aa43c215SJeff Kirsher 3157aa43c215SJeff Kirsher #ifdef CONFIG_INET 3158aa43c215SJeff Kirsher 3159aa43c215SJeff Kirsher #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 3160aa43c215SJeff Kirsher 3161aa43c215SJeff Kirsher static void 3162aa43c215SJeff Kirsher qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, 3163aa43c215SJeff Kirsher struct net_device *dev, unsigned long event) 3164aa43c215SJeff Kirsher { 3165aa43c215SJeff Kirsher struct in_device *indev; 3166aa43c215SJeff Kirsher 3167aa43c215SJeff Kirsher indev = in_dev_get(dev); 3168aa43c215SJeff Kirsher if (!indev) 3169aa43c215SJeff Kirsher return; 3170aa43c215SJeff Kirsher 3171aa43c215SJeff Kirsher for_ifa(indev) { 3172aa43c215SJeff Kirsher switch (event) { 3173aa43c215SJeff Kirsher case NETDEV_UP: 3174aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 3175aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_UP); 3176aa43c215SJeff Kirsher break; 3177aa43c215SJeff Kirsher case NETDEV_DOWN: 3178aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, 3179aa43c215SJeff Kirsher ifa->ifa_address, QLCNIC_IP_DOWN); 3180aa43c215SJeff Kirsher break; 3181aa43c215SJeff Kirsher default: 3182aa43c215SJeff Kirsher break; 3183aa43c215SJeff Kirsher } 3184aa43c215SJeff Kirsher } endfor_ifa(indev); 3185aa43c215SJeff Kirsher 3186aa43c215SJeff Kirsher in_dev_put(indev); 3187aa43c215SJeff Kirsher } 3188aa43c215SJeff Kirsher 3189319ecf12SSony Chacko void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) 3190aa43c215SJeff Kirsher { 3191aa43c215SJeff Kirsher struct qlcnic_adapter *adapter = netdev_priv(netdev); 3192aa43c215SJeff Kirsher struct net_device *dev; 3193aa43c215SJeff Kirsher u16 vid; 3194aa43c215SJeff Kirsher 3195aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, netdev, event); 3196aa43c215SJeff Kirsher 319743c00a75SJiri Pirko rcu_read_lock(); 3198aa43c215SJeff Kirsher for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { 3199aa43c215SJeff Kirsher dev = __vlan_find_dev_deep(netdev, vid); 3200aa43c215SJeff Kirsher if (!dev) 3201aa43c215SJeff Kirsher continue; 3202aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 3203aa43c215SJeff Kirsher } 320443c00a75SJiri Pirko rcu_read_unlock(); 3205aa43c215SJeff Kirsher } 3206aa43c215SJeff Kirsher 3207aa43c215SJeff Kirsher static int qlcnic_netdev_event(struct notifier_block *this, 3208aa43c215SJeff Kirsher unsigned long event, void *ptr) 3209aa43c215SJeff Kirsher { 3210aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 3211aa43c215SJeff Kirsher struct net_device *dev = (struct net_device *)ptr; 3212aa43c215SJeff Kirsher 3213aa43c215SJeff Kirsher recheck: 3214aa43c215SJeff Kirsher if (dev == NULL) 3215aa43c215SJeff Kirsher goto done; 3216aa43c215SJeff Kirsher 3217aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 3218aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 3219aa43c215SJeff Kirsher goto recheck; 3220aa43c215SJeff Kirsher } 3221aa43c215SJeff Kirsher 3222aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 3223aa43c215SJeff Kirsher goto done; 3224aa43c215SJeff Kirsher 3225aa43c215SJeff Kirsher adapter = netdev_priv(dev); 3226aa43c215SJeff Kirsher 3227aa43c215SJeff Kirsher if (!adapter) 3228aa43c215SJeff Kirsher goto done; 3229aa43c215SJeff Kirsher 3230aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3231aa43c215SJeff Kirsher goto done; 3232aa43c215SJeff Kirsher 3233aa43c215SJeff Kirsher qlcnic_config_indev_addr(adapter, dev, event); 3234aa43c215SJeff Kirsher done: 3235aa43c215SJeff Kirsher return NOTIFY_DONE; 3236aa43c215SJeff Kirsher } 3237aa43c215SJeff Kirsher 3238aa43c215SJeff Kirsher static int 3239aa43c215SJeff Kirsher qlcnic_inetaddr_event(struct notifier_block *this, 3240aa43c215SJeff Kirsher unsigned long event, void *ptr) 3241aa43c215SJeff Kirsher { 3242aa43c215SJeff Kirsher struct qlcnic_adapter *adapter; 3243aa43c215SJeff Kirsher struct net_device *dev; 3244aa43c215SJeff Kirsher 3245aa43c215SJeff Kirsher struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 3246aa43c215SJeff Kirsher 3247aa43c215SJeff Kirsher dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 3248aa43c215SJeff Kirsher 3249aa43c215SJeff Kirsher recheck: 3250aa43c215SJeff Kirsher if (dev == NULL) 3251aa43c215SJeff Kirsher goto done; 3252aa43c215SJeff Kirsher 3253aa43c215SJeff Kirsher if (dev->priv_flags & IFF_802_1Q_VLAN) { 3254aa43c215SJeff Kirsher dev = vlan_dev_real_dev(dev); 3255aa43c215SJeff Kirsher goto recheck; 3256aa43c215SJeff Kirsher } 3257aa43c215SJeff Kirsher 3258aa43c215SJeff Kirsher if (!is_qlcnic_netdev(dev)) 3259aa43c215SJeff Kirsher goto done; 3260aa43c215SJeff Kirsher 3261aa43c215SJeff Kirsher adapter = netdev_priv(dev); 3262aa43c215SJeff Kirsher 3263aa43c215SJeff Kirsher if (!adapter) 3264aa43c215SJeff Kirsher goto done; 3265aa43c215SJeff Kirsher 3266aa43c215SJeff Kirsher if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 3267aa43c215SJeff Kirsher goto done; 3268aa43c215SJeff Kirsher 3269aa43c215SJeff Kirsher switch (event) { 3270aa43c215SJeff Kirsher case NETDEV_UP: 3271aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); 327213159183SSony Chacko 3273aa43c215SJeff Kirsher break; 3274aa43c215SJeff Kirsher case NETDEV_DOWN: 3275aa43c215SJeff Kirsher qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); 327613159183SSony Chacko 3277aa43c215SJeff Kirsher break; 3278aa43c215SJeff Kirsher default: 3279aa43c215SJeff Kirsher break; 3280aa43c215SJeff Kirsher } 3281aa43c215SJeff Kirsher 3282aa43c215SJeff Kirsher done: 3283aa43c215SJeff Kirsher return NOTIFY_DONE; 3284aa43c215SJeff Kirsher } 3285aa43c215SJeff Kirsher 3286aa43c215SJeff Kirsher static struct notifier_block qlcnic_netdev_cb = { 3287aa43c215SJeff Kirsher .notifier_call = qlcnic_netdev_event, 3288aa43c215SJeff Kirsher }; 3289aa43c215SJeff Kirsher 3290aa43c215SJeff Kirsher static struct notifier_block qlcnic_inetaddr_cb = { 3291aa43c215SJeff Kirsher .notifier_call = qlcnic_inetaddr_event, 3292aa43c215SJeff Kirsher }; 3293aa43c215SJeff Kirsher #else 3294f8ca2b6fSSony Chacko void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) 3295aa43c215SJeff Kirsher { } 3296aa43c215SJeff Kirsher #endif 329763507592SShahed Shaikh static struct pci_error_handlers qlcnic_err_handler = { 3298aa43c215SJeff Kirsher .error_detected = qlcnic_io_error_detected, 3299aa43c215SJeff Kirsher .slot_reset = qlcnic_io_slot_reset, 3300aa43c215SJeff Kirsher .resume = qlcnic_io_resume, 3301aa43c215SJeff Kirsher }; 3302aa43c215SJeff Kirsher 3303aa43c215SJeff Kirsher static struct pci_driver qlcnic_driver = { 3304aa43c215SJeff Kirsher .name = qlcnic_driver_name, 3305aa43c215SJeff Kirsher .id_table = qlcnic_pci_tbl, 3306aa43c215SJeff Kirsher .probe = qlcnic_probe, 33076bb58bb0SBill Pemberton .remove = qlcnic_remove, 3308aa43c215SJeff Kirsher #ifdef CONFIG_PM 3309aa43c215SJeff Kirsher .suspend = qlcnic_suspend, 3310aa43c215SJeff Kirsher .resume = qlcnic_resume, 3311aa43c215SJeff Kirsher #endif 3312aa43c215SJeff Kirsher .shutdown = qlcnic_shutdown, 3313aa43c215SJeff Kirsher .err_handler = &qlcnic_err_handler 3314aa43c215SJeff Kirsher 3315aa43c215SJeff Kirsher }; 3316aa43c215SJeff Kirsher 3317aa43c215SJeff Kirsher static int __init qlcnic_init_module(void) 3318aa43c215SJeff Kirsher { 3319aa43c215SJeff Kirsher int ret; 3320aa43c215SJeff Kirsher 3321aa43c215SJeff Kirsher printk(KERN_INFO "%s\n", qlcnic_driver_string); 3322aa43c215SJeff Kirsher 3323aa43c215SJeff Kirsher #ifdef CONFIG_INET 3324aa43c215SJeff Kirsher register_netdevice_notifier(&qlcnic_netdev_cb); 3325aa43c215SJeff Kirsher register_inetaddr_notifier(&qlcnic_inetaddr_cb); 3326aa43c215SJeff Kirsher #endif 3327aa43c215SJeff Kirsher 3328aa43c215SJeff Kirsher ret = pci_register_driver(&qlcnic_driver); 3329aa43c215SJeff Kirsher if (ret) { 3330aa43c215SJeff Kirsher #ifdef CONFIG_INET 3331aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 3332aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 3333aa43c215SJeff Kirsher #endif 3334aa43c215SJeff Kirsher } 3335aa43c215SJeff Kirsher 3336aa43c215SJeff Kirsher return ret; 3337aa43c215SJeff Kirsher } 3338aa43c215SJeff Kirsher 3339aa43c215SJeff Kirsher module_init(qlcnic_init_module); 3340aa43c215SJeff Kirsher 3341aa43c215SJeff Kirsher static void __exit qlcnic_exit_module(void) 3342aa43c215SJeff Kirsher { 3343aa43c215SJeff Kirsher pci_unregister_driver(&qlcnic_driver); 3344aa43c215SJeff Kirsher 3345aa43c215SJeff Kirsher #ifdef CONFIG_INET 3346aa43c215SJeff Kirsher unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); 3347aa43c215SJeff Kirsher unregister_netdevice_notifier(&qlcnic_netdev_cb); 3348aa43c215SJeff Kirsher #endif 3349aa43c215SJeff Kirsher } 3350aa43c215SJeff Kirsher 3351aa43c215SJeff Kirsher module_exit(qlcnic_exit_module); 3352