blob: b3ab7a3386e388401bd8ddc772982aa7a5b28ec9 [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 Chackobff57d8e2012-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
Rajesh Borundia4000e7a2013-04-19 07:01:11 +0000344#ifdef CONFIG_QLCNIC_SRIOV
345 .ndo_set_vf_mac = qlcnic_sriov_set_vf_mac,
346 .ndo_set_vf_tx_rate = qlcnic_sriov_set_vf_tx_rate,
347 .ndo_get_vf_config = qlcnic_sriov_get_vf_config,
348#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000349};
350
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000351static const struct net_device_ops qlcnic_netdev_failed_ops = {
352 .ndo_open = qlcnic_open,
353};
354
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000355static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000356 .config_bridged_mode = qlcnic_config_bridged_mode,
357 .config_led = qlcnic_82xx_config_led,
358 .start_firmware = qlcnic_82xx_start_firmware,
359 .request_reset = qlcnic_82xx_dev_request_reset,
360 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
361 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000362 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000363 .config_ipaddr = qlcnic_82xx_config_ipaddr,
364 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000365};
366
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000367struct qlcnic_nic_template qlcnic_vf_ops = {
368 .config_bridged_mode = qlcnicvf_config_bridged_mode,
369 .config_led = qlcnicvf_config_led,
370 .start_firmware = qlcnicvf_start_firmware
371};
372
373static struct qlcnic_hardware_ops qlcnic_hw_ops = {
374 .read_crb = qlcnic_82xx_read_crb,
375 .write_crb = qlcnic_82xx_write_crb,
376 .read_reg = qlcnic_82xx_hw_read_wx_2M,
377 .write_reg = qlcnic_82xx_hw_write_wx_2M,
378 .get_mac_address = qlcnic_82xx_get_mac_address,
379 .setup_intr = qlcnic_82xx_setup_intr,
380 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
381 .mbx_cmd = qlcnic_82xx_issue_cmd,
382 .get_func_no = qlcnic_82xx_get_func_no,
383 .api_lock = qlcnic_82xx_api_lock,
384 .api_unlock = qlcnic_82xx_api_unlock,
385 .add_sysfs = qlcnic_82xx_add_sysfs,
386 .remove_sysfs = qlcnic_82xx_remove_sysfs,
387 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
388 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
389 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000390 .del_rx_ctx = qlcnic_82xx_fw_cmd_del_rx_ctx,
391 .del_tx_ctx = qlcnic_82xx_fw_cmd_del_tx_ctx,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000392 .setup_link_event = qlcnic_82xx_linkevent_request,
393 .get_nic_info = qlcnic_82xx_get_nic_info,
394 .get_pci_info = qlcnic_82xx_get_pci_info,
395 .set_nic_info = qlcnic_82xx_set_nic_info,
396 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
397 .napi_enable = qlcnic_82xx_napi_enable,
398 .napi_disable = qlcnic_82xx_napi_disable,
399 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
400 .config_rss = qlcnic_82xx_config_rss,
401 .config_hw_lro = qlcnic_82xx_config_hw_lro,
402 .config_loopback = qlcnic_82xx_set_lb_mode,
403 .clear_loopback = qlcnic_82xx_clear_lb_mode,
404 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
405 .change_l2_filter = qlcnic_82xx_change_filter,
406 .get_board_info = qlcnic_82xx_get_board_info,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000407};
408
Sony Chacko7f9664522013-01-01 03:20:19 +0000409int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000410{
411 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000412 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000413 int max_tx_rings, tx_vector;
414
415 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
416 max_tx_rings = 0;
417 tx_vector = 0;
418 } else {
419 max_tx_rings = adapter->max_drv_tx_rings;
420 tx_vector = 1;
421 }
Sony Chacko13159182013-01-01 03:20:21 +0000422
423 if (!adapter->msix_entries) {
424 adapter->msix_entries = kcalloc(num_msix,
425 sizeof(struct msix_entry),
426 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000427 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000428 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000429 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000430
431 adapter->max_sds_rings = 1;
432 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000433
Sony Chacko79788452012-12-04 03:33:53 +0000434 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000435 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000436 for (i = 0; i < num_msix; i++)
437 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000438 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
439 if (err == 0) {
440 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000441 if (qlcnic_83xx_check(adapter)) {
442 adapter->ahw->num_msix = num_msix;
443 /* subtract mail box and tx ring vectors */
Sony Chacko13159182013-01-01 03:20:21 +0000444 adapter->max_sds_rings = num_msix -
445 max_tx_rings - 1;
446 } else {
447 adapter->max_sds_rings = num_msix;
448 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000449 dev_info(&pdev->dev, "using msi-x interrupts\n");
450 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000451 } else if (err > 0) {
452 dev_info(&pdev->dev,
453 "Unable to allocate %d MSI-X interrupt vectors\n",
454 num_msix);
455 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000456 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000457 return err;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000458 err -= (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000459 num_msix = rounddown_pow_of_two(err);
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000460 num_msix += (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000461 } else {
462 num_msix = rounddown_pow_of_two(err);
463 }
464
465 if (num_msix) {
466 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000467 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000468 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000469 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000470 }
471 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000472 dev_info(&pdev->dev,
473 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000474 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000475 }
476 }
Sony Chacko13159182013-01-01 03:20:21 +0000477
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000478 return err;
479}
480
Manish chopra9a97e702013-01-25 10:20:37 +0000481static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000482{
Manish chopra9a97e702013-01-25 10:20:37 +0000483 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000484 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000485 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000486 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000487 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000488
Sony Chacko099f7aa2012-12-04 03:33:58 +0000489 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000490 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000491 offset = msi_tgt_status[adapter->ahw->pci_func];
492 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
493 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000494 dev_info(&pdev->dev, "using msi interrupts\n");
495 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000496 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000497 }
Manish chopra9a97e702013-01-25 10:20:37 +0000498 if (qlcnic_use_msi || qlcnic_use_msi_x)
499 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000500
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000501 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000502 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000503 offset = legacy_intrp->tgt_status_reg;
504 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
505 mask_reg = legacy_intrp->tgt_mask_reg;
506 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
507 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
508 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000509 dev_info(&pdev->dev, "using legacy interrupts\n");
510 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000511 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000512}
513
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000514int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000515{
Manish chopra9a97e702013-01-25 10:20:37 +0000516 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000517
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000518 if (!num_intr)
519 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
520
521 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000522 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000523 num_intr));
524 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000525 num_msix = 1;
526
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000527 err = qlcnic_enable_msix(adapter, num_msix);
528 if (err == -ENOMEM || !err)
529 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000530
Manish chopra9a97e702013-01-25 10:20:37 +0000531 err = qlcnic_enable_msi_legacy(adapter);
532 if (!err)
533 return err;
534
535 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000536}
Sony Chacko13159182013-01-01 03:20:21 +0000537
Sony Chacko319ecf12013-01-01 03:20:22 +0000538void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000539{
540 if (adapter->flags & QLCNIC_MSIX_ENABLED)
541 pci_disable_msix(adapter->pdev);
542 if (adapter->flags & QLCNIC_MSI_ENABLED)
543 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000544
545 kfree(adapter->msix_entries);
546 adapter->msix_entries = NULL;
547
548 if (adapter->ahw->intr_tbl) {
549 vfree(adapter->ahw->intr_tbl);
550 adapter->ahw->intr_tbl = NULL;
551 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000552}
553
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000554static void qlcnic_cleanup_pci_map(struct qlcnic_hardware_context *ahw)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000555{
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +0000556 if (ahw->pci_base0 != NULL)
557 iounmap(ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000558}
559
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000560static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
561{
562 struct qlcnic_pci_info *pci_info;
563 int ret;
564
565 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
566 switch (adapter->ahw->port_type) {
567 case QLCNIC_GBE:
568 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
569 break;
570 case QLCNIC_XGBE:
571 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
572 break;
573 }
574 return 0;
575 }
576
577 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
578 return 0;
579
580 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
581 if (!pci_info)
582 return -ENOMEM;
583
584 ret = qlcnic_get_pci_info(adapter, pci_info);
585 kfree(pci_info);
586 return ret;
587}
Sony Chackod71170f2013-01-01 03:20:26 +0000588
589int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000590{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000591 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d8e2012-12-04 03:33:56 +0000592 int i, ret = 0, j = 0;
593 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000594 u8 pfn;
595
Dan Carpentere88db3b2010-08-09 21:49:36 +0000596 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
597 if (!pci_info)
598 return -ENOMEM;
599
Sony Chackobff57d8e2012-12-04 03:33:56 +0000600 ret = qlcnic_get_pci_info(adapter, pci_info);
601 if (ret)
602 goto err_pci_info;
603
604 act_pci_func = adapter->ahw->act_pci_func;
605
Dan Carpenterca315ac2010-08-09 21:47:56 +0000606 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d8e2012-12-04 03:33:56 +0000607 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000608 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000609 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000610 goto err_pci_info;
611 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000612
Dan Carpenterca315ac2010-08-09 21:47:56 +0000613 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000614 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
615 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000616 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000617 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000618 }
619
Dan Carpenterca315ac2010-08-09 21:47:56 +0000620 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
621 pfn = pci_info[i].id;
Sony Chackobff57d8e2012-12-04 03:33:56 +0000622
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000623 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000624 ret = QL_STATUS_INVALID_PARAM;
625 goto err_eswitch;
626 }
Sony Chackobff57d8e2012-12-04 03:33:56 +0000627
628 if (!pci_info[i].active ||
629 (pci_info[i].type != QLCNIC_TYPE_NIC))
630 continue;
631
632 adapter->npars[j].pci_func = pfn;
633 adapter->npars[j].active = (u8)pci_info[i].active;
634 adapter->npars[j].type = (u8)pci_info[i].type;
635 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
636 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
637 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
638 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000639 }
640
Sony Chacko13159182013-01-01 03:20:21 +0000641 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000642 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000643 if (qlcnic_83xx_check(adapter))
644 qlcnic_enable_eswitch(adapter, i, 1);
645 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000646
Dan Carpentere88db3b2010-08-09 21:49:36 +0000647 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000648 return 0;
649
650err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000651 kfree(adapter->eswitch);
652 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000653err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000654 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000655 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000656err_pci_info:
657 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000658
659 return ret;
660}
661
662static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000663qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
664{
665 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000666 int i, ret = 1;
667 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d8e2012-12-04 03:33:56 +0000668 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000669
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000670 ret = qlcnic_api_lock(adapter);
671 if (ret)
672 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000673
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000674 if (qlcnic_config_npars) {
Sony Chackobff57d8e2012-12-04 03:33:56 +0000675 for (i = 0; i < ahw->act_pci_func; i++) {
676 id = adapter->npars[i].pci_func;
677 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000678 continue;
679 data |= (qlcnic_config_npars &
680 QLC_DEV_SET_DRV(0xf, id));
681 }
682 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000683 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d8e2012-12-04 03:33:56 +0000684 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000685 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d8e2012-12-04 03:33:56 +0000686 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000687 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000688 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000689 qlcnic_api_unlock(adapter);
690err_lock:
691 return ret;
692}
693
Sony Chacko13159182013-01-01 03:20:21 +0000694static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
695 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000696{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000697 u32 op_mode, priv_level;
698
699 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000700 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
701 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000702
703 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000704 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000705
706 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000707 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000708 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000709 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000710 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000711 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000712
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000713 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000714 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000715 dev_info(&adapter->pdev->dev,
716 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000717 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000718 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000719 } else
720 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000721}
722
Sony Chacko15087c22012-12-04 03:33:54 +0000723#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000724#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000725static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000726{
Sony Chacko15087c22012-12-04 03:33:54 +0000727 switch (dev_id) {
728 case PCI_DEVICE_ID_QLOGIC_QLE824X:
729 *bar = QLCNIC_82XX_BAR0_LENGTH;
730 break;
Sony Chacko13159182013-01-01 03:20:21 +0000731 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000732 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +0000733 *bar = QLCNIC_83XX_BAR0_LENGTH;
734 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000735 default:
736 *bar = 0;
737 }
738}
739
740static int qlcnic_setup_pci_map(struct pci_dev *pdev,
741 struct qlcnic_hardware_context *ahw)
742{
743 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000744 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000745 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000746
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000747 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000748 mem_len = pci_resource_len(pdev, 0);
749
Sony Chacko15087c22012-12-04 03:33:54 +0000750 qlcnic_get_bar_length(pdev->device, &bar0_len);
751 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000752
753 mem_ptr0 = pci_ioremap_bar(pdev, 0);
754 if (mem_ptr0 == NULL) {
755 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
756 return -EIO;
757 }
758 pci_len0 = mem_len;
759 } else {
760 return -EIO;
761 }
762
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000763 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000764
Sony Chacko15087c22012-12-04 03:33:54 +0000765 ahw->pci_base0 = mem_ptr0;
766 ahw->pci_len0 = pci_len0;
767 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
768 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000769
770 return 0;
771}
772
Sony Chacko22999792012-12-04 03:33:55 +0000773static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000774{
775 struct pci_dev *pdev = adapter->pdev;
776 int i, found = 0;
777
778 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
779 if (qlcnic_boards[i].vendor == pdev->vendor &&
780 qlcnic_boards[i].device == pdev->device &&
781 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
782 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000783 sprintf(name, "%pM: %s" ,
784 adapter->mac_addr,
785 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000786 found = 1;
787 break;
788 }
789
790 }
791
792 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000793 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000794}
795
796static void
797qlcnic_check_options(struct qlcnic_adapter *adapter)
798{
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000799 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000800 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000801 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000802 struct qlcnic_hardware_context *ahw = adapter->ahw;
803 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000804
805 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000806
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000807 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
808 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
809 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000810
811 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
812
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000813 err = qlcnic_get_board_info(adapter);
814 if (err) {
815 dev_err(&pdev->dev, "Error getting board config info.\n");
816 return;
817 }
818 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +0000819 if (fw_dump->tmpl_hdr == NULL ||
820 adapter->fw_version > prev_fw_version) {
821 if (fw_dump->tmpl_hdr)
822 vfree(fw_dump->tmpl_hdr);
823 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
824 dev_info(&pdev->dev,
825 "Supports FW dump capability\n");
826 }
827 }
828
Sony Chacko13159182013-01-01 03:20:21 +0000829 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
830 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
831
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000832 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000833 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
834 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
835 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
836 } else {
837 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
838 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
839 }
840
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000841 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000842 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
843
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000844 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000845 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
846 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000847 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
848 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000849 }
850
Sony Chacko099f7aa2012-12-04 03:33:58 +0000851 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000852
853 adapter->num_txd = MAX_CMD_DESCRIPTORS;
854
Sony Chacko251b0362010-08-19 05:08:24 +0000855 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000856}
857
Rajesh Borundia174240a2010-08-31 17:17:47 +0000858static int
859qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
860{
861 int err;
862 struct qlcnic_info nic_info;
863
Sony Chackobff57d8e2012-12-04 03:33:56 +0000864 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000865 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000866 if (err)
867 return err;
868
Sony Chacko79788452012-12-04 03:33:53 +0000869 adapter->ahw->physical_port = (u8)nic_info.phys_port;
870 adapter->ahw->switch_mode = nic_info.switch_mode;
871 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
872 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
873 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +0000874
875 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
876 u32 temp;
877 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
878 adapter->ahw->capabilities2 = temp;
879 }
Sony Chacko79788452012-12-04 03:33:53 +0000880 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
881 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000882
Sony Chacko13159182013-01-01 03:20:21 +0000883 /* Disable NPAR for 83XX */
884 if (qlcnic_83xx_check(adapter))
885 return err;
886
Sony Chacko79788452012-12-04 03:33:53 +0000887 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +0000888 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
889 else
890 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
891
892 return err;
893}
894
Sony Chackoec079a02012-11-28 04:34:28 +0000895void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
896 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000897{
898 if (esw_cfg->discard_tagged)
899 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
900 else
901 adapter->flags |= QLCNIC_TAGGING_ENABLED;
902
903 if (esw_cfg->vlan_id)
904 adapter->pvid = esw_cfg->vlan_id;
905 else
906 adapter->pvid = 0;
907}
908
Jiri Pirko8e586132011-12-08 19:52:37 -0500909static int
Patrick McHardy80d5c362013-04-19 02:04:28 +0000910qlcnic_vlan_rx_add(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000911{
912 struct qlcnic_adapter *adapter = netdev_priv(netdev);
913 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500914 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000915}
916
Jiri Pirko8e586132011-12-08 19:52:37 -0500917static int
Patrick McHardy80d5c362013-04-19 02:04:28 +0000918qlcnic_vlan_rx_del(struct net_device *netdev, __be16 proto, u16 vid)
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000919{
920 struct qlcnic_adapter *adapter = netdev_priv(netdev);
921
922 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
923 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500924 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000925}
926
Sony Chackoec079a02012-11-28 04:34:28 +0000927void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
928 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000929{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000930 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
931 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000932
933 if (esw_cfg->mac_anti_spoof)
934 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000935
Rajesh Borundia73733732010-08-31 17:17:50 +0000936 if (!esw_cfg->mac_override)
937 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
938
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000939 if (!esw_cfg->promisc_mode)
940 adapter->flags |= QLCNIC_PROMISC_DISABLED;
941
Rajesh Borundia0325d692010-08-19 05:08:26 +0000942 qlcnic_set_netdev_features(adapter, esw_cfg);
943}
944
Sony Chackod71170f2013-01-01 03:20:26 +0000945int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000946{
947 struct qlcnic_esw_func_cfg esw_cfg;
948
949 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
950 return 0;
951
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000952 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000953 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
954 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000955 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000956 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
957
958 return 0;
959}
960
961static void
962qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
963 struct qlcnic_esw_func_cfg *esw_cfg)
964{
965 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +0000966 unsigned long features, vlan_features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000967
Sony Chacko13159182013-01-01 03:20:21 +0000968 if (qlcnic_83xx_check(adapter))
969 return;
970
Sony Chacko7e38d042013-01-01 03:20:28 +0000971 features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
972 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000973 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Sony Chacko13159182013-01-01 03:20:21 +0000974 NETIF_F_IPV6_CSUM);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000975
Sony Chacko13159182013-01-01 03:20:21 +0000976 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000977 features |= (NETIF_F_TSO | NETIF_F_TSO6);
978 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
979 }
Rajesh Borundiab56421d2011-04-01 14:28:31 +0000980
981 if (netdev->features & NETIF_F_LRO)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000982 features |= NETIF_F_LRO;
983
984 if (esw_cfg->offload_flags & BIT_0) {
985 netdev->features |= features;
Sony Chacko13159182013-01-01 03:20:21 +0000986 adapter->rx_csum = 1;
Sony Chacko7e38d042013-01-01 03:20:28 +0000987 if (!(esw_cfg->offload_flags & BIT_1)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000988 netdev->features &= ~NETIF_F_TSO;
Sony Chacko7e38d042013-01-01 03:20:28 +0000989 features &= ~NETIF_F_TSO;
990 }
991 if (!(esw_cfg->offload_flags & BIT_2)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000992 netdev->features &= ~NETIF_F_TSO6;
Sony Chacko7e38d042013-01-01 03:20:28 +0000993 features &= ~NETIF_F_TSO6;
994 }
Rajesh Borundia0325d692010-08-19 05:08:26 +0000995 } else {
996 netdev->features &= ~features;
Sony Chacko7e38d042013-01-01 03:20:28 +0000997 features &= ~features;
Sony Chacko13159182013-01-01 03:20:21 +0000998 adapter->rx_csum = 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000999 }
1000
1001 netdev->vlan_features = (features & vlan_features);
1002}
1003
1004static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001005qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
1006{
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001007 u32 op_mode, priv_level;
1008 int err = 0;
1009
Rajesh Borundia174240a2010-08-31 17:17:47 +00001010 err = qlcnic_initialize_nic(adapter);
1011 if (err)
1012 return err;
1013
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001014 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1015 return 0;
1016
Sony Chacko13159182013-01-01 03:20:21 +00001017 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
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
1020 if (op_mode == QLC_DEV_DRV_DEFAULT)
1021 priv_level = QLCNIC_MGMT_FUNC;
1022 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001023 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001024
Rajesh Borundia174240a2010-08-31 17:17:47 +00001025 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001026 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001027 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001028 err = qlcnic_init_pci_info(adapter);
1029 if (err)
1030 return err;
1031 /* Set privilege level for other functions */
1032 qlcnic_set_function_modes(adapter);
1033 dev_info(&adapter->pdev->dev,
1034 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001035 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001036 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001037 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001038 dev_info(&adapter->pdev->dev,
1039 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001040 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001041 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001042 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001043
1044 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1045
1046 return err;
1047}
1048
Sony Chackod71170f2013-01-01 03:20:26 +00001049int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001050{
1051 struct qlcnic_esw_func_cfg esw_cfg;
1052 struct qlcnic_npar_info *npar;
1053 u8 i;
1054
Rajesh Borundia174240a2010-08-31 17:17:47 +00001055 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001056 return 0;
1057
Sony Chackobff57d8e2012-12-04 03:33:56 +00001058 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +00001059 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d8e2012-12-04 03:33:56 +00001060 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001061 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001062 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001063 if (qlcnic_82xx_check(adapter)) {
1064 esw_cfg.offload_flags = BIT_0;
1065 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1066 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1067 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001068 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1069 return -EIO;
1070 npar = &adapter->npars[i];
1071 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001072 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001073 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1074 npar->discard_tagged = esw_cfg.discard_tagged;
1075 npar->promisc_mode = esw_cfg.promisc_mode;
1076 npar->offload_flags = esw_cfg.offload_flags;
1077 }
1078
1079 return 0;
1080}
1081
Sony Chacko13159182013-01-01 03:20:21 +00001082
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001083static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001084qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1085 struct qlcnic_npar_info *npar, int pci_func)
1086{
1087 struct qlcnic_esw_func_cfg esw_cfg;
1088 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1089 esw_cfg.pci_func = pci_func;
1090 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001091 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001092 esw_cfg.discard_tagged = npar->discard_tagged;
1093 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1094 esw_cfg.offload_flags = npar->offload_flags;
1095 esw_cfg.promisc_mode = npar->promisc_mode;
1096 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1097 return -EIO;
1098
1099 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1100 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1101 return -EIO;
1102
1103 return 0;
1104}
1105
Sony Chackod71170f2013-01-01 03:20:26 +00001106int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001107{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001108 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001109 struct qlcnic_npar_info *npar;
1110 struct qlcnic_info nic_info;
Sony Chackobff57d8e2012-12-04 03:33:56 +00001111 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001112
Sony Chackobff57d8e2012-12-04 03:33:56 +00001113 if (qlcnic_82xx_check(adapter))
1114 if (!adapter->need_fw_reset)
1115 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001116
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001117 /* Set the NPAR config data after FW reset */
Sony Chackobff57d8e2012-12-04 03:33:56 +00001118 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001119 npar = &adapter->npars[i];
Sony Chackobff57d8e2012-12-04 03:33:56 +00001120 pci_func = npar->pci_func;
1121 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001122 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001123 if (err)
1124 return err;
1125 nic_info.min_tx_bw = npar->min_bw;
1126 nic_info.max_tx_bw = npar->max_bw;
1127 err = qlcnic_set_nic_info(adapter, &nic_info);
1128 if (err)
1129 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001130
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001131 if (npar->enable_pm) {
1132 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d8e2012-12-04 03:33:56 +00001133 npar->dest_npar, 1,
1134 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001135 if (err)
1136 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001137 }
Sony Chackobff57d8e2012-12-04 03:33:56 +00001138 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001139 if (err)
1140 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001141 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001142 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001143}
1144
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001145static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1146{
1147 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1148 u32 npar_state;
1149
Sony Chacko79788452012-12-04 03:33:53 +00001150 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001151 return 0;
1152
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001153 npar_state = QLC_SHARED_REG_RD32(adapter,
1154 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001155 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1156 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001157 npar_state = QLC_SHARED_REG_RD32(adapter,
1158 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001159 }
1160 if (!npar_opt_timeo) {
1161 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001162 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001163 return -EIO;
1164 }
1165 return 0;
1166}
1167
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001168static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001169qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1170{
1171 int err;
1172
1173 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001174 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001175 return 0;
1176
1177 err = qlcnic_set_default_offload_settings(adapter);
1178 if (err)
1179 return err;
1180
1181 err = qlcnic_reset_npar_config(adapter);
1182 if (err)
1183 return err;
1184
1185 qlcnic_dev_set_npar_ready(adapter);
1186
1187 return err;
1188}
1189
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001190int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001191{
Sony Chackod4066832010-08-19 05:08:31 +00001192 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001193
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001194 err = qlcnic_can_start_firmware(adapter);
1195 if (err < 0)
1196 return err;
1197 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001198 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001199
Sony Chacko099f7aa2012-12-04 03:33:58 +00001200 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001201 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001202 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001203 err = qlcnic_check_flash_fw_ver(adapter);
1204 if (err)
schacko8f891382010-06-17 02:56:40 +00001205 goto err_out;
1206
Sony Chacko79788452012-12-04 03:33:53 +00001207 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001208 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001209
1210 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001211 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001212 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001213
Sony Chackod4066832010-08-19 05:08:31 +00001214 err = qlcnic_pinit_from_rom(adapter);
1215 if (err)
1216 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001217
1218 err = qlcnic_load_firmware(adapter);
1219 if (err)
1220 goto err_out;
1221
1222 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001223 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001224
Sony Chackod4066832010-08-19 05:08:31 +00001225check_fw_status:
1226 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001227 if (err)
1228 goto err_out;
1229
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001230 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001231 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001232 err = qlcnic_check_eswitch_mode(adapter);
1233 if (err) {
1234 dev_err(&adapter->pdev->dev,
1235 "Memory allocation failed for eswitch\n");
1236 goto err_out;
1237 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001238 err = qlcnic_set_mgmt_operations(adapter);
1239 if (err)
1240 goto err_out;
1241
1242 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001243 adapter->need_fw_reset = 0;
1244
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001245 qlcnic_release_firmware(adapter);
1246 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001247
1248err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001249 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001250 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001251
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001252 qlcnic_release_firmware(adapter);
1253 return err;
1254}
1255
1256static int
1257qlcnic_request_irq(struct qlcnic_adapter *adapter)
1258{
1259 irq_handler_t handler;
1260 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001261 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001262 int err, ring;
1263
1264 unsigned long flags = 0;
1265 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001266 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001267
Sony Chacko79788452012-12-04 03:33:53 +00001268 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001269 if (qlcnic_82xx_check(adapter))
1270 handler = qlcnic_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001271 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1272 flags |= IRQF_SHARED;
1273
1274 } else {
1275 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1276 handler = qlcnic_msix_intr;
1277 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1278 handler = qlcnic_msi_intr;
1279 else {
1280 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001281 if (qlcnic_82xx_check(adapter))
1282 handler = qlcnic_intr;
1283 else
1284 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001285 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001286 }
1287 adapter->irq = netdev->irq;
1288
Sony Chacko13159182013-01-01 03:20:21 +00001289 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001290 if (qlcnic_82xx_check(adapter) ||
1291 (qlcnic_83xx_check(adapter) &&
1292 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1293 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1294 sds_ring = &recv_ctx->sds_rings[ring];
1295 snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ,
1296 "%s[%d]", netdev->name, ring);
1297 err = request_irq(sds_ring->irq, handler, flags,
1298 sds_ring->name, sds_ring);
1299 if (err)
1300 return err;
1301 }
Sony Chacko13159182013-01-01 03:20:21 +00001302 }
1303 if (qlcnic_83xx_check(adapter) &&
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001304 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1305 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001306 handler = qlcnic_msix_tx_intr;
1307 for (ring = 0; ring < adapter->max_drv_tx_rings;
1308 ring++) {
1309 tx_ring = &adapter->tx_ring[ring];
1310 snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ,
1311 "%s[%d]", netdev->name,
Himanshu Madhaniac166702013-02-18 12:06:15 +00001312 adapter->max_sds_rings + ring);
Sony Chacko13159182013-01-01 03:20:21 +00001313 err = request_irq(tx_ring->irq, handler, flags,
1314 tx_ring->name, tx_ring);
1315 if (err)
1316 return err;
1317 }
1318 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001319 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001320 return 0;
1321}
1322
1323static void
1324qlcnic_free_irq(struct qlcnic_adapter *adapter)
1325{
1326 int ring;
1327 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001328 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001329
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001330 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001331
Sony Chacko13159182013-01-01 03:20:21 +00001332 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001333 if (qlcnic_82xx_check(adapter) ||
1334 (qlcnic_83xx_check(adapter) &&
1335 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1336 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1337 sds_ring = &recv_ctx->sds_rings[ring];
1338 free_irq(sds_ring->irq, sds_ring);
1339 }
Sony Chacko13159182013-01-01 03:20:21 +00001340 }
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001341 if (qlcnic_83xx_check(adapter) &&
1342 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001343 for (ring = 0; ring < adapter->max_drv_tx_rings;
1344 ring++) {
1345 tx_ring = &adapter->tx_ring[ring];
1346 if (tx_ring->irq)
1347 free_irq(tx_ring->irq, tx_ring);
1348 }
1349 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001350 }
1351}
1352
Shahed Shaikh99e85872013-02-18 12:06:16 +00001353static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1354{
1355 u32 capab = 0;
1356
1357 if (qlcnic_82xx_check(adapter)) {
1358 if (adapter->ahw->capabilities2 &
1359 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1360 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1361 } else {
1362 capab = adapter->ahw->capabilities;
1363 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1364 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1365 }
1366}
1367
Sony Chacko319ecf12013-01-01 03:20:22 +00001368int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001369{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001370 int ring;
1371 struct qlcnic_host_rds_ring *rds_ring;
1372
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001373 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1374 return -EIO;
1375
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001376 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1377 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001378 if (qlcnic_set_eswitch_port_config(adapter))
1379 return -EIO;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001380 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001381
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001382 if (qlcnic_fw_create_ctx(adapter))
1383 return -EIO;
1384
1385 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001386 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001387 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001388 }
1389
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001390 qlcnic_set_multi(netdev);
1391 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1392
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001393 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001394
1395 if (adapter->max_sds_rings > 1)
1396 qlcnic_config_rss(adapter, 1);
1397
1398 qlcnic_config_intr_coalesce(adapter);
1399
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001400 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001401 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1402
1403 qlcnic_napi_enable(adapter);
1404
1405 qlcnic_linkevent_request(adapter, 1);
1406
Sony Chacko79788452012-12-04 03:33:53 +00001407 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001408 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1409 return 0;
1410}
1411
Sony Chacko629263a2013-01-01 04:11:55 +00001412int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001413{
1414 int err = 0;
1415
1416 rtnl_lock();
1417 if (netif_running(netdev))
1418 err = __qlcnic_up(adapter, netdev);
1419 rtnl_unlock();
1420
1421 return err;
1422}
1423
Sony Chacko319ecf12013-01-01 03:20:22 +00001424void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001425{
1426 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1427 return;
1428
1429 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1430 return;
1431
Rajesh Borundiae8b508e2013-03-29 05:46:38 +00001432 if (qlcnic_sriov_vf_check(adapter))
1433 qlcnic_sriov_cleanup_async_list(&adapter->ahw->sriov->bc);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001434 smp_mb();
1435 spin_lock(&adapter->tx_clean_lock);
1436 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001437 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001438 netif_tx_disable(netdev);
1439
1440 qlcnic_free_mac_list(adapter);
1441
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001442 if (adapter->fhash.fnum)
1443 qlcnic_delete_lb_filters(adapter);
1444
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001445 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1446
1447 qlcnic_napi_disable(adapter);
1448
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001449 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001450 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001451
1452 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001453 qlcnic_release_tx_buffers(adapter);
1454 spin_unlock(&adapter->tx_clean_lock);
1455}
1456
1457/* Usage: During suspend and firmware recovery module */
1458
Sony Chacko629263a2013-01-01 04:11:55 +00001459void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001460{
1461 rtnl_lock();
1462 if (netif_running(netdev))
1463 __qlcnic_down(adapter, netdev);
1464 rtnl_unlock();
1465
1466}
1467
Sony Chacko319ecf12013-01-01 03:20:22 +00001468int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001469qlcnic_attach(struct qlcnic_adapter *adapter)
1470{
1471 struct net_device *netdev = adapter->netdev;
1472 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001473 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001474
1475 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1476 return 0;
1477
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001478 err = qlcnic_napi_add(adapter, netdev);
1479 if (err)
1480 return err;
1481
1482 err = qlcnic_alloc_sw_resources(adapter);
1483 if (err) {
1484 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001485 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001486 }
1487
1488 err = qlcnic_alloc_hw_resources(adapter);
1489 if (err) {
1490 dev_err(&pdev->dev, "Error in setting hw resources\n");
1491 goto err_out_free_sw;
1492 }
1493
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001494 err = qlcnic_request_irq(adapter);
1495 if (err) {
1496 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001497 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001498 }
1499
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001500 qlcnic_create_sysfs_entries(adapter);
1501
1502 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1503 return 0;
1504
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001505err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001506 qlcnic_free_hw_resources(adapter);
1507err_out_free_sw:
1508 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001509err_out_napi_del:
1510 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001511 return err;
1512}
1513
Sony Chacko319ecf12013-01-01 03:20:22 +00001514void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001515{
1516 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1517 return;
1518
1519 qlcnic_remove_sysfs_entries(adapter);
1520
1521 qlcnic_free_hw_resources(adapter);
1522 qlcnic_release_rx_buffers(adapter);
1523 qlcnic_free_irq(adapter);
1524 qlcnic_napi_del(adapter);
1525 qlcnic_free_sw_resources(adapter);
1526
1527 adapter->is_up = 0;
1528}
1529
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001530void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1531{
1532 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1533 struct qlcnic_host_sds_ring *sds_ring;
1534 int ring;
1535
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001536 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001537 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001538 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001539 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001540 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001541 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001542 }
1543
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001544 qlcnic_fw_destroy_ctx(adapter);
1545
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001546 qlcnic_detach(adapter);
1547
Sony Chacko79788452012-12-04 03:33:53 +00001548 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001549 adapter->max_sds_rings = max_sds_rings;
1550
1551 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001552 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001553
1554 if (netif_running(netdev))
1555 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001556out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001557 netif_device_attach(netdev);
1558}
1559
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001560static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1561{
1562 int err = 0;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001563 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1564 GFP_KERNEL);
1565 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001566 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001567 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001568 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001569 /* Initialize interrupt coalesce parameters */
1570 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1571 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1572 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Sony Chacko4be41e92013-01-01 03:20:20 +00001573 /* clear stats */
1574 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001575err_out:
1576 return err;
1577}
1578
1579static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1580{
1581 kfree(adapter->recv_ctx);
1582 adapter->recv_ctx = NULL;
1583
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001584 if (adapter->ahw->fw_dump.tmpl_hdr) {
1585 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1586 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1587 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001588
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001589 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001590 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001591}
1592
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001593int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1594{
1595 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1596 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001597 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001598 int ring;
1599 int ret;
1600
1601 netif_device_detach(netdev);
1602
1603 if (netif_running(netdev))
1604 __qlcnic_down(adapter, netdev);
1605
1606 qlcnic_detach(adapter);
1607
1608 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001609 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001610 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001611
1612 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001613 if (ret) {
1614 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001615 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001616 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001617
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001618 ret = qlcnic_fw_create_ctx(adapter);
1619 if (ret) {
1620 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001621 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001622 return ret;
1623 }
1624
1625 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001626 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001627 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001628 }
1629
Sony Chacko79788452012-12-04 03:33:53 +00001630 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001631 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001632 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001633 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001634 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001635 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001636
Sony Chacko79788452012-12-04 03:33:53 +00001637 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001638 adapter->ahw->loopback_state = 0;
1639 qlcnic_linkevent_request(adapter, 1);
1640 }
1641
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001642 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001643
1644 return 0;
1645}
1646
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001647/* Reset context in hardware only */
1648static int
1649qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1650{
1651 struct net_device *netdev = adapter->netdev;
1652
1653 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1654 return -EBUSY;
1655
1656 netif_device_detach(netdev);
1657
1658 qlcnic_down(adapter, netdev);
1659
1660 qlcnic_up(adapter, netdev);
1661
1662 netif_device_attach(netdev);
1663
1664 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001665 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001666 return 0;
1667}
1668
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001669int
1670qlcnic_reset_context(struct qlcnic_adapter *adapter)
1671{
1672 int err = 0;
1673 struct net_device *netdev = adapter->netdev;
1674
1675 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1676 return -EBUSY;
1677
1678 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1679
1680 netif_device_detach(netdev);
1681
1682 if (netif_running(netdev))
1683 __qlcnic_down(adapter, netdev);
1684
1685 qlcnic_detach(adapter);
1686
1687 if (netif_running(netdev)) {
1688 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001689 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001690 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001691 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1692 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001693 }
1694
1695 netif_device_attach(netdev);
1696 }
1697
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001698 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1699 return err;
1700}
1701
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001702int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001703qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1704 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001705{
1706 int err;
1707 struct pci_dev *pdev = adapter->pdev;
1708
Sony Chacko13159182013-01-01 03:20:21 +00001709 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001710 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001711 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001712
1713 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001714 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001715
1716 qlcnic_change_mtu(netdev, netdev->mtu);
1717
1718 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1719
Sony Chacko7e38d042013-01-01 03:20:28 +00001720 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00001721 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
Patrick McHardyf6469682013-04-19 02:04:27 +00001722 NETIF_F_HW_VLAN_CTAG_RX);
Sony Chacko13159182013-01-01 03:20:21 +00001723 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1724 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001725
Sony Chacko13159182013-01-01 03:20:21 +00001726 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1727 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1728 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1729 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001730
Sony Chacko13159182013-01-01 03:20:21 +00001731 if (pci_using_dac) {
1732 netdev->features |= NETIF_F_HIGHDMA;
1733 netdev->vlan_features |= NETIF_F_HIGHDMA;
1734 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001735
Sony Chacko13159182013-01-01 03:20:21 +00001736 if (qlcnic_vlan_tx_check(adapter))
Patrick McHardyf6469682013-04-19 02:04:27 +00001737 netdev->features |= (NETIF_F_HW_VLAN_CTAG_TX);
Sony Chacko13159182013-01-01 03:20:21 +00001738
Sony Chacko79788452012-12-04 03:33:53 +00001739 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001740 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001741
Sony Chacko7e38d042013-01-01 03:20:28 +00001742 netdev->hw_features = netdev->features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001743 netdev->irq = adapter->msix_entries[0].vector;
1744
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001745 err = register_netdev(netdev);
1746 if (err) {
1747 dev_err(&pdev->dev, "failed to register net device\n");
1748 return err;
1749 }
1750
1751 return 0;
1752}
1753
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001754static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001755{
1756 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1757 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1758 *pci_using_dac = 1;
1759 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1760 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1761 *pci_using_dac = 0;
1762 else {
1763 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1764 return -EIO;
1765 }
1766
1767 return 0;
1768}
1769
Sony Chacko4be41e92013-01-01 03:20:20 +00001770void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1771{
1772 int ring;
1773 struct qlcnic_host_tx_ring *tx_ring;
1774
1775 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1776 tx_ring = &adapter->tx_ring[ring];
1777 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1778 vfree(tx_ring->cmd_buf_arr);
1779 tx_ring->cmd_buf_arr = NULL;
1780 }
1781 }
1782 if (adapter->tx_ring != NULL)
1783 kfree(adapter->tx_ring);
1784}
1785
1786int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1787 struct net_device *netdev)
1788{
Joe Perchesb2adaca2013-02-03 17:43:58 +00001789 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00001790 struct qlcnic_host_tx_ring *tx_ring;
1791 struct qlcnic_cmd_buffer *cmd_buf_arr;
1792
Joe Perchesb2adaca2013-02-03 17:43:58 +00001793 tx_ring = kcalloc(adapter->max_drv_tx_rings,
1794 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
1795 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00001796 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00001797
Sony Chacko4be41e92013-01-01 03:20:20 +00001798 adapter->tx_ring = tx_ring;
1799
1800 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1801 tx_ring = &adapter->tx_ring[ring];
1802 tx_ring->num_desc = adapter->num_txd;
1803 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1804 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1805 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001806 qlcnic_free_tx_rings(adapter);
1807 return -ENOMEM;
1808 }
1809 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1810 tx_ring->cmd_buf_arr = cmd_buf_arr;
1811 }
1812
1813 if (qlcnic_83xx_check(adapter)) {
1814 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1815 tx_ring = &adapter->tx_ring[ring];
1816 tx_ring->adapter = adapter;
1817 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1818 index = adapter->max_sds_rings + ring;
1819 vector = adapter->msix_entries[index].vector;
1820 tx_ring->irq = vector;
1821 }
1822 }
1823 }
1824 return 0;
1825}
1826
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001827static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001828qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1829{
1830 struct net_device *netdev = NULL;
1831 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001832 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001833 int err, pci_using_dac = -1;
Sritej Velagac84e3402013-01-25 10:20:34 +00001834 u32 capab2;
Dan Carpenter7bc48642013-01-30 22:14:10 +00001835 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001836
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001837 if (pdev->is_virtfn)
1838 return -ENODEV;
1839
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001840 err = pci_enable_device(pdev);
1841 if (err)
1842 return err;
1843
1844 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1845 err = -ENODEV;
1846 goto err_out_disable_pdev;
1847 }
1848
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001849 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1850 if (err)
1851 goto err_out_disable_pdev;
1852
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001853 err = pci_request_regions(pdev, qlcnic_driver_name);
1854 if (err)
1855 goto err_out_disable_pdev;
1856
1857 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001858 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001859
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001860 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
1861 if (!ahw)
1862 goto err_out_free_res;
1863
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001864 switch (ent->device) {
1865 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001866 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001867 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
1868 break;
1869 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +00001870 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001871 break;
1872 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
1873 qlcnic_sriov_vf_register_map(ahw);
1874 break;
1875 default:
Sony Chacko13159182013-01-01 03:20:21 +00001876 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001877 }
1878
1879 err = qlcnic_setup_pci_map(pdev, ahw);
1880 if (err)
1881 goto err_out_free_hw_res;
1882
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001883 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1884 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001885 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001886 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001887 }
1888
1889 SET_NETDEV_DEV(netdev, &pdev->dev);
1890
1891 adapter = netdev_priv(netdev);
1892 adapter->netdev = netdev;
1893 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00001894 adapter->ahw = ahw;
1895
1896 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
1897 if (adapter->qlcnic_wq == NULL) {
1898 dev_err(&pdev->dev, "Failed to create workqueue\n");
1899 goto err_out_free_netdev;
1900 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001901
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001902 err = qlcnic_alloc_adapter_resources(adapter);
1903 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001904 goto err_out_free_netdev;
1905
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001906 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001907 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001908 if (qlcnic_mac_learn == FDB_MAC_LEARN)
1909 adapter->fdb_mac_learn = true;
1910 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
1911 adapter->drv_mac_learn = true;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001912 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001913
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001914 rwlock_init(&adapter->ahw->crb_lock);
1915 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001916
1917 spin_lock_init(&adapter->tx_clean_lock);
1918 INIT_LIST_HEAD(&adapter->mac_list);
1919
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001920 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00001921 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001922 adapter->portnum = adapter->ahw->pci_func;
1923 err = qlcnic_start_firmware(adapter);
1924 if (err) {
1925 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1926 goto err_out_free_hw;
1927 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001928
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001929 err = qlcnic_setup_idc_param(adapter);
1930 if (err)
1931 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001932
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001933 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00001934 } else if (qlcnic_83xx_check(adapter)) {
1935 qlcnic_83xx_check_vf(adapter, ent);
1936 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001937 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00001938 if (err) {
1939 dev_err(&pdev->dev, "%s: failed\n", __func__);
1940 goto err_out_free_hw;
1941 }
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001942 if (qlcnic_sriov_vf_check(adapter))
1943 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00001944 } else {
1945 dev_err(&pdev->dev,
1946 "%s: failed. Please Reboot\n", __func__);
1947 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001948 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001949
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001950 if (qlcnic_read_mac_addr(adapter))
1951 dev_warn(&pdev->dev, "failed to read mac addr\n");
1952
1953 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00001954 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00001955
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001956 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00001957 module_name(THIS_MODULE),
1958 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001959 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00001960
1961 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
1962 !!qlcnic_use_msi)
1963 dev_warn(&pdev->dev,
1964 "83xx adapter do not support MSI interrupts\n");
1965
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001966 err = qlcnic_setup_intr(adapter, 0);
Manish chopra9a97e702013-01-25 10:20:37 +00001967 if (err) {
1968 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001969 goto err_out_disable_msi;
Manish chopra9a97e702013-01-25 10:20:37 +00001970 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001971
Sony Chacko13159182013-01-01 03:20:21 +00001972 if (qlcnic_83xx_check(adapter)) {
1973 err = qlcnic_83xx_setup_mbx_intr(adapter);
1974 if (err)
1975 goto err_out_disable_msi;
1976 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001977
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001978 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001979 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001980 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001981
Sritej Velagac84e3402013-01-25 10:20:34 +00001982 if (qlcnic_82xx_check(adapter)) {
1983 if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1984 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1985 if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB)
1986 qlcnic_fw_cmd_set_drv_version(adapter);
1987 }
1988 }
1989
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001990 pci_set_drvdata(pdev, adapter);
1991
Sony Chacko97ee45e2012-12-04 03:33:52 +00001992 if (qlcnic_82xx_check(adapter))
1993 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1994 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001995
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001996 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001997 case QLCNIC_GBE:
1998 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1999 adapter->netdev->name);
2000 break;
2001 case QLCNIC_XGBE:
2002 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
2003 adapter->netdev->name);
2004 break;
2005 }
2006
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002007 if (qlcnic_get_act_pci_func(adapter))
2008 goto err_out_disable_mbx_intr;
2009
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00002010 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002011 qlcnic_alloc_lb_filters_mem(adapter);
2012
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002013 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002014
2015 return 0;
2016
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002017err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002018 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002019 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002020
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002021err_out_disable_msi:
2022 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002023 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002024 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002025
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002026err_out_free_hw:
2027 qlcnic_free_adapter_resources(adapter);
2028
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002029err_out_free_netdev:
2030 free_netdev(netdev);
2031
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002032err_out_iounmap:
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002033 qlcnic_cleanup_pci_map(ahw);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002034
2035err_out_free_hw_res:
2036 kfree(ahw);
2037
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002038err_out_free_res:
2039 pci_release_regions(pdev);
2040
2041err_out_disable_pdev:
2042 pci_set_drvdata(pdev, NULL);
2043 pci_disable_device(pdev);
2044 return err;
2045}
2046
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002047static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002048{
2049 struct qlcnic_adapter *adapter;
2050 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002051 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002052
2053 adapter = pci_get_drvdata(pdev);
2054 if (adapter == NULL)
2055 return;
2056
2057 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002058 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002059
Sony Chacko13159182013-01-01 03:20:21 +00002060 qlcnic_cancel_idc_work(adapter);
2061 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002062
2063 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002064 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002065
Sony Chacko13159182013-01-01 03:20:21 +00002066 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002067 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002068 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2069 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00002070 }
2071
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002072 qlcnic_detach(adapter);
2073
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002074 if (adapter->npars != NULL)
2075 kfree(adapter->npars);
2076 if (adapter->eswitch != NULL)
2077 kfree(adapter->eswitch);
2078
Sony Chacko97ee45e2012-12-04 03:33:52 +00002079 if (qlcnic_82xx_check(adapter))
2080 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002081
2082 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2083
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002084 qlcnic_free_lb_filters_mem(adapter);
2085
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002086 qlcnic_teardown_intr(adapter);
2087
Sony Chacko13159182013-01-01 03:20:21 +00002088 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002089
Rajesh Borundiaf1a094a2013-04-02 05:34:41 +00002090 qlcnic_cleanup_pci_map(adapter->ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002091
2092 qlcnic_release_firmware(adapter);
2093
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002094 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002095 pci_release_regions(pdev);
2096 pci_disable_device(pdev);
2097 pci_set_drvdata(pdev, NULL);
2098
Sony Chacko13159182013-01-01 03:20:21 +00002099 if (adapter->qlcnic_wq) {
2100 destroy_workqueue(adapter->qlcnic_wq);
2101 adapter->qlcnic_wq = NULL;
2102 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002103 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002104 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002105 free_netdev(netdev);
2106}
2107static int __qlcnic_shutdown(struct pci_dev *pdev)
2108{
2109 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2110 struct net_device *netdev = adapter->netdev;
2111 int retval;
2112
2113 netif_device_detach(netdev);
2114
Sony Chacko13159182013-01-01 03:20:21 +00002115 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002116
2117 if (netif_running(netdev))
2118 qlcnic_down(adapter, netdev);
2119
Rajesh Borundia97d81052013-04-19 07:01:09 +00002120 qlcnic_sriov_cleanup(adapter);
Sony Chacko97ee45e2012-12-04 03:33:52 +00002121 if (qlcnic_82xx_check(adapter))
2122 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002123
2124 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2125
2126 retval = pci_save_state(pdev);
2127 if (retval)
2128 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002129 if (qlcnic_82xx_check(adapter)) {
2130 if (qlcnic_wol_supported(adapter)) {
2131 pci_enable_wake(pdev, PCI_D3cold, 1);
2132 pci_enable_wake(pdev, PCI_D3hot, 1);
2133 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002134 }
2135
2136 return 0;
2137}
2138
2139static void qlcnic_shutdown(struct pci_dev *pdev)
2140{
2141 if (__qlcnic_shutdown(pdev))
2142 return;
2143
2144 pci_disable_device(pdev);
2145}
2146
2147#ifdef CONFIG_PM
2148static int
2149qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2150{
2151 int retval;
2152
2153 retval = __qlcnic_shutdown(pdev);
2154 if (retval)
2155 return retval;
2156
2157 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2158 return 0;
2159}
2160
2161static int
2162qlcnic_resume(struct pci_dev *pdev)
2163{
2164 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2165 struct net_device *netdev = adapter->netdev;
2166 int err;
2167
2168 err = pci_enable_device(pdev);
2169 if (err)
2170 return err;
2171
2172 pci_set_power_state(pdev, PCI_D0);
2173 pci_set_master(pdev);
2174 pci_restore_state(pdev);
2175
Sony Chacko13159182013-01-01 03:20:21 +00002176 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002177 if (err) {
2178 dev_err(&pdev->dev, "failed to start firmware\n");
2179 return err;
2180 }
2181
2182 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002183 err = qlcnic_up(adapter, netdev);
2184 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002185 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002186
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002187 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002188 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002189done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002190 netif_device_attach(netdev);
2191 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2192 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002193}
2194#endif
2195
2196static int qlcnic_open(struct net_device *netdev)
2197{
2198 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2199 int err;
2200
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002201 netif_carrier_off(netdev);
2202
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002203 err = qlcnic_attach(adapter);
2204 if (err)
2205 return err;
2206
2207 err = __qlcnic_up(adapter, netdev);
2208 if (err)
2209 goto err_out;
2210
2211 netif_start_queue(netdev);
2212
2213 return 0;
2214
2215err_out:
2216 qlcnic_detach(adapter);
2217 return err;
2218}
2219
2220/*
2221 * qlcnic_close - Disables a network interface entry point
2222 */
2223static int qlcnic_close(struct net_device *netdev)
2224{
2225 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2226
2227 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002228
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002229 return 0;
2230}
2231
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002232void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002233{
2234 void *head;
2235 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002236 struct net_device *netdev = adapter->netdev;
2237 u32 filter_size = 0;
2238 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002239
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002240 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002241 return;
2242
Sony Chacko13159182013-01-01 03:20:21 +00002243 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002244 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002245 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002246
Sony Chacko13159182013-01-01 03:20:21 +00002247 if (qlcnic_82xx_check(adapter)) {
2248 filter_size = QLCNIC_LB_MAX_FILTERS;
2249 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2250 } else {
2251 filter_size = QLC_83XX_LB_MAX_FILTERS;
2252 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2253 }
2254
2255 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002256 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002257
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002258 if (!head)
2259 return;
2260
Sony Chacko13159182013-01-01 03:20:21 +00002261 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002262 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002263
Sony Chacko13159182013-01-01 03:20:21 +00002264 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2265 act_pci_func, adapter->fhash.fmax);
2266
2267 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002268 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002269
2270 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2271
2272 head = kcalloc(adapter->rx_fhash.fbucket_size,
2273 sizeof(struct hlist_head), GFP_ATOMIC);
2274
2275 if (!head)
2276 return;
2277
2278 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2279 adapter->rx_fhash.fhead = head;
2280
2281 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2282 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002283}
2284
2285static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2286{
2287 if (adapter->fhash.fmax && adapter->fhash.fhead)
2288 kfree(adapter->fhash.fhead);
2289
2290 adapter->fhash.fhead = NULL;
2291 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002292
2293 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2294 kfree(adapter->rx_fhash.fhead);
2295
2296 adapter->rx_fhash.fmax = 0;
2297 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002298}
2299
Sony Chacko629263a2013-01-01 04:11:55 +00002300int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002301{
2302 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002303 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002304 int rv = 0;
2305
Sony Chacko13159182013-01-01 03:20:21 +00002306 if (qlcnic_83xx_check(adapter))
2307 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2308
Sony Chacko97ee45e2012-12-04 03:33:52 +00002309 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002310 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002311
2312 temp_state = qlcnic_get_temp_state(temp);
2313 temp_val = qlcnic_get_temp_val(temp);
2314
2315 if (temp_state == QLCNIC_TEMP_PANIC) {
2316 dev_err(&netdev->dev,
2317 "Device temperature %d degrees C exceeds"
2318 " maximum allowed. Hardware has been shut down.\n",
2319 temp_val);
2320 rv = 1;
2321 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002322 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002323 dev_err(&netdev->dev,
2324 "Device temperature %d degrees C "
2325 "exceeds operating range."
2326 " Immediate action needed.\n",
2327 temp_val);
2328 }
2329 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002330 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002331 dev_info(&netdev->dev,
2332 "Device temperature is now %d degrees C"
2333 " in normal range.\n", temp_val);
2334 }
2335 }
Sony Chacko79788452012-12-04 03:33:53 +00002336 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002337 return rv;
2338}
2339
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002340static void qlcnic_tx_timeout(struct net_device *netdev)
2341{
2342 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2343
2344 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2345 return;
2346
2347 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002348
2349 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002350 adapter->need_fw_reset = 1;
2351 else
Sony Chacko79788452012-12-04 03:33:53 +00002352 adapter->ahw->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002353}
2354
2355static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2356{
2357 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2358 struct net_device_stats *stats = &netdev->stats;
2359
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002360 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2361 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002362 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002363 stats->tx_bytes = adapter->stats.txbytes;
2364 stats->rx_dropped = adapter->stats.rxdropped;
2365 stats->tx_dropped = adapter->stats.txdropped;
2366
2367 return stats;
2368}
2369
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002370irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002371{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002372 u32 status;
2373
2374 status = readl(adapter->isr_int_vec);
2375
Sony Chacko79788452012-12-04 03:33:53 +00002376 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002377 return IRQ_NONE;
2378
2379 /* check interrupt state machine, to be sure */
2380 status = readl(adapter->crb_int_state_reg);
2381 if (!ISR_LEGACY_INT_TRIGGERED(status))
2382 return IRQ_NONE;
2383
2384 writel(0xffffffff, adapter->tgt_status_reg);
2385 /* read twice to ensure write is flushed */
2386 readl(adapter->isr_int_vec);
2387 readl(adapter->isr_int_vec);
2388
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002389 return IRQ_HANDLED;
2390}
2391
2392static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2393{
2394 struct qlcnic_host_sds_ring *sds_ring = data;
2395 struct qlcnic_adapter *adapter = sds_ring->adapter;
2396
2397 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2398 goto done;
2399 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2400 writel(0xffffffff, adapter->tgt_status_reg);
2401 goto done;
2402 }
2403
2404 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2405 return IRQ_NONE;
2406
2407done:
Sony Chacko79788452012-12-04 03:33:53 +00002408 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002409 qlcnic_enable_int(sds_ring);
2410 return IRQ_HANDLED;
2411}
2412
2413static irqreturn_t qlcnic_intr(int irq, void *data)
2414{
2415 struct qlcnic_host_sds_ring *sds_ring = data;
2416 struct qlcnic_adapter *adapter = sds_ring->adapter;
2417
2418 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2419 return IRQ_NONE;
2420
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002421 napi_schedule(&sds_ring->napi);
2422
2423 return IRQ_HANDLED;
2424}
2425
2426static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2427{
2428 struct qlcnic_host_sds_ring *sds_ring = data;
2429 struct qlcnic_adapter *adapter = sds_ring->adapter;
2430
2431 /* clear interrupt */
2432 writel(0xffffffff, adapter->tgt_status_reg);
2433
2434 napi_schedule(&sds_ring->napi);
2435 return IRQ_HANDLED;
2436}
2437
2438static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2439{
2440 struct qlcnic_host_sds_ring *sds_ring = data;
2441
2442 napi_schedule(&sds_ring->napi);
2443 return IRQ_HANDLED;
2444}
2445
Sony Chacko13159182013-01-01 03:20:21 +00002446static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2447{
2448 struct qlcnic_host_tx_ring *tx_ring = data;
2449
2450 napi_schedule(&tx_ring->napi);
2451 return IRQ_HANDLED;
2452}
2453
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002454#ifdef CONFIG_NET_POLL_CONTROLLER
2455static void qlcnic_poll_controller(struct net_device *netdev)
2456{
Yinglin Luanbf827912010-08-22 21:57:56 +00002457 int ring;
2458 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002459 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002460 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002461
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002462 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002463 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2464 sds_ring = &recv_ctx->sds_rings[ring];
2465 qlcnic_intr(adapter->irq, sds_ring);
2466 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002467 enable_irq(adapter->irq);
2468}
2469#endif
2470
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002471static void
2472qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2473{
2474 u32 val;
2475
2476 val = adapter->portnum & 0xf;
2477 val |= encoding << 7;
2478 val |= (jiffies - adapter->dev_rst_time) << 8;
2479
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002480 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002481 adapter->dev_rst_time = jiffies;
2482}
2483
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002484static int
2485qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002486{
2487 u32 val;
2488
2489 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2490 state != QLCNIC_DEV_NEED_QUISCENT);
2491
2492 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002493 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002494
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002495 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002496
2497 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002498 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002499 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002500 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002501
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002502 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002503
2504 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002505
2506 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002507}
2508
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002509static int
2510qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2511{
2512 u32 val;
2513
2514 if (qlcnic_api_lock(adapter))
2515 return -EBUSY;
2516
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002517 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002518 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002519 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002520
2521 qlcnic_api_unlock(adapter);
2522
2523 return 0;
2524}
2525
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002527qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002528{
2529 u32 val;
2530
2531 if (qlcnic_api_lock(adapter))
2532 goto err;
2533
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002534 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002535 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002536 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002537
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002538 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002539 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2540 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002541 dev_info(&adapter->pdev->dev,
2542 "Device state set to Failed. Please Reboot\n");
2543 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002544 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2545 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002546
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002547 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002548 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002549 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002550
2551 qlcnic_api_unlock(adapter);
2552err:
2553 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002554 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002555 clear_bit(__QLCNIC_START_FW, &adapter->state);
2556 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2557}
2558
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002559/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002560static int
2561qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2562{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002563 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002564 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002565
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002566 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2567 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002568
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002569 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002570 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002571 act = act & active_mask;
2572 }
2573
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002574 if (((state & 0x11111111) == (act & 0x11111111)) ||
2575 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2576 return 0;
2577 else
2578 return 1;
2579}
2580
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002581static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2582{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002583 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002584
2585 if (val != QLCNIC_DRV_IDC_VER) {
2586 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2587 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2588 }
2589
2590 return 0;
2591}
2592
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002593static int
2594qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2595{
2596 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002597 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002598 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002599 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002600
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002601 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2602 return 1;
2603
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002604 if (qlcnic_api_lock(adapter))
2605 return -1;
2606
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002607 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002608 if (!(val & (1 << (portnum * 4)))) {
2609 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002610 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002611 }
2612
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002613 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002614 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002615
2616 switch (prev_state) {
2617 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002618 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2619 QLCNIC_DEV_INITIALIZING);
2620 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2621 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002622 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002623 qlcnic_api_unlock(adapter);
2624 return 1;
2625
2626 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002627 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002628 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002629 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002630
2631 case QLCNIC_DEV_NEED_RESET:
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_RST_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_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002638 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002639 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002640 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002641 break;
2642
2643 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002644 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002645 qlcnic_api_unlock(adapter);
2646 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002647
2648 case QLCNIC_DEV_INITIALIZING:
2649 case QLCNIC_DEV_QUISCENT:
2650 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002651 }
2652
2653 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002654
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002655 do {
2656 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002657 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002658
2659 if (prev_state == QLCNIC_DEV_QUISCENT)
2660 continue;
2661 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002662
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002663 if (!dev_init_timeo) {
2664 dev_err(&adapter->pdev->dev,
2665 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002666 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002667 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002668
2669 if (qlcnic_api_lock(adapter))
2670 return -1;
2671
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002672 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002673 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002674 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002675
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002676 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002677 qlcnic_api_unlock(adapter);
2678
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002679 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002680}
2681
2682static void
2683qlcnic_fwinit_work(struct work_struct *work)
2684{
2685 struct qlcnic_adapter *adapter = container_of(work,
2686 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002687 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002688 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002689
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002690 if (qlcnic_api_lock(adapter))
2691 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002692
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002693 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002694 if (dev_state == QLCNIC_DEV_QUISCENT ||
2695 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002696 qlcnic_api_unlock(adapter);
2697 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2698 FW_POLL_DELAY * 2);
2699 return;
2700 }
2701
Sony Chacko79788452012-12-04 03:33:53 +00002702 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002703 qlcnic_api_unlock(adapter);
2704 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002705 }
2706
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002707 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2708 dev_state == QLCNIC_DEV_READY) {
2709 dev_info(&adapter->pdev->dev, "Detected state change from "
2710 "DEV_NEED_RESET, skipping ack check\n");
2711 goto skip_ack_check;
2712 }
2713
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002714 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002715 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002716 adapter->reset_ack_timeo);
2717 goto skip_ack_check;
2718 }
2719
2720 if (!qlcnic_check_drv_state(adapter)) {
2721skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002722 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002723
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002724 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002725 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2726 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002727 set_bit(__QLCNIC_START_FW, &adapter->state);
2728 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002729 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002730 val = QLC_SHARED_REG_RD32(adapter,
2731 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002732 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002733 QLC_SHARED_REG_WR32(adapter,
2734 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002735 }
2736
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002737 qlcnic_api_unlock(adapter);
2738
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002739 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002740 if (adapter->ahw->fw_dump.enable &&
2741 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002742 QLCDB(adapter, DRV, "Take FW dump\n");
2743 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002744 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002745 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002746 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002747
2748 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002749 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002750 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002751 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002752 return;
2753 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002754 goto err_ret;
2755 }
2756
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002757 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002758
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002759wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002760 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002761 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002762
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002763 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002764 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002765 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002766 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002767 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002768 return;
2769 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002770 case QLCNIC_DEV_FAILED:
2771 break;
2772 default:
2773 qlcnic_schedule_work(adapter,
2774 qlcnic_fwinit_work, FW_POLL_DELAY);
2775 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002776 }
2777
2778err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002779 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2780 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002781 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002782 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002783}
2784
2785static void
2786qlcnic_detach_work(struct work_struct *work)
2787{
2788 struct qlcnic_adapter *adapter = container_of(work,
2789 struct qlcnic_adapter, fw_work.work);
2790 struct net_device *netdev = adapter->netdev;
2791 u32 status;
2792
2793 netif_device_detach(netdev);
2794
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002795 /* Dont grab rtnl lock during Quiscent mode */
2796 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2797 if (netif_running(netdev))
2798 __qlcnic_down(adapter, netdev);
2799 } else
2800 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002801
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002802 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002803
Sony Chacko44f65b22011-08-29 12:50:26 +00002804 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2805 dev_err(&adapter->pdev->dev,
2806 "Detaching the device: peg halt status1=0x%x\n",
2807 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002808
Sony Chacko44f65b22011-08-29 12:50:26 +00002809 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2810 dev_err(&adapter->pdev->dev,
2811 "On board active cooling fan failed. "
2812 "Device has been halted.\n");
2813 dev_err(&adapter->pdev->dev,
2814 "Replace the adapter.\n");
2815 }
2816
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002817 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002818 }
2819
Sony Chacko79788452012-12-04 03:33:53 +00002820 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002821 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002822 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002823 goto err_ret;
2824 }
2825
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002826 /* Dont ack if this instance is the reset owner */
2827 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002828 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2829 dev_err(&adapter->pdev->dev,
2830 "Failed to set driver state,"
2831 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002832 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002833 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002834 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002835
2836 adapter->fw_wait_cnt = 0;
2837
2838 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2839
2840 return;
2841
2842err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002843 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002844 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002845}
2846
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002847/*Transit NPAR state to NON Operational */
2848static void
2849qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2850{
2851 u32 state;
2852
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002853 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002854 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2855 return;
2856
2857 if (qlcnic_api_lock(adapter))
2858 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002859 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2860 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002861 qlcnic_api_unlock(adapter);
2862}
2863
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002864void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002865{
Sritej Velaga646779f2012-02-03 13:45:41 +00002866 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002867
Sritej Velaga646779f2012-02-03 13:45:41 +00002868 qlcnic_xg_set_xg0_mask(xg_val);
2869 qlcnic_xg_set_xg1_mask(xg_val);
2870 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2871 qlcnic_gb_set_gb0_mask(gb_val);
2872 qlcnic_gb_set_gb1_mask(gb_val);
2873 qlcnic_gb_set_gb2_mask(gb_val);
2874 qlcnic_gb_set_gb3_mask(gb_val);
2875 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2876 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2877 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002878 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002879
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002880 if (qlcnic_api_lock(adapter))
2881 return;
2882
Sony Chacko13159182013-01-01 03:20:21 +00002883 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002884
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002885 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00002886 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2887 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002888 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002889 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002890 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002891 }
2892
Sony Chacko13159182013-01-01 03:20:21 +00002893 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2894 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002895 qlcnic_api_unlock(adapter);
2896}
2897
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002898/* Transit to NPAR READY state from NPAR NOT READY state */
2899static void
2900qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2901{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002902 if (qlcnic_api_lock(adapter))
2903 return;
2904
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002905 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2906 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002907 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002908
2909 qlcnic_api_unlock(adapter);
2910}
2911
Sony Chacko13159182013-01-01 03:20:21 +00002912void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2913 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002914{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002915 if (test_bit(__QLCNIC_AER, &adapter->state))
2916 return;
2917
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002918 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00002919 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
2920 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002921}
2922
2923static void
2924qlcnic_attach_work(struct work_struct *work)
2925{
2926 struct qlcnic_adapter *adapter = container_of(work,
2927 struct qlcnic_adapter, fw_work.work);
2928 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002929 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002930
Sony Chacko79788452012-12-04 03:33:53 +00002931 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002932 npar_state = QLC_SHARED_REG_RD32(adapter,
2933 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002934 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2935 qlcnic_clr_all_drv_state(adapter, 0);
2936 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2937 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2938 FW_POLL_DELAY);
2939 else
2940 goto attach;
2941 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2942 return;
2943 }
2944attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002945 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002946 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002947 goto done;
2948
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002949 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002950 }
2951
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002952done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002953 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002954 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002955 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002956 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002957
2958 if (!qlcnic_clr_drv_state(adapter))
2959 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2960 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002961}
2962
2963static int
2964qlcnic_check_health(struct qlcnic_adapter *adapter)
2965{
Sony Chacko4e708122010-08-31 17:17:44 +00002966 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002967 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002968
2969 if (qlcnic_check_temp(adapter))
2970 goto detach;
2971
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002972 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002973 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002974
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002975 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002976 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002977 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002978 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002979 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2980 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002981
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002982 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00002983 if (heartbeat != adapter->heartbeat) {
2984 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002985 adapter->fw_fail_cnt = 0;
2986 if (adapter->need_fw_reset)
2987 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002988
Sony Chacko099f7aa2012-12-04 03:33:58 +00002989 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002990 qlcnic_reset_hw_context(adapter);
2991 adapter->netdev->trans_start = jiffies;
2992 }
2993
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002994 return 0;
2995 }
2996
2997 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2998 return 0;
2999
Sritej Velaga032a13c2011-07-29 13:30:27 +00003000 adapter->flags |= QLCNIC_FW_HANG;
3001
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00003002 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003003
Sony Chacko099f7aa2012-12-04 03:33:58 +00003004 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003005 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003006
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003007 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003008 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003009 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00003010 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3011 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3012 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3013 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003014 peg_status,
3015 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00003016 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3017 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3018 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3019 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3020 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00003021 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003022 dev_err(&adapter->pdev->dev,
3023 "Firmware aborted with error code 0x00006700. "
3024 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003025detach:
3026 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3027 QLCNIC_DEV_NEED_RESET;
3028
Sony Chacko099f7aa2012-12-04 03:33:58 +00003029 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3030 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003031
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003032 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003033 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3034 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003035
3036 return 1;
3037}
3038
3039static void
3040qlcnic_fw_poll_work(struct work_struct *work)
3041{
3042 struct qlcnic_adapter *adapter = container_of(work,
3043 struct qlcnic_adapter, fw_work.work);
3044
3045 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3046 goto reschedule;
3047
3048
3049 if (qlcnic_check_health(adapter))
3050 return;
3051
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003052 if (adapter->fhash.fnum)
3053 qlcnic_prune_lb_filters(adapter);
3054
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003055reschedule:
3056 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3057}
3058
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003059static int qlcnic_is_first_func(struct pci_dev *pdev)
3060{
3061 struct pci_dev *oth_pdev;
3062 int val = pdev->devfn;
3063
3064 while (val-- > 0) {
3065 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3066 (pdev->bus), pdev->bus->number,
3067 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003068 if (!oth_pdev)
3069 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003070
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003071 if (oth_pdev->current_state != PCI_D3cold) {
3072 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003073 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003074 }
3075 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003076 }
3077 return 1;
3078}
3079
3080static int qlcnic_attach_func(struct pci_dev *pdev)
3081{
3082 int err, first_func;
3083 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3084 struct net_device *netdev = adapter->netdev;
3085
3086 pdev->error_state = pci_channel_io_normal;
3087
3088 err = pci_enable_device(pdev);
3089 if (err)
3090 return err;
3091
3092 pci_set_power_state(pdev, PCI_D0);
3093 pci_set_master(pdev);
3094 pci_restore_state(pdev);
3095
3096 first_func = qlcnic_is_first_func(pdev);
3097
3098 if (qlcnic_api_lock(adapter))
3099 return -EINVAL;
3100
Sony Chacko79788452012-12-04 03:33:53 +00003101 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003102 adapter->need_fw_reset = 1;
3103 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003104 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3105 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003106 QLCDB(adapter, DRV, "Restarting fw\n");
3107 }
3108 qlcnic_api_unlock(adapter);
3109
Sony Chacko13159182013-01-01 03:20:21 +00003110 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003111 if (err)
3112 return err;
3113
3114 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003115 kfree(adapter->msix_entries);
3116 adapter->msix_entries = NULL;
3117 err = qlcnic_setup_intr(adapter, 0);
3118
Manish chopra9a97e702013-01-25 10:20:37 +00003119 if (err) {
3120 kfree(adapter->msix_entries);
3121 netdev_err(netdev, "failed to setup interrupt\n");
3122 return err;
3123 }
3124
Sony Chacko13159182013-01-01 03:20:21 +00003125 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003126 /* register for NIC IDC AEN Events */
3127 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003128 err = qlcnic_83xx_setup_mbx_intr(adapter);
3129 if (err) {
3130 dev_err(&adapter->pdev->dev,
3131 "failed to setup mbx interrupt\n");
3132 qlcnic_clr_all_drv_state(adapter, 1);
3133 clear_bit(__QLCNIC_AER, &adapter->state);
3134 goto done;
3135 }
3136 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003137
3138 if (netif_running(netdev)) {
3139 err = qlcnic_attach(adapter);
3140 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003141 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003142 clear_bit(__QLCNIC_AER, &adapter->state);
3143 netif_device_attach(netdev);
3144 return err;
3145 }
3146
3147 err = qlcnic_up(adapter, netdev);
3148 if (err)
3149 goto done;
3150
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003151 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003152 }
3153 done:
3154 netif_device_attach(netdev);
3155 return err;
3156}
3157
3158static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3159 pci_channel_state_t state)
3160{
3161 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3162 struct net_device *netdev = adapter->netdev;
3163
3164 if (state == pci_channel_io_perm_failure)
3165 return PCI_ERS_RESULT_DISCONNECT;
3166
3167 if (state == pci_channel_io_normal)
3168 return PCI_ERS_RESULT_RECOVERED;
3169
3170 set_bit(__QLCNIC_AER, &adapter->state);
3171 netif_device_detach(netdev);
3172
3173 cancel_delayed_work_sync(&adapter->fw_work);
3174
3175 if (netif_running(netdev))
3176 qlcnic_down(adapter, netdev);
3177
Sony Chacko13159182013-01-01 03:20:21 +00003178 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003179 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00003180 qlcnic_83xx_register_nic_idc_func(adapter, 0);
3181 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00003182 }
3183
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003184 qlcnic_detach(adapter);
3185 qlcnic_teardown_intr(adapter);
3186
3187 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3188
3189 pci_save_state(pdev);
3190 pci_disable_device(pdev);
3191
3192 return PCI_ERS_RESULT_NEED_RESET;
3193}
3194
3195static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3196{
3197 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3198 PCI_ERS_RESULT_RECOVERED;
3199}
3200
3201static void qlcnic_io_resume(struct pci_dev *pdev)
3202{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003203 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003204 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3205
3206 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003207 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3208 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3209 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003210 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3211 FW_POLL_DELAY);
3212}
3213
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003214static int
3215qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3216{
3217 int err;
3218
3219 err = qlcnic_can_start_firmware(adapter);
3220 if (err)
3221 return err;
3222
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003223 err = qlcnic_check_npar_opertional(adapter);
3224 if (err)
3225 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003226
Rajesh Borundia174240a2010-08-31 17:17:47 +00003227 err = qlcnic_initialize_nic(adapter);
3228 if (err)
3229 return err;
3230
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003231 qlcnic_check_options(adapter);
3232
Rajesh Borundia73733732010-08-31 17:17:50 +00003233 err = qlcnic_set_eswitch_port_config(adapter);
3234 if (err)
3235 return err;
3236
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003237 adapter->need_fw_reset = 0;
3238
3239 return err;
3240}
3241
Sony Chacko319ecf12013-01-01 03:20:22 +00003242int qlcnic_validate_max_rss(u8 max_hw, u8 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003243{
Sony Chacko319ecf12013-01-01 03:20:22 +00003244 u32 max_allowed;
3245
3246 if (max_hw > QLC_MAX_SDS_RINGS) {
3247 max_hw = QLC_MAX_SDS_RINGS;
3248 pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003249 }
3250
Sony Chacko319ecf12013-01-01 03:20:22 +00003251 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3252 num_online_cpus()));
3253 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
3254 pr_info("rss_ring valid range [2 - %x] in powers of 2\n",
3255 max_allowed);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003256 return -EINVAL;
3257 }
3258 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003259}
3260
Sony Chacko319ecf12013-01-01 03:20:22 +00003261int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003262{
Sony Chacko13159182013-01-01 03:20:21 +00003263 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003264 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003265
Sony Chacko319ecf12013-01-01 03:20:22 +00003266 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3267 return -EBUSY;
3268
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003269 netif_device_detach(netdev);
3270 if (netif_running(netdev))
3271 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003272
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003273 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003274
3275 if (qlcnic_83xx_check(adapter))
3276 qlcnic_83xx_free_mbx_intr(adapter);
3277
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003278 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003279 err = qlcnic_setup_intr(adapter, data);
Manish chopra9a97e702013-01-25 10:20:37 +00003280 if (err) {
3281 kfree(adapter->msix_entries);
3282 netdev_err(netdev, "failed to setup interrupt\n");
3283 return err;
3284 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003285
Sony Chacko13159182013-01-01 03:20:21 +00003286 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003287 /* register for NIC IDC AEN Events */
3288 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003289 err = qlcnic_83xx_setup_mbx_intr(adapter);
3290 if (err) {
3291 dev_err(&adapter->pdev->dev,
3292 "failed to setup mbx interrupt\n");
3293 goto done;
3294 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003295 }
3296
3297 if (netif_running(netdev)) {
3298 err = qlcnic_attach(adapter);
3299 if (err)
3300 goto done;
3301 err = __qlcnic_up(adapter, netdev);
3302 if (err)
3303 goto done;
3304 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3305 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003306 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003307 done:
3308 netif_device_attach(netdev);
3309 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3310 return err;
3311}
3312
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003313#ifdef CONFIG_INET
3314
3315#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3316
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003317static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003318qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3319 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003320{
3321 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003322
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003323 indev = in_dev_get(dev);
3324 if (!indev)
3325 return;
3326
3327 for_ifa(indev) {
3328 switch (event) {
3329 case NETDEV_UP:
3330 qlcnic_config_ipaddr(adapter,
3331 ifa->ifa_address, QLCNIC_IP_UP);
3332 break;
3333 case NETDEV_DOWN:
3334 qlcnic_config_ipaddr(adapter,
3335 ifa->ifa_address, QLCNIC_IP_DOWN);
3336 break;
3337 default:
3338 break;
3339 }
3340 } endfor_ifa(indev);
3341
3342 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003343}
3344
Sony Chacko319ecf12013-01-01 03:20:22 +00003345void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003346{
3347 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3348 struct net_device *dev;
3349 u16 vid;
3350
3351 qlcnic_config_indev_addr(adapter, netdev, event);
3352
Jiri Pirko43c00a72013-01-03 22:48:57 +00003353 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003354 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Patrick McHardy1fd9b1f2013-04-19 02:04:29 +00003355 dev = __vlan_find_dev_deep(netdev, htons(ETH_P_8021Q), vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003356 if (!dev)
3357 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003358 qlcnic_config_indev_addr(adapter, dev, event);
3359 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003360 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003361}
3362
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003363static int qlcnic_netdev_event(struct notifier_block *this,
3364 unsigned long event, void *ptr)
3365{
3366 struct qlcnic_adapter *adapter;
3367 struct net_device *dev = (struct net_device *)ptr;
3368
3369recheck:
3370 if (dev == NULL)
3371 goto done;
3372
3373 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3374 dev = vlan_dev_real_dev(dev);
3375 goto recheck;
3376 }
3377
3378 if (!is_qlcnic_netdev(dev))
3379 goto done;
3380
3381 adapter = netdev_priv(dev);
3382
3383 if (!adapter)
3384 goto done;
3385
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003386 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003387 goto done;
3388
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003389 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003390done:
3391 return NOTIFY_DONE;
3392}
3393
3394static int
3395qlcnic_inetaddr_event(struct notifier_block *this,
3396 unsigned long event, void *ptr)
3397{
3398 struct qlcnic_adapter *adapter;
3399 struct net_device *dev;
3400
3401 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3402
3403 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3404
3405recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003406 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003407 goto done;
3408
3409 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3410 dev = vlan_dev_real_dev(dev);
3411 goto recheck;
3412 }
3413
3414 if (!is_qlcnic_netdev(dev))
3415 goto done;
3416
3417 adapter = netdev_priv(dev);
3418
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003419 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003420 goto done;
3421
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003422 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003423 goto done;
3424
3425 switch (event) {
3426 case NETDEV_UP:
3427 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003428
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003429 break;
3430 case NETDEV_DOWN:
3431 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003432
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003433 break;
3434 default:
3435 break;
3436 }
3437
3438done:
3439 return NOTIFY_DONE;
3440}
3441
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003442static struct notifier_block qlcnic_netdev_cb = {
3443 .notifier_call = qlcnic_netdev_event,
3444};
3445
3446static struct notifier_block qlcnic_inetaddr_cb = {
3447 .notifier_call = qlcnic_inetaddr_event,
3448};
3449#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003450void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003451{ }
3452#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003453static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003454 .error_detected = qlcnic_io_error_detected,
3455 .slot_reset = qlcnic_io_slot_reset,
3456 .resume = qlcnic_io_resume,
3457};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003458
3459static struct pci_driver qlcnic_driver = {
3460 .name = qlcnic_driver_name,
3461 .id_table = qlcnic_pci_tbl,
3462 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003463 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003464#ifdef CONFIG_PM
3465 .suspend = qlcnic_suspend,
3466 .resume = qlcnic_resume,
3467#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003468 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003469 .err_handler = &qlcnic_err_handler,
3470#ifdef CONFIG_QLCNIC_SRIOV
3471 .sriov_configure = qlcnic_pci_sriov_configure,
3472#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003473
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003474};
3475
3476static int __init qlcnic_init_module(void)
3477{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003478 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003479
3480 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3481
3482#ifdef CONFIG_INET
3483 register_netdevice_notifier(&qlcnic_netdev_cb);
3484 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3485#endif
3486
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003487 ret = pci_register_driver(&qlcnic_driver);
3488 if (ret) {
3489#ifdef CONFIG_INET
3490 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3491 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3492#endif
3493 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003494
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003495 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003496}
3497
3498module_init(qlcnic_init_module);
3499
3500static void __exit qlcnic_exit_module(void)
3501{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003502 pci_unregister_driver(&qlcnic_driver);
3503
3504#ifdef CONFIG_INET
3505 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3506 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3507#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003508}
3509
3510module_exit(qlcnic_exit_module);