blob: aeb26a8506799c6a9263e41fa5d82633deafb9d7 [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
Sony Chacko629263a2013-01-01 04:11:55 +000055int qlcnic_config_npars;
amit salechab11a25a2011-01-10 00:15:23 +000056module_param(qlcnic_config_npars, int, 0444);
Himanshu Madhani9fd13332013-05-09 09:25:11 +000057MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled)");
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000058
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000059static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050060static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000061static int qlcnic_open(struct net_device *netdev);
62static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000063static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000064static void qlcnic_attach_work(struct work_struct *work);
65static void qlcnic_fwinit_work(struct work_struct *work);
66static void qlcnic_fw_poll_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000067#ifdef CONFIG_NET_POLL_CONTROLLER
68static void qlcnic_poll_controller(struct net_device *netdev);
69#endif
70
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000071static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000072static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000073static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
74
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000075static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000076static irqreturn_t qlcnic_intr(int irq, void *data);
77static irqreturn_t qlcnic_msi_intr(int irq, void *data);
78static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000079static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000080
81static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000082static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000083
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000084static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000085static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000086static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000087static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
88static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000089
Sony Chacko13159182013-01-01 03:20:21 +000090static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
91{
92 struct qlcnic_hardware_context *ahw = adapter->ahw;
93
94 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
95 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
96 else
97 return 1;
98}
99
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000100/* PCI Device ID Table */
101#define ENTRY(device) \
102 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
103 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
104
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000105static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000106 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000107 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000108 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000109 {0,}
110};
111
112MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
113
114
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000115inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000116{
117 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000118}
119
120static const u32 msi_tgt_status[8] = {
121 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
122 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
123 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
124 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
125};
126
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000127static const u32 qlcnic_reg_tbl[] = {
128 0x1B20A8, /* PEG_HALT_STAT1 */
129 0x1B20AC, /* PEG_HALT_STAT2 */
130 0x1B20B0, /* FW_HEARTBEAT */
131 0x1B2100, /* LOCK ID */
132 0x1B2128, /* FW_CAPABILITIES */
133 0x1B2138, /* drv active */
134 0x1B2140, /* dev state */
135 0x1B2144, /* drv state */
136 0x1B2148, /* drv scratch */
137 0x1B214C, /* dev partition info */
138 0x1B2174, /* drv idc ver */
139 0x1B2150, /* fw version major */
140 0x1B2154, /* fw version minor */
141 0x1B2158, /* fw version sub */
142 0x1B219C, /* npar state */
143 0x1B21FC, /* FW_IMG_VALID */
144 0x1B2250, /* CMD_PEG_STATE */
145 0x1B233C, /* RCV_PEG_STATE */
146 0x1B23B4, /* ASIC TEMP */
147 0x1B216C, /* FW api */
148 0x1B2170, /* drv op mode */
149 0x13C010, /* flash lock */
150 0x13C014, /* flash unlock */
151};
152
Sony Chacko22999792012-12-04 03:33:55 +0000153static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000154 { PCI_VENDOR_ID_QLOGIC,
155 PCI_DEVICE_ID_QLOGIC_QLE834X,
156 PCI_VENDOR_ID_QLOGIC,
157 0x24e,
158 "8300 Series Dual Port 10GbE Converged Network Adapter "
159 "(TCP/IP Networking)" },
160 { PCI_VENDOR_ID_QLOGIC,
161 PCI_DEVICE_ID_QLOGIC_QLE834X,
162 PCI_VENDOR_ID_QLOGIC,
163 0x243,
164 "8300 Series Single Port 10GbE Converged Network Adapter "
165 "(TCP/IP Networking)" },
166 { PCI_VENDOR_ID_QLOGIC,
167 PCI_DEVICE_ID_QLOGIC_QLE834X,
168 PCI_VENDOR_ID_QLOGIC,
169 0x24a,
170 "8300 Series Dual Port 10GbE Converged Network Adapter "
171 "(TCP/IP Networking)" },
172 { PCI_VENDOR_ID_QLOGIC,
173 PCI_DEVICE_ID_QLOGIC_QLE834X,
174 PCI_VENDOR_ID_QLOGIC,
175 0x246,
176 "8300 Series Dual Port 10GbE Converged Network Adapter "
177 "(TCP/IP Networking)" },
178 { PCI_VENDOR_ID_QLOGIC,
179 PCI_DEVICE_ID_QLOGIC_QLE834X,
180 PCI_VENDOR_ID_QLOGIC,
181 0x252,
182 "8300 Series Dual Port 10GbE Converged Network Adapter "
183 "(TCP/IP Networking)" },
184 { PCI_VENDOR_ID_QLOGIC,
185 PCI_DEVICE_ID_QLOGIC_QLE834X,
186 PCI_VENDOR_ID_QLOGIC,
187 0x26e,
188 "8300 Series Dual Port 10GbE Converged Network Adapter "
189 "(TCP/IP Networking)" },
190 { PCI_VENDOR_ID_QLOGIC,
191 PCI_DEVICE_ID_QLOGIC_QLE834X,
192 PCI_VENDOR_ID_QLOGIC,
193 0x260,
194 "8300 Series Dual Port 10GbE Converged Network Adapter "
195 "(TCP/IP Networking)" },
196 { PCI_VENDOR_ID_QLOGIC,
197 PCI_DEVICE_ID_QLOGIC_QLE834X,
198 PCI_VENDOR_ID_QLOGIC,
199 0x266,
200 "8300 Series Single Port 10GbE Converged Network Adapter "
201 "(TCP/IP Networking)" },
202 { PCI_VENDOR_ID_QLOGIC,
203 PCI_DEVICE_ID_QLOGIC_QLE834X,
204 PCI_VENDOR_ID_QLOGIC,
205 0x269,
206 "8300 Series Dual Port 10GbE Converged Network Adapter "
207 "(TCP/IP Networking)" },
208 { PCI_VENDOR_ID_QLOGIC,
209 PCI_DEVICE_ID_QLOGIC_QLE834X,
210 PCI_VENDOR_ID_QLOGIC,
211 0x271,
212 "8300 Series Dual Port 10GbE Converged Network Adapter "
213 "(TCP/IP Networking)" },
214 { PCI_VENDOR_ID_QLOGIC,
215 PCI_DEVICE_ID_QLOGIC_QLE834X,
216 0x0, 0x0, "8300 Series 1/10GbE Controller" },
217 { PCI_VENDOR_ID_QLOGIC,
218 PCI_DEVICE_ID_QLOGIC_QLE824X,
219 PCI_VENDOR_ID_QLOGIC,
220 0x203,
221 "8200 Series Single Port 10GbE Converged Network Adapter"
222 "(TCP/IP Networking)" },
223 { PCI_VENDOR_ID_QLOGIC,
224 PCI_DEVICE_ID_QLOGIC_QLE824X,
225 PCI_VENDOR_ID_QLOGIC,
226 0x207,
227 "8200 Series Dual Port 10GbE Converged Network Adapter"
228 "(TCP/IP Networking)" },
229 { PCI_VENDOR_ID_QLOGIC,
230 PCI_DEVICE_ID_QLOGIC_QLE824X,
231 PCI_VENDOR_ID_QLOGIC,
232 0x20b,
233 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
234 { PCI_VENDOR_ID_QLOGIC,
235 PCI_DEVICE_ID_QLOGIC_QLE824X,
236 PCI_VENDOR_ID_QLOGIC,
237 0x20c,
238 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
239 { PCI_VENDOR_ID_QLOGIC,
240 PCI_DEVICE_ID_QLOGIC_QLE824X,
241 PCI_VENDOR_ID_QLOGIC,
242 0x20f,
243 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
244 { PCI_VENDOR_ID_QLOGIC,
245 PCI_DEVICE_ID_QLOGIC_QLE824X,
246 0x103c, 0x3733,
247 "NC523SFP 10Gb 2-port Server Adapter" },
248 { PCI_VENDOR_ID_QLOGIC,
249 PCI_DEVICE_ID_QLOGIC_QLE824X,
250 0x103c, 0x3346,
251 "CN1000Q Dual Port Converged Network Adapter" },
252 { PCI_VENDOR_ID_QLOGIC,
253 PCI_DEVICE_ID_QLOGIC_QLE824X,
254 PCI_VENDOR_ID_QLOGIC,
255 0x210,
256 "QME8242-k 10GbE Dual Port Mezzanine Card" },
257 { PCI_VENDOR_ID_QLOGIC,
258 PCI_DEVICE_ID_QLOGIC_QLE824X,
259 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000260};
261
262#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
Sony Chacko319ecf12013-01-01 03:20:22 +0000263#define QLC_MAX_SDS_RINGS 8
Sony Chacko22999792012-12-04 03:33:55 +0000264
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{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000287 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000288 struct net_device *netdev = adapter->netdev;
289 struct pci_dev *pdev = adapter->pdev;
290
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000291 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000292 return -EIO;
293
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000294 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000295 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
296
297 /* set station address */
298
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000299 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000300 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
301 netdev->dev_addr);
302
303 return 0;
304}
305
Manish Chopracffe52f32013-05-09 09:25:09 +0000306static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
307{
308 struct qlcnic_mac_list_s *cur;
309 struct list_head *head;
310
311 list_for_each(head, &adapter->mac_list) {
312 cur = list_entry(head, struct qlcnic_mac_list_s, list);
313 if (!memcmp(adapter->mac_addr, cur->mac_addr, ETH_ALEN)) {
314 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
315 0, QLCNIC_MAC_DEL);
316 list_del(&cur->list);
317 kfree(cur);
318 return;
319 }
320 }
321}
322
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000323static int qlcnic_set_mac(struct net_device *netdev, void *p)
324{
325 struct qlcnic_adapter *adapter = netdev_priv(netdev);
326 struct sockaddr *addr = p;
327
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000328 if (qlcnic_sriov_vf_check(adapter))
329 return -EINVAL;
330
Rajesh Borundia73733732010-08-31 17:17:50 +0000331 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
332 return -EOPNOTSUPP;
333
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000334 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000335 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000336
Manish Chopracffe52f32013-05-09 09:25:09 +0000337 if (!memcmp(adapter->mac_addr, addr->sa_data, ETH_ALEN))
338 return 0;
339
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000340 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000341 netif_device_detach(netdev);
342 qlcnic_napi_disable(adapter);
343 }
344
Manish Chopracffe52f32013-05-09 09:25:09 +0000345 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000346 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
347 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
348 qlcnic_set_multi(adapter->netdev);
349
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000350 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000351 netif_device_attach(netdev);
352 qlcnic_napi_enable(adapter);
353 }
354 return 0;
355}
356
Vlad Yasevich1690be62013-02-13 12:00:18 +0000357static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
358 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000359{
360 struct qlcnic_adapter *adapter = netdev_priv(netdev);
361 int err = -EOPNOTSUPP;
362
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000363 if (!adapter->fdb_mac_learn)
364 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000365
366 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
367 if (is_unicast_ether_addr(addr))
368 err = qlcnic_nic_del_mac(adapter, addr);
369 else if (is_multicast_ether_addr(addr))
370 err = dev_mc_del(netdev, addr);
371 else
372 err = -EINVAL;
373 }
374 return err;
375}
376
377static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
378 struct net_device *netdev,
379 const unsigned char *addr, u16 flags)
380{
381 struct qlcnic_adapter *adapter = netdev_priv(netdev);
382 int err = 0;
383
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000384 if (!adapter->fdb_mac_learn)
385 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000386
387 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
388 pr_info("%s: FDB e-switch is not enabled\n", __func__);
389 return -EOPNOTSUPP;
390 }
391
392 if (ether_addr_equal(addr, adapter->mac_addr))
393 return err;
394
395 if (is_unicast_ether_addr(addr))
Rajesh Borundia91b72822013-04-19 07:01:12 +0000396 err = qlcnic_nic_add_mac(adapter, addr, 0);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000397 else if (is_multicast_ether_addr(addr))
398 err = dev_mc_add_excl(netdev, addr);
399 else
400 err = -EINVAL;
401
402 return err;
403}
404
405static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
406 struct net_device *netdev, int idx)
407{
408 struct qlcnic_adapter *adapter = netdev_priv(netdev);
409
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000410 if (!adapter->fdb_mac_learn)
411 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000412
413 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
414 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
415
416 return idx;
417}
418
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000419static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
420{
421 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
422 usleep_range(10000, 11000);
423
424 cancel_delayed_work_sync(&adapter->fw_work);
425}
426
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000427static const struct net_device_ops qlcnic_netdev_ops = {
428 .ndo_open = qlcnic_open,
429 .ndo_stop = qlcnic_close,
430 .ndo_start_xmit = qlcnic_xmit_frame,
431 .ndo_get_stats = qlcnic_get_stats,
432 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000433 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000434 .ndo_set_mac_address = qlcnic_set_mac,
435 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000436 .ndo_fix_features = qlcnic_fix_features,
437 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000438 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000439 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
440 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000441 .ndo_fdb_add = qlcnic_fdb_add,
442 .ndo_fdb_del = qlcnic_fdb_del,
443 .ndo_fdb_dump = qlcnic_fdb_dump,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000444#ifdef CONFIG_NET_POLL_CONTROLLER
445 .ndo_poll_controller = qlcnic_poll_controller,
446#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000447#ifdef CONFIG_QLCNIC_SRIOV
448 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
449 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate,
450 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000451 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000452#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000453};
454
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000455static const struct net_device_ops qlcnic_netdev_failed_ops = {
456 .ndo_open = qlcnic_open,
457};
458
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000459static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000460 .config_bridged_mode = qlcnic_config_bridged_mode,
461 .config_led = qlcnic_82xx_config_led,
462 .start_firmware = qlcnic_82xx_start_firmware,
463 .request_reset = qlcnic_82xx_dev_request_reset,
464 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
465 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000466 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000467 .config_ipaddr = qlcnic_82xx_config_ipaddr,
468 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000469};
470
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000471struct qlcnic_nic_template qlcnic_vf_ops = {
472 .config_bridged_mode = qlcnicvf_config_bridged_mode,
473 .config_led = qlcnicvf_config_led,
474 .start_firmware = qlcnicvf_start_firmware
475};
476
477static struct qlcnic_hardware_ops qlcnic_hw_ops = {
478 .read_crb = qlcnic_82xx_read_crb,
479 .write_crb = qlcnic_82xx_write_crb,
480 .read_reg = qlcnic_82xx_hw_read_wx_2M,
481 .write_reg = qlcnic_82xx_hw_write_wx_2M,
482 .get_mac_address = qlcnic_82xx_get_mac_address,
483 .setup_intr = qlcnic_82xx_setup_intr,
484 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
485 .mbx_cmd = qlcnic_82xx_issue_cmd,
486 .get_func_no = qlcnic_82xx_get_func_no,
487 .api_lock = qlcnic_82xx_api_lock,
488 .api_unlock = qlcnic_82xx_api_unlock,
489 .add_sysfs = qlcnic_82xx_add_sysfs,
490 .remove_sysfs = qlcnic_82xx_remove_sysfs,
491 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
492 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
493 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000494 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
495 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000496 .setup_link_event = qlcnic_82xx_linkevent_request,
497 .get_nic_info = qlcnic_82xx_get_nic_info,
498 .get_pci_info = qlcnic_82xx_get_pci_info,
499 .set_nic_info = qlcnic_82xx_set_nic_info,
500 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
501 .napi_enable = qlcnic_82xx_napi_enable,
502 .napi_disable = qlcnic_82xx_napi_disable,
503 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
504 .config_rss = qlcnic_82xx_config_rss,
505 .config_hw_lro = qlcnic_82xx_config_hw_lro,
506 .config_loopback = qlcnic_82xx_set_lb_mode,
507 .clear_loopback = qlcnic_82xx_clear_lb_mode,
508 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
509 .change_l2_filter = qlcnic_82xx_change_filter,
510 .get_board_info = qlcnic_82xx_get_board_info,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000511 .free_mac_list = qlcnic_82xx_free_mac_list,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000512};
513
Sony Chacko7f9664522013-01-01 03:20:19 +0000514int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000515{
516 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000517 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000518 int max_tx_rings, tx_vector;
519
520 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
521 max_tx_rings = 0;
522 tx_vector = 0;
523 } else {
524 max_tx_rings = adapter->max_drv_tx_rings;
525 tx_vector = 1;
526 }
Sony Chacko13159182013-01-01 03:20:21 +0000527
528 if (!adapter->msix_entries) {
529 adapter->msix_entries = kcalloc(num_msix,
530 sizeof(struct msix_entry),
531 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000532 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000533 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000534 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000535
536 adapter->max_sds_rings = 1;
537 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000538
Sony Chacko79788452012-12-04 03:33:53 +0000539 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000540 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000541 for (i = 0; i < num_msix; i++)
542 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000543 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
544 if (err == 0) {
545 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000546 if (qlcnic_83xx_check(adapter)) {
547 adapter->ahw->num_msix = num_msix;
548 /* subtract mail box and tx ring vectors */
Sony Chacko13159182013-01-01 03:20:21 +0000549 adapter->max_sds_rings = num_msix -
550 max_tx_rings - 1;
551 } else {
552 adapter->max_sds_rings = num_msix;
553 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000554 dev_info(&pdev->dev, "using msi-x interrupts\n");
555 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000556 } else if (err > 0) {
557 dev_info(&pdev->dev,
558 "Unable to allocate %d MSI-X interrupt vectors\n",
559 num_msix);
560 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000561 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000562 return err;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000563 err -= (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000564 num_msix = rounddown_pow_of_two(err);
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000565 num_msix += (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000566 } else {
567 num_msix = rounddown_pow_of_two(err);
568 }
569
570 if (num_msix) {
571 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000572 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000573 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000574 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000575 }
576 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000577 dev_info(&pdev->dev,
578 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000579 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000580 }
581 }
Sony Chacko13159182013-01-01 03:20:21 +0000582
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000583 return err;
584}
585
Manish chopra9a97e702013-01-25 10:20:37 +0000586static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000587{
Manish chopra9a97e702013-01-25 10:20:37 +0000588 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000589 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000590 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000591 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000592 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000593
Sony Chacko099f7aa2012-12-04 03:33:58 +0000594 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000595 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000596 offset = msi_tgt_status[adapter->ahw->pci_func];
597 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
598 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000599 dev_info(&pdev->dev, "using msi interrupts\n");
600 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000601 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000602 }
Manish chopra9a97e702013-01-25 10:20:37 +0000603 if (qlcnic_use_msi || qlcnic_use_msi_x)
604 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000605
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000606 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000607 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000608 offset = legacy_intrp->tgt_status_reg;
609 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
610 mask_reg = legacy_intrp->tgt_mask_reg;
611 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
612 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
613 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000614 dev_info(&pdev->dev, "using legacy interrupts\n");
615 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000616 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000617}
618
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000619int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000620{
Manish chopra9a97e702013-01-25 10:20:37 +0000621 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000622
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000623 if (!num_intr)
624 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
625
626 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000627 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000628 num_intr));
629 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000630 num_msix = 1;
631
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000632 err = qlcnic_enable_msix(adapter, num_msix);
633 if (err == -ENOMEM || !err)
634 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000635
Manish chopra9a97e702013-01-25 10:20:37 +0000636 err = qlcnic_enable_msi_legacy(adapter);
637 if (!err)
638 return err;
639
640 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000641}
Sony Chacko13159182013-01-01 03:20:21 +0000642
Sony Chacko319ecf12013-01-01 03:20:22 +0000643void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000644{
645 if (adapter->flags & QLCNIC_MSIX_ENABLED)
646 pci_disable_msix(adapter->pdev);
647 if (adapter->flags & QLCNIC_MSI_ENABLED)
648 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000649
650 kfree(adapter->msix_entries);
651 adapter->msix_entries = NULL;
652
653 if (adapter->ahw->intr_tbl) {
654 vfree(adapter->ahw->intr_tbl);
655 adapter->ahw->intr_tbl = NULL;
656 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000657}
658
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000659static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000660{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000661 if (ahw->pci_base0 != NULL)
662 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000663}
664
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000665static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
666{
667 struct qlcnic_pci_info *pci_info;
668 int ret;
669
670 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
671 switch (adapter->ahw->port_type) {
672 case QLCNIC_GBE:
673 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
674 break;
675 case QLCNIC_XGBE:
676 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
677 break;
678 }
679 return 0;
680 }
681
682 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
683 return 0;
684
685 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
686 if (!pci_info)
687 return -ENOMEM;
688
689 ret = qlcnic_get_pci_info(adapter, pci_info);
690 kfree(pci_info);
691 return ret;
692}
Sony Chackod71170f2013-01-01 03:20:26 +0000693
694int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000695{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000696 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000697 int i, ret = 0, j = 0;
698 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000699 u8 pfn;
700
Dan Carpentere88db3b2010-08-09 21:49:36 +0000701 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
702 if (!pci_info)
703 return -ENOMEM;
704
Sony Chackobff57d82012-12-04 03:33:56 +0000705 ret = qlcnic_get_pci_info(adapter, pci_info);
706 if (ret)
707 goto err_pci_info;
708
709 act_pci_func = adapter->ahw->act_pci_func;
710
Dan Carpenterca315ac2010-08-09 21:47:56 +0000711 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000712 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000713 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000714 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000715 goto err_pci_info;
716 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000717
Dan Carpenterca315ac2010-08-09 21:47:56 +0000718 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000719 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
720 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000721 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000722 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000723 }
724
Dan Carpenterca315ac2010-08-09 21:47:56 +0000725 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
726 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000727
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000728 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000729 ret = QL_STATUS_INVALID_PARAM;
730 goto err_eswitch;
731 }
Sony Chackobff57d82012-12-04 03:33:56 +0000732
733 if (!pci_info[i].active ||
734 (pci_info[i].type != QLCNIC_TYPE_NIC))
735 continue;
736
737 adapter->npars[j].pci_func = pfn;
738 adapter->npars[j].active = (u8)pci_info[i].active;
739 adapter->npars[j].type = (u8)pci_info[i].type;
740 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
741 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
742 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
743 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000744 }
745
Sony Chacko13159182013-01-01 03:20:21 +0000746 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000747 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000748 if (qlcnic_83xx_check(adapter))
749 qlcnic_enable_eswitch(adapter, i, 1);
750 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000751
Dan Carpentere88db3b2010-08-09 21:49:36 +0000752 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000753 return 0;
754
755err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000756 kfree(adapter->eswitch);
757 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000758err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000759 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000760 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000761err_pci_info:
762 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000763
764 return ret;
765}
766
767static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000768qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
769{
770 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000771 int i, ret = 1;
772 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000773 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000774
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000775 ret = qlcnic_api_lock(adapter);
776 if (ret)
777 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000778
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000779 if (qlcnic_config_npars) {
Sony Chackobff57d82012-12-04 03:33:56 +0000780 for (i = 0; i < ahw->act_pci_func; i++) {
781 id = adapter->npars[i].pci_func;
782 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000783 continue;
784 data |= (qlcnic_config_npars &
785 QLC_DEV_SET_DRV(0xf, id));
786 }
787 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000788 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d82012-12-04 03:33:56 +0000789 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000790 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d82012-12-04 03:33:56 +0000791 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000792 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000793 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000794 qlcnic_api_unlock(adapter);
795err_lock:
796 return ret;
797}
798
Sony Chacko13159182013-01-01 03:20:21 +0000799static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
800 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000801{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000802 u32 op_mode, priv_level;
803
804 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000805 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
806 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000807
808 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000809 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000810
811 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000812 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000813 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000814 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000815 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000816 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000817
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000818 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000819 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000820 dev_info(&adapter->pdev->dev,
821 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000822 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000823 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000824 } else
825 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000826}
827
Sony Chacko15087c22012-12-04 03:33:54 +0000828#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000829#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000830static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000831{
Sony Chacko15087c22012-12-04 03:33:54 +0000832 switch (dev_id) {
833 case PCI_DEVICE_ID_QLOGIC_QLE824X:
834 *bar = QLCNIC_82XX_BAR0_LENGTH;
835 break;
Sony Chacko13159182013-01-01 03:20:21 +0000836 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000837 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +0000838 *bar = QLCNIC_83XX_BAR0_LENGTH;
839 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000840 default:
841 *bar = 0;
842 }
843}
844
845static int qlcnic_setup_pci_map(struct pci_dev *pdev,
846 struct qlcnic_hardware_context *ahw)
847{
848 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000849 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000850 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000851
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000852 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000853 mem_len = pci_resource_len(pdev, 0);
854
Sony Chacko15087c22012-12-04 03:33:54 +0000855 qlcnic_get_bar_length(pdev->device, &bar0_len);
856 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000857
858 mem_ptr0 = pci_ioremap_bar(pdev, 0);
859 if (mem_ptr0 == NULL) {
860 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
861 return -EIO;
862 }
863 pci_len0 = mem_len;
864 } else {
865 return -EIO;
866 }
867
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000868 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000869
Sony Chacko15087c22012-12-04 03:33:54 +0000870 ahw->pci_base0 = mem_ptr0;
871 ahw->pci_len0 = pci_len0;
872 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
873 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000874
875 return 0;
876}
877
Sony Chacko22999792012-12-04 03:33:55 +0000878static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000879{
880 struct pci_dev *pdev = adapter->pdev;
881 int i, found = 0;
882
883 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
884 if (qlcnic_boards[i].vendor == pdev->vendor &&
885 qlcnic_boards[i].device == pdev->device &&
886 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
887 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000888 sprintf(name, "%pM: %s" ,
889 adapter->mac_addr,
890 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000891 found = 1;
892 break;
893 }
894
895 }
896
897 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000898 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000899}
900
901static void
902qlcnic_check_options(struct qlcnic_adapter *adapter)
903{
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000904 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000905 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000906 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000907 struct qlcnic_hardware_context *ahw = adapter->ahw;
908 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000909
910 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000911
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000912 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
913 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
914 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000915
916 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
917
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000918 err = qlcnic_get_board_info(adapter);
919 if (err) {
920 dev_err(&pdev->dev, "Error getting board config info.\n");
921 return;
922 }
923 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +0000924 if (fw_dump->tmpl_hdr == NULL ||
925 adapter->fw_version > prev_fw_version) {
926 if (fw_dump->tmpl_hdr)
927 vfree(fw_dump->tmpl_hdr);
928 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
929 dev_info(&pdev->dev,
930 "Supports FW dump capability\n");
931 }
932 }
933
Sony Chacko13159182013-01-01 03:20:21 +0000934 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
935 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
936
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000937 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000938 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
939 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
940 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
941 } else {
942 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
943 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
944 }
945
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000946 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000947 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
948
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000949 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000950 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
951 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000952 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
953 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000954 }
955
Sony Chacko099f7aa2012-12-04 03:33:58 +0000956 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000957
958 adapter->num_txd = MAX_CMD_DESCRIPTORS;
959
Sony Chacko251b0362010-08-19 05:08:24 +0000960 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000961}
962
Rajesh Borundia174240a2010-08-31 17:17:47 +0000963static int
964qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
965{
966 int err;
967 struct qlcnic_info nic_info;
968
Sony Chackobff57d82012-12-04 03:33:56 +0000969 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000970 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000971 if (err)
972 return err;
973
Sony Chacko79788452012-12-04 03:33:53 +0000974 adapter->ahw->physical_port = (u8)nic_info.phys_port;
975 adapter->ahw->switch_mode = nic_info.switch_mode;
976 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
977 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
978 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +0000979
980 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
981 u32 temp;
982 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
983 adapter->ahw->capabilities2 = temp;
984 }
Sony Chacko79788452012-12-04 03:33:53 +0000985 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
986 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000987
Sony Chacko13159182013-01-01 03:20:21 +0000988 /* Disable NPAR for 83XX */
989 if (qlcnic_83xx_check(adapter))
990 return err;
991
Sony Chacko79788452012-12-04 03:33:53 +0000992 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +0000993 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
994 else
995 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
996
997 return err;
998}
999
Sony Chackoec079a02012-11-28 04:34:28 +00001000void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1001 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001002{
1003 if (esw_cfg->discard_tagged)
1004 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1005 else
1006 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1007
Rajesh Borundia91b72822013-04-19 07:01:12 +00001008 if (esw_cfg->vlan_id) {
1009 adapter->rx_pvid = esw_cfg->vlan_id;
1010 adapter->tx_pvid = esw_cfg->vlan_id;
1011 } else {
1012 adapter->rx_pvid = 0;
1013 adapter->tx_pvid = 0;
1014 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001015}
1016
Jiri Pirko8e586132011-12-08 19:52:37 -05001017static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001018qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001019{
1020 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001021 int err;
1022
1023 if (qlcnic_sriov_vf_check(adapter)) {
1024 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1025 if (err) {
1026 netdev_err(netdev,
1027 "Cannot add VLAN filter for VLAN id %d, err=%d",
1028 vid, err);
1029 return err;
1030 }
1031 }
1032
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001033 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001034 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001035}
1036
Jiri Pirko8e586132011-12-08 19:52:37 -05001037static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001038qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001039{
1040 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001041 int err;
1042
1043 if (qlcnic_sriov_vf_check(adapter)) {
1044 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1045 if (err) {
1046 netdev_err(netdev,
1047 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1048 vid, err);
1049 return err;
1050 }
1051 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001052
1053 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1054 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001055 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001056}
1057
Sony Chackoec079a02012-11-28 04:34:28 +00001058void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1059 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001060{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001061 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1062 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001063
1064 if (esw_cfg->mac_anti_spoof)
1065 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001066
Rajesh Borundia73733732010-08-31 17:17:50 +00001067 if (!esw_cfg->mac_override)
1068 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1069
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001070 if (!esw_cfg->promisc_mode)
1071 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001072}
1073
Sony Chackod71170f2013-01-01 03:20:26 +00001074int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001075{
1076 struct qlcnic_esw_func_cfg esw_cfg;
1077
1078 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1079 return 0;
1080
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001081 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001082 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1083 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001084 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001085 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001086 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001087
1088 return 0;
1089}
1090
Shahed Shaikh147a9082013-05-21 09:27:01 +00001091void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1092 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001093{
1094 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001095
Sony Chacko13159182013-01-01 03:20:21 +00001096 if (qlcnic_83xx_check(adapter))
1097 return;
1098
Shahed Shaikh147a9082013-05-21 09:27:01 +00001099 adapter->offload_flags = esw_cfg->offload_flags;
1100 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1101 netdev_update_features(netdev);
1102 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001103}
1104
1105static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001106qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1107{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001108 u32 op_mode, priv_level;
1109 int err = 0;
1110
Rajesh Borundia174240a2010-08-31 17:17:47 +00001111 err = qlcnic_initialize_nic(adapter);
1112 if (err)
1113 return err;
1114
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001115 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1116 return 0;
1117
Sony Chacko13159182013-01-01 03:20:21 +00001118 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001119 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001120
1121 if (op_mode == QLC_DEV_DRV_DEFAULT)
1122 priv_level = QLCNIC_MGMT_FUNC;
1123 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001124 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001125
Rajesh Borundia174240a2010-08-31 17:17:47 +00001126 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001127 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001128 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001129 err = qlcnic_init_pci_info(adapter);
1130 if (err)
1131 return err;
1132 /* Set privilege level for other functions */
1133 qlcnic_set_function_modes(adapter);
1134 dev_info(&adapter->pdev->dev,
1135 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001136 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001137 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001138 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001139 dev_info(&adapter->pdev->dev,
1140 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001141 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001142 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001143 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001144
1145 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1146
1147 return err;
1148}
1149
Sony Chackod71170f2013-01-01 03:20:26 +00001150int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001151{
1152 struct qlcnic_esw_func_cfg esw_cfg;
1153 struct qlcnic_npar_info *npar;
1154 u8 i;
1155
Rajesh Borundia174240a2010-08-31 17:17:47 +00001156 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001157 return 0;
1158
Sony Chackobff57d82012-12-04 03:33:56 +00001159 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +00001160 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001161 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001162 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001163 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001164 if (qlcnic_82xx_check(adapter)) {
1165 esw_cfg.offload_flags = BIT_0;
1166 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1167 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1168 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001169 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1170 return -EIO;
1171 npar = &adapter->npars[i];
1172 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001173 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001174 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1175 npar->discard_tagged = esw_cfg.discard_tagged;
1176 npar->promisc_mode = esw_cfg.promisc_mode;
1177 npar->offload_flags = esw_cfg.offload_flags;
1178 }
1179
1180 return 0;
1181}
1182
Sony Chacko13159182013-01-01 03:20:21 +00001183
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001184static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001185qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1186 struct qlcnic_npar_info *npar, int pci_func)
1187{
1188 struct qlcnic_esw_func_cfg esw_cfg;
1189 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1190 esw_cfg.pci_func = pci_func;
1191 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001192 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001193 esw_cfg.discard_tagged = npar->discard_tagged;
1194 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1195 esw_cfg.offload_flags = npar->offload_flags;
1196 esw_cfg.promisc_mode = npar->promisc_mode;
1197 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1198 return -EIO;
1199
1200 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1201 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1202 return -EIO;
1203
1204 return 0;
1205}
1206
Sony Chackod71170f2013-01-01 03:20:26 +00001207int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001208{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001209 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001210 struct qlcnic_npar_info *npar;
1211 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001212 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001213
Sony Chackobff57d82012-12-04 03:33:56 +00001214 if (qlcnic_82xx_check(adapter))
1215 if (!adapter->need_fw_reset)
1216 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001217
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001218 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001219 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001220 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001221 pci_func = npar->pci_func;
1222 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001223 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001224 if (err)
1225 return err;
1226 nic_info.min_tx_bw = npar->min_bw;
1227 nic_info.max_tx_bw = npar->max_bw;
1228 err = qlcnic_set_nic_info(adapter, &nic_info);
1229 if (err)
1230 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001231
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001232 if (npar->enable_pm) {
1233 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001234 npar->dest_npar, 1,
1235 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001236 if (err)
1237 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001238 }
Sony Chackobff57d82012-12-04 03:33:56 +00001239 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001240 if (err)
1241 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001242 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001243 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001244}
1245
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001246static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1247{
1248 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1249 u32 npar_state;
1250
Sony Chacko79788452012-12-04 03:33:53 +00001251 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001252 return 0;
1253
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001254 npar_state = QLC_SHARED_REG_RD32(adapter,
1255 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001256 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1257 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001258 npar_state = QLC_SHARED_REG_RD32(adapter,
1259 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001260 }
1261 if (!npar_opt_timeo) {
1262 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001263 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001264 return -EIO;
1265 }
1266 return 0;
1267}
1268
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001269static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001270qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1271{
1272 int err;
1273
1274 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001275 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001276 return 0;
1277
1278 err = qlcnic_set_default_offload_settings(adapter);
1279 if (err)
1280 return err;
1281
1282 err = qlcnic_reset_npar_config(adapter);
1283 if (err)
1284 return err;
1285
1286 qlcnic_dev_set_npar_ready(adapter);
1287
1288 return err;
1289}
1290
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001291int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001292{
Sony Chackod4066832010-08-19 05:08:31 +00001293 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001294
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001295 err = qlcnic_can_start_firmware(adapter);
1296 if (err < 0)
1297 return err;
1298 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001299 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001300
Sony Chacko099f7aa2012-12-04 03:33:58 +00001301 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001302 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001303 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001304 err = qlcnic_check_flash_fw_ver(adapter);
1305 if (err)
schacko8f891382010-06-17 02:56:40 +00001306 goto err_out;
1307
Sony Chacko79788452012-12-04 03:33:53 +00001308 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001309 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001310
1311 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001312 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001313 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001314
Sony Chackod4066832010-08-19 05:08:31 +00001315 err = qlcnic_pinit_from_rom(adapter);
1316 if (err)
1317 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001318
1319 err = qlcnic_load_firmware(adapter);
1320 if (err)
1321 goto err_out;
1322
1323 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001324 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001325
Sony Chackod4066832010-08-19 05:08:31 +00001326check_fw_status:
1327 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001328 if (err)
1329 goto err_out;
1330
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001331 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001332 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001333 err = qlcnic_check_eswitch_mode(adapter);
1334 if (err) {
1335 dev_err(&adapter->pdev->dev,
1336 "Memory allocation failed for eswitch\n");
1337 goto err_out;
1338 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001339 err = qlcnic_set_mgmt_operations(adapter);
1340 if (err)
1341 goto err_out;
1342
1343 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001344 adapter->need_fw_reset = 0;
1345
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001346 qlcnic_release_firmware(adapter);
1347 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001348
1349err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001350 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001351 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001352
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001353 qlcnic_release_firmware(adapter);
1354 return err;
1355}
1356
1357static int
1358qlcnic_request_irq(struct qlcnic_adapter *adapter)
1359{
1360 irq_handler_t handler;
1361 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001362 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001363 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001364
1365 unsigned long flags = 0;
1366 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001367 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001368
Sony Chacko79788452012-12-04 03:33:53 +00001369 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001370 if (qlcnic_82xx_check(adapter))
1371 handler = qlcnic_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001372 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1373 flags |= IRQF_SHARED;
1374
1375 } else {
1376 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1377 handler = qlcnic_msix_intr;
1378 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1379 handler = qlcnic_msi_intr;
1380 else {
1381 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001382 if (qlcnic_82xx_check(adapter))
1383 handler = qlcnic_intr;
1384 else
1385 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001386 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001387 }
1388 adapter->irq = netdev->irq;
1389
Sony Chacko13159182013-01-01 03:20:21 +00001390 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001391 if (qlcnic_82xx_check(adapter) ||
1392 (qlcnic_83xx_check(adapter) &&
1393 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001394 num_sds_rings = adapter->max_sds_rings;
1395 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001396 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001397 if (qlcnic_82xx_check(adapter) &&
1398 (ring == (num_sds_rings - 1)))
1399 snprintf(sds_ring->name,
1400 sizeof(sds_ring->name),
1401 "qlcnic-%s[Tx0+Rx%d]",
1402 netdev->name, ring);
1403 else
1404 snprintf(sds_ring->name,
1405 sizeof(sds_ring->name),
1406 "qlcnic-%s[Rx%d]",
1407 netdev->name, ring);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001408 err = request_irq(sds_ring->irq, handler, flags,
1409 sds_ring->name, sds_ring);
1410 if (err)
1411 return err;
1412 }
Sony Chacko13159182013-01-01 03:20:21 +00001413 }
1414 if (qlcnic_83xx_check(adapter) &&
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001415 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1416 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001417 handler = qlcnic_msix_tx_intr;
1418 for (ring = 0; ring < adapter->max_drv_tx_rings;
1419 ring++) {
1420 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001421 snprintf(tx_ring->name, sizeof(tx_ring->name),
1422 "qlcnic-%s[Tx%d]", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001423 err = request_irq(tx_ring->irq, handler, flags,
1424 tx_ring->name, tx_ring);
1425 if (err)
1426 return err;
1427 }
1428 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001429 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001430 return 0;
1431}
1432
1433static void
1434qlcnic_free_irq(struct qlcnic_adapter *adapter)
1435{
1436 int ring;
1437 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001438 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001439
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001440 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001441
Sony Chacko13159182013-01-01 03:20:21 +00001442 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001443 if (qlcnic_82xx_check(adapter) ||
1444 (qlcnic_83xx_check(adapter) &&
1445 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1446 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1447 sds_ring = &recv_ctx->sds_rings[ring];
1448 free_irq(sds_ring->irq, sds_ring);
1449 }
Sony Chacko13159182013-01-01 03:20:21 +00001450 }
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001451 if (qlcnic_83xx_check(adapter) &&
1452 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001453 for (ring = 0; ring < adapter->max_drv_tx_rings;
1454 ring++) {
1455 tx_ring = &adapter->tx_ring[ring];
1456 if (tx_ring->irq)
1457 free_irq(tx_ring->irq, tx_ring);
1458 }
1459 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001460 }
1461}
1462
Shahed Shaikh99e85872013-02-18 12:06:16 +00001463static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1464{
1465 u32 capab = 0;
1466
1467 if (qlcnic_82xx_check(adapter)) {
1468 if (adapter->ahw->capabilities2 &
1469 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1470 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1471 } else {
1472 capab = adapter->ahw->capabilities;
1473 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1474 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1475 }
1476}
1477
Sony Chacko319ecf12013-01-01 03:20:22 +00001478int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001479{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001480 int ring;
1481 struct qlcnic_host_rds_ring *rds_ring;
1482
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001483 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1484 return -EIO;
1485
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001486 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1487 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001488 if (qlcnic_set_eswitch_port_config(adapter))
1489 return -EIO;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001490 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001491
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001492 if (qlcnic_fw_create_ctx(adapter))
1493 return -EIO;
1494
1495 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001496 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001497 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001498 }
1499
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001500 qlcnic_set_multi(netdev);
1501 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1502
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001503 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001504
1505 if (adapter->max_sds_rings > 1)
1506 qlcnic_config_rss(adapter, 1);
1507
1508 qlcnic_config_intr_coalesce(adapter);
1509
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001510 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001511 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1512
1513 qlcnic_napi_enable(adapter);
1514
1515 qlcnic_linkevent_request(adapter, 1);
1516
Sony Chacko79788452012-12-04 03:33:53 +00001517 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001518 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1519 return 0;
1520}
1521
Sony Chacko629263a2013-01-01 04:11:55 +00001522int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001523{
1524 int err = 0;
1525
1526 rtnl_lock();
1527 if (netif_running(netdev))
1528 err = __qlcnic_up(adapter, netdev);
1529 rtnl_unlock();
1530
1531 return err;
1532}
1533
Sony Chacko319ecf12013-01-01 03:20:22 +00001534void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001535{
1536 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1537 return;
1538
1539 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1540 return;
1541
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001542 if (qlcnic_sriov_vf_check(adapter))
1543 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001544 smp_mb();
1545 spin_lock(&adapter->tx_clean_lock);
1546 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001547 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001548 netif_tx_disable(netdev);
1549
1550 qlcnic_free_mac_list(adapter);
1551
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001552 if (adapter->fhash.fnum)
1553 qlcnic_delete_lb_filters(adapter);
1554
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001555 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1556
1557 qlcnic_napi_disable(adapter);
1558
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001559 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001560 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001561
1562 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001563 qlcnic_release_tx_buffers(adapter);
1564 spin_unlock(&adapter->tx_clean_lock);
1565}
1566
1567/* Usage: During suspend and firmware recovery module */
1568
Sony Chacko629263a2013-01-01 04:11:55 +00001569void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001570{
1571 rtnl_lock();
1572 if (netif_running(netdev))
1573 __qlcnic_down(adapter, netdev);
1574 rtnl_unlock();
1575
1576}
1577
Sony Chacko319ecf12013-01-01 03:20:22 +00001578int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001579qlcnic_attach(struct qlcnic_adapter *adapter)
1580{
1581 struct net_device *netdev = adapter->netdev;
1582 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001583 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001584
1585 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1586 return 0;
1587
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001588 err = qlcnic_napi_add(adapter, netdev);
1589 if (err)
1590 return err;
1591
1592 err = qlcnic_alloc_sw_resources(adapter);
1593 if (err) {
1594 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001595 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001596 }
1597
1598 err = qlcnic_alloc_hw_resources(adapter);
1599 if (err) {
1600 dev_err(&pdev->dev, "Error in setting hw resources\n");
1601 goto err_out_free_sw;
1602 }
1603
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001604 err = qlcnic_request_irq(adapter);
1605 if (err) {
1606 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001607 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001608 }
1609
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001610 qlcnic_create_sysfs_entries(adapter);
1611
1612 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1613 return 0;
1614
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001615err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001616 qlcnic_free_hw_resources(adapter);
1617err_out_free_sw:
1618 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001619err_out_napi_del:
1620 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001621 return err;
1622}
1623
Sony Chacko319ecf12013-01-01 03:20:22 +00001624void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001625{
1626 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1627 return;
1628
1629 qlcnic_remove_sysfs_entries(adapter);
1630
1631 qlcnic_free_hw_resources(adapter);
1632 qlcnic_release_rx_buffers(adapter);
1633 qlcnic_free_irq(adapter);
1634 qlcnic_napi_del(adapter);
1635 qlcnic_free_sw_resources(adapter);
1636
1637 adapter->is_up = 0;
1638}
1639
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001640void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1641{
1642 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1643 struct qlcnic_host_sds_ring *sds_ring;
1644 int ring;
1645
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001646 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001647 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001648 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001649 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001650 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001651 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001652 }
1653
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001654 qlcnic_fw_destroy_ctx(adapter);
1655
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001656 qlcnic_detach(adapter);
1657
Sony Chacko79788452012-12-04 03:33:53 +00001658 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001659 adapter->max_sds_rings = max_sds_rings;
1660
1661 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001662 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001663
1664 if (netif_running(netdev))
1665 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001666out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001667 netif_device_attach(netdev);
1668}
1669
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001670static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1671{
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001672 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001673 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001674
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001675 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1676 GFP_KERNEL);
1677 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001678 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001679 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001680 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001681 /* Initialize interrupt coalesce parameters */
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001682 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1683 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1684 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1685 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1686 if (qlcnic_83xx_check(adapter)) {
1687 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1688 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1689 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001690 /* clear stats */
1691 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001692err_out:
1693 return err;
1694}
1695
1696static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1697{
1698 kfree(adapter->recv_ctx);
1699 adapter->recv_ctx = NULL;
1700
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001701 if (adapter->ahw->fw_dump.tmpl_hdr) {
1702 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1703 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1704 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001705
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001706 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001707 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001708}
1709
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001710int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1711{
1712 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1713 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001714 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001715 int ring;
1716 int ret;
1717
1718 netif_device_detach(netdev);
1719
1720 if (netif_running(netdev))
1721 __qlcnic_down(adapter, netdev);
1722
1723 qlcnic_detach(adapter);
1724
1725 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001726 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001727 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001728
1729 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001730 if (ret) {
1731 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001732 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001733 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001734
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001735 ret = qlcnic_fw_create_ctx(adapter);
1736 if (ret) {
1737 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001738 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001739 return ret;
1740 }
1741
1742 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001743 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001744 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001745 }
1746
Sony Chacko79788452012-12-04 03:33:53 +00001747 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001748 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001749 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001750 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001751 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001752 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001753
Sony Chacko79788452012-12-04 03:33:53 +00001754 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001755 adapter->ahw->loopback_state = 0;
1756 qlcnic_linkevent_request(adapter, 1);
1757 }
1758
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001759 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001760
1761 return 0;
1762}
1763
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001764/* Reset context in hardware only */
1765static int
1766qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1767{
1768 struct net_device *netdev = adapter->netdev;
1769
1770 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1771 return -EBUSY;
1772
1773 netif_device_detach(netdev);
1774
1775 qlcnic_down(adapter, netdev);
1776
1777 qlcnic_up(adapter, netdev);
1778
1779 netif_device_attach(netdev);
1780
1781 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001782 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001783 return 0;
1784}
1785
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001786int
1787qlcnic_reset_context(struct qlcnic_adapter *adapter)
1788{
1789 int err = 0;
1790 struct net_device *netdev = adapter->netdev;
1791
1792 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1793 return -EBUSY;
1794
1795 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1796
1797 netif_device_detach(netdev);
1798
1799 if (netif_running(netdev))
1800 __qlcnic_down(adapter, netdev);
1801
1802 qlcnic_detach(adapter);
1803
1804 if (netif_running(netdev)) {
1805 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001806 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001807 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001808 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1809 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001810 }
1811
1812 netif_device_attach(netdev);
1813 }
1814
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001815 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1816 return err;
1817}
1818
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001819int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001820qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1821 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001822{
1823 int err;
1824 struct pci_dev *pdev = adapter->pdev;
1825
Sony Chacko13159182013-01-01 03:20:21 +00001826 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001827 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001828 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001829
1830 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001831 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001832
1833 qlcnic_change_mtu(netdev, netdev->mtu);
1834
Rajesh Borundiad1a11052013-04-19 07:01:13 +00001835 if (qlcnic_sriov_vf_check(adapter))
1836 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops);
1837 else
1838 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001839
Sony Chacko7e38d042013-01-01 03:20:28 +00001840 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00001841 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00001842 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00001843 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1844 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001845
Sony Chacko13159182013-01-01 03:20:21 +00001846 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1847 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1848 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1849 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001850
Sony Chacko13159182013-01-01 03:20:21 +00001851 if (pci_using_dac) {
1852 netdev->features |= NETIF_F_HIGHDMA;
1853 netdev->vlan_features |= NETIF_F_HIGHDMA;
1854 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001855
Sony Chacko13159182013-01-01 03:20:21 +00001856 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00001857 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00001858
Rajesh Borundia91b72822013-04-19 07:01:12 +00001859 if (qlcnic_sriov_vf_check(adapter))
1860 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
1861
Sony Chacko79788452012-12-04 03:33:53 +00001862 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001863 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001864
Sony Chacko7e38d042013-01-01 03:20:28 +00001865 netdev->hw_features = netdev->features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001866 netdev->irq = adapter->msix_entries[0].vector;
1867
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001868 err = register_netdev(netdev);
1869 if (err) {
1870 dev_err(&pdev->dev, "failed to register net device\n");
1871 return err;
1872 }
1873
1874 return 0;
1875}
1876
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001877static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001878{
1879 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1880 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1881 *pci_using_dac = 1;
1882 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1883 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1884 *pci_using_dac = 0;
1885 else {
1886 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1887 return -EIO;
1888 }
1889
1890 return 0;
1891}
1892
Sony Chacko4be41e92013-01-01 03:20:20 +00001893void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1894{
1895 int ring;
1896 struct qlcnic_host_tx_ring *tx_ring;
1897
1898 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1899 tx_ring = &adapter->tx_ring[ring];
1900 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1901 vfree(tx_ring->cmd_buf_arr);
1902 tx_ring->cmd_buf_arr = NULL;
1903 }
1904 }
1905 if (adapter->tx_ring != NULL)
1906 kfree(adapter->tx_ring);
1907}
1908
1909int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1910 struct net_device *netdev)
1911{
Joe Perchesb2adaca2013-02-03 17:43:58 +00001912 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00001913 struct qlcnic_host_tx_ring *tx_ring;
1914 struct qlcnic_cmd_buffer *cmd_buf_arr;
1915
Joe Perchesb2adaca2013-02-03 17:43:58 +00001916 tx_ring = kcalloc(adapter->max_drv_tx_rings,
1917 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
1918 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00001919 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00001920
Sony Chacko4be41e92013-01-01 03:20:20 +00001921 adapter->tx_ring = tx_ring;
1922
1923 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1924 tx_ring = &adapter->tx_ring[ring];
1925 tx_ring->num_desc = adapter->num_txd;
1926 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1927 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1928 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001929 qlcnic_free_tx_rings(adapter);
1930 return -ENOMEM;
1931 }
1932 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1933 tx_ring->cmd_buf_arr = cmd_buf_arr;
1934 }
1935
1936 if (qlcnic_83xx_check(adapter)) {
1937 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1938 tx_ring = &adapter->tx_ring[ring];
1939 tx_ring->adapter = adapter;
1940 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1941 index = adapter->max_sds_rings + ring;
1942 vector = adapter->msix_entries[index].vector;
1943 tx_ring->irq = vector;
1944 }
1945 }
1946 }
1947 return 0;
1948}
1949
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001950static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001951qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1952{
1953 struct net_device *netdev = NULL;
1954 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001955 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001956 int err, pci_using_dac = -1;
Sritej Velagac84e3402013-01-25 10:20:34 +00001957 u32 capab2;
Dan Carpenter7bc48642013-01-30 22:14:10 +00001958 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001959
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001960 if (pdev->is_virtfn)
1961 return -ENODEV;
1962
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001963 err = pci_enable_device(pdev);
1964 if (err)
1965 return err;
1966
1967 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1968 err = -ENODEV;
1969 goto err_out_disable_pdev;
1970 }
1971
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001972 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1973 if (err)
1974 goto err_out_disable_pdev;
1975
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001976 err = pci_request_regions(pdev, qlcnic_driver_name);
1977 if (err)
1978 goto err_out_disable_pdev;
1979
1980 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001981 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001982
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001983 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00001984 if (!ahw) {
1985 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001986 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00001987 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001988
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001989 switch (ent->device) {
1990 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001991 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001992 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
1993 break;
1994 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +00001995 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001996 break;
1997 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
1998 qlcnic_sriov_vf_register_map(ahw);
1999 break;
2000 default:
Sony Chacko13159182013-01-01 03:20:21 +00002001 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002002 }
2003
2004 err = qlcnic_setup_pci_map(pdev, ahw);
2005 if (err)
2006 goto err_out_free_hw_res;
2007
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002008 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
2009 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002010 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002011 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002012 }
2013
2014 SET_NETDEV_DEV(netdev, &pdev->dev);
2015
2016 adapter = netdev_priv(netdev);
2017 adapter->netdev = netdev;
2018 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002019 adapter->ahw = ahw;
2020
2021 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2022 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002023 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002024 dev_err(&pdev->dev, "Failed to create workqueue\n");
2025 goto err_out_free_netdev;
2026 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002027
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002028 err = qlcnic_alloc_adapter_resources(adapter);
2029 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002030 goto err_out_free_netdev;
2031
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002032 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002033 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002034 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2035 adapter->fdb_mac_learn = true;
2036 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2037 adapter->drv_mac_learn = true;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002038 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002039
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002040 rwlock_init(&adapter->ahw->crb_lock);
2041 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002042
2043 spin_lock_init(&adapter->tx_clean_lock);
2044 INIT_LIST_HEAD(&adapter->mac_list);
2045
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002046 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002047 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002048 adapter->portnum = adapter->ahw->pci_func;
2049 err = qlcnic_start_firmware(adapter);
2050 if (err) {
2051 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
2052 goto err_out_free_hw;
2053 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002054
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002055 err = qlcnic_setup_idc_param(adapter);
2056 if (err)
2057 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002058
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002059 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00002060 } else if (qlcnic_83xx_check(adapter)) {
2061 qlcnic_83xx_check_vf(adapter, ent);
2062 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002063 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002064 if (err) {
2065 dev_err(&pdev->dev, "%s: failed\n", __func__);
2066 goto err_out_free_hw;
2067 }
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002068 if (qlcnic_sriov_vf_check(adapter))
2069 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002070 } else {
2071 dev_err(&pdev->dev,
2072 "%s: failed. Please Reboot\n", __func__);
2073 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002074 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002075
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002076 if (qlcnic_read_mac_addr(adapter))
2077 dev_warn(&pdev->dev, "failed to read mac addr\n");
2078
2079 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002080 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002081
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002082 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002083 module_name(THIS_MODULE),
2084 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002085 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002086
2087 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2088 !!qlcnic_use_msi)
2089 dev_warn(&pdev->dev,
2090 "83xx adapter do not support MSI interrupts\n");
2091
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002092 err = qlcnic_setup_intr(adapter, 0);
Manish chopra9a97e702013-01-25 10:20:37 +00002093 if (err) {
2094 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002095 goto err_out_disable_msi;
Manish chopra9a97e702013-01-25 10:20:37 +00002096 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002097
Sony Chacko13159182013-01-01 03:20:21 +00002098 if (qlcnic_83xx_check(adapter)) {
2099 err = qlcnic_83xx_setup_mbx_intr(adapter);
2100 if (err)
2101 goto err_out_disable_msi;
2102 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002103
Sony Chacko02135582013-05-21 09:26:59 +00002104 err = qlcnic_get_act_pci_func(adapter);
2105 if (err)
2106 goto err_out_disable_mbx_intr;
2107
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002108 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002109 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002110 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002111
Sritej Velagac84e3402013-01-25 10:20:34 +00002112 if (qlcnic_82xx_check(adapter)) {
2113 if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
2114 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
2115 if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB)
2116 qlcnic_fw_cmd_set_drv_version(adapter);
2117 }
2118 }
2119
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002120 pci_set_drvdata(pdev, adapter);
2121
Sony Chacko97ee45e2012-12-04 03:33:52 +00002122 if (qlcnic_82xx_check(adapter))
2123 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2124 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002125
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002126 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002127 case QLCNIC_GBE:
2128 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2129 adapter->netdev->name);
2130 break;
2131 case QLCNIC_XGBE:
2132 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2133 adapter->netdev->name);
2134 break;
2135 }
2136
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002137 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002138 qlcnic_alloc_lb_filters_mem(adapter);
2139
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002140 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002141
2142 return 0;
2143
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002144err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002145 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002146 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002147
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002148err_out_disable_msi:
2149 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002150 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002151 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002152
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002153err_out_free_hw:
2154 qlcnic_free_adapter_resources(adapter);
2155
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002156err_out_free_netdev:
2157 free_netdev(netdev);
2158
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002159err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002160 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002161
2162err_out_free_hw_res:
2163 kfree(ahw);
2164
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002165err_out_free_res:
2166 pci_release_regions(pdev);
2167
2168err_out_disable_pdev:
2169 pci_set_drvdata(pdev, NULL);
2170 pci_disable_device(pdev);
2171 return err;
2172}
2173
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002174static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002175{
2176 struct qlcnic_adapter *adapter;
2177 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002178 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002179
2180 adapter = pci_get_drvdata(pdev);
2181 if (adapter == NULL)
2182 return;
2183
2184 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002185 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002186
Sony Chacko13159182013-01-01 03:20:21 +00002187 qlcnic_cancel_idc_work(adapter);
2188 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002189
2190 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002191 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002192
Sony Chacko13159182013-01-01 03:20:21 +00002193 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002194 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002195 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2196 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00002197 }
2198
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002199 qlcnic_detach(adapter);
2200
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002201 if (adapter->npars != NULL)
2202 kfree(adapter->npars);
2203 if (adapter->eswitch != NULL)
2204 kfree(adapter->eswitch);
2205
Sony Chacko97ee45e2012-12-04 03:33:52 +00002206 if (qlcnic_82xx_check(adapter))
2207 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002208
2209 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2210
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002211 qlcnic_free_lb_filters_mem(adapter);
2212
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002213 qlcnic_teardown_intr(adapter);
2214
Sony Chacko13159182013-01-01 03:20:21 +00002215 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002216
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002217 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002218
2219 qlcnic_release_firmware(adapter);
2220
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002221 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002222 pci_release_regions(pdev);
2223 pci_disable_device(pdev);
2224 pci_set_drvdata(pdev, NULL);
2225
Sony Chacko13159182013-01-01 03:20:21 +00002226 if (adapter->qlcnic_wq) {
2227 destroy_workqueue(adapter->qlcnic_wq);
2228 adapter->qlcnic_wq = NULL;
2229 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002230 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002231 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002232 free_netdev(netdev);
2233}
2234static int __qlcnic_shutdown(struct pci_dev *pdev)
2235{
2236 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2237 struct net_device *netdev = adapter->netdev;
2238 int retval;
2239
2240 netif_device_detach(netdev);
2241
Sony Chacko13159182013-01-01 03:20:21 +00002242 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002243
2244 if (netif_running(netdev))
2245 qlcnic_down(adapter, netdev);
2246
Rajesh Borundia97d81052013-04-19 07:01:09 +00002247 qlcnic_sriov_cleanup(adapter);
Sony Chacko97ee45e2012-12-04 03:33:52 +00002248 if (qlcnic_82xx_check(adapter))
2249 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002250
2251 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2252
2253 retval = pci_save_state(pdev);
2254 if (retval)
2255 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002256 if (qlcnic_82xx_check(adapter)) {
2257 if (qlcnic_wol_supported(adapter)) {
2258 pci_enable_wake(pdev, PCI_D3cold, 1);
2259 pci_enable_wake(pdev, PCI_D3hot, 1);
2260 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002261 }
2262
2263 return 0;
2264}
2265
2266static void qlcnic_shutdown(struct pci_dev *pdev)
2267{
2268 if (__qlcnic_shutdown(pdev))
2269 return;
2270
2271 pci_disable_device(pdev);
2272}
2273
2274#ifdef CONFIG_PM
2275static int
2276qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2277{
2278 int retval;
2279
2280 retval = __qlcnic_shutdown(pdev);
2281 if (retval)
2282 return retval;
2283
2284 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2285 return 0;
2286}
2287
2288static int
2289qlcnic_resume(struct pci_dev *pdev)
2290{
2291 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2292 struct net_device *netdev = adapter->netdev;
2293 int err;
2294
2295 err = pci_enable_device(pdev);
2296 if (err)
2297 return err;
2298
2299 pci_set_power_state(pdev, PCI_D0);
2300 pci_set_master(pdev);
2301 pci_restore_state(pdev);
2302
Sony Chacko13159182013-01-01 03:20:21 +00002303 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002304 if (err) {
2305 dev_err(&pdev->dev, "failed to start firmware\n");
2306 return err;
2307 }
2308
2309 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002310 err = qlcnic_up(adapter, netdev);
2311 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002312 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002313
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002314 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002315 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002316done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002317 netif_device_attach(netdev);
2318 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2319 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002320}
2321#endif
2322
2323static int qlcnic_open(struct net_device *netdev)
2324{
2325 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2326 int err;
2327
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002328 netif_carrier_off(netdev);
2329
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002330 err = qlcnic_attach(adapter);
2331 if (err)
2332 return err;
2333
2334 err = __qlcnic_up(adapter, netdev);
2335 if (err)
2336 goto err_out;
2337
2338 netif_start_queue(netdev);
2339
2340 return 0;
2341
2342err_out:
2343 qlcnic_detach(adapter);
2344 return err;
2345}
2346
2347/*
2348 * qlcnic_close - Disables a network interface entry point
2349 */
2350static int qlcnic_close(struct net_device *netdev)
2351{
2352 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2353
2354 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002355
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002356 return 0;
2357}
2358
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002359void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002360{
2361 void *head;
2362 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002363 struct net_device *netdev = adapter->netdev;
2364 u32 filter_size = 0;
2365 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002366
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002367 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002368 return;
2369
Sony Chacko13159182013-01-01 03:20:21 +00002370 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002371 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002372 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002373
Sony Chacko13159182013-01-01 03:20:21 +00002374 if (qlcnic_82xx_check(adapter)) {
2375 filter_size = QLCNIC_LB_MAX_FILTERS;
2376 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2377 } else {
2378 filter_size = QLC_83XX_LB_MAX_FILTERS;
2379 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2380 }
2381
2382 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002383 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002384
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002385 if (!head)
2386 return;
2387
Sony Chacko13159182013-01-01 03:20:21 +00002388 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002389 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002390
Sony Chacko13159182013-01-01 03:20:21 +00002391 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2392 act_pci_func, adapter->fhash.fmax);
2393
2394 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002395 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002396
2397 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2398
2399 head = kcalloc(adapter->rx_fhash.fbucket_size,
2400 sizeof(struct hlist_head), GFP_ATOMIC);
2401
2402 if (!head)
2403 return;
2404
2405 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2406 adapter->rx_fhash.fhead = head;
2407
2408 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2409 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002410}
2411
2412static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2413{
2414 if (adapter->fhash.fmax && adapter->fhash.fhead)
2415 kfree(adapter->fhash.fhead);
2416
2417 adapter->fhash.fhead = NULL;
2418 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002419
2420 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2421 kfree(adapter->rx_fhash.fhead);
2422
2423 adapter->rx_fhash.fmax = 0;
2424 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002425}
2426
Sony Chacko629263a2013-01-01 04:11:55 +00002427int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002428{
2429 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002430 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002431 int rv = 0;
2432
Sony Chacko13159182013-01-01 03:20:21 +00002433 if (qlcnic_83xx_check(adapter))
2434 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2435
Sony Chacko97ee45e2012-12-04 03:33:52 +00002436 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002437 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002438
2439 temp_state = qlcnic_get_temp_state(temp);
2440 temp_val = qlcnic_get_temp_val(temp);
2441
2442 if (temp_state == QLCNIC_TEMP_PANIC) {
2443 dev_err(&netdev->dev,
2444 "Device temperature %d degrees C exceeds"
2445 " maximum allowed. Hardware has been shut down.\n",
2446 temp_val);
2447 rv = 1;
2448 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002449 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002450 dev_err(&netdev->dev,
2451 "Device temperature %d degrees C "
2452 "exceeds operating range."
2453 " Immediate action needed.\n",
2454 temp_val);
2455 }
2456 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002457 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002458 dev_info(&netdev->dev,
2459 "Device temperature is now %d degrees C"
2460 " in normal range.\n", temp_val);
2461 }
2462 }
Sony Chacko79788452012-12-04 03:33:53 +00002463 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002464 return rv;
2465}
2466
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002467static void qlcnic_tx_timeout(struct net_device *netdev)
2468{
2469 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2470
2471 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2472 return;
2473
Sony Chacko536faa62013-05-09 09:25:13 +00002474 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
2475 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
2476 if (qlcnic_82xx_check(adapter))
2477 adapter->need_fw_reset = 1;
2478 else if (qlcnic_83xx_check(adapter))
2479 qlcnic_83xx_idc_request_reset(adapter,
2480 QLCNIC_FORCE_FW_DUMP_KEY);
2481 } else {
2482 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Sony Chacko79788452012-12-04 03:33:53 +00002483 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00002484 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002485}
2486
2487static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2488{
2489 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2490 struct net_device_stats *stats = &netdev->stats;
2491
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002492 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2493 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002494 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002495 stats->tx_bytes = adapter->stats.txbytes;
2496 stats->rx_dropped = adapter->stats.rxdropped;
2497 stats->tx_dropped = adapter->stats.txdropped;
2498
2499 return stats;
2500}
2501
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002502irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002503{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002504 u32 status;
2505
2506 status = readl(adapter->isr_int_vec);
2507
Sony Chacko79788452012-12-04 03:33:53 +00002508 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002509 return IRQ_NONE;
2510
2511 /* check interrupt state machine, to be sure */
2512 status = readl(adapter->crb_int_state_reg);
2513 if (!ISR_LEGACY_INT_TRIGGERED(status))
2514 return IRQ_NONE;
2515
2516 writel(0xffffffff, adapter->tgt_status_reg);
2517 /* read twice to ensure write is flushed */
2518 readl(adapter->isr_int_vec);
2519 readl(adapter->isr_int_vec);
2520
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002521 return IRQ_HANDLED;
2522}
2523
2524static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2525{
2526 struct qlcnic_host_sds_ring *sds_ring = data;
2527 struct qlcnic_adapter *adapter = sds_ring->adapter;
2528
2529 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2530 goto done;
2531 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2532 writel(0xffffffff, adapter->tgt_status_reg);
2533 goto done;
2534 }
2535
2536 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2537 return IRQ_NONE;
2538
2539done:
Sony Chacko79788452012-12-04 03:33:53 +00002540 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002541 qlcnic_enable_int(sds_ring);
2542 return IRQ_HANDLED;
2543}
2544
2545static irqreturn_t qlcnic_intr(int irq, void *data)
2546{
2547 struct qlcnic_host_sds_ring *sds_ring = data;
2548 struct qlcnic_adapter *adapter = sds_ring->adapter;
2549
2550 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2551 return IRQ_NONE;
2552
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002553 napi_schedule(&sds_ring->napi);
2554
2555 return IRQ_HANDLED;
2556}
2557
2558static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2559{
2560 struct qlcnic_host_sds_ring *sds_ring = data;
2561 struct qlcnic_adapter *adapter = sds_ring->adapter;
2562
2563 /* clear interrupt */
2564 writel(0xffffffff, adapter->tgt_status_reg);
2565
2566 napi_schedule(&sds_ring->napi);
2567 return IRQ_HANDLED;
2568}
2569
2570static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2571{
2572 struct qlcnic_host_sds_ring *sds_ring = data;
2573
2574 napi_schedule(&sds_ring->napi);
2575 return IRQ_HANDLED;
2576}
2577
Sony Chacko13159182013-01-01 03:20:21 +00002578static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2579{
2580 struct qlcnic_host_tx_ring *tx_ring = data;
2581
2582 napi_schedule(&tx_ring->napi);
2583 return IRQ_HANDLED;
2584}
2585
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002586#ifdef CONFIG_NET_POLL_CONTROLLER
2587static void qlcnic_poll_controller(struct net_device *netdev)
2588{
Yinglin Luanbf827912010-08-22 21:57:56 +00002589 int ring;
2590 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002591 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002592 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002593
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002594 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002595 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2596 sds_ring = &recv_ctx->sds_rings[ring];
2597 qlcnic_intr(adapter->irq, sds_ring);
2598 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002599 enable_irq(adapter->irq);
2600}
2601#endif
2602
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002603static void
2604qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2605{
2606 u32 val;
2607
2608 val = adapter->portnum & 0xf;
2609 val |= encoding << 7;
2610 val |= (jiffies - adapter->dev_rst_time) << 8;
2611
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002612 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002613 adapter->dev_rst_time = jiffies;
2614}
2615
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002616static int
2617qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002618{
2619 u32 val;
2620
2621 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2622 state != QLCNIC_DEV_NEED_QUISCENT);
2623
2624 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002625 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002626
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002627 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002628
2629 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002630 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002631 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002632 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002633
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002634 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002635
2636 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002637
2638 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002639}
2640
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002641static int
2642qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2643{
2644 u32 val;
2645
2646 if (qlcnic_api_lock(adapter))
2647 return -EBUSY;
2648
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002649 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002650 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002651 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002652
2653 qlcnic_api_unlock(adapter);
2654
2655 return 0;
2656}
2657
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002658static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002659qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002660{
2661 u32 val;
2662
2663 if (qlcnic_api_lock(adapter))
2664 goto err;
2665
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002666 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002667 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002668 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002669
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002670 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002671 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2672 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002673 dev_info(&adapter->pdev->dev,
2674 "Device state set to Failed. Please Reboot\n");
2675 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002676 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2677 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002678
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002679 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002680 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002681 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002682
2683 qlcnic_api_unlock(adapter);
2684err:
2685 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002686 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002687 clear_bit(__QLCNIC_START_FW, &adapter->state);
2688 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2689}
2690
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002691/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002692static int
2693qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2694{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002695 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002696 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002697
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002698 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2699 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002700
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002701 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002702 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002703 act = act & active_mask;
2704 }
2705
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002706 if (((state & 0x11111111) == (act & 0x11111111)) ||
2707 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2708 return 0;
2709 else
2710 return 1;
2711}
2712
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002713static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2714{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002715 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002716
2717 if (val != QLCNIC_DRV_IDC_VER) {
2718 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2719 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2720 }
2721
2722 return 0;
2723}
2724
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002725static int
2726qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2727{
2728 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002729 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002730 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002731 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002732
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002733 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2734 return 1;
2735
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002736 if (qlcnic_api_lock(adapter))
2737 return -1;
2738
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002739 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002740 if (!(val & (1 << (portnum * 4)))) {
2741 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002742 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002743 }
2744
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002745 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002746 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002747
2748 switch (prev_state) {
2749 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002750 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2751 QLCNIC_DEV_INITIALIZING);
2752 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2753 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002754 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002755 qlcnic_api_unlock(adapter);
2756 return 1;
2757
2758 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002759 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002760 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002761 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002762
2763 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002764 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002765 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002766 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002767 break;
2768
2769 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002770 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002771 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002772 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002773 break;
2774
2775 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002776 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002777 qlcnic_api_unlock(adapter);
2778 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002779
2780 case QLCNIC_DEV_INITIALIZING:
2781 case QLCNIC_DEV_QUISCENT:
2782 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002783 }
2784
2785 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002786
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002787 do {
2788 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002789 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002790
2791 if (prev_state == QLCNIC_DEV_QUISCENT)
2792 continue;
2793 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002794
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002795 if (!dev_init_timeo) {
2796 dev_err(&adapter->pdev->dev,
2797 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002798 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002799 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002800
2801 if (qlcnic_api_lock(adapter))
2802 return -1;
2803
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002804 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002805 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002806 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002807
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002808 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002809 qlcnic_api_unlock(adapter);
2810
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002811 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002812}
2813
2814static void
2815qlcnic_fwinit_work(struct work_struct *work)
2816{
2817 struct qlcnic_adapter *adapter = container_of(work,
2818 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002819 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002820 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002821
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002822 if (qlcnic_api_lock(adapter))
2823 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002824
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002825 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002826 if (dev_state == QLCNIC_DEV_QUISCENT ||
2827 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002828 qlcnic_api_unlock(adapter);
2829 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2830 FW_POLL_DELAY * 2);
2831 return;
2832 }
2833
Sony Chacko79788452012-12-04 03:33:53 +00002834 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002835 qlcnic_api_unlock(adapter);
2836 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002837 }
2838
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002839 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2840 dev_state == QLCNIC_DEV_READY) {
2841 dev_info(&adapter->pdev->dev, "Detected state change from "
2842 "DEV_NEED_RESET, skipping ack check\n");
2843 goto skip_ack_check;
2844 }
2845
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002846 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002847 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002848 adapter->reset_ack_timeo);
2849 goto skip_ack_check;
2850 }
2851
2852 if (!qlcnic_check_drv_state(adapter)) {
2853skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002854 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002855
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002856 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002857 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2858 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002859 set_bit(__QLCNIC_START_FW, &adapter->state);
2860 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002861 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002862 val = QLC_SHARED_REG_RD32(adapter,
2863 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002864 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002865 QLC_SHARED_REG_WR32(adapter,
2866 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002867 }
2868
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002869 qlcnic_api_unlock(adapter);
2870
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002871 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002872 if (adapter->ahw->fw_dump.enable &&
2873 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002874 QLCDB(adapter, DRV, "Take FW dump\n");
2875 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002876 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002877 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002878 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002879
2880 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002881 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002882 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002883 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002884 return;
2885 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002886 goto err_ret;
2887 }
2888
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002889 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002890
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002891wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002892 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002893 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002894
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002895 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002896 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002897 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002898 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002899 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002900 return;
2901 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002902 case QLCNIC_DEV_FAILED:
2903 break;
2904 default:
2905 qlcnic_schedule_work(adapter,
2906 qlcnic_fwinit_work, FW_POLL_DELAY);
2907 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002908 }
2909
2910err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002911 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2912 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002913 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002914 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002915}
2916
2917static void
2918qlcnic_detach_work(struct work_struct *work)
2919{
2920 struct qlcnic_adapter *adapter = container_of(work,
2921 struct qlcnic_adapter, fw_work.work);
2922 struct net_device *netdev = adapter->netdev;
2923 u32 status;
2924
2925 netif_device_detach(netdev);
2926
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002927 /* Dont grab rtnl lock during Quiscent mode */
2928 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2929 if (netif_running(netdev))
2930 __qlcnic_down(adapter, netdev);
2931 } else
2932 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002933
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002934 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002935
Sony Chacko44f65b22011-08-29 12:50:26 +00002936 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2937 dev_err(&adapter->pdev->dev,
2938 "Detaching the device: peg halt status1=0x%x\n",
2939 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002940
Sony Chacko44f65b22011-08-29 12:50:26 +00002941 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2942 dev_err(&adapter->pdev->dev,
2943 "On board active cooling fan failed. "
2944 "Device has been halted.\n");
2945 dev_err(&adapter->pdev->dev,
2946 "Replace the adapter.\n");
2947 }
2948
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002949 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002950 }
2951
Sony Chacko79788452012-12-04 03:33:53 +00002952 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002953 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002954 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002955 goto err_ret;
2956 }
2957
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002958 /* Dont ack if this instance is the reset owner */
2959 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002960 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2961 dev_err(&adapter->pdev->dev,
2962 "Failed to set driver state,"
2963 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002964 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002965 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002966 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002967
2968 adapter->fw_wait_cnt = 0;
2969
2970 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2971
2972 return;
2973
2974err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002975 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002976 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002977}
2978
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002979/*Transit NPAR state to NON Operational */
2980static void
2981qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2982{
2983 u32 state;
2984
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002985 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002986 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2987 return;
2988
2989 if (qlcnic_api_lock(adapter))
2990 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002991 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2992 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002993 qlcnic_api_unlock(adapter);
2994}
2995
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002996void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002997{
Sritej Velaga646779f2012-02-03 13:45:41 +00002998 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002999
Sritej Velaga646779f2012-02-03 13:45:41 +00003000 qlcnic_xg_set_xg0_mask(xg_val);
3001 qlcnic_xg_set_xg1_mask(xg_val);
3002 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3003 qlcnic_gb_set_gb0_mask(gb_val);
3004 qlcnic_gb_set_gb1_mask(gb_val);
3005 qlcnic_gb_set_gb2_mask(gb_val);
3006 qlcnic_gb_set_gb3_mask(gb_val);
3007 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3008 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3009 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003010 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003011
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003012 if (qlcnic_api_lock(adapter))
3013 return;
3014
Sony Chacko13159182013-01-01 03:20:21 +00003015 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003016
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003017 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003018 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3019 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003020 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003021 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003022 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003023 }
3024
Sony Chacko13159182013-01-01 03:20:21 +00003025 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3026 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003027 qlcnic_api_unlock(adapter);
3028}
3029
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003030/* Transit to NPAR READY state from NPAR NOT READY state */
3031static void
3032qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3033{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003034 if (qlcnic_api_lock(adapter))
3035 return;
3036
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003037 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3038 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003039 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003040
3041 qlcnic_api_unlock(adapter);
3042}
3043
Sony Chacko13159182013-01-01 03:20:21 +00003044void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3045 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003046{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003047 if (test_bit(__QLCNIC_AER, &adapter->state))
3048 return;
3049
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003050 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003051 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3052 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003053}
3054
3055static void
3056qlcnic_attach_work(struct work_struct *work)
3057{
3058 struct qlcnic_adapter *adapter = container_of(work,
3059 struct qlcnic_adapter, fw_work.work);
3060 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003061 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003062
Sony Chacko79788452012-12-04 03:33:53 +00003063 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003064 npar_state = QLC_SHARED_REG_RD32(adapter,
3065 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003066 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3067 qlcnic_clr_all_drv_state(adapter, 0);
3068 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3069 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3070 FW_POLL_DELAY);
3071 else
3072 goto attach;
3073 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3074 return;
3075 }
3076attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003077 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003078 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003079 goto done;
3080
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003081 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003082 }
3083
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003084done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003085 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003086 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003087 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003088 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003089
3090 if (!qlcnic_clr_drv_state(adapter))
3091 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3092 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003093}
3094
3095static int
3096qlcnic_check_health(struct qlcnic_adapter *adapter)
3097{
Sony Chacko4e708122010-08-31 17:17:44 +00003098 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003099 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003100
3101 if (qlcnic_check_temp(adapter))
3102 goto detach;
3103
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003104 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003105 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003106
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003107 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003108 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003109 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003110 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003111 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3112 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003113
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003114 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003115 if (heartbeat != adapter->heartbeat) {
3116 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003117 adapter->fw_fail_cnt = 0;
3118 if (adapter->need_fw_reset)
3119 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003120
Sony Chacko0ce54ce2013-05-21 09:27:00 +00003121 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003122 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003123
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003124 return 0;
3125 }
3126
3127 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3128 return 0;
3129
Sritej Velaga032a13c2011-07-29 13:30:27 +00003130 adapter->flags |= QLCNIC_FW_HANG;
3131
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003132 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003133
Sony Chacko099f7aa2012-12-04 03:33:58 +00003134 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003135 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003136
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003137 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003138 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003139 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003140 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3141 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3142 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3143 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003144 peg_status,
3145 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00003146 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3147 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3148 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3149 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3150 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00003151 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003152 dev_err(&adapter->pdev->dev,
3153 "Firmware aborted with error code 0x00006700. "
3154 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003155detach:
3156 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3157 QLCNIC_DEV_NEED_RESET;
3158
Sony Chacko099f7aa2012-12-04 03:33:58 +00003159 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3160 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003161
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003162 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003163 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3164 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003165
3166 return 1;
3167}
3168
3169static void
3170qlcnic_fw_poll_work(struct work_struct *work)
3171{
3172 struct qlcnic_adapter *adapter = container_of(work,
3173 struct qlcnic_adapter, fw_work.work);
3174
3175 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3176 goto reschedule;
3177
3178
3179 if (qlcnic_check_health(adapter))
3180 return;
3181
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003182 if (adapter->fhash.fnum)
3183 qlcnic_prune_lb_filters(adapter);
3184
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003185reschedule:
3186 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3187}
3188
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003189static int qlcnic_is_first_func(struct pci_dev *pdev)
3190{
3191 struct pci_dev *oth_pdev;
3192 int val = pdev->devfn;
3193
3194 while (val-- > 0) {
3195 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3196 (pdev->bus), pdev->bus->number,
3197 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003198 if (!oth_pdev)
3199 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003200
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003201 if (oth_pdev->current_state != PCI_D3cold) {
3202 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003203 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003204 }
3205 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003206 }
3207 return 1;
3208}
3209
3210static int qlcnic_attach_func(struct pci_dev *pdev)
3211{
3212 int err, first_func;
3213 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3214 struct net_device *netdev = adapter->netdev;
3215
3216 pdev->error_state = pci_channel_io_normal;
3217
3218 err = pci_enable_device(pdev);
3219 if (err)
3220 return err;
3221
3222 pci_set_power_state(pdev, PCI_D0);
3223 pci_set_master(pdev);
3224 pci_restore_state(pdev);
3225
3226 first_func = qlcnic_is_first_func(pdev);
3227
3228 if (qlcnic_api_lock(adapter))
3229 return -EINVAL;
3230
Sony Chacko79788452012-12-04 03:33:53 +00003231 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003232 adapter->need_fw_reset = 1;
3233 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003234 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3235 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003236 QLCDB(adapter, DRV, "Restarting fw\n");
3237 }
3238 qlcnic_api_unlock(adapter);
3239
Sony Chacko13159182013-01-01 03:20:21 +00003240 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003241 if (err)
3242 return err;
3243
3244 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003245 kfree(adapter->msix_entries);
3246 adapter->msix_entries = NULL;
3247 err = qlcnic_setup_intr(adapter, 0);
3248
Manish chopra9a97e702013-01-25 10:20:37 +00003249 if (err) {
3250 kfree(adapter->msix_entries);
3251 netdev_err(netdev, "failed to setup interrupt\n");
3252 return err;
3253 }
3254
Sony Chacko13159182013-01-01 03:20:21 +00003255 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003256 /* register for NIC IDC AEN Events */
3257 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003258 err = qlcnic_83xx_setup_mbx_intr(adapter);
3259 if (err) {
3260 dev_err(&adapter->pdev->dev,
3261 "failed to setup mbx interrupt\n");
3262 qlcnic_clr_all_drv_state(adapter, 1);
3263 clear_bit(__QLCNIC_AER, &adapter->state);
3264 goto done;
3265 }
3266 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003267
3268 if (netif_running(netdev)) {
3269 err = qlcnic_attach(adapter);
3270 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003271 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003272 clear_bit(__QLCNIC_AER, &adapter->state);
3273 netif_device_attach(netdev);
3274 return err;
3275 }
3276
3277 err = qlcnic_up(adapter, netdev);
3278 if (err)
3279 goto done;
3280
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003281 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003282 }
3283 done:
3284 netif_device_attach(netdev);
3285 return err;
3286}
3287
3288static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3289 pci_channel_state_t state)
3290{
3291 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3292 struct net_device *netdev = adapter->netdev;
3293
3294 if (state == pci_channel_io_perm_failure)
3295 return PCI_ERS_RESULT_DISCONNECT;
3296
3297 if (state == pci_channel_io_normal)
3298 return PCI_ERS_RESULT_RECOVERED;
3299
3300 set_bit(__QLCNIC_AER, &adapter->state);
3301 netif_device_detach(netdev);
3302
3303 cancel_delayed_work_sync(&adapter->fw_work);
3304
3305 if (netif_running(netdev))
3306 qlcnic_down(adapter, netdev);
3307
Sony Chacko13159182013-01-01 03:20:21 +00003308 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003309 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00003310 qlcnic_83xx_register_nic_idc_func(adapter, 0);
3311 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00003312 }
3313
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003314 qlcnic_detach(adapter);
3315 qlcnic_teardown_intr(adapter);
3316
3317 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3318
3319 pci_save_state(pdev);
3320 pci_disable_device(pdev);
3321
3322 return PCI_ERS_RESULT_NEED_RESET;
3323}
3324
3325static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3326{
3327 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3328 PCI_ERS_RESULT_RECOVERED;
3329}
3330
3331static void qlcnic_io_resume(struct pci_dev *pdev)
3332{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003333 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003334 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3335
3336 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003337 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3338 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3339 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003340 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3341 FW_POLL_DELAY);
3342}
3343
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003344static int
3345qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3346{
3347 int err;
3348
3349 err = qlcnic_can_start_firmware(adapter);
3350 if (err)
3351 return err;
3352
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003353 err = qlcnic_check_npar_opertional(adapter);
3354 if (err)
3355 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003356
Rajesh Borundia174240a2010-08-31 17:17:47 +00003357 err = qlcnic_initialize_nic(adapter);
3358 if (err)
3359 return err;
3360
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003361 qlcnic_check_options(adapter);
3362
Rajesh Borundia73733732010-08-31 17:17:50 +00003363 err = qlcnic_set_eswitch_port_config(adapter);
3364 if (err)
3365 return err;
3366
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003367 adapter->need_fw_reset = 0;
3368
3369 return err;
3370}
3371
Manish Chopra6389b762013-04-24 12:42:39 +00003372int qlcnic_validate_max_rss(struct qlcnic_adapter *adapter,
3373 __u32 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003374{
Manish Chopra6389b762013-04-24 12:42:39 +00003375 struct net_device *netdev = adapter->netdev;
3376 u8 max_hw = adapter->ahw->max_rx_ques;
Sony Chacko319ecf12013-01-01 03:20:22 +00003377 u32 max_allowed;
3378
Manish Chopra6389b762013-04-24 12:42:39 +00003379 if (val > QLC_MAX_SDS_RINGS) {
3380 netdev_err(netdev, "RSS value should not be higher than %u\n",
3381 QLC_MAX_SDS_RINGS);
3382 return -EINVAL;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003383 }
3384
Sony Chacko319ecf12013-01-01 03:20:22 +00003385 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3386 num_online_cpus()));
3387 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
Manish Chopra6389b762013-04-24 12:42:39 +00003388 if (!is_power_of_2(val))
3389 netdev_err(netdev, "RSS value should be a power of 2\n");
3390
3391 if (val < 2)
3392 netdev_err(netdev, "RSS value should not be lower than 2\n");
3393
3394 if (val > max_hw)
3395 netdev_err(netdev,
3396 "RSS value should not be higher than[%u], the max RSS rings supported by the adapter\n",
3397 max_hw);
3398
3399 if (val > num_online_cpus())
3400 netdev_err(netdev,
3401 "RSS value should not be higher than[%u], number of online CPUs in the system\n",
3402 num_online_cpus());
3403
3404 netdev_err(netdev, "Unable to configure %u RSS rings\n", val);
3405
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003406 return -EINVAL;
3407 }
3408 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003409}
3410
Sony Chacko319ecf12013-01-01 03:20:22 +00003411int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003412{
Sony Chacko13159182013-01-01 03:20:21 +00003413 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003414 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003415
Sony Chacko319ecf12013-01-01 03:20:22 +00003416 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3417 return -EBUSY;
3418
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003419 netif_device_detach(netdev);
3420 if (netif_running(netdev))
3421 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003422
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003423 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003424
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003425 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003426 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003427 qlcnic_83xx_enable_mbx_poll(adapter);
3428 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003429
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003430 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003431 err = qlcnic_setup_intr(adapter, data);
Manish chopra9a97e702013-01-25 10:20:37 +00003432 if (err) {
3433 kfree(adapter->msix_entries);
3434 netdev_err(netdev, "failed to setup interrupt\n");
3435 return err;
3436 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003437
Sony Chacko13159182013-01-01 03:20:21 +00003438 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003439 /* register for NIC IDC AEN Events */
3440 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003441 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003442 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003443 if (err) {
3444 dev_err(&adapter->pdev->dev,
3445 "failed to setup mbx interrupt\n");
3446 goto done;
3447 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003448 }
3449
3450 if (netif_running(netdev)) {
3451 err = qlcnic_attach(adapter);
3452 if (err)
3453 goto done;
3454 err = __qlcnic_up(adapter, netdev);
3455 if (err)
3456 goto done;
3457 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3458 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003459 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003460 done:
3461 netif_device_attach(netdev);
3462 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3463 return err;
3464}
3465
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003466#ifdef CONFIG_INET
3467
3468#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3469
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003470static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003471qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3472 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003473{
3474 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003475
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003476 indev = in_dev_get(dev);
3477 if (!indev)
3478 return;
3479
3480 for_ifa(indev) {
3481 switch (event) {
3482 case NETDEV_UP:
3483 qlcnic_config_ipaddr(adapter,
3484 ifa->ifa_address, QLCNIC_IP_UP);
3485 break;
3486 case NETDEV_DOWN:
3487 qlcnic_config_ipaddr(adapter,
3488 ifa->ifa_address, QLCNIC_IP_DOWN);
3489 break;
3490 default:
3491 break;
3492 }
3493 } endfor_ifa(indev);
3494
3495 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003496}
3497
Sony Chacko319ecf12013-01-01 03:20:22 +00003498void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003499{
3500 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3501 struct net_device *dev;
3502 u16 vid;
3503
3504 qlcnic_config_indev_addr(adapter, netdev, event);
3505
Jiri Pirko43c00a72013-01-03 22:48:57 +00003506 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003507 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003508 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003509 if (!dev)
3510 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003511 qlcnic_config_indev_addr(adapter, dev, event);
3512 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003513 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003514}
3515
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003516static int qlcnic_netdev_event(struct notifier_block *this,
3517 unsigned long event, void *ptr)
3518{
3519 struct qlcnic_adapter *adapter;
3520 struct net_device *dev = (struct net_device *)ptr;
3521
3522recheck:
3523 if (dev == NULL)
3524 goto done;
3525
3526 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3527 dev = vlan_dev_real_dev(dev);
3528 goto recheck;
3529 }
3530
3531 if (!is_qlcnic_netdev(dev))
3532 goto done;
3533
3534 adapter = netdev_priv(dev);
3535
3536 if (!adapter)
3537 goto done;
3538
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003539 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003540 goto done;
3541
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003542 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003543done:
3544 return NOTIFY_DONE;
3545}
3546
3547static int
3548qlcnic_inetaddr_event(struct notifier_block *this,
3549 unsigned long event, void *ptr)
3550{
3551 struct qlcnic_adapter *adapter;
3552 struct net_device *dev;
3553
3554 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3555
3556 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3557
3558recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003559 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003560 goto done;
3561
3562 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3563 dev = vlan_dev_real_dev(dev);
3564 goto recheck;
3565 }
3566
3567 if (!is_qlcnic_netdev(dev))
3568 goto done;
3569
3570 adapter = netdev_priv(dev);
3571
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003572 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003573 goto done;
3574
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003575 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003576 goto done;
3577
3578 switch (event) {
3579 case NETDEV_UP:
3580 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003581
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003582 break;
3583 case NETDEV_DOWN:
3584 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003585
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003586 break;
3587 default:
3588 break;
3589 }
3590
3591done:
3592 return NOTIFY_DONE;
3593}
3594
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003595static struct notifier_block qlcnic_netdev_cb = {
3596 .notifier_call = qlcnic_netdev_event,
3597};
3598
3599static struct notifier_block qlcnic_inetaddr_cb = {
3600 .notifier_call = qlcnic_inetaddr_event,
3601};
3602#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003603void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003604{ }
3605#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003606static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003607 .error_detected = qlcnic_io_error_detected,
3608 .slot_reset = qlcnic_io_slot_reset,
3609 .resume = qlcnic_io_resume,
3610};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003611
3612static struct pci_driver qlcnic_driver = {
3613 .name = qlcnic_driver_name,
3614 .id_table = qlcnic_pci_tbl,
3615 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003616 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003617#ifdef CONFIG_PM
3618 .suspend = qlcnic_suspend,
3619 .resume = qlcnic_resume,
3620#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003621 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003622 .err_handler = &qlcnic_err_handler,
3623#ifdef CONFIG_QLCNIC_SRIOV
3624 .sriov_configure = qlcnic_pci_sriov_configure,
3625#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003626
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003627};
3628
3629static int __init qlcnic_init_module(void)
3630{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003631 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003632
3633 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3634
3635#ifdef CONFIG_INET
3636 register_netdevice_notifier(&qlcnic_netdev_cb);
3637 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3638#endif
3639
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003640 ret = pci_register_driver(&qlcnic_driver);
3641 if (ret) {
3642#ifdef CONFIG_INET
3643 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3644 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3645#endif
3646 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003647
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003648 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003649}
3650
3651module_init(qlcnic_init_module);
3652
3653static void __exit qlcnic_exit_module(void)
3654{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003655 pci_unregister_driver(&qlcnic_driver);
3656
3657#ifdef CONFIG_INET
3658 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3659 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3660#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003661}
3662
3663module_exit(qlcnic_exit_module);