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