blob: 2c8cac0c6a55a7e9a32541c4f88e7d0ddcd5a977 [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>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000024
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000025MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000026MODULE_LICENSE("GPL");
27MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
28MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
29
30char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000031static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
32 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000033
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000034static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000035module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000036MODULE_PARM_DESC(qlcnic_mac_learn,
37 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000038
Sony Chacko629263a2013-01-01 04:11:55 +000039int qlcnic_use_msi = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000040MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000041module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000042
Sony Chacko629263a2013-01-01 04:11:55 +000043int qlcnic_use_msi_x = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000044MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000045module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000046
Sony Chacko629263a2013-01-01 04:11:55 +000047int qlcnic_auto_fw_reset = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000048MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000049module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000050
Sony Chacko629263a2013-01-01 04:11:55 +000051int qlcnic_load_fw_file;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000052MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000053module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000054
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000055static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050056static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000057static int qlcnic_open(struct net_device *netdev);
58static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000059static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000060static void qlcnic_attach_work(struct work_struct *work);
61static void qlcnic_fwinit_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000062#ifdef CONFIG_NET_POLL_CONTROLLER
63static void qlcnic_poll_controller(struct net_device *netdev);
64#endif
65
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000066static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000067static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
68
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000069static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000070static irqreturn_t qlcnic_intr(int irq, void *data);
71static irqreturn_t qlcnic_msi_intr(int irq, void *data);
72static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000073static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000074
75static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000076static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000077
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000078static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000079static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000080static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000081static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
82static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000083
Sony Chacko13159182013-01-01 03:20:21 +000084static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
85{
86 struct qlcnic_hardware_context *ahw = adapter->ahw;
87
88 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
89 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
90 else
91 return 1;
92}
93
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000094/* PCI Device ID Table */
95#define ENTRY(device) \
96 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
97 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
98
Amit Kumar Salecha6a902882010-02-01 05:24:54 +000099static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000100 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000101 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000102 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Manish Chopra15ca1402013-08-16 19:07:13 -0400103 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X),
104 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000105 {0,}
106};
107
108MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
109
110
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000111inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000112{
113 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000114}
115
116static const u32 msi_tgt_status[8] = {
117 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
118 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
119 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
120 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
121};
122
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000123static const u32 qlcnic_reg_tbl[] = {
124 0x1B20A8, /* PEG_HALT_STAT1 */
125 0x1B20AC, /* PEG_HALT_STAT2 */
126 0x1B20B0, /* FW_HEARTBEAT */
127 0x1B2100, /* LOCK ID */
128 0x1B2128, /* FW_CAPABILITIES */
129 0x1B2138, /* drv active */
130 0x1B2140, /* dev state */
131 0x1B2144, /* drv state */
132 0x1B2148, /* drv scratch */
133 0x1B214C, /* dev partition info */
134 0x1B2174, /* drv idc ver */
135 0x1B2150, /* fw version major */
136 0x1B2154, /* fw version minor */
137 0x1B2158, /* fw version sub */
138 0x1B219C, /* npar state */
139 0x1B21FC, /* FW_IMG_VALID */
140 0x1B2250, /* CMD_PEG_STATE */
141 0x1B233C, /* RCV_PEG_STATE */
142 0x1B23B4, /* ASIC TEMP */
143 0x1B216C, /* FW api */
144 0x1B2170, /* drv op mode */
145 0x13C010, /* flash lock */
146 0x13C014, /* flash unlock */
147};
148
Sony Chacko22999792012-12-04 03:33:55 +0000149static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000150 { PCI_VENDOR_ID_QLOGIC,
Manish Chopra15ca1402013-08-16 19:07:13 -0400151 PCI_DEVICE_ID_QLOGIC_QLE844X,
152 0x0,
153 0x0,
154 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
155 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000156 PCI_DEVICE_ID_QLOGIC_QLE834X,
157 PCI_VENDOR_ID_QLOGIC,
158 0x24e,
159 "8300 Series Dual Port 10GbE Converged Network Adapter "
160 "(TCP/IP Networking)" },
161 { PCI_VENDOR_ID_QLOGIC,
162 PCI_DEVICE_ID_QLOGIC_QLE834X,
163 PCI_VENDOR_ID_QLOGIC,
164 0x243,
165 "8300 Series Single Port 10GbE Converged Network Adapter "
166 "(TCP/IP Networking)" },
167 { PCI_VENDOR_ID_QLOGIC,
168 PCI_DEVICE_ID_QLOGIC_QLE834X,
169 PCI_VENDOR_ID_QLOGIC,
170 0x24a,
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 0x246,
177 "8300 Series Dual 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 0x252,
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 0x26e,
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 0x260,
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 0x266,
201 "8300 Series Single 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 0x269,
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 0x271,
213 "8300 Series Dual Port 10GbE Converged Network Adapter "
214 "(TCP/IP Networking)" },
215 { PCI_VENDOR_ID_QLOGIC,
216 PCI_DEVICE_ID_QLOGIC_QLE834X,
217 0x0, 0x0, "8300 Series 1/10GbE Controller" },
218 { PCI_VENDOR_ID_QLOGIC,
219 PCI_DEVICE_ID_QLOGIC_QLE824X,
220 PCI_VENDOR_ID_QLOGIC,
221 0x203,
222 "8200 Series Single Port 10GbE Converged Network Adapter"
223 "(TCP/IP Networking)" },
224 { PCI_VENDOR_ID_QLOGIC,
225 PCI_DEVICE_ID_QLOGIC_QLE824X,
226 PCI_VENDOR_ID_QLOGIC,
227 0x207,
228 "8200 Series Dual Port 10GbE Converged Network Adapter"
229 "(TCP/IP Networking)" },
230 { PCI_VENDOR_ID_QLOGIC,
231 PCI_DEVICE_ID_QLOGIC_QLE824X,
232 PCI_VENDOR_ID_QLOGIC,
233 0x20b,
234 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
235 { PCI_VENDOR_ID_QLOGIC,
236 PCI_DEVICE_ID_QLOGIC_QLE824X,
237 PCI_VENDOR_ID_QLOGIC,
238 0x20c,
239 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
240 { PCI_VENDOR_ID_QLOGIC,
241 PCI_DEVICE_ID_QLOGIC_QLE824X,
242 PCI_VENDOR_ID_QLOGIC,
243 0x20f,
244 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
245 { PCI_VENDOR_ID_QLOGIC,
246 PCI_DEVICE_ID_QLOGIC_QLE824X,
247 0x103c, 0x3733,
248 "NC523SFP 10Gb 2-port Server Adapter" },
249 { PCI_VENDOR_ID_QLOGIC,
250 PCI_DEVICE_ID_QLOGIC_QLE824X,
251 0x103c, 0x3346,
252 "CN1000Q Dual Port Converged Network Adapter" },
253 { PCI_VENDOR_ID_QLOGIC,
254 PCI_DEVICE_ID_QLOGIC_QLE824X,
255 PCI_VENDOR_ID_QLOGIC,
256 0x210,
257 "QME8242-k 10GbE Dual Port Mezzanine Card" },
258 { PCI_VENDOR_ID_QLOGIC,
259 PCI_DEVICE_ID_QLOGIC_QLE824X,
260 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000261};
262
263#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
264
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000265static const
266struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
267
Sony Chackoc70001a2012-11-28 04:34:26 +0000268int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000269{
270 int size = sizeof(struct qlcnic_host_sds_ring) * count;
271
272 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
273
Eric Dumazet807540b2010-09-23 05:40:09 +0000274 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000275}
276
Sony Chackoc70001a2012-11-28 04:34:26 +0000277void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000278{
279 if (recv_ctx->sds_rings != NULL)
280 kfree(recv_ctx->sds_rings);
281
282 recv_ctx->sds_rings = NULL;
283}
284
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000285int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000286{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000287 struct net_device *netdev = adapter->netdev;
288 struct pci_dev *pdev = adapter->pdev;
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400289 u8 mac_addr[ETH_ALEN];
290 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000291
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400292 ret = qlcnic_get_mac_address(adapter, mac_addr,
293 adapter->ahw->pci_func);
294 if (ret)
295 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000296
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000297 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000298 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
299
300 /* set station address */
301
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000302 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000303 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
304 netdev->dev_addr);
305
306 return 0;
307}
308
Manish Chopracffe52f2013-05-09 09:25:09 +0000309static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
310{
311 struct qlcnic_mac_list_s *cur;
312 struct list_head *head;
313
314 list_for_each(head, &adapter->mac_list) {
315 cur = list_entry(head, struct qlcnic_mac_list_s, list);
316 if (!memcmp(adapter->mac_addr, cur->mac_addr, ETH_ALEN)) {
317 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
318 0, QLCNIC_MAC_DEL);
319 list_del(&cur->list);
320 kfree(cur);
321 return;
322 }
323 }
324}
325
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000326static int qlcnic_set_mac(struct net_device *netdev, void *p)
327{
328 struct qlcnic_adapter *adapter = netdev_priv(netdev);
329 struct sockaddr *addr = p;
330
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000331 if (qlcnic_sriov_vf_check(adapter))
332 return -EINVAL;
333
Rajesh Borundia73733732010-08-31 17:17:50 +0000334 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
335 return -EOPNOTSUPP;
336
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000337 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000338 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000339
Manish Chopracffe52f2013-05-09 09:25:09 +0000340 if (!memcmp(adapter->mac_addr, addr->sa_data, ETH_ALEN))
341 return 0;
342
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000343 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000344 netif_device_detach(netdev);
345 qlcnic_napi_disable(adapter);
346 }
347
Manish Chopracffe52f2013-05-09 09:25:09 +0000348 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000349 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
350 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
351 qlcnic_set_multi(adapter->netdev);
352
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000353 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000354 netif_device_attach(netdev);
355 qlcnic_napi_enable(adapter);
356 }
357 return 0;
358}
359
Vlad Yasevich1690be62013-02-13 12:00:18 +0000360static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
361 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000362{
363 struct qlcnic_adapter *adapter = netdev_priv(netdev);
364 int err = -EOPNOTSUPP;
365
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000366 if (!adapter->fdb_mac_learn)
367 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000368
369 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400370 if (is_unicast_ether_addr(addr)) {
371 err = dev_uc_del(netdev, addr);
372 if (!err)
373 err = qlcnic_nic_del_mac(adapter, addr);
374 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000375 err = dev_mc_del(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400376 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000377 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400378 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000379 }
380 return err;
381}
382
383static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
384 struct net_device *netdev,
385 const unsigned char *addr, u16 flags)
386{
387 struct qlcnic_adapter *adapter = netdev_priv(netdev);
388 int err = 0;
389
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000390 if (!adapter->fdb_mac_learn)
391 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000392
393 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
394 pr_info("%s: FDB e-switch is not enabled\n", __func__);
395 return -EOPNOTSUPP;
396 }
397
398 if (ether_addr_equal(addr, adapter->mac_addr))
399 return err;
400
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400401 if (is_unicast_ether_addr(addr)) {
402 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
403 err = dev_uc_add_excl(netdev, addr);
404 else
405 err = -ENOMEM;
406 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000407 err = dev_mc_add_excl(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400408 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000409 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400410 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000411
412 return err;
413}
414
415static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
416 struct net_device *netdev, int idx)
417{
418 struct qlcnic_adapter *adapter = netdev_priv(netdev);
419
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000420 if (!adapter->fdb_mac_learn)
421 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000422
423 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
424 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
425
426 return idx;
427}
428
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000429static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
430{
431 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
432 usleep_range(10000, 11000);
433
Sucheta Chakraborty66451612013-09-27 02:12:36 -0400434 if (!adapter->fw_work.work.func)
435 return;
436
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000437 cancel_delayed_work_sync(&adapter->fw_work);
438}
439
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400440static int qlcnic_get_phys_port_id(struct net_device *netdev,
441 struct netdev_phys_port_id *ppid)
442{
443 struct qlcnic_adapter *adapter = netdev_priv(netdev);
444 struct qlcnic_hardware_context *ahw = adapter->ahw;
445
446 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID))
447 return -EOPNOTSUPP;
448
449 ppid->id_len = sizeof(ahw->phys_port_id);
450 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len);
451
452 return 0;
453}
454
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000455static const struct net_device_ops qlcnic_netdev_ops = {
456 .ndo_open = qlcnic_open,
457 .ndo_stop = qlcnic_close,
458 .ndo_start_xmit = qlcnic_xmit_frame,
459 .ndo_get_stats = qlcnic_get_stats,
460 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000461 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000462 .ndo_set_mac_address = qlcnic_set_mac,
463 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000464 .ndo_fix_features = qlcnic_fix_features,
465 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000466 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000467 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
468 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000469 .ndo_fdb_add = qlcnic_fdb_add,
470 .ndo_fdb_del = qlcnic_fdb_del,
471 .ndo_fdb_dump = qlcnic_fdb_dump,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400472 .ndo_get_phys_port_id = qlcnic_get_phys_port_id,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000473#ifdef CONFIG_NET_POLL_CONTROLLER
474 .ndo_poll_controller = qlcnic_poll_controller,
475#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000476#ifdef CONFIG_QLCNIC_SRIOV
477 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
478 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate,
479 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000480 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundiaa80be5a2013-05-23 21:04:25 +0000481 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000482#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000483};
484
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000485static const struct net_device_ops qlcnic_netdev_failed_ops = {
486 .ndo_open = qlcnic_open,
487};
488
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000489static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000490 .config_bridged_mode = qlcnic_config_bridged_mode,
491 .config_led = qlcnic_82xx_config_led,
492 .start_firmware = qlcnic_82xx_start_firmware,
493 .request_reset = qlcnic_82xx_dev_request_reset,
494 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
495 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000496 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000497 .config_ipaddr = qlcnic_82xx_config_ipaddr,
Rajesh Borundia486a5bc2013-06-22 04:12:06 -0400498 .shutdown = qlcnic_82xx_shutdown,
499 .resume = qlcnic_82xx_resume,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000500 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000501};
502
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000503struct qlcnic_nic_template qlcnic_vf_ops = {
504 .config_bridged_mode = qlcnicvf_config_bridged_mode,
505 .config_led = qlcnicvf_config_led,
506 .start_firmware = qlcnicvf_start_firmware
507};
508
509static struct qlcnic_hardware_ops qlcnic_hw_ops = {
510 .read_crb = qlcnic_82xx_read_crb,
511 .write_crb = qlcnic_82xx_write_crb,
512 .read_reg = qlcnic_82xx_hw_read_wx_2M,
513 .write_reg = qlcnic_82xx_hw_write_wx_2M,
514 .get_mac_address = qlcnic_82xx_get_mac_address,
515 .setup_intr = qlcnic_82xx_setup_intr,
516 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
517 .mbx_cmd = qlcnic_82xx_issue_cmd,
518 .get_func_no = qlcnic_82xx_get_func_no,
519 .api_lock = qlcnic_82xx_api_lock,
520 .api_unlock = qlcnic_82xx_api_unlock,
521 .add_sysfs = qlcnic_82xx_add_sysfs,
522 .remove_sysfs = qlcnic_82xx_remove_sysfs,
523 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
524 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
525 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000526 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
527 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000528 .setup_link_event = qlcnic_82xx_linkevent_request,
529 .get_nic_info = qlcnic_82xx_get_nic_info,
530 .get_pci_info = qlcnic_82xx_get_pci_info,
531 .set_nic_info = qlcnic_82xx_set_nic_info,
532 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
533 .napi_enable = qlcnic_82xx_napi_enable,
534 .napi_disable = qlcnic_82xx_napi_disable,
535 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
536 .config_rss = qlcnic_82xx_config_rss,
537 .config_hw_lro = qlcnic_82xx_config_hw_lro,
538 .config_loopback = qlcnic_82xx_set_lb_mode,
539 .clear_loopback = qlcnic_82xx_clear_lb_mode,
540 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
541 .change_l2_filter = qlcnic_82xx_change_filter,
542 .get_board_info = qlcnic_82xx_get_board_info,
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400543 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000544 .free_mac_list = qlcnic_82xx_free_mac_list,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400545 .read_phys_port_id = qlcnic_82xx_read_phys_port_id,
Pratik Pujar4460f2e2013-08-30 13:51:20 -0400546 .io_error_detected = qlcnic_82xx_io_error_detected,
547 .io_slot_reset = qlcnic_82xx_io_slot_reset,
548 .io_resume = qlcnic_82xx_io_resume,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000549};
550
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500551static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter *adapter)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400552{
553 struct qlcnic_hardware_context *ahw = adapter->ahw;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400554
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500555 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400556 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500557 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
558 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400559 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500560 return 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400561 }
562}
563
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500564static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt,
565 int queue_type)
566{
567 int num_rings, max_rings = QLCNIC_MAX_SDS_RINGS;
568
569 if (queue_type == QLCNIC_RX_QUEUE)
570 max_rings = adapter->max_sds_rings;
571 else if (queue_type == QLCNIC_TX_QUEUE)
572 max_rings = adapter->max_tx_rings;
573
574 num_rings = rounddown_pow_of_two(min_t(int, num_online_cpus(),
575 max_rings));
576
577 if (ring_cnt > num_rings)
578 return num_rings;
579 else
580 return ring_cnt;
581}
582
583void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt)
584{
585 /* 83xx adapter does not have max_tx_rings intialized in probe */
586 if (adapter->max_tx_rings)
587 adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt,
588 QLCNIC_TX_QUEUE);
589 else
590 adapter->drv_tx_rings = tx_cnt;
591
592 dev_info(&adapter->pdev->dev, "Set %d Tx rings\n",
593 adapter->drv_tx_rings);
594}
595
596void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt)
597{
598 /* 83xx adapter does not have max_sds_rings intialized in probe */
599 if (adapter->max_sds_rings)
600 adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt,
601 QLCNIC_RX_QUEUE);
602 else
603 adapter->drv_sds_rings = rx_cnt;
604
605 dev_info(&adapter->pdev->dev, "Set %d SDS rings\n",
606 adapter->drv_sds_rings);
607}
608
Sony Chacko7f966452013-01-01 03:20:19 +0000609int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000610{
611 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500612 int drv_tx_rings, drv_sds_rings, tx_vector;
Sony Chacko13159182013-01-01 03:20:21 +0000613 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000614
615 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500616 drv_tx_rings = 0;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000617 tx_vector = 0;
618 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500619 drv_tx_rings = adapter->drv_tx_rings;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000620 tx_vector = 1;
621 }
Sony Chacko13159182013-01-01 03:20:21 +0000622
623 if (!adapter->msix_entries) {
624 adapter->msix_entries = kcalloc(num_msix,
625 sizeof(struct msix_entry),
626 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000627 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000628 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000629 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000630
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500631 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000632 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000633
Sony Chacko79788452012-12-04 03:33:53 +0000634 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000635 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000636 for (i = 0; i < num_msix; i++)
637 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000638 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
639 if (err == 0) {
640 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000641 if (qlcnic_83xx_check(adapter)) {
642 adapter->ahw->num_msix = num_msix;
643 /* subtract mail box and tx ring vectors */
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500644 adapter->drv_sds_rings = num_msix -
645 drv_tx_rings - 1;
Sony Chacko13159182013-01-01 03:20:21 +0000646 } else {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400647 adapter->ahw->num_msix = num_msix;
648 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400649 !adapter->ahw->diag_test &&
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500650 (adapter->drv_tx_rings > 1))
651 drv_sds_rings = num_msix - drv_tx_rings;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400652 else
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500653 drv_sds_rings = num_msix;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400654
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500655 adapter->drv_sds_rings = drv_sds_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000656 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000657 dev_info(&pdev->dev, "using msi-x interrupts\n");
658 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000659 } else if (err > 0) {
660 dev_info(&pdev->dev,
661 "Unable to allocate %d MSI-X interrupt vectors\n",
662 num_msix);
663 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000664 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000665 return err;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500666 err -= drv_tx_rings + 1;
Sony Chacko13159182013-01-01 03:20:21 +0000667 num_msix = rounddown_pow_of_two(err);
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500668 num_msix += drv_tx_rings + 1;
Sony Chacko13159182013-01-01 03:20:21 +0000669 } else {
670 num_msix = rounddown_pow_of_two(err);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400671 if (qlcnic_check_multi_tx(adapter))
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500672 num_msix += drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000673 }
674
675 if (num_msix) {
676 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000677 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000678 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000679 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000680 }
681 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000682 dev_info(&pdev->dev,
683 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000684 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000685 }
686 }
Sony Chacko13159182013-01-01 03:20:21 +0000687
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000688 return err;
689}
690
Manish chopra9a97e702013-01-25 10:20:37 +0000691static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000692{
Manish chopra9a97e702013-01-25 10:20:37 +0000693 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000694 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000695 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000696 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000697 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000698
Sony Chacko099f7aa2012-12-04 03:33:58 +0000699 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000700 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000701 offset = msi_tgt_status[adapter->ahw->pci_func];
702 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
703 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000704 dev_info(&pdev->dev, "using msi interrupts\n");
705 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000706 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000707 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400708
Manish chopra9a97e702013-01-25 10:20:37 +0000709 if (qlcnic_use_msi || qlcnic_use_msi_x)
710 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000711
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000712 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000713 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000714 offset = legacy_intrp->tgt_status_reg;
715 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
716 mask_reg = legacy_intrp->tgt_mask_reg;
717 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
718 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
719 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000720 dev_info(&pdev->dev, "using legacy interrupts\n");
721 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000722 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000723}
724
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500725int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000726{
Manish chopra9a97e702013-01-25 10:20:37 +0000727 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000728
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500729 num_msix = adapter->drv_sds_rings;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000730
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500731 if (qlcnic_check_multi_tx(adapter))
732 num_msix += adapter->drv_tx_rings;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000733
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000734 err = qlcnic_enable_msix(adapter, num_msix);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400735 if (err == -ENOMEM)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000736 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000737
Himanshu Madhani012ec812013-08-21 11:24:10 -0400738 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
739 qlcnic_disable_multi_tx(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +0000740
Himanshu Madhani012ec812013-08-21 11:24:10 -0400741 err = qlcnic_enable_msi_legacy(adapter);
742 if (!err)
743 return err;
744 }
745
746 return 0;
747}
748
749int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
750{
751 struct qlcnic_hardware_context *ahw = adapter->ahw;
752 int err, i;
753
754 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400755 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400756 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
757 ahw->intr_tbl = vzalloc(ahw->num_msix *
758 sizeof(struct qlcnic_intrpt_config));
759 if (!ahw->intr_tbl)
760 return -ENOMEM;
761
762 for (i = 0; i < ahw->num_msix; i++) {
763 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
764 ahw->intr_tbl[i].id = i;
765 ahw->intr_tbl[i].src = 0;
766 }
767
768 err = qlcnic_82xx_config_intrpt(adapter, 1);
769 if (err)
770 dev_err(&adapter->pdev->dev,
771 "Failed to configure Interrupt for %d vector\n",
772 ahw->num_msix);
773 return err;
774 }
775
776 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000777}
Sony Chacko13159182013-01-01 03:20:21 +0000778
Sony Chacko319ecf12013-01-01 03:20:22 +0000779void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000780{
781 if (adapter->flags & QLCNIC_MSIX_ENABLED)
782 pci_disable_msix(adapter->pdev);
783 if (adapter->flags & QLCNIC_MSI_ENABLED)
784 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000785
786 kfree(adapter->msix_entries);
787 adapter->msix_entries = NULL;
788
789 if (adapter->ahw->intr_tbl) {
790 vfree(adapter->ahw->intr_tbl);
791 adapter->ahw->intr_tbl = NULL;
792 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000793}
794
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000795static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000796{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000797 if (ahw->pci_base0 != NULL)
798 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000799}
800
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000801static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
802{
803 struct qlcnic_pci_info *pci_info;
804 int ret;
805
806 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
807 switch (adapter->ahw->port_type) {
808 case QLCNIC_GBE:
809 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
810 break;
811 case QLCNIC_XGBE:
812 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
813 break;
814 }
815 return 0;
816 }
817
818 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
819 return 0;
820
821 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
822 if (!pci_info)
823 return -ENOMEM;
824
825 ret = qlcnic_get_pci_info(adapter, pci_info);
826 kfree(pci_info);
827 return ret;
828}
Sony Chackod71170f2013-01-01 03:20:26 +0000829
Sony Chacko35dafcb2013-08-30 13:51:23 -0400830static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
831{
832 bool ret = false;
833
834 if (qlcnic_84xx_check(adapter)) {
835 ret = true;
836 } else if (qlcnic_83xx_check(adapter)) {
837 if (adapter->ahw->extra_capability[0] &
838 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
839 ret = true;
840 else
841 ret = false;
842 }
843
844 return ret;
845}
846
Sony Chackod71170f2013-01-01 03:20:26 +0000847int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000848{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000849 struct qlcnic_pci_info *pci_info;
Sony Chacko4c776aa2013-10-18 12:22:32 -0400850 int i, id = 0, ret = 0, j = 0;
Sony Chackobff57d82012-12-04 03:33:56 +0000851 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000852 u8 pfn;
853
Dan Carpentere88db3b2010-08-09 21:49:36 +0000854 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
855 if (!pci_info)
856 return -ENOMEM;
857
Sony Chackobff57d82012-12-04 03:33:56 +0000858 ret = qlcnic_get_pci_info(adapter, pci_info);
859 if (ret)
860 goto err_pci_info;
861
862 act_pci_func = adapter->ahw->act_pci_func;
863
Dan Carpenterca315ac2010-08-09 21:47:56 +0000864 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000865 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000866 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000867 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000868 goto err_pci_info;
869 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000870
Dan Carpenterca315ac2010-08-09 21:47:56 +0000871 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000872 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
873 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000874 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000875 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000876 }
877
Dan Carpenterca315ac2010-08-09 21:47:56 +0000878 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
879 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000880
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000881 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000882 ret = QL_STATUS_INVALID_PARAM;
883 goto err_eswitch;
884 }
Sony Chackobff57d82012-12-04 03:33:56 +0000885
886 if (!pci_info[i].active ||
887 (pci_info[i].type != QLCNIC_TYPE_NIC))
888 continue;
889
Sony Chacko35dafcb2013-08-30 13:51:23 -0400890 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko4c776aa2013-10-18 12:22:32 -0400891 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn,
892 &id))
Sony Chacko35dafcb2013-08-30 13:51:23 -0400893 adapter->npars[j].eswitch_status = true;
894 else
895 continue;
896 } else {
897 adapter->npars[j].eswitch_status = true;
898 }
899
Sony Chackobff57d82012-12-04 03:33:56 +0000900 adapter->npars[j].pci_func = pfn;
901 adapter->npars[j].active = (u8)pci_info[i].active;
902 adapter->npars[j].type = (u8)pci_info[i].type;
903 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
904 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
905 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -0400906
Sucheta Chakraborty9e630952013-10-18 12:22:28 -0400907 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN);
Sony Chackobff57d82012-12-04 03:33:56 +0000908 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000909 }
910
Sony Chacko4c776aa2013-10-18 12:22:32 -0400911 /* Update eSwitch status for adapters without per port eSwitch
912 * configuration capability
913 */
914 if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko35dafcb2013-08-30 13:51:23 -0400915 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
916 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000917 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000918
Dan Carpentere88db3b2010-08-09 21:49:36 +0000919 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000920 return 0;
921
922err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000923 kfree(adapter->eswitch);
924 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000925err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000926 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000927 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000928err_pci_info:
929 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000930
931 return ret;
932}
933
934static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000935qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
936{
937 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +0000938 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000939 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000940 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000941
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000942 ret = qlcnic_api_lock(adapter);
943 if (ret)
944 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000945
Shahed Shaikh7e8fd002013-05-23 21:04:28 +0000946 id = ahw->pci_func;
947 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
948 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
949 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000950 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000951 qlcnic_api_unlock(adapter);
952err_lock:
953 return ret;
954}
955
Sony Chacko13159182013-01-01 03:20:21 +0000956static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
957 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000958{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000959 u32 op_mode, priv_level;
960
961 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000962 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
963 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000964
965 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000966 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000967
968 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000969 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000970 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000971 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000972 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000973 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000974
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000975 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000976 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000977 dev_info(&adapter->pdev->dev,
978 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000979 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000980 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000981 } else
982 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000983}
984
Sony Chacko15087c22012-12-04 03:33:54 +0000985#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000986#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000987static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000988{
Sony Chacko15087c22012-12-04 03:33:54 +0000989 switch (dev_id) {
990 case PCI_DEVICE_ID_QLOGIC_QLE824X:
991 *bar = QLCNIC_82XX_BAR0_LENGTH;
992 break;
Sony Chacko13159182013-01-01 03:20:21 +0000993 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -0400994 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000995 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -0400996 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +0000997 *bar = QLCNIC_83XX_BAR0_LENGTH;
998 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000999 default:
1000 *bar = 0;
1001 }
1002}
1003
1004static int qlcnic_setup_pci_map(struct pci_dev *pdev,
1005 struct qlcnic_hardware_context *ahw)
1006{
1007 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001008 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +00001009 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001010
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001011 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001012 mem_len = pci_resource_len(pdev, 0);
1013
Sony Chacko15087c22012-12-04 03:33:54 +00001014 qlcnic_get_bar_length(pdev->device, &bar0_len);
1015 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001016
1017 mem_ptr0 = pci_ioremap_bar(pdev, 0);
1018 if (mem_ptr0 == NULL) {
1019 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
1020 return -EIO;
1021 }
1022 pci_len0 = mem_len;
1023 } else {
1024 return -EIO;
1025 }
1026
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001027 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001028
Sony Chacko15087c22012-12-04 03:33:54 +00001029 ahw->pci_base0 = mem_ptr0;
1030 ahw->pci_len0 = pci_len0;
1031 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1032 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001033
1034 return 0;
1035}
1036
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001037static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1038 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001039{
1040 struct pci_dev *pdev = adapter->pdev;
1041 unsigned short subsystem_vendor;
1042 bool ret = true;
1043
1044 subsystem_vendor = pdev->subsystem_vendor;
1045
1046 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1047 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1048 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1049 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1050 ret = true;
1051 else
1052 ret = false;
1053 }
1054
1055 return ret;
1056}
1057
Sony Chacko22999792012-12-04 03:33:55 +00001058static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001059{
1060 struct pci_dev *pdev = adapter->pdev;
1061 int i, found = 0;
1062
1063 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1064 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001065 qlcnic_boards[i].device == pdev->device &&
1066 qlcnic_validate_subsystem_id(adapter, i)) {
1067 found = 1;
1068 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001069 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001070 }
1071
1072 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001073 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001074 else
1075 sprintf(name, "%pM: %s" , adapter->mac_addr,
1076 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001077}
1078
1079static void
1080qlcnic_check_options(struct qlcnic_adapter *adapter)
1081{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001082 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001083 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001084 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001085 struct qlcnic_hardware_context *ahw = adapter->ahw;
1086 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001087
1088 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001089
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001090 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1091 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1092 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001093
1094 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1095
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001096 err = qlcnic_get_board_info(adapter);
1097 if (err) {
1098 dev_err(&pdev->dev, "Error getting board config info.\n");
1099 return;
1100 }
1101 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001102 if (fw_dump->tmpl_hdr == NULL ||
1103 adapter->fw_version > prev_fw_version) {
1104 if (fw_dump->tmpl_hdr)
1105 vfree(fw_dump->tmpl_hdr);
1106 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1107 dev_info(&pdev->dev,
1108 "Supports FW dump capability\n");
1109 }
1110 }
1111
Sony Chacko13159182013-01-01 03:20:21 +00001112 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1113 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1114
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001115 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001116 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1117 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1118 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1119 } else {
1120 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1121 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1122 }
1123
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001124 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001125 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1126
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001127 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001128 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1129 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001130 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1131 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001132 }
1133
Sony Chacko099f7aa2012-12-04 03:33:58 +00001134 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001135
1136 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1137
Sony Chacko251b0362010-08-19 05:08:24 +00001138 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001139}
1140
Rajesh Borundia174240a2010-08-31 17:17:47 +00001141static int
1142qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1143{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001144 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001145 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001146
Sony Chackobff57d82012-12-04 03:33:56 +00001147 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001148 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001149 if (err)
1150 return err;
1151
Sony Chacko79788452012-12-04 03:33:53 +00001152 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1153 adapter->ahw->switch_mode = nic_info.switch_mode;
1154 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1155 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1156 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001157
1158 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1159 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001160 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1161 if (err == -EIO)
1162 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001163 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001164 } else {
1165 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001166 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001167
Sony Chacko79788452012-12-04 03:33:53 +00001168 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1169 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001170
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001171 if (adapter->ahw->capabilities & BIT_6) {
Rajesh Borundia174240a2010-08-31 17:17:47 +00001172 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001173 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE;
1174 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS;
1175 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
1176
1177 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n");
1178 } else {
1179 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
1180 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS;
Himanshu Madhanif9566262013-12-16 15:36:58 -05001181 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001182 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001183 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001184
1185 return err;
1186}
1187
Sony Chackoec079a02012-11-28 04:34:28 +00001188void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1189 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001190{
1191 if (esw_cfg->discard_tagged)
1192 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1193 else
1194 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1195
Rajesh Borundia91b72822013-04-19 07:01:12 +00001196 if (esw_cfg->vlan_id) {
1197 adapter->rx_pvid = esw_cfg->vlan_id;
1198 adapter->tx_pvid = esw_cfg->vlan_id;
1199 } else {
1200 adapter->rx_pvid = 0;
1201 adapter->tx_pvid = 0;
1202 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001203}
1204
Jiri Pirko8e586132011-12-08 19:52:37 -05001205static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001206qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001207{
1208 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001209 int err;
1210
1211 if (qlcnic_sriov_vf_check(adapter)) {
1212 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1213 if (err) {
1214 netdev_err(netdev,
1215 "Cannot add VLAN filter for VLAN id %d, err=%d",
1216 vid, err);
1217 return err;
1218 }
1219 }
1220
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001221 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001222 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001223}
1224
Jiri Pirko8e586132011-12-08 19:52:37 -05001225static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001226qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001227{
1228 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001229 int err;
1230
1231 if (qlcnic_sriov_vf_check(adapter)) {
1232 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1233 if (err) {
1234 netdev_err(netdev,
1235 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1236 vid, err);
1237 return err;
1238 }
1239 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001240
1241 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1242 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001243 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001244}
1245
Sony Chackoec079a02012-11-28 04:34:28 +00001246void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1247 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001248{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001249 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1250 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001251
1252 if (esw_cfg->mac_anti_spoof)
1253 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001254
Rajesh Borundia73733732010-08-31 17:17:50 +00001255 if (!esw_cfg->mac_override)
1256 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1257
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001258 if (!esw_cfg->promisc_mode)
1259 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001260}
1261
Sony Chackod71170f2013-01-01 03:20:26 +00001262int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001263{
1264 struct qlcnic_esw_func_cfg esw_cfg;
1265
1266 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1267 return 0;
1268
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001269 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001270 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1271 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001272 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001273 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001274 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001275
1276 return 0;
1277}
1278
Shahed Shaikh147a9082013-05-21 09:27:01 +00001279void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1280 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001281{
1282 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001283
Sony Chacko13159182013-01-01 03:20:21 +00001284 if (qlcnic_83xx_check(adapter))
1285 return;
1286
Shahed Shaikh147a9082013-05-21 09:27:01 +00001287 adapter->offload_flags = esw_cfg->offload_flags;
1288 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1289 netdev_update_features(netdev);
1290 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001291}
1292
1293static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001294qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1295{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001296 u32 op_mode, priv_level;
1297 int err = 0;
1298
Rajesh Borundia174240a2010-08-31 17:17:47 +00001299 err = qlcnic_initialize_nic(adapter);
1300 if (err)
1301 return err;
1302
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001303 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1304 return 0;
1305
Sony Chacko13159182013-01-01 03:20:21 +00001306 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001307 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001308
1309 if (op_mode == QLC_DEV_DRV_DEFAULT)
1310 priv_level = QLCNIC_MGMT_FUNC;
1311 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001312 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001313
Rajesh Borundia174240a2010-08-31 17:17:47 +00001314 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001315 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001316 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001317 err = qlcnic_init_pci_info(adapter);
1318 if (err)
1319 return err;
1320 /* Set privilege level for other functions */
1321 qlcnic_set_function_modes(adapter);
1322 dev_info(&adapter->pdev->dev,
1323 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001324 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001325 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001326 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001327 dev_info(&adapter->pdev->dev,
1328 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001329 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001330 }
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001331 } else {
1332 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001333 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001334
1335 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1336
1337 return err;
1338}
1339
Sony Chackod71170f2013-01-01 03:20:26 +00001340int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001341{
1342 struct qlcnic_esw_func_cfg esw_cfg;
1343 struct qlcnic_npar_info *npar;
1344 u8 i;
1345
Rajesh Borundia174240a2010-08-31 17:17:47 +00001346 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001347 return 0;
1348
Sony Chackobff57d82012-12-04 03:33:56 +00001349 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001350 if (!adapter->npars[i].eswitch_status)
1351 continue;
1352
Rajesh Borundia0325d692010-08-19 05:08:26 +00001353 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001354 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001355 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001356 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001357 if (qlcnic_82xx_check(adapter)) {
1358 esw_cfg.offload_flags = BIT_0;
1359 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1360 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1361 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001362 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1363 return -EIO;
1364 npar = &adapter->npars[i];
1365 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001366 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001367 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1368 npar->discard_tagged = esw_cfg.discard_tagged;
1369 npar->promisc_mode = esw_cfg.promisc_mode;
1370 npar->offload_flags = esw_cfg.offload_flags;
1371 }
1372
1373 return 0;
1374}
1375
Sony Chacko13159182013-01-01 03:20:21 +00001376
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001377static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001378qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1379 struct qlcnic_npar_info *npar, int pci_func)
1380{
1381 struct qlcnic_esw_func_cfg esw_cfg;
1382 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1383 esw_cfg.pci_func = pci_func;
1384 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001385 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001386 esw_cfg.discard_tagged = npar->discard_tagged;
1387 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1388 esw_cfg.offload_flags = npar->offload_flags;
1389 esw_cfg.promisc_mode = npar->promisc_mode;
1390 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1391 return -EIO;
1392
1393 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1394 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1395 return -EIO;
1396
1397 return 0;
1398}
1399
Sony Chackod71170f2013-01-01 03:20:26 +00001400int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001401{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001402 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001403 struct qlcnic_npar_info *npar;
1404 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001405 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001406
Sony Chackobff57d82012-12-04 03:33:56 +00001407 if (qlcnic_82xx_check(adapter))
1408 if (!adapter->need_fw_reset)
1409 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001410
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001411 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001412 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001413 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001414 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001415 if (!adapter->npars[i].eswitch_status)
1416 continue;
1417
Sony Chackobff57d82012-12-04 03:33:56 +00001418 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001419 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001420 if (err)
1421 return err;
1422 nic_info.min_tx_bw = npar->min_bw;
1423 nic_info.max_tx_bw = npar->max_bw;
1424 err = qlcnic_set_nic_info(adapter, &nic_info);
1425 if (err)
1426 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001427
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001428 if (npar->enable_pm) {
1429 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001430 npar->dest_npar, 1,
1431 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001432 if (err)
1433 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001434 }
Sony Chackobff57d82012-12-04 03:33:56 +00001435 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001436 if (err)
1437 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001438 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001439 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001440}
1441
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001442static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1443{
1444 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1445 u32 npar_state;
1446
Sony Chacko79788452012-12-04 03:33:53 +00001447 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001448 return 0;
1449
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001450 npar_state = QLC_SHARED_REG_RD32(adapter,
1451 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001452 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1453 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001454 npar_state = QLC_SHARED_REG_RD32(adapter,
1455 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001456 }
1457 if (!npar_opt_timeo) {
1458 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001459 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001460 return -EIO;
1461 }
1462 return 0;
1463}
1464
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001465static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001466qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1467{
1468 int err;
1469
1470 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001471 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001472 return 0;
1473
1474 err = qlcnic_set_default_offload_settings(adapter);
1475 if (err)
1476 return err;
1477
1478 err = qlcnic_reset_npar_config(adapter);
1479 if (err)
1480 return err;
1481
1482 qlcnic_dev_set_npar_ready(adapter);
1483
1484 return err;
1485}
1486
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001487int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001488{
Sony Chackod4066832010-08-19 05:08:31 +00001489 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001490
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001491 err = qlcnic_can_start_firmware(adapter);
1492 if (err < 0)
1493 return err;
1494 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001495 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001496
Sony Chacko099f7aa2012-12-04 03:33:58 +00001497 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001498 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001499 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001500 err = qlcnic_check_flash_fw_ver(adapter);
1501 if (err)
schacko8f891382010-06-17 02:56:40 +00001502 goto err_out;
1503
Sony Chacko79788452012-12-04 03:33:53 +00001504 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001505 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001506
1507 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001508 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001509 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001510
Sony Chackod4066832010-08-19 05:08:31 +00001511 err = qlcnic_pinit_from_rom(adapter);
1512 if (err)
1513 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001514
1515 err = qlcnic_load_firmware(adapter);
1516 if (err)
1517 goto err_out;
1518
1519 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001520 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001521
Sony Chackod4066832010-08-19 05:08:31 +00001522check_fw_status:
1523 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001524 if (err)
1525 goto err_out;
1526
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001527 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001528 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001529 err = qlcnic_check_eswitch_mode(adapter);
1530 if (err) {
1531 dev_err(&adapter->pdev->dev,
1532 "Memory allocation failed for eswitch\n");
1533 goto err_out;
1534 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001535 err = qlcnic_set_mgmt_operations(adapter);
1536 if (err)
1537 goto err_out;
1538
1539 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001540 adapter->need_fw_reset = 0;
1541
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001542 qlcnic_release_firmware(adapter);
1543 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001544
1545err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001546 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001547 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001548
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001549 qlcnic_release_firmware(adapter);
1550 return err;
1551}
1552
1553static int
1554qlcnic_request_irq(struct qlcnic_adapter *adapter)
1555{
1556 irq_handler_t handler;
1557 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001558 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001559 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001560
1561 unsigned long flags = 0;
1562 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001563 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001564
Sony Chacko79788452012-12-04 03:33:53 +00001565 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001566 if (qlcnic_82xx_check(adapter))
1567 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001568 else
1569 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001570 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1571 flags |= IRQF_SHARED;
1572
1573 } else {
1574 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1575 handler = qlcnic_msix_intr;
1576 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1577 handler = qlcnic_msi_intr;
1578 else {
1579 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001580 if (qlcnic_82xx_check(adapter))
1581 handler = qlcnic_intr;
1582 else
1583 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001584 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001585 }
1586 adapter->irq = netdev->irq;
1587
Sony Chacko13159182013-01-01 03:20:21 +00001588 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001589 if (qlcnic_82xx_check(adapter) ||
1590 (qlcnic_83xx_check(adapter) &&
1591 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001592 num_sds_rings = adapter->drv_sds_rings;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001593 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001594 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001595 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001596 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001597 (ring == (num_sds_rings - 1))) {
1598 if (!(adapter->flags &
1599 QLCNIC_MSIX_ENABLED))
1600 snprintf(sds_ring->name,
1601 sizeof(sds_ring->name),
1602 "qlcnic");
1603 else
1604 snprintf(sds_ring->name,
1605 sizeof(sds_ring->name),
1606 "%s-tx-0-rx-%d",
1607 netdev->name, ring);
1608 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001609 snprintf(sds_ring->name,
1610 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001611 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001612 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001613 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001614 err = request_irq(sds_ring->irq, handler, flags,
1615 sds_ring->name, sds_ring);
1616 if (err)
1617 return err;
1618 }
Sony Chacko13159182013-01-01 03:20:21 +00001619 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001620 if ((qlcnic_82xx_check(adapter) &&
1621 qlcnic_check_multi_tx(adapter)) ||
1622 (qlcnic_83xx_check(adapter) &&
1623 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1624 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001625 handler = qlcnic_msix_tx_intr;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001626 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001627 ring++) {
1628 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001629 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001630 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001631 err = request_irq(tx_ring->irq, handler, flags,
1632 tx_ring->name, tx_ring);
1633 if (err)
1634 return err;
1635 }
1636 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001637 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001638 return 0;
1639}
1640
1641static void
1642qlcnic_free_irq(struct qlcnic_adapter *adapter)
1643{
1644 int ring;
1645 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001646 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001647
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001648 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001649
Sony Chacko13159182013-01-01 03:20:21 +00001650 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001651 if (qlcnic_82xx_check(adapter) ||
1652 (qlcnic_83xx_check(adapter) &&
1653 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001654 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001655 sds_ring = &recv_ctx->sds_rings[ring];
1656 free_irq(sds_ring->irq, sds_ring);
1657 }
Sony Chacko13159182013-01-01 03:20:21 +00001658 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001659 if ((qlcnic_83xx_check(adapter) &&
1660 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1661 (qlcnic_82xx_check(adapter) &&
1662 qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001663 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001664 ring++) {
1665 tx_ring = &adapter->tx_ring[ring];
1666 if (tx_ring->irq)
1667 free_irq(tx_ring->irq, tx_ring);
1668 }
1669 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001670 }
1671}
1672
Shahed Shaikh99e85872013-02-18 12:06:16 +00001673static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1674{
1675 u32 capab = 0;
1676
1677 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001678 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001679 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1680 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1681 } else {
1682 capab = adapter->ahw->capabilities;
1683 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1684 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1685 }
1686}
1687
Sony Chacko319ecf12013-01-01 03:20:22 +00001688int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001689{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001690 int ring;
1691 struct qlcnic_host_rds_ring *rds_ring;
1692
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001693 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1694 return -EIO;
1695
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001696 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1697 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001698
Rajesh Borundia0325d692010-08-19 05:08:26 +00001699 if (qlcnic_set_eswitch_port_config(adapter))
1700 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001701
Shahed Shaikh99e85872013-02-18 12:06:16 +00001702 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001703
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001704 if (qlcnic_fw_create_ctx(adapter))
1705 return -EIO;
1706
1707 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001708 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001709 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001710 }
1711
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001712 qlcnic_set_multi(netdev);
1713 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1714
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001715 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001716
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001717 if (adapter->drv_sds_rings > 1)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001718 qlcnic_config_rss(adapter, 1);
1719
1720 qlcnic_config_intr_coalesce(adapter);
1721
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001722 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001723 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1724
Pratik Pujarcfacb172013-07-19 16:56:27 -04001725 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001726 qlcnic_napi_enable(adapter);
1727
1728 qlcnic_linkevent_request(adapter, 1);
1729
Sony Chacko79788452012-12-04 03:33:53 +00001730 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001731 return 0;
1732}
1733
Sony Chacko629263a2013-01-01 04:11:55 +00001734int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001735{
1736 int err = 0;
1737
1738 rtnl_lock();
1739 if (netif_running(netdev))
1740 err = __qlcnic_up(adapter, netdev);
1741 rtnl_unlock();
1742
1743 return err;
1744}
1745
Sony Chacko319ecf12013-01-01 03:20:22 +00001746void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001747{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001748 int ring;
1749
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001750 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1751 return;
1752
1753 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1754 return;
1755
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001756 if (qlcnic_sriov_vf_check(adapter))
1757 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001758 smp_mb();
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001759 spin_lock(&adapter->tx_clean_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001760 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001761 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001762 netif_tx_disable(netdev);
1763
1764 qlcnic_free_mac_list(adapter);
1765
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001766 if (adapter->fhash.fnum)
1767 qlcnic_delete_lb_filters(adapter);
1768
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001769 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1770
1771 qlcnic_napi_disable(adapter);
1772
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001773 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001774 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001775
1776 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001777
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001778 for (ring = 0; ring < adapter->drv_tx_rings; ring++)
Himanshu Madhani012ec812013-08-21 11:24:10 -04001779 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001780 spin_unlock(&adapter->tx_clean_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001781}
1782
1783/* Usage: During suspend and firmware recovery module */
1784
Sony Chacko629263a2013-01-01 04:11:55 +00001785void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001786{
1787 rtnl_lock();
1788 if (netif_running(netdev))
1789 __qlcnic_down(adapter, netdev);
1790 rtnl_unlock();
1791
1792}
1793
Sony Chacko319ecf12013-01-01 03:20:22 +00001794int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001795qlcnic_attach(struct qlcnic_adapter *adapter)
1796{
1797 struct net_device *netdev = adapter->netdev;
1798 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001799 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001800
1801 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1802 return 0;
1803
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001804 err = qlcnic_napi_add(adapter, netdev);
1805 if (err)
1806 return err;
1807
1808 err = qlcnic_alloc_sw_resources(adapter);
1809 if (err) {
1810 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001811 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001812 }
1813
1814 err = qlcnic_alloc_hw_resources(adapter);
1815 if (err) {
1816 dev_err(&pdev->dev, "Error in setting hw resources\n");
1817 goto err_out_free_sw;
1818 }
1819
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001820 err = qlcnic_request_irq(adapter);
1821 if (err) {
1822 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001823 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001824 }
1825
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001826 qlcnic_create_sysfs_entries(adapter);
1827
1828 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1829 return 0;
1830
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001831err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001832 qlcnic_free_hw_resources(adapter);
1833err_out_free_sw:
1834 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001835err_out_napi_del:
1836 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001837 return err;
1838}
1839
Sony Chacko319ecf12013-01-01 03:20:22 +00001840void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001841{
1842 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1843 return;
1844
1845 qlcnic_remove_sysfs_entries(adapter);
1846
1847 qlcnic_free_hw_resources(adapter);
1848 qlcnic_release_rx_buffers(adapter);
1849 qlcnic_free_irq(adapter);
1850 qlcnic_napi_del(adapter);
1851 qlcnic_free_sw_resources(adapter);
1852
1853 adapter->is_up = 0;
1854}
1855
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001856void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings)
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001857{
1858 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1859 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001860 int drv_tx_rings = adapter->drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001861 int ring;
1862
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001863 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001864 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001865 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001866 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001867 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001868 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001869 }
1870
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001871 qlcnic_fw_destroy_ctx(adapter);
1872
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001873 qlcnic_detach(adapter);
1874
Sony Chacko79788452012-12-04 03:33:53 +00001875 adapter->ahw->diag_test = 0;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001876 adapter->drv_sds_rings = drv_sds_rings;
1877 adapter->drv_tx_rings = drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001878
1879 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001880 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001881
1882 if (netif_running(netdev))
1883 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001884out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001885 netif_device_attach(netdev);
1886}
1887
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001888static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1889{
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001890 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001891 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001892
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001893 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1894 GFP_KERNEL);
1895 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001896 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001897 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001898 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001899 /* Initialize interrupt coalesce parameters */
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001900 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1901 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1902 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1903 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1904 if (qlcnic_83xx_check(adapter)) {
1905 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1906 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1907 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001908 /* clear stats */
1909 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001910err_out:
1911 return err;
1912}
1913
1914static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1915{
1916 kfree(adapter->recv_ctx);
1917 adapter->recv_ctx = NULL;
1918
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001919 if (adapter->ahw->fw_dump.tmpl_hdr) {
1920 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1921 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1922 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001923
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001924 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001925 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001926}
1927
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001928int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1929{
1930 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1931 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001932 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001933 int ring;
1934 int ret;
1935
1936 netif_device_detach(netdev);
1937
1938 if (netif_running(netdev))
1939 __qlcnic_down(adapter, netdev);
1940
1941 qlcnic_detach(adapter);
1942
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001943 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sony Chacko79788452012-12-04 03:33:53 +00001944 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001945 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001946
1947 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001948 if (ret) {
1949 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001950 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001951 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001952
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001953 ret = qlcnic_fw_create_ctx(adapter);
1954 if (ret) {
1955 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001956 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001957 return ret;
1958 }
1959
1960 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001961 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001962 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001963 }
1964
Sony Chacko79788452012-12-04 03:33:53 +00001965 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001966 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001967 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001968 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001969 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001970 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001971
Sony Chacko79788452012-12-04 03:33:53 +00001972 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001973 adapter->ahw->loopback_state = 0;
1974 qlcnic_linkevent_request(adapter, 1);
1975 }
1976
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001977 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001978
1979 return 0;
1980}
1981
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001982/* Reset context in hardware only */
1983static int
1984qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1985{
1986 struct net_device *netdev = adapter->netdev;
1987
1988 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1989 return -EBUSY;
1990
1991 netif_device_detach(netdev);
1992
1993 qlcnic_down(adapter, netdev);
1994
1995 qlcnic_up(adapter, netdev);
1996
1997 netif_device_attach(netdev);
1998
1999 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00002000 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002001 return 0;
2002}
2003
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002004int
2005qlcnic_reset_context(struct qlcnic_adapter *adapter)
2006{
2007 int err = 0;
2008 struct net_device *netdev = adapter->netdev;
2009
2010 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2011 return -EBUSY;
2012
2013 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
2014
2015 netif_device_detach(netdev);
2016
2017 if (netif_running(netdev))
2018 __qlcnic_down(adapter, netdev);
2019
2020 qlcnic_detach(adapter);
2021
2022 if (netif_running(netdev)) {
2023 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002024 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002025 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002026 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2027 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002028 }
2029
2030 netif_device_attach(netdev);
2031 }
2032
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002033 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2034 return err;
2035}
2036
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002037void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
2038{
2039 struct qlcnic_hardware_context *ahw = adapter->ahw;
2040 u16 act_pci_fn = ahw->act_pci_func;
2041 u16 count;
2042
2043 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2044 if (act_pci_fn <= 2)
2045 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2046 act_pci_fn;
2047 else
2048 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2049 act_pci_fn;
2050 ahw->max_uc_count = count;
2051}
2052
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002053int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002054qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2055 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002056{
2057 int err;
2058 struct pci_dev *pdev = adapter->pdev;
2059
Sony Chacko13159182013-01-01 03:20:21 +00002060 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002061 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002062 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002063
2064 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002065 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002066
2067 qlcnic_change_mtu(netdev, netdev->mtu);
2068
Rajesh Borundiad1a11052013-04-19 07:01:13 +00002069 if (qlcnic_sriov_vf_check(adapter))
2070 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops);
2071 else
2072 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002073
Sony Chacko7e38d042013-01-01 03:20:28 +00002074 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002075 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002076 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002077 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2078 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002079
Sony Chacko13159182013-01-01 03:20:21 +00002080 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2081 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2082 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2083 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002084
Sony Chacko13159182013-01-01 03:20:21 +00002085 if (pci_using_dac) {
2086 netdev->features |= NETIF_F_HIGHDMA;
2087 netdev->vlan_features |= NETIF_F_HIGHDMA;
2088 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002089
Sony Chacko13159182013-01-01 03:20:21 +00002090 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002091 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002092
Rajesh Borundia91b72822013-04-19 07:01:12 +00002093 if (qlcnic_sriov_vf_check(adapter))
2094 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2095
Sony Chacko79788452012-12-04 03:33:53 +00002096 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002097 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002098
Sony Chacko7e38d042013-01-01 03:20:28 +00002099 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002100 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002101 netdev->irq = adapter->msix_entries[0].vector;
2102
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002103 err = qlcnic_set_real_num_queues(adapter, netdev);
2104 if (err)
2105 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002106
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002107 err = register_netdev(netdev);
2108 if (err) {
2109 dev_err(&pdev->dev, "failed to register net device\n");
2110 return err;
2111 }
2112
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002113 qlcnic_dcb_init_dcbnl_ops(adapter->dcb);
Sucheta Chakraborty48365e42013-08-23 13:38:28 -04002114
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002115 return 0;
2116}
2117
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002118static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002119{
2120 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2121 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2122 *pci_using_dac = 1;
2123 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2124 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2125 *pci_using_dac = 0;
2126 else {
2127 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2128 return -EIO;
2129 }
2130
2131 return 0;
2132}
2133
Sony Chacko4be41e92013-01-01 03:20:20 +00002134void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2135{
2136 int ring;
2137 struct qlcnic_host_tx_ring *tx_ring;
2138
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002139 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002140 tx_ring = &adapter->tx_ring[ring];
2141 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
2142 vfree(tx_ring->cmd_buf_arr);
2143 tx_ring->cmd_buf_arr = NULL;
2144 }
2145 }
2146 if (adapter->tx_ring != NULL)
2147 kfree(adapter->tx_ring);
2148}
2149
2150int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2151 struct net_device *netdev)
2152{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002153 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002154 struct qlcnic_host_tx_ring *tx_ring;
2155 struct qlcnic_cmd_buffer *cmd_buf_arr;
2156
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002157 tx_ring = kcalloc(adapter->drv_tx_rings,
Joe Perchesb2adaca2013-02-03 17:43:58 +00002158 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2159 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002160 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002161
Sony Chacko4be41e92013-01-01 03:20:20 +00002162 adapter->tx_ring = tx_ring;
2163
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002164 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002165 tx_ring = &adapter->tx_ring[ring];
2166 tx_ring->num_desc = adapter->num_txd;
2167 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2168 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2169 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002170 qlcnic_free_tx_rings(adapter);
2171 return -ENOMEM;
2172 }
2173 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
2174 tx_ring->cmd_buf_arr = cmd_buf_arr;
2175 }
2176
Himanshu Madhani012ec812013-08-21 11:24:10 -04002177 if (qlcnic_83xx_check(adapter) ||
2178 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002179 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002180 tx_ring = &adapter->tx_ring[ring];
2181 tx_ring->adapter = adapter;
2182 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002183 index = adapter->drv_sds_rings + ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002184 vector = adapter->msix_entries[index].vector;
2185 tx_ring->irq = vector;
2186 }
2187 }
2188 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002189
Sony Chacko4be41e92013-01-01 03:20:20 +00002190 return 0;
2191}
2192
Pratik Pujar8af3f332013-06-22 04:12:05 -04002193void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2194{
2195 struct qlcnic_hardware_context *ahw = adapter->ahw;
2196 u32 fw_cmd = 0;
2197
2198 if (qlcnic_82xx_check(adapter))
2199 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2200 else if (qlcnic_83xx_check(adapter))
2201 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2202
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002203 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002204 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2205}
2206
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002207static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002208qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2209{
2210 struct net_device *netdev = NULL;
2211 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002212 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002213 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002214 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002215 struct qlcnic_dcb *dcb;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002216
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002217 if (pdev->is_virtfn)
2218 return -ENODEV;
2219
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002220 err = pci_enable_device(pdev);
2221 if (err)
2222 return err;
2223
2224 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2225 err = -ENODEV;
2226 goto err_out_disable_pdev;
2227 }
2228
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002229 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2230 if (err)
2231 goto err_out_disable_pdev;
2232
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002233 err = pci_request_regions(pdev, qlcnic_driver_name);
2234 if (err)
2235 goto err_out_disable_pdev;
2236
2237 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002238 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002239
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002240 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002241 if (!ahw) {
2242 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002243 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002244 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002245
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002246 switch (ent->device) {
2247 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002248 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002249 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2250 break;
2251 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002252 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002253 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002254 break;
2255 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002256 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002257 qlcnic_sriov_vf_register_map(ahw);
2258 break;
2259 default:
Sony Chacko13159182013-01-01 03:20:21 +00002260 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002261 }
2262
2263 err = qlcnic_setup_pci_map(pdev, ahw);
2264 if (err)
2265 goto err_out_free_hw_res;
2266
Himanshu Madhani012ec812013-08-21 11:24:10 -04002267 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2268 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002269 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002270 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002271 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002272 }
2273
2274 SET_NETDEV_DEV(netdev, &pdev->dev);
2275
2276 adapter = netdev_priv(netdev);
2277 adapter->netdev = netdev;
2278 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002279 adapter->ahw = ahw;
2280
2281 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2282 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002283 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002284 dev_err(&pdev->dev, "Failed to create workqueue\n");
2285 goto err_out_free_netdev;
2286 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002287
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002288 err = qlcnic_alloc_adapter_resources(adapter);
2289 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002290 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002291
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002292 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002293 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002294 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2295 adapter->fdb_mac_learn = true;
2296 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2297 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002298
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002299 rwlock_init(&adapter->ahw->crb_lock);
2300 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002301
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002302 spin_lock_init(&adapter->tx_clean_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002303 INIT_LIST_HEAD(&adapter->mac_list);
2304
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002305 qlcnic_register_dcb(adapter);
2306
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002307 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002308 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002309 adapter->portnum = adapter->ahw->pci_func;
2310 err = qlcnic_start_firmware(adapter);
2311 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002312 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2313 "\t\tIf reboot doesn't help, try flashing the card\n");
2314 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002315 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002316
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002317 /* compute and set default and max tx/sds rings */
2318 if (adapter->ahw->msix_supported) {
2319 if (qlcnic_check_multi_tx_capability(adapter) == 1)
2320 qlcnic_set_tx_ring_count(adapter,
2321 QLCNIC_SINGLE_RING);
2322 else
2323 qlcnic_set_tx_ring_count(adapter,
2324 QLCNIC_DEF_TX_RINGS);
2325 qlcnic_set_sds_ring_count(adapter,
2326 QLCNIC_DEF_SDS_RINGS);
2327 } else {
2328 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING);
2329 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002330 }
2331
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002332 err = qlcnic_setup_idc_param(adapter);
2333 if (err)
2334 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002335
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002336 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002337
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002338 dcb = adapter->dcb;
2339
2340 if (dcb && qlcnic_dcb_attach(dcb))
2341 qlcnic_clear_dcb_ops(dcb);
Sony Chacko13159182013-01-01 03:20:21 +00002342 } else if (qlcnic_83xx_check(adapter)) {
2343 qlcnic_83xx_check_vf(adapter, ent);
2344 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002345 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002346 if (err) {
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002347 switch (err) {
2348 case -ENOTRECOVERABLE:
2349 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware. Please reboot\n");
2350 dev_err(&pdev->dev, "If reboot doesn't help, please replace the adapter with new one and return the faulty adapter for repair\n");
2351 goto err_out_free_hw;
2352 case -ENOMEM:
2353 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n");
2354 goto err_out_free_hw;
2355 default:
2356 dev_err(&pdev->dev, "Adapter initialization failed. A reboot may be required to recover from this failure\n");
2357 dev_err(&pdev->dev, "If reboot does not help to recover from this failure, try a flash update of the adapter\n");
2358 goto err_out_maintenance_mode;
2359 }
Sony Chacko629263a2013-01-01 04:11:55 +00002360 }
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002361
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002362 if (qlcnic_sriov_vf_check(adapter))
2363 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002364 } else {
2365 dev_err(&pdev->dev,
2366 "%s: failed. Please Reboot\n", __func__);
2367 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002368 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002369
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002370 if (qlcnic_read_mac_addr(adapter))
2371 dev_warn(&pdev->dev, "failed to read mac addr\n");
2372
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002373 qlcnic_read_phys_port_id(adapter);
2374
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002375 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002376 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002377
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002378 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002379 module_name(THIS_MODULE),
2380 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002381 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002382
2383 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2384 !!qlcnic_use_msi)
2385 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002386 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002387
Manish Chopra068a8d12013-08-02 00:57:41 -04002388 if (qlcnic_82xx_check(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002389 err = qlcnic_setup_intr(adapter);
Manish Chopra068a8d12013-08-02 00:57:41 -04002390 if (err) {
2391 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002392 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002393 }
Sony Chacko13159182013-01-01 03:20:21 +00002394 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002395
Sony Chacko02135582013-05-21 09:26:59 +00002396 err = qlcnic_get_act_pci_func(adapter);
2397 if (err)
2398 goto err_out_disable_mbx_intr;
2399
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002400 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002401 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002402 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002403
Himanshu Madhani24866d12013-08-15 08:29:27 -04002404 if (adapter->portnum == 0)
2405 qlcnic_set_drv_version(adapter);
Sritej Velagac84e3402013-01-25 10:20:34 +00002406
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002407 pci_set_drvdata(pdev, adapter);
2408
Sony Chacko97ee45e2012-12-04 03:33:52 +00002409 if (qlcnic_82xx_check(adapter))
2410 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2411 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002412
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002413 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002414 case QLCNIC_GBE:
2415 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2416 adapter->netdev->name);
2417 break;
2418 case QLCNIC_XGBE:
2419 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2420 adapter->netdev->name);
2421 break;
2422 }
2423
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002424 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002425 qlcnic_alloc_lb_filters_mem(adapter);
2426
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002427 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002428
2429 return 0;
2430
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002431err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002432 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002433 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002434
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002435err_out_disable_msi:
2436 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002437 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002438 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002439
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002440err_out_free_hw:
2441 qlcnic_free_adapter_resources(adapter);
2442
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002443err_out_free_wq:
2444 destroy_workqueue(adapter->qlcnic_wq);
2445
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002446err_out_free_netdev:
2447 free_netdev(netdev);
2448
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002449err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002450 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002451
2452err_out_free_hw_res:
2453 kfree(ahw);
2454
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002455err_out_free_res:
2456 pci_release_regions(pdev);
2457
2458err_out_disable_pdev:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002459 pci_disable_device(pdev);
2460 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002461
2462err_out_maintenance_mode:
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002463 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002464 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
2465 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002466 ahw->port_type = QLCNIC_XGBE;
2467
2468 if (qlcnic_83xx_check(adapter))
2469 adapter->tgt_status_reg = NULL;
2470 else
2471 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS;
2472
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002473 err = register_netdev(netdev);
2474
2475 if (err) {
2476 dev_err(&pdev->dev, "Failed to register net device\n");
2477 qlcnic_clr_all_drv_state(adapter, 0);
2478 goto err_out_free_hw;
2479 }
2480
2481 pci_set_drvdata(pdev, adapter);
2482 qlcnic_add_sysfs(adapter);
2483
2484 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002485}
2486
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002487static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002488{
2489 struct qlcnic_adapter *adapter;
2490 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002491 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002492
2493 adapter = pci_get_drvdata(pdev);
2494 if (adapter == NULL)
2495 return;
2496
2497 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002498 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002499
Sony Chacko13159182013-01-01 03:20:21 +00002500 qlcnic_cancel_idc_work(adapter);
2501 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002502
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002503 qlcnic_dcb_free(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002504
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002505 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002506 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002507
Sony Chacko13159182013-01-01 03:20:21 +00002508 if (qlcnic_83xx_check(adapter)) {
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002509 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2510 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002511 qlcnic_83xx_free_mbx_intr(adapter);
2512 qlcnic_83xx_detach_mailbox_work(adapter);
2513 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002514 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002515 }
2516
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002517 qlcnic_detach(adapter);
2518
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002519 if (adapter->npars != NULL)
2520 kfree(adapter->npars);
2521 if (adapter->eswitch != NULL)
2522 kfree(adapter->eswitch);
2523
Sony Chacko97ee45e2012-12-04 03:33:52 +00002524 if (qlcnic_82xx_check(adapter))
2525 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526
2527 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2528
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002529 qlcnic_free_lb_filters_mem(adapter);
2530
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002531 qlcnic_teardown_intr(adapter);
2532
Sony Chacko13159182013-01-01 03:20:21 +00002533 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002534
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002535 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002536
2537 qlcnic_release_firmware(adapter);
2538
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002539 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002540 pci_release_regions(pdev);
2541 pci_disable_device(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002542
Sony Chacko13159182013-01-01 03:20:21 +00002543 if (adapter->qlcnic_wq) {
2544 destroy_workqueue(adapter->qlcnic_wq);
2545 adapter->qlcnic_wq = NULL;
2546 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002547
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002548 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002549 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002550 free_netdev(netdev);
2551}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002552
2553static void qlcnic_shutdown(struct pci_dev *pdev)
2554{
2555 if (__qlcnic_shutdown(pdev))
2556 return;
2557
2558 pci_disable_device(pdev);
2559}
2560
2561#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002562static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002563{
2564 int retval;
2565
2566 retval = __qlcnic_shutdown(pdev);
2567 if (retval)
2568 return retval;
2569
2570 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2571 return 0;
2572}
2573
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002574static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002575{
2576 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002577 int err;
2578
2579 err = pci_enable_device(pdev);
2580 if (err)
2581 return err;
2582
2583 pci_set_power_state(pdev, PCI_D0);
2584 pci_set_master(pdev);
2585 pci_restore_state(pdev);
2586
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002587 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002588}
2589#endif
2590
2591static int qlcnic_open(struct net_device *netdev)
2592{
2593 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2594 int err;
2595
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002596 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
2597 netdev_err(netdev, "%s: Device is in non-operational state\n",
2598 __func__);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002599
2600 return -EIO;
2601 }
2602
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002603 netif_carrier_off(netdev);
2604
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002605 err = qlcnic_attach(adapter);
2606 if (err)
2607 return err;
2608
2609 err = __qlcnic_up(adapter, netdev);
2610 if (err)
2611 goto err_out;
2612
Himanshu Madhani012ec812013-08-21 11:24:10 -04002613 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002614
2615 return 0;
2616
2617err_out:
2618 qlcnic_detach(adapter);
2619 return err;
2620}
2621
2622/*
2623 * qlcnic_close - Disables a network interface entry point
2624 */
2625static int qlcnic_close(struct net_device *netdev)
2626{
2627 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2628
2629 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002630
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002631 return 0;
2632}
2633
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002634void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002635{
2636 void *head;
2637 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002638 struct net_device *netdev = adapter->netdev;
2639 u32 filter_size = 0;
2640 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002641
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002642 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002643 return;
2644
Sony Chacko13159182013-01-01 03:20:21 +00002645 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002646 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002647 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002648
Sony Chacko13159182013-01-01 03:20:21 +00002649 if (qlcnic_82xx_check(adapter)) {
2650 filter_size = QLCNIC_LB_MAX_FILTERS;
2651 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2652 } else {
2653 filter_size = QLC_83XX_LB_MAX_FILTERS;
2654 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2655 }
2656
2657 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002658 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002659
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002660 if (!head)
2661 return;
2662
Sony Chacko13159182013-01-01 03:20:21 +00002663 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002664 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002665
Sony Chacko13159182013-01-01 03:20:21 +00002666 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2667 act_pci_func, adapter->fhash.fmax);
2668
2669 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002670 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002671
2672 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2673
2674 head = kcalloc(adapter->rx_fhash.fbucket_size,
2675 sizeof(struct hlist_head), GFP_ATOMIC);
2676
2677 if (!head)
2678 return;
2679
2680 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2681 adapter->rx_fhash.fhead = head;
2682
2683 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2684 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002685}
2686
2687static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2688{
2689 if (adapter->fhash.fmax && adapter->fhash.fhead)
2690 kfree(adapter->fhash.fhead);
2691
2692 adapter->fhash.fhead = NULL;
2693 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002694
2695 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2696 kfree(adapter->rx_fhash.fhead);
2697
2698 adapter->rx_fhash.fmax = 0;
2699 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002700}
2701
Sony Chacko629263a2013-01-01 04:11:55 +00002702int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002703{
2704 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002705 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002706 int rv = 0;
2707
Sony Chacko13159182013-01-01 03:20:21 +00002708 if (qlcnic_83xx_check(adapter))
2709 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2710
Sony Chacko97ee45e2012-12-04 03:33:52 +00002711 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002712 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002713
2714 temp_state = qlcnic_get_temp_state(temp);
2715 temp_val = qlcnic_get_temp_val(temp);
2716
2717 if (temp_state == QLCNIC_TEMP_PANIC) {
2718 dev_err(&netdev->dev,
2719 "Device temperature %d degrees C exceeds"
2720 " maximum allowed. Hardware has been shut down.\n",
2721 temp_val);
2722 rv = 1;
2723 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002724 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002725 dev_err(&netdev->dev,
2726 "Device temperature %d degrees C "
2727 "exceeds operating range."
2728 " Immediate action needed.\n",
2729 temp_val);
2730 }
2731 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002732 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002733 dev_info(&netdev->dev,
2734 "Device temperature is now %d degrees C"
2735 " in normal range.\n", temp_val);
2736 }
2737 }
Sony Chacko79788452012-12-04 03:33:53 +00002738 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002739 return rv;
2740}
2741
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002742static void qlcnic_tx_timeout(struct net_device *netdev)
2743{
2744 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002745 struct qlcnic_host_tx_ring *tx_ring;
2746 int ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002747
2748 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2749 return;
2750
Sony Chacko536faa62013-05-09 09:25:13 +00002751 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
2752 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
2753 if (qlcnic_82xx_check(adapter))
2754 adapter->need_fw_reset = 1;
2755 else if (qlcnic_83xx_check(adapter))
2756 qlcnic_83xx_idc_request_reset(adapter,
2757 QLCNIC_FORCE_FW_DUMP_KEY);
2758 } else {
2759 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002760 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhanif27c75b2013-11-04 13:31:30 -05002761 tx_ring = &adapter->tx_ring[ring];
2762 netdev_info(netdev, "Tx ring=%d\n", ring);
2763 netdev_info(netdev,
2764 "crb_intr_mask=%d, producer=%d, sw_consumer=%d, hw_consumer=%d\n",
2765 readl(tx_ring->crb_intr_mask),
2766 readl(tx_ring->crb_cmd_producer),
2767 tx_ring->sw_consumer,
2768 le32_to_cpu(*(tx_ring->hw_consumer)));
2769 netdev_info(netdev,
2770 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
2771 tx_ring->tx_stats.xmit_finished,
2772 tx_ring->tx_stats.xmit_called,
2773 tx_ring->tx_stats.xmit_on,
2774 tx_ring->tx_stats.xmit_off);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002775 }
Sony Chacko79788452012-12-04 03:33:53 +00002776 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00002777 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002778}
2779
2780static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2781{
2782 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2783 struct net_device_stats *stats = &netdev->stats;
2784
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002785 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2786 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002787 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002788 stats->tx_bytes = adapter->stats.txbytes;
2789 stats->rx_dropped = adapter->stats.rxdropped;
2790 stats->tx_dropped = adapter->stats.txdropped;
2791
2792 return stats;
2793}
2794
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002795irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002796{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002797 u32 status;
2798
2799 status = readl(adapter->isr_int_vec);
2800
Sony Chacko79788452012-12-04 03:33:53 +00002801 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802 return IRQ_NONE;
2803
2804 /* check interrupt state machine, to be sure */
2805 status = readl(adapter->crb_int_state_reg);
2806 if (!ISR_LEGACY_INT_TRIGGERED(status))
2807 return IRQ_NONE;
2808
2809 writel(0xffffffff, adapter->tgt_status_reg);
2810 /* read twice to ensure write is flushed */
2811 readl(adapter->isr_int_vec);
2812 readl(adapter->isr_int_vec);
2813
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002814 return IRQ_HANDLED;
2815}
2816
2817static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2818{
2819 struct qlcnic_host_sds_ring *sds_ring = data;
2820 struct qlcnic_adapter *adapter = sds_ring->adapter;
2821
2822 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2823 goto done;
2824 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2825 writel(0xffffffff, adapter->tgt_status_reg);
2826 goto done;
2827 }
2828
2829 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2830 return IRQ_NONE;
2831
2832done:
Sony Chacko79788452012-12-04 03:33:53 +00002833 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002834 qlcnic_enable_int(sds_ring);
2835 return IRQ_HANDLED;
2836}
2837
2838static irqreturn_t qlcnic_intr(int irq, void *data)
2839{
2840 struct qlcnic_host_sds_ring *sds_ring = data;
2841 struct qlcnic_adapter *adapter = sds_ring->adapter;
2842
2843 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2844 return IRQ_NONE;
2845
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002846 napi_schedule(&sds_ring->napi);
2847
2848 return IRQ_HANDLED;
2849}
2850
2851static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2852{
2853 struct qlcnic_host_sds_ring *sds_ring = data;
2854 struct qlcnic_adapter *adapter = sds_ring->adapter;
2855
2856 /* clear interrupt */
2857 writel(0xffffffff, adapter->tgt_status_reg);
2858
2859 napi_schedule(&sds_ring->napi);
2860 return IRQ_HANDLED;
2861}
2862
2863static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2864{
2865 struct qlcnic_host_sds_ring *sds_ring = data;
2866
2867 napi_schedule(&sds_ring->napi);
2868 return IRQ_HANDLED;
2869}
2870
Sony Chacko13159182013-01-01 03:20:21 +00002871static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2872{
2873 struct qlcnic_host_tx_ring *tx_ring = data;
2874
2875 napi_schedule(&tx_ring->napi);
2876 return IRQ_HANDLED;
2877}
2878
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002879#ifdef CONFIG_NET_POLL_CONTROLLER
2880static void qlcnic_poll_controller(struct net_device *netdev)
2881{
Yinglin Luanbf827912010-08-22 21:57:56 +00002882 int ring;
2883 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002884 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002885 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002886
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002887 disable_irq(adapter->irq);
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002888 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Yinglin Luanbf827912010-08-22 21:57:56 +00002889 sds_ring = &recv_ctx->sds_rings[ring];
2890 qlcnic_intr(adapter->irq, sds_ring);
2891 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002892 enable_irq(adapter->irq);
2893}
2894#endif
2895
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002896static void
2897qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2898{
2899 u32 val;
2900
2901 val = adapter->portnum & 0xf;
2902 val |= encoding << 7;
2903 val |= (jiffies - adapter->dev_rst_time) << 8;
2904
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002905 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002906 adapter->dev_rst_time = jiffies;
2907}
2908
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002909static int
2910qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002911{
2912 u32 val;
2913
2914 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2915 state != QLCNIC_DEV_NEED_QUISCENT);
2916
2917 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002918 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002919
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002920 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002921
2922 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002923 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002924 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002925 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002926
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002927 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002928
2929 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002930
2931 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002932}
2933
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002934static int
2935qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2936{
2937 u32 val;
2938
2939 if (qlcnic_api_lock(adapter))
2940 return -EBUSY;
2941
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002942 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002943 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002944 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002945
2946 qlcnic_api_unlock(adapter);
2947
2948 return 0;
2949}
2950
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002951void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002952{
2953 u32 val;
2954
2955 if (qlcnic_api_lock(adapter))
2956 goto err;
2957
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002958 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002959 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002960 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002961
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002962 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002963 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2964 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002965 dev_info(&adapter->pdev->dev,
2966 "Device state set to Failed. Please Reboot\n");
2967 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002968 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2969 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002970
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002971 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002972 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002973 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002974
2975 qlcnic_api_unlock(adapter);
2976err:
2977 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002978 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002979 clear_bit(__QLCNIC_START_FW, &adapter->state);
2980 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2981}
2982
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002983/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002984static int
2985qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2986{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002987 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002988 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002989
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002990 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2991 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002992
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002993 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002994 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002995 act = act & active_mask;
2996 }
2997
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002998 if (((state & 0x11111111) == (act & 0x11111111)) ||
2999 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
3000 return 0;
3001 else
3002 return 1;
3003}
3004
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003005static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
3006{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003007 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003008
3009 if (val != QLCNIC_DRV_IDC_VER) {
3010 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
3011 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
3012 }
3013
3014 return 0;
3015}
3016
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003017static int
3018qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
3019{
3020 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003021 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003022 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003023 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003024
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003025 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
3026 return 1;
3027
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003028 if (qlcnic_api_lock(adapter))
3029 return -1;
3030
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003031 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003032 if (!(val & (1 << (portnum * 4)))) {
3033 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003034 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003035 }
3036
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003037 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003038 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003039
3040 switch (prev_state) {
3041 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003042 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3043 QLCNIC_DEV_INITIALIZING);
3044 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3045 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003046 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003047 qlcnic_api_unlock(adapter);
3048 return 1;
3049
3050 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003051 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003052 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003053 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003054
3055 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003056 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003057 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003058 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003059 break;
3060
3061 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003062 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003063 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003064 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003065 break;
3066
3067 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003068 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003069 qlcnic_api_unlock(adapter);
3070 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003071
3072 case QLCNIC_DEV_INITIALIZING:
3073 case QLCNIC_DEV_QUISCENT:
3074 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003075 }
3076
3077 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003078
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003079 do {
3080 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003081 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003082
3083 if (prev_state == QLCNIC_DEV_QUISCENT)
3084 continue;
3085 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003086
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003087 if (!dev_init_timeo) {
3088 dev_err(&adapter->pdev->dev,
3089 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003090 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003091 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003092
3093 if (qlcnic_api_lock(adapter))
3094 return -1;
3095
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003096 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003097 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003098 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003099
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003100 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003101 qlcnic_api_unlock(adapter);
3102
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003103 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003104}
3105
3106static void
3107qlcnic_fwinit_work(struct work_struct *work)
3108{
3109 struct qlcnic_adapter *adapter = container_of(work,
3110 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003111 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003112 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003113
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003114 if (qlcnic_api_lock(adapter))
3115 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003116
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003117 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003118 if (dev_state == QLCNIC_DEV_QUISCENT ||
3119 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003120 qlcnic_api_unlock(adapter);
3121 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3122 FW_POLL_DELAY * 2);
3123 return;
3124 }
3125
Sony Chacko79788452012-12-04 03:33:53 +00003126 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003127 qlcnic_api_unlock(adapter);
3128 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003129 }
3130
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003131 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3132 dev_state == QLCNIC_DEV_READY) {
3133 dev_info(&adapter->pdev->dev, "Detected state change from "
3134 "DEV_NEED_RESET, skipping ack check\n");
3135 goto skip_ack_check;
3136 }
3137
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003138 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003139 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003140 adapter->reset_ack_timeo);
3141 goto skip_ack_check;
3142 }
3143
3144 if (!qlcnic_check_drv_state(adapter)) {
3145skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003146 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003147
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003148 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003149 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3150 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003151 set_bit(__QLCNIC_START_FW, &adapter->state);
3152 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003153 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003154 val = QLC_SHARED_REG_RD32(adapter,
3155 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003156 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003157 QLC_SHARED_REG_WR32(adapter,
3158 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003159 }
3160
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003161 qlcnic_api_unlock(adapter);
3162
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003163 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003164 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003165 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003166 QLCDB(adapter, DRV, "Take FW dump\n");
3167 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003168 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003169 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003170 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003171
3172 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003173 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003174 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003175 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003176 return;
3177 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003178 goto err_ret;
3179 }
3180
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003181 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003182
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003183wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003184 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003185 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003186
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003187 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003188 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003189 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003190 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003191 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003192 return;
3193 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003194 case QLCNIC_DEV_FAILED:
3195 break;
3196 default:
3197 qlcnic_schedule_work(adapter,
3198 qlcnic_fwinit_work, FW_POLL_DELAY);
3199 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003200 }
3201
3202err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003203 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3204 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003205 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003206 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003207}
3208
3209static void
3210qlcnic_detach_work(struct work_struct *work)
3211{
3212 struct qlcnic_adapter *adapter = container_of(work,
3213 struct qlcnic_adapter, fw_work.work);
3214 struct net_device *netdev = adapter->netdev;
3215 u32 status;
3216
3217 netif_device_detach(netdev);
3218
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003219 /* Dont grab rtnl lock during Quiscent mode */
3220 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3221 if (netif_running(netdev))
3222 __qlcnic_down(adapter, netdev);
3223 } else
3224 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003225
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003226 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003227
Sony Chacko44f65b22011-08-29 12:50:26 +00003228 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3229 dev_err(&adapter->pdev->dev,
3230 "Detaching the device: peg halt status1=0x%x\n",
3231 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003232
Sony Chacko44f65b22011-08-29 12:50:26 +00003233 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3234 dev_err(&adapter->pdev->dev,
3235 "On board active cooling fan failed. "
3236 "Device has been halted.\n");
3237 dev_err(&adapter->pdev->dev,
3238 "Replace the adapter.\n");
3239 }
3240
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003241 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003242 }
3243
Sony Chacko79788452012-12-04 03:33:53 +00003244 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003245 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003246 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003247 goto err_ret;
3248 }
3249
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003250 /* Dont ack if this instance is the reset owner */
3251 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003252 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3253 dev_err(&adapter->pdev->dev,
3254 "Failed to set driver state,"
3255 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003256 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003257 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003258 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003259
3260 adapter->fw_wait_cnt = 0;
3261
3262 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3263
3264 return;
3265
3266err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003267 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003268 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003269}
3270
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003271/*Transit NPAR state to NON Operational */
3272static void
3273qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3274{
3275 u32 state;
3276
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003277 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003278 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3279 return;
3280
3281 if (qlcnic_api_lock(adapter))
3282 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003283 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3284 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003285 qlcnic_api_unlock(adapter);
3286}
3287
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003288void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003289{
Sritej Velaga646779f2012-02-03 13:45:41 +00003290 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003291
Sritej Velaga646779f2012-02-03 13:45:41 +00003292 qlcnic_xg_set_xg0_mask(xg_val);
3293 qlcnic_xg_set_xg1_mask(xg_val);
3294 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3295 qlcnic_gb_set_gb0_mask(gb_val);
3296 qlcnic_gb_set_gb1_mask(gb_val);
3297 qlcnic_gb_set_gb2_mask(gb_val);
3298 qlcnic_gb_set_gb3_mask(gb_val);
3299 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3300 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3301 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003302 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003303
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003304 if (qlcnic_api_lock(adapter))
3305 return;
3306
Sony Chacko13159182013-01-01 03:20:21 +00003307 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05003308
3309 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
3310 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n",
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003311 __func__);
3312 qlcnic_api_unlock(adapter);
3313
3314 return;
3315 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003316
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003317 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003318 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3319 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003320 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003321 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003322 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003323 }
3324
Sony Chacko13159182013-01-01 03:20:21 +00003325 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3326 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003327 qlcnic_api_unlock(adapter);
3328}
3329
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003330/* Transit to NPAR READY state from NPAR NOT READY state */
3331static void
3332qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3333{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003334 if (qlcnic_api_lock(adapter))
3335 return;
3336
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003337 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3338 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003339 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003340
3341 qlcnic_api_unlock(adapter);
3342}
3343
Sony Chacko13159182013-01-01 03:20:21 +00003344void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3345 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003346{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003347 if (test_bit(__QLCNIC_AER, &adapter->state))
3348 return;
3349
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003350 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003351 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3352 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003353}
3354
3355static void
3356qlcnic_attach_work(struct work_struct *work)
3357{
3358 struct qlcnic_adapter *adapter = container_of(work,
3359 struct qlcnic_adapter, fw_work.work);
3360 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003361 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003362
Sony Chacko79788452012-12-04 03:33:53 +00003363 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003364 npar_state = QLC_SHARED_REG_RD32(adapter,
3365 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003366 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3367 qlcnic_clr_all_drv_state(adapter, 0);
3368 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3369 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3370 FW_POLL_DELAY);
3371 else
3372 goto attach;
3373 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3374 return;
3375 }
3376attach:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04003377 qlcnic_dcb_get_info(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003378
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003379 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003380 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003381 goto done;
3382
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003383 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003384 }
3385
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003386done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003387 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003388 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003389 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003390 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003391 if (adapter->portnum == 0)
3392 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003393
3394 if (!qlcnic_clr_drv_state(adapter))
3395 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3396 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003397}
3398
3399static int
3400qlcnic_check_health(struct qlcnic_adapter *adapter)
3401{
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003402 struct qlcnic_hardware_context *ahw = adapter->ahw;
3403 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sony Chacko4e708122010-08-31 17:17:44 +00003404 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003405 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003406 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003407
3408 if (qlcnic_check_temp(adapter))
3409 goto detach;
3410
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003411 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003412 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003413
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003414 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003415 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003416 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003417 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003418 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3419 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003420
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003421 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003422 if (heartbeat != adapter->heartbeat) {
3423 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003424 adapter->fw_fail_cnt = 0;
3425 if (adapter->need_fw_reset)
3426 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003427
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003428 if (ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003429 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003430
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003431 return 0;
3432 }
3433
3434 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3435 return 0;
3436
Sritej Velaga032a13c2011-07-29 13:30:27 +00003437 adapter->flags |= QLCNIC_FW_HANG;
3438
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003439 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003440
Sony Chacko099f7aa2012-12-04 03:33:58 +00003441 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003442 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003443
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003444 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003445 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003446 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003447 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3448 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3449 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3450 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003451 peg_status,
3452 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003453 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3454 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3455 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3456 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3457 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003458 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003459 dev_err(&adapter->pdev->dev,
3460 "Firmware aborted with error code 0x00006700. "
3461 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003462detach:
3463 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3464 QLCNIC_DEV_NEED_RESET;
3465
Sony Chacko099f7aa2012-12-04 03:33:58 +00003466 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3467 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003468
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003469 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003470 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003471 } else if (!qlcnic_auto_fw_reset && fw_dump->enable &&
3472 adapter->flags & QLCNIC_FW_RESET_OWNER) {
3473 qlcnic_dump_fw(adapter);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003474 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003475
3476 return 1;
3477}
3478
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003479void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003480{
3481 struct qlcnic_adapter *adapter = container_of(work,
3482 struct qlcnic_adapter, fw_work.work);
3483
3484 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3485 goto reschedule;
3486
3487
3488 if (qlcnic_check_health(adapter))
3489 return;
3490
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003491 if (adapter->fhash.fnum)
3492 qlcnic_prune_lb_filters(adapter);
3493
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003494reschedule:
3495 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3496}
3497
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003498static int qlcnic_is_first_func(struct pci_dev *pdev)
3499{
3500 struct pci_dev *oth_pdev;
3501 int val = pdev->devfn;
3502
3503 while (val-- > 0) {
3504 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3505 (pdev->bus), pdev->bus->number,
3506 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003507 if (!oth_pdev)
3508 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003509
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003510 if (oth_pdev->current_state != PCI_D3cold) {
3511 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003512 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003513 }
3514 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003515 }
3516 return 1;
3517}
3518
3519static int qlcnic_attach_func(struct pci_dev *pdev)
3520{
3521 int err, first_func;
3522 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3523 struct net_device *netdev = adapter->netdev;
3524
3525 pdev->error_state = pci_channel_io_normal;
3526
3527 err = pci_enable_device(pdev);
3528 if (err)
3529 return err;
3530
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003531 pci_set_master(pdev);
3532 pci_restore_state(pdev);
3533
3534 first_func = qlcnic_is_first_func(pdev);
3535
3536 if (qlcnic_api_lock(adapter))
3537 return -EINVAL;
3538
Sony Chacko79788452012-12-04 03:33:53 +00003539 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003540 adapter->need_fw_reset = 1;
3541 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003542 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3543 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003544 QLCDB(adapter, DRV, "Restarting fw\n");
3545 }
3546 qlcnic_api_unlock(adapter);
3547
Sony Chacko13159182013-01-01 03:20:21 +00003548 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003549 if (err)
3550 return err;
3551
3552 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003553 kfree(adapter->msix_entries);
3554 adapter->msix_entries = NULL;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003555 err = qlcnic_setup_intr(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003556
Manish chopra9a97e702013-01-25 10:20:37 +00003557 if (err) {
3558 kfree(adapter->msix_entries);
3559 netdev_err(netdev, "failed to setup interrupt\n");
3560 return err;
3561 }
3562
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003563 if (netif_running(netdev)) {
3564 err = qlcnic_attach(adapter);
3565 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003566 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003567 clear_bit(__QLCNIC_AER, &adapter->state);
3568 netif_device_attach(netdev);
3569 return err;
3570 }
3571
3572 err = qlcnic_up(adapter, netdev);
3573 if (err)
3574 goto done;
3575
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003576 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003577 }
3578 done:
3579 netif_device_attach(netdev);
3580 return err;
3581}
3582
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003583pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3584 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003585{
3586 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3587 struct net_device *netdev = adapter->netdev;
3588
3589 if (state == pci_channel_io_perm_failure)
3590 return PCI_ERS_RESULT_DISCONNECT;
3591
3592 if (state == pci_channel_io_normal)
3593 return PCI_ERS_RESULT_RECOVERED;
3594
3595 set_bit(__QLCNIC_AER, &adapter->state);
3596 netif_device_detach(netdev);
3597
3598 cancel_delayed_work_sync(&adapter->fw_work);
3599
3600 if (netif_running(netdev))
3601 qlcnic_down(adapter, netdev);
3602
3603 qlcnic_detach(adapter);
3604 qlcnic_teardown_intr(adapter);
3605
3606 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3607
3608 pci_save_state(pdev);
3609 pci_disable_device(pdev);
3610
3611 return PCI_ERS_RESULT_NEED_RESET;
3612}
3613
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003614pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003615{
3616 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3617 PCI_ERS_RESULT_RECOVERED;
3618}
3619
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003620void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003621{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003622 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003623 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3624
3625 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003626 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3627 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3628 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003629 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003630 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003631}
3632
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003633static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3634 pci_channel_state_t state)
3635{
3636 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3637 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3638
3639 if (hw_ops->io_error_detected) {
3640 return hw_ops->io_error_detected(pdev, state);
3641 } else {
3642 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3643 return PCI_ERS_RESULT_DISCONNECT;
3644 }
3645}
3646
3647static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3648{
3649 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3650 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3651
3652 if (hw_ops->io_slot_reset) {
3653 return hw_ops->io_slot_reset(pdev);
3654 } else {
3655 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
3656 return PCI_ERS_RESULT_DISCONNECT;
3657 }
3658}
3659
3660static void qlcnic_io_resume(struct pci_dev *pdev)
3661{
3662 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3663 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3664
3665 if (hw_ops->io_resume)
3666 hw_ops->io_resume(pdev);
3667 else
3668 dev_err(&pdev->dev, "AER resume handler not registered.\n");
3669}
3670
3671
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003672static int
3673qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3674{
3675 int err;
3676
3677 err = qlcnic_can_start_firmware(adapter);
3678 if (err)
3679 return err;
3680
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003681 err = qlcnic_check_npar_opertional(adapter);
3682 if (err)
3683 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003684
Rajesh Borundia174240a2010-08-31 17:17:47 +00003685 err = qlcnic_initialize_nic(adapter);
3686 if (err)
3687 return err;
3688
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003689 qlcnic_check_options(adapter);
3690
Rajesh Borundia73733732010-08-31 17:17:50 +00003691 err = qlcnic_set_eswitch_port_config(adapter);
3692 if (err)
3693 return err;
3694
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003695 adapter->need_fw_reset = 0;
3696
3697 return err;
3698}
3699
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003700int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3701 int queue_type)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003702{
3703 struct net_device *netdev = adapter->netdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003704 u8 max_hw_rings = 0;
3705 char buf[8];
3706 int cur_rings;
3707
3708 if (queue_type == QLCNIC_RX_QUEUE) {
3709 max_hw_rings = adapter->max_sds_rings;
3710 cur_rings = adapter->drv_sds_rings;
3711 strcpy(buf, "SDS");
3712 } else if (queue_type == QLCNIC_TX_QUEUE) {
Himanshu Madhani18afc102013-11-04 13:31:32 -05003713 max_hw_rings = adapter->max_tx_rings;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003714 cur_rings = adapter->drv_tx_rings;
3715 strcpy(buf, "Tx");
3716 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003717
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003718 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003719 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003720 return -EINVAL;
3721 }
3722
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003723 if (adapter->flags & QLCNIC_MSI_ENABLED) {
3724 netdev_err(netdev, "No RSS/TSS support in MSI mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003725 return -EINVAL;
3726 }
3727
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003728 if (ring_cnt < 2) {
3729 netdev_err(netdev,
3730 "%s rings value should not be lower than 2\n", buf);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003731 return -EINVAL;
3732 }
3733
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003734 if (!is_power_of_2(ring_cnt)) {
3735 netdev_err(netdev, "%s rings value should be a power of 2\n",
3736 buf);
3737 return -EINVAL;
3738 }
3739
3740 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) &&
3741 !qlcnic_check_multi_tx(adapter)) {
3742 netdev_err(netdev, "No Multi Tx queue support\n");
3743 return -EINVAL;
3744 }
3745
3746 if (ring_cnt > num_online_cpus()) {
3747 netdev_err(netdev,
3748 "%s value[%u] should not be higher than, number of online CPUs\n",
3749 buf, num_online_cpus());
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003750 return -EINVAL;
3751 }
3752
3753 return 0;
3754}
3755
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003756int qlcnic_setup_rings(struct qlcnic_adapter *adapter, u8 rx_cnt, u8 tx_cnt)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003757{
Manish Chopra6389b762013-04-24 12:42:39 +00003758 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +00003759 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003760
Sony Chacko319ecf12013-01-01 03:20:22 +00003761 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3762 return -EBUSY;
3763
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003764 netif_device_detach(netdev);
3765 if (netif_running(netdev))
3766 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003767
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003768 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003769
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003770 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003771 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003772 qlcnic_83xx_enable_mbx_poll(adapter);
3773 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003774
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003775 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003776
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003777 /* compute and set default and max tx/sds rings */
3778 qlcnic_set_tx_ring_count(adapter, tx_cnt);
3779 qlcnic_set_sds_ring_count(adapter, rx_cnt);
3780
3781 netif_set_real_num_tx_queues(netdev, adapter->drv_tx_rings);
3782
3783 err = qlcnic_setup_intr(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +00003784 if (err) {
3785 kfree(adapter->msix_entries);
3786 netdev_err(netdev, "failed to setup interrupt\n");
3787 return err;
3788 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003789
Sony Chacko13159182013-01-01 03:20:21 +00003790 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003791 /* register for NIC IDC AEN Events */
3792 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003793 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003794 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003795 if (err) {
3796 dev_err(&adapter->pdev->dev,
3797 "failed to setup mbx interrupt\n");
3798 goto done;
3799 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003800 }
3801
3802 if (netif_running(netdev)) {
3803 err = qlcnic_attach(adapter);
3804 if (err)
3805 goto done;
3806 err = __qlcnic_up(adapter, netdev);
3807 if (err)
3808 goto done;
3809 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3810 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003811done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003812 netif_device_attach(netdev);
3813 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3814 return err;
3815}
3816
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003817#ifdef CONFIG_INET
3818
3819#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3820
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003821static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003822qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3823 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003824{
3825 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003826
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003827 indev = in_dev_get(dev);
3828 if (!indev)
3829 return;
3830
3831 for_ifa(indev) {
3832 switch (event) {
3833 case NETDEV_UP:
3834 qlcnic_config_ipaddr(adapter,
3835 ifa->ifa_address, QLCNIC_IP_UP);
3836 break;
3837 case NETDEV_DOWN:
3838 qlcnic_config_ipaddr(adapter,
3839 ifa->ifa_address, QLCNIC_IP_DOWN);
3840 break;
3841 default:
3842 break;
3843 }
3844 } endfor_ifa(indev);
3845
3846 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003847}
3848
Sony Chacko319ecf12013-01-01 03:20:22 +00003849void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003850{
3851 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3852 struct net_device *dev;
3853 u16 vid;
3854
3855 qlcnic_config_indev_addr(adapter, netdev, event);
3856
Jiri Pirko43c00a72013-01-03 22:48:57 +00003857 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003858 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003859 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003860 if (!dev)
3861 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003862 qlcnic_config_indev_addr(adapter, dev, event);
3863 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003864 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003865}
3866
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003867static int qlcnic_netdev_event(struct notifier_block *this,
3868 unsigned long event, void *ptr)
3869{
3870 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00003871 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003872
3873recheck:
3874 if (dev == NULL)
3875 goto done;
3876
3877 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3878 dev = vlan_dev_real_dev(dev);
3879 goto recheck;
3880 }
3881
3882 if (!is_qlcnic_netdev(dev))
3883 goto done;
3884
3885 adapter = netdev_priv(dev);
3886
3887 if (!adapter)
3888 goto done;
3889
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003890 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003891 goto done;
3892
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003893 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003894done:
3895 return NOTIFY_DONE;
3896}
3897
3898static int
3899qlcnic_inetaddr_event(struct notifier_block *this,
3900 unsigned long event, void *ptr)
3901{
3902 struct qlcnic_adapter *adapter;
3903 struct net_device *dev;
3904
3905 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3906
3907 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3908
3909recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003910 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003911 goto done;
3912
3913 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3914 dev = vlan_dev_real_dev(dev);
3915 goto recheck;
3916 }
3917
3918 if (!is_qlcnic_netdev(dev))
3919 goto done;
3920
3921 adapter = netdev_priv(dev);
3922
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003923 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003924 goto done;
3925
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003926 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003927 goto done;
3928
3929 switch (event) {
3930 case NETDEV_UP:
3931 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003932
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003933 break;
3934 case NETDEV_DOWN:
3935 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003936
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003937 break;
3938 default:
3939 break;
3940 }
3941
3942done:
3943 return NOTIFY_DONE;
3944}
3945
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003946static struct notifier_block qlcnic_netdev_cb = {
3947 .notifier_call = qlcnic_netdev_event,
3948};
3949
3950static struct notifier_block qlcnic_inetaddr_cb = {
3951 .notifier_call = qlcnic_inetaddr_event,
3952};
3953#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003954void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003955{ }
3956#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003957static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003958 .error_detected = qlcnic_io_error_detected,
3959 .slot_reset = qlcnic_io_slot_reset,
3960 .resume = qlcnic_io_resume,
3961};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003962
3963static struct pci_driver qlcnic_driver = {
3964 .name = qlcnic_driver_name,
3965 .id_table = qlcnic_pci_tbl,
3966 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003967 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003968#ifdef CONFIG_PM
3969 .suspend = qlcnic_suspend,
3970 .resume = qlcnic_resume,
3971#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003972 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003973 .err_handler = &qlcnic_err_handler,
3974#ifdef CONFIG_QLCNIC_SRIOV
3975 .sriov_configure = qlcnic_pci_sriov_configure,
3976#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003977
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003978};
3979
3980static int __init qlcnic_init_module(void)
3981{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003982 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003983
3984 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3985
3986#ifdef CONFIG_INET
3987 register_netdevice_notifier(&qlcnic_netdev_cb);
3988 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3989#endif
3990
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003991 ret = pci_register_driver(&qlcnic_driver);
3992 if (ret) {
3993#ifdef CONFIG_INET
3994 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3995 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3996#endif
3997 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003998
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003999 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004000}
4001
4002module_init(qlcnic_init_module);
4003
4004static void __exit qlcnic_exit_module(void)
4005{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004006 pci_unregister_driver(&qlcnic_driver);
4007
4008#ifdef CONFIG_INET
4009 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4010 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4011#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004012}
4013
4014module_exit(qlcnic_exit_module);