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