blob: 1222865cfb7319b4ec085c035c00c862cff6dcd2 [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
stephen hemminger21041402014-01-16 10:31:27 -080084static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *);
85static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *, u32);
86static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *);
87static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *);
88static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *);
89static void qlcnic_82xx_io_resume(struct pci_dev *);
90static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *);
91static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *,
92 pci_channel_state_t);
93
Sony Chacko13159182013-01-01 03:20:21 +000094static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
95{
96 struct qlcnic_hardware_context *ahw = adapter->ahw;
97
98 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
99 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
100 else
101 return 1;
102}
103
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000104/* PCI Device ID Table */
105#define ENTRY(device) \
106 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
107 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
108
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000109static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000110 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000112 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Manish Chopra15ca1402013-08-16 19:07:13 -0400113 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE844X),
114 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE844X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000115 {0,}
116};
117
118MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
119
120
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000121inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000122{
123 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000124}
125
126static const u32 msi_tgt_status[8] = {
127 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
128 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
129 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
130 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
131};
132
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000133static const u32 qlcnic_reg_tbl[] = {
134 0x1B20A8, /* PEG_HALT_STAT1 */
135 0x1B20AC, /* PEG_HALT_STAT2 */
136 0x1B20B0, /* FW_HEARTBEAT */
137 0x1B2100, /* LOCK ID */
138 0x1B2128, /* FW_CAPABILITIES */
139 0x1B2138, /* drv active */
140 0x1B2140, /* dev state */
141 0x1B2144, /* drv state */
142 0x1B2148, /* drv scratch */
143 0x1B214C, /* dev partition info */
144 0x1B2174, /* drv idc ver */
145 0x1B2150, /* fw version major */
146 0x1B2154, /* fw version minor */
147 0x1B2158, /* fw version sub */
148 0x1B219C, /* npar state */
149 0x1B21FC, /* FW_IMG_VALID */
150 0x1B2250, /* CMD_PEG_STATE */
151 0x1B233C, /* RCV_PEG_STATE */
152 0x1B23B4, /* ASIC TEMP */
153 0x1B216C, /* FW api */
154 0x1B2170, /* drv op mode */
155 0x13C010, /* flash lock */
156 0x13C014, /* flash unlock */
157};
158
Sony Chacko22999792012-12-04 03:33:55 +0000159static const struct qlcnic_board_info qlcnic_boards[] = {
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000160 { PCI_VENDOR_ID_QLOGIC,
Manish Chopra15ca1402013-08-16 19:07:13 -0400161 PCI_DEVICE_ID_QLOGIC_QLE844X,
162 0x0,
163 0x0,
164 "8400 series 10GbE Converged Network Adapter (TCP/IP Networking)" },
165 { PCI_VENDOR_ID_QLOGIC,
Himanshu Madhanie386cd42013-04-24 12:42:44 +0000166 PCI_DEVICE_ID_QLOGIC_QLE834X,
167 PCI_VENDOR_ID_QLOGIC,
168 0x24e,
169 "8300 Series Dual Port 10GbE Converged Network Adapter "
170 "(TCP/IP Networking)" },
171 { PCI_VENDOR_ID_QLOGIC,
172 PCI_DEVICE_ID_QLOGIC_QLE834X,
173 PCI_VENDOR_ID_QLOGIC,
174 0x243,
175 "8300 Series Single Port 10GbE Converged Network Adapter "
176 "(TCP/IP Networking)" },
177 { PCI_VENDOR_ID_QLOGIC,
178 PCI_DEVICE_ID_QLOGIC_QLE834X,
179 PCI_VENDOR_ID_QLOGIC,
180 0x24a,
181 "8300 Series Dual Port 10GbE Converged Network Adapter "
182 "(TCP/IP Networking)" },
183 { PCI_VENDOR_ID_QLOGIC,
184 PCI_DEVICE_ID_QLOGIC_QLE834X,
185 PCI_VENDOR_ID_QLOGIC,
186 0x246,
187 "8300 Series Dual Port 10GbE Converged Network Adapter "
188 "(TCP/IP Networking)" },
189 { PCI_VENDOR_ID_QLOGIC,
190 PCI_DEVICE_ID_QLOGIC_QLE834X,
191 PCI_VENDOR_ID_QLOGIC,
192 0x252,
193 "8300 Series Dual Port 10GbE Converged Network Adapter "
194 "(TCP/IP Networking)" },
195 { PCI_VENDOR_ID_QLOGIC,
196 PCI_DEVICE_ID_QLOGIC_QLE834X,
197 PCI_VENDOR_ID_QLOGIC,
198 0x26e,
199 "8300 Series Dual Port 10GbE Converged Network Adapter "
200 "(TCP/IP Networking)" },
201 { PCI_VENDOR_ID_QLOGIC,
202 PCI_DEVICE_ID_QLOGIC_QLE834X,
203 PCI_VENDOR_ID_QLOGIC,
204 0x260,
205 "8300 Series Dual Port 10GbE Converged Network Adapter "
206 "(TCP/IP Networking)" },
207 { PCI_VENDOR_ID_QLOGIC,
208 PCI_DEVICE_ID_QLOGIC_QLE834X,
209 PCI_VENDOR_ID_QLOGIC,
210 0x266,
211 "8300 Series Single Port 10GbE Converged Network Adapter "
212 "(TCP/IP Networking)" },
213 { PCI_VENDOR_ID_QLOGIC,
214 PCI_DEVICE_ID_QLOGIC_QLE834X,
215 PCI_VENDOR_ID_QLOGIC,
216 0x269,
217 "8300 Series Dual Port 10GbE Converged Network Adapter "
218 "(TCP/IP Networking)" },
219 { PCI_VENDOR_ID_QLOGIC,
220 PCI_DEVICE_ID_QLOGIC_QLE834X,
221 PCI_VENDOR_ID_QLOGIC,
222 0x271,
223 "8300 Series Dual Port 10GbE Converged Network Adapter "
224 "(TCP/IP Networking)" },
225 { PCI_VENDOR_ID_QLOGIC,
226 PCI_DEVICE_ID_QLOGIC_QLE834X,
227 0x0, 0x0, "8300 Series 1/10GbE Controller" },
228 { PCI_VENDOR_ID_QLOGIC,
229 PCI_DEVICE_ID_QLOGIC_QLE824X,
230 PCI_VENDOR_ID_QLOGIC,
231 0x203,
232 "8200 Series Single Port 10GbE Converged Network Adapter"
233 "(TCP/IP Networking)" },
234 { PCI_VENDOR_ID_QLOGIC,
235 PCI_DEVICE_ID_QLOGIC_QLE824X,
236 PCI_VENDOR_ID_QLOGIC,
237 0x207,
238 "8200 Series Dual Port 10GbE Converged Network Adapter"
239 "(TCP/IP Networking)" },
240 { PCI_VENDOR_ID_QLOGIC,
241 PCI_DEVICE_ID_QLOGIC_QLE824X,
242 PCI_VENDOR_ID_QLOGIC,
243 0x20b,
244 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter" },
245 { PCI_VENDOR_ID_QLOGIC,
246 PCI_DEVICE_ID_QLOGIC_QLE824X,
247 PCI_VENDOR_ID_QLOGIC,
248 0x20c,
249 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter" },
250 { PCI_VENDOR_ID_QLOGIC,
251 PCI_DEVICE_ID_QLOGIC_QLE824X,
252 PCI_VENDOR_ID_QLOGIC,
253 0x20f,
254 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter" },
255 { PCI_VENDOR_ID_QLOGIC,
256 PCI_DEVICE_ID_QLOGIC_QLE824X,
257 0x103c, 0x3733,
258 "NC523SFP 10Gb 2-port Server Adapter" },
259 { PCI_VENDOR_ID_QLOGIC,
260 PCI_DEVICE_ID_QLOGIC_QLE824X,
261 0x103c, 0x3346,
262 "CN1000Q Dual Port Converged Network Adapter" },
263 { PCI_VENDOR_ID_QLOGIC,
264 PCI_DEVICE_ID_QLOGIC_QLE824X,
265 PCI_VENDOR_ID_QLOGIC,
266 0x210,
267 "QME8242-k 10GbE Dual Port Mezzanine Card" },
268 { PCI_VENDOR_ID_QLOGIC,
269 PCI_DEVICE_ID_QLOGIC_QLE824X,
270 0x0, 0x0, "cLOM8214 1/10GbE Controller" },
Sony Chacko22999792012-12-04 03:33:55 +0000271};
272
273#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
274
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000275static const
276struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
277
Sony Chackoc70001a2012-11-28 04:34:26 +0000278int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000279{
280 int size = sizeof(struct qlcnic_host_sds_ring) * count;
281
282 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
283
Eric Dumazet807540b2010-09-23 05:40:09 +0000284 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000285}
286
Sony Chackoc70001a2012-11-28 04:34:26 +0000287void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000288{
289 if (recv_ctx->sds_rings != NULL)
290 kfree(recv_ctx->sds_rings);
291
292 recv_ctx->sds_rings = NULL;
293}
294
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000295int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000296{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000297 struct net_device *netdev = adapter->netdev;
298 struct pci_dev *pdev = adapter->pdev;
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400299 u8 mac_addr[ETH_ALEN];
300 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000301
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400302 ret = qlcnic_get_mac_address(adapter, mac_addr,
303 adapter->ahw->pci_func);
304 if (ret)
305 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000306
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000307 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000308 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
309
310 /* set station address */
311
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000312 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000313 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
314 netdev->dev_addr);
315
316 return 0;
317}
318
Manish Chopracffe52f32013-05-09 09:25:09 +0000319static void qlcnic_delete_adapter_mac(struct qlcnic_adapter *adapter)
320{
Manish Chopra154d0c82013-12-17 09:01:53 -0500321 struct qlcnic_mac_vlan_list *cur;
Manish Chopracffe52f32013-05-09 09:25:09 +0000322 struct list_head *head;
323
324 list_for_each(head, &adapter->mac_list) {
Manish Chopra154d0c82013-12-17 09:01:53 -0500325 cur = list_entry(head, struct qlcnic_mac_vlan_list, list);
dingtianhong6878f792013-12-30 15:41:14 +0800326 if (ether_addr_equal_unaligned(adapter->mac_addr, cur->mac_addr)) {
Manish Chopracffe52f32013-05-09 09:25:09 +0000327 qlcnic_sre_macaddr_change(adapter, cur->mac_addr,
328 0, QLCNIC_MAC_DEL);
329 list_del(&cur->list);
330 kfree(cur);
331 return;
332 }
333 }
334}
335
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000336static int qlcnic_set_mac(struct net_device *netdev, void *p)
337{
338 struct qlcnic_adapter *adapter = netdev_priv(netdev);
339 struct sockaddr *addr = p;
340
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000341 if (qlcnic_sriov_vf_check(adapter))
342 return -EINVAL;
343
Rajesh Borundia73733732010-08-31 17:17:50 +0000344 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
345 return -EOPNOTSUPP;
346
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000347 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000348 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000349
dingtianhong6878f792013-12-30 15:41:14 +0800350 if (ether_addr_equal_unaligned(adapter->mac_addr, addr->sa_data))
Manish Chopracffe52f32013-05-09 09:25:09 +0000351 return 0;
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_detach(netdev);
355 qlcnic_napi_disable(adapter);
356 }
357
Manish Chopracffe52f32013-05-09 09:25:09 +0000358 qlcnic_delete_adapter_mac(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000359 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
360 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
361 qlcnic_set_multi(adapter->netdev);
362
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000363 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000364 netif_device_attach(netdev);
365 qlcnic_napi_enable(adapter);
366 }
367 return 0;
368}
369
Vlad Yasevich1690be62013-02-13 12:00:18 +0000370static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
371 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000372{
373 struct qlcnic_adapter *adapter = netdev_priv(netdev);
374 int err = -EOPNOTSUPP;
375
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000376 if (!adapter->fdb_mac_learn)
377 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000378
379 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400380 if (is_unicast_ether_addr(addr)) {
381 err = dev_uc_del(netdev, addr);
382 if (!err)
383 err = qlcnic_nic_del_mac(adapter, addr);
384 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000385 err = dev_mc_del(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400386 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000387 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400388 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000389 }
390 return err;
391}
392
393static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
394 struct net_device *netdev,
395 const unsigned char *addr, u16 flags)
396{
397 struct qlcnic_adapter *adapter = netdev_priv(netdev);
398 int err = 0;
399
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000400 if (!adapter->fdb_mac_learn)
401 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000402
403 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
404 pr_info("%s: FDB e-switch is not enabled\n", __func__);
405 return -EOPNOTSUPP;
406 }
407
408 if (ether_addr_equal(addr, adapter->mac_addr))
409 return err;
410
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400411 if (is_unicast_ether_addr(addr)) {
412 if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
413 err = dev_uc_add_excl(netdev, addr);
414 else
415 err = -ENOMEM;
416 } else if (is_multicast_ether_addr(addr)) {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000417 err = dev_mc_add_excl(netdev, addr);
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400418 } else {
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000419 err = -EINVAL;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400420 }
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000421
422 return err;
423}
424
425static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
426 struct net_device *netdev, int idx)
427{
428 struct qlcnic_adapter *adapter = netdev_priv(netdev);
429
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000430 if (!adapter->fdb_mac_learn)
431 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000432
433 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
434 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
435
436 return idx;
437}
438
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000439static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
440{
441 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
442 usleep_range(10000, 11000);
443
Sucheta Chakraborty66451612013-09-27 02:12:36 -0400444 if (!adapter->fw_work.work.func)
445 return;
446
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000447 cancel_delayed_work_sync(&adapter->fw_work);
448}
449
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400450static int qlcnic_get_phys_port_id(struct net_device *netdev,
451 struct netdev_phys_port_id *ppid)
452{
453 struct qlcnic_adapter *adapter = netdev_priv(netdev);
454 struct qlcnic_hardware_context *ahw = adapter->ahw;
455
456 if (!(adapter->flags & QLCNIC_HAS_PHYS_PORT_ID))
457 return -EOPNOTSUPP;
458
459 ppid->id_len = sizeof(ahw->phys_port_id);
460 memcpy(ppid->id, ahw->phys_port_id, ppid->id_len);
461
462 return 0;
463}
464
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000465static const struct net_device_ops qlcnic_netdev_ops = {
466 .ndo_open = qlcnic_open,
467 .ndo_stop = qlcnic_close,
468 .ndo_start_xmit = qlcnic_xmit_frame,
469 .ndo_get_stats = qlcnic_get_stats,
470 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000471 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000472 .ndo_set_mac_address = qlcnic_set_mac,
473 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000474 .ndo_fix_features = qlcnic_fix_features,
475 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000476 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000477 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
478 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000479 .ndo_fdb_add = qlcnic_fdb_add,
480 .ndo_fdb_del = qlcnic_fdb_del,
481 .ndo_fdb_dump = qlcnic_fdb_dump,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400482 .ndo_get_phys_port_id = qlcnic_get_phys_port_id,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000483#ifdef CONFIG_NET_POLL_CONTROLLER
484 .ndo_poll_controller = qlcnic_poll_controller,
485#endif
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000486#ifdef CONFIG_QLCNIC_SRIOV
487 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
488 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate,
489 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000490 .ndo_set_vf_vlan = qlcnic_sriov_set_vf_vlan,
Rajesh Borundiaa80be5a2013-05-23 21:04:25 +0000491 .ndo_set_vf_spoofchk = qlcnic_sriov_set_vf_spoofchk,
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000492#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000493};
494
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000495static const struct net_device_ops qlcnic_netdev_failed_ops = {
496 .ndo_open = qlcnic_open,
497};
498
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000499static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000500 .config_bridged_mode = qlcnic_config_bridged_mode,
501 .config_led = qlcnic_82xx_config_led,
502 .start_firmware = qlcnic_82xx_start_firmware,
503 .request_reset = qlcnic_82xx_dev_request_reset,
504 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
505 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000506 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000507 .config_ipaddr = qlcnic_82xx_config_ipaddr,
Rajesh Borundia486a5bc2013-06-22 04:12:06 -0400508 .shutdown = qlcnic_82xx_shutdown,
509 .resume = qlcnic_82xx_resume,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000510 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000511};
512
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000513struct qlcnic_nic_template qlcnic_vf_ops = {
514 .config_bridged_mode = qlcnicvf_config_bridged_mode,
515 .config_led = qlcnicvf_config_led,
516 .start_firmware = qlcnicvf_start_firmware
517};
518
519static struct qlcnic_hardware_ops qlcnic_hw_ops = {
520 .read_crb = qlcnic_82xx_read_crb,
521 .write_crb = qlcnic_82xx_write_crb,
522 .read_reg = qlcnic_82xx_hw_read_wx_2M,
523 .write_reg = qlcnic_82xx_hw_write_wx_2M,
524 .get_mac_address = qlcnic_82xx_get_mac_address,
525 .setup_intr = qlcnic_82xx_setup_intr,
526 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
527 .mbx_cmd = qlcnic_82xx_issue_cmd,
528 .get_func_no = qlcnic_82xx_get_func_no,
529 .api_lock = qlcnic_82xx_api_lock,
530 .api_unlock = qlcnic_82xx_api_unlock,
531 .add_sysfs = qlcnic_82xx_add_sysfs,
532 .remove_sysfs = qlcnic_82xx_remove_sysfs,
533 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
534 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
535 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000536 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
537 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000538 .setup_link_event = qlcnic_82xx_linkevent_request,
539 .get_nic_info = qlcnic_82xx_get_nic_info,
540 .get_pci_info = qlcnic_82xx_get_pci_info,
541 .set_nic_info = qlcnic_82xx_set_nic_info,
542 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
543 .napi_enable = qlcnic_82xx_napi_enable,
544 .napi_disable = qlcnic_82xx_napi_disable,
545 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
546 .config_rss = qlcnic_82xx_config_rss,
547 .config_hw_lro = qlcnic_82xx_config_hw_lro,
548 .config_loopback = qlcnic_82xx_set_lb_mode,
549 .clear_loopback = qlcnic_82xx_clear_lb_mode,
550 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
551 .change_l2_filter = qlcnic_82xx_change_filter,
552 .get_board_info = qlcnic_82xx_get_board_info,
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -0400553 .set_mac_filter_count = qlcnic_82xx_set_mac_filter_count,
Rajesh Borundia91b72822013-04-19 07:01:12 +0000554 .free_mac_list = qlcnic_82xx_free_mac_list,
Shahed Shaikh07a251c2013-08-21 11:24:13 -0400555 .read_phys_port_id = qlcnic_82xx_read_phys_port_id,
Pratik Pujar4460f2e2013-08-30 13:51:20 -0400556 .io_error_detected = qlcnic_82xx_io_error_detected,
557 .io_slot_reset = qlcnic_82xx_io_slot_reset,
558 .io_resume = qlcnic_82xx_io_resume,
Himanshu Madhania0431582014-01-10 11:48:56 -0500559 .get_beacon_state = qlcnic_82xx_get_beacon_state,
Manish chopra2cc57522014-01-23 17:18:30 -0500560 .enable_sds_intr = qlcnic_82xx_enable_sds_intr,
561 .disable_sds_intr = qlcnic_82xx_disable_sds_intr,
562 .enable_tx_intr = qlcnic_82xx_enable_tx_intr,
563 .disable_tx_intr = qlcnic_82xx_disable_tx_intr,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000564};
565
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500566static int qlcnic_check_multi_tx_capability(struct qlcnic_adapter *adapter)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400567{
568 struct qlcnic_hardware_context *ahw = adapter->ahw;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400569
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500570 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400571 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_MULTI_TX)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500572 test_and_set_bit(__QLCNIC_MULTI_TX_UNIQUE, &adapter->state);
573 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400574 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500575 return 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400576 }
577}
578
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500579static int qlcnic_max_rings(struct qlcnic_adapter *adapter, u8 ring_cnt,
580 int queue_type)
581{
582 int num_rings, max_rings = QLCNIC_MAX_SDS_RINGS;
583
584 if (queue_type == QLCNIC_RX_QUEUE)
585 max_rings = adapter->max_sds_rings;
586 else if (queue_type == QLCNIC_TX_QUEUE)
587 max_rings = adapter->max_tx_rings;
588
589 num_rings = rounddown_pow_of_two(min_t(int, num_online_cpus(),
590 max_rings));
591
592 if (ring_cnt > num_rings)
593 return num_rings;
594 else
595 return ring_cnt;
596}
597
598void qlcnic_set_tx_ring_count(struct qlcnic_adapter *adapter, u8 tx_cnt)
599{
600 /* 83xx adapter does not have max_tx_rings intialized in probe */
601 if (adapter->max_tx_rings)
602 adapter->drv_tx_rings = qlcnic_max_rings(adapter, tx_cnt,
603 QLCNIC_TX_QUEUE);
604 else
605 adapter->drv_tx_rings = tx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500606}
607
608void qlcnic_set_sds_ring_count(struct qlcnic_adapter *adapter, u8 rx_cnt)
609{
610 /* 83xx adapter does not have max_sds_rings intialized in probe */
611 if (adapter->max_sds_rings)
612 adapter->drv_sds_rings = qlcnic_max_rings(adapter, rx_cnt,
613 QLCNIC_RX_QUEUE);
614 else
615 adapter->drv_sds_rings = rx_cnt;
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500616}
617
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500618int qlcnic_setup_tss_rss_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000619{
620 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500621 int num_msix = 0, err = 0, vector;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000622
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500623 adapter->flags &= ~QLCNIC_TSS_RSS;
624
625 if (adapter->drv_tss_rings > 0)
626 num_msix += adapter->drv_tss_rings;
627 else
628 num_msix += adapter->drv_tx_rings;
629
630 if (adapter->drv_rss_rings > 0)
631 num_msix += adapter->drv_rss_rings;
632 else
633 num_msix += adapter->drv_sds_rings;
634
635 if (qlcnic_83xx_check(adapter))
636 num_msix += 1;
Sony Chacko13159182013-01-01 03:20:21 +0000637
638 if (!adapter->msix_entries) {
639 adapter->msix_entries = kcalloc(num_msix,
640 sizeof(struct msix_entry),
641 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000642 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000643 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000644 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000645
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500646restore:
647 for (vector = 0; vector < num_msix; vector++)
648 adapter->msix_entries[vector].entry = vector;
649
650 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
651 if (err == 0) {
652 adapter->ahw->num_msix = num_msix;
653 if (adapter->drv_tss_rings > 0)
654 adapter->drv_tx_rings = adapter->drv_tss_rings;
655
656 if (adapter->drv_rss_rings > 0)
657 adapter->drv_sds_rings = adapter->drv_rss_rings;
658 } else {
659 netdev_info(adapter->netdev,
660 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
661 num_msix, err);
662
663 num_msix = adapter->drv_tx_rings + adapter->drv_sds_rings;
664
665 /* Set rings to 0 so we can restore original TSS/RSS count */
666 adapter->drv_tss_rings = 0;
667 adapter->drv_rss_rings = 0;
668
669 if (qlcnic_83xx_check(adapter))
670 num_msix += 1;
671
672 netdev_info(adapter->netdev,
673 "Restoring %d Tx, %d SDS rings for total %d vectors.\n",
674 adapter->drv_tx_rings, adapter->drv_sds_rings,
675 num_msix);
676 goto restore;
677
678 err = -EIO;
679 }
680
681 return err;
682}
683
684int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
685{
686 struct pci_dev *pdev = adapter->pdev;
687 int err = -1, vector;
688
689 if (!adapter->msix_entries) {
690 adapter->msix_entries = kcalloc(num_msix,
691 sizeof(struct msix_entry),
692 GFP_KERNEL);
693 if (!adapter->msix_entries)
694 return -ENOMEM;
695 }
696
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000697 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000698
Sony Chacko79788452012-12-04 03:33:53 +0000699 if (adapter->ahw->msix_supported) {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500700enable_msix:
701 for (vector = 0; vector < num_msix; vector++)
702 adapter->msix_entries[vector].entry = vector;
703
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000704 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
705 if (err == 0) {
706 adapter->flags |= QLCNIC_MSIX_ENABLED;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500707 adapter->ahw->num_msix = num_msix;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000708 dev_info(&pdev->dev, "using msi-x interrupts\n");
709 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000710 } else if (err > 0) {
711 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500712 "Unable to allocate %d MSI-X vectors, Available vectors %d\n",
713 num_msix, err);
714
715 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +0000716 num_msix = rounddown_pow_of_two(err);
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500717 if (err < QLCNIC_82XX_MINIMUM_VECTOR)
718 return -EIO;
Sony Chacko13159182013-01-01 03:20:21 +0000719 } else {
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500720 num_msix = rounddown_pow_of_two(err - 1);
721 num_msix += 1;
722 if (err < QLCNIC_83XX_MINIMUM_VECTOR)
723 return -EIO;
724 }
725
726 if (qlcnic_82xx_check(adapter) &&
727 !qlcnic_check_multi_tx(adapter)) {
728 adapter->drv_sds_rings = num_msix;
729 adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
730 } else {
731 /* Distribute vectors equally */
732 adapter->drv_tx_rings = num_msix / 2;
733 adapter->drv_sds_rings = adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +0000734 }
735
736 if (num_msix) {
737 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000738 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000739 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000740 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000741 }
742 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000743 dev_info(&pdev->dev,
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500744 "Unable to allocate %d MSI-X vectors, err=%d\n",
745 num_msix, err);
746 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000747 }
748 }
Sony Chacko13159182013-01-01 03:20:21 +0000749
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000750 return err;
751}
752
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500753static int qlcnic_82xx_calculate_msix_vector(struct qlcnic_adapter *adapter)
754{
755 int num_msix;
756
757 num_msix = adapter->drv_sds_rings;
758
759 if (qlcnic_check_multi_tx(adapter))
760 num_msix += adapter->drv_tx_rings;
761 else
762 num_msix += QLCNIC_SINGLE_RING;
763
764 return num_msix;
765}
766
Manish chopra9a97e702013-01-25 10:20:37 +0000767static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000768{
Manish chopra9a97e702013-01-25 10:20:37 +0000769 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000770 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000771 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000772 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000773 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000774
Sony Chacko099f7aa2012-12-04 03:33:58 +0000775 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000776 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000777 offset = msi_tgt_status[adapter->ahw->pci_func];
778 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
779 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000780 dev_info(&pdev->dev, "using msi interrupts\n");
781 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000782 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000783 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400784
Manish chopra9a97e702013-01-25 10:20:37 +0000785 if (qlcnic_use_msi || qlcnic_use_msi_x)
786 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000787
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000788 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000789 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000790 offset = legacy_intrp->tgt_status_reg;
791 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
792 mask_reg = legacy_intrp->tgt_mask_reg;
793 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
794 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
795 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000796 dev_info(&pdev->dev, "using legacy interrupts\n");
797 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000798 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000799}
800
stephen hemminger21041402014-01-16 10:31:27 -0800801static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000802{
Manish chopra9a97e702013-01-25 10:20:37 +0000803 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000804
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500805 if (adapter->flags & QLCNIC_TSS_RSS) {
806 err = qlcnic_setup_tss_rss_intr(adapter);
807 if (err < 0)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400808 return err;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500809 num_msix = adapter->ahw->num_msix;
810 } else {
811 num_msix = qlcnic_82xx_calculate_msix_vector(adapter);
812
813 err = qlcnic_enable_msix(adapter, num_msix);
814 if (err == -ENOMEM)
815 return err;
816
817 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
818 qlcnic_disable_multi_tx(adapter);
Rajesh Borundia42beb3f2014-02-24 08:54:49 -0500819 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500820
821 err = qlcnic_enable_msi_legacy(adapter);
Shahed Shaikhfc49bea2014-02-24 08:54:46 -0500822 if (err)
Himanshu Madhanicb9327d2014-01-23 17:18:33 -0500823 return err;
824 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400825 }
826
827 return 0;
828}
829
830int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
831{
832 struct qlcnic_hardware_context *ahw = adapter->ahw;
833 int err, i;
834
835 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400836 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400837 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
838 ahw->intr_tbl = vzalloc(ahw->num_msix *
839 sizeof(struct qlcnic_intrpt_config));
840 if (!ahw->intr_tbl)
841 return -ENOMEM;
842
843 for (i = 0; i < ahw->num_msix; i++) {
844 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
845 ahw->intr_tbl[i].id = i;
846 ahw->intr_tbl[i].src = 0;
847 }
848
849 err = qlcnic_82xx_config_intrpt(adapter, 1);
850 if (err)
851 dev_err(&adapter->pdev->dev,
852 "Failed to configure Interrupt for %d vector\n",
853 ahw->num_msix);
854 return err;
855 }
856
857 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000858}
Sony Chacko13159182013-01-01 03:20:21 +0000859
Sony Chacko319ecf12013-01-01 03:20:22 +0000860void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000861{
862 if (adapter->flags & QLCNIC_MSIX_ENABLED)
863 pci_disable_msix(adapter->pdev);
864 if (adapter->flags & QLCNIC_MSI_ENABLED)
865 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000866
867 kfree(adapter->msix_entries);
868 adapter->msix_entries = NULL;
869
870 if (adapter->ahw->intr_tbl) {
871 vfree(adapter->ahw->intr_tbl);
872 adapter->ahw->intr_tbl = NULL;
873 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000874}
875
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000876static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000877{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000878 if (ahw->pci_base0 != NULL)
879 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000880}
881
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000882static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
883{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500884 struct qlcnic_hardware_context *ahw = adapter->ahw;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000885 struct qlcnic_pci_info *pci_info;
886 int ret;
887
888 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500889 switch (ahw->port_type) {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000890 case QLCNIC_GBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500891 ahw->total_nic_func = QLCNIC_NIU_MAX_GBE_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000892 break;
893 case QLCNIC_XGBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500894 ahw->total_nic_func = QLCNIC_NIU_MAX_XG_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000895 break;
896 }
897 return 0;
898 }
899
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500900 if (ahw->op_mode == QLCNIC_MGMT_FUNC)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000901 return 0;
902
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500903 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000904 if (!pci_info)
905 return -ENOMEM;
906
907 ret = qlcnic_get_pci_info(adapter, pci_info);
908 kfree(pci_info);
909 return ret;
910}
Sony Chackod71170f2013-01-01 03:20:26 +0000911
Sony Chacko35dafcb2013-08-30 13:51:23 -0400912static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
913{
914 bool ret = false;
915
916 if (qlcnic_84xx_check(adapter)) {
917 ret = true;
918 } else if (qlcnic_83xx_check(adapter)) {
919 if (adapter->ahw->extra_capability[0] &
920 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
921 ret = true;
922 else
923 ret = false;
924 }
925
926 return ret;
927}
928
Sony Chackod71170f2013-01-01 03:20:26 +0000929int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000930{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500931 struct qlcnic_hardware_context *ahw = adapter->ahw;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000932 struct qlcnic_pci_info *pci_info;
Sony Chacko4c776aa2013-10-18 12:22:32 -0400933 int i, id = 0, ret = 0, j = 0;
Sony Chackobff57d82012-12-04 03:33:56 +0000934 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000935 u8 pfn;
936
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500937 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000938 if (!pci_info)
939 return -ENOMEM;
940
Sony Chackobff57d82012-12-04 03:33:56 +0000941 ret = qlcnic_get_pci_info(adapter, pci_info);
942 if (ret)
943 goto err_pci_info;
944
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500945 act_pci_func = ahw->total_nic_func;
Sony Chackobff57d82012-12-04 03:33:56 +0000946
Dan Carpenterca315ac2010-08-09 21:47:56 +0000947 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000948 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000949 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000950 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000951 goto err_pci_info;
952 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000953
Dan Carpenterca315ac2010-08-09 21:47:56 +0000954 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000955 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
956 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000957 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000958 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000959 }
960
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500961 for (i = 0; i < ahw->max_vnic_func; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000962 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000963
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500964 if (pfn >= ahw->max_vnic_func) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000965 ret = QL_STATUS_INVALID_PARAM;
966 goto err_eswitch;
967 }
Sony Chackobff57d82012-12-04 03:33:56 +0000968
969 if (!pci_info[i].active ||
970 (pci_info[i].type != QLCNIC_TYPE_NIC))
971 continue;
972
Sony Chacko35dafcb2013-08-30 13:51:23 -0400973 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko4c776aa2013-10-18 12:22:32 -0400974 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn,
975 &id))
Sony Chacko35dafcb2013-08-30 13:51:23 -0400976 adapter->npars[j].eswitch_status = true;
977 else
978 continue;
979 } else {
980 adapter->npars[j].eswitch_status = true;
981 }
982
Sony Chackobff57d82012-12-04 03:33:56 +0000983 adapter->npars[j].pci_func = pfn;
984 adapter->npars[j].active = (u8)pci_info[i].active;
985 adapter->npars[j].type = (u8)pci_info[i].type;
986 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
987 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
988 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -0400989
Sucheta Chakraborty9e630952013-10-18 12:22:28 -0400990 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN);
Sony Chackobff57d82012-12-04 03:33:56 +0000991 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000992 }
993
Sony Chacko4c776aa2013-10-18 12:22:32 -0400994 /* Update eSwitch status for adapters without per port eSwitch
995 * configuration capability
996 */
997 if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko35dafcb2013-08-30 13:51:23 -0400998 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
999 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +00001000 }
Dan Carpenterca315ac2010-08-09 21:47:56 +00001001
Dan Carpentere88db3b2010-08-09 21:49:36 +00001002 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001003 return 0;
1004
1005err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001006 kfree(adapter->eswitch);
1007 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001008err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001009 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001010 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001011err_pci_info:
1012 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001013
1014 return ret;
1015}
1016
1017static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001018qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
1019{
1020 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001021 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001022 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +00001023 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001024
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001025 ret = qlcnic_api_lock(adapter);
1026 if (ret)
1027 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001028
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001029 id = ahw->pci_func;
1030 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
1031 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
1032 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001033 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001034 qlcnic_api_unlock(adapter);
1035err_lock:
1036 return ret;
1037}
1038
Sony Chacko13159182013-01-01 03:20:21 +00001039static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
1040 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001041{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001042 u32 op_mode, priv_level;
1043
1044 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +00001045 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
1046 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001047
1048 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +00001049 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001050
1051 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +00001052 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001053 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001054 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001055 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001056 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001057
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001058 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001059 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001060 dev_info(&adapter->pdev->dev,
1061 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001062 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001063 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001064 } else
1065 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001066}
1067
Sony Chacko15087c22012-12-04 03:33:54 +00001068#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +00001069#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +00001070static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001071{
Sony Chacko15087c22012-12-04 03:33:54 +00001072 switch (dev_id) {
1073 case PCI_DEVICE_ID_QLOGIC_QLE824X:
1074 *bar = QLCNIC_82XX_BAR0_LENGTH;
1075 break;
Sony Chacko13159182013-01-01 03:20:21 +00001076 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001077 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001078 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001079 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00001080 *bar = QLCNIC_83XX_BAR0_LENGTH;
1081 break;
Sony Chacko15087c22012-12-04 03:33:54 +00001082 default:
1083 *bar = 0;
1084 }
1085}
1086
1087static int qlcnic_setup_pci_map(struct pci_dev *pdev,
1088 struct qlcnic_hardware_context *ahw)
1089{
1090 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001091 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +00001092 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001093
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001094 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001095 mem_len = pci_resource_len(pdev, 0);
1096
Sony Chacko15087c22012-12-04 03:33:54 +00001097 qlcnic_get_bar_length(pdev->device, &bar0_len);
1098 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001099
1100 mem_ptr0 = pci_ioremap_bar(pdev, 0);
1101 if (mem_ptr0 == NULL) {
1102 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
1103 return -EIO;
1104 }
1105 pci_len0 = mem_len;
1106 } else {
1107 return -EIO;
1108 }
1109
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001110 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001111
Sony Chacko15087c22012-12-04 03:33:54 +00001112 ahw->pci_base0 = mem_ptr0;
1113 ahw->pci_len0 = pci_len0;
1114 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1115 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001116
1117 return 0;
1118}
1119
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001120static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1121 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001122{
1123 struct pci_dev *pdev = adapter->pdev;
1124 unsigned short subsystem_vendor;
1125 bool ret = true;
1126
1127 subsystem_vendor = pdev->subsystem_vendor;
1128
1129 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1130 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1131 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1132 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1133 ret = true;
1134 else
1135 ret = false;
1136 }
1137
1138 return ret;
1139}
1140
Sony Chacko22999792012-12-04 03:33:55 +00001141static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001142{
1143 struct pci_dev *pdev = adapter->pdev;
1144 int i, found = 0;
1145
1146 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1147 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001148 qlcnic_boards[i].device == pdev->device &&
1149 qlcnic_validate_subsystem_id(adapter, i)) {
1150 found = 1;
1151 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001152 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001153 }
1154
1155 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001156 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001157 else
1158 sprintf(name, "%pM: %s" , adapter->mac_addr,
1159 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001160}
1161
1162static void
1163qlcnic_check_options(struct qlcnic_adapter *adapter)
1164{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001165 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001166 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001167 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001168 struct qlcnic_hardware_context *ahw = adapter->ahw;
1169 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001170
1171 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001172
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001173 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1174 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1175 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001176
1177 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1178
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001179 err = qlcnic_get_board_info(adapter);
1180 if (err) {
1181 dev_err(&pdev->dev, "Error getting board config info.\n");
1182 return;
1183 }
1184 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001185 if (fw_dump->tmpl_hdr == NULL ||
1186 adapter->fw_version > prev_fw_version) {
1187 if (fw_dump->tmpl_hdr)
1188 vfree(fw_dump->tmpl_hdr);
1189 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1190 dev_info(&pdev->dev,
1191 "Supports FW dump capability\n");
1192 }
1193 }
1194
Sony Chacko13159182013-01-01 03:20:21 +00001195 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1196 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1197
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001198 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001199 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1200 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1201 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1202 } else {
1203 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1204 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1205 }
1206
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001207 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001208 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1209
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001210 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001211 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1212 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001213 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1214 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001215 }
1216
Sony Chacko099f7aa2012-12-04 03:33:58 +00001217 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001218
1219 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1220
Sony Chacko251b0362010-08-19 05:08:24 +00001221 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001222}
1223
Rajesh Borundia174240a2010-08-31 17:17:47 +00001224static int
1225qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1226{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001227 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001228 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001229
Sony Chackobff57d82012-12-04 03:33:56 +00001230 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001231 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001232 if (err)
1233 return err;
1234
Sony Chacko79788452012-12-04 03:33:53 +00001235 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1236 adapter->ahw->switch_mode = nic_info.switch_mode;
1237 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1238 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1239 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001240
1241 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1242 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001243 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1244 if (err == -EIO)
1245 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001246 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001247 } else {
1248 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001249 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001250
Sony Chacko79788452012-12-04 03:33:53 +00001251 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1252 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001253
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001254 if (adapter->ahw->capabilities & BIT_6) {
Rajesh Borundia174240a2010-08-31 17:17:47 +00001255 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001256 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE;
1257 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS;
1258 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
1259
1260 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n");
1261 } else {
1262 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
1263 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS;
Himanshu Madhanif9566262013-12-16 15:36:58 -05001264 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001265 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001266 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001267
1268 return err;
1269}
1270
Sony Chackoec079a02012-11-28 04:34:28 +00001271void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1272 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001273{
1274 if (esw_cfg->discard_tagged)
1275 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1276 else
1277 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1278
Rajesh Borundia91b72822013-04-19 07:01:12 +00001279 if (esw_cfg->vlan_id) {
1280 adapter->rx_pvid = esw_cfg->vlan_id;
1281 adapter->tx_pvid = esw_cfg->vlan_id;
1282 } else {
1283 adapter->rx_pvid = 0;
1284 adapter->tx_pvid = 0;
1285 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001286}
1287
Jiri Pirko8e586132011-12-08 19:52:37 -05001288static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001289qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001290{
1291 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001292 int err;
1293
1294 if (qlcnic_sriov_vf_check(adapter)) {
1295 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1296 if (err) {
1297 netdev_err(netdev,
1298 "Cannot add VLAN filter for VLAN id %d, err=%d",
1299 vid, err);
1300 return err;
1301 }
1302 }
1303
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001304 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001305 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001306}
1307
Jiri Pirko8e586132011-12-08 19:52:37 -05001308static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001309qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001310{
1311 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001312 int err;
1313
1314 if (qlcnic_sriov_vf_check(adapter)) {
1315 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1316 if (err) {
1317 netdev_err(netdev,
1318 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1319 vid, err);
1320 return err;
1321 }
1322 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001323
1324 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1325 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001326 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001327}
1328
Sony Chackoec079a02012-11-28 04:34:28 +00001329void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1330 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001331{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001332 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1333 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001334
1335 if (esw_cfg->mac_anti_spoof)
1336 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001337
Rajesh Borundia73733732010-08-31 17:17:50 +00001338 if (!esw_cfg->mac_override)
1339 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1340
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001341 if (!esw_cfg->promisc_mode)
1342 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001343}
1344
Sony Chackod71170f2013-01-01 03:20:26 +00001345int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001346{
1347 struct qlcnic_esw_func_cfg esw_cfg;
1348
1349 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1350 return 0;
1351
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001352 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001353 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1354 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001355 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001356 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001357 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001358
1359 return 0;
1360}
1361
Shahed Shaikh147a9082013-05-21 09:27:01 +00001362void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1363 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001364{
1365 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001366
Sony Chacko13159182013-01-01 03:20:21 +00001367 if (qlcnic_83xx_check(adapter))
1368 return;
1369
Shahed Shaikh147a9082013-05-21 09:27:01 +00001370 adapter->offload_flags = esw_cfg->offload_flags;
1371 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1372 netdev_update_features(netdev);
1373 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001374}
1375
1376static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001377qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1378{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001379 u32 op_mode, priv_level;
1380 int err = 0;
1381
Rajesh Borundia174240a2010-08-31 17:17:47 +00001382 err = qlcnic_initialize_nic(adapter);
1383 if (err)
1384 return err;
1385
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001386 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1387 return 0;
1388
Sony Chacko13159182013-01-01 03:20:21 +00001389 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001390 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001391
1392 if (op_mode == QLC_DEV_DRV_DEFAULT)
1393 priv_level = QLCNIC_MGMT_FUNC;
1394 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001395 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001396
Rajesh Borundia174240a2010-08-31 17:17:47 +00001397 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001398 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001399 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001400 err = qlcnic_init_pci_info(adapter);
1401 if (err)
1402 return err;
1403 /* Set privilege level for other functions */
1404 qlcnic_set_function_modes(adapter);
1405 dev_info(&adapter->pdev->dev,
1406 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001407 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001408 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001409 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001410 dev_info(&adapter->pdev->dev,
1411 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001412 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001413 }
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001414 } else {
1415 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001416 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001417
1418 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1419
1420 return err;
1421}
1422
Sony Chackod71170f2013-01-01 03:20:26 +00001423int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001424{
1425 struct qlcnic_esw_func_cfg esw_cfg;
1426 struct qlcnic_npar_info *npar;
1427 u8 i;
1428
Rajesh Borundia174240a2010-08-31 17:17:47 +00001429 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001430 return 0;
1431
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001432 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001433 if (!adapter->npars[i].eswitch_status)
1434 continue;
1435
Rajesh Borundia0325d692010-08-19 05:08:26 +00001436 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001437 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001438 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001439 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001440 if (qlcnic_82xx_check(adapter)) {
1441 esw_cfg.offload_flags = BIT_0;
1442 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1443 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1444 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001445 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1446 return -EIO;
1447 npar = &adapter->npars[i];
1448 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001449 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001450 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1451 npar->discard_tagged = esw_cfg.discard_tagged;
1452 npar->promisc_mode = esw_cfg.promisc_mode;
1453 npar->offload_flags = esw_cfg.offload_flags;
1454 }
1455
1456 return 0;
1457}
1458
Sony Chacko13159182013-01-01 03:20:21 +00001459
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001460static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001461qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1462 struct qlcnic_npar_info *npar, int pci_func)
1463{
1464 struct qlcnic_esw_func_cfg esw_cfg;
1465 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1466 esw_cfg.pci_func = pci_func;
1467 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001468 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001469 esw_cfg.discard_tagged = npar->discard_tagged;
1470 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1471 esw_cfg.offload_flags = npar->offload_flags;
1472 esw_cfg.promisc_mode = npar->promisc_mode;
1473 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1474 return -EIO;
1475
1476 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1477 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1478 return -EIO;
1479
1480 return 0;
1481}
1482
Sony Chackod71170f2013-01-01 03:20:26 +00001483int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001484{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001485 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001486 struct qlcnic_npar_info *npar;
1487 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001488 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001489
Sony Chackobff57d82012-12-04 03:33:56 +00001490 if (qlcnic_82xx_check(adapter))
1491 if (!adapter->need_fw_reset)
1492 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001493
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001494 /* Set the NPAR config data after FW reset */
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001495 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001496 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001497 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001498 if (!adapter->npars[i].eswitch_status)
1499 continue;
1500
Sony Chackobff57d82012-12-04 03:33:56 +00001501 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001502 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001503 if (err)
1504 return err;
1505 nic_info.min_tx_bw = npar->min_bw;
1506 nic_info.max_tx_bw = npar->max_bw;
1507 err = qlcnic_set_nic_info(adapter, &nic_info);
1508 if (err)
1509 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001510
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001511 if (npar->enable_pm) {
1512 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001513 npar->dest_npar, 1,
1514 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001515 if (err)
1516 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001517 }
Sony Chackobff57d82012-12-04 03:33:56 +00001518 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001519 if (err)
1520 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001521 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001522 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001523}
1524
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001525static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1526{
1527 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1528 u32 npar_state;
1529
Sony Chacko79788452012-12-04 03:33:53 +00001530 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001531 return 0;
1532
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001533 npar_state = QLC_SHARED_REG_RD32(adapter,
1534 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001535 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1536 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001537 npar_state = QLC_SHARED_REG_RD32(adapter,
1538 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001539 }
1540 if (!npar_opt_timeo) {
1541 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001542 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001543 return -EIO;
1544 }
1545 return 0;
1546}
1547
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001548static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001549qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1550{
1551 int err;
1552
1553 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001554 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001555 return 0;
1556
1557 err = qlcnic_set_default_offload_settings(adapter);
1558 if (err)
1559 return err;
1560
1561 err = qlcnic_reset_npar_config(adapter);
1562 if (err)
1563 return err;
1564
1565 qlcnic_dev_set_npar_ready(adapter);
1566
1567 return err;
1568}
1569
stephen hemminger21041402014-01-16 10:31:27 -08001570static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001571{
Sony Chackod4066832010-08-19 05:08:31 +00001572 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001573
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001574 err = qlcnic_can_start_firmware(adapter);
1575 if (err < 0)
1576 return err;
1577 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001578 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001579
Sony Chacko099f7aa2012-12-04 03:33:58 +00001580 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001581 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001582 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001583 err = qlcnic_check_flash_fw_ver(adapter);
1584 if (err)
schacko8f891382010-06-17 02:56:40 +00001585 goto err_out;
1586
Sony Chacko79788452012-12-04 03:33:53 +00001587 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001588 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001589
1590 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001591 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001592 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001593
Sony Chackod4066832010-08-19 05:08:31 +00001594 err = qlcnic_pinit_from_rom(adapter);
1595 if (err)
1596 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001597
1598 err = qlcnic_load_firmware(adapter);
1599 if (err)
1600 goto err_out;
1601
1602 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001603 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001604
Sony Chackod4066832010-08-19 05:08:31 +00001605check_fw_status:
1606 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001607 if (err)
1608 goto err_out;
1609
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001610 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001611 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001612 err = qlcnic_check_eswitch_mode(adapter);
1613 if (err) {
1614 dev_err(&adapter->pdev->dev,
1615 "Memory allocation failed for eswitch\n");
1616 goto err_out;
1617 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001618 err = qlcnic_set_mgmt_operations(adapter);
1619 if (err)
1620 goto err_out;
1621
1622 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001623 adapter->need_fw_reset = 0;
1624
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001625 qlcnic_release_firmware(adapter);
1626 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001627
1628err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001629 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001630 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001631
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001632 qlcnic_release_firmware(adapter);
1633 return err;
1634}
1635
1636static int
1637qlcnic_request_irq(struct qlcnic_adapter *adapter)
1638{
1639 irq_handler_t handler;
1640 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001641 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001642 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001643
1644 unsigned long flags = 0;
1645 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001646 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001647
Sony Chacko79788452012-12-04 03:33:53 +00001648 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001649 if (qlcnic_82xx_check(adapter))
1650 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001651 else
1652 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001653 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1654 flags |= IRQF_SHARED;
1655
1656 } else {
1657 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1658 handler = qlcnic_msix_intr;
1659 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1660 handler = qlcnic_msi_intr;
1661 else {
1662 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001663 if (qlcnic_82xx_check(adapter))
1664 handler = qlcnic_intr;
1665 else
1666 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001667 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001668 }
1669 adapter->irq = netdev->irq;
1670
Sony Chacko13159182013-01-01 03:20:21 +00001671 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001672 if (qlcnic_82xx_check(adapter) ||
1673 (qlcnic_83xx_check(adapter) &&
1674 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001675 num_sds_rings = adapter->drv_sds_rings;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001676 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001677 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001678 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001679 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001680 (ring == (num_sds_rings - 1))) {
1681 if (!(adapter->flags &
1682 QLCNIC_MSIX_ENABLED))
1683 snprintf(sds_ring->name,
1684 sizeof(sds_ring->name),
1685 "qlcnic");
1686 else
1687 snprintf(sds_ring->name,
1688 sizeof(sds_ring->name),
1689 "%s-tx-0-rx-%d",
1690 netdev->name, ring);
1691 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001692 snprintf(sds_ring->name,
1693 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001694 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001695 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001696 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001697 err = request_irq(sds_ring->irq, handler, flags,
1698 sds_ring->name, sds_ring);
1699 if (err)
1700 return err;
1701 }
Sony Chacko13159182013-01-01 03:20:21 +00001702 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001703 if ((qlcnic_82xx_check(adapter) &&
1704 qlcnic_check_multi_tx(adapter)) ||
1705 (qlcnic_83xx_check(adapter) &&
1706 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1707 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001708 handler = qlcnic_msix_tx_intr;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001709 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001710 ring++) {
1711 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001712 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001713 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001714 err = request_irq(tx_ring->irq, handler, flags,
1715 tx_ring->name, tx_ring);
1716 if (err)
1717 return err;
1718 }
1719 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001720 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001721 return 0;
1722}
1723
1724static void
1725qlcnic_free_irq(struct qlcnic_adapter *adapter)
1726{
1727 int ring;
1728 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001729 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001730
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001731 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001732
Sony Chacko13159182013-01-01 03:20:21 +00001733 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001734 if (qlcnic_82xx_check(adapter) ||
1735 (qlcnic_83xx_check(adapter) &&
1736 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001737 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001738 sds_ring = &recv_ctx->sds_rings[ring];
1739 free_irq(sds_ring->irq, sds_ring);
1740 }
Sony Chacko13159182013-01-01 03:20:21 +00001741 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001742 if ((qlcnic_83xx_check(adapter) &&
1743 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1744 (qlcnic_82xx_check(adapter) &&
1745 qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001746 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001747 ring++) {
1748 tx_ring = &adapter->tx_ring[ring];
1749 if (tx_ring->irq)
1750 free_irq(tx_ring->irq, tx_ring);
1751 }
1752 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001753 }
1754}
1755
Shahed Shaikh99e85872013-02-18 12:06:16 +00001756static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1757{
1758 u32 capab = 0;
1759
1760 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001761 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001762 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1763 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1764 } else {
1765 capab = adapter->ahw->capabilities;
1766 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1767 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1768 }
1769}
1770
Himanshu Madhania5147222014-01-23 17:18:32 -05001771static int qlcnic_config_def_intr_coalesce(struct qlcnic_adapter *adapter)
1772{
1773 struct qlcnic_hardware_context *ahw = adapter->ahw;
1774 int err;
1775
1776 /* Initialize interrupt coalesce parameters */
1777 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1778
1779 if (qlcnic_83xx_check(adapter)) {
1780 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
1781 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1782 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1783 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1784 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1785
1786 err = qlcnic_83xx_set_rx_tx_intr_coal(adapter);
1787 } else {
1788 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1789 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1790 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1791
1792 err = qlcnic_82xx_set_rx_coalesce(adapter);
1793 }
1794
1795 return err;
1796}
1797
Sony Chacko319ecf12013-01-01 03:20:22 +00001798int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001799{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001800 int ring;
1801 struct qlcnic_host_rds_ring *rds_ring;
1802
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001803 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1804 return -EIO;
1805
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001806 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1807 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001808
Rajesh Borundia0325d692010-08-19 05:08:26 +00001809 if (qlcnic_set_eswitch_port_config(adapter))
1810 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001811
Shahed Shaikh99e85872013-02-18 12:06:16 +00001812 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001813
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001814 if (qlcnic_fw_create_ctx(adapter))
1815 return -EIO;
1816
1817 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001818 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001819 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001820 }
1821
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001822 qlcnic_set_multi(netdev);
1823 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1824
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001825 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001826
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001827 if (adapter->drv_sds_rings > 1)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001828 qlcnic_config_rss(adapter, 1);
1829
Himanshu Madhania5147222014-01-23 17:18:32 -05001830 qlcnic_config_def_intr_coalesce(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001831
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001832 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001833 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1834
Pratik Pujarcfacb172013-07-19 16:56:27 -04001835 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001836 qlcnic_napi_enable(adapter);
1837
1838 qlcnic_linkevent_request(adapter, 1);
1839
Sony Chacko79788452012-12-04 03:33:53 +00001840 adapter->ahw->reset_context = 0;
Rajesh Borundia060d0562014-01-28 11:55:29 -05001841 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001842 return 0;
1843}
1844
Sony Chacko629263a2013-01-01 04:11:55 +00001845int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001846{
1847 int err = 0;
1848
1849 rtnl_lock();
1850 if (netif_running(netdev))
1851 err = __qlcnic_up(adapter, netdev);
1852 rtnl_unlock();
1853
1854 return err;
1855}
1856
Sony Chacko319ecf12013-01-01 03:20:22 +00001857void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001858{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001859 int ring;
1860
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001861 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1862 return;
1863
1864 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1865 return;
1866
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001867 if (qlcnic_sriov_vf_check(adapter))
1868 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001869 smp_mb();
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001870 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001871 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001872 netif_tx_disable(netdev);
1873
1874 qlcnic_free_mac_list(adapter);
1875
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001876 if (adapter->fhash.fnum)
1877 qlcnic_delete_lb_filters(adapter);
1878
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001879 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1880
1881 qlcnic_napi_disable(adapter);
1882
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001883 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001884 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001885
1886 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001887
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001888 for (ring = 0; ring < adapter->drv_tx_rings; ring++)
Himanshu Madhani012ec812013-08-21 11:24:10 -04001889 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001890}
1891
1892/* Usage: During suspend and firmware recovery module */
1893
Sony Chacko629263a2013-01-01 04:11:55 +00001894void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001895{
1896 rtnl_lock();
1897 if (netif_running(netdev))
1898 __qlcnic_down(adapter, netdev);
1899 rtnl_unlock();
1900
1901}
1902
Sony Chacko319ecf12013-01-01 03:20:22 +00001903int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001904qlcnic_attach(struct qlcnic_adapter *adapter)
1905{
1906 struct net_device *netdev = adapter->netdev;
1907 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001908 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001909
1910 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1911 return 0;
1912
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001913 err = qlcnic_napi_add(adapter, netdev);
1914 if (err)
1915 return err;
1916
1917 err = qlcnic_alloc_sw_resources(adapter);
1918 if (err) {
1919 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001920 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001921 }
1922
1923 err = qlcnic_alloc_hw_resources(adapter);
1924 if (err) {
1925 dev_err(&pdev->dev, "Error in setting hw resources\n");
1926 goto err_out_free_sw;
1927 }
1928
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001929 err = qlcnic_request_irq(adapter);
1930 if (err) {
1931 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001932 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001933 }
1934
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001935 qlcnic_create_sysfs_entries(adapter);
1936
1937 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1938 return 0;
1939
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001940err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001941 qlcnic_free_hw_resources(adapter);
1942err_out_free_sw:
1943 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001944err_out_napi_del:
1945 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001946 return err;
1947}
1948
Sony Chacko319ecf12013-01-01 03:20:22 +00001949void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001950{
1951 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1952 return;
1953
1954 qlcnic_remove_sysfs_entries(adapter);
1955
1956 qlcnic_free_hw_resources(adapter);
1957 qlcnic_release_rx_buffers(adapter);
1958 qlcnic_free_irq(adapter);
1959 qlcnic_napi_del(adapter);
1960 qlcnic_free_sw_resources(adapter);
1961
1962 adapter->is_up = 0;
1963}
1964
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001965void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings)
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001966{
1967 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1968 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001969 int drv_tx_rings = adapter->drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001970 int ring;
1971
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001972 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001973 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001974 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001975 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001976 qlcnic_disable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001977 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001978 }
1979
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001980 qlcnic_fw_destroy_ctx(adapter);
1981
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001982 qlcnic_detach(adapter);
1983
Sony Chacko79788452012-12-04 03:33:53 +00001984 adapter->ahw->diag_test = 0;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001985 adapter->drv_sds_rings = drv_sds_rings;
1986 adapter->drv_tx_rings = drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001987
1988 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001989 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001990
1991 if (netif_running(netdev))
1992 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001993out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001994 netif_device_attach(netdev);
1995}
1996
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001997static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1998{
1999 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00002000
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002001 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
2002 GFP_KERNEL);
2003 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002004 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00002005 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002006 }
Himanshu Madhania5147222014-01-23 17:18:32 -05002007
Sony Chacko4be41e92013-01-01 03:20:20 +00002008 /* clear stats */
2009 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002010err_out:
2011 return err;
2012}
2013
2014static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
2015{
2016 kfree(adapter->recv_ctx);
2017 adapter->recv_ctx = NULL;
2018
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002019 if (adapter->ahw->fw_dump.tmpl_hdr) {
2020 vfree(adapter->ahw->fw_dump.tmpl_hdr);
2021 adapter->ahw->fw_dump.tmpl_hdr = NULL;
2022 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002023
Sony Chacko81d0aeb2013-01-01 03:20:25 +00002024 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00002025 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002026}
2027
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002028int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
2029{
2030 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2031 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002032 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002033 int ring;
2034 int ret;
2035
2036 netif_device_detach(netdev);
2037
2038 if (netif_running(netdev))
2039 __qlcnic_down(adapter, netdev);
2040
2041 qlcnic_detach(adapter);
2042
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002043 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sony Chacko79788452012-12-04 03:33:53 +00002044 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00002045 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002046
2047 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002048 if (ret) {
2049 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002050 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002051 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002052
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002053 ret = qlcnic_fw_create_ctx(adapter);
2054 if (ret) {
2055 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00002056 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002057 return ret;
2058 }
2059
2060 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002061 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00002062 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002063 }
2064
Sony Chacko79788452012-12-04 03:33:53 +00002065 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002066 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002067 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002068 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002069 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002070 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002071
Sony Chacko79788452012-12-04 03:33:53 +00002072 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002073 adapter->ahw->loopback_state = 0;
2074 qlcnic_linkevent_request(adapter, 1);
2075 }
2076
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002077 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002078
2079 return 0;
2080}
2081
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002082/* Reset context in hardware only */
2083static int
2084qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
2085{
2086 struct net_device *netdev = adapter->netdev;
2087
2088 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2089 return -EBUSY;
2090
2091 netif_device_detach(netdev);
2092
2093 qlcnic_down(adapter, netdev);
2094
2095 qlcnic_up(adapter, netdev);
2096
2097 netif_device_attach(netdev);
2098
2099 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani95b38902014-01-23 17:18:29 -05002100 netdev_info(adapter->netdev, "%s: soft reset complete\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002101 return 0;
2102}
2103
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002104int
2105qlcnic_reset_context(struct qlcnic_adapter *adapter)
2106{
2107 int err = 0;
2108 struct net_device *netdev = adapter->netdev;
2109
2110 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2111 return -EBUSY;
2112
2113 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
2114
2115 netif_device_detach(netdev);
2116
2117 if (netif_running(netdev))
2118 __qlcnic_down(adapter, netdev);
2119
2120 qlcnic_detach(adapter);
2121
2122 if (netif_running(netdev)) {
2123 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002124 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002125 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002126 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2127 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002128 }
2129
2130 netif_device_attach(netdev);
2131 }
2132
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002133 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2134 return err;
2135}
2136
stephen hemminger21041402014-01-16 10:31:27 -08002137static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002138{
2139 struct qlcnic_hardware_context *ahw = adapter->ahw;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002140 u16 act_pci_fn = ahw->total_nic_func;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002141 u16 count;
2142
2143 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2144 if (act_pci_fn <= 2)
2145 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2146 act_pci_fn;
2147 else
2148 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2149 act_pci_fn;
2150 ahw->max_uc_count = count;
2151}
2152
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002153int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002154qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2155 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002156{
2157 int err;
2158 struct pci_dev *pdev = adapter->pdev;
2159
Sony Chacko13159182013-01-01 03:20:21 +00002160 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002161 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002162 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002163
2164 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002165 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002166
2167 qlcnic_change_mtu(netdev, netdev->mtu);
2168
Rajesh Borundiad1a11052013-04-19 07:01:13 +00002169 if (qlcnic_sriov_vf_check(adapter))
2170 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops);
2171 else
2172 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002173
Sony Chacko7e38d042013-01-01 03:20:28 +00002174 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002175 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002176 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002177 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2178 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002179
Sony Chacko13159182013-01-01 03:20:21 +00002180 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2181 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2182 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2183 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002184
Sony Chacko13159182013-01-01 03:20:21 +00002185 if (pci_using_dac) {
2186 netdev->features |= NETIF_F_HIGHDMA;
2187 netdev->vlan_features |= NETIF_F_HIGHDMA;
2188 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002189
Sony Chacko13159182013-01-01 03:20:21 +00002190 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002191 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002192
Rajesh Borundia91b72822013-04-19 07:01:12 +00002193 if (qlcnic_sriov_vf_check(adapter))
2194 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2195
Sony Chacko79788452012-12-04 03:33:53 +00002196 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002197 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002198
Sony Chacko7e38d042013-01-01 03:20:28 +00002199 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002200 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002201 netdev->irq = adapter->msix_entries[0].vector;
2202
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002203 err = qlcnic_set_real_num_queues(adapter, netdev);
2204 if (err)
2205 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002206
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002207 err = register_netdev(netdev);
2208 if (err) {
2209 dev_err(&pdev->dev, "failed to register net device\n");
2210 return err;
2211 }
2212
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002213 qlcnic_dcb_init_dcbnl_ops(adapter->dcb);
Sucheta Chakraborty48365e42013-08-23 13:38:28 -04002214
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002215 return 0;
2216}
2217
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002218static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002219{
2220 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2221 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2222 *pci_using_dac = 1;
2223 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2224 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2225 *pci_using_dac = 0;
2226 else {
2227 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2228 return -EIO;
2229 }
2230
2231 return 0;
2232}
2233
Sony Chacko4be41e92013-01-01 03:20:20 +00002234void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2235{
2236 int ring;
2237 struct qlcnic_host_tx_ring *tx_ring;
2238
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002239 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002240 tx_ring = &adapter->tx_ring[ring];
2241 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
2242 vfree(tx_ring->cmd_buf_arr);
2243 tx_ring->cmd_buf_arr = NULL;
2244 }
2245 }
2246 if (adapter->tx_ring != NULL)
2247 kfree(adapter->tx_ring);
2248}
2249
2250int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2251 struct net_device *netdev)
2252{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002253 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002254 struct qlcnic_host_tx_ring *tx_ring;
2255 struct qlcnic_cmd_buffer *cmd_buf_arr;
2256
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002257 tx_ring = kcalloc(adapter->drv_tx_rings,
Joe Perchesb2adaca2013-02-03 17:43:58 +00002258 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2259 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002260 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002261
Sony Chacko4be41e92013-01-01 03:20:20 +00002262 adapter->tx_ring = tx_ring;
2263
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002264 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002265 tx_ring = &adapter->tx_ring[ring];
2266 tx_ring->num_desc = adapter->num_txd;
2267 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2268 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2269 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002270 qlcnic_free_tx_rings(adapter);
2271 return -ENOMEM;
2272 }
2273 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
2274 tx_ring->cmd_buf_arr = cmd_buf_arr;
Shahed Shaikha02bdd42014-01-03 01:34:28 -05002275 spin_lock_init(&tx_ring->tx_clean_lock);
Sony Chacko4be41e92013-01-01 03:20:20 +00002276 }
2277
Himanshu Madhani012ec812013-08-21 11:24:10 -04002278 if (qlcnic_83xx_check(adapter) ||
2279 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002280 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002281 tx_ring = &adapter->tx_ring[ring];
2282 tx_ring->adapter = adapter;
2283 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002284 index = adapter->drv_sds_rings + ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002285 vector = adapter->msix_entries[index].vector;
2286 tx_ring->irq = vector;
2287 }
2288 }
2289 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002290
Sony Chacko4be41e92013-01-01 03:20:20 +00002291 return 0;
2292}
2293
Pratik Pujar8af3f332013-06-22 04:12:05 -04002294void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2295{
2296 struct qlcnic_hardware_context *ahw = adapter->ahw;
2297 u32 fw_cmd = 0;
2298
2299 if (qlcnic_82xx_check(adapter))
2300 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2301 else if (qlcnic_83xx_check(adapter))
2302 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2303
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002304 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002305 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2306}
2307
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002308static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002309qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2310{
2311 struct net_device *netdev = NULL;
2312 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002313 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002314 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002315 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002316
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002317 if (pdev->is_virtfn)
2318 return -ENODEV;
2319
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002320 err = pci_enable_device(pdev);
2321 if (err)
2322 return err;
2323
2324 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2325 err = -ENODEV;
2326 goto err_out_disable_pdev;
2327 }
2328
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002329 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2330 if (err)
2331 goto err_out_disable_pdev;
2332
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002333 err = pci_request_regions(pdev, qlcnic_driver_name);
2334 if (err)
2335 goto err_out_disable_pdev;
2336
2337 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002338 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002339
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002340 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002341 if (!ahw) {
2342 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002343 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002344 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002345
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002346 switch (ent->device) {
2347 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002348 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002349 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2350 break;
2351 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002352 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002353 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002354 break;
2355 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002356 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002357 qlcnic_sriov_vf_register_map(ahw);
2358 break;
2359 default:
Sony Chacko13159182013-01-01 03:20:21 +00002360 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002361 }
2362
2363 err = qlcnic_setup_pci_map(pdev, ahw);
2364 if (err)
2365 goto err_out_free_hw_res;
2366
Himanshu Madhani012ec812013-08-21 11:24:10 -04002367 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2368 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002369 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002370 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002371 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002372 }
2373
2374 SET_NETDEV_DEV(netdev, &pdev->dev);
2375
2376 adapter = netdev_priv(netdev);
2377 adapter->netdev = netdev;
2378 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002379 adapter->ahw = ahw;
2380
2381 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2382 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002383 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002384 dev_err(&pdev->dev, "Failed to create workqueue\n");
2385 goto err_out_free_netdev;
2386 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002387
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002388 err = qlcnic_alloc_adapter_resources(adapter);
2389 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002390 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002391
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002392 adapter->dev_rst_time = jiffies;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002393 ahw->revision_id = pdev->revision;
2394 ahw->max_vnic_func = qlcnic_get_vnic_func_count(adapter);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002395 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2396 adapter->fdb_mac_learn = true;
2397 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2398 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002399
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002400 rwlock_init(&adapter->ahw->crb_lock);
2401 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002402
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002403 INIT_LIST_HEAD(&adapter->mac_list);
2404
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002405 qlcnic_register_dcb(adapter);
2406
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002407 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002408 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002409 adapter->portnum = adapter->ahw->pci_func;
2410 err = qlcnic_start_firmware(adapter);
2411 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002412 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2413 "\t\tIf reboot doesn't help, try flashing the card\n");
2414 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002415 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002416
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002417 /* compute and set default and max tx/sds rings */
2418 if (adapter->ahw->msix_supported) {
2419 if (qlcnic_check_multi_tx_capability(adapter) == 1)
2420 qlcnic_set_tx_ring_count(adapter,
2421 QLCNIC_SINGLE_RING);
2422 else
2423 qlcnic_set_tx_ring_count(adapter,
2424 QLCNIC_DEF_TX_RINGS);
2425 qlcnic_set_sds_ring_count(adapter,
2426 QLCNIC_DEF_SDS_RINGS);
2427 } else {
2428 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING);
2429 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002430 }
2431
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002432 err = qlcnic_setup_idc_param(adapter);
2433 if (err)
2434 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002435
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002436 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002437
Sony Chacko13159182013-01-01 03:20:21 +00002438 } else if (qlcnic_83xx_check(adapter)) {
2439 qlcnic_83xx_check_vf(adapter, ent);
2440 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002441 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002442 if (err) {
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002443 switch (err) {
2444 case -ENOTRECOVERABLE:
2445 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware. Please reboot\n");
2446 dev_err(&pdev->dev, "If reboot doesn't help, please replace the adapter with new one and return the faulty adapter for repair\n");
2447 goto err_out_free_hw;
2448 case -ENOMEM:
2449 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n");
2450 goto err_out_free_hw;
2451 default:
2452 dev_err(&pdev->dev, "Adapter initialization failed. A reboot may be required to recover from this failure\n");
2453 dev_err(&pdev->dev, "If reboot does not help to recover from this failure, try a flash update of the adapter\n");
2454 goto err_out_maintenance_mode;
2455 }
Sony Chacko629263a2013-01-01 04:11:55 +00002456 }
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002457
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002458 if (qlcnic_sriov_vf_check(adapter))
2459 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002460 } else {
2461 dev_err(&pdev->dev,
2462 "%s: failed. Please Reboot\n", __func__);
2463 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002464 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002465
Sucheta Chakraborty3c44bba2013-12-17 09:01:49 -05002466 qlcnic_dcb_enable(adapter->dcb);
2467
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002468 if (qlcnic_read_mac_addr(adapter))
2469 dev_warn(&pdev->dev, "failed to read mac addr\n");
2470
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002471 qlcnic_read_phys_port_id(adapter);
2472
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002473 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002474 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002475
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002476 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002477 module_name(THIS_MODULE),
2478 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002479 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002480
2481 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2482 !!qlcnic_use_msi)
2483 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002484 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002485
Manish Chopra068a8d12013-08-02 00:57:41 -04002486 if (qlcnic_82xx_check(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002487 err = qlcnic_setup_intr(adapter);
Manish Chopra068a8d12013-08-02 00:57:41 -04002488 if (err) {
2489 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002490 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002491 }
Sony Chacko13159182013-01-01 03:20:21 +00002492 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002493
Sony Chacko02135582013-05-21 09:26:59 +00002494 err = qlcnic_get_act_pci_func(adapter);
2495 if (err)
2496 goto err_out_disable_mbx_intr;
2497
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002498 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002499 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002500 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002501
Himanshu Madhani24866d12013-08-15 08:29:27 -04002502 if (adapter->portnum == 0)
2503 qlcnic_set_drv_version(adapter);
Sritej Velagac84e3402013-01-25 10:20:34 +00002504
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002505 pci_set_drvdata(pdev, adapter);
2506
Sony Chacko97ee45e2012-12-04 03:33:52 +00002507 if (qlcnic_82xx_check(adapter))
2508 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2509 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002510
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002511 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002512 case QLCNIC_GBE:
2513 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2514 adapter->netdev->name);
2515 break;
2516 case QLCNIC_XGBE:
2517 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2518 adapter->netdev->name);
2519 break;
2520 }
2521
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002522 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002523 qlcnic_alloc_lb_filters_mem(adapter);
2524
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002525 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526
2527 return 0;
2528
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002529err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002530 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002531 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002532
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002533err_out_disable_msi:
2534 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002535 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002536 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002537
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002538err_out_free_hw:
2539 qlcnic_free_adapter_resources(adapter);
2540
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002541err_out_free_wq:
2542 destroy_workqueue(adapter->qlcnic_wq);
2543
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002544err_out_free_netdev:
2545 free_netdev(netdev);
2546
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002547err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002548 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002549
2550err_out_free_hw_res:
2551 kfree(ahw);
2552
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002553err_out_free_res:
2554 pci_release_regions(pdev);
2555
2556err_out_disable_pdev:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002557 pci_disable_device(pdev);
2558 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002559
2560err_out_maintenance_mode:
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002561 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002562 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
2563 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002564 ahw->port_type = QLCNIC_XGBE;
2565
2566 if (qlcnic_83xx_check(adapter))
2567 adapter->tgt_status_reg = NULL;
2568 else
2569 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS;
2570
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002571 err = register_netdev(netdev);
2572
2573 if (err) {
2574 dev_err(&pdev->dev, "Failed to register net device\n");
2575 qlcnic_clr_all_drv_state(adapter, 0);
2576 goto err_out_free_hw;
2577 }
2578
2579 pci_set_drvdata(pdev, adapter);
2580 qlcnic_add_sysfs(adapter);
2581
2582 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002583}
2584
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002585static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002586{
2587 struct qlcnic_adapter *adapter;
2588 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002589 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002590
2591 adapter = pci_get_drvdata(pdev);
2592 if (adapter == NULL)
2593 return;
2594
2595 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002596 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002597
Sony Chacko13159182013-01-01 03:20:21 +00002598 qlcnic_cancel_idc_work(adapter);
2599 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002600
2601 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002602 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002603
Sony Chacko13159182013-01-01 03:20:21 +00002604 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05002605 qlcnic_83xx_initialize_nic(adapter, 0);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002606 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002607 qlcnic_83xx_free_mbx_intr(adapter);
2608 qlcnic_83xx_detach_mailbox_work(adapter);
2609 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002610 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002611 }
2612
Sucheta Chakraborty3720bf72013-12-17 09:01:50 -05002613 qlcnic_dcb_free(adapter->dcb);
2614
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002615 qlcnic_detach(adapter);
2616
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002617 if (adapter->npars != NULL)
2618 kfree(adapter->npars);
2619 if (adapter->eswitch != NULL)
2620 kfree(adapter->eswitch);
2621
Sony Chacko97ee45e2012-12-04 03:33:52 +00002622 if (qlcnic_82xx_check(adapter))
2623 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002624
2625 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2626
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002627 qlcnic_free_lb_filters_mem(adapter);
2628
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002629 qlcnic_teardown_intr(adapter);
2630
Sony Chacko13159182013-01-01 03:20:21 +00002631 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002632
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002633 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002634
2635 qlcnic_release_firmware(adapter);
2636
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002637 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002638 pci_release_regions(pdev);
2639 pci_disable_device(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002640
Sony Chacko13159182013-01-01 03:20:21 +00002641 if (adapter->qlcnic_wq) {
2642 destroy_workqueue(adapter->qlcnic_wq);
2643 adapter->qlcnic_wq = NULL;
2644 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002645
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002646 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002647 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002648 free_netdev(netdev);
2649}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002650
2651static void qlcnic_shutdown(struct pci_dev *pdev)
2652{
2653 if (__qlcnic_shutdown(pdev))
2654 return;
2655
2656 pci_disable_device(pdev);
2657}
2658
2659#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002660static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002661{
2662 int retval;
2663
2664 retval = __qlcnic_shutdown(pdev);
2665 if (retval)
2666 return retval;
2667
2668 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2669 return 0;
2670}
2671
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002672static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002673{
2674 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002675 int err;
2676
2677 err = pci_enable_device(pdev);
2678 if (err)
2679 return err;
2680
2681 pci_set_power_state(pdev, PCI_D0);
2682 pci_set_master(pdev);
2683 pci_restore_state(pdev);
2684
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002685 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002686}
2687#endif
2688
2689static int qlcnic_open(struct net_device *netdev)
2690{
2691 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2692 int err;
2693
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002694 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
2695 netdev_err(netdev, "%s: Device is in non-operational state\n",
2696 __func__);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002697
2698 return -EIO;
2699 }
2700
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002701 netif_carrier_off(netdev);
2702
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002703 err = qlcnic_attach(adapter);
2704 if (err)
2705 return err;
2706
2707 err = __qlcnic_up(adapter, netdev);
2708 if (err)
Rajesh Borundia060d0562014-01-28 11:55:29 -05002709 qlcnic_detach(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002710
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002711 return err;
2712}
2713
2714/*
2715 * qlcnic_close - Disables a network interface entry point
2716 */
2717static int qlcnic_close(struct net_device *netdev)
2718{
2719 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2720
2721 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002722
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002723 return 0;
2724}
2725
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002726void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002727{
2728 void *head;
2729 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002730 struct net_device *netdev = adapter->netdev;
2731 u32 filter_size = 0;
2732 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002733
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002734 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002735 return;
2736
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002737 act_pci_func = adapter->ahw->total_nic_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002738 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002739 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002740
Sony Chacko13159182013-01-01 03:20:21 +00002741 if (qlcnic_82xx_check(adapter)) {
2742 filter_size = QLCNIC_LB_MAX_FILTERS;
2743 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2744 } else {
2745 filter_size = QLC_83XX_LB_MAX_FILTERS;
2746 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2747 }
2748
2749 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002750 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002751
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002752 if (!head)
2753 return;
2754
Sony Chacko13159182013-01-01 03:20:21 +00002755 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002756 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002757
Sony Chacko13159182013-01-01 03:20:21 +00002758 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2759 act_pci_func, adapter->fhash.fmax);
2760
2761 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002762 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002763
2764 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2765
2766 head = kcalloc(adapter->rx_fhash.fbucket_size,
2767 sizeof(struct hlist_head), GFP_ATOMIC);
2768
2769 if (!head)
2770 return;
2771
2772 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2773 adapter->rx_fhash.fhead = head;
2774
2775 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2776 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002777}
2778
2779static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2780{
2781 if (adapter->fhash.fmax && adapter->fhash.fhead)
2782 kfree(adapter->fhash.fhead);
2783
2784 adapter->fhash.fhead = NULL;
2785 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002786
2787 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2788 kfree(adapter->rx_fhash.fhead);
2789
2790 adapter->rx_fhash.fmax = 0;
2791 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002792}
2793
Sony Chacko629263a2013-01-01 04:11:55 +00002794int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002795{
2796 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002797 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002798 int rv = 0;
2799
Sony Chacko13159182013-01-01 03:20:21 +00002800 if (qlcnic_83xx_check(adapter))
2801 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2802
Sony Chacko97ee45e2012-12-04 03:33:52 +00002803 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002804 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002805
2806 temp_state = qlcnic_get_temp_state(temp);
2807 temp_val = qlcnic_get_temp_val(temp);
2808
2809 if (temp_state == QLCNIC_TEMP_PANIC) {
2810 dev_err(&netdev->dev,
2811 "Device temperature %d degrees C exceeds"
2812 " maximum allowed. Hardware has been shut down.\n",
2813 temp_val);
2814 rv = 1;
2815 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002816 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002817 dev_err(&netdev->dev,
2818 "Device temperature %d degrees C "
2819 "exceeds operating range."
2820 " Immediate action needed.\n",
2821 temp_val);
2822 }
2823 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002824 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002825 dev_info(&netdev->dev,
2826 "Device temperature is now %d degrees C"
2827 " in normal range.\n", temp_val);
2828 }
2829 }
Sony Chacko79788452012-12-04 03:33:53 +00002830 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002831 return rv;
2832}
2833
Himanshu Madhani95b38902014-01-23 17:18:29 -05002834static inline void dump_tx_ring_desc(struct qlcnic_host_tx_ring *tx_ring)
2835{
2836 int i;
2837 struct cmd_desc_type0 *tx_desc_info;
2838
2839 for (i = 0; i < tx_ring->num_desc; i++) {
2840 tx_desc_info = &tx_ring->desc_head[i];
2841 pr_info("TX Desc: %d\n", i);
2842 print_hex_dump(KERN_INFO, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
2843 &tx_ring->desc_head[i],
2844 sizeof(struct cmd_desc_type0), true);
2845 }
2846}
2847
2848static void qlcnic_dump_tx_rings(struct qlcnic_adapter *adapter)
2849{
2850 struct net_device *netdev = adapter->netdev;
2851 struct qlcnic_host_tx_ring *tx_ring;
2852 int ring;
2853
2854 if (!netdev || !netif_running(netdev))
2855 return;
2856
2857 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2858 tx_ring = &adapter->tx_ring[ring];
2859 netdev_info(netdev, "Tx ring=%d Context Id=0x%x\n",
2860 ring, tx_ring->ctx_id);
2861 netdev_info(netdev,
2862 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
2863 tx_ring->tx_stats.xmit_finished,
2864 tx_ring->tx_stats.xmit_called,
2865 tx_ring->tx_stats.xmit_on,
2866 tx_ring->tx_stats.xmit_off);
2867 netdev_info(netdev,
2868 "crb_intr_mask=%d, hw_producer=%d, sw_producer=%d sw_consumer=%d, hw_consumer=%d\n",
2869 readl(tx_ring->crb_intr_mask),
2870 readl(tx_ring->crb_cmd_producer),
2871 tx_ring->producer, tx_ring->sw_consumer,
2872 le32_to_cpu(*(tx_ring->hw_consumer)));
2873
2874 netdev_info(netdev, "Total desc=%d, Available desc=%d\n",
2875 tx_ring->num_desc, qlcnic_tx_avail(tx_ring));
2876
2877 if (netif_msg_tx_done(adapter->ahw))
2878 dump_tx_ring_desc(tx_ring);
2879 }
2880}
2881
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002882static void qlcnic_tx_timeout(struct net_device *netdev)
2883{
2884 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2885
2886 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2887 return;
2888
Sony Chacko536faa62013-05-09 09:25:13 +00002889 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
2890 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
2891 if (qlcnic_82xx_check(adapter))
2892 adapter->need_fw_reset = 1;
2893 else if (qlcnic_83xx_check(adapter))
2894 qlcnic_83xx_idc_request_reset(adapter,
2895 QLCNIC_FORCE_FW_DUMP_KEY);
2896 } else {
2897 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Himanshu Madhani95b38902014-01-23 17:18:29 -05002898 qlcnic_dump_tx_rings(adapter);
Sony Chacko79788452012-12-04 03:33:53 +00002899 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00002900 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002901}
2902
2903static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2904{
2905 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2906 struct net_device_stats *stats = &netdev->stats;
2907
Manish Chopra1ac67622014-01-09 12:41:04 -05002908 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2909 qlcnic_update_stats(adapter);
2910
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002911 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2912 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002913 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002914 stats->tx_bytes = adapter->stats.txbytes;
2915 stats->rx_dropped = adapter->stats.rxdropped;
2916 stats->tx_dropped = adapter->stats.txdropped;
2917
2918 return stats;
2919}
2920
stephen hemminger21041402014-01-16 10:31:27 -08002921static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002922{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002923 u32 status;
2924
2925 status = readl(adapter->isr_int_vec);
2926
Sony Chacko79788452012-12-04 03:33:53 +00002927 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002928 return IRQ_NONE;
2929
2930 /* check interrupt state machine, to be sure */
2931 status = readl(adapter->crb_int_state_reg);
2932 if (!ISR_LEGACY_INT_TRIGGERED(status))
2933 return IRQ_NONE;
2934
2935 writel(0xffffffff, adapter->tgt_status_reg);
2936 /* read twice to ensure write is flushed */
2937 readl(adapter->isr_int_vec);
2938 readl(adapter->isr_int_vec);
2939
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002940 return IRQ_HANDLED;
2941}
2942
2943static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2944{
2945 struct qlcnic_host_sds_ring *sds_ring = data;
2946 struct qlcnic_adapter *adapter = sds_ring->adapter;
2947
2948 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2949 goto done;
2950 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2951 writel(0xffffffff, adapter->tgt_status_reg);
2952 goto done;
2953 }
2954
2955 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2956 return IRQ_NONE;
2957
2958done:
Sony Chacko79788452012-12-04 03:33:53 +00002959 adapter->ahw->diag_cnt++;
Manish chopra2cc57522014-01-23 17:18:30 -05002960 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002961 return IRQ_HANDLED;
2962}
2963
2964static irqreturn_t qlcnic_intr(int irq, void *data)
2965{
2966 struct qlcnic_host_sds_ring *sds_ring = data;
2967 struct qlcnic_adapter *adapter = sds_ring->adapter;
2968
2969 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2970 return IRQ_NONE;
2971
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002972 napi_schedule(&sds_ring->napi);
2973
2974 return IRQ_HANDLED;
2975}
2976
2977static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2978{
2979 struct qlcnic_host_sds_ring *sds_ring = data;
2980 struct qlcnic_adapter *adapter = sds_ring->adapter;
2981
2982 /* clear interrupt */
2983 writel(0xffffffff, adapter->tgt_status_reg);
2984
2985 napi_schedule(&sds_ring->napi);
2986 return IRQ_HANDLED;
2987}
2988
2989static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2990{
2991 struct qlcnic_host_sds_ring *sds_ring = data;
2992
2993 napi_schedule(&sds_ring->napi);
2994 return IRQ_HANDLED;
2995}
2996
Sony Chacko13159182013-01-01 03:20:21 +00002997static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2998{
2999 struct qlcnic_host_tx_ring *tx_ring = data;
3000
3001 napi_schedule(&tx_ring->napi);
3002 return IRQ_HANDLED;
3003}
3004
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003005#ifdef CONFIG_NET_POLL_CONTROLLER
3006static void qlcnic_poll_controller(struct net_device *netdev)
3007{
3008 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Manish chopra2b018ad92014-01-23 17:18:31 -05003009 struct qlcnic_host_sds_ring *sds_ring;
3010 struct qlcnic_recv_context *recv_ctx;
3011 struct qlcnic_host_tx_ring *tx_ring;
3012 int ring;
Yinglin Luanbf827912010-08-22 21:57:56 +00003013
Manish chopra2b018ad92014-01-23 17:18:31 -05003014 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3015 return;
3016
3017 recv_ctx = adapter->recv_ctx;
3018
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003019 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Yinglin Luanbf827912010-08-22 21:57:56 +00003020 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2b018ad92014-01-23 17:18:31 -05003021 qlcnic_disable_sds_intr(adapter, sds_ring);
3022 napi_schedule(&sds_ring->napi);
Yinglin Luanbf827912010-08-22 21:57:56 +00003023 }
Manish chopra2b018ad92014-01-23 17:18:31 -05003024
3025 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
3026 /* Only Multi-Tx queue capable devices need to
3027 * schedule NAPI for TX rings
3028 */
3029 if ((qlcnic_83xx_check(adapter) &&
3030 (adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
3031 (qlcnic_82xx_check(adapter) &&
3032 !qlcnic_check_multi_tx(adapter)))
3033 return;
3034
3035 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
3036 tx_ring = &adapter->tx_ring[ring];
3037 qlcnic_disable_tx_intr(adapter, tx_ring);
3038 napi_schedule(&tx_ring->napi);
3039 }
3040 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003041}
3042#endif
3043
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003044static void
3045qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
3046{
3047 u32 val;
3048
3049 val = adapter->portnum & 0xf;
3050 val |= encoding << 7;
3051 val |= (jiffies - adapter->dev_rst_time) << 8;
3052
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003053 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003054 adapter->dev_rst_time = jiffies;
3055}
3056
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003057static int
3058qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003059{
3060 u32 val;
3061
3062 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
3063 state != QLCNIC_DEV_NEED_QUISCENT);
3064
3065 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003066 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003067
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003068 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003069
3070 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003071 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003072 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003073 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003074
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003075 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003076
3077 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003078
3079 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003080}
3081
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003082static int
3083qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
3084{
3085 u32 val;
3086
3087 if (qlcnic_api_lock(adapter))
3088 return -EBUSY;
3089
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003090 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003091 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003092 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003093
3094 qlcnic_api_unlock(adapter);
3095
3096 return 0;
3097}
3098
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003099void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003100{
3101 u32 val;
3102
3103 if (qlcnic_api_lock(adapter))
3104 goto err;
3105
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003106 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003107 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003108 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003109
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003110 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003111 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3112 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003113 dev_info(&adapter->pdev->dev,
3114 "Device state set to Failed. Please Reboot\n");
3115 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003116 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3117 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003118
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003119 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003120 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003121 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003122
3123 qlcnic_api_unlock(adapter);
3124err:
3125 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003126 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003127 clear_bit(__QLCNIC_START_FW, &adapter->state);
3128 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3129}
3130
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003131/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003132static int
3133qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
3134{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003135 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003136 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003137
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003138 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
3139 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003140
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003141 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003142 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003143 act = act & active_mask;
3144 }
3145
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003146 if (((state & 0x11111111) == (act & 0x11111111)) ||
3147 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
3148 return 0;
3149 else
3150 return 1;
3151}
3152
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003153static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
3154{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003155 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003156
3157 if (val != QLCNIC_DRV_IDC_VER) {
3158 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
3159 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
3160 }
3161
3162 return 0;
3163}
3164
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003165static int
3166qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
3167{
3168 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003169 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003170 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003171 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003172
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003173 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
3174 return 1;
3175
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003176 if (qlcnic_api_lock(adapter))
3177 return -1;
3178
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003179 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003180 if (!(val & (1 << (portnum * 4)))) {
3181 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003182 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003183 }
3184
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003185 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003186 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003187
3188 switch (prev_state) {
3189 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003190 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3191 QLCNIC_DEV_INITIALIZING);
3192 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3193 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003194 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003195 qlcnic_api_unlock(adapter);
3196 return 1;
3197
3198 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003199 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003200 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003201 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003202
3203 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003204 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003205 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003206 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003207 break;
3208
3209 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003210 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003211 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003212 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003213 break;
3214
3215 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003216 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003217 qlcnic_api_unlock(adapter);
3218 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003219
3220 case QLCNIC_DEV_INITIALIZING:
3221 case QLCNIC_DEV_QUISCENT:
3222 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003223 }
3224
3225 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003226
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003227 do {
3228 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003229 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003230
3231 if (prev_state == QLCNIC_DEV_QUISCENT)
3232 continue;
3233 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003234
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003235 if (!dev_init_timeo) {
3236 dev_err(&adapter->pdev->dev,
3237 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003238 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003239 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003240
3241 if (qlcnic_api_lock(adapter))
3242 return -1;
3243
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003244 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003245 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003246 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003247
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003248 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003249 qlcnic_api_unlock(adapter);
3250
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003251 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003252}
3253
3254static void
3255qlcnic_fwinit_work(struct work_struct *work)
3256{
3257 struct qlcnic_adapter *adapter = container_of(work,
3258 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003259 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003260 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003261
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003262 if (qlcnic_api_lock(adapter))
3263 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003264
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003265 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003266 if (dev_state == QLCNIC_DEV_QUISCENT ||
3267 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003268 qlcnic_api_unlock(adapter);
3269 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3270 FW_POLL_DELAY * 2);
3271 return;
3272 }
3273
Sony Chacko79788452012-12-04 03:33:53 +00003274 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003275 qlcnic_api_unlock(adapter);
3276 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003277 }
3278
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003279 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3280 dev_state == QLCNIC_DEV_READY) {
3281 dev_info(&adapter->pdev->dev, "Detected state change from "
3282 "DEV_NEED_RESET, skipping ack check\n");
3283 goto skip_ack_check;
3284 }
3285
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003286 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003287 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003288 adapter->reset_ack_timeo);
3289 goto skip_ack_check;
3290 }
3291
3292 if (!qlcnic_check_drv_state(adapter)) {
3293skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003294 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003295
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003296 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003297 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3298 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003299 set_bit(__QLCNIC_START_FW, &adapter->state);
3300 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003301 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003302 val = QLC_SHARED_REG_RD32(adapter,
3303 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003304 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003305 QLC_SHARED_REG_WR32(adapter,
3306 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003307 }
3308
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003309 qlcnic_api_unlock(adapter);
3310
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003311 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003312 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003313 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003314 QLCDB(adapter, DRV, "Take FW dump\n");
3315 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003316 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003317 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003318 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003319
3320 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003321 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003322 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003323 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003324 return;
3325 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003326 goto err_ret;
3327 }
3328
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003329 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003330
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003331wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003332 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003333 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003334
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003335 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003336 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003337 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003338 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003339 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003340 return;
3341 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003342 case QLCNIC_DEV_FAILED:
3343 break;
3344 default:
3345 qlcnic_schedule_work(adapter,
3346 qlcnic_fwinit_work, FW_POLL_DELAY);
3347 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003348 }
3349
3350err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003351 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3352 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003353 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003354 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003355}
3356
3357static void
3358qlcnic_detach_work(struct work_struct *work)
3359{
3360 struct qlcnic_adapter *adapter = container_of(work,
3361 struct qlcnic_adapter, fw_work.work);
3362 struct net_device *netdev = adapter->netdev;
3363 u32 status;
3364
3365 netif_device_detach(netdev);
3366
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003367 /* Dont grab rtnl lock during Quiscent mode */
3368 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3369 if (netif_running(netdev))
3370 __qlcnic_down(adapter, netdev);
3371 } else
3372 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003373
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003374 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003375
Sony Chacko44f65b22011-08-29 12:50:26 +00003376 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3377 dev_err(&adapter->pdev->dev,
3378 "Detaching the device: peg halt status1=0x%x\n",
3379 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003380
Sony Chacko44f65b22011-08-29 12:50:26 +00003381 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3382 dev_err(&adapter->pdev->dev,
3383 "On board active cooling fan failed. "
3384 "Device has been halted.\n");
3385 dev_err(&adapter->pdev->dev,
3386 "Replace the adapter.\n");
3387 }
3388
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003389 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003390 }
3391
Sony Chacko79788452012-12-04 03:33:53 +00003392 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003393 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003394 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003395 goto err_ret;
3396 }
3397
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003398 /* Dont ack if this instance is the reset owner */
3399 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003400 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3401 dev_err(&adapter->pdev->dev,
3402 "Failed to set driver state,"
3403 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003404 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003405 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003406 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003407
3408 adapter->fw_wait_cnt = 0;
3409
3410 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3411
3412 return;
3413
3414err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003415 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003416 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003417}
3418
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003419/*Transit NPAR state to NON Operational */
3420static void
3421qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3422{
3423 u32 state;
3424
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003425 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003426 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3427 return;
3428
3429 if (qlcnic_api_lock(adapter))
3430 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003431 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3432 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003433 qlcnic_api_unlock(adapter);
3434}
3435
stephen hemminger21041402014-01-16 10:31:27 -08003436static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter,
3437 u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003438{
Sritej Velaga646779f2012-02-03 13:45:41 +00003439 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003440
Sritej Velaga646779f2012-02-03 13:45:41 +00003441 qlcnic_xg_set_xg0_mask(xg_val);
3442 qlcnic_xg_set_xg1_mask(xg_val);
3443 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3444 qlcnic_gb_set_gb0_mask(gb_val);
3445 qlcnic_gb_set_gb1_mask(gb_val);
3446 qlcnic_gb_set_gb2_mask(gb_val);
3447 qlcnic_gb_set_gb3_mask(gb_val);
3448 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3449 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3450 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003451 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003452
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003453 if (qlcnic_api_lock(adapter))
3454 return;
3455
Sony Chacko13159182013-01-01 03:20:21 +00003456 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05003457
3458 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
3459 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n",
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003460 __func__);
3461 qlcnic_api_unlock(adapter);
3462
3463 return;
3464 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003465
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003466 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003467 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3468 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003469 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003470 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003471 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003472 }
3473
Sony Chacko13159182013-01-01 03:20:21 +00003474 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3475 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003476 qlcnic_api_unlock(adapter);
3477}
3478
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003479/* Transit to NPAR READY state from NPAR NOT READY state */
3480static void
3481qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3482{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003483 if (qlcnic_api_lock(adapter))
3484 return;
3485
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003486 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3487 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003488 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003489
3490 qlcnic_api_unlock(adapter);
3491}
3492
Sony Chacko13159182013-01-01 03:20:21 +00003493void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3494 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003495{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003496 if (test_bit(__QLCNIC_AER, &adapter->state))
3497 return;
3498
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003499 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003500 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3501 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003502}
3503
3504static void
3505qlcnic_attach_work(struct work_struct *work)
3506{
3507 struct qlcnic_adapter *adapter = container_of(work,
3508 struct qlcnic_adapter, fw_work.work);
3509 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003510 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003511
Sony Chacko79788452012-12-04 03:33:53 +00003512 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003513 npar_state = QLC_SHARED_REG_RD32(adapter,
3514 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003515 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3516 qlcnic_clr_all_drv_state(adapter, 0);
3517 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3518 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3519 FW_POLL_DELAY);
3520 else
3521 goto attach;
3522 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3523 return;
3524 }
3525attach:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04003526 qlcnic_dcb_get_info(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003527
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003528 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003529 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003530 goto done;
3531
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003532 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003533 }
3534
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003535done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003536 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003537 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003538 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003539 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003540 if (adapter->portnum == 0)
3541 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003542
3543 if (!qlcnic_clr_drv_state(adapter))
3544 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3545 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003546}
3547
3548static int
3549qlcnic_check_health(struct qlcnic_adapter *adapter)
3550{
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003551 struct qlcnic_hardware_context *ahw = adapter->ahw;
3552 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sony Chacko4e708122010-08-31 17:17:44 +00003553 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003554 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003555 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003556
3557 if (qlcnic_check_temp(adapter))
3558 goto detach;
3559
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003560 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003561 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003562
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003563 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003564 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003565 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003566 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003567 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3568 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003569
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003570 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003571 if (heartbeat != adapter->heartbeat) {
3572 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003573 adapter->fw_fail_cnt = 0;
3574 if (adapter->need_fw_reset)
3575 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003576
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003577 if (ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003578 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003579
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003580 return 0;
3581 }
3582
3583 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3584 return 0;
3585
Sritej Velaga032a13c2011-07-29 13:30:27 +00003586 adapter->flags |= QLCNIC_FW_HANG;
3587
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003588 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003589
Sony Chacko099f7aa2012-12-04 03:33:58 +00003590 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003591 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003592
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003593 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003594 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003595 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003596 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3597 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3598 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3599 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003600 peg_status,
3601 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003602 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3603 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3604 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3605 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3606 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003607 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003608 dev_err(&adapter->pdev->dev,
3609 "Firmware aborted with error code 0x00006700. "
3610 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003611detach:
3612 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3613 QLCNIC_DEV_NEED_RESET;
3614
Sony Chacko099f7aa2012-12-04 03:33:58 +00003615 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3616 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003617
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003618 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003619 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003620 } else if (!qlcnic_auto_fw_reset && fw_dump->enable &&
3621 adapter->flags & QLCNIC_FW_RESET_OWNER) {
3622 qlcnic_dump_fw(adapter);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003623 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003624
3625 return 1;
3626}
3627
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003628void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003629{
3630 struct qlcnic_adapter *adapter = container_of(work,
3631 struct qlcnic_adapter, fw_work.work);
3632
3633 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3634 goto reschedule;
3635
3636
3637 if (qlcnic_check_health(adapter))
3638 return;
3639
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003640 if (adapter->fhash.fnum)
3641 qlcnic_prune_lb_filters(adapter);
3642
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003643reschedule:
3644 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3645}
3646
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003647static int qlcnic_is_first_func(struct pci_dev *pdev)
3648{
3649 struct pci_dev *oth_pdev;
3650 int val = pdev->devfn;
3651
3652 while (val-- > 0) {
3653 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3654 (pdev->bus), pdev->bus->number,
3655 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003656 if (!oth_pdev)
3657 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003658
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003659 if (oth_pdev->current_state != PCI_D3cold) {
3660 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003661 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003662 }
3663 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003664 }
3665 return 1;
3666}
3667
3668static int qlcnic_attach_func(struct pci_dev *pdev)
3669{
3670 int err, first_func;
3671 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3672 struct net_device *netdev = adapter->netdev;
3673
3674 pdev->error_state = pci_channel_io_normal;
3675
3676 err = pci_enable_device(pdev);
3677 if (err)
3678 return err;
3679
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003680 pci_set_master(pdev);
3681 pci_restore_state(pdev);
3682
3683 first_func = qlcnic_is_first_func(pdev);
3684
3685 if (qlcnic_api_lock(adapter))
3686 return -EINVAL;
3687
Sony Chacko79788452012-12-04 03:33:53 +00003688 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003689 adapter->need_fw_reset = 1;
3690 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003691 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3692 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003693 QLCDB(adapter, DRV, "Restarting fw\n");
3694 }
3695 qlcnic_api_unlock(adapter);
3696
Sony Chacko13159182013-01-01 03:20:21 +00003697 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003698 if (err)
3699 return err;
3700
3701 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003702 kfree(adapter->msix_entries);
3703 adapter->msix_entries = NULL;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003704 err = qlcnic_setup_intr(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003705
Manish chopra9a97e702013-01-25 10:20:37 +00003706 if (err) {
3707 kfree(adapter->msix_entries);
3708 netdev_err(netdev, "failed to setup interrupt\n");
3709 return err;
3710 }
3711
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003712 if (netif_running(netdev)) {
3713 err = qlcnic_attach(adapter);
3714 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003715 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003716 clear_bit(__QLCNIC_AER, &adapter->state);
3717 netif_device_attach(netdev);
3718 return err;
3719 }
3720
3721 err = qlcnic_up(adapter, netdev);
3722 if (err)
3723 goto done;
3724
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003725 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003726 }
3727 done:
3728 netif_device_attach(netdev);
3729 return err;
3730}
3731
stephen hemminger21041402014-01-16 10:31:27 -08003732static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3733 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003734{
3735 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3736 struct net_device *netdev = adapter->netdev;
3737
3738 if (state == pci_channel_io_perm_failure)
3739 return PCI_ERS_RESULT_DISCONNECT;
3740
3741 if (state == pci_channel_io_normal)
3742 return PCI_ERS_RESULT_RECOVERED;
3743
3744 set_bit(__QLCNIC_AER, &adapter->state);
3745 netif_device_detach(netdev);
3746
3747 cancel_delayed_work_sync(&adapter->fw_work);
3748
3749 if (netif_running(netdev))
3750 qlcnic_down(adapter, netdev);
3751
3752 qlcnic_detach(adapter);
3753 qlcnic_teardown_intr(adapter);
3754
3755 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3756
3757 pci_save_state(pdev);
3758 pci_disable_device(pdev);
3759
3760 return PCI_ERS_RESULT_NEED_RESET;
3761}
3762
stephen hemminger21041402014-01-16 10:31:27 -08003763static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003764{
3765 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3766 PCI_ERS_RESULT_RECOVERED;
3767}
3768
stephen hemminger21041402014-01-16 10:31:27 -08003769static void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003770{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003771 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003772 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3773
3774 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003775 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3776 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3777 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003778 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003779 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003780}
3781
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003782static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3783 pci_channel_state_t state)
3784{
3785 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3786 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3787
3788 if (hw_ops->io_error_detected) {
3789 return hw_ops->io_error_detected(pdev, state);
3790 } else {
3791 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3792 return PCI_ERS_RESULT_DISCONNECT;
3793 }
3794}
3795
3796static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3797{
3798 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3799 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3800
3801 if (hw_ops->io_slot_reset) {
3802 return hw_ops->io_slot_reset(pdev);
3803 } else {
3804 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
3805 return PCI_ERS_RESULT_DISCONNECT;
3806 }
3807}
3808
3809static void qlcnic_io_resume(struct pci_dev *pdev)
3810{
3811 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3812 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3813
3814 if (hw_ops->io_resume)
3815 hw_ops->io_resume(pdev);
3816 else
3817 dev_err(&pdev->dev, "AER resume handler not registered.\n");
3818}
3819
3820
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003821static int
3822qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3823{
3824 int err;
3825
3826 err = qlcnic_can_start_firmware(adapter);
3827 if (err)
3828 return err;
3829
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003830 err = qlcnic_check_npar_opertional(adapter);
3831 if (err)
3832 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003833
Rajesh Borundia174240a2010-08-31 17:17:47 +00003834 err = qlcnic_initialize_nic(adapter);
3835 if (err)
3836 return err;
3837
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003838 qlcnic_check_options(adapter);
3839
Rajesh Borundia73733732010-08-31 17:17:50 +00003840 err = qlcnic_set_eswitch_port_config(adapter);
3841 if (err)
3842 return err;
3843
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003844 adapter->need_fw_reset = 0;
3845
3846 return err;
3847}
3848
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003849int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3850 int queue_type)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003851{
3852 struct net_device *netdev = adapter->netdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003853 u8 max_hw_rings = 0;
3854 char buf[8];
3855 int cur_rings;
3856
3857 if (queue_type == QLCNIC_RX_QUEUE) {
3858 max_hw_rings = adapter->max_sds_rings;
3859 cur_rings = adapter->drv_sds_rings;
3860 strcpy(buf, "SDS");
3861 } else if (queue_type == QLCNIC_TX_QUEUE) {
Himanshu Madhani18afc102013-11-04 13:31:32 -05003862 max_hw_rings = adapter->max_tx_rings;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003863 cur_rings = adapter->drv_tx_rings;
3864 strcpy(buf, "Tx");
3865 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003866
Shahed Shaikhb7520d22014-02-24 08:54:47 -05003867 if (!QLCNIC_IS_MSI_FAMILY(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003868 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003869 return -EINVAL;
3870 }
3871
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003872 if (adapter->flags & QLCNIC_MSI_ENABLED) {
3873 netdev_err(netdev, "No RSS/TSS support in MSI mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003874 return -EINVAL;
3875 }
3876
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003877 if (!is_power_of_2(ring_cnt)) {
3878 netdev_err(netdev, "%s rings value should be a power of 2\n",
3879 buf);
3880 return -EINVAL;
3881 }
3882
3883 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) &&
3884 !qlcnic_check_multi_tx(adapter)) {
3885 netdev_err(netdev, "No Multi Tx queue support\n");
3886 return -EINVAL;
3887 }
3888
3889 if (ring_cnt > num_online_cpus()) {
3890 netdev_err(netdev,
3891 "%s value[%u] should not be higher than, number of online CPUs\n",
3892 buf, num_online_cpus());
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003893 return -EINVAL;
3894 }
3895
3896 return 0;
3897}
3898
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05003899int qlcnic_setup_rings(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003900{
Manish Chopra6389b762013-04-24 12:42:39 +00003901 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +00003902 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003903
Sony Chacko319ecf12013-01-01 03:20:22 +00003904 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3905 return -EBUSY;
3906
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003907 netif_device_detach(netdev);
3908 if (netif_running(netdev))
3909 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003910
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003911 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003912
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003913 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003914 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003915 qlcnic_83xx_enable_mbx_poll(adapter);
3916 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003917
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003918 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003919
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003920 err = qlcnic_setup_intr(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +00003921 if (err) {
3922 kfree(adapter->msix_entries);
3923 netdev_err(netdev, "failed to setup interrupt\n");
3924 return err;
3925 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003926
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05003927 netif_set_real_num_tx_queues(netdev, adapter->drv_tx_rings);
3928
Sony Chacko13159182013-01-01 03:20:21 +00003929 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05003930 qlcnic_83xx_initialize_nic(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003931 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003932 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003933 if (err) {
3934 dev_err(&adapter->pdev->dev,
3935 "failed to setup mbx interrupt\n");
3936 goto done;
3937 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003938 }
3939
3940 if (netif_running(netdev)) {
3941 err = qlcnic_attach(adapter);
3942 if (err)
3943 goto done;
3944 err = __qlcnic_up(adapter, netdev);
3945 if (err)
3946 goto done;
3947 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3948 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003949done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003950 netif_device_attach(netdev);
3951 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3952 return err;
3953}
3954
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003955#ifdef CONFIG_INET
3956
3957#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3958
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003959static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003960qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3961 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003962{
3963 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003964
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003965 indev = in_dev_get(dev);
3966 if (!indev)
3967 return;
3968
3969 for_ifa(indev) {
3970 switch (event) {
3971 case NETDEV_UP:
3972 qlcnic_config_ipaddr(adapter,
3973 ifa->ifa_address, QLCNIC_IP_UP);
3974 break;
3975 case NETDEV_DOWN:
3976 qlcnic_config_ipaddr(adapter,
3977 ifa->ifa_address, QLCNIC_IP_DOWN);
3978 break;
3979 default:
3980 break;
3981 }
3982 } endfor_ifa(indev);
3983
3984 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003985}
3986
Sony Chacko319ecf12013-01-01 03:20:22 +00003987void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003988{
3989 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3990 struct net_device *dev;
3991 u16 vid;
3992
3993 qlcnic_config_indev_addr(adapter, netdev, event);
3994
Jiri Pirko43c00a72013-01-03 22:48:57 +00003995 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003996 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003997 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003998 if (!dev)
3999 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004000 qlcnic_config_indev_addr(adapter, dev, event);
4001 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00004002 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004003}
4004
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004005static int qlcnic_netdev_event(struct notifier_block *this,
4006 unsigned long event, void *ptr)
4007{
4008 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00004009 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004010
4011recheck:
4012 if (dev == NULL)
4013 goto done;
4014
4015 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4016 dev = vlan_dev_real_dev(dev);
4017 goto recheck;
4018 }
4019
4020 if (!is_qlcnic_netdev(dev))
4021 goto done;
4022
4023 adapter = netdev_priv(dev);
4024
4025 if (!adapter)
4026 goto done;
4027
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004028 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004029 goto done;
4030
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004031 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004032done:
4033 return NOTIFY_DONE;
4034}
4035
4036static int
4037qlcnic_inetaddr_event(struct notifier_block *this,
4038 unsigned long event, void *ptr)
4039{
4040 struct qlcnic_adapter *adapter;
4041 struct net_device *dev;
4042
4043 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4044
4045 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4046
4047recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004048 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004049 goto done;
4050
4051 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4052 dev = vlan_dev_real_dev(dev);
4053 goto recheck;
4054 }
4055
4056 if (!is_qlcnic_netdev(dev))
4057 goto done;
4058
4059 adapter = netdev_priv(dev);
4060
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00004061 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004062 goto done;
4063
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004064 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004065 goto done;
4066
4067 switch (event) {
4068 case NETDEV_UP:
4069 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00004070
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004071 break;
4072 case NETDEV_DOWN:
4073 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00004074
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004075 break;
4076 default:
4077 break;
4078 }
4079
4080done:
4081 return NOTIFY_DONE;
4082}
4083
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004084static struct notifier_block qlcnic_netdev_cb = {
4085 .notifier_call = qlcnic_netdev_event,
4086};
4087
4088static struct notifier_block qlcnic_inetaddr_cb = {
4089 .notifier_call = qlcnic_inetaddr_event,
4090};
4091#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00004092void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004093{ }
4094#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00004095static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004096 .error_detected = qlcnic_io_error_detected,
4097 .slot_reset = qlcnic_io_slot_reset,
4098 .resume = qlcnic_io_resume,
4099};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004100
4101static struct pci_driver qlcnic_driver = {
4102 .name = qlcnic_driver_name,
4103 .id_table = qlcnic_pci_tbl,
4104 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05004105 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004106#ifdef CONFIG_PM
4107 .suspend = qlcnic_suspend,
4108 .resume = qlcnic_resume,
4109#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004110 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00004111 .err_handler = &qlcnic_err_handler,
4112#ifdef CONFIG_QLCNIC_SRIOV
4113 .sriov_configure = qlcnic_pci_sriov_configure,
4114#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004115
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004116};
4117
4118static int __init qlcnic_init_module(void)
4119{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004120 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004121
4122 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4123
4124#ifdef CONFIG_INET
4125 register_netdevice_notifier(&qlcnic_netdev_cb);
4126 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4127#endif
4128
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004129 ret = pci_register_driver(&qlcnic_driver);
4130 if (ret) {
4131#ifdef CONFIG_INET
4132 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4133 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4134#endif
4135 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004136
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004137 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004138}
4139
4140module_init(qlcnic_init_module);
4141
4142static void __exit qlcnic_exit_module(void)
4143{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004144 pci_unregister_driver(&qlcnic_driver);
4145
4146#ifdef CONFIG_INET
4147 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4148 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4149#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004150}
4151
4152module_exit(qlcnic_exit_module);