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