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