blob: d132765f92af34ea1f419a220fdf9b8e58ba1105 [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
Sritej Velaga40839129f2010-12-02 20:41:56 +00002 * QLogic qlcnic NIC Driver
Jitendra Kalsaria577ae392013-02-04 12:33:07 +00003 * Copyright (c) 2009-2013 QLogic Corporation
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004 *
Sritej Velaga40839129f2010-12-02 20:41:56 +00005 * See LICENSE.qlcnic for copyright and licensing details.
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00006 */
7
8#include <linux/vmalloc.h>
9#include <linux/interrupt.h>
10
11#include "qlcnic.h"
Rajesh Borundia02feda12013-03-29 05:46:33 +000012#include "qlcnic_sriov.h"
Himanshu Madhania15ebd32013-01-01 03:20:18 +000013#include "qlcnic_hw.h"
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000014
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000015#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000016#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000017#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000018#include <net/ip.h>
19#include <linux/ipv6.h>
20#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000021#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000022#include <linux/log2.h>
Stephen Rothwell47caf252013-01-02 17:23:53 +000023#include <linux/pci.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000024
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000025MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000026MODULE_LICENSE("GPL");
27MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
28MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
29
30char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000031static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
32 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000033
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000034static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000035module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000036MODULE_PARM_DESC(qlcnic_mac_learn,
37 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000038
Sony Chacko629263a2013-01-01 04:11:55 +000039int qlcnic_use_msi = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000040MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000041module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000042
Sony Chacko629263a2013-01-01 04:11:55 +000043int qlcnic_use_msi_x = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000044MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000045module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000046
Sony Chacko629263a2013-01-01 04:11:55 +000047int qlcnic_auto_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000048MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000049module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000050
Sony Chacko629263a2013-01-01 04:11:55 +000051int qlcnic_load_fw_file;
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000052MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
Sony Chacko099f7aa2012-12-04 03:33:58 +000053module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000054
Sony Chacko629263a2013-01-01 04:11:55 +000055int qlcnic_config_npars;
amit salechab11a25a2011-01-10 00:15:23 +000056module_param(qlcnic_config_npars, int, 0444);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000057MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
58
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000059static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050060static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000061static int qlcnic_open(struct net_device *netdev);
62static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000063static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000064static void qlcnic_attach_work(struct work_struct *work);
65static void qlcnic_fwinit_work(struct work_struct *work);
66static void qlcnic_fw_poll_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000067#ifdef CONFIG_NET_POLL_CONTROLLER
68static void qlcnic_poll_controller(struct net_device *netdev);
69#endif
70
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000071static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000072static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000073static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
74
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000075static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000076static irqreturn_t qlcnic_intr(int irq, void *data);
77static irqreturn_t qlcnic_msi_intr(int irq, void *data);
78static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000079static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000080
81static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000082static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000083
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000084static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000085static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000086static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Rajesh Borundia0325d692010-08-19 05:08:26 +000087static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
88 struct qlcnic_esw_func_cfg *);
Patrick McHardy80d5c362013-04-19 02:04:28 +000089static int qlcnic_vlan_rx_add(struct net_device *, __be16, u16);
90static int qlcnic_vlan_rx_del(struct net_device *, __be16, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000091
Sony Chackobff57d82012-12-04 03:33:56 +000092#define QLCNIC_IS_TSO_CAPABLE(adapter) \
93 ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO)
94
Sony Chacko13159182013-01-01 03:20:21 +000095static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
96{
97 struct qlcnic_hardware_context *ahw = adapter->ahw;
98
99 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
100 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
101 else
102 return 1;
103}
104
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000105/* PCI Device ID Table */
106#define ENTRY(device) \
107 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
108 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
109
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000110static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000112 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000113 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000114 {0,}
115};
116
117MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
118
119
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000120inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000121{
122 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000123}
124
125static const u32 msi_tgt_status[8] = {
126 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
127 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
128 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
129 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
130};
131
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000132static const u32 qlcnic_reg_tbl[] = {
133 0x1B20A8, /* PEG_HALT_STAT1 */
134 0x1B20AC, /* PEG_HALT_STAT2 */
135 0x1B20B0, /* FW_HEARTBEAT */
136 0x1B2100, /* LOCK ID */
137 0x1B2128, /* FW_CAPABILITIES */
138 0x1B2138, /* drv active */
139 0x1B2140, /* dev state */
140 0x1B2144, /* drv state */
141 0x1B2148, /* drv scratch */
142 0x1B214C, /* dev partition info */
143 0x1B2174, /* drv idc ver */
144 0x1B2150, /* fw version major */
145 0x1B2154, /* fw version minor */
146 0x1B2158, /* fw version sub */
147 0x1B219C, /* npar state */
148 0x1B21FC, /* FW_IMG_VALID */
149 0x1B2250, /* CMD_PEG_STATE */
150 0x1B233C, /* RCV_PEG_STATE */
151 0x1B23B4, /* ASIC TEMP */
152 0x1B216C, /* FW api */
153 0x1B2170, /* drv op mode */
154 0x13C010, /* flash lock */
155 0x13C014, /* flash unlock */
156};
157
Sony Chacko22999792012-12-04 03:33:55 +0000158static const struct qlcnic_board_info qlcnic_boards[] = {
159 {0x1077, 0x8020, 0x1077, 0x203,
160 "8200 Series Single Port 10GbE Converged Network Adapter"
161 "(TCP/IP Networking)"},
162 {0x1077, 0x8020, 0x1077, 0x207,
163 "8200 Series Dual Port 10GbE Converged Network Adapter"
164 "(TCP/IP Networking)"},
165 {0x1077, 0x8020, 0x1077, 0x20b,
166 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"},
167 {0x1077, 0x8020, 0x1077, 0x20c,
168 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"},
169 {0x1077, 0x8020, 0x1077, 0x20f,
170 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"},
171 {0x1077, 0x8020, 0x103c, 0x3733,
172 "NC523SFP 10Gb 2-port Server Adapter"},
173 {0x1077, 0x8020, 0x103c, 0x3346,
174 "CN1000Q Dual Port Converged Network Adapter"},
175 {0x1077, 0x8020, 0x1077, 0x210,
176 "QME8242-k 10GbE Dual Port Mezzanine Card"},
177 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"},
178};
179
180#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
Sony Chacko319ecf12013-01-01 03:20:22 +0000181#define QLC_MAX_SDS_RINGS 8
Sony Chacko22999792012-12-04 03:33:55 +0000182
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000183static const
184struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
185
Sony Chackoc70001a2012-11-28 04:34:26 +0000186int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000187{
188 int size = sizeof(struct qlcnic_host_sds_ring) * count;
189
190 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
191
Eric Dumazet807540b2010-09-23 05:40:09 +0000192 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000193}
194
Sony Chackoc70001a2012-11-28 04:34:26 +0000195void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000196{
197 if (recv_ctx->sds_rings != NULL)
198 kfree(recv_ctx->sds_rings);
199
200 recv_ctx->sds_rings = NULL;
201}
202
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000203int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000204{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000205 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000206 struct net_device *netdev = adapter->netdev;
207 struct pci_dev *pdev = adapter->pdev;
208
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000209 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000210 return -EIO;
211
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000212 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000213 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
214
215 /* set station address */
216
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000217 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000218 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
219 netdev->dev_addr);
220
221 return 0;
222}
223
224static int qlcnic_set_mac(struct net_device *netdev, void *p)
225{
226 struct qlcnic_adapter *adapter = netdev_priv(netdev);
227 struct sockaddr *addr = p;
228
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000229 if (qlcnic_sriov_vf_check(adapter))
230 return -EINVAL;
231
Rajesh Borundia73733732010-08-31 17:17:50 +0000232 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
233 return -EOPNOTSUPP;
234
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000235 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000236 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000237
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000238 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000239 netif_device_detach(netdev);
240 qlcnic_napi_disable(adapter);
241 }
242
243 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
244 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
245 qlcnic_set_multi(adapter->netdev);
246
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000247 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000248 netif_device_attach(netdev);
249 qlcnic_napi_enable(adapter);
250 }
251 return 0;
252}
253
Vlad Yasevich1690be62013-02-13 12:00:18 +0000254static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
255 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000256{
257 struct qlcnic_adapter *adapter = netdev_priv(netdev);
258 int err = -EOPNOTSUPP;
259
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000260 if (!adapter->fdb_mac_learn)
261 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000262
263 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
264 if (is_unicast_ether_addr(addr))
265 err = qlcnic_nic_del_mac(adapter, addr);
266 else if (is_multicast_ether_addr(addr))
267 err = dev_mc_del(netdev, addr);
268 else
269 err = -EINVAL;
270 }
271 return err;
272}
273
274static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
275 struct net_device *netdev,
276 const unsigned char *addr, u16 flags)
277{
278 struct qlcnic_adapter *adapter = netdev_priv(netdev);
279 int err = 0;
280
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000281 if (!adapter->fdb_mac_learn)
282 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000283
284 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
285 pr_info("%s: FDB e-switch is not enabled\n", __func__);
286 return -EOPNOTSUPP;
287 }
288
289 if (ether_addr_equal(addr, adapter->mac_addr))
290 return err;
291
292 if (is_unicast_ether_addr(addr))
293 err = qlcnic_nic_add_mac(adapter, addr);
294 else if (is_multicast_ether_addr(addr))
295 err = dev_mc_add_excl(netdev, addr);
296 else
297 err = -EINVAL;
298
299 return err;
300}
301
302static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
303 struct net_device *netdev, int idx)
304{
305 struct qlcnic_adapter *adapter = netdev_priv(netdev);
306
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000307 if (!adapter->fdb_mac_learn)
308 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000309
310 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
311 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
312
313 return idx;
314}
315
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000316static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
317{
318 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
319 usleep_range(10000, 11000);
320
321 cancel_delayed_work_sync(&adapter->fw_work);
322}
323
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000324static const struct net_device_ops qlcnic_netdev_ops = {
325 .ndo_open = qlcnic_open,
326 .ndo_stop = qlcnic_close,
327 .ndo_start_xmit = qlcnic_xmit_frame,
328 .ndo_get_stats = qlcnic_get_stats,
329 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000330 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000331 .ndo_set_mac_address = qlcnic_set_mac,
332 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000333 .ndo_fix_features = qlcnic_fix_features,
334 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000335 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000336 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
337 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000338 .ndo_fdb_add = qlcnic_fdb_add,
339 .ndo_fdb_del = qlcnic_fdb_del,
340 .ndo_fdb_dump = qlcnic_fdb_dump,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000341#ifdef CONFIG_NET_POLL_CONTROLLER
342 .ndo_poll_controller = qlcnic_poll_controller,
343#endif
344};
345
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000346static const struct net_device_ops qlcnic_netdev_failed_ops = {
347 .ndo_open = qlcnic_open,
348};
349
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000350static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000351 .config_bridged_mode = qlcnic_config_bridged_mode,
352 .config_led = qlcnic_82xx_config_led,
353 .start_firmware = qlcnic_82xx_start_firmware,
354 .request_reset = qlcnic_82xx_dev_request_reset,
355 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
356 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000357 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000358 .config_ipaddr = qlcnic_82xx_config_ipaddr,
359 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000360};
361
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000362struct qlcnic_nic_template qlcnic_vf_ops = {
363 .config_bridged_mode = qlcnicvf_config_bridged_mode,
364 .config_led = qlcnicvf_config_led,
365 .start_firmware = qlcnicvf_start_firmware
366};
367
368static struct qlcnic_hardware_ops qlcnic_hw_ops = {
369 .read_crb = qlcnic_82xx_read_crb,
370 .write_crb = qlcnic_82xx_write_crb,
371 .read_reg = qlcnic_82xx_hw_read_wx_2M,
372 .write_reg = qlcnic_82xx_hw_write_wx_2M,
373 .get_mac_address = qlcnic_82xx_get_mac_address,
374 .setup_intr = qlcnic_82xx_setup_intr,
375 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
376 .mbx_cmd = qlcnic_82xx_issue_cmd,
377 .get_func_no = qlcnic_82xx_get_func_no,
378 .api_lock = qlcnic_82xx_api_lock,
379 .api_unlock = qlcnic_82xx_api_unlock,
380 .add_sysfs = qlcnic_82xx_add_sysfs,
381 .remove_sysfs = qlcnic_82xx_remove_sysfs,
382 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
383 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
384 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000385 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
386 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000387 .setup_link_event = qlcnic_82xx_linkevent_request,
388 .get_nic_info = qlcnic_82xx_get_nic_info,
389 .get_pci_info = qlcnic_82xx_get_pci_info,
390 .set_nic_info = qlcnic_82xx_set_nic_info,
391 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
392 .napi_enable = qlcnic_82xx_napi_enable,
393 .napi_disable = qlcnic_82xx_napi_disable,
394 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
395 .config_rss = qlcnic_82xx_config_rss,
396 .config_hw_lro = qlcnic_82xx_config_hw_lro,
397 .config_loopback = qlcnic_82xx_set_lb_mode,
398 .clear_loopback = qlcnic_82xx_clear_lb_mode,
399 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
400 .change_l2_filter = qlcnic_82xx_change_filter,
401 .get_board_info = qlcnic_82xx_get_board_info,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000402};
403
Sony Chacko7f9664522013-01-01 03:20:19 +0000404int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000405{
406 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000407 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000408 int max_tx_rings, tx_vector;
409
410 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
411 max_tx_rings = 0;
412 tx_vector = 0;
413 } else {
414 max_tx_rings = adapter->max_drv_tx_rings;
415 tx_vector = 1;
416 }
Sony Chacko13159182013-01-01 03:20:21 +0000417
418 if (!adapter->msix_entries) {
419 adapter->msix_entries = kcalloc(num_msix,
420 sizeof(struct msix_entry),
421 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000422 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000423 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000424 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000425
426 adapter->max_sds_rings = 1;
427 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000428
Sony Chacko79788452012-12-04 03:33:53 +0000429 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000430 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000431 for (i = 0; i < num_msix; i++)
432 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000433 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
434 if (err == 0) {
435 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000436 if (qlcnic_83xx_check(adapter)) {
437 adapter->ahw->num_msix = num_msix;
438 /* subtract mail box and tx ring vectors */
Sony Chacko13159182013-01-01 03:20:21 +0000439 adapter->max_sds_rings = num_msix -
440 max_tx_rings - 1;
441 } else {
442 adapter->max_sds_rings = num_msix;
443 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000444 dev_info(&pdev->dev, "using msi-x interrupts\n");
445 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000446 } else if (err > 0) {
447 dev_info(&pdev->dev,
448 "Unable to allocate %d MSI-X interrupt vectors\n",
449 num_msix);
450 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000451 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000452 return err;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000453 err -= (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000454 num_msix = rounddown_pow_of_two(err);
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000455 num_msix += (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000456 } else {
457 num_msix = rounddown_pow_of_two(err);
458 }
459
460 if (num_msix) {
461 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000462 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000463 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000464 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000465 }
466 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000467 dev_info(&pdev->dev,
468 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000469 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000470 }
471 }
Sony Chacko13159182013-01-01 03:20:21 +0000472
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000473 return err;
474}
475
Manish chopra9a97e702013-01-25 10:20:37 +0000476static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000477{
Manish chopra9a97e702013-01-25 10:20:37 +0000478 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000479 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000480 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000481 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000482 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000483
Sony Chacko099f7aa2012-12-04 03:33:58 +0000484 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000485 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000486 offset = msi_tgt_status[adapter->ahw->pci_func];
487 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
488 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000489 dev_info(&pdev->dev, "using msi interrupts\n");
490 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000491 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000492 }
Manish chopra9a97e702013-01-25 10:20:37 +0000493 if (qlcnic_use_msi || qlcnic_use_msi_x)
494 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000495
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000496 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000497 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000498 offset = legacy_intrp->tgt_status_reg;
499 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
500 mask_reg = legacy_intrp->tgt_mask_reg;
501 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
502 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
503 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000504 dev_info(&pdev->dev, "using legacy interrupts\n");
505 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000506 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000507}
508
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000509int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000510{
Manish chopra9a97e702013-01-25 10:20:37 +0000511 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000512
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000513 if (!num_intr)
514 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
515
516 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000517 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000518 num_intr));
519 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000520 num_msix = 1;
521
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000522 err = qlcnic_enable_msix(adapter, num_msix);
523 if (err == -ENOMEM || !err)
524 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000525
Manish chopra9a97e702013-01-25 10:20:37 +0000526 err = qlcnic_enable_msi_legacy(adapter);
527 if (!err)
528 return err;
529
530 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000531}
Sony Chacko13159182013-01-01 03:20:21 +0000532
Sony Chacko319ecf12013-01-01 03:20:22 +0000533void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000534{
535 if (adapter->flags & QLCNIC_MSIX_ENABLED)
536 pci_disable_msix(adapter->pdev);
537 if (adapter->flags & QLCNIC_MSI_ENABLED)
538 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000539
540 kfree(adapter->msix_entries);
541 adapter->msix_entries = NULL;
542
543 if (adapter->ahw->intr_tbl) {
544 vfree(adapter->ahw->intr_tbl);
545 adapter->ahw->intr_tbl = NULL;
546 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000547}
548
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000549static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000550{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000551 if (ahw->pci_base0 != NULL)
552 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000553}
554
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000555static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
556{
557 struct qlcnic_pci_info *pci_info;
558 int ret;
559
560 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
561 switch (adapter->ahw->port_type) {
562 case QLCNIC_GBE:
563 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
564 break;
565 case QLCNIC_XGBE:
566 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
567 break;
568 }
569 return 0;
570 }
571
572 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
573 return 0;
574
575 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
576 if (!pci_info)
577 return -ENOMEM;
578
579 ret = qlcnic_get_pci_info(adapter, pci_info);
580 kfree(pci_info);
581 return ret;
582}
Sony Chackod71170f2013-01-01 03:20:26 +0000583
584int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000585{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000586 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000587 int i, ret = 0, j = 0;
588 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000589 u8 pfn;
590
Dan Carpentere88db3b2010-08-09 21:49:36 +0000591 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
592 if (!pci_info)
593 return -ENOMEM;
594
Sony Chackobff57d82012-12-04 03:33:56 +0000595 ret = qlcnic_get_pci_info(adapter, pci_info);
596 if (ret)
597 goto err_pci_info;
598
599 act_pci_func = adapter->ahw->act_pci_func;
600
Dan Carpenterca315ac2010-08-09 21:47:56 +0000601 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000602 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000603 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000604 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000605 goto err_pci_info;
606 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000607
Dan Carpenterca315ac2010-08-09 21:47:56 +0000608 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000609 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
610 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000611 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000612 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000613 }
614
Dan Carpenterca315ac2010-08-09 21:47:56 +0000615 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
616 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000617
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000618 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000619 ret = QL_STATUS_INVALID_PARAM;
620 goto err_eswitch;
621 }
Sony Chackobff57d82012-12-04 03:33:56 +0000622
623 if (!pci_info[i].active ||
624 (pci_info[i].type != QLCNIC_TYPE_NIC))
625 continue;
626
627 adapter->npars[j].pci_func = pfn;
628 adapter->npars[j].active = (u8)pci_info[i].active;
629 adapter->npars[j].type = (u8)pci_info[i].type;
630 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
631 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
632 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
633 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000634 }
635
Sony Chacko13159182013-01-01 03:20:21 +0000636 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000637 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000638 if (qlcnic_83xx_check(adapter))
639 qlcnic_enable_eswitch(adapter, i, 1);
640 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000641
Dan Carpentere88db3b2010-08-09 21:49:36 +0000642 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000643 return 0;
644
645err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000646 kfree(adapter->eswitch);
647 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000648err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000649 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000650 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000651err_pci_info:
652 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000653
654 return ret;
655}
656
657static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000658qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
659{
660 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000661 int i, ret = 1;
662 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000663 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000664
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000665 ret = qlcnic_api_lock(adapter);
666 if (ret)
667 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000668
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000669 if (qlcnic_config_npars) {
Sony Chackobff57d82012-12-04 03:33:56 +0000670 for (i = 0; i < ahw->act_pci_func; i++) {
671 id = adapter->npars[i].pci_func;
672 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000673 continue;
674 data |= (qlcnic_config_npars &
675 QLC_DEV_SET_DRV(0xf, id));
676 }
677 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000678 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d82012-12-04 03:33:56 +0000679 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000680 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d82012-12-04 03:33:56 +0000681 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000682 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000683 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000684 qlcnic_api_unlock(adapter);
685err_lock:
686 return ret;
687}
688
Sony Chacko13159182013-01-01 03:20:21 +0000689static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
690 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000691{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000692 u32 op_mode, priv_level;
693
694 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000695 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
696 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000697
698 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000699 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000700
701 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000702 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000703 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000704 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000705 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000706 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000707
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000708 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000709 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000710 dev_info(&adapter->pdev->dev,
711 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000712 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000713 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000714 } else
715 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000716}
717
Sony Chacko15087c22012-12-04 03:33:54 +0000718#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000719#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000720static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000721{
Sony Chacko15087c22012-12-04 03:33:54 +0000722 switch (dev_id) {
723 case PCI_DEVICE_ID_QLOGIC_QLE824X:
724 *bar = QLCNIC_82XX_BAR0_LENGTH;
725 break;
Sony Chacko13159182013-01-01 03:20:21 +0000726 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000727 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +0000728 *bar = QLCNIC_83XX_BAR0_LENGTH;
729 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000730 default:
731 *bar = 0;
732 }
733}
734
735static int qlcnic_setup_pci_map(struct pci_dev *pdev,
736 struct qlcnic_hardware_context *ahw)
737{
738 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000739 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000740 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000741
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000742 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000743 mem_len = pci_resource_len(pdev, 0);
744
Sony Chacko15087c22012-12-04 03:33:54 +0000745 qlcnic_get_bar_length(pdev->device, &bar0_len);
746 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000747
748 mem_ptr0 = pci_ioremap_bar(pdev, 0);
749 if (mem_ptr0 == NULL) {
750 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
751 return -EIO;
752 }
753 pci_len0 = mem_len;
754 } else {
755 return -EIO;
756 }
757
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000758 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000759
Sony Chacko15087c22012-12-04 03:33:54 +0000760 ahw->pci_base0 = mem_ptr0;
761 ahw->pci_len0 = pci_len0;
762 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
763 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000764
765 return 0;
766}
767
Sony Chacko22999792012-12-04 03:33:55 +0000768static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000769{
770 struct pci_dev *pdev = adapter->pdev;
771 int i, found = 0;
772
773 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
774 if (qlcnic_boards[i].vendor == pdev->vendor &&
775 qlcnic_boards[i].device == pdev->device &&
776 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
777 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000778 sprintf(name, "%pM: %s" ,
779 adapter->mac_addr,
780 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000781 found = 1;
782 break;
783 }
784
785 }
786
787 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000788 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000789}
790
791static void
792qlcnic_check_options(struct qlcnic_adapter *adapter)
793{
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000794 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000795 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000796 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000797 struct qlcnic_hardware_context *ahw = adapter->ahw;
798 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000799
800 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000801
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000802 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
803 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
804 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000805
806 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
807
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000808 err = qlcnic_get_board_info(adapter);
809 if (err) {
810 dev_err(&pdev->dev, "Error getting board config info.\n");
811 return;
812 }
813 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +0000814 if (fw_dump->tmpl_hdr == NULL ||
815 adapter->fw_version > prev_fw_version) {
816 if (fw_dump->tmpl_hdr)
817 vfree(fw_dump->tmpl_hdr);
818 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
819 dev_info(&pdev->dev,
820 "Supports FW dump capability\n");
821 }
822 }
823
Sony Chacko13159182013-01-01 03:20:21 +0000824 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
825 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
826
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000827 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000828 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
829 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
830 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
831 } else {
832 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
833 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
834 }
835
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000836 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000837 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
838
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000839 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000840 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
841 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000842 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
843 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000844 }
845
Sony Chacko099f7aa2012-12-04 03:33:58 +0000846 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000847
848 adapter->num_txd = MAX_CMD_DESCRIPTORS;
849
Sony Chacko251b0362010-08-19 05:08:24 +0000850 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000851}
852
Rajesh Borundia174240a2010-08-31 17:17:47 +0000853static int
854qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
855{
856 int err;
857 struct qlcnic_info nic_info;
858
Sony Chackobff57d82012-12-04 03:33:56 +0000859 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000860 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000861 if (err)
862 return err;
863
Sony Chacko79788452012-12-04 03:33:53 +0000864 adapter->ahw->physical_port = (u8)nic_info.phys_port;
865 adapter->ahw->switch_mode = nic_info.switch_mode;
866 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
867 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
868 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +0000869
870 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
871 u32 temp;
872 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
873 adapter->ahw->capabilities2 = temp;
874 }
Sony Chacko79788452012-12-04 03:33:53 +0000875 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
876 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000877
Sony Chacko13159182013-01-01 03:20:21 +0000878 /* Disable NPAR for 83XX */
879 if (qlcnic_83xx_check(adapter))
880 return err;
881
Sony Chacko79788452012-12-04 03:33:53 +0000882 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +0000883 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
884 else
885 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
886
887 return err;
888}
889
Sony Chackoec079a02012-11-28 04:34:28 +0000890void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
891 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000892{
893 if (esw_cfg->discard_tagged)
894 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
895 else
896 adapter->flags |= QLCNIC_TAGGING_ENABLED;
897
898 if (esw_cfg->vlan_id)
899 adapter->pvid = esw_cfg->vlan_id;
900 else
901 adapter->pvid = 0;
902}
903
Jiri Pirko8e586132011-12-08 19:52:37 -0500904static int
Patrick McHardy80d5c362013-04-19 02:04:28 +0000905qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000906{
907 struct qlcnic_adapter *adapter = netdev_priv(netdev);
908 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500909 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000910}
911
Jiri Pirko8e586132011-12-08 19:52:37 -0500912static int
Patrick McHardy80d5c362013-04-19 02:04:28 +0000913qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000914{
915 struct qlcnic_adapter *adapter = netdev_priv(netdev);
916
917 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
918 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500919 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000920}
921
Sony Chackoec079a02012-11-28 04:34:28 +0000922void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
923 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000924{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000925 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
926 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000927
928 if (esw_cfg->mac_anti_spoof)
929 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000930
Rajesh Borundia73733732010-08-31 17:17:50 +0000931 if (!esw_cfg->mac_override)
932 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
933
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000934 if (!esw_cfg->promisc_mode)
935 adapter->flags |= QLCNIC_PROMISC_DISABLED;
936
Rajesh Borundia0325d692010-08-19 05:08:26 +0000937 qlcnic_set_netdev_features(adapter, esw_cfg);
938}
939
Sony Chackod71170f2013-01-01 03:20:26 +0000940int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000941{
942 struct qlcnic_esw_func_cfg esw_cfg;
943
944 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
945 return 0;
946
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000947 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000948 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
949 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000950 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000951 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
952
953 return 0;
954}
955
956static void
957qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
958 struct qlcnic_esw_func_cfg *esw_cfg)
959{
960 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +0000961 unsigned long features, vlan_features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000962
Sony Chacko13159182013-01-01 03:20:21 +0000963 if (qlcnic_83xx_check(adapter))
964 return;
965
Sony Chacko7e38d042013-01-01 03:20:28 +0000966 features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
967 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000968 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Sony Chacko13159182013-01-01 03:20:21 +0000969 NETIF_F_IPV6_CSUM);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000970
Sony Chacko13159182013-01-01 03:20:21 +0000971 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000972 features |= (NETIF_F_TSO | NETIF_F_TSO6);
973 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
974 }
Rajesh Borundiab56421d2011-04-01 14:28:31 +0000975
976 if (netdev->features & NETIF_F_LRO)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000977 features |= NETIF_F_LRO;
978
979 if (esw_cfg->offload_flags & BIT_0) {
980 netdev->features |= features;
Sony Chacko13159182013-01-01 03:20:21 +0000981 adapter->rx_csum = 1;
Sony Chacko7e38d042013-01-01 03:20:28 +0000982 if (!(esw_cfg->offload_flags & BIT_1)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000983 netdev->features &= ~NETIF_F_TSO;
Sony Chacko7e38d042013-01-01 03:20:28 +0000984 features &= ~NETIF_F_TSO;
985 }
986 if (!(esw_cfg->offload_flags & BIT_2)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000987 netdev->features &= ~NETIF_F_TSO6;
Sony Chacko7e38d042013-01-01 03:20:28 +0000988 features &= ~NETIF_F_TSO6;
989 }
Rajesh Borundia0325d692010-08-19 05:08:26 +0000990 } else {
991 netdev->features &= ~features;
Sony Chacko7e38d042013-01-01 03:20:28 +0000992 features &= ~features;
Sony Chacko13159182013-01-01 03:20:21 +0000993 adapter->rx_csum = 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000994 }
995
996 netdev->vlan_features = (features & vlan_features);
997}
998
999static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001000qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1001{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001002 u32 op_mode, priv_level;
1003 int err = 0;
1004
Rajesh Borundia174240a2010-08-31 17:17:47 +00001005 err = qlcnic_initialize_nic(adapter);
1006 if (err)
1007 return err;
1008
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001009 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1010 return 0;
1011
Sony Chacko13159182013-01-01 03:20:21 +00001012 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001013 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001014
1015 if (op_mode == QLC_DEV_DRV_DEFAULT)
1016 priv_level = QLCNIC_MGMT_FUNC;
1017 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001018 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001019
Rajesh Borundia174240a2010-08-31 17:17:47 +00001020 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001021 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001022 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001023 err = qlcnic_init_pci_info(adapter);
1024 if (err)
1025 return err;
1026 /* Set privilege level for other functions */
1027 qlcnic_set_function_modes(adapter);
1028 dev_info(&adapter->pdev->dev,
1029 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001030 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001031 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001032 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001033 dev_info(&adapter->pdev->dev,
1034 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001035 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001036 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001037 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001038
1039 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1040
1041 return err;
1042}
1043
Sony Chackod71170f2013-01-01 03:20:26 +00001044int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001045{
1046 struct qlcnic_esw_func_cfg esw_cfg;
1047 struct qlcnic_npar_info *npar;
1048 u8 i;
1049
Rajesh Borundia174240a2010-08-31 17:17:47 +00001050 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001051 return 0;
1052
Sony Chackobff57d82012-12-04 03:33:56 +00001053 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +00001054 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001055 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001056 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001057 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001058 if (qlcnic_82xx_check(adapter)) {
1059 esw_cfg.offload_flags = BIT_0;
1060 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1061 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1062 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001063 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1064 return -EIO;
1065 npar = &adapter->npars[i];
1066 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001067 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001068 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1069 npar->discard_tagged = esw_cfg.discard_tagged;
1070 npar->promisc_mode = esw_cfg.promisc_mode;
1071 npar->offload_flags = esw_cfg.offload_flags;
1072 }
1073
1074 return 0;
1075}
1076
Sony Chacko13159182013-01-01 03:20:21 +00001077
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001078static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001079qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1080 struct qlcnic_npar_info *npar, int pci_func)
1081{
1082 struct qlcnic_esw_func_cfg esw_cfg;
1083 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1084 esw_cfg.pci_func = pci_func;
1085 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001086 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001087 esw_cfg.discard_tagged = npar->discard_tagged;
1088 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1089 esw_cfg.offload_flags = npar->offload_flags;
1090 esw_cfg.promisc_mode = npar->promisc_mode;
1091 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1092 return -EIO;
1093
1094 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1095 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1096 return -EIO;
1097
1098 return 0;
1099}
1100
Sony Chackod71170f2013-01-01 03:20:26 +00001101int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001102{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001103 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001104 struct qlcnic_npar_info *npar;
1105 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001106 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001107
Sony Chackobff57d82012-12-04 03:33:56 +00001108 if (qlcnic_82xx_check(adapter))
1109 if (!adapter->need_fw_reset)
1110 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001111
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001112 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001113 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001114 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001115 pci_func = npar->pci_func;
1116 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001117 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001118 if (err)
1119 return err;
1120 nic_info.min_tx_bw = npar->min_bw;
1121 nic_info.max_tx_bw = npar->max_bw;
1122 err = qlcnic_set_nic_info(adapter, &nic_info);
1123 if (err)
1124 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001125
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001126 if (npar->enable_pm) {
1127 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001128 npar->dest_npar, 1,
1129 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001130 if (err)
1131 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001132 }
Sony Chackobff57d82012-12-04 03:33:56 +00001133 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001134 if (err)
1135 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001136 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001137 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001138}
1139
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001140static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1141{
1142 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1143 u32 npar_state;
1144
Sony Chacko79788452012-12-04 03:33:53 +00001145 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001146 return 0;
1147
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001148 npar_state = QLC_SHARED_REG_RD32(adapter,
1149 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001150 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1151 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001152 npar_state = QLC_SHARED_REG_RD32(adapter,
1153 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001154 }
1155 if (!npar_opt_timeo) {
1156 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001157 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001158 return -EIO;
1159 }
1160 return 0;
1161}
1162
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001163static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001164qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1165{
1166 int err;
1167
1168 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001169 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001170 return 0;
1171
1172 err = qlcnic_set_default_offload_settings(adapter);
1173 if (err)
1174 return err;
1175
1176 err = qlcnic_reset_npar_config(adapter);
1177 if (err)
1178 return err;
1179
1180 qlcnic_dev_set_npar_ready(adapter);
1181
1182 return err;
1183}
1184
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001185int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001186{
Sony Chackod4066832010-08-19 05:08:31 +00001187 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001188
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001189 err = qlcnic_can_start_firmware(adapter);
1190 if (err < 0)
1191 return err;
1192 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001193 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001194
Sony Chacko099f7aa2012-12-04 03:33:58 +00001195 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001196 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001197 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001198 err = qlcnic_check_flash_fw_ver(adapter);
1199 if (err)
schacko8f891382010-06-17 02:56:40 +00001200 goto err_out;
1201
Sony Chacko79788452012-12-04 03:33:53 +00001202 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001203 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001204
1205 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001206 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001207 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001208
Sony Chackod4066832010-08-19 05:08:31 +00001209 err = qlcnic_pinit_from_rom(adapter);
1210 if (err)
1211 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001212
1213 err = qlcnic_load_firmware(adapter);
1214 if (err)
1215 goto err_out;
1216
1217 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001218 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001219
Sony Chackod4066832010-08-19 05:08:31 +00001220check_fw_status:
1221 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001222 if (err)
1223 goto err_out;
1224
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001225 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001226 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001227 err = qlcnic_check_eswitch_mode(adapter);
1228 if (err) {
1229 dev_err(&adapter->pdev->dev,
1230 "Memory allocation failed for eswitch\n");
1231 goto err_out;
1232 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001233 err = qlcnic_set_mgmt_operations(adapter);
1234 if (err)
1235 goto err_out;
1236
1237 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001238 adapter->need_fw_reset = 0;
1239
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001240 qlcnic_release_firmware(adapter);
1241 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001242
1243err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001244 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001245 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001246
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001247 qlcnic_release_firmware(adapter);
1248 return err;
1249}
1250
1251static int
1252qlcnic_request_irq(struct qlcnic_adapter *adapter)
1253{
1254 irq_handler_t handler;
1255 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001256 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001257 int err, ring;
1258
1259 unsigned long flags = 0;
1260 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001261 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001262
Sony Chacko79788452012-12-04 03:33:53 +00001263 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001264 if (qlcnic_82xx_check(adapter))
1265 handler = qlcnic_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001266 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1267 flags |= IRQF_SHARED;
1268
1269 } else {
1270 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1271 handler = qlcnic_msix_intr;
1272 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1273 handler = qlcnic_msi_intr;
1274 else {
1275 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001276 if (qlcnic_82xx_check(adapter))
1277 handler = qlcnic_intr;
1278 else
1279 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001280 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001281 }
1282 adapter->irq = netdev->irq;
1283
Sony Chacko13159182013-01-01 03:20:21 +00001284 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001285 if (qlcnic_82xx_check(adapter) ||
1286 (qlcnic_83xx_check(adapter) &&
1287 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1288 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1289 sds_ring = &recv_ctx->sds_rings[ring];
1290 snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ,
1291 "%s[%d]", netdev->name, ring);
1292 err = request_irq(sds_ring->irq, handler, flags,
1293 sds_ring->name, sds_ring);
1294 if (err)
1295 return err;
1296 }
Sony Chacko13159182013-01-01 03:20:21 +00001297 }
1298 if (qlcnic_83xx_check(adapter) &&
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001299 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1300 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001301 handler = qlcnic_msix_tx_intr;
1302 for (ring = 0; ring < adapter->max_drv_tx_rings;
1303 ring++) {
1304 tx_ring = &adapter->tx_ring[ring];
1305 snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ,
1306 "%s[%d]", netdev->name,
Himanshu Madhaniac166702013-02-18 12:06:15 +00001307 adapter->max_sds_rings + ring);
Sony Chacko13159182013-01-01 03:20:21 +00001308 err = request_irq(tx_ring->irq, handler, flags,
1309 tx_ring->name, tx_ring);
1310 if (err)
1311 return err;
1312 }
1313 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001314 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001315 return 0;
1316}
1317
1318static void
1319qlcnic_free_irq(struct qlcnic_adapter *adapter)
1320{
1321 int ring;
1322 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001323 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001324
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001325 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001326
Sony Chacko13159182013-01-01 03:20:21 +00001327 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001328 if (qlcnic_82xx_check(adapter) ||
1329 (qlcnic_83xx_check(adapter) &&
1330 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1331 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1332 sds_ring = &recv_ctx->sds_rings[ring];
1333 free_irq(sds_ring->irq, sds_ring);
1334 }
Sony Chacko13159182013-01-01 03:20:21 +00001335 }
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001336 if (qlcnic_83xx_check(adapter) &&
1337 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001338 for (ring = 0; ring < adapter->max_drv_tx_rings;
1339 ring++) {
1340 tx_ring = &adapter->tx_ring[ring];
1341 if (tx_ring->irq)
1342 free_irq(tx_ring->irq, tx_ring);
1343 }
1344 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001345 }
1346}
1347
Shahed Shaikh99e85872013-02-18 12:06:16 +00001348static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1349{
1350 u32 capab = 0;
1351
1352 if (qlcnic_82xx_check(adapter)) {
1353 if (adapter->ahw->capabilities2 &
1354 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1355 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1356 } else {
1357 capab = adapter->ahw->capabilities;
1358 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1359 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1360 }
1361}
1362
Sony Chacko319ecf12013-01-01 03:20:22 +00001363int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001364{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001365 int ring;
1366 struct qlcnic_host_rds_ring *rds_ring;
1367
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001368 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1369 return -EIO;
1370
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001371 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1372 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001373 if (qlcnic_set_eswitch_port_config(adapter))
1374 return -EIO;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001375 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001376
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001377 if (qlcnic_fw_create_ctx(adapter))
1378 return -EIO;
1379
1380 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001381 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001382 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001383 }
1384
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001385 qlcnic_set_multi(netdev);
1386 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1387
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001388 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001389
1390 if (adapter->max_sds_rings > 1)
1391 qlcnic_config_rss(adapter, 1);
1392
1393 qlcnic_config_intr_coalesce(adapter);
1394
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001395 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001396 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1397
1398 qlcnic_napi_enable(adapter);
1399
1400 qlcnic_linkevent_request(adapter, 1);
1401
Sony Chacko79788452012-12-04 03:33:53 +00001402 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001403 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1404 return 0;
1405}
1406
Sony Chacko629263a2013-01-01 04:11:55 +00001407int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001408{
1409 int err = 0;
1410
1411 rtnl_lock();
1412 if (netif_running(netdev))
1413 err = __qlcnic_up(adapter, netdev);
1414 rtnl_unlock();
1415
1416 return err;
1417}
1418
Sony Chacko319ecf12013-01-01 03:20:22 +00001419void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001420{
1421 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1422 return;
1423
1424 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1425 return;
1426
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001427 if (qlcnic_sriov_vf_check(adapter))
1428 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001429 smp_mb();
1430 spin_lock(&adapter->tx_clean_lock);
1431 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001432 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001433 netif_tx_disable(netdev);
1434
1435 qlcnic_free_mac_list(adapter);
1436
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001437 if (adapter->fhash.fnum)
1438 qlcnic_delete_lb_filters(adapter);
1439
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001440 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1441
1442 qlcnic_napi_disable(adapter);
1443
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001444 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001445 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001446
1447 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001448 qlcnic_release_tx_buffers(adapter);
1449 spin_unlock(&adapter->tx_clean_lock);
1450}
1451
1452/* Usage: During suspend and firmware recovery module */
1453
Sony Chacko629263a2013-01-01 04:11:55 +00001454void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001455{
1456 rtnl_lock();
1457 if (netif_running(netdev))
1458 __qlcnic_down(adapter, netdev);
1459 rtnl_unlock();
1460
1461}
1462
Sony Chacko319ecf12013-01-01 03:20:22 +00001463int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001464qlcnic_attach(struct qlcnic_adapter *adapter)
1465{
1466 struct net_device *netdev = adapter->netdev;
1467 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001468 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001469
1470 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1471 return 0;
1472
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001473 err = qlcnic_napi_add(adapter, netdev);
1474 if (err)
1475 return err;
1476
1477 err = qlcnic_alloc_sw_resources(adapter);
1478 if (err) {
1479 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001480 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001481 }
1482
1483 err = qlcnic_alloc_hw_resources(adapter);
1484 if (err) {
1485 dev_err(&pdev->dev, "Error in setting hw resources\n");
1486 goto err_out_free_sw;
1487 }
1488
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001489 err = qlcnic_request_irq(adapter);
1490 if (err) {
1491 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001492 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001493 }
1494
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001495 qlcnic_create_sysfs_entries(adapter);
1496
1497 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1498 return 0;
1499
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001500err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001501 qlcnic_free_hw_resources(adapter);
1502err_out_free_sw:
1503 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001504err_out_napi_del:
1505 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001506 return err;
1507}
1508
Sony Chacko319ecf12013-01-01 03:20:22 +00001509void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001510{
1511 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1512 return;
1513
1514 qlcnic_remove_sysfs_entries(adapter);
1515
1516 qlcnic_free_hw_resources(adapter);
1517 qlcnic_release_rx_buffers(adapter);
1518 qlcnic_free_irq(adapter);
1519 qlcnic_napi_del(adapter);
1520 qlcnic_free_sw_resources(adapter);
1521
1522 adapter->is_up = 0;
1523}
1524
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001525void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1526{
1527 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1528 struct qlcnic_host_sds_ring *sds_ring;
1529 int ring;
1530
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001531 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001532 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001533 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001534 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001535 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001536 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001537 }
1538
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001539 qlcnic_fw_destroy_ctx(adapter);
1540
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001541 qlcnic_detach(adapter);
1542
Sony Chacko79788452012-12-04 03:33:53 +00001543 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001544 adapter->max_sds_rings = max_sds_rings;
1545
1546 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001547 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001548
1549 if (netif_running(netdev))
1550 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001551out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001552 netif_device_attach(netdev);
1553}
1554
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001555static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1556{
1557 int err = 0;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001558 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1559 GFP_KERNEL);
1560 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001561 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001562 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001563 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001564 /* Initialize interrupt coalesce parameters */
1565 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1566 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1567 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Sony Chacko4be41e92013-01-01 03:20:20 +00001568 /* clear stats */
1569 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001570err_out:
1571 return err;
1572}
1573
1574static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1575{
1576 kfree(adapter->recv_ctx);
1577 adapter->recv_ctx = NULL;
1578
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001579 if (adapter->ahw->fw_dump.tmpl_hdr) {
1580 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1581 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1582 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001583
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001584 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001585 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001586}
1587
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001588int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1589{
1590 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1591 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001592 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001593 int ring;
1594 int ret;
1595
1596 netif_device_detach(netdev);
1597
1598 if (netif_running(netdev))
1599 __qlcnic_down(adapter, netdev);
1600
1601 qlcnic_detach(adapter);
1602
1603 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001604 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001605 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001606
1607 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001608 if (ret) {
1609 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001610 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001611 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001612
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001613 ret = qlcnic_fw_create_ctx(adapter);
1614 if (ret) {
1615 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001616 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001617 return ret;
1618 }
1619
1620 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001621 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001622 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001623 }
1624
Sony Chacko79788452012-12-04 03:33:53 +00001625 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001626 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001627 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001628 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001629 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001630 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001631
Sony Chacko79788452012-12-04 03:33:53 +00001632 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001633 adapter->ahw->loopback_state = 0;
1634 qlcnic_linkevent_request(adapter, 1);
1635 }
1636
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001637 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001638
1639 return 0;
1640}
1641
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001642/* Reset context in hardware only */
1643static int
1644qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1645{
1646 struct net_device *netdev = adapter->netdev;
1647
1648 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1649 return -EBUSY;
1650
1651 netif_device_detach(netdev);
1652
1653 qlcnic_down(adapter, netdev);
1654
1655 qlcnic_up(adapter, netdev);
1656
1657 netif_device_attach(netdev);
1658
1659 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001660 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001661 return 0;
1662}
1663
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001664int
1665qlcnic_reset_context(struct qlcnic_adapter *adapter)
1666{
1667 int err = 0;
1668 struct net_device *netdev = adapter->netdev;
1669
1670 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1671 return -EBUSY;
1672
1673 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1674
1675 netif_device_detach(netdev);
1676
1677 if (netif_running(netdev))
1678 __qlcnic_down(adapter, netdev);
1679
1680 qlcnic_detach(adapter);
1681
1682 if (netif_running(netdev)) {
1683 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001684 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001685 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001686 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1687 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001688 }
1689
1690 netif_device_attach(netdev);
1691 }
1692
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001693 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1694 return err;
1695}
1696
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001697int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001698qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1699 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001700{
1701 int err;
1702 struct pci_dev *pdev = adapter->pdev;
1703
Sony Chacko13159182013-01-01 03:20:21 +00001704 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001705 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001706 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001707
1708 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001709 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001710
1711 qlcnic_change_mtu(netdev, netdev->mtu);
1712
1713 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1714
Sony Chacko7e38d042013-01-01 03:20:28 +00001715 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00001716 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00001717 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00001718 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1719 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001720
Sony Chacko13159182013-01-01 03:20:21 +00001721 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1722 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1723 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1724 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001725
Sony Chacko13159182013-01-01 03:20:21 +00001726 if (pci_using_dac) {
1727 netdev->features |= NETIF_F_HIGHDMA;
1728 netdev->vlan_features |= NETIF_F_HIGHDMA;
1729 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001730
Sony Chacko13159182013-01-01 03:20:21 +00001731 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00001732 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00001733
Sony Chacko79788452012-12-04 03:33:53 +00001734 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001735 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001736
Sony Chacko7e38d042013-01-01 03:20:28 +00001737 netdev->hw_features = netdev->features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001738 netdev->irq = adapter->msix_entries[0].vector;
1739
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001740 err = register_netdev(netdev);
1741 if (err) {
1742 dev_err(&pdev->dev, "failed to register net device\n");
1743 return err;
1744 }
1745
1746 return 0;
1747}
1748
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001749static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001750{
1751 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1752 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1753 *pci_using_dac = 1;
1754 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1755 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1756 *pci_using_dac = 0;
1757 else {
1758 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1759 return -EIO;
1760 }
1761
1762 return 0;
1763}
1764
Sony Chacko4be41e92013-01-01 03:20:20 +00001765void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1766{
1767 int ring;
1768 struct qlcnic_host_tx_ring *tx_ring;
1769
1770 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1771 tx_ring = &adapter->tx_ring[ring];
1772 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1773 vfree(tx_ring->cmd_buf_arr);
1774 tx_ring->cmd_buf_arr = NULL;
1775 }
1776 }
1777 if (adapter->tx_ring != NULL)
1778 kfree(adapter->tx_ring);
1779}
1780
1781int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1782 struct net_device *netdev)
1783{
Joe Perchesb2adaca2013-02-03 17:43:58 +00001784 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00001785 struct qlcnic_host_tx_ring *tx_ring;
1786 struct qlcnic_cmd_buffer *cmd_buf_arr;
1787
Joe Perchesb2adaca2013-02-03 17:43:58 +00001788 tx_ring = kcalloc(adapter->max_drv_tx_rings,
1789 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
1790 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00001791 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00001792
Sony Chacko4be41e92013-01-01 03:20:20 +00001793 adapter->tx_ring = tx_ring;
1794
1795 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1796 tx_ring = &adapter->tx_ring[ring];
1797 tx_ring->num_desc = adapter->num_txd;
1798 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1799 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1800 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001801 qlcnic_free_tx_rings(adapter);
1802 return -ENOMEM;
1803 }
1804 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1805 tx_ring->cmd_buf_arr = cmd_buf_arr;
1806 }
1807
1808 if (qlcnic_83xx_check(adapter)) {
1809 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1810 tx_ring = &adapter->tx_ring[ring];
1811 tx_ring->adapter = adapter;
1812 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1813 index = adapter->max_sds_rings + ring;
1814 vector = adapter->msix_entries[index].vector;
1815 tx_ring->irq = vector;
1816 }
1817 }
1818 }
1819 return 0;
1820}
1821
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001822static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001823qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1824{
1825 struct net_device *netdev = NULL;
1826 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001827 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001828 int err, pci_using_dac = -1;
Sritej Velagac84e3402013-01-25 10:20:34 +00001829 u32 capab2;
Dan Carpenter7bc48642013-01-30 22:14:10 +00001830 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001831
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001832 if (pdev->is_virtfn)
1833 return -ENODEV;
1834
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001835 err = pci_enable_device(pdev);
1836 if (err)
1837 return err;
1838
1839 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1840 err = -ENODEV;
1841 goto err_out_disable_pdev;
1842 }
1843
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001844 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1845 if (err)
1846 goto err_out_disable_pdev;
1847
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001848 err = pci_request_regions(pdev, qlcnic_driver_name);
1849 if (err)
1850 goto err_out_disable_pdev;
1851
1852 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001853 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001854
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001855 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
1856 if (!ahw)
1857 goto err_out_free_res;
1858
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001859 switch (ent->device) {
1860 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001861 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001862 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
1863 break;
1864 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +00001865 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001866 break;
1867 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
1868 qlcnic_sriov_vf_register_map(ahw);
1869 break;
1870 default:
Sony Chacko13159182013-01-01 03:20:21 +00001871 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001872 }
1873
1874 err = qlcnic_setup_pci_map(pdev, ahw);
1875 if (err)
1876 goto err_out_free_hw_res;
1877
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001878 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1879 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001880 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001881 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001882 }
1883
1884 SET_NETDEV_DEV(netdev, &pdev->dev);
1885
1886 adapter = netdev_priv(netdev);
1887 adapter->netdev = netdev;
1888 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00001889 adapter->ahw = ahw;
1890
1891 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
1892 if (adapter->qlcnic_wq == NULL) {
1893 dev_err(&pdev->dev, "Failed to create workqueue\n");
1894 goto err_out_free_netdev;
1895 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001896
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001897 err = qlcnic_alloc_adapter_resources(adapter);
1898 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001899 goto err_out_free_netdev;
1900
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001901 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001902 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001903 if (qlcnic_mac_learn == FDB_MAC_LEARN)
1904 adapter->fdb_mac_learn = true;
1905 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
1906 adapter->drv_mac_learn = true;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001907 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001908
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001909 rwlock_init(&adapter->ahw->crb_lock);
1910 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001911
1912 spin_lock_init(&adapter->tx_clean_lock);
1913 INIT_LIST_HEAD(&adapter->mac_list);
1914
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001915 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00001916 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001917 adapter->portnum = adapter->ahw->pci_func;
1918 err = qlcnic_start_firmware(adapter);
1919 if (err) {
1920 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1921 goto err_out_free_hw;
1922 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001923
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001924 err = qlcnic_setup_idc_param(adapter);
1925 if (err)
1926 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001927
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001928 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00001929 } else if (qlcnic_83xx_check(adapter)) {
1930 qlcnic_83xx_check_vf(adapter, ent);
1931 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001932 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00001933 if (err) {
1934 dev_err(&pdev->dev, "%s: failed\n", __func__);
1935 goto err_out_free_hw;
1936 }
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001937 if (qlcnic_sriov_vf_check(adapter))
1938 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00001939 } else {
1940 dev_err(&pdev->dev,
1941 "%s: failed. Please Reboot\n", __func__);
1942 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001943 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001944
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001945 if (qlcnic_read_mac_addr(adapter))
1946 dev_warn(&pdev->dev, "failed to read mac addr\n");
1947
1948 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00001949 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00001950
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001951 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00001952 module_name(THIS_MODULE),
1953 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001954 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00001955
1956 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
1957 !!qlcnic_use_msi)
1958 dev_warn(&pdev->dev,
1959 "83xx adapter do not support MSI interrupts\n");
1960
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001961 err = qlcnic_setup_intr(adapter, 0);
Manish chopra9a97e702013-01-25 10:20:37 +00001962 if (err) {
1963 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001964 goto err_out_disable_msi;
Manish chopra9a97e702013-01-25 10:20:37 +00001965 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001966
Sony Chacko13159182013-01-01 03:20:21 +00001967 if (qlcnic_83xx_check(adapter)) {
1968 err = qlcnic_83xx_setup_mbx_intr(adapter);
1969 if (err)
1970 goto err_out_disable_msi;
1971 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001972
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001973 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001974 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001975 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001976
Sritej Velagac84e3402013-01-25 10:20:34 +00001977 if (qlcnic_82xx_check(adapter)) {
1978 if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1979 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1980 if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB)
1981 qlcnic_fw_cmd_set_drv_version(adapter);
1982 }
1983 }
1984
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001985 pci_set_drvdata(pdev, adapter);
1986
Sony Chacko97ee45e2012-12-04 03:33:52 +00001987 if (qlcnic_82xx_check(adapter))
1988 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1989 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001990
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001991 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001992 case QLCNIC_GBE:
1993 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1994 adapter->netdev->name);
1995 break;
1996 case QLCNIC_XGBE:
1997 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1998 adapter->netdev->name);
1999 break;
2000 }
2001
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002002 if (qlcnic_get_act_pci_func(adapter))
2003 goto err_out_disable_mbx_intr;
2004
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002005 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002006 qlcnic_alloc_lb_filters_mem(adapter);
2007
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002008 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002009
2010 return 0;
2011
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002012err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002013 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002014 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002015
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002016err_out_disable_msi:
2017 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002018 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002019 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002020
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002021err_out_free_hw:
2022 qlcnic_free_adapter_resources(adapter);
2023
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002024err_out_free_netdev:
2025 free_netdev(netdev);
2026
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002027err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002028 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002029
2030err_out_free_hw_res:
2031 kfree(ahw);
2032
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002033err_out_free_res:
2034 pci_release_regions(pdev);
2035
2036err_out_disable_pdev:
2037 pci_set_drvdata(pdev, NULL);
2038 pci_disable_device(pdev);
2039 return err;
2040}
2041
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002042static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002043{
2044 struct qlcnic_adapter *adapter;
2045 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002046 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002047
2048 adapter = pci_get_drvdata(pdev);
2049 if (adapter == NULL)
2050 return;
2051
2052 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002053 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002054
Sony Chacko13159182013-01-01 03:20:21 +00002055 qlcnic_cancel_idc_work(adapter);
2056 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002057
2058 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002059 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002060
Sony Chacko13159182013-01-01 03:20:21 +00002061 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002062 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002063 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2064 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00002065 }
2066
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002067 qlcnic_detach(adapter);
2068
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002069 if (adapter->npars != NULL)
2070 kfree(adapter->npars);
2071 if (adapter->eswitch != NULL)
2072 kfree(adapter->eswitch);
2073
Sony Chacko97ee45e2012-12-04 03:33:52 +00002074 if (qlcnic_82xx_check(adapter))
2075 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002076
2077 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2078
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002079 qlcnic_free_lb_filters_mem(adapter);
2080
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002081 qlcnic_teardown_intr(adapter);
2082
Sony Chacko13159182013-01-01 03:20:21 +00002083 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002084
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002085 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002086
2087 qlcnic_release_firmware(adapter);
2088
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002089 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002090 pci_release_regions(pdev);
2091 pci_disable_device(pdev);
2092 pci_set_drvdata(pdev, NULL);
2093
Sony Chacko13159182013-01-01 03:20:21 +00002094 if (adapter->qlcnic_wq) {
2095 destroy_workqueue(adapter->qlcnic_wq);
2096 adapter->qlcnic_wq = NULL;
2097 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002098 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002099 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002100 free_netdev(netdev);
2101}
2102static int __qlcnic_shutdown(struct pci_dev *pdev)
2103{
2104 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2105 struct net_device *netdev = adapter->netdev;
2106 int retval;
2107
2108 netif_device_detach(netdev);
2109
Sony Chacko13159182013-01-01 03:20:21 +00002110 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002111
2112 if (netif_running(netdev))
2113 qlcnic_down(adapter, netdev);
2114
Sony Chacko97ee45e2012-12-04 03:33:52 +00002115 if (qlcnic_82xx_check(adapter))
2116 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002117
2118 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2119
2120 retval = pci_save_state(pdev);
2121 if (retval)
2122 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002123 if (qlcnic_82xx_check(adapter)) {
2124 if (qlcnic_wol_supported(adapter)) {
2125 pci_enable_wake(pdev, PCI_D3cold, 1);
2126 pci_enable_wake(pdev, PCI_D3hot, 1);
2127 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002128 }
2129
2130 return 0;
2131}
2132
2133static void qlcnic_shutdown(struct pci_dev *pdev)
2134{
2135 if (__qlcnic_shutdown(pdev))
2136 return;
2137
2138 pci_disable_device(pdev);
2139}
2140
2141#ifdef CONFIG_PM
2142static int
2143qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2144{
2145 int retval;
2146
2147 retval = __qlcnic_shutdown(pdev);
2148 if (retval)
2149 return retval;
2150
2151 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2152 return 0;
2153}
2154
2155static int
2156qlcnic_resume(struct pci_dev *pdev)
2157{
2158 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2159 struct net_device *netdev = adapter->netdev;
2160 int err;
2161
2162 err = pci_enable_device(pdev);
2163 if (err)
2164 return err;
2165
2166 pci_set_power_state(pdev, PCI_D0);
2167 pci_set_master(pdev);
2168 pci_restore_state(pdev);
2169
Sony Chacko13159182013-01-01 03:20:21 +00002170 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002171 if (err) {
2172 dev_err(&pdev->dev, "failed to start firmware\n");
2173 return err;
2174 }
2175
2176 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002177 err = qlcnic_up(adapter, netdev);
2178 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002179 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002180
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002181 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002182 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002183done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002184 netif_device_attach(netdev);
2185 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2186 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002187}
2188#endif
2189
2190static int qlcnic_open(struct net_device *netdev)
2191{
2192 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2193 int err;
2194
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002195 netif_carrier_off(netdev);
2196
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002197 err = qlcnic_attach(adapter);
2198 if (err)
2199 return err;
2200
2201 err = __qlcnic_up(adapter, netdev);
2202 if (err)
2203 goto err_out;
2204
2205 netif_start_queue(netdev);
2206
2207 return 0;
2208
2209err_out:
2210 qlcnic_detach(adapter);
2211 return err;
2212}
2213
2214/*
2215 * qlcnic_close - Disables a network interface entry point
2216 */
2217static int qlcnic_close(struct net_device *netdev)
2218{
2219 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2220
2221 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002222
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002223 return 0;
2224}
2225
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002226void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002227{
2228 void *head;
2229 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002230 struct net_device *netdev = adapter->netdev;
2231 u32 filter_size = 0;
2232 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002233
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002234 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002235 return;
2236
Sony Chacko13159182013-01-01 03:20:21 +00002237 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002238 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002239 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002240
Sony Chacko13159182013-01-01 03:20:21 +00002241 if (qlcnic_82xx_check(adapter)) {
2242 filter_size = QLCNIC_LB_MAX_FILTERS;
2243 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2244 } else {
2245 filter_size = QLC_83XX_LB_MAX_FILTERS;
2246 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2247 }
2248
2249 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002250 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002251
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002252 if (!head)
2253 return;
2254
Sony Chacko13159182013-01-01 03:20:21 +00002255 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002256 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002257
Sony Chacko13159182013-01-01 03:20:21 +00002258 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2259 act_pci_func, adapter->fhash.fmax);
2260
2261 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002262 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002263
2264 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2265
2266 head = kcalloc(adapter->rx_fhash.fbucket_size,
2267 sizeof(struct hlist_head), GFP_ATOMIC);
2268
2269 if (!head)
2270 return;
2271
2272 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2273 adapter->rx_fhash.fhead = head;
2274
2275 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2276 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002277}
2278
2279static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2280{
2281 if (adapter->fhash.fmax && adapter->fhash.fhead)
2282 kfree(adapter->fhash.fhead);
2283
2284 adapter->fhash.fhead = NULL;
2285 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002286
2287 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2288 kfree(adapter->rx_fhash.fhead);
2289
2290 adapter->rx_fhash.fmax = 0;
2291 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002292}
2293
Sony Chacko629263a2013-01-01 04:11:55 +00002294int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002295{
2296 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002297 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002298 int rv = 0;
2299
Sony Chacko13159182013-01-01 03:20:21 +00002300 if (qlcnic_83xx_check(adapter))
2301 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2302
Sony Chacko97ee45e2012-12-04 03:33:52 +00002303 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002304 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002305
2306 temp_state = qlcnic_get_temp_state(temp);
2307 temp_val = qlcnic_get_temp_val(temp);
2308
2309 if (temp_state == QLCNIC_TEMP_PANIC) {
2310 dev_err(&netdev->dev,
2311 "Device temperature %d degrees C exceeds"
2312 " maximum allowed. Hardware has been shut down.\n",
2313 temp_val);
2314 rv = 1;
2315 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002316 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002317 dev_err(&netdev->dev,
2318 "Device temperature %d degrees C "
2319 "exceeds operating range."
2320 " Immediate action needed.\n",
2321 temp_val);
2322 }
2323 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002324 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002325 dev_info(&netdev->dev,
2326 "Device temperature is now %d degrees C"
2327 " in normal range.\n", temp_val);
2328 }
2329 }
Sony Chacko79788452012-12-04 03:33:53 +00002330 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002331 return rv;
2332}
2333
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002334static void qlcnic_tx_timeout(struct net_device *netdev)
2335{
2336 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2337
2338 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2339 return;
2340
2341 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002342
2343 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002344 adapter->need_fw_reset = 1;
2345 else
Sony Chacko79788452012-12-04 03:33:53 +00002346 adapter->ahw->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002347}
2348
2349static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2350{
2351 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2352 struct net_device_stats *stats = &netdev->stats;
2353
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002354 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2355 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002356 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002357 stats->tx_bytes = adapter->stats.txbytes;
2358 stats->rx_dropped = adapter->stats.rxdropped;
2359 stats->tx_dropped = adapter->stats.txdropped;
2360
2361 return stats;
2362}
2363
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002364irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002365{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002366 u32 status;
2367
2368 status = readl(adapter->isr_int_vec);
2369
Sony Chacko79788452012-12-04 03:33:53 +00002370 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002371 return IRQ_NONE;
2372
2373 /* check interrupt state machine, to be sure */
2374 status = readl(adapter->crb_int_state_reg);
2375 if (!ISR_LEGACY_INT_TRIGGERED(status))
2376 return IRQ_NONE;
2377
2378 writel(0xffffffff, adapter->tgt_status_reg);
2379 /* read twice to ensure write is flushed */
2380 readl(adapter->isr_int_vec);
2381 readl(adapter->isr_int_vec);
2382
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002383 return IRQ_HANDLED;
2384}
2385
2386static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2387{
2388 struct qlcnic_host_sds_ring *sds_ring = data;
2389 struct qlcnic_adapter *adapter = sds_ring->adapter;
2390
2391 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2392 goto done;
2393 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2394 writel(0xffffffff, adapter->tgt_status_reg);
2395 goto done;
2396 }
2397
2398 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2399 return IRQ_NONE;
2400
2401done:
Sony Chacko79788452012-12-04 03:33:53 +00002402 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002403 qlcnic_enable_int(sds_ring);
2404 return IRQ_HANDLED;
2405}
2406
2407static irqreturn_t qlcnic_intr(int irq, void *data)
2408{
2409 struct qlcnic_host_sds_ring *sds_ring = data;
2410 struct qlcnic_adapter *adapter = sds_ring->adapter;
2411
2412 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2413 return IRQ_NONE;
2414
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002415 napi_schedule(&sds_ring->napi);
2416
2417 return IRQ_HANDLED;
2418}
2419
2420static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2421{
2422 struct qlcnic_host_sds_ring *sds_ring = data;
2423 struct qlcnic_adapter *adapter = sds_ring->adapter;
2424
2425 /* clear interrupt */
2426 writel(0xffffffff, adapter->tgt_status_reg);
2427
2428 napi_schedule(&sds_ring->napi);
2429 return IRQ_HANDLED;
2430}
2431
2432static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2433{
2434 struct qlcnic_host_sds_ring *sds_ring = data;
2435
2436 napi_schedule(&sds_ring->napi);
2437 return IRQ_HANDLED;
2438}
2439
Sony Chacko13159182013-01-01 03:20:21 +00002440static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2441{
2442 struct qlcnic_host_tx_ring *tx_ring = data;
2443
2444 napi_schedule(&tx_ring->napi);
2445 return IRQ_HANDLED;
2446}
2447
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002448#ifdef CONFIG_NET_POLL_CONTROLLER
2449static void qlcnic_poll_controller(struct net_device *netdev)
2450{
Yinglin Luanbf827912010-08-22 21:57:56 +00002451 int ring;
2452 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002453 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002454 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002455
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002456 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002457 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2458 sds_ring = &recv_ctx->sds_rings[ring];
2459 qlcnic_intr(adapter->irq, sds_ring);
2460 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002461 enable_irq(adapter->irq);
2462}
2463#endif
2464
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002465static void
2466qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2467{
2468 u32 val;
2469
2470 val = adapter->portnum & 0xf;
2471 val |= encoding << 7;
2472 val |= (jiffies - adapter->dev_rst_time) << 8;
2473
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002474 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002475 adapter->dev_rst_time = jiffies;
2476}
2477
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002478static int
2479qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002480{
2481 u32 val;
2482
2483 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2484 state != QLCNIC_DEV_NEED_QUISCENT);
2485
2486 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002487 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002488
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002489 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002490
2491 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002492 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002493 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002494 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002495
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002496 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002497
2498 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002499
2500 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002501}
2502
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002503static int
2504qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2505{
2506 u32 val;
2507
2508 if (qlcnic_api_lock(adapter))
2509 return -EBUSY;
2510
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002511 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002512 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002513 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002514
2515 qlcnic_api_unlock(adapter);
2516
2517 return 0;
2518}
2519
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002520static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002521qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002522{
2523 u32 val;
2524
2525 if (qlcnic_api_lock(adapter))
2526 goto err;
2527
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002528 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002529 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002530 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002531
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002532 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002533 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2534 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002535 dev_info(&adapter->pdev->dev,
2536 "Device state set to Failed. Please Reboot\n");
2537 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002538 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2539 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002540
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002541 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002542 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002543 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002544
2545 qlcnic_api_unlock(adapter);
2546err:
2547 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002548 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002549 clear_bit(__QLCNIC_START_FW, &adapter->state);
2550 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2551}
2552
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002553/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002554static int
2555qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2556{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002557 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002558 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002559
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002560 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2561 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002562
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002563 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002564 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002565 act = act & active_mask;
2566 }
2567
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002568 if (((state & 0x11111111) == (act & 0x11111111)) ||
2569 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2570 return 0;
2571 else
2572 return 1;
2573}
2574
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002575static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2576{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002577 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002578
2579 if (val != QLCNIC_DRV_IDC_VER) {
2580 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2581 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2582 }
2583
2584 return 0;
2585}
2586
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002587static int
2588qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2589{
2590 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002591 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002592 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002593 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002594
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002595 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2596 return 1;
2597
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002598 if (qlcnic_api_lock(adapter))
2599 return -1;
2600
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002601 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002602 if (!(val & (1 << (portnum * 4)))) {
2603 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002604 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002605 }
2606
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002607 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002608 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002609
2610 switch (prev_state) {
2611 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002612 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2613 QLCNIC_DEV_INITIALIZING);
2614 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2615 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002616 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002617 qlcnic_api_unlock(adapter);
2618 return 1;
2619
2620 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002621 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002622 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002623 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002624
2625 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002626 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002627 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002628 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002629 break;
2630
2631 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002632 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002633 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002634 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002635 break;
2636
2637 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002638 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002639 qlcnic_api_unlock(adapter);
2640 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002641
2642 case QLCNIC_DEV_INITIALIZING:
2643 case QLCNIC_DEV_QUISCENT:
2644 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002645 }
2646
2647 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002648
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002649 do {
2650 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002651 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002652
2653 if (prev_state == QLCNIC_DEV_QUISCENT)
2654 continue;
2655 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002656
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002657 if (!dev_init_timeo) {
2658 dev_err(&adapter->pdev->dev,
2659 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002660 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002661 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002662
2663 if (qlcnic_api_lock(adapter))
2664 return -1;
2665
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002666 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002667 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002668 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002669
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002670 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002671 qlcnic_api_unlock(adapter);
2672
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002673 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002674}
2675
2676static void
2677qlcnic_fwinit_work(struct work_struct *work)
2678{
2679 struct qlcnic_adapter *adapter = container_of(work,
2680 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002681 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002682 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002683
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002684 if (qlcnic_api_lock(adapter))
2685 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002686
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002687 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002688 if (dev_state == QLCNIC_DEV_QUISCENT ||
2689 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002690 qlcnic_api_unlock(adapter);
2691 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2692 FW_POLL_DELAY * 2);
2693 return;
2694 }
2695
Sony Chacko79788452012-12-04 03:33:53 +00002696 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002697 qlcnic_api_unlock(adapter);
2698 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002699 }
2700
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002701 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2702 dev_state == QLCNIC_DEV_READY) {
2703 dev_info(&adapter->pdev->dev, "Detected state change from "
2704 "DEV_NEED_RESET, skipping ack check\n");
2705 goto skip_ack_check;
2706 }
2707
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002708 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002709 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002710 adapter->reset_ack_timeo);
2711 goto skip_ack_check;
2712 }
2713
2714 if (!qlcnic_check_drv_state(adapter)) {
2715skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002716 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002717
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002718 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002719 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2720 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002721 set_bit(__QLCNIC_START_FW, &adapter->state);
2722 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002723 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002724 val = QLC_SHARED_REG_RD32(adapter,
2725 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002726 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002727 QLC_SHARED_REG_WR32(adapter,
2728 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002729 }
2730
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002731 qlcnic_api_unlock(adapter);
2732
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002733 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002734 if (adapter->ahw->fw_dump.enable &&
2735 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002736 QLCDB(adapter, DRV, "Take FW dump\n");
2737 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002738 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002739 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002740 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002741
2742 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002743 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002744 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002745 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002746 return;
2747 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002748 goto err_ret;
2749 }
2750
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002751 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002752
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002753wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002754 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002755 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002756
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002757 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002758 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002759 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002760 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002761 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002762 return;
2763 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002764 case QLCNIC_DEV_FAILED:
2765 break;
2766 default:
2767 qlcnic_schedule_work(adapter,
2768 qlcnic_fwinit_work, FW_POLL_DELAY);
2769 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002770 }
2771
2772err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002773 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2774 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002775 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002776 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002777}
2778
2779static void
2780qlcnic_detach_work(struct work_struct *work)
2781{
2782 struct qlcnic_adapter *adapter = container_of(work,
2783 struct qlcnic_adapter, fw_work.work);
2784 struct net_device *netdev = adapter->netdev;
2785 u32 status;
2786
2787 netif_device_detach(netdev);
2788
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002789 /* Dont grab rtnl lock during Quiscent mode */
2790 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2791 if (netif_running(netdev))
2792 __qlcnic_down(adapter, netdev);
2793 } else
2794 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002795
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002796 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002797
Sony Chacko44f65b22011-08-29 12:50:26 +00002798 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2799 dev_err(&adapter->pdev->dev,
2800 "Detaching the device: peg halt status1=0x%x\n",
2801 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002802
Sony Chacko44f65b22011-08-29 12:50:26 +00002803 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2804 dev_err(&adapter->pdev->dev,
2805 "On board active cooling fan failed. "
2806 "Device has been halted.\n");
2807 dev_err(&adapter->pdev->dev,
2808 "Replace the adapter.\n");
2809 }
2810
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002811 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002812 }
2813
Sony Chacko79788452012-12-04 03:33:53 +00002814 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002815 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002816 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002817 goto err_ret;
2818 }
2819
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002820 /* Dont ack if this instance is the reset owner */
2821 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002822 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2823 dev_err(&adapter->pdev->dev,
2824 "Failed to set driver state,"
2825 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002826 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002827 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002828 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002829
2830 adapter->fw_wait_cnt = 0;
2831
2832 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2833
2834 return;
2835
2836err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002837 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002838 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002839}
2840
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002841/*Transit NPAR state to NON Operational */
2842static void
2843qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2844{
2845 u32 state;
2846
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002847 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002848 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2849 return;
2850
2851 if (qlcnic_api_lock(adapter))
2852 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002853 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2854 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002855 qlcnic_api_unlock(adapter);
2856}
2857
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002858void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002859{
Sritej Velaga646779f2012-02-03 13:45:41 +00002860 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002861
Sritej Velaga646779f2012-02-03 13:45:41 +00002862 qlcnic_xg_set_xg0_mask(xg_val);
2863 qlcnic_xg_set_xg1_mask(xg_val);
2864 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2865 qlcnic_gb_set_gb0_mask(gb_val);
2866 qlcnic_gb_set_gb1_mask(gb_val);
2867 qlcnic_gb_set_gb2_mask(gb_val);
2868 qlcnic_gb_set_gb3_mask(gb_val);
2869 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2870 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2871 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002872 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002873
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002874 if (qlcnic_api_lock(adapter))
2875 return;
2876
Sony Chacko13159182013-01-01 03:20:21 +00002877 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002878
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002879 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00002880 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2881 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002882 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002883 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002884 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002885 }
2886
Sony Chacko13159182013-01-01 03:20:21 +00002887 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2888 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002889 qlcnic_api_unlock(adapter);
2890}
2891
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002892/* Transit to NPAR READY state from NPAR NOT READY state */
2893static void
2894qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2895{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002896 if (qlcnic_api_lock(adapter))
2897 return;
2898
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002899 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2900 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002901 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002902
2903 qlcnic_api_unlock(adapter);
2904}
2905
Sony Chacko13159182013-01-01 03:20:21 +00002906void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2907 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002908{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002909 if (test_bit(__QLCNIC_AER, &adapter->state))
2910 return;
2911
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002912 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00002913 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
2914 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002915}
2916
2917static void
2918qlcnic_attach_work(struct work_struct *work)
2919{
2920 struct qlcnic_adapter *adapter = container_of(work,
2921 struct qlcnic_adapter, fw_work.work);
2922 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002923 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002924
Sony Chacko79788452012-12-04 03:33:53 +00002925 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002926 npar_state = QLC_SHARED_REG_RD32(adapter,
2927 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002928 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2929 qlcnic_clr_all_drv_state(adapter, 0);
2930 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2931 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2932 FW_POLL_DELAY);
2933 else
2934 goto attach;
2935 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2936 return;
2937 }
2938attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002939 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002940 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002941 goto done;
2942
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002943 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002944 }
2945
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002946done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002947 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002948 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002949 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002950 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002951
2952 if (!qlcnic_clr_drv_state(adapter))
2953 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2954 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002955}
2956
2957static int
2958qlcnic_check_health(struct qlcnic_adapter *adapter)
2959{
Sony Chacko4e708122010-08-31 17:17:44 +00002960 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002961 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002962
2963 if (qlcnic_check_temp(adapter))
2964 goto detach;
2965
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002966 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002967 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002968
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002969 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002970 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002971 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002972 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002973 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2974 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002975
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002976 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00002977 if (heartbeat != adapter->heartbeat) {
2978 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002979 adapter->fw_fail_cnt = 0;
2980 if (adapter->need_fw_reset)
2981 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002982
Sony Chacko099f7aa2012-12-04 03:33:58 +00002983 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002984 qlcnic_reset_hw_context(adapter);
2985 adapter->netdev->trans_start = jiffies;
2986 }
2987
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002988 return 0;
2989 }
2990
2991 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2992 return 0;
2993
Sritej Velaga032a13c2011-07-29 13:30:27 +00002994 adapter->flags |= QLCNIC_FW_HANG;
2995
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002996 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002997
Sony Chacko099f7aa2012-12-04 03:33:58 +00002998 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002999 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003000
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003001 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003002 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003003 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003004 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3005 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3006 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3007 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003008 peg_status,
3009 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00003010 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3011 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3012 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3013 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3014 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00003015 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003016 dev_err(&adapter->pdev->dev,
3017 "Firmware aborted with error code 0x00006700. "
3018 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003019detach:
3020 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3021 QLCNIC_DEV_NEED_RESET;
3022
Sony Chacko099f7aa2012-12-04 03:33:58 +00003023 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3024 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003025
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003026 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003027 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3028 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003029
3030 return 1;
3031}
3032
3033static void
3034qlcnic_fw_poll_work(struct work_struct *work)
3035{
3036 struct qlcnic_adapter *adapter = container_of(work,
3037 struct qlcnic_adapter, fw_work.work);
3038
3039 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3040 goto reschedule;
3041
3042
3043 if (qlcnic_check_health(adapter))
3044 return;
3045
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003046 if (adapter->fhash.fnum)
3047 qlcnic_prune_lb_filters(adapter);
3048
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003049reschedule:
3050 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3051}
3052
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003053static int qlcnic_is_first_func(struct pci_dev *pdev)
3054{
3055 struct pci_dev *oth_pdev;
3056 int val = pdev->devfn;
3057
3058 while (val-- > 0) {
3059 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3060 (pdev->bus), pdev->bus->number,
3061 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003062 if (!oth_pdev)
3063 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003064
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003065 if (oth_pdev->current_state != PCI_D3cold) {
3066 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003067 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003068 }
3069 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003070 }
3071 return 1;
3072}
3073
3074static int qlcnic_attach_func(struct pci_dev *pdev)
3075{
3076 int err, first_func;
3077 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3078 struct net_device *netdev = adapter->netdev;
3079
3080 pdev->error_state = pci_channel_io_normal;
3081
3082 err = pci_enable_device(pdev);
3083 if (err)
3084 return err;
3085
3086 pci_set_power_state(pdev, PCI_D0);
3087 pci_set_master(pdev);
3088 pci_restore_state(pdev);
3089
3090 first_func = qlcnic_is_first_func(pdev);
3091
3092 if (qlcnic_api_lock(adapter))
3093 return -EINVAL;
3094
Sony Chacko79788452012-12-04 03:33:53 +00003095 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003096 adapter->need_fw_reset = 1;
3097 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003098 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3099 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003100 QLCDB(adapter, DRV, "Restarting fw\n");
3101 }
3102 qlcnic_api_unlock(adapter);
3103
Sony Chacko13159182013-01-01 03:20:21 +00003104 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003105 if (err)
3106 return err;
3107
3108 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003109 kfree(adapter->msix_entries);
3110 adapter->msix_entries = NULL;
3111 err = qlcnic_setup_intr(adapter, 0);
3112
Manish chopra9a97e702013-01-25 10:20:37 +00003113 if (err) {
3114 kfree(adapter->msix_entries);
3115 netdev_err(netdev, "failed to setup interrupt\n");
3116 return err;
3117 }
3118
Sony Chacko13159182013-01-01 03:20:21 +00003119 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003120 /* register for NIC IDC AEN Events */
3121 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003122 err = qlcnic_83xx_setup_mbx_intr(adapter);
3123 if (err) {
3124 dev_err(&adapter->pdev->dev,
3125 "failed to setup mbx interrupt\n");
3126 qlcnic_clr_all_drv_state(adapter, 1);
3127 clear_bit(__QLCNIC_AER, &adapter->state);
3128 goto done;
3129 }
3130 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003131
3132 if (netif_running(netdev)) {
3133 err = qlcnic_attach(adapter);
3134 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003135 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003136 clear_bit(__QLCNIC_AER, &adapter->state);
3137 netif_device_attach(netdev);
3138 return err;
3139 }
3140
3141 err = qlcnic_up(adapter, netdev);
3142 if (err)
3143 goto done;
3144
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003145 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003146 }
3147 done:
3148 netif_device_attach(netdev);
3149 return err;
3150}
3151
3152static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3153 pci_channel_state_t state)
3154{
3155 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3156 struct net_device *netdev = adapter->netdev;
3157
3158 if (state == pci_channel_io_perm_failure)
3159 return PCI_ERS_RESULT_DISCONNECT;
3160
3161 if (state == pci_channel_io_normal)
3162 return PCI_ERS_RESULT_RECOVERED;
3163
3164 set_bit(__QLCNIC_AER, &adapter->state);
3165 netif_device_detach(netdev);
3166
3167 cancel_delayed_work_sync(&adapter->fw_work);
3168
3169 if (netif_running(netdev))
3170 qlcnic_down(adapter, netdev);
3171
Sony Chacko13159182013-01-01 03:20:21 +00003172 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003173 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00003174 qlcnic_83xx_register_nic_idc_func(adapter, 0);
3175 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00003176 }
3177
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003178 qlcnic_detach(adapter);
3179 qlcnic_teardown_intr(adapter);
3180
3181 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3182
3183 pci_save_state(pdev);
3184 pci_disable_device(pdev);
3185
3186 return PCI_ERS_RESULT_NEED_RESET;
3187}
3188
3189static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3190{
3191 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3192 PCI_ERS_RESULT_RECOVERED;
3193}
3194
3195static void qlcnic_io_resume(struct pci_dev *pdev)
3196{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003197 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003198 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3199
3200 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003201 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3202 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3203 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003204 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3205 FW_POLL_DELAY);
3206}
3207
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003208static int
3209qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3210{
3211 int err;
3212
3213 err = qlcnic_can_start_firmware(adapter);
3214 if (err)
3215 return err;
3216
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003217 err = qlcnic_check_npar_opertional(adapter);
3218 if (err)
3219 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003220
Rajesh Borundia174240a2010-08-31 17:17:47 +00003221 err = qlcnic_initialize_nic(adapter);
3222 if (err)
3223 return err;
3224
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003225 qlcnic_check_options(adapter);
3226
Rajesh Borundia73733732010-08-31 17:17:50 +00003227 err = qlcnic_set_eswitch_port_config(adapter);
3228 if (err)
3229 return err;
3230
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003231 adapter->need_fw_reset = 0;
3232
3233 return err;
3234}
3235
Sony Chacko319ecf12013-01-01 03:20:22 +00003236int qlcnic_validate_max_rss(u8 max_hw, u8 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003237{
Sony Chacko319ecf12013-01-01 03:20:22 +00003238 u32 max_allowed;
3239
3240 if (max_hw > QLC_MAX_SDS_RINGS) {
3241 max_hw = QLC_MAX_SDS_RINGS;
3242 pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003243 }
3244
Sony Chacko319ecf12013-01-01 03:20:22 +00003245 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3246 num_online_cpus()));
3247 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
3248 pr_info("rss_ring valid range [2 - %x] in powers of 2\n",
3249 max_allowed);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003250 return -EINVAL;
3251 }
3252 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003253}
3254
Sony Chacko319ecf12013-01-01 03:20:22 +00003255int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003256{
Sony Chacko13159182013-01-01 03:20:21 +00003257 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003258 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003259
Sony Chacko319ecf12013-01-01 03:20:22 +00003260 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3261 return -EBUSY;
3262
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003263 netif_device_detach(netdev);
3264 if (netif_running(netdev))
3265 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003266
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003267 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003268
3269 if (qlcnic_83xx_check(adapter))
3270 qlcnic_83xx_free_mbx_intr(adapter);
3271
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003272 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003273 err = qlcnic_setup_intr(adapter, data);
Manish chopra9a97e702013-01-25 10:20:37 +00003274 if (err) {
3275 kfree(adapter->msix_entries);
3276 netdev_err(netdev, "failed to setup interrupt\n");
3277 return err;
3278 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003279
Sony Chacko13159182013-01-01 03:20:21 +00003280 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003281 /* register for NIC IDC AEN Events */
3282 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003283 err = qlcnic_83xx_setup_mbx_intr(adapter);
3284 if (err) {
3285 dev_err(&adapter->pdev->dev,
3286 "failed to setup mbx interrupt\n");
3287 goto done;
3288 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003289 }
3290
3291 if (netif_running(netdev)) {
3292 err = qlcnic_attach(adapter);
3293 if (err)
3294 goto done;
3295 err = __qlcnic_up(adapter, netdev);
3296 if (err)
3297 goto done;
3298 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3299 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003300 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003301 done:
3302 netif_device_attach(netdev);
3303 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3304 return err;
3305}
3306
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003307#ifdef CONFIG_INET
3308
3309#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3310
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003311static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003312qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3313 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003314{
3315 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003316
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003317 indev = in_dev_get(dev);
3318 if (!indev)
3319 return;
3320
3321 for_ifa(indev) {
3322 switch (event) {
3323 case NETDEV_UP:
3324 qlcnic_config_ipaddr(adapter,
3325 ifa->ifa_address, QLCNIC_IP_UP);
3326 break;
3327 case NETDEV_DOWN:
3328 qlcnic_config_ipaddr(adapter,
3329 ifa->ifa_address, QLCNIC_IP_DOWN);
3330 break;
3331 default:
3332 break;
3333 }
3334 } endfor_ifa(indev);
3335
3336 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003337}
3338
Sony Chacko319ecf12013-01-01 03:20:22 +00003339void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003340{
3341 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3342 struct net_device *dev;
3343 u16 vid;
3344
3345 qlcnic_config_indev_addr(adapter, netdev, event);
3346
Jiri Pirko43c00a72013-01-03 22:48:57 +00003347 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003348 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003349 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003350 if (!dev)
3351 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003352 qlcnic_config_indev_addr(adapter, dev, event);
3353 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003354 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003355}
3356
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003357static int qlcnic_netdev_event(struct notifier_block *this,
3358 unsigned long event, void *ptr)
3359{
3360 struct qlcnic_adapter *adapter;
3361 struct net_device *dev = (struct net_device *)ptr;
3362
3363recheck:
3364 if (dev == NULL)
3365 goto done;
3366
3367 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3368 dev = vlan_dev_real_dev(dev);
3369 goto recheck;
3370 }
3371
3372 if (!is_qlcnic_netdev(dev))
3373 goto done;
3374
3375 adapter = netdev_priv(dev);
3376
3377 if (!adapter)
3378 goto done;
3379
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003380 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003381 goto done;
3382
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003383 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003384done:
3385 return NOTIFY_DONE;
3386}
3387
3388static int
3389qlcnic_inetaddr_event(struct notifier_block *this,
3390 unsigned long event, void *ptr)
3391{
3392 struct qlcnic_adapter *adapter;
3393 struct net_device *dev;
3394
3395 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3396
3397 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3398
3399recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003400 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003401 goto done;
3402
3403 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3404 dev = vlan_dev_real_dev(dev);
3405 goto recheck;
3406 }
3407
3408 if (!is_qlcnic_netdev(dev))
3409 goto done;
3410
3411 adapter = netdev_priv(dev);
3412
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003413 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003414 goto done;
3415
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003416 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003417 goto done;
3418
3419 switch (event) {
3420 case NETDEV_UP:
3421 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003422
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003423 break;
3424 case NETDEV_DOWN:
3425 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003426
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003427 break;
3428 default:
3429 break;
3430 }
3431
3432done:
3433 return NOTIFY_DONE;
3434}
3435
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003436static struct notifier_block qlcnic_netdev_cb = {
3437 .notifier_call = qlcnic_netdev_event,
3438};
3439
3440static struct notifier_block qlcnic_inetaddr_cb = {
3441 .notifier_call = qlcnic_inetaddr_event,
3442};
3443#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003444void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003445{ }
3446#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003447static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003448 .error_detected = qlcnic_io_error_detected,
3449 .slot_reset = qlcnic_io_slot_reset,
3450 .resume = qlcnic_io_resume,
3451};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003452
3453static struct pci_driver qlcnic_driver = {
3454 .name = qlcnic_driver_name,
3455 .id_table = qlcnic_pci_tbl,
3456 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003457 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003458#ifdef CONFIG_PM
3459 .suspend = qlcnic_suspend,
3460 .resume = qlcnic_resume,
3461#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003462 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003463 .err_handler = &qlcnic_err_handler,
3464#ifdef CONFIG_QLCNIC_SRIOV
3465 .sriov_configure = qlcnic_pci_sriov_configure,
3466#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003467
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003468};
3469
3470static int __init qlcnic_init_module(void)
3471{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003472 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003473
3474 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3475
3476#ifdef CONFIG_INET
3477 register_netdevice_notifier(&qlcnic_netdev_cb);
3478 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3479#endif
3480
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003481 ret = pci_register_driver(&qlcnic_driver);
3482 if (ret) {
3483#ifdef CONFIG_INET
3484 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3485 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3486#endif
3487 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003488
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003489 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003490}
3491
3492module_init(qlcnic_init_module);
3493
3494static void __exit qlcnic_exit_module(void)
3495{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003496 pci_unregister_driver(&qlcnic_driver);
3497
3498#ifdef CONFIG_INET
3499 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3500 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3501#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003502}
3503
3504module_exit(qlcnic_exit_module);