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