blob: a3dcd04be22f6291e2546f84e474cef31e7fae34 [file] [log] [blame]
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001/*
2 * Copyright (C) 2009 - QLogic Corporation.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
19 *
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
22 *
23 */
24
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000026#include <linux/vmalloc.h>
27#include <linux/interrupt.h>
28
29#include "qlcnic.h"
30
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +000031#include <linux/swab.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000032#include <linux/dma-mapping.h>
33#include <linux/if_vlan.h>
34#include <net/ip.h>
35#include <linux/ipv6.h>
36#include <linux/inetdevice.h>
37#include <linux/sysfs.h>
Sucheta Chakraborty451724c2010-07-13 20:33:34 +000038#include <linux/aer.h>
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000039
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000040MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000041MODULE_LICENSE("GPL");
42MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
43MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
44
45char qlcnic_driver_name[] = "qlcnic";
Sritej Velaga7f9a0c32010-06-17 02:56:39 +000046static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
47 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000048
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +000049static struct workqueue_struct *qlcnic_wq;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +000050static int qlcnic_mac_learn;
51module_param(qlcnic_mac_learn, int, 0644);
52MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
53
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000054static int use_msi = 1;
55module_param(use_msi, int, 0644);
56MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
57
58static int use_msi_x = 1;
59module_param(use_msi_x, int, 0644);
60MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
61
62static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
63module_param(auto_fw_reset, int, 0644);
64MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
65
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +000066static int load_fw_file;
67module_param(load_fw_file, int, 0644);
68MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
69
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +000070static int qlcnic_config_npars;
71module_param(qlcnic_config_npars, int, 0644);
72MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
73
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000074static int __devinit qlcnic_probe(struct pci_dev *pdev,
75 const struct pci_device_id *ent);
76static void __devexit qlcnic_remove(struct pci_dev *pdev);
77static int qlcnic_open(struct net_device *netdev);
78static int qlcnic_close(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000079static void qlcnic_tx_timeout(struct net_device *netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000080static void qlcnic_attach_work(struct work_struct *work);
81static void qlcnic_fwinit_work(struct work_struct *work);
82static void qlcnic_fw_poll_work(struct work_struct *work);
83static void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
84 work_func_t func, int delay);
85static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter);
86static int qlcnic_poll(struct napi_struct *napi, int budget);
schacko8f891382010-06-17 02:56:40 +000087static int qlcnic_rx_poll(struct napi_struct *napi, int budget);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000088#ifdef CONFIG_NET_POLL_CONTROLLER
89static void qlcnic_poll_controller(struct net_device *netdev);
90#endif
91
92static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter);
93static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter);
94static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter);
95static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter);
96
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +000097static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +000098static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +000099static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
100
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +0000101static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000102static irqreturn_t qlcnic_intr(int irq, void *data);
103static irqreturn_t qlcnic_msi_intr(int irq, void *data);
104static irqreturn_t qlcnic_msix_intr(int irq, void *data);
105
106static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +0000107static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000108static int qlcnic_start_firmware(struct qlcnic_adapter *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000109
Amit Kumar Salechab5e54922010-08-31 17:17:51 +0000110static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter);
111static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000112static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000113static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
114static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
115static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000116static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
117 struct qlcnic_esw_func_cfg *);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000118/* PCI Device ID Table */
119#define ENTRY(device) \
120 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
121 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
122
123#define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
124
Amit Kumar Salecha6a902882010-02-01 05:24:54 +0000125static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000126 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
127 {0,}
128};
129
130MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
131
132
133void
134qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
135 struct qlcnic_host_tx_ring *tx_ring)
136{
137 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000138}
139
140static const u32 msi_tgt_status[8] = {
141 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
142 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
143 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
144 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
145};
146
147static const
148struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
149
150static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring)
151{
152 writel(0, sds_ring->crb_intr_mask);
153}
154
155static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring)
156{
157 struct qlcnic_adapter *adapter = sds_ring->adapter;
158
159 writel(0x1, sds_ring->crb_intr_mask);
160
161 if (!QLCNIC_IS_MSI_FAMILY(adapter))
162 writel(0xfbff, adapter->tgt_mask_reg);
163}
164
165static int
166qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
167{
168 int size = sizeof(struct qlcnic_host_sds_ring) * count;
169
170 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
171
Eric Dumazet807540b2010-09-23 05:40:09 +0000172 return recv_ctx->sds_rings == NULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000173}
174
175static void
176qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
177{
178 if (recv_ctx->sds_rings != NULL)
179 kfree(recv_ctx->sds_rings);
180
181 recv_ctx->sds_rings = NULL;
182}
183
184static int
185qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev)
186{
187 int ring;
188 struct qlcnic_host_sds_ring *sds_ring;
189 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
190
191 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
192 return -ENOMEM;
193
194 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
195 sds_ring = &recv_ctx->sds_rings[ring];
schacko8f891382010-06-17 02:56:40 +0000196
197 if (ring == adapter->max_sds_rings - 1)
198 netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll,
199 QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings);
200 else
201 netif_napi_add(netdev, &sds_ring->napi,
202 qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000203 }
204
205 return 0;
206}
207
208static void
209qlcnic_napi_del(struct qlcnic_adapter *adapter)
210{
211 int ring;
212 struct qlcnic_host_sds_ring *sds_ring;
213 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
214
215 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
216 sds_ring = &recv_ctx->sds_rings[ring];
217 netif_napi_del(&sds_ring->napi);
218 }
219
220 qlcnic_free_sds_rings(&adapter->recv_ctx);
221}
222
223static void
224qlcnic_napi_enable(struct qlcnic_adapter *adapter)
225{
226 int ring;
227 struct qlcnic_host_sds_ring *sds_ring;
228 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
229
Amit Kumar Salecha780ab792010-04-22 02:51:41 +0000230 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
231 return;
232
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000233 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
234 sds_ring = &recv_ctx->sds_rings[ring];
235 napi_enable(&sds_ring->napi);
236 qlcnic_enable_int(sds_ring);
237 }
238}
239
240static void
241qlcnic_napi_disable(struct qlcnic_adapter *adapter)
242{
243 int ring;
244 struct qlcnic_host_sds_ring *sds_ring;
245 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
246
Amit Kumar Salecha780ab792010-04-22 02:51:41 +0000247 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
248 return;
249
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000250 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
251 sds_ring = &recv_ctx->sds_rings[ring];
252 qlcnic_disable_int(sds_ring);
253 napi_synchronize(&sds_ring->napi);
254 napi_disable(&sds_ring->napi);
255 }
256}
257
258static void qlcnic_clear_stats(struct qlcnic_adapter *adapter)
259{
260 memset(&adapter->stats, 0, sizeof(adapter->stats));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000261}
262
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000263static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable)
264{
265 u32 control;
266 int pos;
267
268 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
269 if (pos) {
270 pci_read_config_dword(pdev, pos, &control);
271 if (enable)
272 control |= PCI_MSIX_FLAGS_ENABLE;
273 else
274 control = 0;
275 pci_write_config_dword(pdev, pos, control);
276 }
277}
278
279static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count)
280{
281 int i;
282
283 for (i = 0; i < count; i++)
284 adapter->msix_entries[i].entry = i;
285}
286
287static int
288qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
289{
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000290 u8 mac_addr[ETH_ALEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000291 struct net_device *netdev = adapter->netdev;
292 struct pci_dev *pdev = adapter->pdev;
293
Rajesh Borundiada48e6c2010-08-31 17:17:46 +0000294 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000295 return -EIO;
296
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000297 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000298 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
299 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
300
301 /* set station address */
302
303 if (!is_valid_ether_addr(netdev->perm_addr))
304 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
305 netdev->dev_addr);
306
307 return 0;
308}
309
310static int qlcnic_set_mac(struct net_device *netdev, void *p)
311{
312 struct qlcnic_adapter *adapter = netdev_priv(netdev);
313 struct sockaddr *addr = p;
314
Rajesh Borundia73733732010-08-31 17:17:50 +0000315 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
316 return -EOPNOTSUPP;
317
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000318 if (!is_valid_ether_addr(addr->sa_data))
319 return -EINVAL;
320
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000321 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000322 netif_device_detach(netdev);
323 qlcnic_napi_disable(adapter);
324 }
325
326 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
327 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
328 qlcnic_set_multi(adapter->netdev);
329
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +0000330 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000331 netif_device_attach(netdev);
332 qlcnic_napi_enable(adapter);
333 }
334 return 0;
335}
336
Amit Kumar Salechad5790662010-09-16 19:14:39 +0000337static void qlcnic_vlan_rx_register(struct net_device *netdev,
338 struct vlan_group *grp)
339{
340 struct qlcnic_adapter *adapter = netdev_priv(netdev);
341 adapter->vlgrp = grp;
342}
343
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000344static const struct net_device_ops qlcnic_netdev_ops = {
345 .ndo_open = qlcnic_open,
346 .ndo_stop = qlcnic_close,
347 .ndo_start_xmit = qlcnic_xmit_frame,
348 .ndo_get_stats = qlcnic_get_stats,
349 .ndo_validate_addr = eth_validate_addr,
350 .ndo_set_multicast_list = qlcnic_set_multi,
351 .ndo_set_mac_address = qlcnic_set_mac,
352 .ndo_change_mtu = qlcnic_change_mtu,
353 .ndo_tx_timeout = qlcnic_tx_timeout,
Amit Kumar Salechad5790662010-09-16 19:14:39 +0000354 .ndo_vlan_rx_register = qlcnic_vlan_rx_register,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000355#ifdef CONFIG_NET_POLL_CONTROLLER
356 .ndo_poll_controller = qlcnic_poll_controller,
357#endif
358};
359
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000360static struct qlcnic_nic_template qlcnic_ops = {
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000361 .config_bridged_mode = qlcnic_config_bridged_mode,
362 .config_led = qlcnic_config_led,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000363 .start_firmware = qlcnic_start_firmware
364};
365
366static struct qlcnic_nic_template qlcnic_vf_ops = {
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000367 .config_bridged_mode = qlcnicvf_config_bridged_mode,
368 .config_led = qlcnicvf_config_led,
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000369 .start_firmware = qlcnicvf_start_firmware
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000370};
371
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000372static void
373qlcnic_setup_intr(struct qlcnic_adapter *adapter)
374{
375 const struct qlcnic_legacy_intr_set *legacy_intrp;
376 struct pci_dev *pdev = adapter->pdev;
377 int err, num_msix;
378
379 if (adapter->rss_supported) {
380 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
381 MSIX_ENTRIES_PER_ADAPTER : 2;
382 } else
383 num_msix = 1;
384
385 adapter->max_sds_rings = 1;
386
387 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
388
389 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
390
391 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
392 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
393 legacy_intrp->tgt_status_reg);
394 adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter,
395 legacy_intrp->tgt_mask_reg);
396 adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR);
397
398 adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter,
399 ISR_INT_STATE_REG);
400
401 qlcnic_set_msix_bit(pdev, 0);
402
403 if (adapter->msix_supported) {
404
405 qlcnic_init_msix_entries(adapter, num_msix);
406 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
407 if (err == 0) {
408 adapter->flags |= QLCNIC_MSIX_ENABLED;
409 qlcnic_set_msix_bit(pdev, 1);
410
411 if (adapter->rss_supported)
412 adapter->max_sds_rings = num_msix;
413
414 dev_info(&pdev->dev, "using msi-x interrupts\n");
415 return;
416 }
417
418 if (err > 0)
419 pci_disable_msix(pdev);
420
421 /* fall through for msi */
422 }
423
424 if (use_msi && !pci_enable_msi(pdev)) {
425 adapter->flags |= QLCNIC_MSI_ENABLED;
426 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
427 msi_tgt_status[adapter->ahw.pci_func]);
428 dev_info(&pdev->dev, "using msi interrupts\n");
429 adapter->msix_entries[0].vector = pdev->irq;
430 return;
431 }
432
433 dev_info(&pdev->dev, "using legacy interrupts\n");
434 adapter->msix_entries[0].vector = pdev->irq;
435}
436
437static void
438qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
439{
440 if (adapter->flags & QLCNIC_MSIX_ENABLED)
441 pci_disable_msix(adapter->pdev);
442 if (adapter->flags & QLCNIC_MSI_ENABLED)
443 pci_disable_msi(adapter->pdev);
444}
445
446static void
447qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
448{
449 if (adapter->ahw.pci_base0 != NULL)
450 iounmap(adapter->ahw.pci_base0);
451}
452
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000453static int
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000454qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
455{
Dan Carpentere88db3b2010-08-09 21:49:36 +0000456 struct qlcnic_pci_info *pci_info;
Julia Lawall900853a2010-08-16 10:23:51 +0000457 int i, ret = 0;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000458 u8 pfn;
459
Dan Carpentere88db3b2010-08-09 21:49:36 +0000460 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
461 if (!pci_info)
462 return -ENOMEM;
463
Dan Carpenterca315ac2010-08-09 21:47:56 +0000464 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000465 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
Dan Carpentere88db3b2010-08-09 21:49:36 +0000466 if (!adapter->npars) {
Julia Lawall900853a2010-08-16 10:23:51 +0000467 ret = -ENOMEM;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000468 goto err_pci_info;
469 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000470
Dan Carpenterca315ac2010-08-09 21:47:56 +0000471 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000472 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
473 if (!adapter->eswitch) {
Julia Lawall900853a2010-08-16 10:23:51 +0000474 ret = -ENOMEM;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000475 goto err_npars;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000476 }
477
478 ret = qlcnic_get_pci_info(adapter, pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000479 if (ret)
480 goto err_eswitch;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000481
Dan Carpenterca315ac2010-08-09 21:47:56 +0000482 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
483 pfn = pci_info[i].id;
484 if (pfn > QLCNIC_MAX_PCI_FUNC)
485 return QL_STATUS_INVALID_PARAM;
Sucheta Chakrabortya1c0c452010-10-04 04:20:14 +0000486 adapter->npars[pfn].active = (u8)pci_info[i].active;
487 adapter->npars[pfn].type = (u8)pci_info[i].type;
488 adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000489 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
490 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000491 }
492
Dan Carpenterca315ac2010-08-09 21:47:56 +0000493 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
494 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
495
Dan Carpentere88db3b2010-08-09 21:49:36 +0000496 kfree(pci_info);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000497 return 0;
498
499err_eswitch:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000500 kfree(adapter->eswitch);
501 adapter->eswitch = NULL;
Dan Carpenterca315ac2010-08-09 21:47:56 +0000502err_npars:
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000503 kfree(adapter->npars);
Dan Carpenterca315ac2010-08-09 21:47:56 +0000504 adapter->npars = NULL;
Dan Carpentere88db3b2010-08-09 21:49:36 +0000505err_pci_info:
506 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000507
508 return ret;
509}
510
511static int
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000512qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
513{
514 u8 id;
515 u32 ref_count;
516 int i, ret = 1;
517 u32 data = QLCNIC_MGMT_FUNC;
518 void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
519
520 /* If other drivers are not in use set their privilege level */
Amit Kumar Salecha31018e02010-08-25 04:03:05 +0000521 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000522 ret = qlcnic_api_lock(adapter);
523 if (ret)
524 goto err_lock;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000525
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000526 if (qlcnic_config_npars) {
527 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
Rajesh K Borundia346fe762010-06-29 08:01:20 +0000528 id = i;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000529 if (adapter->npars[i].type != QLCNIC_TYPE_NIC ||
530 id == adapter->ahw.pci_func)
531 continue;
532 data |= (qlcnic_config_npars &
533 QLC_DEV_SET_DRV(0xf, id));
534 }
535 } else {
536 data = readl(priv_op);
537 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) |
538 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
539 adapter->ahw.pci_func));
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000540 }
541 writel(data, priv_op);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000542 qlcnic_api_unlock(adapter);
543err_lock:
544 return ret;
545}
546
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000547static void
548qlcnic_check_vf(struct qlcnic_adapter *adapter)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000549{
550 void __iomem *msix_base_addr;
551 void __iomem *priv_op;
552 u32 func;
553 u32 msix_base;
554 u32 op_mode, priv_level;
555
556 /* Determine FW API version */
557 adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000558
559 /* Find PCI function number */
560 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
561 msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE;
562 msix_base = readl(msix_base_addr);
563 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
564 adapter->ahw.pci_func = func;
565
566 /* Determine function privilege level */
567 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
568 op_mode = readl(priv_op);
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000569 if (op_mode == QLC_DEV_DRV_DEFAULT)
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000570 priv_level = QLCNIC_MGMT_FUNC;
Anirban Chakraborty0e33c662010-06-16 09:07:27 +0000571 else
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000572 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
573
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000574 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
Anirban Chakraborty9f26f542010-06-01 11:33:09 +0000575 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
576 dev_info(&adapter->pdev->dev,
577 "HAL Version: %d Non Privileged function\n",
578 adapter->fw_hal_version);
579 adapter->nic_ops = &qlcnic_vf_ops;
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000580 } else
581 adapter->nic_ops = &qlcnic_ops;
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000582}
583
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000584static int
585qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
586{
587 void __iomem *mem_ptr0 = NULL;
588 resource_size_t mem_base;
589 unsigned long mem_len, pci_len0 = 0;
590
591 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000592
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000593 /* remap phys address */
594 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
595 mem_len = pci_resource_len(pdev, 0);
596
597 if (mem_len == QLCNIC_PCI_2MB_SIZE) {
598
599 mem_ptr0 = pci_ioremap_bar(pdev, 0);
600 if (mem_ptr0 == NULL) {
601 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
602 return -EIO;
603 }
604 pci_len0 = mem_len;
605 } else {
606 return -EIO;
607 }
608
609 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
610
611 adapter->ahw.pci_base0 = mem_ptr0;
612 adapter->ahw.pci_len0 = pci_len0;
613
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000614 qlcnic_check_vf(adapter);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000615
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000616 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter,
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +0000617 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func)));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000618
619 return 0;
620}
621
622static void get_brd_name(struct qlcnic_adapter *adapter, char *name)
623{
624 struct pci_dev *pdev = adapter->pdev;
625 int i, found = 0;
626
627 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
628 if (qlcnic_boards[i].vendor == pdev->vendor &&
629 qlcnic_boards[i].device == pdev->device &&
630 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
631 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
Sucheta Chakraborty02f6e462010-05-17 01:22:09 +0000632 sprintf(name, "%pM: %s" ,
633 adapter->mac_addr,
634 qlcnic_boards[i].short_name);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000635 found = 1;
636 break;
637 }
638
639 }
640
641 if (!found)
Sritej Velaga7f9a0c32010-06-17 02:56:39 +0000642 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000643}
644
645static void
646qlcnic_check_options(struct qlcnic_adapter *adapter)
647{
648 u32 fw_major, fw_minor, fw_build;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000649 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000650
651 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
652 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
653 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
654
655 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
656
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +0000657 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
658 fw_major, fw_minor, fw_build);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000659 if (adapter->ahw.port_type == QLCNIC_XGBE) {
Sony Chacko90d19002010-10-26 17:53:08 +0000660 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
661 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
662 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
663 } else {
664 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
665 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
666 }
667
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000668 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
Sony Chacko90d19002010-10-26 17:53:08 +0000669 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
670
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000671 } else if (adapter->ahw.port_type == QLCNIC_GBE) {
672 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
673 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
Sony Chacko90d19002010-10-26 17:53:08 +0000674 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
675 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000676 }
677
678 adapter->msix_supported = !!use_msi_x;
679 adapter->rss_supported = !!use_msi_x;
680
681 adapter->num_txd = MAX_CMD_DESCRIPTORS;
682
Sony Chacko251b0362010-08-19 05:08:24 +0000683 adapter->max_rds_rings = MAX_RDS_RINGS;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000684}
685
Rajesh Borundia174240a2010-08-31 17:17:47 +0000686static int
687qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
688{
689 int err;
690 struct qlcnic_info nic_info;
691
692 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func);
693 if (err)
694 return err;
695
Sucheta Chakrabortya1c0c452010-10-04 04:20:14 +0000696 adapter->physical_port = (u8)nic_info.phys_port;
Rajesh Borundia174240a2010-08-31 17:17:47 +0000697 adapter->switch_mode = nic_info.switch_mode;
698 adapter->max_tx_ques = nic_info.max_tx_ques;
699 adapter->max_rx_ques = nic_info.max_rx_ques;
700 adapter->capabilities = nic_info.capabilities;
701 adapter->max_mac_filters = nic_info.max_mac_filters;
702 adapter->max_mtu = nic_info.max_mtu;
703
704 if (adapter->capabilities & BIT_6)
705 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
706 else
707 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
708
709 return err;
710}
711
Rajesh Borundia0325d692010-08-19 05:08:26 +0000712static void
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000713qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
714 struct qlcnic_esw_func_cfg *esw_cfg)
715{
716 if (esw_cfg->discard_tagged)
717 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
718 else
719 adapter->flags |= QLCNIC_TAGGING_ENABLED;
720
721 if (esw_cfg->vlan_id)
722 adapter->pvid = esw_cfg->vlan_id;
723 else
724 adapter->pvid = 0;
725}
726
727static void
Rajesh Borundia0325d692010-08-19 05:08:26 +0000728qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
729 struct qlcnic_esw_func_cfg *esw_cfg)
730{
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000731 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
732 QLCNIC_PROMISC_DISABLED);
Rajesh Borundia7613c872010-08-31 17:17:48 +0000733
734 if (esw_cfg->mac_anti_spoof)
735 adapter->flags |= QLCNIC_MACSPOOF;
Sony Chackofe4d4342010-08-19 05:08:27 +0000736
Rajesh Borundia73733732010-08-31 17:17:50 +0000737 if (!esw_cfg->mac_override)
738 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
739
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000740 if (!esw_cfg->promisc_mode)
741 adapter->flags |= QLCNIC_PROMISC_DISABLED;
742
Rajesh Borundia0325d692010-08-19 05:08:26 +0000743 qlcnic_set_netdev_features(adapter, esw_cfg);
744}
745
746static int
747qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
748{
749 struct qlcnic_esw_func_cfg esw_cfg;
750
751 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
752 return 0;
753
754 esw_cfg.pci_func = adapter->ahw.pci_func;
755 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
756 return -EIO;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +0000757 qlcnic_set_vlan_config(adapter, &esw_cfg);
Rajesh Borundia0325d692010-08-19 05:08:26 +0000758 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
759
760 return 0;
761}
762
763static void
764qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
765 struct qlcnic_esw_func_cfg *esw_cfg)
766{
767 struct net_device *netdev = adapter->netdev;
768 unsigned long features, vlan_features;
769
770 features = (NETIF_F_SG | NETIF_F_IP_CSUM |
771 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
772 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
773 NETIF_F_IPV6_CSUM);
774
775 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
776 features |= (NETIF_F_TSO | NETIF_F_TSO6);
777 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
778 }
779 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
780 features |= NETIF_F_LRO;
781
782 if (esw_cfg->offload_flags & BIT_0) {
783 netdev->features |= features;
784 adapter->rx_csum = 1;
785 if (!(esw_cfg->offload_flags & BIT_1))
786 netdev->features &= ~NETIF_F_TSO;
787 if (!(esw_cfg->offload_flags & BIT_2))
788 netdev->features &= ~NETIF_F_TSO6;
789 } else {
790 netdev->features &= ~features;
791 adapter->rx_csum = 0;
792 }
793
794 netdev->vlan_features = (features & vlan_features);
795}
796
797static int
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000798qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
799{
800 void __iomem *priv_op;
801 u32 op_mode, priv_level;
802 int err = 0;
803
Rajesh Borundia174240a2010-08-31 17:17:47 +0000804 err = qlcnic_initialize_nic(adapter);
805 if (err)
806 return err;
807
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000808 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
809 return 0;
810
811 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
812 op_mode = readl(priv_op);
813 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
814
815 if (op_mode == QLC_DEV_DRV_DEFAULT)
816 priv_level = QLCNIC_MGMT_FUNC;
817 else
818 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
819
Rajesh Borundia174240a2010-08-31 17:17:47 +0000820 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000821 if (priv_level == QLCNIC_MGMT_FUNC) {
822 adapter->op_mode = QLCNIC_MGMT_FUNC;
823 err = qlcnic_init_pci_info(adapter);
824 if (err)
825 return err;
826 /* Set privilege level for other functions */
827 qlcnic_set_function_modes(adapter);
828 dev_info(&adapter->pdev->dev,
829 "HAL Version: %d, Management function\n",
830 adapter->fw_hal_version);
831 } else if (priv_level == QLCNIC_PRIV_FUNC) {
832 adapter->op_mode = QLCNIC_PRIV_FUNC;
833 dev_info(&adapter->pdev->dev,
834 "HAL Version: %d, Privileged function\n",
835 adapter->fw_hal_version);
836 }
Rajesh Borundia174240a2010-08-31 17:17:47 +0000837 }
Anirban Chakraborty0866d962010-08-26 14:02:52 +0000838
839 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
840
841 return err;
842}
843
844static int
Rajesh Borundia0325d692010-08-19 05:08:26 +0000845qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
846{
847 struct qlcnic_esw_func_cfg esw_cfg;
848 struct qlcnic_npar_info *npar;
849 u8 i;
850
Rajesh Borundia174240a2010-08-31 17:17:47 +0000851 if (adapter->need_fw_reset)
Rajesh Borundia0325d692010-08-19 05:08:26 +0000852 return 0;
853
854 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
855 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
856 continue;
857 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
858 esw_cfg.pci_func = i;
859 esw_cfg.offload_flags = BIT_0;
Rajesh Borundia73733732010-08-31 17:17:50 +0000860 esw_cfg.mac_override = BIT_0;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +0000861 esw_cfg.promisc_mode = BIT_0;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000862 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
863 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
864 if (qlcnic_config_switch_port(adapter, &esw_cfg))
865 return -EIO;
866 npar = &adapter->npars[i];
867 npar->pvid = esw_cfg.vlan_id;
Rajesh Borundia73733732010-08-31 17:17:50 +0000868 npar->mac_override = esw_cfg.mac_override;
Rajesh Borundia0325d692010-08-19 05:08:26 +0000869 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
870 npar->discard_tagged = esw_cfg.discard_tagged;
871 npar->promisc_mode = esw_cfg.promisc_mode;
872 npar->offload_flags = esw_cfg.offload_flags;
873 }
874
875 return 0;
876}
877
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000878static int
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000879qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
880 struct qlcnic_npar_info *npar, int pci_func)
881{
882 struct qlcnic_esw_func_cfg esw_cfg;
883 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
884 esw_cfg.pci_func = pci_func;
885 esw_cfg.vlan_id = npar->pvid;
Rajesh Borundia73733732010-08-31 17:17:50 +0000886 esw_cfg.mac_override = npar->mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000887 esw_cfg.discard_tagged = npar->discard_tagged;
888 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
889 esw_cfg.offload_flags = npar->offload_flags;
890 esw_cfg.promisc_mode = npar->promisc_mode;
891 if (qlcnic_config_switch_port(adapter, &esw_cfg))
892 return -EIO;
893
894 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
895 if (qlcnic_config_switch_port(adapter, &esw_cfg))
896 return -EIO;
897
898 return 0;
899}
900
901static int
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000902qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
903{
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000904 int i, err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000905 struct qlcnic_npar_info *npar;
906 struct qlcnic_info nic_info;
907
Rajesh Borundia174240a2010-08-31 17:17:47 +0000908 if (!adapter->need_fw_reset)
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000909 return 0;
910
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000911 /* Set the NPAR config data after FW reset */
912 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
913 npar = &adapter->npars[i];
914 if (npar->type != QLCNIC_TYPE_NIC)
915 continue;
916 err = qlcnic_get_nic_info(adapter, &nic_info, i);
917 if (err)
918 return err;
919 nic_info.min_tx_bw = npar->min_bw;
920 nic_info.max_tx_bw = npar->max_bw;
921 err = qlcnic_set_nic_info(adapter, &nic_info);
922 if (err)
923 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000924
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000925 if (npar->enable_pm) {
926 err = qlcnic_config_port_mirroring(adapter,
927 npar->dest_npar, 1, i);
928 if (err)
929 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000930 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000931 err = qlcnic_reset_eswitch_config(adapter, npar, i);
932 if (err)
933 return err;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000934 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +0000935 return 0;
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000936}
937
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +0000938static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
939{
940 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
941 u32 npar_state;
942
943 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
944 return 0;
945
946 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
947 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
948 msleep(1000);
949 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
950 }
951 if (!npar_opt_timeo) {
952 dev_err(&adapter->pdev->dev,
953 "Waiting for NPAR state to opertional timeout\n");
954 return -EIO;
955 }
956 return 0;
957}
958
Anirban Chakrabortycea89752010-07-13 20:33:35 +0000959static int
Rajesh Borundia174240a2010-08-31 17:17:47 +0000960qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
961{
962 int err;
963
964 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
965 adapter->op_mode != QLCNIC_MGMT_FUNC)
966 return 0;
967
968 err = qlcnic_set_default_offload_settings(adapter);
969 if (err)
970 return err;
971
972 err = qlcnic_reset_npar_config(adapter);
973 if (err)
974 return err;
975
976 qlcnic_dev_set_npar_ready(adapter);
977
978 return err;
979}
980
981static int
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000982qlcnic_start_firmware(struct qlcnic_adapter *adapter)
983{
Sony Chackod4066832010-08-19 05:08:31 +0000984 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000985
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +0000986 err = qlcnic_can_start_firmware(adapter);
987 if (err < 0)
988 return err;
989 else if (!err)
Sony Chackod4066832010-08-19 05:08:31 +0000990 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +0000991
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +0000992 if (load_fw_file)
993 qlcnic_request_firmware(adapter);
schacko8f891382010-06-17 02:56:40 +0000994 else {
Sony Chacko8cfdce02010-08-26 14:02:41 +0000995 err = qlcnic_check_flash_fw_ver(adapter);
996 if (err)
schacko8f891382010-06-17 02:56:40 +0000997 goto err_out;
998
Amit Kumar Salecha4d5bdb32010-05-17 01:22:11 +0000999 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
schacko8f891382010-06-17 02:56:40 +00001000 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001001
1002 err = qlcnic_need_fw_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001003 if (err == 0)
Sony Chacko4e708122010-08-31 17:17:44 +00001004 goto check_fw_status;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001005
Sony Chackod4066832010-08-19 05:08:31 +00001006 err = qlcnic_pinit_from_rom(adapter);
1007 if (err)
1008 goto err_out;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001009
1010 err = qlcnic_load_firmware(adapter);
1011 if (err)
1012 goto err_out;
1013
1014 qlcnic_release_firmware(adapter);
Sony Chackod4066832010-08-19 05:08:31 +00001015 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001016
Sony Chackod4066832010-08-19 05:08:31 +00001017check_fw_status:
1018 err = qlcnic_check_fw_status(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001019 if (err)
1020 goto err_out;
1021
1022 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001023 qlcnic_idc_debug_info(adapter, 1);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00001024
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001025 err = qlcnic_check_eswitch_mode(adapter);
1026 if (err) {
1027 dev_err(&adapter->pdev->dev,
1028 "Memory allocation failed for eswitch\n");
1029 goto err_out;
1030 }
Rajesh Borundia174240a2010-08-31 17:17:47 +00001031 err = qlcnic_set_mgmt_operations(adapter);
1032 if (err)
1033 goto err_out;
1034
1035 qlcnic_check_options(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001036 adapter->need_fw_reset = 0;
1037
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001038 qlcnic_release_firmware(adapter);
1039 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001040
1041err_out:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001042 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
1043 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
Anirban Chakraborty0866d962010-08-26 14:02:52 +00001044
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001045 qlcnic_release_firmware(adapter);
1046 return err;
1047}
1048
1049static int
1050qlcnic_request_irq(struct qlcnic_adapter *adapter)
1051{
1052 irq_handler_t handler;
1053 struct qlcnic_host_sds_ring *sds_ring;
1054 int err, ring;
1055
1056 unsigned long flags = 0;
1057 struct net_device *netdev = adapter->netdev;
1058 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1059
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001060 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1061 handler = qlcnic_tmp_intr;
1062 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1063 flags |= IRQF_SHARED;
1064
1065 } else {
1066 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1067 handler = qlcnic_msix_intr;
1068 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1069 handler = qlcnic_msi_intr;
1070 else {
1071 flags |= IRQF_SHARED;
1072 handler = qlcnic_intr;
1073 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001074 }
1075 adapter->irq = netdev->irq;
1076
1077 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1078 sds_ring = &recv_ctx->sds_rings[ring];
1079 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1080 err = request_irq(sds_ring->irq, handler,
1081 flags, sds_ring->name, sds_ring);
1082 if (err)
1083 return err;
1084 }
1085
1086 return 0;
1087}
1088
1089static void
1090qlcnic_free_irq(struct qlcnic_adapter *adapter)
1091{
1092 int ring;
1093 struct qlcnic_host_sds_ring *sds_ring;
1094
1095 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1096
1097 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1098 sds_ring = &recv_ctx->sds_rings[ring];
1099 free_irq(sds_ring->irq, sds_ring);
1100 }
1101}
1102
1103static void
1104qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter)
1105{
1106 adapter->coal.flags = QLCNIC_INTR_DEFAULT;
1107 adapter->coal.normal.data.rx_time_us =
1108 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1109 adapter->coal.normal.data.rx_packets =
1110 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
1111 adapter->coal.normal.data.tx_time_us =
1112 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US;
1113 adapter->coal.normal.data.tx_packets =
1114 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS;
1115}
1116
1117static int
1118__qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1119{
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001120 int ring;
1121 struct qlcnic_host_rds_ring *rds_ring;
1122
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001123 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1124 return -EIO;
1125
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001126 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1127 return 0;
Rajesh Borundia0325d692010-08-19 05:08:26 +00001128 if (qlcnic_set_eswitch_port_config(adapter))
1129 return -EIO;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001130
1131 if (qlcnic_fw_create_ctx(adapter))
1132 return -EIO;
1133
1134 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1135 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1136 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1137 }
1138
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001139 qlcnic_set_multi(netdev);
1140 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1141
1142 adapter->ahw.linkup = 0;
1143
1144 if (adapter->max_sds_rings > 1)
1145 qlcnic_config_rss(adapter, 1);
1146
1147 qlcnic_config_intr_coalesce(adapter);
1148
Sucheta Chakraborty24763d82010-08-17 00:34:25 +00001149 if (netdev->features & NETIF_F_LRO)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001150 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1151
1152 qlcnic_napi_enable(adapter);
1153
1154 qlcnic_linkevent_request(adapter, 1);
1155
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001156 adapter->reset_context = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001157 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1158 return 0;
1159}
1160
1161/* Usage: During resume and firmware recovery module.*/
1162
1163static int
1164qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1165{
1166 int err = 0;
1167
1168 rtnl_lock();
1169 if (netif_running(netdev))
1170 err = __qlcnic_up(adapter, netdev);
1171 rtnl_unlock();
1172
1173 return err;
1174}
1175
1176static void
1177__qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1178{
1179 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1180 return;
1181
1182 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1183 return;
1184
1185 smp_mb();
1186 spin_lock(&adapter->tx_clean_lock);
1187 netif_carrier_off(netdev);
1188 netif_tx_disable(netdev);
1189
1190 qlcnic_free_mac_list(adapter);
1191
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001192 if (adapter->fhash.fnum)
1193 qlcnic_delete_lb_filters(adapter);
1194
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001195 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1196
1197 qlcnic_napi_disable(adapter);
1198
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001199 qlcnic_fw_destroy_ctx(adapter);
1200
1201 qlcnic_reset_rx_buffers_list(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001202 qlcnic_release_tx_buffers(adapter);
1203 spin_unlock(&adapter->tx_clean_lock);
1204}
1205
1206/* Usage: During suspend and firmware recovery module */
1207
1208static void
1209qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1210{
1211 rtnl_lock();
1212 if (netif_running(netdev))
1213 __qlcnic_down(adapter, netdev);
1214 rtnl_unlock();
1215
1216}
1217
1218static int
1219qlcnic_attach(struct qlcnic_adapter *adapter)
1220{
1221 struct net_device *netdev = adapter->netdev;
1222 struct pci_dev *pdev = adapter->pdev;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001223 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001224
1225 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1226 return 0;
1227
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001228 err = qlcnic_napi_add(adapter, netdev);
1229 if (err)
1230 return err;
1231
1232 err = qlcnic_alloc_sw_resources(adapter);
1233 if (err) {
1234 dev_err(&pdev->dev, "Error in setting sw resources\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001235 goto err_out_napi_del;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001236 }
1237
1238 err = qlcnic_alloc_hw_resources(adapter);
1239 if (err) {
1240 dev_err(&pdev->dev, "Error in setting hw resources\n");
1241 goto err_out_free_sw;
1242 }
1243
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001244 err = qlcnic_request_irq(adapter);
1245 if (err) {
1246 dev_err(&pdev->dev, "failed to setup interrupt\n");
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001247 goto err_out_free_hw;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001248 }
1249
1250 qlcnic_init_coalesce_defaults(adapter);
1251
1252 qlcnic_create_sysfs_entries(adapter);
1253
1254 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1255 return 0;
1256
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001257err_out_free_hw:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001258 qlcnic_free_hw_resources(adapter);
1259err_out_free_sw:
1260 qlcnic_free_sw_resources(adapter);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001261err_out_napi_del:
1262 qlcnic_napi_del(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001263 return err;
1264}
1265
1266static void
1267qlcnic_detach(struct qlcnic_adapter *adapter)
1268{
1269 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1270 return;
1271
1272 qlcnic_remove_sysfs_entries(adapter);
1273
1274 qlcnic_free_hw_resources(adapter);
1275 qlcnic_release_rx_buffers(adapter);
1276 qlcnic_free_irq(adapter);
1277 qlcnic_napi_del(adapter);
1278 qlcnic_free_sw_resources(adapter);
1279
1280 adapter->is_up = 0;
1281}
1282
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001283void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1284{
1285 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1286 struct qlcnic_host_sds_ring *sds_ring;
1287 int ring;
1288
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001289 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001290 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1291 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1292 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1293 qlcnic_disable_int(sds_ring);
1294 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001295 }
1296
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001297 qlcnic_fw_destroy_ctx(adapter);
1298
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001299 qlcnic_detach(adapter);
1300
1301 adapter->diag_test = 0;
1302 adapter->max_sds_rings = max_sds_rings;
1303
1304 if (qlcnic_attach(adapter))
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001305 goto out;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001306
1307 if (netif_running(netdev))
1308 __qlcnic_up(adapter, netdev);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001309out:
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001310 netif_device_attach(netdev);
1311}
1312
1313int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1314{
1315 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1316 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001317 struct qlcnic_host_rds_ring *rds_ring;
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001318 int ring;
1319 int ret;
1320
1321 netif_device_detach(netdev);
1322
1323 if (netif_running(netdev))
1324 __qlcnic_down(adapter, netdev);
1325
1326 qlcnic_detach(adapter);
1327
1328 adapter->max_sds_rings = 1;
1329 adapter->diag_test = test;
1330
1331 ret = qlcnic_attach(adapter);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001332 if (ret) {
1333 netif_device_attach(netdev);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001334 return ret;
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001335 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001336
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001337 ret = qlcnic_fw_create_ctx(adapter);
1338 if (ret) {
1339 qlcnic_detach(adapter);
Sony Chacko57e46242010-07-24 18:32:18 +00001340 netif_device_attach(netdev);
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00001341 return ret;
1342 }
1343
1344 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1345 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1346 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1347 }
1348
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00001349 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1350 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1351 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1352 qlcnic_enable_int(sds_ring);
1353 }
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001354 }
Sucheta Chakraborty78ad3892010-05-17 01:22:12 +00001355 set_bit(__QLCNIC_DEV_UP, &adapter->state);
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00001356
1357 return 0;
1358}
1359
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00001360/* Reset context in hardware only */
1361static int
1362qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1363{
1364 struct net_device *netdev = adapter->netdev;
1365
1366 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1367 return -EBUSY;
1368
1369 netif_device_detach(netdev);
1370
1371 qlcnic_down(adapter, netdev);
1372
1373 qlcnic_up(adapter, netdev);
1374
1375 netif_device_attach(netdev);
1376
1377 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1378 return 0;
1379}
1380
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001381int
1382qlcnic_reset_context(struct qlcnic_adapter *adapter)
1383{
1384 int err = 0;
1385 struct net_device *netdev = adapter->netdev;
1386
1387 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1388 return -EBUSY;
1389
1390 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1391
1392 netif_device_detach(netdev);
1393
1394 if (netif_running(netdev))
1395 __qlcnic_down(adapter, netdev);
1396
1397 qlcnic_detach(adapter);
1398
1399 if (netif_running(netdev)) {
1400 err = qlcnic_attach(adapter);
1401 if (!err)
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00001402 __qlcnic_up(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001403 }
1404
1405 netif_device_attach(netdev);
1406 }
1407
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001408 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1409 return err;
1410}
1411
1412static int
1413qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001414 struct net_device *netdev, u8 pci_using_dac)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001415{
1416 int err;
1417 struct pci_dev *pdev = adapter->pdev;
1418
1419 adapter->rx_csum = 1;
1420 adapter->mc_enabled = 0;
1421 adapter->max_mc_count = 38;
1422
1423 netdev->netdev_ops = &qlcnic_netdev_ops;
Rajesh K Borundiaef71ff82010-06-17 02:56:41 +00001424 netdev->watchdog_timeo = 5*HZ;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001425
1426 qlcnic_change_mtu(netdev, netdev->mtu);
1427
1428 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1429
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001430 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
Amit Kumar Salechad5790662010-09-16 19:14:39 +00001431 NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_HW_VLAN_RX);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001432 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
Anirban Chakrabortyac8d0c42010-07-09 13:14:58 +00001433 NETIF_F_IPV6_CSUM);
1434
1435 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
1436 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1437 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1438 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001439
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001440 if (pci_using_dac) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001441 netdev->features |= NETIF_F_HIGHDMA;
1442 netdev->vlan_features |= NETIF_F_HIGHDMA;
1443 }
1444
1445 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
1446 netdev->features |= (NETIF_F_HW_VLAN_TX);
1447
1448 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1449 netdev->features |= NETIF_F_LRO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001450 netdev->irq = adapter->msix_entries[0].vector;
1451
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001452 netif_carrier_off(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001453
1454 err = register_netdev(netdev);
1455 if (err) {
1456 dev_err(&pdev->dev, "failed to register net device\n");
1457 return err;
1458 }
1459
1460 return 0;
1461}
1462
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001463static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac)
1464{
1465 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1466 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1467 *pci_using_dac = 1;
1468 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1469 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1470 *pci_using_dac = 0;
1471 else {
1472 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1473 return -EIO;
1474 }
1475
1476 return 0;
1477}
1478
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001479static int __devinit
1480qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1481{
1482 struct net_device *netdev = NULL;
1483 struct qlcnic_adapter *adapter = NULL;
1484 int err;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001485 uint8_t revision_id;
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001486 uint8_t pci_using_dac;
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001487 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001488
1489 err = pci_enable_device(pdev);
1490 if (err)
1491 return err;
1492
1493 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1494 err = -ENODEV;
1495 goto err_out_disable_pdev;
1496 }
1497
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001498 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1499 if (err)
1500 goto err_out_disable_pdev;
1501
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001502 err = pci_request_regions(pdev, qlcnic_driver_name);
1503 if (err)
1504 goto err_out_disable_pdev;
1505
1506 pci_set_master(pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001507 pci_enable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001508
1509 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1510 if (!netdev) {
1511 dev_err(&pdev->dev, "failed to allocate net_device\n");
1512 err = -ENOMEM;
1513 goto err_out_free_res;
1514 }
1515
1516 SET_NETDEV_DEV(netdev, &pdev->dev);
1517
1518 adapter = netdev_priv(netdev);
1519 adapter->netdev = netdev;
1520 adapter->pdev = pdev;
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00001521 adapter->dev_rst_time = jiffies;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001522
1523 revision_id = pdev->revision;
1524 adapter->ahw.revision_id = revision_id;
1525
1526 rwlock_init(&adapter->ahw.crb_lock);
1527 mutex_init(&adapter->ahw.mem_lock);
1528
1529 spin_lock_init(&adapter->tx_clean_lock);
1530 INIT_LIST_HEAD(&adapter->mac_list);
1531
1532 err = qlcnic_setup_pci_map(adapter);
1533 if (err)
1534 goto err_out_free_netdev;
1535
1536 /* This will be reset for mezz cards */
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001537 adapter->portnum = adapter->ahw.pci_func;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001538
1539 err = qlcnic_get_board_info(adapter);
1540 if (err) {
1541 dev_err(&pdev->dev, "Error getting board config info.\n");
1542 goto err_out_iounmap;
1543 }
1544
Sony Chacko8cfdce02010-08-26 14:02:41 +00001545 err = qlcnic_setup_idc_param(adapter);
1546 if (err)
Sucheta Chakrabortyb3a24642010-05-13 03:07:48 +00001547 goto err_out_iounmap;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001548
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001549 err = adapter->nic_ops->start_firmware(adapter);
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001550 if (err) {
1551 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001552 goto err_out_decr_ref;
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00001553 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001554
Rajesh Borundiada48e6c2010-08-31 17:17:46 +00001555 if (qlcnic_read_mac_addr(adapter))
1556 dev_warn(&pdev->dev, "failed to read mac addr\n");
1557
1558 if (adapter->portnum == 0) {
1559 get_brd_name(adapter, brd_name);
1560
1561 pr_info("%s: %s Board Chip rev 0x%x\n",
1562 module_name(THIS_MODULE),
1563 brd_name, adapter->ahw.revision_id);
1564 }
1565
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001566 qlcnic_clear_stats(adapter);
1567
1568 qlcnic_setup_intr(adapter);
1569
Amit Kumar Salecha1bb09fb2010-05-14 03:07:46 -07001570 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001571 if (err)
1572 goto err_out_disable_msi;
1573
1574 pci_set_drvdata(pdev, adapter);
1575
1576 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1577
1578 switch (adapter->ahw.port_type) {
1579 case QLCNIC_GBE:
1580 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1581 adapter->netdev->name);
1582 break;
1583 case QLCNIC_XGBE:
1584 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1585 adapter->netdev->name);
1586 break;
1587 }
1588
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001589 qlcnic_alloc_lb_filters_mem(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001590 qlcnic_create_diag_entries(adapter);
1591
1592 return 0;
1593
1594err_out_disable_msi:
1595 qlcnic_teardown_intr(adapter);
1596
1597err_out_decr_ref:
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001598 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001599
1600err_out_iounmap:
1601 qlcnic_cleanup_pci_map(adapter);
1602
1603err_out_free_netdev:
1604 free_netdev(netdev);
1605
1606err_out_free_res:
1607 pci_release_regions(pdev);
1608
1609err_out_disable_pdev:
1610 pci_set_drvdata(pdev, NULL);
1611 pci_disable_device(pdev);
1612 return err;
1613}
1614
1615static void __devexit qlcnic_remove(struct pci_dev *pdev)
1616{
1617 struct qlcnic_adapter *adapter;
1618 struct net_device *netdev;
1619
1620 adapter = pci_get_drvdata(pdev);
1621 if (adapter == NULL)
1622 return;
1623
1624 netdev = adapter->netdev;
1625
1626 qlcnic_cancel_fw_work(adapter);
1627
1628 unregister_netdev(netdev);
1629
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001630 qlcnic_detach(adapter);
1631
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001632 if (adapter->npars != NULL)
1633 kfree(adapter->npars);
1634 if (adapter->eswitch != NULL)
1635 kfree(adapter->eswitch);
1636
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001637 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001638
1639 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1640
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001641 qlcnic_free_lb_filters_mem(adapter);
1642
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001643 qlcnic_teardown_intr(adapter);
1644
1645 qlcnic_remove_diag_entries(adapter);
1646
1647 qlcnic_cleanup_pci_map(adapter);
1648
1649 qlcnic_release_firmware(adapter);
1650
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00001651 pci_disable_pcie_error_reporting(pdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001652 pci_release_regions(pdev);
1653 pci_disable_device(pdev);
1654 pci_set_drvdata(pdev, NULL);
1655
1656 free_netdev(netdev);
1657}
1658static int __qlcnic_shutdown(struct pci_dev *pdev)
1659{
1660 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1661 struct net_device *netdev = adapter->netdev;
1662 int retval;
1663
1664 netif_device_detach(netdev);
1665
1666 qlcnic_cancel_fw_work(adapter);
1667
1668 if (netif_running(netdev))
1669 qlcnic_down(adapter, netdev);
1670
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00001671 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001672
1673 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1674
1675 retval = pci_save_state(pdev);
1676 if (retval)
1677 return retval;
1678
1679 if (qlcnic_wol_supported(adapter)) {
1680 pci_enable_wake(pdev, PCI_D3cold, 1);
1681 pci_enable_wake(pdev, PCI_D3hot, 1);
1682 }
1683
1684 return 0;
1685}
1686
1687static void qlcnic_shutdown(struct pci_dev *pdev)
1688{
1689 if (__qlcnic_shutdown(pdev))
1690 return;
1691
1692 pci_disable_device(pdev);
1693}
1694
1695#ifdef CONFIG_PM
1696static int
1697qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1698{
1699 int retval;
1700
1701 retval = __qlcnic_shutdown(pdev);
1702 if (retval)
1703 return retval;
1704
1705 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1706 return 0;
1707}
1708
1709static int
1710qlcnic_resume(struct pci_dev *pdev)
1711{
1712 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1713 struct net_device *netdev = adapter->netdev;
1714 int err;
1715
1716 err = pci_enable_device(pdev);
1717 if (err)
1718 return err;
1719
1720 pci_set_power_state(pdev, PCI_D0);
1721 pci_set_master(pdev);
1722 pci_restore_state(pdev);
1723
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00001724 err = adapter->nic_ops->start_firmware(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001725 if (err) {
1726 dev_err(&pdev->dev, "failed to start firmware\n");
1727 return err;
1728 }
1729
1730 if (netif_running(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001731 err = qlcnic_up(adapter, netdev);
1732 if (err)
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001733 goto done;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001734
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00001735 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001736 }
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00001737done:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001738 netif_device_attach(netdev);
1739 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1740 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001741}
1742#endif
1743
1744static int qlcnic_open(struct net_device *netdev)
1745{
1746 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1747 int err;
1748
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001749 err = qlcnic_attach(adapter);
1750 if (err)
1751 return err;
1752
1753 err = __qlcnic_up(adapter, netdev);
1754 if (err)
1755 goto err_out;
1756
1757 netif_start_queue(netdev);
1758
1759 return 0;
1760
1761err_out:
1762 qlcnic_detach(adapter);
1763 return err;
1764}
1765
1766/*
1767 * qlcnic_close - Disables a network interface entry point
1768 */
1769static int qlcnic_close(struct net_device *netdev)
1770{
1771 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1772
1773 __qlcnic_down(adapter, netdev);
1774 return 0;
1775}
1776
1777static void
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001778qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
1779{
1780 void *head;
1781 int i;
1782
1783 if (!qlcnic_mac_learn)
1784 return;
1785
1786 spin_lock_init(&adapter->mac_learn_lock);
1787
1788 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1789 GFP_KERNEL);
1790 if (!head)
1791 return;
1792
1793 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
1794 adapter->fhash.fhead = (struct hlist_head *)head;
1795
1796 for (i = 0; i < adapter->fhash.fmax; i++)
1797 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1798}
1799
1800static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1801{
1802 if (adapter->fhash.fmax && adapter->fhash.fhead)
1803 kfree(adapter->fhash.fhead);
1804
1805 adapter->fhash.fhead = NULL;
1806 adapter->fhash.fmax = 0;
1807}
1808
1809static void qlcnic_change_filter(struct qlcnic_adapter *adapter,
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001810 u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001811{
1812 struct cmd_desc_type0 *hwdesc;
1813 struct qlcnic_nic_req *req;
1814 struct qlcnic_mac_req *mac_req;
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001815 struct qlcnic_vlan_req *vlan_req;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001816 u32 producer;
1817 u64 word;
1818
1819 producer = tx_ring->producer;
1820 hwdesc = &tx_ring->desc_head[tx_ring->producer];
1821
1822 req = (struct qlcnic_nic_req *)hwdesc;
1823 memset(req, 0, sizeof(struct qlcnic_nic_req));
1824 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
1825
1826 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
1827 req->req_hdr = cpu_to_le64(word);
1828
1829 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001830 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001831 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
1832
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001833 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
1834 vlan_req->vlan_id = vlan_id;
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001835
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001836 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
1837}
1838
1839#define QLCNIC_MAC_HASH(MAC)\
1840 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1841
1842static void
1843qlcnic_send_filter(struct qlcnic_adapter *adapter,
1844 struct qlcnic_host_tx_ring *tx_ring,
1845 struct cmd_desc_type0 *first_desc,
1846 struct sk_buff *skb)
1847{
1848 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
1849 struct qlcnic_filter *fil, *tmp_fil;
1850 struct hlist_node *tmp_hnode, *n;
1851 struct hlist_head *head;
1852 u64 src_addr = 0;
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001853 __le16 vlan_id = 0;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001854 u8 hindex;
1855
1856 if (!compare_ether_addr(phdr->h_source, adapter->mac_addr))
1857 return;
1858
1859 if (adapter->fhash.fnum >= adapter->fhash.fmax)
1860 return;
1861
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001862 /* Only NPAR capable devices support vlan based learning*/
1863 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
1864 vlan_id = first_desc->vlan_TCI;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001865 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
1866 hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1);
1867 head = &(adapter->fhash.fhead[hindex]);
1868
1869 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001870 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1871 tmp_fil->vlan_id == vlan_id) {
amit salechae5edb7b2010-10-26 17:53:07 +00001872
1873 if (jiffies >
1874 (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
1875 qlcnic_change_filter(adapter, src_addr, vlan_id,
1876 tx_ring);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001877 tmp_fil->ftime = jiffies;
1878 return;
1879 }
1880 }
1881
1882 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
1883 if (!fil)
1884 return;
1885
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001886 qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring);
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001887
1888 fil->ftime = jiffies;
Amit Kumar Salecha03c5d772010-08-31 17:17:52 +00001889 fil->vlan_id = vlan_id;
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00001890 memcpy(fil->faddr, &src_addr, ETH_ALEN);
1891 spin_lock(&adapter->mac_learn_lock);
1892 hlist_add_head(&(fil->fnode), head);
1893 adapter->fhash.fnum++;
1894 spin_unlock(&adapter->mac_learn_lock);
1895}
1896
1897static void
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001898qlcnic_tso_check(struct net_device *netdev,
1899 struct qlcnic_host_tx_ring *tx_ring,
1900 struct cmd_desc_type0 *first_desc,
1901 struct sk_buff *skb)
1902{
1903 u8 opcode = TX_ETHER_PKT;
1904 __be16 protocol = skb->protocol;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00001905 u16 flags = 0;
1906 int copied, offset, copy_len, hdr_len = 0, tso = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001907 struct cmd_desc_type0 *hwdesc;
1908 struct vlan_ethhdr *vh;
Sucheta Chakraborty8bfe8b92010-03-08 00:14:46 +00001909 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001910 u32 producer = tx_ring->producer;
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001911 __le16 vlan_oob = first_desc->flags_opcode &
1912 cpu_to_le16(FLAGS_VLAN_OOB);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001913
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00001914 if (*(skb->data) & BIT_0) {
1915 flags |= BIT_0;
1916 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
1917 }
1918
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001919 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1920 skb_shinfo(skb)->gso_size > 0) {
1921
1922 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1923
1924 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1925 first_desc->total_hdr_length = hdr_len;
1926 if (vlan_oob) {
1927 first_desc->total_hdr_length += VLAN_HLEN;
1928 first_desc->tcp_hdr_offset = VLAN_HLEN;
1929 first_desc->ip_hdr_offset = VLAN_HLEN;
1930 /* Only in case of TSO on vlan device */
1931 flags |= FLAGS_VLAN_TAGGED;
1932 }
1933
1934 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
1935 TX_TCP_LSO6 : TX_TCP_LSO;
1936 tso = 1;
1937
1938 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1939 u8 l4proto;
1940
1941 if (protocol == cpu_to_be16(ETH_P_IP)) {
1942 l4proto = ip_hdr(skb)->protocol;
1943
1944 if (l4proto == IPPROTO_TCP)
1945 opcode = TX_TCP_PKT;
1946 else if (l4proto == IPPROTO_UDP)
1947 opcode = TX_UDP_PKT;
1948 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
1949 l4proto = ipv6_hdr(skb)->nexthdr;
1950
1951 if (l4proto == IPPROTO_TCP)
1952 opcode = TX_TCPV6_PKT;
1953 else if (l4proto == IPPROTO_UDP)
1954 opcode = TX_UDPV6_PKT;
1955 }
1956 }
1957
1958 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1959 first_desc->ip_hdr_offset += skb_network_offset(skb);
1960 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
1961
1962 if (!tso)
1963 return;
1964
1965 /* For LSO, we need to copy the MAC/IP/TCP headers into
1966 * the descriptor ring
1967 */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001968 copied = 0;
1969 offset = 2;
1970
1971 if (vlan_oob) {
1972 /* Create a TSO vlan header template for firmware */
1973
1974 hwdesc = &tx_ring->desc_head[producer];
1975 tx_ring->cmd_buf_arr[producer].skb = NULL;
1976
1977 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1978 hdr_len + VLAN_HLEN);
1979
1980 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1981 skb_copy_from_linear_data(skb, vh, 12);
1982 vh->h_vlan_proto = htons(ETH_P_8021Q);
Sucheta Chakraborty7e56cac2010-10-04 04:20:13 +00001983 vh->h_vlan_TCI = (__be16)swab16((u16)first_desc->vlan_TCI);
1984
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00001985 skb_copy_from_linear_data_offset(skb, 12,
1986 (char *)vh + 16, copy_len - 16);
1987
1988 copied = copy_len - VLAN_HLEN;
1989 offset = 0;
1990
1991 producer = get_next_index(producer, tx_ring->num_desc);
1992 }
1993
1994 while (copied < hdr_len) {
1995
1996 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1997 (hdr_len - copied));
1998
1999 hwdesc = &tx_ring->desc_head[producer];
2000 tx_ring->cmd_buf_arr[producer].skb = NULL;
2001
2002 skb_copy_from_linear_data_offset(skb, copied,
2003 (char *)hwdesc + offset, copy_len);
2004
2005 copied += copy_len;
2006 offset = 0;
2007
2008 producer = get_next_index(producer, tx_ring->num_desc);
2009 }
2010
2011 tx_ring->producer = producer;
2012 barrier();
Sucheta Chakraborty8bfe8b92010-03-08 00:14:46 +00002013 adapter->stats.lso_frames++;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002014}
2015
2016static int
2017qlcnic_map_tx_skb(struct pci_dev *pdev,
2018 struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf)
2019{
2020 struct qlcnic_skb_frag *nf;
2021 struct skb_frag_struct *frag;
2022 int i, nr_frags;
2023 dma_addr_t map;
2024
2025 nr_frags = skb_shinfo(skb)->nr_frags;
2026 nf = &pbuf->frag_array[0];
2027
2028 map = pci_map_single(pdev, skb->data,
2029 skb_headlen(skb), PCI_DMA_TODEVICE);
2030 if (pci_dma_mapping_error(pdev, map))
2031 goto out_err;
2032
2033 nf->dma = map;
2034 nf->length = skb_headlen(skb);
2035
2036 for (i = 0; i < nr_frags; i++) {
2037 frag = &skb_shinfo(skb)->frags[i];
2038 nf = &pbuf->frag_array[i+1];
2039
2040 map = pci_map_page(pdev, frag->page, frag->page_offset,
2041 frag->size, PCI_DMA_TODEVICE);
2042 if (pci_dma_mapping_error(pdev, map))
2043 goto unwind;
2044
2045 nf->dma = map;
2046 nf->length = frag->size;
2047 }
2048
2049 return 0;
2050
2051unwind:
2052 while (--i >= 0) {
2053 nf = &pbuf->frag_array[i+1];
2054 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2055 }
2056
2057 nf = &pbuf->frag_array[0];
2058 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2059
2060out_err:
2061 return -ENOMEM;
2062}
2063
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00002064static int
2065qlcnic_check_tx_tagging(struct qlcnic_adapter *adapter,
2066 struct sk_buff *skb,
2067 struct cmd_desc_type0 *first_desc)
2068{
2069 u8 opcode = 0;
2070 u16 flags = 0;
2071 __be16 protocol = skb->protocol;
2072 struct vlan_ethhdr *vh;
2073
2074 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
2075 vh = (struct vlan_ethhdr *)skb->data;
2076 protocol = vh->h_vlan_encapsulated_proto;
2077 flags = FLAGS_VLAN_TAGGED;
2078 qlcnic_set_tx_vlan_tci(first_desc, ntohs(vh->h_vlan_TCI));
2079 } else if (vlan_tx_tag_present(skb)) {
2080 flags = FLAGS_VLAN_OOB;
2081 qlcnic_set_tx_vlan_tci(first_desc, vlan_tx_tag_get(skb));
2082 }
2083 if (unlikely(adapter->pvid)) {
2084 if (first_desc->vlan_TCI &&
2085 !(adapter->flags & QLCNIC_TAGGING_ENABLED))
2086 return -EIO;
2087 if (first_desc->vlan_TCI &&
2088 (adapter->flags & QLCNIC_TAGGING_ENABLED))
2089 goto set_flags;
2090
2091 flags = FLAGS_VLAN_OOB;
2092 qlcnic_set_tx_vlan_tci(first_desc, adapter->pvid);
2093 }
2094set_flags:
2095 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2096 return 0;
2097}
2098
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002099static inline void
2100qlcnic_clear_cmddesc(u64 *desc)
2101{
2102 desc[0] = 0ULL;
2103 desc[2] = 0ULL;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00002104 desc[7] = 0ULL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002105}
2106
Amit Kumar Salechacdaff182010-02-01 05:25:00 +00002107netdev_tx_t
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002108qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2109{
2110 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2111 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2112 struct qlcnic_cmd_buffer *pbuf;
2113 struct qlcnic_skb_frag *buffrag;
2114 struct cmd_desc_type0 *hwdesc, *first_desc;
2115 struct pci_dev *pdev;
Rajesh Borundiadcb50af2010-08-31 17:17:49 +00002116 struct ethhdr *phdr;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002117 int i, k;
2118
2119 u32 producer;
2120 int frag_count, no_of_desc;
2121 u32 num_txd = tx_ring->num_desc;
2122
Amit Kumar Salecha780ab792010-04-22 02:51:41 +00002123 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
2124 netif_stop_queue(netdev);
2125 return NETDEV_TX_BUSY;
2126 }
2127
Sony Chackofe4d4342010-08-19 05:08:27 +00002128 if (adapter->flags & QLCNIC_MACSPOOF) {
Rajesh Borundiadcb50af2010-08-31 17:17:49 +00002129 phdr = (struct ethhdr *)skb->data;
2130 if (compare_ether_addr(phdr->h_source,
Sony Chackofe4d4342010-08-19 05:08:27 +00002131 adapter->mac_addr))
2132 goto drop_packet;
2133 }
2134
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002135 frag_count = skb_shinfo(skb)->nr_frags + 1;
2136
2137 /* 4 fragments per cmd des */
2138 no_of_desc = (frag_count + 3) >> 2;
2139
Rajesh K Borundiaef71ff82010-06-17 02:56:41 +00002140 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002141 netif_stop_queue(netdev);
Rajesh K Borundiaef71ff82010-06-17 02:56:41 +00002142 smp_mb();
2143 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
2144 netif_start_queue(netdev);
2145 else {
2146 adapter->stats.xmit_off++;
2147 return NETDEV_TX_BUSY;
2148 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002149 }
2150
2151 producer = tx_ring->producer;
2152 pbuf = &tx_ring->cmd_buf_arr[producer];
2153
2154 pdev = adapter->pdev;
2155
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00002156 first_desc = hwdesc = &tx_ring->desc_head[producer];
2157 qlcnic_clear_cmddesc((u64 *)hwdesc);
2158
2159 if (qlcnic_check_tx_tagging(adapter, skb, first_desc))
2160 goto drop_packet;
2161
Amit Kumar Salecha8ae6df92010-04-22 02:51:35 +00002162 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
2163 adapter->stats.tx_dma_map_error++;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002164 goto drop_packet;
Amit Kumar Salecha8ae6df92010-04-22 02:51:35 +00002165 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002166
2167 pbuf->skb = skb;
2168 pbuf->frag_count = frag_count;
2169
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002170 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
2171 qlcnic_set_tx_port(first_desc, adapter->portnum);
2172
2173 for (i = 0; i < frag_count; i++) {
2174
2175 k = i % 4;
2176
2177 if ((k == 0) && (i > 0)) {
2178 /* move to next desc.*/
2179 producer = get_next_index(producer, num_txd);
2180 hwdesc = &tx_ring->desc_head[producer];
2181 qlcnic_clear_cmddesc((u64 *)hwdesc);
2182 tx_ring->cmd_buf_arr[producer].skb = NULL;
2183 }
2184
2185 buffrag = &pbuf->frag_array[i];
2186
2187 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2188 switch (k) {
2189 case 0:
2190 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2191 break;
2192 case 1:
2193 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2194 break;
2195 case 2:
2196 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2197 break;
2198 case 3:
2199 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2200 break;
2201 }
2202 }
2203
2204 tx_ring->producer = get_next_index(producer, num_txd);
2205
2206 qlcnic_tso_check(netdev, tx_ring, first_desc, skb);
2207
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00002208 if (qlcnic_mac_learn)
2209 qlcnic_send_filter(adapter, tx_ring, first_desc, skb);
2210
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002211 qlcnic_update_cmd_producer(adapter, tx_ring);
2212
2213 adapter->stats.txbytes += skb->len;
2214 adapter->stats.xmitcalled++;
2215
2216 return NETDEV_TX_OK;
2217
2218drop_packet:
2219 adapter->stats.txdropped++;
2220 dev_kfree_skb_any(skb);
2221 return NETDEV_TX_OK;
2222}
2223
2224static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
2225{
2226 struct net_device *netdev = adapter->netdev;
2227 u32 temp, temp_state, temp_val;
2228 int rv = 0;
2229
2230 temp = QLCRD32(adapter, CRB_TEMP_STATE);
2231
2232 temp_state = qlcnic_get_temp_state(temp);
2233 temp_val = qlcnic_get_temp_val(temp);
2234
2235 if (temp_state == QLCNIC_TEMP_PANIC) {
2236 dev_err(&netdev->dev,
2237 "Device temperature %d degrees C exceeds"
2238 " maximum allowed. Hardware has been shut down.\n",
2239 temp_val);
2240 rv = 1;
2241 } else if (temp_state == QLCNIC_TEMP_WARN) {
2242 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
2243 dev_err(&netdev->dev,
2244 "Device temperature %d degrees C "
2245 "exceeds operating range."
2246 " Immediate action needed.\n",
2247 temp_val);
2248 }
2249 } else {
2250 if (adapter->temp == QLCNIC_TEMP_WARN) {
2251 dev_info(&netdev->dev,
2252 "Device temperature is now %d degrees C"
2253 " in normal range.\n", temp_val);
2254 }
2255 }
2256 adapter->temp = temp_state;
2257 return rv;
2258}
2259
2260void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2261{
2262 struct net_device *netdev = adapter->netdev;
2263
2264 if (adapter->ahw.linkup && !linkup) {
Sony Chacko69324272010-08-17 00:34:23 +00002265 netdev_info(netdev, "NIC Link is down\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002266 adapter->ahw.linkup = 0;
2267 if (netif_running(netdev)) {
2268 netif_carrier_off(netdev);
2269 netif_stop_queue(netdev);
2270 }
2271 } else if (!adapter->ahw.linkup && linkup) {
Sony Chacko69324272010-08-17 00:34:23 +00002272 netdev_info(netdev, "NIC Link is up\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002273 adapter->ahw.linkup = 1;
2274 if (netif_running(netdev)) {
2275 netif_carrier_on(netdev);
2276 netif_wake_queue(netdev);
2277 }
2278 }
2279}
2280
2281static void qlcnic_tx_timeout(struct net_device *netdev)
2282{
2283 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2284
2285 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2286 return;
2287
2288 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002289
2290 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00002291 adapter->need_fw_reset = 1;
2292 else
2293 adapter->reset_context = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002294}
2295
2296static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2297{
2298 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2299 struct net_device_stats *stats = &netdev->stats;
2300
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002301 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2302 stats->tx_packets = adapter->stats.xmitfinished;
Sucheta Chakraborty7e382592010-05-17 01:22:10 +00002303 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002304 stats->tx_bytes = adapter->stats.txbytes;
2305 stats->rx_dropped = adapter->stats.rxdropped;
2306 stats->tx_dropped = adapter->stats.txdropped;
2307
2308 return stats;
2309}
2310
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002311static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002312{
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002313 u32 status;
2314
2315 status = readl(adapter->isr_int_vec);
2316
2317 if (!(status & adapter->int_vec_bit))
2318 return IRQ_NONE;
2319
2320 /* check interrupt state machine, to be sure */
2321 status = readl(adapter->crb_int_state_reg);
2322 if (!ISR_LEGACY_INT_TRIGGERED(status))
2323 return IRQ_NONE;
2324
2325 writel(0xffffffff, adapter->tgt_status_reg);
2326 /* read twice to ensure write is flushed */
2327 readl(adapter->isr_int_vec);
2328 readl(adapter->isr_int_vec);
2329
Amit Kumar Salecha7eb98552010-02-01 05:24:59 +00002330 return IRQ_HANDLED;
2331}
2332
2333static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2334{
2335 struct qlcnic_host_sds_ring *sds_ring = data;
2336 struct qlcnic_adapter *adapter = sds_ring->adapter;
2337
2338 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2339 goto done;
2340 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2341 writel(0xffffffff, adapter->tgt_status_reg);
2342 goto done;
2343 }
2344
2345 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2346 return IRQ_NONE;
2347
2348done:
2349 adapter->diag_cnt++;
2350 qlcnic_enable_int(sds_ring);
2351 return IRQ_HANDLED;
2352}
2353
2354static irqreturn_t qlcnic_intr(int irq, void *data)
2355{
2356 struct qlcnic_host_sds_ring *sds_ring = data;
2357 struct qlcnic_adapter *adapter = sds_ring->adapter;
2358
2359 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2360 return IRQ_NONE;
2361
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002362 napi_schedule(&sds_ring->napi);
2363
2364 return IRQ_HANDLED;
2365}
2366
2367static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2368{
2369 struct qlcnic_host_sds_ring *sds_ring = data;
2370 struct qlcnic_adapter *adapter = sds_ring->adapter;
2371
2372 /* clear interrupt */
2373 writel(0xffffffff, adapter->tgt_status_reg);
2374
2375 napi_schedule(&sds_ring->napi);
2376 return IRQ_HANDLED;
2377}
2378
2379static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2380{
2381 struct qlcnic_host_sds_ring *sds_ring = data;
2382
2383 napi_schedule(&sds_ring->napi);
2384 return IRQ_HANDLED;
2385}
2386
2387static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter)
2388{
2389 u32 sw_consumer, hw_consumer;
2390 int count = 0, i;
2391 struct qlcnic_cmd_buffer *buffer;
2392 struct pci_dev *pdev = adapter->pdev;
2393 struct net_device *netdev = adapter->netdev;
2394 struct qlcnic_skb_frag *frag;
2395 int done;
2396 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2397
2398 if (!spin_trylock(&adapter->tx_clean_lock))
2399 return 1;
2400
2401 sw_consumer = tx_ring->sw_consumer;
2402 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2403
2404 while (sw_consumer != hw_consumer) {
2405 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
2406 if (buffer->skb) {
2407 frag = &buffer->frag_array[0];
2408 pci_unmap_single(pdev, frag->dma, frag->length,
2409 PCI_DMA_TODEVICE);
2410 frag->dma = 0ULL;
2411 for (i = 1; i < buffer->frag_count; i++) {
2412 frag++;
2413 pci_unmap_page(pdev, frag->dma, frag->length,
2414 PCI_DMA_TODEVICE);
2415 frag->dma = 0ULL;
2416 }
2417
2418 adapter->stats.xmitfinished++;
2419 dev_kfree_skb_any(buffer->skb);
2420 buffer->skb = NULL;
2421 }
2422
2423 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
2424 if (++count >= MAX_STATUS_HANDLE)
2425 break;
2426 }
2427
2428 if (count && netif_running(netdev)) {
2429 tx_ring->sw_consumer = sw_consumer;
2430
2431 smp_mb();
2432
2433 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002434 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
2435 netif_wake_queue(netdev);
Sucheta Chakraborty8bfe8b92010-03-08 00:14:46 +00002436 adapter->stats.xmit_on++;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002437 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002438 }
Rajesh K Borundiaef71ff82010-06-17 02:56:41 +00002439 adapter->tx_timeo_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002440 }
2441 /*
2442 * If everything is freed up to consumer then check if the ring is full
2443 * If the ring is full then check if more needs to be freed and
2444 * schedule the call back again.
2445 *
2446 * This happens when there are 2 CPUs. One could be freeing and the
2447 * other filling it. If the ring is full when we get out of here and
2448 * the card has already interrupted the host then the host can miss the
2449 * interrupt.
2450 *
2451 * There is still a possible race condition and the host could miss an
2452 * interrupt. The card has to take care of this.
2453 */
2454 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2455 done = (sw_consumer == hw_consumer);
2456 spin_unlock(&adapter->tx_clean_lock);
2457
2458 return done;
2459}
2460
2461static int qlcnic_poll(struct napi_struct *napi, int budget)
2462{
2463 struct qlcnic_host_sds_ring *sds_ring =
2464 container_of(napi, struct qlcnic_host_sds_ring, napi);
2465
2466 struct qlcnic_adapter *adapter = sds_ring->adapter;
2467
2468 int tx_complete;
2469 int work_done;
2470
2471 tx_complete = qlcnic_process_cmd_ring(adapter);
2472
2473 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2474
2475 if ((work_done < budget) && tx_complete) {
2476 napi_complete(&sds_ring->napi);
2477 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2478 qlcnic_enable_int(sds_ring);
2479 }
2480
2481 return work_done;
2482}
2483
schacko8f891382010-06-17 02:56:40 +00002484static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
2485{
2486 struct qlcnic_host_sds_ring *sds_ring =
2487 container_of(napi, struct qlcnic_host_sds_ring, napi);
2488
2489 struct qlcnic_adapter *adapter = sds_ring->adapter;
2490 int work_done;
2491
2492 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2493
2494 if (work_done < budget) {
2495 napi_complete(&sds_ring->napi);
2496 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2497 qlcnic_enable_int(sds_ring);
2498 }
2499
2500 return work_done;
2501}
2502
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002503#ifdef CONFIG_NET_POLL_CONTROLLER
2504static void qlcnic_poll_controller(struct net_device *netdev)
2505{
Yinglin Luanbf827912010-08-22 21:57:56 +00002506 int ring;
2507 struct qlcnic_host_sds_ring *sds_ring;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002508 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Yinglin Luanbf827912010-08-22 21:57:56 +00002509 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
2510
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002511 disable_irq(adapter->irq);
Yinglin Luanbf827912010-08-22 21:57:56 +00002512 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2513 sds_ring = &recv_ctx->sds_rings[ring];
2514 qlcnic_intr(adapter->irq, sds_ring);
2515 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002516 enable_irq(adapter->irq);
2517}
2518#endif
2519
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002520static void
2521qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2522{
2523 u32 val;
2524
2525 val = adapter->portnum & 0xf;
2526 val |= encoding << 7;
2527 val |= (jiffies - adapter->dev_rst_time) << 8;
2528
2529 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2530 adapter->dev_rst_time = jiffies;
2531}
2532
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002533static int
2534qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002535{
2536 u32 val;
2537
2538 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2539 state != QLCNIC_DEV_NEED_QUISCENT);
2540
2541 if (qlcnic_api_lock(adapter))
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002542 return -EIO;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002543
2544 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2545
2546 if (state == QLCNIC_DEV_NEED_RESET)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002547 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002548 else if (state == QLCNIC_DEV_NEED_QUISCENT)
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002549 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002550
2551 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2552
2553 qlcnic_api_unlock(adapter);
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002554
2555 return 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002556}
2557
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002558static int
2559qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2560{
2561 u32 val;
2562
2563 if (qlcnic_api_lock(adapter))
2564 return -EBUSY;
2565
2566 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002567 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00002568 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2569
2570 qlcnic_api_unlock(adapter);
2571
2572 return 0;
2573}
2574
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002575static void
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002576qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002577{
2578 u32 val;
2579
2580 if (qlcnic_api_lock(adapter))
2581 goto err;
2582
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002583 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002584 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002585 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002586
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002587 if (failed) {
2588 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2589 dev_info(&adapter->pdev->dev,
2590 "Device state set to Failed. Please Reboot\n");
2591 } else if (!(val & 0x11111111))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002592 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2593
2594 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002595 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002596 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2597
2598 qlcnic_api_unlock(adapter);
2599err:
2600 adapter->fw_fail_cnt = 0;
2601 clear_bit(__QLCNIC_START_FW, &adapter->state);
2602 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2603}
2604
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002605/* Grab api lock, before checking state */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002606static int
2607qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2608{
2609 int act, state;
2610
2611 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002612 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002613
2614 if (((state & 0x11111111) == (act & 0x11111111)) ||
2615 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2616 return 0;
2617 else
2618 return 1;
2619}
2620
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002621static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2622{
2623 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2624
2625 if (val != QLCNIC_DRV_IDC_VER) {
2626 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2627 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2628 }
2629
2630 return 0;
2631}
2632
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002633static int
2634qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2635{
2636 u32 val, prev_state;
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002637 u8 dev_init_timeo = adapter->dev_init_timeo;
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002638 u8 portnum = adapter->portnum;
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002639 u8 ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002640
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002641 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2642 return 1;
2643
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002644 if (qlcnic_api_lock(adapter))
2645 return -1;
2646
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002647 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002648 if (!(val & (1 << (portnum * 4)))) {
2649 QLC_DEV_SET_REF_CNT(val, portnum);
Amit Kumar Salecha31018e02010-08-25 04:03:05 +00002650 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002651 }
2652
2653 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002654 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002655
2656 switch (prev_state) {
2657 case QLCNIC_DEV_COLD:
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002658 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002659 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002660 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002661 qlcnic_api_unlock(adapter);
2662 return 1;
2663
2664 case QLCNIC_DEV_READY:
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002665 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002666 qlcnic_api_unlock(adapter);
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002667 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002668
2669 case QLCNIC_DEV_NEED_RESET:
2670 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002671 QLC_DEV_SET_RST_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002672 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2673 break;
2674
2675 case QLCNIC_DEV_NEED_QUISCENT:
2676 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002677 QLC_DEV_SET_QSCNT_RDY(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002678 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2679 break;
2680
2681 case QLCNIC_DEV_FAILED:
Amit Kumar Salechaa7fc9482010-05-17 01:22:14 +00002682 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002683 qlcnic_api_unlock(adapter);
2684 return -1;
Amit Kumar Salechabbd8c6a2010-04-22 02:51:36 +00002685
2686 case QLCNIC_DEV_INITIALIZING:
2687 case QLCNIC_DEV_QUISCENT:
2688 break;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002689 }
2690
2691 qlcnic_api_unlock(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002692
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002693 do {
2694 msleep(1000);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002695 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2696
2697 if (prev_state == QLCNIC_DEV_QUISCENT)
2698 continue;
2699 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002700
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002701 if (!dev_init_timeo) {
2702 dev_err(&adapter->pdev->dev,
2703 "Waiting for device to initialize timeout\n");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002704 return -1;
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002705 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002706
2707 if (qlcnic_api_lock(adapter))
2708 return -1;
2709
2710 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
Amit Kumar Salecha6d2a4722010-04-22 02:51:38 +00002711 QLC_DEV_CLR_RST_QSCNT(val, portnum);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002712 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2713
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002714 ret = qlcnic_check_idc_ver(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002715 qlcnic_api_unlock(adapter);
2716
Sucheta Chakraborty96f81182010-05-13 03:07:47 +00002717 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002718}
2719
2720static void
2721qlcnic_fwinit_work(struct work_struct *work)
2722{
2723 struct qlcnic_adapter *adapter = container_of(work,
2724 struct qlcnic_adapter, fw_work.work);
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002725 u32 dev_state = 0xf;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002726
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002727 if (qlcnic_api_lock(adapter))
2728 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002729
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002730 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002731 if (dev_state == QLCNIC_DEV_QUISCENT ||
2732 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002733 qlcnic_api_unlock(adapter);
2734 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2735 FW_POLL_DELAY * 2);
2736 return;
2737 }
2738
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002739 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002740 qlcnic_api_unlock(adapter);
2741 goto wait_npar;
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002742 }
2743
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002744 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
2745 dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
2746 adapter->reset_ack_timeo);
2747 goto skip_ack_check;
2748 }
2749
2750 if (!qlcnic_check_drv_state(adapter)) {
2751skip_ack_check:
2752 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Sucheta Chakrabortya5e463d2010-05-13 03:07:49 +00002753
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002754 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2755 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2756 QLCNIC_DEV_INITIALIZING);
2757 set_bit(__QLCNIC_START_FW, &adapter->state);
2758 QLCDB(adapter, DRV, "Restarting fw\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002759 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002760 }
2761
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002762 qlcnic_api_unlock(adapter);
2763
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002764 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002765 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002766 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002767 return;
2768 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002769 goto err_ret;
2770 }
2771
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002772 qlcnic_api_unlock(adapter);
Sucheta Chakrabortyaa5e18c2010-04-01 19:01:32 +00002773
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002774wait_npar:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002775 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002776 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002777
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002778 switch (dev_state) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002779 case QLCNIC_DEV_READY:
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002780 if (!adapter->nic_ops->start_firmware(adapter)) {
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002781 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002782 adapter->fw_wait_cnt = 0;
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002783 return;
2784 }
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002785 case QLCNIC_DEV_FAILED:
2786 break;
2787 default:
2788 qlcnic_schedule_work(adapter,
2789 qlcnic_fwinit_work, FW_POLL_DELAY);
2790 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002791 }
2792
2793err_ret:
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002794 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2795 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002796 netif_device_attach(adapter->netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002797 qlcnic_clr_all_drv_state(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002798}
2799
2800static void
2801qlcnic_detach_work(struct work_struct *work)
2802{
2803 struct qlcnic_adapter *adapter = container_of(work,
2804 struct qlcnic_adapter, fw_work.work);
2805 struct net_device *netdev = adapter->netdev;
2806 u32 status;
2807
2808 netif_device_detach(netdev);
2809
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002810 /* Dont grab rtnl lock during Quiscent mode */
2811 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2812 if (netif_running(netdev))
2813 __qlcnic_down(adapter, netdev);
2814 } else
2815 qlcnic_down(adapter, netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002816
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002817 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2818
2819 if (status & QLCNIC_RCODE_FATAL_ERROR)
2820 goto err_ret;
2821
2822 if (adapter->temp == QLCNIC_TEMP_PANIC)
2823 goto err_ret;
2824
Amit Kumar Salechaade91f82010-04-22 02:51:39 +00002825 if (qlcnic_set_drv_state(adapter, adapter->dev_state))
2826 goto err_ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002827
2828 adapter->fw_wait_cnt = 0;
2829
2830 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2831
2832 return;
2833
2834err_ret:
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002835 dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n",
2836 status, adapter->temp);
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002837 netif_device_attach(netdev);
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00002838 qlcnic_clr_all_drv_state(adapter, 1);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002839}
2840
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002841/*Transit NPAR state to NON Operational */
2842static void
2843qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2844{
2845 u32 state;
2846
2847 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2848 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2849 return;
2850
2851 if (qlcnic_api_lock(adapter))
2852 return;
2853 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2854 qlcnic_api_unlock(adapter);
2855}
2856
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00002857/* Caller should held RESETTING bit.
2858 * This should be call in sync with qlcnic_request_quiscent_mode.
2859 */
2860void qlcnic_clear_quiscent_mode(struct qlcnic_adapter *adapter)
2861{
2862 qlcnic_clr_drv_state(adapter);
2863 qlcnic_api_lock(adapter);
2864 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
2865 qlcnic_api_unlock(adapter);
2866}
2867
2868/* Caller should held RESETTING bit.
2869 */
2870int qlcnic_request_quiscent_mode(struct qlcnic_adapter *adapter)
2871{
2872 u8 timeo = adapter->dev_init_timeo / 2;
2873 u32 state;
2874
2875 if (qlcnic_api_lock(adapter))
2876 return -EIO;
2877
2878 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2879 if (state != QLCNIC_DEV_READY)
2880 return -EIO;
2881
2882 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_QUISCENT);
2883 qlcnic_api_unlock(adapter);
2884 QLCDB(adapter, DRV, "NEED QUISCENT state set\n");
2885 qlcnic_idc_debug_info(adapter, 0);
2886
2887 qlcnic_set_drv_state(adapter, QLCNIC_DEV_NEED_QUISCENT);
2888
2889 do {
2890 msleep(2000);
2891 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2892 if (state == QLCNIC_DEV_QUISCENT)
2893 return 0;
2894 if (!qlcnic_check_drv_state(adapter)) {
2895 if (qlcnic_api_lock(adapter))
2896 return -EIO;
2897 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2898 QLCNIC_DEV_QUISCENT);
2899 qlcnic_api_unlock(adapter);
2900 QLCDB(adapter, DRV, "QUISCENT mode set\n");
2901 return 0;
2902 }
2903 } while (--timeo);
2904
2905 dev_err(&adapter->pdev->dev, "Failed to quiesce device, DRV_STATE=%08x"
2906 " DRV_ACTIVE=%08x\n", QLCRD32(adapter, QLCNIC_CRB_DRV_STATE),
2907 QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE));
2908 qlcnic_clear_quiscent_mode(adapter);
2909 return -EIO;
2910}
2911
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002912/*Transit to RESET state from READY state only */
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002913static void
2914qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2915{
2916 u32 state;
2917
Anirban Chakrabortycea89752010-07-13 20:33:35 +00002918 adapter->need_fw_reset = 1;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002919 if (qlcnic_api_lock(adapter))
2920 return;
2921
2922 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2923
Amit Kumar Salechaf73dfc52010-04-22 02:51:37 +00002924 if (state == QLCNIC_DEV_READY) {
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002925 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00002926 QLCDB(adapter, DRV, "NEED_RESET state set\n");
Sucheta Chakraborty6df900e2010-05-13 03:07:50 +00002927 qlcnic_idc_debug_info(adapter, 0);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002928 }
2929
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002930 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002931 qlcnic_api_unlock(adapter);
2932}
2933
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002934/* Transit to NPAR READY state from NPAR NOT READY state */
2935static void
2936qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2937{
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002938 if (qlcnic_api_lock(adapter))
2939 return;
2940
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00002941 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2942 QLCDB(adapter, DRV, "NPAR operational state set\n");
Anirban Chakraborty9f26f542010-06-01 11:33:09 +00002943
2944 qlcnic_api_unlock(adapter);
2945}
2946
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002947static void
2948qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2949 work_func_t func, int delay)
2950{
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00002951 if (test_bit(__QLCNIC_AER, &adapter->state))
2952 return;
2953
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002954 INIT_DELAYED_WORK(&adapter->fw_work, func);
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00002955 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
2956 round_jiffies_relative(delay));
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002957}
2958
2959static void
2960qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
2961{
2962 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2963 msleep(10);
2964
2965 cancel_delayed_work_sync(&adapter->fw_work);
2966}
2967
2968static void
2969qlcnic_attach_work(struct work_struct *work)
2970{
2971 struct qlcnic_adapter *adapter = container_of(work,
2972 struct qlcnic_adapter, fw_work.work);
2973 struct net_device *netdev = adapter->netdev;
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002974 u32 npar_state;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002975
Amit Kumar Salechab18971d2010-08-25 04:03:04 +00002976 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2977 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2978 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2979 qlcnic_clr_all_drv_state(adapter, 0);
2980 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2981 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2982 FW_POLL_DELAY);
2983 else
2984 goto attach;
2985 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2986 return;
2987 }
2988attach:
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002989 if (netif_running(netdev)) {
Amit Kumar Salecha52486a32010-06-22 03:19:02 +00002990 if (qlcnic_up(adapter, netdev))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002991 goto done;
2992
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00002993 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002994 }
2995
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002996done:
Amit Kumar Salecha34ce3622010-04-01 19:01:34 +00002997 netif_device_attach(netdev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00002998 adapter->fw_fail_cnt = 0;
2999 clear_bit(__QLCNIC_RESETTING, &adapter->state);
Amit Kumar Salecha1b95a832010-02-01 05:24:56 +00003000
3001 if (!qlcnic_clr_drv_state(adapter))
3002 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3003 FW_POLL_DELAY);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003004}
3005
3006static int
3007qlcnic_check_health(struct qlcnic_adapter *adapter)
3008{
Sony Chacko4e708122010-08-31 17:17:44 +00003009 u32 state = 0, heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003010 struct net_device *netdev = adapter->netdev;
3011
3012 if (qlcnic_check_temp(adapter))
3013 goto detach;
3014
Amit Kumar Salecha2372a5f2010-05-13 03:07:42 +00003015 if (adapter->need_fw_reset)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003016 qlcnic_dev_request_reset(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003017
3018 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003019 if (state == QLCNIC_DEV_NEED_RESET) {
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003020 qlcnic_set_npar_non_operational(adapter);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003021 adapter->need_fw_reset = 1;
Amit Kumar Salechab8c17622010-10-07 23:46:06 +00003022 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3023 goto detach;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003024
Sony Chacko4e708122010-08-31 17:17:44 +00003025 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
3026 if (heartbeat != adapter->heartbeat) {
3027 adapter->heartbeat = heartbeat;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003028 adapter->fw_fail_cnt = 0;
3029 if (adapter->need_fw_reset)
3030 goto detach;
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003031
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003032 if (adapter->reset_context &&
3033 auto_fw_reset == AUTO_FW_RESET_ENABLED) {
Amit Kumar Salecha68bf1c62010-06-22 03:19:03 +00003034 qlcnic_reset_hw_context(adapter);
3035 adapter->netdev->trans_start = jiffies;
3036 }
3037
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003038 return 0;
3039 }
3040
3041 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3042 return 0;
3043
3044 qlcnic_dev_request_reset(adapter);
3045
Amit Kumar Salecha0df170b2010-07-13 20:33:32 +00003046 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED))
3047 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003048
3049 dev_info(&netdev->dev, "firmware hang detected\n");
3050
3051detach:
3052 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3053 QLCNIC_DEV_NEED_RESET;
3054
3055 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003056 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
3057
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003058 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
Amit Kumar Salecha65b5b422010-04-01 19:01:33 +00003059 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3060 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003061
3062 return 1;
3063}
3064
3065static void
3066qlcnic_fw_poll_work(struct work_struct *work)
3067{
3068 struct qlcnic_adapter *adapter = container_of(work,
3069 struct qlcnic_adapter, fw_work.work);
3070
3071 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3072 goto reschedule;
3073
3074
3075 if (qlcnic_check_health(adapter))
3076 return;
3077
Amit Kumar Salechab5e54922010-08-31 17:17:51 +00003078 if (adapter->fhash.fnum)
3079 qlcnic_prune_lb_filters(adapter);
3080
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003081reschedule:
3082 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3083}
3084
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003085static int qlcnic_is_first_func(struct pci_dev *pdev)
3086{
3087 struct pci_dev *oth_pdev;
3088 int val = pdev->devfn;
3089
3090 while (val-- > 0) {
3091 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3092 (pdev->bus), pdev->bus->number,
3093 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003094 if (!oth_pdev)
3095 continue;
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003096
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003097 if (oth_pdev->current_state != PCI_D3cold) {
3098 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003099 return 0;
Amit Kumar Salechabfc978f2010-07-18 14:51:59 -07003100 }
3101 pci_dev_put(oth_pdev);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003102 }
3103 return 1;
3104}
3105
3106static int qlcnic_attach_func(struct pci_dev *pdev)
3107{
3108 int err, first_func;
3109 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3110 struct net_device *netdev = adapter->netdev;
3111
3112 pdev->error_state = pci_channel_io_normal;
3113
3114 err = pci_enable_device(pdev);
3115 if (err)
3116 return err;
3117
3118 pci_set_power_state(pdev, PCI_D0);
3119 pci_set_master(pdev);
3120 pci_restore_state(pdev);
3121
3122 first_func = qlcnic_is_first_func(pdev);
3123
3124 if (qlcnic_api_lock(adapter))
3125 return -EINVAL;
3126
Amit Kumar Salecha933fce122010-08-17 00:34:19 +00003127 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003128 adapter->need_fw_reset = 1;
3129 set_bit(__QLCNIC_START_FW, &adapter->state);
3130 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
3131 QLCDB(adapter, DRV, "Restarting fw\n");
3132 }
3133 qlcnic_api_unlock(adapter);
3134
3135 err = adapter->nic_ops->start_firmware(adapter);
3136 if (err)
3137 return err;
3138
3139 qlcnic_clr_drv_state(adapter);
3140 qlcnic_setup_intr(adapter);
3141
3142 if (netif_running(netdev)) {
3143 err = qlcnic_attach(adapter);
3144 if (err) {
Amit Kumar Salecha21854f02010-08-19 05:08:29 +00003145 qlcnic_clr_all_drv_state(adapter, 1);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003146 clear_bit(__QLCNIC_AER, &adapter->state);
3147 netif_device_attach(netdev);
3148 return err;
3149 }
3150
3151 err = qlcnic_up(adapter, netdev);
3152 if (err)
3153 goto done;
3154
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00003155 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00003156 }
3157 done:
3158 netif_device_attach(netdev);
3159 return err;
3160}
3161
3162static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3163 pci_channel_state_t state)
3164{
3165 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3166 struct net_device *netdev = adapter->netdev;
3167
3168 if (state == pci_channel_io_perm_failure)
3169 return PCI_ERS_RESULT_DISCONNECT;
3170
3171 if (state == pci_channel_io_normal)
3172 return PCI_ERS_RESULT_RECOVERED;
3173
3174 set_bit(__QLCNIC_AER, &adapter->state);
3175 netif_device_detach(netdev);
3176
3177 cancel_delayed_work_sync(&adapter->fw_work);
3178
3179 if (netif_running(netdev))
3180 qlcnic_down(adapter, netdev);
3181
3182 qlcnic_detach(adapter);
3183 qlcnic_teardown_intr(adapter);
3184
3185 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3186
3187 pci_save_state(pdev);
3188 pci_disable_device(pdev);
3189
3190 return PCI_ERS_RESULT_NEED_RESET;
3191}
3192
3193static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3194{
3195 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3196 PCI_ERS_RESULT_RECOVERED;
3197}
3198
3199static void qlcnic_io_resume(struct pci_dev *pdev)
3200{
3201 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3202
3203 pci_cleanup_aer_uncorrect_error_status(pdev);
3204
3205 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
3206 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
3207 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3208 FW_POLL_DELAY);
3209}
3210
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003211static int
3212qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3213{
3214 int err;
3215
3216 err = qlcnic_can_start_firmware(adapter);
3217 if (err)
3218 return err;
3219
Amit Kumar Salecha78f84e12010-08-19 05:08:28 +00003220 err = qlcnic_check_npar_opertional(adapter);
3221 if (err)
3222 return err;
Amit Kumar Salecha3c4b23b2010-08-17 00:34:20 +00003223
Rajesh Borundia174240a2010-08-31 17:17:47 +00003224 err = qlcnic_initialize_nic(adapter);
3225 if (err)
3226 return err;
3227
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003228 qlcnic_check_options(adapter);
3229
Rajesh Borundia73733732010-08-31 17:17:50 +00003230 err = qlcnic_set_eswitch_port_config(adapter);
3231 if (err)
3232 return err;
3233
Anirban Chakraborty87eb7432010-06-03 07:50:56 +00003234 adapter->need_fw_reset = 0;
3235
3236 return err;
3237}
3238
3239static int
3240qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
3241{
3242 return -EOPNOTSUPP;
3243}
3244
3245static int
3246qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
3247{
3248 return -EOPNOTSUPP;
3249}
3250
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003251static ssize_t
3252qlcnic_store_bridged_mode(struct device *dev,
3253 struct device_attribute *attr, const char *buf, size_t len)
3254{
3255 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3256 unsigned long new;
3257 int ret = -EINVAL;
3258
3259 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG))
3260 goto err_out;
3261
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00003262 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003263 goto err_out;
3264
3265 if (strict_strtoul(buf, 2, &new))
3266 goto err_out;
3267
Anirban Chakraborty2e9d7222010-06-01 11:28:51 +00003268 if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003269 ret = len;
3270
3271err_out:
3272 return ret;
3273}
3274
3275static ssize_t
3276qlcnic_show_bridged_mode(struct device *dev,
3277 struct device_attribute *attr, char *buf)
3278{
3279 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3280 int bridged_mode = 0;
3281
3282 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3283 bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
3284
3285 return sprintf(buf, "%d\n", bridged_mode);
3286}
3287
3288static struct device_attribute dev_attr_bridged_mode = {
3289 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
3290 .show = qlcnic_show_bridged_mode,
3291 .store = qlcnic_store_bridged_mode,
3292};
3293
3294static ssize_t
3295qlcnic_store_diag_mode(struct device *dev,
3296 struct device_attribute *attr, const char *buf, size_t len)
3297{
3298 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3299 unsigned long new;
3300
3301 if (strict_strtoul(buf, 2, &new))
3302 return -EINVAL;
3303
3304 if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
3305 adapter->flags ^= QLCNIC_DIAG_ENABLED;
3306
3307 return len;
3308}
3309
3310static ssize_t
3311qlcnic_show_diag_mode(struct device *dev,
3312 struct device_attribute *attr, char *buf)
3313{
3314 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3315
3316 return sprintf(buf, "%d\n",
3317 !!(adapter->flags & QLCNIC_DIAG_ENABLED));
3318}
3319
3320static struct device_attribute dev_attr_diag_mode = {
3321 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
3322 .show = qlcnic_show_diag_mode,
3323 .store = qlcnic_store_diag_mode,
3324};
3325
3326static int
3327qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
3328 loff_t offset, size_t size)
3329{
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003330 size_t crb_size = 4;
3331
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003332 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3333 return -EIO;
3334
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003335 if (offset < QLCNIC_PCI_CRBSPACE) {
3336 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
3337 QLCNIC_PCI_CAMQM_END))
3338 crb_size = 8;
3339 else
3340 return -EINVAL;
3341 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003342
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003343 if ((size != crb_size) || (offset & (crb_size-1)))
3344 return -EINVAL;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003345
3346 return 0;
3347}
3348
3349static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003350qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
3351 struct bin_attribute *attr,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003352 char *buf, loff_t offset, size_t size)
3353{
3354 struct device *dev = container_of(kobj, struct device, kobj);
3355 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3356 u32 data;
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003357 u64 qmdata;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003358 int ret;
3359
3360 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3361 if (ret != 0)
3362 return ret;
3363
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003364 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3365 qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata);
3366 memcpy(buf, &qmdata, size);
3367 } else {
3368 data = QLCRD32(adapter, offset);
3369 memcpy(buf, &data, size);
3370 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003371 return size;
3372}
3373
3374static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003375qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
3376 struct bin_attribute *attr,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003377 char *buf, loff_t offset, size_t size)
3378{
3379 struct device *dev = container_of(kobj, struct device, kobj);
3380 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3381 u32 data;
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003382 u64 qmdata;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003383 int ret;
3384
3385 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3386 if (ret != 0)
3387 return ret;
3388
Dhananjay Phadke897e8c72010-04-01 19:01:29 +00003389 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3390 memcpy(&qmdata, buf, size);
3391 qlcnic_pci_camqm_write_2M(adapter, offset, qmdata);
3392 } else {
3393 memcpy(&data, buf, size);
3394 QLCWR32(adapter, offset, data);
3395 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003396 return size;
3397}
3398
3399static int
3400qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
3401 loff_t offset, size_t size)
3402{
3403 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3404 return -EIO;
3405
3406 if ((size != 8) || (offset & 0x7))
3407 return -EIO;
3408
3409 return 0;
3410}
3411
3412static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003413qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
3414 struct bin_attribute *attr,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003415 char *buf, loff_t offset, size_t size)
3416{
3417 struct device *dev = container_of(kobj, struct device, kobj);
3418 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3419 u64 data;
3420 int ret;
3421
3422 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3423 if (ret != 0)
3424 return ret;
3425
3426 if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
3427 return -EIO;
3428
3429 memcpy(buf, &data, size);
3430
3431 return size;
3432}
3433
3434static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003435qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
3436 struct bin_attribute *attr,
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003437 char *buf, loff_t offset, size_t size)
3438{
3439 struct device *dev = container_of(kobj, struct device, kobj);
3440 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3441 u64 data;
3442 int ret;
3443
3444 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3445 if (ret != 0)
3446 return ret;
3447
3448 memcpy(&data, buf, size);
3449
3450 if (qlcnic_pci_mem_write_2M(adapter, offset, data))
3451 return -EIO;
3452
3453 return size;
3454}
3455
3456
3457static struct bin_attribute bin_attr_crb = {
3458 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
3459 .size = 0,
3460 .read = qlcnic_sysfs_read_crb,
3461 .write = qlcnic_sysfs_write_crb,
3462};
3463
3464static struct bin_attribute bin_attr_mem = {
3465 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
3466 .size = 0,
3467 .read = qlcnic_sysfs_read_mem,
3468 .write = qlcnic_sysfs_write_mem,
3469};
3470
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003471static int
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003472validate_pm_config(struct qlcnic_adapter *adapter,
3473 struct qlcnic_pm_func_cfg *pm_cfg, int count)
3474{
3475
3476 u8 src_pci_func, s_esw_id, d_esw_id;
3477 u8 dest_pci_func;
3478 int i;
3479
3480 for (i = 0; i < count; i++) {
3481 src_pci_func = pm_cfg[i].pci_func;
3482 dest_pci_func = pm_cfg[i].dest_npar;
3483 if (src_pci_func >= QLCNIC_MAX_PCI_FUNC
3484 || dest_pci_func >= QLCNIC_MAX_PCI_FUNC)
3485 return QL_STATUS_INVALID_PARAM;
3486
3487 if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC)
3488 return QL_STATUS_INVALID_PARAM;
3489
3490 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3491 return QL_STATUS_INVALID_PARAM;
3492
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003493 s_esw_id = adapter->npars[src_pci_func].phy_port;
3494 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3495
3496 if (s_esw_id != d_esw_id)
3497 return QL_STATUS_INVALID_PARAM;
3498
3499 }
3500 return 0;
3501
3502}
3503
3504static ssize_t
3505qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3506 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3507{
3508 struct device *dev = container_of(kobj, struct device, kobj);
3509 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3510 struct qlcnic_pm_func_cfg *pm_cfg;
3511 u32 id, action, pci_func;
3512 int count, rem, i, ret;
3513
3514 count = size / sizeof(struct qlcnic_pm_func_cfg);
3515 rem = size % sizeof(struct qlcnic_pm_func_cfg);
3516 if (rem)
3517 return QL_STATUS_INVALID_PARAM;
3518
3519 pm_cfg = (struct qlcnic_pm_func_cfg *) buf;
3520
3521 ret = validate_pm_config(adapter, pm_cfg, count);
3522 if (ret)
3523 return ret;
3524 for (i = 0; i < count; i++) {
3525 pci_func = pm_cfg[i].pci_func;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003526 action = !!pm_cfg[i].action;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003527 id = adapter->npars[pci_func].phy_port;
3528 ret = qlcnic_config_port_mirroring(adapter, id,
3529 action, pci_func);
3530 if (ret)
3531 return ret;
3532 }
3533
3534 for (i = 0; i < count; i++) {
3535 pci_func = pm_cfg[i].pci_func;
3536 id = adapter->npars[pci_func].phy_port;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003537 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003538 adapter->npars[pci_func].dest_npar = id;
3539 }
3540 return size;
3541}
3542
3543static ssize_t
3544qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3545 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3546{
3547 struct device *dev = container_of(kobj, struct device, kobj);
3548 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3549 struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC];
3550 int i;
3551
3552 if (size != sizeof(pm_cfg))
3553 return QL_STATUS_INVALID_PARAM;
3554
3555 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3556 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3557 continue;
3558 pm_cfg[i].action = adapter->npars[i].enable_pm;
3559 pm_cfg[i].dest_npar = 0;
3560 pm_cfg[i].pci_func = i;
3561 }
3562 memcpy(buf, &pm_cfg, size);
3563
3564 return size;
3565}
3566
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003567static int
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003568validate_esw_config(struct qlcnic_adapter *adapter,
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003569 struct qlcnic_esw_func_cfg *esw_cfg, int count)
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003570{
Rajesh Borundia7613c872010-08-31 17:17:48 +00003571 u32 op_mode;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003572 u8 pci_func;
3573 int i;
Rajesh Borundia7613c872010-08-31 17:17:48 +00003574
3575 op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE);
3576
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003577 for (i = 0; i < count; i++) {
3578 pci_func = esw_cfg[i].pci_func;
3579 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3580 return QL_STATUS_INVALID_PARAM;
3581
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003582 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3583 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003584 return QL_STATUS_INVALID_PARAM;
3585
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003586 switch (esw_cfg[i].op_mode) {
3587 case QLCNIC_PORT_DEFAULTS:
Rajesh Borundia7613c872010-08-31 17:17:48 +00003588 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
Rajesh Borundia73733732010-08-31 17:17:50 +00003589 QLCNIC_NON_PRIV_FUNC) {
Rajesh Borundia7613c872010-08-31 17:17:48 +00003590 esw_cfg[i].mac_anti_spoof = 0;
Rajesh Borundia73733732010-08-31 17:17:50 +00003591 esw_cfg[i].mac_override = 1;
Rajesh Borundiaee07c1a2010-10-07 23:46:09 +00003592 esw_cfg[i].promisc_mode = 1;
Rajesh Borundia73733732010-08-31 17:17:50 +00003593 }
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003594 break;
3595 case QLCNIC_ADD_VLAN:
3596 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3597 return QL_STATUS_INVALID_PARAM;
3598 if (!esw_cfg[i].op_type)
3599 return QL_STATUS_INVALID_PARAM;
3600 break;
3601 case QLCNIC_DEL_VLAN:
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003602 if (!esw_cfg[i].op_type)
3603 return QL_STATUS_INVALID_PARAM;
3604 break;
3605 default:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003606 return QL_STATUS_INVALID_PARAM;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003607 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003608 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003609 return 0;
3610}
3611
3612static ssize_t
3613qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3614 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3615{
3616 struct device *dev = container_of(kobj, struct device, kobj);
3617 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3618 struct qlcnic_esw_func_cfg *esw_cfg;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003619 struct qlcnic_npar_info *npar;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003620 int count, rem, i, ret;
Rajesh Borundia0325d692010-08-19 05:08:26 +00003621 u8 pci_func, op_mode = 0;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003622
3623 count = size / sizeof(struct qlcnic_esw_func_cfg);
3624 rem = size % sizeof(struct qlcnic_esw_func_cfg);
3625 if (rem)
3626 return QL_STATUS_INVALID_PARAM;
3627
3628 esw_cfg = (struct qlcnic_esw_func_cfg *) buf;
3629 ret = validate_esw_config(adapter, esw_cfg, count);
3630 if (ret)
3631 return ret;
3632
3633 for (i = 0; i < count; i++) {
Rajesh Borundia0325d692010-08-19 05:08:26 +00003634 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3635 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3636 return QL_STATUS_INVALID_PARAM;
Rajesh Borundiae9a47702010-08-25 04:03:02 +00003637
3638 if (adapter->ahw.pci_func != esw_cfg[i].pci_func)
3639 continue;
3640
3641 op_mode = esw_cfg[i].op_mode;
3642 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3643 esw_cfg[i].op_mode = op_mode;
3644 esw_cfg[i].pci_func = adapter->ahw.pci_func;
3645
3646 switch (esw_cfg[i].op_mode) {
3647 case QLCNIC_PORT_DEFAULTS:
3648 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3649 break;
Amit Kumar Salecha8cf61f82010-08-25 04:03:03 +00003650 case QLCNIC_ADD_VLAN:
3651 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3652 break;
3653 case QLCNIC_DEL_VLAN:
3654 esw_cfg[i].vlan_id = 0;
3655 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3656 break;
Rajesh Borundia0325d692010-08-19 05:08:26 +00003657 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003658 }
3659
Rajesh Borundia0325d692010-08-19 05:08:26 +00003660 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3661 goto out;
Rajesh Borundiae9a47702010-08-25 04:03:02 +00003662
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003663 for (i = 0; i < count; i++) {
3664 pci_func = esw_cfg[i].pci_func;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003665 npar = &adapter->npars[pci_func];
3666 switch (esw_cfg[i].op_mode) {
3667 case QLCNIC_PORT_DEFAULTS:
3668 npar->promisc_mode = esw_cfg[i].promisc_mode;
Rajesh Borundia73733732010-08-31 17:17:50 +00003669 npar->mac_override = esw_cfg[i].mac_override;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003670 npar->offload_flags = esw_cfg[i].offload_flags;
3671 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3672 npar->discard_tagged = esw_cfg[i].discard_tagged;
3673 break;
3674 case QLCNIC_ADD_VLAN:
3675 npar->pvid = esw_cfg[i].vlan_id;
3676 break;
3677 case QLCNIC_DEL_VLAN:
3678 npar->pvid = 0;
3679 break;
3680 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003681 }
Rajesh Borundia0325d692010-08-19 05:08:26 +00003682out:
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003683 return size;
3684}
3685
3686static ssize_t
3687qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3688 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3689{
3690 struct device *dev = container_of(kobj, struct device, kobj);
3691 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3692 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003693 u8 i;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003694
3695 if (size != sizeof(esw_cfg))
3696 return QL_STATUS_INVALID_PARAM;
3697
3698 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3699 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3700 continue;
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00003701 esw_cfg[i].pci_func = i;
3702 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
3703 return QL_STATUS_INVALID_PARAM;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003704 }
3705 memcpy(buf, &esw_cfg, size);
3706
3707 return size;
3708}
3709
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003710static int
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003711validate_npar_config(struct qlcnic_adapter *adapter,
3712 struct qlcnic_npar_func_cfg *np_cfg, int count)
3713{
3714 u8 pci_func, i;
3715
3716 for (i = 0; i < count; i++) {
3717 pci_func = np_cfg[i].pci_func;
3718 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3719 return QL_STATUS_INVALID_PARAM;
3720
3721 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3722 return QL_STATUS_INVALID_PARAM;
3723
3724 if (!IS_VALID_BW(np_cfg[i].min_bw)
3725 || !IS_VALID_BW(np_cfg[i].max_bw)
3726 || !IS_VALID_RX_QUEUES(np_cfg[i].max_rx_queues)
3727 || !IS_VALID_TX_QUEUES(np_cfg[i].max_tx_queues))
3728 return QL_STATUS_INVALID_PARAM;
3729 }
3730 return 0;
3731}
3732
3733static ssize_t
3734qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj,
3735 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3736{
3737 struct device *dev = container_of(kobj, struct device, kobj);
3738 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3739 struct qlcnic_info nic_info;
3740 struct qlcnic_npar_func_cfg *np_cfg;
3741 int i, count, rem, ret;
3742 u8 pci_func;
3743
3744 count = size / sizeof(struct qlcnic_npar_func_cfg);
3745 rem = size % sizeof(struct qlcnic_npar_func_cfg);
3746 if (rem)
3747 return QL_STATUS_INVALID_PARAM;
3748
3749 np_cfg = (struct qlcnic_npar_func_cfg *) buf;
3750 ret = validate_npar_config(adapter, np_cfg, count);
3751 if (ret)
3752 return ret;
3753
3754 for (i = 0; i < count ; i++) {
3755 pci_func = np_cfg[i].pci_func;
3756 ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
3757 if (ret)
3758 return ret;
3759 nic_info.pci_func = pci_func;
3760 nic_info.min_tx_bw = np_cfg[i].min_bw;
3761 nic_info.max_tx_bw = np_cfg[i].max_bw;
3762 ret = qlcnic_set_nic_info(adapter, &nic_info);
3763 if (ret)
3764 return ret;
Anirban Chakrabortycea89752010-07-13 20:33:35 +00003765 adapter->npars[i].min_bw = nic_info.min_tx_bw;
3766 adapter->npars[i].max_bw = nic_info.max_tx_bw;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003767 }
3768
3769 return size;
3770
3771}
3772static ssize_t
3773qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
3774 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3775{
3776 struct device *dev = container_of(kobj, struct device, kobj);
3777 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3778 struct qlcnic_info nic_info;
3779 struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
3780 int i, ret;
3781
3782 if (size != sizeof(np_cfg))
3783 return QL_STATUS_INVALID_PARAM;
3784
3785 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3786 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3787 continue;
3788 ret = qlcnic_get_nic_info(adapter, &nic_info, i);
3789 if (ret)
3790 return ret;
3791
3792 np_cfg[i].pci_func = i;
Sucheta Chakrabortya1c0c452010-10-04 04:20:14 +00003793 np_cfg[i].op_mode = (u8)nic_info.op_mode;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003794 np_cfg[i].port_num = nic_info.phys_port;
3795 np_cfg[i].fw_capab = nic_info.capabilities;
3796 np_cfg[i].min_bw = nic_info.min_tx_bw ;
3797 np_cfg[i].max_bw = nic_info.max_tx_bw;
3798 np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
3799 np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
3800 }
3801 memcpy(buf, &np_cfg, size);
3802 return size;
3803}
3804
3805static ssize_t
Amit Kumar Salechab6021212010-08-17 00:34:22 +00003806qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
3807 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3808{
3809 struct device *dev = container_of(kobj, struct device, kobj);
3810 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3811 struct qlcnic_esw_statistics port_stats;
3812 int ret;
3813
3814 if (size != sizeof(struct qlcnic_esw_statistics))
3815 return QL_STATUS_INVALID_PARAM;
3816
3817 if (offset >= QLCNIC_MAX_PCI_FUNC)
3818 return QL_STATUS_INVALID_PARAM;
3819
3820 memset(&port_stats, 0, size);
3821 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3822 &port_stats.rx);
3823 if (ret)
3824 return ret;
3825
3826 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3827 &port_stats.tx);
3828 if (ret)
3829 return ret;
3830
3831 memcpy(buf, &port_stats, size);
3832 return size;
3833}
3834
3835static ssize_t
3836qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
3837 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3838{
3839 struct device *dev = container_of(kobj, struct device, kobj);
3840 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3841 struct qlcnic_esw_statistics esw_stats;
3842 int ret;
3843
3844 if (size != sizeof(struct qlcnic_esw_statistics))
3845 return QL_STATUS_INVALID_PARAM;
3846
3847 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3848 return QL_STATUS_INVALID_PARAM;
3849
3850 memset(&esw_stats, 0, size);
3851 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3852 &esw_stats.rx);
3853 if (ret)
3854 return ret;
3855
3856 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3857 &esw_stats.tx);
3858 if (ret)
3859 return ret;
3860
3861 memcpy(buf, &esw_stats, size);
3862 return size;
3863}
3864
3865static ssize_t
3866qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
3867 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3868{
3869 struct device *dev = container_of(kobj, struct device, kobj);
3870 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3871 int ret;
3872
3873 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3874 return QL_STATUS_INVALID_PARAM;
3875
3876 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3877 QLCNIC_QUERY_RX_COUNTER);
3878 if (ret)
3879 return ret;
3880
3881 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3882 QLCNIC_QUERY_TX_COUNTER);
3883 if (ret)
3884 return ret;
3885
3886 return size;
3887}
3888
3889static ssize_t
3890qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
3891 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3892{
3893
3894 struct device *dev = container_of(kobj, struct device, kobj);
3895 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3896 int ret;
3897
3898 if (offset >= QLCNIC_MAX_PCI_FUNC)
3899 return QL_STATUS_INVALID_PARAM;
3900
3901 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3902 QLCNIC_QUERY_RX_COUNTER);
3903 if (ret)
3904 return ret;
3905
3906 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3907 QLCNIC_QUERY_TX_COUNTER);
3908 if (ret)
3909 return ret;
3910
3911 return size;
3912}
3913
3914static ssize_t
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003915qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3916 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3917{
3918 struct device *dev = container_of(kobj, struct device, kobj);
3919 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3920 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
Dan Carpentere88db3b2010-08-09 21:49:36 +00003921 struct qlcnic_pci_info *pci_info;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003922 int i, ret;
3923
3924 if (size != sizeof(pci_cfg))
3925 return QL_STATUS_INVALID_PARAM;
3926
Dan Carpentere88db3b2010-08-09 21:49:36 +00003927 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
3928 if (!pci_info)
3929 return -ENOMEM;
3930
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003931 ret = qlcnic_get_pci_info(adapter, pci_info);
Dan Carpentere88db3b2010-08-09 21:49:36 +00003932 if (ret) {
3933 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003934 return ret;
Dan Carpentere88db3b2010-08-09 21:49:36 +00003935 }
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003936
3937 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3938 pci_cfg[i].pci_func = pci_info[i].id;
3939 pci_cfg[i].func_type = pci_info[i].type;
3940 pci_cfg[i].port_num = pci_info[i].default_port;
3941 pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
3942 pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
3943 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
3944 }
3945 memcpy(buf, &pci_cfg, size);
Dan Carpentere88db3b2010-08-09 21:49:36 +00003946 kfree(pci_info);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003947 return size;
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003948}
3949static struct bin_attribute bin_attr_npar_config = {
3950 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
3951 .size = 0,
3952 .read = qlcnic_sysfs_read_npar_config,
3953 .write = qlcnic_sysfs_write_npar_config,
3954};
3955
3956static struct bin_attribute bin_attr_pci_config = {
3957 .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
3958 .size = 0,
3959 .read = qlcnic_sysfs_read_pci_config,
3960 .write = NULL,
3961};
3962
Amit Kumar Salechab6021212010-08-17 00:34:22 +00003963static struct bin_attribute bin_attr_port_stats = {
3964 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
3965 .size = 0,
3966 .read = qlcnic_sysfs_get_port_stats,
3967 .write = qlcnic_sysfs_clear_port_stats,
3968};
3969
3970static struct bin_attribute bin_attr_esw_stats = {
3971 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
3972 .size = 0,
3973 .read = qlcnic_sysfs_get_esw_stats,
3974 .write = qlcnic_sysfs_clear_esw_stats,
3975};
3976
Rajesh K Borundia346fe762010-06-29 08:01:20 +00003977static struct bin_attribute bin_attr_esw_config = {
3978 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
3979 .size = 0,
3980 .read = qlcnic_sysfs_read_esw_config,
3981 .write = qlcnic_sysfs_write_esw_config,
3982};
3983
3984static struct bin_attribute bin_attr_pm_config = {
3985 .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
3986 .size = 0,
3987 .read = qlcnic_sysfs_read_pm_config,
3988 .write = qlcnic_sysfs_write_pm_config,
3989};
3990
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00003991static void
3992qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
3993{
3994 struct device *dev = &adapter->pdev->dev;
3995
3996 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3997 if (device_create_file(dev, &dev_attr_bridged_mode))
3998 dev_warn(dev,
3999 "failed to create bridged_mode sysfs entry\n");
4000}
4001
4002static void
4003qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
4004{
4005 struct device *dev = &adapter->pdev->dev;
4006
4007 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
4008 device_remove_file(dev, &dev_attr_bridged_mode);
4009}
4010
4011static void
4012qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
4013{
4014 struct device *dev = &adapter->pdev->dev;
4015
Amit Kumar Salechab6021212010-08-17 00:34:22 +00004016 if (device_create_bin_file(dev, &bin_attr_port_stats))
4017 dev_info(dev, "failed to create port stats sysfs entry");
4018
Anirban Chakraborty132ff002010-07-09 13:15:05 +00004019 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4020 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004021 if (device_create_file(dev, &dev_attr_diag_mode))
4022 dev_info(dev, "failed to create diag_mode sysfs entry\n");
4023 if (device_create_bin_file(dev, &bin_attr_crb))
4024 dev_info(dev, "failed to create crb sysfs entry\n");
4025 if (device_create_bin_file(dev, &bin_attr_mem))
4026 dev_info(dev, "failed to create mem sysfs entry\n");
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00004027 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4028 return;
4029 if (device_create_bin_file(dev, &bin_attr_esw_config))
4030 dev_info(dev, "failed to create esw config sysfs entry");
4031 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
Rajesh K Borundia346fe762010-06-29 08:01:20 +00004032 return;
4033 if (device_create_bin_file(dev, &bin_attr_pci_config))
4034 dev_info(dev, "failed to create pci config sysfs entry");
4035 if (device_create_bin_file(dev, &bin_attr_npar_config))
4036 dev_info(dev, "failed to create npar config sysfs entry");
Rajesh K Borundia346fe762010-06-29 08:01:20 +00004037 if (device_create_bin_file(dev, &bin_attr_pm_config))
4038 dev_info(dev, "failed to create pm config sysfs entry");
Amit Kumar Salechab6021212010-08-17 00:34:22 +00004039 if (device_create_bin_file(dev, &bin_attr_esw_stats))
4040 dev_info(dev, "failed to create eswitch stats sysfs entry");
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004041}
4042
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004043static void
4044qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
4045{
4046 struct device *dev = &adapter->pdev->dev;
4047
Amit Kumar Salechab6021212010-08-17 00:34:22 +00004048 device_remove_bin_file(dev, &bin_attr_port_stats);
4049
Anirban Chakraborty132ff002010-07-09 13:15:05 +00004050 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4051 return;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004052 device_remove_file(dev, &dev_attr_diag_mode);
4053 device_remove_bin_file(dev, &bin_attr_crb);
4054 device_remove_bin_file(dev, &bin_attr_mem);
Rajesh Borundia4e8acb02010-08-19 05:08:25 +00004055 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4056 return;
4057 device_remove_bin_file(dev, &bin_attr_esw_config);
4058 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
Rajesh K Borundia346fe762010-06-29 08:01:20 +00004059 return;
4060 device_remove_bin_file(dev, &bin_attr_pci_config);
4061 device_remove_bin_file(dev, &bin_attr_npar_config);
Rajesh K Borundia346fe762010-06-29 08:01:20 +00004062 device_remove_bin_file(dev, &bin_attr_pm_config);
Amit Kumar Salechab6021212010-08-17 00:34:22 +00004063 device_remove_bin_file(dev, &bin_attr_esw_stats);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004064}
4065
4066#ifdef CONFIG_INET
4067
4068#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4069
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004070static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004071qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4072 struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004073{
4074 struct in_device *indev;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004075
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004076 indev = in_dev_get(dev);
4077 if (!indev)
4078 return;
4079
4080 for_ifa(indev) {
4081 switch (event) {
4082 case NETDEV_UP:
4083 qlcnic_config_ipaddr(adapter,
4084 ifa->ifa_address, QLCNIC_IP_UP);
4085 break;
4086 case NETDEV_DOWN:
4087 qlcnic_config_ipaddr(adapter,
4088 ifa->ifa_address, QLCNIC_IP_DOWN);
4089 break;
4090 default:
4091 break;
4092 }
4093 } endfor_ifa(indev);
4094
4095 in_dev_put(indev);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004096}
4097
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004098static void
4099qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
4100{
4101 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4102 struct net_device *dev;
4103 u16 vid;
4104
4105 qlcnic_config_indev_addr(adapter, netdev, event);
4106
4107 if (!adapter->vlgrp)
4108 return;
4109
Jesse Grossb7381272010-10-20 13:56:02 +00004110 for (vid = 0; vid < VLAN_N_VID; vid++) {
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004111 dev = vlan_group_get_device(adapter->vlgrp, vid);
4112 if (!dev)
4113 continue;
4114
4115 qlcnic_config_indev_addr(adapter, dev, event);
4116 }
4117}
4118
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004119static int qlcnic_netdev_event(struct notifier_block *this,
4120 unsigned long event, void *ptr)
4121{
4122 struct qlcnic_adapter *adapter;
4123 struct net_device *dev = (struct net_device *)ptr;
4124
4125recheck:
4126 if (dev == NULL)
4127 goto done;
4128
4129 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4130 dev = vlan_dev_real_dev(dev);
4131 goto recheck;
4132 }
4133
4134 if (!is_qlcnic_netdev(dev))
4135 goto done;
4136
4137 adapter = netdev_priv(dev);
4138
4139 if (!adapter)
4140 goto done;
4141
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004142 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004143 goto done;
4144
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004145 qlcnic_config_indev_addr(adapter, dev, event);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004146done:
4147 return NOTIFY_DONE;
4148}
4149
4150static int
4151qlcnic_inetaddr_event(struct notifier_block *this,
4152 unsigned long event, void *ptr)
4153{
4154 struct qlcnic_adapter *adapter;
4155 struct net_device *dev;
4156
4157 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4158
4159 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4160
4161recheck:
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004162 if (dev == NULL)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004163 goto done;
4164
4165 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4166 dev = vlan_dev_real_dev(dev);
4167 goto recheck;
4168 }
4169
4170 if (!is_qlcnic_netdev(dev))
4171 goto done;
4172
4173 adapter = netdev_priv(dev);
4174
Amit Kumar Salecha251a84c2010-05-13 03:07:46 +00004175 if (!adapter)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004176 goto done;
4177
Amit Kumar Salecha8a15ad12010-06-22 03:19:01 +00004178 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004179 goto done;
4180
4181 switch (event) {
4182 case NETDEV_UP:
4183 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
4184 break;
4185 case NETDEV_DOWN:
4186 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
4187 break;
4188 default:
4189 break;
4190 }
4191
4192done:
4193 return NOTIFY_DONE;
4194}
4195
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004196static struct notifier_block qlcnic_netdev_cb = {
4197 .notifier_call = qlcnic_netdev_event,
4198};
4199
4200static struct notifier_block qlcnic_inetaddr_cb = {
4201 .notifier_call = qlcnic_inetaddr_event,
4202};
4203#else
4204static void
Amit Kumar Salechaaec1e842010-09-16 19:14:41 +00004205qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004206{ }
4207#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004208static struct pci_error_handlers qlcnic_err_handler = {
4209 .error_detected = qlcnic_io_error_detected,
4210 .slot_reset = qlcnic_io_slot_reset,
4211 .resume = qlcnic_io_resume,
4212};
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004213
4214static struct pci_driver qlcnic_driver = {
4215 .name = qlcnic_driver_name,
4216 .id_table = qlcnic_pci_tbl,
4217 .probe = qlcnic_probe,
4218 .remove = __devexit_p(qlcnic_remove),
4219#ifdef CONFIG_PM
4220 .suspend = qlcnic_suspend,
4221 .resume = qlcnic_resume,
4222#endif
Sucheta Chakraborty451724c2010-07-13 20:33:34 +00004223 .shutdown = qlcnic_shutdown,
4224 .err_handler = &qlcnic_err_handler
4225
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004226};
4227
4228static int __init qlcnic_init_module(void)
4229{
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004230 int ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004231
4232 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4233
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00004234 qlcnic_wq = create_singlethread_workqueue("qlcnic");
4235 if (qlcnic_wq == NULL) {
4236 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
4237 return -ENOMEM;
4238 }
4239
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004240#ifdef CONFIG_INET
4241 register_netdevice_notifier(&qlcnic_netdev_cb);
4242 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4243#endif
4244
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004245 ret = pci_register_driver(&qlcnic_driver);
4246 if (ret) {
4247#ifdef CONFIG_INET
4248 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4249 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4250#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00004251 destroy_workqueue(qlcnic_wq);
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004252 }
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004253
Amit Kumar Salecha0cf3a142010-07-13 20:33:33 +00004254 return ret;
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004255}
4256
4257module_init(qlcnic_init_module);
4258
4259static void __exit qlcnic_exit_module(void)
4260{
4261
4262 pci_unregister_driver(&qlcnic_driver);
4263
4264#ifdef CONFIG_INET
4265 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4266 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4267#endif
Amit Kumar Salechaf7ec8042010-10-07 23:46:05 +00004268 destroy_workqueue(qlcnic_wq);
Amit Kumar Salechaaf19b492010-01-13 00:37:25 +00004269}
4270
4271module_exit(qlcnic_exit_module);