blob: 5d5fd06c4b428f3a134d1cb0c4eb80d0b58518eb [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"
Himanshu Madhania15ebd32013-01-01 03:20:18 +000012#include "qlcnic_hw.h"
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000013
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000014#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000015#include <linux/dma-mapping.h>
Sony Chacko13159182013-01-01 03:20:21 +000016#include <linux/if_vlan.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000017#include <net/ip.h>
18#include <linux/ipv6.h>
19#include <linux/inetdevice.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000020#include <linux/aer.h>
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +000021#include <linux/log2.h>
Stephen Rothwell47caf252013-01-02 17:23:53 +000022#include <linux/pci.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000023
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000024MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000025MODULE_LICENSE("GPL");
26MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
27MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
28
29char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000030static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
31 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000032
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000033static int qlcnic_mac_learn;
amit salechab11a25a2011-01-10 00:15:23 +000034module_param(qlcnic_mac_learn, int, 0444);
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +000035MODULE_PARM_DESC(qlcnic_mac_learn,
36 "Mac Filter (0=learning is disabled, 1=Driver learning is enabled, 2=FDB learning is enabled)");
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000037
Sony Chacko629263a2013-01-01 04:11:55 +000038int qlcnic_use_msi = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000039MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000040module_param_named(use_msi, qlcnic_use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000041
Sony Chacko629263a2013-01-01 04:11:55 +000042int qlcnic_use_msi_x = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000043MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000044module_param_named(use_msi_x, qlcnic_use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000045
Sony Chacko629263a2013-01-01 04:11:55 +000046int qlcnic_auto_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000047MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
Sony Chacko099f7aa2012-12-04 03:33:58 +000048module_param_named(auto_fw_reset, qlcnic_auto_fw_reset, int, 0644);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000049
Sony Chacko629263a2013-01-01 04:11:55 +000050int qlcnic_load_fw_file;
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000051MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
Sony Chacko099f7aa2012-12-04 03:33:58 +000052module_param_named(load_fw_file, qlcnic_load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000053
Sony Chacko629263a2013-01-01 04:11:55 +000054int qlcnic_config_npars;
amit salechab11a25a2011-01-10 00:15:23 +000055module_param(qlcnic_config_npars, int, 0444);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000056MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
57
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000058static int qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050059static void qlcnic_remove(struct pci_dev *pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000060static int qlcnic_open(struct net_device *netdev);
61static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000062static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000063static void qlcnic_attach_work(struct work_struct *work);
64static void qlcnic_fwinit_work(struct work_struct *work);
65static void qlcnic_fw_poll_work(struct work_struct *work);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000066#ifdef CONFIG_NET_POLL_CONTROLLER
67static void qlcnic_poll_controller(struct net_device *netdev);
68#endif
69
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000070static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000071static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000072static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
73
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000074static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000075static irqreturn_t qlcnic_intr(int irq, void *data);
76static irqreturn_t qlcnic_msi_intr(int irq, void *data);
77static irqreturn_t qlcnic_msix_intr(int irq, void *data);
Sony Chacko13159182013-01-01 03:20:21 +000078static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000079
80static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000081static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000082
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000083static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000084static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000085static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Rajesh Borundia0325d692010-08-19 05:08:26 +000086static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
87 struct qlcnic_esw_func_cfg *);
Jiri Pirko8e586132011-12-08 19:52:37 -050088static int qlcnic_vlan_rx_add(struct net_device *, u16);
89static int qlcnic_vlan_rx_del(struct net_device *, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000090
Sony Chackobff57d82012-12-04 03:33:56 +000091#define QLCNIC_IS_TSO_CAPABLE(adapter) \
92 ((adapter)->ahw->capabilities & QLCNIC_FW_CAPABILITY_TSO)
93
Sony Chacko13159182013-01-01 03:20:21 +000094static u32 qlcnic_vlan_tx_check(struct qlcnic_adapter *adapter)
95{
96 struct qlcnic_hardware_context *ahw = adapter->ahw;
97
98 if (adapter->pdev->device == PCI_DEVICE_ID_QLOGIC_QLE824X)
99 return ahw->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX;
100 else
101 return 1;
102}
103
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000104/* PCI Device ID Table */
105#define ENTRY(device) \
106 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
107 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
108
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000109static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000110 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
Sony Chacko13159182013-01-01 03:20:21 +0000111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE834X),
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000112 {0,}
113};
114
115MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
116
117
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000118inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000119{
120 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000121}
122
123static const u32 msi_tgt_status[8] = {
124 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
125 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
126 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
127 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
128};
129
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000130static const u32 qlcnic_reg_tbl[] = {
131 0x1B20A8, /* PEG_HALT_STAT1 */
132 0x1B20AC, /* PEG_HALT_STAT2 */
133 0x1B20B0, /* FW_HEARTBEAT */
134 0x1B2100, /* LOCK ID */
135 0x1B2128, /* FW_CAPABILITIES */
136 0x1B2138, /* drv active */
137 0x1B2140, /* dev state */
138 0x1B2144, /* drv state */
139 0x1B2148, /* drv scratch */
140 0x1B214C, /* dev partition info */
141 0x1B2174, /* drv idc ver */
142 0x1B2150, /* fw version major */
143 0x1B2154, /* fw version minor */
144 0x1B2158, /* fw version sub */
145 0x1B219C, /* npar state */
146 0x1B21FC, /* FW_IMG_VALID */
147 0x1B2250, /* CMD_PEG_STATE */
148 0x1B233C, /* RCV_PEG_STATE */
149 0x1B23B4, /* ASIC TEMP */
150 0x1B216C, /* FW api */
151 0x1B2170, /* drv op mode */
152 0x13C010, /* flash lock */
153 0x13C014, /* flash unlock */
154};
155
Sony Chacko22999792012-12-04 03:33:55 +0000156static const struct qlcnic_board_info qlcnic_boards[] = {
157 {0x1077, 0x8020, 0x1077, 0x203,
158 "8200 Series Single Port 10GbE Converged Network Adapter"
159 "(TCP/IP Networking)"},
160 {0x1077, 0x8020, 0x1077, 0x207,
161 "8200 Series Dual Port 10GbE Converged Network Adapter"
162 "(TCP/IP Networking)"},
163 {0x1077, 0x8020, 0x1077, 0x20b,
164 "3200 Series Dual Port 10Gb Intelligent Ethernet Adapter"},
165 {0x1077, 0x8020, 0x1077, 0x20c,
166 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"},
167 {0x1077, 0x8020, 0x1077, 0x20f,
168 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"},
169 {0x1077, 0x8020, 0x103c, 0x3733,
170 "NC523SFP 10Gb 2-port Server Adapter"},
171 {0x1077, 0x8020, 0x103c, 0x3346,
172 "CN1000Q Dual Port Converged Network Adapter"},
173 {0x1077, 0x8020, 0x1077, 0x210,
174 "QME8242-k 10GbE Dual Port Mezzanine Card"},
175 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"},
176};
177
178#define NUM_SUPPORTED_BOARDS ARRAY_SIZE(qlcnic_boards)
Sony Chacko319ecf12013-01-01 03:20:22 +0000179#define QLC_MAX_SDS_RINGS 8
Sony Chacko22999792012-12-04 03:33:55 +0000180
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000181static const
182struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
183
Sony Chackoc70001a2012-11-28 04:34:26 +0000184int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000185{
186 int size = sizeof(struct qlcnic_host_sds_ring) * count;
187
188 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
189
Eric Dumazet807540b2010-09-23 05:40:09 +0000190 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000191}
192
Sony Chackoc70001a2012-11-28 04:34:26 +0000193void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000194{
195 if (recv_ctx->sds_rings != NULL)
196 kfree(recv_ctx->sds_rings);
197
198 recv_ctx->sds_rings = NULL;
199}
200
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000201static int
202qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
203{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000204 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000205 struct net_device *netdev = adapter->netdev;
206 struct pci_dev *pdev = adapter->pdev;
207
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000208 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000209 return -EIO;
210
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000211 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000212 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
213
214 /* set station address */
215
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +0000216 if (!is_valid_ether_addr(netdev->dev_addr))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000217 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
218 netdev->dev_addr);
219
220 return 0;
221}
222
223static int qlcnic_set_mac(struct net_device *netdev, void *p)
224{
225 struct qlcnic_adapter *adapter = netdev_priv(netdev);
226 struct sockaddr *addr = p;
227
Rajesh Borundia73733732010-08-31 17:17:50 +0000228 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
229 return -EOPNOTSUPP;
230
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000231 if (!is_valid_ether_addr(addr->sa_data))
Sony Chacko13159182013-01-01 03:20:21 +0000232 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000233
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000234 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000235 netif_device_detach(netdev);
236 qlcnic_napi_disable(adapter);
237 }
238
239 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
240 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
241 qlcnic_set_multi(adapter->netdev);
242
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000243 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000244 netif_device_attach(netdev);
245 qlcnic_napi_enable(adapter);
246 }
247 return 0;
248}
249
Vlad Yasevich1690be62013-02-13 12:00:18 +0000250static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
251 struct net_device *netdev, const unsigned char *addr)
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000252{
253 struct qlcnic_adapter *adapter = netdev_priv(netdev);
254 int err = -EOPNOTSUPP;
255
256 if (!adapter->fdb_mac_learn) {
257 pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n",
258 __func__);
259 return err;
260 }
261
262 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
263 if (is_unicast_ether_addr(addr))
264 err = qlcnic_nic_del_mac(adapter, addr);
265 else if (is_multicast_ether_addr(addr))
266 err = dev_mc_del(netdev, addr);
267 else
268 err = -EINVAL;
269 }
270 return err;
271}
272
273static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
274 struct net_device *netdev,
275 const unsigned char *addr, u16 flags)
276{
277 struct qlcnic_adapter *adapter = netdev_priv(netdev);
278 int err = 0;
279
280 if (!adapter->fdb_mac_learn) {
281 pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n",
282 __func__);
283 return -EOPNOTSUPP;
284 }
285
286 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
287 pr_info("%s: FDB e-switch is not enabled\n", __func__);
288 return -EOPNOTSUPP;
289 }
290
291 if (ether_addr_equal(addr, adapter->mac_addr))
292 return err;
293
294 if (is_unicast_ether_addr(addr))
295 err = qlcnic_nic_add_mac(adapter, addr);
296 else if (is_multicast_ether_addr(addr))
297 err = dev_mc_add_excl(netdev, addr);
298 else
299 err = -EINVAL;
300
301 return err;
302}
303
304static int qlcnic_fdb_dump(struct sk_buff *skb, struct netlink_callback *ncb,
305 struct net_device *netdev, int idx)
306{
307 struct qlcnic_adapter *adapter = netdev_priv(netdev);
308
309 if (!adapter->fdb_mac_learn) {
310 pr_info("%s: Driver mac learn is enabled, FDB operation not allowed\n",
311 __func__);
312 return -EOPNOTSUPP;
313 }
314
315 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
316 idx = ndo_dflt_fdb_dump(skb, ncb, netdev, idx);
317
318 return idx;
319}
320
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000321static void qlcnic_82xx_cancel_idc_work(struct qlcnic_adapter *adapter)
322{
323 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
324 usleep_range(10000, 11000);
325
326 cancel_delayed_work_sync(&adapter->fw_work);
327}
328
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000329static const struct net_device_ops qlcnic_netdev_ops = {
330 .ndo_open = qlcnic_open,
331 .ndo_stop = qlcnic_close,
332 .ndo_start_xmit = qlcnic_xmit_frame,
333 .ndo_get_stats = qlcnic_get_stats,
334 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000335 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000336 .ndo_set_mac_address = qlcnic_set_mac,
337 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000338 .ndo_fix_features = qlcnic_fix_features,
339 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000340 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000341 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
342 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000343 .ndo_fdb_add = qlcnic_fdb_add,
344 .ndo_fdb_del = qlcnic_fdb_del,
345 .ndo_fdb_dump = qlcnic_fdb_dump,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000346#ifdef CONFIG_NET_POLL_CONTROLLER
347 .ndo_poll_controller = qlcnic_poll_controller,
348#endif
349};
350
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000351static const struct net_device_ops qlcnic_netdev_failed_ops = {
352 .ndo_open = qlcnic_open,
353};
354
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000355static struct qlcnic_nic_template qlcnic_ops = {
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000356 .config_bridged_mode = qlcnic_config_bridged_mode,
357 .config_led = qlcnic_82xx_config_led,
358 .start_firmware = qlcnic_82xx_start_firmware,
359 .request_reset = qlcnic_82xx_dev_request_reset,
360 .cancel_idc_work = qlcnic_82xx_cancel_idc_work,
361 .napi_add = qlcnic_82xx_napi_add,
Sony Chacko4be41e92013-01-01 03:20:20 +0000362 .napi_del = qlcnic_82xx_napi_del,
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000363 .config_ipaddr = qlcnic_82xx_config_ipaddr,
364 .clear_legacy_intr = qlcnic_82xx_clear_legacy_intr,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000365};
366
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000367struct qlcnic_nic_template qlcnic_vf_ops = {
368 .config_bridged_mode = qlcnicvf_config_bridged_mode,
369 .config_led = qlcnicvf_config_led,
370 .start_firmware = qlcnicvf_start_firmware
371};
372
373static struct qlcnic_hardware_ops qlcnic_hw_ops = {
374 .read_crb = qlcnic_82xx_read_crb,
375 .write_crb = qlcnic_82xx_write_crb,
376 .read_reg = qlcnic_82xx_hw_read_wx_2M,
377 .write_reg = qlcnic_82xx_hw_write_wx_2M,
378 .get_mac_address = qlcnic_82xx_get_mac_address,
379 .setup_intr = qlcnic_82xx_setup_intr,
380 .alloc_mbx_args = qlcnic_82xx_alloc_mbx_args,
381 .mbx_cmd = qlcnic_82xx_issue_cmd,
382 .get_func_no = qlcnic_82xx_get_func_no,
383 .api_lock = qlcnic_82xx_api_lock,
384 .api_unlock = qlcnic_82xx_api_unlock,
385 .add_sysfs = qlcnic_82xx_add_sysfs,
386 .remove_sysfs = qlcnic_82xx_remove_sysfs,
387 .process_lb_rcv_ring_diag = qlcnic_82xx_process_rcv_ring_diag,
388 .create_rx_ctx = qlcnic_82xx_fw_cmd_create_rx_ctx,
389 .create_tx_ctx = qlcnic_82xx_fw_cmd_create_tx_ctx,
390 .setup_link_event = qlcnic_82xx_linkevent_request,
391 .get_nic_info = qlcnic_82xx_get_nic_info,
392 .get_pci_info = qlcnic_82xx_get_pci_info,
393 .set_nic_info = qlcnic_82xx_set_nic_info,
394 .change_macvlan = qlcnic_82xx_sre_macaddr_change,
395 .napi_enable = qlcnic_82xx_napi_enable,
396 .napi_disable = qlcnic_82xx_napi_disable,
397 .config_intr_coal = qlcnic_82xx_config_intr_coalesce,
398 .config_rss = qlcnic_82xx_config_rss,
399 .config_hw_lro = qlcnic_82xx_config_hw_lro,
400 .config_loopback = qlcnic_82xx_set_lb_mode,
401 .clear_loopback = qlcnic_82xx_clear_lb_mode,
402 .config_promisc_mode = qlcnic_82xx_nic_set_promisc,
403 .change_l2_filter = qlcnic_82xx_change_filter,
404 .get_board_info = qlcnic_82xx_get_board_info,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000405};
406
Sony Chacko7f9664522013-01-01 03:20:19 +0000407int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000408{
409 struct pci_dev *pdev = adapter->pdev;
Sony Chacko13159182013-01-01 03:20:21 +0000410 int err = -1, i;
411 int max_tx_rings;
412
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 */
434 max_tx_rings = adapter->max_drv_tx_rings;
435 adapter->max_sds_rings = num_msix -
436 max_tx_rings - 1;
437 } else {
438 adapter->max_sds_rings = num_msix;
439 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000440 dev_info(&pdev->dev, "using msi-x interrupts\n");
441 return err;
Sony Chacko13159182013-01-01 03:20:21 +0000442 } else if (err > 0) {
443 dev_info(&pdev->dev,
444 "Unable to allocate %d MSI-X interrupt vectors\n",
445 num_msix);
446 if (qlcnic_83xx_check(adapter)) {
447 if (err < QLC_83XX_MINIMUM_VECTOR)
448 return err;
449 err -= (adapter->max_drv_tx_rings + 1);
450 num_msix = rounddown_pow_of_two(err);
451 num_msix += (adapter->max_drv_tx_rings + 1);
452 } else {
453 num_msix = rounddown_pow_of_two(err);
454 }
455
456 if (num_msix) {
457 dev_info(&pdev->dev,
Manish Chopradce056c2013-02-09 09:29:54 +0000458 "Trying to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000459 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000460 goto enable_msix;
Sony Chacko13159182013-01-01 03:20:21 +0000461 }
462 } else {
Manish Chopradce056c2013-02-09 09:29:54 +0000463 dev_info(&pdev->dev,
464 "Unable to allocate %d MSI-X interrupt vectors\n",
Sony Chacko13159182013-01-01 03:20:21 +0000465 num_msix);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000466 }
467 }
Sony Chacko13159182013-01-01 03:20:21 +0000468
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000469 return err;
470}
471
Manish chopra9a97e702013-01-25 10:20:37 +0000472static int qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000473{
Manish chopra9a97e702013-01-25 10:20:37 +0000474 int err = 0;
Sony Chacko15087c22012-12-04 03:33:54 +0000475 u32 offset, mask_reg;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000476 const struct qlcnic_legacy_intr_set *legacy_intrp;
Sony Chacko15087c22012-12-04 03:33:54 +0000477 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000478 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000479
Sony Chacko099f7aa2012-12-04 03:33:58 +0000480 if (qlcnic_use_msi && !pci_enable_msi(pdev)) {
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000481 adapter->flags |= QLCNIC_MSI_ENABLED;
Sony Chacko15087c22012-12-04 03:33:54 +0000482 offset = msi_tgt_status[adapter->ahw->pci_func];
483 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter->ahw,
484 offset);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000485 dev_info(&pdev->dev, "using msi interrupts\n");
486 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000487 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000488 }
Manish chopra9a97e702013-01-25 10:20:37 +0000489 if (qlcnic_use_msi || qlcnic_use_msi_x)
490 return -EOPNOTSUPP;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000491
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000492 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Sony Chacko79788452012-12-04 03:33:53 +0000493 adapter->ahw->int_vec_bit = legacy_intrp->int_vec_bit;
Sony Chacko15087c22012-12-04 03:33:54 +0000494 offset = legacy_intrp->tgt_status_reg;
495 adapter->tgt_status_reg = qlcnic_get_ioaddr(ahw, offset);
496 mask_reg = legacy_intrp->tgt_mask_reg;
497 adapter->tgt_mask_reg = qlcnic_get_ioaddr(ahw, mask_reg);
498 adapter->isr_int_vec = qlcnic_get_ioaddr(ahw, ISR_INT_VECTOR);
499 adapter->crb_int_state_reg = qlcnic_get_ioaddr(ahw, ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000500 dev_info(&pdev->dev, "using legacy interrupts\n");
501 adapter->msix_entries[0].vector = pdev->irq;
Manish chopra9a97e702013-01-25 10:20:37 +0000502 return err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000503}
504
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000505int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter, u8 num_intr)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000506{
Manish chopra9a97e702013-01-25 10:20:37 +0000507 int num_msix, err = 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000508
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000509 if (!num_intr)
510 num_intr = QLCNIC_DEF_NUM_STS_DESC_RINGS;
511
512 if (adapter->ahw->msix_supported)
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000513 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000514 num_intr));
515 else
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000516 num_msix = 1;
517
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000518 err = qlcnic_enable_msix(adapter, num_msix);
519 if (err == -ENOMEM || !err)
520 return err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000521
Manish chopra9a97e702013-01-25 10:20:37 +0000522 err = qlcnic_enable_msi_legacy(adapter);
523 if (!err)
524 return err;
525
526 return -EIO;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000527}
Sony Chacko13159182013-01-01 03:20:21 +0000528
Sony Chacko319ecf12013-01-01 03:20:22 +0000529void qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000530{
531 if (adapter->flags & QLCNIC_MSIX_ENABLED)
532 pci_disable_msix(adapter->pdev);
533 if (adapter->flags & QLCNIC_MSI_ENABLED)
534 pci_disable_msi(adapter->pdev);
Sony Chacko13159182013-01-01 03:20:21 +0000535
536 kfree(adapter->msix_entries);
537 adapter->msix_entries = NULL;
538
539 if (adapter->ahw->intr_tbl) {
540 vfree(adapter->ahw->intr_tbl);
541 adapter->ahw->intr_tbl = NULL;
542 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000543}
544
545static void
546qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
547{
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000548 if (adapter->ahw->pci_base0 != NULL)
549 iounmap(adapter->ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000550}
551
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000552static int qlcnic_get_act_pci_func(struct qlcnic_adapter *adapter)
553{
554 struct qlcnic_pci_info *pci_info;
555 int ret;
556
557 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
558 switch (adapter->ahw->port_type) {
559 case QLCNIC_GBE:
560 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_GBE_PORTS;
561 break;
562 case QLCNIC_XGBE:
563 adapter->ahw->act_pci_func = QLCNIC_NIU_MAX_XG_PORTS;
564 break;
565 }
566 return 0;
567 }
568
569 if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC)
570 return 0;
571
572 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
573 if (!pci_info)
574 return -ENOMEM;
575
576 ret = qlcnic_get_pci_info(adapter, pci_info);
577 kfree(pci_info);
578 return ret;
579}
Sony Chackod71170f2013-01-01 03:20:26 +0000580
581int qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000582{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000583 struct qlcnic_pci_info *pci_info;
Sony Chackobff57d82012-12-04 03:33:56 +0000584 int i, ret = 0, j = 0;
585 u16 act_pci_func;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000586 u8 pfn;
587
Dan Carpentere88db3b2010-08-09 21:49:36 +0000588 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
589 if (!pci_info)
590 return -ENOMEM;
591
Sony Chackobff57d82012-12-04 03:33:56 +0000592 ret = qlcnic_get_pci_info(adapter, pci_info);
593 if (ret)
594 goto err_pci_info;
595
596 act_pci_func = adapter->ahw->act_pci_func;
597
Dan Carpenterca315ac2010-08-09 21:47:56 +0000598 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Sony Chackobff57d82012-12-04 03:33:56 +0000599 act_pci_func, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000600 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000601 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000602 goto err_pci_info;
603 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000604
Dan Carpenterca315ac2010-08-09 21:47:56 +0000605 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000606 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
607 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000608 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000609 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000610 }
611
Dan Carpenterca315ac2010-08-09 21:47:56 +0000612 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
613 pfn = pci_info[i].id;
Sony Chackobff57d82012-12-04 03:33:56 +0000614
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000615 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000616 ret = QL_STATUS_INVALID_PARAM;
617 goto err_eswitch;
618 }
Sony Chackobff57d82012-12-04 03:33:56 +0000619
620 if (!pci_info[i].active ||
621 (pci_info[i].type != QLCNIC_TYPE_NIC))
622 continue;
623
624 adapter->npars[j].pci_func = pfn;
625 adapter->npars[j].active = (u8)pci_info[i].active;
626 adapter->npars[j].type = (u8)pci_info[i].type;
627 adapter->npars[j].phy_port = (u8)pci_info[i].default_port;
628 adapter->npars[j].min_bw = pci_info[i].tx_min_bw;
629 adapter->npars[j].max_bw = pci_info[i].tx_max_bw;
630 j++;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000631 }
632
Sony Chacko13159182013-01-01 03:20:21 +0000633 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) {
Dan Carpenterca315ac2010-08-09 21:47:56 +0000634 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
Sony Chacko13159182013-01-01 03:20:21 +0000635 if (qlcnic_83xx_check(adapter))
636 qlcnic_enable_eswitch(adapter, i, 1);
637 }
Dan Carpenterca315ac2010-08-09 21:47:56 +0000638
Dan Carpentere88db3b2010-08-09 21:49:36 +0000639 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000640 return 0;
641
642err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000643 kfree(adapter->eswitch);
644 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000645err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000646 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000647 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000648err_pci_info:
649 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000650
651 return ret;
652}
653
654static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000655qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
656{
657 u8 id;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000658 int i, ret = 1;
659 u32 data = QLCNIC_MGMT_FUNC;
Sony Chackobff57d82012-12-04 03:33:56 +0000660 struct qlcnic_hardware_context *ahw = adapter->ahw;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000661
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000662 ret = qlcnic_api_lock(adapter);
663 if (ret)
664 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000665
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000666 if (qlcnic_config_npars) {
Sony Chackobff57d82012-12-04 03:33:56 +0000667 for (i = 0; i < ahw->act_pci_func; i++) {
668 id = adapter->npars[i].pci_func;
669 if (id == ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000670 continue;
671 data |= (qlcnic_config_npars &
672 QLC_DEV_SET_DRV(0xf, id));
673 }
674 } else {
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000675 data = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Sony Chackobff57d82012-12-04 03:33:56 +0000676 data = (data & ~QLC_DEV_SET_DRV(0xf, ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000677 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Sony Chackobff57d82012-12-04 03:33:56 +0000678 ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000679 }
Himanshu Madhania15ebd32013-01-01 03:20:18 +0000680 QLC_SHARED_REG_WR32(adapter, QLCNIC_DRV_OP_MODE, data);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000681 qlcnic_api_unlock(adapter);
682err_lock:
683 return ret;
684}
685
Sony Chacko13159182013-01-01 03:20:21 +0000686static void qlcnic_check_vf(struct qlcnic_adapter *adapter,
687 const struct pci_device_id *ent)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000688{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000689 u32 op_mode, priv_level;
690
691 /* Determine FW API version */
Sony Chacko13159182013-01-01 03:20:21 +0000692 adapter->ahw->fw_hal_version = QLC_SHARED_REG_RD32(adapter,
693 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000694
695 /* Find PCI function number */
Sony Chacko13159182013-01-01 03:20:21 +0000696 qlcnic_get_func_no(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000697
698 /* Determine function privilege level */
Sony Chacko13159182013-01-01 03:20:21 +0000699 op_mode = QLC_SHARED_REG_RD32(adapter, QLCNIC_DRV_OP_MODE);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000700 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000701 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000702 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000703 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000704
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000705 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Sony Chacko79788452012-12-04 03:33:53 +0000706 adapter->ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000707 dev_info(&adapter->pdev->dev,
708 "HAL Version: %d Non Privileged function\n",
Sony Chacko79788452012-12-04 03:33:53 +0000709 adapter->ahw->fw_hal_version);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000710 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000711 } else
712 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000713}
714
Sony Chacko15087c22012-12-04 03:33:54 +0000715#define QLCNIC_82XX_BAR0_LENGTH 0x00200000UL
Sony Chacko13159182013-01-01 03:20:21 +0000716#define QLCNIC_83XX_BAR0_LENGTH 0x4000
Sony Chacko15087c22012-12-04 03:33:54 +0000717static void qlcnic_get_bar_length(u32 dev_id, ulong *bar)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000718{
Sony Chacko15087c22012-12-04 03:33:54 +0000719 switch (dev_id) {
720 case PCI_DEVICE_ID_QLOGIC_QLE824X:
721 *bar = QLCNIC_82XX_BAR0_LENGTH;
722 break;
Sony Chacko13159182013-01-01 03:20:21 +0000723 case PCI_DEVICE_ID_QLOGIC_QLE834X:
724 *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
754 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
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,
1153 "Waiting for NPAR state to opertional timeout\n");
1154 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) &&
1295 (adapter->flags & QLCNIC_MSIX_ENABLED)) {
1296 handler = qlcnic_msix_tx_intr;
1297 for (ring = 0; ring < adapter->max_drv_tx_rings;
1298 ring++) {
1299 tx_ring = &adapter->tx_ring[ring];
1300 snprintf(tx_ring->name, sizeof(int) + IFNAMSIZ,
1301 "%s[%d]", netdev->name,
Himanshu Madhaniac166702013-02-18 12:06:15 +00001302 adapter->max_sds_rings + ring);
Sony Chacko13159182013-01-01 03:20:21 +00001303 err = request_irq(tx_ring->irq, handler, flags,
1304 tx_ring->name, tx_ring);
1305 if (err)
1306 return err;
1307 }
1308 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001309 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001310 return 0;
1311}
1312
1313static void
1314qlcnic_free_irq(struct qlcnic_adapter *adapter)
1315{
1316 int ring;
1317 struct qlcnic_host_sds_ring *sds_ring;
Sony Chacko13159182013-01-01 03:20:21 +00001318 struct qlcnic_host_tx_ring *tx_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001319
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001320 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001321
Sony Chacko13159182013-01-01 03:20:21 +00001322 if (adapter->ahw->diag_test != QLCNIC_LOOPBACK_TEST) {
Himanshu Madhaniac166702013-02-18 12:06:15 +00001323 if (qlcnic_82xx_check(adapter) ||
1324 (qlcnic_83xx_check(adapter) &&
1325 (adapter->flags & QLCNIC_MSIX_ENABLED))) {
1326 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1327 sds_ring = &recv_ctx->sds_rings[ring];
1328 free_irq(sds_ring->irq, sds_ring);
1329 }
Sony Chacko13159182013-01-01 03:20:21 +00001330 }
1331 if (qlcnic_83xx_check(adapter)) {
1332 for (ring = 0; ring < adapter->max_drv_tx_rings;
1333 ring++) {
1334 tx_ring = &adapter->tx_ring[ring];
1335 if (tx_ring->irq)
1336 free_irq(tx_ring->irq, tx_ring);
1337 }
1338 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001339 }
1340}
1341
Shahed Shaikh99e85872013-02-18 12:06:16 +00001342static void qlcnic_get_lro_mss_capability(struct qlcnic_adapter *adapter)
1343{
1344 u32 capab = 0;
1345
1346 if (qlcnic_82xx_check(adapter)) {
1347 if (adapter->ahw->capabilities2 &
1348 QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1349 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1350 } else {
1351 capab = adapter->ahw->capabilities;
1352 if (QLC_83XX_GET_FW_LRO_MSS_CAPABILITY(capab))
1353 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1354 }
1355}
1356
Sony Chacko319ecf12013-01-01 03:20:22 +00001357int __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001358{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001359 int ring;
1360 struct qlcnic_host_rds_ring *rds_ring;
1361
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001362 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1363 return -EIO;
1364
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001365 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1366 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001367 if (qlcnic_set_eswitch_port_config(adapter))
1368 return -EIO;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001369 qlcnic_get_lro_mss_capability(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001370
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001371 if (qlcnic_fw_create_ctx(adapter))
1372 return -EIO;
1373
1374 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001375 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001376 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001377 }
1378
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001379 qlcnic_set_multi(netdev);
1380 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1381
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001382 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001383
1384 if (adapter->max_sds_rings > 1)
1385 qlcnic_config_rss(adapter, 1);
1386
1387 qlcnic_config_intr_coalesce(adapter);
1388
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001389 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001390 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1391
1392 qlcnic_napi_enable(adapter);
1393
1394 qlcnic_linkevent_request(adapter, 1);
1395
Sony Chacko79788452012-12-04 03:33:53 +00001396 adapter->ahw->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001397 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1398 return 0;
1399}
1400
Sony Chacko629263a2013-01-01 04:11:55 +00001401int qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001402{
1403 int err = 0;
1404
1405 rtnl_lock();
1406 if (netif_running(netdev))
1407 err = __qlcnic_up(adapter, netdev);
1408 rtnl_unlock();
1409
1410 return err;
1411}
1412
Sony Chacko319ecf12013-01-01 03:20:22 +00001413void __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001414{
1415 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1416 return;
1417
1418 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1419 return;
1420
1421 smp_mb();
1422 spin_lock(&adapter->tx_clean_lock);
1423 netif_carrier_off(netdev);
1424 netif_tx_disable(netdev);
1425
1426 qlcnic_free_mac_list(adapter);
1427
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001428 if (adapter->fhash.fnum)
1429 qlcnic_delete_lb_filters(adapter);
1430
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001431 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1432
1433 qlcnic_napi_disable(adapter);
1434
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001435 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001436 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001437
1438 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001439 qlcnic_release_tx_buffers(adapter);
1440 spin_unlock(&adapter->tx_clean_lock);
1441}
1442
1443/* Usage: During suspend and firmware recovery module */
1444
Sony Chacko629263a2013-01-01 04:11:55 +00001445void qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001446{
1447 rtnl_lock();
1448 if (netif_running(netdev))
1449 __qlcnic_down(adapter, netdev);
1450 rtnl_unlock();
1451
1452}
1453
Sony Chacko319ecf12013-01-01 03:20:22 +00001454int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001455qlcnic_attach(struct qlcnic_adapter *adapter)
1456{
1457 struct net_device *netdev = adapter->netdev;
1458 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001459 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001460
1461 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1462 return 0;
1463
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001464 err = qlcnic_napi_add(adapter, netdev);
1465 if (err)
1466 return err;
1467
1468 err = qlcnic_alloc_sw_resources(adapter);
1469 if (err) {
1470 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001471 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001472 }
1473
1474 err = qlcnic_alloc_hw_resources(adapter);
1475 if (err) {
1476 dev_err(&pdev->dev, "Error in setting hw resources\n");
1477 goto err_out_free_sw;
1478 }
1479
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001480 err = qlcnic_request_irq(adapter);
1481 if (err) {
1482 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001483 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001484 }
1485
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001486 qlcnic_create_sysfs_entries(adapter);
1487
1488 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1489 return 0;
1490
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001491err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001492 qlcnic_free_hw_resources(adapter);
1493err_out_free_sw:
1494 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001495err_out_napi_del:
1496 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001497 return err;
1498}
1499
Sony Chacko319ecf12013-01-01 03:20:22 +00001500void qlcnic_detach(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001501{
1502 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1503 return;
1504
1505 qlcnic_remove_sysfs_entries(adapter);
1506
1507 qlcnic_free_hw_resources(adapter);
1508 qlcnic_release_rx_buffers(adapter);
1509 qlcnic_free_irq(adapter);
1510 qlcnic_napi_del(adapter);
1511 qlcnic_free_sw_resources(adapter);
1512
1513 adapter->is_up = 0;
1514}
1515
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001516void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1517{
1518 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1519 struct qlcnic_host_sds_ring *sds_ring;
1520 int ring;
1521
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001522 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Sony Chacko79788452012-12-04 03:33:53 +00001523 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001524 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001525 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001526 qlcnic_disable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001527 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001528 }
1529
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001530 qlcnic_fw_destroy_ctx(adapter);
1531
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001532 qlcnic_detach(adapter);
1533
Sony Chacko79788452012-12-04 03:33:53 +00001534 adapter->ahw->diag_test = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001535 adapter->max_sds_rings = max_sds_rings;
1536
1537 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001538 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001539
1540 if (netif_running(netdev))
1541 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001542out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001543 netif_device_attach(netdev);
1544}
1545
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001546static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1547{
1548 int err = 0;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001549 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1550 GFP_KERNEL);
1551 if (!adapter->recv_ctx) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001552 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001553 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001554 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001555 /* Initialize interrupt coalesce parameters */
1556 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1557 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1558 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Sony Chacko4be41e92013-01-01 03:20:20 +00001559 /* clear stats */
1560 memset(&adapter->stats, 0, sizeof(adapter->stats));
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001561err_out:
1562 return err;
1563}
1564
1565static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1566{
1567 kfree(adapter->recv_ctx);
1568 adapter->recv_ctx = NULL;
1569
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001570 if (adapter->ahw->fw_dump.tmpl_hdr) {
1571 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1572 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1573 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001574
Sony Chacko81d0aeb2013-01-01 03:20:25 +00001575 kfree(adapter->ahw->reset.buff);
Sony Chacko4be41e92013-01-01 03:20:20 +00001576 adapter->ahw->fw_dump.tmpl_hdr = NULL;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001577}
1578
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001579int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1580{
1581 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1582 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001583 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001584 int ring;
1585 int ret;
1586
1587 netif_device_detach(netdev);
1588
1589 if (netif_running(netdev))
1590 __qlcnic_down(adapter, netdev);
1591
1592 qlcnic_detach(adapter);
1593
1594 adapter->max_sds_rings = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001595 adapter->ahw->diag_test = test;
Sony Chacko4be41e92013-01-01 03:20:20 +00001596 adapter->ahw->linkup = 0;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001597
1598 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001599 if (ret) {
1600 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001601 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001602 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001603
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001604 ret = qlcnic_fw_create_ctx(adapter);
1605 if (ret) {
1606 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001607 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001608 return ret;
1609 }
1610
1611 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001612 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001613 qlcnic_post_rx_buffers(adapter, rds_ring, ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001614 }
1615
Sony Chacko79788452012-12-04 03:33:53 +00001616 if (adapter->ahw->diag_test == QLCNIC_INTERRUPT_TEST) {
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001617 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001618 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Jitendra Kalsariaba4468db2013-02-09 09:29:51 +00001619 qlcnic_enable_int(sds_ring);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001620 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001621 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001622
Sony Chacko79788452012-12-04 03:33:53 +00001623 if (adapter->ahw->diag_test == QLCNIC_LOOPBACK_TEST) {
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001624 adapter->ahw->loopback_state = 0;
1625 qlcnic_linkevent_request(adapter, 1);
1626 }
1627
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001628 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001629
1630 return 0;
1631}
1632
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001633/* Reset context in hardware only */
1634static int
1635qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1636{
1637 struct net_device *netdev = adapter->netdev;
1638
1639 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1640 return -EBUSY;
1641
1642 netif_device_detach(netdev);
1643
1644 qlcnic_down(adapter, netdev);
1645
1646 qlcnic_up(adapter, netdev);
1647
1648 netif_device_attach(netdev);
1649
1650 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Sony Chacko13159182013-01-01 03:20:21 +00001651 dev_err(&adapter->pdev->dev, "%s:\n", __func__);
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001652 return 0;
1653}
1654
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001655int
1656qlcnic_reset_context(struct qlcnic_adapter *adapter)
1657{
1658 int err = 0;
1659 struct net_device *netdev = adapter->netdev;
1660
1661 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1662 return -EBUSY;
1663
1664 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1665
1666 netif_device_detach(netdev);
1667
1668 if (netif_running(netdev))
1669 __qlcnic_down(adapter, netdev);
1670
1671 qlcnic_detach(adapter);
1672
1673 if (netif_running(netdev)) {
1674 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001675 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001676 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001677 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1678 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001679 }
1680
1681 netif_device_attach(netdev);
1682 }
1683
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001684 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1685 return err;
1686}
1687
1688static int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001689qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1690 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001691{
1692 int err;
1693 struct pci_dev *pdev = adapter->pdev;
1694
Sony Chacko13159182013-01-01 03:20:21 +00001695 adapter->rx_csum = 1;
Sony Chacko79788452012-12-04 03:33:53 +00001696 adapter->ahw->mc_enabled = 0;
Sony Chacko13159182013-01-01 03:20:21 +00001697 adapter->ahw->max_mc_count = QLCNIC_MAX_MC_COUNT;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001698
1699 netdev->netdev_ops = &qlcnic_netdev_ops;
Sony Chacko13159182013-01-01 03:20:21 +00001700 netdev->watchdog_timeo = QLCNIC_WATCHDOG_TIMEOUTVALUE * HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001701
1702 qlcnic_change_mtu(netdev, netdev->mtu);
1703
1704 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1705
Sony Chacko7e38d042013-01-01 03:20:28 +00001706 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Sony Chacko13159182013-01-01 03:20:21 +00001707 NETIF_F_IPV6_CSUM | NETIF_F_GRO |
1708 NETIF_F_HW_VLAN_RX);
1709 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1710 NETIF_F_IPV6_CSUM);
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001711
Sony Chacko13159182013-01-01 03:20:21 +00001712 if (QLCNIC_IS_TSO_CAPABLE(adapter)) {
1713 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1714 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1715 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001716
Sony Chacko13159182013-01-01 03:20:21 +00001717 if (pci_using_dac) {
1718 netdev->features |= NETIF_F_HIGHDMA;
1719 netdev->vlan_features |= NETIF_F_HIGHDMA;
1720 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001721
Sony Chacko13159182013-01-01 03:20:21 +00001722 if (qlcnic_vlan_tx_check(adapter))
1723 netdev->features |= (NETIF_F_HW_VLAN_TX);
1724
Sony Chacko79788452012-12-04 03:33:53 +00001725 if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Sony Chacko13159182013-01-01 03:20:21 +00001726 netdev->features |= NETIF_F_LRO;
Michał Mirosław135d84a2011-04-19 03:03:57 +00001727
Sony Chacko7e38d042013-01-01 03:20:28 +00001728 netdev->hw_features = netdev->features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001729 netdev->irq = adapter->msix_entries[0].vector;
1730
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001731 err = register_netdev(netdev);
1732 if (err) {
1733 dev_err(&pdev->dev, "failed to register net device\n");
1734 return err;
1735 }
1736
1737 return 0;
1738}
1739
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001740static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001741{
1742 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1743 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1744 *pci_using_dac = 1;
1745 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1746 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1747 *pci_using_dac = 0;
1748 else {
1749 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1750 return -EIO;
1751 }
1752
1753 return 0;
1754}
1755
Sony Chacko4be41e92013-01-01 03:20:20 +00001756void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
1757{
1758 int ring;
1759 struct qlcnic_host_tx_ring *tx_ring;
1760
1761 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1762 tx_ring = &adapter->tx_ring[ring];
1763 if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
1764 vfree(tx_ring->cmd_buf_arr);
1765 tx_ring->cmd_buf_arr = NULL;
1766 }
1767 }
1768 if (adapter->tx_ring != NULL)
1769 kfree(adapter->tx_ring);
1770}
1771
1772int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
1773 struct net_device *netdev)
1774{
Joe Perchesb2adaca2013-02-03 17:43:58 +00001775 int ring, vector, index;
Sony Chacko4be41e92013-01-01 03:20:20 +00001776 struct qlcnic_host_tx_ring *tx_ring;
1777 struct qlcnic_cmd_buffer *cmd_buf_arr;
1778
Joe Perchesb2adaca2013-02-03 17:43:58 +00001779 tx_ring = kcalloc(adapter->max_drv_tx_rings,
1780 sizeof(struct qlcnic_host_tx_ring), GFP_KERNEL);
1781 if (tx_ring == NULL)
Sony Chacko4be41e92013-01-01 03:20:20 +00001782 return -ENOMEM;
Joe Perchesb2adaca2013-02-03 17:43:58 +00001783
Sony Chacko4be41e92013-01-01 03:20:20 +00001784 adapter->tx_ring = tx_ring;
1785
1786 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1787 tx_ring = &adapter->tx_ring[ring];
1788 tx_ring->num_desc = adapter->num_txd;
1789 tx_ring->txq = netdev_get_tx_queue(netdev, ring);
1790 cmd_buf_arr = vzalloc(TX_BUFF_RINGSIZE(tx_ring));
1791 if (cmd_buf_arr == NULL) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001792 qlcnic_free_tx_rings(adapter);
1793 return -ENOMEM;
1794 }
1795 memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring));
1796 tx_ring->cmd_buf_arr = cmd_buf_arr;
1797 }
1798
1799 if (qlcnic_83xx_check(adapter)) {
1800 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1801 tx_ring = &adapter->tx_ring[ring];
1802 tx_ring->adapter = adapter;
1803 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1804 index = adapter->max_sds_rings + ring;
1805 vector = adapter->msix_entries[index].vector;
1806 tx_ring->irq = vector;
1807 }
1808 }
1809 }
1810 return 0;
1811}
1812
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001813static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001814qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1815{
1816 struct net_device *netdev = NULL;
1817 struct qlcnic_adapter *adapter = NULL;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001818 struct qlcnic_hardware_context *ahw;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001819 int err, pci_using_dac = -1;
Sritej Velagac84e3402013-01-25 10:20:34 +00001820 u32 capab2;
Dan Carpenter7bc48642013-01-30 22:14:10 +00001821 char board_name[QLCNIC_MAX_BOARD_NAME_LEN + 19]; /* MAC + ": " + name */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001822
1823 err = pci_enable_device(pdev);
1824 if (err)
1825 return err;
1826
1827 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1828 err = -ENODEV;
1829 goto err_out_disable_pdev;
1830 }
1831
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001832 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1833 if (err)
1834 goto err_out_disable_pdev;
1835
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001836 err = pci_request_regions(pdev, qlcnic_driver_name);
1837 if (err)
1838 goto err_out_disable_pdev;
1839
1840 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001841 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001842
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001843 ahw = kzalloc(sizeof(struct qlcnic_hardware_context), GFP_KERNEL);
1844 if (!ahw)
1845 goto err_out_free_res;
1846
1847 if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE824X) {
1848 ahw->hw_ops = &qlcnic_hw_ops;
1849 ahw->reg_tbl = (u32 *)qlcnic_reg_tbl;
Sony Chacko13159182013-01-01 03:20:21 +00001850 } else if (ent->device == PCI_DEVICE_ID_QLOGIC_QLE834X) {
1851 qlcnic_83xx_register_map(ahw);
1852 } else {
1853 goto err_out_free_hw_res;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001854 }
1855
1856 err = qlcnic_setup_pci_map(pdev, ahw);
1857 if (err)
1858 goto err_out_free_hw_res;
1859
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001860 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1861 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001862 err = -ENOMEM;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001863 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001864 }
1865
1866 SET_NETDEV_DEV(netdev, &pdev->dev);
1867
1868 adapter = netdev_priv(netdev);
1869 adapter->netdev = netdev;
1870 adapter->pdev = pdev;
Sony Chacko13159182013-01-01 03:20:21 +00001871 adapter->ahw = ahw;
1872
1873 adapter->qlcnic_wq = create_singlethread_workqueue("qlcnic");
1874 if (adapter->qlcnic_wq == NULL) {
1875 dev_err(&pdev->dev, "Failed to create workqueue\n");
1876 goto err_out_free_netdev;
1877 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001878
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001879 err = qlcnic_alloc_adapter_resources(adapter);
1880 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001881 goto err_out_free_netdev;
1882
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001883 adapter->dev_rst_time = jiffies;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001884 adapter->ahw->revision_id = pdev->revision;
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001885 if (qlcnic_mac_learn == FDB_MAC_LEARN)
1886 adapter->fdb_mac_learn = true;
1887 else if (qlcnic_mac_learn == DRV_MAC_LEARN)
1888 adapter->drv_mac_learn = true;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001889 adapter->max_drv_tx_rings = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001890
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001891 rwlock_init(&adapter->ahw->crb_lock);
1892 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001893
1894 spin_lock_init(&adapter->tx_clean_lock);
1895 INIT_LIST_HEAD(&adapter->mac_list);
1896
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001897 if (qlcnic_82xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00001898 qlcnic_check_vf(adapter, ent);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001899 adapter->portnum = adapter->ahw->pci_func;
1900 err = qlcnic_start_firmware(adapter);
1901 if (err) {
1902 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1903 goto err_out_free_hw;
1904 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001905
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001906 err = qlcnic_setup_idc_param(adapter);
1907 if (err)
1908 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001909
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001910 adapter->flags |= QLCNIC_NEED_FLR;
Sony Chacko13159182013-01-01 03:20:21 +00001911 } else if (qlcnic_83xx_check(adapter)) {
1912 qlcnic_83xx_check_vf(adapter, ent);
1913 adapter->portnum = adapter->ahw->pci_func;
Sony Chacko629263a2013-01-01 04:11:55 +00001914 err = qlcnic_83xx_init(adapter);
1915 if (err) {
1916 dev_err(&pdev->dev, "%s: failed\n", __func__);
1917 goto err_out_free_hw;
1918 }
Sony Chacko13159182013-01-01 03:20:21 +00001919 } else {
1920 dev_err(&pdev->dev,
1921 "%s: failed. Please Reboot\n", __func__);
1922 goto err_out_free_hw;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001923 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001924
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001925 if (qlcnic_read_mac_addr(adapter))
1926 dev_warn(&pdev->dev, "failed to read mac addr\n");
1927
1928 if (adapter->portnum == 0) {
Sony Chacko22999792012-12-04 03:33:55 +00001929 qlcnic_get_board_name(adapter, board_name);
Sony Chacko13159182013-01-01 03:20:21 +00001930
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001931 pr_info("%s: %s Board Chip rev 0x%x\n",
Sony Chacko22999792012-12-04 03:33:55 +00001932 module_name(THIS_MODULE),
1933 board_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001934 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001935 err = qlcnic_setup_intr(adapter, 0);
Manish chopra9a97e702013-01-25 10:20:37 +00001936 if (err) {
1937 dev_err(&pdev->dev, "Failed to setup interrupt\n");
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001938 goto err_out_disable_msi;
Manish chopra9a97e702013-01-25 10:20:37 +00001939 }
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001940
Sony Chacko13159182013-01-01 03:20:21 +00001941 if (qlcnic_83xx_check(adapter)) {
1942 err = qlcnic_83xx_setup_mbx_intr(adapter);
1943 if (err)
1944 goto err_out_disable_msi;
1945 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001946
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001947 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001948 if (err)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001949 goto err_out_disable_mbx_intr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001950
Sritej Velagac84e3402013-01-25 10:20:34 +00001951 if (qlcnic_82xx_check(adapter)) {
1952 if (ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1953 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1954 if (capab2 & QLCNIC_FW_CAPABILITY_2_OCBB)
1955 qlcnic_fw_cmd_set_drv_version(adapter);
1956 }
1957 }
1958
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001959 pci_set_drvdata(pdev, adapter);
1960
Sony Chacko97ee45e2012-12-04 03:33:52 +00001961 if (qlcnic_82xx_check(adapter))
1962 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1963 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001964
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001965 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001966 case QLCNIC_GBE:
1967 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1968 adapter->netdev->name);
1969 break;
1970 case QLCNIC_XGBE:
1971 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1972 adapter->netdev->name);
1973 break;
1974 }
1975
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001976 if (qlcnic_get_act_pci_func(adapter))
1977 goto err_out_disable_mbx_intr;
1978
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +00001979 if (adapter->drv_mac_learn)
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001980 qlcnic_alloc_lb_filters_mem(adapter);
1981
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001982 qlcnic_add_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001983
1984 return 0;
1985
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001986err_out_disable_mbx_intr:
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00001987 if (qlcnic_83xx_check(adapter))
Sony Chacko13159182013-01-01 03:20:21 +00001988 qlcnic_83xx_free_mbx_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001989
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001990err_out_disable_msi:
1991 qlcnic_teardown_intr(adapter);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001992 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001993 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001994
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001995err_out_free_hw:
1996 qlcnic_free_adapter_resources(adapter);
1997
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001998err_out_free_netdev:
1999 free_netdev(netdev);
2000
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002001err_out_iounmap:
2002 qlcnic_cleanup_pci_map(adapter);
2003
2004err_out_free_hw_res:
2005 kfree(ahw);
2006
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002007err_out_free_res:
2008 pci_release_regions(pdev);
2009
2010err_out_disable_pdev:
2011 pci_set_drvdata(pdev, NULL);
2012 pci_disable_device(pdev);
2013 return err;
2014}
2015
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002016static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002017{
2018 struct qlcnic_adapter *adapter;
2019 struct net_device *netdev;
Sony Chacko13159182013-01-01 03:20:21 +00002020 struct qlcnic_hardware_context *ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002021
2022 adapter = pci_get_drvdata(pdev);
2023 if (adapter == NULL)
2024 return;
2025
2026 netdev = adapter->netdev;
2027
Sony Chacko13159182013-01-01 03:20:21 +00002028 qlcnic_cancel_idc_work(adapter);
2029 ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002030
2031 unregister_netdev(netdev);
2032
Sony Chacko13159182013-01-01 03:20:21 +00002033 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00002034 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00002035 qlcnic_83xx_register_nic_idc_func(adapter, 0);
2036 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00002037 }
2038
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002039 qlcnic_detach(adapter);
2040
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00002041 if (adapter->npars != NULL)
2042 kfree(adapter->npars);
2043 if (adapter->eswitch != NULL)
2044 kfree(adapter->eswitch);
2045
Sony Chacko97ee45e2012-12-04 03:33:52 +00002046 if (qlcnic_82xx_check(adapter))
2047 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002048
2049 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2050
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002051 qlcnic_free_lb_filters_mem(adapter);
2052
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002053 qlcnic_teardown_intr(adapter);
2054
Sony Chacko13159182013-01-01 03:20:21 +00002055 qlcnic_remove_sysfs(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002056
2057 qlcnic_cleanup_pci_map(adapter);
2058
2059 qlcnic_release_firmware(adapter);
2060
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002061 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002062 pci_release_regions(pdev);
2063 pci_disable_device(pdev);
2064 pci_set_drvdata(pdev, NULL);
2065
Sony Chacko13159182013-01-01 03:20:21 +00002066 if (adapter->qlcnic_wq) {
2067 destroy_workqueue(adapter->qlcnic_wq);
2068 adapter->qlcnic_wq = NULL;
2069 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002070 qlcnic_free_adapter_resources(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00002071 kfree(ahw);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002072 free_netdev(netdev);
2073}
2074static int __qlcnic_shutdown(struct pci_dev *pdev)
2075{
2076 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2077 struct net_device *netdev = adapter->netdev;
2078 int retval;
2079
2080 netif_device_detach(netdev);
2081
Sony Chacko13159182013-01-01 03:20:21 +00002082 qlcnic_cancel_idc_work(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002083
2084 if (netif_running(netdev))
2085 qlcnic_down(adapter, netdev);
2086
Sony Chacko97ee45e2012-12-04 03:33:52 +00002087 if (qlcnic_82xx_check(adapter))
2088 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002089
2090 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2091
2092 retval = pci_save_state(pdev);
2093 if (retval)
2094 return retval;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002095 if (qlcnic_82xx_check(adapter)) {
2096 if (qlcnic_wol_supported(adapter)) {
2097 pci_enable_wake(pdev, PCI_D3cold, 1);
2098 pci_enable_wake(pdev, PCI_D3hot, 1);
2099 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002100 }
2101
2102 return 0;
2103}
2104
2105static void qlcnic_shutdown(struct pci_dev *pdev)
2106{
2107 if (__qlcnic_shutdown(pdev))
2108 return;
2109
2110 pci_disable_device(pdev);
2111}
2112
2113#ifdef CONFIG_PM
2114static int
2115qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
2116{
2117 int retval;
2118
2119 retval = __qlcnic_shutdown(pdev);
2120 if (retval)
2121 return retval;
2122
2123 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2124 return 0;
2125}
2126
2127static int
2128qlcnic_resume(struct pci_dev *pdev)
2129{
2130 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2131 struct net_device *netdev = adapter->netdev;
2132 int err;
2133
2134 err = pci_enable_device(pdev);
2135 if (err)
2136 return err;
2137
2138 pci_set_power_state(pdev, PCI_D0);
2139 pci_set_master(pdev);
2140 pci_restore_state(pdev);
2141
Sony Chacko13159182013-01-01 03:20:21 +00002142 err = qlcnic_start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002143 if (err) {
2144 dev_err(&pdev->dev, "failed to start firmware\n");
2145 return err;
2146 }
2147
2148 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002149 err = qlcnic_up(adapter, netdev);
2150 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002151 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002152
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002153 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002154 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002155done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002156 netif_device_attach(netdev);
2157 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2158 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002159}
2160#endif
2161
2162static int qlcnic_open(struct net_device *netdev)
2163{
2164 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2165 int err;
2166
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00002167 netif_carrier_off(netdev);
2168
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002169 err = qlcnic_attach(adapter);
2170 if (err)
2171 return err;
2172
2173 err = __qlcnic_up(adapter, netdev);
2174 if (err)
2175 goto err_out;
2176
2177 netif_start_queue(netdev);
2178
2179 return 0;
2180
2181err_out:
2182 qlcnic_detach(adapter);
2183 return err;
2184}
2185
2186/*
2187 * qlcnic_close - Disables a network interface entry point
2188 */
2189static int qlcnic_close(struct net_device *netdev)
2190{
2191 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2192
2193 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00002194
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002195 return 0;
2196}
2197
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002198void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002199{
2200 void *head;
2201 int i;
Sony Chacko13159182013-01-01 03:20:21 +00002202 struct net_device *netdev = adapter->netdev;
2203 u32 filter_size = 0;
2204 u16 act_pci_func = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002205
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00002206 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002207 return;
2208
Sony Chacko13159182013-01-01 03:20:21 +00002209 act_pci_func = adapter->ahw->act_pci_func;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002210 spin_lock_init(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002211 spin_lock_init(&adapter->rx_mac_learn_lock);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002212
Sony Chacko13159182013-01-01 03:20:21 +00002213 if (qlcnic_82xx_check(adapter)) {
2214 filter_size = QLCNIC_LB_MAX_FILTERS;
2215 adapter->fhash.fbucket_size = QLCNIC_LB_BUCKET_SIZE;
2216 } else {
2217 filter_size = QLC_83XX_LB_MAX_FILTERS;
2218 adapter->fhash.fbucket_size = QLC_83XX_LB_BUCKET_SIZE;
2219 }
2220
2221 head = kcalloc(adapter->fhash.fbucket_size,
Jitendra Kalsaria1d9219d2013-01-25 10:20:39 +00002222 sizeof(struct hlist_head), GFP_ATOMIC);
Sony Chacko13159182013-01-01 03:20:21 +00002223
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002224 if (!head)
2225 return;
2226
Sony Chacko13159182013-01-01 03:20:21 +00002227 adapter->fhash.fmax = (filter_size / act_pci_func);
Joe Perches43d620c2011-06-16 19:08:06 +00002228 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002229
Sony Chacko13159182013-01-01 03:20:21 +00002230 netdev_info(netdev, "active nic func = %d, mac filter size=%d\n",
2231 act_pci_func, adapter->fhash.fmax);
2232
2233 for (i = 0; i < adapter->fhash.fbucket_size; i++)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002234 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
Shahed Shaikh53643a72013-02-18 13:22:37 +00002235
2236 adapter->rx_fhash.fbucket_size = adapter->fhash.fbucket_size;
2237
2238 head = kcalloc(adapter->rx_fhash.fbucket_size,
2239 sizeof(struct hlist_head), GFP_ATOMIC);
2240
2241 if (!head)
2242 return;
2243
2244 adapter->rx_fhash.fmax = (filter_size / act_pci_func);
2245 adapter->rx_fhash.fhead = head;
2246
2247 for (i = 0; i < adapter->rx_fhash.fbucket_size; i++)
2248 INIT_HLIST_HEAD(&adapter->rx_fhash.fhead[i]);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002249}
2250
2251static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
2252{
2253 if (adapter->fhash.fmax && adapter->fhash.fhead)
2254 kfree(adapter->fhash.fhead);
2255
2256 adapter->fhash.fhead = NULL;
2257 adapter->fhash.fmax = 0;
Shahed Shaikh53643a72013-02-18 13:22:37 +00002258
2259 if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
2260 kfree(adapter->rx_fhash.fhead);
2261
2262 adapter->rx_fhash.fmax = 0;
2263 adapter->rx_fhash.fhead = NULL;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002264}
2265
Sony Chacko629263a2013-01-01 04:11:55 +00002266int qlcnic_check_temp(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002267{
2268 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00002269 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002270 int rv = 0;
2271
Sony Chacko13159182013-01-01 03:20:21 +00002272 if (qlcnic_83xx_check(adapter))
2273 temp = QLCRDX(adapter->ahw, QLC_83XX_ASIC_TEMP);
2274
Sony Chacko97ee45e2012-12-04 03:33:52 +00002275 if (qlcnic_82xx_check(adapter))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002276 temp = QLC_SHARED_REG_RD32(adapter, QLCNIC_ASIC_TEMP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002277
2278 temp_state = qlcnic_get_temp_state(temp);
2279 temp_val = qlcnic_get_temp_val(temp);
2280
2281 if (temp_state == QLCNIC_TEMP_PANIC) {
2282 dev_err(&netdev->dev,
2283 "Device temperature %d degrees C exceeds"
2284 " maximum allowed. Hardware has been shut down.\n",
2285 temp_val);
2286 rv = 1;
2287 } else if (temp_state == QLCNIC_TEMP_WARN) {
Sony Chacko79788452012-12-04 03:33:53 +00002288 if (adapter->ahw->temp == QLCNIC_TEMP_NORMAL) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002289 dev_err(&netdev->dev,
2290 "Device temperature %d degrees C "
2291 "exceeds operating range."
2292 " Immediate action needed.\n",
2293 temp_val);
2294 }
2295 } else {
Sony Chacko79788452012-12-04 03:33:53 +00002296 if (adapter->ahw->temp == QLCNIC_TEMP_WARN) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002297 dev_info(&netdev->dev,
2298 "Device temperature is now %d degrees C"
2299 " in normal range.\n", temp_val);
2300 }
2301 }
Sony Chacko79788452012-12-04 03:33:53 +00002302 adapter->ahw->temp = temp_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002303 return rv;
2304}
2305
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002306static void qlcnic_tx_timeout(struct net_device *netdev)
2307{
2308 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2309
2310 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2311 return;
2312
2313 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002314
2315 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002316 adapter->need_fw_reset = 1;
2317 else
Sony Chacko79788452012-12-04 03:33:53 +00002318 adapter->ahw->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002319}
2320
2321static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2322{
2323 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2324 struct net_device_stats *stats = &netdev->stats;
2325
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002326 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2327 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002328 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002329 stats->tx_bytes = adapter->stats.txbytes;
2330 stats->rx_dropped = adapter->stats.rxdropped;
2331 stats->tx_dropped = adapter->stats.txdropped;
2332
2333 return stats;
2334}
2335
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002336irqreturn_t qlcnic_82xx_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002337{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002338 u32 status;
2339
2340 status = readl(adapter->isr_int_vec);
2341
Sony Chacko79788452012-12-04 03:33:53 +00002342 if (!(status & adapter->ahw->int_vec_bit))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002343 return IRQ_NONE;
2344
2345 /* check interrupt state machine, to be sure */
2346 status = readl(adapter->crb_int_state_reg);
2347 if (!ISR_LEGACY_INT_TRIGGERED(status))
2348 return IRQ_NONE;
2349
2350 writel(0xffffffff, adapter->tgt_status_reg);
2351 /* read twice to ensure write is flushed */
2352 readl(adapter->isr_int_vec);
2353 readl(adapter->isr_int_vec);
2354
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002355 return IRQ_HANDLED;
2356}
2357
2358static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2359{
2360 struct qlcnic_host_sds_ring *sds_ring = data;
2361 struct qlcnic_adapter *adapter = sds_ring->adapter;
2362
2363 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2364 goto done;
2365 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2366 writel(0xffffffff, adapter->tgt_status_reg);
2367 goto done;
2368 }
2369
2370 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2371 return IRQ_NONE;
2372
2373done:
Sony Chacko79788452012-12-04 03:33:53 +00002374 adapter->ahw->diag_cnt++;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002375 qlcnic_enable_int(sds_ring);
2376 return IRQ_HANDLED;
2377}
2378
2379static irqreturn_t qlcnic_intr(int irq, void *data)
2380{
2381 struct qlcnic_host_sds_ring *sds_ring = data;
2382 struct qlcnic_adapter *adapter = sds_ring->adapter;
2383
2384 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2385 return IRQ_NONE;
2386
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002387 napi_schedule(&sds_ring->napi);
2388
2389 return IRQ_HANDLED;
2390}
2391
2392static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2393{
2394 struct qlcnic_host_sds_ring *sds_ring = data;
2395 struct qlcnic_adapter *adapter = sds_ring->adapter;
2396
2397 /* clear interrupt */
2398 writel(0xffffffff, adapter->tgt_status_reg);
2399
2400 napi_schedule(&sds_ring->napi);
2401 return IRQ_HANDLED;
2402}
2403
2404static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2405{
2406 struct qlcnic_host_sds_ring *sds_ring = data;
2407
2408 napi_schedule(&sds_ring->napi);
2409 return IRQ_HANDLED;
2410}
2411
Sony Chacko13159182013-01-01 03:20:21 +00002412static irqreturn_t qlcnic_msix_tx_intr(int irq, void *data)
2413{
2414 struct qlcnic_host_tx_ring *tx_ring = data;
2415
2416 napi_schedule(&tx_ring->napi);
2417 return IRQ_HANDLED;
2418}
2419
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002420#ifdef CONFIG_NET_POLL_CONTROLLER
2421static void qlcnic_poll_controller(struct net_device *netdev)
2422{
Yinglin Luanbf827912010-08-22 21:57:56 +00002423 int ring;
2424 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002425 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00002426 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00002427
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002428 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002429 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2430 sds_ring = &recv_ctx->sds_rings[ring];
2431 qlcnic_intr(adapter->irq, sds_ring);
2432 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002433 enable_irq(adapter->irq);
2434}
2435#endif
2436
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002437static void
2438qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2439{
2440 u32 val;
2441
2442 val = adapter->portnum & 0xf;
2443 val |= encoding << 7;
2444 val |= (jiffies - adapter->dev_rst_time) << 8;
2445
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002446 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002447 adapter->dev_rst_time = jiffies;
2448}
2449
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002450static int
2451qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002452{
2453 u32 val;
2454
2455 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2456 state != QLCNIC_DEV_NEED_QUISCENT);
2457
2458 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002459 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002460
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002461 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002462
2463 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002464 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002465 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002466 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002467
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002468 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002469
2470 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002471
2472 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002473}
2474
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002475static int
2476qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2477{
2478 u32 val;
2479
2480 if (qlcnic_api_lock(adapter))
2481 return -EBUSY;
2482
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002483 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002484 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002485 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002486
2487 qlcnic_api_unlock(adapter);
2488
2489 return 0;
2490}
2491
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002492static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002493qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002494{
2495 u32 val;
2496
2497 if (qlcnic_api_lock(adapter))
2498 goto err;
2499
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002500 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002501 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002502 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002503
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002504 if (failed) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002505 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2506 QLCNIC_DEV_FAILED);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002507 dev_info(&adapter->pdev->dev,
2508 "Device state set to Failed. Please Reboot\n");
2509 } else if (!(val & 0x11111111))
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002510 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2511 QLCNIC_DEV_COLD);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002512
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002513 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002514 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002515 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002516
2517 qlcnic_api_unlock(adapter);
2518err:
2519 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002520 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002521 clear_bit(__QLCNIC_START_FW, &adapter->state);
2522 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2523}
2524
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002525/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526static int
2527qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2528{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002529 int act, state, active_mask;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002530 struct qlcnic_hardware_context *ahw = adapter->ahw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002531
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002532 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
2533 act = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002534
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002535 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002536 active_mask = (~(1 << (ahw->pci_func * 4)));
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002537 act = act & active_mask;
2538 }
2539
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002540 if (((state & 0x11111111) == (act & 0x11111111)) ||
2541 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2542 return 0;
2543 else
2544 return 1;
2545}
2546
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002547static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2548{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002549 u32 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002550
2551 if (val != QLCNIC_DRV_IDC_VER) {
2552 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2553 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2554 }
2555
2556 return 0;
2557}
2558
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002559static int
2560qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2561{
2562 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002563 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002564 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002565 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002566
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002567 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2568 return 1;
2569
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002570 if (qlcnic_api_lock(adapter))
2571 return -1;
2572
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002573 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002574 if (!(val & (1 << (portnum * 4)))) {
2575 QLC_DEV_SET_REF_CNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002576 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002577 }
2578
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002579 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002580 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002581
2582 switch (prev_state) {
2583 case QLCNIC_DEV_COLD:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002584 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2585 QLCNIC_DEV_INITIALIZING);
2586 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_IDC_VER,
2587 QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002588 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002589 qlcnic_api_unlock(adapter);
2590 return 1;
2591
2592 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002593 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002594 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002595 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002596
2597 case QLCNIC_DEV_NEED_RESET:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002598 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002599 QLC_DEV_SET_RST_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002600 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002601 break;
2602
2603 case QLCNIC_DEV_NEED_QUISCENT:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002604 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002605 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002606 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002607 break;
2608
2609 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002610 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002611 qlcnic_api_unlock(adapter);
2612 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002613
2614 case QLCNIC_DEV_INITIALIZING:
2615 case QLCNIC_DEV_QUISCENT:
2616 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002617 }
2618
2619 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002620
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002621 do {
2622 msleep(1000);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002623 prev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002624
2625 if (prev_state == QLCNIC_DEV_QUISCENT)
2626 continue;
2627 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002628
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002629 if (!dev_init_timeo) {
2630 dev_err(&adapter->pdev->dev,
2631 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002632 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002633 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002634
2635 if (qlcnic_api_lock(adapter))
2636 return -1;
2637
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002638 val = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002639 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002640 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002641
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002642 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002643 qlcnic_api_unlock(adapter);
2644
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002645 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002646}
2647
2648static void
2649qlcnic_fwinit_work(struct work_struct *work)
2650{
2651 struct qlcnic_adapter *adapter = container_of(work,
2652 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002653 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002654 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002655
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002656 if (qlcnic_api_lock(adapter))
2657 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002658
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002659 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002660 if (dev_state == QLCNIC_DEV_QUISCENT ||
2661 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002662 qlcnic_api_unlock(adapter);
2663 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2664 FW_POLL_DELAY * 2);
2665 return;
2666 }
2667
Sony Chacko79788452012-12-04 03:33:53 +00002668 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002669 qlcnic_api_unlock(adapter);
2670 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002671 }
2672
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002673 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2674 dev_state == QLCNIC_DEV_READY) {
2675 dev_info(&adapter->pdev->dev, "Detected state change from "
2676 "DEV_NEED_RESET, skipping ack check\n");
2677 goto skip_ack_check;
2678 }
2679
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002680 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002681 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002682 adapter->reset_ack_timeo);
2683 goto skip_ack_check;
2684 }
2685
2686 if (!qlcnic_check_drv_state(adapter)) {
2687skip_ack_check:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002688 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002689
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002690 if (dev_state == QLCNIC_DEV_NEED_RESET) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002691 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2692 QLCNIC_DEV_INITIALIZING);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002693 set_bit(__QLCNIC_START_FW, &adapter->state);
2694 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002695 qlcnic_idc_debug_info(adapter, 0);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002696 val = QLC_SHARED_REG_RD32(adapter,
2697 QLCNIC_CRB_DRV_STATE);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002698 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002699 QLC_SHARED_REG_WR32(adapter,
2700 QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002701 }
2702
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002703 qlcnic_api_unlock(adapter);
2704
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002705 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002706 if (adapter->ahw->fw_dump.enable &&
2707 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002708 QLCDB(adapter, DRV, "Take FW dump\n");
2709 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002710 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002711 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002712 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002713
2714 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002715 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002716 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002717 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002718 return;
2719 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002720 goto err_ret;
2721 }
2722
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002723 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002724
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002725wait_npar:
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002726 dev_state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002727 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002728
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002729 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002730 case QLCNIC_DEV_READY:
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002731 if (!qlcnic_start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002732 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002733 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002734 return;
2735 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002736 case QLCNIC_DEV_FAILED:
2737 break;
2738 default:
2739 qlcnic_schedule_work(adapter,
2740 qlcnic_fwinit_work, FW_POLL_DELAY);
2741 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002742 }
2743
2744err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002745 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2746 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002747 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002748 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002749}
2750
2751static void
2752qlcnic_detach_work(struct work_struct *work)
2753{
2754 struct qlcnic_adapter *adapter = container_of(work,
2755 struct qlcnic_adapter, fw_work.work);
2756 struct net_device *netdev = adapter->netdev;
2757 u32 status;
2758
2759 netif_device_detach(netdev);
2760
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002761 /* Dont grab rtnl lock during Quiscent mode */
2762 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2763 if (netif_running(netdev))
2764 __qlcnic_down(adapter, netdev);
2765 } else
2766 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002767
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002768 status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002769
Sony Chacko44f65b22011-08-29 12:50:26 +00002770 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2771 dev_err(&adapter->pdev->dev,
2772 "Detaching the device: peg halt status1=0x%x\n",
2773 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002774
Sony Chacko44f65b22011-08-29 12:50:26 +00002775 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2776 dev_err(&adapter->pdev->dev,
2777 "On board active cooling fan failed. "
2778 "Device has been halted.\n");
2779 dev_err(&adapter->pdev->dev,
2780 "Replace the adapter.\n");
2781 }
2782
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002783 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002784 }
2785
Sony Chacko79788452012-12-04 03:33:53 +00002786 if (adapter->ahw->temp == QLCNIC_TEMP_PANIC) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002787 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
Sony Chacko79788452012-12-04 03:33:53 +00002788 adapter->ahw->temp);
Sony Chacko44f65b22011-08-29 12:50:26 +00002789 goto err_ret;
2790 }
2791
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002792 /* Dont ack if this instance is the reset owner */
2793 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002794 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2795 dev_err(&adapter->pdev->dev,
2796 "Failed to set driver state,"
2797 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002798 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002799 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002800 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002801
2802 adapter->fw_wait_cnt = 0;
2803
2804 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2805
2806 return;
2807
2808err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002809 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002810 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002811}
2812
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002813/*Transit NPAR state to NON Operational */
2814static void
2815qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2816{
2817 u32 state;
2818
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002819 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002820 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2821 return;
2822
2823 if (qlcnic_api_lock(adapter))
2824 return;
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002825 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2826 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002827 qlcnic_api_unlock(adapter);
2828}
2829
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002830void qlcnic_82xx_dev_request_reset(struct qlcnic_adapter *adapter, u32 key)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002831{
Sritej Velaga646779f2012-02-03 13:45:41 +00002832 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002833
Sritej Velaga646779f2012-02-03 13:45:41 +00002834 qlcnic_xg_set_xg0_mask(xg_val);
2835 qlcnic_xg_set_xg1_mask(xg_val);
2836 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2837 qlcnic_gb_set_gb0_mask(gb_val);
2838 qlcnic_gb_set_gb1_mask(gb_val);
2839 qlcnic_gb_set_gb2_mask(gb_val);
2840 qlcnic_gb_set_gb3_mask(gb_val);
2841 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2842 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2843 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002844 adapter->need_fw_reset = 1;
Sony Chacko13159182013-01-01 03:20:21 +00002845
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002846 if (qlcnic_api_lock(adapter))
2847 return;
2848
Sony Chacko13159182013-01-01 03:20:21 +00002849 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002850
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002851 if (state == QLCNIC_DEV_READY) {
Sony Chacko13159182013-01-01 03:20:21 +00002852 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
2853 QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002854 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002855 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002856 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002857 }
2858
Sony Chacko13159182013-01-01 03:20:21 +00002859 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2860 QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002861 qlcnic_api_unlock(adapter);
2862}
2863
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002864/* Transit to NPAR READY state from NPAR NOT READY state */
2865static void
2866qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2867{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002868 if (qlcnic_api_lock(adapter))
2869 return;
2870
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002871 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2872 QLCNIC_DEV_NPAR_OPER);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002873 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002874
2875 qlcnic_api_unlock(adapter);
2876}
2877
Sony Chacko13159182013-01-01 03:20:21 +00002878void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2879 work_func_t func, int delay)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002880{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002881 if (test_bit(__QLCNIC_AER, &adapter->state))
2882 return;
2883
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002884 INIT_DELAYED_WORK(&adapter->fw_work, func);
Sony Chacko13159182013-01-01 03:20:21 +00002885 queue_delayed_work(adapter->qlcnic_wq, &adapter->fw_work,
2886 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002887}
2888
2889static void
2890qlcnic_attach_work(struct work_struct *work)
2891{
2892 struct qlcnic_adapter *adapter = container_of(work,
2893 struct qlcnic_adapter, fw_work.work);
2894 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002895 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002896
Sony Chacko79788452012-12-04 03:33:53 +00002897 if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) {
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002898 npar_state = QLC_SHARED_REG_RD32(adapter,
2899 QLCNIC_CRB_DEV_NPAR_STATE);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002900 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2901 qlcnic_clr_all_drv_state(adapter, 0);
2902 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2903 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2904 FW_POLL_DELAY);
2905 else
2906 goto attach;
2907 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2908 return;
2909 }
2910attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002911 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002912 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002913 goto done;
2914
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002915 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002916 }
2917
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002918done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002919 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002920 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002921 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002922 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002923
2924 if (!qlcnic_clr_drv_state(adapter))
2925 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2926 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002927}
2928
2929static int
2930qlcnic_check_health(struct qlcnic_adapter *adapter)
2931{
Sony Chacko4e708122010-08-31 17:17:44 +00002932 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002933 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002934
2935 if (qlcnic_check_temp(adapter))
2936 goto detach;
2937
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002938 if (adapter->need_fw_reset)
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002939 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002940
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002941 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002942 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002943 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002944 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002945 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2946 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002947
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002948 heartbeat = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
Sony Chacko4e708122010-08-31 17:17:44 +00002949 if (heartbeat != adapter->heartbeat) {
2950 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002951 adapter->fw_fail_cnt = 0;
2952 if (adapter->need_fw_reset)
2953 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002954
Sony Chacko099f7aa2012-12-04 03:33:58 +00002955 if (adapter->ahw->reset_context && qlcnic_auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002956 qlcnic_reset_hw_context(adapter);
2957 adapter->netdev->trans_start = jiffies;
2958 }
2959
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002960 return 0;
2961 }
2962
2963 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2964 return 0;
2965
Sritej Velaga032a13c2011-07-29 13:30:27 +00002966 adapter->flags |= QLCNIC_FW_HANG;
2967
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00002968 qlcnic_dev_request_reset(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002969
Sony Chacko099f7aa2012-12-04 03:33:58 +00002970 if (qlcnic_auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002971 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002972
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002973 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002974 peg_status = QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002975 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00002976 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2977 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2978 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2979 "PEG_NET_4_PC: 0x%x\n",
Himanshu Madhania15ebd32013-01-01 03:20:18 +00002980 peg_status,
2981 QLC_SHARED_REG_RD32(adapter, QLCNIC_PEG_HALT_STATUS2),
Sritej Velagac76ecb72011-07-29 13:30:29 +00002982 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
2983 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
2984 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
2985 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
2986 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Sritej Velaga97048a12012-02-03 13:45:43 +00002987 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002988 dev_err(&adapter->pdev->dev,
2989 "Firmware aborted with error code 0x00006700. "
2990 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002991detach:
2992 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
2993 QLCNIC_DEV_NEED_RESET;
2994
Sony Chacko099f7aa2012-12-04 03:33:58 +00002995 if (qlcnic_auto_fw_reset && !test_and_set_bit(__QLCNIC_RESETTING,
2996 &adapter->state)) {
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002997
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002998 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002999 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3000 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003001
3002 return 1;
3003}
3004
3005static void
3006qlcnic_fw_poll_work(struct work_struct *work)
3007{
3008 struct qlcnic_adapter *adapter = container_of(work,
3009 struct qlcnic_adapter, fw_work.work);
3010
3011 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3012 goto reschedule;
3013
3014
3015 if (qlcnic_check_health(adapter))
3016 return;
3017
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003018 if (adapter->fhash.fnum)
3019 qlcnic_prune_lb_filters(adapter);
3020
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003021reschedule:
3022 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3023}
3024
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003025static int qlcnic_is_first_func(struct pci_dev *pdev)
3026{
3027 struct pci_dev *oth_pdev;
3028 int val = pdev->devfn;
3029
3030 while (val-- > 0) {
3031 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3032 (pdev->bus), pdev->bus->number,
3033 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003034 if (!oth_pdev)
3035 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003036
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003037 if (oth_pdev->current_state != PCI_D3cold) {
3038 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003039 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003040 }
3041 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003042 }
3043 return 1;
3044}
3045
3046static int qlcnic_attach_func(struct pci_dev *pdev)
3047{
3048 int err, first_func;
3049 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3050 struct net_device *netdev = adapter->netdev;
3051
3052 pdev->error_state = pci_channel_io_normal;
3053
3054 err = pci_enable_device(pdev);
3055 if (err)
3056 return err;
3057
3058 pci_set_power_state(pdev, PCI_D0);
3059 pci_set_master(pdev);
3060 pci_restore_state(pdev);
3061
3062 first_func = qlcnic_is_first_func(pdev);
3063
3064 if (qlcnic_api_lock(adapter))
3065 return -EINVAL;
3066
Sony Chacko79788452012-12-04 03:33:53 +00003067 if (adapter->ahw->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003068 adapter->need_fw_reset = 1;
3069 set_bit(__QLCNIC_START_FW, &adapter->state);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003070 QLC_SHARED_REG_WR32(adapter, QLCNIC_CRB_DEV_STATE,
3071 QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003072 QLCDB(adapter, DRV, "Restarting fw\n");
3073 }
3074 qlcnic_api_unlock(adapter);
3075
Sony Chacko13159182013-01-01 03:20:21 +00003076 err = qlcnic_start_firmware(adapter);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003077 if (err)
3078 return err;
3079
3080 qlcnic_clr_drv_state(adapter);
Sony Chacko13159182013-01-01 03:20:21 +00003081 kfree(adapter->msix_entries);
3082 adapter->msix_entries = NULL;
3083 err = qlcnic_setup_intr(adapter, 0);
3084
Manish chopra9a97e702013-01-25 10:20:37 +00003085 if (err) {
3086 kfree(adapter->msix_entries);
3087 netdev_err(netdev, "failed to setup interrupt\n");
3088 return err;
3089 }
3090
Sony Chacko13159182013-01-01 03:20:21 +00003091 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003092 /* register for NIC IDC AEN Events */
3093 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003094 err = qlcnic_83xx_setup_mbx_intr(adapter);
3095 if (err) {
3096 dev_err(&adapter->pdev->dev,
3097 "failed to setup mbx interrupt\n");
3098 qlcnic_clr_all_drv_state(adapter, 1);
3099 clear_bit(__QLCNIC_AER, &adapter->state);
3100 goto done;
3101 }
3102 }
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003103
3104 if (netif_running(netdev)) {
3105 err = qlcnic_attach(adapter);
3106 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003107 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003108 clear_bit(__QLCNIC_AER, &adapter->state);
3109 netif_device_attach(netdev);
3110 return err;
3111 }
3112
3113 err = qlcnic_up(adapter, netdev);
3114 if (err)
3115 goto done;
3116
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003117 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003118 }
3119 done:
3120 netif_device_attach(netdev);
3121 return err;
3122}
3123
3124static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3125 pci_channel_state_t state)
3126{
3127 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3128 struct net_device *netdev = adapter->netdev;
3129
3130 if (state == pci_channel_io_perm_failure)
3131 return PCI_ERS_RESULT_DISCONNECT;
3132
3133 if (state == pci_channel_io_normal)
3134 return PCI_ERS_RESULT_RECOVERED;
3135
3136 set_bit(__QLCNIC_AER, &adapter->state);
3137 netif_device_detach(netdev);
3138
3139 cancel_delayed_work_sync(&adapter->fw_work);
3140
3141 if (netif_running(netdev))
3142 qlcnic_down(adapter, netdev);
3143
Sony Chacko13159182013-01-01 03:20:21 +00003144 if (qlcnic_83xx_check(adapter)) {
Sony Chacko13159182013-01-01 03:20:21 +00003145 qlcnic_83xx_free_mbx_intr(adapter);
Jitendra Kalsaria3d73b5f2013-02-09 09:29:49 +00003146 qlcnic_83xx_register_nic_idc_func(adapter, 0);
3147 cancel_delayed_work_sync(&adapter->idc_aen_work);
Sony Chacko13159182013-01-01 03:20:21 +00003148 }
3149
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003150 qlcnic_detach(adapter);
3151 qlcnic_teardown_intr(adapter);
3152
3153 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3154
3155 pci_save_state(pdev);
3156 pci_disable_device(pdev);
3157
3158 return PCI_ERS_RESULT_NEED_RESET;
3159}
3160
3161static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3162{
3163 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3164 PCI_ERS_RESULT_RECOVERED;
3165}
3166
3167static void qlcnic_io_resume(struct pci_dev *pdev)
3168{
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003169 u32 state;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003170 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3171
3172 pci_cleanup_aer_uncorrect_error_status(pdev);
Himanshu Madhania15ebd32013-01-01 03:20:18 +00003173 state = QLC_SHARED_REG_RD32(adapter, QLCNIC_CRB_DEV_STATE);
3174 if (state == QLCNIC_DEV_READY && test_and_clear_bit(__QLCNIC_AER,
3175 &adapter->state))
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003176 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3177 FW_POLL_DELAY);
3178}
3179
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003180static int
3181qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3182{
3183 int err;
3184
3185 err = qlcnic_can_start_firmware(adapter);
3186 if (err)
3187 return err;
3188
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003189 err = qlcnic_check_npar_opertional(adapter);
3190 if (err)
3191 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003192
Rajesh Borundia174240a2010-08-31 17:17:47 +00003193 err = qlcnic_initialize_nic(adapter);
3194 if (err)
3195 return err;
3196
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003197 qlcnic_check_options(adapter);
3198
Rajesh Borundia73733732010-08-31 17:17:50 +00003199 err = qlcnic_set_eswitch_port_config(adapter);
3200 if (err)
3201 return err;
3202
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003203 adapter->need_fw_reset = 0;
3204
3205 return err;
3206}
3207
Sony Chacko319ecf12013-01-01 03:20:22 +00003208int qlcnic_validate_max_rss(u8 max_hw, u8 val)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003209{
Sony Chacko319ecf12013-01-01 03:20:22 +00003210 u32 max_allowed;
3211
3212 if (max_hw > QLC_MAX_SDS_RINGS) {
3213 max_hw = QLC_MAX_SDS_RINGS;
3214 pr_info("max rss reset to %d\n", QLC_MAX_SDS_RINGS);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003215 }
3216
Sony Chacko319ecf12013-01-01 03:20:22 +00003217 max_allowed = rounddown_pow_of_two(min_t(int, max_hw,
3218 num_online_cpus()));
3219 if ((val > max_allowed) || (val < 2) || !is_power_of_2(val)) {
3220 pr_info("rss_ring valid range [2 - %x] in powers of 2\n",
3221 max_allowed);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003222 return -EINVAL;
3223 }
3224 return 0;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003225}
3226
Sony Chacko319ecf12013-01-01 03:20:22 +00003227int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data, size_t len)
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003228{
Sony Chacko13159182013-01-01 03:20:21 +00003229 int err;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003230 struct net_device *netdev = adapter->netdev;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003231
Sony Chacko319ecf12013-01-01 03:20:22 +00003232 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3233 return -EBUSY;
3234
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003235 netif_device_detach(netdev);
3236 if (netif_running(netdev))
3237 __qlcnic_down(adapter, netdev);
Sony Chacko13159182013-01-01 03:20:21 +00003238
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003239 qlcnic_detach(adapter);
Sucheta Chakraborty7dd90cf2013-02-18 12:06:14 +00003240
3241 if (qlcnic_83xx_check(adapter))
3242 qlcnic_83xx_free_mbx_intr(adapter);
3243
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003244 qlcnic_teardown_intr(adapter);
Sony Chacko319ecf12013-01-01 03:20:22 +00003245 err = qlcnic_setup_intr(adapter, data);
Manish chopra9a97e702013-01-25 10:20:37 +00003246 if (err) {
3247 kfree(adapter->msix_entries);
3248 netdev_err(netdev, "failed to setup interrupt\n");
3249 return err;
3250 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003251
Sony Chacko13159182013-01-01 03:20:21 +00003252 if (qlcnic_83xx_check(adapter)) {
Himanshu Madhanid5fcff02013-02-09 09:29:48 +00003253 /* register for NIC IDC AEN Events */
3254 qlcnic_83xx_register_nic_idc_func(adapter, 1);
Sony Chacko13159182013-01-01 03:20:21 +00003255 err = qlcnic_83xx_setup_mbx_intr(adapter);
3256 if (err) {
3257 dev_err(&adapter->pdev->dev,
3258 "failed to setup mbx interrupt\n");
3259 goto done;
3260 }
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003261 }
3262
3263 if (netif_running(netdev)) {
3264 err = qlcnic_attach(adapter);
3265 if (err)
3266 goto done;
3267 err = __qlcnic_up(adapter, netdev);
3268 if (err)
3269 goto done;
3270 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3271 }
Sony Chacko319ecf12013-01-01 03:20:22 +00003272 err = len;
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00003273 done:
3274 netif_device_attach(netdev);
3275 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3276 return err;
3277}
3278
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003279#ifdef CONFIG_INET
3280
3281#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3282
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003283static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003284qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
3285 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003286{
3287 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003288
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003289 indev = in_dev_get(dev);
3290 if (!indev)
3291 return;
3292
3293 for_ifa(indev) {
3294 switch (event) {
3295 case NETDEV_UP:
3296 qlcnic_config_ipaddr(adapter,
3297 ifa->ifa_address, QLCNIC_IP_UP);
3298 break;
3299 case NETDEV_DOWN:
3300 qlcnic_config_ipaddr(adapter,
3301 ifa->ifa_address, QLCNIC_IP_DOWN);
3302 break;
3303 default:
3304 break;
3305 }
3306 } endfor_ifa(indev);
3307
3308 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003309}
3310
Sony Chacko319ecf12013-01-01 03:20:22 +00003311void qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003312{
3313 struct qlcnic_adapter *adapter = netdev_priv(netdev);
3314 struct net_device *dev;
3315 u16 vid;
3316
3317 qlcnic_config_indev_addr(adapter, netdev, event);
3318
Jiri Pirko43c00a72013-01-03 22:48:57 +00003319 rcu_read_lock();
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00003320 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Jiri Pirko223bb152011-07-20 04:54:44 +00003321 dev = __vlan_find_dev_deep(netdev, vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003322 if (!dev)
3323 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003324 qlcnic_config_indev_addr(adapter, dev, event);
3325 }
Jiri Pirko43c00a72013-01-03 22:48:57 +00003326 rcu_read_unlock();
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003327}
3328
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003329static int qlcnic_netdev_event(struct notifier_block *this,
3330 unsigned long event, void *ptr)
3331{
3332 struct qlcnic_adapter *adapter;
3333 struct net_device *dev = (struct net_device *)ptr;
3334
3335recheck:
3336 if (dev == NULL)
3337 goto done;
3338
3339 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3340 dev = vlan_dev_real_dev(dev);
3341 goto recheck;
3342 }
3343
3344 if (!is_qlcnic_netdev(dev))
3345 goto done;
3346
3347 adapter = netdev_priv(dev);
3348
3349 if (!adapter)
3350 goto done;
3351
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003352 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003353 goto done;
3354
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003355 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003356done:
3357 return NOTIFY_DONE;
3358}
3359
3360static int
3361qlcnic_inetaddr_event(struct notifier_block *this,
3362 unsigned long event, void *ptr)
3363{
3364 struct qlcnic_adapter *adapter;
3365 struct net_device *dev;
3366
3367 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3368
3369 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3370
3371recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003372 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003373 goto done;
3374
3375 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3376 dev = vlan_dev_real_dev(dev);
3377 goto recheck;
3378 }
3379
3380 if (!is_qlcnic_netdev(dev))
3381 goto done;
3382
3383 adapter = netdev_priv(dev);
3384
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00003385 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003386 goto done;
3387
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003388 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003389 goto done;
3390
3391 switch (event) {
3392 case NETDEV_UP:
3393 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
Sony Chacko13159182013-01-01 03:20:21 +00003394
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003395 break;
3396 case NETDEV_DOWN:
3397 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
Sony Chacko13159182013-01-01 03:20:21 +00003398
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003399 break;
3400 default:
3401 break;
3402 }
3403
3404done:
3405 return NOTIFY_DONE;
3406}
3407
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003408static struct notifier_block qlcnic_netdev_cb = {
3409 .notifier_call = qlcnic_netdev_event,
3410};
3411
3412static struct notifier_block qlcnic_inetaddr_cb = {
3413 .notifier_call = qlcnic_inetaddr_event,
3414};
3415#else
Sony Chackof8ca2b62013-01-02 23:10:15 +00003416void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003417{ }
3418#endif
Stephen Hemmingerfec9dd12013-01-30 12:47:18 +00003419static const struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003420 .error_detected = qlcnic_io_error_detected,
3421 .slot_reset = qlcnic_io_slot_reset,
3422 .resume = qlcnic_io_resume,
3423};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003424
3425static struct pci_driver qlcnic_driver = {
3426 .name = qlcnic_driver_name,
3427 .id_table = qlcnic_pci_tbl,
3428 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05003429 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003430#ifdef CONFIG_PM
3431 .suspend = qlcnic_suspend,
3432 .resume = qlcnic_resume,
3433#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003434 .shutdown = qlcnic_shutdown,
3435 .err_handler = &qlcnic_err_handler
3436
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003437};
3438
3439static int __init qlcnic_init_module(void)
3440{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003441 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003442
3443 printk(KERN_INFO "%s\n", qlcnic_driver_string);
3444
3445#ifdef CONFIG_INET
3446 register_netdevice_notifier(&qlcnic_netdev_cb);
3447 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
3448#endif
3449
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003450 ret = pci_register_driver(&qlcnic_driver);
3451 if (ret) {
3452#ifdef CONFIG_INET
3453 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3454 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3455#endif
3456 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003457
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00003458 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003459}
3460
3461module_init(qlcnic_init_module);
3462
3463static void __exit qlcnic_exit_module(void)
3464{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003465 pci_unregister_driver(&qlcnic_driver);
3466
3467#ifdef CONFIG_INET
3468 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
3469 unregister_netdevice_notifier(&qlcnic_netdev_cb);
3470#endif
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003471}
3472
3473module_exit(qlcnic_exit_module);