blob: 158e1d9f255f124dd905b56dcf40f14f86ba0330 [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>
10
11#include "qlcnic.h"
Rajesh Borundia02feda12013-03-29 05:46:33 +000012#include "qlcnic_sriov.h"
Himanshu Madhania15ebd32013-01-01 03:20:18 +000013#include "qlcnic_hw.h"
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000014
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000015#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000016#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000017#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000018#include <net/ip.h>
19#include <linux/ipv6.h>
20#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000021#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000022#include <linux/log2.h>
Stephen Rothwell47caf252013-01-02 17:23:53 +000023#include <linux/pci.h>
Shahed Shaikh7f1f6052014-04-01 16:29:32 -040024#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -040025#include <net/vxlan.h>
Shahed Shaikh7f1f6052014-04-01 16:29:32 -040026#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000027
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000028MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000029MODULE_LICENSE("GPL");
30MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
31MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
32
33char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000034static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
35 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000036
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000037static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000038module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000039MODULE_PARM_DESC(qlcnic_mac_learn,
40 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000041
Sony Chacko629263a2013-01-01 04:11:55 +000042int qlcnic_use_msi = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000043MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000044module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000045
Sony Chacko629263a2013-01-01 04:11:55 +000046int qlcnic_use_msi_x = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000047MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000048module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000049
Sony Chacko629263a2013-01-01 04:11:55 +000050int qlcnic_auto_fw_reset = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000051MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000052module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000053
Sony Chacko629263a2013-01-01 04:11:55 +000054int qlcnic_load_fw_file;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000055MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000056module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000057
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000058static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050059static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000060static int qlcnic_open(struct net_device *netdev);
61static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000062static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000063static void qlcnic_attach_work(struct work_struct *work);
64static void qlcnic_fwinit_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000065#ifdef CONFIG_NET_POLL_CONTROLLER
66static void qlcnic_poll_controller(struct net_device *netdev);
67#endif
68
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000069static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000070static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
71
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000072static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000073static irqreturn_t qlcnic_intr(int irq, void *data);
74static irqreturn_t qlcnic_msi_intr(int irq, void *data);
75static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000076static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000077
78static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000079static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000080
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000081static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000082static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000083static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000084static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
85static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000086
stephen hemminger21041402014-01-16 10:31:27 -080087static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *);
88static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *, u32);
89static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *);
90static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *);
91static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *);
92static void qlcnic_82xx_io_resume(struct pci_dev *);
93static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *);
94static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *,
95 pci_channel_state_t);
Sony Chacko13159182013-01-01 03:20:21 +000096static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
97{
98 struct qlcnic_hardware_context *ahw = adapter->ahw;
99
100 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
101 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
102 else
103 return 1;
104}
105
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000106/* PCI Device ID Table */
107#define ENTRY(device) \
108 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
109 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
110
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000111static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000112 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000113 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000114 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Manish Chopra15ca1402013-08-16 19:07:13 -0400115 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X),
116 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000117 {0,}
118};
119
120MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
121
122
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000123inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000124{
125 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000126}
127
128static const u32 msi_tgt_status[8] = {
129 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
130 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
131 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
132 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
133};
134
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000135static const u32 qlcnic_reg_tbl[] = {
136 0x1B20A8, /* PEG_HALT_STAT1 */
137 0x1B20AC, /* PEG_HALT_STAT2 */
138 0x1B20B0, /* FW_HEARTBEAT */
139 0x1B2100, /* LOCK ID */
140 0x1B2128, /* FW_CAPABILITIES */
141 0x1B2138, /* drv active */
142 0x1B2140, /* dev state */
143 0x1B2144, /* drv state */
144 0x1B2148, /* drv scratch */
145 0x1B214C, /* dev partition info */
146 0x1B2174, /* drv idc ver */
147 0x1B2150, /* fw version major */
148 0x1B2154, /* fw version minor */
149 0x1B2158, /* fw version sub */
150 0x1B219C, /* npar state */
151 0x1B21FC, /* FW_IMG_VALID */
152 0x1B2250, /* CMD_PEG_STATE */
153 0x1B233C, /* RCV_PEG_STATE */
154 0x1B23B4, /* ASIC TEMP */
155 0x1B216C, /* FW api */
156 0x1B2170, /* drv op mode */
157 0x13C010, /* flash lock */
158 0x13C014, /* flash unlock */
159};
160
Sony Chacko22999792012-12-04 03:33:55 +0000161static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000162 { PCI_VENDOR_ID_QLOGIC,
Manish Chopra15ca1402013-08-16 19:07:13 -0400163 PCI_DEVICE_ID_QLOGIC_QLE844X,
164 0x0,
165 0x0,
166 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
167 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000168 PCI_DEVICE_ID_QLOGIC_QLE834X,
169 PCI_VENDOR_ID_QLOGIC,
170 0x24e,
171 "8300 Series Dual Port 10GbE Converged Network Adapter "
172 "(TCP/IP Networking)" },
173 { PCI_VENDOR_ID_QLOGIC,
174 PCI_DEVICE_ID_QLOGIC_QLE834X,
175 PCI_VENDOR_ID_QLOGIC,
176 0x243,
177 "8300 Series Single Port 10GbE Converged Network Adapter "
178 "(TCP/IP Networking)" },
179 { PCI_VENDOR_ID_QLOGIC,
180 PCI_DEVICE_ID_QLOGIC_QLE834X,
181 PCI_VENDOR_ID_QLOGIC,
182 0x24a,
183 "8300 Series Dual Port 10GbE Converged Network Adapter "
184 "(TCP/IP Networking)" },
185 { PCI_VENDOR_ID_QLOGIC,
186 PCI_DEVICE_ID_QLOGIC_QLE834X,
187 PCI_VENDOR_ID_QLOGIC,
188 0x246,
189 "8300 Series Dual Port 10GbE Converged Network Adapter "
190 "(TCP/IP Networking)" },
191 { PCI_VENDOR_ID_QLOGIC,
192 PCI_DEVICE_ID_QLOGIC_QLE834X,
193 PCI_VENDOR_ID_QLOGIC,
194 0x252,
195 "8300 Series Dual Port 10GbE Converged Network Adapter "
196 "(TCP/IP Networking)" },
197 { PCI_VENDOR_ID_QLOGIC,
198 PCI_DEVICE_ID_QLOGIC_QLE834X,
199 PCI_VENDOR_ID_QLOGIC,
200 0x26e,
201 "8300 Series Dual Port 10GbE Converged Network Adapter "
202 "(TCP/IP Networking)" },
203 { PCI_VENDOR_ID_QLOGIC,
204 PCI_DEVICE_ID_QLOGIC_QLE834X,
205 PCI_VENDOR_ID_QLOGIC,
206 0x260,
207 "8300 Series Dual Port 10GbE Converged Network Adapter "
208 "(TCP/IP Networking)" },
209 { PCI_VENDOR_ID_QLOGIC,
210 PCI_DEVICE_ID_QLOGIC_QLE834X,
211 PCI_VENDOR_ID_QLOGIC,
212 0x266,
213 "8300 Series Single Port 10GbE Converged Network Adapter "
214 "(TCP/IP Networking)" },
215 { PCI_VENDOR_ID_QLOGIC,
216 PCI_DEVICE_ID_QLOGIC_QLE834X,
217 PCI_VENDOR_ID_QLOGIC,
218 0x269,
219 "8300 Series Dual Port 10GbE Converged Network Adapter "
220 "(TCP/IP Networking)" },
221 { PCI_VENDOR_ID_QLOGIC,
222 PCI_DEVICE_ID_QLOGIC_QLE834X,
223 PCI_VENDOR_ID_QLOGIC,
224 0x271,
225 "8300 Series Dual Port 10GbE Converged Network Adapter "
226 "(TCP/IP Networking)" },
227 { PCI_VENDOR_ID_QLOGIC,
228 PCI_DEVICE_ID_QLOGIC_QLE834X,
229 0x0, 0x0, "8300 Series 1/10GbE Controller" },
230 { PCI_VENDOR_ID_QLOGIC,
231 PCI_DEVICE_ID_QLOGIC_QLE824X,
232 PCI_VENDOR_ID_QLOGIC,
233 0x203,
234 "8200 Series Single Port 10GbE Converged Network Adapter"
235 "(TCP/IP Networking)" },
236 { PCI_VENDOR_ID_QLOGIC,
237 PCI_DEVICE_ID_QLOGIC_QLE824X,
238 PCI_VENDOR_ID_QLOGIC,
239 0x207,
240 "8200 Series Dual 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 0x20b,
246 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
247 { PCI_VENDOR_ID_QLOGIC,
248 PCI_DEVICE_ID_QLOGIC_QLE824X,
249 PCI_VENDOR_ID_QLOGIC,
250 0x20c,
251 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
252 { PCI_VENDOR_ID_QLOGIC,
253 PCI_DEVICE_ID_QLOGIC_QLE824X,
254 PCI_VENDOR_ID_QLOGIC,
255 0x20f,
256 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
257 { PCI_VENDOR_ID_QLOGIC,
258 PCI_DEVICE_ID_QLOGIC_QLE824X,
259 0x103c, 0x3733,
260 "NC523SFP 10Gb 2-port Server Adapter" },
261 { PCI_VENDOR_ID_QLOGIC,
262 PCI_DEVICE_ID_QLOGIC_QLE824X,
263 0x103c, 0x3346,
264 "CN1000Q Dual Port Converged Network Adapter" },
265 { PCI_VENDOR_ID_QLOGIC,
266 PCI_DEVICE_ID_QLOGIC_QLE824X,
267 PCI_VENDOR_ID_QLOGIC,
268 0x210,
269 "QME8242-k 10GbE Dual Port Mezzanine Card" },
270 { PCI_VENDOR_ID_QLOGIC,
271 PCI_DEVICE_ID_QLOGIC_QLE824X,
272 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000273};
274
275#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
276
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000277static const
278struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
279
Sony Chackoc70001a2012-11-28 04:34:26 +0000280int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000281{
282 int size = sizeof(struct qlcnic_host_sds_ring) * count;
283
284 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
285
Eric Dumazet807540b2010-09-23 05:40:09 +0000286 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000287}
288
Sony Chackoc70001a2012-11-28 04:34:26 +0000289void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000290{
291 if (recv_ctx->sds_rings != NULL)
292 kfree(recv_ctx->sds_rings);
293
294 recv_ctx->sds_rings = NULL;
295}
296
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000297int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000298{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000299 struct net_device *netdev = adapter->netdev;
300 struct pci_dev *pdev = adapter->pdev;
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400301 u8 mac_addr[ETH_ALEN];
302 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000303
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400304 ret = qlcnic_get_mac_address(adapter, mac_addr,
305 adapter->ahw->pci_func);
306 if (ret)
307 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000308
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000309 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000310 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
311
312 /* set station address */
313
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000314 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000315 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
316 netdev->dev_addr);
317
318 return 0;
319}
320
Manish Chopracffe52f2013-05-09 09:25:09 +0000321static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
322{
Manish Chopra154d0c82013-12-17 09:01:53 -0500323 struct qlcnic_mac_vlan_list *cur;
Manish Chopracffe52f2013-05-09 09:25:09 +0000324 struct list_head *head;
325
326 list_for_each(head, &adapter->mac_list) {
Manish Chopra154d0c82013-12-17 09:01:53 -0500327 cur = list_entry(head, struct qlcnic_mac_vlan_list, list);
dingtianhong6878f792013-12-30 15:41:14 +0800328 if (ether_addr_equal_unaligned(adapter->mac_addr, cur->mac_addr)) {
Manish Chopracffe52f2013-05-09 09:25:09 +0000329 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
330 0, QLCNIC_MAC_DEL);
331 list_del(&cur->list);
332 kfree(cur);
333 return;
334 }
335 }
336}
337
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000338static int qlcnic_set_mac(struct net_device *netdev, void *p)
339{
340 struct qlcnic_adapter *adapter = netdev_priv(netdev);
341 struct sockaddr *addr = p;
342
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000343 if (qlcnic_sriov_vf_check(adapter))
344 return -EINVAL;
345
Rajesh Borundia73733732010-08-31 17:17:50 +0000346 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
347 return -EOPNOTSUPP;
348
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000349 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000350 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000351
dingtianhong6878f792013-12-30 15:41:14 +0800352 if (ether_addr_equal_unaligned(adapter->mac_addr, addr->sa_data))
Manish Chopracffe52f2013-05-09 09:25:09 +0000353 return 0;
354
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000355 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000356 netif_device_detach(netdev);
357 qlcnic_napi_disable(adapter);
358 }
359
Manish Chopracffe52f2013-05-09 09:25:09 +0000360 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000361 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
362 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
363 qlcnic_set_multi(adapter->netdev);
364
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000365 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000366 netif_device_attach(netdev);
367 qlcnic_napi_enable(adapter);
368 }
369 return 0;
370}
371
Vlad Yasevich1690be62013-02-13 12:00:18 +0000372static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
373 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000374{
375 struct qlcnic_adapter *adapter = netdev_priv(netdev);
376 int err = -EOPNOTSUPP;
377
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000378 if (!adapter->fdb_mac_learn)
379 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000380
Rajesh Borundiad747c332014-05-09 02:51:31 -0400381 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
382 qlcnic_sriov_check(adapter)) {
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400383 if (is_unicast_ether_addr(addr)) {
384 err = dev_uc_del(netdev, addr);
385 if (!err)
386 err = qlcnic_nic_del_mac(adapter, addr);
387 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000388 err = dev_mc_del(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400389 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000390 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400391 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000392 }
393 return err;
394}
395
396static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
397 struct net_device *netdev,
398 const unsigned char *addr, u16 flags)
399{
400 struct qlcnic_adapter *adapter = netdev_priv(netdev);
401 int err = 0;
402
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000403 if (!adapter->fdb_mac_learn)
404 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000405
Rajesh Borundiad747c332014-05-09 02:51:31 -0400406 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) &&
407 !qlcnic_sriov_check(adapter)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000408 pr_info("%s: FDB e-switch is not enabled\n", __func__);
409 return -EOPNOTSUPP;
410 }
411
412 if (ether_addr_equal(addr, adapter->mac_addr))
413 return err;
414
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400415 if (is_unicast_ether_addr(addr)) {
416 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
417 err = dev_uc_add_excl(netdev, addr);
418 else
419 err = -ENOMEM;
420 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000421 err = dev_mc_add_excl(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400422 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000423 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400424 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000425
426 return err;
427}
428
429static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
430 struct net_device *netdev, int idx)
431{
432 struct qlcnic_adapter *adapter = netdev_priv(netdev);
433
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000434 if (!adapter->fdb_mac_learn)
435 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000436
Rajesh Borundiad747c332014-05-09 02:51:31 -0400437 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
438 qlcnic_sriov_check(adapter))
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000439 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
440
441 return idx;
442}
443
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000444static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
445{
446 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
447 usleep_range(10000, 11000);
448
Sucheta Chakraborty66451612013-09-27 02:12:36 -0400449 if (!adapter->fw_work.work.func)
450 return;
451
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000452 cancel_delayed_work_sync(&adapter->fw_work);
453}
454
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400455static int qlcnic_get_phys_port_id(struct net_device *netdev,
456 struct netdev_phys_port_id *ppid)
457{
458 struct qlcnic_adapter *adapter = netdev_priv(netdev);
459 struct qlcnic_hardware_context *ahw = adapter->ahw;
460
461 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID))
462 return -EOPNOTSUPP;
463
464 ppid->id_len = sizeof(ahw->phys_port_id);
465 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len);
466
467 return 0;
468}
469
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400470#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400471static void qlcnic_add_vxlan_port(struct net_device *netdev,
472 sa_family_t sa_family, __be16 port)
473{
474 struct qlcnic_adapter *adapter = netdev_priv(netdev);
475 struct qlcnic_hardware_context *ahw = adapter->ahw;
476
477 /* Adapter supports only one VXLAN port. Use very first port
478 * for enabling offload
479 */
480 if (!qlcnic_encap_rx_offload(adapter) || ahw->vxlan_port)
481 return;
482
483 ahw->vxlan_port = ntohs(port);
484 adapter->flags |= QLCNIC_ADD_VXLAN_PORT;
485}
486
487static void qlcnic_del_vxlan_port(struct net_device *netdev,
488 sa_family_t sa_family, __be16 port)
489{
490 struct qlcnic_adapter *adapter = netdev_priv(netdev);
491 struct qlcnic_hardware_context *ahw = adapter->ahw;
492
493 if (!qlcnic_encap_rx_offload(adapter) || !ahw->vxlan_port ||
494 (ahw->vxlan_port != ntohs(port)))
495 return;
496
497 adapter->flags |= QLCNIC_DEL_VXLAN_PORT;
498}
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400499#endif
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400500
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000501static const struct net_device_ops qlcnic_netdev_ops = {
502 .ndo_open = qlcnic_open,
503 .ndo_stop = qlcnic_close,
504 .ndo_start_xmit = qlcnic_xmit_frame,
505 .ndo_get_stats = qlcnic_get_stats,
506 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000507 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000508 .ndo_set_mac_address = qlcnic_set_mac,
509 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000510 .ndo_fix_features = qlcnic_fix_features,
511 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000512 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000513 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
514 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000515 .ndo_fdb_add = qlcnic_fdb_add,
516 .ndo_fdb_del = qlcnic_fdb_del,
517 .ndo_fdb_dump = qlcnic_fdb_dump,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400518 .ndo_get_phys_port_id = qlcnic_get_phys_port_id,
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400519#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -0400520 .ndo_add_vxlan_port = qlcnic_add_vxlan_port,
521 .ndo_del_vxlan_port = qlcnic_del_vxlan_port,
Shahed Shaikh7f1f6052014-04-01 16:29:32 -0400522#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000523#ifdef CONFIG_NET_POLL_CONTROLLER
524 .ndo_poll_controller = qlcnic_poll_controller,
525#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000526#ifdef CONFIG_QLCNIC_SRIOV
527 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -0400528 .ndo_set_vf_rate = qlcnic_sriov_set_vf_tx_rate,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000529 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000530 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundiaa80be5a2013-05-23 21:04:25 +0000531 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000532#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000533};
534
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000535static const struct net_device_ops qlcnic_netdev_failed_ops = {
536 .ndo_open = qlcnic_open,
537};
538
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000539static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000540 .config_bridged_mode = qlcnic_config_bridged_mode,
541 .config_led = qlcnic_82xx_config_led,
542 .start_firmware = qlcnic_82xx_start_firmware,
543 .request_reset = qlcnic_82xx_dev_request_reset,
544 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
545 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000546 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000547 .config_ipaddr = qlcnic_82xx_config_ipaddr,
Rajesh Borundia486a5bc2013-06-22 04:12:06 -0400548 .shutdown = qlcnic_82xx_shutdown,
549 .resume = qlcnic_82xx_resume,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000550 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000551};
552
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000553struct qlcnic_nic_template qlcnic_vf_ops = {
554 .config_bridged_mode = qlcnicvf_config_bridged_mode,
555 .config_led = qlcnicvf_config_led,
556 .start_firmware = qlcnicvf_start_firmware
557};
558
559static struct qlcnic_hardware_ops qlcnic_hw_ops = {
560 .read_crb = qlcnic_82xx_read_crb,
561 .write_crb = qlcnic_82xx_write_crb,
562 .read_reg = qlcnic_82xx_hw_read_wx_2M,
563 .write_reg = qlcnic_82xx_hw_write_wx_2M,
564 .get_mac_address = qlcnic_82xx_get_mac_address,
565 .setup_intr = qlcnic_82xx_setup_intr,
566 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
567 .mbx_cmd = qlcnic_82xx_issue_cmd,
568 .get_func_no = qlcnic_82xx_get_func_no,
569 .api_lock = qlcnic_82xx_api_lock,
570 .api_unlock = qlcnic_82xx_api_unlock,
571 .add_sysfs = qlcnic_82xx_add_sysfs,
572 .remove_sysfs = qlcnic_82xx_remove_sysfs,
573 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
574 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
575 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000576 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
577 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000578 .setup_link_event = qlcnic_82xx_linkevent_request,
579 .get_nic_info = qlcnic_82xx_get_nic_info,
580 .get_pci_info = qlcnic_82xx_get_pci_info,
581 .set_nic_info = qlcnic_82xx_set_nic_info,
582 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
583 .napi_enable = qlcnic_82xx_napi_enable,
584 .napi_disable = qlcnic_82xx_napi_disable,
585 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
586 .config_rss = qlcnic_82xx_config_rss,
587 .config_hw_lro = qlcnic_82xx_config_hw_lro,
588 .config_loopback = qlcnic_82xx_set_lb_mode,
589 .clear_loopback = qlcnic_82xx_clear_lb_mode,
590 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
591 .change_l2_filter = qlcnic_82xx_change_filter,
592 .get_board_info = qlcnic_82xx_get_board_info,
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400593 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000594 .free_mac_list = qlcnic_82xx_free_mac_list,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400595 .read_phys_port_id = qlcnic_82xx_read_phys_port_id,
Pratik Pujar4460f2e2013-08-30 13:51:20 -0400596 .io_error_detected = qlcnic_82xx_io_error_detected,
597 .io_slot_reset = qlcnic_82xx_io_slot_reset,
598 .io_resume = qlcnic_82xx_io_resume,
Himanshu Madhania0431582014-01-10 11:48:56 -0500599 .get_beacon_state = qlcnic_82xx_get_beacon_state,
Manish chopra2cc57522014-01-23 17:18:30 -0500600 .enable_sds_intr = qlcnic_82xx_enable_sds_intr,
601 .disable_sds_intr = qlcnic_82xx_disable_sds_intr,
602 .enable_tx_intr = qlcnic_82xx_enable_tx_intr,
603 .disable_tx_intr = qlcnic_82xx_disable_tx_intr,
Shahed Shaikh225837a2014-02-21 13:20:10 -0500604 .get_saved_state = qlcnic_82xx_get_saved_state,
605 .set_saved_state = qlcnic_82xx_set_saved_state,
606 .cache_tmpl_hdr_values = qlcnic_82xx_cache_tmpl_hdr_values,
607 .get_cap_size = qlcnic_82xx_get_cap_size,
608 .set_sys_info = qlcnic_82xx_set_sys_info,
609 .store_cap_mask = qlcnic_82xx_store_cap_mask,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000610};
611
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500612static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter *adapter)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400613{
614 struct qlcnic_hardware_context *ahw = adapter->ahw;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400615
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500616 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400617 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500618 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
619 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400620 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500621 return 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400622 }
623}
624
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500625static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt,
626 int queue_type)
627{
628 int num_rings, max_rings = QLCNIC_MAX_SDS_RINGS;
629
630 if (queue_type == QLCNIC_RX_QUEUE)
631 max_rings = adapter->max_sds_rings;
632 else if (queue_type == QLCNIC_TX_QUEUE)
633 max_rings = adapter->max_tx_rings;
634
635 num_rings = rounddown_pow_of_two(min_t(int, num_online_cpus(),
636 max_rings));
637
638 if (ring_cnt > num_rings)
639 return num_rings;
640 else
641 return ring_cnt;
642}
643
644void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt)
645{
646 /* 83xx adapter does not have max_tx_rings intialized in probe */
647 if (adapter->max_tx_rings)
648 adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt,
649 QLCNIC_TX_QUEUE);
650 else
651 adapter->drv_tx_rings = tx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500652}
653
654void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt)
655{
656 /* 83xx adapter does not have max_sds_rings intialized in probe */
657 if (adapter->max_sds_rings)
658 adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt,
659 QLCNIC_RX_QUEUE);
660 else
661 adapter->drv_sds_rings = rx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500662}
663
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500664int qlcnic_setup_tss_rss_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000665{
666 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500667 int num_msix = 0, err = 0, vector;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000668
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500669 adapter->flags &= ~QLCNIC_TSS_RSS;
670
671 if (adapter->drv_tss_rings > 0)
672 num_msix += adapter->drv_tss_rings;
673 else
674 num_msix += adapter->drv_tx_rings;
675
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200676 if (adapter->drv_rss_rings > 0)
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500677 num_msix += adapter->drv_rss_rings;
678 else
679 num_msix += adapter->drv_sds_rings;
680
681 if (qlcnic_83xx_check(adapter))
682 num_msix += 1;
Sony Chacko13159182013-01-01 03:20:21 +0000683
684 if (!adapter->msix_entries) {
685 adapter->msix_entries = kcalloc(num_msix,
686 sizeof(struct msix_entry),
687 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000688 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000689 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000690 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000691
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500692 for (vector = 0; vector < num_msix; vector++)
693 adapter->msix_entries[vector].entry = vector;
694
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200695restore:
Alexander Gordeevf7167752014-04-25 11:43:50 +0200696 err = pci_enable_msix_exact(pdev, adapter->msix_entries, num_msix);
697 if (err == -ENOSPC) {
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200698 if (!adapter->drv_tss_rings && !adapter->drv_rss_rings)
Alexander Gordeevf7167752014-04-25 11:43:50 +0200699 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500700
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500701 netdev_info(adapter->netdev,
702 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
703 num_msix, err);
704
705 num_msix = adapter->drv_tx_rings + adapter->drv_sds_rings;
706
707 /* Set rings to 0 so we can restore original TSS/RSS count */
708 adapter->drv_tss_rings = 0;
709 adapter->drv_rss_rings = 0;
710
711 if (qlcnic_83xx_check(adapter))
712 num_msix += 1;
713
714 netdev_info(adapter->netdev,
715 "Restoring %d Tx, %d SDS rings for total %d vectors.\n",
716 adapter->drv_tx_rings, adapter->drv_sds_rings,
717 num_msix);
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500718
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200719 goto restore;
720 } else if (err < 0) {
721 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500722 }
723
Alexander Gordeev8564ae02014-04-15 11:37:14 +0200724 adapter->ahw->num_msix = num_msix;
725 if (adapter->drv_tss_rings > 0)
726 adapter->drv_tx_rings = adapter->drv_tss_rings;
727
728 if (adapter->drv_rss_rings > 0)
729 adapter->drv_sds_rings = adapter->drv_rss_rings;
730
731 return 0;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500732}
733
734int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
735{
736 struct pci_dev *pdev = adapter->pdev;
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100737 int err, vector;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500738
739 if (!adapter->msix_entries) {
740 adapter->msix_entries = kcalloc(num_msix,
741 sizeof(struct msix_entry),
742 GFP_KERNEL);
743 if (!adapter->msix_entries)
744 return -ENOMEM;
745 }
746
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000747 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000748
Sony Chacko79788452012-12-04 03:33:53 +0000749 if (adapter->ahw->msix_supported) {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500750enable_msix:
751 for (vector = 0; vector < num_msix; vector++)
752 adapter->msix_entries[vector].entry = vector;
753
Alexander Gordeev9732ec02014-02-18 11:11:57 +0100754 err = pci_enable_msix_range(pdev,
755 adapter->msix_entries, 1, num_msix);
756
757 if (err == num_msix) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000758 adapter->flags |= QLCNIC_MSIX_ENABLED;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500759 adapter->ahw->num_msix = num_msix;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000760 dev_info(&pdev->dev, "using msi-x interrupts\n");
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100761 return 0;
Sony Chacko13159182013-01-01 03:20:21 +0000762 } else if (err > 0) {
Alexander Gordeev9732ec02014-02-18 11:11:57 +0100763 pci_disable_msix(pdev);
764
Sony Chacko13159182013-01-01 03:20:21 +0000765 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500766 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
767 num_msix, err);
768
769 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +0000770 num_msix = rounddown_pow_of_two(err);
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500771 if (err < QLCNIC_82XX_MINIMUM_VECTOR)
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100772 return -ENOSPC;
Sony Chacko13159182013-01-01 03:20:21 +0000773 } else {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500774 num_msix = rounddown_pow_of_two(err - 1);
775 num_msix += 1;
776 if (err < QLCNIC_83XX_MINIMUM_VECTOR)
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100777 return -ENOSPC;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500778 }
779
780 if (qlcnic_82xx_check(adapter) &&
781 !qlcnic_check_multi_tx(adapter)) {
782 adapter->drv_sds_rings = num_msix;
783 adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
784 } else {
785 /* Distribute vectors equally */
786 adapter->drv_tx_rings = num_msix / 2;
787 adapter->drv_sds_rings = adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000788 }
789
790 if (num_msix) {
791 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000792 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000793 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000794 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000795 }
796 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000797 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500798 "Unable to allocate %d MSI-X vectors, err=%d\n",
799 num_msix, err);
800 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000801 }
802 }
Sony Chacko13159182013-01-01 03:20:21 +0000803
Alexander Gordeev74a1fa42014-02-18 11:11:56 +0100804 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000805}
806
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500807static int qlcnic_82xx_calculate_msix_vector(struct qlcnic_adapter *adapter)
808{
809 int num_msix;
810
811 num_msix = adapter->drv_sds_rings;
812
813 if (qlcnic_check_multi_tx(adapter))
814 num_msix += adapter->drv_tx_rings;
815 else
816 num_msix += QLCNIC_SINGLE_RING;
817
818 return num_msix;
819}
820
Manish chopra9a97e702013-01-25 10:20:37 +0000821static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000822{
Manish chopra9a97e702013-01-25 10:20:37 +0000823 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000824 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000825 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000826 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000827 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000828
Sony Chacko099f7aa2012-12-04 03:33:58 +0000829 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000830 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000831 offset = msi_tgt_status[adapter->ahw->pci_func];
832 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
833 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000834 dev_info(&pdev->dev, "using msi interrupts\n");
835 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000836 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000837 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400838
Manish chopra9a97e702013-01-25 10:20:37 +0000839 if (qlcnic_use_msi || qlcnic_use_msi_x)
840 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000841
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000842 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000843 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000844 offset = legacy_intrp->tgt_status_reg;
845 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
846 mask_reg = legacy_intrp->tgt_mask_reg;
847 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
848 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
849 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000850 dev_info(&pdev->dev, "using legacy interrupts\n");
851 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000852 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000853}
854
stephen hemminger21041402014-01-16 10:31:27 -0800855static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000856{
Manish chopra9a97e702013-01-25 10:20:37 +0000857 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000858
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500859 if (adapter->flags & QLCNIC_TSS_RSS) {
860 err = qlcnic_setup_tss_rss_intr(adapter);
861 if (err < 0)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400862 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500863 num_msix = adapter->ahw->num_msix;
864 } else {
865 num_msix = qlcnic_82xx_calculate_msix_vector(adapter);
866
867 err = qlcnic_enable_msix(adapter, num_msix);
868 if (err == -ENOMEM)
869 return err;
870
871 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
872 qlcnic_disable_multi_tx(adapter);
Rajesh Borundia42beb3f2014-02-24 08:54:49 -0500873 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500874
875 err = qlcnic_enable_msi_legacy(adapter);
Shahed Shaikhfc49bea2014-02-24 08:54:46 -0500876 if (err)
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500877 return err;
878 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400879 }
880
881 return 0;
882}
883
884int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
885{
886 struct qlcnic_hardware_context *ahw = adapter->ahw;
887 int err, i;
888
889 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400890 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400891 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
892 ahw->intr_tbl = vzalloc(ahw->num_msix *
893 sizeof(struct qlcnic_intrpt_config));
894 if (!ahw->intr_tbl)
895 return -ENOMEM;
896
897 for (i = 0; i < ahw->num_msix; i++) {
898 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
899 ahw->intr_tbl[i].id = i;
900 ahw->intr_tbl[i].src = 0;
901 }
902
903 err = qlcnic_82xx_config_intrpt(adapter, 1);
904 if (err)
905 dev_err(&adapter->pdev->dev,
906 "Failed to configure Interrupt for %d vector\n",
907 ahw->num_msix);
908 return err;
909 }
910
911 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000912}
Sony Chacko13159182013-01-01 03:20:21 +0000913
Sony Chacko319ecf12013-01-01 03:20:22 +0000914void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000915{
916 if (adapter->flags & QLCNIC_MSIX_ENABLED)
917 pci_disable_msix(adapter->pdev);
918 if (adapter->flags & QLCNIC_MSI_ENABLED)
919 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000920
921 kfree(adapter->msix_entries);
922 adapter->msix_entries = NULL;
923
924 if (adapter->ahw->intr_tbl) {
925 vfree(adapter->ahw->intr_tbl);
926 adapter->ahw->intr_tbl = NULL;
927 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000928}
929
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000930static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000931{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000932 if (ahw->pci_base0 != NULL)
933 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000934}
935
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000936static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
937{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500938 struct qlcnic_hardware_context *ahw = adapter->ahw;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000939 struct qlcnic_pci_info *pci_info;
940 int ret;
941
942 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500943 switch (ahw->port_type) {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000944 case QLCNIC_GBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500945 ahw->total_nic_func = QLCNIC_NIU_MAX_GBE_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000946 break;
947 case QLCNIC_XGBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500948 ahw->total_nic_func = QLCNIC_NIU_MAX_XG_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000949 break;
950 }
951 return 0;
952 }
953
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500954 if (ahw->op_mode == QLCNIC_MGMT_FUNC)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000955 return 0;
956
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500957 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000958 if (!pci_info)
959 return -ENOMEM;
960
961 ret = qlcnic_get_pci_info(adapter, pci_info);
962 kfree(pci_info);
963 return ret;
964}
Sony Chackod71170f2013-01-01 03:20:26 +0000965
Sony Chacko35dafcb2013-08-30 13:51:23 -0400966static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
967{
968 bool ret = false;
969
970 if (qlcnic_84xx_check(adapter)) {
971 ret = true;
972 } else if (qlcnic_83xx_check(adapter)) {
973 if (adapter->ahw->extra_capability[0] &
974 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
975 ret = true;
976 else
977 ret = false;
978 }
979
980 return ret;
981}
982
Sony Chackod71170f2013-01-01 03:20:26 +0000983int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000984{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500985 struct qlcnic_hardware_context *ahw = adapter->ahw;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000986 struct qlcnic_pci_info *pci_info;
Sony Chacko4c776aa2013-10-18 12:22:32 -0400987 int i, id = 0, ret = 0, j = 0;
Sony Chackobff57d8e2012-12-04 03:33:56 +0000988 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000989 u8 pfn;
990
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500991 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000992 if (!pci_info)
993 return -ENOMEM;
994
Sony Chackobff57d8e2012-12-04 03:33:56 +0000995 ret = qlcnic_get_pci_info(adapter, pci_info);
996 if (ret)
997 goto err_pci_info;
998
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500999 act_pci_func = ahw->total_nic_func;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001000
Dan Carpenterca315ac2010-08-09 21:47:56 +00001001 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d8e2012-12-04 03:33:56 +00001002 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +00001003 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +00001004 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001005 goto err_pci_info;
1006 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001007
Dan Carpenterca315ac2010-08-09 21:47:56 +00001008 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001009 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
1010 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +00001011 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001012 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001013 }
1014
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001015 for (i = 0; i < ahw->max_vnic_func; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +00001016 pfn = pci_info[i].id;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001017
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001018 if (pfn >= ahw->max_vnic_func) {
Sony Chackof848d6d2011-04-01 14:27:59 +00001019 ret = QL_STATUS_INVALID_PARAM;
Sucheta Chakrabortyc65762f2014-04-25 17:43:59 -04001020 dev_err(&adapter->pdev->dev, "%s: Invalid function 0x%x, max 0x%x\n",
1021 __func__, pfn, ahw->max_vnic_func);
Sony Chackof848d6d2011-04-01 14:27:59 +00001022 goto err_eswitch;
1023 }
Sony Chackobff57d8e2012-12-04 03:33:56 +00001024
1025 if (!pci_info[i].active ||
1026 (pci_info[i].type != QLCNIC_TYPE_NIC))
1027 continue;
1028
Sony Chacko35dafcb2013-08-30 13:51:23 -04001029 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko4c776aa2013-10-18 12:22:32 -04001030 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn,
1031 &id))
Sony Chacko35dafcb2013-08-30 13:51:23 -04001032 adapter->npars[j].eswitch_status = true;
1033 else
1034 continue;
1035 } else {
1036 adapter->npars[j].eswitch_status = true;
1037 }
1038
Sony Chackobff57d8e2012-12-04 03:33:56 +00001039 adapter->npars[j].pci_func = pfn;
1040 adapter->npars[j].active = (u8)pci_info[i].active;
1041 adapter->npars[j].type = (u8)pci_info[i].type;
1042 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
1043 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
1044 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001045
Sucheta Chakraborty9e630952013-10-18 12:22:28 -04001046 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN);
Sony Chackobff57d8e2012-12-04 03:33:56 +00001047 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001048 }
1049
Sony Chacko4c776aa2013-10-18 12:22:32 -04001050 /* Update eSwitch status for adapters without per port eSwitch
1051 * configuration capability
1052 */
1053 if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001054 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
1055 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +00001056 }
Dan Carpenterca315ac2010-08-09 21:47:56 +00001057
Dan Carpentere88db3b2010-08-09 21:49:36 +00001058 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001059 return 0;
1060
1061err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001062 kfree(adapter->eswitch);
1063 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001064err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001065 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001066 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001067err_pci_info:
1068 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001069
1070 return ret;
1071}
1072
1073static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001074qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
1075{
1076 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001077 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001078 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001079 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001080
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001081 ret = qlcnic_api_lock(adapter);
1082 if (ret)
1083 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001084
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001085 id = ahw->pci_func;
1086 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
1087 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
1088 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001089 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001090 qlcnic_api_unlock(adapter);
1091err_lock:
1092 return ret;
1093}
1094
Sony Chacko13159182013-01-01 03:20:21 +00001095static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
1096 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001097{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001098 u32 op_mode, priv_level;
1099
1100 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +00001101 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
1102 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001103
1104 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +00001105 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001106
1107 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +00001108 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001109 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001110 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001111 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001112 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001113
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001114 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001115 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001116 dev_info(&adapter->pdev->dev,
1117 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001118 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001119 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001120 } else
1121 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001122}
1123
Sony Chacko15087c22012-12-04 03:33:54 +00001124#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +00001125#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +00001126static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001127{
Sony Chacko15087c22012-12-04 03:33:54 +00001128 switch (dev_id) {
1129 case PCI_DEVICE_ID_QLOGIC_QLE824X:
1130 *bar = QLCNIC_82XX_BAR0_LENGTH;
1131 break;
Sony Chacko13159182013-01-01 03:20:21 +00001132 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001133 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001134 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001135 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00001136 *bar = QLCNIC_83XX_BAR0_LENGTH;
1137 break;
Sony Chacko15087c22012-12-04 03:33:54 +00001138 default:
1139 *bar = 0;
1140 }
1141}
1142
1143static int qlcnic_setup_pci_map(struct pci_dev *pdev,
1144 struct qlcnic_hardware_context *ahw)
1145{
1146 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001147 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +00001148 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001149
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001150 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001151 mem_len = pci_resource_len(pdev, 0);
1152
Sony Chacko15087c22012-12-04 03:33:54 +00001153 qlcnic_get_bar_length(pdev->device, &bar0_len);
1154 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001155
1156 mem_ptr0 = pci_ioremap_bar(pdev, 0);
1157 if (mem_ptr0 == NULL) {
1158 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
1159 return -EIO;
1160 }
1161 pci_len0 = mem_len;
1162 } else {
1163 return -EIO;
1164 }
1165
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001166 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001167
Sony Chacko15087c22012-12-04 03:33:54 +00001168 ahw->pci_base0 = mem_ptr0;
1169 ahw->pci_len0 = pci_len0;
1170 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1171 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001172
1173 return 0;
1174}
1175
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001176static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1177 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001178{
1179 struct pci_dev *pdev = adapter->pdev;
1180 unsigned short subsystem_vendor;
1181 bool ret = true;
1182
1183 subsystem_vendor = pdev->subsystem_vendor;
1184
1185 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1186 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1187 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1188 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1189 ret = true;
1190 else
1191 ret = false;
1192 }
1193
1194 return ret;
1195}
1196
Sony Chacko22999792012-12-04 03:33:55 +00001197static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001198{
1199 struct pci_dev *pdev = adapter->pdev;
1200 int i, found = 0;
1201
1202 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1203 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001204 qlcnic_boards[i].device == pdev->device &&
1205 qlcnic_validate_subsystem_id(adapter, i)) {
1206 found = 1;
1207 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001208 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001209 }
1210
1211 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001212 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001213 else
1214 sprintf(name, "%pM: %s" , adapter->mac_addr,
1215 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001216}
1217
1218static void
1219qlcnic_check_options(struct qlcnic_adapter *adapter)
1220{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001221 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001222 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001223 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001224 struct qlcnic_hardware_context *ahw = adapter->ahw;
1225 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001226
1227 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001228
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001229 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1230 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1231 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001232
1233 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1234
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001235 err = qlcnic_get_board_info(adapter);
1236 if (err) {
1237 dev_err(&pdev->dev, "Error getting board config info.\n");
1238 return;
1239 }
1240 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001241 if (fw_dump->tmpl_hdr == NULL ||
1242 adapter->fw_version > prev_fw_version) {
1243 if (fw_dump->tmpl_hdr)
1244 vfree(fw_dump->tmpl_hdr);
1245 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1246 dev_info(&pdev->dev,
1247 "Supports FW dump capability\n");
1248 }
1249 }
1250
Sony Chacko13159182013-01-01 03:20:21 +00001251 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1252 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1253
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001254 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001255 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1256 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1257 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1258 } else {
1259 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1260 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1261 }
1262
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001263 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001264 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1265
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001266 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001267 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1268 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001269 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1270 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001271 }
1272
Sony Chacko099f7aa2012-12-04 03:33:58 +00001273 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001274
1275 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1276
Sony Chacko251b0362010-08-19 05:08:24 +00001277 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001278}
1279
Rajesh Borundia174240a2010-08-31 17:17:47 +00001280static int
1281qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1282{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001283 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001284 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001285
Sony Chackobff57d8e2012-12-04 03:33:56 +00001286 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001287 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001288 if (err)
1289 return err;
1290
Sony Chacko79788452012-12-04 03:33:53 +00001291 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1292 adapter->ahw->switch_mode = nic_info.switch_mode;
1293 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1294 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1295 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001296
1297 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1298 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001299 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1300 if (err == -EIO)
1301 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001302 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001303 } else {
1304 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001305 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001306
Sony Chacko79788452012-12-04 03:33:53 +00001307 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1308 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001309
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001310 if (adapter->ahw->capabilities & BIT_6) {
Rajesh Borundia174240a2010-08-31 17:17:47 +00001311 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001312 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE;
1313 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS;
1314 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
1315
1316 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n");
1317 } else {
1318 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
1319 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS;
Himanshu Madhanif9566262013-12-16 15:36:58 -05001320 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001321 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001322 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001323
1324 return err;
1325}
1326
Sony Chackoec079a02012-11-28 04:34:28 +00001327void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1328 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001329{
1330 if (esw_cfg->discard_tagged)
1331 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1332 else
1333 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1334
Rajesh Borundia91b72822013-04-19 07:01:12 +00001335 if (esw_cfg->vlan_id) {
1336 adapter->rx_pvid = esw_cfg->vlan_id;
1337 adapter->tx_pvid = esw_cfg->vlan_id;
1338 } else {
1339 adapter->rx_pvid = 0;
1340 adapter->tx_pvid = 0;
1341 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001342}
1343
Jiri Pirko8e586132011-12-08 19:52:37 -05001344static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001345qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001346{
1347 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001348 int err;
1349
1350 if (qlcnic_sriov_vf_check(adapter)) {
1351 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1352 if (err) {
1353 netdev_err(netdev,
1354 "Cannot add VLAN filter for VLAN id %d, err=%d",
1355 vid, err);
1356 return err;
1357 }
1358 }
1359
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001360 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001361 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001362}
1363
Jiri Pirko8e586132011-12-08 19:52:37 -05001364static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001365qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001366{
1367 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001368 int err;
1369
1370 if (qlcnic_sriov_vf_check(adapter)) {
1371 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1372 if (err) {
1373 netdev_err(netdev,
1374 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1375 vid, err);
1376 return err;
1377 }
1378 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001379
1380 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1381 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001382 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001383}
1384
Sony Chackoec079a02012-11-28 04:34:28 +00001385void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1386 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001387{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001388 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1389 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001390
1391 if (esw_cfg->mac_anti_spoof)
1392 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001393
Rajesh Borundia73733732010-08-31 17:17:50 +00001394 if (!esw_cfg->mac_override)
1395 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1396
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001397 if (!esw_cfg->promisc_mode)
1398 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001399}
1400
Sony Chackod71170f2013-01-01 03:20:26 +00001401int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001402{
1403 struct qlcnic_esw_func_cfg esw_cfg;
1404
1405 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1406 return 0;
1407
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001408 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001409 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1410 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001411 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001412 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001413 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001414
1415 return 0;
1416}
1417
Shahed Shaikh147a9082013-05-21 09:27:01 +00001418void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1419 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001420{
1421 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001422
Sony Chacko13159182013-01-01 03:20:21 +00001423 if (qlcnic_83xx_check(adapter))
1424 return;
1425
Shahed Shaikh147a9082013-05-21 09:27:01 +00001426 adapter->offload_flags = esw_cfg->offload_flags;
1427 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1428 netdev_update_features(netdev);
1429 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001430}
1431
1432static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001433qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1434{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001435 u32 op_mode, priv_level;
1436 int err = 0;
1437
Rajesh Borundia174240a2010-08-31 17:17:47 +00001438 err = qlcnic_initialize_nic(adapter);
1439 if (err)
1440 return err;
1441
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001442 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1443 return 0;
1444
Sony Chacko13159182013-01-01 03:20:21 +00001445 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001446 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001447
1448 if (op_mode == QLC_DEV_DRV_DEFAULT)
1449 priv_level = QLCNIC_MGMT_FUNC;
1450 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001451 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001452
Rajesh Borundia174240a2010-08-31 17:17:47 +00001453 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001454 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001455 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001456 err = qlcnic_init_pci_info(adapter);
1457 if (err)
1458 return err;
1459 /* Set privilege level for other functions */
1460 qlcnic_set_function_modes(adapter);
1461 dev_info(&adapter->pdev->dev,
1462 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001463 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001464 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001465 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001466 dev_info(&adapter->pdev->dev,
1467 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001468 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001469 }
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001470 } else {
1471 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001472 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001473
1474 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1475
1476 return err;
1477}
1478
Sony Chackod71170f2013-01-01 03:20:26 +00001479int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001480{
1481 struct qlcnic_esw_func_cfg esw_cfg;
1482 struct qlcnic_npar_info *npar;
1483 u8 i;
1484
Rajesh Borundia174240a2010-08-31 17:17:47 +00001485 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001486 return 0;
1487
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001488 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001489 if (!adapter->npars[i].eswitch_status)
1490 continue;
1491
Rajesh Borundia0325d692010-08-19 05:08:26 +00001492 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d8e2012-12-04 03:33:56 +00001493 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001494 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001495 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001496 if (qlcnic_82xx_check(adapter)) {
1497 esw_cfg.offload_flags = BIT_0;
1498 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1499 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1500 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001501 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1502 return -EIO;
1503 npar = &adapter->npars[i];
1504 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001505 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001506 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1507 npar->discard_tagged = esw_cfg.discard_tagged;
1508 npar->promisc_mode = esw_cfg.promisc_mode;
1509 npar->offload_flags = esw_cfg.offload_flags;
1510 }
1511
1512 return 0;
1513}
1514
Sony Chacko13159182013-01-01 03:20:21 +00001515
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001516static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001517qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1518 struct qlcnic_npar_info *npar, int pci_func)
1519{
1520 struct qlcnic_esw_func_cfg esw_cfg;
1521 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1522 esw_cfg.pci_func = pci_func;
1523 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001524 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001525 esw_cfg.discard_tagged = npar->discard_tagged;
1526 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1527 esw_cfg.offload_flags = npar->offload_flags;
1528 esw_cfg.promisc_mode = npar->promisc_mode;
1529 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1530 return -EIO;
1531
1532 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1533 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1534 return -EIO;
1535
1536 return 0;
1537}
1538
Sony Chackod71170f2013-01-01 03:20:26 +00001539int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001540{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001541 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001542 struct qlcnic_npar_info *npar;
1543 struct qlcnic_info nic_info;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001544 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001545
Sony Chackobff57d8e2012-12-04 03:33:56 +00001546 if (qlcnic_82xx_check(adapter))
1547 if (!adapter->need_fw_reset)
1548 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001549
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001550 /* Set the NPAR config data after FW reset */
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001551 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001552 npar = &adapter->npars[i];
Sony Chackobff57d8e2012-12-04 03:33:56 +00001553 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001554 if (!adapter->npars[i].eswitch_status)
1555 continue;
1556
Sony Chackobff57d8e2012-12-04 03:33:56 +00001557 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001558 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001559 if (err)
1560 return err;
1561 nic_info.min_tx_bw = npar->min_bw;
1562 nic_info.max_tx_bw = npar->max_bw;
1563 err = qlcnic_set_nic_info(adapter, &nic_info);
1564 if (err)
1565 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001566
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001567 if (npar->enable_pm) {
1568 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d8e2012-12-04 03:33:56 +00001569 npar->dest_npar, 1,
1570 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001571 if (err)
1572 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001573 }
Sony Chackobff57d8e2012-12-04 03:33:56 +00001574 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001575 if (err)
1576 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001577 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001578 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001579}
1580
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001581static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1582{
1583 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1584 u32 npar_state;
1585
Sony Chacko79788452012-12-04 03:33:53 +00001586 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001587 return 0;
1588
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001589 npar_state = QLC_SHARED_REG_RD32(adapter,
1590 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001591 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1592 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001593 npar_state = QLC_SHARED_REG_RD32(adapter,
1594 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001595 }
1596 if (!npar_opt_timeo) {
1597 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001598 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001599 return -EIO;
1600 }
1601 return 0;
1602}
1603
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001604static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001605qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1606{
1607 int err;
1608
1609 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001610 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001611 return 0;
1612
1613 err = qlcnic_set_default_offload_settings(adapter);
1614 if (err)
1615 return err;
1616
1617 err = qlcnic_reset_npar_config(adapter);
1618 if (err)
1619 return err;
1620
1621 qlcnic_dev_set_npar_ready(adapter);
1622
1623 return err;
1624}
1625
stephen hemminger21041402014-01-16 10:31:27 -08001626static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001627{
Sony Chackod4066832010-08-19 05:08:31 +00001628 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001629
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001630 err = qlcnic_can_start_firmware(adapter);
1631 if (err < 0)
1632 return err;
1633 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001634 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001635
Sony Chacko099f7aa2012-12-04 03:33:58 +00001636 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001637 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001638 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001639 err = qlcnic_check_flash_fw_ver(adapter);
1640 if (err)
schacko8f891382010-06-17 02:56:40 +00001641 goto err_out;
1642
Sony Chacko79788452012-12-04 03:33:53 +00001643 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001644 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001645
1646 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001647 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001648 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001649
Sony Chackod4066832010-08-19 05:08:31 +00001650 err = qlcnic_pinit_from_rom(adapter);
1651 if (err)
1652 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001653
1654 err = qlcnic_load_firmware(adapter);
1655 if (err)
1656 goto err_out;
1657
1658 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001659 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001660
Sony Chackod4066832010-08-19 05:08:31 +00001661check_fw_status:
1662 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001663 if (err)
1664 goto err_out;
1665
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001666 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001667 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001668 err = qlcnic_check_eswitch_mode(adapter);
1669 if (err) {
1670 dev_err(&adapter->pdev->dev,
1671 "Memory allocation failed for eswitch\n");
1672 goto err_out;
1673 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001674 err = qlcnic_set_mgmt_operations(adapter);
1675 if (err)
1676 goto err_out;
1677
1678 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001679 adapter->need_fw_reset = 0;
1680
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001681 qlcnic_release_firmware(adapter);
1682 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001683
1684err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001685 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001686 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001687
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001688 qlcnic_release_firmware(adapter);
1689 return err;
1690}
1691
1692static int
1693qlcnic_request_irq(struct qlcnic_adapter *adapter)
1694{
1695 irq_handler_t handler;
1696 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001697 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001698 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001699
1700 unsigned long flags = 0;
1701 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001702 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001703
Sony Chacko79788452012-12-04 03:33:53 +00001704 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001705 if (qlcnic_82xx_check(adapter))
1706 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001707 else
1708 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001709 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1710 flags |= IRQF_SHARED;
1711
1712 } else {
1713 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1714 handler = qlcnic_msix_intr;
1715 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1716 handler = qlcnic_msi_intr;
1717 else {
1718 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001719 if (qlcnic_82xx_check(adapter))
1720 handler = qlcnic_intr;
1721 else
1722 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001723 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001724 }
1725 adapter->irq = netdev->irq;
1726
Sony Chacko13159182013-01-01 03:20:21 +00001727 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001728 if (qlcnic_82xx_check(adapter) ||
1729 (qlcnic_83xx_check(adapter) &&
1730 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001731 num_sds_rings = adapter->drv_sds_rings;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001732 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001733 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001734 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001735 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001736 (ring == (num_sds_rings - 1))) {
1737 if (!(adapter->flags &
1738 QLCNIC_MSIX_ENABLED))
1739 snprintf(sds_ring->name,
1740 sizeof(sds_ring->name),
1741 "qlcnic");
1742 else
1743 snprintf(sds_ring->name,
1744 sizeof(sds_ring->name),
1745 "%s-tx-0-rx-%d",
1746 netdev->name, ring);
1747 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001748 snprintf(sds_ring->name,
1749 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001750 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001751 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001752 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001753 err = request_irq(sds_ring->irq, handler, flags,
1754 sds_ring->name, sds_ring);
1755 if (err)
1756 return err;
1757 }
Sony Chacko13159182013-01-01 03:20:21 +00001758 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001759 if ((qlcnic_82xx_check(adapter) &&
1760 qlcnic_check_multi_tx(adapter)) ||
1761 (qlcnic_83xx_check(adapter) &&
1762 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1763 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001764 handler = qlcnic_msix_tx_intr;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001765 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001766 ring++) {
1767 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001768 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001769 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001770 err = request_irq(tx_ring->irq, handler, flags,
1771 tx_ring->name, tx_ring);
1772 if (err)
1773 return err;
1774 }
1775 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001776 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001777 return 0;
1778}
1779
1780static void
1781qlcnic_free_irq(struct qlcnic_adapter *adapter)
1782{
1783 int ring;
1784 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001785 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001786
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001787 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001788
Sony Chacko13159182013-01-01 03:20:21 +00001789 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001790 if (qlcnic_82xx_check(adapter) ||
1791 (qlcnic_83xx_check(adapter) &&
1792 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001793 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001794 sds_ring = &recv_ctx->sds_rings[ring];
1795 free_irq(sds_ring->irq, sds_ring);
1796 }
Sony Chacko13159182013-01-01 03:20:21 +00001797 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001798 if ((qlcnic_83xx_check(adapter) &&
1799 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1800 (qlcnic_82xx_check(adapter) &&
1801 qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001802 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001803 ring++) {
1804 tx_ring = &adapter->tx_ring[ring];
1805 if (tx_ring->irq)
1806 free_irq(tx_ring->irq, tx_ring);
1807 }
1808 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001809 }
1810}
1811
Shahed Shaikh99e85872013-02-18 12:06:16 +00001812static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1813{
1814 u32 capab = 0;
1815
1816 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001817 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001818 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1819 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1820 } else {
1821 capab = adapter->ahw->capabilities;
1822 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1823 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1824 }
1825}
1826
Himanshu Madhania5147222014-01-23 17:18:32 -05001827static int qlcnic_config_def_intr_coalesce(struct qlcnic_adapter *adapter)
1828{
1829 struct qlcnic_hardware_context *ahw = adapter->ahw;
1830 int err;
1831
1832 /* Initialize interrupt coalesce parameters */
1833 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1834
1835 if (qlcnic_83xx_check(adapter)) {
1836 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
1837 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1838 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1839 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1840 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1841
1842 err = qlcnic_83xx_set_rx_tx_intr_coal(adapter);
1843 } else {
1844 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1845 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1846 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1847
1848 err = qlcnic_82xx_set_rx_coalesce(adapter);
1849 }
1850
1851 return err;
1852}
1853
Sony Chacko319ecf12013-01-01 03:20:22 +00001854int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001855{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001856 int ring;
1857 struct qlcnic_host_rds_ring *rds_ring;
1858
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001859 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1860 return -EIO;
1861
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001862 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1863 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001864
Rajesh Borundia0325d692010-08-19 05:08:26 +00001865 if (qlcnic_set_eswitch_port_config(adapter))
1866 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001867
Shahed Shaikh99e85872013-02-18 12:06:16 +00001868 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001869
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001870 if (qlcnic_fw_create_ctx(adapter))
1871 return -EIO;
1872
1873 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001874 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001875 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001876 }
1877
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001878 qlcnic_set_multi(netdev);
1879 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1880
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001881 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001882
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001883 if (adapter->drv_sds_rings > 1)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001884 qlcnic_config_rss(adapter, 1);
1885
Himanshu Madhania5147222014-01-23 17:18:32 -05001886 qlcnic_config_def_intr_coalesce(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001887
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001888 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001889 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1890
Pratik Pujarcfacb172013-07-19 16:56:27 -04001891 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001892 qlcnic_napi_enable(adapter);
1893
1894 qlcnic_linkevent_request(adapter, 1);
1895
Sony Chacko79788452012-12-04 03:33:53 +00001896 adapter->ahw->reset_context = 0;
Rajesh Borundia060d0562014-01-28 11:55:29 -05001897 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001898 return 0;
1899}
1900
Sony Chacko629263a2013-01-01 04:11:55 +00001901int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001902{
1903 int err = 0;
1904
1905 rtnl_lock();
1906 if (netif_running(netdev))
1907 err = __qlcnic_up(adapter, netdev);
1908 rtnl_unlock();
1909
1910 return err;
1911}
1912
Sony Chacko319ecf12013-01-01 03:20:22 +00001913void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001914{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001915 int ring;
1916
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001917 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1918 return;
1919
1920 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1921 return;
1922
1923 smp_mb();
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001924 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001925 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001926 netif_tx_disable(netdev);
1927
1928 qlcnic_free_mac_list(adapter);
1929
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001930 if (adapter->fhash.fnum)
1931 qlcnic_delete_lb_filters(adapter);
1932
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001933 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
Rajesh Borundia74b7ba12014-05-09 02:51:30 -04001934 if (qlcnic_sriov_vf_check(adapter))
1935 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001936
1937 qlcnic_napi_disable(adapter);
1938
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001939 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001940 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001941
1942 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001943
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001944 for (ring = 0; ring < adapter->drv_tx_rings; ring++)
Himanshu Madhani012ec812013-08-21 11:24:10 -04001945 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001946}
1947
1948/* Usage: During suspend and firmware recovery module */
1949
Sony Chacko629263a2013-01-01 04:11:55 +00001950void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001951{
1952 rtnl_lock();
1953 if (netif_running(netdev))
1954 __qlcnic_down(adapter, netdev);
1955 rtnl_unlock();
1956
1957}
1958
Sony Chacko319ecf12013-01-01 03:20:22 +00001959int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001960qlcnic_attach(struct qlcnic_adapter *adapter)
1961{
1962 struct net_device *netdev = adapter->netdev;
1963 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001964 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001965
1966 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1967 return 0;
1968
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001969 err = qlcnic_napi_add(adapter, netdev);
1970 if (err)
1971 return err;
1972
1973 err = qlcnic_alloc_sw_resources(adapter);
1974 if (err) {
1975 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001976 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001977 }
1978
1979 err = qlcnic_alloc_hw_resources(adapter);
1980 if (err) {
1981 dev_err(&pdev->dev, "Error in setting hw resources\n");
1982 goto err_out_free_sw;
1983 }
1984
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001985 err = qlcnic_request_irq(adapter);
1986 if (err) {
1987 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001988 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001989 }
1990
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001991 qlcnic_create_sysfs_entries(adapter);
1992
Shahed Shaikh7f1f6052014-04-01 16:29:32 -04001993#ifdef CONFIG_QLCNIC_VXLAN
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04001994 if (qlcnic_encap_rx_offload(adapter))
1995 vxlan_get_rx_port(netdev);
Shahed Shaikh7f1f6052014-04-01 16:29:32 -04001996#endif
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04001997
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001998 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1999 return 0;
2000
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002001err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002002 qlcnic_free_hw_resources(adapter);
2003err_out_free_sw:
2004 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002005err_out_napi_del:
2006 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002007 return err;
2008}
2009
Sony Chacko319ecf12013-01-01 03:20:22 +00002010void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002011{
2012 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2013 return;
2014
2015 qlcnic_remove_sysfs_entries(adapter);
2016
2017 qlcnic_free_hw_resources(adapter);
2018 qlcnic_release_rx_buffers(adapter);
2019 qlcnic_free_irq(adapter);
2020 qlcnic_napi_del(adapter);
2021 qlcnic_free_sw_resources(adapter);
2022
2023 adapter->is_up = 0;
2024}
2025
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002026void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings)
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002027{
2028 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2029 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002030 int drv_tx_rings = adapter->drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002031 int ring;
2032
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002033 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00002034 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002035 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002036 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002037 qlcnic_disable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002038 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002039 }
2040
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002041 qlcnic_fw_destroy_ctx(adapter);
2042
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002043 qlcnic_detach(adapter);
2044
Sony Chacko79788452012-12-04 03:33:53 +00002045 adapter->ahw->diag_test = 0;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002046 adapter->drv_sds_rings = drv_sds_rings;
2047 adapter->drv_tx_rings = drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002048
2049 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002050 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002051
2052 if (netif_running(netdev))
2053 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002054out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002055 netif_device_attach(netdev);
2056}
2057
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002058static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
2059{
Sucheta Chakraborty868e9142014-04-25 17:43:58 -04002060 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002061 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00002062
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002063 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
2064 GFP_KERNEL);
2065 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002066 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00002067 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002068 }
Himanshu Madhania5147222014-01-23 17:18:32 -05002069
Sucheta Chakraborty868e9142014-04-25 17:43:58 -04002070 if (qlcnic_83xx_check(adapter)) {
2071 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
2072 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
2073 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
2074 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
2075 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
2076 } else {
2077 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
2078 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
2079 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
2080 }
2081
Sony Chacko4be41e92013-01-01 03:20:20 +00002082 /* clear stats */
2083 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002084err_out:
2085 return err;
2086}
2087
2088static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
2089{
Shahed Shaikh4da005c2014-06-11 14:09:11 -04002090 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
2091
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002092 kfree(adapter->recv_ctx);
2093 adapter->recv_ctx = NULL;
2094
Shahed Shaikh4da005c2014-06-11 14:09:11 -04002095 if (fw_dump->tmpl_hdr) {
2096 vfree(fw_dump->tmpl_hdr);
2097 fw_dump->tmpl_hdr = NULL;
2098 }
2099
2100 if (fw_dump->dma_buffer) {
2101 dma_free_coherent(&adapter->pdev->dev, QLC_PEX_DMA_READ_SIZE,
2102 fw_dump->dma_buffer, fw_dump->phys_addr);
2103 fw_dump->dma_buffer = NULL;
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002104 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002105
Sony Chacko81d0aeb2013-01-01 03:20:25 +00002106 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00002107 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002108}
2109
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002110int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
2111{
2112 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2113 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002114 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002115 int ring;
2116 int ret;
2117
2118 netif_device_detach(netdev);
2119
2120 if (netif_running(netdev))
2121 __qlcnic_down(adapter, netdev);
2122
2123 qlcnic_detach(adapter);
2124
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002125 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sony Chacko79788452012-12-04 03:33:53 +00002126 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00002127 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002128
2129 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002130 if (ret) {
2131 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002132 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002133 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002134
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002135 ret = qlcnic_fw_create_ctx(adapter);
2136 if (ret) {
2137 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00002138 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002139 return ret;
2140 }
2141
2142 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002143 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00002144 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002145 }
2146
Sony Chacko79788452012-12-04 03:33:53 +00002147 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002148 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002149 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002150 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002151 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002152 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002153
Sony Chacko79788452012-12-04 03:33:53 +00002154 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002155 adapter->ahw->loopback_state = 0;
2156 qlcnic_linkevent_request(adapter, 1);
2157 }
2158
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002159 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002160
2161 return 0;
2162}
2163
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002164/* Reset context in hardware only */
2165static int
2166qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
2167{
2168 struct net_device *netdev = adapter->netdev;
2169
2170 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2171 return -EBUSY;
2172
2173 netif_device_detach(netdev);
2174
2175 qlcnic_down(adapter, netdev);
2176
2177 qlcnic_up(adapter, netdev);
2178
2179 netif_device_attach(netdev);
2180
2181 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani95b38902014-01-23 17:18:29 -05002182 netdev_info(adapter->netdev, "%s: soft reset complete\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002183 return 0;
2184}
2185
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002186int
2187qlcnic_reset_context(struct qlcnic_adapter *adapter)
2188{
2189 int err = 0;
2190 struct net_device *netdev = adapter->netdev;
2191
2192 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2193 return -EBUSY;
2194
2195 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
2196
2197 netif_device_detach(netdev);
2198
2199 if (netif_running(netdev))
2200 __qlcnic_down(adapter, netdev);
2201
2202 qlcnic_detach(adapter);
2203
2204 if (netif_running(netdev)) {
2205 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002206 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002207 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002208 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2209 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002210 }
2211
2212 netif_device_attach(netdev);
2213 }
2214
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002215 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2216 return err;
2217}
2218
stephen hemminger21041402014-01-16 10:31:27 -08002219static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002220{
2221 struct qlcnic_hardware_context *ahw = adapter->ahw;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002222 u16 act_pci_fn = ahw->total_nic_func;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002223 u16 count;
2224
2225 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2226 if (act_pci_fn <= 2)
2227 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2228 act_pci_fn;
2229 else
2230 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2231 act_pci_fn;
2232 ahw->max_uc_count = count;
2233}
2234
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04002235static int qlcnic_set_real_num_queues(struct qlcnic_adapter *adapter,
2236 u8 tx_queues, u8 rx_queues)
2237{
2238 struct net_device *netdev = adapter->netdev;
2239 int err = 0;
2240
2241 if (tx_queues) {
2242 err = netif_set_real_num_tx_queues(netdev, tx_queues);
2243 if (err) {
2244 netdev_err(netdev, "failed to set %d Tx queues\n",
2245 tx_queues);
2246 return err;
2247 }
2248 }
2249
2250 if (rx_queues) {
2251 err = netif_set_real_num_rx_queues(netdev, rx_queues);
2252 if (err)
2253 netdev_err(netdev, "failed to set %d Rx queues\n",
2254 rx_queues);
2255 }
2256
2257 return err;
2258}
2259
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002260int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002261qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2262 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002263{
2264 int err;
2265 struct pci_dev *pdev = adapter->pdev;
2266
Sony Chacko13159182013-01-01 03:20:21 +00002267 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002268 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002269 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002270
2271 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002272 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002273
2274 qlcnic_change_mtu(netdev, netdev->mtu);
2275
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002276 netdev->ethtool_ops = (qlcnic_sriov_vf_check(adapter)) ?
2277 &qlcnic_sriov_vf_ethtool_ops : &qlcnic_ethtool_ops;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002278
Sony Chacko7e38d042013-01-01 03:20:28 +00002279 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002280 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002281 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002282 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2283 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002284
Sony Chacko13159182013-01-01 03:20:21 +00002285 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2286 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2287 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2288 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002289
Sony Chacko13159182013-01-01 03:20:21 +00002290 if (pci_using_dac) {
2291 netdev->features |= NETIF_F_HIGHDMA;
2292 netdev->vlan_features |= NETIF_F_HIGHDMA;
2293 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002294
Sony Chacko13159182013-01-01 03:20:21 +00002295 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002296 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002297
Rajesh Borundia91b72822013-04-19 07:01:12 +00002298 if (qlcnic_sriov_vf_check(adapter))
2299 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2300
Sony Chacko79788452012-12-04 03:33:53 +00002301 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002302 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002303
Shahed Shaikh381709d2014-03-21 04:41:16 -04002304 if (qlcnic_encap_tx_offload(adapter)) {
2305 netdev->features |= NETIF_F_GSO_UDP_TUNNEL;
2306
2307 /* encapsulation Tx offload supported by Adapter */
2308 netdev->hw_enc_features = NETIF_F_IP_CSUM |
2309 NETIF_F_GSO_UDP_TUNNEL |
2310 NETIF_F_TSO |
2311 NETIF_F_TSO6;
2312 }
2313
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04002314 if (qlcnic_encap_rx_offload(adapter))
2315 netdev->hw_enc_features |= NETIF_F_RXCSUM;
2316
Sony Chacko7e38d042013-01-01 03:20:28 +00002317 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002318 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002319 netdev->irq = adapter->msix_entries[0].vector;
2320
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04002321 err = qlcnic_set_real_num_queues(adapter, adapter->drv_tx_rings,
2322 adapter->drv_sds_rings);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002323 if (err)
2324 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002325
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002326 err = register_netdev(netdev);
2327 if (err) {
2328 dev_err(&pdev->dev, "failed to register net device\n");
2329 return err;
2330 }
2331
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002332 qlcnic_dcb_init_dcbnl_ops(adapter->dcb);
Sucheta Chakraborty48365e42013-08-23 13:38:28 -04002333
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002334 return 0;
2335}
2336
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002337static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002338{
2339 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2340 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2341 *pci_using_dac = 1;
2342 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2343 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2344 *pci_using_dac = 0;
2345 else {
2346 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2347 return -EIO;
2348 }
2349
2350 return 0;
2351}
2352
Sony Chacko4be41e92013-01-01 03:20:20 +00002353void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2354{
2355 int ring;
2356 struct qlcnic_host_tx_ring *tx_ring;
2357
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002358 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002359 tx_ring = &adapter->tx_ring[ring];
2360 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
2361 vfree(tx_ring->cmd_buf_arr);
2362 tx_ring->cmd_buf_arr = NULL;
2363 }
2364 }
2365 if (adapter->tx_ring != NULL)
2366 kfree(adapter->tx_ring);
2367}
2368
2369int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2370 struct net_device *netdev)
2371{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002372 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002373 struct qlcnic_host_tx_ring *tx_ring;
2374 struct qlcnic_cmd_buffer *cmd_buf_arr;
2375
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002376 tx_ring = kcalloc(adapter->drv_tx_rings,
Joe Perchesb2adaca2013-02-03 17:43:58 +00002377 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2378 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002379 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002380
Sony Chacko4be41e92013-01-01 03:20:20 +00002381 adapter->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];
2385 tx_ring->num_desc = adapter->num_txd;
2386 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2387 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2388 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002389 qlcnic_free_tx_rings(adapter);
2390 return -ENOMEM;
2391 }
2392 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
2393 tx_ring->cmd_buf_arr = cmd_buf_arr;
Shahed Shaikha02bdd42014-01-03 01:34:28 -05002394 spin_lock_init(&tx_ring->tx_clean_lock);
Sony Chacko4be41e92013-01-01 03:20:20 +00002395 }
2396
Himanshu Madhani012ec812013-08-21 11:24:10 -04002397 if (qlcnic_83xx_check(adapter) ||
2398 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002399 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002400 tx_ring = &adapter->tx_ring[ring];
2401 tx_ring->adapter = adapter;
2402 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002403 index = adapter->drv_sds_rings + ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002404 vector = adapter->msix_entries[index].vector;
2405 tx_ring->irq = vector;
2406 }
2407 }
2408 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002409
Sony Chacko4be41e92013-01-01 03:20:20 +00002410 return 0;
2411}
2412
Pratik Pujar8af3f332013-06-22 04:12:05 -04002413void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2414{
2415 struct qlcnic_hardware_context *ahw = adapter->ahw;
2416 u32 fw_cmd = 0;
2417
2418 if (qlcnic_82xx_check(adapter))
2419 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2420 else if (qlcnic_83xx_check(adapter))
2421 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2422
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002423 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002424 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2425}
2426
Sony Chacko2c97e9e2014-04-23 09:59:55 -04002427/* Reset firmware API lock */
2428static void qlcnic_reset_api_lock(struct qlcnic_adapter *adapter)
2429{
2430 qlcnic_api_lock(adapter);
2431 qlcnic_api_unlock(adapter);
2432}
2433
2434
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002435static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002436qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2437{
2438 struct net_device *netdev = NULL;
2439 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002440 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002441 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002442 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002443
2444 err = pci_enable_device(pdev);
2445 if (err)
2446 return err;
2447
2448 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2449 err = -ENODEV;
2450 goto err_out_disable_pdev;
2451 }
2452
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002453 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2454 if (err)
2455 goto err_out_disable_pdev;
2456
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002457 err = pci_request_regions(pdev, qlcnic_driver_name);
2458 if (err)
2459 goto err_out_disable_pdev;
2460
2461 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002462 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002463
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002464 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002465 if (!ahw) {
2466 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002467 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002468 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002469
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002470 switch (ent->device) {
2471 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002472 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002473 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2474 break;
2475 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002476 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002477 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002478 break;
2479 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002480 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002481 qlcnic_sriov_vf_register_map(ahw);
2482 break;
2483 default:
Sony Chacko13159182013-01-01 03:20:21 +00002484 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002485 }
2486
2487 err = qlcnic_setup_pci_map(pdev, ahw);
2488 if (err)
2489 goto err_out_free_hw_res;
2490
Himanshu Madhani012ec812013-08-21 11:24:10 -04002491 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2492 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002493 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002494 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002495 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002496 }
2497
2498 SET_NETDEV_DEV(netdev, &pdev->dev);
2499
2500 adapter = netdev_priv(netdev);
2501 adapter->netdev = netdev;
2502 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002503 adapter->ahw = ahw;
2504
2505 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2506 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002507 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002508 dev_err(&pdev->dev, "Failed to create workqueue\n");
2509 goto err_out_free_netdev;
2510 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002511
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002512 err = qlcnic_alloc_adapter_resources(adapter);
2513 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002514 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002515
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002516 adapter->dev_rst_time = jiffies;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002517 ahw->revision_id = pdev->revision;
2518 ahw->max_vnic_func = qlcnic_get_vnic_func_count(adapter);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002519 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2520 adapter->fdb_mac_learn = true;
2521 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2522 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002523
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002524 rwlock_init(&adapter->ahw->crb_lock);
2525 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002527 INIT_LIST_HEAD(&adapter->mac_list);
2528
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002529 qlcnic_register_dcb(adapter);
2530
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002531 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002532 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002533 adapter->portnum = adapter->ahw->pci_func;
Sony Chacko2c97e9e2014-04-23 09:59:55 -04002534 qlcnic_reset_api_lock(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002535 err = qlcnic_start_firmware(adapter);
2536 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002537 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2538 "\t\tIf reboot doesn't help, try flashing the card\n");
2539 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002540 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002541
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002542 /* compute and set default and max tx/sds rings */
2543 if (adapter->ahw->msix_supported) {
2544 if (qlcnic_check_multi_tx_capability(adapter) == 1)
2545 qlcnic_set_tx_ring_count(adapter,
2546 QLCNIC_SINGLE_RING);
2547 else
2548 qlcnic_set_tx_ring_count(adapter,
2549 QLCNIC_DEF_TX_RINGS);
2550 qlcnic_set_sds_ring_count(adapter,
2551 QLCNIC_DEF_SDS_RINGS);
2552 } else {
2553 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING);
2554 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002555 }
2556
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002557 err = qlcnic_setup_idc_param(adapter);
2558 if (err)
2559 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002560
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002561 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002562
Sony Chacko13159182013-01-01 03:20:21 +00002563 } else if (qlcnic_83xx_check(adapter)) {
2564 qlcnic_83xx_check_vf(adapter, ent);
2565 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002566 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002567 if (err) {
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002568 switch (err) {
2569 case -ENOTRECOVERABLE:
Sucheta Chakraborty2a355aec2014-02-21 13:20:12 -05002570 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware\n");
2571 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 -05002572 goto err_out_free_hw;
2573 case -ENOMEM:
2574 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n");
2575 goto err_out_free_hw;
Sucheta Chakrabortyaaecf512014-04-25 17:44:00 -04002576 case -EOPNOTSUPP:
2577 dev_err(&pdev->dev, "Adapter initialization failed\n");
2578 goto err_out_free_hw;
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002579 default:
Sucheta Chakrabortyc65762f2014-04-25 17:43:59 -04002580 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 -05002581 goto err_out_maintenance_mode;
2582 }
Sony Chacko629263a2013-01-01 04:11:55 +00002583 }
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002584
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002585 if (qlcnic_sriov_vf_check(adapter))
2586 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002587 } else {
2588 dev_err(&pdev->dev,
2589 "%s: failed. Please Reboot\n", __func__);
2590 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002591 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002592
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002593 if (qlcnic_read_mac_addr(adapter))
2594 dev_warn(&pdev->dev, "failed to read mac addr\n");
2595
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002596 qlcnic_read_phys_port_id(adapter);
2597
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002598 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002599 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002600
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002601 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002602 module_name(THIS_MODULE),
2603 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002604 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002605
2606 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2607 !!qlcnic_use_msi)
2608 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002609 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002610
Manish Chopra068a8d12013-08-02 00:57:41 -04002611 if (qlcnic_82xx_check(adapter)) {
Sucheta Chakraborty4d52e1e2014-04-14 10:02:19 -04002612 qlcnic_dcb_enable(adapter->dcb);
2613 qlcnic_dcb_get_info(adapter->dcb);
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002614 err = qlcnic_setup_intr(adapter);
Sucheta Chakraborty4d52e1e2014-04-14 10:02:19 -04002615
Manish Chopra068a8d12013-08-02 00:57:41 -04002616 if (err) {
2617 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002618 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002619 }
Sony Chacko13159182013-01-01 03:20:21 +00002620 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002621
Sony Chacko02135582013-05-21 09:26:59 +00002622 err = qlcnic_get_act_pci_func(adapter);
2623 if (err)
2624 goto err_out_disable_mbx_intr;
2625
Rajesh Borundiabf630142014-08-04 11:51:17 -04002626 if (adapter->portnum == 0)
2627 qlcnic_set_drv_version(adapter);
2628
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002629 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002630 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002631 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002632
2633 pci_set_drvdata(pdev, adapter);
2634
Sony Chacko97ee45e2012-12-04 03:33:52 +00002635 if (qlcnic_82xx_check(adapter))
2636 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2637 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002638
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002639 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002640 case QLCNIC_GBE:
2641 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2642 adapter->netdev->name);
2643 break;
2644 case QLCNIC_XGBE:
2645 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2646 adapter->netdev->name);
2647 break;
2648 }
2649
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002650 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002651 qlcnic_alloc_lb_filters_mem(adapter);
2652
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002653 qlcnic_add_sysfs(adapter);
Harish Patil1f0f4672014-04-25 17:43:57 -04002654 qlcnic_register_hwmon_dev(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002655 return 0;
2656
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002657err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002658 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002659 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002660
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002661err_out_disable_msi:
2662 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002663 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002664 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002665
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002666err_out_free_hw:
2667 qlcnic_free_adapter_resources(adapter);
2668
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002669err_out_free_wq:
2670 destroy_workqueue(adapter->qlcnic_wq);
2671
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002672err_out_free_netdev:
2673 free_netdev(netdev);
2674
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002675err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002676 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002677
2678err_out_free_hw_res:
2679 kfree(ahw);
2680
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002681err_out_free_res:
2682 pci_release_regions(pdev);
2683
2684err_out_disable_pdev:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002685 pci_disable_device(pdev);
2686 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002687
2688err_out_maintenance_mode:
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002689 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002690 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002691 netdev->ethtool_ops = &qlcnic_ethtool_failed_ops;
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002692 ahw->port_type = QLCNIC_XGBE;
2693
2694 if (qlcnic_83xx_check(adapter))
2695 adapter->tgt_status_reg = NULL;
2696 else
2697 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS;
2698
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002699 err = register_netdev(netdev);
2700
2701 if (err) {
2702 dev_err(&pdev->dev, "Failed to register net device\n");
2703 qlcnic_clr_all_drv_state(adapter, 0);
2704 goto err_out_free_hw;
2705 }
2706
2707 pci_set_drvdata(pdev, adapter);
2708 qlcnic_add_sysfs(adapter);
2709
2710 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002711}
2712
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002713static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002714{
2715 struct qlcnic_adapter *adapter;
2716 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002717 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002718
2719 adapter = pci_get_drvdata(pdev);
2720 if (adapter == NULL)
2721 return;
2722
2723 netdev = adapter->netdev;
2724
Sony Chacko13159182013-01-01 03:20:21 +00002725 qlcnic_cancel_idc_work(adapter);
Rajesh Borundia132a3f22014-05-09 02:51:29 -04002726 qlcnic_sriov_pf_disable(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002727 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002728
2729 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002730 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002731
Sony Chacko13159182013-01-01 03:20:21 +00002732 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05002733 qlcnic_83xx_initialize_nic(adapter, 0);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002734 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002735 qlcnic_83xx_free_mbx_intr(adapter);
2736 qlcnic_83xx_detach_mailbox_work(adapter);
2737 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002738 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002739 }
2740
Sucheta Chakraborty3720bf72013-12-17 09:01:50 -05002741 qlcnic_dcb_free(adapter->dcb);
2742
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002743 qlcnic_detach(adapter);
2744
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002745 if (adapter->npars != NULL)
2746 kfree(adapter->npars);
2747 if (adapter->eswitch != NULL)
2748 kfree(adapter->eswitch);
2749
Sony Chacko97ee45e2012-12-04 03:33:52 +00002750 if (qlcnic_82xx_check(adapter))
2751 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002752
2753 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2754
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002755 qlcnic_free_lb_filters_mem(adapter);
2756
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002757 qlcnic_teardown_intr(adapter);
2758
Sony Chacko13159182013-01-01 03:20:21 +00002759 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002760
Harish Patil1f0f4672014-04-25 17:43:57 -04002761 qlcnic_unregister_hwmon_dev(adapter);
2762
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002763 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002764
2765 qlcnic_release_firmware(adapter);
2766
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002767 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002768 pci_release_regions(pdev);
2769 pci_disable_device(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002770
Sony Chacko13159182013-01-01 03:20:21 +00002771 if (adapter->qlcnic_wq) {
2772 destroy_workqueue(adapter->qlcnic_wq);
2773 adapter->qlcnic_wq = NULL;
2774 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002775
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002776 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002777 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002778 free_netdev(netdev);
2779}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002780
2781static void qlcnic_shutdown(struct pci_dev *pdev)
2782{
2783 if (__qlcnic_shutdown(pdev))
2784 return;
2785
2786 pci_disable_device(pdev);
2787}
2788
2789#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002790static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002791{
2792 int retval;
2793
2794 retval = __qlcnic_shutdown(pdev);
2795 if (retval)
2796 return retval;
2797
2798 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2799 return 0;
2800}
2801
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002802static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002803{
2804 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002805 int err;
2806
2807 err = pci_enable_device(pdev);
2808 if (err)
2809 return err;
2810
2811 pci_set_power_state(pdev, PCI_D0);
2812 pci_set_master(pdev);
2813 pci_restore_state(pdev);
2814
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002815 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002816}
2817#endif
2818
2819static int qlcnic_open(struct net_device *netdev)
2820{
2821 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2822 int err;
2823
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002824 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
2825 netdev_err(netdev, "%s: Device is in non-operational state\n",
2826 __func__);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002827
2828 return -EIO;
2829 }
2830
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002831 netif_carrier_off(netdev);
2832
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002833 err = qlcnic_attach(adapter);
2834 if (err)
2835 return err;
2836
2837 err = __qlcnic_up(adapter, netdev);
2838 if (err)
Rajesh Borundia060d0562014-01-28 11:55:29 -05002839 qlcnic_detach(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002840
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002841 return err;
2842}
2843
2844/*
2845 * qlcnic_close - Disables a network interface entry point
2846 */
2847static int qlcnic_close(struct net_device *netdev)
2848{
2849 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2850
2851 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002852
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002853 return 0;
2854}
2855
Rajesh Borundiad747c332014-05-09 02:51:31 -04002856#define QLCNIC_VF_LB_BUCKET_SIZE 1
2857
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002858void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002859{
2860 void *head;
2861 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002862 struct net_device *netdev = adapter->netdev;
2863 u32 filter_size = 0;
2864 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002865
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002866 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002867 return;
2868
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002869 act_pci_func = adapter->ahw->total_nic_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002870 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002871 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002872
Rajesh Borundiad747c332014-05-09 02:51:31 -04002873 if (qlcnic_sriov_vf_check(adapter)) {
2874 filter_size = QLCNIC_83XX_SRIOV_VF_MAX_MAC - 1;
2875 adapter->fhash.fbucket_size = QLCNIC_VF_LB_BUCKET_SIZE;
2876 } else if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002877 filter_size = QLCNIC_LB_MAX_FILTERS;
2878 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2879 } else {
2880 filter_size = QLC_83XX_LB_MAX_FILTERS;
2881 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2882 }
2883
2884 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002885 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002886
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002887 if (!head)
2888 return;
2889
Sony Chacko13159182013-01-01 03:20:21 +00002890 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002891 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002892
Sony Chacko13159182013-01-01 03:20:21 +00002893 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2894 act_pci_func, adapter->fhash.fmax);
2895
2896 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002897 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002898
2899 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2900
2901 head = kcalloc(adapter->rx_fhash.fbucket_size,
2902 sizeof(struct hlist_head), GFP_ATOMIC);
2903
2904 if (!head)
2905 return;
2906
2907 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2908 adapter->rx_fhash.fhead = head;
2909
2910 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2911 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002912}
2913
2914static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2915{
2916 if (adapter->fhash.fmax && adapter->fhash.fhead)
2917 kfree(adapter->fhash.fhead);
2918
2919 adapter->fhash.fhead = NULL;
2920 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002921
2922 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2923 kfree(adapter->rx_fhash.fhead);
2924
2925 adapter->rx_fhash.fmax = 0;
2926 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002927}
2928
Sony Chacko629263a2013-01-01 04:11:55 +00002929int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002930{
2931 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002932 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002933 int rv = 0;
2934
Sony Chacko13159182013-01-01 03:20:21 +00002935 if (qlcnic_83xx_check(adapter))
2936 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2937
Sony Chacko97ee45e2012-12-04 03:33:52 +00002938 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002939 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002940
2941 temp_state = qlcnic_get_temp_state(temp);
2942 temp_val = qlcnic_get_temp_val(temp);
2943
2944 if (temp_state == QLCNIC_TEMP_PANIC) {
2945 dev_err(&netdev->dev,
2946 "Device temperature %d degrees C exceeds"
2947 " maximum allowed. Hardware has been shut down.\n",
2948 temp_val);
2949 rv = 1;
2950 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002951 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002952 dev_err(&netdev->dev,
2953 "Device temperature %d degrees C "
2954 "exceeds operating range."
2955 " Immediate action needed.\n",
2956 temp_val);
2957 }
2958 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002959 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002960 dev_info(&netdev->dev,
2961 "Device temperature is now %d degrees C"
2962 " in normal range.\n", temp_val);
2963 }
2964 }
Sony Chacko79788452012-12-04 03:33:53 +00002965 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002966 return rv;
2967}
2968
Himanshu Madhani95b38902014-01-23 17:18:29 -05002969static inline void dump_tx_ring_desc(struct qlcnic_host_tx_ring *tx_ring)
2970{
2971 int i;
2972 struct cmd_desc_type0 *tx_desc_info;
2973
2974 for (i = 0; i < tx_ring->num_desc; i++) {
2975 tx_desc_info = &tx_ring->desc_head[i];
2976 pr_info("TX Desc: %d\n", i);
2977 print_hex_dump(KERN_INFO, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
2978 &tx_ring->desc_head[i],
2979 sizeof(struct cmd_desc_type0), true);
2980 }
2981}
2982
2983static void qlcnic_dump_tx_rings(struct qlcnic_adapter *adapter)
2984{
2985 struct net_device *netdev = adapter->netdev;
2986 struct qlcnic_host_tx_ring *tx_ring;
2987 int ring;
2988
2989 if (!netdev || !netif_running(netdev))
2990 return;
2991
2992 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2993 tx_ring = &adapter->tx_ring[ring];
2994 netdev_info(netdev, "Tx ring=%d Context Id=0x%x\n",
2995 ring, tx_ring->ctx_id);
2996 netdev_info(netdev,
2997 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
2998 tx_ring->tx_stats.xmit_finished,
2999 tx_ring->tx_stats.xmit_called,
3000 tx_ring->tx_stats.xmit_on,
3001 tx_ring->tx_stats.xmit_off);
Manish Choprad5d2bf32014-05-06 03:46:48 -04003002
3003 if (tx_ring->crb_intr_mask)
3004 netdev_info(netdev, "crb_intr_mask=%d\n",
3005 readl(tx_ring->crb_intr_mask));
3006
Himanshu Madhani95b38902014-01-23 17:18:29 -05003007 netdev_info(netdev,
Manish Choprad5d2bf32014-05-06 03:46:48 -04003008 "hw_producer=%d, sw_producer=%d sw_consumer=%d, hw_consumer=%d\n",
Himanshu Madhani95b38902014-01-23 17:18:29 -05003009 readl(tx_ring->crb_cmd_producer),
3010 tx_ring->producer, tx_ring->sw_consumer,
3011 le32_to_cpu(*(tx_ring->hw_consumer)));
3012
3013 netdev_info(netdev, "Total desc=%d, Available desc=%d\n",
3014 tx_ring->num_desc, qlcnic_tx_avail(tx_ring));
3015
3016 if (netif_msg_tx_done(adapter->ahw))
3017 dump_tx_ring_desc(tx_ring);
3018 }
3019}
3020
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003021static void qlcnic_tx_timeout(struct net_device *netdev)
3022{
3023 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3024
3025 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3026 return;
3027
Sony Chacko536faa62013-05-09 09:25:13 +00003028 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
3029 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
3030 if (qlcnic_82xx_check(adapter))
3031 adapter->need_fw_reset = 1;
3032 else if (qlcnic_83xx_check(adapter))
3033 qlcnic_83xx_idc_request_reset(adapter,
3034 QLCNIC_FORCE_FW_DUMP_KEY);
3035 } else {
3036 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Himanshu Madhani95b38902014-01-23 17:18:29 -05003037 qlcnic_dump_tx_rings(adapter);
Sony Chacko79788452012-12-04 03:33:53 +00003038 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00003039 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003040}
3041
3042static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
3043{
3044 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3045 struct net_device_stats *stats = &netdev->stats;
3046
Manish Chopra1ac67622014-01-09 12:41:04 -05003047 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
3048 qlcnic_update_stats(adapter);
3049
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003050 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
3051 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00003052 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003053 stats->tx_bytes = adapter->stats.txbytes;
3054 stats->rx_dropped = adapter->stats.rxdropped;
3055 stats->tx_dropped = adapter->stats.txdropped;
3056
3057 return stats;
3058}
3059
stephen hemminger21041402014-01-16 10:31:27 -08003060static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003061{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003062 u32 status;
3063
3064 status = readl(adapter->isr_int_vec);
3065
Sony Chacko79788452012-12-04 03:33:53 +00003066 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003067 return IRQ_NONE;
3068
3069 /* check interrupt state machine, to be sure */
3070 status = readl(adapter->crb_int_state_reg);
3071 if (!ISR_LEGACY_INT_TRIGGERED(status))
3072 return IRQ_NONE;
3073
3074 writel(0xffffffff, adapter->tgt_status_reg);
3075 /* read twice to ensure write is flushed */
3076 readl(adapter->isr_int_vec);
3077 readl(adapter->isr_int_vec);
3078
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00003079 return IRQ_HANDLED;
3080}
3081
3082static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
3083{
3084 struct qlcnic_host_sds_ring *sds_ring = data;
3085 struct qlcnic_adapter *adapter = sds_ring->adapter;
3086
3087 if (adapter->flags & QLCNIC_MSIX_ENABLED)
3088 goto done;
3089 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
3090 writel(0xffffffff, adapter->tgt_status_reg);
3091 goto done;
3092 }
3093
3094 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
3095 return IRQ_NONE;
3096
3097done:
Sony Chacko79788452012-12-04 03:33:53 +00003098 adapter->ahw->diag_cnt++;
Manish chopra2cc57522014-01-23 17:18:30 -05003099 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00003100 return IRQ_HANDLED;
3101}
3102
3103static irqreturn_t qlcnic_intr(int irq, void *data)
3104{
3105 struct qlcnic_host_sds_ring *sds_ring = data;
3106 struct qlcnic_adapter *adapter = sds_ring->adapter;
3107
3108 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
3109 return IRQ_NONE;
3110
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003111 napi_schedule(&sds_ring->napi);
3112
3113 return IRQ_HANDLED;
3114}
3115
3116static irqreturn_t qlcnic_msi_intr(int irq, void *data)
3117{
3118 struct qlcnic_host_sds_ring *sds_ring = data;
3119 struct qlcnic_adapter *adapter = sds_ring->adapter;
3120
3121 /* clear interrupt */
3122 writel(0xffffffff, adapter->tgt_status_reg);
3123
3124 napi_schedule(&sds_ring->napi);
3125 return IRQ_HANDLED;
3126}
3127
3128static irqreturn_t qlcnic_msix_intr(int irq, void *data)
3129{
3130 struct qlcnic_host_sds_ring *sds_ring = data;
3131
3132 napi_schedule(&sds_ring->napi);
3133 return IRQ_HANDLED;
3134}
3135
Sony Chacko13159182013-01-01 03:20:21 +00003136static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
3137{
3138 struct qlcnic_host_tx_ring *tx_ring = data;
3139
3140 napi_schedule(&tx_ring->napi);
3141 return IRQ_HANDLED;
3142}
3143
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003144#ifdef CONFIG_NET_POLL_CONTROLLER
3145static void qlcnic_poll_controller(struct net_device *netdev)
3146{
3147 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Manish chopra2b018ad92014-01-23 17:18:31 -05003148 struct qlcnic_host_sds_ring *sds_ring;
3149 struct qlcnic_recv_context *recv_ctx;
3150 struct qlcnic_host_tx_ring *tx_ring;
3151 int ring;
Yinglin Luanbf827912010-08-22 21:57:56 +00003152
Manish chopra2b018ad92014-01-23 17:18:31 -05003153 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3154 return;
3155
3156 recv_ctx = adapter->recv_ctx;
3157
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003158 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Yinglin Luanbf827912010-08-22 21:57:56 +00003159 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2b018ad92014-01-23 17:18:31 -05003160 qlcnic_disable_sds_intr(adapter, sds_ring);
3161 napi_schedule(&sds_ring->napi);
Yinglin Luanbf827912010-08-22 21:57:56 +00003162 }
Manish chopra2b018ad92014-01-23 17:18:31 -05003163
3164 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
3165 /* Only Multi-Tx queue capable devices need to
3166 * schedule NAPI for TX rings
3167 */
3168 if ((qlcnic_83xx_check(adapter) &&
3169 (adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
3170 (qlcnic_82xx_check(adapter) &&
3171 !qlcnic_check_multi_tx(adapter)))
3172 return;
3173
3174 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
3175 tx_ring = &adapter->tx_ring[ring];
3176 qlcnic_disable_tx_intr(adapter, tx_ring);
3177 napi_schedule(&tx_ring->napi);
3178 }
3179 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003180}
3181#endif
3182
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003183static void
3184qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
3185{
3186 u32 val;
3187
3188 val = adapter->portnum & 0xf;
3189 val |= encoding << 7;
3190 val |= (jiffies - adapter->dev_rst_time) << 8;
3191
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003192 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003193 adapter->dev_rst_time = jiffies;
3194}
3195
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003196static int
3197qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003198{
3199 u32 val;
3200
3201 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
3202 state != QLCNIC_DEV_NEED_QUISCENT);
3203
3204 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003205 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003206
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003207 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003208
3209 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003210 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003211 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003212 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003213
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003214 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003215
3216 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003217
3218 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003219}
3220
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003221static int
3222qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
3223{
3224 u32 val;
3225
3226 if (qlcnic_api_lock(adapter))
3227 return -EBUSY;
3228
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003229 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003230 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003231 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003232
3233 qlcnic_api_unlock(adapter);
3234
3235 return 0;
3236}
3237
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003238void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003239{
3240 u32 val;
3241
3242 if (qlcnic_api_lock(adapter))
3243 goto err;
3244
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003245 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003246 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003247 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003248
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003249 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003250 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3251 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003252 dev_info(&adapter->pdev->dev,
3253 "Device state set to Failed. Please Reboot\n");
3254 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003255 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3256 QLCNIC_DEV_COLD);
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 Salecha6d2a4722010-04-22 02:51:38 +00003259 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003260 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003261
3262 qlcnic_api_unlock(adapter);
3263err:
3264 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003265 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003266 clear_bit(__QLCNIC_START_FW, &adapter->state);
3267 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3268}
3269
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003270/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003271static int
3272qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
3273{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003274 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003275 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003276
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003277 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
3278 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003279
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003280 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003281 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003282 act = act & active_mask;
3283 }
3284
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003285 if (((state & 0x11111111) == (act & 0x11111111)) ||
3286 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
3287 return 0;
3288 else
3289 return 1;
3290}
3291
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003292static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
3293{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003294 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003295
3296 if (val != QLCNIC_DRV_IDC_VER) {
3297 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
3298 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
3299 }
3300
3301 return 0;
3302}
3303
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003304static int
3305qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
3306{
3307 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003308 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003309 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003310 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003311
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003312 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
3313 return 1;
3314
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003315 if (qlcnic_api_lock(adapter))
3316 return -1;
3317
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003318 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003319 if (!(val & (1 << (portnum * 4)))) {
3320 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003321 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003322 }
3323
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003324 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003325 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003326
3327 switch (prev_state) {
3328 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003329 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3330 QLCNIC_DEV_INITIALIZING);
3331 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3332 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003333 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003334 qlcnic_api_unlock(adapter);
3335 return 1;
3336
3337 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003338 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003339 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003340 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003341
3342 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003343 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003344 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003345 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003346 break;
3347
3348 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003349 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003350 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003351 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003352 break;
3353
3354 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003355 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003356 qlcnic_api_unlock(adapter);
3357 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003358
3359 case QLCNIC_DEV_INITIALIZING:
3360 case QLCNIC_DEV_QUISCENT:
3361 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003362 }
3363
3364 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003365
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003366 do {
3367 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003368 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003369
3370 if (prev_state == QLCNIC_DEV_QUISCENT)
3371 continue;
3372 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003373
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003374 if (!dev_init_timeo) {
3375 dev_err(&adapter->pdev->dev,
3376 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003377 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003378 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003379
3380 if (qlcnic_api_lock(adapter))
3381 return -1;
3382
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003383 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003384 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003385 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003386
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003387 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003388 qlcnic_api_unlock(adapter);
3389
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003390 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003391}
3392
3393static void
3394qlcnic_fwinit_work(struct work_struct *work)
3395{
3396 struct qlcnic_adapter *adapter = container_of(work,
3397 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003398 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003399 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003400
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003401 if (qlcnic_api_lock(adapter))
3402 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003403
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003404 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003405 if (dev_state == QLCNIC_DEV_QUISCENT ||
3406 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003407 qlcnic_api_unlock(adapter);
3408 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3409 FW_POLL_DELAY * 2);
3410 return;
3411 }
3412
Sony Chacko79788452012-12-04 03:33:53 +00003413 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003414 qlcnic_api_unlock(adapter);
3415 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003416 }
3417
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003418 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3419 dev_state == QLCNIC_DEV_READY) {
3420 dev_info(&adapter->pdev->dev, "Detected state change from "
3421 "DEV_NEED_RESET, skipping ack check\n");
3422 goto skip_ack_check;
3423 }
3424
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003425 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003426 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003427 adapter->reset_ack_timeo);
3428 goto skip_ack_check;
3429 }
3430
3431 if (!qlcnic_check_drv_state(adapter)) {
3432skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003433 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003434
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003435 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003436 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3437 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003438 set_bit(__QLCNIC_START_FW, &adapter->state);
3439 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003440 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003441 val = QLC_SHARED_REG_RD32(adapter,
3442 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003443 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003444 QLC_SHARED_REG_WR32(adapter,
3445 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003446 }
3447
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003448 qlcnic_api_unlock(adapter);
3449
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003450 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003451 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003452 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003453 QLCDB(adapter, DRV, "Take FW dump\n");
3454 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003455 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003456 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003457 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003458
3459 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003460 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003461 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003462 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003463 return;
3464 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003465 goto err_ret;
3466 }
3467
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003468 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003469
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003470wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003471 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003472 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003473
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003474 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003475 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003476 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003477 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003478 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003479 return;
3480 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003481 case QLCNIC_DEV_FAILED:
3482 break;
3483 default:
3484 qlcnic_schedule_work(adapter,
3485 qlcnic_fwinit_work, FW_POLL_DELAY);
3486 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003487 }
3488
3489err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003490 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3491 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003492 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003493 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003494}
3495
3496static void
3497qlcnic_detach_work(struct work_struct *work)
3498{
3499 struct qlcnic_adapter *adapter = container_of(work,
3500 struct qlcnic_adapter, fw_work.work);
3501 struct net_device *netdev = adapter->netdev;
3502 u32 status;
3503
3504 netif_device_detach(netdev);
3505
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003506 /* Dont grab rtnl lock during Quiscent mode */
3507 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3508 if (netif_running(netdev))
3509 __qlcnic_down(adapter, netdev);
3510 } else
3511 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003512
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003513 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003514
Sony Chacko44f65b22011-08-29 12:50:26 +00003515 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3516 dev_err(&adapter->pdev->dev,
3517 "Detaching the device: peg halt status1=0x%x\n",
3518 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003519
Sony Chacko44f65b22011-08-29 12:50:26 +00003520 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3521 dev_err(&adapter->pdev->dev,
3522 "On board active cooling fan failed. "
3523 "Device has been halted.\n");
3524 dev_err(&adapter->pdev->dev,
3525 "Replace the adapter.\n");
3526 }
3527
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003528 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003529 }
3530
Sony Chacko79788452012-12-04 03:33:53 +00003531 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003532 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003533 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003534 goto err_ret;
3535 }
3536
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003537 /* Dont ack if this instance is the reset owner */
3538 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003539 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3540 dev_err(&adapter->pdev->dev,
3541 "Failed to set driver state,"
3542 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003543 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003544 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003545 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003546
3547 adapter->fw_wait_cnt = 0;
3548
3549 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3550
3551 return;
3552
3553err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003554 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003555 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003556}
3557
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003558/*Transit NPAR state to NON Operational */
3559static void
3560qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3561{
3562 u32 state;
3563
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003564 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003565 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3566 return;
3567
3568 if (qlcnic_api_lock(adapter))
3569 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003570 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3571 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003572 qlcnic_api_unlock(adapter);
3573}
3574
stephen hemminger21041402014-01-16 10:31:27 -08003575static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter,
3576 u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003577{
Sritej Velaga646779f2012-02-03 13:45:41 +00003578 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003579
Sritej Velaga646779f2012-02-03 13:45:41 +00003580 qlcnic_xg_set_xg0_mask(xg_val);
3581 qlcnic_xg_set_xg1_mask(xg_val);
3582 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3583 qlcnic_gb_set_gb0_mask(gb_val);
3584 qlcnic_gb_set_gb1_mask(gb_val);
3585 qlcnic_gb_set_gb2_mask(gb_val);
3586 qlcnic_gb_set_gb3_mask(gb_val);
3587 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3588 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3589 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003590 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003591
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003592 if (qlcnic_api_lock(adapter))
3593 return;
3594
Sony Chacko13159182013-01-01 03:20:21 +00003595 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05003596
3597 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
3598 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n",
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003599 __func__);
3600 qlcnic_api_unlock(adapter);
3601
3602 return;
3603 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003604
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003605 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003606 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3607 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003608 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003609 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003610 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003611 }
3612
Sony Chacko13159182013-01-01 03:20:21 +00003613 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3614 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003615 qlcnic_api_unlock(adapter);
3616}
3617
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003618/* Transit to NPAR READY state from NPAR NOT READY state */
3619static void
3620qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3621{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003622 if (qlcnic_api_lock(adapter))
3623 return;
3624
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003625 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3626 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003627 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003628
3629 qlcnic_api_unlock(adapter);
3630}
3631
Sony Chacko13159182013-01-01 03:20:21 +00003632void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3633 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003634{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003635 if (test_bit(__QLCNIC_AER, &adapter->state))
3636 return;
3637
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003638 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003639 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3640 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003641}
3642
3643static void
3644qlcnic_attach_work(struct work_struct *work)
3645{
3646 struct qlcnic_adapter *adapter = container_of(work,
3647 struct qlcnic_adapter, fw_work.work);
3648 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003649 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003650
Sony Chacko79788452012-12-04 03:33:53 +00003651 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003652 npar_state = QLC_SHARED_REG_RD32(adapter,
3653 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003654 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3655 qlcnic_clr_all_drv_state(adapter, 0);
3656 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3657 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3658 FW_POLL_DELAY);
3659 else
3660 goto attach;
3661 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3662 return;
3663 }
3664attach:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04003665 qlcnic_dcb_get_info(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003666
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003667 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003668 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003669 goto done;
3670
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003671 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003672 }
3673
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003674done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003675 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003676 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003677 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003678 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003679 if (adapter->portnum == 0)
3680 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003681
3682 if (!qlcnic_clr_drv_state(adapter))
3683 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3684 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003685}
3686
3687static int
3688qlcnic_check_health(struct qlcnic_adapter *adapter)
3689{
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003690 struct qlcnic_hardware_context *ahw = adapter->ahw;
3691 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sony Chacko4e708122010-08-31 17:17:44 +00003692 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003693 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003694 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003695
3696 if (qlcnic_check_temp(adapter))
3697 goto detach;
3698
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003699 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003700 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003701
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003702 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003703 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003704 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003705 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003706 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3707 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003708
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003709 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003710 if (heartbeat != adapter->heartbeat) {
3711 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003712 adapter->fw_fail_cnt = 0;
3713 if (adapter->need_fw_reset)
3714 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003715
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003716 if (ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003717 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003718
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003719 return 0;
3720 }
3721
3722 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3723 return 0;
3724
Sritej Velaga032a13c2011-07-29 13:30:27 +00003725 adapter->flags |= QLCNIC_FW_HANG;
3726
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003727 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003728
Sony Chacko099f7aa2012-12-04 03:33:58 +00003729 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003730 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003731
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003732 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003733 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003734 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003735 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3736 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3737 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3738 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003739 peg_status,
3740 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003741 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3742 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3743 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3744 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3745 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003746 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003747 dev_err(&adapter->pdev->dev,
3748 "Firmware aborted with error code 0x00006700. "
3749 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003750detach:
3751 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3752 QLCNIC_DEV_NEED_RESET;
3753
Sony Chacko099f7aa2012-12-04 03:33:58 +00003754 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3755 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003756
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003757 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003758 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003759 } else if (!qlcnic_auto_fw_reset && fw_dump->enable &&
3760 adapter->flags & QLCNIC_FW_RESET_OWNER) {
3761 qlcnic_dump_fw(adapter);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003762 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003763
3764 return 1;
3765}
3766
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003767void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003768{
3769 struct qlcnic_adapter *adapter = container_of(work,
3770 struct qlcnic_adapter, fw_work.work);
3771
3772 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3773 goto reschedule;
3774
3775
3776 if (qlcnic_check_health(adapter))
3777 return;
3778
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003779 if (adapter->fhash.fnum)
3780 qlcnic_prune_lb_filters(adapter);
3781
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003782reschedule:
3783 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3784}
3785
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003786static int qlcnic_is_first_func(struct pci_dev *pdev)
3787{
3788 struct pci_dev *oth_pdev;
3789 int val = pdev->devfn;
3790
3791 while (val-- > 0) {
3792 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3793 (pdev->bus), pdev->bus->number,
3794 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003795 if (!oth_pdev)
3796 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003797
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003798 if (oth_pdev->current_state != PCI_D3cold) {
3799 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003800 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003801 }
3802 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003803 }
3804 return 1;
3805}
3806
3807static int qlcnic_attach_func(struct pci_dev *pdev)
3808{
3809 int err, first_func;
3810 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3811 struct net_device *netdev = adapter->netdev;
3812
3813 pdev->error_state = pci_channel_io_normal;
3814
3815 err = pci_enable_device(pdev);
3816 if (err)
3817 return err;
3818
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003819 pci_set_master(pdev);
3820 pci_restore_state(pdev);
3821
3822 first_func = qlcnic_is_first_func(pdev);
3823
3824 if (qlcnic_api_lock(adapter))
3825 return -EINVAL;
3826
Sony Chacko79788452012-12-04 03:33:53 +00003827 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003828 adapter->need_fw_reset = 1;
3829 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003830 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3831 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003832 QLCDB(adapter, DRV, "Restarting fw\n");
3833 }
3834 qlcnic_api_unlock(adapter);
3835
Sony Chacko13159182013-01-01 03:20:21 +00003836 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003837 if (err)
3838 return err;
3839
3840 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003841 kfree(adapter->msix_entries);
3842 adapter->msix_entries = NULL;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003843 err = qlcnic_setup_intr(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003844
Manish chopra9a97e702013-01-25 10:20:37 +00003845 if (err) {
3846 kfree(adapter->msix_entries);
3847 netdev_err(netdev, "failed to setup interrupt\n");
3848 return err;
3849 }
3850
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003851 if (netif_running(netdev)) {
3852 err = qlcnic_attach(adapter);
3853 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003854 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003855 clear_bit(__QLCNIC_AER, &adapter->state);
3856 netif_device_attach(netdev);
3857 return err;
3858 }
3859
3860 err = qlcnic_up(adapter, netdev);
3861 if (err)
3862 goto done;
3863
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003864 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003865 }
3866 done:
3867 netif_device_attach(netdev);
3868 return err;
3869}
3870
stephen hemminger21041402014-01-16 10:31:27 -08003871static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3872 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003873{
3874 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3875 struct net_device *netdev = adapter->netdev;
3876
3877 if (state == pci_channel_io_perm_failure)
3878 return PCI_ERS_RESULT_DISCONNECT;
3879
3880 if (state == pci_channel_io_normal)
3881 return PCI_ERS_RESULT_RECOVERED;
3882
3883 set_bit(__QLCNIC_AER, &adapter->state);
3884 netif_device_detach(netdev);
3885
3886 cancel_delayed_work_sync(&adapter->fw_work);
3887
3888 if (netif_running(netdev))
3889 qlcnic_down(adapter, netdev);
3890
3891 qlcnic_detach(adapter);
3892 qlcnic_teardown_intr(adapter);
3893
3894 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3895
3896 pci_save_state(pdev);
3897 pci_disable_device(pdev);
3898
3899 return PCI_ERS_RESULT_NEED_RESET;
3900}
3901
stephen hemminger21041402014-01-16 10:31:27 -08003902static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003903{
3904 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3905 PCI_ERS_RESULT_RECOVERED;
3906}
3907
stephen hemminger21041402014-01-16 10:31:27 -08003908static void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003909{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003910 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003911 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3912
3913 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003914 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3915 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3916 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003917 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003918 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003919}
3920
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003921static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3922 pci_channel_state_t state)
3923{
3924 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3925 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3926
3927 if (hw_ops->io_error_detected) {
3928 return hw_ops->io_error_detected(pdev, state);
3929 } else {
3930 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3931 return PCI_ERS_RESULT_DISCONNECT;
3932 }
3933}
3934
3935static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3936{
3937 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3938 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3939
3940 if (hw_ops->io_slot_reset) {
3941 return hw_ops->io_slot_reset(pdev);
3942 } else {
3943 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
3944 return PCI_ERS_RESULT_DISCONNECT;
3945 }
3946}
3947
3948static void qlcnic_io_resume(struct pci_dev *pdev)
3949{
3950 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3951 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3952
3953 if (hw_ops->io_resume)
3954 hw_ops->io_resume(pdev);
3955 else
3956 dev_err(&pdev->dev, "AER resume handler not registered.\n");
3957}
3958
3959
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003960static int
3961qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3962{
3963 int err;
3964
3965 err = qlcnic_can_start_firmware(adapter);
3966 if (err)
3967 return err;
3968
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003969 err = qlcnic_check_npar_opertional(adapter);
3970 if (err)
3971 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003972
Rajesh Borundia174240a2010-08-31 17:17:47 +00003973 err = qlcnic_initialize_nic(adapter);
3974 if (err)
3975 return err;
3976
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003977 qlcnic_check_options(adapter);
3978
Rajesh Borundia73733732010-08-31 17:17:50 +00003979 err = qlcnic_set_eswitch_port_config(adapter);
3980 if (err)
3981 return err;
3982
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003983 adapter->need_fw_reset = 0;
3984
3985 return err;
3986}
3987
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003988int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3989 int queue_type)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003990{
3991 struct net_device *netdev = adapter->netdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003992 u8 max_hw_rings = 0;
3993 char buf[8];
3994 int cur_rings;
3995
3996 if (queue_type == QLCNIC_RX_QUEUE) {
3997 max_hw_rings = adapter->max_sds_rings;
3998 cur_rings = adapter->drv_sds_rings;
3999 strcpy(buf, "SDS");
4000 } else if (queue_type == QLCNIC_TX_QUEUE) {
Himanshu Madhani18afc102013-11-04 13:31:32 -05004001 max_hw_rings = adapter->max_tx_rings;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004002 cur_rings = adapter->drv_tx_rings;
4003 strcpy(buf, "Tx");
4004 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004005
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004006 if (!is_power_of_2(ring_cnt)) {
4007 netdev_err(netdev, "%s rings value should be a power of 2\n",
4008 buf);
4009 return -EINVAL;
4010 }
4011
4012 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) &&
4013 !qlcnic_check_multi_tx(adapter)) {
4014 netdev_err(netdev, "No Multi Tx queue support\n");
4015 return -EINVAL;
4016 }
4017
4018 if (ring_cnt > num_online_cpus()) {
4019 netdev_err(netdev,
4020 "%s value[%u] should not be higher than, number of online CPUs\n",
4021 buf, num_online_cpus());
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004022 return -EINVAL;
4023 }
4024
4025 return 0;
4026}
4027
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05004028int qlcnic_setup_rings(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004029{
Manish Chopra6389b762013-04-24 12:42:39 +00004030 struct net_device *netdev = adapter->netdev;
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004031 u8 tx_rings, rx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00004032 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004033
Sony Chacko319ecf12013-01-01 03:20:22 +00004034 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
4035 return -EBUSY;
4036
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004037 tx_rings = adapter->drv_tss_rings;
4038 rx_rings = adapter->drv_rss_rings;
4039
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004040 netif_device_detach(netdev);
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004041
4042 err = qlcnic_set_real_num_queues(adapter, tx_rings, rx_rings);
4043 if (err)
4044 goto done;
4045
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004046 if (netif_running(netdev))
4047 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00004048
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004049 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004050
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004051 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004052 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004053 qlcnic_83xx_enable_mbx_poll(adapter);
4054 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00004055
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004056 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004057
Himanshu Madhani34e8c402013-11-04 13:31:31 -05004058 err = qlcnic_setup_intr(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +00004059 if (err) {
4060 kfree(adapter->msix_entries);
4061 netdev_err(netdev, "failed to setup interrupt\n");
4062 return err;
4063 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004064
Shahed Shaikh84d7ad22014-05-06 03:46:49 -04004065 /* Check if we need to update real_num_{tx|rx}_queues because
4066 * qlcnic_setup_intr() may change Tx/Rx rings size
4067 */
4068 if ((tx_rings != adapter->drv_tx_rings) ||
4069 (rx_rings != adapter->drv_sds_rings)) {
4070 err = qlcnic_set_real_num_queues(adapter,
4071 adapter->drv_tx_rings,
4072 adapter->drv_sds_rings);
4073 if (err)
4074 goto done;
4075 }
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05004076
Sony Chacko13159182013-01-01 03:20:21 +00004077 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05004078 qlcnic_83xx_initialize_nic(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00004079 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00004080 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00004081 if (err) {
4082 dev_err(&adapter->pdev->dev,
4083 "failed to setup mbx interrupt\n");
4084 goto done;
4085 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004086 }
4087
4088 if (netif_running(netdev)) {
4089 err = qlcnic_attach(adapter);
4090 if (err)
4091 goto done;
4092 err = __qlcnic_up(adapter, netdev);
4093 if (err)
4094 goto done;
4095 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
4096 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04004097done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00004098 netif_device_attach(netdev);
4099 clear_bit(__QLCNIC_RESETTING, &adapter->state);
4100 return err;
4101}
4102
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004103#ifdef CONFIG_INET
4104
4105#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4106
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004107static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004108qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4109 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004110{
4111 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004112
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004113 indev = in_dev_get(dev);
4114 if (!indev)
4115 return;
4116
4117 for_ifa(indev) {
4118 switch (event) {
4119 case NETDEV_UP:
4120 qlcnic_config_ipaddr(adapter,
4121 ifa->ifa_address, QLCNIC_IP_UP);
4122 break;
4123 case NETDEV_DOWN:
4124 qlcnic_config_ipaddr(adapter,
4125 ifa->ifa_address, QLCNIC_IP_DOWN);
4126 break;
4127 default:
4128 break;
4129 }
4130 } endfor_ifa(indev);
4131
4132 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004133}
4134
Sony Chacko319ecf12013-01-01 03:20:22 +00004135void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004136{
4137 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4138 struct net_device *dev;
4139 u16 vid;
4140
4141 qlcnic_config_indev_addr(adapter, netdev, event);
4142
Jiri Pirko43c00a72013-01-03 22:48:57 +00004143 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00004144 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
dingtianhongf06c7f9f2014-05-09 14:58:05 +08004145 dev = __vlan_find_dev_deep_rcu(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004146 if (!dev)
4147 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004148 qlcnic_config_indev_addr(adapter, dev, event);
4149 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00004150 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004151}
4152
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004153static int qlcnic_netdev_event(struct notifier_block *this,
4154 unsigned long event, void *ptr)
4155{
4156 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00004157 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004158
4159recheck:
4160 if (dev == NULL)
4161 goto done;
4162
4163 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4164 dev = vlan_dev_real_dev(dev);
4165 goto recheck;
4166 }
4167
4168 if (!is_qlcnic_netdev(dev))
4169 goto done;
4170
4171 adapter = netdev_priv(dev);
4172
4173 if (!adapter)
4174 goto done;
4175
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004176 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004177 goto done;
4178
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004179 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004180done:
4181 return NOTIFY_DONE;
4182}
4183
4184static int
4185qlcnic_inetaddr_event(struct notifier_block *this,
4186 unsigned long event, void *ptr)
4187{
4188 struct qlcnic_adapter *adapter;
4189 struct net_device *dev;
4190
4191 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4192
4193 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4194
4195recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004196 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004197 goto done;
4198
4199 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4200 dev = vlan_dev_real_dev(dev);
4201 goto recheck;
4202 }
4203
4204 if (!is_qlcnic_netdev(dev))
4205 goto done;
4206
4207 adapter = netdev_priv(dev);
4208
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00004209 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004210 goto done;
4211
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004212 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004213 goto done;
4214
4215 switch (event) {
4216 case NETDEV_UP:
4217 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00004218
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004219 break;
4220 case NETDEV_DOWN:
4221 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00004222
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004223 break;
4224 default:
4225 break;
4226 }
4227
4228done:
4229 return NOTIFY_DONE;
4230}
4231
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004232static struct notifier_block qlcnic_netdev_cb = {
4233 .notifier_call = qlcnic_netdev_event,
4234};
4235
4236static struct notifier_block qlcnic_inetaddr_cb = {
4237 .notifier_call = qlcnic_inetaddr_event,
4238};
4239#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00004240void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004241{ }
4242#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00004243static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004244 .error_detected = qlcnic_io_error_detected,
4245 .slot_reset = qlcnic_io_slot_reset,
4246 .resume = qlcnic_io_resume,
4247};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004248
4249static struct pci_driver qlcnic_driver = {
4250 .name = qlcnic_driver_name,
4251 .id_table = qlcnic_pci_tbl,
4252 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05004253 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004254#ifdef CONFIG_PM
4255 .suspend = qlcnic_suspend,
4256 .resume = qlcnic_resume,
4257#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004258 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00004259 .err_handler = &qlcnic_err_handler,
4260#ifdef CONFIG_QLCNIC_SRIOV
4261 .sriov_configure = qlcnic_pci_sriov_configure,
4262#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004263
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004264};
4265
4266static int __init qlcnic_init_module(void)
4267{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004268 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004269
4270 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4271
4272#ifdef CONFIG_INET
4273 register_netdevice_notifier(&qlcnic_netdev_cb);
4274 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4275#endif
4276
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004277 ret = pci_register_driver(&qlcnic_driver);
4278 if (ret) {
4279#ifdef CONFIG_INET
4280 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4281 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4282#endif
4283 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004284
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004285 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004286}
4287
4288module_init(qlcnic_init_module);
4289
4290static void __exit qlcnic_exit_module(void)
4291{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004292 pci_unregister_driver(&qlcnic_driver);
4293
4294#ifdef CONFIG_INET
4295 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4296 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4297#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004298}
4299
4300module_exit(qlcnic_exit_module);