blob: c71e1dc7295da21ddfbdb4bc997520ac8ee2b38f [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
Sritej Velaga40839129f2010-12-02 20:41:56 +00002 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 QLogic Corporation
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004 *
Sony Chacko13159182013-01-01 03:20:21 +00005 * PCI searching functions pci_get_domain_bus_and_slot & pci_channel_offline
6 * Copyright (C) 1993 -- 1997 Drew Eckhardt, Frederic Potter,
7 * David Mosberger-Tang
8 * Copyright (C) 1997 -- 2000 Martin Mares <mj@ucw.cz>
9 * Copyright (C) 2003 -- 2004 Greg Kroah-Hartman <greg@kroah.com>.
10 *
Sritej Velaga40839129f2010-12-02 20:41:56 +000011 * See LICENSE.qlcnic for copyright and licensing details.
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000012 */
13
14#include <linux/vmalloc.h>
15#include <linux/interrupt.h>
16
17#include "qlcnic.h"
Himanshu Madhania15ebd32013-01-01 03:20:18 +000018#include "qlcnic_hw.h"
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000019
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000020#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000021#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000022#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000023#include <net/ip.h>
24#include <linux/ipv6.h>
25#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000026#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000027#include <linux/log2.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000028
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000029MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000030MODULE_LICENSE("GPL");
31MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
32MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
33
34char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000035static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
36 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000037
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000038static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000039module_param(qlcnic_mac_learn, int, 0444);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000040MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
41
Sony Chacko629263a2013-01-01 04:11:55 +000042int qlcnic_use_msi = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000043MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000044module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000045
Sony Chacko629263a2013-01-01 04:11:55 +000046int qlcnic_use_msi_x = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000047MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000048module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000049
Sony Chacko629263a2013-01-01 04:11:55 +000050int qlcnic_auto_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000051MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000052module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000053
Sony Chacko629263a2013-01-01 04:11:55 +000054int qlcnic_load_fw_file;
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000055MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
Sony Chacko099f7aa2012-12-04 03:33:58 +000056module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000057
Sony Chacko629263a2013-01-01 04:11:55 +000058int qlcnic_config_npars;
amit salechab11a25a2011-01-10 00:15:23 +000059module_param(qlcnic_config_npars, int, 0444);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000060MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
61
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000062static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050063static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000064static int qlcnic_open(struct net_device *netdev);
65static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000066static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000067static void qlcnic_attach_work(struct work_struct *work);
68static void qlcnic_fwinit_work(struct work_struct *work);
69static void qlcnic_fw_poll_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000070#ifdef CONFIG_NET_POLL_CONTROLLER
71static void qlcnic_poll_controller(struct net_device *netdev);
72#endif
73
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000074static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000075static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000076static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
77
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000078static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000079static irqreturn_t qlcnic_intr(int irq, void *data);
80static irqreturn_t qlcnic_msi_intr(int irq, void *data);
81static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000082static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000083
84static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000085static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000086
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000087static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000088static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000089static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Rajesh Borundia0325d692010-08-19 05:08:26 +000090static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
91 struct qlcnic_esw_func_cfg *);
Jiri Pirko8e586132011-12-08 19:52:37 -050092static int qlcnic_vlan_rx_add(struct net_device *, u16);
93static int qlcnic_vlan_rx_del(struct net_device *, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000094
Sony Chackobff57d82012-12-04 03:33:56 +000095#define QLCNIC_IS_TSO_CAPABLE(adapter) \
96 ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO)
97
Sony Chacko13159182013-01-01 03:20:21 +000098static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
99{
100 struct qlcnic_hardware_context *ahw = adapter->ahw;
101
102 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
103 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
104 else
105 return 1;
106}
107
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000108/* PCI Device ID Table */
109#define ENTRY(device) \
110 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
111 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
112
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000113static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000114 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000115 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000116 {0,}
117};
118
119MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
120
121
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000122inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000123{
124 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000125}
126
127static const u32 msi_tgt_status[8] = {
128 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
129 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
130 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
131 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
132};
133
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000134static const u32 qlcnic_reg_tbl[] = {
135 0x1B20A8, /* PEG_HALT_STAT1 */
136 0x1B20AC, /* PEG_HALT_STAT2 */
137 0x1B20B0, /* FW_HEARTBEAT */
138 0x1B2100, /* LOCK ID */
139 0x1B2128, /* FW_CAPABILITIES */
140 0x1B2138, /* drv active */
141 0x1B2140, /* dev state */
142 0x1B2144, /* drv state */
143 0x1B2148, /* drv scratch */
144 0x1B214C, /* dev partition info */
145 0x1B2174, /* drv idc ver */
146 0x1B2150, /* fw version major */
147 0x1B2154, /* fw version minor */
148 0x1B2158, /* fw version sub */
149 0x1B219C, /* npar state */
150 0x1B21FC, /* FW_IMG_VALID */
151 0x1B2250, /* CMD_PEG_STATE */
152 0x1B233C, /* RCV_PEG_STATE */
153 0x1B23B4, /* ASIC TEMP */
154 0x1B216C, /* FW api */
155 0x1B2170, /* drv op mode */
156 0x13C010, /* flash lock */
157 0x13C014, /* flash unlock */
158};
159
Sony Chacko22999792012-12-04 03:33:55 +0000160static const struct qlcnic_board_info qlcnic_boards[] = {
161 {0x1077, 0x8020, 0x1077, 0x203,
162 "8200 Series Single Port 10GbE Converged Network Adapter"
163 "(TCP/IP Networking)"},
164 {0x1077, 0x8020, 0x1077, 0x207,
165 "8200 Series Dual Port 10GbE Converged Network Adapter"
166 "(TCP/IP Networking)"},
167 {0x1077, 0x8020, 0x1077, 0x20b,
168 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"},
169 {0x1077, 0x8020, 0x1077, 0x20c,
170 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"},
171 {0x1077, 0x8020, 0x1077, 0x20f,
172 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"},
173 {0x1077, 0x8020, 0x103c, 0x3733,
174 "NC523SFP 10Gb 2-port Server Adapter"},
175 {0x1077, 0x8020, 0x103c, 0x3346,
176 "CN1000Q Dual Port Converged Network Adapter"},
177 {0x1077, 0x8020, 0x1077, 0x210,
178 "QME8242-k 10GbE Dual Port Mezzanine Card"},
179 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"},
180};
181
182#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
Sony Chacko319ecf12013-01-01 03:20:22 +0000183#define QLC_MAX_SDS_RINGS 8
Sony Chacko22999792012-12-04 03:33:55 +0000184
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000185static const
186struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
187
Sony Chackoc70001a2012-11-28 04:34:26 +0000188int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000189{
190 int size = sizeof(struct qlcnic_host_sds_ring) * count;
191
192 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
193
Eric Dumazet807540b2010-09-23 05:40:09 +0000194 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000195}
196
Sony Chackoc70001a2012-11-28 04:34:26 +0000197void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000198{
199 if (recv_ctx->sds_rings != NULL)
200 kfree(recv_ctx->sds_rings);
201
202 recv_ctx->sds_rings = NULL;
203}
204
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000205static int
206qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
207{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000208 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000209 struct net_device *netdev = adapter->netdev;
210 struct pci_dev *pdev = adapter->pdev;
211
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000212 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000213 return -EIO;
214
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000215 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000216 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
217 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
218
219 /* set station address */
220
221 if (!is_valid_ether_addr(netdev->perm_addr))
222 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
223 netdev->dev_addr);
224
225 return 0;
226}
227
228static int qlcnic_set_mac(struct net_device *netdev, void *p)
229{
230 struct qlcnic_adapter *adapter = netdev_priv(netdev);
231 struct sockaddr *addr = p;
232
Rajesh Borundia73733732010-08-31 17:17:50 +0000233 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
234 return -EOPNOTSUPP;
235
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000236 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000237 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000238
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000239 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000240 netif_device_detach(netdev);
241 qlcnic_napi_disable(adapter);
242 }
243
244 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
245 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
246 qlcnic_set_multi(adapter->netdev);
247
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000248 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000249 netif_device_attach(netdev);
250 qlcnic_napi_enable(adapter);
251 }
252 return 0;
253}
254
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000255static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
256{
257 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
258 usleep_range(10000, 11000);
259
260 cancel_delayed_work_sync(&adapter->fw_work);
261}
262
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000263static const struct net_device_ops qlcnic_netdev_ops = {
264 .ndo_open = qlcnic_open,
265 .ndo_stop = qlcnic_close,
266 .ndo_start_xmit = qlcnic_xmit_frame,
267 .ndo_get_stats = qlcnic_get_stats,
268 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000269 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000270 .ndo_set_mac_address = qlcnic_set_mac,
271 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000272 .ndo_fix_features = qlcnic_fix_features,
273 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000274 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000275 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
276 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000277#ifdef CONFIG_NET_POLL_CONTROLLER
278 .ndo_poll_controller = qlcnic_poll_controller,
279#endif
280};
281
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000282static const struct net_device_ops qlcnic_netdev_failed_ops = {
283 .ndo_open = qlcnic_open,
284};
285
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000286static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000287 .config_bridged_mode = qlcnic_config_bridged_mode,
288 .config_led = qlcnic_82xx_config_led,
289 .start_firmware = qlcnic_82xx_start_firmware,
290 .request_reset = qlcnic_82xx_dev_request_reset,
291 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
292 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000293 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000294 .config_ipaddr = qlcnic_82xx_config_ipaddr,
295 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000296};
297
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000298struct qlcnic_nic_template qlcnic_vf_ops = {
299 .config_bridged_mode = qlcnicvf_config_bridged_mode,
300 .config_led = qlcnicvf_config_led,
301 .start_firmware = qlcnicvf_start_firmware
302};
303
304static struct qlcnic_hardware_ops qlcnic_hw_ops = {
305 .read_crb = qlcnic_82xx_read_crb,
306 .write_crb = qlcnic_82xx_write_crb,
307 .read_reg = qlcnic_82xx_hw_read_wx_2M,
308 .write_reg = qlcnic_82xx_hw_write_wx_2M,
309 .get_mac_address = qlcnic_82xx_get_mac_address,
310 .setup_intr = qlcnic_82xx_setup_intr,
311 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
312 .mbx_cmd = qlcnic_82xx_issue_cmd,
313 .get_func_no = qlcnic_82xx_get_func_no,
314 .api_lock = qlcnic_82xx_api_lock,
315 .api_unlock = qlcnic_82xx_api_unlock,
316 .add_sysfs = qlcnic_82xx_add_sysfs,
317 .remove_sysfs = qlcnic_82xx_remove_sysfs,
318 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
319 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
320 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
321 .setup_link_event = qlcnic_82xx_linkevent_request,
322 .get_nic_info = qlcnic_82xx_get_nic_info,
323 .get_pci_info = qlcnic_82xx_get_pci_info,
324 .set_nic_info = qlcnic_82xx_set_nic_info,
325 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
326 .napi_enable = qlcnic_82xx_napi_enable,
327 .napi_disable = qlcnic_82xx_napi_disable,
328 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
329 .config_rss = qlcnic_82xx_config_rss,
330 .config_hw_lro = qlcnic_82xx_config_hw_lro,
331 .config_loopback = qlcnic_82xx_set_lb_mode,
332 .clear_loopback = qlcnic_82xx_clear_lb_mode,
333 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
334 .change_l2_filter = qlcnic_82xx_change_filter,
335 .get_board_info = qlcnic_82xx_get_board_info,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000336};
337
Sony Chacko7f9664522013-01-01 03:20:19 +0000338int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000339{
340 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000341 int err = -1, i;
342 int max_tx_rings;
343
344 if (!adapter->msix_entries) {
345 adapter->msix_entries = kcalloc(num_msix,
346 sizeof(struct msix_entry),
347 GFP_KERNEL);
348 if (!adapter->msix_entries) {
349 dev_err(&pdev->dev, "failed allocating msix_entries\n");
350 return -ENOMEM;
351 }
352 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000353
354 adapter->max_sds_rings = 1;
355 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000356
Sony Chacko79788452012-12-04 03:33:53 +0000357 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000358 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000359 for (i = 0; i < num_msix; i++)
360 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000361 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
362 if (err == 0) {
363 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000364 if (qlcnic_83xx_check(adapter)) {
365 adapter->ahw->num_msix = num_msix;
366 /* subtract mail box and tx ring vectors */
367 max_tx_rings = adapter->max_drv_tx_rings;
368 adapter->max_sds_rings = num_msix -
369 max_tx_rings - 1;
370 } else {
371 adapter->max_sds_rings = num_msix;
372 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000373 dev_info(&pdev->dev, "using msi-x interrupts\n");
374 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000375 } else if (err > 0) {
376 dev_info(&pdev->dev,
377 "Unable to allocate %d MSI-X interrupt vectors\n",
378 num_msix);
379 if (qlcnic_83xx_check(adapter)) {
380 if (err < QLC_83XX_MINIMUM_VECTOR)
381 return err;
382 err -= (adapter->max_drv_tx_rings + 1);
383 num_msix = rounddown_pow_of_two(err);
384 num_msix += (adapter->max_drv_tx_rings + 1);
385 } else {
386 num_msix = rounddown_pow_of_two(err);
387 }
388
389 if (num_msix) {
390 dev_info(&pdev->dev,
391 "Trying %d MSI-X interrupt vectors\n",
392 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000393 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000394 }
395 } else {
396 dev_info(&pdev->dev, "Failed to get %d vectors\n",
397 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000398 }
399 }
Sony Chacko13159182013-01-01 03:20:21 +0000400
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000401 return err;
402}
403
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000404static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000405{
Sony Chacko15087c22012-12-04 03:33:54 +0000406 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000407 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000408 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000409 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000410
Sony Chacko099f7aa2012-12-04 03:33:58 +0000411 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000412 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000413 offset = msi_tgt_status[adapter->ahw->pci_func];
414 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
415 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000416 dev_info(&pdev->dev, "using msi interrupts\n");
417 adapter->msix_entries[0].vector = pdev->irq;
418 return;
419 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000420
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000421 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000422 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000423 offset = legacy_intrp->tgt_status_reg;
424 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
425 mask_reg = legacy_intrp->tgt_mask_reg;
426 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
427 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
428 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000429 dev_info(&pdev->dev, "using legacy interrupts\n");
430 adapter->msix_entries[0].vector = pdev->irq;
431}
432
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000433int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000434{
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000435 int num_msix, err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000436
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000437 if (!num_intr)
438 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
439
440 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000441 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000442 num_intr));
443 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000444 num_msix = 1;
445
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000446 err = qlcnic_enable_msix(adapter, num_msix);
447 if (err == -ENOMEM || !err)
448 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000449
450 qlcnic_enable_msi_legacy(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000451 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000452}
Sony Chacko13159182013-01-01 03:20:21 +0000453
Sony Chacko319ecf12013-01-01 03:20:22 +0000454void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000455{
456 if (adapter->flags & QLCNIC_MSIX_ENABLED)
457 pci_disable_msix(adapter->pdev);
458 if (adapter->flags & QLCNIC_MSI_ENABLED)
459 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000460
461 kfree(adapter->msix_entries);
462 adapter->msix_entries = NULL;
463
464 if (adapter->ahw->intr_tbl) {
465 vfree(adapter->ahw->intr_tbl);
466 adapter->ahw->intr_tbl = NULL;
467 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000468}
469
470static void
471qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
472{
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000473 if (adapter->ahw->pci_base0 != NULL)
474 iounmap(adapter->ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000475}
476
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000477static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
478{
479 struct qlcnic_pci_info *pci_info;
480 int ret;
481
482 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
483 switch (adapter->ahw->port_type) {
484 case QLCNIC_GBE:
485 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
486 break;
487 case QLCNIC_XGBE:
488 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
489 break;
490 }
491 return 0;
492 }
493
494 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
495 return 0;
496
497 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
498 if (!pci_info)
499 return -ENOMEM;
500
501 ret = qlcnic_get_pci_info(adapter, pci_info);
502 kfree(pci_info);
503 return ret;
504}
Sony Chackobff57d82012-12-04 03:33:56 +0000505static int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000506{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000507 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000508 int i, ret = 0, j = 0;
509 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000510 u8 pfn;
511
Dan Carpentere88db3b2010-08-09 21:49:36 +0000512 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
513 if (!pci_info)
514 return -ENOMEM;
515
Sony Chackobff57d82012-12-04 03:33:56 +0000516 ret = qlcnic_get_pci_info(adapter, pci_info);
517 if (ret)
518 goto err_pci_info;
519
520 act_pci_func = adapter->ahw->act_pci_func;
521
Dan Carpenterca315ac2010-08-09 21:47:56 +0000522 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000523 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000524 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000525 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000526 goto err_pci_info;
527 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000528
Dan Carpenterca315ac2010-08-09 21:47:56 +0000529 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000530 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
531 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000532 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000533 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000534 }
535
Dan Carpenterca315ac2010-08-09 21:47:56 +0000536 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
537 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000538
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000539 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000540 ret = QL_STATUS_INVALID_PARAM;
541 goto err_eswitch;
542 }
Sony Chackobff57d82012-12-04 03:33:56 +0000543
544 if (!pci_info[i].active ||
545 (pci_info[i].type != QLCNIC_TYPE_NIC))
546 continue;
547
548 adapter->npars[j].pci_func = pfn;
549 adapter->npars[j].active = (u8)pci_info[i].active;
550 adapter->npars[j].type = (u8)pci_info[i].type;
551 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
552 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
553 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
554 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000555 }
556
Sony Chacko13159182013-01-01 03:20:21 +0000557 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000558 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000559 if (qlcnic_83xx_check(adapter))
560 qlcnic_enable_eswitch(adapter, i, 1);
561 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000562
Dan Carpentere88db3b2010-08-09 21:49:36 +0000563 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000564 return 0;
565
566err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000567 kfree(adapter->eswitch);
568 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000569err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000570 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000571 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000572err_pci_info:
573 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000574
575 return ret;
576}
577
578static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000579qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
580{
581 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000582 int i, ret = 1;
583 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000584 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000585
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000586 ret = qlcnic_api_lock(adapter);
587 if (ret)
588 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000589
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000590 if (qlcnic_config_npars) {
Sony Chackobff57d82012-12-04 03:33:56 +0000591 for (i = 0; i < ahw->act_pci_func; i++) {
592 id = adapter->npars[i].pci_func;
593 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000594 continue;
595 data |= (qlcnic_config_npars &
596 QLC_DEV_SET_DRV(0xf, id));
597 }
598 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000599 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d82012-12-04 03:33:56 +0000600 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000601 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d82012-12-04 03:33:56 +0000602 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000603 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000604 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000605 qlcnic_api_unlock(adapter);
606err_lock:
607 return ret;
608}
609
Sony Chacko13159182013-01-01 03:20:21 +0000610static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
611 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000612{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000613 u32 op_mode, priv_level;
614
615 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000616 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
617 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000618
619 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000620 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000621
622 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000623 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000624 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000625 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000626 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000627 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000628
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000629 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000630 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000631 dev_info(&adapter->pdev->dev,
632 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000633 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000634 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000635 } else
636 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000637}
638
Sony Chacko15087c22012-12-04 03:33:54 +0000639#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000640#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000641static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000642{
Sony Chacko15087c22012-12-04 03:33:54 +0000643 switch (dev_id) {
644 case PCI_DEVICE_ID_QLOGIC_QLE824X:
645 *bar = QLCNIC_82XX_BAR0_LENGTH;
646 break;
Sony Chacko13159182013-01-01 03:20:21 +0000647 case PCI_DEVICE_ID_QLOGIC_QLE834X:
648 *bar = QLCNIC_83XX_BAR0_LENGTH;
649 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000650 default:
651 *bar = 0;
652 }
653}
654
655static int qlcnic_setup_pci_map(struct pci_dev *pdev,
656 struct qlcnic_hardware_context *ahw)
657{
658 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000659 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000660 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000661
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000662 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000663 mem_len = pci_resource_len(pdev, 0);
664
Sony Chacko15087c22012-12-04 03:33:54 +0000665 qlcnic_get_bar_length(pdev->device, &bar0_len);
666 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000667
668 mem_ptr0 = pci_ioremap_bar(pdev, 0);
669 if (mem_ptr0 == NULL) {
670 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
671 return -EIO;
672 }
673 pci_len0 = mem_len;
674 } else {
675 return -EIO;
676 }
677
678 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000679
Sony Chacko15087c22012-12-04 03:33:54 +0000680 ahw->pci_base0 = mem_ptr0;
681 ahw->pci_len0 = pci_len0;
682 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
683 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000684
685 return 0;
686}
687
Sony Chacko22999792012-12-04 03:33:55 +0000688static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000689{
690 struct pci_dev *pdev = adapter->pdev;
691 int i, found = 0;
692
693 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
694 if (qlcnic_boards[i].vendor == pdev->vendor &&
695 qlcnic_boards[i].device == pdev->device &&
696 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
697 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000698 sprintf(name, "%pM: %s" ,
699 adapter->mac_addr,
700 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000701 found = 1;
702 break;
703 }
704
705 }
706
707 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000708 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000709}
710
711static void
712qlcnic_check_options(struct qlcnic_adapter *adapter)
713{
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000714 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000715 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000716 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000717 struct qlcnic_hardware_context *ahw = adapter->ahw;
718 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000719
720 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000721
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000722 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
723 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
724 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000725
726 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
727
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000728 err = qlcnic_get_board_info(adapter);
729 if (err) {
730 dev_err(&pdev->dev, "Error getting board config info.\n");
731 return;
732 }
733 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +0000734 if (fw_dump->tmpl_hdr == NULL ||
735 adapter->fw_version > prev_fw_version) {
736 if (fw_dump->tmpl_hdr)
737 vfree(fw_dump->tmpl_hdr);
738 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
739 dev_info(&pdev->dev,
740 "Supports FW dump capability\n");
741 }
742 }
743
Sony Chacko13159182013-01-01 03:20:21 +0000744 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
745 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
746
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000747 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000748 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
749 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
750 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
751 } else {
752 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
753 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
754 }
755
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000756 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000757 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
758
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000759 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000760 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
761 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000762 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
763 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000764 }
765
Sony Chacko099f7aa2012-12-04 03:33:58 +0000766 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000767
768 adapter->num_txd = MAX_CMD_DESCRIPTORS;
769
Sony Chacko251b0362010-08-19 05:08:24 +0000770 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000771}
772
Rajesh Borundia174240a2010-08-31 17:17:47 +0000773static int
774qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
775{
776 int err;
777 struct qlcnic_info nic_info;
778
Sony Chackobff57d82012-12-04 03:33:56 +0000779 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000780 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000781 if (err)
782 return err;
783
Sony Chacko79788452012-12-04 03:33:53 +0000784 adapter->ahw->physical_port = (u8)nic_info.phys_port;
785 adapter->ahw->switch_mode = nic_info.switch_mode;
786 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
787 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
788 adapter->ahw->capabilities = nic_info.capabilities;
789 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
790 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000791
Sony Chacko13159182013-01-01 03:20:21 +0000792 /* Disable NPAR for 83XX */
793 if (qlcnic_83xx_check(adapter))
794 return err;
795
Sony Chacko79788452012-12-04 03:33:53 +0000796 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +0000797 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
798 else
799 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
800
801 return err;
802}
803
Sony Chackoec079a02012-11-28 04:34:28 +0000804void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
805 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000806{
807 if (esw_cfg->discard_tagged)
808 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
809 else
810 adapter->flags |= QLCNIC_TAGGING_ENABLED;
811
812 if (esw_cfg->vlan_id)
813 adapter->pvid = esw_cfg->vlan_id;
814 else
815 adapter->pvid = 0;
816}
817
Jiri Pirko8e586132011-12-08 19:52:37 -0500818static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000819qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid)
820{
821 struct qlcnic_adapter *adapter = netdev_priv(netdev);
822 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500823 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000824}
825
Jiri Pirko8e586132011-12-08 19:52:37 -0500826static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000827qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid)
828{
829 struct qlcnic_adapter *adapter = netdev_priv(netdev);
830
831 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
832 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500833 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000834}
835
Sony Chackoec079a02012-11-28 04:34:28 +0000836void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
837 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000838{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000839 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
840 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000841
842 if (esw_cfg->mac_anti_spoof)
843 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000844
Rajesh Borundia73733732010-08-31 17:17:50 +0000845 if (!esw_cfg->mac_override)
846 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
847
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000848 if (!esw_cfg->promisc_mode)
849 adapter->flags |= QLCNIC_PROMISC_DISABLED;
850
Rajesh Borundia0325d692010-08-19 05:08:26 +0000851 qlcnic_set_netdev_features(adapter, esw_cfg);
852}
853
Sony Chackoec079a02012-11-28 04:34:28 +0000854static int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000855{
856 struct qlcnic_esw_func_cfg esw_cfg;
857
858 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
859 return 0;
860
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000861 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000862 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
863 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000864 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000865 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
866
867 return 0;
868}
869
870static void
871qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
872 struct qlcnic_esw_func_cfg *esw_cfg)
873{
874 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +0000875 unsigned long features, vlan_features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000876
Sony Chacko13159182013-01-01 03:20:21 +0000877 if (qlcnic_83xx_check(adapter))
878 return;
879
880 features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Rajesh Borundia0325d692010-08-19 05:08:26 +0000881 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
882 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Sony Chacko13159182013-01-01 03:20:21 +0000883 NETIF_F_IPV6_CSUM);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000884
Sony Chacko13159182013-01-01 03:20:21 +0000885 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000886 features |= (NETIF_F_TSO | NETIF_F_TSO6);
887 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
888 }
Rajesh Borundiab56421d2011-04-01 14:28:31 +0000889
890 if (netdev->features & NETIF_F_LRO)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000891 features |= NETIF_F_LRO;
892
893 if (esw_cfg->offload_flags & BIT_0) {
894 netdev->features |= features;
Sony Chacko13159182013-01-01 03:20:21 +0000895 adapter->rx_csum = 1;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000896 if (!(esw_cfg->offload_flags & BIT_1))
897 netdev->features &= ~NETIF_F_TSO;
898 if (!(esw_cfg->offload_flags & BIT_2))
899 netdev->features &= ~NETIF_F_TSO6;
900 } else {
901 netdev->features &= ~features;
Sony Chacko13159182013-01-01 03:20:21 +0000902 adapter->rx_csum = 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000903 }
904
905 netdev->vlan_features = (features & vlan_features);
906}
907
908static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000909qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
910{
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000911 u32 op_mode, priv_level;
912 int err = 0;
913
Rajesh Borundia174240a2010-08-31 17:17:47 +0000914 err = qlcnic_initialize_nic(adapter);
915 if (err)
916 return err;
917
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000918 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
919 return 0;
920
Sony Chacko13159182013-01-01 03:20:21 +0000921 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000922 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000923
924 if (op_mode == QLC_DEV_DRV_DEFAULT)
925 priv_level = QLCNIC_MGMT_FUNC;
926 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000927 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000928
Rajesh Borundia174240a2010-08-31 17:17:47 +0000929 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000930 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000931 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000932 err = qlcnic_init_pci_info(adapter);
933 if (err)
934 return err;
935 /* Set privilege level for other functions */
936 qlcnic_set_function_modes(adapter);
937 dev_info(&adapter->pdev->dev,
938 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000939 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000940 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000941 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000942 dev_info(&adapter->pdev->dev,
943 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000944 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000945 }
Rajesh Borundia174240a2010-08-31 17:17:47 +0000946 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000947
948 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
949
950 return err;
951}
952
Sony Chackobff57d82012-12-04 03:33:56 +0000953static int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000954{
955 struct qlcnic_esw_func_cfg esw_cfg;
956 struct qlcnic_npar_info *npar;
957 u8 i;
958
Rajesh Borundia174240a2010-08-31 17:17:47 +0000959 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000960 return 0;
961
Sony Chackobff57d82012-12-04 03:33:56 +0000962 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000963 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +0000964 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +0000965 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000966 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +0000967 if (qlcnic_82xx_check(adapter)) {
968 esw_cfg.offload_flags = BIT_0;
969 if (QLCNIC_IS_TSO_CAPABLE(adapter))
970 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
971 }
Rajesh Borundia0325d692010-08-19 05:08:26 +0000972 if (qlcnic_config_switch_port(adapter, &esw_cfg))
973 return -EIO;
974 npar = &adapter->npars[i];
975 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +0000976 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000977 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
978 npar->discard_tagged = esw_cfg.discard_tagged;
979 npar->promisc_mode = esw_cfg.promisc_mode;
980 npar->offload_flags = esw_cfg.offload_flags;
981 }
982
983 return 0;
984}
985
Sony Chacko13159182013-01-01 03:20:21 +0000986
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000987static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000988qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
989 struct qlcnic_npar_info *npar, int pci_func)
990{
991 struct qlcnic_esw_func_cfg esw_cfg;
992 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
993 esw_cfg.pci_func = pci_func;
994 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +0000995 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000996 esw_cfg.discard_tagged = npar->discard_tagged;
997 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
998 esw_cfg.offload_flags = npar->offload_flags;
999 esw_cfg.promisc_mode = npar->promisc_mode;
1000 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1001 return -EIO;
1002
1003 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1004 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1005 return -EIO;
1006
1007 return 0;
1008}
1009
Sony Chackobff57d82012-12-04 03:33:56 +00001010static int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001011{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001012 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001013 struct qlcnic_npar_info *npar;
1014 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001015 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001016
Sony Chackobff57d82012-12-04 03:33:56 +00001017 if (qlcnic_82xx_check(adapter))
1018 if (!adapter->need_fw_reset)
1019 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001020
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001021 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001022 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001023 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001024 pci_func = npar->pci_func;
1025 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001026 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001027 if (err)
1028 return err;
1029 nic_info.min_tx_bw = npar->min_bw;
1030 nic_info.max_tx_bw = npar->max_bw;
1031 err = qlcnic_set_nic_info(adapter, &nic_info);
1032 if (err)
1033 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001034
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001035 if (npar->enable_pm) {
1036 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001037 npar->dest_npar, 1,
1038 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001039 if (err)
1040 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001041 }
Sony Chackobff57d82012-12-04 03:33:56 +00001042 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001043 if (err)
1044 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001045 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001046 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001047}
1048
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001049static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1050{
1051 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1052 u32 npar_state;
1053
Sony Chacko79788452012-12-04 03:33:53 +00001054 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001055 return 0;
1056
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001057 npar_state = QLC_SHARED_REG_RD32(adapter,
1058 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001059 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1060 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001061 npar_state = QLC_SHARED_REG_RD32(adapter,
1062 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001063 }
1064 if (!npar_opt_timeo) {
1065 dev_err(&adapter->pdev->dev,
1066 "Waiting for NPAR state to opertional timeout\n");
1067 return -EIO;
1068 }
1069 return 0;
1070}
1071
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001072static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001073qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1074{
1075 int err;
1076
1077 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001078 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001079 return 0;
1080
1081 err = qlcnic_set_default_offload_settings(adapter);
1082 if (err)
1083 return err;
1084
1085 err = qlcnic_reset_npar_config(adapter);
1086 if (err)
1087 return err;
1088
1089 qlcnic_dev_set_npar_ready(adapter);
1090
Sony Chacko13159182013-01-01 03:20:21 +00001091 if (qlcnic_83xx_check(adapter))
1092 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Rajesh Borundia174240a2010-08-31 17:17:47 +00001093 return err;
1094}
1095
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001096int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001097{
Sony Chackod4066832010-08-19 05:08:31 +00001098 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001099
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001100 err = qlcnic_can_start_firmware(adapter);
1101 if (err < 0)
1102 return err;
1103 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001104 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001105
Sony Chacko099f7aa2012-12-04 03:33:58 +00001106 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001107 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001108 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001109 err = qlcnic_check_flash_fw_ver(adapter);
1110 if (err)
schacko8f891382010-06-17 02:56:40 +00001111 goto err_out;
1112
Sony Chacko79788452012-12-04 03:33:53 +00001113 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001114 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001115
1116 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001117 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001118 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001119
Sony Chackod4066832010-08-19 05:08:31 +00001120 err = qlcnic_pinit_from_rom(adapter);
1121 if (err)
1122 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001123
1124 err = qlcnic_load_firmware(adapter);
1125 if (err)
1126 goto err_out;
1127
1128 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001129 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001130
Sony Chackod4066832010-08-19 05:08:31 +00001131check_fw_status:
1132 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001133 if (err)
1134 goto err_out;
1135
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001136 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001137 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001138 err = qlcnic_check_eswitch_mode(adapter);
1139 if (err) {
1140 dev_err(&adapter->pdev->dev,
1141 "Memory allocation failed for eswitch\n");
1142 goto err_out;
1143 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001144 err = qlcnic_set_mgmt_operations(adapter);
1145 if (err)
1146 goto err_out;
1147
1148 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001149 adapter->need_fw_reset = 0;
1150
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001151 qlcnic_release_firmware(adapter);
1152 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001153
1154err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001155 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001156 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001157
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001158 qlcnic_release_firmware(adapter);
1159 return err;
1160}
1161
1162static int
1163qlcnic_request_irq(struct qlcnic_adapter *adapter)
1164{
1165 irq_handler_t handler;
1166 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001167 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001168 int err, ring;
1169
1170 unsigned long flags = 0;
1171 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001172 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001173
Sony Chacko79788452012-12-04 03:33:53 +00001174 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001175 if (qlcnic_82xx_check(adapter))
1176 handler = qlcnic_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001177 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1178 flags |= IRQF_SHARED;
1179
1180 } else {
1181 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1182 handler = qlcnic_msix_intr;
1183 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1184 handler = qlcnic_msi_intr;
1185 else {
1186 flags |= IRQF_SHARED;
1187 handler = qlcnic_intr;
1188 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001189 }
1190 adapter->irq = netdev->irq;
1191
Sony Chacko13159182013-01-01 03:20:21 +00001192 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
1193 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1194 sds_ring = &recv_ctx->sds_rings[ring];
1195 snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ,
1196 "%s[%d]", netdev->name, ring);
1197 err = request_irq(sds_ring->irq, handler, flags,
1198 sds_ring->name, sds_ring);
1199 if (err)
1200 return err;
1201 }
1202 if (qlcnic_83xx_check(adapter) &&
1203 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
1204 handler = qlcnic_msix_tx_intr;
1205 for (ring = 0; ring < adapter->max_drv_tx_rings;
1206 ring++) {
1207 tx_ring = &adapter->tx_ring[ring];
1208 snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ,
1209 "%s[%d]", netdev->name,
1210 adapter->max_sds_rings + ring);
1211 err = request_irq(tx_ring->irq, handler, flags,
1212 tx_ring->name, tx_ring);
1213 if (err)
1214 return err;
1215 }
1216 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001217 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001218 return 0;
1219}
1220
1221static void
1222qlcnic_free_irq(struct qlcnic_adapter *adapter)
1223{
1224 int ring;
1225 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001226 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001227
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001228 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001229
Sony Chacko13159182013-01-01 03:20:21 +00001230 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
1231 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1232 sds_ring = &recv_ctx->sds_rings[ring];
1233 free_irq(sds_ring->irq, sds_ring);
1234 }
1235 if (qlcnic_83xx_check(adapter)) {
1236 for (ring = 0; ring < adapter->max_drv_tx_rings;
1237 ring++) {
1238 tx_ring = &adapter->tx_ring[ring];
1239 if (tx_ring->irq)
1240 free_irq(tx_ring->irq, tx_ring);
1241 }
1242 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001243 }
1244}
1245
Sony Chacko319ecf12013-01-01 03:20:22 +00001246int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001247{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001248 int ring;
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001249 u32 capab2;
1250
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001251 struct qlcnic_host_rds_ring *rds_ring;
1252
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001253 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1254 return -EIO;
1255
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001256 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1257 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001258 if (qlcnic_set_eswitch_port_config(adapter))
1259 return -EIO;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001260
Sony Chacko79788452012-12-04 03:33:53 +00001261 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001262 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1263 if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1264 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1265 }
1266
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001267 if (qlcnic_fw_create_ctx(adapter))
1268 return -EIO;
1269
1270 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001271 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001272 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001273 }
1274
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001275 qlcnic_set_multi(netdev);
1276 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1277
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001278 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001279
1280 if (adapter->max_sds_rings > 1)
1281 qlcnic_config_rss(adapter, 1);
1282
1283 qlcnic_config_intr_coalesce(adapter);
1284
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001285 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001286 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1287
1288 qlcnic_napi_enable(adapter);
1289
1290 qlcnic_linkevent_request(adapter, 1);
1291
Sony Chacko79788452012-12-04 03:33:53 +00001292 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001293 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1294 return 0;
1295}
1296
Sony Chacko629263a2013-01-01 04:11:55 +00001297int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001298{
1299 int err = 0;
1300
1301 rtnl_lock();
1302 if (netif_running(netdev))
1303 err = __qlcnic_up(adapter, netdev);
1304 rtnl_unlock();
1305
1306 return err;
1307}
1308
Sony Chacko319ecf12013-01-01 03:20:22 +00001309void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001310{
1311 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1312 return;
1313
1314 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1315 return;
1316
1317 smp_mb();
1318 spin_lock(&adapter->tx_clean_lock);
1319 netif_carrier_off(netdev);
1320 netif_tx_disable(netdev);
1321
1322 qlcnic_free_mac_list(adapter);
1323
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001324 if (adapter->fhash.fnum)
1325 qlcnic_delete_lb_filters(adapter);
1326
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001327 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1328
1329 qlcnic_napi_disable(adapter);
1330
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001331 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001332 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001333
1334 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001335 qlcnic_release_tx_buffers(adapter);
1336 spin_unlock(&adapter->tx_clean_lock);
1337}
1338
1339/* Usage: During suspend and firmware recovery module */
1340
Sony Chacko629263a2013-01-01 04:11:55 +00001341void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001342{
1343 rtnl_lock();
1344 if (netif_running(netdev))
1345 __qlcnic_down(adapter, netdev);
1346 rtnl_unlock();
1347
1348}
1349
Sony Chacko319ecf12013-01-01 03:20:22 +00001350int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001351qlcnic_attach(struct qlcnic_adapter *adapter)
1352{
1353 struct net_device *netdev = adapter->netdev;
1354 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001355 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001356
1357 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1358 return 0;
1359
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001360 err = qlcnic_napi_add(adapter, netdev);
1361 if (err)
1362 return err;
1363
1364 err = qlcnic_alloc_sw_resources(adapter);
1365 if (err) {
1366 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001367 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001368 }
1369
1370 err = qlcnic_alloc_hw_resources(adapter);
1371 if (err) {
1372 dev_err(&pdev->dev, "Error in setting hw resources\n");
1373 goto err_out_free_sw;
1374 }
1375
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001376 err = qlcnic_request_irq(adapter);
1377 if (err) {
1378 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001379 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001380 }
1381
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001382 qlcnic_create_sysfs_entries(adapter);
1383
1384 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1385 return 0;
1386
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001387err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001388 qlcnic_free_hw_resources(adapter);
1389err_out_free_sw:
1390 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001391err_out_napi_del:
1392 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001393 return err;
1394}
1395
Sony Chacko319ecf12013-01-01 03:20:22 +00001396void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001397{
1398 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1399 return;
1400
1401 qlcnic_remove_sysfs_entries(adapter);
1402
1403 qlcnic_free_hw_resources(adapter);
1404 qlcnic_release_rx_buffers(adapter);
1405 qlcnic_free_irq(adapter);
1406 qlcnic_napi_del(adapter);
1407 qlcnic_free_sw_resources(adapter);
1408
1409 adapter->is_up = 0;
1410}
1411
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001412void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1413{
1414 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1415 struct qlcnic_host_sds_ring *sds_ring;
1416 int ring;
1417
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001418 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001419 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001420 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001421 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Sony Chacko13159182013-01-01 03:20:21 +00001422 if (qlcnic_83xx_check(adapter))
1423 writel(1, sds_ring->crb_intr_mask);
1424 else
1425 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001426 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001427 }
1428
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001429 qlcnic_fw_destroy_ctx(adapter);
1430
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001431 qlcnic_detach(adapter);
1432
Sony Chacko79788452012-12-04 03:33:53 +00001433 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001434 adapter->max_sds_rings = max_sds_rings;
1435
1436 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001437 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001438
1439 if (netif_running(netdev))
1440 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001441out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001442 netif_device_attach(netdev);
1443}
1444
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001445static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1446{
1447 int err = 0;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001448 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1449 GFP_KERNEL);
1450 if (!adapter->recv_ctx) {
1451 dev_err(&adapter->pdev->dev,
1452 "Failed to allocate recv ctx resources for adapter\n");
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001453 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001454 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001455 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001456 /* Initialize interrupt coalesce parameters */
1457 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1458 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1459 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Sony Chacko4be41e92013-01-01 03:20:20 +00001460 /* clear stats */
1461 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001462err_out:
1463 return err;
1464}
1465
1466static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1467{
1468 kfree(adapter->recv_ctx);
1469 adapter->recv_ctx = NULL;
1470
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001471 if (adapter->ahw->fw_dump.tmpl_hdr) {
1472 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1473 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1474 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001475
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001476 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001477 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001478}
1479
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001480int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1481{
1482 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1483 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001484 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001485 int ring;
1486 int ret;
1487
1488 netif_device_detach(netdev);
1489
1490 if (netif_running(netdev))
1491 __qlcnic_down(adapter, netdev);
1492
1493 qlcnic_detach(adapter);
1494
1495 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001496 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001497 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001498
1499 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001500 if (ret) {
1501 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001502 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001503 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001504
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001505 ret = qlcnic_fw_create_ctx(adapter);
1506 if (ret) {
1507 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001508 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001509 return ret;
1510 }
1511
1512 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001513 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001514 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001515 }
1516
Sony Chacko79788452012-12-04 03:33:53 +00001517 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001518 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001519 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001520 qlcnic_enable_int(sds_ring);
1521 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001522 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001523
Sony Chacko79788452012-12-04 03:33:53 +00001524 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001525 adapter->ahw->loopback_state = 0;
1526 qlcnic_linkevent_request(adapter, 1);
1527 }
1528
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001529 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001530
1531 return 0;
1532}
1533
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001534/* Reset context in hardware only */
1535static int
1536qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1537{
1538 struct net_device *netdev = adapter->netdev;
1539
1540 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1541 return -EBUSY;
1542
1543 netif_device_detach(netdev);
1544
1545 qlcnic_down(adapter, netdev);
1546
1547 qlcnic_up(adapter, netdev);
1548
1549 netif_device_attach(netdev);
1550
1551 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001552 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001553 return 0;
1554}
1555
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001556int
1557qlcnic_reset_context(struct qlcnic_adapter *adapter)
1558{
1559 int err = 0;
1560 struct net_device *netdev = adapter->netdev;
1561
1562 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1563 return -EBUSY;
1564
1565 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1566
1567 netif_device_detach(netdev);
1568
1569 if (netif_running(netdev))
1570 __qlcnic_down(adapter, netdev);
1571
1572 qlcnic_detach(adapter);
1573
1574 if (netif_running(netdev)) {
1575 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001576 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001577 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001578 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1579 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001580 }
1581
1582 netif_device_attach(netdev);
1583 }
1584
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001585 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1586 return err;
1587}
1588
1589static int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001590qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1591 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001592{
1593 int err;
1594 struct pci_dev *pdev = adapter->pdev;
1595
Sony Chacko13159182013-01-01 03:20:21 +00001596 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001597 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001598 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001599
1600 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001601 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001602
1603 qlcnic_change_mtu(netdev, netdev->mtu);
1604
1605 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1606
Sony Chacko13159182013-01-01 03:20:21 +00001607 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1608 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
1609 NETIF_F_HW_VLAN_RX);
1610 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1611 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001612
Sony Chacko13159182013-01-01 03:20:21 +00001613 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1614 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1615 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1616 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001617
Sony Chacko13159182013-01-01 03:20:21 +00001618 if (pci_using_dac) {
1619 netdev->features |= NETIF_F_HIGHDMA;
1620 netdev->vlan_features |= NETIF_F_HIGHDMA;
1621 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001622
Sony Chacko13159182013-01-01 03:20:21 +00001623 if (qlcnic_vlan_tx_check(adapter))
1624 netdev->features |= (NETIF_F_HW_VLAN_TX);
1625
Sony Chacko79788452012-12-04 03:33:53 +00001626 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001627 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001628
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001629 netdev->irq = adapter->msix_entries[0].vector;
1630
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001631 err = register_netdev(netdev);
1632 if (err) {
1633 dev_err(&pdev->dev, "failed to register net device\n");
1634 return err;
1635 }
1636
1637 return 0;
1638}
1639
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001640static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001641{
1642 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1643 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1644 *pci_using_dac = 1;
1645 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1646 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1647 *pci_using_dac = 0;
1648 else {
1649 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1650 return -EIO;
1651 }
1652
1653 return 0;
1654}
1655
Sony Chacko4be41e92013-01-01 03:20:20 +00001656void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1657{
1658 int ring;
1659 struct qlcnic_host_tx_ring *tx_ring;
1660
1661 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1662 tx_ring = &adapter->tx_ring[ring];
1663 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1664 vfree(tx_ring->cmd_buf_arr);
1665 tx_ring->cmd_buf_arr = NULL;
1666 }
1667 }
1668 if (adapter->tx_ring != NULL)
1669 kfree(adapter->tx_ring);
1670}
1671
1672int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1673 struct net_device *netdev)
1674{
1675 int ring, size, vector, index;
1676 struct qlcnic_host_tx_ring *tx_ring;
1677 struct qlcnic_cmd_buffer *cmd_buf_arr;
1678
1679 size = adapter->max_drv_tx_rings * sizeof(struct qlcnic_host_tx_ring);
1680 tx_ring = kzalloc(size, GFP_KERNEL);
1681 if (tx_ring == NULL) {
1682 dev_err(&netdev->dev, "failed to allocate tx rings\n");
1683 return -ENOMEM;
1684 }
1685 adapter->tx_ring = tx_ring;
1686
1687 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1688 tx_ring = &adapter->tx_ring[ring];
1689 tx_ring->num_desc = adapter->num_txd;
1690 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1691 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1692 if (cmd_buf_arr == NULL) {
1693 dev_err(&netdev->dev,
1694 "failed to allocate cmd buffer ring\n");
1695 qlcnic_free_tx_rings(adapter);
1696 return -ENOMEM;
1697 }
1698 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1699 tx_ring->cmd_buf_arr = cmd_buf_arr;
1700 }
1701
1702 if (qlcnic_83xx_check(adapter)) {
1703 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1704 tx_ring = &adapter->tx_ring[ring];
1705 tx_ring->adapter = adapter;
1706 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1707 index = adapter->max_sds_rings + ring;
1708 vector = adapter->msix_entries[index].vector;
1709 tx_ring->irq = vector;
1710 }
1711 }
1712 }
1713 return 0;
1714}
1715
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001716static int __devinit
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001717qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1718{
1719 struct net_device *netdev = NULL;
1720 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001721 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001722 int err, pci_using_dac = -1;
Sony Chacko22999792012-12-04 03:33:55 +00001723 char board_name[QLCNIC_MAX_BOARD_NAME_LEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001724
1725 err = pci_enable_device(pdev);
1726 if (err)
1727 return err;
1728
1729 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1730 err = -ENODEV;
1731 goto err_out_disable_pdev;
1732 }
1733
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001734 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1735 if (err)
1736 goto err_out_disable_pdev;
1737
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001738 err = pci_request_regions(pdev, qlcnic_driver_name);
1739 if (err)
1740 goto err_out_disable_pdev;
1741
1742 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001743 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001744
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001745 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
1746 if (!ahw)
1747 goto err_out_free_res;
1748
1749 if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE824X) {
1750 ahw->hw_ops = &qlcnic_hw_ops;
1751 ahw->reg_tbl = (u32 *)qlcnic_reg_tbl;
Sony Chacko13159182013-01-01 03:20:21 +00001752 } else if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1753 qlcnic_83xx_register_map(ahw);
1754 } else {
1755 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001756 }
1757
1758 err = qlcnic_setup_pci_map(pdev, ahw);
1759 if (err)
1760 goto err_out_free_hw_res;
1761
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001762 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1763 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001764 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001765 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001766 }
1767
1768 SET_NETDEV_DEV(netdev, &pdev->dev);
1769
1770 adapter = netdev_priv(netdev);
1771 adapter->netdev = netdev;
1772 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00001773 adapter->ahw = ahw;
1774
1775 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
1776 if (adapter->qlcnic_wq == NULL) {
1777 dev_err(&pdev->dev, "Failed to create workqueue\n");
1778 goto err_out_free_netdev;
1779 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001780
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001781 err = qlcnic_alloc_adapter_resources(adapter);
1782 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001783 goto err_out_free_netdev;
1784
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001785 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001786 adapter->ahw->revision_id = pdev->revision;
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001787 adapter->mac_learn = qlcnic_mac_learn;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001788 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001789
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001790 rwlock_init(&adapter->ahw->crb_lock);
1791 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001792
1793 spin_lock_init(&adapter->tx_clean_lock);
1794 INIT_LIST_HEAD(&adapter->mac_list);
1795
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001796 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00001797 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001798 adapter->portnum = adapter->ahw->pci_func;
1799 err = qlcnic_start_firmware(adapter);
1800 if (err) {
1801 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1802 goto err_out_free_hw;
1803 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001804
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001805 err = qlcnic_setup_idc_param(adapter);
1806 if (err)
1807 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001808
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001809 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00001810 } else if (qlcnic_83xx_check(adapter)) {
1811 qlcnic_83xx_check_vf(adapter, ent);
1812 adapter->portnum = adapter->ahw->pci_func;
Sony Chacko629263a2013-01-01 04:11:55 +00001813 err = qlcnic_83xx_init(adapter);
1814 if (err) {
1815 dev_err(&pdev->dev, "%s: failed\n", __func__);
1816 goto err_out_free_hw;
1817 }
Sony Chacko13159182013-01-01 03:20:21 +00001818 } else {
1819 dev_err(&pdev->dev,
1820 "%s: failed. Please Reboot\n", __func__);
1821 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001822 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001823
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001824 if (qlcnic_read_mac_addr(adapter))
1825 dev_warn(&pdev->dev, "failed to read mac addr\n");
1826
1827 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00001828 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00001829
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001830 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00001831 module_name(THIS_MODULE),
1832 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001833 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001834 err = qlcnic_setup_intr(adapter, 0);
1835 if (err)
1836 goto err_out_disable_msi;
1837
Sony Chacko13159182013-01-01 03:20:21 +00001838 if (qlcnic_83xx_check(adapter)) {
1839 err = qlcnic_83xx_setup_mbx_intr(adapter);
1840 if (err)
1841 goto err_out_disable_msi;
1842 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001843
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001844 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001845 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001846 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001847
1848 pci_set_drvdata(pdev, adapter);
1849
Sony Chacko97ee45e2012-12-04 03:33:52 +00001850 if (qlcnic_82xx_check(adapter))
1851 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1852 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001853
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001854 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001855 case QLCNIC_GBE:
1856 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1857 adapter->netdev->name);
1858 break;
1859 case QLCNIC_XGBE:
1860 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1861 adapter->netdev->name);
1862 break;
1863 }
1864
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001865 if (qlcnic_get_act_pci_func(adapter))
1866 goto err_out_disable_mbx_intr;
1867
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001868 if (adapter->mac_learn)
1869 qlcnic_alloc_lb_filters_mem(adapter);
1870
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001871 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001872
1873 return 0;
1874
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001875err_out_disable_mbx_intr:
Sony Chacko13159182013-01-01 03:20:21 +00001876 if (qlcnic_83xx_check(adapter)) {
1877 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1878 qlcnic_83xx_config_intrpt(adapter, 0);
1879 qlcnic_83xx_free_mbx_intr(adapter);
1880 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001881
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001882err_out_disable_msi:
1883 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001884 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001885 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001886
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001887err_out_free_hw:
1888 qlcnic_free_adapter_resources(adapter);
1889
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001890err_out_free_netdev:
1891 free_netdev(netdev);
1892
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001893err_out_iounmap:
1894 qlcnic_cleanup_pci_map(adapter);
1895
1896err_out_free_hw_res:
1897 kfree(ahw);
1898
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001899err_out_free_res:
1900 pci_release_regions(pdev);
1901
1902err_out_disable_pdev:
1903 pci_set_drvdata(pdev, NULL);
1904 pci_disable_device(pdev);
1905 return err;
1906}
1907
Sony Chacko13159182013-01-01 03:20:21 +00001908static void __devexit qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001909{
1910 struct qlcnic_adapter *adapter;
1911 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00001912 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001913
1914 adapter = pci_get_drvdata(pdev);
1915 if (adapter == NULL)
1916 return;
1917
1918 netdev = adapter->netdev;
1919
Sony Chacko13159182013-01-01 03:20:21 +00001920 qlcnic_cancel_idc_work(adapter);
1921 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001922
1923 unregister_netdev(netdev);
1924
Sony Chacko13159182013-01-01 03:20:21 +00001925 if (qlcnic_83xx_check(adapter)) {
1926 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1927 qlcnic_83xx_config_intrpt(adapter, 0);
1928 qlcnic_83xx_free_mbx_intr(adapter);
1929 }
1930
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001931 qlcnic_detach(adapter);
1932
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001933 if (adapter->npars != NULL)
1934 kfree(adapter->npars);
1935 if (adapter->eswitch != NULL)
1936 kfree(adapter->eswitch);
1937
Sony Chacko97ee45e2012-12-04 03:33:52 +00001938 if (qlcnic_82xx_check(adapter))
1939 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001940
1941 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1942
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001943 qlcnic_free_lb_filters_mem(adapter);
1944
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001945 qlcnic_teardown_intr(adapter);
1946
Sony Chacko13159182013-01-01 03:20:21 +00001947 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001948
1949 qlcnic_cleanup_pci_map(adapter);
1950
1951 qlcnic_release_firmware(adapter);
1952
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001953 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001954 pci_release_regions(pdev);
1955 pci_disable_device(pdev);
1956 pci_set_drvdata(pdev, NULL);
1957
Sony Chacko13159182013-01-01 03:20:21 +00001958 if (adapter->qlcnic_wq) {
1959 destroy_workqueue(adapter->qlcnic_wq);
1960 adapter->qlcnic_wq = NULL;
1961 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001962 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00001963 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001964 free_netdev(netdev);
1965}
1966static int __qlcnic_shutdown(struct pci_dev *pdev)
1967{
1968 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1969 struct net_device *netdev = adapter->netdev;
1970 int retval;
1971
1972 netif_device_detach(netdev);
1973
Sony Chacko13159182013-01-01 03:20:21 +00001974 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001975
1976 if (netif_running(netdev))
1977 qlcnic_down(adapter, netdev);
1978
Sony Chacko97ee45e2012-12-04 03:33:52 +00001979 if (qlcnic_82xx_check(adapter))
1980 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001981
1982 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1983
1984 retval = pci_save_state(pdev);
1985 if (retval)
1986 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00001987 if (qlcnic_82xx_check(adapter)) {
1988 if (qlcnic_wol_supported(adapter)) {
1989 pci_enable_wake(pdev, PCI_D3cold, 1);
1990 pci_enable_wake(pdev, PCI_D3hot, 1);
1991 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001992 }
1993
1994 return 0;
1995}
1996
1997static void qlcnic_shutdown(struct pci_dev *pdev)
1998{
1999 if (__qlcnic_shutdown(pdev))
2000 return;
2001
2002 pci_disable_device(pdev);
2003}
2004
2005#ifdef CONFIG_PM
2006static int
2007qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2008{
2009 int retval;
2010
2011 retval = __qlcnic_shutdown(pdev);
2012 if (retval)
2013 return retval;
2014
2015 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2016 return 0;
2017}
2018
2019static int
2020qlcnic_resume(struct pci_dev *pdev)
2021{
2022 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2023 struct net_device *netdev = adapter->netdev;
2024 int err;
2025
2026 err = pci_enable_device(pdev);
2027 if (err)
2028 return err;
2029
2030 pci_set_power_state(pdev, PCI_D0);
2031 pci_set_master(pdev);
2032 pci_restore_state(pdev);
2033
Sony Chacko13159182013-01-01 03:20:21 +00002034 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002035 if (err) {
2036 dev_err(&pdev->dev, "failed to start firmware\n");
2037 return err;
2038 }
2039
2040 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002041 err = qlcnic_up(adapter, netdev);
2042 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002043 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002044
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002045 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002046 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002047done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002048 netif_device_attach(netdev);
2049 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2050 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002051}
2052#endif
2053
2054static int qlcnic_open(struct net_device *netdev)
2055{
2056 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2057 int err;
2058
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002059 netif_carrier_off(netdev);
2060
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002061 err = qlcnic_attach(adapter);
2062 if (err)
2063 return err;
2064
2065 err = __qlcnic_up(adapter, netdev);
2066 if (err)
2067 goto err_out;
2068
2069 netif_start_queue(netdev);
2070
2071 return 0;
2072
2073err_out:
2074 qlcnic_detach(adapter);
2075 return err;
2076}
2077
2078/*
2079 * qlcnic_close - Disables a network interface entry point
2080 */
2081static int qlcnic_close(struct net_device *netdev)
2082{
2083 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2084
2085 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002086 if (qlcnic_83xx_check(adapter)) {
2087 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2088 cancel_delayed_work_sync(&adapter->idc_aen_work);
2089 }
2090
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002091 return 0;
2092}
2093
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002094void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002095{
2096 void *head;
2097 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002098 struct net_device *netdev = adapter->netdev;
2099 u32 filter_size = 0;
2100 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002101
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002102 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002103 return;
2104
Sony Chacko13159182013-01-01 03:20:21 +00002105 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002106 spin_lock_init(&adapter->mac_learn_lock);
2107
Sony Chacko13159182013-01-01 03:20:21 +00002108 if (qlcnic_82xx_check(adapter)) {
2109 filter_size = QLCNIC_LB_MAX_FILTERS;
2110 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2111 } else {
2112 filter_size = QLC_83XX_LB_MAX_FILTERS;
2113 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2114 }
2115
2116 head = kcalloc(adapter->fhash.fbucket_size,
2117 sizeof(struct hlist_head), GFP_KERNEL);
2118
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002119 if (!head)
2120 return;
2121
Sony Chacko13159182013-01-01 03:20:21 +00002122 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002123 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002124
Sony Chacko13159182013-01-01 03:20:21 +00002125 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2126 act_pci_func, adapter->fhash.fmax);
2127
2128 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002129 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
2130}
2131
2132static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2133{
2134 if (adapter->fhash.fmax && adapter->fhash.fhead)
2135 kfree(adapter->fhash.fhead);
2136
2137 adapter->fhash.fhead = NULL;
2138 adapter->fhash.fmax = 0;
2139}
2140
Sony Chacko629263a2013-01-01 04:11:55 +00002141int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002142{
2143 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002144 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002145 int rv = 0;
2146
Sony Chacko13159182013-01-01 03:20:21 +00002147 if (qlcnic_83xx_check(adapter))
2148 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2149
Sony Chacko97ee45e2012-12-04 03:33:52 +00002150 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002151 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002152
2153 temp_state = qlcnic_get_temp_state(temp);
2154 temp_val = qlcnic_get_temp_val(temp);
2155
2156 if (temp_state == QLCNIC_TEMP_PANIC) {
2157 dev_err(&netdev->dev,
2158 "Device temperature %d degrees C exceeds"
2159 " maximum allowed. Hardware has been shut down.\n",
2160 temp_val);
2161 rv = 1;
2162 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002163 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002164 dev_err(&netdev->dev,
2165 "Device temperature %d degrees C "
2166 "exceeds operating range."
2167 " Immediate action needed.\n",
2168 temp_val);
2169 }
2170 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002171 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002172 dev_info(&netdev->dev,
2173 "Device temperature is now %d degrees C"
2174 " in normal range.\n", temp_val);
2175 }
2176 }
Sony Chacko79788452012-12-04 03:33:53 +00002177 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002178 return rv;
2179}
2180
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002181static void qlcnic_tx_timeout(struct net_device *netdev)
2182{
2183 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2184
2185 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2186 return;
2187
2188 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002189
2190 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002191 adapter->need_fw_reset = 1;
2192 else
Sony Chacko79788452012-12-04 03:33:53 +00002193 adapter->ahw->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002194}
2195
2196static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2197{
2198 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2199 struct net_device_stats *stats = &netdev->stats;
2200
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002201 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2202 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002203 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002204 stats->tx_bytes = adapter->stats.txbytes;
2205 stats->rx_dropped = adapter->stats.rxdropped;
2206 stats->tx_dropped = adapter->stats.txdropped;
2207
2208 return stats;
2209}
2210
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002211irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002212{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002213 u32 status;
2214
2215 status = readl(adapter->isr_int_vec);
2216
Sony Chacko79788452012-12-04 03:33:53 +00002217 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002218 return IRQ_NONE;
2219
2220 /* check interrupt state machine, to be sure */
2221 status = readl(adapter->crb_int_state_reg);
2222 if (!ISR_LEGACY_INT_TRIGGERED(status))
2223 return IRQ_NONE;
2224
2225 writel(0xffffffff, adapter->tgt_status_reg);
2226 /* read twice to ensure write is flushed */
2227 readl(adapter->isr_int_vec);
2228 readl(adapter->isr_int_vec);
2229
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002230 return IRQ_HANDLED;
2231}
2232
2233static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2234{
2235 struct qlcnic_host_sds_ring *sds_ring = data;
2236 struct qlcnic_adapter *adapter = sds_ring->adapter;
2237
2238 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2239 goto done;
2240 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2241 writel(0xffffffff, adapter->tgt_status_reg);
2242 goto done;
2243 }
2244
2245 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2246 return IRQ_NONE;
2247
2248done:
Sony Chacko79788452012-12-04 03:33:53 +00002249 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002250 qlcnic_enable_int(sds_ring);
2251 return IRQ_HANDLED;
2252}
2253
2254static irqreturn_t qlcnic_intr(int irq, void *data)
2255{
2256 struct qlcnic_host_sds_ring *sds_ring = data;
2257 struct qlcnic_adapter *adapter = sds_ring->adapter;
2258
2259 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2260 return IRQ_NONE;
2261
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002262 napi_schedule(&sds_ring->napi);
2263
2264 return IRQ_HANDLED;
2265}
2266
2267static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2268{
2269 struct qlcnic_host_sds_ring *sds_ring = data;
2270 struct qlcnic_adapter *adapter = sds_ring->adapter;
2271
2272 /* clear interrupt */
2273 writel(0xffffffff, adapter->tgt_status_reg);
2274
2275 napi_schedule(&sds_ring->napi);
2276 return IRQ_HANDLED;
2277}
2278
2279static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2280{
2281 struct qlcnic_host_sds_ring *sds_ring = data;
2282
2283 napi_schedule(&sds_ring->napi);
2284 return IRQ_HANDLED;
2285}
2286
Sony Chacko13159182013-01-01 03:20:21 +00002287static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2288{
2289 struct qlcnic_host_tx_ring *tx_ring = data;
2290
2291 napi_schedule(&tx_ring->napi);
2292 return IRQ_HANDLED;
2293}
2294
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002295#ifdef CONFIG_NET_POLL_CONTROLLER
2296static void qlcnic_poll_controller(struct net_device *netdev)
2297{
Yinglin Luanbf827912010-08-22 21:57:56 +00002298 int ring;
2299 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002300 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002301 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002302
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002303 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002304 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2305 sds_ring = &recv_ctx->sds_rings[ring];
2306 qlcnic_intr(adapter->irq, sds_ring);
2307 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002308 enable_irq(adapter->irq);
2309}
2310#endif
2311
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002312static void
2313qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2314{
2315 u32 val;
2316
2317 val = adapter->portnum & 0xf;
2318 val |= encoding << 7;
2319 val |= (jiffies - adapter->dev_rst_time) << 8;
2320
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002321 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002322 adapter->dev_rst_time = jiffies;
2323}
2324
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002325static int
2326qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002327{
2328 u32 val;
2329
2330 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2331 state != QLCNIC_DEV_NEED_QUISCENT);
2332
2333 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002334 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002335
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002336 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002337
2338 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002339 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002340 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002341 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002342
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002343 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002344
2345 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002346
2347 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002348}
2349
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002350static int
2351qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2352{
2353 u32 val;
2354
2355 if (qlcnic_api_lock(adapter))
2356 return -EBUSY;
2357
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002358 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002359 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002360 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002361
2362 qlcnic_api_unlock(adapter);
2363
2364 return 0;
2365}
2366
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002367static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002368qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002369{
2370 u32 val;
2371
2372 if (qlcnic_api_lock(adapter))
2373 goto err;
2374
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002375 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002376 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002377 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002378
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002379 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002380 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2381 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002382 dev_info(&adapter->pdev->dev,
2383 "Device state set to Failed. Please Reboot\n");
2384 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002385 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2386 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002387
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002388 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002389 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002390 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002391
2392 qlcnic_api_unlock(adapter);
2393err:
2394 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002395 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002396 clear_bit(__QLCNIC_START_FW, &adapter->state);
2397 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2398}
2399
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002400/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002401static int
2402qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2403{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002404 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002405 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002406
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002407 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2408 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002409
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002410 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002411 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002412 act = act & active_mask;
2413 }
2414
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002415 if (((state & 0x11111111) == (act & 0x11111111)) ||
2416 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2417 return 0;
2418 else
2419 return 1;
2420}
2421
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002422static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2423{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002424 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002425
2426 if (val != QLCNIC_DRV_IDC_VER) {
2427 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2428 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2429 }
2430
2431 return 0;
2432}
2433
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002434static int
2435qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2436{
2437 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002438 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002439 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002440 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002441
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002442 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2443 return 1;
2444
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002445 if (qlcnic_api_lock(adapter))
2446 return -1;
2447
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002448 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002449 if (!(val & (1 << (portnum * 4)))) {
2450 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002451 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002452 }
2453
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002454 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002455 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002456
2457 switch (prev_state) {
2458 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002459 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2460 QLCNIC_DEV_INITIALIZING);
2461 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2462 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002463 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002464 qlcnic_api_unlock(adapter);
2465 return 1;
2466
2467 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002468 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002469 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002470 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002471
2472 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002473 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002474 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002475 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002476 break;
2477
2478 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002479 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002480 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002481 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002482 break;
2483
2484 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002485 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002486 qlcnic_api_unlock(adapter);
2487 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002488
2489 case QLCNIC_DEV_INITIALIZING:
2490 case QLCNIC_DEV_QUISCENT:
2491 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002492 }
2493
2494 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002495
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002496 do {
2497 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002498 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002499
2500 if (prev_state == QLCNIC_DEV_QUISCENT)
2501 continue;
2502 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002503
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002504 if (!dev_init_timeo) {
2505 dev_err(&adapter->pdev->dev,
2506 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002507 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002508 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002509
2510 if (qlcnic_api_lock(adapter))
2511 return -1;
2512
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002513 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002514 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002515 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002516
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002517 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002518 qlcnic_api_unlock(adapter);
2519
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002520 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002521}
2522
2523static void
2524qlcnic_fwinit_work(struct work_struct *work)
2525{
2526 struct qlcnic_adapter *adapter = container_of(work,
2527 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002528 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002529 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002530
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002531 if (qlcnic_api_lock(adapter))
2532 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002533
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002534 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002535 if (dev_state == QLCNIC_DEV_QUISCENT ||
2536 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002537 qlcnic_api_unlock(adapter);
2538 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2539 FW_POLL_DELAY * 2);
2540 return;
2541 }
2542
Sony Chacko79788452012-12-04 03:33:53 +00002543 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002544 qlcnic_api_unlock(adapter);
2545 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002546 }
2547
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002548 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2549 dev_state == QLCNIC_DEV_READY) {
2550 dev_info(&adapter->pdev->dev, "Detected state change from "
2551 "DEV_NEED_RESET, skipping ack check\n");
2552 goto skip_ack_check;
2553 }
2554
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002555 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002556 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002557 adapter->reset_ack_timeo);
2558 goto skip_ack_check;
2559 }
2560
2561 if (!qlcnic_check_drv_state(adapter)) {
2562skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002563 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002564
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002565 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002566 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2567 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002568 set_bit(__QLCNIC_START_FW, &adapter->state);
2569 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002570 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002571 val = QLC_SHARED_REG_RD32(adapter,
2572 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002573 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002574 QLC_SHARED_REG_WR32(adapter,
2575 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002576 }
2577
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002578 qlcnic_api_unlock(adapter);
2579
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002580 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002581 if (adapter->ahw->fw_dump.enable &&
2582 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002583 QLCDB(adapter, DRV, "Take FW dump\n");
2584 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002585 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002586 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002587 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002588
2589 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002590 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002591 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002592 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002593 return;
2594 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002595 goto err_ret;
2596 }
2597
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002598 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002599
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002600wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002601 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002602 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002603
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002604 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002605 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002606 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002607 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002608 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002609 return;
2610 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002611 case QLCNIC_DEV_FAILED:
2612 break;
2613 default:
2614 qlcnic_schedule_work(adapter,
2615 qlcnic_fwinit_work, FW_POLL_DELAY);
2616 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002617 }
2618
2619err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002620 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2621 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002622 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002623 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002624}
2625
2626static void
2627qlcnic_detach_work(struct work_struct *work)
2628{
2629 struct qlcnic_adapter *adapter = container_of(work,
2630 struct qlcnic_adapter, fw_work.work);
2631 struct net_device *netdev = adapter->netdev;
2632 u32 status;
2633
2634 netif_device_detach(netdev);
2635
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002636 /* Dont grab rtnl lock during Quiscent mode */
2637 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2638 if (netif_running(netdev))
2639 __qlcnic_down(adapter, netdev);
2640 } else
2641 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002642
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002643 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002644
Sony Chacko44f65b22011-08-29 12:50:26 +00002645 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2646 dev_err(&adapter->pdev->dev,
2647 "Detaching the device: peg halt status1=0x%x\n",
2648 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002649
Sony Chacko44f65b22011-08-29 12:50:26 +00002650 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2651 dev_err(&adapter->pdev->dev,
2652 "On board active cooling fan failed. "
2653 "Device has been halted.\n");
2654 dev_err(&adapter->pdev->dev,
2655 "Replace the adapter.\n");
2656 }
2657
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002658 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002659 }
2660
Sony Chacko79788452012-12-04 03:33:53 +00002661 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002662 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002663 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002664 goto err_ret;
2665 }
2666
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002667 /* Dont ack if this instance is the reset owner */
2668 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002669 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2670 dev_err(&adapter->pdev->dev,
2671 "Failed to set driver state,"
2672 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002673 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002674 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002675 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002676
2677 adapter->fw_wait_cnt = 0;
2678
2679 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2680
2681 return;
2682
2683err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002684 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002685 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002686}
2687
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002688/*Transit NPAR state to NON Operational */
2689static void
2690qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2691{
2692 u32 state;
2693
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002694 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002695 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2696 return;
2697
2698 if (qlcnic_api_lock(adapter))
2699 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002700 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2701 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002702 qlcnic_api_unlock(adapter);
2703}
2704
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002705void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002706{
Sritej Velaga646779f2012-02-03 13:45:41 +00002707 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002708
Sritej Velaga646779f2012-02-03 13:45:41 +00002709 qlcnic_xg_set_xg0_mask(xg_val);
2710 qlcnic_xg_set_xg1_mask(xg_val);
2711 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2712 qlcnic_gb_set_gb0_mask(gb_val);
2713 qlcnic_gb_set_gb1_mask(gb_val);
2714 qlcnic_gb_set_gb2_mask(gb_val);
2715 qlcnic_gb_set_gb3_mask(gb_val);
2716 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2717 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2718 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002719 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002720
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002721 if (qlcnic_api_lock(adapter))
2722 return;
2723
Sony Chacko13159182013-01-01 03:20:21 +00002724 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002725
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002726 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00002727 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2728 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002729 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002730 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002731 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002732 }
2733
Sony Chacko13159182013-01-01 03:20:21 +00002734 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2735 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002736 qlcnic_api_unlock(adapter);
2737}
2738
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002739/* Transit to NPAR READY state from NPAR NOT READY state */
2740static void
2741qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2742{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002743 if (qlcnic_api_lock(adapter))
2744 return;
2745
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002746 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2747 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002748 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002749
2750 qlcnic_api_unlock(adapter);
2751}
2752
Sony Chacko13159182013-01-01 03:20:21 +00002753void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2754 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002755{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002756 if (test_bit(__QLCNIC_AER, &adapter->state))
2757 return;
2758
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002759 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00002760 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
2761 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002762}
2763
2764static void
2765qlcnic_attach_work(struct work_struct *work)
2766{
2767 struct qlcnic_adapter *adapter = container_of(work,
2768 struct qlcnic_adapter, fw_work.work);
2769 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002770 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002771
Sony Chacko79788452012-12-04 03:33:53 +00002772 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002773 npar_state = QLC_SHARED_REG_RD32(adapter,
2774 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002775 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2776 qlcnic_clr_all_drv_state(adapter, 0);
2777 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2778 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2779 FW_POLL_DELAY);
2780 else
2781 goto attach;
2782 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2783 return;
2784 }
2785attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002786 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002787 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002788 goto done;
2789
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002790 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002791 }
2792
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002793done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002794 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002795 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002796 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002797 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002798
2799 if (!qlcnic_clr_drv_state(adapter))
2800 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2801 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802}
2803
2804static int
2805qlcnic_check_health(struct qlcnic_adapter *adapter)
2806{
Sony Chacko4e708122010-08-31 17:17:44 +00002807 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002808 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002809
2810 if (qlcnic_check_temp(adapter))
2811 goto detach;
2812
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002813 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002814 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002815
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002816 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002817 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002818 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002819 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002820 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2821 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002822
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002823 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00002824 if (heartbeat != adapter->heartbeat) {
2825 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002826 adapter->fw_fail_cnt = 0;
2827 if (adapter->need_fw_reset)
2828 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002829
Sony Chacko099f7aa2012-12-04 03:33:58 +00002830 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002831 qlcnic_reset_hw_context(adapter);
2832 adapter->netdev->trans_start = jiffies;
2833 }
2834
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002835 return 0;
2836 }
2837
2838 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2839 return 0;
2840
Sritej Velaga032a13c2011-07-29 13:30:27 +00002841 adapter->flags |= QLCNIC_FW_HANG;
2842
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002843 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002844
Sony Chacko099f7aa2012-12-04 03:33:58 +00002845 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002846 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002847
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002848 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002849 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002850 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00002851 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2852 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2853 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2854 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002855 peg_status,
2856 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00002857 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
2858 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
2859 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
2860 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
2861 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00002862 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002863 dev_err(&adapter->pdev->dev,
2864 "Firmware aborted with error code 0x00006700. "
2865 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002866detach:
2867 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
2868 QLCNIC_DEV_NEED_RESET;
2869
Sony Chacko099f7aa2012-12-04 03:33:58 +00002870 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
2871 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002872
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002873 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002874 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
2875 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002876
2877 return 1;
2878}
2879
2880static void
2881qlcnic_fw_poll_work(struct work_struct *work)
2882{
2883 struct qlcnic_adapter *adapter = container_of(work,
2884 struct qlcnic_adapter, fw_work.work);
2885
2886 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2887 goto reschedule;
2888
2889
2890 if (qlcnic_check_health(adapter))
2891 return;
2892
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002893 if (adapter->fhash.fnum)
2894 qlcnic_prune_lb_filters(adapter);
2895
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002896reschedule:
2897 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2898}
2899
Sony Chacko13159182013-01-01 03:20:21 +00002900struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
2901 unsigned int devfn)
2902{
2903 struct pci_dev *dev = NULL;
2904
2905 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
2906 if (pci_domain_nr(dev->bus) == domain &&
2907 (dev->bus->number == bus && dev->devfn == devfn))
2908 return dev;
2909 }
2910 return NULL;
2911}
2912
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002913static int qlcnic_is_first_func(struct pci_dev *pdev)
2914{
2915 struct pci_dev *oth_pdev;
2916 int val = pdev->devfn;
2917
2918 while (val-- > 0) {
2919 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
2920 (pdev->bus), pdev->bus->number,
2921 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002922 if (!oth_pdev)
2923 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002924
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002925 if (oth_pdev->current_state != PCI_D3cold) {
2926 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002927 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002928 }
2929 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002930 }
2931 return 1;
2932}
2933
2934static int qlcnic_attach_func(struct pci_dev *pdev)
2935{
2936 int err, first_func;
2937 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2938 struct net_device *netdev = adapter->netdev;
2939
2940 pdev->error_state = pci_channel_io_normal;
2941
2942 err = pci_enable_device(pdev);
2943 if (err)
2944 return err;
2945
2946 pci_set_power_state(pdev, PCI_D0);
2947 pci_set_master(pdev);
2948 pci_restore_state(pdev);
2949
2950 first_func = qlcnic_is_first_func(pdev);
2951
2952 if (qlcnic_api_lock(adapter))
2953 return -EINVAL;
2954
Sony Chacko79788452012-12-04 03:33:53 +00002955 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002956 adapter->need_fw_reset = 1;
2957 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002958 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2959 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002960 QLCDB(adapter, DRV, "Restarting fw\n");
2961 }
2962 qlcnic_api_unlock(adapter);
2963
Sony Chacko13159182013-01-01 03:20:21 +00002964 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002965 if (err)
2966 return err;
2967
2968 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002969 kfree(adapter->msix_entries);
2970 adapter->msix_entries = NULL;
2971 err = qlcnic_setup_intr(adapter, 0);
2972
2973 if (qlcnic_83xx_check(adapter)) {
2974 err = qlcnic_83xx_setup_mbx_intr(adapter);
2975 if (err) {
2976 dev_err(&adapter->pdev->dev,
2977 "failed to setup mbx interrupt\n");
2978 qlcnic_clr_all_drv_state(adapter, 1);
2979 clear_bit(__QLCNIC_AER, &adapter->state);
2980 goto done;
2981 }
2982 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002983
2984 if (netif_running(netdev)) {
2985 err = qlcnic_attach(adapter);
2986 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002987 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002988 clear_bit(__QLCNIC_AER, &adapter->state);
2989 netif_device_attach(netdev);
2990 return err;
2991 }
2992
2993 err = qlcnic_up(adapter, netdev);
2994 if (err)
2995 goto done;
2996
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002997 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002998 }
2999 done:
3000 netif_device_attach(netdev);
3001 return err;
3002}
3003
3004static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3005 pci_channel_state_t state)
3006{
3007 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3008 struct net_device *netdev = adapter->netdev;
3009
3010 if (state == pci_channel_io_perm_failure)
3011 return PCI_ERS_RESULT_DISCONNECT;
3012
3013 if (state == pci_channel_io_normal)
3014 return PCI_ERS_RESULT_RECOVERED;
3015
3016 set_bit(__QLCNIC_AER, &adapter->state);
3017 netif_device_detach(netdev);
3018
3019 cancel_delayed_work_sync(&adapter->fw_work);
3020
3021 if (netif_running(netdev))
3022 qlcnic_down(adapter, netdev);
3023
Sony Chacko13159182013-01-01 03:20:21 +00003024 if (qlcnic_83xx_check(adapter)) {
3025 if (adapter->flags & QLCNIC_MSIX_ENABLED)
3026 qlcnic_83xx_config_intrpt(adapter, 0);
3027 qlcnic_83xx_free_mbx_intr(adapter);
3028 }
3029
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003030 qlcnic_detach(adapter);
3031 qlcnic_teardown_intr(adapter);
3032
3033 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3034
3035 pci_save_state(pdev);
3036 pci_disable_device(pdev);
3037
3038 return PCI_ERS_RESULT_NEED_RESET;
3039}
3040
3041static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3042{
3043 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3044 PCI_ERS_RESULT_RECOVERED;
3045}
3046
3047static void qlcnic_io_resume(struct pci_dev *pdev)
3048{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003049 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003050 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3051
3052 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003053 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3054 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3055 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003056 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3057 FW_POLL_DELAY);
3058}
3059
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003060static int
3061qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3062{
3063 int err;
3064
3065 err = qlcnic_can_start_firmware(adapter);
3066 if (err)
3067 return err;
3068
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003069 err = qlcnic_check_npar_opertional(adapter);
3070 if (err)
3071 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003072
Rajesh Borundia174240a2010-08-31 17:17:47 +00003073 err = qlcnic_initialize_nic(adapter);
3074 if (err)
3075 return err;
3076
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003077 qlcnic_check_options(adapter);
3078
Rajesh Borundia73733732010-08-31 17:17:50 +00003079 err = qlcnic_set_eswitch_port_config(adapter);
3080 if (err)
3081 return err;
3082
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003083 adapter->need_fw_reset = 0;
3084
3085 return err;
3086}
3087
Sony Chacko319ecf12013-01-01 03:20:22 +00003088int qlcnic_validate_max_rss(u8 max_hw, u8 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003089{
Sony Chacko319ecf12013-01-01 03:20:22 +00003090 u32 max_allowed;
3091
3092 if (max_hw > QLC_MAX_SDS_RINGS) {
3093 max_hw = QLC_MAX_SDS_RINGS;
3094 pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003095 }
3096
Sony Chacko319ecf12013-01-01 03:20:22 +00003097 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3098 num_online_cpus()));
3099 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
3100 pr_info("rss_ring valid range [2 - %x] in powers of 2\n",
3101 max_allowed);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003102 return -EINVAL;
3103 }
3104 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003105}
3106
Sony Chacko319ecf12013-01-01 03:20:22 +00003107int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003108{
Sony Chacko13159182013-01-01 03:20:21 +00003109 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003110 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003111
Sony Chacko319ecf12013-01-01 03:20:22 +00003112 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3113 return -EBUSY;
3114
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003115 netif_device_detach(netdev);
3116 if (netif_running(netdev))
3117 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003118
Sony Chacko319ecf12013-01-01 03:20:22 +00003119 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003120 if (adapter->flags & QLCNIC_MSIX_ENABLED)
3121 qlcnic_83xx_config_intrpt(adapter, 0);
3122 qlcnic_83xx_free_mbx_intr(adapter);
3123 }
3124
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003125 qlcnic_detach(adapter);
3126 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003127 err = qlcnic_setup_intr(adapter, data);
Sony Chacko13159182013-01-01 03:20:21 +00003128 if (err)
3129 dev_err(&adapter->pdev->dev,
3130 "failed setting max_rss; rss disabled\n");
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003131
Sony Chacko13159182013-01-01 03:20:21 +00003132 if (qlcnic_83xx_check(adapter)) {
3133 err = qlcnic_83xx_setup_mbx_intr(adapter);
3134 if (err) {
3135 dev_err(&adapter->pdev->dev,
3136 "failed to setup mbx interrupt\n");
3137 goto done;
3138 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003139 }
3140
3141 if (netif_running(netdev)) {
3142 err = qlcnic_attach(adapter);
3143 if (err)
3144 goto done;
3145 err = __qlcnic_up(adapter, netdev);
3146 if (err)
3147 goto done;
3148 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3149 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003150 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003151 done:
3152 netif_device_attach(netdev);
3153 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3154 return err;
3155}
3156
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003157#ifdef CONFIG_INET
3158
3159#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3160
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003161static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003162qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3163 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003164{
3165 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003166
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003167 indev = in_dev_get(dev);
3168 if (!indev)
3169 return;
3170
3171 for_ifa(indev) {
3172 switch (event) {
3173 case NETDEV_UP:
3174 qlcnic_config_ipaddr(adapter,
3175 ifa->ifa_address, QLCNIC_IP_UP);
3176 break;
3177 case NETDEV_DOWN:
3178 qlcnic_config_ipaddr(adapter,
3179 ifa->ifa_address, QLCNIC_IP_DOWN);
3180 break;
3181 default:
3182 break;
3183 }
3184 } endfor_ifa(indev);
3185
3186 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003187}
3188
Sony Chacko319ecf12013-01-01 03:20:22 +00003189void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003190{
3191 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3192 struct net_device *dev;
3193 u16 vid;
3194
3195 qlcnic_config_indev_addr(adapter, netdev, event);
3196
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003197 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Jiri Pirko223bb152011-07-20 04:54:44 +00003198 dev = __vlan_find_dev_deep(netdev, vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003199 if (!dev)
3200 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003201 qlcnic_config_indev_addr(adapter, dev, event);
3202 }
3203}
3204
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003205static int qlcnic_netdev_event(struct notifier_block *this,
3206 unsigned long event, void *ptr)
3207{
3208 struct qlcnic_adapter *adapter;
3209 struct net_device *dev = (struct net_device *)ptr;
3210
3211recheck:
3212 if (dev == NULL)
3213 goto done;
3214
3215 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3216 dev = vlan_dev_real_dev(dev);
3217 goto recheck;
3218 }
3219
3220 if (!is_qlcnic_netdev(dev))
3221 goto done;
3222
3223 adapter = netdev_priv(dev);
3224
3225 if (!adapter)
3226 goto done;
3227
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003228 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003229 goto done;
3230
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003231 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003232done:
3233 return NOTIFY_DONE;
3234}
3235
3236static int
3237qlcnic_inetaddr_event(struct notifier_block *this,
3238 unsigned long event, void *ptr)
3239{
3240 struct qlcnic_adapter *adapter;
3241 struct net_device *dev;
3242
3243 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3244
3245 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3246
3247recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003248 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003249 goto done;
3250
3251 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3252 dev = vlan_dev_real_dev(dev);
3253 goto recheck;
3254 }
3255
3256 if (!is_qlcnic_netdev(dev))
3257 goto done;
3258
3259 adapter = netdev_priv(dev);
3260
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003261 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003262 goto done;
3263
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003264 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003265 goto done;
3266
3267 switch (event) {
3268 case NETDEV_UP:
3269 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003270
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003271 break;
3272 case NETDEV_DOWN:
3273 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003274
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003275 break;
3276 default:
3277 break;
3278 }
3279
3280done:
3281 return NOTIFY_DONE;
3282}
3283
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003284static struct notifier_block qlcnic_netdev_cb = {
3285 .notifier_call = qlcnic_netdev_event,
3286};
3287
3288static struct notifier_block qlcnic_inetaddr_cb = {
3289 .notifier_call = qlcnic_inetaddr_event,
3290};
3291#else
3292static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003293qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003294{ }
3295#endif
Shahed Shaikh63507592012-11-23 23:56:52 +00003296static struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003297 .error_detected = qlcnic_io_error_detected,
3298 .slot_reset = qlcnic_io_slot_reset,
3299 .resume = qlcnic_io_resume,
3300};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003301
3302static struct pci_driver qlcnic_driver = {
3303 .name = qlcnic_driver_name,
3304 .id_table = qlcnic_pci_tbl,
3305 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003306 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003307#ifdef CONFIG_PM
3308 .suspend = qlcnic_suspend,
3309 .resume = qlcnic_resume,
3310#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003311 .shutdown = qlcnic_shutdown,
3312 .err_handler = &qlcnic_err_handler
3313
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003314};
3315
3316static int __init qlcnic_init_module(void)
3317{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003318 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003319
3320 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3321
3322#ifdef CONFIG_INET
3323 register_netdevice_notifier(&qlcnic_netdev_cb);
3324 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3325#endif
3326
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003327 ret = pci_register_driver(&qlcnic_driver);
3328 if (ret) {
3329#ifdef CONFIG_INET
3330 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3331 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3332#endif
3333 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003334
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003335 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003336}
3337
3338module_init(qlcnic_init_module);
3339
3340static void __exit qlcnic_exit_module(void)
3341{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003342 pci_unregister_driver(&qlcnic_driver);
3343
3344#ifdef CONFIG_INET
3345 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3346 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3347#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003348}
3349
3350module_exit(qlcnic_exit_module);