blob: 1c29105b6c364f0064da46f0e060e11208b2526e [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
Sritej Velaga40839129f2010-12-02 20:41:56 +00002 * QLogic qlcnic NIC Driver
Jitendra Kalsaria577ae392013-02-04 12:33:07 +00003 * Copyright (c) 2009-2013 QLogic Corporation
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004 *
Sritej Velaga40839129f2010-12-02 20:41:56 +00005 * See LICENSE.qlcnic for copyright and licensing details.
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00006 */
7
8#include <linux/vmalloc.h>
9#include <linux/interrupt.h>
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000010#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000011#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000012#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000013#include <net/ip.h>
14#include <linux/ipv6.h>
15#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000016#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000017#include <linux/log2.h>
Stephen Rothwell47caf252013-01-02 17:23:53 +000018#include <linux/pci.h>
Shahed Shaikh7f1f6052014-04-01 16:29:32 -040019#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -040020#include <net/vxlan.h>
Shahed Shaikh7f1f6052014-04-01 16:29:32 -040021#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000022
Harish Patila930a462015-08-07 07:17:02 -040023#include "qlcnic.h"
24#include "qlcnic_sriov.h"
25#include "qlcnic_hw.h"
26
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000027MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000028MODULE_LICENSE("GPL");
29MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
30MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
31
32char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000033static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
34 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000035
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000036static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000037module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000038MODULE_PARM_DESC(qlcnic_mac_learn,
39 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000040
Sony Chacko629263a2013-01-01 04:11:55 +000041int qlcnic_use_msi = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000042MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000043module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000044
Sony Chacko629263a2013-01-01 04:11:55 +000045int qlcnic_use_msi_x = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000046MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000047module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000048
Sony Chacko629263a2013-01-01 04:11:55 +000049int qlcnic_auto_fw_reset = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000050MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000051module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000052
Sony Chacko629263a2013-01-01 04:11:55 +000053int qlcnic_load_fw_file;
Shahed Shaikh3ced0a82014-08-27 12:43:20 -040054MODULE_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)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000055module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000056
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000057static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050058static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000059static int qlcnic_open(struct net_device *netdev);
60static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000061static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000062static void qlcnic_attach_work(struct work_struct *work);
63static void qlcnic_fwinit_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000064#ifdef CONFIG_NET_POLL_CONTROLLER
65static void qlcnic_poll_controller(struct net_device *netdev);
66#endif
67
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000068static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000069static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
70
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000071static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000072static irqreturn_t qlcnic_intr(int irq, void *data);
73static irqreturn_t qlcnic_msi_intr(int irq, void *data);
74static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000075static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000076
77static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000078static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000079
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000080static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000081static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000082static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000083static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
84static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000085
stephen hemminger21041402014-01-16 10:31:27 -080086static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *);
87static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *, u32);
88static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *);
89static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *);
90static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *);
91static void qlcnic_82xx_io_resume(struct pci_dev *);
92static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *);
93static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *,
94 pci_channel_state_t);
Sony Chacko13159182013-01-01 03:20:21 +000095static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
96{
97 struct qlcnic_hardware_context *ahw = adapter->ahw;
98
99 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
100 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
101 else
102 return 1;
103}
104
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000105/* PCI Device ID Table */
106#define ENTRY(device) \
107 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
108 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
109
Benoit Taine9baa3c32014-08-08 15:56:03 +0200110static const struct pci_device_id qlcnic_pci_tbl[] = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000112 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000113 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Shahed Shaikhda286a62015-08-07 07:17:05 -0400114 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE8830),
115 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE8C30),
Manish Chopra15ca1402013-08-16 19:07:13 -0400116 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X),
117 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000118 {0,}
119};
120
121MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
122
123
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000124inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000125{
126 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000127}
128
129static const u32 msi_tgt_status[8] = {
130 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
131 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
132 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
133 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
134};
135
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000136static const u32 qlcnic_reg_tbl[] = {
137 0x1B20A8, /* PEG_HALT_STAT1 */
138 0x1B20AC, /* PEG_HALT_STAT2 */
139 0x1B20B0, /* FW_HEARTBEAT */
140 0x1B2100, /* LOCK ID */
141 0x1B2128, /* FW_CAPABILITIES */
142 0x1B2138, /* drv active */
143 0x1B2140, /* dev state */
144 0x1B2144, /* drv state */
145 0x1B2148, /* drv scratch */
146 0x1B214C, /* dev partition info */
147 0x1B2174, /* drv idc ver */
148 0x1B2150, /* fw version major */
149 0x1B2154, /* fw version minor */
150 0x1B2158, /* fw version sub */
151 0x1B219C, /* npar state */
152 0x1B21FC, /* FW_IMG_VALID */
153 0x1B2250, /* CMD_PEG_STATE */
154 0x1B233C, /* RCV_PEG_STATE */
155 0x1B23B4, /* ASIC TEMP */
156 0x1B216C, /* FW api */
157 0x1B2170, /* drv op mode */
158 0x13C010, /* flash lock */
159 0x13C014, /* flash unlock */
160};
161
Sony Chacko22999792012-12-04 03:33:55 +0000162static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000163 { PCI_VENDOR_ID_QLOGIC,
Manish Chopra15ca1402013-08-16 19:07:13 -0400164 PCI_DEVICE_ID_QLOGIC_QLE844X,
165 0x0,
166 0x0,
167 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
168 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000169 PCI_DEVICE_ID_QLOGIC_QLE834X,
170 PCI_VENDOR_ID_QLOGIC,
171 0x24e,
172 "8300 Series Dual Port 10GbE Converged Network Adapter "
173 "(TCP/IP Networking)" },
174 { PCI_VENDOR_ID_QLOGIC,
175 PCI_DEVICE_ID_QLOGIC_QLE834X,
176 PCI_VENDOR_ID_QLOGIC,
177 0x243,
178 "8300 Series Single Port 10GbE Converged Network Adapter "
179 "(TCP/IP Networking)" },
180 { PCI_VENDOR_ID_QLOGIC,
181 PCI_DEVICE_ID_QLOGIC_QLE834X,
182 PCI_VENDOR_ID_QLOGIC,
183 0x24a,
184 "8300 Series Dual Port 10GbE Converged Network Adapter "
185 "(TCP/IP Networking)" },
186 { PCI_VENDOR_ID_QLOGIC,
187 PCI_DEVICE_ID_QLOGIC_QLE834X,
188 PCI_VENDOR_ID_QLOGIC,
189 0x246,
190 "8300 Series Dual Port 10GbE Converged Network Adapter "
191 "(TCP/IP Networking)" },
192 { PCI_VENDOR_ID_QLOGIC,
193 PCI_DEVICE_ID_QLOGIC_QLE834X,
194 PCI_VENDOR_ID_QLOGIC,
195 0x252,
196 "8300 Series Dual Port 10GbE Converged Network Adapter "
197 "(TCP/IP Networking)" },
198 { PCI_VENDOR_ID_QLOGIC,
199 PCI_DEVICE_ID_QLOGIC_QLE834X,
200 PCI_VENDOR_ID_QLOGIC,
201 0x26e,
202 "8300 Series Dual Port 10GbE Converged Network Adapter "
203 "(TCP/IP Networking)" },
204 { PCI_VENDOR_ID_QLOGIC,
205 PCI_DEVICE_ID_QLOGIC_QLE834X,
206 PCI_VENDOR_ID_QLOGIC,
207 0x260,
208 "8300 Series Dual Port 10GbE Converged Network Adapter "
209 "(TCP/IP Networking)" },
210 { PCI_VENDOR_ID_QLOGIC,
211 PCI_DEVICE_ID_QLOGIC_QLE834X,
212 PCI_VENDOR_ID_QLOGIC,
213 0x266,
214 "8300 Series Single Port 10GbE Converged Network Adapter "
215 "(TCP/IP Networking)" },
216 { PCI_VENDOR_ID_QLOGIC,
217 PCI_DEVICE_ID_QLOGIC_QLE834X,
218 PCI_VENDOR_ID_QLOGIC,
219 0x269,
220 "8300 Series Dual Port 10GbE Converged Network Adapter "
221 "(TCP/IP Networking)" },
222 { PCI_VENDOR_ID_QLOGIC,
223 PCI_DEVICE_ID_QLOGIC_QLE834X,
224 PCI_VENDOR_ID_QLOGIC,
225 0x271,
226 "8300 Series Dual Port 10GbE Converged Network Adapter "
227 "(TCP/IP Networking)" },
228 { PCI_VENDOR_ID_QLOGIC,
229 PCI_DEVICE_ID_QLOGIC_QLE834X,
230 0x0, 0x0, "8300 Series 1/10GbE Controller" },
231 { PCI_VENDOR_ID_QLOGIC,
Shahed Shaikh40e2b8e2014-08-27 12:43:18 -0400232 PCI_DEVICE_ID_QLOGIC_QLE8830,
233 0x0,
234 0x0,
235 "8830 Series 1/10GbE Controller" },
236 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000237 PCI_DEVICE_ID_QLOGIC_QLE824X,
238 PCI_VENDOR_ID_QLOGIC,
239 0x203,
240 "8200 Series Single Port 10GbE Converged Network Adapter"
241 "(TCP/IP Networking)" },
242 { PCI_VENDOR_ID_QLOGIC,
243 PCI_DEVICE_ID_QLOGIC_QLE824X,
244 PCI_VENDOR_ID_QLOGIC,
245 0x207,
246 "8200 Series Dual Port 10GbE Converged Network Adapter"
247 "(TCP/IP Networking)" },
248 { PCI_VENDOR_ID_QLOGIC,
249 PCI_DEVICE_ID_QLOGIC_QLE824X,
250 PCI_VENDOR_ID_QLOGIC,
251 0x20b,
252 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
253 { PCI_VENDOR_ID_QLOGIC,
254 PCI_DEVICE_ID_QLOGIC_QLE824X,
255 PCI_VENDOR_ID_QLOGIC,
256 0x20c,
257 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
258 { PCI_VENDOR_ID_QLOGIC,
259 PCI_DEVICE_ID_QLOGIC_QLE824X,
260 PCI_VENDOR_ID_QLOGIC,
261 0x20f,
262 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
263 { PCI_VENDOR_ID_QLOGIC,
264 PCI_DEVICE_ID_QLOGIC_QLE824X,
265 0x103c, 0x3733,
266 "NC523SFP 10Gb 2-port Server Adapter" },
267 { PCI_VENDOR_ID_QLOGIC,
268 PCI_DEVICE_ID_QLOGIC_QLE824X,
269 0x103c, 0x3346,
270 "CN1000Q Dual Port Converged Network Adapter" },
271 { PCI_VENDOR_ID_QLOGIC,
272 PCI_DEVICE_ID_QLOGIC_QLE824X,
273 PCI_VENDOR_ID_QLOGIC,
274 0x210,
275 "QME8242-k 10GbE Dual Port Mezzanine Card" },
276 { PCI_VENDOR_ID_QLOGIC,
277 PCI_DEVICE_ID_QLOGIC_QLE824X,
278 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000279};
280
281#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
282
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000283static const
284struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
285
Sony Chackoc70001a2012-11-28 04:34:26 +0000286int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000287{
288 int size = sizeof(struct qlcnic_host_sds_ring) * count;
289
290 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
291
Eric Dumazet807540b2010-09-23 05:40:09 +0000292 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000293}
294
Sony Chackoc70001a2012-11-28 04:34:26 +0000295void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000296{
Markus Elfring7061b2b2015-02-04 14:07:56 +0100297 kfree(recv_ctx->sds_rings);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000298 recv_ctx->sds_rings = NULL;
299}
300
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000301int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000302{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000303 struct net_device *netdev = adapter->netdev;
304 struct pci_dev *pdev = adapter->pdev;
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400305 u8 mac_addr[ETH_ALEN];
306 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000307
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400308 ret = qlcnic_get_mac_address(adapter, mac_addr,
309 adapter->ahw->pci_func);
310 if (ret)
311 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000312
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000313 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000314 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
315
316 /* set station address */
317
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000318 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000319 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
320 netdev->dev_addr);
321
322 return 0;
323}
324
Manish Chopracffe52f2013-05-09 09:25:09 +0000325static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
326{
Manish Chopra154d0c82013-12-17 09:01:53 -0500327 struct qlcnic_mac_vlan_list *cur;
Manish Chopracffe52f2013-05-09 09:25:09 +0000328 struct list_head *head;
329
330 list_for_each(head, &adapter->mac_list) {
Manish Chopra154d0c82013-12-17 09:01:53 -0500331 cur = list_entry(head, struct qlcnic_mac_vlan_list, list);
dingtianhong6878f792013-12-30 15:41:14 +0800332 if (ether_addr_equal_unaligned(adapter->mac_addr, cur->mac_addr)) {
Manish Chopracffe52f2013-05-09 09:25:09 +0000333 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
334 0, QLCNIC_MAC_DEL);
335 list_del(&cur->list);
336 kfree(cur);
337 return;
338 }
339 }
340}
341
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000342static int qlcnic_set_mac(struct net_device *netdev, void *p)
343{
344 struct qlcnic_adapter *adapter = netdev_priv(netdev);
345 struct sockaddr *addr = p;
346
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000347 if (qlcnic_sriov_vf_check(adapter))
348 return -EINVAL;
349
Rajesh Borundia73733732010-08-31 17:17:50 +0000350 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
351 return -EOPNOTSUPP;
352
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000353 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000354 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000355
Jarod Wilsone824de82015-11-06 09:25:31 -0500356 if (ether_addr_equal_unaligned(adapter->mac_addr, addr->sa_data) &&
357 ether_addr_equal_unaligned(netdev->dev_addr, addr->sa_data))
Manish Chopracffe52f2013-05-09 09:25:09 +0000358 return 0;
359
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000360 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000361 netif_device_detach(netdev);
362 qlcnic_napi_disable(adapter);
363 }
364
Manish Chopracffe52f2013-05-09 09:25:09 +0000365 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000366 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
367 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
368 qlcnic_set_multi(adapter->netdev);
369
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000370 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000371 netif_device_attach(netdev);
372 qlcnic_napi_enable(adapter);
373 }
374 return 0;
375}
376
Vlad Yasevich1690be62013-02-13 12:00:18 +0000377static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
Jiri Pirkof6f64242014-11-28 14:34:15 +0100378 struct net_device *netdev,
379 const unsigned char *addr, u16 vid)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000380{
381 struct qlcnic_adapter *adapter = netdev_priv(netdev);
382 int err = -EOPNOTSUPP;
383
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000384 if (!adapter->fdb_mac_learn)
Jiri Pirkof6f64242014-11-28 14:34:15 +0100385 return ndo_dflt_fdb_del(ndm, tb, netdev, addr, vid);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000386
Rajesh Borundiad747c332014-05-09 02:51:31 -0400387 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
388 qlcnic_sriov_check(adapter)) {
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400389 if (is_unicast_ether_addr(addr)) {
390 err = dev_uc_del(netdev, addr);
391 if (!err)
392 err = qlcnic_nic_del_mac(adapter, addr);
393 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000394 err = dev_mc_del(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400395 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000396 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400397 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000398 }
399 return err;
400}
401
402static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
403 struct net_device *netdev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100404 const unsigned char *addr, u16 vid, u16 flags)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000405{
406 struct qlcnic_adapter *adapter = netdev_priv(netdev);
407 int err = 0;
408
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000409 if (!adapter->fdb_mac_learn)
Jiri Pirkof6f64242014-11-28 14:34:15 +0100410 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, vid, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000411
Rajesh Borundiad747c332014-05-09 02:51:31 -0400412 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) &&
413 !qlcnic_sriov_check(adapter)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000414 pr_info("%s: FDB e-switch is not enabled\n", __func__);
415 return -EOPNOTSUPP;
416 }
417
418 if (ether_addr_equal(addr, adapter->mac_addr))
419 return err;
420
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400421 if (is_unicast_ether_addr(addr)) {
422 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
423 err = dev_uc_add_excl(netdev, addr);
424 else
425 err = -ENOMEM;
426 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000427 err = dev_mc_add_excl(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400428 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000429 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400430 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000431
432 return err;
433}
434
435static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400436 struct net_device *netdev,
437 struct net_device *filter_dev, int idx)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000438{
439 struct qlcnic_adapter *adapter = netdev_priv(netdev);
440
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000441 if (!adapter->fdb_mac_learn)
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400442 return ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000443
Rajesh Borundiad747c332014-05-09 02:51:31 -0400444 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
445 qlcnic_sriov_check(adapter))
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400446 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, filter_dev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000447
448 return idx;
449}
450
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000451static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
452{
453 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
454 usleep_range(10000, 11000);
455
Sucheta Chakraborty66451612013-09-27 02:12:36 -0400456 if (!adapter->fw_work.work.func)
457 return;
458
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000459 cancel_delayed_work_sync(&adapter->fw_work);
460}
461
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400462static int qlcnic_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +0100463 struct netdev_phys_item_id *ppid)
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400464{
465 struct qlcnic_adapter *adapter = netdev_priv(netdev);
466 struct qlcnic_hardware_context *ahw = adapter->ahw;
467
468 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID))
469 return -EOPNOTSUPP;
470
471 ppid->id_len = sizeof(ahw->phys_port_id);
472 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len);
473
474 return 0;
475}
476
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400477#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400478static void qlcnic_add_vxlan_port(struct net_device *netdev,
479 sa_family_t sa_family, __be16 port)
480{
481 struct qlcnic_adapter *adapter = netdev_priv(netdev);
482 struct qlcnic_hardware_context *ahw = adapter->ahw;
483
484 /* Adapter supports only one VXLAN port. Use very first port
485 * for enabling offload
486 */
Jiri Benc378fddc2015-09-17 16:11:12 +0200487 if (!qlcnic_encap_rx_offload(adapter))
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400488 return;
Jiri Benc378fddc2015-09-17 16:11:12 +0200489 if (!ahw->vxlan_port_count) {
490 ahw->vxlan_port_count = 1;
491 ahw->vxlan_port = ntohs(port);
492 adapter->flags |= QLCNIC_ADD_VXLAN_PORT;
493 return;
494 }
495 if (ahw->vxlan_port == ntohs(port))
496 ahw->vxlan_port_count++;
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400497
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400498}
499
500static void qlcnic_del_vxlan_port(struct net_device *netdev,
501 sa_family_t sa_family, __be16 port)
502{
503 struct qlcnic_adapter *adapter = netdev_priv(netdev);
504 struct qlcnic_hardware_context *ahw = adapter->ahw;
505
Jiri Benc378fddc2015-09-17 16:11:12 +0200506 if (!qlcnic_encap_rx_offload(adapter) || !ahw->vxlan_port_count ||
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400507 (ahw->vxlan_port != ntohs(port)))
508 return;
509
Jiri Benc378fddc2015-09-17 16:11:12 +0200510 ahw->vxlan_port_count--;
511 if (!ahw->vxlan_port_count)
512 adapter->flags |= QLCNIC_DEL_VXLAN_PORT;
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400513}
Joe Stringer795a05c2014-11-13 16:38:15 -0800514
Jesse Gross5f352272014-12-23 22:37:26 -0800515static netdev_features_t qlcnic_features_check(struct sk_buff *skb,
516 struct net_device *dev,
517 netdev_features_t features)
Joe Stringer795a05c2014-11-13 16:38:15 -0800518{
Toshiaki Makita8cb65d02015-03-27 14:31:12 +0900519 features = vlan_features_check(skb, features);
Jesse Gross5f352272014-12-23 22:37:26 -0800520 return vxlan_features_check(skb, features);
Joe Stringer795a05c2014-11-13 16:38:15 -0800521}
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400522#endif
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400523
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000524static const struct net_device_ops qlcnic_netdev_ops = {
525 .ndo_open = qlcnic_open,
526 .ndo_stop = qlcnic_close,
527 .ndo_start_xmit = qlcnic_xmit_frame,
528 .ndo_get_stats = qlcnic_get_stats,
529 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000530 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000531 .ndo_set_mac_address = qlcnic_set_mac,
532 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000533 .ndo_fix_features = qlcnic_fix_features,
534 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000535 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000536 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
537 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000538 .ndo_fdb_add = qlcnic_fdb_add,
539 .ndo_fdb_del = qlcnic_fdb_del,
540 .ndo_fdb_dump = qlcnic_fdb_dump,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400541 .ndo_get_phys_port_id = qlcnic_get_phys_port_id,
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400542#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400543 .ndo_add_vxlan_port = qlcnic_add_vxlan_port,
544 .ndo_del_vxlan_port = qlcnic_del_vxlan_port,
Jesse Gross5f352272014-12-23 22:37:26 -0800545 .ndo_features_check = qlcnic_features_check,
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400546#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000547#ifdef CONFIG_NET_POLL_CONTROLLER
548 .ndo_poll_controller = qlcnic_poll_controller,
549#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000550#ifdef CONFIG_QLCNIC_SRIOV
551 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -0400552 .ndo_set_vf_rate = qlcnic_sriov_set_vf_tx_rate,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000553 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000554 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundiaa80be5a2013-05-23 21:04:25 +0000555 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000556#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000557};
558
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000559static const struct net_device_ops qlcnic_netdev_failed_ops = {
560 .ndo_open = qlcnic_open,
561};
562
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000563static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000564 .config_bridged_mode = qlcnic_config_bridged_mode,
565 .config_led = qlcnic_82xx_config_led,
566 .start_firmware = qlcnic_82xx_start_firmware,
567 .request_reset = qlcnic_82xx_dev_request_reset,
568 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
569 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000570 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000571 .config_ipaddr = qlcnic_82xx_config_ipaddr,
Rajesh Borundia486a5bc2013-06-22 04:12:06 -0400572 .shutdown = qlcnic_82xx_shutdown,
573 .resume = qlcnic_82xx_resume,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000574 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000575};
576
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000577struct qlcnic_nic_template qlcnic_vf_ops = {
578 .config_bridged_mode = qlcnicvf_config_bridged_mode,
579 .config_led = qlcnicvf_config_led,
580 .start_firmware = qlcnicvf_start_firmware
581};
582
583static struct qlcnic_hardware_ops qlcnic_hw_ops = {
584 .read_crb = qlcnic_82xx_read_crb,
585 .write_crb = qlcnic_82xx_write_crb,
586 .read_reg = qlcnic_82xx_hw_read_wx_2M,
587 .write_reg = qlcnic_82xx_hw_write_wx_2M,
588 .get_mac_address = qlcnic_82xx_get_mac_address,
589 .setup_intr = qlcnic_82xx_setup_intr,
590 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
591 .mbx_cmd = qlcnic_82xx_issue_cmd,
592 .get_func_no = qlcnic_82xx_get_func_no,
593 .api_lock = qlcnic_82xx_api_lock,
594 .api_unlock = qlcnic_82xx_api_unlock,
595 .add_sysfs = qlcnic_82xx_add_sysfs,
596 .remove_sysfs = qlcnic_82xx_remove_sysfs,
597 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
598 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
599 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000600 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
601 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000602 .setup_link_event = qlcnic_82xx_linkevent_request,
603 .get_nic_info = qlcnic_82xx_get_nic_info,
604 .get_pci_info = qlcnic_82xx_get_pci_info,
605 .set_nic_info = qlcnic_82xx_set_nic_info,
606 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
607 .napi_enable = qlcnic_82xx_napi_enable,
608 .napi_disable = qlcnic_82xx_napi_disable,
609 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
610 .config_rss = qlcnic_82xx_config_rss,
611 .config_hw_lro = qlcnic_82xx_config_hw_lro,
612 .config_loopback = qlcnic_82xx_set_lb_mode,
613 .clear_loopback = qlcnic_82xx_clear_lb_mode,
614 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
615 .change_l2_filter = qlcnic_82xx_change_filter,
616 .get_board_info = qlcnic_82xx_get_board_info,
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400617 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000618 .free_mac_list = qlcnic_82xx_free_mac_list,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400619 .read_phys_port_id = qlcnic_82xx_read_phys_port_id,
Pratik Pujar4460f2e2013-08-30 13:51:20 -0400620 .io_error_detected = qlcnic_82xx_io_error_detected,
621 .io_slot_reset = qlcnic_82xx_io_slot_reset,
622 .io_resume = qlcnic_82xx_io_resume,
Himanshu Madhania0431582014-01-10 11:48:56 -0500623 .get_beacon_state = qlcnic_82xx_get_beacon_state,
Manish chopra2cc57522014-01-23 17:18:30 -0500624 .enable_sds_intr = qlcnic_82xx_enable_sds_intr,
625 .disable_sds_intr = qlcnic_82xx_disable_sds_intr,
626 .enable_tx_intr = qlcnic_82xx_enable_tx_intr,
627 .disable_tx_intr = qlcnic_82xx_disable_tx_intr,
Shahed Shaikh225837a2014-02-21 13:20:10 -0500628 .get_saved_state = qlcnic_82xx_get_saved_state,
629 .set_saved_state = qlcnic_82xx_set_saved_state,
630 .cache_tmpl_hdr_values = qlcnic_82xx_cache_tmpl_hdr_values,
631 .get_cap_size = qlcnic_82xx_get_cap_size,
632 .set_sys_info = qlcnic_82xx_set_sys_info,
633 .store_cap_mask = qlcnic_82xx_store_cap_mask,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000634};
635
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500636static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter *adapter)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400637{
638 struct qlcnic_hardware_context *ahw = adapter->ahw;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400639
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500640 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400641 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500642 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
643 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400644 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500645 return 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400646 }
647}
648
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500649static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt,
650 int queue_type)
651{
652 int num_rings, max_rings = QLCNIC_MAX_SDS_RINGS;
653
654 if (queue_type == QLCNIC_RX_QUEUE)
655 max_rings = adapter->max_sds_rings;
656 else if (queue_type == QLCNIC_TX_QUEUE)
657 max_rings = adapter->max_tx_rings;
658
659 num_rings = rounddown_pow_of_two(min_t(int, num_online_cpus(),
660 max_rings));
661
662 if (ring_cnt > num_rings)
663 return num_rings;
664 else
665 return ring_cnt;
666}
667
668void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt)
669{
670 /* 83xx adapter does not have max_tx_rings intialized in probe */
671 if (adapter->max_tx_rings)
672 adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt,
673 QLCNIC_TX_QUEUE);
674 else
675 adapter->drv_tx_rings = tx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500676}
677
678void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt)
679{
680 /* 83xx adapter does not have max_sds_rings intialized in probe */
681 if (adapter->max_sds_rings)
682 adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt,
683 QLCNIC_RX_QUEUE);
684 else
685 adapter->drv_sds_rings = rx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500686}
687
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500688int qlcnic_setup_tss_rss_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000689{
690 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500691 int num_msix = 0, err = 0, vector;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000692
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500693 adapter->flags &= ~QLCNIC_TSS_RSS;
694
695 if (adapter->drv_tss_rings > 0)
696 num_msix += adapter->drv_tss_rings;
697 else
698 num_msix += adapter->drv_tx_rings;
699
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200700 if (adapter->drv_rss_rings > 0)
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500701 num_msix += adapter->drv_rss_rings;
702 else
703 num_msix += adapter->drv_sds_rings;
704
705 if (qlcnic_83xx_check(adapter))
706 num_msix += 1;
Sony Chacko13159182013-01-01 03:20:21 +0000707
708 if (!adapter->msix_entries) {
709 adapter->msix_entries = kcalloc(num_msix,
710 sizeof(struct msix_entry),
711 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000712 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000713 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000714 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000715
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500716 for (vector = 0; vector < num_msix; vector++)
717 adapter->msix_entries[vector].entry = vector;
718
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200719restore:
Alexander Gordeevf7167752014-04-25 11:43:50 +0200720 err = pci_enable_msix_exact(pdev, adapter->msix_entries, num_msix);
721 if (err == -ENOSPC) {
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200722 if (!adapter->drv_tss_rings && !adapter->drv_rss_rings)
Alexander Gordeevf7167752014-04-25 11:43:50 +0200723 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500724
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500725 netdev_info(adapter->netdev,
726 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
727 num_msix, err);
728
729 num_msix = adapter->drv_tx_rings + adapter->drv_sds_rings;
730
731 /* Set rings to 0 so we can restore original TSS/RSS count */
732 adapter->drv_tss_rings = 0;
733 adapter->drv_rss_rings = 0;
734
735 if (qlcnic_83xx_check(adapter))
736 num_msix += 1;
737
738 netdev_info(adapter->netdev,
739 "Restoring %d Tx, %d SDS rings for total %d vectors.\n",
740 adapter->drv_tx_rings, adapter->drv_sds_rings,
741 num_msix);
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500742
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200743 goto restore;
744 } else if (err < 0) {
745 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500746 }
747
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200748 adapter->ahw->num_msix = num_msix;
749 if (adapter->drv_tss_rings > 0)
750 adapter->drv_tx_rings = adapter->drv_tss_rings;
751
752 if (adapter->drv_rss_rings > 0)
753 adapter->drv_sds_rings = adapter->drv_rss_rings;
754
755 return 0;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500756}
757
758int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
759{
760 struct pci_dev *pdev = adapter->pdev;
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100761 int err, vector;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500762
763 if (!adapter->msix_entries) {
764 adapter->msix_entries = kcalloc(num_msix,
765 sizeof(struct msix_entry),
766 GFP_KERNEL);
767 if (!adapter->msix_entries)
768 return -ENOMEM;
769 }
770
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000771 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000772
Sony Chacko79788452012-12-04 03:33:53 +0000773 if (adapter->ahw->msix_supported) {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500774enable_msix:
775 for (vector = 0; vector < num_msix; vector++)
776 adapter->msix_entries[vector].entry = vector;
777
Alexander Gordeev9732ec02014-02-18 11:11:57 +0100778 err = pci_enable_msix_range(pdev,
779 adapter->msix_entries, 1, num_msix);
780
781 if (err == num_msix) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000782 adapter->flags |= QLCNIC_MSIX_ENABLED;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500783 adapter->ahw->num_msix = num_msix;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000784 dev_info(&pdev->dev, "using msi-x interrupts\n");
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100785 return 0;
Sony Chacko13159182013-01-01 03:20:21 +0000786 } else if (err > 0) {
Alexander Gordeev9732ec02014-02-18 11:11:57 +0100787 pci_disable_msix(pdev);
788
Sony Chacko13159182013-01-01 03:20:21 +0000789 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500790 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
791 num_msix, err);
792
793 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +0000794 num_msix = rounddown_pow_of_two(err);
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500795 if (err < QLCNIC_82XX_MINIMUM_VECTOR)
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100796 return -ENOSPC;
Sony Chacko13159182013-01-01 03:20:21 +0000797 } else {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500798 num_msix = rounddown_pow_of_two(err - 1);
799 num_msix += 1;
800 if (err < QLCNIC_83XX_MINIMUM_VECTOR)
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100801 return -ENOSPC;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500802 }
803
804 if (qlcnic_82xx_check(adapter) &&
805 !qlcnic_check_multi_tx(adapter)) {
806 adapter->drv_sds_rings = num_msix;
807 adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
808 } else {
809 /* Distribute vectors equally */
810 adapter->drv_tx_rings = num_msix / 2;
811 adapter->drv_sds_rings = adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000812 }
813
814 if (num_msix) {
815 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000816 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000817 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000818 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000819 }
820 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000821 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500822 "Unable to allocate %d MSI-X vectors, err=%d\n",
823 num_msix, err);
824 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000825 }
826 }
Sony Chacko13159182013-01-01 03:20:21 +0000827
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100828 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000829}
830
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500831static int qlcnic_82xx_calculate_msix_vector(struct qlcnic_adapter *adapter)
832{
833 int num_msix;
834
835 num_msix = adapter->drv_sds_rings;
836
837 if (qlcnic_check_multi_tx(adapter))
838 num_msix += adapter->drv_tx_rings;
839 else
840 num_msix += QLCNIC_SINGLE_RING;
841
842 return num_msix;
843}
844
Manish chopra9a97e702013-01-25 10:20:37 +0000845static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000846{
Manish chopra9a97e702013-01-25 10:20:37 +0000847 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000848 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000849 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000850 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000851 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000852
Sony Chacko099f7aa2012-12-04 03:33:58 +0000853 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000854 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000855 offset = msi_tgt_status[adapter->ahw->pci_func];
856 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
857 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000858 dev_info(&pdev->dev, "using msi interrupts\n");
859 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000860 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000861 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400862
Manish chopra9a97e702013-01-25 10:20:37 +0000863 if (qlcnic_use_msi || qlcnic_use_msi_x)
864 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000865
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000866 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000867 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000868 offset = legacy_intrp->tgt_status_reg;
869 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
870 mask_reg = legacy_intrp->tgt_mask_reg;
871 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
872 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
873 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000874 dev_info(&pdev->dev, "using legacy interrupts\n");
875 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000876 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000877}
878
stephen hemminger21041402014-01-16 10:31:27 -0800879static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000880{
Manish chopra9a97e702013-01-25 10:20:37 +0000881 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000882
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500883 if (adapter->flags & QLCNIC_TSS_RSS) {
884 err = qlcnic_setup_tss_rss_intr(adapter);
885 if (err < 0)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400886 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500887 num_msix = adapter->ahw->num_msix;
888 } else {
889 num_msix = qlcnic_82xx_calculate_msix_vector(adapter);
890
891 err = qlcnic_enable_msix(adapter, num_msix);
892 if (err == -ENOMEM)
893 return err;
894
895 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
896 qlcnic_disable_multi_tx(adapter);
Rajesh Borundia42beb3f2014-02-24 08:54:49 -0500897 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500898
899 err = qlcnic_enable_msi_legacy(adapter);
Shahed Shaikhfc49bea2014-02-24 08:54:46 -0500900 if (err)
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500901 return err;
902 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400903 }
904
905 return 0;
906}
907
908int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
909{
910 struct qlcnic_hardware_context *ahw = adapter->ahw;
911 int err, i;
912
913 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400914 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400915 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
916 ahw->intr_tbl = vzalloc(ahw->num_msix *
917 sizeof(struct qlcnic_intrpt_config));
918 if (!ahw->intr_tbl)
919 return -ENOMEM;
920
921 for (i = 0; i < ahw->num_msix; i++) {
922 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
923 ahw->intr_tbl[i].id = i;
924 ahw->intr_tbl[i].src = 0;
925 }
926
927 err = qlcnic_82xx_config_intrpt(adapter, 1);
928 if (err)
929 dev_err(&adapter->pdev->dev,
930 "Failed to configure Interrupt for %d vector\n",
931 ahw->num_msix);
932 return err;
933 }
934
935 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000936}
Sony Chacko13159182013-01-01 03:20:21 +0000937
Sony Chacko319ecf12013-01-01 03:20:22 +0000938void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000939{
940 if (adapter->flags & QLCNIC_MSIX_ENABLED)
941 pci_disable_msix(adapter->pdev);
942 if (adapter->flags & QLCNIC_MSI_ENABLED)
943 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000944
945 kfree(adapter->msix_entries);
946 adapter->msix_entries = NULL;
947
948 if (adapter->ahw->intr_tbl) {
949 vfree(adapter->ahw->intr_tbl);
950 adapter->ahw->intr_tbl = NULL;
951 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000952}
953
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000954static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000955{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000956 if (ahw->pci_base0 != NULL)
957 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000958}
959
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000960static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
961{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500962 struct qlcnic_hardware_context *ahw = adapter->ahw;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000963 struct qlcnic_pci_info *pci_info;
964 int ret;
965
966 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500967 switch (ahw->port_type) {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000968 case QLCNIC_GBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500969 ahw->total_nic_func = QLCNIC_NIU_MAX_GBE_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000970 break;
971 case QLCNIC_XGBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500972 ahw->total_nic_func = QLCNIC_NIU_MAX_XG_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000973 break;
974 }
975 return 0;
976 }
977
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500978 if (ahw->op_mode == QLCNIC_MGMT_FUNC)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000979 return 0;
980
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500981 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000982 if (!pci_info)
983 return -ENOMEM;
984
985 ret = qlcnic_get_pci_info(adapter, pci_info);
986 kfree(pci_info);
987 return ret;
988}
Sony Chackod71170f2013-01-01 03:20:26 +0000989
Sony Chacko35dafcb2013-08-30 13:51:23 -0400990static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
991{
992 bool ret = false;
993
994 if (qlcnic_84xx_check(adapter)) {
995 ret = true;
996 } else if (qlcnic_83xx_check(adapter)) {
997 if (adapter->ahw->extra_capability[0] &
998 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
999 ret = true;
1000 else
1001 ret = false;
1002 }
1003
1004 return ret;
1005}
1006
Sony Chackod71170f2013-01-01 03:20:26 +00001007int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001008{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001009 struct qlcnic_hardware_context *ahw = adapter->ahw;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001010 struct qlcnic_pci_info *pci_info;
Sony Chacko4c776aa2013-10-18 12:22:32 -04001011 int i, id = 0, ret = 0, j = 0;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001012 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001013 u8 pfn;
1014
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001015 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +00001016 if (!pci_info)
1017 return -ENOMEM;
1018
Sony Chackobff57d8e2012-12-04 03:33:56 +00001019 ret = qlcnic_get_pci_info(adapter, pci_info);
1020 if (ret)
1021 goto err_pci_info;
1022
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001023 act_pci_func = ahw->total_nic_func;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001024
Dan Carpenterca315ac2010-08-09 21:47:56 +00001025 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d8e2012-12-04 03:33:56 +00001026 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +00001027 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +00001028 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001029 goto err_pci_info;
1030 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001031
Dan Carpenterca315ac2010-08-09 21:47:56 +00001032 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001033 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
1034 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +00001035 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001036 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001037 }
1038
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001039 for (i = 0; i < ahw->max_vnic_func; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +00001040 pfn = pci_info[i].id;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001041
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001042 if (pfn >= ahw->max_vnic_func) {
Vladimir Zapolskiyd7a32b62015-05-26 03:49:45 +03001043 ret = -EINVAL;
Sucheta Chakrabortyc65762f2014-04-25 17:43:59 -04001044 dev_err(&adapter->pdev->dev, "%s: Invalid function 0x%x, max 0x%x\n",
1045 __func__, pfn, ahw->max_vnic_func);
Sony Chackof848d6d2011-04-01 14:27:59 +00001046 goto err_eswitch;
1047 }
Sony Chackobff57d8e2012-12-04 03:33:56 +00001048
1049 if (!pci_info[i].active ||
1050 (pci_info[i].type != QLCNIC_TYPE_NIC))
1051 continue;
1052
Sony Chacko35dafcb2013-08-30 13:51:23 -04001053 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko4c776aa2013-10-18 12:22:32 -04001054 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn,
1055 &id))
Sony Chacko35dafcb2013-08-30 13:51:23 -04001056 adapter->npars[j].eswitch_status = true;
1057 else
1058 continue;
1059 } else {
1060 adapter->npars[j].eswitch_status = true;
1061 }
1062
Sony Chackobff57d8e2012-12-04 03:33:56 +00001063 adapter->npars[j].pci_func = pfn;
1064 adapter->npars[j].active = (u8)pci_info[i].active;
1065 adapter->npars[j].type = (u8)pci_info[i].type;
1066 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
1067 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
1068 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001069
Sucheta Chakraborty9e630952013-10-18 12:22:28 -04001070 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN);
Sony Chackobff57d8e2012-12-04 03:33:56 +00001071 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001072 }
1073
Sony Chacko4c776aa2013-10-18 12:22:32 -04001074 /* Update eSwitch status for adapters without per port eSwitch
1075 * configuration capability
1076 */
1077 if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001078 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
1079 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +00001080 }
Dan Carpenterca315ac2010-08-09 21:47:56 +00001081
Dan Carpentere88db3b2010-08-09 21:49:36 +00001082 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001083 return 0;
1084
1085err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001086 kfree(adapter->eswitch);
1087 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001088err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001089 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001090 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001091err_pci_info:
1092 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001093
1094 return ret;
1095}
1096
1097static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001098qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
1099{
1100 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001101 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001102 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001103 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001104
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001105 ret = qlcnic_api_lock(adapter);
1106 if (ret)
1107 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001108
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001109 id = ahw->pci_func;
1110 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
1111 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
1112 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001113 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001114 qlcnic_api_unlock(adapter);
1115err_lock:
1116 return ret;
1117}
1118
Sony Chacko13159182013-01-01 03:20:21 +00001119static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
1120 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001121{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001122 u32 op_mode, priv_level;
1123
1124 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +00001125 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
1126 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001127
1128 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +00001129 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001130
1131 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +00001132 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001133 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001134 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001135 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001136 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001137
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001138 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001139 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001140 dev_info(&adapter->pdev->dev,
1141 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001142 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001143 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001144 } else
1145 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001146}
1147
Sony Chacko15087c22012-12-04 03:33:54 +00001148#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +00001149#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +00001150static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001151{
Sony Chacko15087c22012-12-04 03:33:54 +00001152 switch (dev_id) {
1153 case PCI_DEVICE_ID_QLOGIC_QLE824X:
1154 *bar = QLCNIC_82XX_BAR0_LENGTH;
1155 break;
Sony Chacko13159182013-01-01 03:20:21 +00001156 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Shahed Shaikh40e2b8e2014-08-27 12:43:18 -04001157 case PCI_DEVICE_ID_QLOGIC_QLE8830:
Manish Chopra15ca1402013-08-16 19:07:13 -04001158 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001159 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001160 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Shahed Shaikhda286a62015-08-07 07:17:05 -04001161 case PCI_DEVICE_ID_QLOGIC_VF_QLE8C30:
Sony Chacko13159182013-01-01 03:20:21 +00001162 *bar = QLCNIC_83XX_BAR0_LENGTH;
1163 break;
Sony Chacko15087c22012-12-04 03:33:54 +00001164 default:
1165 *bar = 0;
1166 }
1167}
1168
1169static int qlcnic_setup_pci_map(struct pci_dev *pdev,
1170 struct qlcnic_hardware_context *ahw)
1171{
1172 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001173 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +00001174 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001175
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001176 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001177 mem_len = pci_resource_len(pdev, 0);
1178
Sony Chacko15087c22012-12-04 03:33:54 +00001179 qlcnic_get_bar_length(pdev->device, &bar0_len);
1180 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001181
1182 mem_ptr0 = pci_ioremap_bar(pdev, 0);
1183 if (mem_ptr0 == NULL) {
1184 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
1185 return -EIO;
1186 }
1187 pci_len0 = mem_len;
1188 } else {
1189 return -EIO;
1190 }
1191
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001192 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001193
Sony Chacko15087c22012-12-04 03:33:54 +00001194 ahw->pci_base0 = mem_ptr0;
1195 ahw->pci_len0 = pci_len0;
1196 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1197 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001198
1199 return 0;
1200}
1201
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001202static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1203 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001204{
1205 struct pci_dev *pdev = adapter->pdev;
1206 unsigned short subsystem_vendor;
1207 bool ret = true;
1208
1209 subsystem_vendor = pdev->subsystem_vendor;
1210
1211 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1212 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1213 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1214 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1215 ret = true;
1216 else
1217 ret = false;
1218 }
1219
1220 return ret;
1221}
1222
Sony Chacko22999792012-12-04 03:33:55 +00001223static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001224{
1225 struct pci_dev *pdev = adapter->pdev;
1226 int i, found = 0;
1227
1228 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1229 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001230 qlcnic_boards[i].device == pdev->device &&
1231 qlcnic_validate_subsystem_id(adapter, i)) {
1232 found = 1;
1233 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001234 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001235 }
1236
1237 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001238 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001239 else
1240 sprintf(name, "%pM: %s" , adapter->mac_addr,
1241 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001242}
1243
1244static void
1245qlcnic_check_options(struct qlcnic_adapter *adapter)
1246{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001247 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001248 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001249 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001250 struct qlcnic_hardware_context *ahw = adapter->ahw;
1251 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001252
1253 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001254
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001255 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1256 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1257 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001258
1259 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1260
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001261 err = qlcnic_get_board_info(adapter);
1262 if (err) {
1263 dev_err(&pdev->dev, "Error getting board config info.\n");
1264 return;
1265 }
1266 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001267 if (fw_dump->tmpl_hdr == NULL ||
1268 adapter->fw_version > prev_fw_version) {
Markus Elfring7061b2b2015-02-04 14:07:56 +01001269 vfree(fw_dump->tmpl_hdr);
Sritej Velaga031a4a22011-07-29 13:30:28 +00001270 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1271 dev_info(&pdev->dev,
1272 "Supports FW dump capability\n");
1273 }
1274 }
1275
Sony Chacko13159182013-01-01 03:20:21 +00001276 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1277 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1278
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001279 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001280 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1281 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1282 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1283 } else {
1284 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1285 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1286 }
1287
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001288 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001289 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1290
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001291 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001292 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1293 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001294 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1295 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001296 }
1297
Sony Chacko099f7aa2012-12-04 03:33:58 +00001298 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001299
1300 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1301
Sony Chacko251b0362010-08-19 05:08:24 +00001302 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001303}
1304
Rajesh Borundia174240a2010-08-31 17:17:47 +00001305static int
1306qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1307{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001308 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001309 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001310
Sony Chackobff57d8e2012-12-04 03:33:56 +00001311 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001312 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001313 if (err)
1314 return err;
1315
Sony Chacko79788452012-12-04 03:33:53 +00001316 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1317 adapter->ahw->switch_mode = nic_info.switch_mode;
1318 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1319 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1320 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001321
1322 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1323 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001324 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1325 if (err == -EIO)
1326 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001327 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001328 } else {
1329 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001330 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001331
Sony Chacko79788452012-12-04 03:33:53 +00001332 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1333 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001334
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001335 if (adapter->ahw->capabilities & BIT_6) {
Rajesh Borundia174240a2010-08-31 17:17:47 +00001336 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001337 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE;
1338 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS;
1339 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
1340
1341 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n");
1342 } else {
1343 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
1344 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS;
Himanshu Madhanif9566262013-12-16 15:36:58 -05001345 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001346 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001347 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001348
1349 return err;
1350}
1351
Sony Chackoec079a02012-11-28 04:34:28 +00001352void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1353 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001354{
1355 if (esw_cfg->discard_tagged)
1356 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1357 else
1358 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1359
Rajesh Borundia91b72822013-04-19 07:01:12 +00001360 if (esw_cfg->vlan_id) {
1361 adapter->rx_pvid = esw_cfg->vlan_id;
1362 adapter->tx_pvid = esw_cfg->vlan_id;
1363 } else {
1364 adapter->rx_pvid = 0;
1365 adapter->tx_pvid = 0;
1366 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001367}
1368
Jiri Pirko8e586132011-12-08 19:52:37 -05001369static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001370qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001371{
1372 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001373 int err;
1374
1375 if (qlcnic_sriov_vf_check(adapter)) {
1376 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1377 if (err) {
1378 netdev_err(netdev,
1379 "Cannot add VLAN filter for VLAN id %d, err=%d",
1380 vid, err);
1381 return err;
1382 }
1383 }
1384
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001385 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001386 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001387}
1388
Jiri Pirko8e586132011-12-08 19:52:37 -05001389static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001390qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001391{
1392 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001393 int err;
1394
1395 if (qlcnic_sriov_vf_check(adapter)) {
1396 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1397 if (err) {
1398 netdev_err(netdev,
1399 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1400 vid, err);
1401 return err;
1402 }
1403 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001404
1405 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1406 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001407 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001408}
1409
Sony Chackoec079a02012-11-28 04:34:28 +00001410void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1411 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001412{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001413 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1414 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001415
1416 if (esw_cfg->mac_anti_spoof)
1417 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001418
Rajesh Borundia73733732010-08-31 17:17:50 +00001419 if (!esw_cfg->mac_override)
1420 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1421
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001422 if (!esw_cfg->promisc_mode)
1423 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001424}
1425
Sony Chackod71170f2013-01-01 03:20:26 +00001426int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001427{
1428 struct qlcnic_esw_func_cfg esw_cfg;
1429
1430 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1431 return 0;
1432
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001433 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001434 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1435 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001436 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001437 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001438 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001439
1440 return 0;
1441}
1442
Shahed Shaikh147a9082013-05-21 09:27:01 +00001443void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1444 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001445{
1446 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001447
Sony Chacko13159182013-01-01 03:20:21 +00001448 if (qlcnic_83xx_check(adapter))
1449 return;
1450
Shahed Shaikh147a9082013-05-21 09:27:01 +00001451 adapter->offload_flags = esw_cfg->offload_flags;
1452 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1453 netdev_update_features(netdev);
1454 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001455}
1456
1457static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001458qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1459{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001460 u32 op_mode, priv_level;
1461 int err = 0;
1462
Rajesh Borundia174240a2010-08-31 17:17:47 +00001463 err = qlcnic_initialize_nic(adapter);
1464 if (err)
1465 return err;
1466
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001467 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1468 return 0;
1469
Sony Chacko13159182013-01-01 03:20:21 +00001470 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001471 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001472
1473 if (op_mode == QLC_DEV_DRV_DEFAULT)
1474 priv_level = QLCNIC_MGMT_FUNC;
1475 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001476 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001477
Rajesh Borundia174240a2010-08-31 17:17:47 +00001478 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001479 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001480 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001481 err = qlcnic_init_pci_info(adapter);
1482 if (err)
1483 return err;
1484 /* Set privilege level for other functions */
1485 qlcnic_set_function_modes(adapter);
1486 dev_info(&adapter->pdev->dev,
1487 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001488 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001489 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001490 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001491 dev_info(&adapter->pdev->dev,
1492 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001493 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001494 }
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001495 } else {
1496 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001497 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001498
1499 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1500
1501 return err;
1502}
1503
Sony Chackod71170f2013-01-01 03:20:26 +00001504int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001505{
1506 struct qlcnic_esw_func_cfg esw_cfg;
1507 struct qlcnic_npar_info *npar;
1508 u8 i;
1509
Rajesh Borundia174240a2010-08-31 17:17:47 +00001510 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001511 return 0;
1512
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001513 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001514 if (!adapter->npars[i].eswitch_status)
1515 continue;
1516
Rajesh Borundia0325d692010-08-19 05:08:26 +00001517 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d8e2012-12-04 03:33:56 +00001518 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001519 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001520 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001521 if (qlcnic_82xx_check(adapter)) {
1522 esw_cfg.offload_flags = BIT_0;
1523 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1524 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1525 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001526 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1527 return -EIO;
1528 npar = &adapter->npars[i];
1529 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001530 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001531 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1532 npar->discard_tagged = esw_cfg.discard_tagged;
1533 npar->promisc_mode = esw_cfg.promisc_mode;
1534 npar->offload_flags = esw_cfg.offload_flags;
1535 }
1536
1537 return 0;
1538}
1539
Sony Chacko13159182013-01-01 03:20:21 +00001540
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001541static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001542qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1543 struct qlcnic_npar_info *npar, int pci_func)
1544{
1545 struct qlcnic_esw_func_cfg esw_cfg;
1546 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1547 esw_cfg.pci_func = pci_func;
1548 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001549 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001550 esw_cfg.discard_tagged = npar->discard_tagged;
1551 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1552 esw_cfg.offload_flags = npar->offload_flags;
1553 esw_cfg.promisc_mode = npar->promisc_mode;
1554 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1555 return -EIO;
1556
1557 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1558 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1559 return -EIO;
1560
1561 return 0;
1562}
1563
Sony Chackod71170f2013-01-01 03:20:26 +00001564int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001565{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001566 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001567 struct qlcnic_npar_info *npar;
1568 struct qlcnic_info nic_info;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001569 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001570
Sony Chackobff57d8e2012-12-04 03:33:56 +00001571 if (qlcnic_82xx_check(adapter))
1572 if (!adapter->need_fw_reset)
1573 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001574
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001575 /* Set the NPAR config data after FW reset */
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001576 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001577 npar = &adapter->npars[i];
Sony Chackobff57d8e2012-12-04 03:33:56 +00001578 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001579 if (!adapter->npars[i].eswitch_status)
1580 continue;
1581
Sony Chackobff57d8e2012-12-04 03:33:56 +00001582 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001583 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001584 if (err)
1585 return err;
1586 nic_info.min_tx_bw = npar->min_bw;
1587 nic_info.max_tx_bw = npar->max_bw;
1588 err = qlcnic_set_nic_info(adapter, &nic_info);
1589 if (err)
1590 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001591
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001592 if (npar->enable_pm) {
1593 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d8e2012-12-04 03:33:56 +00001594 npar->dest_npar, 1,
1595 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001596 if (err)
1597 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001598 }
Sony Chackobff57d8e2012-12-04 03:33:56 +00001599 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001600 if (err)
1601 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001602 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001603 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001604}
1605
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001606static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1607{
1608 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1609 u32 npar_state;
1610
Sony Chacko79788452012-12-04 03:33:53 +00001611 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001612 return 0;
1613
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001614 npar_state = QLC_SHARED_REG_RD32(adapter,
1615 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001616 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1617 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001618 npar_state = QLC_SHARED_REG_RD32(adapter,
1619 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001620 }
1621 if (!npar_opt_timeo) {
1622 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001623 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001624 return -EIO;
1625 }
1626 return 0;
1627}
1628
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001629static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001630qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1631{
1632 int err;
1633
1634 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001635 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001636 return 0;
1637
1638 err = qlcnic_set_default_offload_settings(adapter);
1639 if (err)
1640 return err;
1641
1642 err = qlcnic_reset_npar_config(adapter);
1643 if (err)
1644 return err;
1645
1646 qlcnic_dev_set_npar_ready(adapter);
1647
1648 return err;
1649}
1650
stephen hemminger21041402014-01-16 10:31:27 -08001651static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001652{
Sony Chackod4066832010-08-19 05:08:31 +00001653 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001654
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001655 err = qlcnic_can_start_firmware(adapter);
1656 if (err < 0)
1657 return err;
1658 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001659 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001660
Sony Chacko099f7aa2012-12-04 03:33:58 +00001661 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001662 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001663 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001664 err = qlcnic_check_flash_fw_ver(adapter);
1665 if (err)
schacko8f891382010-06-17 02:56:40 +00001666 goto err_out;
1667
Sony Chacko79788452012-12-04 03:33:53 +00001668 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001669 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001670
1671 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001672 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001673 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001674
Sony Chackod4066832010-08-19 05:08:31 +00001675 err = qlcnic_pinit_from_rom(adapter);
1676 if (err)
1677 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001678
1679 err = qlcnic_load_firmware(adapter);
1680 if (err)
1681 goto err_out;
1682
1683 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001684 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001685
Sony Chackod4066832010-08-19 05:08:31 +00001686check_fw_status:
1687 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001688 if (err)
1689 goto err_out;
1690
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001691 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001692 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001693 err = qlcnic_check_eswitch_mode(adapter);
1694 if (err) {
1695 dev_err(&adapter->pdev->dev,
1696 "Memory allocation failed for eswitch\n");
1697 goto err_out;
1698 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001699 err = qlcnic_set_mgmt_operations(adapter);
1700 if (err)
1701 goto err_out;
1702
1703 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001704 adapter->need_fw_reset = 0;
1705
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001706 qlcnic_release_firmware(adapter);
1707 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001708
1709err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001710 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001711 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001712
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001713 qlcnic_release_firmware(adapter);
1714 return err;
1715}
1716
1717static int
1718qlcnic_request_irq(struct qlcnic_adapter *adapter)
1719{
1720 irq_handler_t handler;
1721 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001722 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001723 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001724
1725 unsigned long flags = 0;
1726 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001727 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001728
Sony Chacko79788452012-12-04 03:33:53 +00001729 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001730 if (qlcnic_82xx_check(adapter))
1731 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001732 else
1733 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001734 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1735 flags |= IRQF_SHARED;
1736
1737 } else {
1738 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1739 handler = qlcnic_msix_intr;
1740 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1741 handler = qlcnic_msi_intr;
1742 else {
1743 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001744 if (qlcnic_82xx_check(adapter))
1745 handler = qlcnic_intr;
1746 else
1747 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001748 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001749 }
1750 adapter->irq = netdev->irq;
1751
Sony Chacko13159182013-01-01 03:20:21 +00001752 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001753 if (qlcnic_82xx_check(adapter) ||
1754 (qlcnic_83xx_check(adapter) &&
1755 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001756 num_sds_rings = adapter->drv_sds_rings;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001757 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001758 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001759 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001760 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001761 (ring == (num_sds_rings - 1))) {
1762 if (!(adapter->flags &
1763 QLCNIC_MSIX_ENABLED))
1764 snprintf(sds_ring->name,
1765 sizeof(sds_ring->name),
1766 "qlcnic");
1767 else
1768 snprintf(sds_ring->name,
1769 sizeof(sds_ring->name),
1770 "%s-tx-0-rx-%d",
1771 netdev->name, ring);
1772 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001773 snprintf(sds_ring->name,
1774 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001775 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001776 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001777 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001778 err = request_irq(sds_ring->irq, handler, flags,
1779 sds_ring->name, sds_ring);
1780 if (err)
1781 return err;
1782 }
Sony Chacko13159182013-01-01 03:20:21 +00001783 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001784 if ((qlcnic_82xx_check(adapter) &&
1785 qlcnic_check_multi_tx(adapter)) ||
1786 (qlcnic_83xx_check(adapter) &&
1787 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1788 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001789 handler = qlcnic_msix_tx_intr;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001790 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001791 ring++) {
1792 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001793 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001794 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001795 err = request_irq(tx_ring->irq, handler, flags,
1796 tx_ring->name, tx_ring);
1797 if (err)
1798 return err;
1799 }
1800 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001801 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001802 return 0;
1803}
1804
1805static void
1806qlcnic_free_irq(struct qlcnic_adapter *adapter)
1807{
1808 int ring;
1809 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001810 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001811
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001812 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001813
Sony Chacko13159182013-01-01 03:20:21 +00001814 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001815 if (qlcnic_82xx_check(adapter) ||
1816 (qlcnic_83xx_check(adapter) &&
1817 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001818 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001819 sds_ring = &recv_ctx->sds_rings[ring];
1820 free_irq(sds_ring->irq, sds_ring);
1821 }
Sony Chacko13159182013-01-01 03:20:21 +00001822 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001823 if ((qlcnic_83xx_check(adapter) &&
1824 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1825 (qlcnic_82xx_check(adapter) &&
1826 qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001827 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001828 ring++) {
1829 tx_ring = &adapter->tx_ring[ring];
1830 if (tx_ring->irq)
1831 free_irq(tx_ring->irq, tx_ring);
1832 }
1833 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001834 }
1835}
1836
Shahed Shaikh99e85872013-02-18 12:06:16 +00001837static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1838{
1839 u32 capab = 0;
1840
1841 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001842 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001843 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1844 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1845 } else {
1846 capab = adapter->ahw->capabilities;
1847 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1848 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1849 }
1850}
1851
Himanshu Madhania5147222014-01-23 17:18:32 -05001852static int qlcnic_config_def_intr_coalesce(struct qlcnic_adapter *adapter)
1853{
1854 struct qlcnic_hardware_context *ahw = adapter->ahw;
1855 int err;
1856
1857 /* Initialize interrupt coalesce parameters */
1858 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1859
1860 if (qlcnic_83xx_check(adapter)) {
1861 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
1862 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1863 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1864 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1865 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1866
1867 err = qlcnic_83xx_set_rx_tx_intr_coal(adapter);
1868 } else {
1869 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1870 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1871 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1872
1873 err = qlcnic_82xx_set_rx_coalesce(adapter);
1874 }
1875
1876 return err;
1877}
1878
Sony Chacko319ecf12013-01-01 03:20:22 +00001879int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001880{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001881 int ring;
1882 struct qlcnic_host_rds_ring *rds_ring;
1883
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001884 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1885 return -EIO;
1886
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001887 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1888 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001889
Rajesh Borundia0325d692010-08-19 05:08:26 +00001890 if (qlcnic_set_eswitch_port_config(adapter))
1891 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001892
Shahed Shaikh99e85872013-02-18 12:06:16 +00001893 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001894
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001895 if (qlcnic_fw_create_ctx(adapter))
1896 return -EIO;
1897
1898 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001899 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001900 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001901 }
1902
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001903 qlcnic_set_multi(netdev);
1904 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1905
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001906 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001907
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001908 if (adapter->drv_sds_rings > 1)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001909 qlcnic_config_rss(adapter, 1);
1910
Himanshu Madhania5147222014-01-23 17:18:32 -05001911 qlcnic_config_def_intr_coalesce(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001912
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001913 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001914 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1915
Pratik Pujarcfacb172013-07-19 16:56:27 -04001916 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001917 qlcnic_napi_enable(adapter);
1918
1919 qlcnic_linkevent_request(adapter, 1);
1920
Sony Chacko79788452012-12-04 03:33:53 +00001921 adapter->ahw->reset_context = 0;
Rajesh Borundia060d0562014-01-28 11:55:29 -05001922 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001923 return 0;
1924}
1925
Sony Chacko629263a2013-01-01 04:11:55 +00001926int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001927{
1928 int err = 0;
1929
1930 rtnl_lock();
1931 if (netif_running(netdev))
1932 err = __qlcnic_up(adapter, netdev);
1933 rtnl_unlock();
1934
1935 return err;
1936}
1937
Sony Chacko319ecf12013-01-01 03:20:22 +00001938void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001939{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001940 int ring;
1941
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001942 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1943 return;
1944
1945 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1946 return;
1947
1948 smp_mb();
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001949 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001950 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001951 netif_tx_disable(netdev);
1952
1953 qlcnic_free_mac_list(adapter);
1954
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001955 if (adapter->fhash.fnum)
1956 qlcnic_delete_lb_filters(adapter);
1957
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001958 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
Rajesh Borundia74b7ba12014-05-09 02:51:30 -04001959 if (qlcnic_sriov_vf_check(adapter))
1960 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001961
1962 qlcnic_napi_disable(adapter);
1963
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001964 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001965 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001966
1967 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001968
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001969 for (ring = 0; ring < adapter->drv_tx_rings; ring++)
Himanshu Madhani012ec812013-08-21 11:24:10 -04001970 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001971}
1972
1973/* Usage: During suspend and firmware recovery module */
1974
Sony Chacko629263a2013-01-01 04:11:55 +00001975void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001976{
1977 rtnl_lock();
1978 if (netif_running(netdev))
1979 __qlcnic_down(adapter, netdev);
1980 rtnl_unlock();
1981
1982}
1983
Sony Chacko319ecf12013-01-01 03:20:22 +00001984int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001985qlcnic_attach(struct qlcnic_adapter *adapter)
1986{
1987 struct net_device *netdev = adapter->netdev;
1988 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001989 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001990
1991 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1992 return 0;
1993
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001994 err = qlcnic_napi_add(adapter, netdev);
1995 if (err)
1996 return err;
1997
1998 err = qlcnic_alloc_sw_resources(adapter);
1999 if (err) {
2000 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002001 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002002 }
2003
2004 err = qlcnic_alloc_hw_resources(adapter);
2005 if (err) {
2006 dev_err(&pdev->dev, "Error in setting hw resources\n");
2007 goto err_out_free_sw;
2008 }
2009
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002010 err = qlcnic_request_irq(adapter);
2011 if (err) {
2012 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002013 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002014 }
2015
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002016 qlcnic_create_sysfs_entries(adapter);
2017
Shahed Shaikh7f1f6052014-04-01 16:29:32 -04002018#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04002019 if (qlcnic_encap_rx_offload(adapter))
2020 vxlan_get_rx_port(netdev);
Shahed Shaikh7f1f6052014-04-01 16:29:32 -04002021#endif
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04002022
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002023 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
2024 return 0;
2025
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002026err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002027 qlcnic_free_hw_resources(adapter);
2028err_out_free_sw:
2029 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002030err_out_napi_del:
2031 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002032 return err;
2033}
2034
Sony Chacko319ecf12013-01-01 03:20:22 +00002035void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002036{
2037 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2038 return;
2039
2040 qlcnic_remove_sysfs_entries(adapter);
2041
2042 qlcnic_free_hw_resources(adapter);
2043 qlcnic_release_rx_buffers(adapter);
2044 qlcnic_free_irq(adapter);
2045 qlcnic_napi_del(adapter);
2046 qlcnic_free_sw_resources(adapter);
2047
2048 adapter->is_up = 0;
2049}
2050
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002051void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings)
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002052{
2053 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2054 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002055 int drv_tx_rings = adapter->drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002056 int ring;
2057
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002058 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00002059 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002060 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002061 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002062 qlcnic_disable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002063 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002064 }
2065
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002066 qlcnic_fw_destroy_ctx(adapter);
2067
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002068 qlcnic_detach(adapter);
2069
Sony Chacko79788452012-12-04 03:33:53 +00002070 adapter->ahw->diag_test = 0;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002071 adapter->drv_sds_rings = drv_sds_rings;
2072 adapter->drv_tx_rings = drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002073
2074 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002075 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002076
2077 if (netif_running(netdev))
2078 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002079out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002080 netif_device_attach(netdev);
2081}
2082
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002083static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
2084{
Sucheta Chakraborty868e9142014-04-25 17:43:58 -04002085 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002086 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00002087
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002088 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
2089 GFP_KERNEL);
2090 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002091 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00002092 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002093 }
Himanshu Madhania5147222014-01-23 17:18:32 -05002094
Sucheta Chakraborty868e9142014-04-25 17:43:58 -04002095 if (qlcnic_83xx_check(adapter)) {
2096 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
2097 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
2098 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
2099 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
2100 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
2101 } else {
2102 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
2103 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
2104 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
2105 }
2106
Sony Chacko4be41e92013-01-01 03:20:20 +00002107 /* clear stats */
2108 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002109err_out:
2110 return err;
2111}
2112
2113static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
2114{
Shahed Shaikh4da005c2014-06-11 14:09:11 -04002115 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
2116
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002117 kfree(adapter->recv_ctx);
2118 adapter->recv_ctx = NULL;
2119
Shahed Shaikh4da005c2014-06-11 14:09:11 -04002120 if (fw_dump->tmpl_hdr) {
2121 vfree(fw_dump->tmpl_hdr);
2122 fw_dump->tmpl_hdr = NULL;
2123 }
2124
2125 if (fw_dump->dma_buffer) {
2126 dma_free_coherent(&adapter->pdev->dev, QLC_PEX_DMA_READ_SIZE,
2127 fw_dump->dma_buffer, fw_dump->phys_addr);
2128 fw_dump->dma_buffer = NULL;
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002129 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002130
Sony Chacko81d0aeb2013-01-01 03:20:25 +00002131 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00002132 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002133}
2134
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002135int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
2136{
2137 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2138 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002139 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002140 int ring;
2141 int ret;
2142
2143 netif_device_detach(netdev);
2144
2145 if (netif_running(netdev))
2146 __qlcnic_down(adapter, netdev);
2147
2148 qlcnic_detach(adapter);
2149
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002150 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sony Chacko79788452012-12-04 03:33:53 +00002151 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00002152 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002153
2154 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002155 if (ret) {
2156 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002157 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002158 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002159
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002160 ret = qlcnic_fw_create_ctx(adapter);
2161 if (ret) {
2162 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00002163 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002164 return ret;
2165 }
2166
2167 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002168 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00002169 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002170 }
2171
Sony Chacko79788452012-12-04 03:33:53 +00002172 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002173 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002174 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002175 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002176 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002177 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002178
Sony Chacko79788452012-12-04 03:33:53 +00002179 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002180 adapter->ahw->loopback_state = 0;
2181 qlcnic_linkevent_request(adapter, 1);
2182 }
2183
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002184 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002185
2186 return 0;
2187}
2188
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002189/* Reset context in hardware only */
2190static int
2191qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
2192{
2193 struct net_device *netdev = adapter->netdev;
2194
2195 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2196 return -EBUSY;
2197
2198 netif_device_detach(netdev);
2199
2200 qlcnic_down(adapter, netdev);
2201
2202 qlcnic_up(adapter, netdev);
2203
2204 netif_device_attach(netdev);
2205
2206 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani95b38902014-01-23 17:18:29 -05002207 netdev_info(adapter->netdev, "%s: soft reset complete\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002208 return 0;
2209}
2210
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002211int
2212qlcnic_reset_context(struct qlcnic_adapter *adapter)
2213{
2214 int err = 0;
2215 struct net_device *netdev = adapter->netdev;
2216
2217 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2218 return -EBUSY;
2219
2220 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
2221
2222 netif_device_detach(netdev);
2223
2224 if (netif_running(netdev))
2225 __qlcnic_down(adapter, netdev);
2226
2227 qlcnic_detach(adapter);
2228
2229 if (netif_running(netdev)) {
2230 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002231 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002232 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002233 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2234 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002235 }
2236
2237 netif_device_attach(netdev);
2238 }
2239
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002240 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2241 return err;
2242}
2243
stephen hemminger21041402014-01-16 10:31:27 -08002244static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002245{
2246 struct qlcnic_hardware_context *ahw = adapter->ahw;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002247 u16 act_pci_fn = ahw->total_nic_func;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002248 u16 count;
2249
2250 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2251 if (act_pci_fn <= 2)
2252 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2253 act_pci_fn;
2254 else
2255 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2256 act_pci_fn;
2257 ahw->max_uc_count = count;
2258}
2259
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04002260static int qlcnic_set_real_num_queues(struct qlcnic_adapter *adapter,
2261 u8 tx_queues, u8 rx_queues)
2262{
2263 struct net_device *netdev = adapter->netdev;
2264 int err = 0;
2265
2266 if (tx_queues) {
2267 err = netif_set_real_num_tx_queues(netdev, tx_queues);
2268 if (err) {
2269 netdev_err(netdev, "failed to set %d Tx queues\n",
2270 tx_queues);
2271 return err;
2272 }
2273 }
2274
2275 if (rx_queues) {
2276 err = netif_set_real_num_rx_queues(netdev, rx_queues);
2277 if (err)
2278 netdev_err(netdev, "failed to set %d Rx queues\n",
2279 rx_queues);
2280 }
2281
2282 return err;
2283}
2284
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002285int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002286qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2287 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002288{
2289 int err;
2290 struct pci_dev *pdev = adapter->pdev;
2291
Sony Chacko13159182013-01-01 03:20:21 +00002292 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002293 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002294 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002295
2296 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002297 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002298
2299 qlcnic_change_mtu(netdev, netdev->mtu);
2300
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002301 netdev->ethtool_ops = (qlcnic_sriov_vf_check(adapter)) ?
2302 &qlcnic_sriov_vf_ethtool_ops : &qlcnic_ethtool_ops;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002303
Sony Chacko7e38d042013-01-01 03:20:28 +00002304 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002305 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002306 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002307 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2308 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002309
Sony Chacko13159182013-01-01 03:20:21 +00002310 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2311 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2312 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2313 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002314
Sony Chacko13159182013-01-01 03:20:21 +00002315 if (pci_using_dac) {
2316 netdev->features |= NETIF_F_HIGHDMA;
2317 netdev->vlan_features |= NETIF_F_HIGHDMA;
2318 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002319
Sony Chacko13159182013-01-01 03:20:21 +00002320 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002321 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002322
Rajesh Borundia91b72822013-04-19 07:01:12 +00002323 if (qlcnic_sriov_vf_check(adapter))
2324 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2325
Sony Chacko79788452012-12-04 03:33:53 +00002326 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002327 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002328
Shahed Shaikh381709d2014-03-21 04:41:16 -04002329 if (qlcnic_encap_tx_offload(adapter)) {
2330 netdev->features |= NETIF_F_GSO_UDP_TUNNEL;
2331
2332 /* encapsulation Tx offload supported by Adapter */
2333 netdev->hw_enc_features = NETIF_F_IP_CSUM |
2334 NETIF_F_GSO_UDP_TUNNEL |
2335 NETIF_F_TSO |
2336 NETIF_F_TSO6;
2337 }
2338
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04002339 if (qlcnic_encap_rx_offload(adapter))
2340 netdev->hw_enc_features |= NETIF_F_RXCSUM;
2341
Sony Chacko7e38d042013-01-01 03:20:28 +00002342 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002343 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002344 netdev->irq = adapter->msix_entries[0].vector;
2345
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04002346 err = qlcnic_set_real_num_queues(adapter, adapter->drv_tx_rings,
2347 adapter->drv_sds_rings);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002348 if (err)
2349 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002350
Rajesh Borundiacd1560e2014-08-04 11:51:18 -04002351 qlcnic_dcb_init_dcbnl_ops(adapter->dcb);
2352
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002353 err = register_netdev(netdev);
2354 if (err) {
2355 dev_err(&pdev->dev, "failed to register net device\n");
2356 return err;
2357 }
2358
2359 return 0;
2360}
2361
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002362static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002363{
2364 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2365 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2366 *pci_using_dac = 1;
2367 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2368 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2369 *pci_using_dac = 0;
2370 else {
2371 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2372 return -EIO;
2373 }
2374
2375 return 0;
2376}
2377
Sony Chacko4be41e92013-01-01 03:20:20 +00002378void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2379{
2380 int ring;
2381 struct qlcnic_host_tx_ring *tx_ring;
2382
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002383 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002384 tx_ring = &adapter->tx_ring[ring];
Markus Elfring7061b2b2015-02-04 14:07:56 +01002385 if (tx_ring) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002386 vfree(tx_ring->cmd_buf_arr);
2387 tx_ring->cmd_buf_arr = NULL;
2388 }
2389 }
Markus Elfring7061b2b2015-02-04 14:07:56 +01002390 kfree(adapter->tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002391}
2392
2393int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2394 struct net_device *netdev)
2395{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002396 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002397 struct qlcnic_host_tx_ring *tx_ring;
2398 struct qlcnic_cmd_buffer *cmd_buf_arr;
2399
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002400 tx_ring = kcalloc(adapter->drv_tx_rings,
Joe Perchesb2adaca2013-02-03 17:43:58 +00002401 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2402 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002403 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002404
Sony Chacko4be41e92013-01-01 03:20:20 +00002405 adapter->tx_ring = tx_ring;
2406
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002407 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002408 tx_ring = &adapter->tx_ring[ring];
2409 tx_ring->num_desc = adapter->num_txd;
2410 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2411 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2412 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002413 qlcnic_free_tx_rings(adapter);
2414 return -ENOMEM;
2415 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002416 tx_ring->cmd_buf_arr = cmd_buf_arr;
Shahed Shaikha02bdd42014-01-03 01:34:28 -05002417 spin_lock_init(&tx_ring->tx_clean_lock);
Sony Chacko4be41e92013-01-01 03:20:20 +00002418 }
2419
Himanshu Madhani012ec812013-08-21 11:24:10 -04002420 if (qlcnic_83xx_check(adapter) ||
2421 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002422 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002423 tx_ring = &adapter->tx_ring[ring];
2424 tx_ring->adapter = adapter;
2425 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002426 index = adapter->drv_sds_rings + ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002427 vector = adapter->msix_entries[index].vector;
2428 tx_ring->irq = vector;
2429 }
2430 }
2431 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002432
Sony Chacko4be41e92013-01-01 03:20:20 +00002433 return 0;
2434}
2435
Pratik Pujar8af3f332013-06-22 04:12:05 -04002436void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2437{
2438 struct qlcnic_hardware_context *ahw = adapter->ahw;
2439 u32 fw_cmd = 0;
2440
2441 if (qlcnic_82xx_check(adapter))
2442 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2443 else if (qlcnic_83xx_check(adapter))
2444 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2445
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002446 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002447 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2448}
2449
Sony Chacko2c97e9e2014-04-23 09:59:55 -04002450/* Reset firmware API lock */
2451static void qlcnic_reset_api_lock(struct qlcnic_adapter *adapter)
2452{
2453 qlcnic_api_lock(adapter);
2454 qlcnic_api_unlock(adapter);
2455}
2456
2457
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002458static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002459qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2460{
2461 struct net_device *netdev = NULL;
2462 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002463 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002464 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002465 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002466
2467 err = pci_enable_device(pdev);
2468 if (err)
2469 return err;
2470
2471 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2472 err = -ENODEV;
2473 goto err_out_disable_pdev;
2474 }
2475
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002476 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2477 if (err)
2478 goto err_out_disable_pdev;
2479
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002480 err = pci_request_regions(pdev, qlcnic_driver_name);
2481 if (err)
2482 goto err_out_disable_pdev;
2483
2484 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002485 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002486
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002487 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002488 if (!ahw) {
2489 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002490 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002491 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002492
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002493 switch (ent->device) {
2494 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002495 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002496 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2497 break;
2498 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Shahed Shaikh40e2b8e2014-08-27 12:43:18 -04002499 case PCI_DEVICE_ID_QLOGIC_QLE8830:
Manish Chopra15ca1402013-08-16 19:07:13 -04002500 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002501 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002502 break;
2503 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Shahed Shaikhda286a62015-08-07 07:17:05 -04002504 case PCI_DEVICE_ID_QLOGIC_VF_QLE8C30:
Manish Chopra15ca1402013-08-16 19:07:13 -04002505 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002506 qlcnic_sriov_vf_register_map(ahw);
2507 break;
2508 default:
Sony Chacko13159182013-01-01 03:20:21 +00002509 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002510 }
2511
2512 err = qlcnic_setup_pci_map(pdev, ahw);
2513 if (err)
2514 goto err_out_free_hw_res;
2515
Himanshu Madhani012ec812013-08-21 11:24:10 -04002516 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2517 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002518 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002519 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002520 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002521 }
2522
2523 SET_NETDEV_DEV(netdev, &pdev->dev);
2524
2525 adapter = netdev_priv(netdev);
2526 adapter->netdev = netdev;
2527 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002528 adapter->ahw = ahw;
2529
2530 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2531 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002532 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002533 dev_err(&pdev->dev, "Failed to create workqueue\n");
2534 goto err_out_free_netdev;
2535 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002536
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002537 err = qlcnic_alloc_adapter_resources(adapter);
2538 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002539 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002540
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002541 adapter->dev_rst_time = jiffies;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002542 ahw->revision_id = pdev->revision;
2543 ahw->max_vnic_func = qlcnic_get_vnic_func_count(adapter);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002544 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2545 adapter->fdb_mac_learn = true;
2546 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2547 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002548
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002549 rwlock_init(&adapter->ahw->crb_lock);
2550 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002551
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002552 INIT_LIST_HEAD(&adapter->mac_list);
2553
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002554 qlcnic_register_dcb(adapter);
2555
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002556 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002557 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002558 adapter->portnum = adapter->ahw->pci_func;
Sony Chacko2c97e9e2014-04-23 09:59:55 -04002559 qlcnic_reset_api_lock(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002560 err = qlcnic_start_firmware(adapter);
2561 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002562 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2563 "\t\tIf reboot doesn't help, try flashing the card\n");
2564 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002565 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002566
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002567 /* compute and set default and max tx/sds rings */
2568 if (adapter->ahw->msix_supported) {
2569 if (qlcnic_check_multi_tx_capability(adapter) == 1)
2570 qlcnic_set_tx_ring_count(adapter,
2571 QLCNIC_SINGLE_RING);
2572 else
2573 qlcnic_set_tx_ring_count(adapter,
2574 QLCNIC_DEF_TX_RINGS);
2575 qlcnic_set_sds_ring_count(adapter,
2576 QLCNIC_DEF_SDS_RINGS);
2577 } else {
2578 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING);
2579 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002580 }
2581
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002582 err = qlcnic_setup_idc_param(adapter);
2583 if (err)
2584 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002585
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002586 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002587
Sony Chacko13159182013-01-01 03:20:21 +00002588 } else if (qlcnic_83xx_check(adapter)) {
2589 qlcnic_83xx_check_vf(adapter, ent);
2590 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002591 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002592 if (err) {
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002593 switch (err) {
2594 case -ENOTRECOVERABLE:
Sucheta Chakraborty2a355aec2014-02-21 13:20:12 -05002595 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware\n");
2596 dev_err(&pdev->dev, "Please replace the adapter with new one and return the faulty adapter for repair\n");
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002597 goto err_out_free_hw;
2598 case -ENOMEM:
2599 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n");
2600 goto err_out_free_hw;
Sucheta Chakrabortyaaecf512014-04-25 17:44:00 -04002601 case -EOPNOTSUPP:
2602 dev_err(&pdev->dev, "Adapter initialization failed\n");
2603 goto err_out_free_hw;
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002604 default:
Sucheta Chakrabortyc65762f2014-04-25 17:43:59 -04002605 dev_err(&pdev->dev, "Adapter initialization failed. Driver will load in maintenance mode to recover the adapter using the application\n");
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002606 goto err_out_maintenance_mode;
2607 }
Sony Chacko629263a2013-01-01 04:11:55 +00002608 }
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002609
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002610 if (qlcnic_sriov_vf_check(adapter))
2611 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002612 } else {
2613 dev_err(&pdev->dev,
2614 "%s: failed. Please Reboot\n", __func__);
Yongjian Xu7824acd2014-12-30 16:03:46 +08002615 err = -ENODEV;
Sony Chacko13159182013-01-01 03:20:21 +00002616 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002617 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002618
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002619 if (qlcnic_read_mac_addr(adapter))
2620 dev_warn(&pdev->dev, "failed to read mac addr\n");
2621
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002622 qlcnic_read_phys_port_id(adapter);
2623
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002624 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002625 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002626
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002627 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002628 module_name(THIS_MODULE),
2629 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002630 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002631
2632 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2633 !!qlcnic_use_msi)
2634 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002635 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002636
Manish Chopra068a8d12013-08-02 00:57:41 -04002637 if (qlcnic_82xx_check(adapter)) {
Sucheta Chakraborty4d52e1e2014-04-14 10:02:19 -04002638 qlcnic_dcb_enable(adapter->dcb);
2639 qlcnic_dcb_get_info(adapter->dcb);
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002640 err = qlcnic_setup_intr(adapter);
Sucheta Chakraborty4d52e1e2014-04-14 10:02:19 -04002641
Manish Chopra068a8d12013-08-02 00:57:41 -04002642 if (err) {
2643 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002644 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002645 }
Sony Chacko13159182013-01-01 03:20:21 +00002646 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002647
Sony Chacko02135582013-05-21 09:26:59 +00002648 err = qlcnic_get_act_pci_func(adapter);
2649 if (err)
2650 goto err_out_disable_mbx_intr;
2651
Rajesh Borundiabf630142014-08-04 11:51:17 -04002652 if (adapter->portnum == 0)
2653 qlcnic_set_drv_version(adapter);
2654
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002655 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002656 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002657 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002658
2659 pci_set_drvdata(pdev, adapter);
2660
Sony Chacko97ee45e2012-12-04 03:33:52 +00002661 if (qlcnic_82xx_check(adapter))
2662 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2663 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002664
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002665 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002666 case QLCNIC_GBE:
2667 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2668 adapter->netdev->name);
2669 break;
2670 case QLCNIC_XGBE:
2671 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2672 adapter->netdev->name);
2673 break;
2674 }
2675
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002676 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002677 qlcnic_alloc_lb_filters_mem(adapter);
2678
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002679 qlcnic_add_sysfs(adapter);
Harish Patil1f0f4672014-04-25 17:43:57 -04002680 qlcnic_register_hwmon_dev(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002681 return 0;
2682
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002683err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002684 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002685 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002686
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002687err_out_disable_msi:
2688 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002689 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002690 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002691
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002692err_out_free_hw:
2693 qlcnic_free_adapter_resources(adapter);
2694
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002695err_out_free_wq:
2696 destroy_workqueue(adapter->qlcnic_wq);
2697
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002698err_out_free_netdev:
2699 free_netdev(netdev);
2700
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002701err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002702 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002703
2704err_out_free_hw_res:
2705 kfree(ahw);
2706
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002707err_out_free_res:
2708 pci_release_regions(pdev);
2709
2710err_out_disable_pdev:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002711 pci_disable_device(pdev);
2712 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002713
2714err_out_maintenance_mode:
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002715 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002716 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002717 netdev->ethtool_ops = &qlcnic_ethtool_failed_ops;
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002718 ahw->port_type = QLCNIC_XGBE;
2719
2720 if (qlcnic_83xx_check(adapter))
2721 adapter->tgt_status_reg = NULL;
2722 else
2723 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS;
2724
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002725 err = register_netdev(netdev);
2726
2727 if (err) {
2728 dev_err(&pdev->dev, "Failed to register net device\n");
2729 qlcnic_clr_all_drv_state(adapter, 0);
2730 goto err_out_free_hw;
2731 }
2732
2733 pci_set_drvdata(pdev, adapter);
2734 qlcnic_add_sysfs(adapter);
2735
2736 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002737}
2738
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002739static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002740{
2741 struct qlcnic_adapter *adapter;
2742 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002743 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002744
2745 adapter = pci_get_drvdata(pdev);
2746 if (adapter == NULL)
2747 return;
2748
2749 netdev = adapter->netdev;
2750
Sony Chacko13159182013-01-01 03:20:21 +00002751 qlcnic_cancel_idc_work(adapter);
Rajesh Borundia132a3f22014-05-09 02:51:29 -04002752 qlcnic_sriov_pf_disable(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002753 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002754
2755 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002756 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002757
Sony Chacko13159182013-01-01 03:20:21 +00002758 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05002759 qlcnic_83xx_initialize_nic(adapter, 0);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002760 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002761 qlcnic_83xx_free_mbx_intr(adapter);
2762 qlcnic_83xx_detach_mailbox_work(adapter);
2763 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002764 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002765 }
2766
Sucheta Chakraborty3720bf72013-12-17 09:01:50 -05002767 qlcnic_dcb_free(adapter->dcb);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002768 qlcnic_detach(adapter);
Markus Elfring7061b2b2015-02-04 14:07:56 +01002769 kfree(adapter->npars);
2770 kfree(adapter->eswitch);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002771
Sony Chacko97ee45e2012-12-04 03:33:52 +00002772 if (qlcnic_82xx_check(adapter))
2773 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002774
2775 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2776
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002777 qlcnic_free_lb_filters_mem(adapter);
2778
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002779 qlcnic_teardown_intr(adapter);
2780
Sony Chacko13159182013-01-01 03:20:21 +00002781 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002782
Harish Patil1f0f4672014-04-25 17:43:57 -04002783 qlcnic_unregister_hwmon_dev(adapter);
2784
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002785 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002786
2787 qlcnic_release_firmware(adapter);
2788
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002789 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002790 pci_release_regions(pdev);
2791 pci_disable_device(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002792
Sony Chacko13159182013-01-01 03:20:21 +00002793 if (adapter->qlcnic_wq) {
2794 destroy_workqueue(adapter->qlcnic_wq);
2795 adapter->qlcnic_wq = NULL;
2796 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002797
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002798 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002799 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002800 free_netdev(netdev);
2801}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802
2803static void qlcnic_shutdown(struct pci_dev *pdev)
2804{
2805 if (__qlcnic_shutdown(pdev))
2806 return;
2807
2808 pci_disable_device(pdev);
2809}
2810
2811#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002812static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002813{
2814 int retval;
2815
2816 retval = __qlcnic_shutdown(pdev);
2817 if (retval)
2818 return retval;
2819
2820 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2821 return 0;
2822}
2823
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002824static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002825{
2826 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002827 int err;
2828
2829 err = pci_enable_device(pdev);
2830 if (err)
2831 return err;
2832
2833 pci_set_power_state(pdev, PCI_D0);
2834 pci_set_master(pdev);
2835 pci_restore_state(pdev);
2836
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002837 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002838}
2839#endif
2840
2841static int qlcnic_open(struct net_device *netdev)
2842{
2843 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2844 int err;
2845
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002846 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
2847 netdev_err(netdev, "%s: Device is in non-operational state\n",
2848 __func__);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002849
2850 return -EIO;
2851 }
2852
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002853 netif_carrier_off(netdev);
2854
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002855 err = qlcnic_attach(adapter);
2856 if (err)
2857 return err;
2858
2859 err = __qlcnic_up(adapter, netdev);
2860 if (err)
Rajesh Borundia060d0562014-01-28 11:55:29 -05002861 qlcnic_detach(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002862
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002863 return err;
2864}
2865
2866/*
2867 * qlcnic_close - Disables a network interface entry point
2868 */
2869static int qlcnic_close(struct net_device *netdev)
2870{
2871 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2872
2873 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002874
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002875 return 0;
2876}
2877
Rajesh Borundiad747c332014-05-09 02:51:31 -04002878#define QLCNIC_VF_LB_BUCKET_SIZE 1
2879
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002880void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002881{
2882 void *head;
2883 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002884 struct net_device *netdev = adapter->netdev;
2885 u32 filter_size = 0;
2886 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002887
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002888 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002889 return;
2890
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002891 act_pci_func = adapter->ahw->total_nic_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002892 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002893 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002894
Rajesh Borundiad747c332014-05-09 02:51:31 -04002895 if (qlcnic_sriov_vf_check(adapter)) {
2896 filter_size = QLCNIC_83XX_SRIOV_VF_MAX_MAC - 1;
2897 adapter->fhash.fbucket_size = QLCNIC_VF_LB_BUCKET_SIZE;
2898 } else if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002899 filter_size = QLCNIC_LB_MAX_FILTERS;
2900 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2901 } else {
2902 filter_size = QLC_83XX_LB_MAX_FILTERS;
2903 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2904 }
2905
2906 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002907 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002908
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002909 if (!head)
2910 return;
2911
Sony Chacko13159182013-01-01 03:20:21 +00002912 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002913 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002914
Sony Chacko13159182013-01-01 03:20:21 +00002915 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2916 act_pci_func, adapter->fhash.fmax);
2917
2918 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002919 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002920
2921 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2922
2923 head = kcalloc(adapter->rx_fhash.fbucket_size,
2924 sizeof(struct hlist_head), GFP_ATOMIC);
2925
2926 if (!head)
2927 return;
2928
2929 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2930 adapter->rx_fhash.fhead = head;
2931
2932 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2933 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002934}
2935
2936static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2937{
Markus Elfring7061b2b2015-02-04 14:07:56 +01002938 if (adapter->fhash.fmax)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002939 kfree(adapter->fhash.fhead);
2940
2941 adapter->fhash.fhead = NULL;
2942 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002943
Markus Elfring7061b2b2015-02-04 14:07:56 +01002944 if (adapter->rx_fhash.fmax)
Shahed Shaikh53643a72013-02-18 13:22:37 +00002945 kfree(adapter->rx_fhash.fhead);
2946
2947 adapter->rx_fhash.fmax = 0;
2948 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002949}
2950
Sony Chacko629263a2013-01-01 04:11:55 +00002951int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002952{
2953 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002954 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002955 int rv = 0;
2956
Sony Chacko13159182013-01-01 03:20:21 +00002957 if (qlcnic_83xx_check(adapter))
2958 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2959
Sony Chacko97ee45e2012-12-04 03:33:52 +00002960 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002961 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002962
2963 temp_state = qlcnic_get_temp_state(temp);
2964 temp_val = qlcnic_get_temp_val(temp);
2965
2966 if (temp_state == QLCNIC_TEMP_PANIC) {
2967 dev_err(&netdev->dev,
2968 "Device temperature %d degrees C exceeds"
2969 " maximum allowed. Hardware has been shut down.\n",
2970 temp_val);
2971 rv = 1;
2972 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002973 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002974 dev_err(&netdev->dev,
2975 "Device temperature %d degrees C "
2976 "exceeds operating range."
2977 " Immediate action needed.\n",
2978 temp_val);
2979 }
2980 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002981 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002982 dev_info(&netdev->dev,
2983 "Device temperature is now %d degrees C"
2984 " in normal range.\n", temp_val);
2985 }
2986 }
Sony Chacko79788452012-12-04 03:33:53 +00002987 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002988 return rv;
2989}
2990
Himanshu Madhani95b38902014-01-23 17:18:29 -05002991static inline void dump_tx_ring_desc(struct qlcnic_host_tx_ring *tx_ring)
2992{
2993 int i;
2994 struct cmd_desc_type0 *tx_desc_info;
2995
2996 for (i = 0; i < tx_ring->num_desc; i++) {
2997 tx_desc_info = &tx_ring->desc_head[i];
2998 pr_info("TX Desc: %d\n", i);
2999 print_hex_dump(KERN_INFO, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
3000 &tx_ring->desc_head[i],
3001 sizeof(struct cmd_desc_type0), true);
3002 }
3003}
3004
Harish Patil665d1ec2014-06-27 19:01:38 -04003005static void qlcnic_dump_rings(struct qlcnic_adapter *adapter)
Himanshu Madhani95b38902014-01-23 17:18:29 -05003006{
Harish Patil665d1ec2014-06-27 19:01:38 -04003007 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani95b38902014-01-23 17:18:29 -05003008 struct net_device *netdev = adapter->netdev;
Harish Patil665d1ec2014-06-27 19:01:38 -04003009 struct qlcnic_host_rds_ring *rds_ring;
3010 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani95b38902014-01-23 17:18:29 -05003011 struct qlcnic_host_tx_ring *tx_ring;
3012 int ring;
3013
3014 if (!netdev || !netif_running(netdev))
3015 return;
3016
Harish Patil665d1ec2014-06-27 19:01:38 -04003017 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
3018 rds_ring = &recv_ctx->rds_rings[ring];
3019 if (!rds_ring)
3020 continue;
3021 netdev_info(netdev,
3022 "rds_ring=%d crb_rcv_producer=%d producer=%u num_desc=%u\n",
3023 ring, readl(rds_ring->crb_rcv_producer),
3024 rds_ring->producer, rds_ring->num_desc);
3025 }
3026
3027 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
3028 sds_ring = &(recv_ctx->sds_rings[ring]);
3029 if (!sds_ring)
3030 continue;
3031 netdev_info(netdev,
3032 "sds_ring=%d crb_sts_consumer=%d consumer=%u crb_intr_mask=%d num_desc=%u\n",
3033 ring, readl(sds_ring->crb_sts_consumer),
3034 sds_ring->consumer, readl(sds_ring->crb_intr_mask),
3035 sds_ring->num_desc);
3036 }
3037
Himanshu Madhani95b38902014-01-23 17:18:29 -05003038 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
3039 tx_ring = &adapter->tx_ring[ring];
Harish Patil665d1ec2014-06-27 19:01:38 -04003040 if (!tx_ring)
3041 continue;
Himanshu Madhani95b38902014-01-23 17:18:29 -05003042 netdev_info(netdev, "Tx ring=%d Context Id=0x%x\n",
3043 ring, tx_ring->ctx_id);
3044 netdev_info(netdev,
3045 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
3046 tx_ring->tx_stats.xmit_finished,
3047 tx_ring->tx_stats.xmit_called,
3048 tx_ring->tx_stats.xmit_on,
3049 tx_ring->tx_stats.xmit_off);
Manish Choprad5d2bf32014-05-06 03:46:48 -04003050
3051 if (tx_ring->crb_intr_mask)
3052 netdev_info(netdev, "crb_intr_mask=%d\n",
3053 readl(tx_ring->crb_intr_mask));
3054
Himanshu Madhani95b38902014-01-23 17:18:29 -05003055 netdev_info(netdev,
Manish Choprad5d2bf32014-05-06 03:46:48 -04003056 "hw_producer=%d, sw_producer=%d sw_consumer=%d, hw_consumer=%d\n",
Himanshu Madhani95b38902014-01-23 17:18:29 -05003057 readl(tx_ring->crb_cmd_producer),
3058 tx_ring->producer, tx_ring->sw_consumer,
3059 le32_to_cpu(*(tx_ring->hw_consumer)));
3060
3061 netdev_info(netdev, "Total desc=%d, Available desc=%d\n",
3062 tx_ring->num_desc, qlcnic_tx_avail(tx_ring));
3063
Harish Patil665d1ec2014-06-27 19:01:38 -04003064 if (netif_msg_tx_err(adapter->ahw))
Himanshu Madhani95b38902014-01-23 17:18:29 -05003065 dump_tx_ring_desc(tx_ring);
3066 }
Harish Patil665d1ec2014-06-27 19:01:38 -04003067
Himanshu Madhani95b38902014-01-23 17:18:29 -05003068}
3069
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003070static void qlcnic_tx_timeout(struct net_device *netdev)
3071{
3072 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3073
3074 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3075 return;
3076
Harish Patil665d1ec2014-06-27 19:01:38 -04003077 qlcnic_dump_rings(adapter);
3078
3079 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS ||
3080 netif_msg_tx_err(adapter->ahw)) {
3081 netdev_err(netdev, "Tx timeout, reset the adapter.\n");
Sony Chacko536faa62013-05-09 09:25:13 +00003082 if (qlcnic_82xx_check(adapter))
3083 adapter->need_fw_reset = 1;
3084 else if (qlcnic_83xx_check(adapter))
3085 qlcnic_83xx_idc_request_reset(adapter,
3086 QLCNIC_FORCE_FW_DUMP_KEY);
3087 } else {
Harish Patil665d1ec2014-06-27 19:01:38 -04003088 netdev_err(netdev, "Tx timeout, reset adapter context.\n");
Sony Chacko79788452012-12-04 03:33:53 +00003089 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00003090 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003091}
3092
3093static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
3094{
3095 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3096 struct net_device_stats *stats = &netdev->stats;
3097
Manish Chopra1ac67622014-01-09 12:41:04 -05003098 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
3099 qlcnic_update_stats(adapter);
3100
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003101 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
3102 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00003103 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003104 stats->tx_bytes = adapter->stats.txbytes;
3105 stats->rx_dropped = adapter->stats.rxdropped;
3106 stats->tx_dropped = adapter->stats.txdropped;
3107
3108 return stats;
3109}
3110
stephen hemminger21041402014-01-16 10:31:27 -08003111static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003112{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003113 u32 status;
3114
3115 status = readl(adapter->isr_int_vec);
3116
Sony Chacko79788452012-12-04 03:33:53 +00003117 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003118 return IRQ_NONE;
3119
3120 /* check interrupt state machine, to be sure */
3121 status = readl(adapter->crb_int_state_reg);
3122 if (!ISR_LEGACY_INT_TRIGGERED(status))
3123 return IRQ_NONE;
3124
3125 writel(0xffffffff, adapter->tgt_status_reg);
3126 /* read twice to ensure write is flushed */
3127 readl(adapter->isr_int_vec);
3128 readl(adapter->isr_int_vec);
3129
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00003130 return IRQ_HANDLED;
3131}
3132
3133static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
3134{
3135 struct qlcnic_host_sds_ring *sds_ring = data;
3136 struct qlcnic_adapter *adapter = sds_ring->adapter;
3137
3138 if (adapter->flags & QLCNIC_MSIX_ENABLED)
3139 goto done;
3140 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
3141 writel(0xffffffff, adapter->tgt_status_reg);
3142 goto done;
3143 }
3144
3145 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
3146 return IRQ_NONE;
3147
3148done:
Sony Chacko79788452012-12-04 03:33:53 +00003149 adapter->ahw->diag_cnt++;
Manish chopra2cc57522014-01-23 17:18:30 -05003150 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00003151 return IRQ_HANDLED;
3152}
3153
3154static irqreturn_t qlcnic_intr(int irq, void *data)
3155{
3156 struct qlcnic_host_sds_ring *sds_ring = data;
3157 struct qlcnic_adapter *adapter = sds_ring->adapter;
3158
3159 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
3160 return IRQ_NONE;
3161
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003162 napi_schedule(&sds_ring->napi);
3163
3164 return IRQ_HANDLED;
3165}
3166
3167static irqreturn_t qlcnic_msi_intr(int irq, void *data)
3168{
3169 struct qlcnic_host_sds_ring *sds_ring = data;
3170 struct qlcnic_adapter *adapter = sds_ring->adapter;
3171
3172 /* clear interrupt */
3173 writel(0xffffffff, adapter->tgt_status_reg);
3174
3175 napi_schedule(&sds_ring->napi);
3176 return IRQ_HANDLED;
3177}
3178
3179static irqreturn_t qlcnic_msix_intr(int irq, void *data)
3180{
3181 struct qlcnic_host_sds_ring *sds_ring = data;
3182
3183 napi_schedule(&sds_ring->napi);
3184 return IRQ_HANDLED;
3185}
3186
Sony Chacko13159182013-01-01 03:20:21 +00003187static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
3188{
3189 struct qlcnic_host_tx_ring *tx_ring = data;
3190
3191 napi_schedule(&tx_ring->napi);
3192 return IRQ_HANDLED;
3193}
3194
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003195#ifdef CONFIG_NET_POLL_CONTROLLER
3196static void qlcnic_poll_controller(struct net_device *netdev)
3197{
3198 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Manish chopra2b018ad92014-01-23 17:18:31 -05003199 struct qlcnic_host_sds_ring *sds_ring;
3200 struct qlcnic_recv_context *recv_ctx;
3201 struct qlcnic_host_tx_ring *tx_ring;
3202 int ring;
Yinglin Luanbf827912010-08-22 21:57:56 +00003203
Manish chopra2b018ad92014-01-23 17:18:31 -05003204 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3205 return;
3206
3207 recv_ctx = adapter->recv_ctx;
3208
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003209 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Yinglin Luanbf827912010-08-22 21:57:56 +00003210 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2b018ad92014-01-23 17:18:31 -05003211 qlcnic_disable_sds_intr(adapter, sds_ring);
3212 napi_schedule(&sds_ring->napi);
Yinglin Luanbf827912010-08-22 21:57:56 +00003213 }
Manish chopra2b018ad92014-01-23 17:18:31 -05003214
3215 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
3216 /* Only Multi-Tx queue capable devices need to
3217 * schedule NAPI for TX rings
3218 */
3219 if ((qlcnic_83xx_check(adapter) &&
3220 (adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
3221 (qlcnic_82xx_check(adapter) &&
3222 !qlcnic_check_multi_tx(adapter)))
3223 return;
3224
3225 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
3226 tx_ring = &adapter->tx_ring[ring];
3227 qlcnic_disable_tx_intr(adapter, tx_ring);
3228 napi_schedule(&tx_ring->napi);
3229 }
3230 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003231}
3232#endif
3233
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003234static void
3235qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
3236{
3237 u32 val;
3238
3239 val = adapter->portnum & 0xf;
3240 val |= encoding << 7;
3241 val |= (jiffies - adapter->dev_rst_time) << 8;
3242
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003243 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003244 adapter->dev_rst_time = jiffies;
3245}
3246
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003247static int
3248qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003249{
3250 u32 val;
3251
3252 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
3253 state != QLCNIC_DEV_NEED_QUISCENT);
3254
3255 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003256 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003257
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003258 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003259
3260 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003261 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003262 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003263 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003264
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003265 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003266
3267 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003268
3269 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003270}
3271
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003272static int
3273qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
3274{
3275 u32 val;
3276
3277 if (qlcnic_api_lock(adapter))
3278 return -EBUSY;
3279
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003280 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003281 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003282 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003283
3284 qlcnic_api_unlock(adapter);
3285
3286 return 0;
3287}
3288
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003289void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003290{
3291 u32 val;
3292
3293 if (qlcnic_api_lock(adapter))
3294 goto err;
3295
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003296 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003297 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003298 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003299
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003300 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003301 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3302 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003303 dev_info(&adapter->pdev->dev,
3304 "Device state set to Failed. Please Reboot\n");
3305 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003306 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3307 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003308
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003309 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003310 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003311 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003312
3313 qlcnic_api_unlock(adapter);
3314err:
3315 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003316 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003317 clear_bit(__QLCNIC_START_FW, &adapter->state);
3318 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3319}
3320
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003321/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003322static int
3323qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
3324{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003325 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003326 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003327
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003328 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
3329 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003330
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003331 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003332 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003333 act = act & active_mask;
3334 }
3335
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003336 if (((state & 0x11111111) == (act & 0x11111111)) ||
3337 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
3338 return 0;
3339 else
3340 return 1;
3341}
3342
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003343static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
3344{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003345 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003346
3347 if (val != QLCNIC_DRV_IDC_VER) {
3348 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
3349 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
3350 }
3351
3352 return 0;
3353}
3354
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003355static int
3356qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
3357{
3358 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003359 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003360 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003361 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003362
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003363 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
3364 return 1;
3365
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003366 if (qlcnic_api_lock(adapter))
3367 return -1;
3368
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003369 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003370 if (!(val & (1 << (portnum * 4)))) {
3371 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003372 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003373 }
3374
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003375 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003376 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003377
3378 switch (prev_state) {
3379 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003380 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3381 QLCNIC_DEV_INITIALIZING);
3382 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3383 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003384 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003385 qlcnic_api_unlock(adapter);
3386 return 1;
3387
3388 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003389 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003390 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003391 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003392
3393 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003394 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003395 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003396 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003397 break;
3398
3399 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003400 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003401 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003402 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003403 break;
3404
3405 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003406 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003407 qlcnic_api_unlock(adapter);
3408 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003409
3410 case QLCNIC_DEV_INITIALIZING:
3411 case QLCNIC_DEV_QUISCENT:
3412 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003413 }
3414
3415 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003416
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003417 do {
3418 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003419 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003420
3421 if (prev_state == QLCNIC_DEV_QUISCENT)
3422 continue;
3423 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003424
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003425 if (!dev_init_timeo) {
3426 dev_err(&adapter->pdev->dev,
3427 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003428 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003429 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003430
3431 if (qlcnic_api_lock(adapter))
3432 return -1;
3433
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003434 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003435 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003436 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003437
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003438 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003439 qlcnic_api_unlock(adapter);
3440
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003441 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003442}
3443
3444static void
3445qlcnic_fwinit_work(struct work_struct *work)
3446{
3447 struct qlcnic_adapter *adapter = container_of(work,
3448 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003449 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003450 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003451
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003452 if (qlcnic_api_lock(adapter))
3453 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003454
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003455 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003456 if (dev_state == QLCNIC_DEV_QUISCENT ||
3457 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003458 qlcnic_api_unlock(adapter);
3459 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3460 FW_POLL_DELAY * 2);
3461 return;
3462 }
3463
Sony Chacko79788452012-12-04 03:33:53 +00003464 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003465 qlcnic_api_unlock(adapter);
3466 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003467 }
3468
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003469 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3470 dev_state == QLCNIC_DEV_READY) {
3471 dev_info(&adapter->pdev->dev, "Detected state change from "
3472 "DEV_NEED_RESET, skipping ack check\n");
3473 goto skip_ack_check;
3474 }
3475
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003476 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003477 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003478 adapter->reset_ack_timeo);
3479 goto skip_ack_check;
3480 }
3481
3482 if (!qlcnic_check_drv_state(adapter)) {
3483skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003484 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003485
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003486 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003487 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3488 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003489 set_bit(__QLCNIC_START_FW, &adapter->state);
3490 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003491 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003492 val = QLC_SHARED_REG_RD32(adapter,
3493 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003494 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003495 QLC_SHARED_REG_WR32(adapter,
3496 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003497 }
3498
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003499 qlcnic_api_unlock(adapter);
3500
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003501 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003502 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003503 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003504 QLCDB(adapter, DRV, "Take FW dump\n");
3505 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003506 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003507 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003508 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003509
3510 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003511 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003512 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003513 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003514 return;
3515 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003516 goto err_ret;
3517 }
3518
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003519 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003520
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003521wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003522 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003523 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003524
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003525 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003526 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003527 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003528 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003529 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003530 return;
3531 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003532 case QLCNIC_DEV_FAILED:
3533 break;
3534 default:
3535 qlcnic_schedule_work(adapter,
3536 qlcnic_fwinit_work, FW_POLL_DELAY);
3537 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003538 }
3539
3540err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003541 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3542 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003543 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003544 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003545}
3546
3547static void
3548qlcnic_detach_work(struct work_struct *work)
3549{
3550 struct qlcnic_adapter *adapter = container_of(work,
3551 struct qlcnic_adapter, fw_work.work);
3552 struct net_device *netdev = adapter->netdev;
3553 u32 status;
3554
3555 netif_device_detach(netdev);
3556
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003557 /* Dont grab rtnl lock during Quiscent mode */
3558 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3559 if (netif_running(netdev))
3560 __qlcnic_down(adapter, netdev);
3561 } else
3562 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003563
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003564 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003565
Sony Chacko44f65b22011-08-29 12:50:26 +00003566 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3567 dev_err(&adapter->pdev->dev,
3568 "Detaching the device: peg halt status1=0x%x\n",
3569 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003570
Sony Chacko44f65b22011-08-29 12:50:26 +00003571 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3572 dev_err(&adapter->pdev->dev,
3573 "On board active cooling fan failed. "
3574 "Device has been halted.\n");
3575 dev_err(&adapter->pdev->dev,
3576 "Replace the adapter.\n");
3577 }
3578
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003579 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003580 }
3581
Sony Chacko79788452012-12-04 03:33:53 +00003582 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003583 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003584 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003585 goto err_ret;
3586 }
3587
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003588 /* Dont ack if this instance is the reset owner */
3589 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003590 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3591 dev_err(&adapter->pdev->dev,
3592 "Failed to set driver state,"
3593 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003594 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003595 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003596 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003597
3598 adapter->fw_wait_cnt = 0;
3599
3600 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3601
3602 return;
3603
3604err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003605 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003606 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003607}
3608
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003609/*Transit NPAR state to NON Operational */
3610static void
3611qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3612{
3613 u32 state;
3614
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003615 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003616 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3617 return;
3618
3619 if (qlcnic_api_lock(adapter))
3620 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003621 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3622 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003623 qlcnic_api_unlock(adapter);
3624}
3625
stephen hemminger21041402014-01-16 10:31:27 -08003626static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter,
3627 u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003628{
Sritej Velaga646779f2012-02-03 13:45:41 +00003629 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003630
Sritej Velaga646779f2012-02-03 13:45:41 +00003631 qlcnic_xg_set_xg0_mask(xg_val);
3632 qlcnic_xg_set_xg1_mask(xg_val);
3633 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3634 qlcnic_gb_set_gb0_mask(gb_val);
3635 qlcnic_gb_set_gb1_mask(gb_val);
3636 qlcnic_gb_set_gb2_mask(gb_val);
3637 qlcnic_gb_set_gb3_mask(gb_val);
3638 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3639 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3640 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003641 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003642
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003643 if (qlcnic_api_lock(adapter))
3644 return;
3645
Sony Chacko13159182013-01-01 03:20:21 +00003646 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05003647
3648 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
3649 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n",
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003650 __func__);
3651 qlcnic_api_unlock(adapter);
3652
3653 return;
3654 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003655
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003656 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003657 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3658 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003659 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003660 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003661 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003662 }
3663
Sony Chacko13159182013-01-01 03:20:21 +00003664 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3665 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003666 qlcnic_api_unlock(adapter);
3667}
3668
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003669/* Transit to NPAR READY state from NPAR NOT READY state */
3670static void
3671qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3672{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003673 if (qlcnic_api_lock(adapter))
3674 return;
3675
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003676 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3677 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003678 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003679
3680 qlcnic_api_unlock(adapter);
3681}
3682
Sony Chacko13159182013-01-01 03:20:21 +00003683void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3684 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003685{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003686 if (test_bit(__QLCNIC_AER, &adapter->state))
3687 return;
3688
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003689 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003690 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3691 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003692}
3693
3694static void
3695qlcnic_attach_work(struct work_struct *work)
3696{
3697 struct qlcnic_adapter *adapter = container_of(work,
3698 struct qlcnic_adapter, fw_work.work);
3699 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003700 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003701
Sony Chacko79788452012-12-04 03:33:53 +00003702 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003703 npar_state = QLC_SHARED_REG_RD32(adapter,
3704 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003705 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3706 qlcnic_clr_all_drv_state(adapter, 0);
3707 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3708 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3709 FW_POLL_DELAY);
3710 else
3711 goto attach;
3712 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3713 return;
3714 }
3715attach:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04003716 qlcnic_dcb_get_info(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003717
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003718 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003719 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003720 goto done;
3721
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003722 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003723 }
3724
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003725done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003726 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003727 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003728 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003729 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003730 if (adapter->portnum == 0)
3731 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003732
3733 if (!qlcnic_clr_drv_state(adapter))
3734 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3735 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003736}
3737
3738static int
3739qlcnic_check_health(struct qlcnic_adapter *adapter)
3740{
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003741 struct qlcnic_hardware_context *ahw = adapter->ahw;
3742 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sony Chacko4e708122010-08-31 17:17:44 +00003743 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003744 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003745 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003746
3747 if (qlcnic_check_temp(adapter))
3748 goto detach;
3749
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003750 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003751 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003752
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003753 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003754 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003755 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003756 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003757 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3758 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003759
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003760 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003761 if (heartbeat != adapter->heartbeat) {
3762 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003763 adapter->fw_fail_cnt = 0;
3764 if (adapter->need_fw_reset)
3765 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003766
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003767 if (ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003768 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003769
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003770 return 0;
3771 }
3772
3773 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3774 return 0;
3775
Sritej Velaga032a13c2011-07-29 13:30:27 +00003776 adapter->flags |= QLCNIC_FW_HANG;
3777
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003778 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003779
Sony Chacko099f7aa2012-12-04 03:33:58 +00003780 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003781 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003782
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003783 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003784 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003785 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003786 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3787 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3788 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3789 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003790 peg_status,
3791 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003792 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3793 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3794 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3795 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3796 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003797 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003798 dev_err(&adapter->pdev->dev,
3799 "Firmware aborted with error code 0x00006700. "
3800 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003801detach:
3802 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3803 QLCNIC_DEV_NEED_RESET;
3804
Sony Chacko099f7aa2012-12-04 03:33:58 +00003805 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3806 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003807
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003808 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003809 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003810 } else if (!qlcnic_auto_fw_reset && fw_dump->enable &&
3811 adapter->flags & QLCNIC_FW_RESET_OWNER) {
3812 qlcnic_dump_fw(adapter);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003813 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003814
3815 return 1;
3816}
3817
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003818void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003819{
3820 struct qlcnic_adapter *adapter = container_of(work,
3821 struct qlcnic_adapter, fw_work.work);
3822
3823 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3824 goto reschedule;
3825
3826
3827 if (qlcnic_check_health(adapter))
3828 return;
3829
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003830 if (adapter->fhash.fnum)
3831 qlcnic_prune_lb_filters(adapter);
3832
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003833reschedule:
3834 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3835}
3836
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003837static int qlcnic_is_first_func(struct pci_dev *pdev)
3838{
3839 struct pci_dev *oth_pdev;
3840 int val = pdev->devfn;
3841
3842 while (val-- > 0) {
3843 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3844 (pdev->bus), pdev->bus->number,
3845 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003846 if (!oth_pdev)
3847 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003848
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003849 if (oth_pdev->current_state != PCI_D3cold) {
3850 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003851 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003852 }
3853 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003854 }
3855 return 1;
3856}
3857
3858static int qlcnic_attach_func(struct pci_dev *pdev)
3859{
3860 int err, first_func;
3861 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3862 struct net_device *netdev = adapter->netdev;
3863
3864 pdev->error_state = pci_channel_io_normal;
3865
3866 err = pci_enable_device(pdev);
3867 if (err)
3868 return err;
3869
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003870 pci_set_master(pdev);
3871 pci_restore_state(pdev);
3872
3873 first_func = qlcnic_is_first_func(pdev);
3874
3875 if (qlcnic_api_lock(adapter))
3876 return -EINVAL;
3877
Sony Chacko79788452012-12-04 03:33:53 +00003878 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003879 adapter->need_fw_reset = 1;
3880 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003881 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3882 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003883 QLCDB(adapter, DRV, "Restarting fw\n");
3884 }
3885 qlcnic_api_unlock(adapter);
3886
Sony Chacko13159182013-01-01 03:20:21 +00003887 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003888 if (err)
3889 return err;
3890
3891 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003892 kfree(adapter->msix_entries);
3893 adapter->msix_entries = NULL;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003894 err = qlcnic_setup_intr(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003895
Manish chopra9a97e702013-01-25 10:20:37 +00003896 if (err) {
3897 kfree(adapter->msix_entries);
3898 netdev_err(netdev, "failed to setup interrupt\n");
3899 return err;
3900 }
3901
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003902 if (netif_running(netdev)) {
3903 err = qlcnic_attach(adapter);
3904 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003905 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003906 clear_bit(__QLCNIC_AER, &adapter->state);
3907 netif_device_attach(netdev);
3908 return err;
3909 }
3910
3911 err = qlcnic_up(adapter, netdev);
3912 if (err)
3913 goto done;
3914
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003915 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003916 }
3917 done:
3918 netif_device_attach(netdev);
3919 return err;
3920}
3921
stephen hemminger21041402014-01-16 10:31:27 -08003922static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3923 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003924{
3925 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3926 struct net_device *netdev = adapter->netdev;
3927
3928 if (state == pci_channel_io_perm_failure)
3929 return PCI_ERS_RESULT_DISCONNECT;
3930
3931 if (state == pci_channel_io_normal)
3932 return PCI_ERS_RESULT_RECOVERED;
3933
3934 set_bit(__QLCNIC_AER, &adapter->state);
3935 netif_device_detach(netdev);
3936
3937 cancel_delayed_work_sync(&adapter->fw_work);
3938
3939 if (netif_running(netdev))
3940 qlcnic_down(adapter, netdev);
3941
3942 qlcnic_detach(adapter);
3943 qlcnic_teardown_intr(adapter);
3944
3945 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3946
3947 pci_save_state(pdev);
3948 pci_disable_device(pdev);
3949
3950 return PCI_ERS_RESULT_NEED_RESET;
3951}
3952
stephen hemminger21041402014-01-16 10:31:27 -08003953static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003954{
Hannes Frederic Sowa50d65d72016-04-18 21:19:46 +02003955 pci_ers_result_t res;
3956
3957 rtnl_lock();
3958 res = qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3959 PCI_ERS_RESULT_RECOVERED;
3960 rtnl_unlock();
3961
3962 return res;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003963}
3964
stephen hemminger21041402014-01-16 10:31:27 -08003965static void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003966{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003967 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003968 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3969
3970 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003971 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3972 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3973 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003974 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003975 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003976}
3977
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003978static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3979 pci_channel_state_t state)
3980{
3981 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3982 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3983
3984 if (hw_ops->io_error_detected) {
3985 return hw_ops->io_error_detected(pdev, state);
3986 } else {
3987 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3988 return PCI_ERS_RESULT_DISCONNECT;
3989 }
3990}
3991
3992static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3993{
3994 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3995 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3996
3997 if (hw_ops->io_slot_reset) {
3998 return hw_ops->io_slot_reset(pdev);
3999 } else {
4000 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
4001 return PCI_ERS_RESULT_DISCONNECT;
4002 }
4003}
4004
4005static void qlcnic_io_resume(struct pci_dev *pdev)
4006{
4007 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
4008 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
4009
4010 if (hw_ops->io_resume)
4011 hw_ops->io_resume(pdev);
4012 else
4013 dev_err(&pdev->dev, "AER resume handler not registered.\n");
4014}
4015
4016
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00004017static int
4018qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
4019{
4020 int err;
4021
4022 err = qlcnic_can_start_firmware(adapter);
4023 if (err)
4024 return err;
4025
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00004026 err = qlcnic_check_npar_opertional(adapter);
4027 if (err)
4028 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00004029
Rajesh Borundia174240a2010-08-31 17:17:47 +00004030 err = qlcnic_initialize_nic(adapter);
4031 if (err)
4032 return err;
4033
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00004034 qlcnic_check_options(adapter);
4035
Rajesh Borundia73733732010-08-31 17:17:50 +00004036 err = qlcnic_set_eswitch_port_config(adapter);
4037 if (err)
4038 return err;
4039
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00004040 adapter->need_fw_reset = 0;
4041
4042 return err;
4043}
4044
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004045int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
4046 int queue_type)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004047{
4048 struct net_device *netdev = adapter->netdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004049 u8 max_hw_rings = 0;
4050 char buf[8];
4051 int cur_rings;
4052
4053 if (queue_type == QLCNIC_RX_QUEUE) {
4054 max_hw_rings = adapter->max_sds_rings;
4055 cur_rings = adapter->drv_sds_rings;
4056 strcpy(buf, "SDS");
4057 } else if (queue_type == QLCNIC_TX_QUEUE) {
Himanshu Madhani18afc102013-11-04 13:31:32 -05004058 max_hw_rings = adapter->max_tx_rings;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004059 cur_rings = adapter->drv_tx_rings;
4060 strcpy(buf, "Tx");
4061 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004062
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004063 if (!is_power_of_2(ring_cnt)) {
4064 netdev_err(netdev, "%s rings value should be a power of 2\n",
4065 buf);
4066 return -EINVAL;
4067 }
4068
4069 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) &&
4070 !qlcnic_check_multi_tx(adapter)) {
4071 netdev_err(netdev, "No Multi Tx queue support\n");
4072 return -EINVAL;
4073 }
4074
4075 if (ring_cnt > num_online_cpus()) {
4076 netdev_err(netdev,
4077 "%s value[%u] should not be higher than, number of online CPUs\n",
4078 buf, num_online_cpus());
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004079 return -EINVAL;
4080 }
4081
4082 return 0;
4083}
4084
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05004085int qlcnic_setup_rings(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004086{
Manish Chopra6389b762013-04-24 12:42:39 +00004087 struct net_device *netdev = adapter->netdev;
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004088 u8 tx_rings, rx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00004089 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004090
Sony Chacko319ecf12013-01-01 03:20:22 +00004091 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
4092 return -EBUSY;
4093
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004094 tx_rings = adapter->drv_tss_rings;
4095 rx_rings = adapter->drv_rss_rings;
4096
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004097 netif_device_detach(netdev);
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004098
4099 err = qlcnic_set_real_num_queues(adapter, tx_rings, rx_rings);
4100 if (err)
4101 goto done;
4102
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004103 if (netif_running(netdev))
4104 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00004105
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004106 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004107
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004108 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004109 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004110 qlcnic_83xx_enable_mbx_poll(adapter);
4111 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004112
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004113 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004114
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004115 err = qlcnic_setup_intr(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +00004116 if (err) {
4117 kfree(adapter->msix_entries);
4118 netdev_err(netdev, "failed to setup interrupt\n");
4119 return err;
4120 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004121
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004122 /* Check if we need to update real_num_{tx|rx}_queues because
4123 * qlcnic_setup_intr() may change Tx/Rx rings size
4124 */
4125 if ((tx_rings != adapter->drv_tx_rings) ||
4126 (rx_rings != adapter->drv_sds_rings)) {
4127 err = qlcnic_set_real_num_queues(adapter,
4128 adapter->drv_tx_rings,
4129 adapter->drv_sds_rings);
4130 if (err)
4131 goto done;
4132 }
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05004133
Sony Chacko13159182013-01-01 03:20:21 +00004134 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05004135 qlcnic_83xx_initialize_nic(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00004136 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004137 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00004138 if (err) {
4139 dev_err(&adapter->pdev->dev,
4140 "failed to setup mbx interrupt\n");
4141 goto done;
4142 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004143 }
4144
4145 if (netif_running(netdev)) {
4146 err = qlcnic_attach(adapter);
4147 if (err)
4148 goto done;
4149 err = __qlcnic_up(adapter, netdev);
4150 if (err)
4151 goto done;
4152 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
4153 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004154done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004155 netif_device_attach(netdev);
4156 clear_bit(__QLCNIC_RESETTING, &adapter->state);
4157 return err;
4158}
4159
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004160#ifdef CONFIG_INET
4161
4162#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4163
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004164static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004165qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4166 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004167{
4168 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004169
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004170 indev = in_dev_get(dev);
4171 if (!indev)
4172 return;
4173
4174 for_ifa(indev) {
4175 switch (event) {
4176 case NETDEV_UP:
4177 qlcnic_config_ipaddr(adapter,
4178 ifa->ifa_address, QLCNIC_IP_UP);
4179 break;
4180 case NETDEV_DOWN:
4181 qlcnic_config_ipaddr(adapter,
4182 ifa->ifa_address, QLCNIC_IP_DOWN);
4183 break;
4184 default:
4185 break;
4186 }
4187 } endfor_ifa(indev);
4188
4189 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004190}
4191
Sony Chacko319ecf12013-01-01 03:20:22 +00004192void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004193{
4194 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4195 struct net_device *dev;
4196 u16 vid;
4197
4198 qlcnic_config_indev_addr(adapter, netdev, event);
4199
Jiri Pirko43c00a72013-01-03 22:48:57 +00004200 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00004201 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
dingtianhongf06c7f9f2014-05-09 14:58:05 +08004202 dev = __vlan_find_dev_deep_rcu(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004203 if (!dev)
4204 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004205 qlcnic_config_indev_addr(adapter, dev, event);
4206 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00004207 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004208}
4209
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004210static int qlcnic_netdev_event(struct notifier_block *this,
4211 unsigned long event, void *ptr)
4212{
4213 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00004214 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004215
4216recheck:
4217 if (dev == NULL)
4218 goto done;
4219
4220 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4221 dev = vlan_dev_real_dev(dev);
4222 goto recheck;
4223 }
4224
4225 if (!is_qlcnic_netdev(dev))
4226 goto done;
4227
4228 adapter = netdev_priv(dev);
4229
4230 if (!adapter)
4231 goto done;
4232
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004233 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004234 goto done;
4235
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004236 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004237done:
4238 return NOTIFY_DONE;
4239}
4240
4241static int
4242qlcnic_inetaddr_event(struct notifier_block *this,
4243 unsigned long event, void *ptr)
4244{
4245 struct qlcnic_adapter *adapter;
4246 struct net_device *dev;
4247
4248 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4249
4250 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4251
4252recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004253 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004254 goto done;
4255
4256 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4257 dev = vlan_dev_real_dev(dev);
4258 goto recheck;
4259 }
4260
4261 if (!is_qlcnic_netdev(dev))
4262 goto done;
4263
4264 adapter = netdev_priv(dev);
4265
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00004266 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004267 goto done;
4268
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004269 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004270 goto done;
4271
4272 switch (event) {
4273 case NETDEV_UP:
4274 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00004275
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004276 break;
4277 case NETDEV_DOWN:
4278 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00004279
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004280 break;
4281 default:
4282 break;
4283 }
4284
4285done:
4286 return NOTIFY_DONE;
4287}
4288
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004289static struct notifier_block qlcnic_netdev_cb = {
4290 .notifier_call = qlcnic_netdev_event,
4291};
4292
4293static struct notifier_block qlcnic_inetaddr_cb = {
4294 .notifier_call = qlcnic_inetaddr_event,
4295};
4296#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00004297void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004298{ }
4299#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00004300static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004301 .error_detected = qlcnic_io_error_detected,
4302 .slot_reset = qlcnic_io_slot_reset,
4303 .resume = qlcnic_io_resume,
4304};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004305
4306static struct pci_driver qlcnic_driver = {
4307 .name = qlcnic_driver_name,
4308 .id_table = qlcnic_pci_tbl,
4309 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05004310 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004311#ifdef CONFIG_PM
4312 .suspend = qlcnic_suspend,
4313 .resume = qlcnic_resume,
4314#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004315 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00004316 .err_handler = &qlcnic_err_handler,
4317#ifdef CONFIG_QLCNIC_SRIOV
4318 .sriov_configure = qlcnic_pci_sriov_configure,
4319#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004320
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004321};
4322
4323static int __init qlcnic_init_module(void)
4324{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004325 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004326
4327 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4328
4329#ifdef CONFIG_INET
4330 register_netdevice_notifier(&qlcnic_netdev_cb);
4331 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4332#endif
4333
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004334 ret = pci_register_driver(&qlcnic_driver);
4335 if (ret) {
4336#ifdef CONFIG_INET
4337 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4338 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4339#endif
4340 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004341
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004342 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004343}
4344
4345module_init(qlcnic_init_module);
4346
4347static void __exit qlcnic_exit_module(void)
4348{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004349 pci_unregister_driver(&qlcnic_driver);
4350
4351#ifdef CONFIG_INET
4352 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4353 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4354#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004355}
4356
4357module_exit(qlcnic_exit_module);