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