blob: 0110db1d0a346da4423abbbb8e3b4f4bde1b0d6c [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
Sritej Velaga40839129f2010-12-02 20:41:56 +00002 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 QLogic Corporation
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004 *
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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00009#include <linux/vmalloc.h>
10#include <linux/interrupt.h>
11
12#include "qlcnic.h"
13
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>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000016#include <net/ip.h>
17#include <linux/ipv6.h>
18#include <linux/inetdevice.h>
19#include <linux/sysfs.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>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000022
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000023MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000024MODULE_LICENSE("GPL");
25MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
26MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
27
28char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000029static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
30 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000031
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +000032static struct workqueue_struct *qlcnic_wq;
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);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000035MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
36
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000037static int use_msi = 1;
amit salechab11a25a2011-01-10 00:15:23 +000038module_param(use_msi, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000039MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
40
41static int use_msi_x = 1;
amit salechab11a25a2011-01-10 00:15:23 +000042module_param(use_msi_x, int, 0444);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000043MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
44
amit salecha9ce13ca2011-02-23 03:21:24 +000045static int auto_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000046module_param(auto_fw_reset, int, 0644);
47MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
48
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000049static int load_fw_file;
amit salechab11a25a2011-01-10 00:15:23 +000050module_param(load_fw_file, int, 0444);
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000051MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
52
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000053static int qlcnic_config_npars;
amit salechab11a25a2011-01-10 00:15:23 +000054module_param(qlcnic_config_npars, int, 0444);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000055MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
56
Bill Pemberton6bb58bb2012-12-03 09:23:25 -050057static int qlcnic_probe(struct pci_dev *pdev,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000058 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);
66static void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
67 work_func_t func, int delay);
68static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000069#ifdef CONFIG_NET_POLL_CONTROLLER
70static void qlcnic_poll_controller(struct net_device *netdev);
71#endif
72
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000073static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000074static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000075static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
76
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +000077static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000078static irqreturn_t qlcnic_intr(int irq, void *data);
79static irqreturn_t qlcnic_msi_intr(int irq, void *data);
80static irqreturn_t qlcnic_msix_intr(int irq, void *data);
81
82static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +000083static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000084static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000085
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000086static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000087static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +000088static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Rajesh Borundia0325d692010-08-19 05:08:26 +000089static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
90 struct qlcnic_esw_func_cfg *);
Jiri Pirko8e586132011-12-08 19:52:37 -050091static int qlcnic_vlan_rx_add(struct net_device *, u16);
92static int qlcnic_vlan_rx_del(struct net_device *, u16);
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +000093
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000094/* PCI Device ID Table */
95#define ENTRY(device) \
96 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
97 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
98
99#define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
100
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000101static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000102 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
103 {0,}
104};
105
106MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
107
108
Sony Chacko5ad6ff92012-11-17 21:04:38 +0000109inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000110{
111 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000112}
113
114static const u32 msi_tgt_status[8] = {
115 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
116 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
117 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
118 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
119};
120
121static const
122struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
123
Sony Chackoc70001a2012-11-28 04:34:26 +0000124int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000125{
126 int size = sizeof(struct qlcnic_host_sds_ring) * count;
127
128 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
129
Eric Dumazet807540b2010-09-23 05:40:09 +0000130 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000131}
132
Sony Chackoc70001a2012-11-28 04:34:26 +0000133void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000134{
135 if (recv_ctx->sds_rings != NULL)
136 kfree(recv_ctx->sds_rings);
137
138 recv_ctx->sds_rings = NULL;
139}
140
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000141static void qlcnic_clear_stats(struct qlcnic_adapter *adapter)
142{
143 memset(&adapter->stats, 0, sizeof(adapter->stats));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000144}
145
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000146static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable)
147{
148 u32 control;
149 int pos;
150
151 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
152 if (pos) {
153 pci_read_config_dword(pdev, pos, &control);
154 if (enable)
155 control |= PCI_MSIX_FLAGS_ENABLE;
156 else
157 control = 0;
158 pci_write_config_dword(pdev, pos, control);
159 }
160}
161
162static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count)
163{
164 int i;
165
166 for (i = 0; i < count; i++)
167 adapter->msix_entries[i].entry = i;
168}
169
170static int
171qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
172{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000173 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000174 struct net_device *netdev = adapter->netdev;
175 struct pci_dev *pdev = adapter->pdev;
176
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000177 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000178 return -EIO;
179
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000180 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000181 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
182 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
183
184 /* set station address */
185
186 if (!is_valid_ether_addr(netdev->perm_addr))
187 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
188 netdev->dev_addr);
189
190 return 0;
191}
192
193static int qlcnic_set_mac(struct net_device *netdev, void *p)
194{
195 struct qlcnic_adapter *adapter = netdev_priv(netdev);
196 struct sockaddr *addr = p;
197
Rajesh Borundia73733732010-08-31 17:17:50 +0000198 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
199 return -EOPNOTSUPP;
200
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000201 if (!is_valid_ether_addr(addr->sa_data))
Danny Kukawka504f9b52012-02-21 02:07:49 +0000202 return -EADDRNOTAVAIL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000203
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000204 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000205 netif_device_detach(netdev);
206 qlcnic_napi_disable(adapter);
207 }
208
209 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
210 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
211 qlcnic_set_multi(adapter->netdev);
212
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000213 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000214 netif_device_attach(netdev);
215 qlcnic_napi_enable(adapter);
216 }
217 return 0;
218}
219
220static const struct net_device_ops qlcnic_netdev_ops = {
221 .ndo_open = qlcnic_open,
222 .ndo_stop = qlcnic_close,
223 .ndo_start_xmit = qlcnic_xmit_frame,
224 .ndo_get_stats = qlcnic_get_stats,
225 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000226 .ndo_set_rx_mode = qlcnic_set_multi,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000227 .ndo_set_mac_address = qlcnic_set_mac,
228 .ndo_change_mtu = qlcnic_change_mtu,
Michał Mirosław135d84a2011-04-19 03:03:57 +0000229 .ndo_fix_features = qlcnic_fix_features,
230 .ndo_set_features = qlcnic_set_features,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000231 .ndo_tx_timeout = qlcnic_tx_timeout,
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000232 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
233 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000234#ifdef CONFIG_NET_POLL_CONTROLLER
235 .ndo_poll_controller = qlcnic_poll_controller,
236#endif
237};
238
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +0000239static const struct net_device_ops qlcnic_netdev_failed_ops = {
240 .ndo_open = qlcnic_open,
241};
242
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000243static struct qlcnic_nic_template qlcnic_ops = {
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000244 .config_bridged_mode = qlcnic_config_bridged_mode,
245 .config_led = qlcnic_config_led,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000246 .start_firmware = qlcnic_start_firmware
247};
248
249static struct qlcnic_nic_template qlcnic_vf_ops = {
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000250 .config_bridged_mode = qlcnicvf_config_bridged_mode,
251 .config_led = qlcnicvf_config_led,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000252 .start_firmware = qlcnicvf_start_firmware
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000253};
254
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000255static int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
256{
257 struct pci_dev *pdev = adapter->pdev;
258 int err = -1;
259
260 adapter->max_sds_rings = 1;
261 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
262 qlcnic_set_msix_bit(pdev, 0);
263
264 if (adapter->msix_supported) {
265 enable_msix:
266 qlcnic_init_msix_entries(adapter, num_msix);
267 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
268 if (err == 0) {
269 adapter->flags |= QLCNIC_MSIX_ENABLED;
270 qlcnic_set_msix_bit(pdev, 1);
271
272 adapter->max_sds_rings = num_msix;
273
274 dev_info(&pdev->dev, "using msi-x interrupts\n");
275 return err;
276 }
277 if (err > 0) {
278 num_msix = rounddown_pow_of_two(err);
279 if (num_msix)
280 goto enable_msix;
281 }
282 }
283 return err;
284}
285
286
287static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000288{
289 const struct qlcnic_legacy_intr_set *legacy_intrp;
290 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000291
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000292 if (use_msi && !pci_enable_msi(pdev)) {
293 adapter->flags |= QLCNIC_MSI_ENABLED;
294 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
295 msi_tgt_status[adapter->ahw->pci_func]);
296 dev_info(&pdev->dev, "using msi interrupts\n");
297 adapter->msix_entries[0].vector = pdev->irq;
298 return;
299 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000300
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000301 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000302
303 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
304 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
305 legacy_intrp->tgt_status_reg);
306 adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter,
307 legacy_intrp->tgt_mask_reg);
308 adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR);
309
310 adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter,
311 ISR_INT_STATE_REG);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000312 dev_info(&pdev->dev, "using legacy interrupts\n");
313 adapter->msix_entries[0].vector = pdev->irq;
314}
315
316static void
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000317qlcnic_setup_intr(struct qlcnic_adapter *adapter)
318{
319 int num_msix;
320
321 if (adapter->msix_supported) {
Sucheta Chakraborty5f6ec292011-06-22 02:52:20 +0000322 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
323 QLCNIC_DEF_NUM_STS_DESC_RINGS));
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +0000324 } else
325 num_msix = 1;
326
327 if (!qlcnic_enable_msix(adapter, num_msix))
328 return;
329
330 qlcnic_enable_msi_legacy(adapter);
331}
332
333static void
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000334qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
335{
336 if (adapter->flags & QLCNIC_MSIX_ENABLED)
337 pci_disable_msix(adapter->pdev);
338 if (adapter->flags & QLCNIC_MSI_ENABLED)
339 pci_disable_msi(adapter->pdev);
340}
341
342static void
343qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
344{
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000345 if (adapter->ahw->pci_base0 != NULL)
346 iounmap(adapter->ahw->pci_base0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000347}
348
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000349static int
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000350qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
351{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000352 struct qlcnic_pci_info *pci_info;
Julia Lawall900853a2010-08-16 10:23:51 +0000353 int i, ret = 0;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000354 u8 pfn;
355
Dan Carpentere88db3b2010-08-09 21:49:36 +0000356 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
357 if (!pci_info)
358 return -ENOMEM;
359
Dan Carpenterca315ac2010-08-09 21:47:56 +0000360 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000361 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000362 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000363 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000364 goto err_pci_info;
365 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000366
Dan Carpenterca315ac2010-08-09 21:47:56 +0000367 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000368 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
369 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000370 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000371 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000372 }
373
374 ret = qlcnic_get_pci_info(adapter, pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000375 if (ret)
376 goto err_eswitch;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000377
Dan Carpenterca315ac2010-08-09 21:47:56 +0000378 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
379 pfn = pci_info[i].id;
Dan Carpenter0f6efff92012-06-14 08:34:24 +0000380 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
Sony Chackof848d6d2011-04-01 14:27:59 +0000381 ret = QL_STATUS_INVALID_PARAM;
382 goto err_eswitch;
383 }
Sucheta Chakrabortya1c0c452010-10-04 04:20:14 +0000384 adapter->npars[pfn].active = (u8)pci_info[i].active;
385 adapter->npars[pfn].type = (u8)pci_info[i].type;
386 adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000387 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
388 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000389 }
390
Dan Carpenterca315ac2010-08-09 21:47:56 +0000391 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
392 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
393
Dan Carpentere88db3b2010-08-09 21:49:36 +0000394 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000395 return 0;
396
397err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000398 kfree(adapter->eswitch);
399 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000400err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000401 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000402 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000403err_pci_info:
404 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000405
406 return ret;
407}
408
409static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000410qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
411{
412 u8 id;
413 u32 ref_count;
414 int i, ret = 1;
415 u32 data = QLCNIC_MGMT_FUNC;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000416 void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000417
418 /* If other drivers are not in use set their privilege level */
Amit Kumar Salecha31018e02010-08-25 04:03:05 +0000419 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000420 ret = qlcnic_api_lock(adapter);
421 if (ret)
422 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000423
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000424 if (qlcnic_config_npars) {
425 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000426 id = i;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000427 if (adapter->npars[i].type != QLCNIC_TYPE_NIC ||
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000428 id == adapter->ahw->pci_func)
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000429 continue;
430 data |= (qlcnic_config_npars &
431 QLC_DEV_SET_DRV(0xf, id));
432 }
433 } else {
434 data = readl(priv_op);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000435 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) |
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000436 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000437 adapter->ahw->pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000438 }
439 writel(data, priv_op);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000440 qlcnic_api_unlock(adapter);
441err_lock:
442 return ret;
443}
444
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000445static void
446qlcnic_check_vf(struct qlcnic_adapter *adapter)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000447{
448 void __iomem *msix_base_addr;
449 void __iomem *priv_op;
450 u32 func;
451 u32 msix_base;
452 u32 op_mode, priv_level;
453
454 /* Determine FW API version */
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000455 adapter->fw_hal_version = readl(adapter->ahw->pci_base0 +
456 QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000457
458 /* Find PCI function number */
459 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000460 msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000461 msix_base = readl(msix_base_addr);
462 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000463 adapter->ahw->pci_func = func;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000464
465 /* Determine function privilege level */
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000466 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000467 op_mode = readl(priv_op);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000468 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000469 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000470 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000471 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000472
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000473 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000474 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
475 dev_info(&adapter->pdev->dev,
476 "HAL Version: %d Non Privileged function\n",
477 adapter->fw_hal_version);
478 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000479 } else
480 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000481}
482
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000483static int
484qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
485{
486 void __iomem *mem_ptr0 = NULL;
487 resource_size_t mem_base;
488 unsigned long mem_len, pci_len0 = 0;
489
490 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000491
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000492 /* remap phys address */
493 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
494 mem_len = pci_resource_len(pdev, 0);
495
496 if (mem_len == QLCNIC_PCI_2MB_SIZE) {
497
498 mem_ptr0 = pci_ioremap_bar(pdev, 0);
499 if (mem_ptr0 == NULL) {
500 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
501 return -EIO;
502 }
503 pci_len0 = mem_len;
504 } else {
505 return -EIO;
506 }
507
508 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
509
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000510 adapter->ahw->pci_base0 = mem_ptr0;
511 adapter->ahw->pci_len0 = pci_len0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000512
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000513 qlcnic_check_vf(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000514
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000515 adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter,
516 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(
517 adapter->ahw->pci_func)));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000518
519 return 0;
520}
521
522static void get_brd_name(struct qlcnic_adapter *adapter, char *name)
523{
524 struct pci_dev *pdev = adapter->pdev;
525 int i, found = 0;
526
527 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
528 if (qlcnic_boards[i].vendor == pdev->vendor &&
529 qlcnic_boards[i].device == pdev->device &&
530 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
531 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000532 sprintf(name, "%pM: %s" ,
533 adapter->mac_addr,
534 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000535 found = 1;
536 break;
537 }
538
539 }
540
541 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000542 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000543}
544
545static void
546qlcnic_check_options(struct qlcnic_adapter *adapter)
547{
Sritej Velaga031a4a22011-07-29 13:30:28 +0000548 u32 fw_major, fw_minor, fw_build, prev_fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000549 struct pci_dev *pdev = adapter->pdev;
Sritej Velaga031a4a22011-07-29 13:30:28 +0000550 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
551
552 prev_fw_version = adapter->fw_version;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000553
554 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
555 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
556 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
557
558 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
559
Sritej Velaga031a4a22011-07-29 13:30:28 +0000560 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC) {
561 if (fw_dump->tmpl_hdr == NULL ||
562 adapter->fw_version > prev_fw_version) {
563 if (fw_dump->tmpl_hdr)
564 vfree(fw_dump->tmpl_hdr);
565 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
566 dev_info(&pdev->dev,
567 "Supports FW dump capability\n");
568 }
569 }
570
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +0000571 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
572 fw_major, fw_minor, fw_build);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000573 if (adapter->ahw->port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000574 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
575 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
576 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
577 } else {
578 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
579 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
580 }
581
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000582 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000583 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
584
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000585 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000586 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
587 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000588 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
589 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000590 }
591
592 adapter->msix_supported = !!use_msi_x;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000593
594 adapter->num_txd = MAX_CMD_DESCRIPTORS;
595
Sony Chacko251b0362010-08-19 05:08:24 +0000596 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000597}
598
Rajesh Borundia174240a2010-08-31 17:17:47 +0000599static int
600qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
601{
602 int err;
603 struct qlcnic_info nic_info;
604
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000605 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
Rajesh Borundia174240a2010-08-31 17:17:47 +0000606 if (err)
607 return err;
608
Sucheta Chakrabortya1c0c452010-10-04 04:20:14 +0000609 adapter->physical_port = (u8)nic_info.phys_port;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000610 adapter->switch_mode = nic_info.switch_mode;
611 adapter->max_tx_ques = nic_info.max_tx_ques;
612 adapter->max_rx_ques = nic_info.max_rx_ques;
613 adapter->capabilities = nic_info.capabilities;
614 adapter->max_mac_filters = nic_info.max_mac_filters;
615 adapter->max_mtu = nic_info.max_mtu;
616
617 if (adapter->capabilities & BIT_6)
618 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
619 else
620 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
621
622 return err;
623}
624
Sony Chackoec079a02012-11-28 04:34:28 +0000625void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
626 struct qlcnic_esw_func_cfg *esw_cfg)
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000627{
628 if (esw_cfg->discard_tagged)
629 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
630 else
631 adapter->flags |= QLCNIC_TAGGING_ENABLED;
632
633 if (esw_cfg->vlan_id)
634 adapter->pvid = esw_cfg->vlan_id;
635 else
636 adapter->pvid = 0;
637}
638
Jiri Pirko8e586132011-12-08 19:52:37 -0500639static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000640qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid)
641{
642 struct qlcnic_adapter *adapter = netdev_priv(netdev);
643 set_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500644 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000645}
646
Jiri Pirko8e586132011-12-08 19:52:37 -0500647static int
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000648qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid)
649{
650 struct qlcnic_adapter *adapter = netdev_priv(netdev);
651
652 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
653 clear_bit(vid, adapter->vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -0500654 return 0;
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000655}
656
Sony Chackoec079a02012-11-28 04:34:28 +0000657void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
658 struct qlcnic_esw_func_cfg *esw_cfg)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000659{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000660 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
661 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000662
663 if (esw_cfg->mac_anti_spoof)
664 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000665
Rajesh Borundia73733732010-08-31 17:17:50 +0000666 if (!esw_cfg->mac_override)
667 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
668
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000669 if (!esw_cfg->promisc_mode)
670 adapter->flags |= QLCNIC_PROMISC_DISABLED;
671
Rajesh Borundia0325d692010-08-19 05:08:26 +0000672 qlcnic_set_netdev_features(adapter, esw_cfg);
673}
674
Sony Chackoec079a02012-11-28 04:34:28 +0000675static int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000676{
677 struct qlcnic_esw_func_cfg esw_cfg;
678
679 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
680 return 0;
681
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000682 esw_cfg.pci_func = adapter->ahw->pci_func;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000683 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
684 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000685 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000686 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
687
688 return 0;
689}
690
691static void
692qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
693 struct qlcnic_esw_func_cfg *esw_cfg)
694{
695 struct net_device *netdev = adapter->netdev;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000696 netdev_features_t features, vlan_features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000697
Michał Mirosław135d84a2011-04-19 03:03:57 +0000698 features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
Rajesh Borundia0325d692010-08-19 05:08:26 +0000699 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
700 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +0000701 NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000702
703 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
704 features |= (NETIF_F_TSO | NETIF_F_TSO6);
705 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
706 }
Rajesh Borundiab56421d2011-04-01 14:28:31 +0000707
708 if (netdev->features & NETIF_F_LRO)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000709 features |= NETIF_F_LRO;
710
711 if (esw_cfg->offload_flags & BIT_0) {
712 netdev->features |= features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000713 if (!(esw_cfg->offload_flags & BIT_1))
714 netdev->features &= ~NETIF_F_TSO;
715 if (!(esw_cfg->offload_flags & BIT_2))
716 netdev->features &= ~NETIF_F_TSO6;
717 } else {
718 netdev->features &= ~features;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000719 }
720
721 netdev->vlan_features = (features & vlan_features);
722}
723
724static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000725qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
726{
727 void __iomem *priv_op;
728 u32 op_mode, priv_level;
729 int err = 0;
730
Rajesh Borundia174240a2010-08-31 17:17:47 +0000731 err = qlcnic_initialize_nic(adapter);
732 if (err)
733 return err;
734
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000735 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
736 return 0;
737
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000738 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000739 op_mode = readl(priv_op);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000740 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000741
742 if (op_mode == QLC_DEV_DRV_DEFAULT)
743 priv_level = QLCNIC_MGMT_FUNC;
744 else
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000745 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000746
Rajesh Borundia174240a2010-08-31 17:17:47 +0000747 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000748 if (priv_level == QLCNIC_MGMT_FUNC) {
749 adapter->op_mode = QLCNIC_MGMT_FUNC;
750 err = qlcnic_init_pci_info(adapter);
751 if (err)
752 return err;
753 /* Set privilege level for other functions */
754 qlcnic_set_function_modes(adapter);
755 dev_info(&adapter->pdev->dev,
756 "HAL Version: %d, Management function\n",
757 adapter->fw_hal_version);
758 } else if (priv_level == QLCNIC_PRIV_FUNC) {
759 adapter->op_mode = QLCNIC_PRIV_FUNC;
760 dev_info(&adapter->pdev->dev,
761 "HAL Version: %d, Privileged function\n",
762 adapter->fw_hal_version);
763 }
Rajesh Borundia174240a2010-08-31 17:17:47 +0000764 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000765
766 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
767
768 return err;
769}
770
771static int
Rajesh Borundia0325d692010-08-19 05:08:26 +0000772qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
773{
774 struct qlcnic_esw_func_cfg esw_cfg;
775 struct qlcnic_npar_info *npar;
776 u8 i;
777
Rajesh Borundia174240a2010-08-31 17:17:47 +0000778 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000779 return 0;
780
781 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
782 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
783 continue;
784 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
785 esw_cfg.pci_func = i;
786 esw_cfg.offload_flags = BIT_0;
Rajesh Borundia73733732010-08-31 17:17:50 +0000787 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000788 esw_cfg.promisc_mode = BIT_0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000789 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
790 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
791 if (qlcnic_config_switch_port(adapter, &esw_cfg))
792 return -EIO;
793 npar = &adapter->npars[i];
794 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +0000795 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000796 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
797 npar->discard_tagged = esw_cfg.discard_tagged;
798 npar->promisc_mode = esw_cfg.promisc_mode;
799 npar->offload_flags = esw_cfg.offload_flags;
800 }
801
802 return 0;
803}
804
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000805static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000806qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
807 struct qlcnic_npar_info *npar, int pci_func)
808{
809 struct qlcnic_esw_func_cfg esw_cfg;
810 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
811 esw_cfg.pci_func = pci_func;
812 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +0000813 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000814 esw_cfg.discard_tagged = npar->discard_tagged;
815 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
816 esw_cfg.offload_flags = npar->offload_flags;
817 esw_cfg.promisc_mode = npar->promisc_mode;
818 if (qlcnic_config_switch_port(adapter, &esw_cfg))
819 return -EIO;
820
821 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
822 if (qlcnic_config_switch_port(adapter, &esw_cfg))
823 return -EIO;
824
825 return 0;
826}
827
828static int
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000829qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
830{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000831 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000832 struct qlcnic_npar_info *npar;
833 struct qlcnic_info nic_info;
834
Rajesh Borundia174240a2010-08-31 17:17:47 +0000835 if (!adapter->need_fw_reset)
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000836 return 0;
837
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000838 /* Set the NPAR config data after FW reset */
839 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
840 npar = &adapter->npars[i];
841 if (npar->type != QLCNIC_TYPE_NIC)
842 continue;
843 err = qlcnic_get_nic_info(adapter, &nic_info, i);
844 if (err)
845 return err;
846 nic_info.min_tx_bw = npar->min_bw;
847 nic_info.max_tx_bw = npar->max_bw;
848 err = qlcnic_set_nic_info(adapter, &nic_info);
849 if (err)
850 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000851
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000852 if (npar->enable_pm) {
853 err = qlcnic_config_port_mirroring(adapter,
854 npar->dest_npar, 1, i);
855 if (err)
856 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000857 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000858 err = qlcnic_reset_eswitch_config(adapter, npar, i);
859 if (err)
860 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000861 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000862 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000863}
864
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +0000865static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
866{
867 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
868 u32 npar_state;
869
870 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
871 return 0;
872
873 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
874 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
875 msleep(1000);
876 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
877 }
878 if (!npar_opt_timeo) {
879 dev_err(&adapter->pdev->dev,
880 "Waiting for NPAR state to opertional timeout\n");
881 return -EIO;
882 }
883 return 0;
884}
885
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000886static int
Rajesh Borundia174240a2010-08-31 17:17:47 +0000887qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
888{
889 int err;
890
891 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
892 adapter->op_mode != QLCNIC_MGMT_FUNC)
893 return 0;
894
895 err = qlcnic_set_default_offload_settings(adapter);
896 if (err)
897 return err;
898
899 err = qlcnic_reset_npar_config(adapter);
900 if (err)
901 return err;
902
903 qlcnic_dev_set_npar_ready(adapter);
904
905 return err;
906}
907
908static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000909qlcnic_start_firmware(struct qlcnic_adapter *adapter)
910{
Sony Chackod4066832010-08-19 05:08:31 +0000911 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000912
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +0000913 err = qlcnic_can_start_firmware(adapter);
914 if (err < 0)
915 return err;
916 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +0000917 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000918
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +0000919 if (load_fw_file)
920 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +0000921 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +0000922 err = qlcnic_check_flash_fw_ver(adapter);
923 if (err)
schacko8f891382010-06-17 02:56:40 +0000924 goto err_out;
925
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +0000926 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +0000927 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000928
929 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000930 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +0000931 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000932
Sony Chackod4066832010-08-19 05:08:31 +0000933 err = qlcnic_pinit_from_rom(adapter);
934 if (err)
935 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000936
937 err = qlcnic_load_firmware(adapter);
938 if (err)
939 goto err_out;
940
941 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +0000942 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000943
Sony Chackod4066832010-08-19 05:08:31 +0000944check_fw_status:
945 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000946 if (err)
947 goto err_out;
948
949 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +0000950 qlcnic_idc_debug_info(adapter, 1);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +0000951
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000952 err = qlcnic_check_eswitch_mode(adapter);
953 if (err) {
954 dev_err(&adapter->pdev->dev,
955 "Memory allocation failed for eswitch\n");
956 goto err_out;
957 }
Rajesh Borundia174240a2010-08-31 17:17:47 +0000958 err = qlcnic_set_mgmt_operations(adapter);
959 if (err)
960 goto err_out;
961
962 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000963 adapter->need_fw_reset = 0;
964
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +0000965 qlcnic_release_firmware(adapter);
966 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000967
968err_out:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +0000969 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
970 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000971
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000972 qlcnic_release_firmware(adapter);
973 return err;
974}
975
976static int
977qlcnic_request_irq(struct qlcnic_adapter *adapter)
978{
979 irq_handler_t handler;
980 struct qlcnic_host_sds_ring *sds_ring;
981 int err, ring;
982
983 unsigned long flags = 0;
984 struct net_device *netdev = adapter->netdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +0000985 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000986
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +0000987 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
988 handler = qlcnic_tmp_intr;
989 if (!QLCNIC_IS_MSI_FAMILY(adapter))
990 flags |= IRQF_SHARED;
991
992 } else {
993 if (adapter->flags & QLCNIC_MSIX_ENABLED)
994 handler = qlcnic_msix_intr;
995 else if (adapter->flags & QLCNIC_MSI_ENABLED)
996 handler = qlcnic_msi_intr;
997 else {
998 flags |= IRQF_SHARED;
999 handler = qlcnic_intr;
1000 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001001 }
1002 adapter->irq = netdev->irq;
1003
1004 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1005 sds_ring = &recv_ctx->sds_rings[ring];
1006 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1007 err = request_irq(sds_ring->irq, handler,
1008 flags, sds_ring->name, sds_ring);
1009 if (err)
1010 return err;
1011 }
1012
1013 return 0;
1014}
1015
1016static void
1017qlcnic_free_irq(struct qlcnic_adapter *adapter)
1018{
1019 int ring;
1020 struct qlcnic_host_sds_ring *sds_ring;
1021
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001022 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001023
1024 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1025 sds_ring = &recv_ctx->sds_rings[ring];
1026 free_irq(sds_ring->irq, sds_ring);
1027 }
1028}
1029
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001030static int
1031__qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1032{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001033 int ring;
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001034 u32 capab2;
1035
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001036 struct qlcnic_host_rds_ring *rds_ring;
1037
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001038 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1039 return -EIO;
1040
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001041 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1042 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001043 if (qlcnic_set_eswitch_port_config(adapter))
1044 return -EIO;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001045
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001046 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1047 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1048 if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1049 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1050 }
1051
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001052 if (qlcnic_fw_create_ctx(adapter))
1053 return -EIO;
1054
1055 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001056 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1057 qlcnic_post_rx_buffers(adapter, rds_ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001058 }
1059
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001060 qlcnic_set_multi(netdev);
1061 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1062
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001063 adapter->ahw->linkup = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001064
1065 if (adapter->max_sds_rings > 1)
1066 qlcnic_config_rss(adapter, 1);
1067
1068 qlcnic_config_intr_coalesce(adapter);
1069
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001070 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001071 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1072
1073 qlcnic_napi_enable(adapter);
1074
1075 qlcnic_linkevent_request(adapter, 1);
1076
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001077 adapter->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001078 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1079 return 0;
1080}
1081
1082/* Usage: During resume and firmware recovery module.*/
1083
1084static int
1085qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1086{
1087 int err = 0;
1088
1089 rtnl_lock();
1090 if (netif_running(netdev))
1091 err = __qlcnic_up(adapter, netdev);
1092 rtnl_unlock();
1093
1094 return err;
1095}
1096
1097static void
1098__qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1099{
1100 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1101 return;
1102
1103 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1104 return;
1105
1106 smp_mb();
1107 spin_lock(&adapter->tx_clean_lock);
1108 netif_carrier_off(netdev);
1109 netif_tx_disable(netdev);
1110
1111 qlcnic_free_mac_list(adapter);
1112
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001113 if (adapter->fhash.fnum)
1114 qlcnic_delete_lb_filters(adapter);
1115
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001116 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1117
1118 qlcnic_napi_disable(adapter);
1119
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001120 qlcnic_fw_destroy_ctx(adapter);
Rajesh Borundiacae82d42012-06-06 07:35:06 +00001121 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001122
1123 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001124 qlcnic_release_tx_buffers(adapter);
1125 spin_unlock(&adapter->tx_clean_lock);
1126}
1127
1128/* Usage: During suspend and firmware recovery module */
1129
1130static void
1131qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1132{
1133 rtnl_lock();
1134 if (netif_running(netdev))
1135 __qlcnic_down(adapter, netdev);
1136 rtnl_unlock();
1137
1138}
1139
1140static int
1141qlcnic_attach(struct qlcnic_adapter *adapter)
1142{
1143 struct net_device *netdev = adapter->netdev;
1144 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001145 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001146
1147 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1148 return 0;
1149
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001150 err = qlcnic_napi_add(adapter, netdev);
1151 if (err)
1152 return err;
1153
1154 err = qlcnic_alloc_sw_resources(adapter);
1155 if (err) {
1156 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001157 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001158 }
1159
1160 err = qlcnic_alloc_hw_resources(adapter);
1161 if (err) {
1162 dev_err(&pdev->dev, "Error in setting hw resources\n");
1163 goto err_out_free_sw;
1164 }
1165
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001166 err = qlcnic_request_irq(adapter);
1167 if (err) {
1168 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001169 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001170 }
1171
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001172 qlcnic_create_sysfs_entries(adapter);
1173
1174 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1175 return 0;
1176
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001177err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001178 qlcnic_free_hw_resources(adapter);
1179err_out_free_sw:
1180 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001181err_out_napi_del:
1182 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001183 return err;
1184}
1185
1186static void
1187qlcnic_detach(struct qlcnic_adapter *adapter)
1188{
1189 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1190 return;
1191
1192 qlcnic_remove_sysfs_entries(adapter);
1193
1194 qlcnic_free_hw_resources(adapter);
1195 qlcnic_release_rx_buffers(adapter);
1196 qlcnic_free_irq(adapter);
1197 qlcnic_napi_del(adapter);
1198 qlcnic_free_sw_resources(adapter);
1199
1200 adapter->is_up = 0;
1201}
1202
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001203void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1204{
1205 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1206 struct qlcnic_host_sds_ring *sds_ring;
1207 int ring;
1208
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001209 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001210 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1211 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001212 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001213 qlcnic_disable_int(sds_ring);
1214 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001215 }
1216
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001217 qlcnic_fw_destroy_ctx(adapter);
1218
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001219 qlcnic_detach(adapter);
1220
1221 adapter->diag_test = 0;
1222 adapter->max_sds_rings = max_sds_rings;
1223
1224 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001225 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001226
1227 if (netif_running(netdev))
1228 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001229out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001230 netif_device_attach(netdev);
1231}
1232
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001233static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1234{
1235 int err = 0;
1236 adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context),
1237 GFP_KERNEL);
1238 if (!adapter->ahw) {
1239 dev_err(&adapter->pdev->dev,
1240 "Failed to allocate recv ctx resources for adapter\n");
1241 err = -ENOMEM;
1242 goto err_out;
1243 }
1244 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1245 GFP_KERNEL);
1246 if (!adapter->recv_ctx) {
1247 dev_err(&adapter->pdev->dev,
1248 "Failed to allocate recv ctx resources for adapter\n");
1249 kfree(adapter->ahw);
1250 adapter->ahw = NULL;
1251 err = -ENOMEM;
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001252 goto err_out;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001253 }
Anirban Chakraborty8816d002011-04-01 14:28:21 +00001254 /* Initialize interrupt coalesce parameters */
1255 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1256 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1257 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001258err_out:
1259 return err;
1260}
1261
1262static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1263{
1264 kfree(adapter->recv_ctx);
1265 adapter->recv_ctx = NULL;
1266
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00001267 if (adapter->ahw->fw_dump.tmpl_hdr) {
1268 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1269 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1270 }
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001271 kfree(adapter->ahw);
1272 adapter->ahw = NULL;
1273}
1274
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001275int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1276{
1277 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1278 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001279 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001280 int ring;
1281 int ret;
1282
1283 netif_device_detach(netdev);
1284
1285 if (netif_running(netdev))
1286 __qlcnic_down(adapter, netdev);
1287
1288 qlcnic_detach(adapter);
1289
1290 adapter->max_sds_rings = 1;
1291 adapter->diag_test = test;
1292
1293 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001294 if (ret) {
1295 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001296 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001297 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001298
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001299 ret = qlcnic_fw_create_ctx(adapter);
1300 if (ret) {
1301 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001302 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001303 return ret;
1304 }
1305
1306 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001307 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1308 qlcnic_post_rx_buffers(adapter, rds_ring);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001309 }
1310
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001311 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1312 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001313 sds_ring = &adapter->recv_ctx->sds_rings[ring];
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001314 qlcnic_enable_int(sds_ring);
1315 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001316 }
Sucheta Chakraborty22c8c932011-06-22 02:52:23 +00001317
1318 if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) {
1319 adapter->ahw->loopback_state = 0;
1320 qlcnic_linkevent_request(adapter, 1);
1321 }
1322
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001323 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001324
1325 return 0;
1326}
1327
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001328/* Reset context in hardware only */
1329static int
1330qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1331{
1332 struct net_device *netdev = adapter->netdev;
1333
1334 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1335 return -EBUSY;
1336
1337 netif_device_detach(netdev);
1338
1339 qlcnic_down(adapter, netdev);
1340
1341 qlcnic_up(adapter, netdev);
1342
1343 netif_device_attach(netdev);
1344
1345 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1346 return 0;
1347}
1348
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001349int
1350qlcnic_reset_context(struct qlcnic_adapter *adapter)
1351{
1352 int err = 0;
1353 struct net_device *netdev = adapter->netdev;
1354
1355 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1356 return -EBUSY;
1357
1358 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1359
1360 netif_device_detach(netdev);
1361
1362 if (netif_running(netdev))
1363 __qlcnic_down(adapter, netdev);
1364
1365 qlcnic_detach(adapter);
1366
1367 if (netif_running(netdev)) {
1368 err = qlcnic_attach(adapter);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001369 if (!err) {
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001370 __qlcnic_up(adapter, netdev);
Anirban Chakraborty1d5c88e2012-03-23 06:32:34 +00001371 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1372 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001373 }
1374
1375 netif_device_attach(netdev);
1376 }
1377
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001378 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1379 return err;
1380}
1381
1382static int
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001383qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev,
1384 int pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001385{
1386 int err;
1387 struct pci_dev *pdev = adapter->pdev;
1388
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001389 adapter->mc_enabled = 0;
1390 adapter->max_mc_count = 38;
1391
1392 netdev->netdev_ops = &qlcnic_netdev_ops;
Rajesh K Borundiaef71ff82010-06-17 02:56:41 +00001393 netdev->watchdog_timeo = 5*HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001394
1395 qlcnic_change_mtu(netdev, netdev->mtu);
1396
1397 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1398
Michał Mirosław135d84a2011-04-19 03:03:57 +00001399 netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
1400 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM;
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001401
Michał Mirosław135d84a2011-04-19 03:03:57 +00001402 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
1403 netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001404 if (pci_using_dac == 1)
Michał Mirosław135d84a2011-04-19 03:03:57 +00001405 netdev->hw_features |= NETIF_F_HIGHDMA;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001406
Michał Mirosław135d84a2011-04-19 03:03:57 +00001407 netdev->vlan_features = netdev->hw_features;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001408
1409 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
Michał Mirosław135d84a2011-04-19 03:03:57 +00001410 netdev->hw_features |= NETIF_F_HW_VLAN_TX;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001411 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
Michał Mirosław135d84a2011-04-19 03:03:57 +00001412 netdev->hw_features |= NETIF_F_LRO;
1413
1414 netdev->features |= netdev->hw_features |
1415 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
1416
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001417 netdev->irq = adapter->msix_entries[0].vector;
1418
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001419 err = register_netdev(netdev);
1420 if (err) {
1421 dev_err(&pdev->dev, "failed to register net device\n");
1422 return err;
1423 }
1424
1425 return 0;
1426}
1427
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001428static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac)
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001429{
1430 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1431 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1432 *pci_using_dac = 1;
1433 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1434 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1435 *pci_using_dac = 0;
1436 else {
1437 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1438 return -EIO;
1439 }
1440
1441 return 0;
1442}
1443
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001444static int
1445qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count)
1446{
1447 adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry),
1448 GFP_KERNEL);
1449
1450 if (adapter->msix_entries)
1451 return 0;
1452
1453 dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n");
1454 return -ENOMEM;
1455}
1456
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001457static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001458qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1459{
1460 struct net_device *netdev = NULL;
1461 struct qlcnic_adapter *adapter = NULL;
Sony Chacko5ad6ff92012-11-17 21:04:38 +00001462 int err, pci_using_dac = -1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001463 uint8_t revision_id;
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001464 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001465
1466 err = pci_enable_device(pdev);
1467 if (err)
1468 return err;
1469
1470 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1471 err = -ENODEV;
1472 goto err_out_disable_pdev;
1473 }
1474
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001475 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1476 if (err)
1477 goto err_out_disable_pdev;
1478
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001479 err = pci_request_regions(pdev, qlcnic_driver_name);
1480 if (err)
1481 goto err_out_disable_pdev;
1482
1483 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001484 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001485
1486 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1487 if (!netdev) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001488 err = -ENOMEM;
1489 goto err_out_free_res;
1490 }
1491
1492 SET_NETDEV_DEV(netdev, &pdev->dev);
1493
1494 adapter = netdev_priv(netdev);
1495 adapter->netdev = netdev;
1496 adapter->pdev = pdev;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001497
Peter Senna Tschudin2dfc9672012-10-05 12:10:50 +00001498 err = qlcnic_alloc_adapter_resources(adapter);
1499 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001500 goto err_out_free_netdev;
1501
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001502 adapter->dev_rst_time = jiffies;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001503 revision_id = pdev->revision;
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001504 adapter->ahw->revision_id = revision_id;
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001505 adapter->mac_learn = qlcnic_mac_learn;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001506
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001507 rwlock_init(&adapter->ahw->crb_lock);
1508 mutex_init(&adapter->ahw->mem_lock);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001509
1510 spin_lock_init(&adapter->tx_clean_lock);
1511 INIT_LIST_HEAD(&adapter->mac_list);
1512
1513 err = qlcnic_setup_pci_map(adapter);
1514 if (err)
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001515 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001516
1517 /* This will be reset for mezz cards */
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001518 adapter->portnum = adapter->ahw->pci_func;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001519
1520 err = qlcnic_get_board_info(adapter);
1521 if (err) {
1522 dev_err(&pdev->dev, "Error getting board config info.\n");
1523 goto err_out_iounmap;
1524 }
1525
Sony Chacko8cfdce02010-08-26 14:02:41 +00001526 err = qlcnic_setup_idc_param(adapter);
1527 if (err)
Sucheta Chakrabortyb3a24642010-05-13 03:07:48 +00001528 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001529
Rajesh Borundia1dc0f3c2010-12-16 22:59:02 +00001530 adapter->flags |= QLCNIC_NEED_FLR;
Rajesh Borundiab0044bc2010-11-23 01:25:21 +00001531
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001532 err = adapter->nic_ops->start_firmware(adapter);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001533 if (err) {
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001534 dev_err(&pdev->dev, "Loading fw failed. Please Reboot\n"
1535 "\t\tIf reboot doesn't help, try flashing the card\n");
1536 goto err_out_maintenance_mode;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001537 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001538
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001539 if (qlcnic_read_mac_addr(adapter))
1540 dev_warn(&pdev->dev, "failed to read mac addr\n");
1541
1542 if (adapter->portnum == 0) {
1543 get_brd_name(adapter, brd_name);
1544
1545 pr_info("%s: %s Board Chip rev 0x%x\n",
1546 module_name(THIS_MODULE),
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001547 brd_name, adapter->ahw->revision_id);
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001548 }
1549
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001550 qlcnic_clear_stats(adapter);
1551
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001552 err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques);
1553 if (err)
1554 goto err_out_decr_ref;
1555
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001556 qlcnic_setup_intr(adapter);
1557
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001558 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001559 if (err)
1560 goto err_out_disable_msi;
1561
1562 pci_set_drvdata(pdev, adapter);
1563
1564 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1565
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001566 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001567 case QLCNIC_GBE:
1568 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1569 adapter->netdev->name);
1570 break;
1571 case QLCNIC_XGBE:
1572 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1573 adapter->netdev->name);
1574 break;
1575 }
1576
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001577 if (adapter->mac_learn)
1578 qlcnic_alloc_lb_filters_mem(adapter);
1579
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001580 qlcnic_create_diag_entries(adapter);
1581
1582 return 0;
1583
1584err_out_disable_msi:
1585 qlcnic_teardown_intr(adapter);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001586 kfree(adapter->msix_entries);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001587
1588err_out_decr_ref:
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001589 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001590
1591err_out_iounmap:
1592 qlcnic_cleanup_pci_map(adapter);
1593
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001594err_out_free_hw:
1595 qlcnic_free_adapter_resources(adapter);
1596
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001597err_out_free_netdev:
1598 free_netdev(netdev);
1599
1600err_out_free_res:
1601 pci_release_regions(pdev);
1602
1603err_out_disable_pdev:
1604 pci_set_drvdata(pdev, NULL);
1605 pci_disable_device(pdev);
1606 return err;
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001607
1608err_out_maintenance_mode:
1609 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
1610 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
1611 err = register_netdev(netdev);
1612 if (err) {
1613 dev_err(&pdev->dev, "failed to register net device\n");
1614 goto err_out_decr_ref;
1615 }
1616 pci_set_drvdata(pdev, adapter);
1617 qlcnic_create_diag_entries(adapter);
1618 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001619}
1620
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001621static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001622{
1623 struct qlcnic_adapter *adapter;
1624 struct net_device *netdev;
1625
1626 adapter = pci_get_drvdata(pdev);
1627 if (adapter == NULL)
1628 return;
1629
1630 netdev = adapter->netdev;
1631
1632 qlcnic_cancel_fw_work(adapter);
1633
1634 unregister_netdev(netdev);
1635
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001636 qlcnic_detach(adapter);
1637
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001638 if (adapter->npars != NULL)
1639 kfree(adapter->npars);
1640 if (adapter->eswitch != NULL)
1641 kfree(adapter->eswitch);
1642
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001643 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001644
1645 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1646
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001647 qlcnic_free_lb_filters_mem(adapter);
1648
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001649 qlcnic_teardown_intr(adapter);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001650 kfree(adapter->msix_entries);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001651
1652 qlcnic_remove_diag_entries(adapter);
1653
1654 qlcnic_cleanup_pci_map(adapter);
1655
1656 qlcnic_release_firmware(adapter);
1657
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001658 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001659 pci_release_regions(pdev);
1660 pci_disable_device(pdev);
1661 pci_set_drvdata(pdev, NULL);
1662
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001663 qlcnic_free_adapter_resources(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001664 free_netdev(netdev);
1665}
1666static int __qlcnic_shutdown(struct pci_dev *pdev)
1667{
1668 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1669 struct net_device *netdev = adapter->netdev;
1670 int retval;
1671
1672 netif_device_detach(netdev);
1673
1674 qlcnic_cancel_fw_work(adapter);
1675
1676 if (netif_running(netdev))
1677 qlcnic_down(adapter, netdev);
1678
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001679 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001680
1681 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1682
1683 retval = pci_save_state(pdev);
1684 if (retval)
1685 return retval;
1686
1687 if (qlcnic_wol_supported(adapter)) {
1688 pci_enable_wake(pdev, PCI_D3cold, 1);
1689 pci_enable_wake(pdev, PCI_D3hot, 1);
1690 }
1691
1692 return 0;
1693}
1694
1695static void qlcnic_shutdown(struct pci_dev *pdev)
1696{
1697 if (__qlcnic_shutdown(pdev))
1698 return;
1699
1700 pci_disable_device(pdev);
1701}
1702
1703#ifdef CONFIG_PM
1704static int
1705qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1706{
1707 int retval;
1708
1709 retval = __qlcnic_shutdown(pdev);
1710 if (retval)
1711 return retval;
1712
1713 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1714 return 0;
1715}
1716
1717static int
1718qlcnic_resume(struct pci_dev *pdev)
1719{
1720 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1721 struct net_device *netdev = adapter->netdev;
1722 int err;
1723
1724 err = pci_enable_device(pdev);
1725 if (err)
1726 return err;
1727
1728 pci_set_power_state(pdev, PCI_D0);
1729 pci_set_master(pdev);
1730 pci_restore_state(pdev);
1731
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001732 err = adapter->nic_ops->start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001733 if (err) {
1734 dev_err(&pdev->dev, "failed to start firmware\n");
1735 return err;
1736 }
1737
1738 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001739 err = qlcnic_up(adapter, netdev);
1740 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001741 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001742
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00001743 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001744 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001745done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001746 netif_device_attach(netdev);
1747 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1748 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001749}
1750#endif
1751
1752static int qlcnic_open(struct net_device *netdev)
1753{
1754 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001755 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001756 int err;
1757
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001758 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
1759 netdev_err(netdev, "Device in FAILED state\n");
1760 return -EIO;
1761 }
1762
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00001763 netif_carrier_off(netdev);
1764
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001765 err = qlcnic_attach(adapter);
1766 if (err)
1767 return err;
1768
1769 err = __qlcnic_up(adapter, netdev);
1770 if (err)
1771 goto err_out;
1772
1773 netif_start_queue(netdev);
1774
1775 return 0;
1776
1777err_out:
1778 qlcnic_detach(adapter);
1779 return err;
1780}
1781
1782/*
1783 * qlcnic_close - Disables a network interface entry point
1784 */
1785static int qlcnic_close(struct net_device *netdev)
1786{
1787 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1788
1789 __qlcnic_down(adapter, netdev);
1790 return 0;
1791}
1792
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001793void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001794{
1795 void *head;
1796 int i;
1797
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001798 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001799 return;
1800
1801 spin_lock_init(&adapter->mac_learn_lock);
1802
1803 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1804 GFP_KERNEL);
1805 if (!head)
1806 return;
1807
1808 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
Joe Perches43d620c2011-06-16 19:08:06 +00001809 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001810
1811 for (i = 0; i < adapter->fhash.fmax; i++)
1812 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1813}
1814
1815static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1816{
1817 if (adapter->fhash.fmax && adapter->fhash.fhead)
1818 kfree(adapter->fhash.fhead);
1819
1820 adapter->fhash.fhead = NULL;
1821 adapter->fhash.fmax = 0;
1822}
1823
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001824static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
1825{
1826 struct net_device *netdev = adapter->netdev;
1827 u32 temp, temp_state, temp_val;
1828 int rv = 0;
1829
1830 temp = QLCRD32(adapter, CRB_TEMP_STATE);
1831
1832 temp_state = qlcnic_get_temp_state(temp);
1833 temp_val = qlcnic_get_temp_val(temp);
1834
1835 if (temp_state == QLCNIC_TEMP_PANIC) {
1836 dev_err(&netdev->dev,
1837 "Device temperature %d degrees C exceeds"
1838 " maximum allowed. Hardware has been shut down.\n",
1839 temp_val);
1840 rv = 1;
1841 } else if (temp_state == QLCNIC_TEMP_WARN) {
1842 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
1843 dev_err(&netdev->dev,
1844 "Device temperature %d degrees C "
1845 "exceeds operating range."
1846 " Immediate action needed.\n",
1847 temp_val);
1848 }
1849 } else {
1850 if (adapter->temp == QLCNIC_TEMP_WARN) {
1851 dev_info(&netdev->dev,
1852 "Device temperature is now %d degrees C"
1853 " in normal range.\n", temp_val);
1854 }
1855 }
1856 adapter->temp = temp_state;
1857 return rv;
1858}
1859
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001860static void qlcnic_tx_timeout(struct net_device *netdev)
1861{
1862 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1863
1864 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1865 return;
1866
1867 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001868
1869 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001870 adapter->need_fw_reset = 1;
1871 else
1872 adapter->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001873}
1874
1875static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
1876{
1877 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1878 struct net_device_stats *stats = &netdev->stats;
1879
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001880 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
1881 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00001882 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001883 stats->tx_bytes = adapter->stats.txbytes;
1884 stats->rx_dropped = adapter->stats.rxdropped;
1885 stats->tx_dropped = adapter->stats.txdropped;
1886
1887 return stats;
1888}
1889
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001890static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001891{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001892 u32 status;
1893
1894 status = readl(adapter->isr_int_vec);
1895
1896 if (!(status & adapter->int_vec_bit))
1897 return IRQ_NONE;
1898
1899 /* check interrupt state machine, to be sure */
1900 status = readl(adapter->crb_int_state_reg);
1901 if (!ISR_LEGACY_INT_TRIGGERED(status))
1902 return IRQ_NONE;
1903
1904 writel(0xffffffff, adapter->tgt_status_reg);
1905 /* read twice to ensure write is flushed */
1906 readl(adapter->isr_int_vec);
1907 readl(adapter->isr_int_vec);
1908
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001909 return IRQ_HANDLED;
1910}
1911
1912static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
1913{
1914 struct qlcnic_host_sds_ring *sds_ring = data;
1915 struct qlcnic_adapter *adapter = sds_ring->adapter;
1916
1917 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1918 goto done;
1919 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
1920 writel(0xffffffff, adapter->tgt_status_reg);
1921 goto done;
1922 }
1923
1924 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
1925 return IRQ_NONE;
1926
1927done:
1928 adapter->diag_cnt++;
1929 qlcnic_enable_int(sds_ring);
1930 return IRQ_HANDLED;
1931}
1932
1933static irqreturn_t qlcnic_intr(int irq, void *data)
1934{
1935 struct qlcnic_host_sds_ring *sds_ring = data;
1936 struct qlcnic_adapter *adapter = sds_ring->adapter;
1937
1938 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
1939 return IRQ_NONE;
1940
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001941 napi_schedule(&sds_ring->napi);
1942
1943 return IRQ_HANDLED;
1944}
1945
1946static irqreturn_t qlcnic_msi_intr(int irq, void *data)
1947{
1948 struct qlcnic_host_sds_ring *sds_ring = data;
1949 struct qlcnic_adapter *adapter = sds_ring->adapter;
1950
1951 /* clear interrupt */
1952 writel(0xffffffff, adapter->tgt_status_reg);
1953
1954 napi_schedule(&sds_ring->napi);
1955 return IRQ_HANDLED;
1956}
1957
1958static irqreturn_t qlcnic_msix_intr(int irq, void *data)
1959{
1960 struct qlcnic_host_sds_ring *sds_ring = data;
1961
1962 napi_schedule(&sds_ring->napi);
1963 return IRQ_HANDLED;
1964}
1965
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001966#ifdef CONFIG_NET_POLL_CONTROLLER
1967static void qlcnic_poll_controller(struct net_device *netdev)
1968{
Yinglin Luanbf827912010-08-22 21:57:56 +00001969 int ring;
1970 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001971 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001972 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00001973
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001974 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00001975 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1976 sds_ring = &recv_ctx->sds_rings[ring];
1977 qlcnic_intr(adapter->irq, sds_ring);
1978 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001979 enable_irq(adapter->irq);
1980}
1981#endif
1982
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001983static void
1984qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
1985{
1986 u32 val;
1987
1988 val = adapter->portnum & 0xf;
1989 val |= encoding << 7;
1990 val |= (jiffies - adapter->dev_rst_time) << 8;
1991
1992 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
1993 adapter->dev_rst_time = jiffies;
1994}
1995
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00001996static int
1997qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001998{
1999 u32 val;
2000
2001 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2002 state != QLCNIC_DEV_NEED_QUISCENT);
2003
2004 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002005 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002006
2007 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2008
2009 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002010 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002011 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002012 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002013
2014 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2015
2016 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002017
2018 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002019}
2020
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002021static int
2022qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2023{
2024 u32 val;
2025
2026 if (qlcnic_api_lock(adapter))
2027 return -EBUSY;
2028
2029 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002030 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002031 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2032
2033 qlcnic_api_unlock(adapter);
2034
2035 return 0;
2036}
2037
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002038static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002039qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002040{
2041 u32 val;
2042
2043 if (qlcnic_api_lock(adapter))
2044 goto err;
2045
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002046 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002047 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002048 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002049
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002050 if (failed) {
2051 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2052 dev_info(&adapter->pdev->dev,
2053 "Device state set to Failed. Please Reboot\n");
2054 } else if (!(val & 0x11111111))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002055 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2056
2057 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002058 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002059 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2060
2061 qlcnic_api_unlock(adapter);
2062err:
2063 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002064 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002065 clear_bit(__QLCNIC_START_FW, &adapter->state);
2066 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2067}
2068
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002069/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002070static int
2071qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2072{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002073 int act, state, active_mask;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002074
2075 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002076 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002077
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002078 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
2079 active_mask = (~(1 << (adapter->ahw->pci_func * 4)));
2080 act = act & active_mask;
2081 }
2082
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002083 if (((state & 0x11111111) == (act & 0x11111111)) ||
2084 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2085 return 0;
2086 else
2087 return 1;
2088}
2089
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002090static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2091{
2092 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2093
2094 if (val != QLCNIC_DRV_IDC_VER) {
2095 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2096 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2097 }
2098
2099 return 0;
2100}
2101
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002102static int
2103qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2104{
2105 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002106 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002107 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002108 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002109
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002110 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2111 return 1;
2112
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002113 if (qlcnic_api_lock(adapter))
2114 return -1;
2115
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002116 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002117 if (!(val & (1 << (portnum * 4)))) {
2118 QLC_DEV_SET_REF_CNT(val, portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002119 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002120 }
2121
2122 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002123 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002124
2125 switch (prev_state) {
2126 case QLCNIC_DEV_COLD:
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002127 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002128 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002129 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002130 qlcnic_api_unlock(adapter);
2131 return 1;
2132
2133 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002134 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002135 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002136 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002137
2138 case QLCNIC_DEV_NEED_RESET:
2139 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002140 QLC_DEV_SET_RST_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002141 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2142 break;
2143
2144 case QLCNIC_DEV_NEED_QUISCENT:
2145 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002146 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002147 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2148 break;
2149
2150 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002151 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002152 qlcnic_api_unlock(adapter);
2153 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002154
2155 case QLCNIC_DEV_INITIALIZING:
2156 case QLCNIC_DEV_QUISCENT:
2157 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002158 }
2159
2160 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002161
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002162 do {
2163 msleep(1000);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002164 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2165
2166 if (prev_state == QLCNIC_DEV_QUISCENT)
2167 continue;
2168 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002169
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002170 if (!dev_init_timeo) {
2171 dev_err(&adapter->pdev->dev,
2172 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002173 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002174 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002175
2176 if (qlcnic_api_lock(adapter))
2177 return -1;
2178
2179 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002180 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002181 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2182
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002183 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002184 qlcnic_api_unlock(adapter);
2185
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002186 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002187}
2188
2189static void
2190qlcnic_fwinit_work(struct work_struct *work)
2191{
2192 struct qlcnic_adapter *adapter = container_of(work,
2193 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002194 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002195 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002196
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002197 if (qlcnic_api_lock(adapter))
2198 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002199
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002200 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002201 if (dev_state == QLCNIC_DEV_QUISCENT ||
2202 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002203 qlcnic_api_unlock(adapter);
2204 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2205 FW_POLL_DELAY * 2);
2206 return;
2207 }
2208
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002209 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002210 qlcnic_api_unlock(adapter);
2211 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002212 }
2213
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002214 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2215 dev_state == QLCNIC_DEV_READY) {
2216 dev_info(&adapter->pdev->dev, "Detected state change from "
2217 "DEV_NEED_RESET, skipping ack check\n");
2218 goto skip_ack_check;
2219 }
2220
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002221 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002222 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002223 adapter->reset_ack_timeo);
2224 goto skip_ack_check;
2225 }
2226
2227 if (!qlcnic_check_drv_state(adapter)) {
2228skip_ack_check:
2229 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002230
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002231 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2232 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2233 QLCNIC_DEV_INITIALIZING);
2234 set_bit(__QLCNIC_START_FW, &adapter->state);
2235 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002236 qlcnic_idc_debug_info(adapter, 0);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002237 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2238 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2239 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002240 }
2241
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002242 qlcnic_api_unlock(adapter);
2243
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002244 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002245 if (adapter->ahw->fw_dump.enable &&
2246 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002247 QLCDB(adapter, DRV, "Take FW dump\n");
2248 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002249 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002250 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002251 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002252
2253 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002254 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002255 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002256 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002257 return;
2258 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002259 goto err_ret;
2260 }
2261
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002262 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002263
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002264wait_npar:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002265 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002266 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002267
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002268 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002269 case QLCNIC_DEV_READY:
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002270 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002271 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002272 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002273 return;
2274 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002275 case QLCNIC_DEV_FAILED:
2276 break;
2277 default:
2278 qlcnic_schedule_work(adapter,
2279 qlcnic_fwinit_work, FW_POLL_DELAY);
2280 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002281 }
2282
2283err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002284 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2285 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002286 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002287 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002288}
2289
2290static void
2291qlcnic_detach_work(struct work_struct *work)
2292{
2293 struct qlcnic_adapter *adapter = container_of(work,
2294 struct qlcnic_adapter, fw_work.work);
2295 struct net_device *netdev = adapter->netdev;
2296 u32 status;
2297
2298 netif_device_detach(netdev);
2299
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002300 /* Dont grab rtnl lock during Quiscent mode */
2301 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2302 if (netif_running(netdev))
2303 __qlcnic_down(adapter, netdev);
2304 } else
2305 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002306
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002307 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2308
Sony Chacko44f65b22011-08-29 12:50:26 +00002309 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2310 dev_err(&adapter->pdev->dev,
2311 "Detaching the device: peg halt status1=0x%x\n",
2312 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002313
Sony Chacko44f65b22011-08-29 12:50:26 +00002314 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2315 dev_err(&adapter->pdev->dev,
2316 "On board active cooling fan failed. "
2317 "Device has been halted.\n");
2318 dev_err(&adapter->pdev->dev,
2319 "Replace the adapter.\n");
2320 }
2321
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002322 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002323 }
2324
2325 if (adapter->temp == QLCNIC_TEMP_PANIC) {
2326 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
2327 adapter->temp);
2328 goto err_ret;
2329 }
2330
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002331 /* Dont ack if this instance is the reset owner */
2332 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002333 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2334 dev_err(&adapter->pdev->dev,
2335 "Failed to set driver state,"
2336 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002337 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002338 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002339 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002340
2341 adapter->fw_wait_cnt = 0;
2342
2343 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2344
2345 return;
2346
2347err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002348 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002349 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002350}
2351
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002352/*Transit NPAR state to NON Operational */
2353static void
2354qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2355{
2356 u32 state;
2357
2358 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2359 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2360 return;
2361
2362 if (qlcnic_api_lock(adapter))
2363 return;
2364 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2365 qlcnic_api_unlock(adapter);
2366}
2367
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002368/*Transit to RESET state from READY state only */
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002369void
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002370qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2371{
Sritej Velaga646779f2012-02-03 13:45:41 +00002372 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002373
Sritej Velaga646779f2012-02-03 13:45:41 +00002374 qlcnic_xg_set_xg0_mask(xg_val);
2375 qlcnic_xg_set_xg1_mask(xg_val);
2376 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2377 qlcnic_gb_set_gb0_mask(gb_val);
2378 qlcnic_gb_set_gb1_mask(gb_val);
2379 qlcnic_gb_set_gb2_mask(gb_val);
2380 qlcnic_gb_set_gb3_mask(gb_val);
2381 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2382 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2383 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002384 adapter->need_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002385 if (qlcnic_api_lock(adapter))
2386 return;
2387
2388 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00002389 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
2390 netdev_err(adapter->netdev,
2391 "Device is in FAILED state, Please Reboot\n");
2392 qlcnic_api_unlock(adapter);
2393 return;
2394 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002395
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002396 if (state == QLCNIC_DEV_READY) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002397 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002398 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002399 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002400 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002401 }
2402
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002403 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002404 qlcnic_api_unlock(adapter);
2405}
2406
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002407/* Transit to NPAR READY state from NPAR NOT READY state */
2408static void
2409qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2410{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002411 if (qlcnic_api_lock(adapter))
2412 return;
2413
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002414 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2415 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002416
2417 qlcnic_api_unlock(adapter);
2418}
2419
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002420static void
2421qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2422 work_func_t func, int delay)
2423{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002424 if (test_bit(__QLCNIC_AER, &adapter->state))
2425 return;
2426
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002427 INIT_DELAYED_WORK(&adapter->fw_work, func);
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002428 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
2429 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002430}
2431
2432static void
2433qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
2434{
2435 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2436 msleep(10);
2437
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00002438 if (!adapter->fw_work.work.func)
2439 return;
2440
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002441 cancel_delayed_work_sync(&adapter->fw_work);
2442}
2443
2444static void
2445qlcnic_attach_work(struct work_struct *work)
2446{
2447 struct qlcnic_adapter *adapter = container_of(work,
2448 struct qlcnic_adapter, fw_work.work);
2449 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002450 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002451
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002452 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2453 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2454 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2455 qlcnic_clr_all_drv_state(adapter, 0);
2456 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2457 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2458 FW_POLL_DELAY);
2459 else
2460 goto attach;
2461 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2462 return;
2463 }
2464attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002465 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002466 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002467 goto done;
2468
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002469 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002470 }
2471
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002472done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002473 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002474 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002475 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002476 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002477
2478 if (!qlcnic_clr_drv_state(adapter))
2479 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2480 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002481}
2482
2483static int
2484qlcnic_check_health(struct qlcnic_adapter *adapter)
2485{
Sony Chacko4e708122010-08-31 17:17:44 +00002486 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002487 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002488
2489 if (qlcnic_check_temp(adapter))
2490 goto detach;
2491
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002492 if (adapter->need_fw_reset)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002493 qlcnic_dev_request_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002494
2495 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002496 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002497 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002498 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002499 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2500 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002501
Sony Chacko4e708122010-08-31 17:17:44 +00002502 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
2503 if (heartbeat != adapter->heartbeat) {
2504 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002505 adapter->fw_fail_cnt = 0;
2506 if (adapter->need_fw_reset)
2507 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002508
amit salecha9ce13ca2011-02-23 03:21:24 +00002509 if (adapter->reset_context && auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002510 qlcnic_reset_hw_context(adapter);
2511 adapter->netdev->trans_start = jiffies;
2512 }
2513
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002514 return 0;
2515 }
2516
2517 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2518 return 0;
2519
Sritej Velaga032a13c2011-07-29 13:30:27 +00002520 adapter->flags |= QLCNIC_FW_HANG;
2521
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002522 qlcnic_dev_request_reset(adapter);
2523
amit salecha9ce13ca2011-02-23 03:21:24 +00002524 if (auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002525 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002526
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002527 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
2528 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00002529 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2530 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2531 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2532 "PEG_NET_4_PC: 0x%x\n",
2533 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1),
2534 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2),
2535 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
2536 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
2537 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
2538 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
2539 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002540 peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Sritej Velaga97048a12012-02-03 13:45:43 +00002541 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002542 dev_err(&adapter->pdev->dev,
2543 "Firmware aborted with error code 0x00006700. "
2544 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002545detach:
2546 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
2547 QLCNIC_DEV_NEED_RESET;
2548
amit salecha9ce13ca2011-02-23 03:21:24 +00002549 if (auto_fw_reset &&
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002550 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
2551
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002552 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002553 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
2554 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002555
2556 return 1;
2557}
2558
2559static void
2560qlcnic_fw_poll_work(struct work_struct *work)
2561{
2562 struct qlcnic_adapter *adapter = container_of(work,
2563 struct qlcnic_adapter, fw_work.work);
2564
2565 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2566 goto reschedule;
2567
2568
2569 if (qlcnic_check_health(adapter))
2570 return;
2571
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002572 if (adapter->fhash.fnum)
2573 qlcnic_prune_lb_filters(adapter);
2574
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002575reschedule:
2576 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2577}
2578
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002579static int qlcnic_is_first_func(struct pci_dev *pdev)
2580{
2581 struct pci_dev *oth_pdev;
2582 int val = pdev->devfn;
2583
2584 while (val-- > 0) {
2585 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
2586 (pdev->bus), pdev->bus->number,
2587 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002588 if (!oth_pdev)
2589 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002590
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002591 if (oth_pdev->current_state != PCI_D3cold) {
2592 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002593 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002594 }
2595 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002596 }
2597 return 1;
2598}
2599
2600static int qlcnic_attach_func(struct pci_dev *pdev)
2601{
2602 int err, first_func;
2603 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2604 struct net_device *netdev = adapter->netdev;
2605
2606 pdev->error_state = pci_channel_io_normal;
2607
2608 err = pci_enable_device(pdev);
2609 if (err)
2610 return err;
2611
2612 pci_set_power_state(pdev, PCI_D0);
2613 pci_set_master(pdev);
2614 pci_restore_state(pdev);
2615
2616 first_func = qlcnic_is_first_func(pdev);
2617
2618 if (qlcnic_api_lock(adapter))
2619 return -EINVAL;
2620
Amit Kumar Salecha933fce122010-08-17 00:34:19 +00002621 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002622 adapter->need_fw_reset = 1;
2623 set_bit(__QLCNIC_START_FW, &adapter->state);
2624 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2625 QLCDB(adapter, DRV, "Restarting fw\n");
2626 }
2627 qlcnic_api_unlock(adapter);
2628
2629 err = adapter->nic_ops->start_firmware(adapter);
2630 if (err)
2631 return err;
2632
2633 qlcnic_clr_drv_state(adapter);
2634 qlcnic_setup_intr(adapter);
2635
2636 if (netif_running(netdev)) {
2637 err = qlcnic_attach(adapter);
2638 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002639 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002640 clear_bit(__QLCNIC_AER, &adapter->state);
2641 netif_device_attach(netdev);
2642 return err;
2643 }
2644
2645 err = qlcnic_up(adapter, netdev);
2646 if (err)
2647 goto done;
2648
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002649 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002650 }
2651 done:
2652 netif_device_attach(netdev);
2653 return err;
2654}
2655
2656static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
2657 pci_channel_state_t state)
2658{
2659 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2660 struct net_device *netdev = adapter->netdev;
2661
2662 if (state == pci_channel_io_perm_failure)
2663 return PCI_ERS_RESULT_DISCONNECT;
2664
2665 if (state == pci_channel_io_normal)
2666 return PCI_ERS_RESULT_RECOVERED;
2667
2668 set_bit(__QLCNIC_AER, &adapter->state);
2669 netif_device_detach(netdev);
2670
2671 cancel_delayed_work_sync(&adapter->fw_work);
2672
2673 if (netif_running(netdev))
2674 qlcnic_down(adapter, netdev);
2675
2676 qlcnic_detach(adapter);
2677 qlcnic_teardown_intr(adapter);
2678
2679 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2680
2681 pci_save_state(pdev);
2682 pci_disable_device(pdev);
2683
2684 return PCI_ERS_RESULT_NEED_RESET;
2685}
2686
2687static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
2688{
2689 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
2690 PCI_ERS_RESULT_RECOVERED;
2691}
2692
2693static void qlcnic_io_resume(struct pci_dev *pdev)
2694{
2695 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2696
2697 pci_cleanup_aer_uncorrect_error_status(pdev);
2698
2699 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
2700 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
2701 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2702 FW_POLL_DELAY);
2703}
2704
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002705static int
2706qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
2707{
2708 int err;
2709
2710 err = qlcnic_can_start_firmware(adapter);
2711 if (err)
2712 return err;
2713
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00002714 err = qlcnic_check_npar_opertional(adapter);
2715 if (err)
2716 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002717
Rajesh Borundia174240a2010-08-31 17:17:47 +00002718 err = qlcnic_initialize_nic(adapter);
2719 if (err)
2720 return err;
2721
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002722 qlcnic_check_options(adapter);
2723
Rajesh Borundia73733732010-08-31 17:17:50 +00002724 err = qlcnic_set_eswitch_port_config(adapter);
2725 if (err)
2726 return err;
2727
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002728 adapter->need_fw_reset = 0;
2729
2730 return err;
2731}
2732
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00002733int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val)
2734{
2735 if (!use_msi_x && !use_msi) {
2736 netdev_info(netdev, "no msix or msi support, hence no rss\n");
2737 return -EINVAL;
2738 }
2739
2740 if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) {
2741 netdev_info(netdev, "rss_ring valid range [2 - %x] in "
2742 " powers of 2\n", max_hw);
2743 return -EINVAL;
2744 }
2745 return 0;
2746
2747}
2748
2749int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data)
2750{
2751 struct net_device *netdev = adapter->netdev;
2752 int err = 0;
2753
2754 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2755 return -EBUSY;
2756
2757 netif_device_detach(netdev);
2758 if (netif_running(netdev))
2759 __qlcnic_down(adapter, netdev);
2760 qlcnic_detach(adapter);
2761 qlcnic_teardown_intr(adapter);
2762
2763 if (qlcnic_enable_msix(adapter, data)) {
2764 netdev_info(netdev, "failed setting max_rss; rss disabled\n");
2765 qlcnic_enable_msi_legacy(adapter);
2766 }
2767
2768 if (netif_running(netdev)) {
2769 err = qlcnic_attach(adapter);
2770 if (err)
2771 goto done;
2772 err = __qlcnic_up(adapter, netdev);
2773 if (err)
2774 goto done;
2775 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2776 }
2777 done:
2778 netif_device_attach(netdev);
2779 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2780 return err;
2781}
2782
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002783#ifdef CONFIG_INET
2784
2785#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
2786
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002787static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002788qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
2789 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002790{
2791 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002792
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002793 indev = in_dev_get(dev);
2794 if (!indev)
2795 return;
2796
2797 for_ifa(indev) {
2798 switch (event) {
2799 case NETDEV_UP:
2800 qlcnic_config_ipaddr(adapter,
2801 ifa->ifa_address, QLCNIC_IP_UP);
2802 break;
2803 case NETDEV_DOWN:
2804 qlcnic_config_ipaddr(adapter,
2805 ifa->ifa_address, QLCNIC_IP_DOWN);
2806 break;
2807 default:
2808 break;
2809 }
2810 } endfor_ifa(indev);
2811
2812 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002813}
2814
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002815static void
2816qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
2817{
2818 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2819 struct net_device *dev;
2820 u16 vid;
2821
2822 qlcnic_config_indev_addr(adapter, netdev, event);
2823
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00002824 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Jiri Pirko223bb152011-07-20 04:54:44 +00002825 dev = __vlan_find_dev_deep(netdev, vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002826 if (!dev)
2827 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002828 qlcnic_config_indev_addr(adapter, dev, event);
2829 }
2830}
2831
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002832static int qlcnic_netdev_event(struct notifier_block *this,
2833 unsigned long event, void *ptr)
2834{
2835 struct qlcnic_adapter *adapter;
2836 struct net_device *dev = (struct net_device *)ptr;
2837
2838recheck:
2839 if (dev == NULL)
2840 goto done;
2841
2842 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2843 dev = vlan_dev_real_dev(dev);
2844 goto recheck;
2845 }
2846
2847 if (!is_qlcnic_netdev(dev))
2848 goto done;
2849
2850 adapter = netdev_priv(dev);
2851
2852 if (!adapter)
2853 goto done;
2854
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002855 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002856 goto done;
2857
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002858 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002859done:
2860 return NOTIFY_DONE;
2861}
2862
2863static int
2864qlcnic_inetaddr_event(struct notifier_block *this,
2865 unsigned long event, void *ptr)
2866{
2867 struct qlcnic_adapter *adapter;
2868 struct net_device *dev;
2869
2870 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2871
2872 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2873
2874recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002875 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002876 goto done;
2877
2878 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2879 dev = vlan_dev_real_dev(dev);
2880 goto recheck;
2881 }
2882
2883 if (!is_qlcnic_netdev(dev))
2884 goto done;
2885
2886 adapter = netdev_priv(dev);
2887
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00002888 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002889 goto done;
2890
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002891 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002892 goto done;
2893
2894 switch (event) {
2895 case NETDEV_UP:
2896 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
2897 break;
2898 case NETDEV_DOWN:
2899 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
2900 break;
2901 default:
2902 break;
2903 }
2904
2905done:
2906 return NOTIFY_DONE;
2907}
2908
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002909static struct notifier_block qlcnic_netdev_cb = {
2910 .notifier_call = qlcnic_netdev_event,
2911};
2912
2913static struct notifier_block qlcnic_inetaddr_cb = {
2914 .notifier_call = qlcnic_inetaddr_event,
2915};
2916#else
2917static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002918qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002919{ }
2920#endif
Shahed Shaikh63507592012-11-23 23:56:52 +00002921static struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002922 .error_detected = qlcnic_io_error_detected,
2923 .slot_reset = qlcnic_io_slot_reset,
2924 .resume = qlcnic_io_resume,
2925};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002926
2927static struct pci_driver qlcnic_driver = {
2928 .name = qlcnic_driver_name,
2929 .id_table = qlcnic_pci_tbl,
2930 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002931 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002932#ifdef CONFIG_PM
2933 .suspend = qlcnic_suspend,
2934 .resume = qlcnic_resume,
2935#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002936 .shutdown = qlcnic_shutdown,
2937 .err_handler = &qlcnic_err_handler
2938
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002939};
2940
2941static int __init qlcnic_init_module(void)
2942{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002943 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002944
2945 printk(KERN_INFO "%s\n", qlcnic_driver_string);
2946
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002947 qlcnic_wq = create_singlethread_workqueue("qlcnic");
2948 if (qlcnic_wq == NULL) {
2949 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
2950 return -ENOMEM;
2951 }
2952
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002953#ifdef CONFIG_INET
2954 register_netdevice_notifier(&qlcnic_netdev_cb);
2955 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
2956#endif
2957
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002958 ret = pci_register_driver(&qlcnic_driver);
2959 if (ret) {
2960#ifdef CONFIG_INET
2961 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
2962 unregister_netdevice_notifier(&qlcnic_netdev_cb);
2963#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002964 destroy_workqueue(qlcnic_wq);
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002965 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002966
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002967 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002968}
2969
2970module_init(qlcnic_init_module);
2971
2972static void __exit qlcnic_exit_module(void)
2973{
2974
2975 pci_unregister_driver(&qlcnic_driver);
2976
2977#ifdef CONFIG_INET
2978 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
2979 unregister_netdevice_notifier(&qlcnic_netdev_cb);
2980#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002981 destroy_workqueue(qlcnic_wq);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002982}
2983
2984module_exit(qlcnic_exit_module);