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