blob: d8f4897e9e820ebef4469c2c744e75910f6ebf2c [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
Sritej Velaga40839129f2010-12-02 20:41:56 +00002 * QLogic qlcnic NIC Driver
Jitendra Kalsaria577ae392013-02-04 12:33:07 +00003 * Copyright (c) 2009-2013 QLogic Corporation
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004 *
Sritej Velaga40839129f2010-12-02 20:41:56 +00005 * See LICENSE.qlcnic for copyright and licensing details.
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00006 */
7
8#include <linux/vmalloc.h>
9#include <linux/interrupt.h>
10
11#include "qlcnic.h"
Rajesh Borundia02feda12013-03-29 05:46:33 +000012#include "qlcnic_sriov.h"
Himanshu Madhania15ebd32013-01-01 03:20:18 +000013#include "qlcnic_hw.h"
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000014
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000015#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000016#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000017#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000018#include <net/ip.h>
19#include <linux/ipv6.h>
20#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000021#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000022#include <linux/log2.h>
Stephen Rothwell47caf252013-01-02 17:23:53 +000023#include <linux/pci.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000024
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000025MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000026MODULE_LICENSE("GPL");
27MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
28MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
29
30char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000031static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
32 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000033
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000034static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000035module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000036MODULE_PARM_DESC(qlcnic_mac_learn,
37 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000038
Sony Chacko629263a2013-01-01 04:11:55 +000039int qlcnic_use_msi = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000040MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000041module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000042
Sony Chacko629263a2013-01-01 04:11:55 +000043int qlcnic_use_msi_x = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000044MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000045module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000046
Sony Chacko629263a2013-01-01 04:11:55 +000047int qlcnic_auto_fw_reset = 1;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000048MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000049module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000050
Sony Chacko629263a2013-01-01 04:11:55 +000051int qlcnic_load_fw_file;
Himanshu Madhani9fd13332013-05-09 09:25:11 +000052MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file)");
Sony Chacko099f7aa2012-12-04 03:33:58 +000053module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000054
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000055static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050056static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000057static int qlcnic_open(struct net_device *netdev);
58static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000059static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000060static void qlcnic_attach_work(struct work_struct *work);
61static void qlcnic_fwinit_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000062#ifdef CONFIG_NET_POLL_CONTROLLER
63static void qlcnic_poll_controller(struct net_device *netdev);
64#endif
65
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000066static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000067static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
68
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000069static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000070static irqreturn_t qlcnic_intr(int irq, void *data);
71static irqreturn_t qlcnic_msi_intr(int irq, void *data);
72static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000073static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000074
75static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000076static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000077
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000078static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000079static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000080static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000081static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
82static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000083
Sony Chacko13159182013-01-01 03:20:21 +000084static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
85{
86 struct qlcnic_hardware_context *ahw = adapter->ahw;
87
88 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
89 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
90 else
91 return 1;
92}
93
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000094/* PCI Device ID Table */
95#define ENTRY(device) \
96 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
97 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
98
Amit Kumar Salecha6a902882010-02-01 05:24:54 +000099static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000100 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000101 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000102 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Manish Chopra15ca1402013-08-16 19:07:13 -0400103 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X),
104 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000105 {0,}
106};
107
108MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
109
110
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000111inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000112{
113 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000114}
115
116static const u32 msi_tgt_status[8] = {
117 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
118 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
119 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
120 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
121};
122
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000123static const u32 qlcnic_reg_tbl[] = {
124 0x1B20A8, /* PEG_HALT_STAT1 */
125 0x1B20AC, /* PEG_HALT_STAT2 */
126 0x1B20B0, /* FW_HEARTBEAT */
127 0x1B2100, /* LOCK ID */
128 0x1B2128, /* FW_CAPABILITIES */
129 0x1B2138, /* drv active */
130 0x1B2140, /* dev state */
131 0x1B2144, /* drv state */
132 0x1B2148, /* drv scratch */
133 0x1B214C, /* dev partition info */
134 0x1B2174, /* drv idc ver */
135 0x1B2150, /* fw version major */
136 0x1B2154, /* fw version minor */
137 0x1B2158, /* fw version sub */
138 0x1B219C, /* npar state */
139 0x1B21FC, /* FW_IMG_VALID */
140 0x1B2250, /* CMD_PEG_STATE */
141 0x1B233C, /* RCV_PEG_STATE */
142 0x1B23B4, /* ASIC TEMP */
143 0x1B216C, /* FW api */
144 0x1B2170, /* drv op mode */
145 0x13C010, /* flash lock */
146 0x13C014, /* flash unlock */
147};
148
Sony Chacko22999792012-12-04 03:33:55 +0000149static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000150 { PCI_VENDOR_ID_QLOGIC,
Manish Chopra15ca1402013-08-16 19:07:13 -0400151 PCI_DEVICE_ID_QLOGIC_QLE844X,
152 0x0,
153 0x0,
154 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
155 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000156 PCI_DEVICE_ID_QLOGIC_QLE834X,
157 PCI_VENDOR_ID_QLOGIC,
158 0x24e,
159 "8300 Series Dual Port 10GbE Converged Network Adapter "
160 "(TCP/IP Networking)" },
161 { PCI_VENDOR_ID_QLOGIC,
162 PCI_DEVICE_ID_QLOGIC_QLE834X,
163 PCI_VENDOR_ID_QLOGIC,
164 0x243,
165 "8300 Series Single Port 10GbE Converged Network Adapter "
166 "(TCP/IP Networking)" },
167 { PCI_VENDOR_ID_QLOGIC,
168 PCI_DEVICE_ID_QLOGIC_QLE834X,
169 PCI_VENDOR_ID_QLOGIC,
170 0x24a,
171 "8300 Series Dual Port 10GbE Converged Network Adapter "
172 "(TCP/IP Networking)" },
173 { PCI_VENDOR_ID_QLOGIC,
174 PCI_DEVICE_ID_QLOGIC_QLE834X,
175 PCI_VENDOR_ID_QLOGIC,
176 0x246,
177 "8300 Series Dual Port 10GbE Converged Network Adapter "
178 "(TCP/IP Networking)" },
179 { PCI_VENDOR_ID_QLOGIC,
180 PCI_DEVICE_ID_QLOGIC_QLE834X,
181 PCI_VENDOR_ID_QLOGIC,
182 0x252,
183 "8300 Series Dual Port 10GbE Converged Network Adapter "
184 "(TCP/IP Networking)" },
185 { PCI_VENDOR_ID_QLOGIC,
186 PCI_DEVICE_ID_QLOGIC_QLE834X,
187 PCI_VENDOR_ID_QLOGIC,
188 0x26e,
189 "8300 Series Dual Port 10GbE Converged Network Adapter "
190 "(TCP/IP Networking)" },
191 { PCI_VENDOR_ID_QLOGIC,
192 PCI_DEVICE_ID_QLOGIC_QLE834X,
193 PCI_VENDOR_ID_QLOGIC,
194 0x260,
195 "8300 Series Dual Port 10GbE Converged Network Adapter "
196 "(TCP/IP Networking)" },
197 { PCI_VENDOR_ID_QLOGIC,
198 PCI_DEVICE_ID_QLOGIC_QLE834X,
199 PCI_VENDOR_ID_QLOGIC,
200 0x266,
201 "8300 Series Single Port 10GbE Converged Network Adapter "
202 "(TCP/IP Networking)" },
203 { PCI_VENDOR_ID_QLOGIC,
204 PCI_DEVICE_ID_QLOGIC_QLE834X,
205 PCI_VENDOR_ID_QLOGIC,
206 0x269,
207 "8300 Series Dual Port 10GbE Converged Network Adapter "
208 "(TCP/IP Networking)" },
209 { PCI_VENDOR_ID_QLOGIC,
210 PCI_DEVICE_ID_QLOGIC_QLE834X,
211 PCI_VENDOR_ID_QLOGIC,
212 0x271,
213 "8300 Series Dual Port 10GbE Converged Network Adapter "
214 "(TCP/IP Networking)" },
215 { PCI_VENDOR_ID_QLOGIC,
216 PCI_DEVICE_ID_QLOGIC_QLE834X,
217 0x0, 0x0, "8300 Series 1/10GbE Controller" },
218 { PCI_VENDOR_ID_QLOGIC,
219 PCI_DEVICE_ID_QLOGIC_QLE824X,
220 PCI_VENDOR_ID_QLOGIC,
221 0x203,
222 "8200 Series Single Port 10GbE Converged Network Adapter"
223 "(TCP/IP Networking)" },
224 { PCI_VENDOR_ID_QLOGIC,
225 PCI_DEVICE_ID_QLOGIC_QLE824X,
226 PCI_VENDOR_ID_QLOGIC,
227 0x207,
228 "8200 Series Dual Port 10GbE Converged Network Adapter"
229 "(TCP/IP Networking)" },
230 { PCI_VENDOR_ID_QLOGIC,
231 PCI_DEVICE_ID_QLOGIC_QLE824X,
232 PCI_VENDOR_ID_QLOGIC,
233 0x20b,
234 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
235 { PCI_VENDOR_ID_QLOGIC,
236 PCI_DEVICE_ID_QLOGIC_QLE824X,
237 PCI_VENDOR_ID_QLOGIC,
238 0x20c,
239 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
240 { PCI_VENDOR_ID_QLOGIC,
241 PCI_DEVICE_ID_QLOGIC_QLE824X,
242 PCI_VENDOR_ID_QLOGIC,
243 0x20f,
244 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
245 { PCI_VENDOR_ID_QLOGIC,
246 PCI_DEVICE_ID_QLOGIC_QLE824X,
247 0x103c, 0x3733,
248 "NC523SFP 10Gb 2-port Server Adapter" },
249 { PCI_VENDOR_ID_QLOGIC,
250 PCI_DEVICE_ID_QLOGIC_QLE824X,
251 0x103c, 0x3346,
252 "CN1000Q Dual Port Converged Network Adapter" },
253 { PCI_VENDOR_ID_QLOGIC,
254 PCI_DEVICE_ID_QLOGIC_QLE824X,
255 PCI_VENDOR_ID_QLOGIC,
256 0x210,
257 "QME8242-k 10GbE Dual Port Mezzanine Card" },
258 { PCI_VENDOR_ID_QLOGIC,
259 PCI_DEVICE_ID_QLOGIC_QLE824X,
260 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000261};
262
263#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
264
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000265static const
266struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
267
Sony Chackoc70001a2012-11-28 04:34:26 +0000268int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000269{
270 int size = sizeof(struct qlcnic_host_sds_ring) * count;
271
272 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
273
Eric Dumazet807540b2010-09-23 05:40:09 +0000274 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000275}
276
Sony Chackoc70001a2012-11-28 04:34:26 +0000277void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000278{
279 if (recv_ctx->sds_rings != NULL)
280 kfree(recv_ctx->sds_rings);
281
282 recv_ctx->sds_rings = NULL;
283}
284
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000285int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000286{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000287 struct net_device *netdev = adapter->netdev;
288 struct pci_dev *pdev = adapter->pdev;
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400289 u8 mac_addr[ETH_ALEN];
290 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000291
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400292 ret = qlcnic_get_mac_address(adapter, mac_addr,
293 adapter->ahw->pci_func);
294 if (ret)
295 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000296
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000297 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000298 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
299
300 /* set station address */
301
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000302 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000303 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
304 netdev->dev_addr);
305
306 return 0;
307}
308
Manish Chopracffe52f32013-05-09 09:25:09 +0000309static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
310{
311 struct qlcnic_mac_list_s *cur;
312 struct list_head *head;
313
314 list_for_each(head, &adapter->mac_list) {
315 cur = list_entry(head, struct qlcnic_mac_list_s, list);
316 if (!memcmp(adapter->mac_addr, cur->mac_addr, ETH_ALEN)) {
317 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
318 0, QLCNIC_MAC_DEL);
319 list_del(&cur->list);
320 kfree(cur);
321 return;
322 }
323 }
324}
325
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000326static int qlcnic_set_mac(struct net_device *netdev, void *p)
327{
328 struct qlcnic_adapter *adapter = netdev_priv(netdev);
329 struct sockaddr *addr = p;
330
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000331 if (qlcnic_sriov_vf_check(adapter))
332 return -EINVAL;
333
Rajesh Borundia73733732010-08-31 17:17:50 +0000334 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
335 return -EOPNOTSUPP;
336
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000337 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000338 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000339
Manish Chopracffe52f32013-05-09 09:25:09 +0000340 if (!memcmp(adapter->mac_addr, addr->sa_data, ETH_ALEN))
341 return 0;
342
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000343 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000344 netif_device_detach(netdev);
345 qlcnic_napi_disable(adapter);
346 }
347
Manish Chopracffe52f32013-05-09 09:25:09 +0000348 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000349 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
350 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
351 qlcnic_set_multi(adapter->netdev);
352
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000353 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000354 netif_device_attach(netdev);
355 qlcnic_napi_enable(adapter);
356 }
357 return 0;
358}
359
Vlad Yasevich1690be62013-02-13 12:00:18 +0000360static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
361 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000362{
363 struct qlcnic_adapter *adapter = netdev_priv(netdev);
364 int err = -EOPNOTSUPP;
365
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000366 if (!adapter->fdb_mac_learn)
367 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000368
369 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400370 if (is_unicast_ether_addr(addr)) {
371 err = dev_uc_del(netdev, addr);
372 if (!err)
373 err = qlcnic_nic_del_mac(adapter, addr);
374 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000375 err = dev_mc_del(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400376 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000377 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400378 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000379 }
380 return err;
381}
382
383static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
384 struct net_device *netdev,
385 const unsigned char *addr, u16 flags)
386{
387 struct qlcnic_adapter *adapter = netdev_priv(netdev);
388 int err = 0;
389
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000390 if (!adapter->fdb_mac_learn)
391 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000392
393 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
394 pr_info("%s: FDB e-switch is not enabled\n", __func__);
395 return -EOPNOTSUPP;
396 }
397
398 if (ether_addr_equal(addr, adapter->mac_addr))
399 return err;
400
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400401 if (is_unicast_ether_addr(addr)) {
402 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
403 err = dev_uc_add_excl(netdev, addr);
404 else
405 err = -ENOMEM;
406 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000407 err = dev_mc_add_excl(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400408 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000409 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400410 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000411
412 return err;
413}
414
415static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
416 struct net_device *netdev, int idx)
417{
418 struct qlcnic_adapter *adapter = netdev_priv(netdev);
419
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000420 if (!adapter->fdb_mac_learn)
421 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000422
423 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
424 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
425
426 return idx;
427}
428
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000429static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
430{
431 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
432 usleep_range(10000, 11000);
433
Sucheta Chakraborty66451612013-09-27 02:12:36 -0400434 if (!adapter->fw_work.work.func)
435 return;
436
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000437 cancel_delayed_work_sync(&adapter->fw_work);
438}
439
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400440static int qlcnic_get_phys_port_id(struct net_device *netdev,
441 struct netdev_phys_port_id *ppid)
442{
443 struct qlcnic_adapter *adapter = netdev_priv(netdev);
444 struct qlcnic_hardware_context *ahw = adapter->ahw;
445
446 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID))
447 return -EOPNOTSUPP;
448
449 ppid->id_len = sizeof(ahw->phys_port_id);
450 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len);
451
452 return 0;
453}
454
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000455static const struct net_device_ops qlcnic_netdev_ops = {
456 .ndo_open = qlcnic_open,
457 .ndo_stop = qlcnic_close,
458 .ndo_start_xmit = qlcnic_xmit_frame,
459 .ndo_get_stats = qlcnic_get_stats,
460 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000461 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000462 .ndo_set_mac_address = qlcnic_set_mac,
463 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000464 .ndo_fix_features = qlcnic_fix_features,
465 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000466 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000467 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
468 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000469 .ndo_fdb_add = qlcnic_fdb_add,
470 .ndo_fdb_del = qlcnic_fdb_del,
471 .ndo_fdb_dump = qlcnic_fdb_dump,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400472 .ndo_get_phys_port_id = qlcnic_get_phys_port_id,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000473#ifdef CONFIG_NET_POLL_CONTROLLER
474 .ndo_poll_controller = qlcnic_poll_controller,
475#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000476#ifdef CONFIG_QLCNIC_SRIOV
477 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
478 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate,
479 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000480 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundiaa80be5a2013-05-23 21:04:25 +0000481 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000482#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000483};
484
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000485static const struct net_device_ops qlcnic_netdev_failed_ops = {
486 .ndo_open = qlcnic_open,
487};
488
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000489static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000490 .config_bridged_mode = qlcnic_config_bridged_mode,
491 .config_led = qlcnic_82xx_config_led,
492 .start_firmware = qlcnic_82xx_start_firmware,
493 .request_reset = qlcnic_82xx_dev_request_reset,
494 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
495 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000496 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000497 .config_ipaddr = qlcnic_82xx_config_ipaddr,
Rajesh Borundia486a5bc2013-06-22 04:12:06 -0400498 .shutdown = qlcnic_82xx_shutdown,
499 .resume = qlcnic_82xx_resume,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000500 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000501};
502
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000503struct qlcnic_nic_template qlcnic_vf_ops = {
504 .config_bridged_mode = qlcnicvf_config_bridged_mode,
505 .config_led = qlcnicvf_config_led,
506 .start_firmware = qlcnicvf_start_firmware
507};
508
509static struct qlcnic_hardware_ops qlcnic_hw_ops = {
510 .read_crb = qlcnic_82xx_read_crb,
511 .write_crb = qlcnic_82xx_write_crb,
512 .read_reg = qlcnic_82xx_hw_read_wx_2M,
513 .write_reg = qlcnic_82xx_hw_write_wx_2M,
514 .get_mac_address = qlcnic_82xx_get_mac_address,
515 .setup_intr = qlcnic_82xx_setup_intr,
516 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
517 .mbx_cmd = qlcnic_82xx_issue_cmd,
518 .get_func_no = qlcnic_82xx_get_func_no,
519 .api_lock = qlcnic_82xx_api_lock,
520 .api_unlock = qlcnic_82xx_api_unlock,
521 .add_sysfs = qlcnic_82xx_add_sysfs,
522 .remove_sysfs = qlcnic_82xx_remove_sysfs,
523 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
524 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
525 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000526 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
527 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000528 .setup_link_event = qlcnic_82xx_linkevent_request,
529 .get_nic_info = qlcnic_82xx_get_nic_info,
530 .get_pci_info = qlcnic_82xx_get_pci_info,
531 .set_nic_info = qlcnic_82xx_set_nic_info,
532 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
533 .napi_enable = qlcnic_82xx_napi_enable,
534 .napi_disable = qlcnic_82xx_napi_disable,
535 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
536 .config_rss = qlcnic_82xx_config_rss,
537 .config_hw_lro = qlcnic_82xx_config_hw_lro,
538 .config_loopback = qlcnic_82xx_set_lb_mode,
539 .clear_loopback = qlcnic_82xx_clear_lb_mode,
540 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
541 .change_l2_filter = qlcnic_82xx_change_filter,
542 .get_board_info = qlcnic_82xx_get_board_info,
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400543 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000544 .free_mac_list = qlcnic_82xx_free_mac_list,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400545 .read_phys_port_id = qlcnic_82xx_read_phys_port_id,
Pratik Pujar4460f2e2013-08-30 13:51:20 -0400546 .io_error_detected = qlcnic_82xx_io_error_detected,
547 .io_slot_reset = qlcnic_82xx_io_slot_reset,
548 .io_resume = qlcnic_82xx_io_resume,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000549};
550
Himanshu Madhani012ec812013-08-21 11:24:10 -0400551static void qlcnic_get_multiq_capability(struct qlcnic_adapter *adapter)
552{
553 struct qlcnic_hardware_context *ahw = adapter->ahw;
554 int num_tx_q;
555
556 if (ahw->msix_supported &&
557 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) {
558 num_tx_q = min_t(int, QLCNIC_DEF_NUM_TX_RINGS,
559 num_online_cpus());
560 if (num_tx_q > 1) {
561 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE,
562 &adapter->state);
563 adapter->max_drv_tx_rings = num_tx_q;
564 }
565 } else {
566 adapter->max_drv_tx_rings = 1;
567 }
568}
569
Sony Chacko7f9664522013-01-01 03:20:19 +0000570int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000571{
572 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400573 int max_tx_rings, max_sds_rings, tx_vector;
Sony Chacko13159182013-01-01 03:20:21 +0000574 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000575
576 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
577 max_tx_rings = 0;
578 tx_vector = 0;
579 } else {
580 max_tx_rings = adapter->max_drv_tx_rings;
581 tx_vector = 1;
582 }
Sony Chacko13159182013-01-01 03:20:21 +0000583
584 if (!adapter->msix_entries) {
585 adapter->msix_entries = kcalloc(num_msix,
586 sizeof(struct msix_entry),
587 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000588 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000589 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000590 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000591
592 adapter->max_sds_rings = 1;
593 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000594
Sony Chacko79788452012-12-04 03:33:53 +0000595 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000596 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000597 for (i = 0; i < num_msix; i++)
598 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000599 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
600 if (err == 0) {
601 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000602 if (qlcnic_83xx_check(adapter)) {
603 adapter->ahw->num_msix = num_msix;
604 /* subtract mail box and tx ring vectors */
Sony Chacko13159182013-01-01 03:20:21 +0000605 adapter->max_sds_rings = num_msix -
606 max_tx_rings - 1;
607 } else {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400608 adapter->ahw->num_msix = num_msix;
609 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400610 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400611 (adapter->max_drv_tx_rings > 1))
612 max_sds_rings = num_msix - max_tx_rings;
613 else
614 max_sds_rings = num_msix;
615
616 adapter->max_sds_rings = max_sds_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000617 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000618 dev_info(&pdev->dev, "using msi-x interrupts\n");
619 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000620 } else if (err > 0) {
621 dev_info(&pdev->dev,
622 "Unable to allocate %d MSI-X interrupt vectors\n",
623 num_msix);
624 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000625 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000626 return err;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000627 err -= (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000628 num_msix = rounddown_pow_of_two(err);
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000629 num_msix += (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000630 } else {
631 num_msix = rounddown_pow_of_two(err);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400632 if (qlcnic_check_multi_tx(adapter))
633 num_msix += max_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000634 }
635
636 if (num_msix) {
637 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000638 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000639 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000640 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000641 }
642 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000643 dev_info(&pdev->dev,
644 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000645 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000646 }
647 }
Sony Chacko13159182013-01-01 03:20:21 +0000648
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000649 return err;
650}
651
Manish chopra9a97e702013-01-25 10:20:37 +0000652static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000653{
Manish chopra9a97e702013-01-25 10:20:37 +0000654 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000655 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000656 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000657 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000658 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000659
Sony Chacko099f7aa2012-12-04 03:33:58 +0000660 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000661 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000662 offset = msi_tgt_status[adapter->ahw->pci_func];
663 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
664 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000665 dev_info(&pdev->dev, "using msi interrupts\n");
666 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000667 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000668 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400669
Manish chopra9a97e702013-01-25 10:20:37 +0000670 if (qlcnic_use_msi || qlcnic_use_msi_x)
671 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000672
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000673 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000674 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000675 offset = legacy_intrp->tgt_status_reg;
676 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
677 mask_reg = legacy_intrp->tgt_mask_reg;
678 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
679 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
680 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000681 dev_info(&pdev->dev, "using legacy interrupts\n");
682 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000683 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000684}
685
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -0400686int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr, int txq)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000687{
Himanshu Madhani012ec812013-08-21 11:24:10 -0400688 struct qlcnic_hardware_context *ahw = adapter->ahw;
Manish chopra9a97e702013-01-25 10:20:37 +0000689 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000690
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000691 if (!num_intr)
692 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
693
Himanshu Madhani012ec812013-08-21 11:24:10 -0400694 if (ahw->msix_supported) {
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000695 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000696 num_intr));
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -0400697 if (qlcnic_check_multi_tx(adapter)) {
698 if (txq)
699 adapter->max_drv_tx_rings = txq;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400700 num_msix += adapter->max_drv_tx_rings;
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -0400701 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400702 } else {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000703 num_msix = 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400704 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000705
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000706 err = qlcnic_enable_msix(adapter, num_msix);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400707 if (err == -ENOMEM)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000708 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000709
Himanshu Madhani012ec812013-08-21 11:24:10 -0400710 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
711 qlcnic_disable_multi_tx(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +0000712
Himanshu Madhani012ec812013-08-21 11:24:10 -0400713 err = qlcnic_enable_msi_legacy(adapter);
714 if (!err)
715 return err;
716 }
717
718 return 0;
719}
720
721int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
722{
723 struct qlcnic_hardware_context *ahw = adapter->ahw;
724 int err, i;
725
726 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400727 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400728 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
729 ahw->intr_tbl = vzalloc(ahw->num_msix *
730 sizeof(struct qlcnic_intrpt_config));
731 if (!ahw->intr_tbl)
732 return -ENOMEM;
733
734 for (i = 0; i < ahw->num_msix; i++) {
735 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
736 ahw->intr_tbl[i].id = i;
737 ahw->intr_tbl[i].src = 0;
738 }
739
740 err = qlcnic_82xx_config_intrpt(adapter, 1);
741 if (err)
742 dev_err(&adapter->pdev->dev,
743 "Failed to configure Interrupt for %d vector\n",
744 ahw->num_msix);
745 return err;
746 }
747
748 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000749}
Sony Chacko13159182013-01-01 03:20:21 +0000750
Sony Chacko319ecf12013-01-01 03:20:22 +0000751void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000752{
753 if (adapter->flags & QLCNIC_MSIX_ENABLED)
754 pci_disable_msix(adapter->pdev);
755 if (adapter->flags & QLCNIC_MSI_ENABLED)
756 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000757
758 kfree(adapter->msix_entries);
759 adapter->msix_entries = NULL;
760
761 if (adapter->ahw->intr_tbl) {
762 vfree(adapter->ahw->intr_tbl);
763 adapter->ahw->intr_tbl = NULL;
764 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000765}
766
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000767static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000768{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000769 if (ahw->pci_base0 != NULL)
770 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000771}
772
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000773static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
774{
775 struct qlcnic_pci_info *pci_info;
776 int ret;
777
778 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
779 switch (adapter->ahw->port_type) {
780 case QLCNIC_GBE:
781 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
782 break;
783 case QLCNIC_XGBE:
784 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
785 break;
786 }
787 return 0;
788 }
789
790 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
791 return 0;
792
793 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
794 if (!pci_info)
795 return -ENOMEM;
796
797 ret = qlcnic_get_pci_info(adapter, pci_info);
798 kfree(pci_info);
799 return ret;
800}
Sony Chackod71170f2013-01-01 03:20:26 +0000801
Sony Chacko35dafcb2013-08-30 13:51:23 -0400802static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
803{
804 bool ret = false;
805
806 if (qlcnic_84xx_check(adapter)) {
807 ret = true;
808 } else if (qlcnic_83xx_check(adapter)) {
809 if (adapter->ahw->extra_capability[0] &
810 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
811 ret = true;
812 else
813 ret = false;
814 }
815
816 return ret;
817}
818
Sony Chackod71170f2013-01-01 03:20:26 +0000819int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000820{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000821 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000822 int i, ret = 0, j = 0;
823 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000824 u8 pfn;
825
Dan Carpentere88db3b2010-08-09 21:49:36 +0000826 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
827 if (!pci_info)
828 return -ENOMEM;
829
Sony Chackobff57d82012-12-04 03:33:56 +0000830 ret = qlcnic_get_pci_info(adapter, pci_info);
831 if (ret)
832 goto err_pci_info;
833
834 act_pci_func = adapter->ahw->act_pci_func;
835
Dan Carpenterca315ac2010-08-09 21:47:56 +0000836 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000837 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000838 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000839 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000840 goto err_pci_info;
841 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000842
Dan Carpenterca315ac2010-08-09 21:47:56 +0000843 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000844 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
845 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000846 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000847 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000848 }
849
Dan Carpenterca315ac2010-08-09 21:47:56 +0000850 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
851 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000852
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000853 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000854 ret = QL_STATUS_INVALID_PARAM;
855 goto err_eswitch;
856 }
Sony Chackobff57d82012-12-04 03:33:56 +0000857
858 if (!pci_info[i].active ||
859 (pci_info[i].type != QLCNIC_TYPE_NIC))
860 continue;
861
Sony Chacko35dafcb2013-08-30 13:51:23 -0400862 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
863 if (!qlcnic_83xx_enable_port_eswitch(adapter, pfn))
864 adapter->npars[j].eswitch_status = true;
865 else
866 continue;
867 } else {
868 adapter->npars[j].eswitch_status = true;
869 }
870
Sony Chackobff57d82012-12-04 03:33:56 +0000871 adapter->npars[j].pci_func = pfn;
872 adapter->npars[j].active = (u8)pci_info[i].active;
873 adapter->npars[j].type = (u8)pci_info[i].type;
874 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
875 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
876 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -0400877
Sony Chackobff57d82012-12-04 03:33:56 +0000878 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000879 }
880
Sony Chacko35dafcb2013-08-30 13:51:23 -0400881 if (qlcnic_82xx_check(adapter)) {
882 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
883 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
884 } else if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
885 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
Sony Chacko13159182013-01-01 03:20:21 +0000886 qlcnic_enable_eswitch(adapter, i, 1);
887 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000888
Dan Carpentere88db3b2010-08-09 21:49:36 +0000889 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000890 return 0;
891
892err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000893 kfree(adapter->eswitch);
894 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000895err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000896 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000897 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000898err_pci_info:
899 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000900
901 return ret;
902}
903
904static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000905qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
906{
907 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +0000908 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000909 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000910 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000911
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000912 ret = qlcnic_api_lock(adapter);
913 if (ret)
914 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000915
Shahed Shaikh7e8fd002013-05-23 21:04:28 +0000916 id = ahw->pci_func;
917 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
918 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
919 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000920 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000921 qlcnic_api_unlock(adapter);
922err_lock:
923 return ret;
924}
925
Sony Chacko13159182013-01-01 03:20:21 +0000926static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
927 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000928{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000929 u32 op_mode, priv_level;
930
931 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000932 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
933 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000934
935 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000936 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000937
938 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000939 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000940 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000941 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000942 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000943 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000944
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000945 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000946 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000947 dev_info(&adapter->pdev->dev,
948 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000949 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000950 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000951 } else
952 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000953}
954
Sony Chacko15087c22012-12-04 03:33:54 +0000955#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000956#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000957static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000958{
Sony Chacko15087c22012-12-04 03:33:54 +0000959 switch (dev_id) {
960 case PCI_DEVICE_ID_QLOGIC_QLE824X:
961 *bar = QLCNIC_82XX_BAR0_LENGTH;
962 break;
Sony Chacko13159182013-01-01 03:20:21 +0000963 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -0400964 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000965 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -0400966 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +0000967 *bar = QLCNIC_83XX_BAR0_LENGTH;
968 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000969 default:
970 *bar = 0;
971 }
972}
973
974static int qlcnic_setup_pci_map(struct pci_dev *pdev,
975 struct qlcnic_hardware_context *ahw)
976{
977 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000978 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000979 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000980
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000981 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000982 mem_len = pci_resource_len(pdev, 0);
983
Sony Chacko15087c22012-12-04 03:33:54 +0000984 qlcnic_get_bar_length(pdev->device, &bar0_len);
985 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000986
987 mem_ptr0 = pci_ioremap_bar(pdev, 0);
988 if (mem_ptr0 == NULL) {
989 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
990 return -EIO;
991 }
992 pci_len0 = mem_len;
993 } else {
994 return -EIO;
995 }
996
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000997 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000998
Sony Chacko15087c22012-12-04 03:33:54 +0000999 ahw->pci_base0 = mem_ptr0;
1000 ahw->pci_len0 = pci_len0;
1001 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1002 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001003
1004 return 0;
1005}
1006
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001007static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1008 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001009{
1010 struct pci_dev *pdev = adapter->pdev;
1011 unsigned short subsystem_vendor;
1012 bool ret = true;
1013
1014 subsystem_vendor = pdev->subsystem_vendor;
1015
1016 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1017 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1018 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1019 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1020 ret = true;
1021 else
1022 ret = false;
1023 }
1024
1025 return ret;
1026}
1027
Sony Chacko22999792012-12-04 03:33:55 +00001028static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001029{
1030 struct pci_dev *pdev = adapter->pdev;
1031 int i, found = 0;
1032
1033 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1034 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001035 qlcnic_boards[i].device == pdev->device &&
1036 qlcnic_validate_subsystem_id(adapter, i)) {
1037 found = 1;
1038 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001039 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001040 }
1041
1042 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001043 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001044 else
1045 sprintf(name, "%pM: %s" , adapter->mac_addr,
1046 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001047}
1048
1049static void
1050qlcnic_check_options(struct qlcnic_adapter *adapter)
1051{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001052 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001053 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001054 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001055 struct qlcnic_hardware_context *ahw = adapter->ahw;
1056 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001057
1058 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001059
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001060 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1061 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1062 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001063
1064 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1065
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001066 err = qlcnic_get_board_info(adapter);
1067 if (err) {
1068 dev_err(&pdev->dev, "Error getting board config info.\n");
1069 return;
1070 }
1071 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001072 if (fw_dump->tmpl_hdr == NULL ||
1073 adapter->fw_version > prev_fw_version) {
1074 if (fw_dump->tmpl_hdr)
1075 vfree(fw_dump->tmpl_hdr);
1076 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1077 dev_info(&pdev->dev,
1078 "Supports FW dump capability\n");
1079 }
1080 }
1081
Sony Chacko13159182013-01-01 03:20:21 +00001082 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1083 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1084
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001085 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001086 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1087 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1088 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1089 } else {
1090 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1091 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1092 }
1093
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001094 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001095 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1096
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001097 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001098 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1099 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001100 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1101 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001102 }
1103
Sony Chacko099f7aa2012-12-04 03:33:58 +00001104 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001105
1106 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1107
Sony Chacko251b0362010-08-19 05:08:24 +00001108 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001109}
1110
Rajesh Borundia174240a2010-08-31 17:17:47 +00001111static int
1112qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1113{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001114 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001115 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001116
Sony Chackobff57d82012-12-04 03:33:56 +00001117 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001118 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001119 if (err)
1120 return err;
1121
Sony Chacko79788452012-12-04 03:33:53 +00001122 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1123 adapter->ahw->switch_mode = nic_info.switch_mode;
1124 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1125 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1126 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001127
1128 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1129 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001130 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1131 if (err == -EIO)
1132 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001133 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001134 } else {
1135 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001136 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001137
Sony Chacko79788452012-12-04 03:33:53 +00001138 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1139 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001140
Sony Chacko13159182013-01-01 03:20:21 +00001141 /* Disable NPAR for 83XX */
1142 if (qlcnic_83xx_check(adapter))
1143 return err;
1144
Sony Chacko79788452012-12-04 03:33:53 +00001145 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001146 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
1147 else
1148 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
1149
1150 return err;
1151}
1152
Sony Chackoec079a02012-11-28 04:34:28 +00001153void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1154 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001155{
1156 if (esw_cfg->discard_tagged)
1157 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1158 else
1159 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1160
Rajesh Borundia91b72822013-04-19 07:01:12 +00001161 if (esw_cfg->vlan_id) {
1162 adapter->rx_pvid = esw_cfg->vlan_id;
1163 adapter->tx_pvid = esw_cfg->vlan_id;
1164 } else {
1165 adapter->rx_pvid = 0;
1166 adapter->tx_pvid = 0;
1167 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001168}
1169
Jiri Pirko8e586132011-12-08 19:52:37 -05001170static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001171qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001172{
1173 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001174 int err;
1175
1176 if (qlcnic_sriov_vf_check(adapter)) {
1177 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1178 if (err) {
1179 netdev_err(netdev,
1180 "Cannot add VLAN filter for VLAN id %d, err=%d",
1181 vid, err);
1182 return err;
1183 }
1184 }
1185
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001186 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001187 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001188}
1189
Jiri Pirko8e586132011-12-08 19:52:37 -05001190static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001191qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001192{
1193 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001194 int err;
1195
1196 if (qlcnic_sriov_vf_check(adapter)) {
1197 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1198 if (err) {
1199 netdev_err(netdev,
1200 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1201 vid, err);
1202 return err;
1203 }
1204 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001205
1206 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1207 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001208 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001209}
1210
Sony Chackoec079a02012-11-28 04:34:28 +00001211void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1212 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001213{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001214 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1215 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001216
1217 if (esw_cfg->mac_anti_spoof)
1218 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001219
Rajesh Borundia73733732010-08-31 17:17:50 +00001220 if (!esw_cfg->mac_override)
1221 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1222
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001223 if (!esw_cfg->promisc_mode)
1224 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001225}
1226
Sony Chackod71170f2013-01-01 03:20:26 +00001227int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001228{
1229 struct qlcnic_esw_func_cfg esw_cfg;
1230
1231 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1232 return 0;
1233
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001234 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001235 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1236 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001237 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001238 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001239 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001240
1241 return 0;
1242}
1243
Shahed Shaikh147a9082013-05-21 09:27:01 +00001244void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1245 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001246{
1247 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001248
Sony Chacko13159182013-01-01 03:20:21 +00001249 if (qlcnic_83xx_check(adapter))
1250 return;
1251
Shahed Shaikh147a9082013-05-21 09:27:01 +00001252 adapter->offload_flags = esw_cfg->offload_flags;
1253 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1254 netdev_update_features(netdev);
1255 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001256}
1257
1258static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001259qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1260{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001261 u32 op_mode, priv_level;
1262 int err = 0;
1263
Rajesh Borundia174240a2010-08-31 17:17:47 +00001264 err = qlcnic_initialize_nic(adapter);
1265 if (err)
1266 return err;
1267
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001268 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1269 return 0;
1270
Sony Chacko13159182013-01-01 03:20:21 +00001271 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001272 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001273
1274 if (op_mode == QLC_DEV_DRV_DEFAULT)
1275 priv_level = QLCNIC_MGMT_FUNC;
1276 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001277 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001278
Rajesh Borundia174240a2010-08-31 17:17:47 +00001279 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001280 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001281 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001282 err = qlcnic_init_pci_info(adapter);
1283 if (err)
1284 return err;
1285 /* Set privilege level for other functions */
1286 qlcnic_set_function_modes(adapter);
1287 dev_info(&adapter->pdev->dev,
1288 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001289 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001290 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001291 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001292 dev_info(&adapter->pdev->dev,
1293 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001294 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001295 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001296 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001297
1298 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1299
1300 return err;
1301}
1302
Sony Chackod71170f2013-01-01 03:20:26 +00001303int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001304{
1305 struct qlcnic_esw_func_cfg esw_cfg;
1306 struct qlcnic_npar_info *npar;
1307 u8 i;
1308
Rajesh Borundia174240a2010-08-31 17:17:47 +00001309 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001310 return 0;
1311
Sony Chackobff57d82012-12-04 03:33:56 +00001312 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001313 if (!adapter->npars[i].eswitch_status)
1314 continue;
1315
Rajesh Borundia0325d692010-08-19 05:08:26 +00001316 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001317 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001318 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001319 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001320 if (qlcnic_82xx_check(adapter)) {
1321 esw_cfg.offload_flags = BIT_0;
1322 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1323 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1324 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001325 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1326 return -EIO;
1327 npar = &adapter->npars[i];
1328 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001329 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001330 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1331 npar->discard_tagged = esw_cfg.discard_tagged;
1332 npar->promisc_mode = esw_cfg.promisc_mode;
1333 npar->offload_flags = esw_cfg.offload_flags;
1334 }
1335
1336 return 0;
1337}
1338
Sony Chacko13159182013-01-01 03:20:21 +00001339
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001340static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001341qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1342 struct qlcnic_npar_info *npar, int pci_func)
1343{
1344 struct qlcnic_esw_func_cfg esw_cfg;
1345 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1346 esw_cfg.pci_func = pci_func;
1347 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001348 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001349 esw_cfg.discard_tagged = npar->discard_tagged;
1350 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1351 esw_cfg.offload_flags = npar->offload_flags;
1352 esw_cfg.promisc_mode = npar->promisc_mode;
1353 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1354 return -EIO;
1355
1356 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1357 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1358 return -EIO;
1359
1360 return 0;
1361}
1362
Sony Chackod71170f2013-01-01 03:20:26 +00001363int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001364{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001365 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001366 struct qlcnic_npar_info *npar;
1367 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001368 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001369
Sony Chackobff57d82012-12-04 03:33:56 +00001370 if (qlcnic_82xx_check(adapter))
1371 if (!adapter->need_fw_reset)
1372 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001373
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001374 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001375 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001376 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001377 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001378 if (!adapter->npars[i].eswitch_status)
1379 continue;
1380
Sony Chackobff57d82012-12-04 03:33:56 +00001381 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001382 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001383 if (err)
1384 return err;
1385 nic_info.min_tx_bw = npar->min_bw;
1386 nic_info.max_tx_bw = npar->max_bw;
1387 err = qlcnic_set_nic_info(adapter, &nic_info);
1388 if (err)
1389 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001390
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001391 if (npar->enable_pm) {
1392 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001393 npar->dest_npar, 1,
1394 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001395 if (err)
1396 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001397 }
Sony Chackobff57d82012-12-04 03:33:56 +00001398 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001399 if (err)
1400 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001401 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001402 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001403}
1404
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001405static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1406{
1407 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1408 u32 npar_state;
1409
Sony Chacko79788452012-12-04 03:33:53 +00001410 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001411 return 0;
1412
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001413 npar_state = QLC_SHARED_REG_RD32(adapter,
1414 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001415 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1416 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001417 npar_state = QLC_SHARED_REG_RD32(adapter,
1418 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001419 }
1420 if (!npar_opt_timeo) {
1421 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001422 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001423 return -EIO;
1424 }
1425 return 0;
1426}
1427
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001428static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001429qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1430{
1431 int err;
1432
1433 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001434 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001435 return 0;
1436
1437 err = qlcnic_set_default_offload_settings(adapter);
1438 if (err)
1439 return err;
1440
1441 err = qlcnic_reset_npar_config(adapter);
1442 if (err)
1443 return err;
1444
1445 qlcnic_dev_set_npar_ready(adapter);
1446
1447 return err;
1448}
1449
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001450int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001451{
Sony Chackod4066832010-08-19 05:08:31 +00001452 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001453
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001454 err = qlcnic_can_start_firmware(adapter);
1455 if (err < 0)
1456 return err;
1457 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001458 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001459
Sony Chacko099f7aa2012-12-04 03:33:58 +00001460 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001461 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001462 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001463 err = qlcnic_check_flash_fw_ver(adapter);
1464 if (err)
schacko8f891382010-06-17 02:56:40 +00001465 goto err_out;
1466
Sony Chacko79788452012-12-04 03:33:53 +00001467 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001468 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001469
1470 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001471 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001472 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001473
Sony Chackod4066832010-08-19 05:08:31 +00001474 err = qlcnic_pinit_from_rom(adapter);
1475 if (err)
1476 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001477
1478 err = qlcnic_load_firmware(adapter);
1479 if (err)
1480 goto err_out;
1481
1482 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001483 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001484
Sony Chackod4066832010-08-19 05:08:31 +00001485check_fw_status:
1486 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001487 if (err)
1488 goto err_out;
1489
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001490 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001491 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001492 err = qlcnic_check_eswitch_mode(adapter);
1493 if (err) {
1494 dev_err(&adapter->pdev->dev,
1495 "Memory allocation failed for eswitch\n");
1496 goto err_out;
1497 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001498 err = qlcnic_set_mgmt_operations(adapter);
1499 if (err)
1500 goto err_out;
1501
1502 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001503 adapter->need_fw_reset = 0;
1504
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001505 qlcnic_release_firmware(adapter);
1506 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001507
1508err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001509 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001510 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001511
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001512 qlcnic_release_firmware(adapter);
1513 return err;
1514}
1515
1516static int
1517qlcnic_request_irq(struct qlcnic_adapter *adapter)
1518{
1519 irq_handler_t handler;
1520 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001521 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001522 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001523
1524 unsigned long flags = 0;
1525 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001526 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001527
Sony Chacko79788452012-12-04 03:33:53 +00001528 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001529 if (qlcnic_82xx_check(adapter))
1530 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001531 else
1532 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001533 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1534 flags |= IRQF_SHARED;
1535
1536 } else {
1537 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1538 handler = qlcnic_msix_intr;
1539 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1540 handler = qlcnic_msi_intr;
1541 else {
1542 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001543 if (qlcnic_82xx_check(adapter))
1544 handler = qlcnic_intr;
1545 else
1546 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001547 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001548 }
1549 adapter->irq = netdev->irq;
1550
Sony Chacko13159182013-01-01 03:20:21 +00001551 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001552 if (qlcnic_82xx_check(adapter) ||
1553 (qlcnic_83xx_check(adapter) &&
1554 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001555 num_sds_rings = adapter->max_sds_rings;
1556 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001557 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001558 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001559 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001560 (ring == (num_sds_rings - 1))) {
1561 if (!(adapter->flags &
1562 QLCNIC_MSIX_ENABLED))
1563 snprintf(sds_ring->name,
1564 sizeof(sds_ring->name),
1565 "qlcnic");
1566 else
1567 snprintf(sds_ring->name,
1568 sizeof(sds_ring->name),
1569 "%s-tx-0-rx-%d",
1570 netdev->name, ring);
1571 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001572 snprintf(sds_ring->name,
1573 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001574 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001575 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001576 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001577 err = request_irq(sds_ring->irq, handler, flags,
1578 sds_ring->name, sds_ring);
1579 if (err)
1580 return err;
1581 }
Sony Chacko13159182013-01-01 03:20:21 +00001582 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001583 if ((qlcnic_82xx_check(adapter) &&
1584 qlcnic_check_multi_tx(adapter)) ||
1585 (qlcnic_83xx_check(adapter) &&
1586 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1587 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001588 handler = qlcnic_msix_tx_intr;
1589 for (ring = 0; ring < adapter->max_drv_tx_rings;
1590 ring++) {
1591 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001592 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001593 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001594 err = request_irq(tx_ring->irq, handler, flags,
1595 tx_ring->name, tx_ring);
1596 if (err)
1597 return err;
1598 }
1599 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001600 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001601 return 0;
1602}
1603
1604static void
1605qlcnic_free_irq(struct qlcnic_adapter *adapter)
1606{
1607 int ring;
1608 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001609 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001610
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001611 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001612
Sony Chacko13159182013-01-01 03:20:21 +00001613 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001614 if (qlcnic_82xx_check(adapter) ||
1615 (qlcnic_83xx_check(adapter) &&
1616 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1617 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1618 sds_ring = &recv_ctx->sds_rings[ring];
1619 free_irq(sds_ring->irq, sds_ring);
1620 }
Sony Chacko13159182013-01-01 03:20:21 +00001621 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001622 if ((qlcnic_83xx_check(adapter) &&
1623 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1624 (qlcnic_82xx_check(adapter) &&
1625 qlcnic_check_multi_tx(adapter))) {
Sony Chacko13159182013-01-01 03:20:21 +00001626 for (ring = 0; ring < adapter->max_drv_tx_rings;
1627 ring++) {
1628 tx_ring = &adapter->tx_ring[ring];
1629 if (tx_ring->irq)
1630 free_irq(tx_ring->irq, tx_ring);
1631 }
1632 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001633 }
1634}
1635
Shahed Shaikh99e85872013-02-18 12:06:16 +00001636static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1637{
1638 u32 capab = 0;
1639
1640 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001641 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001642 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1643 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1644 } else {
1645 capab = adapter->ahw->capabilities;
1646 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1647 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1648 }
1649}
1650
Sony Chacko319ecf12013-01-01 03:20:22 +00001651int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001652{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001653 int ring;
1654 struct qlcnic_host_rds_ring *rds_ring;
1655
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001656 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1657 return -EIO;
1658
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001659 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1660 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001661
Rajesh Borundia0325d692010-08-19 05:08:26 +00001662 if (qlcnic_set_eswitch_port_config(adapter))
1663 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001664
Shahed Shaikh99e85872013-02-18 12:06:16 +00001665 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001666
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001667 if (qlcnic_fw_create_ctx(adapter))
1668 return -EIO;
1669
1670 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001671 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001672 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001673 }
1674
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001675 qlcnic_set_multi(netdev);
1676 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1677
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001678 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001679
1680 if (adapter->max_sds_rings > 1)
1681 qlcnic_config_rss(adapter, 1);
1682
1683 qlcnic_config_intr_coalesce(adapter);
1684
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001685 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001686 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1687
Pratik Pujarcfacb172013-07-19 16:56:27 -04001688 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001689 qlcnic_napi_enable(adapter);
1690
1691 qlcnic_linkevent_request(adapter, 1);
1692
Sony Chacko79788452012-12-04 03:33:53 +00001693 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001694 return 0;
1695}
1696
Sony Chacko629263a2013-01-01 04:11:55 +00001697int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001698{
1699 int err = 0;
1700
1701 rtnl_lock();
1702 if (netif_running(netdev))
1703 err = __qlcnic_up(adapter, netdev);
1704 rtnl_unlock();
1705
1706 return err;
1707}
1708
Sony Chacko319ecf12013-01-01 03:20:22 +00001709void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001710{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001711 int ring;
1712
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001713 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1714 return;
1715
1716 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1717 return;
1718
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001719 if (qlcnic_sriov_vf_check(adapter))
1720 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001721 smp_mb();
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001722 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001723 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001724 netif_tx_disable(netdev);
1725
1726 qlcnic_free_mac_list(adapter);
1727
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001728 if (adapter->fhash.fnum)
1729 qlcnic_delete_lb_filters(adapter);
1730
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001731 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1732
1733 qlcnic_napi_disable(adapter);
1734
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001735 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001736 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001737
1738 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001739
1740 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++)
1741 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001742}
1743
1744/* Usage: During suspend and firmware recovery module */
1745
Sony Chacko629263a2013-01-01 04:11:55 +00001746void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001747{
1748 rtnl_lock();
1749 if (netif_running(netdev))
1750 __qlcnic_down(adapter, netdev);
1751 rtnl_unlock();
1752
1753}
1754
Sony Chacko319ecf12013-01-01 03:20:22 +00001755int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001756qlcnic_attach(struct qlcnic_adapter *adapter)
1757{
1758 struct net_device *netdev = adapter->netdev;
1759 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001760 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001761
1762 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1763 return 0;
1764
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001765 err = qlcnic_napi_add(adapter, netdev);
1766 if (err)
1767 return err;
1768
1769 err = qlcnic_alloc_sw_resources(adapter);
1770 if (err) {
1771 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001772 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001773 }
1774
1775 err = qlcnic_alloc_hw_resources(adapter);
1776 if (err) {
1777 dev_err(&pdev->dev, "Error in setting hw resources\n");
1778 goto err_out_free_sw;
1779 }
1780
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001781 err = qlcnic_request_irq(adapter);
1782 if (err) {
1783 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001784 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001785 }
1786
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001787 qlcnic_create_sysfs_entries(adapter);
1788
1789 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1790 return 0;
1791
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001792err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001793 qlcnic_free_hw_resources(adapter);
1794err_out_free_sw:
1795 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001796err_out_napi_del:
1797 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001798 return err;
1799}
1800
Sony Chacko319ecf12013-01-01 03:20:22 +00001801void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001802{
1803 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1804 return;
1805
1806 qlcnic_remove_sysfs_entries(adapter);
1807
1808 qlcnic_free_hw_resources(adapter);
1809 qlcnic_release_rx_buffers(adapter);
1810 qlcnic_free_irq(adapter);
1811 qlcnic_napi_del(adapter);
1812 qlcnic_free_sw_resources(adapter);
1813
1814 adapter->is_up = 0;
1815}
1816
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001817void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1818{
1819 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1820 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001821 int max_tx_rings = adapter->max_drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001822 int ring;
1823
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001824 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001825 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001826 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001827 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001828 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001829 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001830 }
1831
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001832 qlcnic_fw_destroy_ctx(adapter);
1833
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001834 qlcnic_detach(adapter);
1835
Sony Chacko79788452012-12-04 03:33:53 +00001836 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001837 adapter->max_sds_rings = max_sds_rings;
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001838 adapter->max_drv_tx_rings = max_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001839
1840 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001841 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001842
1843 if (netif_running(netdev))
1844 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001845out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001846 netif_device_attach(netdev);
1847}
1848
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001849static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1850{
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001851 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001852 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001853
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001854 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1855 GFP_KERNEL);
1856 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001857 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001858 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001859 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001860 /* Initialize interrupt coalesce parameters */
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001861 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1862 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1863 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1864 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1865 if (qlcnic_83xx_check(adapter)) {
1866 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1867 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1868 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001869 /* clear stats */
1870 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001871err_out:
1872 return err;
1873}
1874
1875static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1876{
1877 kfree(adapter->recv_ctx);
1878 adapter->recv_ctx = NULL;
1879
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001880 if (adapter->ahw->fw_dump.tmpl_hdr) {
1881 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1882 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1883 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001884
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001885 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001886 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001887}
1888
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001889int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1890{
1891 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1892 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001893 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001894 int ring;
1895 int ret;
1896
1897 netif_device_detach(netdev);
1898
1899 if (netif_running(netdev))
1900 __qlcnic_down(adapter, netdev);
1901
1902 qlcnic_detach(adapter);
1903
1904 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001905 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001906 adapter->ahw->linkup = 0;
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001907 adapter->max_drv_tx_rings = 1;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001908
1909 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001910 if (ret) {
1911 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001912 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001913 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001914
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001915 ret = qlcnic_fw_create_ctx(adapter);
1916 if (ret) {
1917 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001918 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001919 return ret;
1920 }
1921
1922 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001923 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001924 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001925 }
1926
Sony Chacko79788452012-12-04 03:33:53 +00001927 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001928 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001929 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001930 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001931 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001932 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001933
Sony Chacko79788452012-12-04 03:33:53 +00001934 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001935 adapter->ahw->loopback_state = 0;
1936 qlcnic_linkevent_request(adapter, 1);
1937 }
1938
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001939 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001940
1941 return 0;
1942}
1943
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001944/* Reset context in hardware only */
1945static int
1946qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1947{
1948 struct net_device *netdev = adapter->netdev;
1949
1950 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1951 return -EBUSY;
1952
1953 netif_device_detach(netdev);
1954
1955 qlcnic_down(adapter, netdev);
1956
1957 qlcnic_up(adapter, netdev);
1958
1959 netif_device_attach(netdev);
1960
1961 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001962 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001963 return 0;
1964}
1965
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001966int
1967qlcnic_reset_context(struct qlcnic_adapter *adapter)
1968{
1969 int err = 0;
1970 struct net_device *netdev = adapter->netdev;
1971
1972 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1973 return -EBUSY;
1974
1975 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1976
1977 netif_device_detach(netdev);
1978
1979 if (netif_running(netdev))
1980 __qlcnic_down(adapter, netdev);
1981
1982 qlcnic_detach(adapter);
1983
1984 if (netif_running(netdev)) {
1985 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001986 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001987 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001988 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1989 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001990 }
1991
1992 netif_device_attach(netdev);
1993 }
1994
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001995 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1996 return err;
1997}
1998
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04001999void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
2000{
2001 struct qlcnic_hardware_context *ahw = adapter->ahw;
2002 u16 act_pci_fn = ahw->act_pci_func;
2003 u16 count;
2004
2005 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2006 if (act_pci_fn <= 2)
2007 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2008 act_pci_fn;
2009 else
2010 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2011 act_pci_fn;
2012 ahw->max_uc_count = count;
2013}
2014
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002015int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002016qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2017 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002018{
2019 int err;
2020 struct pci_dev *pdev = adapter->pdev;
2021
Sony Chacko13159182013-01-01 03:20:21 +00002022 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002023 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002024 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002025
2026 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002027 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002028
2029 qlcnic_change_mtu(netdev, netdev->mtu);
2030
Rajesh Borundiad1a11052013-04-19 07:01:13 +00002031 if (qlcnic_sriov_vf_check(adapter))
2032 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops);
2033 else
2034 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002035
Sony Chacko7e38d042013-01-01 03:20:28 +00002036 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002037 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002038 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002039 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2040 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002041
Sony Chacko13159182013-01-01 03:20:21 +00002042 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2043 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2044 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2045 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002046
Sony Chacko13159182013-01-01 03:20:21 +00002047 if (pci_using_dac) {
2048 netdev->features |= NETIF_F_HIGHDMA;
2049 netdev->vlan_features |= NETIF_F_HIGHDMA;
2050 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002051
Sony Chacko13159182013-01-01 03:20:21 +00002052 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002053 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002054
Rajesh Borundia91b72822013-04-19 07:01:12 +00002055 if (qlcnic_sriov_vf_check(adapter))
2056 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2057
Sony Chacko79788452012-12-04 03:33:53 +00002058 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002059 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002060
Sony Chacko7e38d042013-01-01 03:20:28 +00002061 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002062 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002063 netdev->irq = adapter->msix_entries[0].vector;
2064
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002065 err = qlcnic_set_real_num_queues(adapter, netdev);
2066 if (err)
2067 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002068
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002069 err = register_netdev(netdev);
2070 if (err) {
2071 dev_err(&pdev->dev, "failed to register net device\n");
2072 return err;
2073 }
2074
Sucheta Chakraborty48365e42013-08-23 13:38:28 -04002075 qlcnic_dcb_init_dcbnl_ops(adapter);
2076
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002077 return 0;
2078}
2079
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002080static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002081{
2082 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2083 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2084 *pci_using_dac = 1;
2085 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2086 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2087 *pci_using_dac = 0;
2088 else {
2089 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2090 return -EIO;
2091 }
2092
2093 return 0;
2094}
2095
Sony Chacko4be41e92013-01-01 03:20:20 +00002096void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2097{
2098 int ring;
2099 struct qlcnic_host_tx_ring *tx_ring;
2100
2101 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
2102 tx_ring = &adapter->tx_ring[ring];
2103 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
2104 vfree(tx_ring->cmd_buf_arr);
2105 tx_ring->cmd_buf_arr = NULL;
2106 }
2107 }
2108 if (adapter->tx_ring != NULL)
2109 kfree(adapter->tx_ring);
2110}
2111
2112int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2113 struct net_device *netdev)
2114{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002115 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002116 struct qlcnic_host_tx_ring *tx_ring;
2117 struct qlcnic_cmd_buffer *cmd_buf_arr;
2118
Joe Perchesb2adaca2013-02-03 17:43:58 +00002119 tx_ring = kcalloc(adapter->max_drv_tx_rings,
2120 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2121 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002122 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002123
Sony Chacko4be41e92013-01-01 03:20:20 +00002124 adapter->tx_ring = tx_ring;
2125
2126 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
2127 tx_ring = &adapter->tx_ring[ring];
2128 tx_ring->num_desc = adapter->num_txd;
2129 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2130 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2131 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002132 qlcnic_free_tx_rings(adapter);
2133 return -ENOMEM;
2134 }
2135 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
2136 tx_ring->cmd_buf_arr = cmd_buf_arr;
2137 }
2138
Himanshu Madhani012ec812013-08-21 11:24:10 -04002139 if (qlcnic_83xx_check(adapter) ||
2140 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002141 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
2142 tx_ring = &adapter->tx_ring[ring];
2143 tx_ring->adapter = adapter;
2144 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
2145 index = adapter->max_sds_rings + ring;
2146 vector = adapter->msix_entries[index].vector;
2147 tx_ring->irq = vector;
2148 }
2149 }
2150 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002151
Sony Chacko4be41e92013-01-01 03:20:20 +00002152 return 0;
2153}
2154
Pratik Pujar8af3f332013-06-22 04:12:05 -04002155void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2156{
2157 struct qlcnic_hardware_context *ahw = adapter->ahw;
2158 u32 fw_cmd = 0;
2159
2160 if (qlcnic_82xx_check(adapter))
2161 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2162 else if (qlcnic_83xx_check(adapter))
2163 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2164
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002165 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002166 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2167}
2168
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002169static int qlcnic_register_dcb(struct qlcnic_adapter *adapter)
2170{
2171 return __qlcnic_register_dcb(adapter);
2172}
2173
2174void qlcnic_clear_dcb_ops(struct qlcnic_adapter *adapter)
2175{
2176 kfree(adapter->dcb);
2177 adapter->dcb = NULL;
2178}
2179
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002180static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002181qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2182{
2183 struct net_device *netdev = NULL;
2184 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002185 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002186 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002187 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002188
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002189 if (pdev->is_virtfn)
2190 return -ENODEV;
2191
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002192 err = pci_enable_device(pdev);
2193 if (err)
2194 return err;
2195
2196 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2197 err = -ENODEV;
2198 goto err_out_disable_pdev;
2199 }
2200
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002201 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2202 if (err)
2203 goto err_out_disable_pdev;
2204
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002205 err = pci_request_regions(pdev, qlcnic_driver_name);
2206 if (err)
2207 goto err_out_disable_pdev;
2208
2209 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002210 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002211
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002212 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002213 if (!ahw) {
2214 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002215 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002216 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002217
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002218 switch (ent->device) {
2219 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002220 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002221 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2222 break;
2223 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002224 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002225 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002226 break;
2227 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002228 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002229 qlcnic_sriov_vf_register_map(ahw);
2230 break;
2231 default:
Sony Chacko13159182013-01-01 03:20:21 +00002232 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002233 }
2234
2235 err = qlcnic_setup_pci_map(pdev, ahw);
2236 if (err)
2237 goto err_out_free_hw_res;
2238
Himanshu Madhani012ec812013-08-21 11:24:10 -04002239 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2240 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002241 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002242 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002243 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002244 }
2245
2246 SET_NETDEV_DEV(netdev, &pdev->dev);
2247
2248 adapter = netdev_priv(netdev);
2249 adapter->netdev = netdev;
2250 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002251 adapter->ahw = ahw;
2252
2253 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2254 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002255 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002256 dev_err(&pdev->dev, "Failed to create workqueue\n");
2257 goto err_out_free_netdev;
2258 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002259
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002260 err = qlcnic_alloc_adapter_resources(adapter);
2261 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002262 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002263
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002264 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002265 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002266 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2267 adapter->fdb_mac_learn = true;
2268 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2269 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002270
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002271 rwlock_init(&adapter->ahw->crb_lock);
2272 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002273
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002274 INIT_LIST_HEAD(&adapter->mac_list);
2275
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002276 qlcnic_register_dcb(adapter);
2277
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002278 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002279 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002280 adapter->portnum = adapter->ahw->pci_func;
2281 err = qlcnic_start_firmware(adapter);
2282 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002283 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2284 "\t\tIf reboot doesn't help, try flashing the card\n");
2285 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002286 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002287
Himanshu Madhani012ec812013-08-21 11:24:10 -04002288 qlcnic_get_multiq_capability(adapter);
2289
2290 if ((adapter->ahw->act_pci_func > 2) &&
2291 qlcnic_check_multi_tx(adapter)) {
2292 adapter->max_drv_tx_rings = QLCNIC_DEF_NUM_TX_RINGS;
2293 dev_info(&adapter->pdev->dev,
2294 "vNIC mode enabled, Set max TX rings = %d\n",
2295 adapter->max_drv_tx_rings);
2296 }
2297
2298 if (!qlcnic_check_multi_tx(adapter)) {
2299 clear_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
2300 adapter->max_drv_tx_rings = 1;
2301 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002302 err = qlcnic_setup_idc_param(adapter);
2303 if (err)
2304 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002305
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002306 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002307
2308 if (adapter->dcb && qlcnic_dcb_attach(adapter))
2309 qlcnic_clear_dcb_ops(adapter);
2310
Sony Chacko13159182013-01-01 03:20:21 +00002311 } else if (qlcnic_83xx_check(adapter)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04002312 adapter->max_drv_tx_rings = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002313 qlcnic_83xx_check_vf(adapter, ent);
2314 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002315 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002316 if (err) {
2317 dev_err(&pdev->dev, "%s: failed\n", __func__);
2318 goto err_out_free_hw;
2319 }
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002320 if (qlcnic_sriov_vf_check(adapter))
2321 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002322 } else {
2323 dev_err(&pdev->dev,
2324 "%s: failed. Please Reboot\n", __func__);
2325 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002326 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002327
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002328 if (qlcnic_read_mac_addr(adapter))
2329 dev_warn(&pdev->dev, "failed to read mac addr\n");
2330
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002331 qlcnic_read_phys_port_id(adapter);
2332
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002333 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002334 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002335
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002336 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002337 module_name(THIS_MODULE),
2338 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002339 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002340
2341 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2342 !!qlcnic_use_msi)
2343 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002344 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002345
Manish Chopra068a8d12013-08-02 00:57:41 -04002346 if (qlcnic_82xx_check(adapter)) {
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002347 err = qlcnic_setup_intr(adapter, 0, 0);
Manish Chopra068a8d12013-08-02 00:57:41 -04002348 if (err) {
2349 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002350 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002351 }
Sony Chacko13159182013-01-01 03:20:21 +00002352 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002353
Sony Chacko02135582013-05-21 09:26:59 +00002354 err = qlcnic_get_act_pci_func(adapter);
2355 if (err)
2356 goto err_out_disable_mbx_intr;
2357
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002358 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002359 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002360 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002361
Himanshu Madhani24866d12013-08-15 08:29:27 -04002362 if (adapter->portnum == 0)
2363 qlcnic_set_drv_version(adapter);
Sritej Velagac84e3402013-01-25 10:20:34 +00002364
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002365 pci_set_drvdata(pdev, adapter);
2366
Sony Chacko97ee45e2012-12-04 03:33:52 +00002367 if (qlcnic_82xx_check(adapter))
2368 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2369 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002370
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002371 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002372 case QLCNIC_GBE:
2373 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2374 adapter->netdev->name);
2375 break;
2376 case QLCNIC_XGBE:
2377 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2378 adapter->netdev->name);
2379 break;
2380 }
2381
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002382 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002383 qlcnic_alloc_lb_filters_mem(adapter);
2384
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002385 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002386
2387 return 0;
2388
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002389err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002390 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002391 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002392
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002393err_out_disable_msi:
2394 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002395 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002396 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002397
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002398err_out_free_hw:
2399 qlcnic_free_adapter_resources(adapter);
2400
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002401err_out_free_wq:
2402 destroy_workqueue(adapter->qlcnic_wq);
2403
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002404err_out_free_netdev:
2405 free_netdev(netdev);
2406
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002407err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002408 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002409
2410err_out_free_hw_res:
2411 kfree(ahw);
2412
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002413err_out_free_res:
2414 pci_release_regions(pdev);
2415
2416err_out_disable_pdev:
2417 pci_set_drvdata(pdev, NULL);
2418 pci_disable_device(pdev);
2419 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002420
2421err_out_maintenance_mode:
2422 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
2423 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
2424 err = register_netdev(netdev);
2425
2426 if (err) {
2427 dev_err(&pdev->dev, "Failed to register net device\n");
2428 qlcnic_clr_all_drv_state(adapter, 0);
2429 goto err_out_free_hw;
2430 }
2431
2432 pci_set_drvdata(pdev, adapter);
2433 qlcnic_add_sysfs(adapter);
2434
2435 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002436}
2437
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002438static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002439{
2440 struct qlcnic_adapter *adapter;
2441 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002442 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002443
2444 adapter = pci_get_drvdata(pdev);
2445 if (adapter == NULL)
2446 return;
2447
2448 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002449 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002450
Sony Chacko13159182013-01-01 03:20:21 +00002451 qlcnic_cancel_idc_work(adapter);
2452 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002453
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002454 qlcnic_dcb_free(adapter);
2455
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002456 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002457 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002458
Sony Chacko13159182013-01-01 03:20:21 +00002459 if (qlcnic_83xx_check(adapter)) {
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002460 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2461 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002462 qlcnic_83xx_free_mbx_intr(adapter);
2463 qlcnic_83xx_detach_mailbox_work(adapter);
2464 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002465 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002466 }
2467
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002468 qlcnic_detach(adapter);
2469
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002470 if (adapter->npars != NULL)
2471 kfree(adapter->npars);
2472 if (adapter->eswitch != NULL)
2473 kfree(adapter->eswitch);
2474
Sony Chacko97ee45e2012-12-04 03:33:52 +00002475 if (qlcnic_82xx_check(adapter))
2476 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002477
2478 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2479
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002480 qlcnic_free_lb_filters_mem(adapter);
2481
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002482 qlcnic_teardown_intr(adapter);
2483
Sony Chacko13159182013-01-01 03:20:21 +00002484 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002485
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002486 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002487
2488 qlcnic_release_firmware(adapter);
2489
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002490 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002491 pci_release_regions(pdev);
2492 pci_disable_device(pdev);
2493 pci_set_drvdata(pdev, NULL);
2494
Sony Chacko13159182013-01-01 03:20:21 +00002495 if (adapter->qlcnic_wq) {
2496 destroy_workqueue(adapter->qlcnic_wq);
2497 adapter->qlcnic_wq = NULL;
2498 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002499
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002500 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002501 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002502 free_netdev(netdev);
2503}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002504
2505static void qlcnic_shutdown(struct pci_dev *pdev)
2506{
2507 if (__qlcnic_shutdown(pdev))
2508 return;
2509
2510 pci_disable_device(pdev);
2511}
2512
2513#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002514static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002515{
2516 int retval;
2517
2518 retval = __qlcnic_shutdown(pdev);
2519 if (retval)
2520 return retval;
2521
2522 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2523 return 0;
2524}
2525
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002526static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002527{
2528 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002529 int err;
2530
2531 err = pci_enable_device(pdev);
2532 if (err)
2533 return err;
2534
2535 pci_set_power_state(pdev, PCI_D0);
2536 pci_set_master(pdev);
2537 pci_restore_state(pdev);
2538
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002539 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002540}
2541#endif
2542
2543static int qlcnic_open(struct net_device *netdev)
2544{
2545 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002546 u32 state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002547 int err;
2548
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002549 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
2550 if (state == QLCNIC_DEV_FAILED || state == QLCNIC_DEV_BADBAD) {
2551 netdev_err(netdev, "%s: Device is in FAILED state\n", __func__);
2552
2553 return -EIO;
2554 }
2555
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002556 netif_carrier_off(netdev);
2557
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002558 err = qlcnic_attach(adapter);
2559 if (err)
2560 return err;
2561
2562 err = __qlcnic_up(adapter, netdev);
2563 if (err)
2564 goto err_out;
2565
Himanshu Madhani012ec812013-08-21 11:24:10 -04002566 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002567
2568 return 0;
2569
2570err_out:
2571 qlcnic_detach(adapter);
2572 return err;
2573}
2574
2575/*
2576 * qlcnic_close - Disables a network interface entry point
2577 */
2578static int qlcnic_close(struct net_device *netdev)
2579{
2580 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2581
2582 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002583
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002584 return 0;
2585}
2586
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002587void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002588{
2589 void *head;
2590 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002591 struct net_device *netdev = adapter->netdev;
2592 u32 filter_size = 0;
2593 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002594
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002595 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002596 return;
2597
Sony Chacko13159182013-01-01 03:20:21 +00002598 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002599 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002600 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002601
Sony Chacko13159182013-01-01 03:20:21 +00002602 if (qlcnic_82xx_check(adapter)) {
2603 filter_size = QLCNIC_LB_MAX_FILTERS;
2604 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2605 } else {
2606 filter_size = QLC_83XX_LB_MAX_FILTERS;
2607 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2608 }
2609
2610 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002611 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002612
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002613 if (!head)
2614 return;
2615
Sony Chacko13159182013-01-01 03:20:21 +00002616 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002617 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002618
Sony Chacko13159182013-01-01 03:20:21 +00002619 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2620 act_pci_func, adapter->fhash.fmax);
2621
2622 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002623 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002624
2625 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2626
2627 head = kcalloc(adapter->rx_fhash.fbucket_size,
2628 sizeof(struct hlist_head), GFP_ATOMIC);
2629
2630 if (!head)
2631 return;
2632
2633 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2634 adapter->rx_fhash.fhead = head;
2635
2636 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2637 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002638}
2639
2640static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2641{
2642 if (adapter->fhash.fmax && adapter->fhash.fhead)
2643 kfree(adapter->fhash.fhead);
2644
2645 adapter->fhash.fhead = NULL;
2646 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002647
2648 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2649 kfree(adapter->rx_fhash.fhead);
2650
2651 adapter->rx_fhash.fmax = 0;
2652 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002653}
2654
Sony Chacko629263a2013-01-01 04:11:55 +00002655int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002656{
2657 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002658 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002659 int rv = 0;
2660
Sony Chacko13159182013-01-01 03:20:21 +00002661 if (qlcnic_83xx_check(adapter))
2662 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2663
Sony Chacko97ee45e2012-12-04 03:33:52 +00002664 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002665 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002666
2667 temp_state = qlcnic_get_temp_state(temp);
2668 temp_val = qlcnic_get_temp_val(temp);
2669
2670 if (temp_state == QLCNIC_TEMP_PANIC) {
2671 dev_err(&netdev->dev,
2672 "Device temperature %d degrees C exceeds"
2673 " maximum allowed. Hardware has been shut down.\n",
2674 temp_val);
2675 rv = 1;
2676 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002677 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002678 dev_err(&netdev->dev,
2679 "Device temperature %d degrees C "
2680 "exceeds operating range."
2681 " Immediate action needed.\n",
2682 temp_val);
2683 }
2684 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002685 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002686 dev_info(&netdev->dev,
2687 "Device temperature is now %d degrees C"
2688 " in normal range.\n", temp_val);
2689 }
2690 }
Sony Chacko79788452012-12-04 03:33:53 +00002691 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002692 return rv;
2693}
2694
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002695static void qlcnic_tx_timeout(struct net_device *netdev)
2696{
2697 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002698 struct qlcnic_host_tx_ring *tx_ring;
2699 int ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002700
2701 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2702 return;
2703
Sony Chacko536faa62013-05-09 09:25:13 +00002704 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
2705 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
2706 if (qlcnic_82xx_check(adapter))
2707 adapter->need_fw_reset = 1;
2708 else if (qlcnic_83xx_check(adapter))
2709 qlcnic_83xx_idc_request_reset(adapter,
2710 QLCNIC_FORCE_FW_DUMP_KEY);
2711 } else {
2712 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Himanshu Madhani012ec812013-08-21 11:24:10 -04002713 if (qlcnic_82xx_check(adapter)) {
2714 for (ring = 0; ring < adapter->max_drv_tx_rings;
2715 ring++) {
2716 tx_ring = &adapter->tx_ring[ring];
2717 dev_info(&netdev->dev, "ring=%d\n", ring);
2718 dev_info(&netdev->dev, "crb_intr_mask=%d\n",
2719 readl(tx_ring->crb_intr_mask));
2720 dev_info(&netdev->dev, "producer=%d\n",
2721 readl(tx_ring->crb_cmd_producer));
2722 dev_info(&netdev->dev, "sw_consumer = %d\n",
2723 tx_ring->sw_consumer);
2724 dev_info(&netdev->dev, "hw_consumer = %d\n",
2725 le32_to_cpu(*(tx_ring->hw_consumer)));
2726 dev_info(&netdev->dev, "xmit-on=%llu\n",
2727 tx_ring->xmit_on);
2728 dev_info(&netdev->dev, "xmit-off=%llu\n",
2729 tx_ring->xmit_off);
2730 }
2731 }
Sony Chacko79788452012-12-04 03:33:53 +00002732 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00002733 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002734}
2735
2736static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2737{
2738 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2739 struct net_device_stats *stats = &netdev->stats;
2740
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002741 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2742 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002743 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002744 stats->tx_bytes = adapter->stats.txbytes;
2745 stats->rx_dropped = adapter->stats.rxdropped;
2746 stats->tx_dropped = adapter->stats.txdropped;
2747
2748 return stats;
2749}
2750
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002751irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002752{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002753 u32 status;
2754
2755 status = readl(adapter->isr_int_vec);
2756
Sony Chacko79788452012-12-04 03:33:53 +00002757 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002758 return IRQ_NONE;
2759
2760 /* check interrupt state machine, to be sure */
2761 status = readl(adapter->crb_int_state_reg);
2762 if (!ISR_LEGACY_INT_TRIGGERED(status))
2763 return IRQ_NONE;
2764
2765 writel(0xffffffff, adapter->tgt_status_reg);
2766 /* read twice to ensure write is flushed */
2767 readl(adapter->isr_int_vec);
2768 readl(adapter->isr_int_vec);
2769
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002770 return IRQ_HANDLED;
2771}
2772
2773static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2774{
2775 struct qlcnic_host_sds_ring *sds_ring = data;
2776 struct qlcnic_adapter *adapter = sds_ring->adapter;
2777
2778 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2779 goto done;
2780 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2781 writel(0xffffffff, adapter->tgt_status_reg);
2782 goto done;
2783 }
2784
2785 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2786 return IRQ_NONE;
2787
2788done:
Sony Chacko79788452012-12-04 03:33:53 +00002789 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002790 qlcnic_enable_int(sds_ring);
2791 return IRQ_HANDLED;
2792}
2793
2794static irqreturn_t qlcnic_intr(int irq, void *data)
2795{
2796 struct qlcnic_host_sds_ring *sds_ring = data;
2797 struct qlcnic_adapter *adapter = sds_ring->adapter;
2798
2799 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2800 return IRQ_NONE;
2801
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802 napi_schedule(&sds_ring->napi);
2803
2804 return IRQ_HANDLED;
2805}
2806
2807static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2808{
2809 struct qlcnic_host_sds_ring *sds_ring = data;
2810 struct qlcnic_adapter *adapter = sds_ring->adapter;
2811
2812 /* clear interrupt */
2813 writel(0xffffffff, adapter->tgt_status_reg);
2814
2815 napi_schedule(&sds_ring->napi);
2816 return IRQ_HANDLED;
2817}
2818
2819static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2820{
2821 struct qlcnic_host_sds_ring *sds_ring = data;
2822
2823 napi_schedule(&sds_ring->napi);
2824 return IRQ_HANDLED;
2825}
2826
Sony Chacko13159182013-01-01 03:20:21 +00002827static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2828{
2829 struct qlcnic_host_tx_ring *tx_ring = data;
2830
2831 napi_schedule(&tx_ring->napi);
2832 return IRQ_HANDLED;
2833}
2834
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002835#ifdef CONFIG_NET_POLL_CONTROLLER
2836static void qlcnic_poll_controller(struct net_device *netdev)
2837{
Yinglin Luanbf827912010-08-22 21:57:56 +00002838 int ring;
2839 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002840 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002841 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002842
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002843 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002844 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2845 sds_ring = &recv_ctx->sds_rings[ring];
2846 qlcnic_intr(adapter->irq, sds_ring);
2847 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002848 enable_irq(adapter->irq);
2849}
2850#endif
2851
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002852static void
2853qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2854{
2855 u32 val;
2856
2857 val = adapter->portnum & 0xf;
2858 val |= encoding << 7;
2859 val |= (jiffies - adapter->dev_rst_time) << 8;
2860
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002861 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002862 adapter->dev_rst_time = jiffies;
2863}
2864
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002865static int
2866qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002867{
2868 u32 val;
2869
2870 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2871 state != QLCNIC_DEV_NEED_QUISCENT);
2872
2873 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002874 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002875
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002876 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002877
2878 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002879 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002880 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002881 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002882
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002883 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002884
2885 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002886
2887 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002888}
2889
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002890static int
2891qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2892{
2893 u32 val;
2894
2895 if (qlcnic_api_lock(adapter))
2896 return -EBUSY;
2897
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002898 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002899 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002900 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002901
2902 qlcnic_api_unlock(adapter);
2903
2904 return 0;
2905}
2906
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002907void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002908{
2909 u32 val;
2910
2911 if (qlcnic_api_lock(adapter))
2912 goto err;
2913
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002914 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002915 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002916 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002917
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002918 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002919 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2920 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002921 dev_info(&adapter->pdev->dev,
2922 "Device state set to Failed. Please Reboot\n");
2923 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002924 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2925 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002926
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002927 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002928 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002929 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002930
2931 qlcnic_api_unlock(adapter);
2932err:
2933 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002934 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002935 clear_bit(__QLCNIC_START_FW, &adapter->state);
2936 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2937}
2938
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002939/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002940static int
2941qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2942{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002943 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002944 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002945
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002946 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2947 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002948
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002949 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002950 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002951 act = act & active_mask;
2952 }
2953
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002954 if (((state & 0x11111111) == (act & 0x11111111)) ||
2955 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2956 return 0;
2957 else
2958 return 1;
2959}
2960
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002961static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2962{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002963 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002964
2965 if (val != QLCNIC_DRV_IDC_VER) {
2966 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2967 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2968 }
2969
2970 return 0;
2971}
2972
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002973static int
2974qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2975{
2976 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002977 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002978 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002979 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002980
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002981 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2982 return 1;
2983
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002984 if (qlcnic_api_lock(adapter))
2985 return -1;
2986
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002987 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002988 if (!(val & (1 << (portnum * 4)))) {
2989 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002990 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002991 }
2992
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002993 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002994 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002995
2996 switch (prev_state) {
2997 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002998 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2999 QLCNIC_DEV_INITIALIZING);
3000 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3001 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003002 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003003 qlcnic_api_unlock(adapter);
3004 return 1;
3005
3006 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003007 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003008 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003009 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003010
3011 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003012 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003013 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003014 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003015 break;
3016
3017 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003018 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003019 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003020 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003021 break;
3022
3023 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003024 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003025 qlcnic_api_unlock(adapter);
3026 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003027
3028 case QLCNIC_DEV_INITIALIZING:
3029 case QLCNIC_DEV_QUISCENT:
3030 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003031 }
3032
3033 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003034
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003035 do {
3036 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003037 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003038
3039 if (prev_state == QLCNIC_DEV_QUISCENT)
3040 continue;
3041 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003042
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003043 if (!dev_init_timeo) {
3044 dev_err(&adapter->pdev->dev,
3045 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003046 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003047 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003048
3049 if (qlcnic_api_lock(adapter))
3050 return -1;
3051
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003052 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003053 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003054 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003055
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003056 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003057 qlcnic_api_unlock(adapter);
3058
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003059 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003060}
3061
3062static void
3063qlcnic_fwinit_work(struct work_struct *work)
3064{
3065 struct qlcnic_adapter *adapter = container_of(work,
3066 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003067 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003068 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003069
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003070 if (qlcnic_api_lock(adapter))
3071 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003072
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003073 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003074 if (dev_state == QLCNIC_DEV_QUISCENT ||
3075 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003076 qlcnic_api_unlock(adapter);
3077 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3078 FW_POLL_DELAY * 2);
3079 return;
3080 }
3081
Sony Chacko79788452012-12-04 03:33:53 +00003082 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003083 qlcnic_api_unlock(adapter);
3084 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003085 }
3086
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003087 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3088 dev_state == QLCNIC_DEV_READY) {
3089 dev_info(&adapter->pdev->dev, "Detected state change from "
3090 "DEV_NEED_RESET, skipping ack check\n");
3091 goto skip_ack_check;
3092 }
3093
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003094 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003095 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003096 adapter->reset_ack_timeo);
3097 goto skip_ack_check;
3098 }
3099
3100 if (!qlcnic_check_drv_state(adapter)) {
3101skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003102 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003103
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003104 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003105 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3106 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003107 set_bit(__QLCNIC_START_FW, &adapter->state);
3108 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003109 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003110 val = QLC_SHARED_REG_RD32(adapter,
3111 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003112 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003113 QLC_SHARED_REG_WR32(adapter,
3114 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003115 }
3116
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003117 qlcnic_api_unlock(adapter);
3118
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003119 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003120 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003121 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003122 QLCDB(adapter, DRV, "Take FW dump\n");
3123 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003124 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003125 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003126 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003127
3128 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003129 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003130 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003131 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003132 return;
3133 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003134 goto err_ret;
3135 }
3136
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003137 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003138
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003139wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003140 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003141 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003142
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003143 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003144 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003145 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003146 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003147 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003148 return;
3149 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003150 case QLCNIC_DEV_FAILED:
3151 break;
3152 default:
3153 qlcnic_schedule_work(adapter,
3154 qlcnic_fwinit_work, FW_POLL_DELAY);
3155 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003156 }
3157
3158err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003159 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3160 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003161 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003162 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003163}
3164
3165static void
3166qlcnic_detach_work(struct work_struct *work)
3167{
3168 struct qlcnic_adapter *adapter = container_of(work,
3169 struct qlcnic_adapter, fw_work.work);
3170 struct net_device *netdev = adapter->netdev;
3171 u32 status;
3172
3173 netif_device_detach(netdev);
3174
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003175 /* Dont grab rtnl lock during Quiscent mode */
3176 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3177 if (netif_running(netdev))
3178 __qlcnic_down(adapter, netdev);
3179 } else
3180 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003181
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003182 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003183
Sony Chacko44f65b22011-08-29 12:50:26 +00003184 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3185 dev_err(&adapter->pdev->dev,
3186 "Detaching the device: peg halt status1=0x%x\n",
3187 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003188
Sony Chacko44f65b22011-08-29 12:50:26 +00003189 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3190 dev_err(&adapter->pdev->dev,
3191 "On board active cooling fan failed. "
3192 "Device has been halted.\n");
3193 dev_err(&adapter->pdev->dev,
3194 "Replace the adapter.\n");
3195 }
3196
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003197 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003198 }
3199
Sony Chacko79788452012-12-04 03:33:53 +00003200 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003201 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003202 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003203 goto err_ret;
3204 }
3205
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003206 /* Dont ack if this instance is the reset owner */
3207 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003208 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3209 dev_err(&adapter->pdev->dev,
3210 "Failed to set driver state,"
3211 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003212 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003213 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003214 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003215
3216 adapter->fw_wait_cnt = 0;
3217
3218 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3219
3220 return;
3221
3222err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003223 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003224 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003225}
3226
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003227/*Transit NPAR state to NON Operational */
3228static void
3229qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3230{
3231 u32 state;
3232
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003233 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003234 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3235 return;
3236
3237 if (qlcnic_api_lock(adapter))
3238 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003239 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3240 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003241 qlcnic_api_unlock(adapter);
3242}
3243
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003244void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003245{
Sritej Velaga646779f2012-02-03 13:45:41 +00003246 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003247
Sritej Velaga646779f2012-02-03 13:45:41 +00003248 qlcnic_xg_set_xg0_mask(xg_val);
3249 qlcnic_xg_set_xg1_mask(xg_val);
3250 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3251 qlcnic_gb_set_gb0_mask(gb_val);
3252 qlcnic_gb_set_gb1_mask(gb_val);
3253 qlcnic_gb_set_gb2_mask(gb_val);
3254 qlcnic_gb_set_gb3_mask(gb_val);
3255 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3256 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3257 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003258 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003259
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003260 if (qlcnic_api_lock(adapter))
3261 return;
3262
Sony Chacko13159182013-01-01 03:20:21 +00003263 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003264 if (state == QLCNIC_DEV_FAILED || state == QLCNIC_DEV_BADBAD) {
3265 netdev_err(adapter->netdev, "%s: Device is in FAILED state\n",
3266 __func__);
3267 qlcnic_api_unlock(adapter);
3268
3269 return;
3270 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003271
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003272 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003273 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3274 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003275 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003276 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003277 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003278 }
3279
Sony Chacko13159182013-01-01 03:20:21 +00003280 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3281 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003282 qlcnic_api_unlock(adapter);
3283}
3284
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003285/* Transit to NPAR READY state from NPAR NOT READY state */
3286static void
3287qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3288{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003289 if (qlcnic_api_lock(adapter))
3290 return;
3291
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003292 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3293 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003294 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003295
3296 qlcnic_api_unlock(adapter);
3297}
3298
Sony Chacko13159182013-01-01 03:20:21 +00003299void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3300 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003301{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003302 if (test_bit(__QLCNIC_AER, &adapter->state))
3303 return;
3304
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003305 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003306 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3307 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003308}
3309
3310static void
3311qlcnic_attach_work(struct work_struct *work)
3312{
3313 struct qlcnic_adapter *adapter = container_of(work,
3314 struct qlcnic_adapter, fw_work.work);
3315 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003316 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003317
Sony Chacko79788452012-12-04 03:33:53 +00003318 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003319 npar_state = QLC_SHARED_REG_RD32(adapter,
3320 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003321 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3322 qlcnic_clr_all_drv_state(adapter, 0);
3323 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3324 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3325 FW_POLL_DELAY);
3326 else
3327 goto attach;
3328 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3329 return;
3330 }
3331attach:
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003332 qlcnic_dcb_get_info(adapter);
3333
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003334 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003335 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003336 goto done;
3337
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003338 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003339 }
3340
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003341done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003342 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003343 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003344 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003345 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003346 if (adapter->portnum == 0)
3347 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003348
3349 if (!qlcnic_clr_drv_state(adapter))
3350 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3351 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003352}
3353
3354static int
3355qlcnic_check_health(struct qlcnic_adapter *adapter)
3356{
Sony Chacko4e708122010-08-31 17:17:44 +00003357 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003358 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003359 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003360
3361 if (qlcnic_check_temp(adapter))
3362 goto detach;
3363
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003364 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003365 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003366
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003367 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003368 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003369 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003370 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003371 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3372 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003373
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003374 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003375 if (heartbeat != adapter->heartbeat) {
3376 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003377 adapter->fw_fail_cnt = 0;
3378 if (adapter->need_fw_reset)
3379 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003380
Sony Chacko0ce54ce2013-05-21 09:27:00 +00003381 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003382 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003383
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003384 return 0;
3385 }
3386
3387 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3388 return 0;
3389
Sritej Velaga032a13c2011-07-29 13:30:27 +00003390 adapter->flags |= QLCNIC_FW_HANG;
3391
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003392 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003393
Sony Chacko099f7aa2012-12-04 03:33:58 +00003394 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003395 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003396
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003397 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003398 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003399 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003400 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3401 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3402 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3403 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003404 peg_status,
3405 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003406 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3407 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3408 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3409 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3410 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003411 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003412 dev_err(&adapter->pdev->dev,
3413 "Firmware aborted with error code 0x00006700. "
3414 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003415detach:
3416 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3417 QLCNIC_DEV_NEED_RESET;
3418
Sony Chacko099f7aa2012-12-04 03:33:58 +00003419 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3420 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003421
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003422 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003423 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3424 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003425
3426 return 1;
3427}
3428
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003429void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003430{
3431 struct qlcnic_adapter *adapter = container_of(work,
3432 struct qlcnic_adapter, fw_work.work);
3433
3434 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3435 goto reschedule;
3436
3437
3438 if (qlcnic_check_health(adapter))
3439 return;
3440
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003441 if (adapter->fhash.fnum)
3442 qlcnic_prune_lb_filters(adapter);
3443
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003444reschedule:
3445 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3446}
3447
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003448static int qlcnic_is_first_func(struct pci_dev *pdev)
3449{
3450 struct pci_dev *oth_pdev;
3451 int val = pdev->devfn;
3452
3453 while (val-- > 0) {
3454 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3455 (pdev->bus), pdev->bus->number,
3456 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003457 if (!oth_pdev)
3458 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003459
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003460 if (oth_pdev->current_state != PCI_D3cold) {
3461 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003462 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003463 }
3464 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003465 }
3466 return 1;
3467}
3468
3469static int qlcnic_attach_func(struct pci_dev *pdev)
3470{
3471 int err, first_func;
3472 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3473 struct net_device *netdev = adapter->netdev;
3474
3475 pdev->error_state = pci_channel_io_normal;
3476
3477 err = pci_enable_device(pdev);
3478 if (err)
3479 return err;
3480
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003481 pci_set_master(pdev);
3482 pci_restore_state(pdev);
3483
3484 first_func = qlcnic_is_first_func(pdev);
3485
3486 if (qlcnic_api_lock(adapter))
3487 return -EINVAL;
3488
Sony Chacko79788452012-12-04 03:33:53 +00003489 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003490 adapter->need_fw_reset = 1;
3491 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003492 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3493 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003494 QLCDB(adapter, DRV, "Restarting fw\n");
3495 }
3496 qlcnic_api_unlock(adapter);
3497
Sony Chacko13159182013-01-01 03:20:21 +00003498 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003499 if (err)
3500 return err;
3501
3502 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003503 kfree(adapter->msix_entries);
3504 adapter->msix_entries = NULL;
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003505 err = qlcnic_setup_intr(adapter, 0, 0);
Sony Chacko13159182013-01-01 03:20:21 +00003506
Manish chopra9a97e702013-01-25 10:20:37 +00003507 if (err) {
3508 kfree(adapter->msix_entries);
3509 netdev_err(netdev, "failed to setup interrupt\n");
3510 return err;
3511 }
3512
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003513 if (netif_running(netdev)) {
3514 err = qlcnic_attach(adapter);
3515 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003516 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003517 clear_bit(__QLCNIC_AER, &adapter->state);
3518 netif_device_attach(netdev);
3519 return err;
3520 }
3521
3522 err = qlcnic_up(adapter, netdev);
3523 if (err)
3524 goto done;
3525
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003526 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003527 }
3528 done:
3529 netif_device_attach(netdev);
3530 return err;
3531}
3532
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003533pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3534 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003535{
3536 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3537 struct net_device *netdev = adapter->netdev;
3538
3539 if (state == pci_channel_io_perm_failure)
3540 return PCI_ERS_RESULT_DISCONNECT;
3541
3542 if (state == pci_channel_io_normal)
3543 return PCI_ERS_RESULT_RECOVERED;
3544
3545 set_bit(__QLCNIC_AER, &adapter->state);
3546 netif_device_detach(netdev);
3547
3548 cancel_delayed_work_sync(&adapter->fw_work);
3549
3550 if (netif_running(netdev))
3551 qlcnic_down(adapter, netdev);
3552
3553 qlcnic_detach(adapter);
3554 qlcnic_teardown_intr(adapter);
3555
3556 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3557
3558 pci_save_state(pdev);
3559 pci_disable_device(pdev);
3560
3561 return PCI_ERS_RESULT_NEED_RESET;
3562}
3563
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003564pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003565{
3566 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3567 PCI_ERS_RESULT_RECOVERED;
3568}
3569
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003570void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003571{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003572 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003573 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3574
3575 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003576 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3577 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3578 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003579 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003580 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003581}
3582
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003583static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3584 pci_channel_state_t state)
3585{
3586 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3587 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3588
3589 if (hw_ops->io_error_detected) {
3590 return hw_ops->io_error_detected(pdev, state);
3591 } else {
3592 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3593 return PCI_ERS_RESULT_DISCONNECT;
3594 }
3595}
3596
3597static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3598{
3599 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3600 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3601
3602 if (hw_ops->io_slot_reset) {
3603 return hw_ops->io_slot_reset(pdev);
3604 } else {
3605 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
3606 return PCI_ERS_RESULT_DISCONNECT;
3607 }
3608}
3609
3610static void qlcnic_io_resume(struct pci_dev *pdev)
3611{
3612 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3613 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3614
3615 if (hw_ops->io_resume)
3616 hw_ops->io_resume(pdev);
3617 else
3618 dev_err(&pdev->dev, "AER resume handler not registered.\n");
3619}
3620
3621
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003622static int
3623qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3624{
3625 int err;
3626
3627 err = qlcnic_can_start_firmware(adapter);
3628 if (err)
3629 return err;
3630
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003631 err = qlcnic_check_npar_opertional(adapter);
3632 if (err)
3633 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003634
Rajesh Borundia174240a2010-08-31 17:17:47 +00003635 err = qlcnic_initialize_nic(adapter);
3636 if (err)
3637 return err;
3638
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003639 qlcnic_check_options(adapter);
3640
Rajesh Borundia73733732010-08-31 17:17:50 +00003641 err = qlcnic_set_eswitch_port_config(adapter);
3642 if (err)
3643 return err;
3644
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003645 adapter->need_fw_reset = 0;
3646
3647 return err;
3648}
3649
Dan Carpenter80b17be2013-08-27 04:16:22 +03003650int qlcnic_validate_max_tx_rings(struct qlcnic_adapter *adapter, u32 txq)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003651{
3652 struct net_device *netdev = adapter->netdev;
3653 u8 max_hw = QLCNIC_MAX_TX_RINGS;
3654 u32 max_allowed;
3655
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003656 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
3657 netdev_err(netdev, "No Multi TX-Q support in INT-x mode\n");
3658 return -EINVAL;
3659 }
3660
3661 if (!qlcnic_check_multi_tx(adapter)) {
3662 netdev_err(netdev, "No Multi TX-Q support\n");
3663 return -EINVAL;
3664 }
3665
3666 if (txq > QLCNIC_MAX_TX_RINGS) {
3667 netdev_err(netdev, "Invalid ring count\n");
3668 return -EINVAL;
3669 }
3670
3671 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3672 num_online_cpus()));
3673 if ((txq > max_allowed) || !is_power_of_2(txq)) {
3674 if (!is_power_of_2(txq))
3675 netdev_err(netdev,
3676 "TX queue should be a power of 2\n");
3677 if (txq > num_online_cpus())
3678 netdev_err(netdev,
3679 "Tx queue should not be higher than [%u], number of online CPUs in the system\n",
3680 num_online_cpus());
3681 netdev_err(netdev, "Unable to configure %u Tx rings\n", txq);
3682 return -EINVAL;
3683 }
3684
3685 return 0;
3686}
3687
Manish Chopra6389b762013-04-24 12:42:39 +00003688int qlcnic_validate_max_rss(struct qlcnic_adapter *adapter,
Himanshu Madhani012ec812013-08-21 11:24:10 -04003689 __u32 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003690{
Manish Chopra6389b762013-04-24 12:42:39 +00003691 struct net_device *netdev = adapter->netdev;
3692 u8 max_hw = adapter->ahw->max_rx_ques;
Sony Chacko319ecf12013-01-01 03:20:22 +00003693 u32 max_allowed;
3694
Himanshu Madhani66c562e2013-10-17 18:26:38 -04003695 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003696 netdev_err(netdev, "No RSS support in INT-x mode\n");
3697 return -EINVAL;
3698 }
3699
Himanshu Madhani012ec812013-08-21 11:24:10 -04003700 if (val > QLCNIC_MAX_SDS_RINGS) {
Manish Chopra6389b762013-04-24 12:42:39 +00003701 netdev_err(netdev, "RSS value should not be higher than %u\n",
Himanshu Madhani012ec812013-08-21 11:24:10 -04003702 QLCNIC_MAX_SDS_RINGS);
Manish Chopra6389b762013-04-24 12:42:39 +00003703 return -EINVAL;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003704 }
3705
Sony Chacko319ecf12013-01-01 03:20:22 +00003706 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3707 num_online_cpus()));
3708 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
Manish Chopra6389b762013-04-24 12:42:39 +00003709 if (!is_power_of_2(val))
3710 netdev_err(netdev, "RSS value should be a power of 2\n");
3711
3712 if (val < 2)
3713 netdev_err(netdev, "RSS value should not be lower than 2\n");
3714
3715 if (val > max_hw)
3716 netdev_err(netdev,
3717 "RSS value should not be higher than[%u], the max RSS rings supported by the adapter\n",
3718 max_hw);
3719
3720 if (val > num_online_cpus())
3721 netdev_err(netdev,
3722 "RSS value should not be higher than[%u], number of online CPUs in the system\n",
3723 num_online_cpus());
3724
3725 netdev_err(netdev, "Unable to configure %u RSS rings\n", val);
3726
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003727 return -EINVAL;
3728 }
3729 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003730}
3731
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003732int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, int txq)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003733{
Sony Chacko13159182013-01-01 03:20:21 +00003734 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003735 struct net_device *netdev = adapter->netdev;
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003736 int num_msix;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003737
Sony Chacko319ecf12013-01-01 03:20:22 +00003738 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3739 return -EBUSY;
3740
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003741 if (qlcnic_82xx_check(adapter) && !qlcnic_use_msi_x &&
3742 !qlcnic_use_msi) {
3743 netdev_err(netdev, "No RSS support in INT-x mode\n");
3744 return -EINVAL;
3745 }
3746
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003747 netif_device_detach(netdev);
3748 if (netif_running(netdev))
3749 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003750
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003751 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003752
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003753 if (qlcnic_82xx_check(adapter)) {
3754 if (txq != 0)
3755 adapter->max_drv_tx_rings = txq;
3756
3757 if (qlcnic_check_multi_tx(adapter) &&
3758 (txq > adapter->max_drv_tx_rings))
3759 num_msix = adapter->max_drv_tx_rings;
3760 else
3761 num_msix = data;
3762 }
3763
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003764 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003765 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003766 qlcnic_83xx_enable_mbx_poll(adapter);
3767 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003768
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003769 netif_set_real_num_tx_queues(netdev, adapter->max_drv_tx_rings);
3770
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003771 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003772
3773 err = qlcnic_setup_intr(adapter, data, txq);
Manish chopra9a97e702013-01-25 10:20:37 +00003774 if (err) {
3775 kfree(adapter->msix_entries);
3776 netdev_err(netdev, "failed to setup interrupt\n");
3777 return err;
3778 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003779
Sony Chacko13159182013-01-01 03:20:21 +00003780 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003781 /* register for NIC IDC AEN Events */
3782 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003783 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003784 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003785 if (err) {
3786 dev_err(&adapter->pdev->dev,
3787 "failed to setup mbx interrupt\n");
3788 goto done;
3789 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003790 }
3791
3792 if (netif_running(netdev)) {
3793 err = qlcnic_attach(adapter);
3794 if (err)
3795 goto done;
3796 err = __qlcnic_up(adapter, netdev);
3797 if (err)
3798 goto done;
3799 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3800 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003801done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003802 netif_device_attach(netdev);
3803 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3804 return err;
3805}
3806
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003807#ifdef CONFIG_INET
3808
3809#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3810
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003811static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003812qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3813 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003814{
3815 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003816
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003817 indev = in_dev_get(dev);
3818 if (!indev)
3819 return;
3820
3821 for_ifa(indev) {
3822 switch (event) {
3823 case NETDEV_UP:
3824 qlcnic_config_ipaddr(adapter,
3825 ifa->ifa_address, QLCNIC_IP_UP);
3826 break;
3827 case NETDEV_DOWN:
3828 qlcnic_config_ipaddr(adapter,
3829 ifa->ifa_address, QLCNIC_IP_DOWN);
3830 break;
3831 default:
3832 break;
3833 }
3834 } endfor_ifa(indev);
3835
3836 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003837}
3838
Sony Chacko319ecf12013-01-01 03:20:22 +00003839void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003840{
3841 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3842 struct net_device *dev;
3843 u16 vid;
3844
3845 qlcnic_config_indev_addr(adapter, netdev, event);
3846
Jiri Pirko43c00a72013-01-03 22:48:57 +00003847 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003848 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003849 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003850 if (!dev)
3851 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003852 qlcnic_config_indev_addr(adapter, dev, event);
3853 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003854 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003855}
3856
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003857static int qlcnic_netdev_event(struct notifier_block *this,
3858 unsigned long event, void *ptr)
3859{
3860 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00003861 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003862
3863recheck:
3864 if (dev == NULL)
3865 goto done;
3866
3867 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3868 dev = vlan_dev_real_dev(dev);
3869 goto recheck;
3870 }
3871
3872 if (!is_qlcnic_netdev(dev))
3873 goto done;
3874
3875 adapter = netdev_priv(dev);
3876
3877 if (!adapter)
3878 goto done;
3879
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003880 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003881 goto done;
3882
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003883 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003884done:
3885 return NOTIFY_DONE;
3886}
3887
3888static int
3889qlcnic_inetaddr_event(struct notifier_block *this,
3890 unsigned long event, void *ptr)
3891{
3892 struct qlcnic_adapter *adapter;
3893 struct net_device *dev;
3894
3895 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3896
3897 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3898
3899recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003900 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003901 goto done;
3902
3903 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3904 dev = vlan_dev_real_dev(dev);
3905 goto recheck;
3906 }
3907
3908 if (!is_qlcnic_netdev(dev))
3909 goto done;
3910
3911 adapter = netdev_priv(dev);
3912
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003913 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003914 goto done;
3915
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003916 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003917 goto done;
3918
3919 switch (event) {
3920 case NETDEV_UP:
3921 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003922
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003923 break;
3924 case NETDEV_DOWN:
3925 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003926
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003927 break;
3928 default:
3929 break;
3930 }
3931
3932done:
3933 return NOTIFY_DONE;
3934}
3935
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003936static struct notifier_block qlcnic_netdev_cb = {
3937 .notifier_call = qlcnic_netdev_event,
3938};
3939
3940static struct notifier_block qlcnic_inetaddr_cb = {
3941 .notifier_call = qlcnic_inetaddr_event,
3942};
3943#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003944void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003945{ }
3946#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003947static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003948 .error_detected = qlcnic_io_error_detected,
3949 .slot_reset = qlcnic_io_slot_reset,
3950 .resume = qlcnic_io_resume,
3951};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003952
3953static struct pci_driver qlcnic_driver = {
3954 .name = qlcnic_driver_name,
3955 .id_table = qlcnic_pci_tbl,
3956 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003957 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003958#ifdef CONFIG_PM
3959 .suspend = qlcnic_suspend,
3960 .resume = qlcnic_resume,
3961#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003962 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003963 .err_handler = &qlcnic_err_handler,
3964#ifdef CONFIG_QLCNIC_SRIOV
3965 .sriov_configure = qlcnic_pci_sriov_configure,
3966#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003967
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003968};
3969
3970static int __init qlcnic_init_module(void)
3971{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003972 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003973
3974 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3975
3976#ifdef CONFIG_INET
3977 register_netdevice_notifier(&qlcnic_netdev_cb);
3978 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3979#endif
3980
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003981 ret = pci_register_driver(&qlcnic_driver);
3982 if (ret) {
3983#ifdef CONFIG_INET
3984 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3985 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3986#endif
3987 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003988
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003989 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003990}
3991
3992module_init(qlcnic_init_module);
3993
3994static void __exit qlcnic_exit_module(void)
3995{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003996 pci_unregister_driver(&qlcnic_driver);
3997
3998#ifdef CONFIG_INET
3999 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4000 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4001#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004002}
4003
4004module_exit(qlcnic_exit_module);