blob: f838a17cb326117491ea6f9f92abc46e73287dc1 [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
Sony Chacko97ee45e2012-12-04 03:33:52 +00001564 if (qlcnic_82xx_check(adapter))
1565 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
1566 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001567
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001568 switch (adapter->ahw->port_type) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001569 case QLCNIC_GBE:
1570 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1571 adapter->netdev->name);
1572 break;
1573 case QLCNIC_XGBE:
1574 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1575 adapter->netdev->name);
1576 break;
1577 }
1578
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001579 if (adapter->mac_learn)
1580 qlcnic_alloc_lb_filters_mem(adapter);
1581
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001582 qlcnic_create_diag_entries(adapter);
1583
1584 return 0;
1585
1586err_out_disable_msi:
1587 qlcnic_teardown_intr(adapter);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001588 kfree(adapter->msix_entries);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001589
1590err_out_decr_ref:
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001591 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001592
1593err_out_iounmap:
1594 qlcnic_cleanup_pci_map(adapter);
1595
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001596err_out_free_hw:
1597 qlcnic_free_adapter_resources(adapter);
1598
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001599err_out_free_netdev:
1600 free_netdev(netdev);
1601
1602err_out_free_res:
1603 pci_release_regions(pdev);
1604
1605err_out_disable_pdev:
1606 pci_set_drvdata(pdev, NULL);
1607 pci_disable_device(pdev);
1608 return err;
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001609
1610err_out_maintenance_mode:
1611 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
1612 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
1613 err = register_netdev(netdev);
1614 if (err) {
1615 dev_err(&pdev->dev, "failed to register net device\n");
1616 goto err_out_decr_ref;
1617 }
1618 pci_set_drvdata(pdev, adapter);
1619 qlcnic_create_diag_entries(adapter);
1620 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001621}
1622
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05001623static void qlcnic_remove(struct pci_dev *pdev)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001624{
1625 struct qlcnic_adapter *adapter;
1626 struct net_device *netdev;
1627
1628 adapter = pci_get_drvdata(pdev);
1629 if (adapter == NULL)
1630 return;
1631
1632 netdev = adapter->netdev;
1633
1634 qlcnic_cancel_fw_work(adapter);
1635
1636 unregister_netdev(netdev);
1637
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001638 qlcnic_detach(adapter);
1639
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001640 if (adapter->npars != NULL)
1641 kfree(adapter->npars);
1642 if (adapter->eswitch != NULL)
1643 kfree(adapter->eswitch);
1644
Sony Chacko97ee45e2012-12-04 03:33:52 +00001645 if (qlcnic_82xx_check(adapter))
1646 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001647
1648 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1649
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001650 qlcnic_free_lb_filters_mem(adapter);
1651
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001652 qlcnic_teardown_intr(adapter);
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00001653 kfree(adapter->msix_entries);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001654
1655 qlcnic_remove_diag_entries(adapter);
1656
1657 qlcnic_cleanup_pci_map(adapter);
1658
1659 qlcnic_release_firmware(adapter);
1660
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001661 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001662 pci_release_regions(pdev);
1663 pci_disable_device(pdev);
1664 pci_set_drvdata(pdev, NULL);
1665
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001666 qlcnic_free_adapter_resources(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001667 free_netdev(netdev);
1668}
1669static int __qlcnic_shutdown(struct pci_dev *pdev)
1670{
1671 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1672 struct net_device *netdev = adapter->netdev;
1673 int retval;
1674
1675 netif_device_detach(netdev);
1676
1677 qlcnic_cancel_fw_work(adapter);
1678
1679 if (netif_running(netdev))
1680 qlcnic_down(adapter, netdev);
1681
Sony Chacko97ee45e2012-12-04 03:33:52 +00001682 if (qlcnic_82xx_check(adapter))
1683 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001684
1685 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1686
1687 retval = pci_save_state(pdev);
1688 if (retval)
1689 return retval;
1690
Sony Chacko97ee45e2012-12-04 03:33:52 +00001691 if (qlcnic_82xx_check(adapter)) {
1692 if (qlcnic_wol_supported(adapter)) {
1693 pci_enable_wake(pdev, PCI_D3cold, 1);
1694 pci_enable_wake(pdev, PCI_D3hot, 1);
1695 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001696 }
1697
1698 return 0;
1699}
1700
1701static void qlcnic_shutdown(struct pci_dev *pdev)
1702{
1703 if (__qlcnic_shutdown(pdev))
1704 return;
1705
1706 pci_disable_device(pdev);
1707}
1708
1709#ifdef CONFIG_PM
1710static int
1711qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1712{
1713 int retval;
1714
1715 retval = __qlcnic_shutdown(pdev);
1716 if (retval)
1717 return retval;
1718
1719 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1720 return 0;
1721}
1722
1723static int
1724qlcnic_resume(struct pci_dev *pdev)
1725{
1726 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1727 struct net_device *netdev = adapter->netdev;
1728 int err;
1729
1730 err = pci_enable_device(pdev);
1731 if (err)
1732 return err;
1733
1734 pci_set_power_state(pdev, PCI_D0);
1735 pci_set_master(pdev);
1736 pci_restore_state(pdev);
1737
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001738 err = adapter->nic_ops->start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001739 if (err) {
1740 dev_err(&pdev->dev, "failed to start firmware\n");
1741 return err;
1742 }
1743
1744 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001745 err = qlcnic_up(adapter, netdev);
1746 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001747 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001748
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00001749 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001750 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001751done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001752 netif_device_attach(netdev);
1753 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1754 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001755}
1756#endif
1757
1758static int qlcnic_open(struct net_device *netdev)
1759{
1760 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001761 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001762 int err;
1763
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00001764 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
1765 netdev_err(netdev, "Device in FAILED state\n");
1766 return -EIO;
1767 }
1768
Amit Kumar Salechac55ad8e2011-06-22 02:52:21 +00001769 netif_carrier_off(netdev);
1770
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001771 err = qlcnic_attach(adapter);
1772 if (err)
1773 return err;
1774
1775 err = __qlcnic_up(adapter, netdev);
1776 if (err)
1777 goto err_out;
1778
1779 netif_start_queue(netdev);
1780
1781 return 0;
1782
1783err_out:
1784 qlcnic_detach(adapter);
1785 return err;
1786}
1787
1788/*
1789 * qlcnic_close - Disables a network interface entry point
1790 */
1791static int qlcnic_close(struct net_device *netdev)
1792{
1793 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1794
1795 __qlcnic_down(adapter, netdev);
1796 return 0;
1797}
1798
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001799void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001800{
1801 void *head;
1802 int i;
1803
Sucheta Chakrabortye5dcf6d2011-07-14 03:16:52 +00001804 if (adapter->fhash.fmax && adapter->fhash.fhead)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001805 return;
1806
1807 spin_lock_init(&adapter->mac_learn_lock);
1808
1809 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1810 GFP_KERNEL);
1811 if (!head)
1812 return;
1813
1814 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
Joe Perches43d620c2011-06-16 19:08:06 +00001815 adapter->fhash.fhead = head;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001816
1817 for (i = 0; i < adapter->fhash.fmax; i++)
1818 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1819}
1820
1821static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1822{
1823 if (adapter->fhash.fmax && adapter->fhash.fhead)
1824 kfree(adapter->fhash.fhead);
1825
1826 adapter->fhash.fhead = NULL;
1827 adapter->fhash.fmax = 0;
1828}
1829
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001830static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
1831{
1832 struct net_device *netdev = adapter->netdev;
Sony Chacko97ee45e2012-12-04 03:33:52 +00001833 u32 temp_state, temp_val, temp = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001834 int rv = 0;
1835
Sony Chacko97ee45e2012-12-04 03:33:52 +00001836 if (qlcnic_82xx_check(adapter))
1837 temp = QLCRD32(adapter, CRB_TEMP_STATE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001838
1839 temp_state = qlcnic_get_temp_state(temp);
1840 temp_val = qlcnic_get_temp_val(temp);
1841
1842 if (temp_state == QLCNIC_TEMP_PANIC) {
1843 dev_err(&netdev->dev,
1844 "Device temperature %d degrees C exceeds"
1845 " maximum allowed. Hardware has been shut down.\n",
1846 temp_val);
1847 rv = 1;
1848 } else if (temp_state == QLCNIC_TEMP_WARN) {
1849 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
1850 dev_err(&netdev->dev,
1851 "Device temperature %d degrees C "
1852 "exceeds operating range."
1853 " Immediate action needed.\n",
1854 temp_val);
1855 }
1856 } else {
1857 if (adapter->temp == QLCNIC_TEMP_WARN) {
1858 dev_info(&netdev->dev,
1859 "Device temperature is now %d degrees C"
1860 " in normal range.\n", temp_val);
1861 }
1862 }
1863 adapter->temp = temp_state;
1864 return rv;
1865}
1866
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001867static void qlcnic_tx_timeout(struct net_device *netdev)
1868{
1869 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1870
1871 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1872 return;
1873
1874 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001875
1876 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001877 adapter->need_fw_reset = 1;
1878 else
1879 adapter->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001880}
1881
1882static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
1883{
1884 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1885 struct net_device_stats *stats = &netdev->stats;
1886
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001887 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
1888 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00001889 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001890 stats->tx_bytes = adapter->stats.txbytes;
1891 stats->rx_dropped = adapter->stats.rxdropped;
1892 stats->tx_dropped = adapter->stats.txdropped;
1893
1894 return stats;
1895}
1896
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001897static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001898{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001899 u32 status;
1900
1901 status = readl(adapter->isr_int_vec);
1902
1903 if (!(status & adapter->int_vec_bit))
1904 return IRQ_NONE;
1905
1906 /* check interrupt state machine, to be sure */
1907 status = readl(adapter->crb_int_state_reg);
1908 if (!ISR_LEGACY_INT_TRIGGERED(status))
1909 return IRQ_NONE;
1910
1911 writel(0xffffffff, adapter->tgt_status_reg);
1912 /* read twice to ensure write is flushed */
1913 readl(adapter->isr_int_vec);
1914 readl(adapter->isr_int_vec);
1915
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001916 return IRQ_HANDLED;
1917}
1918
1919static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
1920{
1921 struct qlcnic_host_sds_ring *sds_ring = data;
1922 struct qlcnic_adapter *adapter = sds_ring->adapter;
1923
1924 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1925 goto done;
1926 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
1927 writel(0xffffffff, adapter->tgt_status_reg);
1928 goto done;
1929 }
1930
1931 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
1932 return IRQ_NONE;
1933
1934done:
1935 adapter->diag_cnt++;
1936 qlcnic_enable_int(sds_ring);
1937 return IRQ_HANDLED;
1938}
1939
1940static irqreturn_t qlcnic_intr(int irq, void *data)
1941{
1942 struct qlcnic_host_sds_ring *sds_ring = data;
1943 struct qlcnic_adapter *adapter = sds_ring->adapter;
1944
1945 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
1946 return IRQ_NONE;
1947
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001948 napi_schedule(&sds_ring->napi);
1949
1950 return IRQ_HANDLED;
1951}
1952
1953static irqreturn_t qlcnic_msi_intr(int irq, void *data)
1954{
1955 struct qlcnic_host_sds_ring *sds_ring = data;
1956 struct qlcnic_adapter *adapter = sds_ring->adapter;
1957
1958 /* clear interrupt */
1959 writel(0xffffffff, adapter->tgt_status_reg);
1960
1961 napi_schedule(&sds_ring->napi);
1962 return IRQ_HANDLED;
1963}
1964
1965static irqreturn_t qlcnic_msix_intr(int irq, void *data)
1966{
1967 struct qlcnic_host_sds_ring *sds_ring = data;
1968
1969 napi_schedule(&sds_ring->napi);
1970 return IRQ_HANDLED;
1971}
1972
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001973#ifdef CONFIG_NET_POLL_CONTROLLER
1974static void qlcnic_poll_controller(struct net_device *netdev)
1975{
Yinglin Luanbf827912010-08-22 21:57:56 +00001976 int ring;
1977 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001978 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakrabortyb1fc6d32011-04-01 14:28:05 +00001979 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Yinglin Luanbf827912010-08-22 21:57:56 +00001980
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001981 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00001982 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1983 sds_ring = &recv_ctx->sds_rings[ring];
1984 qlcnic_intr(adapter->irq, sds_ring);
1985 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001986 enable_irq(adapter->irq);
1987}
1988#endif
1989
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001990static void
1991qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
1992{
1993 u32 val;
1994
1995 val = adapter->portnum & 0xf;
1996 val |= encoding << 7;
1997 val |= (jiffies - adapter->dev_rst_time) << 8;
1998
1999 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2000 adapter->dev_rst_time = jiffies;
2001}
2002
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002003static int
2004qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002005{
2006 u32 val;
2007
2008 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2009 state != QLCNIC_DEV_NEED_QUISCENT);
2010
2011 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002012 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002013
2014 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2015
2016 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002017 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002018 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002019 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002020
2021 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2022
2023 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002024
2025 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002026}
2027
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002028static int
2029qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2030{
2031 u32 val;
2032
2033 if (qlcnic_api_lock(adapter))
2034 return -EBUSY;
2035
2036 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002037 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002038 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2039
2040 qlcnic_api_unlock(adapter);
2041
2042 return 0;
2043}
2044
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002045static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002046qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002047{
2048 u32 val;
2049
2050 if (qlcnic_api_lock(adapter))
2051 goto err;
2052
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002053 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002054 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002055 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002056
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002057 if (failed) {
2058 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2059 dev_info(&adapter->pdev->dev,
2060 "Device state set to Failed. Please Reboot\n");
2061 } else if (!(val & 0x11111111))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002062 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2063
2064 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002065 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002066 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2067
2068 qlcnic_api_unlock(adapter);
2069err:
2070 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002071 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002072 clear_bit(__QLCNIC_START_FW, &adapter->state);
2073 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2074}
2075
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002076/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002077static int
2078qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2079{
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002080 int act, state, active_mask;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002081
2082 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002083 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002084
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002085 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
2086 active_mask = (~(1 << (adapter->ahw->pci_func * 4)));
2087 act = act & active_mask;
2088 }
2089
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002090 if (((state & 0x11111111) == (act & 0x11111111)) ||
2091 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2092 return 0;
2093 else
2094 return 1;
2095}
2096
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002097static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2098{
2099 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2100
2101 if (val != QLCNIC_DRV_IDC_VER) {
2102 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2103 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2104 }
2105
2106 return 0;
2107}
2108
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002109static int
2110qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2111{
2112 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002113 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002114 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002115 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002116
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002117 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2118 return 1;
2119
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002120 if (qlcnic_api_lock(adapter))
2121 return -1;
2122
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002123 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002124 if (!(val & (1 << (portnum * 4)))) {
2125 QLC_DEV_SET_REF_CNT(val, portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002126 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002127 }
2128
2129 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002130 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002131
2132 switch (prev_state) {
2133 case QLCNIC_DEV_COLD:
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002134 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002135 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002136 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002137 qlcnic_api_unlock(adapter);
2138 return 1;
2139
2140 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002141 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002142 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002143 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002144
2145 case QLCNIC_DEV_NEED_RESET:
2146 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002147 QLC_DEV_SET_RST_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002148 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2149 break;
2150
2151 case QLCNIC_DEV_NEED_QUISCENT:
2152 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002153 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002154 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2155 break;
2156
2157 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002158 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002159 qlcnic_api_unlock(adapter);
2160 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002161
2162 case QLCNIC_DEV_INITIALIZING:
2163 case QLCNIC_DEV_QUISCENT:
2164 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002165 }
2166
2167 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002168
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002169 do {
2170 msleep(1000);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002171 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2172
2173 if (prev_state == QLCNIC_DEV_QUISCENT)
2174 continue;
2175 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002176
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002177 if (!dev_init_timeo) {
2178 dev_err(&adapter->pdev->dev,
2179 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002180 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002181 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002182
2183 if (qlcnic_api_lock(adapter))
2184 return -1;
2185
2186 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002187 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002188 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2189
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002190 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002191 qlcnic_api_unlock(adapter);
2192
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002193 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002194}
2195
2196static void
2197qlcnic_fwinit_work(struct work_struct *work)
2198{
2199 struct qlcnic_adapter *adapter = container_of(work,
2200 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002201 u32 dev_state = 0xf;
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002202 u32 val;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002203
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002204 if (qlcnic_api_lock(adapter))
2205 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002206
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002207 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002208 if (dev_state == QLCNIC_DEV_QUISCENT ||
2209 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002210 qlcnic_api_unlock(adapter);
2211 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2212 FW_POLL_DELAY * 2);
2213 return;
2214 }
2215
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002216 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002217 qlcnic_api_unlock(adapter);
2218 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002219 }
2220
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002221 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2222 dev_state == QLCNIC_DEV_READY) {
2223 dev_info(&adapter->pdev->dev, "Detected state change from "
2224 "DEV_NEED_RESET, skipping ack check\n");
2225 goto skip_ack_check;
2226 }
2227
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002228 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
Sritej Velaga16e3cf72011-10-28 12:57:11 +00002229 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002230 adapter->reset_ack_timeo);
2231 goto skip_ack_check;
2232 }
2233
2234 if (!qlcnic_check_drv_state(adapter)) {
2235skip_ack_check:
2236 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002237
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002238 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2239 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2240 QLCNIC_DEV_INITIALIZING);
2241 set_bit(__QLCNIC_START_FW, &adapter->state);
2242 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002243 qlcnic_idc_debug_info(adapter, 0);
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002244 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2245 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2246 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002247 }
2248
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002249 qlcnic_api_unlock(adapter);
2250
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002251 rtnl_lock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002252 if (adapter->ahw->fw_dump.enable &&
2253 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002254 QLCDB(adapter, DRV, "Take FW dump\n");
2255 qlcnic_dump_fw(adapter);
Sritej Velaga032a13c2011-07-29 13:30:27 +00002256 adapter->flags |= QLCNIC_FW_HANG;
Anirban Chakraborty9d6a6442011-06-22 02:52:22 +00002257 }
Anirban Chakraborty287e38a2011-06-22 02:52:18 +00002258 rtnl_unlock();
Sritej Velaga7b749ff2011-07-14 03:16:50 +00002259
2260 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002261 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002262 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002263 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002264 return;
2265 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002266 goto err_ret;
2267 }
2268
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002269 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002270
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002271wait_npar:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002272 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002273 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002274
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002275 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002276 case QLCNIC_DEV_READY:
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002277 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002278 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002279 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002280 return;
2281 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002282 case QLCNIC_DEV_FAILED:
2283 break;
2284 default:
2285 qlcnic_schedule_work(adapter,
2286 qlcnic_fwinit_work, FW_POLL_DELAY);
2287 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002288 }
2289
2290err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002291 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2292 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002293 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002294 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002295}
2296
2297static void
2298qlcnic_detach_work(struct work_struct *work)
2299{
2300 struct qlcnic_adapter *adapter = container_of(work,
2301 struct qlcnic_adapter, fw_work.work);
2302 struct net_device *netdev = adapter->netdev;
2303 u32 status;
2304
2305 netif_device_detach(netdev);
2306
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002307 /* Dont grab rtnl lock during Quiscent mode */
2308 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2309 if (netif_running(netdev))
2310 __qlcnic_down(adapter, netdev);
2311 } else
2312 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002313
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002314 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2315
Sony Chacko44f65b22011-08-29 12:50:26 +00002316 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2317 dev_err(&adapter->pdev->dev,
2318 "Detaching the device: peg halt status1=0x%x\n",
2319 status);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002320
Sony Chacko44f65b22011-08-29 12:50:26 +00002321 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2322 dev_err(&adapter->pdev->dev,
2323 "On board active cooling fan failed. "
2324 "Device has been halted.\n");
2325 dev_err(&adapter->pdev->dev,
2326 "Replace the adapter.\n");
2327 }
2328
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002329 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002330 }
2331
2332 if (adapter->temp == QLCNIC_TEMP_PANIC) {
2333 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
2334 adapter->temp);
2335 goto err_ret;
2336 }
2337
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002338 /* Dont ack if this instance is the reset owner */
2339 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
Sony Chacko44f65b22011-08-29 12:50:26 +00002340 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2341 dev_err(&adapter->pdev->dev,
2342 "Failed to set driver state,"
2343 "detaching the device.\n");
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002344 goto err_ret;
Sony Chacko44f65b22011-08-29 12:50:26 +00002345 }
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002346 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002347
2348 adapter->fw_wait_cnt = 0;
2349
2350 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2351
2352 return;
2353
2354err_ret:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002355 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002356 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002357}
2358
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002359/*Transit NPAR state to NON Operational */
2360static void
2361qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2362{
2363 u32 state;
2364
2365 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2366 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2367 return;
2368
2369 if (qlcnic_api_lock(adapter))
2370 return;
2371 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2372 qlcnic_api_unlock(adapter);
2373}
2374
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002375/*Transit to RESET state from READY state only */
Anirban Chakraborty18f2f612011-05-12 12:48:33 +00002376void
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002377qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2378{
Sritej Velaga646779f2012-02-03 13:45:41 +00002379 u32 state, xg_val = 0, gb_val = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002380
Sritej Velaga646779f2012-02-03 13:45:41 +00002381 qlcnic_xg_set_xg0_mask(xg_val);
2382 qlcnic_xg_set_xg1_mask(xg_val);
2383 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
2384 qlcnic_gb_set_gb0_mask(gb_val);
2385 qlcnic_gb_set_gb1_mask(gb_val);
2386 qlcnic_gb_set_gb2_mask(gb_val);
2387 qlcnic_gb_set_gb3_mask(gb_val);
2388 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
2389 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
2390 " on all ports\n");
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002391 adapter->need_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002392 if (qlcnic_api_lock(adapter))
2393 return;
2394
2395 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00002396 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
2397 netdev_err(adapter->netdev,
2398 "Device is in FAILED state, Please Reboot\n");
2399 qlcnic_api_unlock(adapter);
2400 return;
2401 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002402
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002403 if (state == QLCNIC_DEV_READY) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002404 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
Sritej Velaga602ca6f2011-06-22 02:52:17 +00002405 adapter->flags |= QLCNIC_FW_RESET_OWNER;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002406 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002407 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002408 }
2409
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002410 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002411 qlcnic_api_unlock(adapter);
2412}
2413
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002414/* Transit to NPAR READY state from NPAR NOT READY state */
2415static void
2416qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2417{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002418 if (qlcnic_api_lock(adapter))
2419 return;
2420
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002421 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2422 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002423
2424 qlcnic_api_unlock(adapter);
2425}
2426
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002427static void
2428qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2429 work_func_t func, int delay)
2430{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002431 if (test_bit(__QLCNIC_AER, &adapter->state))
2432 return;
2433
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002434 INIT_DELAYED_WORK(&adapter->fw_work, func);
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002435 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
2436 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002437}
2438
2439static void
2440qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
2441{
2442 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2443 msleep(10);
2444
Sucheta Chakrabortyb43e5ee2012-04-26 10:31:29 +00002445 if (!adapter->fw_work.work.func)
2446 return;
2447
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002448 cancel_delayed_work_sync(&adapter->fw_work);
2449}
2450
2451static void
2452qlcnic_attach_work(struct work_struct *work)
2453{
2454 struct qlcnic_adapter *adapter = container_of(work,
2455 struct qlcnic_adapter, fw_work.work);
2456 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002457 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002458
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002459 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2460 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2461 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2462 qlcnic_clr_all_drv_state(adapter, 0);
2463 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2464 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2465 FW_POLL_DELAY);
2466 else
2467 goto attach;
2468 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2469 return;
2470 }
2471attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002472 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002473 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002474 goto done;
2475
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002476 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002477 }
2478
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002479done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002480 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002481 adapter->fw_fail_cnt = 0;
Sritej Velaga032a13c2011-07-29 13:30:27 +00002482 adapter->flags &= ~QLCNIC_FW_HANG;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002483 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002484
2485 if (!qlcnic_clr_drv_state(adapter))
2486 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2487 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002488}
2489
2490static int
2491qlcnic_check_health(struct qlcnic_adapter *adapter)
2492{
Sony Chacko4e708122010-08-31 17:17:44 +00002493 u32 state = 0, heartbeat;
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002494 u32 peg_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002495
2496 if (qlcnic_check_temp(adapter))
2497 goto detach;
2498
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00002499 if (adapter->need_fw_reset)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002500 qlcnic_dev_request_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002501
2502 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002503 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002504 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002505 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002506 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2507 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002508
Sony Chacko4e708122010-08-31 17:17:44 +00002509 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
2510 if (heartbeat != adapter->heartbeat) {
2511 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002512 adapter->fw_fail_cnt = 0;
2513 if (adapter->need_fw_reset)
2514 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002515
amit salecha9ce13ca2011-02-23 03:21:24 +00002516 if (adapter->reset_context && auto_fw_reset) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002517 qlcnic_reset_hw_context(adapter);
2518 adapter->netdev->trans_start = jiffies;
2519 }
2520
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002521 return 0;
2522 }
2523
2524 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2525 return 0;
2526
Sritej Velaga032a13c2011-07-29 13:30:27 +00002527 adapter->flags |= QLCNIC_FW_HANG;
2528
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002529 qlcnic_dev_request_reset(adapter);
2530
amit salecha9ce13ca2011-02-23 03:21:24 +00002531 if (auto_fw_reset)
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00002532 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002533
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002534 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
2535 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
Sritej Velagac76ecb72011-07-29 13:30:29 +00002536 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
2537 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
2538 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
2539 "PEG_NET_4_PC: 0x%x\n",
2540 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1),
2541 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2),
2542 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
2543 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
2544 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
2545 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
2546 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002547 peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
Sritej Velaga97048a12012-02-03 13:45:43 +00002548 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
Ameen Rahman853d4bc2011-09-13 08:06:17 +00002549 dev_err(&adapter->pdev->dev,
2550 "Firmware aborted with error code 0x00006700. "
2551 "Device is being reset.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002552detach:
2553 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
2554 QLCNIC_DEV_NEED_RESET;
2555
amit salecha9ce13ca2011-02-23 03:21:24 +00002556 if (auto_fw_reset &&
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002557 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
2558
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002559 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002560 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
2561 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002562
2563 return 1;
2564}
2565
2566static void
2567qlcnic_fw_poll_work(struct work_struct *work)
2568{
2569 struct qlcnic_adapter *adapter = container_of(work,
2570 struct qlcnic_adapter, fw_work.work);
2571
2572 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2573 goto reschedule;
2574
2575
2576 if (qlcnic_check_health(adapter))
2577 return;
2578
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002579 if (adapter->fhash.fnum)
2580 qlcnic_prune_lb_filters(adapter);
2581
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002582reschedule:
2583 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2584}
2585
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002586static int qlcnic_is_first_func(struct pci_dev *pdev)
2587{
2588 struct pci_dev *oth_pdev;
2589 int val = pdev->devfn;
2590
2591 while (val-- > 0) {
2592 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
2593 (pdev->bus), pdev->bus->number,
2594 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002595 if (!oth_pdev)
2596 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002597
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002598 if (oth_pdev->current_state != PCI_D3cold) {
2599 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002600 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07002601 }
2602 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002603 }
2604 return 1;
2605}
2606
2607static int qlcnic_attach_func(struct pci_dev *pdev)
2608{
2609 int err, first_func;
2610 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2611 struct net_device *netdev = adapter->netdev;
2612
2613 pdev->error_state = pci_channel_io_normal;
2614
2615 err = pci_enable_device(pdev);
2616 if (err)
2617 return err;
2618
2619 pci_set_power_state(pdev, PCI_D0);
2620 pci_set_master(pdev);
2621 pci_restore_state(pdev);
2622
2623 first_func = qlcnic_is_first_func(pdev);
2624
2625 if (qlcnic_api_lock(adapter))
2626 return -EINVAL;
2627
Amit Kumar Salecha933fce122010-08-17 00:34:19 +00002628 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002629 adapter->need_fw_reset = 1;
2630 set_bit(__QLCNIC_START_FW, &adapter->state);
2631 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2632 QLCDB(adapter, DRV, "Restarting fw\n");
2633 }
2634 qlcnic_api_unlock(adapter);
2635
2636 err = adapter->nic_ops->start_firmware(adapter);
2637 if (err)
2638 return err;
2639
2640 qlcnic_clr_drv_state(adapter);
2641 qlcnic_setup_intr(adapter);
2642
2643 if (netif_running(netdev)) {
2644 err = qlcnic_attach(adapter);
2645 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002646 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002647 clear_bit(__QLCNIC_AER, &adapter->state);
2648 netif_device_attach(netdev);
2649 return err;
2650 }
2651
2652 err = qlcnic_up(adapter, netdev);
2653 if (err)
2654 goto done;
2655
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002656 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002657 }
2658 done:
2659 netif_device_attach(netdev);
2660 return err;
2661}
2662
2663static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
2664 pci_channel_state_t state)
2665{
2666 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2667 struct net_device *netdev = adapter->netdev;
2668
2669 if (state == pci_channel_io_perm_failure)
2670 return PCI_ERS_RESULT_DISCONNECT;
2671
2672 if (state == pci_channel_io_normal)
2673 return PCI_ERS_RESULT_RECOVERED;
2674
2675 set_bit(__QLCNIC_AER, &adapter->state);
2676 netif_device_detach(netdev);
2677
2678 cancel_delayed_work_sync(&adapter->fw_work);
2679
2680 if (netif_running(netdev))
2681 qlcnic_down(adapter, netdev);
2682
2683 qlcnic_detach(adapter);
2684 qlcnic_teardown_intr(adapter);
2685
2686 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2687
2688 pci_save_state(pdev);
2689 pci_disable_device(pdev);
2690
2691 return PCI_ERS_RESULT_NEED_RESET;
2692}
2693
2694static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
2695{
2696 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
2697 PCI_ERS_RESULT_RECOVERED;
2698}
2699
2700static void qlcnic_io_resume(struct pci_dev *pdev)
2701{
2702 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2703
2704 pci_cleanup_aer_uncorrect_error_status(pdev);
2705
2706 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
2707 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
2708 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2709 FW_POLL_DELAY);
2710}
2711
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002712static int
2713qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
2714{
2715 int err;
2716
2717 err = qlcnic_can_start_firmware(adapter);
2718 if (err)
2719 return err;
2720
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00002721 err = qlcnic_check_npar_opertional(adapter);
2722 if (err)
2723 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002724
Rajesh Borundia174240a2010-08-31 17:17:47 +00002725 err = qlcnic_initialize_nic(adapter);
2726 if (err)
2727 return err;
2728
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002729 qlcnic_check_options(adapter);
2730
Rajesh Borundia73733732010-08-31 17:17:50 +00002731 err = qlcnic_set_eswitch_port_config(adapter);
2732 if (err)
2733 return err;
2734
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00002735 adapter->need_fw_reset = 0;
2736
2737 return err;
2738}
2739
Sucheta Chakrabortyf94bc1e2011-04-28 11:48:18 +00002740int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val)
2741{
2742 if (!use_msi_x && !use_msi) {
2743 netdev_info(netdev, "no msix or msi support, hence no rss\n");
2744 return -EINVAL;
2745 }
2746
2747 if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) {
2748 netdev_info(netdev, "rss_ring valid range [2 - %x] in "
2749 " powers of 2\n", max_hw);
2750 return -EINVAL;
2751 }
2752 return 0;
2753
2754}
2755
2756int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data)
2757{
2758 struct net_device *netdev = adapter->netdev;
2759 int err = 0;
2760
2761 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2762 return -EBUSY;
2763
2764 netif_device_detach(netdev);
2765 if (netif_running(netdev))
2766 __qlcnic_down(adapter, netdev);
2767 qlcnic_detach(adapter);
2768 qlcnic_teardown_intr(adapter);
2769
2770 if (qlcnic_enable_msix(adapter, data)) {
2771 netdev_info(netdev, "failed setting max_rss; rss disabled\n");
2772 qlcnic_enable_msi_legacy(adapter);
2773 }
2774
2775 if (netif_running(netdev)) {
2776 err = qlcnic_attach(adapter);
2777 if (err)
2778 goto done;
2779 err = __qlcnic_up(adapter, netdev);
2780 if (err)
2781 goto done;
2782 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2783 }
2784 done:
2785 netif_device_attach(netdev);
2786 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2787 return err;
2788}
2789
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002790#ifdef CONFIG_INET
2791
2792#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
2793
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002794static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002795qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
2796 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002797{
2798 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002799
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002800 indev = in_dev_get(dev);
2801 if (!indev)
2802 return;
2803
2804 for_ifa(indev) {
2805 switch (event) {
2806 case NETDEV_UP:
2807 qlcnic_config_ipaddr(adapter,
2808 ifa->ifa_address, QLCNIC_IP_UP);
2809 break;
2810 case NETDEV_DOWN:
2811 qlcnic_config_ipaddr(adapter,
2812 ifa->ifa_address, QLCNIC_IP_DOWN);
2813 break;
2814 default:
2815 break;
2816 }
2817 } endfor_ifa(indev);
2818
2819 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002820}
2821
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002822static void
2823qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
2824{
2825 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2826 struct net_device *dev;
2827 u16 vid;
2828
2829 qlcnic_config_indev_addr(adapter, netdev, event);
2830
Anirban Chakrabortyb9796a12011-04-01 14:28:15 +00002831 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
Jiri Pirko223bb152011-07-20 04:54:44 +00002832 dev = __vlan_find_dev_deep(netdev, vid);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002833 if (!dev)
2834 continue;
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002835 qlcnic_config_indev_addr(adapter, dev, event);
2836 }
2837}
2838
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002839static int qlcnic_netdev_event(struct notifier_block *this,
2840 unsigned long event, void *ptr)
2841{
2842 struct qlcnic_adapter *adapter;
2843 struct net_device *dev = (struct net_device *)ptr;
2844
2845recheck:
2846 if (dev == NULL)
2847 goto done;
2848
2849 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2850 dev = vlan_dev_real_dev(dev);
2851 goto recheck;
2852 }
2853
2854 if (!is_qlcnic_netdev(dev))
2855 goto done;
2856
2857 adapter = netdev_priv(dev);
2858
2859 if (!adapter)
2860 goto done;
2861
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002862 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002863 goto done;
2864
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002865 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002866done:
2867 return NOTIFY_DONE;
2868}
2869
2870static int
2871qlcnic_inetaddr_event(struct notifier_block *this,
2872 unsigned long event, void *ptr)
2873{
2874 struct qlcnic_adapter *adapter;
2875 struct net_device *dev;
2876
2877 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
2878
2879 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
2880
2881recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002882 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002883 goto done;
2884
2885 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2886 dev = vlan_dev_real_dev(dev);
2887 goto recheck;
2888 }
2889
2890 if (!is_qlcnic_netdev(dev))
2891 goto done;
2892
2893 adapter = netdev_priv(dev);
2894
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00002895 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002896 goto done;
2897
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00002898 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002899 goto done;
2900
2901 switch (event) {
2902 case NETDEV_UP:
2903 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
2904 break;
2905 case NETDEV_DOWN:
2906 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
2907 break;
2908 default:
2909 break;
2910 }
2911
2912done:
2913 return NOTIFY_DONE;
2914}
2915
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002916static struct notifier_block qlcnic_netdev_cb = {
2917 .notifier_call = qlcnic_netdev_event,
2918};
2919
2920static struct notifier_block qlcnic_inetaddr_cb = {
2921 .notifier_call = qlcnic_inetaddr_event,
2922};
2923#else
2924static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002925qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002926{ }
2927#endif
Shahed Shaikh63507592012-11-23 23:56:52 +00002928static struct pci_error_handlers qlcnic_err_handler = {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002929 .error_detected = qlcnic_io_error_detected,
2930 .slot_reset = qlcnic_io_slot_reset,
2931 .resume = qlcnic_io_resume,
2932};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002933
2934static struct pci_driver qlcnic_driver = {
2935 .name = qlcnic_driver_name,
2936 .id_table = qlcnic_pci_tbl,
2937 .probe = qlcnic_probe,
Bill Pemberton6bb58bb2012-12-03 09:23:25 -05002938 .remove = qlcnic_remove,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002939#ifdef CONFIG_PM
2940 .suspend = qlcnic_suspend,
2941 .resume = qlcnic_resume,
2942#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002943 .shutdown = qlcnic_shutdown,
2944 .err_handler = &qlcnic_err_handler
2945
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002946};
2947
2948static int __init qlcnic_init_module(void)
2949{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002950 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002951
2952 printk(KERN_INFO "%s\n", qlcnic_driver_string);
2953
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002954 qlcnic_wq = create_singlethread_workqueue("qlcnic");
2955 if (qlcnic_wq == NULL) {
2956 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
2957 return -ENOMEM;
2958 }
2959
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002960#ifdef CONFIG_INET
2961 register_netdevice_notifier(&qlcnic_netdev_cb);
2962 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
2963#endif
2964
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002965 ret = pci_register_driver(&qlcnic_driver);
2966 if (ret) {
2967#ifdef CONFIG_INET
2968 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
2969 unregister_netdevice_notifier(&qlcnic_netdev_cb);
2970#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002971 destroy_workqueue(qlcnic_wq);
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002972 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002973
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00002974 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002975}
2976
2977module_init(qlcnic_init_module);
2978
2979static void __exit qlcnic_exit_module(void)
2980{
2981
2982 pci_unregister_driver(&qlcnic_driver);
2983
2984#ifdef CONFIG_INET
2985 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
2986 unregister_netdevice_notifier(&qlcnic_netdev_cb);
2987#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002988 destroy_workqueue(qlcnic_wq);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002989}
2990
2991module_exit(qlcnic_exit_module);