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