blob: 1f79d47c45fa3c9ec9b747958c71428cd0850ce5 [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);
819
820 err = qlcnic_enable_msi_legacy(adapter);
821 if (!err)
822 return err;
823 }
Himanshu Madhani012ec812013-08-21 11:24:10 -0400824 }
825
826 return 0;
827}
828
829int qlcnic_82xx_mq_intrpt(struct qlcnic_adapter *adapter, int op_type)
830{
831 struct qlcnic_hardware_context *ahw = adapter->ahw;
832 int err, i;
833
834 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400835 !ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -0400836 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
837 ahw->intr_tbl = vzalloc(ahw->num_msix *
838 sizeof(struct qlcnic_intrpt_config));
839 if (!ahw->intr_tbl)
840 return -ENOMEM;
841
842 for (i = 0; i < ahw->num_msix; i++) {
843 ahw->intr_tbl[i].type = QLCNIC_INTRPT_MSIX;
844 ahw->intr_tbl[i].id = i;
845 ahw->intr_tbl[i].src = 0;
846 }
847
848 err = qlcnic_82xx_config_intrpt(adapter, 1);
849 if (err)
850 dev_err(&adapter->pdev->dev,
851 "Failed to configure Interrupt for %d vector\n",
852 ahw->num_msix);
853 return err;
854 }
855
856 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000857}
Sony Chacko13159182013-01-01 03:20:21 +0000858
Sony Chacko319ecf12013-01-01 03:20:22 +0000859void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000860{
861 if (adapter->flags & QLCNIC_MSIX_ENABLED)
862 pci_disable_msix(adapter->pdev);
863 if (adapter->flags & QLCNIC_MSI_ENABLED)
864 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000865
866 kfree(adapter->msix_entries);
867 adapter->msix_entries = NULL;
868
869 if (adapter->ahw->intr_tbl) {
870 vfree(adapter->ahw->intr_tbl);
871 adapter->ahw->intr_tbl = NULL;
872 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000873}
874
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000875static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000876{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000877 if (ahw->pci_base0 != NULL)
878 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000879}
880
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000881static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
882{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500883 struct qlcnic_hardware_context *ahw = adapter->ahw;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000884 struct qlcnic_pci_info *pci_info;
885 int ret;
886
887 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500888 switch (ahw->port_type) {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000889 case QLCNIC_GBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500890 ahw->total_nic_func = QLCNIC_NIU_MAX_GBE_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000891 break;
892 case QLCNIC_XGBE:
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500893 ahw->total_nic_func = QLCNIC_NIU_MAX_XG_PORTS;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000894 break;
895 }
896 return 0;
897 }
898
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500899 if (ahw->op_mode == QLCNIC_MGMT_FUNC)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000900 return 0;
901
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500902 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000903 if (!pci_info)
904 return -ENOMEM;
905
906 ret = qlcnic_get_pci_info(adapter, pci_info);
907 kfree(pci_info);
908 return ret;
909}
Sony Chackod71170f2013-01-01 03:20:26 +0000910
Sony Chacko35dafcb2013-08-30 13:51:23 -0400911static bool qlcnic_port_eswitch_cfg_capability(struct qlcnic_adapter *adapter)
912{
913 bool ret = false;
914
915 if (qlcnic_84xx_check(adapter)) {
916 ret = true;
917 } else if (qlcnic_83xx_check(adapter)) {
918 if (adapter->ahw->extra_capability[0] &
919 QLCNIC_FW_CAPABILITY_2_PER_PORT_ESWITCH_CFG)
920 ret = true;
921 else
922 ret = false;
923 }
924
925 return ret;
926}
927
Sony Chackod71170f2013-01-01 03:20:26 +0000928int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000929{
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500930 struct qlcnic_hardware_context *ahw = adapter->ahw;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000931 struct qlcnic_pci_info *pci_info;
Sony Chacko4c776aa2013-10-18 12:22:32 -0400932 int i, id = 0, ret = 0, j = 0;
Sony Chackobff57d82012-12-04 03:33:56 +0000933 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000934 u8 pfn;
935
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500936 pci_info = kcalloc(ahw->max_vnic_func, sizeof(*pci_info), GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000937 if (!pci_info)
938 return -ENOMEM;
939
Sony Chackobff57d82012-12-04 03:33:56 +0000940 ret = qlcnic_get_pci_info(adapter, pci_info);
941 if (ret)
942 goto err_pci_info;
943
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500944 act_pci_func = ahw->total_nic_func;
Sony Chackobff57d82012-12-04 03:33:56 +0000945
Dan Carpenterca315ac2010-08-09 21:47:56 +0000946 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000947 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000948 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000949 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000950 goto err_pci_info;
951 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000952
Dan Carpenterca315ac2010-08-09 21:47:56 +0000953 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000954 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
955 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000956 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000957 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000958 }
959
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500960 for (i = 0; i < ahw->max_vnic_func; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000961 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000962
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -0500963 if (pfn >= ahw->max_vnic_func) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000964 ret = QL_STATUS_INVALID_PARAM;
965 goto err_eswitch;
966 }
Sony Chackobff57d82012-12-04 03:33:56 +0000967
968 if (!pci_info[i].active ||
969 (pci_info[i].type != QLCNIC_TYPE_NIC))
970 continue;
971
Sony Chacko35dafcb2013-08-30 13:51:23 -0400972 if (qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko4c776aa2013-10-18 12:22:32 -0400973 if (!qlcnic_83xx_set_port_eswitch_status(adapter, pfn,
974 &id))
Sony Chacko35dafcb2013-08-30 13:51:23 -0400975 adapter->npars[j].eswitch_status = true;
976 else
977 continue;
978 } else {
979 adapter->npars[j].eswitch_status = true;
980 }
981
Sony Chackobff57d82012-12-04 03:33:56 +0000982 adapter->npars[j].pci_func = pfn;
983 adapter->npars[j].active = (u8)pci_info[i].active;
984 adapter->npars[j].type = (u8)pci_info[i].type;
985 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
986 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
987 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
Sony Chacko35dafcb2013-08-30 13:51:23 -0400988
Sucheta Chakraborty9e630952013-10-18 12:22:28 -0400989 memcpy(&adapter->npars[j].mac, &pci_info[i].mac, ETH_ALEN);
Sony Chackobff57d82012-12-04 03:33:56 +0000990 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000991 }
992
Sony Chacko4c776aa2013-10-18 12:22:32 -0400993 /* Update eSwitch status for adapters without per port eSwitch
994 * configuration capability
995 */
996 if (!qlcnic_port_eswitch_cfg_capability(adapter)) {
Sony Chacko35dafcb2013-08-30 13:51:23 -0400997 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
998 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000999 }
Dan Carpenterca315ac2010-08-09 21:47:56 +00001000
Dan Carpentere88db3b2010-08-09 21:49:36 +00001001 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001002 return 0;
1003
1004err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001005 kfree(adapter->eswitch);
1006 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +00001007err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001008 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +00001009 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +00001010err_pci_info:
1011 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00001012
1013 return ret;
1014}
1015
1016static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001017qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
1018{
1019 u8 id;
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001020 int ret;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001021 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +00001022 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001023
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001024 ret = qlcnic_api_lock(adapter);
1025 if (ret)
1026 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001027
Shahed Shaikh7e8fd002013-05-23 21:04:28 +00001028 id = ahw->pci_func;
1029 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
1030 data = (data & ~QLC_DEV_SET_DRV(0xf, id)) |
1031 QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, id);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001032 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001033 qlcnic_api_unlock(adapter);
1034err_lock:
1035 return ret;
1036}
1037
Sony Chacko13159182013-01-01 03:20:21 +00001038static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
1039 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001040{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001041 u32 op_mode, priv_level;
1042
1043 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +00001044 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
1045 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001046
1047 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +00001048 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001049
1050 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +00001051 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001052 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001053 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +00001054 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001055 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001056
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001057 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001058 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001059 dev_info(&adapter->pdev->dev,
1060 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001061 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001062 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001063 } else
1064 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001065}
1066
Sony Chacko15087c22012-12-04 03:33:54 +00001067#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +00001068#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +00001069static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001070{
Sony Chacko15087c22012-12-04 03:33:54 +00001071 switch (dev_id) {
1072 case PCI_DEVICE_ID_QLOGIC_QLE824X:
1073 *bar = QLCNIC_82XX_BAR0_LENGTH;
1074 break;
Sony Chacko13159182013-01-01 03:20:21 +00001075 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001076 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001077 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04001078 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00001079 *bar = QLCNIC_83XX_BAR0_LENGTH;
1080 break;
Sony Chacko15087c22012-12-04 03:33:54 +00001081 default:
1082 *bar = 0;
1083 }
1084}
1085
1086static int qlcnic_setup_pci_map(struct pci_dev *pdev,
1087 struct qlcnic_hardware_context *ahw)
1088{
1089 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001090 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +00001091 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001092
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001093 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001094 mem_len = pci_resource_len(pdev, 0);
1095
Sony Chacko15087c22012-12-04 03:33:54 +00001096 qlcnic_get_bar_length(pdev->device, &bar0_len);
1097 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001098
1099 mem_ptr0 = pci_ioremap_bar(pdev, 0);
1100 if (mem_ptr0 == NULL) {
1101 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
1102 return -EIO;
1103 }
1104 pci_len0 = mem_len;
1105 } else {
1106 return -EIO;
1107 }
1108
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001109 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001110
Sony Chacko15087c22012-12-04 03:33:54 +00001111 ahw->pci_base0 = mem_ptr0;
1112 ahw->pci_len0 = pci_len0;
1113 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
1114 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001115
1116 return 0;
1117}
1118
Manish Chopra60dcbcb2013-08-30 13:51:17 -04001119static bool qlcnic_validate_subsystem_id(struct qlcnic_adapter *adapter,
1120 int index)
Manish Chopra2343f062013-05-23 21:04:34 +00001121{
1122 struct pci_dev *pdev = adapter->pdev;
1123 unsigned short subsystem_vendor;
1124 bool ret = true;
1125
1126 subsystem_vendor = pdev->subsystem_vendor;
1127
1128 if (pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X ||
1129 pdev->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1130 if (qlcnic_boards[index].sub_vendor == subsystem_vendor &&
1131 qlcnic_boards[index].sub_device == pdev->subsystem_device)
1132 ret = true;
1133 else
1134 ret = false;
1135 }
1136
1137 return ret;
1138}
1139
Sony Chacko22999792012-12-04 03:33:55 +00001140static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001141{
1142 struct pci_dev *pdev = adapter->pdev;
1143 int i, found = 0;
1144
1145 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
1146 if (qlcnic_boards[i].vendor == pdev->vendor &&
Manish Chopra2343f062013-05-23 21:04:34 +00001147 qlcnic_boards[i].device == pdev->device &&
1148 qlcnic_validate_subsystem_id(adapter, i)) {
1149 found = 1;
1150 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001151 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001152 }
1153
1154 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +00001155 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Manish Chopra2343f062013-05-23 21:04:34 +00001156 else
1157 sprintf(name, "%pM: %s" , adapter->mac_addr,
1158 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001159}
1160
1161static void
1162qlcnic_check_options(struct qlcnic_adapter *adapter)
1163{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001164 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001165 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001166 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001167 struct qlcnic_hardware_context *ahw = adapter->ahw;
1168 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +00001169
1170 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001171
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001172 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
1173 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
1174 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001175
1176 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
1177
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001178 err = qlcnic_get_board_info(adapter);
1179 if (err) {
1180 dev_err(&pdev->dev, "Error getting board config info.\n");
1181 return;
1182 }
1183 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +00001184 if (fw_dump->tmpl_hdr == NULL ||
1185 adapter->fw_version > prev_fw_version) {
1186 if (fw_dump->tmpl_hdr)
1187 vfree(fw_dump->tmpl_hdr);
1188 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
1189 dev_info(&pdev->dev,
1190 "Supports FW dump capability\n");
1191 }
1192 }
1193
Sony Chacko13159182013-01-01 03:20:21 +00001194 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
1195 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
1196
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001197 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +00001198 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
1199 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
1200 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
1201 } else {
1202 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
1203 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
1204 }
1205
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001206 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +00001207 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
1208
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001209 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001210 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
1211 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +00001212 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
1213 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001214 }
1215
Sony Chacko099f7aa2012-12-04 03:33:58 +00001216 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001217
1218 adapter->num_txd = MAX_CMD_DESCRIPTORS;
1219
Sony Chacko251b0362010-08-19 05:08:24 +00001220 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001221}
1222
Rajesh Borundia174240a2010-08-31 17:17:47 +00001223static int
1224qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1225{
Rajesh Borundia174240a2010-08-31 17:17:47 +00001226 struct qlcnic_info nic_info;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001227 int err = 0;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001228
Sony Chackobff57d82012-12-04 03:33:56 +00001229 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001230 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001231 if (err)
1232 return err;
1233
Sony Chacko79788452012-12-04 03:33:53 +00001234 adapter->ahw->physical_port = (u8)nic_info.phys_port;
1235 adapter->ahw->switch_mode = nic_info.switch_mode;
1236 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
1237 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
1238 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001239
1240 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1241 u32 temp;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04001242 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2, &err);
1243 if (err == -EIO)
1244 return err;
Pratik Pujardb131782013-06-22 04:12:04 -04001245 adapter->ahw->extra_capability[0] = temp;
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001246 } else {
1247 adapter->ahw->extra_capability[0] = 0;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001248 }
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04001249
Sony Chacko79788452012-12-04 03:33:53 +00001250 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1251 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001252
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001253 if (adapter->ahw->capabilities & BIT_6) {
Rajesh Borundia174240a2010-08-31 17:17:47 +00001254 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001255 adapter->ahw->nic_mode = QLCNIC_VNIC_MODE;
1256 adapter->max_tx_rings = QLCNIC_MAX_HW_VNIC_TX_RINGS;
1257 adapter->max_sds_rings = QLCNIC_MAX_VNIC_SDS_RINGS;
1258
1259 dev_info(&adapter->pdev->dev, "vNIC mode enabled.\n");
1260 } else {
1261 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
1262 adapter->max_tx_rings = QLCNIC_MAX_HW_TX_RINGS;
Himanshu Madhanif9566262013-12-16 15:36:58 -05001263 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001264 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001265 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001266
1267 return err;
1268}
1269
Sony Chackoec079a02012-11-28 04:34:28 +00001270void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
1271 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001272{
1273 if (esw_cfg->discard_tagged)
1274 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
1275 else
1276 adapter->flags |= QLCNIC_TAGGING_ENABLED;
1277
Rajesh Borundia91b72822013-04-19 07:01:12 +00001278 if (esw_cfg->vlan_id) {
1279 adapter->rx_pvid = esw_cfg->vlan_id;
1280 adapter->tx_pvid = esw_cfg->vlan_id;
1281 } else {
1282 adapter->rx_pvid = 0;
1283 adapter->tx_pvid = 0;
1284 }
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001285}
1286
Jiri Pirko8e586132011-12-08 19:52:37 -05001287static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001288qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001289{
1290 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001291 int err;
1292
1293 if (qlcnic_sriov_vf_check(adapter)) {
1294 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 1);
1295 if (err) {
1296 netdev_err(netdev,
1297 "Cannot add VLAN filter for VLAN id %d, err=%d",
1298 vid, err);
1299 return err;
1300 }
1301 }
1302
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001303 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001304 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001305}
1306
Jiri Pirko8e586132011-12-08 19:52:37 -05001307static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00001308qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001309{
1310 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Rajesh Borundia91b72822013-04-19 07:01:12 +00001311 int err;
1312
1313 if (qlcnic_sriov_vf_check(adapter)) {
1314 err = qlcnic_sriov_cfg_vf_guest_vlan(adapter, vid, 0);
1315 if (err) {
1316 netdev_err(netdev,
1317 "Cannot delete VLAN filter for VLAN id %d, err=%d",
1318 vid, err);
1319 return err;
1320 }
1321 }
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001322
1323 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
1324 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05001325 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00001326}
1327
Sony Chackoec079a02012-11-28 04:34:28 +00001328void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
1329 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001330{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001331 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
1332 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +00001333
1334 if (esw_cfg->mac_anti_spoof)
1335 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +00001336
Rajesh Borundia73733732010-08-31 17:17:50 +00001337 if (!esw_cfg->mac_override)
1338 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
1339
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001340 if (!esw_cfg->promisc_mode)
1341 adapter->flags |= QLCNIC_PROMISC_DISABLED;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001342}
1343
Sony Chackod71170f2013-01-01 03:20:26 +00001344int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001345{
1346 struct qlcnic_esw_func_cfg esw_cfg;
1347
1348 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1349 return 0;
1350
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001351 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001352 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
1353 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001354 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001355 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
Shahed Shaikh147a9082013-05-21 09:27:01 +00001356 qlcnic_set_netdev_features(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +00001357
1358 return 0;
1359}
1360
Shahed Shaikh147a9082013-05-21 09:27:01 +00001361void qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
1362 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001363{
1364 struct net_device *netdev = adapter->netdev;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001365
Sony Chacko13159182013-01-01 03:20:21 +00001366 if (qlcnic_83xx_check(adapter))
1367 return;
1368
Shahed Shaikh147a9082013-05-21 09:27:01 +00001369 adapter->offload_flags = esw_cfg->offload_flags;
1370 adapter->flags |= QLCNIC_APP_CHANGED_FLAGS;
1371 netdev_update_features(netdev);
1372 adapter->flags &= ~QLCNIC_APP_CHANGED_FLAGS;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001373}
1374
1375static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001376qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1377{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001378 u32 op_mode, priv_level;
1379 int err = 0;
1380
Rajesh Borundia174240a2010-08-31 17:17:47 +00001381 err = qlcnic_initialize_nic(adapter);
1382 if (err)
1383 return err;
1384
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001385 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1386 return 0;
1387
Sony Chacko13159182013-01-01 03:20:21 +00001388 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001389 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001390
1391 if (op_mode == QLC_DEV_DRV_DEFAULT)
1392 priv_level = QLCNIC_MGMT_FUNC;
1393 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001394 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001395
Rajesh Borundia174240a2010-08-31 17:17:47 +00001396 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001397 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001398 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001399 err = qlcnic_init_pci_info(adapter);
1400 if (err)
1401 return err;
1402 /* Set privilege level for other functions */
1403 qlcnic_set_function_modes(adapter);
1404 dev_info(&adapter->pdev->dev,
1405 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001406 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001407 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001408 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001409 dev_info(&adapter->pdev->dev,
1410 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001411 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001412 }
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001413 } else {
1414 adapter->ahw->nic_mode = QLCNIC_DEFAULT_MODE;
Rajesh Borundia174240a2010-08-31 17:17:47 +00001415 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001416
1417 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1418
1419 return err;
1420}
1421
Sony Chackod71170f2013-01-01 03:20:26 +00001422int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001423{
1424 struct qlcnic_esw_func_cfg esw_cfg;
1425 struct qlcnic_npar_info *npar;
1426 u8 i;
1427
Rajesh Borundia174240a2010-08-31 17:17:47 +00001428 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001429 return 0;
1430
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001431 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Sony Chacko35dafcb2013-08-30 13:51:23 -04001432 if (!adapter->npars[i].eswitch_status)
1433 continue;
1434
Rajesh Borundia0325d692010-08-19 05:08:26 +00001435 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001436 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001437 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001438 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001439 if (qlcnic_82xx_check(adapter)) {
1440 esw_cfg.offload_flags = BIT_0;
1441 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1442 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1443 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001444 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1445 return -EIO;
1446 npar = &adapter->npars[i];
1447 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001448 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001449 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1450 npar->discard_tagged = esw_cfg.discard_tagged;
1451 npar->promisc_mode = esw_cfg.promisc_mode;
1452 npar->offload_flags = esw_cfg.offload_flags;
1453 }
1454
1455 return 0;
1456}
1457
Sony Chacko13159182013-01-01 03:20:21 +00001458
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001459static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001460qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1461 struct qlcnic_npar_info *npar, int pci_func)
1462{
1463 struct qlcnic_esw_func_cfg esw_cfg;
1464 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1465 esw_cfg.pci_func = pci_func;
1466 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001467 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001468 esw_cfg.discard_tagged = npar->discard_tagged;
1469 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1470 esw_cfg.offload_flags = npar->offload_flags;
1471 esw_cfg.promisc_mode = npar->promisc_mode;
1472 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1473 return -EIO;
1474
1475 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1476 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1477 return -EIO;
1478
1479 return 0;
1480}
1481
Sony Chackod71170f2013-01-01 03:20:26 +00001482int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001483{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001484 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001485 struct qlcnic_npar_info *npar;
1486 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001487 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001488
Sony Chackobff57d82012-12-04 03:33:56 +00001489 if (qlcnic_82xx_check(adapter))
1490 if (!adapter->need_fw_reset)
1491 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001492
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001493 /* Set the NPAR config data after FW reset */
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05001494 for (i = 0; i < adapter->ahw->total_nic_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001495 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001496 pci_func = npar->pci_func;
Sony Chacko35dafcb2013-08-30 13:51:23 -04001497 if (!adapter->npars[i].eswitch_status)
1498 continue;
1499
Sony Chackobff57d82012-12-04 03:33:56 +00001500 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001501 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001502 if (err)
1503 return err;
1504 nic_info.min_tx_bw = npar->min_bw;
1505 nic_info.max_tx_bw = npar->max_bw;
1506 err = qlcnic_set_nic_info(adapter, &nic_info);
1507 if (err)
1508 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001509
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001510 if (npar->enable_pm) {
1511 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001512 npar->dest_npar, 1,
1513 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001514 if (err)
1515 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001516 }
Sony Chackobff57d82012-12-04 03:33:56 +00001517 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001518 if (err)
1519 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001520 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001521 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001522}
1523
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001524static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1525{
1526 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1527 u32 npar_state;
1528
Sony Chacko79788452012-12-04 03:33:53 +00001529 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001530 return 0;
1531
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001532 npar_state = QLC_SHARED_REG_RD32(adapter,
1533 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001534 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1535 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001536 npar_state = QLC_SHARED_REG_RD32(adapter,
1537 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001538 }
1539 if (!npar_opt_timeo) {
1540 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001541 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001542 return -EIO;
1543 }
1544 return 0;
1545}
1546
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001547static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001548qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1549{
1550 int err;
1551
1552 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001553 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001554 return 0;
1555
1556 err = qlcnic_set_default_offload_settings(adapter);
1557 if (err)
1558 return err;
1559
1560 err = qlcnic_reset_npar_config(adapter);
1561 if (err)
1562 return err;
1563
1564 qlcnic_dev_set_npar_ready(adapter);
1565
1566 return err;
1567}
1568
stephen hemminger21041402014-01-16 10:31:27 -08001569static int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001570{
Sony Chackod4066832010-08-19 05:08:31 +00001571 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001572
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001573 err = qlcnic_can_start_firmware(adapter);
1574 if (err < 0)
1575 return err;
1576 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001577 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001578
Sony Chacko099f7aa2012-12-04 03:33:58 +00001579 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001580 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001581 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001582 err = qlcnic_check_flash_fw_ver(adapter);
1583 if (err)
schacko8f891382010-06-17 02:56:40 +00001584 goto err_out;
1585
Sony Chacko79788452012-12-04 03:33:53 +00001586 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001587 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001588
1589 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001590 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001591 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001592
Sony Chackod4066832010-08-19 05:08:31 +00001593 err = qlcnic_pinit_from_rom(adapter);
1594 if (err)
1595 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001596
1597 err = qlcnic_load_firmware(adapter);
1598 if (err)
1599 goto err_out;
1600
1601 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001602 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001603
Sony Chackod4066832010-08-19 05:08:31 +00001604check_fw_status:
1605 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001606 if (err)
1607 goto err_out;
1608
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001609 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001610 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001611 err = qlcnic_check_eswitch_mode(adapter);
1612 if (err) {
1613 dev_err(&adapter->pdev->dev,
1614 "Memory allocation failed for eswitch\n");
1615 goto err_out;
1616 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001617 err = qlcnic_set_mgmt_operations(adapter);
1618 if (err)
1619 goto err_out;
1620
1621 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001622 adapter->need_fw_reset = 0;
1623
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001624 qlcnic_release_firmware(adapter);
1625 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001626
1627err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001628 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001629 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001630
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001631 qlcnic_release_firmware(adapter);
1632 return err;
1633}
1634
1635static int
1636qlcnic_request_irq(struct qlcnic_adapter *adapter)
1637{
1638 irq_handler_t handler;
1639 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001640 struct qlcnic_host_tx_ring *tx_ring;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001641 int err, ring, num_sds_rings;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001642
1643 unsigned long flags = 0;
1644 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001645 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001646
Sony Chacko79788452012-12-04 03:33:53 +00001647 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001648 if (qlcnic_82xx_check(adapter))
1649 handler = qlcnic_tmp_intr;
Manish Choprac2534382013-07-26 16:24:03 -04001650 else
1651 handler = qlcnic_83xx_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001652 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1653 flags |= IRQF_SHARED;
1654
1655 } else {
1656 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1657 handler = qlcnic_msix_intr;
1658 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1659 handler = qlcnic_msi_intr;
1660 else {
1661 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001662 if (qlcnic_82xx_check(adapter))
1663 handler = qlcnic_intr;
1664 else
1665 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001666 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001667 }
1668 adapter->irq = netdev->irq;
1669
Sony Chacko13159182013-01-01 03:20:21 +00001670 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001671 if (qlcnic_82xx_check(adapter) ||
1672 (qlcnic_83xx_check(adapter) &&
1673 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001674 num_sds_rings = adapter->drv_sds_rings;
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001675 for (ring = 0; ring < num_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001676 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001677 if (qlcnic_82xx_check(adapter) &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001678 !qlcnic_check_multi_tx(adapter) &&
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001679 (ring == (num_sds_rings - 1))) {
1680 if (!(adapter->flags &
1681 QLCNIC_MSIX_ENABLED))
1682 snprintf(sds_ring->name,
1683 sizeof(sds_ring->name),
1684 "qlcnic");
1685 else
1686 snprintf(sds_ring->name,
1687 sizeof(sds_ring->name),
1688 "%s-tx-0-rx-%d",
1689 netdev->name, ring);
1690 } else {
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001691 snprintf(sds_ring->name,
1692 sizeof(sds_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001693 "%s-rx-%d",
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001694 netdev->name, ring);
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001695 }
Himanshu Madhaniac166702013-02-18 12:06:15 +00001696 err = request_irq(sds_ring->irq, handler, flags,
1697 sds_ring->name, sds_ring);
1698 if (err)
1699 return err;
1700 }
Sony Chacko13159182013-01-01 03:20:21 +00001701 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001702 if ((qlcnic_82xx_check(adapter) &&
1703 qlcnic_check_multi_tx(adapter)) ||
1704 (qlcnic_83xx_check(adapter) &&
1705 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1706 !(adapter->flags & QLCNIC_TX_INTR_SHARED))) {
Sony Chacko13159182013-01-01 03:20:21 +00001707 handler = qlcnic_msix_tx_intr;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001708 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001709 ring++) {
1710 tx_ring = &adapter->tx_ring[ring];
Himanshu Madhaniddb2e172013-04-24 12:42:43 +00001711 snprintf(tx_ring->name, sizeof(tx_ring->name),
Himanshu Madhaniaa2a8032013-05-23 21:04:27 +00001712 "%s-tx-%d", netdev->name, ring);
Sony Chacko13159182013-01-01 03:20:21 +00001713 err = request_irq(tx_ring->irq, handler, flags,
1714 tx_ring->name, tx_ring);
1715 if (err)
1716 return err;
1717 }
1718 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001719 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001720 return 0;
1721}
1722
1723static void
1724qlcnic_free_irq(struct qlcnic_adapter *adapter)
1725{
1726 int ring;
1727 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001728 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001729
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001730 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001731
Sony Chacko13159182013-01-01 03:20:21 +00001732 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001733 if (qlcnic_82xx_check(adapter) ||
1734 (qlcnic_83xx_check(adapter) &&
1735 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001736 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001737 sds_ring = &recv_ctx->sds_rings[ring];
1738 free_irq(sds_ring->irq, sds_ring);
1739 }
Sony Chacko13159182013-01-01 03:20:21 +00001740 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001741 if ((qlcnic_83xx_check(adapter) &&
1742 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
1743 (qlcnic_82xx_check(adapter) &&
1744 qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001745 for (ring = 0; ring < adapter->drv_tx_rings;
Sony Chacko13159182013-01-01 03:20:21 +00001746 ring++) {
1747 tx_ring = &adapter->tx_ring[ring];
1748 if (tx_ring->irq)
1749 free_irq(tx_ring->irq, tx_ring);
1750 }
1751 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001752 }
1753}
1754
Shahed Shaikh99e85872013-02-18 12:06:16 +00001755static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1756{
1757 u32 capab = 0;
1758
1759 if (qlcnic_82xx_check(adapter)) {
Pratik Pujardb131782013-06-22 04:12:04 -04001760 if (adapter->ahw->extra_capability[0] &
Shahed Shaikh99e85872013-02-18 12:06:16 +00001761 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1762 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1763 } else {
1764 capab = adapter->ahw->capabilities;
1765 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1766 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1767 }
1768}
1769
Himanshu Madhania5147222014-01-23 17:18:32 -05001770static int qlcnic_config_def_intr_coalesce(struct qlcnic_adapter *adapter)
1771{
1772 struct qlcnic_hardware_context *ahw = adapter->ahw;
1773 int err;
1774
1775 /* Initialize interrupt coalesce parameters */
1776 ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1777
1778 if (qlcnic_83xx_check(adapter)) {
1779 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX_TX;
1780 ahw->coal.tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1781 ahw->coal.tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1782 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1783 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1784
1785 err = qlcnic_83xx_set_rx_tx_intr_coal(adapter);
1786 } else {
1787 ahw->coal.type = QLCNIC_INTR_COAL_TYPE_RX;
1788 ahw->coal.rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1789 ahw->coal.rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1790
1791 err = qlcnic_82xx_set_rx_coalesce(adapter);
1792 }
1793
1794 return err;
1795}
1796
Sony Chacko319ecf12013-01-01 03:20:22 +00001797int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001798{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001799 int ring;
1800 struct qlcnic_host_rds_ring *rds_ring;
1801
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001802 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1803 return -EIO;
1804
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001805 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1806 return 0;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001807
Rajesh Borundia0325d692010-08-19 05:08:26 +00001808 if (qlcnic_set_eswitch_port_config(adapter))
1809 return -EIO;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001810
Shahed Shaikh99e85872013-02-18 12:06:16 +00001811 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001812
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001813 if (qlcnic_fw_create_ctx(adapter))
1814 return -EIO;
1815
1816 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001817 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001818 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001819 }
1820
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001821 qlcnic_set_multi(netdev);
1822 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1823
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001824 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001825
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001826 if (adapter->drv_sds_rings > 1)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001827 qlcnic_config_rss(adapter, 1);
1828
Himanshu Madhania5147222014-01-23 17:18:32 -05001829 qlcnic_config_def_intr_coalesce(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001830
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001831 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001832 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1833
Pratik Pujarcfacb172013-07-19 16:56:27 -04001834 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001835 qlcnic_napi_enable(adapter);
1836
1837 qlcnic_linkevent_request(adapter, 1);
1838
Sony Chacko79788452012-12-04 03:33:53 +00001839 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001840 return 0;
1841}
1842
Sony Chacko629263a2013-01-01 04:11:55 +00001843int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001844{
1845 int err = 0;
1846
1847 rtnl_lock();
1848 if (netif_running(netdev))
1849 err = __qlcnic_up(adapter, netdev);
1850 rtnl_unlock();
1851
1852 return err;
1853}
1854
Sony Chacko319ecf12013-01-01 03:20:22 +00001855void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001856{
Himanshu Madhani012ec812013-08-21 11:24:10 -04001857 int ring;
1858
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001859 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1860 return;
1861
1862 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1863 return;
1864
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001865 if (qlcnic_sriov_vf_check(adapter))
1866 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001867 smp_mb();
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001868 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001869 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001870 netif_tx_disable(netdev);
1871
1872 qlcnic_free_mac_list(adapter);
1873
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001874 if (adapter->fhash.fnum)
1875 qlcnic_delete_lb_filters(adapter);
1876
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001877 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1878
1879 qlcnic_napi_disable(adapter);
1880
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001881 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001882 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001883
1884 qlcnic_reset_rx_buffers_list(adapter);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001885
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001886 for (ring = 0; ring < adapter->drv_tx_rings; ring++)
Himanshu Madhani012ec812013-08-21 11:24:10 -04001887 qlcnic_release_tx_buffers(adapter, &adapter->tx_ring[ring]);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001888}
1889
1890/* Usage: During suspend and firmware recovery module */
1891
Sony Chacko629263a2013-01-01 04:11:55 +00001892void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001893{
1894 rtnl_lock();
1895 if (netif_running(netdev))
1896 __qlcnic_down(adapter, netdev);
1897 rtnl_unlock();
1898
1899}
1900
Sony Chacko319ecf12013-01-01 03:20:22 +00001901int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001902qlcnic_attach(struct qlcnic_adapter *adapter)
1903{
1904 struct net_device *netdev = adapter->netdev;
1905 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001906 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001907
1908 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1909 return 0;
1910
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001911 err = qlcnic_napi_add(adapter, netdev);
1912 if (err)
1913 return err;
1914
1915 err = qlcnic_alloc_sw_resources(adapter);
1916 if (err) {
1917 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001918 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001919 }
1920
1921 err = qlcnic_alloc_hw_resources(adapter);
1922 if (err) {
1923 dev_err(&pdev->dev, "Error in setting hw resources\n");
1924 goto err_out_free_sw;
1925 }
1926
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001927 err = qlcnic_request_irq(adapter);
1928 if (err) {
1929 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001930 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001931 }
1932
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001933 qlcnic_create_sysfs_entries(adapter);
1934
1935 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1936 return 0;
1937
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001938err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001939 qlcnic_free_hw_resources(adapter);
1940err_out_free_sw:
1941 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001942err_out_napi_del:
1943 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001944 return err;
1945}
1946
Sony Chacko319ecf12013-01-01 03:20:22 +00001947void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001948{
1949 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1950 return;
1951
1952 qlcnic_remove_sysfs_entries(adapter);
1953
1954 qlcnic_free_hw_resources(adapter);
1955 qlcnic_release_rx_buffers(adapter);
1956 qlcnic_free_irq(adapter);
1957 qlcnic_napi_del(adapter);
1958 qlcnic_free_sw_resources(adapter);
1959
1960 adapter->is_up = 0;
1961}
1962
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001963void qlcnic_diag_free_res(struct net_device *netdev, int drv_sds_rings)
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001964{
1965 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1966 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001967 int drv_tx_rings = adapter->drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001968 int ring;
1969
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001970 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001971 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001972 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001973 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001974 qlcnic_disable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001975 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001976 }
1977
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001978 qlcnic_fw_destroy_ctx(adapter);
1979
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001980 qlcnic_detach(adapter);
1981
Sony Chacko79788452012-12-04 03:33:53 +00001982 adapter->ahw->diag_test = 0;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001983 adapter->drv_sds_rings = drv_sds_rings;
1984 adapter->drv_tx_rings = drv_tx_rings;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001985
1986 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001987 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001988
1989 if (netif_running(netdev))
1990 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001991out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001992 netif_device_attach(netdev);
1993}
1994
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001995static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1996{
1997 int err = 0;
Himanshu Madhanibe273dc2013-04-24 12:42:42 +00001998
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001999 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
2000 GFP_KERNEL);
2001 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002002 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00002003 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002004 }
Himanshu Madhania5147222014-01-23 17:18:32 -05002005
Sony Chacko4be41e92013-01-01 03:20:20 +00002006 /* clear stats */
2007 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002008err_out:
2009 return err;
2010}
2011
2012static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
2013{
2014 kfree(adapter->recv_ctx);
2015 adapter->recv_ctx = NULL;
2016
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002017 if (adapter->ahw->fw_dump.tmpl_hdr) {
2018 vfree(adapter->ahw->fw_dump.tmpl_hdr);
2019 adapter->ahw->fw_dump.tmpl_hdr = NULL;
2020 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002021
Sony Chacko81d0aeb2013-01-01 03:20:25 +00002022 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00002023 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002024}
2025
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002026int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
2027{
2028 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2029 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002030 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002031 int ring;
2032 int ret;
2033
2034 netif_device_detach(netdev);
2035
2036 if (netif_running(netdev))
2037 __qlcnic_down(adapter, netdev);
2038
2039 qlcnic_detach(adapter);
2040
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002041 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
Sony Chacko79788452012-12-04 03:33:53 +00002042 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00002043 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002044
2045 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002046 if (ret) {
2047 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002048 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002049 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002050
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002051 ret = qlcnic_fw_create_ctx(adapter);
2052 if (ret) {
2053 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00002054 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002055 return ret;
2056 }
2057
2058 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002059 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00002060 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002061 }
2062
Sony Chacko79788452012-12-04 03:33:53 +00002063 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002064 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002065 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002066 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002067 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002068 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002069
Sony Chacko79788452012-12-04 03:33:53 +00002070 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00002071 adapter->ahw->loopback_state = 0;
2072 qlcnic_linkevent_request(adapter, 1);
2073 }
2074
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00002075 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002076
2077 return 0;
2078}
2079
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002080/* Reset context in hardware only */
2081static int
2082qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
2083{
2084 struct net_device *netdev = adapter->netdev;
2085
2086 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2087 return -EBUSY;
2088
2089 netif_device_detach(netdev);
2090
2091 qlcnic_down(adapter, netdev);
2092
2093 qlcnic_up(adapter, netdev);
2094
2095 netif_device_attach(netdev);
2096
2097 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani95b38902014-01-23 17:18:29 -05002098 netdev_info(adapter->netdev, "%s: soft reset complete\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002099 return 0;
2100}
2101
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002102int
2103qlcnic_reset_context(struct qlcnic_adapter *adapter)
2104{
2105 int err = 0;
2106 struct net_device *netdev = adapter->netdev;
2107
2108 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2109 return -EBUSY;
2110
2111 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
2112
2113 netif_device_detach(netdev);
2114
2115 if (netif_running(netdev))
2116 __qlcnic_down(adapter, netdev);
2117
2118 qlcnic_detach(adapter);
2119
2120 if (netif_running(netdev)) {
2121 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002122 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002123 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00002124 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2125 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002126 }
2127
2128 netif_device_attach(netdev);
2129 }
2130
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002131 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2132 return err;
2133}
2134
stephen hemminger21041402014-01-16 10:31:27 -08002135static void qlcnic_82xx_set_mac_filter_count(struct qlcnic_adapter *adapter)
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002136{
2137 struct qlcnic_hardware_context *ahw = adapter->ahw;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002138 u16 act_pci_fn = ahw->total_nic_func;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002139 u16 count;
2140
2141 ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
2142 if (act_pci_fn <= 2)
2143 count = (QLCNIC_MAX_UC_COUNT - QLCNIC_MAX_MC_COUNT) /
2144 act_pci_fn;
2145 else
2146 count = (QLCNIC_LB_MAX_FILTERS - QLCNIC_MAX_MC_COUNT) /
2147 act_pci_fn;
2148 ahw->max_uc_count = count;
2149}
2150
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002151int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002152qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
2153 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002154{
2155 int err;
2156 struct pci_dev *pdev = adapter->pdev;
2157
Sony Chacko13159182013-01-01 03:20:21 +00002158 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00002159 adapter->ahw->mc_enabled = 0;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002160 qlcnic_set_mac_filter_count(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002161
2162 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00002163 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002164
2165 qlcnic_change_mtu(netdev, netdev->mtu);
2166
Rajesh Borundiad1a11052013-04-19 07:01:13 +00002167 if (qlcnic_sriov_vf_check(adapter))
2168 SET_ETHTOOL_OPS(netdev, &qlcnic_sriov_vf_ethtool_ops);
2169 else
2170 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002171
Sony Chacko7e38d042013-01-01 03:20:28 +00002172 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00002173 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00002174 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00002175 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
2176 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00002177
Sony Chacko13159182013-01-01 03:20:21 +00002178 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
2179 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
2180 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
2181 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002182
Sony Chacko13159182013-01-01 03:20:21 +00002183 if (pci_using_dac) {
2184 netdev->features |= NETIF_F_HIGHDMA;
2185 netdev->vlan_features |= NETIF_F_HIGHDMA;
2186 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002187
Sony Chacko13159182013-01-01 03:20:21 +00002188 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00002189 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00002190
Rajesh Borundia91b72822013-04-19 07:01:12 +00002191 if (qlcnic_sriov_vf_check(adapter))
2192 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
2193
Sony Chacko79788452012-12-04 03:33:53 +00002194 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00002195 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00002196
Sony Chacko7e38d042013-01-01 03:20:28 +00002197 netdev->hw_features = netdev->features;
Jitendra Kalsaria52e493d2013-06-22 04:12:01 -04002198 netdev->priv_flags |= IFF_UNICAST_FLT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002199 netdev->irq = adapter->msix_entries[0].vector;
2200
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04002201 err = qlcnic_set_real_num_queues(adapter, netdev);
2202 if (err)
2203 return err;
Himanshu Madhani012ec812013-08-21 11:24:10 -04002204
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002205 err = register_netdev(netdev);
2206 if (err) {
2207 dev_err(&pdev->dev, "failed to register net device\n");
2208 return err;
2209 }
2210
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04002211 qlcnic_dcb_init_dcbnl_ops(adapter->dcb);
Sucheta Chakraborty48365e42013-08-23 13:38:28 -04002212
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002213 return 0;
2214}
2215
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002216static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002217{
2218 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
2219 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
2220 *pci_using_dac = 1;
2221 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
2222 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2223 *pci_using_dac = 0;
2224 else {
2225 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
2226 return -EIO;
2227 }
2228
2229 return 0;
2230}
2231
Sony Chacko4be41e92013-01-01 03:20:20 +00002232void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
2233{
2234 int ring;
2235 struct qlcnic_host_tx_ring *tx_ring;
2236
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002237 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002238 tx_ring = &adapter->tx_ring[ring];
2239 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
2240 vfree(tx_ring->cmd_buf_arr);
2241 tx_ring->cmd_buf_arr = NULL;
2242 }
2243 }
2244 if (adapter->tx_ring != NULL)
2245 kfree(adapter->tx_ring);
2246}
2247
2248int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
2249 struct net_device *netdev)
2250{
Joe Perchesb2adaca2013-02-03 17:43:58 +00002251 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00002252 struct qlcnic_host_tx_ring *tx_ring;
2253 struct qlcnic_cmd_buffer *cmd_buf_arr;
2254
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002255 tx_ring = kcalloc(adapter->drv_tx_rings,
Joe Perchesb2adaca2013-02-03 17:43:58 +00002256 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
2257 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00002258 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00002259
Sony Chacko4be41e92013-01-01 03:20:20 +00002260 adapter->tx_ring = tx_ring;
2261
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002262 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002263 tx_ring = &adapter->tx_ring[ring];
2264 tx_ring->num_desc = adapter->num_txd;
2265 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
2266 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
2267 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002268 qlcnic_free_tx_rings(adapter);
2269 return -ENOMEM;
2270 }
2271 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
2272 tx_ring->cmd_buf_arr = cmd_buf_arr;
Shahed Shaikha02bdd42014-01-03 01:34:28 -05002273 spin_lock_init(&tx_ring->tx_clean_lock);
Sony Chacko4be41e92013-01-01 03:20:20 +00002274 }
2275
Himanshu Madhani012ec812013-08-21 11:24:10 -04002276 if (qlcnic_83xx_check(adapter) ||
2277 (qlcnic_82xx_check(adapter) && qlcnic_check_multi_tx(adapter))) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002278 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002279 tx_ring = &adapter->tx_ring[ring];
2280 tx_ring->adapter = adapter;
2281 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002282 index = adapter->drv_sds_rings + ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002283 vector = adapter->msix_entries[index].vector;
2284 tx_ring->irq = vector;
2285 }
2286 }
2287 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04002288
Sony Chacko4be41e92013-01-01 03:20:20 +00002289 return 0;
2290}
2291
Pratik Pujar8af3f332013-06-22 04:12:05 -04002292void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2293{
2294 struct qlcnic_hardware_context *ahw = adapter->ahw;
2295 u32 fw_cmd = 0;
2296
2297 if (qlcnic_82xx_check(adapter))
2298 fw_cmd = QLCNIC_CMD_82XX_SET_DRV_VER;
2299 else if (qlcnic_83xx_check(adapter))
2300 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2301
Shahed Shaikhd6994ca2013-10-25 10:38:37 -04002302 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
Pratik Pujar8af3f332013-06-22 04:12:05 -04002303 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2304}
2305
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002306static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002307qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2308{
2309 struct net_device *netdev = NULL;
2310 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002311 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00002312 int err, pci_using_dac = -1;
Dan Carpenter7bc48642013-01-30 22:14:10 +00002313 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002314
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002315 if (pdev->is_virtfn)
2316 return -ENODEV;
2317
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002318 err = pci_enable_device(pdev);
2319 if (err)
2320 return err;
2321
2322 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2323 err = -ENODEV;
2324 goto err_out_disable_pdev;
2325 }
2326
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002327 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
2328 if (err)
2329 goto err_out_disable_pdev;
2330
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002331 err = pci_request_regions(pdev, qlcnic_driver_name);
2332 if (err)
2333 goto err_out_disable_pdev;
2334
2335 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002336 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002337
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002338 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
Sony Chacko02135582013-05-21 09:26:59 +00002339 if (!ahw) {
2340 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002341 goto err_out_free_res;
Sony Chacko02135582013-05-21 09:26:59 +00002342 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002343
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002344 switch (ent->device) {
2345 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002346 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002347 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
2348 break;
2349 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002350 case PCI_DEVICE_ID_QLOGIC_QLE844X:
Sony Chacko13159182013-01-01 03:20:21 +00002351 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002352 break;
2353 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Manish Chopra15ca1402013-08-16 19:07:13 -04002354 case PCI_DEVICE_ID_QLOGIC_VF_QLE844X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002355 qlcnic_sriov_vf_register_map(ahw);
2356 break;
2357 default:
Sony Chacko13159182013-01-01 03:20:21 +00002358 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002359 }
2360
2361 err = qlcnic_setup_pci_map(pdev, ahw);
2362 if (err)
2363 goto err_out_free_hw_res;
2364
Himanshu Madhani012ec812013-08-21 11:24:10 -04002365 netdev = alloc_etherdev_mq(sizeof(struct qlcnic_adapter),
2366 QLCNIC_MAX_TX_RINGS);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002367 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002368 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002369 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002370 }
2371
2372 SET_NETDEV_DEV(netdev, &pdev->dev);
2373
2374 adapter = netdev_priv(netdev);
2375 adapter->netdev = netdev;
2376 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00002377 adapter->ahw = ahw;
2378
2379 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
2380 if (adapter->qlcnic_wq == NULL) {
Sony Chacko02135582013-05-21 09:26:59 +00002381 err = -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +00002382 dev_err(&pdev->dev, "Failed to create workqueue\n");
2383 goto err_out_free_netdev;
2384 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002385
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00002386 err = qlcnic_alloc_adapter_resources(adapter);
2387 if (err)
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002388 goto err_out_free_wq;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002389
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002390 adapter->dev_rst_time = jiffies;
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002391 ahw->revision_id = pdev->revision;
2392 ahw->max_vnic_func = qlcnic_get_vnic_func_count(adapter);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002393 if (qlcnic_mac_learn == FDB_MAC_LEARN)
2394 adapter->fdb_mac_learn = true;
2395 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
2396 adapter->drv_mac_learn = true;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002397
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002398 rwlock_init(&adapter->ahw->crb_lock);
2399 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002400
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002401 INIT_LIST_HEAD(&adapter->mac_list);
2402
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002403 qlcnic_register_dcb(adapter);
2404
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002405 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002406 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002407 adapter->portnum = adapter->ahw->pci_func;
2408 err = qlcnic_start_firmware(adapter);
2409 if (err) {
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002410 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n"
2411 "\t\tIf reboot doesn't help, try flashing the card\n");
2412 goto err_out_maintenance_mode;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002413 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002414
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002415 /* compute and set default and max tx/sds rings */
2416 if (adapter->ahw->msix_supported) {
2417 if (qlcnic_check_multi_tx_capability(adapter) == 1)
2418 qlcnic_set_tx_ring_count(adapter,
2419 QLCNIC_SINGLE_RING);
2420 else
2421 qlcnic_set_tx_ring_count(adapter,
2422 QLCNIC_DEF_TX_RINGS);
2423 qlcnic_set_sds_ring_count(adapter,
2424 QLCNIC_DEF_SDS_RINGS);
2425 } else {
2426 qlcnic_set_tx_ring_count(adapter, QLCNIC_SINGLE_RING);
2427 qlcnic_set_sds_ring_count(adapter, QLCNIC_SINGLE_RING);
Himanshu Madhani012ec812013-08-21 11:24:10 -04002428 }
2429
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002430 err = qlcnic_setup_idc_param(adapter);
2431 if (err)
2432 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002433
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002434 adapter->flags |= QLCNIC_NEED_FLR;
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002435
Sony Chacko13159182013-01-01 03:20:21 +00002436 } else if (qlcnic_83xx_check(adapter)) {
2437 qlcnic_83xx_check_vf(adapter, ent);
2438 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002439 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00002440 if (err) {
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002441 switch (err) {
2442 case -ENOTRECOVERABLE:
2443 dev_err(&pdev->dev, "Adapter initialization failed due to a faulty hardware. Please reboot\n");
2444 dev_err(&pdev->dev, "If reboot doesn't help, please replace the adapter with new one and return the faulty adapter for repair\n");
2445 goto err_out_free_hw;
2446 case -ENOMEM:
2447 dev_err(&pdev->dev, "Adapter initialization failed. Please reboot\n");
2448 goto err_out_free_hw;
2449 default:
2450 dev_err(&pdev->dev, "Adapter initialization failed. A reboot may be required to recover from this failure\n");
2451 dev_err(&pdev->dev, "If reboot does not help to recover from this failure, try a flash update of the adapter\n");
2452 goto err_out_maintenance_mode;
2453 }
Sony Chacko629263a2013-01-01 04:11:55 +00002454 }
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002455
Rajesh Borundiaf8468332013-03-29 05:46:34 +00002456 if (qlcnic_sriov_vf_check(adapter))
2457 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00002458 } else {
2459 dev_err(&pdev->dev,
2460 "%s: failed. Please Reboot\n", __func__);
2461 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002462 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002463
Sucheta Chakraborty3c44bba2013-12-17 09:01:49 -05002464 qlcnic_dcb_enable(adapter->dcb);
2465
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002466 if (qlcnic_read_mac_addr(adapter))
2467 dev_warn(&pdev->dev, "failed to read mac addr\n");
2468
Shahed Shaikh07a251c2013-08-21 11:24:13 -04002469 qlcnic_read_phys_port_id(adapter);
2470
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002471 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00002472 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00002473
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002474 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00002475 module_name(THIS_MODULE),
2476 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00002477 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00002478
2479 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
2480 !!qlcnic_use_msi)
2481 dev_warn(&pdev->dev,
Pratik Pujar01b91f42013-08-02 23:15:57 -04002482 "Device does not support MSI interrupts\n");
Himanshu Madhani460374f2013-03-22 05:57:54 +00002483
Manish Chopra068a8d12013-08-02 00:57:41 -04002484 if (qlcnic_82xx_check(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002485 err = qlcnic_setup_intr(adapter);
Manish Chopra068a8d12013-08-02 00:57:41 -04002486 if (err) {
2487 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko13159182013-01-01 03:20:21 +00002488 goto err_out_disable_msi;
Manish Chopra068a8d12013-08-02 00:57:41 -04002489 }
Sony Chacko13159182013-01-01 03:20:21 +00002490 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002491
Sony Chacko02135582013-05-21 09:26:59 +00002492 err = qlcnic_get_act_pci_func(adapter);
2493 if (err)
2494 goto err_out_disable_mbx_intr;
2495
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07002496 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002497 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002498 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002499
Himanshu Madhani24866d12013-08-15 08:29:27 -04002500 if (adapter->portnum == 0)
2501 qlcnic_set_drv_version(adapter);
Sritej Velagac84e3402013-01-25 10:20:34 +00002502
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002503 pci_set_drvdata(pdev, adapter);
2504
Sony Chacko97ee45e2012-12-04 03:33:52 +00002505 if (qlcnic_82xx_check(adapter))
2506 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2507 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002508
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002509 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002510 case QLCNIC_GBE:
2511 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
2512 adapter->netdev->name);
2513 break;
2514 case QLCNIC_XGBE:
2515 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2516 adapter->netdev->name);
2517 break;
2518 }
2519
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002520 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002521 qlcnic_alloc_lb_filters_mem(adapter);
2522
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002523 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002524
2525 return 0;
2526
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002527err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002528 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002529 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002530
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002531err_out_disable_msi:
2532 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002533 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002534 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002535
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002536err_out_free_hw:
2537 qlcnic_free_adapter_resources(adapter);
2538
Wei Yongjun2b1f18a2013-10-08 11:32:17 +08002539err_out_free_wq:
2540 destroy_workqueue(adapter->qlcnic_wq);
2541
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002542err_out_free_netdev:
2543 free_netdev(netdev);
2544
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002545err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002546 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002547
2548err_out_free_hw_res:
2549 kfree(ahw);
2550
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002551err_out_free_res:
2552 pci_release_regions(pdev);
2553
2554err_out_disable_pdev:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002555 pci_disable_device(pdev);
2556 return err;
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002557
2558err_out_maintenance_mode:
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002559 set_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002560 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
2561 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002562 ahw->port_type = QLCNIC_XGBE;
2563
2564 if (qlcnic_83xx_check(adapter))
2565 adapter->tgt_status_reg = NULL;
2566 else
2567 ahw->board_type = QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS;
2568
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002569 err = register_netdev(netdev);
2570
2571 if (err) {
2572 dev_err(&pdev->dev, "Failed to register net device\n");
2573 qlcnic_clr_all_drv_state(adapter, 0);
2574 goto err_out_free_hw;
2575 }
2576
2577 pci_set_drvdata(pdev, adapter);
2578 qlcnic_add_sysfs(adapter);
2579
2580 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002581}
2582
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002583static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002584{
2585 struct qlcnic_adapter *adapter;
2586 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002587 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002588
2589 adapter = pci_get_drvdata(pdev);
2590 if (adapter == NULL)
2591 return;
2592
2593 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002594 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002595
Sony Chacko13159182013-01-01 03:20:21 +00002596 qlcnic_cancel_idc_work(adapter);
2597 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002598
2599 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002600 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002601
Sony Chacko13159182013-01-01 03:20:21 +00002602 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05002603 qlcnic_83xx_initialize_nic(adapter, 0);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002604 cancel_delayed_work_sync(&adapter->idc_aen_work);
Manish Chopra068a8d12013-08-02 00:57:41 -04002605 qlcnic_83xx_free_mbx_intr(adapter);
2606 qlcnic_83xx_detach_mailbox_work(adapter);
2607 qlcnic_83xx_free_mailbox(ahw->mailbox);
Pratik Pujar70000782013-08-30 13:51:22 -04002608 kfree(ahw->fw_info);
Sony Chacko13159182013-01-01 03:20:21 +00002609 }
2610
Sucheta Chakraborty3720bf72013-12-17 09:01:50 -05002611 qlcnic_dcb_free(adapter->dcb);
2612
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002613 qlcnic_detach(adapter);
2614
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002615 if (adapter->npars != NULL)
2616 kfree(adapter->npars);
2617 if (adapter->eswitch != NULL)
2618 kfree(adapter->eswitch);
2619
Sony Chacko97ee45e2012-12-04 03:33:52 +00002620 if (qlcnic_82xx_check(adapter))
2621 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002622
2623 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2624
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002625 qlcnic_free_lb_filters_mem(adapter);
2626
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002627 qlcnic_teardown_intr(adapter);
2628
Sony Chacko13159182013-01-01 03:20:21 +00002629 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002630
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002631 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002632
2633 qlcnic_release_firmware(adapter);
2634
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002635 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002636 pci_release_regions(pdev);
2637 pci_disable_device(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002638
Sony Chacko13159182013-01-01 03:20:21 +00002639 if (adapter->qlcnic_wq) {
2640 destroy_workqueue(adapter->qlcnic_wq);
2641 adapter->qlcnic_wq = NULL;
2642 }
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04002643
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002644 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002645 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002646 free_netdev(netdev);
2647}
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002648
2649static void qlcnic_shutdown(struct pci_dev *pdev)
2650{
2651 if (__qlcnic_shutdown(pdev))
2652 return;
2653
2654 pci_disable_device(pdev);
2655}
2656
2657#ifdef CONFIG_PM
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002658static int qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002659{
2660 int retval;
2661
2662 retval = __qlcnic_shutdown(pdev);
2663 if (retval)
2664 return retval;
2665
2666 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2667 return 0;
2668}
2669
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002670static int qlcnic_resume(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002671{
2672 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002673 int err;
2674
2675 err = pci_enable_device(pdev);
2676 if (err)
2677 return err;
2678
2679 pci_set_power_state(pdev, PCI_D0);
2680 pci_set_master(pdev);
2681 pci_restore_state(pdev);
2682
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04002683 return __qlcnic_resume(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002684}
2685#endif
2686
2687static int qlcnic_open(struct net_device *netdev)
2688{
2689 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2690 int err;
2691
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05002692 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
2693 netdev_err(netdev, "%s: Device is in non-operational state\n",
2694 __func__);
Sucheta Chakraborty66451612013-09-27 02:12:36 -04002695
2696 return -EIO;
2697 }
2698
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002699 netif_carrier_off(netdev);
2700
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002701 err = qlcnic_attach(adapter);
2702 if (err)
2703 return err;
2704
2705 err = __qlcnic_up(adapter, netdev);
2706 if (err)
2707 goto err_out;
2708
Himanshu Madhani012ec812013-08-21 11:24:10 -04002709 netif_tx_start_all_queues(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002710
2711 return 0;
2712
2713err_out:
2714 qlcnic_detach(adapter);
2715 return err;
2716}
2717
2718/*
2719 * qlcnic_close - Disables a network interface entry point
2720 */
2721static int qlcnic_close(struct net_device *netdev)
2722{
2723 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2724
2725 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002726
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002727 return 0;
2728}
2729
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002730void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002731{
2732 void *head;
2733 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002734 struct net_device *netdev = adapter->netdev;
2735 u32 filter_size = 0;
2736 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002737
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002738 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002739 return;
2740
Jitendra Kalsaria2f514c52013-12-17 09:01:54 -05002741 act_pci_func = adapter->ahw->total_nic_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002742 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002743 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002744
Sony Chacko13159182013-01-01 03:20:21 +00002745 if (qlcnic_82xx_check(adapter)) {
2746 filter_size = QLCNIC_LB_MAX_FILTERS;
2747 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2748 } else {
2749 filter_size = QLC_83XX_LB_MAX_FILTERS;
2750 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2751 }
2752
2753 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002754 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002755
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002756 if (!head)
2757 return;
2758
Sony Chacko13159182013-01-01 03:20:21 +00002759 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002760 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002761
Sony Chacko13159182013-01-01 03:20:21 +00002762 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2763 act_pci_func, adapter->fhash.fmax);
2764
2765 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002766 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002767
2768 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2769
2770 head = kcalloc(adapter->rx_fhash.fbucket_size,
2771 sizeof(struct hlist_head), GFP_ATOMIC);
2772
2773 if (!head)
2774 return;
2775
2776 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2777 adapter->rx_fhash.fhead = head;
2778
2779 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2780 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002781}
2782
2783static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2784{
2785 if (adapter->fhash.fmax && adapter->fhash.fhead)
2786 kfree(adapter->fhash.fhead);
2787
2788 adapter->fhash.fhead = NULL;
2789 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002790
2791 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2792 kfree(adapter->rx_fhash.fhead);
2793
2794 adapter->rx_fhash.fmax = 0;
2795 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002796}
2797
Sony Chacko629263a2013-01-01 04:11:55 +00002798int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002799{
2800 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002801 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802 int rv = 0;
2803
Sony Chacko13159182013-01-01 03:20:21 +00002804 if (qlcnic_83xx_check(adapter))
2805 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2806
Sony Chacko97ee45e2012-12-04 03:33:52 +00002807 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002808 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002809
2810 temp_state = qlcnic_get_temp_state(temp);
2811 temp_val = qlcnic_get_temp_val(temp);
2812
2813 if (temp_state == QLCNIC_TEMP_PANIC) {
2814 dev_err(&netdev->dev,
2815 "Device temperature %d degrees C exceeds"
2816 " maximum allowed. Hardware has been shut down.\n",
2817 temp_val);
2818 rv = 1;
2819 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002820 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002821 dev_err(&netdev->dev,
2822 "Device temperature %d degrees C "
2823 "exceeds operating range."
2824 " Immediate action needed.\n",
2825 temp_val);
2826 }
2827 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002828 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002829 dev_info(&netdev->dev,
2830 "Device temperature is now %d degrees C"
2831 " in normal range.\n", temp_val);
2832 }
2833 }
Sony Chacko79788452012-12-04 03:33:53 +00002834 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002835 return rv;
2836}
2837
Himanshu Madhani95b38902014-01-23 17:18:29 -05002838static inline void dump_tx_ring_desc(struct qlcnic_host_tx_ring *tx_ring)
2839{
2840 int i;
2841 struct cmd_desc_type0 *tx_desc_info;
2842
2843 for (i = 0; i < tx_ring->num_desc; i++) {
2844 tx_desc_info = &tx_ring->desc_head[i];
2845 pr_info("TX Desc: %d\n", i);
2846 print_hex_dump(KERN_INFO, "TX: ", DUMP_PREFIX_OFFSET, 16, 1,
2847 &tx_ring->desc_head[i],
2848 sizeof(struct cmd_desc_type0), true);
2849 }
2850}
2851
2852static void qlcnic_dump_tx_rings(struct qlcnic_adapter *adapter)
2853{
2854 struct net_device *netdev = adapter->netdev;
2855 struct qlcnic_host_tx_ring *tx_ring;
2856 int ring;
2857
2858 if (!netdev || !netif_running(netdev))
2859 return;
2860
2861 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2862 tx_ring = &adapter->tx_ring[ring];
2863 netdev_info(netdev, "Tx ring=%d Context Id=0x%x\n",
2864 ring, tx_ring->ctx_id);
2865 netdev_info(netdev,
2866 "xmit_finished=%llu, xmit_called=%llu, xmit_on=%llu, xmit_off=%llu\n",
2867 tx_ring->tx_stats.xmit_finished,
2868 tx_ring->tx_stats.xmit_called,
2869 tx_ring->tx_stats.xmit_on,
2870 tx_ring->tx_stats.xmit_off);
2871 netdev_info(netdev,
2872 "crb_intr_mask=%d, hw_producer=%d, sw_producer=%d sw_consumer=%d, hw_consumer=%d\n",
2873 readl(tx_ring->crb_intr_mask),
2874 readl(tx_ring->crb_cmd_producer),
2875 tx_ring->producer, tx_ring->sw_consumer,
2876 le32_to_cpu(*(tx_ring->hw_consumer)));
2877
2878 netdev_info(netdev, "Total desc=%d, Available desc=%d\n",
2879 tx_ring->num_desc, qlcnic_tx_avail(tx_ring));
2880
2881 if (netif_msg_tx_done(adapter->ahw))
2882 dump_tx_ring_desc(tx_ring);
2883 }
2884}
2885
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002886static void qlcnic_tx_timeout(struct net_device *netdev)
2887{
2888 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2889
2890 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2891 return;
2892
Sony Chacko536faa62013-05-09 09:25:13 +00002893 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) {
2894 netdev_info(netdev, "Tx timeout, reset the adapter.\n");
2895 if (qlcnic_82xx_check(adapter))
2896 adapter->need_fw_reset = 1;
2897 else if (qlcnic_83xx_check(adapter))
2898 qlcnic_83xx_idc_request_reset(adapter,
2899 QLCNIC_FORCE_FW_DUMP_KEY);
2900 } else {
2901 netdev_info(netdev, "Tx timeout, reset adapter context.\n");
Himanshu Madhani95b38902014-01-23 17:18:29 -05002902 qlcnic_dump_tx_rings(adapter);
Sony Chacko79788452012-12-04 03:33:53 +00002903 adapter->ahw->reset_context = 1;
Sony Chacko536faa62013-05-09 09:25:13 +00002904 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002905}
2906
2907static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2908{
2909 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2910 struct net_device_stats *stats = &netdev->stats;
2911
Manish Chopra1ac67622014-01-09 12:41:04 -05002912 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2913 qlcnic_update_stats(adapter);
2914
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002915 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2916 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002917 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002918 stats->tx_bytes = adapter->stats.txbytes;
2919 stats->rx_dropped = adapter->stats.rxdropped;
2920 stats->tx_dropped = adapter->stats.txdropped;
2921
2922 return stats;
2923}
2924
stephen hemminger21041402014-01-16 10:31:27 -08002925static irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002926{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002927 u32 status;
2928
2929 status = readl(adapter->isr_int_vec);
2930
Sony Chacko79788452012-12-04 03:33:53 +00002931 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002932 return IRQ_NONE;
2933
2934 /* check interrupt state machine, to be sure */
2935 status = readl(adapter->crb_int_state_reg);
2936 if (!ISR_LEGACY_INT_TRIGGERED(status))
2937 return IRQ_NONE;
2938
2939 writel(0xffffffff, adapter->tgt_status_reg);
2940 /* read twice to ensure write is flushed */
2941 readl(adapter->isr_int_vec);
2942 readl(adapter->isr_int_vec);
2943
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002944 return IRQ_HANDLED;
2945}
2946
2947static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2948{
2949 struct qlcnic_host_sds_ring *sds_ring = data;
2950 struct qlcnic_adapter *adapter = sds_ring->adapter;
2951
2952 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2953 goto done;
2954 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2955 writel(0xffffffff, adapter->tgt_status_reg);
2956 goto done;
2957 }
2958
2959 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2960 return IRQ_NONE;
2961
2962done:
Sony Chacko79788452012-12-04 03:33:53 +00002963 adapter->ahw->diag_cnt++;
Manish chopra2cc57522014-01-23 17:18:30 -05002964 qlcnic_enable_sds_intr(adapter, sds_ring);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002965 return IRQ_HANDLED;
2966}
2967
2968static irqreturn_t qlcnic_intr(int irq, void *data)
2969{
2970 struct qlcnic_host_sds_ring *sds_ring = data;
2971 struct qlcnic_adapter *adapter = sds_ring->adapter;
2972
2973 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2974 return IRQ_NONE;
2975
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002976 napi_schedule(&sds_ring->napi);
2977
2978 return IRQ_HANDLED;
2979}
2980
2981static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2982{
2983 struct qlcnic_host_sds_ring *sds_ring = data;
2984 struct qlcnic_adapter *adapter = sds_ring->adapter;
2985
2986 /* clear interrupt */
2987 writel(0xffffffff, adapter->tgt_status_reg);
2988
2989 napi_schedule(&sds_ring->napi);
2990 return IRQ_HANDLED;
2991}
2992
2993static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2994{
2995 struct qlcnic_host_sds_ring *sds_ring = data;
2996
2997 napi_schedule(&sds_ring->napi);
2998 return IRQ_HANDLED;
2999}
3000
Sony Chacko13159182013-01-01 03:20:21 +00003001static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
3002{
3003 struct qlcnic_host_tx_ring *tx_ring = data;
3004
3005 napi_schedule(&tx_ring->napi);
3006 return IRQ_HANDLED;
3007}
3008
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003009#ifdef CONFIG_NET_POLL_CONTROLLER
3010static void qlcnic_poll_controller(struct net_device *netdev)
3011{
3012 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Manish chopra2b018ad92014-01-23 17:18:31 -05003013 struct qlcnic_host_sds_ring *sds_ring;
3014 struct qlcnic_recv_context *recv_ctx;
3015 struct qlcnic_host_tx_ring *tx_ring;
3016 int ring;
Yinglin Luanbf827912010-08-22 21:57:56 +00003017
Manish chopra2b018ad92014-01-23 17:18:31 -05003018 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3019 return;
3020
3021 recv_ctx = adapter->recv_ctx;
3022
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003023 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Yinglin Luanbf827912010-08-22 21:57:56 +00003024 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2b018ad92014-01-23 17:18:31 -05003025 qlcnic_disable_sds_intr(adapter, sds_ring);
3026 napi_schedule(&sds_ring->napi);
Yinglin Luanbf827912010-08-22 21:57:56 +00003027 }
Manish chopra2b018ad92014-01-23 17:18:31 -05003028
3029 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
3030 /* Only Multi-Tx queue capable devices need to
3031 * schedule NAPI for TX rings
3032 */
3033 if ((qlcnic_83xx_check(adapter) &&
3034 (adapter->flags & QLCNIC_TX_INTR_SHARED)) ||
3035 (qlcnic_82xx_check(adapter) &&
3036 !qlcnic_check_multi_tx(adapter)))
3037 return;
3038
3039 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
3040 tx_ring = &adapter->tx_ring[ring];
3041 qlcnic_disable_tx_intr(adapter, tx_ring);
3042 napi_schedule(&tx_ring->napi);
3043 }
3044 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003045}
3046#endif
3047
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003048static void
3049qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
3050{
3051 u32 val;
3052
3053 val = adapter->portnum & 0xf;
3054 val |= encoding << 7;
3055 val |= (jiffies - adapter->dev_rst_time) << 8;
3056
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003057 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003058 adapter->dev_rst_time = jiffies;
3059}
3060
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003061static int
3062qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003063{
3064 u32 val;
3065
3066 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
3067 state != QLCNIC_DEV_NEED_QUISCENT);
3068
3069 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003070 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003071
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003072 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003073
3074 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003075 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003076 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003077 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003078
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003079 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003080
3081 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00003082
3083 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003084}
3085
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003086static int
3087qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
3088{
3089 u32 val;
3090
3091 if (qlcnic_api_lock(adapter))
3092 return -EBUSY;
3093
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003094 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003095 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003096 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003097
3098 qlcnic_api_unlock(adapter);
3099
3100 return 0;
3101}
3102
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003103void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003104{
3105 u32 val;
3106
3107 if (qlcnic_api_lock(adapter))
3108 goto err;
3109
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003110 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003111 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003112 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003113
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003114 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003115 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3116 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003117 dev_info(&adapter->pdev->dev,
3118 "Device state set to Failed. Please Reboot\n");
3119 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003120 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3121 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003122
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003123 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003124 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003125 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003126
3127 qlcnic_api_unlock(adapter);
3128err:
3129 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003130 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003131 clear_bit(__QLCNIC_START_FW, &adapter->state);
3132 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3133}
3134
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003135/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003136static int
3137qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
3138{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003139 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003140 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003141
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003142 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
3143 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003144
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003145 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003146 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003147 act = act & active_mask;
3148 }
3149
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003150 if (((state & 0x11111111) == (act & 0x11111111)) ||
3151 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
3152 return 0;
3153 else
3154 return 1;
3155}
3156
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003157static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
3158{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003159 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003160
3161 if (val != QLCNIC_DRV_IDC_VER) {
3162 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
3163 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
3164 }
3165
3166 return 0;
3167}
3168
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003169static int
3170qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
3171{
3172 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003173 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003174 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003175 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003176
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003177 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
3178 return 1;
3179
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003180 if (qlcnic_api_lock(adapter))
3181 return -1;
3182
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003183 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003184 if (!(val & (1 << (portnum * 4)))) {
3185 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003186 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003187 }
3188
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003189 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003190 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003191
3192 switch (prev_state) {
3193 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003194 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3195 QLCNIC_DEV_INITIALIZING);
3196 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
3197 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003198 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003199 qlcnic_api_unlock(adapter);
3200 return 1;
3201
3202 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003203 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003204 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003205 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003206
3207 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003208 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003209 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003210 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003211 break;
3212
3213 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003214 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003215 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003216 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003217 break;
3218
3219 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00003220 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003221 qlcnic_api_unlock(adapter);
3222 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00003223
3224 case QLCNIC_DEV_INITIALIZING:
3225 case QLCNIC_DEV_QUISCENT:
3226 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003227 }
3228
3229 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003230
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003231 do {
3232 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003233 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003234
3235 if (prev_state == QLCNIC_DEV_QUISCENT)
3236 continue;
3237 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003238
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003239 if (!dev_init_timeo) {
3240 dev_err(&adapter->pdev->dev,
3241 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003242 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003243 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003244
3245 if (qlcnic_api_lock(adapter))
3246 return -1;
3247
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003248 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00003249 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003250 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003251
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003252 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003253 qlcnic_api_unlock(adapter);
3254
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00003255 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003256}
3257
3258static void
3259qlcnic_fwinit_work(struct work_struct *work)
3260{
3261 struct qlcnic_adapter *adapter = container_of(work,
3262 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003263 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003264 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003265
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003266 if (qlcnic_api_lock(adapter))
3267 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003268
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003269 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003270 if (dev_state == QLCNIC_DEV_QUISCENT ||
3271 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003272 qlcnic_api_unlock(adapter);
3273 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
3274 FW_POLL_DELAY * 2);
3275 return;
3276 }
3277
Sony Chacko79788452012-12-04 03:33:53 +00003278 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003279 qlcnic_api_unlock(adapter);
3280 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003281 }
3282
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003283 if (dev_state == QLCNIC_DEV_INITIALIZING ||
3284 dev_state == QLCNIC_DEV_READY) {
3285 dev_info(&adapter->pdev->dev, "Detected state change from "
3286 "DEV_NEED_RESET, skipping ack check\n");
3287 goto skip_ack_check;
3288 }
3289
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003290 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00003291 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003292 adapter->reset_ack_timeo);
3293 goto skip_ack_check;
3294 }
3295
3296 if (!qlcnic_check_drv_state(adapter)) {
3297skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003298 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00003299
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003300 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003301 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3302 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003303 set_bit(__QLCNIC_START_FW, &adapter->state);
3304 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003305 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003306 val = QLC_SHARED_REG_RD32(adapter,
3307 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003308 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003309 QLC_SHARED_REG_WR32(adapter,
3310 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003311 }
3312
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003313 qlcnic_api_unlock(adapter);
3314
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003315 rtnl_lock();
Shahed Shaikh890b6e02013-08-30 13:51:19 -04003316 if (qlcnic_check_fw_dump_state(adapter) &&
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003317 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003318 QLCDB(adapter, DRV, "Take FW dump\n");
3319 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00003320 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00003321 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00003322 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00003323
3324 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003325 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003326 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003327 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003328 return;
3329 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003330 goto err_ret;
3331 }
3332
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003333 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00003334
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003335wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003336 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003337 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003338
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003339 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003340 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003341 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003342 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003343 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003344 return;
3345 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003346 case QLCNIC_DEV_FAILED:
3347 break;
3348 default:
3349 qlcnic_schedule_work(adapter,
3350 qlcnic_fwinit_work, FW_POLL_DELAY);
3351 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003352 }
3353
3354err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003355 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
3356 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003357 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003358 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003359}
3360
3361static void
3362qlcnic_detach_work(struct work_struct *work)
3363{
3364 struct qlcnic_adapter *adapter = container_of(work,
3365 struct qlcnic_adapter, fw_work.work);
3366 struct net_device *netdev = adapter->netdev;
3367 u32 status;
3368
3369 netif_device_detach(netdev);
3370
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003371 /* Dont grab rtnl lock during Quiscent mode */
3372 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
3373 if (netif_running(netdev))
3374 __qlcnic_down(adapter, netdev);
3375 } else
3376 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003377
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003378 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003379
Sony Chacko44f65b22011-08-29 12:50:26 +00003380 if (status & QLCNIC_RCODE_FATAL_ERROR) {
3381 dev_err(&adapter->pdev->dev,
3382 "Detaching the device: peg halt status1=0x%x\n",
3383 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003384
Sony Chacko44f65b22011-08-29 12:50:26 +00003385 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
3386 dev_err(&adapter->pdev->dev,
3387 "On board active cooling fan failed. "
3388 "Device has been halted.\n");
3389 dev_err(&adapter->pdev->dev,
3390 "Replace the adapter.\n");
3391 }
3392
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003393 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003394 }
3395
Sony Chacko79788452012-12-04 03:33:53 +00003396 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003397 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00003398 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00003399 goto err_ret;
3400 }
3401
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003402 /* Dont ack if this instance is the reset owner */
3403 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00003404 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
3405 dev_err(&adapter->pdev->dev,
3406 "Failed to set driver state,"
3407 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003408 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00003409 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003410 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003411
3412 adapter->fw_wait_cnt = 0;
3413
3414 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3415
3416 return;
3417
3418err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003419 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003420 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003421}
3422
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003423/*Transit NPAR state to NON Operational */
3424static void
3425qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3426{
3427 u32 state;
3428
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003429 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003430 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3431 return;
3432
3433 if (qlcnic_api_lock(adapter))
3434 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003435 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3436 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003437 qlcnic_api_unlock(adapter);
3438}
3439
stephen hemminger21041402014-01-16 10:31:27 -08003440static void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter,
3441 u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003442{
Sritej Velaga646779f2012-02-03 13:45:41 +00003443 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003444
Sritej Velaga646779f2012-02-03 13:45:41 +00003445 qlcnic_xg_set_xg0_mask(xg_val);
3446 qlcnic_xg_set_xg1_mask(xg_val);
3447 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3448 qlcnic_gb_set_gb0_mask(gb_val);
3449 qlcnic_gb_set_gb1_mask(gb_val);
3450 qlcnic_gb_set_gb2_mask(gb_val);
3451 qlcnic_gb_set_gb3_mask(gb_val);
3452 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3453 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3454 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003455 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00003456
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003457 if (qlcnic_api_lock(adapter))
3458 return;
3459
Sony Chacko13159182013-01-01 03:20:21 +00003460 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakraborty78ea2d92013-11-04 13:31:29 -05003461
3462 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state)) {
3463 netdev_err(adapter->netdev, "%s: Device is in non-operational state\n",
Sucheta Chakraborty66451612013-09-27 02:12:36 -04003464 __func__);
3465 qlcnic_api_unlock(adapter);
3466
3467 return;
3468 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003469
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00003470 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00003471 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3472 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00003473 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003474 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00003475 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003476 }
3477
Sony Chacko13159182013-01-01 03:20:21 +00003478 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3479 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003480 qlcnic_api_unlock(adapter);
3481}
3482
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003483/* Transit to NPAR READY state from NPAR NOT READY state */
3484static void
3485qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3486{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003487 if (qlcnic_api_lock(adapter))
3488 return;
3489
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003490 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
3491 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003492 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00003493
3494 qlcnic_api_unlock(adapter);
3495}
3496
Sony Chacko13159182013-01-01 03:20:21 +00003497void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3498 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003499{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003500 if (test_bit(__QLCNIC_AER, &adapter->state))
3501 return;
3502
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003503 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00003504 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
3505 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003506}
3507
3508static void
3509qlcnic_attach_work(struct work_struct *work)
3510{
3511 struct qlcnic_adapter *adapter = container_of(work,
3512 struct qlcnic_adapter, fw_work.work);
3513 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003514 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003515
Sony Chacko79788452012-12-04 03:33:53 +00003516 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003517 npar_state = QLC_SHARED_REG_RD32(adapter,
3518 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00003519 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3520 qlcnic_clr_all_drv_state(adapter, 0);
3521 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3522 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3523 FW_POLL_DELAY);
3524 else
3525 goto attach;
3526 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3527 return;
3528 }
3529attach:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04003530 qlcnic_dcb_get_info(adapter->dcb);
Sucheta Chakraborty14d385b2013-08-23 13:38:25 -04003531
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003532 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00003533 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003534 goto done;
3535
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003536 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003537 }
3538
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003539done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00003540 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003541 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00003542 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003543 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Himanshu Madhani24866d12013-08-15 08:29:27 -04003544 if (adapter->portnum == 0)
3545 qlcnic_set_drv_version(adapter);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003546
3547 if (!qlcnic_clr_drv_state(adapter))
3548 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3549 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003550}
3551
3552static int
3553qlcnic_check_health(struct qlcnic_adapter *adapter)
3554{
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003555 struct qlcnic_hardware_context *ahw = adapter->ahw;
3556 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sony Chacko4e708122010-08-31 17:17:44 +00003557 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003558 u32 peg_status;
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003559 int err = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003560
3561 if (qlcnic_check_temp(adapter))
3562 goto detach;
3563
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003564 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003565 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003566
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003567 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003568 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003569 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003570 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003571 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3572 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003573
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003574 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00003575 if (heartbeat != adapter->heartbeat) {
3576 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003577 adapter->fw_fail_cnt = 0;
3578 if (adapter->need_fw_reset)
3579 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003580
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003581 if (ahw->reset_context && qlcnic_auto_fw_reset)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003582 qlcnic_reset_hw_context(adapter);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003583
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003584 return 0;
3585 }
3586
3587 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3588 return 0;
3589
Sritej Velaga032a13c2011-07-29 13:30:27 +00003590 adapter->flags |= QLCNIC_FW_HANG;
3591
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003592 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003593
Sony Chacko099f7aa2012-12-04 03:33:58 +00003594 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003595 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003596
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003597 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003598 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003599 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003600 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3601 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3602 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3603 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003604 peg_status,
3605 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Himanshu Madhani4bd8e732013-08-02 23:16:01 -04003606 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c, &err),
3607 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c, &err),
3608 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c, &err),
3609 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c, &err),
3610 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c, &err));
Sritej Velaga97048a12012-02-03 13:45:43 +00003611 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003612 dev_err(&adapter->pdev->dev,
3613 "Firmware aborted with error code 0x00006700. "
3614 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003615detach:
3616 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3617 QLCNIC_DEV_NEED_RESET;
3618
Sony Chacko099f7aa2012-12-04 03:33:58 +00003619 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3620 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003621
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003622 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003623 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
Pratik Pujar891e71b1b2013-10-18 12:22:30 -04003624 } else if (!qlcnic_auto_fw_reset && fw_dump->enable &&
3625 adapter->flags & QLCNIC_FW_RESET_OWNER) {
3626 qlcnic_dump_fw(adapter);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003627 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003628
3629 return 1;
3630}
3631
Rajesh Borundia486a5bc2013-06-22 04:12:06 -04003632void qlcnic_fw_poll_work(struct work_struct *work)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003633{
3634 struct qlcnic_adapter *adapter = container_of(work,
3635 struct qlcnic_adapter, fw_work.work);
3636
3637 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3638 goto reschedule;
3639
3640
3641 if (qlcnic_check_health(adapter))
3642 return;
3643
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003644 if (adapter->fhash.fnum)
3645 qlcnic_prune_lb_filters(adapter);
3646
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003647reschedule:
3648 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3649}
3650
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003651static int qlcnic_is_first_func(struct pci_dev *pdev)
3652{
3653 struct pci_dev *oth_pdev;
3654 int val = pdev->devfn;
3655
3656 while (val-- > 0) {
3657 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3658 (pdev->bus), pdev->bus->number,
3659 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003660 if (!oth_pdev)
3661 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003662
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003663 if (oth_pdev->current_state != PCI_D3cold) {
3664 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003665 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003666 }
3667 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003668 }
3669 return 1;
3670}
3671
3672static int qlcnic_attach_func(struct pci_dev *pdev)
3673{
3674 int err, first_func;
3675 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3676 struct net_device *netdev = adapter->netdev;
3677
3678 pdev->error_state = pci_channel_io_normal;
3679
3680 err = pci_enable_device(pdev);
3681 if (err)
3682 return err;
3683
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003684 pci_set_master(pdev);
3685 pci_restore_state(pdev);
3686
3687 first_func = qlcnic_is_first_func(pdev);
3688
3689 if (qlcnic_api_lock(adapter))
3690 return -EINVAL;
3691
Sony Chacko79788452012-12-04 03:33:53 +00003692 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003693 adapter->need_fw_reset = 1;
3694 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003695 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3696 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003697 QLCDB(adapter, DRV, "Restarting fw\n");
3698 }
3699 qlcnic_api_unlock(adapter);
3700
Sony Chacko13159182013-01-01 03:20:21 +00003701 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003702 if (err)
3703 return err;
3704
3705 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003706 kfree(adapter->msix_entries);
3707 adapter->msix_entries = NULL;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003708 err = qlcnic_setup_intr(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003709
Manish chopra9a97e702013-01-25 10:20:37 +00003710 if (err) {
3711 kfree(adapter->msix_entries);
3712 netdev_err(netdev, "failed to setup interrupt\n");
3713 return err;
3714 }
3715
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003716 if (netif_running(netdev)) {
3717 err = qlcnic_attach(adapter);
3718 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003719 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003720 clear_bit(__QLCNIC_AER, &adapter->state);
3721 netif_device_attach(netdev);
3722 return err;
3723 }
3724
3725 err = qlcnic_up(adapter, netdev);
3726 if (err)
3727 goto done;
3728
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003729 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003730 }
3731 done:
3732 netif_device_attach(netdev);
3733 return err;
3734}
3735
stephen hemminger21041402014-01-16 10:31:27 -08003736static pci_ers_result_t qlcnic_82xx_io_error_detected(struct pci_dev *pdev,
3737 pci_channel_state_t state)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003738{
3739 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3740 struct net_device *netdev = adapter->netdev;
3741
3742 if (state == pci_channel_io_perm_failure)
3743 return PCI_ERS_RESULT_DISCONNECT;
3744
3745 if (state == pci_channel_io_normal)
3746 return PCI_ERS_RESULT_RECOVERED;
3747
3748 set_bit(__QLCNIC_AER, &adapter->state);
3749 netif_device_detach(netdev);
3750
3751 cancel_delayed_work_sync(&adapter->fw_work);
3752
3753 if (netif_running(netdev))
3754 qlcnic_down(adapter, netdev);
3755
3756 qlcnic_detach(adapter);
3757 qlcnic_teardown_intr(adapter);
3758
3759 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3760
3761 pci_save_state(pdev);
3762 pci_disable_device(pdev);
3763
3764 return PCI_ERS_RESULT_NEED_RESET;
3765}
3766
stephen hemminger21041402014-01-16 10:31:27 -08003767static pci_ers_result_t qlcnic_82xx_io_slot_reset(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003768{
3769 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3770 PCI_ERS_RESULT_RECOVERED;
3771}
3772
stephen hemminger21041402014-01-16 10:31:27 -08003773static void qlcnic_82xx_io_resume(struct pci_dev *pdev)
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003774{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003775 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003776 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3777
3778 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003779 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3780 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3781 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003782 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003783 FW_POLL_DELAY);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003784}
3785
Pratik Pujar4460f2e2013-08-30 13:51:20 -04003786static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3787 pci_channel_state_t state)
3788{
3789 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3790 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3791
3792 if (hw_ops->io_error_detected) {
3793 return hw_ops->io_error_detected(pdev, state);
3794 } else {
3795 dev_err(&pdev->dev, "AER error_detected handler not registered.\n");
3796 return PCI_ERS_RESULT_DISCONNECT;
3797 }
3798}
3799
3800static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3801{
3802 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3803 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3804
3805 if (hw_ops->io_slot_reset) {
3806 return hw_ops->io_slot_reset(pdev);
3807 } else {
3808 dev_err(&pdev->dev, "AER slot_reset handler not registered.\n");
3809 return PCI_ERS_RESULT_DISCONNECT;
3810 }
3811}
3812
3813static void qlcnic_io_resume(struct pci_dev *pdev)
3814{
3815 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3816 struct qlcnic_hardware_ops *hw_ops = adapter->ahw->hw_ops;
3817
3818 if (hw_ops->io_resume)
3819 hw_ops->io_resume(pdev);
3820 else
3821 dev_err(&pdev->dev, "AER resume handler not registered.\n");
3822}
3823
3824
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003825static int
3826qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3827{
3828 int err;
3829
3830 err = qlcnic_can_start_firmware(adapter);
3831 if (err)
3832 return err;
3833
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003834 err = qlcnic_check_npar_opertional(adapter);
3835 if (err)
3836 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003837
Rajesh Borundia174240a2010-08-31 17:17:47 +00003838 err = qlcnic_initialize_nic(adapter);
3839 if (err)
3840 return err;
3841
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003842 qlcnic_check_options(adapter);
3843
Rajesh Borundia73733732010-08-31 17:17:50 +00003844 err = qlcnic_set_eswitch_port_config(adapter);
3845 if (err)
3846 return err;
3847
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003848 adapter->need_fw_reset = 0;
3849
3850 return err;
3851}
3852
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003853int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3854 int queue_type)
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003855{
3856 struct net_device *netdev = adapter->netdev;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003857 u8 max_hw_rings = 0;
3858 char buf[8];
3859 int cur_rings;
3860
3861 if (queue_type == QLCNIC_RX_QUEUE) {
3862 max_hw_rings = adapter->max_sds_rings;
3863 cur_rings = adapter->drv_sds_rings;
3864 strcpy(buf, "SDS");
3865 } else if (queue_type == QLCNIC_TX_QUEUE) {
Himanshu Madhani18afc102013-11-04 13:31:32 -05003866 max_hw_rings = adapter->max_tx_rings;
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003867 cur_rings = adapter->drv_tx_rings;
3868 strcpy(buf, "Tx");
3869 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003870
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003871 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003872 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003873 return -EINVAL;
3874 }
3875
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003876 if (adapter->flags & QLCNIC_MSI_ENABLED) {
3877 netdev_err(netdev, "No RSS/TSS support in MSI mode\n");
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003878 return -EINVAL;
3879 }
3880
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003881 if (!is_power_of_2(ring_cnt)) {
3882 netdev_err(netdev, "%s rings value should be a power of 2\n",
3883 buf);
3884 return -EINVAL;
3885 }
3886
3887 if (qlcnic_82xx_check(adapter) && (queue_type == QLCNIC_TX_QUEUE) &&
3888 !qlcnic_check_multi_tx(adapter)) {
3889 netdev_err(netdev, "No Multi Tx queue support\n");
3890 return -EINVAL;
3891 }
3892
3893 if (ring_cnt > num_online_cpus()) {
3894 netdev_err(netdev,
3895 "%s value[%u] should not be higher than, number of online CPUs\n",
3896 buf, num_online_cpus());
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003897 return -EINVAL;
3898 }
3899
3900 return 0;
3901}
3902
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05003903int qlcnic_setup_rings(struct qlcnic_adapter *adapter)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003904{
Manish Chopra6389b762013-04-24 12:42:39 +00003905 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +00003906 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003907
Sony Chacko319ecf12013-01-01 03:20:22 +00003908 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3909 return -EBUSY;
3910
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003911 netif_device_detach(netdev);
3912 if (netif_running(netdev))
3913 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003914
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003915 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003916
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003917 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003918 qlcnic_83xx_free_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003919 qlcnic_83xx_enable_mbx_poll(adapter);
3920 }
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003921
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003922 qlcnic_teardown_intr(adapter);
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003923
Himanshu Madhani34e8c402013-11-04 13:31:31 -05003924 err = qlcnic_setup_intr(adapter);
Manish chopra9a97e702013-01-25 10:20:37 +00003925 if (err) {
3926 kfree(adapter->msix_entries);
3927 netdev_err(netdev, "failed to setup interrupt\n");
3928 return err;
3929 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003930
Himanshu Madhanicb9327d2014-01-23 17:18:33 -05003931 netif_set_real_num_tx_queues(netdev, adapter->drv_tx_rings);
3932
Sony Chacko13159182013-01-01 03:20:21 +00003933 if (qlcnic_83xx_check(adapter)) {
Sucheta Chakraborty9b0fff22013-12-17 09:01:51 -05003934 qlcnic_83xx_initialize_nic(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003935 err = qlcnic_83xx_setup_mbx_intr(adapter);
Rajesh Borundia7ed3ce42013-04-19 07:01:14 +00003936 qlcnic_83xx_disable_mbx_poll(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003937 if (err) {
3938 dev_err(&adapter->pdev->dev,
3939 "failed to setup mbx interrupt\n");
3940 goto done;
3941 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003942 }
3943
3944 if (netif_running(netdev)) {
3945 err = qlcnic_attach(adapter);
3946 if (err)
3947 goto done;
3948 err = __qlcnic_up(adapter, netdev);
3949 if (err)
3950 goto done;
3951 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3952 }
Himanshu Madhaniaa4a1f72013-08-21 11:24:11 -04003953done:
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003954 netif_device_attach(netdev);
3955 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3956 return err;
3957}
3958
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003959#ifdef CONFIG_INET
3960
3961#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3962
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003963static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003964qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3965 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003966{
3967 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003968
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003969 indev = in_dev_get(dev);
3970 if (!indev)
3971 return;
3972
3973 for_ifa(indev) {
3974 switch (event) {
3975 case NETDEV_UP:
3976 qlcnic_config_ipaddr(adapter,
3977 ifa->ifa_address, QLCNIC_IP_UP);
3978 break;
3979 case NETDEV_DOWN:
3980 qlcnic_config_ipaddr(adapter,
3981 ifa->ifa_address, QLCNIC_IP_DOWN);
3982 break;
3983 default:
3984 break;
3985 }
3986 } endfor_ifa(indev);
3987
3988 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003989}
3990
Sony Chacko319ecf12013-01-01 03:20:22 +00003991void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003992{
3993 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3994 struct net_device *dev;
3995 u16 vid;
3996
3997 qlcnic_config_indev_addr(adapter, netdev, event);
3998
Jiri Pirko43c00a72013-01-03 22:48:57 +00003999 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00004000 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00004001 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004002 if (!dev)
4003 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004004 qlcnic_config_indev_addr(adapter, dev, event);
4005 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00004006 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004007}
4008
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004009static int qlcnic_netdev_event(struct notifier_block *this,
4010 unsigned long event, void *ptr)
4011{
4012 struct qlcnic_adapter *adapter;
Jiri Pirko351638e2013-05-28 01:30:21 +00004013 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004014
4015recheck:
4016 if (dev == NULL)
4017 goto done;
4018
4019 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4020 dev = vlan_dev_real_dev(dev);
4021 goto recheck;
4022 }
4023
4024 if (!is_qlcnic_netdev(dev))
4025 goto done;
4026
4027 adapter = netdev_priv(dev);
4028
4029 if (!adapter)
4030 goto done;
4031
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004032 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004033 goto done;
4034
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004035 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004036done:
4037 return NOTIFY_DONE;
4038}
4039
4040static int
4041qlcnic_inetaddr_event(struct notifier_block *this,
4042 unsigned long event, void *ptr)
4043{
4044 struct qlcnic_adapter *adapter;
4045 struct net_device *dev;
4046
4047 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4048
4049 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4050
4051recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004052 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004053 goto done;
4054
4055 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4056 dev = vlan_dev_real_dev(dev);
4057 goto recheck;
4058 }
4059
4060 if (!is_qlcnic_netdev(dev))
4061 goto done;
4062
4063 adapter = netdev_priv(dev);
4064
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00004065 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004066 goto done;
4067
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004068 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004069 goto done;
4070
4071 switch (event) {
4072 case NETDEV_UP:
4073 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00004074
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004075 break;
4076 case NETDEV_DOWN:
4077 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00004078
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004079 break;
4080 default:
4081 break;
4082 }
4083
4084done:
4085 return NOTIFY_DONE;
4086}
4087
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004088static struct notifier_block qlcnic_netdev_cb = {
4089 .notifier_call = qlcnic_netdev_event,
4090};
4091
4092static struct notifier_block qlcnic_inetaddr_cb = {
4093 .notifier_call = qlcnic_inetaddr_event,
4094};
4095#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00004096void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004097{ }
4098#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00004099static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004100 .error_detected = qlcnic_io_error_detected,
4101 .slot_reset = qlcnic_io_slot_reset,
4102 .resume = qlcnic_io_resume,
4103};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004104
4105static struct pci_driver qlcnic_driver = {
4106 .name = qlcnic_driver_name,
4107 .id_table = qlcnic_pci_tbl,
4108 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05004109 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004110#ifdef CONFIG_PM
4111 .suspend = qlcnic_suspend,
4112 .resume = qlcnic_resume,
4113#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004114 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00004115 .err_handler = &qlcnic_err_handler,
4116#ifdef CONFIG_QLCNIC_SRIOV
4117 .sriov_configure = qlcnic_pci_sriov_configure,
4118#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004119
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004120};
4121
4122static int __init qlcnic_init_module(void)
4123{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004124 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004125
4126 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4127
4128#ifdef CONFIG_INET
4129 register_netdevice_notifier(&qlcnic_netdev_cb);
4130 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4131#endif
4132
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004133 ret = pci_register_driver(&qlcnic_driver);
4134 if (ret) {
4135#ifdef CONFIG_INET
4136 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4137 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4138#endif
4139 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004140
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004141 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004142}
4143
4144module_init(qlcnic_init_module);
4145
4146static void __exit qlcnic_exit_module(void)
4147{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004148 pci_unregister_driver(&qlcnic_driver);
4149
4150#ifdef CONFIG_INET
4151 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4152 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4153#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004154}
4155
4156module_exit(qlcnic_exit_module);