blob: f67e8c65350e846d6dfa5e9b708279874dbf6e79 [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 *);
Jiri Pirko8e586132011-12-08 19:52:37 -050089static int qlcnic_vlan_rx_add(struct net_device *, u16);
90static int qlcnic_vlan_rx_del(struct net_device *, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000091
Sony Chackobff57d82012-12-04 03:33:56 +000092#define QLCNIC_IS_TSO_CAPABLE(adapter) \
93 ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO)
94
Sony Chacko13159182013-01-01 03:20:21 +000095static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
96{
97 struct qlcnic_hardware_context *ahw = adapter->ahw;
98
99 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
100 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
101 else
102 return 1;
103}
104
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000105/* PCI Device ID Table */
106#define ENTRY(device) \
107 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
108 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
109
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000110static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000112 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000113 ENTRY(PCI_DEVICE_ID_QLOGIC_VF_QLE834X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000114 {0,}
115};
116
117MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
118
119
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000120inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000121{
122 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000123}
124
125static const u32 msi_tgt_status[8] = {
126 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
127 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
128 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
129 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
130};
131
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000132static const u32 qlcnic_reg_tbl[] = {
133 0x1B20A8, /* PEG_HALT_STAT1 */
134 0x1B20AC, /* PEG_HALT_STAT2 */
135 0x1B20B0, /* FW_HEARTBEAT */
136 0x1B2100, /* LOCK ID */
137 0x1B2128, /* FW_CAPABILITIES */
138 0x1B2138, /* drv active */
139 0x1B2140, /* dev state */
140 0x1B2144, /* drv state */
141 0x1B2148, /* drv scratch */
142 0x1B214C, /* dev partition info */
143 0x1B2174, /* drv idc ver */
144 0x1B2150, /* fw version major */
145 0x1B2154, /* fw version minor */
146 0x1B2158, /* fw version sub */
147 0x1B219C, /* npar state */
148 0x1B21FC, /* FW_IMG_VALID */
149 0x1B2250, /* CMD_PEG_STATE */
150 0x1B233C, /* RCV_PEG_STATE */
151 0x1B23B4, /* ASIC TEMP */
152 0x1B216C, /* FW api */
153 0x1B2170, /* drv op mode */
154 0x13C010, /* flash lock */
155 0x13C014, /* flash unlock */
156};
157
Sony Chacko22999792012-12-04 03:33:55 +0000158static const struct qlcnic_board_info qlcnic_boards[] = {
159 {0x1077, 0x8020, 0x1077, 0x203,
160 "8200 Series Single Port 10GbE Converged Network Adapter"
161 "(TCP/IP Networking)"},
162 {0x1077, 0x8020, 0x1077, 0x207,
163 "8200 Series Dual Port 10GbE Converged Network Adapter"
164 "(TCP/IP Networking)"},
165 {0x1077, 0x8020, 0x1077, 0x20b,
166 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"},
167 {0x1077, 0x8020, 0x1077, 0x20c,
168 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"},
169 {0x1077, 0x8020, 0x1077, 0x20f,
170 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"},
171 {0x1077, 0x8020, 0x103c, 0x3733,
172 "NC523SFP 10Gb 2-port Server Adapter"},
173 {0x1077, 0x8020, 0x103c, 0x3346,
174 "CN1000Q Dual Port Converged Network Adapter"},
175 {0x1077, 0x8020, 0x1077, 0x210,
176 "QME8242-k 10GbE Dual Port Mezzanine Card"},
177 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"},
178};
179
180#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
Sony Chacko319ecf12013-01-01 03:20:22 +0000181#define QLC_MAX_SDS_RINGS 8
Sony Chacko22999792012-12-04 03:33:55 +0000182
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000183static const
184struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
185
Sony Chackoc70001a2012-11-28 04:34:26 +0000186int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000187{
188 int size = sizeof(struct qlcnic_host_sds_ring) * count;
189
190 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
191
Eric Dumazet807540b2010-09-23 05:40:09 +0000192 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000193}
194
Sony Chackoc70001a2012-11-28 04:34:26 +0000195void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000196{
197 if (recv_ctx->sds_rings != NULL)
198 kfree(recv_ctx->sds_rings);
199
200 recv_ctx->sds_rings = NULL;
201}
202
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000203int qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000204{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000205 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000206 struct net_device *netdev = adapter->netdev;
207 struct pci_dev *pdev = adapter->pdev;
208
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000209 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000210 return -EIO;
211
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000212 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000213 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
214
215 /* set station address */
216
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000217 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000218 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
219 netdev->dev_addr);
220
221 return 0;
222}
223
224static int qlcnic_set_mac(struct net_device *netdev, void *p)
225{
226 struct qlcnic_adapter *adapter = netdev_priv(netdev);
227 struct sockaddr *addr = p;
228
Rajesh Borundia73733732010-08-31 17:17:50 +0000229 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
230 return -EOPNOTSUPP;
231
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000232 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000233 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000234
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000235 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000236 netif_device_detach(netdev);
237 qlcnic_napi_disable(adapter);
238 }
239
240 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
241 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
242 qlcnic_set_multi(adapter->netdev);
243
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000244 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000245 netif_device_attach(netdev);
246 qlcnic_napi_enable(adapter);
247 }
248 return 0;
249}
250
Vlad Yasevich1690be62013-02-13 12:00:18 +0000251static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
252 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000253{
254 struct qlcnic_adapter *adapter = netdev_priv(netdev);
255 int err = -EOPNOTSUPP;
256
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000257 if (!adapter->fdb_mac_learn)
258 return ndo_dflt_fdb_del(ndm, tb, netdev, addr);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000259
260 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
261 if (is_unicast_ether_addr(addr))
262 err = qlcnic_nic_del_mac(adapter, addr);
263 else if (is_multicast_ether_addr(addr))
264 err = dev_mc_del(netdev, addr);
265 else
266 err = -EINVAL;
267 }
268 return err;
269}
270
271static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
272 struct net_device *netdev,
273 const unsigned char *addr, u16 flags)
274{
275 struct qlcnic_adapter *adapter = netdev_priv(netdev);
276 int err = 0;
277
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000278 if (!adapter->fdb_mac_learn)
279 return ndo_dflt_fdb_add(ndm, tb, netdev, addr, flags);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000280
281 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
282 pr_info("%s: FDB e-switch is not enabled\n", __func__);
283 return -EOPNOTSUPP;
284 }
285
286 if (ether_addr_equal(addr, adapter->mac_addr))
287 return err;
288
289 if (is_unicast_ether_addr(addr))
290 err = qlcnic_nic_add_mac(adapter, addr);
291 else if (is_multicast_ether_addr(addr))
292 err = dev_mc_add_excl(netdev, addr);
293 else
294 err = -EINVAL;
295
296 return err;
297}
298
299static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
300 struct net_device *netdev, int idx)
301{
302 struct qlcnic_adapter *adapter = netdev_priv(netdev);
303
Vlad Yasevich3e5c1122013-03-06 15:39:45 +0000304 if (!adapter->fdb_mac_learn)
305 return ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000306
307 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
308 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
309
310 return idx;
311}
312
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000313static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
314{
315 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
316 usleep_range(10000, 11000);
317
318 cancel_delayed_work_sync(&adapter->fw_work);
319}
320
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000321static const struct net_device_ops qlcnic_netdev_ops = {
322 .ndo_open = qlcnic_open,
323 .ndo_stop = qlcnic_close,
324 .ndo_start_xmit = qlcnic_xmit_frame,
325 .ndo_get_stats = qlcnic_get_stats,
326 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000327 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000328 .ndo_set_mac_address = qlcnic_set_mac,
329 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000330 .ndo_fix_features = qlcnic_fix_features,
331 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000332 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000333 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
334 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000335 .ndo_fdb_add = qlcnic_fdb_add,
336 .ndo_fdb_del = qlcnic_fdb_del,
337 .ndo_fdb_dump = qlcnic_fdb_dump,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000338#ifdef CONFIG_NET_POLL_CONTROLLER
339 .ndo_poll_controller = qlcnic_poll_controller,
340#endif
341};
342
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000343static const struct net_device_ops qlcnic_netdev_failed_ops = {
344 .ndo_open = qlcnic_open,
345};
346
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000347static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000348 .config_bridged_mode = qlcnic_config_bridged_mode,
349 .config_led = qlcnic_82xx_config_led,
350 .start_firmware = qlcnic_82xx_start_firmware,
351 .request_reset = qlcnic_82xx_dev_request_reset,
352 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
353 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000354 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000355 .config_ipaddr = qlcnic_82xx_config_ipaddr,
356 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000357};
358
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000359struct qlcnic_nic_template qlcnic_vf_ops = {
360 .config_bridged_mode = qlcnicvf_config_bridged_mode,
361 .config_led = qlcnicvf_config_led,
362 .start_firmware = qlcnicvf_start_firmware
363};
364
365static struct qlcnic_hardware_ops qlcnic_hw_ops = {
366 .read_crb = qlcnic_82xx_read_crb,
367 .write_crb = qlcnic_82xx_write_crb,
368 .read_reg = qlcnic_82xx_hw_read_wx_2M,
369 .write_reg = qlcnic_82xx_hw_write_wx_2M,
370 .get_mac_address = qlcnic_82xx_get_mac_address,
371 .setup_intr = qlcnic_82xx_setup_intr,
372 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
373 .mbx_cmd = qlcnic_82xx_issue_cmd,
374 .get_func_no = qlcnic_82xx_get_func_no,
375 .api_lock = qlcnic_82xx_api_lock,
376 .api_unlock = qlcnic_82xx_api_unlock,
377 .add_sysfs = qlcnic_82xx_add_sysfs,
378 .remove_sysfs = qlcnic_82xx_remove_sysfs,
379 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
380 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
381 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
382 .setup_link_event = qlcnic_82xx_linkevent_request,
383 .get_nic_info = qlcnic_82xx_get_nic_info,
384 .get_pci_info = qlcnic_82xx_get_pci_info,
385 .set_nic_info = qlcnic_82xx_set_nic_info,
386 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
387 .napi_enable = qlcnic_82xx_napi_enable,
388 .napi_disable = qlcnic_82xx_napi_disable,
389 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
390 .config_rss = qlcnic_82xx_config_rss,
391 .config_hw_lro = qlcnic_82xx_config_hw_lro,
392 .config_loopback = qlcnic_82xx_set_lb_mode,
393 .clear_loopback = qlcnic_82xx_clear_lb_mode,
394 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
395 .change_l2_filter = qlcnic_82xx_change_filter,
396 .get_board_info = qlcnic_82xx_get_board_info,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000397};
398
Sony Chacko7f9664522013-01-01 03:20:19 +0000399int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000400{
401 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000402 int err = -1, i;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000403 int max_tx_rings, tx_vector;
404
405 if (adapter->flags & QLCNIC_TX_INTR_SHARED) {
406 max_tx_rings = 0;
407 tx_vector = 0;
408 } else {
409 max_tx_rings = adapter->max_drv_tx_rings;
410 tx_vector = 1;
411 }
Sony Chacko13159182013-01-01 03:20:21 +0000412
413 if (!adapter->msix_entries) {
414 adapter->msix_entries = kcalloc(num_msix,
415 sizeof(struct msix_entry),
416 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000417 if (!adapter->msix_entries)
Sony Chacko13159182013-01-01 03:20:21 +0000418 return -ENOMEM;
Sony Chacko13159182013-01-01 03:20:21 +0000419 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000420
421 adapter->max_sds_rings = 1;
422 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000423
Sony Chacko79788452012-12-04 03:33:53 +0000424 if (adapter->ahw->msix_supported) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000425 enable_msix:
Sony Chacko13159182013-01-01 03:20:21 +0000426 for (i = 0; i < num_msix; i++)
427 adapter->msix_entries[i].entry = i;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000428 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
429 if (err == 0) {
430 adapter->flags |= QLCNIC_MSIX_ENABLED;
Sony Chacko13159182013-01-01 03:20:21 +0000431 if (qlcnic_83xx_check(adapter)) {
432 adapter->ahw->num_msix = num_msix;
433 /* subtract mail box and tx ring vectors */
Sony Chacko13159182013-01-01 03:20:21 +0000434 adapter->max_sds_rings = num_msix -
435 max_tx_rings - 1;
436 } else {
437 adapter->max_sds_rings = num_msix;
438 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000439 dev_info(&pdev->dev, "using msi-x interrupts\n");
440 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000441 } else if (err > 0) {
442 dev_info(&pdev->dev,
443 "Unable to allocate %d MSI-X interrupt vectors\n",
444 num_msix);
445 if (qlcnic_83xx_check(adapter)) {
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000446 if (err < (QLC_83XX_MINIMUM_VECTOR - tx_vector))
Sony Chacko13159182013-01-01 03:20:21 +0000447 return err;
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000448 err -= (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000449 num_msix = rounddown_pow_of_two(err);
Rajesh Borundiada6c8062013-03-29 05:46:35 +0000450 num_msix += (max_tx_rings + 1);
Sony Chacko13159182013-01-01 03:20:21 +0000451 } else {
452 num_msix = rounddown_pow_of_two(err);
453 }
454
455 if (num_msix) {
456 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000457 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000458 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000459 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000460 }
461 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000462 dev_info(&pdev->dev,
463 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000464 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000465 }
466 }
Sony Chacko13159182013-01-01 03:20:21 +0000467
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000468 return err;
469}
470
Manish chopra9a97e702013-01-25 10:20:37 +0000471static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000472{
Manish chopra9a97e702013-01-25 10:20:37 +0000473 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000474 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000475 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000476 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000477 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000478
Sony Chacko099f7aa2012-12-04 03:33:58 +0000479 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000480 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000481 offset = msi_tgt_status[adapter->ahw->pci_func];
482 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
483 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000484 dev_info(&pdev->dev, "using msi interrupts\n");
485 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000486 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000487 }
Manish chopra9a97e702013-01-25 10:20:37 +0000488 if (qlcnic_use_msi || qlcnic_use_msi_x)
489 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000490
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000491 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000492 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000493 offset = legacy_intrp->tgt_status_reg;
494 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
495 mask_reg = legacy_intrp->tgt_mask_reg;
496 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
497 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
498 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000499 dev_info(&pdev->dev, "using legacy interrupts\n");
500 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000501 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000502}
503
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000504int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000505{
Manish chopra9a97e702013-01-25 10:20:37 +0000506 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000507
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000508 if (!num_intr)
509 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
510
511 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000512 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000513 num_intr));
514 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000515 num_msix = 1;
516
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000517 err = qlcnic_enable_msix(adapter, num_msix);
518 if (err == -ENOMEM || !err)
519 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000520
Manish chopra9a97e702013-01-25 10:20:37 +0000521 err = qlcnic_enable_msi_legacy(adapter);
522 if (!err)
523 return err;
524
525 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000526}
Sony Chacko13159182013-01-01 03:20:21 +0000527
Sony Chacko319ecf12013-01-01 03:20:22 +0000528void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000529{
530 if (adapter->flags & QLCNIC_MSIX_ENABLED)
531 pci_disable_msix(adapter->pdev);
532 if (adapter->flags & QLCNIC_MSI_ENABLED)
533 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000534
535 kfree(adapter->msix_entries);
536 adapter->msix_entries = NULL;
537
538 if (adapter->ahw->intr_tbl) {
539 vfree(adapter->ahw->intr_tbl);
540 adapter->ahw->intr_tbl = NULL;
541 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000542}
543
544static void
545qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
546{
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000547 if (adapter->ahw->pci_base0 != NULL)
548 iounmap(adapter->ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000549}
550
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000551static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
552{
553 struct qlcnic_pci_info *pci_info;
554 int ret;
555
556 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
557 switch (adapter->ahw->port_type) {
558 case QLCNIC_GBE:
559 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
560 break;
561 case QLCNIC_XGBE:
562 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
563 break;
564 }
565 return 0;
566 }
567
568 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
569 return 0;
570
571 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
572 if (!pci_info)
573 return -ENOMEM;
574
575 ret = qlcnic_get_pci_info(adapter, pci_info);
576 kfree(pci_info);
577 return ret;
578}
Sony Chackod71170f2013-01-01 03:20:26 +0000579
580int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000581{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000582 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000583 int i, ret = 0, j = 0;
584 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000585 u8 pfn;
586
Dan Carpentere88db3b2010-08-09 21:49:36 +0000587 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
588 if (!pci_info)
589 return -ENOMEM;
590
Sony Chackobff57d82012-12-04 03:33:56 +0000591 ret = qlcnic_get_pci_info(adapter, pci_info);
592 if (ret)
593 goto err_pci_info;
594
595 act_pci_func = adapter->ahw->act_pci_func;
596
Dan Carpenterca315ac2010-08-09 21:47:56 +0000597 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000598 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000599 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000600 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000601 goto err_pci_info;
602 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000603
Dan Carpenterca315ac2010-08-09 21:47:56 +0000604 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000605 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
606 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000607 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000608 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000609 }
610
Dan Carpenterca315ac2010-08-09 21:47:56 +0000611 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
612 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000613
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000614 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000615 ret = QL_STATUS_INVALID_PARAM;
616 goto err_eswitch;
617 }
Sony Chackobff57d82012-12-04 03:33:56 +0000618
619 if (!pci_info[i].active ||
620 (pci_info[i].type != QLCNIC_TYPE_NIC))
621 continue;
622
623 adapter->npars[j].pci_func = pfn;
624 adapter->npars[j].active = (u8)pci_info[i].active;
625 adapter->npars[j].type = (u8)pci_info[i].type;
626 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
627 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
628 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
629 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000630 }
631
Sony Chacko13159182013-01-01 03:20:21 +0000632 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000633 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000634 if (qlcnic_83xx_check(adapter))
635 qlcnic_enable_eswitch(adapter, i, 1);
636 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000637
Dan Carpentere88db3b2010-08-09 21:49:36 +0000638 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000639 return 0;
640
641err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000642 kfree(adapter->eswitch);
643 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000644err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000645 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000646 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000647err_pci_info:
648 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000649
650 return ret;
651}
652
653static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000654qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
655{
656 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000657 int i, ret = 1;
658 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000659 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000660
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000661 ret = qlcnic_api_lock(adapter);
662 if (ret)
663 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000664
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000665 if (qlcnic_config_npars) {
Sony Chackobff57d82012-12-04 03:33:56 +0000666 for (i = 0; i < ahw->act_pci_func; i++) {
667 id = adapter->npars[i].pci_func;
668 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000669 continue;
670 data |= (qlcnic_config_npars &
671 QLC_DEV_SET_DRV(0xf, id));
672 }
673 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000674 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d82012-12-04 03:33:56 +0000675 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000676 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d82012-12-04 03:33:56 +0000677 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000678 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000679 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000680 qlcnic_api_unlock(adapter);
681err_lock:
682 return ret;
683}
684
Sony Chacko13159182013-01-01 03:20:21 +0000685static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
686 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000687{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000688 u32 op_mode, priv_level;
689
690 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000691 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
692 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000693
694 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000695 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000696
697 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000698 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000699 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000700 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000701 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000702 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000703
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000704 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000705 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000706 dev_info(&adapter->pdev->dev,
707 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000708 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000709 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000710 } else
711 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000712}
713
Sony Chacko15087c22012-12-04 03:33:54 +0000714#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000715#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000716static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000717{
Sony Chacko15087c22012-12-04 03:33:54 +0000718 switch (dev_id) {
719 case PCI_DEVICE_ID_QLOGIC_QLE824X:
720 *bar = QLCNIC_82XX_BAR0_LENGTH;
721 break;
Sony Chacko13159182013-01-01 03:20:21 +0000722 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000723 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +0000724 *bar = QLCNIC_83XX_BAR0_LENGTH;
725 break;
Sony Chacko15087c22012-12-04 03:33:54 +0000726 default:
727 *bar = 0;
728 }
729}
730
731static int qlcnic_setup_pci_map(struct pci_dev *pdev,
732 struct qlcnic_hardware_context *ahw)
733{
734 u32 offset;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000735 void __iomem *mem_ptr0 = NULL;
Sony Chacko15087c22012-12-04 03:33:54 +0000736 unsigned long mem_len, pci_len0 = 0, bar0_len;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000737
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000738 /* remap phys address */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000739 mem_len = pci_resource_len(pdev, 0);
740
Sony Chacko15087c22012-12-04 03:33:54 +0000741 qlcnic_get_bar_length(pdev->device, &bar0_len);
742 if (mem_len >= bar0_len) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000743
744 mem_ptr0 = pci_ioremap_bar(pdev, 0);
745 if (mem_ptr0 == NULL) {
746 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
747 return -EIO;
748 }
749 pci_len0 = mem_len;
750 } else {
751 return -EIO;
752 }
753
Rajesh Borundiaf8468332013-03-29 05:46:34 +0000754 dev_info(&pdev->dev, "%dKB memory map\n", (int)(mem_len >> 10));
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000755
Sony Chacko15087c22012-12-04 03:33:54 +0000756 ahw->pci_base0 = mem_ptr0;
757 ahw->pci_len0 = pci_len0;
758 offset = QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(ahw->pci_func));
759 qlcnic_get_ioaddr(ahw, offset);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000760
761 return 0;
762}
763
Sony Chacko22999792012-12-04 03:33:55 +0000764static void qlcnic_get_board_name(struct qlcnic_adapter *adapter, char *name)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000765{
766 struct pci_dev *pdev = adapter->pdev;
767 int i, found = 0;
768
769 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
770 if (qlcnic_boards[i].vendor == pdev->vendor &&
771 qlcnic_boards[i].device == pdev->device &&
772 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
773 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000774 sprintf(name, "%pM: %s" ,
775 adapter->mac_addr,
776 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000777 found = 1;
778 break;
779 }
780
781 }
782
783 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000784 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000785}
786
787static void
788qlcnic_check_options(struct qlcnic_adapter *adapter)
789{
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000790 int err;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000791 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000792 struct pci_dev *pdev = adapter->pdev;
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000793 struct qlcnic_hardware_context *ahw = adapter->ahw;
794 struct qlcnic_fw_dump *fw_dump = &ahw->fw_dump;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000795
796 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000797
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000798 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
799 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
800 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000801
802 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
803
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000804 err = qlcnic_get_board_info(adapter);
805 if (err) {
806 dev_err(&pdev->dev, "Error getting board config info.\n");
807 return;
808 }
809 if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
Sritej Velaga031a4a22011-07-29 13:30:28 +0000810 if (fw_dump->tmpl_hdr == NULL ||
811 adapter->fw_version > prev_fw_version) {
812 if (fw_dump->tmpl_hdr)
813 vfree(fw_dump->tmpl_hdr);
814 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
815 dev_info(&pdev->dev,
816 "Supports FW dump capability\n");
817 }
818 }
819
Sony Chacko13159182013-01-01 03:20:21 +0000820 dev_info(&pdev->dev, "Driver v%s, firmware v%d.%d.%d\n",
821 QLCNIC_LINUX_VERSIONID, fw_major, fw_minor, fw_build);
822
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000823 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000824 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
825 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
826 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
827 } else {
828 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
829 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
830 }
831
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000832 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000833 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
834
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000835 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000836 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
837 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000838 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
839 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000840 }
841
Sony Chacko099f7aa2012-12-04 03:33:58 +0000842 adapter->ahw->msix_supported = !!qlcnic_use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000843
844 adapter->num_txd = MAX_CMD_DESCRIPTORS;
845
Sony Chacko251b0362010-08-19 05:08:24 +0000846 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000847}
848
Rajesh Borundia174240a2010-08-31 17:17:47 +0000849static int
850qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
851{
852 int err;
853 struct qlcnic_info nic_info;
854
Sony Chackobff57d82012-12-04 03:33:56 +0000855 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000856 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000857 if (err)
858 return err;
859
Sony Chacko79788452012-12-04 03:33:53 +0000860 adapter->ahw->physical_port = (u8)nic_info.phys_port;
861 adapter->ahw->switch_mode = nic_info.switch_mode;
862 adapter->ahw->max_tx_ques = nic_info.max_tx_ques;
863 adapter->ahw->max_rx_ques = nic_info.max_rx_ques;
864 adapter->ahw->capabilities = nic_info.capabilities;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +0000865
866 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
867 u32 temp;
868 temp = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
869 adapter->ahw->capabilities2 = temp;
870 }
Sony Chacko79788452012-12-04 03:33:53 +0000871 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
872 adapter->ahw->max_mtu = nic_info.max_mtu;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000873
Sony Chacko13159182013-01-01 03:20:21 +0000874 /* Disable NPAR for 83XX */
875 if (qlcnic_83xx_check(adapter))
876 return err;
877
Sony Chacko79788452012-12-04 03:33:53 +0000878 if (adapter->ahw->capabilities & BIT_6)
Rajesh Borundia174240a2010-08-31 17:17:47 +0000879 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
880 else
881 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
882
883 return err;
884}
885
Sony Chackoec079a02012-11-28 04:34:28 +0000886void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
887 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000888{
889 if (esw_cfg->discard_tagged)
890 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
891 else
892 adapter->flags |= QLCNIC_TAGGING_ENABLED;
893
894 if (esw_cfg->vlan_id)
895 adapter->pvid = esw_cfg->vlan_id;
896 else
897 adapter->pvid = 0;
898}
899
Jiri Pirko8e586132011-12-08 19:52:37 -0500900static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000901qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid)
902{
903 struct qlcnic_adapter *adapter = netdev_priv(netdev);
904 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500905 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000906}
907
Jiri Pirko8e586132011-12-08 19:52:37 -0500908static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000909qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid)
910{
911 struct qlcnic_adapter *adapter = netdev_priv(netdev);
912
913 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
914 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500915 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000916}
917
Sony Chackoec079a02012-11-28 04:34:28 +0000918void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
919 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000920{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000921 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
922 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000923
924 if (esw_cfg->mac_anti_spoof)
925 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000926
Rajesh Borundia73733732010-08-31 17:17:50 +0000927 if (!esw_cfg->mac_override)
928 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
929
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000930 if (!esw_cfg->promisc_mode)
931 adapter->flags |= QLCNIC_PROMISC_DISABLED;
932
Rajesh Borundia0325d692010-08-19 05:08:26 +0000933 qlcnic_set_netdev_features(adapter, esw_cfg);
934}
935
Sony Chackod71170f2013-01-01 03:20:26 +0000936int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000937{
938 struct qlcnic_esw_func_cfg esw_cfg;
939
940 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
941 return 0;
942
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000943 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000944 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
945 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000946 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000947 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
948
949 return 0;
950}
951
952static void
953qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
954 struct qlcnic_esw_func_cfg *esw_cfg)
955{
956 struct net_device *netdev = adapter->netdev;
Sony Chacko13159182013-01-01 03:20:21 +0000957 unsigned long features, vlan_features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000958
Sony Chacko13159182013-01-01 03:20:21 +0000959 if (qlcnic_83xx_check(adapter))
960 return;
961
Sony Chacko7e38d042013-01-01 03:20:28 +0000962 features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
963 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000964 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Sony Chacko13159182013-01-01 03:20:21 +0000965 NETIF_F_IPV6_CSUM);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000966
Sony Chacko13159182013-01-01 03:20:21 +0000967 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000968 features |= (NETIF_F_TSO | NETIF_F_TSO6);
969 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
970 }
Rajesh Borundiab56421d2011-04-01 14:28:31 +0000971
972 if (netdev->features & NETIF_F_LRO)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000973 features |= NETIF_F_LRO;
974
975 if (esw_cfg->offload_flags & BIT_0) {
976 netdev->features |= features;
Sony Chacko13159182013-01-01 03:20:21 +0000977 adapter->rx_csum = 1;
Sony Chacko7e38d042013-01-01 03:20:28 +0000978 if (!(esw_cfg->offload_flags & BIT_1)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000979 netdev->features &= ~NETIF_F_TSO;
Sony Chacko7e38d042013-01-01 03:20:28 +0000980 features &= ~NETIF_F_TSO;
981 }
982 if (!(esw_cfg->offload_flags & BIT_2)) {
Rajesh Borundia0325d692010-08-19 05:08:26 +0000983 netdev->features &= ~NETIF_F_TSO6;
Sony Chacko7e38d042013-01-01 03:20:28 +0000984 features &= ~NETIF_F_TSO6;
985 }
Rajesh Borundia0325d692010-08-19 05:08:26 +0000986 } else {
987 netdev->features &= ~features;
Sony Chacko7e38d042013-01-01 03:20:28 +0000988 features &= ~features;
Sony Chacko13159182013-01-01 03:20:21 +0000989 adapter->rx_csum = 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000990 }
991
992 netdev->vlan_features = (features & vlan_features);
993}
994
995static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000996qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
997{
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000998 u32 op_mode, priv_level;
999 int err = 0;
1000
Rajesh Borundia174240a2010-08-31 17:17:47 +00001001 err = qlcnic_initialize_nic(adapter);
1002 if (err)
1003 return err;
1004
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001005 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
1006 return 0;
1007
Sony Chacko13159182013-01-01 03:20:21 +00001008 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001009 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001010
1011 if (op_mode == QLC_DEV_DRV_DEFAULT)
1012 priv_level = QLCNIC_MGMT_FUNC;
1013 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001014 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001015
Rajesh Borundia174240a2010-08-31 17:17:47 +00001016 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001017 if (priv_level == QLCNIC_MGMT_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001018 adapter->ahw->op_mode = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001019 err = qlcnic_init_pci_info(adapter);
1020 if (err)
1021 return err;
1022 /* Set privilege level for other functions */
1023 qlcnic_set_function_modes(adapter);
1024 dev_info(&adapter->pdev->dev,
1025 "HAL Version: %d, Management function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001026 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001027 } else if (priv_level == QLCNIC_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +00001028 adapter->ahw->op_mode = QLCNIC_PRIV_FUNC;
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001029 dev_info(&adapter->pdev->dev,
1030 "HAL Version: %d, Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +00001031 adapter->ahw->fw_hal_version);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001032 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001033 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001034
1035 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
1036
1037 return err;
1038}
1039
Sony Chackod71170f2013-01-01 03:20:26 +00001040int qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001041{
1042 struct qlcnic_esw_func_cfg esw_cfg;
1043 struct qlcnic_npar_info *npar;
1044 u8 i;
1045
Rajesh Borundia174240a2010-08-31 17:17:47 +00001046 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +00001047 return 0;
1048
Sony Chackobff57d82012-12-04 03:33:56 +00001049 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +00001050 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
Sony Chackobff57d82012-12-04 03:33:56 +00001051 esw_cfg.pci_func = adapter->npars[i].pci_func;
Rajesh Borundia73733732010-08-31 17:17:50 +00001052 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00001053 esw_cfg.promisc_mode = BIT_0;
Sony Chackobff57d82012-12-04 03:33:56 +00001054 if (qlcnic_82xx_check(adapter)) {
1055 esw_cfg.offload_flags = BIT_0;
1056 if (QLCNIC_IS_TSO_CAPABLE(adapter))
1057 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
1058 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00001059 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1060 return -EIO;
1061 npar = &adapter->npars[i];
1062 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +00001063 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001064 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
1065 npar->discard_tagged = esw_cfg.discard_tagged;
1066 npar->promisc_mode = esw_cfg.promisc_mode;
1067 npar->offload_flags = esw_cfg.offload_flags;
1068 }
1069
1070 return 0;
1071}
1072
Sony Chacko13159182013-01-01 03:20:21 +00001073
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001074static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001075qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
1076 struct qlcnic_npar_info *npar, int pci_func)
1077{
1078 struct qlcnic_esw_func_cfg esw_cfg;
1079 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
1080 esw_cfg.pci_func = pci_func;
1081 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +00001082 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001083 esw_cfg.discard_tagged = npar->discard_tagged;
1084 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
1085 esw_cfg.offload_flags = npar->offload_flags;
1086 esw_cfg.promisc_mode = npar->promisc_mode;
1087 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1088 return -EIO;
1089
1090 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
1091 if (qlcnic_config_switch_port(adapter, &esw_cfg))
1092 return -EIO;
1093
1094 return 0;
1095}
1096
Sony Chackod71170f2013-01-01 03:20:26 +00001097int qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001098{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001099 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001100 struct qlcnic_npar_info *npar;
1101 struct qlcnic_info nic_info;
Sony Chackobff57d82012-12-04 03:33:56 +00001102 u8 pci_func;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001103
Sony Chackobff57d82012-12-04 03:33:56 +00001104 if (qlcnic_82xx_check(adapter))
1105 if (!adapter->need_fw_reset)
1106 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001107
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001108 /* Set the NPAR config data after FW reset */
Sony Chackobff57d82012-12-04 03:33:56 +00001109 for (i = 0; i < adapter->ahw->act_pci_func; i++) {
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001110 npar = &adapter->npars[i];
Sony Chackobff57d82012-12-04 03:33:56 +00001111 pci_func = npar->pci_func;
1112 memset(&nic_info, 0, sizeof(struct qlcnic_info));
Sony Chacko13159182013-01-01 03:20:21 +00001113 err = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001114 if (err)
1115 return err;
1116 nic_info.min_tx_bw = npar->min_bw;
1117 nic_info.max_tx_bw = npar->max_bw;
1118 err = qlcnic_set_nic_info(adapter, &nic_info);
1119 if (err)
1120 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001121
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001122 if (npar->enable_pm) {
1123 err = qlcnic_config_port_mirroring(adapter,
Sony Chackobff57d82012-12-04 03:33:56 +00001124 npar->dest_npar, 1,
1125 pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001126 if (err)
1127 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001128 }
Sony Chackobff57d82012-12-04 03:33:56 +00001129 err = qlcnic_reset_eswitch_config(adapter, npar, pci_func);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001130 if (err)
1131 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001132 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00001133 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001134}
1135
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001136static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
1137{
1138 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
1139 u32 npar_state;
1140
Sony Chacko79788452012-12-04 03:33:53 +00001141 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001142 return 0;
1143
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001144 npar_state = QLC_SHARED_REG_RD32(adapter,
1145 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001146 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
1147 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001148 npar_state = QLC_SHARED_REG_RD32(adapter,
1149 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001150 }
1151 if (!npar_opt_timeo) {
1152 dev_err(&adapter->pdev->dev,
Masanari Iida8a168ca2012-12-29 02:00:09 +09001153 "Waiting for NPAR state to operational timeout\n");
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00001154 return -EIO;
1155 }
1156 return 0;
1157}
1158
Anirban Chakrabortycea89752010-07-13 20:33:35 +00001159static int
Rajesh Borundia174240a2010-08-31 17:17:47 +00001160qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
1161{
1162 int err;
1163
1164 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
Sony Chacko79788452012-12-04 03:33:53 +00001165 adapter->ahw->op_mode != QLCNIC_MGMT_FUNC)
Rajesh Borundia174240a2010-08-31 17:17:47 +00001166 return 0;
1167
1168 err = qlcnic_set_default_offload_settings(adapter);
1169 if (err)
1170 return err;
1171
1172 err = qlcnic_reset_npar_config(adapter);
1173 if (err)
1174 return err;
1175
1176 qlcnic_dev_set_npar_ready(adapter);
1177
1178 return err;
1179}
1180
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001181int qlcnic_82xx_start_firmware(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001182{
Sony Chackod4066832010-08-19 05:08:31 +00001183 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001184
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00001185 err = qlcnic_can_start_firmware(adapter);
1186 if (err < 0)
1187 return err;
1188 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +00001189 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001190
Sony Chacko099f7aa2012-12-04 03:33:58 +00001191 if (qlcnic_load_fw_file)
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +00001192 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +00001193 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +00001194 err = qlcnic_check_flash_fw_ver(adapter);
1195 if (err)
schacko8f891382010-06-17 02:56:40 +00001196 goto err_out;
1197
Sony Chacko79788452012-12-04 03:33:53 +00001198 adapter->ahw->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001199 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001200
1201 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001202 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001203 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001204
Sony Chackod4066832010-08-19 05:08:31 +00001205 err = qlcnic_pinit_from_rom(adapter);
1206 if (err)
1207 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001208
1209 err = qlcnic_load_firmware(adapter);
1210 if (err)
1211 goto err_out;
1212
1213 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001214 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001215
Sony Chackod4066832010-08-19 05:08:31 +00001216check_fw_status:
1217 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001218 if (err)
1219 goto err_out;
1220
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001221 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001222 qlcnic_idc_debug_info(adapter, 1);
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001223 err = qlcnic_check_eswitch_mode(adapter);
1224 if (err) {
1225 dev_err(&adapter->pdev->dev,
1226 "Memory allocation failed for eswitch\n");
1227 goto err_out;
1228 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001229 err = qlcnic_set_mgmt_operations(adapter);
1230 if (err)
1231 goto err_out;
1232
1233 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001234 adapter->need_fw_reset = 0;
1235
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001236 qlcnic_release_firmware(adapter);
1237 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001238
1239err_out:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00001240 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001241 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001242
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001243 qlcnic_release_firmware(adapter);
1244 return err;
1245}
1246
1247static int
1248qlcnic_request_irq(struct qlcnic_adapter *adapter)
1249{
1250 irq_handler_t handler;
1251 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001252 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001253 int err, ring;
1254
1255 unsigned long flags = 0;
1256 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001257 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001258
Sony Chacko79788452012-12-04 03:33:53 +00001259 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Sony Chacko13159182013-01-01 03:20:21 +00001260 if (qlcnic_82xx_check(adapter))
1261 handler = qlcnic_tmp_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001262 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1263 flags |= IRQF_SHARED;
1264
1265 } else {
1266 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1267 handler = qlcnic_msix_intr;
1268 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1269 handler = qlcnic_msi_intr;
1270 else {
1271 flags |= IRQF_SHARED;
Himanshu Madhaniac166702013-02-18 12:06:15 +00001272 if (qlcnic_82xx_check(adapter))
1273 handler = qlcnic_intr;
1274 else
1275 handler = qlcnic_83xx_intr;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001276 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001277 }
1278 adapter->irq = netdev->irq;
1279
Sony Chacko13159182013-01-01 03:20:21 +00001280 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001281 if (qlcnic_82xx_check(adapter) ||
1282 (qlcnic_83xx_check(adapter) &&
1283 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1284 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1285 sds_ring = &recv_ctx->sds_rings[ring];
1286 snprintf(sds_ring->name, sizeof(int) + IFNAMSIZ,
1287 "%s[%d]", netdev->name, ring);
1288 err = request_irq(sds_ring->irq, handler, flags,
1289 sds_ring->name, sds_ring);
1290 if (err)
1291 return err;
1292 }
Sony Chacko13159182013-01-01 03:20:21 +00001293 }
1294 if (qlcnic_83xx_check(adapter) &&
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001295 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1296 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001297 handler = qlcnic_msix_tx_intr;
1298 for (ring = 0; ring < adapter->max_drv_tx_rings;
1299 ring++) {
1300 tx_ring = &adapter->tx_ring[ring];
1301 snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ,
1302 "%s[%d]", netdev->name,
Himanshu Madhaniac166702013-02-18 12:06:15 +00001303 adapter->max_sds_rings + ring);
Sony Chacko13159182013-01-01 03:20:21 +00001304 err = request_irq(tx_ring->irq, handler, flags,
1305 tx_ring->name, tx_ring);
1306 if (err)
1307 return err;
1308 }
1309 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001310 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001311 return 0;
1312}
1313
1314static void
1315qlcnic_free_irq(struct qlcnic_adapter *adapter)
1316{
1317 int ring;
1318 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001319 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001320
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001321 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001322
Sony Chacko13159182013-01-01 03:20:21 +00001323 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001324 if (qlcnic_82xx_check(adapter) ||
1325 (qlcnic_83xx_check(adapter) &&
1326 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1327 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1328 sds_ring = &recv_ctx->sds_rings[ring];
1329 free_irq(sds_ring->irq, sds_ring);
1330 }
Sony Chacko13159182013-01-01 03:20:21 +00001331 }
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001332 if (qlcnic_83xx_check(adapter) &&
1333 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko13159182013-01-01 03:20:21 +00001334 for (ring = 0; ring < adapter->max_drv_tx_rings;
1335 ring++) {
1336 tx_ring = &adapter->tx_ring[ring];
1337 if (tx_ring->irq)
1338 free_irq(tx_ring->irq, tx_ring);
1339 }
1340 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001341 }
1342}
1343
Shahed Shaikh99e85872013-02-18 12:06:16 +00001344static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1345{
1346 u32 capab = 0;
1347
1348 if (qlcnic_82xx_check(adapter)) {
1349 if (adapter->ahw->capabilities2 &
1350 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1351 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1352 } else {
1353 capab = adapter->ahw->capabilities;
1354 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1355 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1356 }
1357}
1358
Sony Chacko319ecf12013-01-01 03:20:22 +00001359int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001360{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001361 int ring;
1362 struct qlcnic_host_rds_ring *rds_ring;
1363
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001364 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1365 return -EIO;
1366
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001367 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1368 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001369 if (qlcnic_set_eswitch_port_config(adapter))
1370 return -EIO;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001371 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001372
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001373 if (qlcnic_fw_create_ctx(adapter))
1374 return -EIO;
1375
1376 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001377 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001378 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001379 }
1380
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001381 qlcnic_set_multi(netdev);
1382 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1383
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001384 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001385
1386 if (adapter->max_sds_rings > 1)
1387 qlcnic_config_rss(adapter, 1);
1388
1389 qlcnic_config_intr_coalesce(adapter);
1390
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001391 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001392 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1393
1394 qlcnic_napi_enable(adapter);
1395
1396 qlcnic_linkevent_request(adapter, 1);
1397
Sony Chacko79788452012-12-04 03:33:53 +00001398 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001399 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1400 return 0;
1401}
1402
Sony Chacko629263a2013-01-01 04:11:55 +00001403int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001404{
1405 int err = 0;
1406
1407 rtnl_lock();
1408 if (netif_running(netdev))
1409 err = __qlcnic_up(adapter, netdev);
1410 rtnl_unlock();
1411
1412 return err;
1413}
1414
Sony Chacko319ecf12013-01-01 03:20:22 +00001415void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001416{
1417 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1418 return;
1419
1420 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1421 return;
1422
1423 smp_mb();
1424 spin_lock(&adapter->tx_clean_lock);
1425 netif_carrier_off(netdev);
Shahed Shaikh0a46bac2013-03-22 05:57:56 +00001426 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001427 netif_tx_disable(netdev);
1428
1429 qlcnic_free_mac_list(adapter);
1430
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001431 if (adapter->fhash.fnum)
1432 qlcnic_delete_lb_filters(adapter);
1433
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001434 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1435
1436 qlcnic_napi_disable(adapter);
1437
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001438 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001439 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001440
1441 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001442 qlcnic_release_tx_buffers(adapter);
1443 spin_unlock(&adapter->tx_clean_lock);
1444}
1445
1446/* Usage: During suspend and firmware recovery module */
1447
Sony Chacko629263a2013-01-01 04:11:55 +00001448void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001449{
1450 rtnl_lock();
1451 if (netif_running(netdev))
1452 __qlcnic_down(adapter, netdev);
1453 rtnl_unlock();
1454
1455}
1456
Sony Chacko319ecf12013-01-01 03:20:22 +00001457int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001458qlcnic_attach(struct qlcnic_adapter *adapter)
1459{
1460 struct net_device *netdev = adapter->netdev;
1461 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001462 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001463
1464 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1465 return 0;
1466
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001467 err = qlcnic_napi_add(adapter, netdev);
1468 if (err)
1469 return err;
1470
1471 err = qlcnic_alloc_sw_resources(adapter);
1472 if (err) {
1473 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001474 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001475 }
1476
1477 err = qlcnic_alloc_hw_resources(adapter);
1478 if (err) {
1479 dev_err(&pdev->dev, "Error in setting hw resources\n");
1480 goto err_out_free_sw;
1481 }
1482
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001483 err = qlcnic_request_irq(adapter);
1484 if (err) {
1485 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001486 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001487 }
1488
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001489 qlcnic_create_sysfs_entries(adapter);
1490
1491 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1492 return 0;
1493
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001494err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001495 qlcnic_free_hw_resources(adapter);
1496err_out_free_sw:
1497 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001498err_out_napi_del:
1499 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001500 return err;
1501}
1502
Sony Chacko319ecf12013-01-01 03:20:22 +00001503void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001504{
1505 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1506 return;
1507
1508 qlcnic_remove_sysfs_entries(adapter);
1509
1510 qlcnic_free_hw_resources(adapter);
1511 qlcnic_release_rx_buffers(adapter);
1512 qlcnic_free_irq(adapter);
1513 qlcnic_napi_del(adapter);
1514 qlcnic_free_sw_resources(adapter);
1515
1516 adapter->is_up = 0;
1517}
1518
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001519void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1520{
1521 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1522 struct qlcnic_host_sds_ring *sds_ring;
1523 int ring;
1524
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001525 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001526 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001527 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001528 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001529 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001530 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001531 }
1532
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001533 qlcnic_fw_destroy_ctx(adapter);
1534
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001535 qlcnic_detach(adapter);
1536
Sony Chacko79788452012-12-04 03:33:53 +00001537 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001538 adapter->max_sds_rings = max_sds_rings;
1539
1540 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001541 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001542
1543 if (netif_running(netdev))
1544 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001545out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001546 netif_device_attach(netdev);
1547}
1548
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001549static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1550{
1551 int err = 0;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001552 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1553 GFP_KERNEL);
1554 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001555 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001556 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001557 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001558 /* Initialize interrupt coalesce parameters */
1559 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1560 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1561 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Sony Chacko4be41e92013-01-01 03:20:20 +00001562 /* clear stats */
1563 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001564err_out:
1565 return err;
1566}
1567
1568static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1569{
1570 kfree(adapter->recv_ctx);
1571 adapter->recv_ctx = NULL;
1572
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001573 if (adapter->ahw->fw_dump.tmpl_hdr) {
1574 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1575 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1576 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001577
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001578 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001579 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001580}
1581
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001582int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1583{
1584 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1585 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001586 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001587 int ring;
1588 int ret;
1589
1590 netif_device_detach(netdev);
1591
1592 if (netif_running(netdev))
1593 __qlcnic_down(adapter, netdev);
1594
1595 qlcnic_detach(adapter);
1596
1597 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001598 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001599 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001600
1601 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001602 if (ret) {
1603 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001604 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001605 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001606
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001607 ret = qlcnic_fw_create_ctx(adapter);
1608 if (ret) {
1609 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001610 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001611 return ret;
1612 }
1613
1614 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001615 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001616 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001617 }
1618
Sony Chacko79788452012-12-04 03:33:53 +00001619 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001620 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001621 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001622 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001623 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001624 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001625
Sony Chacko79788452012-12-04 03:33:53 +00001626 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001627 adapter->ahw->loopback_state = 0;
1628 qlcnic_linkevent_request(adapter, 1);
1629 }
1630
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001631 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001632
1633 return 0;
1634}
1635
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001636/* Reset context in hardware only */
1637static int
1638qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1639{
1640 struct net_device *netdev = adapter->netdev;
1641
1642 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1643 return -EBUSY;
1644
1645 netif_device_detach(netdev);
1646
1647 qlcnic_down(adapter, netdev);
1648
1649 qlcnic_up(adapter, netdev);
1650
1651 netif_device_attach(netdev);
1652
1653 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001654 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001655 return 0;
1656}
1657
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001658int
1659qlcnic_reset_context(struct qlcnic_adapter *adapter)
1660{
1661 int err = 0;
1662 struct net_device *netdev = adapter->netdev;
1663
1664 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1665 return -EBUSY;
1666
1667 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1668
1669 netif_device_detach(netdev);
1670
1671 if (netif_running(netdev))
1672 __qlcnic_down(adapter, netdev);
1673
1674 qlcnic_detach(adapter);
1675
1676 if (netif_running(netdev)) {
1677 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001678 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001679 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001680 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1681 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001682 }
1683
1684 netif_device_attach(netdev);
1685 }
1686
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001687 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1688 return err;
1689}
1690
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001691int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001692qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1693 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001694{
1695 int err;
1696 struct pci_dev *pdev = adapter->pdev;
1697
Sony Chacko13159182013-01-01 03:20:21 +00001698 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001699 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001700 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001701
1702 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001703 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001704
1705 qlcnic_change_mtu(netdev, netdev->mtu);
1706
1707 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1708
Sony Chacko7e38d042013-01-01 03:20:28 +00001709 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00001710 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
1711 NETIF_F_HW_VLAN_RX);
1712 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1713 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001714
Sony Chacko13159182013-01-01 03:20:21 +00001715 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1716 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1717 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1718 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001719
Sony Chacko13159182013-01-01 03:20:21 +00001720 if (pci_using_dac) {
1721 netdev->features |= NETIF_F_HIGHDMA;
1722 netdev->vlan_features |= NETIF_F_HIGHDMA;
1723 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001724
Sony Chacko13159182013-01-01 03:20:21 +00001725 if (qlcnic_vlan_tx_check(adapter))
1726 netdev->features |= (NETIF_F_HW_VLAN_TX);
1727
Sony Chacko79788452012-12-04 03:33:53 +00001728 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001729 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001730
Sony Chacko7e38d042013-01-01 03:20:28 +00001731 netdev->hw_features = netdev->features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001732 netdev->irq = adapter->msix_entries[0].vector;
1733
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001734 err = register_netdev(netdev);
1735 if (err) {
1736 dev_err(&pdev->dev, "failed to register net device\n");
1737 return err;
1738 }
1739
1740 return 0;
1741}
1742
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001743static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001744{
1745 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1746 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1747 *pci_using_dac = 1;
1748 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1749 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1750 *pci_using_dac = 0;
1751 else {
1752 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1753 return -EIO;
1754 }
1755
1756 return 0;
1757}
1758
Sony Chacko4be41e92013-01-01 03:20:20 +00001759void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1760{
1761 int ring;
1762 struct qlcnic_host_tx_ring *tx_ring;
1763
1764 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1765 tx_ring = &adapter->tx_ring[ring];
1766 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1767 vfree(tx_ring->cmd_buf_arr);
1768 tx_ring->cmd_buf_arr = NULL;
1769 }
1770 }
1771 if (adapter->tx_ring != NULL)
1772 kfree(adapter->tx_ring);
1773}
1774
1775int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1776 struct net_device *netdev)
1777{
Joe Perchesb2adaca2013-02-03 17:43:58 +00001778 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00001779 struct qlcnic_host_tx_ring *tx_ring;
1780 struct qlcnic_cmd_buffer *cmd_buf_arr;
1781
Joe Perchesb2adaca2013-02-03 17:43:58 +00001782 tx_ring = kcalloc(adapter->max_drv_tx_rings,
1783 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
1784 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00001785 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00001786
Sony Chacko4be41e92013-01-01 03:20:20 +00001787 adapter->tx_ring = tx_ring;
1788
1789 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1790 tx_ring = &adapter->tx_ring[ring];
1791 tx_ring->num_desc = adapter->num_txd;
1792 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1793 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1794 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001795 qlcnic_free_tx_rings(adapter);
1796 return -ENOMEM;
1797 }
1798 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1799 tx_ring->cmd_buf_arr = cmd_buf_arr;
1800 }
1801
1802 if (qlcnic_83xx_check(adapter)) {
1803 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1804 tx_ring = &adapter->tx_ring[ring];
1805 tx_ring->adapter = adapter;
1806 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1807 index = adapter->max_sds_rings + ring;
1808 vector = adapter->msix_entries[index].vector;
1809 tx_ring->irq = vector;
1810 }
1811 }
1812 }
1813 return 0;
1814}
1815
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001816static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001817qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1818{
1819 struct net_device *netdev = NULL;
1820 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001821 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001822 int err, pci_using_dac = -1;
Sritej Velagac84e3402013-01-25 10:20:34 +00001823 u32 capab2;
Dan Carpenter7bc48642013-01-30 22:14:10 +00001824 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001825
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001826 if (pdev->is_virtfn)
1827 return -ENODEV;
1828
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001829 err = pci_enable_device(pdev);
1830 if (err)
1831 return err;
1832
1833 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1834 err = -ENODEV;
1835 goto err_out_disable_pdev;
1836 }
1837
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001838 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1839 if (err)
1840 goto err_out_disable_pdev;
1841
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001842 err = pci_request_regions(pdev, qlcnic_driver_name);
1843 if (err)
1844 goto err_out_disable_pdev;
1845
1846 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001847 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001848
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001849 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
1850 if (!ahw)
1851 goto err_out_free_res;
1852
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001853 switch (ent->device) {
1854 case PCI_DEVICE_ID_QLOGIC_QLE824X:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001855 ahw->hw_ops = &qlcnic_hw_ops;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001856 ahw->reg_tbl = (u32 *) qlcnic_reg_tbl;
1857 break;
1858 case PCI_DEVICE_ID_QLOGIC_QLE834X:
Sony Chacko13159182013-01-01 03:20:21 +00001859 qlcnic_83xx_register_map(ahw);
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001860 break;
1861 case PCI_DEVICE_ID_QLOGIC_VF_QLE834X:
1862 qlcnic_sriov_vf_register_map(ahw);
1863 break;
1864 default:
Sony Chacko13159182013-01-01 03:20:21 +00001865 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001866 }
1867
1868 err = qlcnic_setup_pci_map(pdev, ahw);
1869 if (err)
1870 goto err_out_free_hw_res;
1871
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001872 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1873 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001874 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001875 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001876 }
1877
1878 SET_NETDEV_DEV(netdev, &pdev->dev);
1879
1880 adapter = netdev_priv(netdev);
1881 adapter->netdev = netdev;
1882 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00001883 adapter->ahw = ahw;
1884
1885 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
1886 if (adapter->qlcnic_wq == NULL) {
1887 dev_err(&pdev->dev, "Failed to create workqueue\n");
1888 goto err_out_free_netdev;
1889 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001890
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001891 err = qlcnic_alloc_adapter_resources(adapter);
1892 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001893 goto err_out_free_netdev;
1894
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001895 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001896 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001897 if (qlcnic_mac_learn == FDB_MAC_LEARN)
1898 adapter->fdb_mac_learn = true;
1899 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
1900 adapter->drv_mac_learn = true;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001901 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001902
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001903 rwlock_init(&adapter->ahw->crb_lock);
1904 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001905
1906 spin_lock_init(&adapter->tx_clean_lock);
1907 INIT_LIST_HEAD(&adapter->mac_list);
1908
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001909 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00001910 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001911 adapter->portnum = adapter->ahw->pci_func;
1912 err = qlcnic_start_firmware(adapter);
1913 if (err) {
1914 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1915 goto err_out_free_hw;
1916 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001917
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001918 err = qlcnic_setup_idc_param(adapter);
1919 if (err)
1920 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001921
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001922 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00001923 } else if (qlcnic_83xx_check(adapter)) {
1924 qlcnic_83xx_check_vf(adapter, ent);
1925 adapter->portnum = adapter->ahw->pci_func;
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001926 err = qlcnic_83xx_init(adapter, pci_using_dac);
Sony Chacko629263a2013-01-01 04:11:55 +00001927 if (err) {
1928 dev_err(&pdev->dev, "%s: failed\n", __func__);
1929 goto err_out_free_hw;
1930 }
Rajesh Borundiaf8468332013-03-29 05:46:34 +00001931 if (qlcnic_sriov_vf_check(adapter))
1932 return 0;
Sony Chacko13159182013-01-01 03:20:21 +00001933 } else {
1934 dev_err(&pdev->dev,
1935 "%s: failed. Please Reboot\n", __func__);
1936 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001937 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001938
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001939 if (qlcnic_read_mac_addr(adapter))
1940 dev_warn(&pdev->dev, "failed to read mac addr\n");
1941
1942 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00001943 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00001944
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001945 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00001946 module_name(THIS_MODULE),
1947 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001948 }
Himanshu Madhani460374f2013-03-22 05:57:54 +00001949
1950 if (qlcnic_83xx_check(adapter) && !qlcnic_use_msi_x &&
1951 !!qlcnic_use_msi)
1952 dev_warn(&pdev->dev,
1953 "83xx adapter do not support MSI interrupts\n");
1954
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001955 err = qlcnic_setup_intr(adapter, 0);
Manish chopra9a97e702013-01-25 10:20:37 +00001956 if (err) {
1957 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001958 goto err_out_disable_msi;
Manish chopra9a97e702013-01-25 10:20:37 +00001959 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001960
Sony Chacko13159182013-01-01 03:20:21 +00001961 if (qlcnic_83xx_check(adapter)) {
1962 err = qlcnic_83xx_setup_mbx_intr(adapter);
1963 if (err)
1964 goto err_out_disable_msi;
1965 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001966
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001967 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001968 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001969 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001970
Sritej Velagac84e3402013-01-25 10:20:34 +00001971 if (qlcnic_82xx_check(adapter)) {
1972 if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1973 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1974 if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB)
1975 qlcnic_fw_cmd_set_drv_version(adapter);
1976 }
1977 }
1978
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001979 pci_set_drvdata(pdev, adapter);
1980
Sony Chacko97ee45e2012-12-04 03:33:52 +00001981 if (qlcnic_82xx_check(adapter))
1982 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1983 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001984
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001985 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001986 case QLCNIC_GBE:
1987 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1988 adapter->netdev->name);
1989 break;
1990 case QLCNIC_XGBE:
1991 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1992 adapter->netdev->name);
1993 break;
1994 }
1995
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001996 if (qlcnic_get_act_pci_func(adapter))
1997 goto err_out_disable_mbx_intr;
1998
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001999 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002000 qlcnic_alloc_lb_filters_mem(adapter);
2001
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002002 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002003
2004 return 0;
2005
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002006err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00002007 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00002008 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002009
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002010err_out_disable_msi:
2011 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002012 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002013 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002014
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002015err_out_free_hw:
2016 qlcnic_free_adapter_resources(adapter);
2017
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002018err_out_free_netdev:
2019 free_netdev(netdev);
2020
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002021err_out_iounmap:
2022 qlcnic_cleanup_pci_map(adapter);
2023
2024err_out_free_hw_res:
2025 kfree(ahw);
2026
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002027err_out_free_res:
2028 pci_release_regions(pdev);
2029
2030err_out_disable_pdev:
2031 pci_set_drvdata(pdev, NULL);
2032 pci_disable_device(pdev);
2033 return err;
2034}
2035
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002036static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002037{
2038 struct qlcnic_adapter *adapter;
2039 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002040 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002041
2042 adapter = pci_get_drvdata(pdev);
2043 if (adapter == NULL)
2044 return;
2045
2046 netdev = adapter->netdev;
Rajesh Borundia02feda12013-03-29 05:46:33 +00002047 qlcnic_sriov_pf_disable(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002048
Sony Chacko13159182013-01-01 03:20:21 +00002049 qlcnic_cancel_idc_work(adapter);
2050 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002051
2052 unregister_netdev(netdev);
Rajesh Borundia02feda12013-03-29 05:46:33 +00002053 qlcnic_sriov_cleanup(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002054
Sony Chacko13159182013-01-01 03:20:21 +00002055 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002056 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002057 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2058 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00002059 }
2060
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002061 qlcnic_detach(adapter);
2062
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002063 if (adapter->npars != NULL)
2064 kfree(adapter->npars);
2065 if (adapter->eswitch != NULL)
2066 kfree(adapter->eswitch);
2067
Sony Chacko97ee45e2012-12-04 03:33:52 +00002068 if (qlcnic_82xx_check(adapter))
2069 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002070
2071 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2072
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002073 qlcnic_free_lb_filters_mem(adapter);
2074
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002075 qlcnic_teardown_intr(adapter);
2076
Sony Chacko13159182013-01-01 03:20:21 +00002077 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002078
2079 qlcnic_cleanup_pci_map(adapter);
2080
2081 qlcnic_release_firmware(adapter);
2082
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002083 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002084 pci_release_regions(pdev);
2085 pci_disable_device(pdev);
2086 pci_set_drvdata(pdev, NULL);
2087
Sony Chacko13159182013-01-01 03:20:21 +00002088 if (adapter->qlcnic_wq) {
2089 destroy_workqueue(adapter->qlcnic_wq);
2090 adapter->qlcnic_wq = NULL;
2091 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002092 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002093 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002094 free_netdev(netdev);
2095}
2096static int __qlcnic_shutdown(struct pci_dev *pdev)
2097{
2098 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2099 struct net_device *netdev = adapter->netdev;
2100 int retval;
2101
2102 netif_device_detach(netdev);
2103
Sony Chacko13159182013-01-01 03:20:21 +00002104 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002105
2106 if (netif_running(netdev))
2107 qlcnic_down(adapter, netdev);
2108
Sony Chacko97ee45e2012-12-04 03:33:52 +00002109 if (qlcnic_82xx_check(adapter))
2110 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002111
2112 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2113
2114 retval = pci_save_state(pdev);
2115 if (retval)
2116 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002117 if (qlcnic_82xx_check(adapter)) {
2118 if (qlcnic_wol_supported(adapter)) {
2119 pci_enable_wake(pdev, PCI_D3cold, 1);
2120 pci_enable_wake(pdev, PCI_D3hot, 1);
2121 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002122 }
2123
2124 return 0;
2125}
2126
2127static void qlcnic_shutdown(struct pci_dev *pdev)
2128{
2129 if (__qlcnic_shutdown(pdev))
2130 return;
2131
2132 pci_disable_device(pdev);
2133}
2134
2135#ifdef CONFIG_PM
2136static int
2137qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2138{
2139 int retval;
2140
2141 retval = __qlcnic_shutdown(pdev);
2142 if (retval)
2143 return retval;
2144
2145 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2146 return 0;
2147}
2148
2149static int
2150qlcnic_resume(struct pci_dev *pdev)
2151{
2152 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2153 struct net_device *netdev = adapter->netdev;
2154 int err;
2155
2156 err = pci_enable_device(pdev);
2157 if (err)
2158 return err;
2159
2160 pci_set_power_state(pdev, PCI_D0);
2161 pci_set_master(pdev);
2162 pci_restore_state(pdev);
2163
Sony Chacko13159182013-01-01 03:20:21 +00002164 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002165 if (err) {
2166 dev_err(&pdev->dev, "failed to start firmware\n");
2167 return err;
2168 }
2169
2170 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002171 err = qlcnic_up(adapter, netdev);
2172 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002173 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002174
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002175 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002176 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002177done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002178 netif_device_attach(netdev);
2179 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2180 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002181}
2182#endif
2183
2184static int qlcnic_open(struct net_device *netdev)
2185{
2186 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2187 int err;
2188
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002189 netif_carrier_off(netdev);
2190
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002191 err = qlcnic_attach(adapter);
2192 if (err)
2193 return err;
2194
2195 err = __qlcnic_up(adapter, netdev);
2196 if (err)
2197 goto err_out;
2198
2199 netif_start_queue(netdev);
2200
2201 return 0;
2202
2203err_out:
2204 qlcnic_detach(adapter);
2205 return err;
2206}
2207
2208/*
2209 * qlcnic_close - Disables a network interface entry point
2210 */
2211static int qlcnic_close(struct net_device *netdev)
2212{
2213 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2214
2215 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002216
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002217 return 0;
2218}
2219
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002220void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002221{
2222 void *head;
2223 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002224 struct net_device *netdev = adapter->netdev;
2225 u32 filter_size = 0;
2226 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002227
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002228 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002229 return;
2230
Sony Chacko13159182013-01-01 03:20:21 +00002231 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002232 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002233 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002234
Sony Chacko13159182013-01-01 03:20:21 +00002235 if (qlcnic_82xx_check(adapter)) {
2236 filter_size = QLCNIC_LB_MAX_FILTERS;
2237 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2238 } else {
2239 filter_size = QLC_83XX_LB_MAX_FILTERS;
2240 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2241 }
2242
2243 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002244 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002245
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002246 if (!head)
2247 return;
2248
Sony Chacko13159182013-01-01 03:20:21 +00002249 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002250 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002251
Sony Chacko13159182013-01-01 03:20:21 +00002252 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2253 act_pci_func, adapter->fhash.fmax);
2254
2255 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002256 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002257
2258 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2259
2260 head = kcalloc(adapter->rx_fhash.fbucket_size,
2261 sizeof(struct hlist_head), GFP_ATOMIC);
2262
2263 if (!head)
2264 return;
2265
2266 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2267 adapter->rx_fhash.fhead = head;
2268
2269 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2270 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002271}
2272
2273static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2274{
2275 if (adapter->fhash.fmax && adapter->fhash.fhead)
2276 kfree(adapter->fhash.fhead);
2277
2278 adapter->fhash.fhead = NULL;
2279 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002280
2281 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2282 kfree(adapter->rx_fhash.fhead);
2283
2284 adapter->rx_fhash.fmax = 0;
2285 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002286}
2287
Sony Chacko629263a2013-01-01 04:11:55 +00002288int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002289{
2290 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002291 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002292 int rv = 0;
2293
Sony Chacko13159182013-01-01 03:20:21 +00002294 if (qlcnic_83xx_check(adapter))
2295 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2296
Sony Chacko97ee45e2012-12-04 03:33:52 +00002297 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002298 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002299
2300 temp_state = qlcnic_get_temp_state(temp);
2301 temp_val = qlcnic_get_temp_val(temp);
2302
2303 if (temp_state == QLCNIC_TEMP_PANIC) {
2304 dev_err(&netdev->dev,
2305 "Device temperature %d degrees C exceeds"
2306 " maximum allowed. Hardware has been shut down.\n",
2307 temp_val);
2308 rv = 1;
2309 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002310 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002311 dev_err(&netdev->dev,
2312 "Device temperature %d degrees C "
2313 "exceeds operating range."
2314 " Immediate action needed.\n",
2315 temp_val);
2316 }
2317 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002318 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002319 dev_info(&netdev->dev,
2320 "Device temperature is now %d degrees C"
2321 " in normal range.\n", temp_val);
2322 }
2323 }
Sony Chacko79788452012-12-04 03:33:53 +00002324 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002325 return rv;
2326}
2327
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002328static void qlcnic_tx_timeout(struct net_device *netdev)
2329{
2330 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2331
2332 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2333 return;
2334
2335 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002336
2337 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002338 adapter->need_fw_reset = 1;
2339 else
Sony Chacko79788452012-12-04 03:33:53 +00002340 adapter->ahw->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002341}
2342
2343static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2344{
2345 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2346 struct net_device_stats *stats = &netdev->stats;
2347
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002348 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2349 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002350 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002351 stats->tx_bytes = adapter->stats.txbytes;
2352 stats->rx_dropped = adapter->stats.rxdropped;
2353 stats->tx_dropped = adapter->stats.txdropped;
2354
2355 return stats;
2356}
2357
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002358irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002359{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002360 u32 status;
2361
2362 status = readl(adapter->isr_int_vec);
2363
Sony Chacko79788452012-12-04 03:33:53 +00002364 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002365 return IRQ_NONE;
2366
2367 /* check interrupt state machine, to be sure */
2368 status = readl(adapter->crb_int_state_reg);
2369 if (!ISR_LEGACY_INT_TRIGGERED(status))
2370 return IRQ_NONE;
2371
2372 writel(0xffffffff, adapter->tgt_status_reg);
2373 /* read twice to ensure write is flushed */
2374 readl(adapter->isr_int_vec);
2375 readl(adapter->isr_int_vec);
2376
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002377 return IRQ_HANDLED;
2378}
2379
2380static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2381{
2382 struct qlcnic_host_sds_ring *sds_ring = data;
2383 struct qlcnic_adapter *adapter = sds_ring->adapter;
2384
2385 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2386 goto done;
2387 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2388 writel(0xffffffff, adapter->tgt_status_reg);
2389 goto done;
2390 }
2391
2392 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2393 return IRQ_NONE;
2394
2395done:
Sony Chacko79788452012-12-04 03:33:53 +00002396 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002397 qlcnic_enable_int(sds_ring);
2398 return IRQ_HANDLED;
2399}
2400
2401static irqreturn_t qlcnic_intr(int irq, void *data)
2402{
2403 struct qlcnic_host_sds_ring *sds_ring = data;
2404 struct qlcnic_adapter *adapter = sds_ring->adapter;
2405
2406 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2407 return IRQ_NONE;
2408
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002409 napi_schedule(&sds_ring->napi);
2410
2411 return IRQ_HANDLED;
2412}
2413
2414static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2415{
2416 struct qlcnic_host_sds_ring *sds_ring = data;
2417 struct qlcnic_adapter *adapter = sds_ring->adapter;
2418
2419 /* clear interrupt */
2420 writel(0xffffffff, adapter->tgt_status_reg);
2421
2422 napi_schedule(&sds_ring->napi);
2423 return IRQ_HANDLED;
2424}
2425
2426static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2427{
2428 struct qlcnic_host_sds_ring *sds_ring = data;
2429
2430 napi_schedule(&sds_ring->napi);
2431 return IRQ_HANDLED;
2432}
2433
Sony Chacko13159182013-01-01 03:20:21 +00002434static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2435{
2436 struct qlcnic_host_tx_ring *tx_ring = data;
2437
2438 napi_schedule(&tx_ring->napi);
2439 return IRQ_HANDLED;
2440}
2441
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002442#ifdef CONFIG_NET_POLL_CONTROLLER
2443static void qlcnic_poll_controller(struct net_device *netdev)
2444{
Yinglin Luanbf827912010-08-22 21:57:56 +00002445 int ring;
2446 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002447 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002448 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002449
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002450 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002451 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2452 sds_ring = &recv_ctx->sds_rings[ring];
2453 qlcnic_intr(adapter->irq, sds_ring);
2454 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002455 enable_irq(adapter->irq);
2456}
2457#endif
2458
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002459static void
2460qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2461{
2462 u32 val;
2463
2464 val = adapter->portnum & 0xf;
2465 val |= encoding << 7;
2466 val |= (jiffies - adapter->dev_rst_time) << 8;
2467
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002468 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002469 adapter->dev_rst_time = jiffies;
2470}
2471
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002472static int
2473qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002474{
2475 u32 val;
2476
2477 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2478 state != QLCNIC_DEV_NEED_QUISCENT);
2479
2480 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002481 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002482
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002483 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002484
2485 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002486 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002487 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002488 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002489
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002490 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002491
2492 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002493
2494 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002495}
2496
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002497static int
2498qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2499{
2500 u32 val;
2501
2502 if (qlcnic_api_lock(adapter))
2503 return -EBUSY;
2504
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002505 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002506 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002507 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002508
2509 qlcnic_api_unlock(adapter);
2510
2511 return 0;
2512}
2513
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002514static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002515qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002516{
2517 u32 val;
2518
2519 if (qlcnic_api_lock(adapter))
2520 goto err;
2521
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002522 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002523 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002524 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002525
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002526 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002527 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2528 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002529 dev_info(&adapter->pdev->dev,
2530 "Device state set to Failed. Please Reboot\n");
2531 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002532 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2533 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002534
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002535 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002536 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002537 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002538
2539 qlcnic_api_unlock(adapter);
2540err:
2541 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002542 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002543 clear_bit(__QLCNIC_START_FW, &adapter->state);
2544 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2545}
2546
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002547/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002548static int
2549qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2550{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002551 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002552 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002553
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002554 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2555 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002556
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002557 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002558 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002559 act = act & active_mask;
2560 }
2561
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002562 if (((state & 0x11111111) == (act & 0x11111111)) ||
2563 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2564 return 0;
2565 else
2566 return 1;
2567}
2568
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002569static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2570{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002571 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002572
2573 if (val != QLCNIC_DRV_IDC_VER) {
2574 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2575 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2576 }
2577
2578 return 0;
2579}
2580
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002581static int
2582qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2583{
2584 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002585 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002586 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002587 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002588
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002589 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2590 return 1;
2591
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002592 if (qlcnic_api_lock(adapter))
2593 return -1;
2594
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002595 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002596 if (!(val & (1 << (portnum * 4)))) {
2597 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002598 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002599 }
2600
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002601 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002602 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002603
2604 switch (prev_state) {
2605 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002606 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2607 QLCNIC_DEV_INITIALIZING);
2608 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2609 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002610 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002611 qlcnic_api_unlock(adapter);
2612 return 1;
2613
2614 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002615 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002616 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002617 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002618
2619 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002620 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002621 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002622 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002623 break;
2624
2625 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002626 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002627 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002628 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002629 break;
2630
2631 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002632 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002633 qlcnic_api_unlock(adapter);
2634 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002635
2636 case QLCNIC_DEV_INITIALIZING:
2637 case QLCNIC_DEV_QUISCENT:
2638 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002639 }
2640
2641 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002642
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002643 do {
2644 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002645 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002646
2647 if (prev_state == QLCNIC_DEV_QUISCENT)
2648 continue;
2649 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002650
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002651 if (!dev_init_timeo) {
2652 dev_err(&adapter->pdev->dev,
2653 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002654 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002655 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002656
2657 if (qlcnic_api_lock(adapter))
2658 return -1;
2659
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002660 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002661 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002662 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002663
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002664 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002665 qlcnic_api_unlock(adapter);
2666
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002667 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002668}
2669
2670static void
2671qlcnic_fwinit_work(struct work_struct *work)
2672{
2673 struct qlcnic_adapter *adapter = container_of(work,
2674 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002675 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002676 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002677
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002678 if (qlcnic_api_lock(adapter))
2679 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002680
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002681 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002682 if (dev_state == QLCNIC_DEV_QUISCENT ||
2683 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002684 qlcnic_api_unlock(adapter);
2685 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2686 FW_POLL_DELAY * 2);
2687 return;
2688 }
2689
Sony Chacko79788452012-12-04 03:33:53 +00002690 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002691 qlcnic_api_unlock(adapter);
2692 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002693 }
2694
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002695 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2696 dev_state == QLCNIC_DEV_READY) {
2697 dev_info(&adapter->pdev->dev, "Detected state change from "
2698 "DEV_NEED_RESET, skipping ack check\n");
2699 goto skip_ack_check;
2700 }
2701
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002702 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002703 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002704 adapter->reset_ack_timeo);
2705 goto skip_ack_check;
2706 }
2707
2708 if (!qlcnic_check_drv_state(adapter)) {
2709skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002710 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002711
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002712 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002713 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2714 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002715 set_bit(__QLCNIC_START_FW, &adapter->state);
2716 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002717 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002718 val = QLC_SHARED_REG_RD32(adapter,
2719 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002720 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002721 QLC_SHARED_REG_WR32(adapter,
2722 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002723 }
2724
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002725 qlcnic_api_unlock(adapter);
2726
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002727 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002728 if (adapter->ahw->fw_dump.enable &&
2729 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002730 QLCDB(adapter, DRV, "Take FW dump\n");
2731 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002732 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002733 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002734 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002735
2736 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002737 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002738 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002739 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002740 return;
2741 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002742 goto err_ret;
2743 }
2744
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002745 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002746
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002747wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002748 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002749 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002750
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002751 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002752 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002753 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002754 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002755 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002756 return;
2757 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002758 case QLCNIC_DEV_FAILED:
2759 break;
2760 default:
2761 qlcnic_schedule_work(adapter,
2762 qlcnic_fwinit_work, FW_POLL_DELAY);
2763 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002764 }
2765
2766err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002767 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2768 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002769 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002770 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002771}
2772
2773static void
2774qlcnic_detach_work(struct work_struct *work)
2775{
2776 struct qlcnic_adapter *adapter = container_of(work,
2777 struct qlcnic_adapter, fw_work.work);
2778 struct net_device *netdev = adapter->netdev;
2779 u32 status;
2780
2781 netif_device_detach(netdev);
2782
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002783 /* Dont grab rtnl lock during Quiscent mode */
2784 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2785 if (netif_running(netdev))
2786 __qlcnic_down(adapter, netdev);
2787 } else
2788 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002789
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002790 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002791
Sony Chacko44f65b22011-08-29 12:50:26 +00002792 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2793 dev_err(&adapter->pdev->dev,
2794 "Detaching the device: peg halt status1=0x%x\n",
2795 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002796
Sony Chacko44f65b22011-08-29 12:50:26 +00002797 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2798 dev_err(&adapter->pdev->dev,
2799 "On board active cooling fan failed. "
2800 "Device has been halted.\n");
2801 dev_err(&adapter->pdev->dev,
2802 "Replace the adapter.\n");
2803 }
2804
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002805 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002806 }
2807
Sony Chacko79788452012-12-04 03:33:53 +00002808 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002809 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002810 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002811 goto err_ret;
2812 }
2813
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002814 /* Dont ack if this instance is the reset owner */
2815 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002816 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2817 dev_err(&adapter->pdev->dev,
2818 "Failed to set driver state,"
2819 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002820 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002821 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002822 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002823
2824 adapter->fw_wait_cnt = 0;
2825
2826 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2827
2828 return;
2829
2830err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002831 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002832 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002833}
2834
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002835/*Transit NPAR state to NON Operational */
2836static void
2837qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2838{
2839 u32 state;
2840
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002841 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002842 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2843 return;
2844
2845 if (qlcnic_api_lock(adapter))
2846 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002847 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2848 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002849 qlcnic_api_unlock(adapter);
2850}
2851
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002852void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002853{
Sritej Velaga646779f2012-02-03 13:45:41 +00002854 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002855
Sritej Velaga646779f2012-02-03 13:45:41 +00002856 qlcnic_xg_set_xg0_mask(xg_val);
2857 qlcnic_xg_set_xg1_mask(xg_val);
2858 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2859 qlcnic_gb_set_gb0_mask(gb_val);
2860 qlcnic_gb_set_gb1_mask(gb_val);
2861 qlcnic_gb_set_gb2_mask(gb_val);
2862 qlcnic_gb_set_gb3_mask(gb_val);
2863 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2864 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2865 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002866 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002867
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002868 if (qlcnic_api_lock(adapter))
2869 return;
2870
Sony Chacko13159182013-01-01 03:20:21 +00002871 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002872
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002873 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00002874 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2875 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002876 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002877 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002878 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002879 }
2880
Sony Chacko13159182013-01-01 03:20:21 +00002881 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2882 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002883 qlcnic_api_unlock(adapter);
2884}
2885
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002886/* Transit to NPAR READY state from NPAR NOT READY state */
2887static void
2888qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2889{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002890 if (qlcnic_api_lock(adapter))
2891 return;
2892
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002893 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2894 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002895 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002896
2897 qlcnic_api_unlock(adapter);
2898}
2899
Sony Chacko13159182013-01-01 03:20:21 +00002900void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2901 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002902{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002903 if (test_bit(__QLCNIC_AER, &adapter->state))
2904 return;
2905
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002906 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00002907 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
2908 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002909}
2910
2911static void
2912qlcnic_attach_work(struct work_struct *work)
2913{
2914 struct qlcnic_adapter *adapter = container_of(work,
2915 struct qlcnic_adapter, fw_work.work);
2916 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002917 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002918
Sony Chacko79788452012-12-04 03:33:53 +00002919 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002920 npar_state = QLC_SHARED_REG_RD32(adapter,
2921 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002922 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2923 qlcnic_clr_all_drv_state(adapter, 0);
2924 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2925 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2926 FW_POLL_DELAY);
2927 else
2928 goto attach;
2929 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2930 return;
2931 }
2932attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002933 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002934 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002935 goto done;
2936
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002937 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002938 }
2939
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002940done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002941 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002942 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002943 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002944 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002945
2946 if (!qlcnic_clr_drv_state(adapter))
2947 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2948 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002949}
2950
2951static int
2952qlcnic_check_health(struct qlcnic_adapter *adapter)
2953{
Sony Chacko4e708122010-08-31 17:17:44 +00002954 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002955 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002956
2957 if (qlcnic_check_temp(adapter))
2958 goto detach;
2959
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002960 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002961 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002962
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002963 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002964 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002965 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002966 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002967 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2968 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002969
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002970 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00002971 if (heartbeat != adapter->heartbeat) {
2972 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002973 adapter->fw_fail_cnt = 0;
2974 if (adapter->need_fw_reset)
2975 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002976
Sony Chacko099f7aa2012-12-04 03:33:58 +00002977 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002978 qlcnic_reset_hw_context(adapter);
2979 adapter->netdev->trans_start = jiffies;
2980 }
2981
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002982 return 0;
2983 }
2984
2985 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2986 return 0;
2987
Sritej Velaga032a13c2011-07-29 13:30:27 +00002988 adapter->flags |= QLCNIC_FW_HANG;
2989
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002990 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002991
Sony Chacko099f7aa2012-12-04 03:33:58 +00002992 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002993 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002994
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002995 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002996 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002997 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00002998 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2999 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3000 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3001 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003002 peg_status,
3003 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00003004 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3005 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3006 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3007 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3008 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00003009 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00003010 dev_err(&adapter->pdev->dev,
3011 "Firmware aborted with error code 0x00006700. "
3012 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003013detach:
3014 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3015 QLCNIC_DEV_NEED_RESET;
3016
Sony Chacko099f7aa2012-12-04 03:33:58 +00003017 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
3018 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003019
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003020 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003021 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3022 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003023
3024 return 1;
3025}
3026
3027static void
3028qlcnic_fw_poll_work(struct work_struct *work)
3029{
3030 struct qlcnic_adapter *adapter = container_of(work,
3031 struct qlcnic_adapter, fw_work.work);
3032
3033 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3034 goto reschedule;
3035
3036
3037 if (qlcnic_check_health(adapter))
3038 return;
3039
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003040 if (adapter->fhash.fnum)
3041 qlcnic_prune_lb_filters(adapter);
3042
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003043reschedule:
3044 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3045}
3046
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003047static int qlcnic_is_first_func(struct pci_dev *pdev)
3048{
3049 struct pci_dev *oth_pdev;
3050 int val = pdev->devfn;
3051
3052 while (val-- > 0) {
3053 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3054 (pdev->bus), pdev->bus->number,
3055 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003056 if (!oth_pdev)
3057 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003058
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003059 if (oth_pdev->current_state != PCI_D3cold) {
3060 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003061 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003062 }
3063 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003064 }
3065 return 1;
3066}
3067
3068static int qlcnic_attach_func(struct pci_dev *pdev)
3069{
3070 int err, first_func;
3071 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3072 struct net_device *netdev = adapter->netdev;
3073
3074 pdev->error_state = pci_channel_io_normal;
3075
3076 err = pci_enable_device(pdev);
3077 if (err)
3078 return err;
3079
3080 pci_set_power_state(pdev, PCI_D0);
3081 pci_set_master(pdev);
3082 pci_restore_state(pdev);
3083
3084 first_func = qlcnic_is_first_func(pdev);
3085
3086 if (qlcnic_api_lock(adapter))
3087 return -EINVAL;
3088
Sony Chacko79788452012-12-04 03:33:53 +00003089 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003090 adapter->need_fw_reset = 1;
3091 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003092 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3093 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003094 QLCDB(adapter, DRV, "Restarting fw\n");
3095 }
3096 qlcnic_api_unlock(adapter);
3097
Sony Chacko13159182013-01-01 03:20:21 +00003098 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003099 if (err)
3100 return err;
3101
3102 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003103 kfree(adapter->msix_entries);
3104 adapter->msix_entries = NULL;
3105 err = qlcnic_setup_intr(adapter, 0);
3106
Manish chopra9a97e702013-01-25 10:20:37 +00003107 if (err) {
3108 kfree(adapter->msix_entries);
3109 netdev_err(netdev, "failed to setup interrupt\n");
3110 return err;
3111 }
3112
Sony Chacko13159182013-01-01 03:20:21 +00003113 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003114 /* register for NIC IDC AEN Events */
3115 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003116 err = qlcnic_83xx_setup_mbx_intr(adapter);
3117 if (err) {
3118 dev_err(&adapter->pdev->dev,
3119 "failed to setup mbx interrupt\n");
3120 qlcnic_clr_all_drv_state(adapter, 1);
3121 clear_bit(__QLCNIC_AER, &adapter->state);
3122 goto done;
3123 }
3124 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003125
3126 if (netif_running(netdev)) {
3127 err = qlcnic_attach(adapter);
3128 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003129 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003130 clear_bit(__QLCNIC_AER, &adapter->state);
3131 netif_device_attach(netdev);
3132 return err;
3133 }
3134
3135 err = qlcnic_up(adapter, netdev);
3136 if (err)
3137 goto done;
3138
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003139 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003140 }
3141 done:
3142 netif_device_attach(netdev);
3143 return err;
3144}
3145
3146static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3147 pci_channel_state_t state)
3148{
3149 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3150 struct net_device *netdev = adapter->netdev;
3151
3152 if (state == pci_channel_io_perm_failure)
3153 return PCI_ERS_RESULT_DISCONNECT;
3154
3155 if (state == pci_channel_io_normal)
3156 return PCI_ERS_RESULT_RECOVERED;
3157
3158 set_bit(__QLCNIC_AER, &adapter->state);
3159 netif_device_detach(netdev);
3160
3161 cancel_delayed_work_sync(&adapter->fw_work);
3162
3163 if (netif_running(netdev))
3164 qlcnic_down(adapter, netdev);
3165
Sony Chacko13159182013-01-01 03:20:21 +00003166 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003167 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00003168 qlcnic_83xx_register_nic_idc_func(adapter, 0);
3169 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00003170 }
3171
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003172 qlcnic_detach(adapter);
3173 qlcnic_teardown_intr(adapter);
3174
3175 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3176
3177 pci_save_state(pdev);
3178 pci_disable_device(pdev);
3179
3180 return PCI_ERS_RESULT_NEED_RESET;
3181}
3182
3183static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3184{
3185 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3186 PCI_ERS_RESULT_RECOVERED;
3187}
3188
3189static void qlcnic_io_resume(struct pci_dev *pdev)
3190{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003191 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003192 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3193
3194 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003195 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3196 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3197 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003198 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3199 FW_POLL_DELAY);
3200}
3201
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003202static int
3203qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3204{
3205 int err;
3206
3207 err = qlcnic_can_start_firmware(adapter);
3208 if (err)
3209 return err;
3210
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003211 err = qlcnic_check_npar_opertional(adapter);
3212 if (err)
3213 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003214
Rajesh Borundia174240a2010-08-31 17:17:47 +00003215 err = qlcnic_initialize_nic(adapter);
3216 if (err)
3217 return err;
3218
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003219 qlcnic_check_options(adapter);
3220
Rajesh Borundia73733732010-08-31 17:17:50 +00003221 err = qlcnic_set_eswitch_port_config(adapter);
3222 if (err)
3223 return err;
3224
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003225 adapter->need_fw_reset = 0;
3226
3227 return err;
3228}
3229
Sony Chacko319ecf12013-01-01 03:20:22 +00003230int qlcnic_validate_max_rss(u8 max_hw, u8 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003231{
Sony Chacko319ecf12013-01-01 03:20:22 +00003232 u32 max_allowed;
3233
3234 if (max_hw > QLC_MAX_SDS_RINGS) {
3235 max_hw = QLC_MAX_SDS_RINGS;
3236 pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003237 }
3238
Sony Chacko319ecf12013-01-01 03:20:22 +00003239 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3240 num_online_cpus()));
3241 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
3242 pr_info("rss_ring valid range [2 - %x] in powers of 2\n",
3243 max_allowed);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003244 return -EINVAL;
3245 }
3246 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003247}
3248
Sony Chacko319ecf12013-01-01 03:20:22 +00003249int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003250{
Sony Chacko13159182013-01-01 03:20:21 +00003251 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003252 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003253
Sony Chacko319ecf12013-01-01 03:20:22 +00003254 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3255 return -EBUSY;
3256
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003257 netif_device_detach(netdev);
3258 if (netif_running(netdev))
3259 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003260
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003261 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003262
3263 if (qlcnic_83xx_check(adapter))
3264 qlcnic_83xx_free_mbx_intr(adapter);
3265
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003266 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003267 err = qlcnic_setup_intr(adapter, data);
Manish chopra9a97e702013-01-25 10:20:37 +00003268 if (err) {
3269 kfree(adapter->msix_entries);
3270 netdev_err(netdev, "failed to setup interrupt\n");
3271 return err;
3272 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003273
Sony Chacko13159182013-01-01 03:20:21 +00003274 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003275 /* register for NIC IDC AEN Events */
3276 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003277 err = qlcnic_83xx_setup_mbx_intr(adapter);
3278 if (err) {
3279 dev_err(&adapter->pdev->dev,
3280 "failed to setup mbx interrupt\n");
3281 goto done;
3282 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003283 }
3284
3285 if (netif_running(netdev)) {
3286 err = qlcnic_attach(adapter);
3287 if (err)
3288 goto done;
3289 err = __qlcnic_up(adapter, netdev);
3290 if (err)
3291 goto done;
3292 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3293 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003294 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003295 done:
3296 netif_device_attach(netdev);
3297 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3298 return err;
3299}
3300
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003301#ifdef CONFIG_INET
3302
3303#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3304
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003305static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003306qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3307 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003308{
3309 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003310
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003311 indev = in_dev_get(dev);
3312 if (!indev)
3313 return;
3314
3315 for_ifa(indev) {
3316 switch (event) {
3317 case NETDEV_UP:
3318 qlcnic_config_ipaddr(adapter,
3319 ifa->ifa_address, QLCNIC_IP_UP);
3320 break;
3321 case NETDEV_DOWN:
3322 qlcnic_config_ipaddr(adapter,
3323 ifa->ifa_address, QLCNIC_IP_DOWN);
3324 break;
3325 default:
3326 break;
3327 }
3328 } endfor_ifa(indev);
3329
3330 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003331}
3332
Sony Chacko319ecf12013-01-01 03:20:22 +00003333void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003334{
3335 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3336 struct net_device *dev;
3337 u16 vid;
3338
3339 qlcnic_config_indev_addr(adapter, netdev, event);
3340
Jiri Pirko43c00a72013-01-03 22:48:57 +00003341 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003342 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Jiri Pirko223bb152011-07-20 04:54:44 +00003343 dev = __vlan_find_dev_deep(netdev, vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003344 if (!dev)
3345 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003346 qlcnic_config_indev_addr(adapter, dev, event);
3347 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003348 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003349}
3350
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003351static int qlcnic_netdev_event(struct notifier_block *this,
3352 unsigned long event, void *ptr)
3353{
3354 struct qlcnic_adapter *adapter;
3355 struct net_device *dev = (struct net_device *)ptr;
3356
3357recheck:
3358 if (dev == NULL)
3359 goto done;
3360
3361 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3362 dev = vlan_dev_real_dev(dev);
3363 goto recheck;
3364 }
3365
3366 if (!is_qlcnic_netdev(dev))
3367 goto done;
3368
3369 adapter = netdev_priv(dev);
3370
3371 if (!adapter)
3372 goto done;
3373
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003374 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003375 goto done;
3376
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003377 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003378done:
3379 return NOTIFY_DONE;
3380}
3381
3382static int
3383qlcnic_inetaddr_event(struct notifier_block *this,
3384 unsigned long event, void *ptr)
3385{
3386 struct qlcnic_adapter *adapter;
3387 struct net_device *dev;
3388
3389 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3390
3391 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3392
3393recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003394 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003395 goto done;
3396
3397 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3398 dev = vlan_dev_real_dev(dev);
3399 goto recheck;
3400 }
3401
3402 if (!is_qlcnic_netdev(dev))
3403 goto done;
3404
3405 adapter = netdev_priv(dev);
3406
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003407 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003408 goto done;
3409
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003410 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003411 goto done;
3412
3413 switch (event) {
3414 case NETDEV_UP:
3415 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003416
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003417 break;
3418 case NETDEV_DOWN:
3419 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003420
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003421 break;
3422 default:
3423 break;
3424 }
3425
3426done:
3427 return NOTIFY_DONE;
3428}
3429
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003430static struct notifier_block qlcnic_netdev_cb = {
3431 .notifier_call = qlcnic_netdev_event,
3432};
3433
3434static struct notifier_block qlcnic_inetaddr_cb = {
3435 .notifier_call = qlcnic_inetaddr_event,
3436};
3437#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003438void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003439{ }
3440#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003441static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003442 .error_detected = qlcnic_io_error_detected,
3443 .slot_reset = qlcnic_io_slot_reset,
3444 .resume = qlcnic_io_resume,
3445};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003446
3447static struct pci_driver qlcnic_driver = {
3448 .name = qlcnic_driver_name,
3449 .id_table = qlcnic_pci_tbl,
3450 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003451 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003452#ifdef CONFIG_PM
3453 .suspend = qlcnic_suspend,
3454 .resume = qlcnic_resume,
3455#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003456 .shutdown = qlcnic_shutdown,
Rajesh Borundia02feda12013-03-29 05:46:33 +00003457 .err_handler = &qlcnic_err_handler,
3458#ifdef CONFIG_QLCNIC_SRIOV
3459 .sriov_configure = qlcnic_pci_sriov_configure,
3460#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003461
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003462};
3463
3464static int __init qlcnic_init_module(void)
3465{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003466 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003467
3468 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3469
3470#ifdef CONFIG_INET
3471 register_netdevice_notifier(&qlcnic_netdev_cb);
3472 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3473#endif
3474
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003475 ret = pci_register_driver(&qlcnic_driver);
3476 if (ret) {
3477#ifdef CONFIG_INET
3478 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3479 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3480#endif
3481 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003482
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003483 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003484}
3485
3486module_init(qlcnic_init_module);
3487
3488static void __exit qlcnic_exit_module(void)
3489{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003490 pci_unregister_driver(&qlcnic_driver);
3491
3492#ifdef CONFIG_INET
3493 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3494 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3495#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003496}
3497
3498module_exit(qlcnic_exit_module);