qlcnic: fix mac anti spoof policy
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / qlcnic / qlcnic_main.c
blob9a3ebb8a820363150547d410a80a2bafcdfa0882
1 /*
2 * Copyright (C) 2009 - QLogic Corporation.
3 * All rights reserved.
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.
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.
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.
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/interrupt.h>
29 #include "qlcnic.h"
31 #include <linux/dma-mapping.h>
32 #include <linux/if_vlan.h>
33 #include <net/ip.h>
34 #include <linux/ipv6.h>
35 #include <linux/inetdevice.h>
36 #include <linux/sysfs.h>
37 #include <linux/aer.h>
39 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
40 MODULE_LICENSE("GPL");
41 MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
42 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
44 char qlcnic_driver_name[] = "qlcnic";
45 static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
46 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
48 static int port_mode = QLCNIC_PORT_MODE_AUTO_NEG;
50 /* Default to restricted 1G auto-neg mode */
51 static int wol_port_mode = 5;
53 static int use_msi = 1;
54 module_param(use_msi, int, 0644);
55 MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
57 static int use_msi_x = 1;
58 module_param(use_msi_x, int, 0644);
59 MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
61 static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
62 module_param(auto_fw_reset, int, 0644);
63 MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
65 static int load_fw_file;
66 module_param(load_fw_file, int, 0644);
67 MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
69 static int qlcnic_config_npars;
70 module_param(qlcnic_config_npars, int, 0644);
71 MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
73 static int __devinit qlcnic_probe(struct pci_dev *pdev,
74 const struct pci_device_id *ent);
75 static void __devexit qlcnic_remove(struct pci_dev *pdev);
76 static int qlcnic_open(struct net_device *netdev);
77 static int qlcnic_close(struct net_device *netdev);
78 static void qlcnic_tx_timeout(struct net_device *netdev);
79 static void qlcnic_attach_work(struct work_struct *work);
80 static void qlcnic_fwinit_work(struct work_struct *work);
81 static void qlcnic_fw_poll_work(struct work_struct *work);
82 static void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
83 work_func_t func, int delay);
84 static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter);
85 static int qlcnic_poll(struct napi_struct *napi, int budget);
86 static int qlcnic_rx_poll(struct napi_struct *napi, int budget);
87 #ifdef CONFIG_NET_POLL_CONTROLLER
88 static void qlcnic_poll_controller(struct net_device *netdev);
89 #endif
91 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter);
92 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter);
93 static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter);
94 static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter);
96 static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
97 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
98 static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
100 static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
101 static irqreturn_t qlcnic_intr(int irq, void *data);
102 static irqreturn_t qlcnic_msi_intr(int irq, void *data);
103 static irqreturn_t qlcnic_msix_intr(int irq, void *data);
105 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
106 static void qlcnic_config_indev_addr(struct net_device *dev, unsigned long);
107 static int qlcnic_start_firmware(struct qlcnic_adapter *);
109 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
110 static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
111 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
112 static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
113 static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
114 struct qlcnic_esw_func_cfg *);
115 /* PCI Device ID Table */
116 #define ENTRY(device) \
117 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
118 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
120 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
122 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
123 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
124 {0,}
127 MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
130 void
131 qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
132 struct qlcnic_host_tx_ring *tx_ring)
134 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
137 static const u32 msi_tgt_status[8] = {
138 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
139 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
140 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
141 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
144 static const
145 struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
147 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring)
149 writel(0, sds_ring->crb_intr_mask);
152 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring)
154 struct qlcnic_adapter *adapter = sds_ring->adapter;
156 writel(0x1, sds_ring->crb_intr_mask);
158 if (!QLCNIC_IS_MSI_FAMILY(adapter))
159 writel(0xfbff, adapter->tgt_mask_reg);
162 static int
163 qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
165 int size = sizeof(struct qlcnic_host_sds_ring) * count;
167 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
169 return (recv_ctx->sds_rings == NULL);
172 static void
173 qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
175 if (recv_ctx->sds_rings != NULL)
176 kfree(recv_ctx->sds_rings);
178 recv_ctx->sds_rings = NULL;
181 static int
182 qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev)
184 int ring;
185 struct qlcnic_host_sds_ring *sds_ring;
186 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
188 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
189 return -ENOMEM;
191 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
192 sds_ring = &recv_ctx->sds_rings[ring];
194 if (ring == adapter->max_sds_rings - 1)
195 netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll,
196 QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings);
197 else
198 netif_napi_add(netdev, &sds_ring->napi,
199 qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2);
202 return 0;
205 static void
206 qlcnic_napi_del(struct qlcnic_adapter *adapter)
208 int ring;
209 struct qlcnic_host_sds_ring *sds_ring;
210 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
212 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
213 sds_ring = &recv_ctx->sds_rings[ring];
214 netif_napi_del(&sds_ring->napi);
217 qlcnic_free_sds_rings(&adapter->recv_ctx);
220 static void
221 qlcnic_napi_enable(struct qlcnic_adapter *adapter)
223 int ring;
224 struct qlcnic_host_sds_ring *sds_ring;
225 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
227 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
228 return;
230 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
231 sds_ring = &recv_ctx->sds_rings[ring];
232 napi_enable(&sds_ring->napi);
233 qlcnic_enable_int(sds_ring);
237 static void
238 qlcnic_napi_disable(struct qlcnic_adapter *adapter)
240 int ring;
241 struct qlcnic_host_sds_ring *sds_ring;
242 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
244 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
245 return;
247 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
248 sds_ring = &recv_ctx->sds_rings[ring];
249 qlcnic_disable_int(sds_ring);
250 napi_synchronize(&sds_ring->napi);
251 napi_disable(&sds_ring->napi);
255 static void qlcnic_clear_stats(struct qlcnic_adapter *adapter)
257 memset(&adapter->stats, 0, sizeof(adapter->stats));
260 static void qlcnic_set_port_mode(struct qlcnic_adapter *adapter)
262 u32 val, data;
264 val = adapter->ahw.board_type;
265 if ((val == QLCNIC_BRDTYPE_P3_HMEZ) ||
266 (val == QLCNIC_BRDTYPE_P3_XG_LOM)) {
267 if (port_mode == QLCNIC_PORT_MODE_802_3_AP) {
268 data = QLCNIC_PORT_MODE_802_3_AP;
269 QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data);
270 } else if (port_mode == QLCNIC_PORT_MODE_XG) {
271 data = QLCNIC_PORT_MODE_XG;
272 QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data);
273 } else if (port_mode == QLCNIC_PORT_MODE_AUTO_NEG_1G) {
274 data = QLCNIC_PORT_MODE_AUTO_NEG_1G;
275 QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data);
276 } else if (port_mode == QLCNIC_PORT_MODE_AUTO_NEG_XG) {
277 data = QLCNIC_PORT_MODE_AUTO_NEG_XG;
278 QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data);
279 } else {
280 data = QLCNIC_PORT_MODE_AUTO_NEG;
281 QLCWR32(adapter, QLCNIC_PORT_MODE_ADDR, data);
284 if ((wol_port_mode != QLCNIC_PORT_MODE_802_3_AP) &&
285 (wol_port_mode != QLCNIC_PORT_MODE_XG) &&
286 (wol_port_mode != QLCNIC_PORT_MODE_AUTO_NEG_1G) &&
287 (wol_port_mode != QLCNIC_PORT_MODE_AUTO_NEG_XG)) {
288 wol_port_mode = QLCNIC_PORT_MODE_AUTO_NEG;
290 QLCWR32(adapter, QLCNIC_WOL_PORT_MODE, wol_port_mode);
294 static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable)
296 u32 control;
297 int pos;
299 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
300 if (pos) {
301 pci_read_config_dword(pdev, pos, &control);
302 if (enable)
303 control |= PCI_MSIX_FLAGS_ENABLE;
304 else
305 control = 0;
306 pci_write_config_dword(pdev, pos, control);
310 static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count)
312 int i;
314 for (i = 0; i < count; i++)
315 adapter->msix_entries[i].entry = i;
318 static int
319 qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
321 u8 mac_addr[ETH_ALEN];
322 struct net_device *netdev = adapter->netdev;
323 struct pci_dev *pdev = adapter->pdev;
325 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
326 return -EIO;
328 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
329 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
330 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
332 /* set station address */
334 if (!is_valid_ether_addr(netdev->perm_addr))
335 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
336 netdev->dev_addr);
338 return 0;
341 static int qlcnic_set_mac(struct net_device *netdev, void *p)
343 struct qlcnic_adapter *adapter = netdev_priv(netdev);
344 struct sockaddr *addr = p;
346 if (!is_valid_ether_addr(addr->sa_data))
347 return -EINVAL;
349 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
350 netif_device_detach(netdev);
351 qlcnic_napi_disable(adapter);
354 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
355 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
356 qlcnic_set_multi(adapter->netdev);
358 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
359 netif_device_attach(netdev);
360 qlcnic_napi_enable(adapter);
362 return 0;
365 static const struct net_device_ops qlcnic_netdev_ops = {
366 .ndo_open = qlcnic_open,
367 .ndo_stop = qlcnic_close,
368 .ndo_start_xmit = qlcnic_xmit_frame,
369 .ndo_get_stats = qlcnic_get_stats,
370 .ndo_validate_addr = eth_validate_addr,
371 .ndo_set_multicast_list = qlcnic_set_multi,
372 .ndo_set_mac_address = qlcnic_set_mac,
373 .ndo_change_mtu = qlcnic_change_mtu,
374 .ndo_tx_timeout = qlcnic_tx_timeout,
375 #ifdef CONFIG_NET_POLL_CONTROLLER
376 .ndo_poll_controller = qlcnic_poll_controller,
377 #endif
380 static struct qlcnic_nic_template qlcnic_ops = {
381 .config_bridged_mode = qlcnic_config_bridged_mode,
382 .config_led = qlcnic_config_led,
383 .start_firmware = qlcnic_start_firmware
386 static struct qlcnic_nic_template qlcnic_vf_ops = {
387 .config_bridged_mode = qlcnicvf_config_bridged_mode,
388 .config_led = qlcnicvf_config_led,
389 .start_firmware = qlcnicvf_start_firmware
392 static void
393 qlcnic_setup_intr(struct qlcnic_adapter *adapter)
395 const struct qlcnic_legacy_intr_set *legacy_intrp;
396 struct pci_dev *pdev = adapter->pdev;
397 int err, num_msix;
399 if (adapter->rss_supported) {
400 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
401 MSIX_ENTRIES_PER_ADAPTER : 2;
402 } else
403 num_msix = 1;
405 adapter->max_sds_rings = 1;
407 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
409 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
411 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
412 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
413 legacy_intrp->tgt_status_reg);
414 adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter,
415 legacy_intrp->tgt_mask_reg);
416 adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR);
418 adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter,
419 ISR_INT_STATE_REG);
421 qlcnic_set_msix_bit(pdev, 0);
423 if (adapter->msix_supported) {
425 qlcnic_init_msix_entries(adapter, num_msix);
426 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
427 if (err == 0) {
428 adapter->flags |= QLCNIC_MSIX_ENABLED;
429 qlcnic_set_msix_bit(pdev, 1);
431 if (adapter->rss_supported)
432 adapter->max_sds_rings = num_msix;
434 dev_info(&pdev->dev, "using msi-x interrupts\n");
435 return;
438 if (err > 0)
439 pci_disable_msix(pdev);
441 /* fall through for msi */
444 if (use_msi && !pci_enable_msi(pdev)) {
445 adapter->flags |= QLCNIC_MSI_ENABLED;
446 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
447 msi_tgt_status[adapter->ahw.pci_func]);
448 dev_info(&pdev->dev, "using msi interrupts\n");
449 adapter->msix_entries[0].vector = pdev->irq;
450 return;
453 dev_info(&pdev->dev, "using legacy interrupts\n");
454 adapter->msix_entries[0].vector = pdev->irq;
457 static void
458 qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
460 if (adapter->flags & QLCNIC_MSIX_ENABLED)
461 pci_disable_msix(adapter->pdev);
462 if (adapter->flags & QLCNIC_MSI_ENABLED)
463 pci_disable_msi(adapter->pdev);
466 static void
467 qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
469 if (adapter->ahw.pci_base0 != NULL)
470 iounmap(adapter->ahw.pci_base0);
473 static int
474 qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
476 struct qlcnic_pci_info *pci_info;
477 int i, ret = 0;
478 u8 pfn;
480 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
481 if (!pci_info)
482 return -ENOMEM;
484 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
485 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
486 if (!adapter->npars) {
487 ret = -ENOMEM;
488 goto err_pci_info;
491 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
492 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
493 if (!adapter->eswitch) {
494 ret = -ENOMEM;
495 goto err_npars;
498 ret = qlcnic_get_pci_info(adapter, pci_info);
499 if (ret)
500 goto err_eswitch;
502 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
503 pfn = pci_info[i].id;
504 if (pfn > QLCNIC_MAX_PCI_FUNC)
505 return QL_STATUS_INVALID_PARAM;
506 adapter->npars[pfn].active = pci_info[i].active;
507 adapter->npars[pfn].type = pci_info[i].type;
508 adapter->npars[pfn].phy_port = pci_info[i].default_port;
509 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
510 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
513 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
514 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
516 kfree(pci_info);
517 return 0;
519 err_eswitch:
520 kfree(adapter->eswitch);
521 adapter->eswitch = NULL;
522 err_npars:
523 kfree(adapter->npars);
524 adapter->npars = NULL;
525 err_pci_info:
526 kfree(pci_info);
528 return ret;
531 static int
532 qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
534 u8 id;
535 u32 ref_count;
536 int i, ret = 1;
537 u32 data = QLCNIC_MGMT_FUNC;
538 void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
540 /* If other drivers are not in use set their privilege level */
541 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
542 ret = qlcnic_api_lock(adapter);
543 if (ret)
544 goto err_lock;
546 if (qlcnic_config_npars) {
547 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
548 id = i;
549 if (adapter->npars[i].type != QLCNIC_TYPE_NIC ||
550 id == adapter->ahw.pci_func)
551 continue;
552 data |= (qlcnic_config_npars &
553 QLC_DEV_SET_DRV(0xf, id));
555 } else {
556 data = readl(priv_op);
557 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) |
558 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
559 adapter->ahw.pci_func));
561 writel(data, priv_op);
562 qlcnic_api_unlock(adapter);
563 err_lock:
564 return ret;
567 static void
568 qlcnic_check_vf(struct qlcnic_adapter *adapter)
570 void __iomem *msix_base_addr;
571 void __iomem *priv_op;
572 u32 func;
573 u32 msix_base;
574 u32 op_mode, priv_level;
576 /* Determine FW API version */
577 adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API);
579 /* Find PCI function number */
580 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
581 msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE;
582 msix_base = readl(msix_base_addr);
583 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
584 adapter->ahw.pci_func = func;
586 /* Determine function privilege level */
587 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
588 op_mode = readl(priv_op);
589 if (op_mode == QLC_DEV_DRV_DEFAULT)
590 priv_level = QLCNIC_MGMT_FUNC;
591 else
592 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
594 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
595 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
596 dev_info(&adapter->pdev->dev,
597 "HAL Version: %d Non Privileged function\n",
598 adapter->fw_hal_version);
599 adapter->nic_ops = &qlcnic_vf_ops;
600 } else
601 adapter->nic_ops = &qlcnic_ops;
604 static int
605 qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
607 void __iomem *mem_ptr0 = NULL;
608 resource_size_t mem_base;
609 unsigned long mem_len, pci_len0 = 0;
611 struct pci_dev *pdev = adapter->pdev;
613 /* remap phys address */
614 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
615 mem_len = pci_resource_len(pdev, 0);
617 if (mem_len == QLCNIC_PCI_2MB_SIZE) {
619 mem_ptr0 = pci_ioremap_bar(pdev, 0);
620 if (mem_ptr0 == NULL) {
621 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
622 return -EIO;
624 pci_len0 = mem_len;
625 } else {
626 return -EIO;
629 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
631 adapter->ahw.pci_base0 = mem_ptr0;
632 adapter->ahw.pci_len0 = pci_len0;
634 qlcnic_check_vf(adapter);
636 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter,
637 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func)));
639 return 0;
642 static void get_brd_name(struct qlcnic_adapter *adapter, char *name)
644 struct pci_dev *pdev = adapter->pdev;
645 int i, found = 0;
647 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
648 if (qlcnic_boards[i].vendor == pdev->vendor &&
649 qlcnic_boards[i].device == pdev->device &&
650 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
651 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
652 sprintf(name, "%pM: %s" ,
653 adapter->mac_addr,
654 qlcnic_boards[i].short_name);
655 found = 1;
656 break;
661 if (!found)
662 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
665 static void
666 qlcnic_check_options(struct qlcnic_adapter *adapter)
668 u32 fw_major, fw_minor, fw_build;
669 struct pci_dev *pdev = adapter->pdev;
671 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
672 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
673 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
675 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
677 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
678 fw_major, fw_minor, fw_build);
680 adapter->flags &= ~QLCNIC_LRO_ENABLED;
682 if (adapter->ahw.port_type == QLCNIC_XGBE) {
683 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
684 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
685 } else if (adapter->ahw.port_type == QLCNIC_GBE) {
686 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
687 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
690 adapter->msix_supported = !!use_msi_x;
691 adapter->rss_supported = !!use_msi_x;
693 adapter->num_txd = MAX_CMD_DESCRIPTORS;
695 adapter->max_rds_rings = MAX_RDS_RINGS;
698 static int
699 qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
701 int err;
702 struct qlcnic_info nic_info;
704 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func);
705 if (err)
706 return err;
708 adapter->physical_port = nic_info.phys_port;
709 adapter->switch_mode = nic_info.switch_mode;
710 adapter->max_tx_ques = nic_info.max_tx_ques;
711 adapter->max_rx_ques = nic_info.max_rx_ques;
712 adapter->capabilities = nic_info.capabilities;
713 adapter->max_mac_filters = nic_info.max_mac_filters;
714 adapter->max_mtu = nic_info.max_mtu;
716 if (adapter->capabilities & BIT_6)
717 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
718 else
719 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
721 return err;
724 static void
725 qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
726 struct qlcnic_esw_func_cfg *esw_cfg)
728 if (esw_cfg->discard_tagged)
729 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
730 else
731 adapter->flags |= QLCNIC_TAGGING_ENABLED;
733 if (esw_cfg->vlan_id)
734 adapter->pvid = esw_cfg->vlan_id;
735 else
736 adapter->pvid = 0;
739 static void
740 qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
741 struct qlcnic_esw_func_cfg *esw_cfg)
743 adapter->flags &= ~QLCNIC_MACSPOOF;
745 if (esw_cfg->mac_anti_spoof)
746 adapter->flags |= QLCNIC_MACSPOOF;
748 qlcnic_set_netdev_features(adapter, esw_cfg);
751 static int
752 qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
754 struct qlcnic_esw_func_cfg esw_cfg;
756 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
757 return 0;
759 esw_cfg.pci_func = adapter->ahw.pci_func;
760 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
761 return -EIO;
762 qlcnic_set_vlan_config(adapter, &esw_cfg);
763 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
765 return 0;
768 static void
769 qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
770 struct qlcnic_esw_func_cfg *esw_cfg)
772 struct net_device *netdev = adapter->netdev;
773 unsigned long features, vlan_features;
775 features = (NETIF_F_SG | NETIF_F_IP_CSUM |
776 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
777 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
778 NETIF_F_IPV6_CSUM);
780 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
781 features |= (NETIF_F_TSO | NETIF_F_TSO6);
782 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
784 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
785 features |= NETIF_F_LRO;
787 if (esw_cfg->offload_flags & BIT_0) {
788 netdev->features |= features;
789 adapter->rx_csum = 1;
790 if (!(esw_cfg->offload_flags & BIT_1))
791 netdev->features &= ~NETIF_F_TSO;
792 if (!(esw_cfg->offload_flags & BIT_2))
793 netdev->features &= ~NETIF_F_TSO6;
794 } else {
795 netdev->features &= ~features;
796 adapter->rx_csum = 0;
799 netdev->vlan_features = (features & vlan_features);
802 static int
803 qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
805 void __iomem *priv_op;
806 u32 op_mode, priv_level;
807 int err = 0;
809 err = qlcnic_initialize_nic(adapter);
810 if (err)
811 return err;
813 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
814 return 0;
816 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
817 op_mode = readl(priv_op);
818 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
820 if (op_mode == QLC_DEV_DRV_DEFAULT)
821 priv_level = QLCNIC_MGMT_FUNC;
822 else
823 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
825 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
826 if (priv_level == QLCNIC_MGMT_FUNC) {
827 adapter->op_mode = QLCNIC_MGMT_FUNC;
828 err = qlcnic_init_pci_info(adapter);
829 if (err)
830 return err;
831 /* Set privilege level for other functions */
832 qlcnic_set_function_modes(adapter);
833 dev_info(&adapter->pdev->dev,
834 "HAL Version: %d, Management function\n",
835 adapter->fw_hal_version);
836 } else if (priv_level == QLCNIC_PRIV_FUNC) {
837 adapter->op_mode = QLCNIC_PRIV_FUNC;
838 dev_info(&adapter->pdev->dev,
839 "HAL Version: %d, Privileged function\n",
840 adapter->fw_hal_version);
844 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
846 return err;
849 static int
850 qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
852 struct qlcnic_esw_func_cfg esw_cfg;
853 struct qlcnic_npar_info *npar;
854 u8 i;
856 if (adapter->need_fw_reset)
857 return 0;
859 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
860 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
861 continue;
862 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
863 esw_cfg.pci_func = i;
864 esw_cfg.offload_flags = BIT_0;
865 esw_cfg.mac_learning = BIT_0;
866 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
867 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
868 if (qlcnic_config_switch_port(adapter, &esw_cfg))
869 return -EIO;
870 npar = &adapter->npars[i];
871 npar->pvid = esw_cfg.vlan_id;
872 npar->mac_learning = esw_cfg.offload_flags;
873 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
874 npar->discard_tagged = esw_cfg.discard_tagged;
875 npar->promisc_mode = esw_cfg.promisc_mode;
876 npar->offload_flags = esw_cfg.offload_flags;
879 return 0;
882 static int
883 qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
884 struct qlcnic_npar_info *npar, int pci_func)
886 struct qlcnic_esw_func_cfg esw_cfg;
887 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
888 esw_cfg.pci_func = pci_func;
889 esw_cfg.vlan_id = npar->pvid;
890 esw_cfg.mac_learning = npar->mac_learning;
891 esw_cfg.discard_tagged = npar->discard_tagged;
892 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
893 esw_cfg.offload_flags = npar->offload_flags;
894 esw_cfg.promisc_mode = npar->promisc_mode;
895 if (qlcnic_config_switch_port(adapter, &esw_cfg))
896 return -EIO;
898 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
899 if (qlcnic_config_switch_port(adapter, &esw_cfg))
900 return -EIO;
902 return 0;
905 static int
906 qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
908 int i, err;
909 struct qlcnic_npar_info *npar;
910 struct qlcnic_info nic_info;
912 if (!adapter->need_fw_reset)
913 return 0;
915 /* Set the NPAR config data after FW reset */
916 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
917 npar = &adapter->npars[i];
918 if (npar->type != QLCNIC_TYPE_NIC)
919 continue;
920 err = qlcnic_get_nic_info(adapter, &nic_info, i);
921 if (err)
922 return err;
923 nic_info.min_tx_bw = npar->min_bw;
924 nic_info.max_tx_bw = npar->max_bw;
925 err = qlcnic_set_nic_info(adapter, &nic_info);
926 if (err)
927 return err;
929 if (npar->enable_pm) {
930 err = qlcnic_config_port_mirroring(adapter,
931 npar->dest_npar, 1, i);
932 if (err)
933 return err;
935 err = qlcnic_reset_eswitch_config(adapter, npar, i);
936 if (err)
937 return err;
939 return 0;
942 static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
944 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
945 u32 npar_state;
947 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
948 return 0;
950 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
951 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
952 msleep(1000);
953 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
955 if (!npar_opt_timeo) {
956 dev_err(&adapter->pdev->dev,
957 "Waiting for NPAR state to opertional timeout\n");
958 return -EIO;
960 return 0;
963 static int
964 qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
966 int err;
968 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
969 adapter->op_mode != QLCNIC_MGMT_FUNC)
970 return 0;
972 err = qlcnic_set_default_offload_settings(adapter);
973 if (err)
974 return err;
976 err = qlcnic_reset_npar_config(adapter);
977 if (err)
978 return err;
980 qlcnic_dev_set_npar_ready(adapter);
982 return err;
985 static int
986 qlcnic_start_firmware(struct qlcnic_adapter *adapter)
988 int err;
990 err = qlcnic_can_start_firmware(adapter);
991 if (err < 0)
992 return err;
993 else if (!err)
994 goto check_fw_status;
996 if (load_fw_file)
997 qlcnic_request_firmware(adapter);
998 else {
999 err = qlcnic_check_flash_fw_ver(adapter);
1000 if (err)
1001 goto err_out;
1003 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
1006 err = qlcnic_need_fw_reset(adapter);
1007 if (err == 0)
1008 goto check_fw_status;
1010 err = qlcnic_pinit_from_rom(adapter);
1011 if (err)
1012 goto err_out;
1013 qlcnic_set_port_mode(adapter);
1015 err = qlcnic_load_firmware(adapter);
1016 if (err)
1017 goto err_out;
1019 qlcnic_release_firmware(adapter);
1020 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
1022 check_fw_status:
1023 err = qlcnic_check_fw_status(adapter);
1024 if (err)
1025 goto err_out;
1027 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
1028 qlcnic_idc_debug_info(adapter, 1);
1030 err = qlcnic_check_eswitch_mode(adapter);
1031 if (err) {
1032 dev_err(&adapter->pdev->dev,
1033 "Memory allocation failed for eswitch\n");
1034 goto err_out;
1036 err = qlcnic_set_mgmt_operations(adapter);
1037 if (err)
1038 goto err_out;
1040 qlcnic_check_options(adapter);
1041 adapter->need_fw_reset = 0;
1043 qlcnic_release_firmware(adapter);
1044 return 0;
1046 err_out:
1047 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
1048 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
1050 qlcnic_release_firmware(adapter);
1051 return err;
1054 static int
1055 qlcnic_request_irq(struct qlcnic_adapter *adapter)
1057 irq_handler_t handler;
1058 struct qlcnic_host_sds_ring *sds_ring;
1059 int err, ring;
1061 unsigned long flags = 0;
1062 struct net_device *netdev = adapter->netdev;
1063 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1065 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1066 handler = qlcnic_tmp_intr;
1067 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1068 flags |= IRQF_SHARED;
1070 } else {
1071 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1072 handler = qlcnic_msix_intr;
1073 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1074 handler = qlcnic_msi_intr;
1075 else {
1076 flags |= IRQF_SHARED;
1077 handler = qlcnic_intr;
1080 adapter->irq = netdev->irq;
1082 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1083 sds_ring = &recv_ctx->sds_rings[ring];
1084 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1085 err = request_irq(sds_ring->irq, handler,
1086 flags, sds_ring->name, sds_ring);
1087 if (err)
1088 return err;
1091 return 0;
1094 static void
1095 qlcnic_free_irq(struct qlcnic_adapter *adapter)
1097 int ring;
1098 struct qlcnic_host_sds_ring *sds_ring;
1100 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1102 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1103 sds_ring = &recv_ctx->sds_rings[ring];
1104 free_irq(sds_ring->irq, sds_ring);
1108 static void
1109 qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter)
1111 adapter->coal.flags = QLCNIC_INTR_DEFAULT;
1112 adapter->coal.normal.data.rx_time_us =
1113 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1114 adapter->coal.normal.data.rx_packets =
1115 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
1116 adapter->coal.normal.data.tx_time_us =
1117 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US;
1118 adapter->coal.normal.data.tx_packets =
1119 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS;
1122 static int
1123 __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1125 int ring;
1126 struct qlcnic_host_rds_ring *rds_ring;
1128 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1129 return -EIO;
1131 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1132 return 0;
1133 if (qlcnic_set_eswitch_port_config(adapter))
1134 return -EIO;
1136 if (qlcnic_fw_create_ctx(adapter))
1137 return -EIO;
1139 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1140 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1141 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1144 qlcnic_set_multi(netdev);
1145 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1147 adapter->ahw.linkup = 0;
1149 if (adapter->max_sds_rings > 1)
1150 qlcnic_config_rss(adapter, 1);
1152 qlcnic_config_intr_coalesce(adapter);
1154 if (netdev->features & NETIF_F_LRO)
1155 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1157 qlcnic_napi_enable(adapter);
1159 qlcnic_linkevent_request(adapter, 1);
1161 adapter->reset_context = 0;
1162 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1163 return 0;
1166 /* Usage: During resume and firmware recovery module.*/
1168 static int
1169 qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1171 int err = 0;
1173 rtnl_lock();
1174 if (netif_running(netdev))
1175 err = __qlcnic_up(adapter, netdev);
1176 rtnl_unlock();
1178 return err;
1181 static void
1182 __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1184 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1185 return;
1187 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1188 return;
1190 smp_mb();
1191 spin_lock(&adapter->tx_clean_lock);
1192 netif_carrier_off(netdev);
1193 netif_tx_disable(netdev);
1195 qlcnic_free_mac_list(adapter);
1197 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1199 qlcnic_napi_disable(adapter);
1201 qlcnic_fw_destroy_ctx(adapter);
1203 qlcnic_reset_rx_buffers_list(adapter);
1204 qlcnic_release_tx_buffers(adapter);
1205 spin_unlock(&adapter->tx_clean_lock);
1208 /* Usage: During suspend and firmware recovery module */
1210 static void
1211 qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1213 rtnl_lock();
1214 if (netif_running(netdev))
1215 __qlcnic_down(adapter, netdev);
1216 rtnl_unlock();
1220 static int
1221 qlcnic_attach(struct qlcnic_adapter *adapter)
1223 struct net_device *netdev = adapter->netdev;
1224 struct pci_dev *pdev = adapter->pdev;
1225 int err;
1227 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1228 return 0;
1230 err = qlcnic_napi_add(adapter, netdev);
1231 if (err)
1232 return err;
1234 err = qlcnic_alloc_sw_resources(adapter);
1235 if (err) {
1236 dev_err(&pdev->dev, "Error in setting sw resources\n");
1237 goto err_out_napi_del;
1240 err = qlcnic_alloc_hw_resources(adapter);
1241 if (err) {
1242 dev_err(&pdev->dev, "Error in setting hw resources\n");
1243 goto err_out_free_sw;
1246 err = qlcnic_request_irq(adapter);
1247 if (err) {
1248 dev_err(&pdev->dev, "failed to setup interrupt\n");
1249 goto err_out_free_hw;
1252 qlcnic_init_coalesce_defaults(adapter);
1254 qlcnic_create_sysfs_entries(adapter);
1256 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1257 return 0;
1259 err_out_free_hw:
1260 qlcnic_free_hw_resources(adapter);
1261 err_out_free_sw:
1262 qlcnic_free_sw_resources(adapter);
1263 err_out_napi_del:
1264 qlcnic_napi_del(adapter);
1265 return err;
1268 static void
1269 qlcnic_detach(struct qlcnic_adapter *adapter)
1271 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1272 return;
1274 qlcnic_remove_sysfs_entries(adapter);
1276 qlcnic_free_hw_resources(adapter);
1277 qlcnic_release_rx_buffers(adapter);
1278 qlcnic_free_irq(adapter);
1279 qlcnic_napi_del(adapter);
1280 qlcnic_free_sw_resources(adapter);
1282 adapter->is_up = 0;
1285 void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1287 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1288 struct qlcnic_host_sds_ring *sds_ring;
1289 int ring;
1291 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
1292 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1293 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1294 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1295 qlcnic_disable_int(sds_ring);
1299 qlcnic_fw_destroy_ctx(adapter);
1301 qlcnic_detach(adapter);
1303 adapter->diag_test = 0;
1304 adapter->max_sds_rings = max_sds_rings;
1306 if (qlcnic_attach(adapter))
1307 goto out;
1309 if (netif_running(netdev))
1310 __qlcnic_up(adapter, netdev);
1311 out:
1312 netif_device_attach(netdev);
1315 int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1317 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1318 struct qlcnic_host_sds_ring *sds_ring;
1319 struct qlcnic_host_rds_ring *rds_ring;
1320 int ring;
1321 int ret;
1323 netif_device_detach(netdev);
1325 if (netif_running(netdev))
1326 __qlcnic_down(adapter, netdev);
1328 qlcnic_detach(adapter);
1330 adapter->max_sds_rings = 1;
1331 adapter->diag_test = test;
1333 ret = qlcnic_attach(adapter);
1334 if (ret) {
1335 netif_device_attach(netdev);
1336 return ret;
1339 ret = qlcnic_fw_create_ctx(adapter);
1340 if (ret) {
1341 qlcnic_detach(adapter);
1342 netif_device_attach(netdev);
1343 return ret;
1346 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1347 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1348 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1351 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1352 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1353 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1354 qlcnic_enable_int(sds_ring);
1357 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1359 return 0;
1362 /* Reset context in hardware only */
1363 static int
1364 qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1366 struct net_device *netdev = adapter->netdev;
1368 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1369 return -EBUSY;
1371 netif_device_detach(netdev);
1373 qlcnic_down(adapter, netdev);
1375 qlcnic_up(adapter, netdev);
1377 netif_device_attach(netdev);
1379 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1380 return 0;
1384 qlcnic_reset_context(struct qlcnic_adapter *adapter)
1386 int err = 0;
1387 struct net_device *netdev = adapter->netdev;
1389 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1390 return -EBUSY;
1392 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1394 netif_device_detach(netdev);
1396 if (netif_running(netdev))
1397 __qlcnic_down(adapter, netdev);
1399 qlcnic_detach(adapter);
1401 if (netif_running(netdev)) {
1402 err = qlcnic_attach(adapter);
1403 if (!err)
1404 __qlcnic_up(adapter, netdev);
1407 netif_device_attach(netdev);
1410 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1411 return err;
1414 static int
1415 qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1416 struct net_device *netdev, u8 pci_using_dac)
1418 int err;
1419 struct pci_dev *pdev = adapter->pdev;
1421 adapter->rx_csum = 1;
1422 adapter->mc_enabled = 0;
1423 adapter->max_mc_count = 38;
1425 netdev->netdev_ops = &qlcnic_netdev_ops;
1426 netdev->watchdog_timeo = 5*HZ;
1428 qlcnic_change_mtu(netdev, netdev->mtu);
1430 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1432 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1433 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
1434 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1435 NETIF_F_IPV6_CSUM);
1437 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
1438 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1439 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1442 if (pci_using_dac) {
1443 netdev->features |= NETIF_F_HIGHDMA;
1444 netdev->vlan_features |= NETIF_F_HIGHDMA;
1447 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
1448 netdev->features |= (NETIF_F_HW_VLAN_TX);
1450 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1451 netdev->features |= NETIF_F_LRO;
1452 netdev->irq = adapter->msix_entries[0].vector;
1454 netif_carrier_off(netdev);
1455 netif_stop_queue(netdev);
1457 err = register_netdev(netdev);
1458 if (err) {
1459 dev_err(&pdev->dev, "failed to register net device\n");
1460 return err;
1463 return 0;
1466 static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac)
1468 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1469 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1470 *pci_using_dac = 1;
1471 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1472 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1473 *pci_using_dac = 0;
1474 else {
1475 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1476 return -EIO;
1479 return 0;
1482 static int __devinit
1483 qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1485 struct net_device *netdev = NULL;
1486 struct qlcnic_adapter *adapter = NULL;
1487 int err;
1488 uint8_t revision_id;
1489 uint8_t pci_using_dac;
1490 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
1492 err = pci_enable_device(pdev);
1493 if (err)
1494 return err;
1496 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1497 err = -ENODEV;
1498 goto err_out_disable_pdev;
1501 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1502 if (err)
1503 goto err_out_disable_pdev;
1505 err = pci_request_regions(pdev, qlcnic_driver_name);
1506 if (err)
1507 goto err_out_disable_pdev;
1509 pci_set_master(pdev);
1510 pci_enable_pcie_error_reporting(pdev);
1512 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1513 if (!netdev) {
1514 dev_err(&pdev->dev, "failed to allocate net_device\n");
1515 err = -ENOMEM;
1516 goto err_out_free_res;
1519 SET_NETDEV_DEV(netdev, &pdev->dev);
1521 adapter = netdev_priv(netdev);
1522 adapter->netdev = netdev;
1523 adapter->pdev = pdev;
1524 adapter->dev_rst_time = jiffies;
1526 revision_id = pdev->revision;
1527 adapter->ahw.revision_id = revision_id;
1529 rwlock_init(&adapter->ahw.crb_lock);
1530 mutex_init(&adapter->ahw.mem_lock);
1532 spin_lock_init(&adapter->tx_clean_lock);
1533 INIT_LIST_HEAD(&adapter->mac_list);
1535 err = qlcnic_setup_pci_map(adapter);
1536 if (err)
1537 goto err_out_free_netdev;
1539 /* This will be reset for mezz cards */
1540 adapter->portnum = adapter->ahw.pci_func;
1542 err = qlcnic_get_board_info(adapter);
1543 if (err) {
1544 dev_err(&pdev->dev, "Error getting board config info.\n");
1545 goto err_out_iounmap;
1548 err = qlcnic_setup_idc_param(adapter);
1549 if (err)
1550 goto err_out_iounmap;
1552 err = adapter->nic_ops->start_firmware(adapter);
1553 if (err) {
1554 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1555 goto err_out_decr_ref;
1558 if (qlcnic_read_mac_addr(adapter))
1559 dev_warn(&pdev->dev, "failed to read mac addr\n");
1561 if (adapter->portnum == 0) {
1562 get_brd_name(adapter, brd_name);
1564 pr_info("%s: %s Board Chip rev 0x%x\n",
1565 module_name(THIS_MODULE),
1566 brd_name, adapter->ahw.revision_id);
1569 qlcnic_clear_stats(adapter);
1571 qlcnic_setup_intr(adapter);
1573 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
1574 if (err)
1575 goto err_out_disable_msi;
1577 pci_set_drvdata(pdev, adapter);
1579 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1581 switch (adapter->ahw.port_type) {
1582 case QLCNIC_GBE:
1583 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1584 adapter->netdev->name);
1585 break;
1586 case QLCNIC_XGBE:
1587 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1588 adapter->netdev->name);
1589 break;
1592 qlcnic_create_diag_entries(adapter);
1594 return 0;
1596 err_out_disable_msi:
1597 qlcnic_teardown_intr(adapter);
1599 err_out_decr_ref:
1600 qlcnic_clr_all_drv_state(adapter, 0);
1602 err_out_iounmap:
1603 qlcnic_cleanup_pci_map(adapter);
1605 err_out_free_netdev:
1606 free_netdev(netdev);
1608 err_out_free_res:
1609 pci_release_regions(pdev);
1611 err_out_disable_pdev:
1612 pci_set_drvdata(pdev, NULL);
1613 pci_disable_device(pdev);
1614 return err;
1617 static void __devexit qlcnic_remove(struct pci_dev *pdev)
1619 struct qlcnic_adapter *adapter;
1620 struct net_device *netdev;
1622 adapter = pci_get_drvdata(pdev);
1623 if (adapter == NULL)
1624 return;
1626 netdev = adapter->netdev;
1628 qlcnic_cancel_fw_work(adapter);
1630 unregister_netdev(netdev);
1632 qlcnic_detach(adapter);
1634 if (adapter->npars != NULL)
1635 kfree(adapter->npars);
1636 if (adapter->eswitch != NULL)
1637 kfree(adapter->eswitch);
1639 qlcnic_clr_all_drv_state(adapter, 0);
1641 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1643 qlcnic_teardown_intr(adapter);
1645 qlcnic_remove_diag_entries(adapter);
1647 qlcnic_cleanup_pci_map(adapter);
1649 qlcnic_release_firmware(adapter);
1651 pci_disable_pcie_error_reporting(pdev);
1652 pci_release_regions(pdev);
1653 pci_disable_device(pdev);
1654 pci_set_drvdata(pdev, NULL);
1656 free_netdev(netdev);
1658 static int __qlcnic_shutdown(struct pci_dev *pdev)
1660 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1661 struct net_device *netdev = adapter->netdev;
1662 int retval;
1664 netif_device_detach(netdev);
1666 qlcnic_cancel_fw_work(adapter);
1668 if (netif_running(netdev))
1669 qlcnic_down(adapter, netdev);
1671 qlcnic_clr_all_drv_state(adapter, 0);
1673 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1675 retval = pci_save_state(pdev);
1676 if (retval)
1677 return retval;
1679 if (qlcnic_wol_supported(adapter)) {
1680 pci_enable_wake(pdev, PCI_D3cold, 1);
1681 pci_enable_wake(pdev, PCI_D3hot, 1);
1684 return 0;
1687 static void qlcnic_shutdown(struct pci_dev *pdev)
1689 if (__qlcnic_shutdown(pdev))
1690 return;
1692 pci_disable_device(pdev);
1695 #ifdef CONFIG_PM
1696 static int
1697 qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1699 int retval;
1701 retval = __qlcnic_shutdown(pdev);
1702 if (retval)
1703 return retval;
1705 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1706 return 0;
1709 static int
1710 qlcnic_resume(struct pci_dev *pdev)
1712 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1713 struct net_device *netdev = adapter->netdev;
1714 int err;
1716 err = pci_enable_device(pdev);
1717 if (err)
1718 return err;
1720 pci_set_power_state(pdev, PCI_D0);
1721 pci_set_master(pdev);
1722 pci_restore_state(pdev);
1724 err = adapter->nic_ops->start_firmware(adapter);
1725 if (err) {
1726 dev_err(&pdev->dev, "failed to start firmware\n");
1727 return err;
1730 if (netif_running(netdev)) {
1731 err = qlcnic_up(adapter, netdev);
1732 if (err)
1733 goto done;
1735 qlcnic_config_indev_addr(netdev, NETDEV_UP);
1737 done:
1738 netif_device_attach(netdev);
1739 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1740 return 0;
1742 #endif
1744 static int qlcnic_open(struct net_device *netdev)
1746 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1747 int err;
1749 err = qlcnic_attach(adapter);
1750 if (err)
1751 return err;
1753 err = __qlcnic_up(adapter, netdev);
1754 if (err)
1755 goto err_out;
1757 netif_start_queue(netdev);
1759 return 0;
1761 err_out:
1762 qlcnic_detach(adapter);
1763 return err;
1767 * qlcnic_close - Disables a network interface entry point
1769 static int qlcnic_close(struct net_device *netdev)
1771 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1773 __qlcnic_down(adapter, netdev);
1774 return 0;
1777 static void
1778 qlcnic_tso_check(struct net_device *netdev,
1779 struct qlcnic_host_tx_ring *tx_ring,
1780 struct cmd_desc_type0 *first_desc,
1781 struct sk_buff *skb)
1783 u8 opcode = TX_ETHER_PKT;
1784 __be16 protocol = skb->protocol;
1785 u16 flags = 0;
1786 int copied, offset, copy_len, hdr_len = 0, tso = 0;
1787 struct cmd_desc_type0 *hwdesc;
1788 struct vlan_ethhdr *vh;
1789 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1790 u32 producer = tx_ring->producer;
1791 int vlan_oob = first_desc->flags_opcode & cpu_to_le16(FLAGS_VLAN_OOB);
1793 if (*(skb->data) & BIT_0) {
1794 flags |= BIT_0;
1795 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
1798 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1799 skb_shinfo(skb)->gso_size > 0) {
1801 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1803 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1804 first_desc->total_hdr_length = hdr_len;
1805 if (vlan_oob) {
1806 first_desc->total_hdr_length += VLAN_HLEN;
1807 first_desc->tcp_hdr_offset = VLAN_HLEN;
1808 first_desc->ip_hdr_offset = VLAN_HLEN;
1809 /* Only in case of TSO on vlan device */
1810 flags |= FLAGS_VLAN_TAGGED;
1813 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
1814 TX_TCP_LSO6 : TX_TCP_LSO;
1815 tso = 1;
1817 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1818 u8 l4proto;
1820 if (protocol == cpu_to_be16(ETH_P_IP)) {
1821 l4proto = ip_hdr(skb)->protocol;
1823 if (l4proto == IPPROTO_TCP)
1824 opcode = TX_TCP_PKT;
1825 else if (l4proto == IPPROTO_UDP)
1826 opcode = TX_UDP_PKT;
1827 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
1828 l4proto = ipv6_hdr(skb)->nexthdr;
1830 if (l4proto == IPPROTO_TCP)
1831 opcode = TX_TCPV6_PKT;
1832 else if (l4proto == IPPROTO_UDP)
1833 opcode = TX_UDPV6_PKT;
1837 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1838 first_desc->ip_hdr_offset += skb_network_offset(skb);
1839 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
1841 if (!tso)
1842 return;
1844 /* For LSO, we need to copy the MAC/IP/TCP headers into
1845 * the descriptor ring
1847 copied = 0;
1848 offset = 2;
1850 if (vlan_oob) {
1851 /* Create a TSO vlan header template for firmware */
1853 hwdesc = &tx_ring->desc_head[producer];
1854 tx_ring->cmd_buf_arr[producer].skb = NULL;
1856 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1857 hdr_len + VLAN_HLEN);
1859 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1860 skb_copy_from_linear_data(skb, vh, 12);
1861 vh->h_vlan_proto = htons(ETH_P_8021Q);
1862 vh->h_vlan_TCI = htons(first_desc->vlan_TCI);
1863 skb_copy_from_linear_data_offset(skb, 12,
1864 (char *)vh + 16, copy_len - 16);
1866 copied = copy_len - VLAN_HLEN;
1867 offset = 0;
1869 producer = get_next_index(producer, tx_ring->num_desc);
1872 while (copied < hdr_len) {
1874 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1875 (hdr_len - copied));
1877 hwdesc = &tx_ring->desc_head[producer];
1878 tx_ring->cmd_buf_arr[producer].skb = NULL;
1880 skb_copy_from_linear_data_offset(skb, copied,
1881 (char *)hwdesc + offset, copy_len);
1883 copied += copy_len;
1884 offset = 0;
1886 producer = get_next_index(producer, tx_ring->num_desc);
1889 tx_ring->producer = producer;
1890 barrier();
1891 adapter->stats.lso_frames++;
1894 static int
1895 qlcnic_map_tx_skb(struct pci_dev *pdev,
1896 struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf)
1898 struct qlcnic_skb_frag *nf;
1899 struct skb_frag_struct *frag;
1900 int i, nr_frags;
1901 dma_addr_t map;
1903 nr_frags = skb_shinfo(skb)->nr_frags;
1904 nf = &pbuf->frag_array[0];
1906 map = pci_map_single(pdev, skb->data,
1907 skb_headlen(skb), PCI_DMA_TODEVICE);
1908 if (pci_dma_mapping_error(pdev, map))
1909 goto out_err;
1911 nf->dma = map;
1912 nf->length = skb_headlen(skb);
1914 for (i = 0; i < nr_frags; i++) {
1915 frag = &skb_shinfo(skb)->frags[i];
1916 nf = &pbuf->frag_array[i+1];
1918 map = pci_map_page(pdev, frag->page, frag->page_offset,
1919 frag->size, PCI_DMA_TODEVICE);
1920 if (pci_dma_mapping_error(pdev, map))
1921 goto unwind;
1923 nf->dma = map;
1924 nf->length = frag->size;
1927 return 0;
1929 unwind:
1930 while (--i >= 0) {
1931 nf = &pbuf->frag_array[i+1];
1932 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
1935 nf = &pbuf->frag_array[0];
1936 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
1938 out_err:
1939 return -ENOMEM;
1942 static int
1943 qlcnic_check_tx_tagging(struct qlcnic_adapter *adapter,
1944 struct sk_buff *skb,
1945 struct cmd_desc_type0 *first_desc)
1947 u8 opcode = 0;
1948 u16 flags = 0;
1949 __be16 protocol = skb->protocol;
1950 struct vlan_ethhdr *vh;
1952 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
1953 vh = (struct vlan_ethhdr *)skb->data;
1954 protocol = vh->h_vlan_encapsulated_proto;
1955 flags = FLAGS_VLAN_TAGGED;
1956 qlcnic_set_tx_vlan_tci(first_desc, ntohs(vh->h_vlan_TCI));
1957 } else if (vlan_tx_tag_present(skb)) {
1958 flags = FLAGS_VLAN_OOB;
1959 qlcnic_set_tx_vlan_tci(first_desc, vlan_tx_tag_get(skb));
1961 if (unlikely(adapter->pvid)) {
1962 if (first_desc->vlan_TCI &&
1963 !(adapter->flags & QLCNIC_TAGGING_ENABLED))
1964 return -EIO;
1965 if (first_desc->vlan_TCI &&
1966 (adapter->flags & QLCNIC_TAGGING_ENABLED))
1967 goto set_flags;
1969 flags = FLAGS_VLAN_OOB;
1970 qlcnic_set_tx_vlan_tci(first_desc, adapter->pvid);
1972 set_flags:
1973 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
1974 return 0;
1977 static inline void
1978 qlcnic_clear_cmddesc(u64 *desc)
1980 desc[0] = 0ULL;
1981 desc[2] = 0ULL;
1982 desc[7] = 0ULL;
1985 netdev_tx_t
1986 qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1988 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1989 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
1990 struct qlcnic_cmd_buffer *pbuf;
1991 struct qlcnic_skb_frag *buffrag;
1992 struct cmd_desc_type0 *hwdesc, *first_desc;
1993 struct pci_dev *pdev;
1994 int i, k;
1996 u32 producer;
1997 int frag_count, no_of_desc;
1998 u32 num_txd = tx_ring->num_desc;
2000 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
2001 netif_stop_queue(netdev);
2002 return NETDEV_TX_BUSY;
2005 if (adapter->flags & QLCNIC_MACSPOOF) {
2006 if (compare_ether_addr(eth_hdr(skb)->h_source,
2007 adapter->mac_addr))
2008 goto drop_packet;
2011 frag_count = skb_shinfo(skb)->nr_frags + 1;
2013 /* 4 fragments per cmd des */
2014 no_of_desc = (frag_count + 3) >> 2;
2016 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
2017 netif_stop_queue(netdev);
2018 smp_mb();
2019 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
2020 netif_start_queue(netdev);
2021 else {
2022 adapter->stats.xmit_off++;
2023 return NETDEV_TX_BUSY;
2027 producer = tx_ring->producer;
2028 pbuf = &tx_ring->cmd_buf_arr[producer];
2030 pdev = adapter->pdev;
2032 first_desc = hwdesc = &tx_ring->desc_head[producer];
2033 qlcnic_clear_cmddesc((u64 *)hwdesc);
2035 if (qlcnic_check_tx_tagging(adapter, skb, first_desc))
2036 goto drop_packet;
2038 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
2039 adapter->stats.tx_dma_map_error++;
2040 goto drop_packet;
2043 pbuf->skb = skb;
2044 pbuf->frag_count = frag_count;
2046 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
2047 qlcnic_set_tx_port(first_desc, adapter->portnum);
2049 for (i = 0; i < frag_count; i++) {
2051 k = i % 4;
2053 if ((k == 0) && (i > 0)) {
2054 /* move to next desc.*/
2055 producer = get_next_index(producer, num_txd);
2056 hwdesc = &tx_ring->desc_head[producer];
2057 qlcnic_clear_cmddesc((u64 *)hwdesc);
2058 tx_ring->cmd_buf_arr[producer].skb = NULL;
2061 buffrag = &pbuf->frag_array[i];
2063 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2064 switch (k) {
2065 case 0:
2066 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2067 break;
2068 case 1:
2069 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2070 break;
2071 case 2:
2072 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2073 break;
2074 case 3:
2075 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2076 break;
2080 tx_ring->producer = get_next_index(producer, num_txd);
2082 qlcnic_tso_check(netdev, tx_ring, first_desc, skb);
2084 qlcnic_update_cmd_producer(adapter, tx_ring);
2086 adapter->stats.txbytes += skb->len;
2087 adapter->stats.xmitcalled++;
2089 return NETDEV_TX_OK;
2091 drop_packet:
2092 adapter->stats.txdropped++;
2093 dev_kfree_skb_any(skb);
2094 return NETDEV_TX_OK;
2097 static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
2099 struct net_device *netdev = adapter->netdev;
2100 u32 temp, temp_state, temp_val;
2101 int rv = 0;
2103 temp = QLCRD32(adapter, CRB_TEMP_STATE);
2105 temp_state = qlcnic_get_temp_state(temp);
2106 temp_val = qlcnic_get_temp_val(temp);
2108 if (temp_state == QLCNIC_TEMP_PANIC) {
2109 dev_err(&netdev->dev,
2110 "Device temperature %d degrees C exceeds"
2111 " maximum allowed. Hardware has been shut down.\n",
2112 temp_val);
2113 rv = 1;
2114 } else if (temp_state == QLCNIC_TEMP_WARN) {
2115 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
2116 dev_err(&netdev->dev,
2117 "Device temperature %d degrees C "
2118 "exceeds operating range."
2119 " Immediate action needed.\n",
2120 temp_val);
2122 } else {
2123 if (adapter->temp == QLCNIC_TEMP_WARN) {
2124 dev_info(&netdev->dev,
2125 "Device temperature is now %d degrees C"
2126 " in normal range.\n", temp_val);
2129 adapter->temp = temp_state;
2130 return rv;
2133 void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2135 struct net_device *netdev = adapter->netdev;
2137 if (adapter->ahw.linkup && !linkup) {
2138 netdev_info(netdev, "NIC Link is down\n");
2139 adapter->ahw.linkup = 0;
2140 if (netif_running(netdev)) {
2141 netif_carrier_off(netdev);
2142 netif_stop_queue(netdev);
2144 } else if (!adapter->ahw.linkup && linkup) {
2145 netdev_info(netdev, "NIC Link is up\n");
2146 adapter->ahw.linkup = 1;
2147 if (netif_running(netdev)) {
2148 netif_carrier_on(netdev);
2149 netif_wake_queue(netdev);
2154 static void qlcnic_tx_timeout(struct net_device *netdev)
2156 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2158 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2159 return;
2161 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
2163 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
2164 adapter->need_fw_reset = 1;
2165 else
2166 adapter->reset_context = 1;
2169 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2171 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2172 struct net_device_stats *stats = &netdev->stats;
2174 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2175 stats->tx_packets = adapter->stats.xmitfinished;
2176 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
2177 stats->tx_bytes = adapter->stats.txbytes;
2178 stats->rx_dropped = adapter->stats.rxdropped;
2179 stats->tx_dropped = adapter->stats.txdropped;
2181 return stats;
2184 static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
2186 u32 status;
2188 status = readl(adapter->isr_int_vec);
2190 if (!(status & adapter->int_vec_bit))
2191 return IRQ_NONE;
2193 /* check interrupt state machine, to be sure */
2194 status = readl(adapter->crb_int_state_reg);
2195 if (!ISR_LEGACY_INT_TRIGGERED(status))
2196 return IRQ_NONE;
2198 writel(0xffffffff, adapter->tgt_status_reg);
2199 /* read twice to ensure write is flushed */
2200 readl(adapter->isr_int_vec);
2201 readl(adapter->isr_int_vec);
2203 return IRQ_HANDLED;
2206 static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2208 struct qlcnic_host_sds_ring *sds_ring = data;
2209 struct qlcnic_adapter *adapter = sds_ring->adapter;
2211 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2212 goto done;
2213 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2214 writel(0xffffffff, adapter->tgt_status_reg);
2215 goto done;
2218 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2219 return IRQ_NONE;
2221 done:
2222 adapter->diag_cnt++;
2223 qlcnic_enable_int(sds_ring);
2224 return IRQ_HANDLED;
2227 static irqreturn_t qlcnic_intr(int irq, void *data)
2229 struct qlcnic_host_sds_ring *sds_ring = data;
2230 struct qlcnic_adapter *adapter = sds_ring->adapter;
2232 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2233 return IRQ_NONE;
2235 napi_schedule(&sds_ring->napi);
2237 return IRQ_HANDLED;
2240 static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2242 struct qlcnic_host_sds_ring *sds_ring = data;
2243 struct qlcnic_adapter *adapter = sds_ring->adapter;
2245 /* clear interrupt */
2246 writel(0xffffffff, adapter->tgt_status_reg);
2248 napi_schedule(&sds_ring->napi);
2249 return IRQ_HANDLED;
2252 static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2254 struct qlcnic_host_sds_ring *sds_ring = data;
2256 napi_schedule(&sds_ring->napi);
2257 return IRQ_HANDLED;
2260 static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter)
2262 u32 sw_consumer, hw_consumer;
2263 int count = 0, i;
2264 struct qlcnic_cmd_buffer *buffer;
2265 struct pci_dev *pdev = adapter->pdev;
2266 struct net_device *netdev = adapter->netdev;
2267 struct qlcnic_skb_frag *frag;
2268 int done;
2269 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2271 if (!spin_trylock(&adapter->tx_clean_lock))
2272 return 1;
2274 sw_consumer = tx_ring->sw_consumer;
2275 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2277 while (sw_consumer != hw_consumer) {
2278 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
2279 if (buffer->skb) {
2280 frag = &buffer->frag_array[0];
2281 pci_unmap_single(pdev, frag->dma, frag->length,
2282 PCI_DMA_TODEVICE);
2283 frag->dma = 0ULL;
2284 for (i = 1; i < buffer->frag_count; i++) {
2285 frag++;
2286 pci_unmap_page(pdev, frag->dma, frag->length,
2287 PCI_DMA_TODEVICE);
2288 frag->dma = 0ULL;
2291 adapter->stats.xmitfinished++;
2292 dev_kfree_skb_any(buffer->skb);
2293 buffer->skb = NULL;
2296 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
2297 if (++count >= MAX_STATUS_HANDLE)
2298 break;
2301 if (count && netif_running(netdev)) {
2302 tx_ring->sw_consumer = sw_consumer;
2304 smp_mb();
2306 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
2307 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
2308 netif_wake_queue(netdev);
2309 adapter->stats.xmit_on++;
2312 adapter->tx_timeo_cnt = 0;
2315 * If everything is freed up to consumer then check if the ring is full
2316 * If the ring is full then check if more needs to be freed and
2317 * schedule the call back again.
2319 * This happens when there are 2 CPUs. One could be freeing and the
2320 * other filling it. If the ring is full when we get out of here and
2321 * the card has already interrupted the host then the host can miss the
2322 * interrupt.
2324 * There is still a possible race condition and the host could miss an
2325 * interrupt. The card has to take care of this.
2327 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2328 done = (sw_consumer == hw_consumer);
2329 spin_unlock(&adapter->tx_clean_lock);
2331 return done;
2334 static int qlcnic_poll(struct napi_struct *napi, int budget)
2336 struct qlcnic_host_sds_ring *sds_ring =
2337 container_of(napi, struct qlcnic_host_sds_ring, napi);
2339 struct qlcnic_adapter *adapter = sds_ring->adapter;
2341 int tx_complete;
2342 int work_done;
2344 tx_complete = qlcnic_process_cmd_ring(adapter);
2346 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2348 if ((work_done < budget) && tx_complete) {
2349 napi_complete(&sds_ring->napi);
2350 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2351 qlcnic_enable_int(sds_ring);
2354 return work_done;
2357 static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
2359 struct qlcnic_host_sds_ring *sds_ring =
2360 container_of(napi, struct qlcnic_host_sds_ring, napi);
2362 struct qlcnic_adapter *adapter = sds_ring->adapter;
2363 int work_done;
2365 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2367 if (work_done < budget) {
2368 napi_complete(&sds_ring->napi);
2369 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2370 qlcnic_enable_int(sds_ring);
2373 return work_done;
2376 #ifdef CONFIG_NET_POLL_CONTROLLER
2377 static void qlcnic_poll_controller(struct net_device *netdev)
2379 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2380 disable_irq(adapter->irq);
2381 qlcnic_intr(adapter->irq, adapter);
2382 enable_irq(adapter->irq);
2384 #endif
2386 static void
2387 qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2389 u32 val;
2391 val = adapter->portnum & 0xf;
2392 val |= encoding << 7;
2393 val |= (jiffies - adapter->dev_rst_time) << 8;
2395 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2396 adapter->dev_rst_time = jiffies;
2399 static int
2400 qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
2402 u32 val;
2404 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2405 state != QLCNIC_DEV_NEED_QUISCENT);
2407 if (qlcnic_api_lock(adapter))
2408 return -EIO;
2410 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2412 if (state == QLCNIC_DEV_NEED_RESET)
2413 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2414 else if (state == QLCNIC_DEV_NEED_QUISCENT)
2415 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
2417 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2419 qlcnic_api_unlock(adapter);
2421 return 0;
2424 static int
2425 qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2427 u32 val;
2429 if (qlcnic_api_lock(adapter))
2430 return -EBUSY;
2432 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2433 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2434 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2436 qlcnic_api_unlock(adapter);
2438 return 0;
2441 static void
2442 qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
2444 u32 val;
2446 if (qlcnic_api_lock(adapter))
2447 goto err;
2449 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2450 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
2451 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2453 if (failed) {
2454 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2455 dev_info(&adapter->pdev->dev,
2456 "Device state set to Failed. Please Reboot\n");
2457 } else if (!(val & 0x11111111))
2458 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2460 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2461 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2462 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2464 qlcnic_api_unlock(adapter);
2465 err:
2466 adapter->fw_fail_cnt = 0;
2467 clear_bit(__QLCNIC_START_FW, &adapter->state);
2468 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2471 /* Grab api lock, before checking state */
2472 static int
2473 qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2475 int act, state;
2477 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2478 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2480 if (((state & 0x11111111) == (act & 0x11111111)) ||
2481 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2482 return 0;
2483 else
2484 return 1;
2487 static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2489 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2491 if (val != QLCNIC_DRV_IDC_VER) {
2492 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2493 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2496 return 0;
2499 static int
2500 qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2502 u32 val, prev_state;
2503 u8 dev_init_timeo = adapter->dev_init_timeo;
2504 u8 portnum = adapter->portnum;
2505 u8 ret;
2507 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2508 return 1;
2510 if (qlcnic_api_lock(adapter))
2511 return -1;
2513 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2514 if (!(val & (1 << (portnum * 4)))) {
2515 QLC_DEV_SET_REF_CNT(val, portnum);
2516 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2519 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2520 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
2522 switch (prev_state) {
2523 case QLCNIC_DEV_COLD:
2524 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2525 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
2526 qlcnic_idc_debug_info(adapter, 0);
2527 qlcnic_api_unlock(adapter);
2528 return 1;
2530 case QLCNIC_DEV_READY:
2531 ret = qlcnic_check_idc_ver(adapter);
2532 qlcnic_api_unlock(adapter);
2533 return ret;
2535 case QLCNIC_DEV_NEED_RESET:
2536 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2537 QLC_DEV_SET_RST_RDY(val, portnum);
2538 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2539 break;
2541 case QLCNIC_DEV_NEED_QUISCENT:
2542 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2543 QLC_DEV_SET_QSCNT_RDY(val, portnum);
2544 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2545 break;
2547 case QLCNIC_DEV_FAILED:
2548 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
2549 qlcnic_api_unlock(adapter);
2550 return -1;
2552 case QLCNIC_DEV_INITIALIZING:
2553 case QLCNIC_DEV_QUISCENT:
2554 break;
2557 qlcnic_api_unlock(adapter);
2559 do {
2560 msleep(1000);
2561 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2563 if (prev_state == QLCNIC_DEV_QUISCENT)
2564 continue;
2565 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
2567 if (!dev_init_timeo) {
2568 dev_err(&adapter->pdev->dev,
2569 "Waiting for device to initialize timeout\n");
2570 return -1;
2573 if (qlcnic_api_lock(adapter))
2574 return -1;
2576 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2577 QLC_DEV_CLR_RST_QSCNT(val, portnum);
2578 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2580 ret = qlcnic_check_idc_ver(adapter);
2581 qlcnic_api_unlock(adapter);
2583 return ret;
2586 static void
2587 qlcnic_fwinit_work(struct work_struct *work)
2589 struct qlcnic_adapter *adapter = container_of(work,
2590 struct qlcnic_adapter, fw_work.work);
2591 u32 dev_state = 0xf;
2593 if (qlcnic_api_lock(adapter))
2594 goto err_ret;
2596 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2597 if (dev_state == QLCNIC_DEV_QUISCENT) {
2598 qlcnic_api_unlock(adapter);
2599 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2600 FW_POLL_DELAY * 2);
2601 return;
2604 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
2605 qlcnic_api_unlock(adapter);
2606 goto wait_npar;
2609 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
2610 dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
2611 adapter->reset_ack_timeo);
2612 goto skip_ack_check;
2615 if (!qlcnic_check_drv_state(adapter)) {
2616 skip_ack_check:
2617 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2619 if (dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2620 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2621 QLCNIC_DEV_QUISCENT);
2622 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2623 FW_POLL_DELAY * 2);
2624 QLCDB(adapter, DRV, "Quiscing the driver\n");
2625 qlcnic_idc_debug_info(adapter, 0);
2627 qlcnic_api_unlock(adapter);
2628 return;
2631 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2632 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2633 QLCNIC_DEV_INITIALIZING);
2634 set_bit(__QLCNIC_START_FW, &adapter->state);
2635 QLCDB(adapter, DRV, "Restarting fw\n");
2636 qlcnic_idc_debug_info(adapter, 0);
2639 qlcnic_api_unlock(adapter);
2641 if (!adapter->nic_ops->start_firmware(adapter)) {
2642 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2643 adapter->fw_wait_cnt = 0;
2644 return;
2646 goto err_ret;
2649 qlcnic_api_unlock(adapter);
2651 wait_npar:
2652 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2653 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
2655 switch (dev_state) {
2656 case QLCNIC_DEV_READY:
2657 if (!adapter->nic_ops->start_firmware(adapter)) {
2658 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2659 adapter->fw_wait_cnt = 0;
2660 return;
2662 case QLCNIC_DEV_FAILED:
2663 break;
2664 default:
2665 qlcnic_schedule_work(adapter,
2666 qlcnic_fwinit_work, FW_POLL_DELAY);
2667 return;
2670 err_ret:
2671 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2672 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
2673 netif_device_attach(adapter->netdev);
2674 qlcnic_clr_all_drv_state(adapter, 0);
2677 static void
2678 qlcnic_detach_work(struct work_struct *work)
2680 struct qlcnic_adapter *adapter = container_of(work,
2681 struct qlcnic_adapter, fw_work.work);
2682 struct net_device *netdev = adapter->netdev;
2683 u32 status;
2685 netif_device_detach(netdev);
2687 qlcnic_down(adapter, netdev);
2689 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2691 if (status & QLCNIC_RCODE_FATAL_ERROR)
2692 goto err_ret;
2694 if (adapter->temp == QLCNIC_TEMP_PANIC)
2695 goto err_ret;
2697 if (qlcnic_set_drv_state(adapter, adapter->dev_state))
2698 goto err_ret;
2700 adapter->fw_wait_cnt = 0;
2702 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2704 return;
2706 err_ret:
2707 dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n",
2708 status, adapter->temp);
2709 netif_device_attach(netdev);
2710 qlcnic_clr_all_drv_state(adapter, 1);
2713 /*Transit NPAR state to NON Operational */
2714 static void
2715 qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2717 u32 state;
2719 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2720 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2721 return;
2723 if (qlcnic_api_lock(adapter))
2724 return;
2725 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2726 qlcnic_api_unlock(adapter);
2729 /*Transit to RESET state from READY state only */
2730 static void
2731 qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2733 u32 state;
2735 adapter->need_fw_reset = 1;
2736 if (qlcnic_api_lock(adapter))
2737 return;
2739 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2741 if (state == QLCNIC_DEV_READY) {
2742 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
2743 QLCDB(adapter, DRV, "NEED_RESET state set\n");
2744 qlcnic_idc_debug_info(adapter, 0);
2747 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2748 qlcnic_api_unlock(adapter);
2751 /* Transit to NPAR READY state from NPAR NOT READY state */
2752 static void
2753 qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2755 if (qlcnic_api_lock(adapter))
2756 return;
2758 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2759 QLCDB(adapter, DRV, "NPAR operational state set\n");
2761 qlcnic_api_unlock(adapter);
2764 static void
2765 qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2766 work_func_t func, int delay)
2768 if (test_bit(__QLCNIC_AER, &adapter->state))
2769 return;
2771 INIT_DELAYED_WORK(&adapter->fw_work, func);
2772 schedule_delayed_work(&adapter->fw_work, round_jiffies_relative(delay));
2775 static void
2776 qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
2778 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2779 msleep(10);
2781 cancel_delayed_work_sync(&adapter->fw_work);
2784 static void
2785 qlcnic_attach_work(struct work_struct *work)
2787 struct qlcnic_adapter *adapter = container_of(work,
2788 struct qlcnic_adapter, fw_work.work);
2789 struct net_device *netdev = adapter->netdev;
2790 u32 npar_state;
2792 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2793 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2794 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2795 qlcnic_clr_all_drv_state(adapter, 0);
2796 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2797 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2798 FW_POLL_DELAY);
2799 else
2800 goto attach;
2801 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2802 return;
2804 attach:
2805 if (netif_running(netdev)) {
2806 if (qlcnic_up(adapter, netdev))
2807 goto done;
2809 qlcnic_config_indev_addr(netdev, NETDEV_UP);
2812 done:
2813 netif_device_attach(netdev);
2814 adapter->fw_fail_cnt = 0;
2815 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2817 if (!qlcnic_clr_drv_state(adapter))
2818 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2819 FW_POLL_DELAY);
2822 static int
2823 qlcnic_check_health(struct qlcnic_adapter *adapter)
2825 u32 state = 0, heartbeat;
2826 struct net_device *netdev = adapter->netdev;
2828 if (qlcnic_check_temp(adapter))
2829 goto detach;
2831 if (adapter->need_fw_reset)
2832 qlcnic_dev_request_reset(adapter);
2834 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2835 if (state == QLCNIC_DEV_NEED_RESET ||
2836 state == QLCNIC_DEV_NEED_QUISCENT) {
2837 qlcnic_set_npar_non_operational(adapter);
2838 adapter->need_fw_reset = 1;
2841 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
2842 if (heartbeat != adapter->heartbeat) {
2843 adapter->heartbeat = heartbeat;
2844 adapter->fw_fail_cnt = 0;
2845 if (adapter->need_fw_reset)
2846 goto detach;
2848 if (adapter->reset_context &&
2849 auto_fw_reset == AUTO_FW_RESET_ENABLED) {
2850 qlcnic_reset_hw_context(adapter);
2851 adapter->netdev->trans_start = jiffies;
2854 return 0;
2857 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2858 return 0;
2860 qlcnic_dev_request_reset(adapter);
2862 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED))
2863 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
2865 dev_info(&netdev->dev, "firmware hang detected\n");
2867 detach:
2868 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
2869 QLCNIC_DEV_NEED_RESET;
2871 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
2872 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
2874 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
2875 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
2878 return 1;
2881 static void
2882 qlcnic_fw_poll_work(struct work_struct *work)
2884 struct qlcnic_adapter *adapter = container_of(work,
2885 struct qlcnic_adapter, fw_work.work);
2887 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2888 goto reschedule;
2891 if (qlcnic_check_health(adapter))
2892 return;
2894 reschedule:
2895 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2898 static int qlcnic_is_first_func(struct pci_dev *pdev)
2900 struct pci_dev *oth_pdev;
2901 int val = pdev->devfn;
2903 while (val-- > 0) {
2904 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
2905 (pdev->bus), pdev->bus->number,
2906 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
2907 if (!oth_pdev)
2908 continue;
2910 if (oth_pdev->current_state != PCI_D3cold) {
2911 pci_dev_put(oth_pdev);
2912 return 0;
2914 pci_dev_put(oth_pdev);
2916 return 1;
2919 static int qlcnic_attach_func(struct pci_dev *pdev)
2921 int err, first_func;
2922 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2923 struct net_device *netdev = adapter->netdev;
2925 pdev->error_state = pci_channel_io_normal;
2927 err = pci_enable_device(pdev);
2928 if (err)
2929 return err;
2931 pci_set_power_state(pdev, PCI_D0);
2932 pci_set_master(pdev);
2933 pci_restore_state(pdev);
2935 first_func = qlcnic_is_first_func(pdev);
2937 if (qlcnic_api_lock(adapter))
2938 return -EINVAL;
2940 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
2941 adapter->need_fw_reset = 1;
2942 set_bit(__QLCNIC_START_FW, &adapter->state);
2943 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2944 QLCDB(adapter, DRV, "Restarting fw\n");
2946 qlcnic_api_unlock(adapter);
2948 err = adapter->nic_ops->start_firmware(adapter);
2949 if (err)
2950 return err;
2952 qlcnic_clr_drv_state(adapter);
2953 qlcnic_setup_intr(adapter);
2955 if (netif_running(netdev)) {
2956 err = qlcnic_attach(adapter);
2957 if (err) {
2958 qlcnic_clr_all_drv_state(adapter, 1);
2959 clear_bit(__QLCNIC_AER, &adapter->state);
2960 netif_device_attach(netdev);
2961 return err;
2964 err = qlcnic_up(adapter, netdev);
2965 if (err)
2966 goto done;
2968 qlcnic_config_indev_addr(netdev, NETDEV_UP);
2970 done:
2971 netif_device_attach(netdev);
2972 return err;
2975 static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
2976 pci_channel_state_t state)
2978 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
2979 struct net_device *netdev = adapter->netdev;
2981 if (state == pci_channel_io_perm_failure)
2982 return PCI_ERS_RESULT_DISCONNECT;
2984 if (state == pci_channel_io_normal)
2985 return PCI_ERS_RESULT_RECOVERED;
2987 set_bit(__QLCNIC_AER, &adapter->state);
2988 netif_device_detach(netdev);
2990 cancel_delayed_work_sync(&adapter->fw_work);
2992 if (netif_running(netdev))
2993 qlcnic_down(adapter, netdev);
2995 qlcnic_detach(adapter);
2996 qlcnic_teardown_intr(adapter);
2998 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3000 pci_save_state(pdev);
3001 pci_disable_device(pdev);
3003 return PCI_ERS_RESULT_NEED_RESET;
3006 static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3008 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3009 PCI_ERS_RESULT_RECOVERED;
3012 static void qlcnic_io_resume(struct pci_dev *pdev)
3014 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3016 pci_cleanup_aer_uncorrect_error_status(pdev);
3018 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
3019 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
3020 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3021 FW_POLL_DELAY);
3024 static int
3025 qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3027 int err;
3029 err = qlcnic_can_start_firmware(adapter);
3030 if (err)
3031 return err;
3033 err = qlcnic_check_npar_opertional(adapter);
3034 if (err)
3035 return err;
3037 err = qlcnic_initialize_nic(adapter);
3038 if (err)
3039 return err;
3041 qlcnic_check_options(adapter);
3043 adapter->need_fw_reset = 0;
3045 return err;
3048 static int
3049 qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
3051 return -EOPNOTSUPP;
3054 static int
3055 qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
3057 return -EOPNOTSUPP;
3060 static ssize_t
3061 qlcnic_store_bridged_mode(struct device *dev,
3062 struct device_attribute *attr, const char *buf, size_t len)
3064 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3065 unsigned long new;
3066 int ret = -EINVAL;
3068 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG))
3069 goto err_out;
3071 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3072 goto err_out;
3074 if (strict_strtoul(buf, 2, &new))
3075 goto err_out;
3077 if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
3078 ret = len;
3080 err_out:
3081 return ret;
3084 static ssize_t
3085 qlcnic_show_bridged_mode(struct device *dev,
3086 struct device_attribute *attr, char *buf)
3088 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3089 int bridged_mode = 0;
3091 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3092 bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
3094 return sprintf(buf, "%d\n", bridged_mode);
3097 static struct device_attribute dev_attr_bridged_mode = {
3098 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
3099 .show = qlcnic_show_bridged_mode,
3100 .store = qlcnic_store_bridged_mode,
3103 static ssize_t
3104 qlcnic_store_diag_mode(struct device *dev,
3105 struct device_attribute *attr, const char *buf, size_t len)
3107 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3108 unsigned long new;
3110 if (strict_strtoul(buf, 2, &new))
3111 return -EINVAL;
3113 if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
3114 adapter->flags ^= QLCNIC_DIAG_ENABLED;
3116 return len;
3119 static ssize_t
3120 qlcnic_show_diag_mode(struct device *dev,
3121 struct device_attribute *attr, char *buf)
3123 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3125 return sprintf(buf, "%d\n",
3126 !!(adapter->flags & QLCNIC_DIAG_ENABLED));
3129 static struct device_attribute dev_attr_diag_mode = {
3130 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
3131 .show = qlcnic_show_diag_mode,
3132 .store = qlcnic_store_diag_mode,
3135 static int
3136 qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
3137 loff_t offset, size_t size)
3139 size_t crb_size = 4;
3141 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3142 return -EIO;
3144 if (offset < QLCNIC_PCI_CRBSPACE) {
3145 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
3146 QLCNIC_PCI_CAMQM_END))
3147 crb_size = 8;
3148 else
3149 return -EINVAL;
3152 if ((size != crb_size) || (offset & (crb_size-1)))
3153 return -EINVAL;
3155 return 0;
3158 static ssize_t
3159 qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
3160 struct bin_attribute *attr,
3161 char *buf, loff_t offset, size_t size)
3163 struct device *dev = container_of(kobj, struct device, kobj);
3164 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3165 u32 data;
3166 u64 qmdata;
3167 int ret;
3169 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3170 if (ret != 0)
3171 return ret;
3173 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3174 qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata);
3175 memcpy(buf, &qmdata, size);
3176 } else {
3177 data = QLCRD32(adapter, offset);
3178 memcpy(buf, &data, size);
3180 return size;
3183 static ssize_t
3184 qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
3185 struct bin_attribute *attr,
3186 char *buf, loff_t offset, size_t size)
3188 struct device *dev = container_of(kobj, struct device, kobj);
3189 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3190 u32 data;
3191 u64 qmdata;
3192 int ret;
3194 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3195 if (ret != 0)
3196 return ret;
3198 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3199 memcpy(&qmdata, buf, size);
3200 qlcnic_pci_camqm_write_2M(adapter, offset, qmdata);
3201 } else {
3202 memcpy(&data, buf, size);
3203 QLCWR32(adapter, offset, data);
3205 return size;
3208 static int
3209 qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
3210 loff_t offset, size_t size)
3212 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3213 return -EIO;
3215 if ((size != 8) || (offset & 0x7))
3216 return -EIO;
3218 return 0;
3221 static ssize_t
3222 qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
3223 struct bin_attribute *attr,
3224 char *buf, loff_t offset, size_t size)
3226 struct device *dev = container_of(kobj, struct device, kobj);
3227 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3228 u64 data;
3229 int ret;
3231 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3232 if (ret != 0)
3233 return ret;
3235 if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
3236 return -EIO;
3238 memcpy(buf, &data, size);
3240 return size;
3243 static ssize_t
3244 qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
3245 struct bin_attribute *attr,
3246 char *buf, loff_t offset, size_t size)
3248 struct device *dev = container_of(kobj, struct device, kobj);
3249 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3250 u64 data;
3251 int ret;
3253 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3254 if (ret != 0)
3255 return ret;
3257 memcpy(&data, buf, size);
3259 if (qlcnic_pci_mem_write_2M(adapter, offset, data))
3260 return -EIO;
3262 return size;
3266 static struct bin_attribute bin_attr_crb = {
3267 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
3268 .size = 0,
3269 .read = qlcnic_sysfs_read_crb,
3270 .write = qlcnic_sysfs_write_crb,
3273 static struct bin_attribute bin_attr_mem = {
3274 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
3275 .size = 0,
3276 .read = qlcnic_sysfs_read_mem,
3277 .write = qlcnic_sysfs_write_mem,
3280 static int
3281 validate_pm_config(struct qlcnic_adapter *adapter,
3282 struct qlcnic_pm_func_cfg *pm_cfg, int count)
3285 u8 src_pci_func, s_esw_id, d_esw_id;
3286 u8 dest_pci_func;
3287 int i;
3289 for (i = 0; i < count; i++) {
3290 src_pci_func = pm_cfg[i].pci_func;
3291 dest_pci_func = pm_cfg[i].dest_npar;
3292 if (src_pci_func >= QLCNIC_MAX_PCI_FUNC
3293 || dest_pci_func >= QLCNIC_MAX_PCI_FUNC)
3294 return QL_STATUS_INVALID_PARAM;
3296 if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC)
3297 return QL_STATUS_INVALID_PARAM;
3299 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3300 return QL_STATUS_INVALID_PARAM;
3302 s_esw_id = adapter->npars[src_pci_func].phy_port;
3303 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3305 if (s_esw_id != d_esw_id)
3306 return QL_STATUS_INVALID_PARAM;
3309 return 0;
3313 static ssize_t
3314 qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3315 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3317 struct device *dev = container_of(kobj, struct device, kobj);
3318 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3319 struct qlcnic_pm_func_cfg *pm_cfg;
3320 u32 id, action, pci_func;
3321 int count, rem, i, ret;
3323 count = size / sizeof(struct qlcnic_pm_func_cfg);
3324 rem = size % sizeof(struct qlcnic_pm_func_cfg);
3325 if (rem)
3326 return QL_STATUS_INVALID_PARAM;
3328 pm_cfg = (struct qlcnic_pm_func_cfg *) buf;
3330 ret = validate_pm_config(adapter, pm_cfg, count);
3331 if (ret)
3332 return ret;
3333 for (i = 0; i < count; i++) {
3334 pci_func = pm_cfg[i].pci_func;
3335 action = !!pm_cfg[i].action;
3336 id = adapter->npars[pci_func].phy_port;
3337 ret = qlcnic_config_port_mirroring(adapter, id,
3338 action, pci_func);
3339 if (ret)
3340 return ret;
3343 for (i = 0; i < count; i++) {
3344 pci_func = pm_cfg[i].pci_func;
3345 id = adapter->npars[pci_func].phy_port;
3346 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
3347 adapter->npars[pci_func].dest_npar = id;
3349 return size;
3352 static ssize_t
3353 qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3354 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3356 struct device *dev = container_of(kobj, struct device, kobj);
3357 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3358 struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC];
3359 int i;
3361 if (size != sizeof(pm_cfg))
3362 return QL_STATUS_INVALID_PARAM;
3364 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3365 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3366 continue;
3367 pm_cfg[i].action = adapter->npars[i].enable_pm;
3368 pm_cfg[i].dest_npar = 0;
3369 pm_cfg[i].pci_func = i;
3371 memcpy(buf, &pm_cfg, size);
3373 return size;
3376 static int
3377 validate_esw_config(struct qlcnic_adapter *adapter,
3378 struct qlcnic_esw_func_cfg *esw_cfg, int count)
3380 u32 op_mode;
3381 u8 pci_func;
3382 int i;
3384 op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE);
3386 for (i = 0; i < count; i++) {
3387 pci_func = esw_cfg[i].pci_func;
3388 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3389 return QL_STATUS_INVALID_PARAM;
3391 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3392 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3393 return QL_STATUS_INVALID_PARAM;
3395 switch (esw_cfg[i].op_mode) {
3396 case QLCNIC_PORT_DEFAULTS:
3397 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
3398 QLCNIC_NON_PRIV_FUNC)
3399 esw_cfg[i].mac_anti_spoof = 0;
3400 break;
3401 case QLCNIC_ADD_VLAN:
3402 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3403 return QL_STATUS_INVALID_PARAM;
3404 if (!esw_cfg[i].op_type)
3405 return QL_STATUS_INVALID_PARAM;
3406 break;
3407 case QLCNIC_DEL_VLAN:
3408 if (!esw_cfg[i].op_type)
3409 return QL_STATUS_INVALID_PARAM;
3410 break;
3411 default:
3412 return QL_STATUS_INVALID_PARAM;
3415 return 0;
3418 static ssize_t
3419 qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3420 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3422 struct device *dev = container_of(kobj, struct device, kobj);
3423 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3424 struct qlcnic_esw_func_cfg *esw_cfg;
3425 struct qlcnic_npar_info *npar;
3426 int count, rem, i, ret;
3427 u8 pci_func, op_mode = 0;
3429 count = size / sizeof(struct qlcnic_esw_func_cfg);
3430 rem = size % sizeof(struct qlcnic_esw_func_cfg);
3431 if (rem)
3432 return QL_STATUS_INVALID_PARAM;
3434 esw_cfg = (struct qlcnic_esw_func_cfg *) buf;
3435 ret = validate_esw_config(adapter, esw_cfg, count);
3436 if (ret)
3437 return ret;
3439 for (i = 0; i < count; i++) {
3440 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3441 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3442 return QL_STATUS_INVALID_PARAM;
3444 if (adapter->ahw.pci_func != esw_cfg[i].pci_func)
3445 continue;
3447 op_mode = esw_cfg[i].op_mode;
3448 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3449 esw_cfg[i].op_mode = op_mode;
3450 esw_cfg[i].pci_func = adapter->ahw.pci_func;
3452 switch (esw_cfg[i].op_mode) {
3453 case QLCNIC_PORT_DEFAULTS:
3454 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3455 break;
3456 case QLCNIC_ADD_VLAN:
3457 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3458 break;
3459 case QLCNIC_DEL_VLAN:
3460 esw_cfg[i].vlan_id = 0;
3461 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3462 break;
3466 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3467 goto out;
3469 for (i = 0; i < count; i++) {
3470 pci_func = esw_cfg[i].pci_func;
3471 npar = &adapter->npars[pci_func];
3472 switch (esw_cfg[i].op_mode) {
3473 case QLCNIC_PORT_DEFAULTS:
3474 npar->promisc_mode = esw_cfg[i].promisc_mode;
3475 npar->mac_learning = esw_cfg[i].mac_learning;
3476 npar->offload_flags = esw_cfg[i].offload_flags;
3477 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3478 npar->discard_tagged = esw_cfg[i].discard_tagged;
3479 break;
3480 case QLCNIC_ADD_VLAN:
3481 npar->pvid = esw_cfg[i].vlan_id;
3482 break;
3483 case QLCNIC_DEL_VLAN:
3484 npar->pvid = 0;
3485 break;
3488 out:
3489 return size;
3492 static ssize_t
3493 qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3494 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3496 struct device *dev = container_of(kobj, struct device, kobj);
3497 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3498 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
3499 u8 i;
3501 if (size != sizeof(esw_cfg))
3502 return QL_STATUS_INVALID_PARAM;
3504 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3505 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3506 continue;
3507 esw_cfg[i].pci_func = i;
3508 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
3509 return QL_STATUS_INVALID_PARAM;
3511 memcpy(buf, &esw_cfg, size);
3513 return size;
3516 static int
3517 validate_npar_config(struct qlcnic_adapter *adapter,
3518 struct qlcnic_npar_func_cfg *np_cfg, int count)
3520 u8 pci_func, i;
3522 for (i = 0; i < count; i++) {
3523 pci_func = np_cfg[i].pci_func;
3524 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3525 return QL_STATUS_INVALID_PARAM;
3527 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3528 return QL_STATUS_INVALID_PARAM;
3530 if (!IS_VALID_BW(np_cfg[i].min_bw)
3531 || !IS_VALID_BW(np_cfg[i].max_bw)
3532 || !IS_VALID_RX_QUEUES(np_cfg[i].max_rx_queues)
3533 || !IS_VALID_TX_QUEUES(np_cfg[i].max_tx_queues))
3534 return QL_STATUS_INVALID_PARAM;
3536 return 0;
3539 static ssize_t
3540 qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj,
3541 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3543 struct device *dev = container_of(kobj, struct device, kobj);
3544 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3545 struct qlcnic_info nic_info;
3546 struct qlcnic_npar_func_cfg *np_cfg;
3547 int i, count, rem, ret;
3548 u8 pci_func;
3550 count = size / sizeof(struct qlcnic_npar_func_cfg);
3551 rem = size % sizeof(struct qlcnic_npar_func_cfg);
3552 if (rem)
3553 return QL_STATUS_INVALID_PARAM;
3555 np_cfg = (struct qlcnic_npar_func_cfg *) buf;
3556 ret = validate_npar_config(adapter, np_cfg, count);
3557 if (ret)
3558 return ret;
3560 for (i = 0; i < count ; i++) {
3561 pci_func = np_cfg[i].pci_func;
3562 ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
3563 if (ret)
3564 return ret;
3565 nic_info.pci_func = pci_func;
3566 nic_info.min_tx_bw = np_cfg[i].min_bw;
3567 nic_info.max_tx_bw = np_cfg[i].max_bw;
3568 ret = qlcnic_set_nic_info(adapter, &nic_info);
3569 if (ret)
3570 return ret;
3571 adapter->npars[i].min_bw = nic_info.min_tx_bw;
3572 adapter->npars[i].max_bw = nic_info.max_tx_bw;
3575 return size;
3578 static ssize_t
3579 qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
3580 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3582 struct device *dev = container_of(kobj, struct device, kobj);
3583 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3584 struct qlcnic_info nic_info;
3585 struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
3586 int i, ret;
3588 if (size != sizeof(np_cfg))
3589 return QL_STATUS_INVALID_PARAM;
3591 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3592 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3593 continue;
3594 ret = qlcnic_get_nic_info(adapter, &nic_info, i);
3595 if (ret)
3596 return ret;
3598 np_cfg[i].pci_func = i;
3599 np_cfg[i].op_mode = nic_info.op_mode;
3600 np_cfg[i].port_num = nic_info.phys_port;
3601 np_cfg[i].fw_capab = nic_info.capabilities;
3602 np_cfg[i].min_bw = nic_info.min_tx_bw ;
3603 np_cfg[i].max_bw = nic_info.max_tx_bw;
3604 np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
3605 np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
3607 memcpy(buf, &np_cfg, size);
3608 return size;
3611 static ssize_t
3612 qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
3613 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3615 struct device *dev = container_of(kobj, struct device, kobj);
3616 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3617 struct qlcnic_esw_statistics port_stats;
3618 int ret;
3620 if (size != sizeof(struct qlcnic_esw_statistics))
3621 return QL_STATUS_INVALID_PARAM;
3623 if (offset >= QLCNIC_MAX_PCI_FUNC)
3624 return QL_STATUS_INVALID_PARAM;
3626 memset(&port_stats, 0, size);
3627 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3628 &port_stats.rx);
3629 if (ret)
3630 return ret;
3632 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3633 &port_stats.tx);
3634 if (ret)
3635 return ret;
3637 memcpy(buf, &port_stats, size);
3638 return size;
3641 static ssize_t
3642 qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
3643 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3645 struct device *dev = container_of(kobj, struct device, kobj);
3646 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3647 struct qlcnic_esw_statistics esw_stats;
3648 int ret;
3650 if (size != sizeof(struct qlcnic_esw_statistics))
3651 return QL_STATUS_INVALID_PARAM;
3653 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3654 return QL_STATUS_INVALID_PARAM;
3656 memset(&esw_stats, 0, size);
3657 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3658 &esw_stats.rx);
3659 if (ret)
3660 return ret;
3662 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3663 &esw_stats.tx);
3664 if (ret)
3665 return ret;
3667 memcpy(buf, &esw_stats, size);
3668 return size;
3671 static ssize_t
3672 qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
3673 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3675 struct device *dev = container_of(kobj, struct device, kobj);
3676 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3677 int ret;
3679 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3680 return QL_STATUS_INVALID_PARAM;
3682 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3683 QLCNIC_QUERY_RX_COUNTER);
3684 if (ret)
3685 return ret;
3687 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3688 QLCNIC_QUERY_TX_COUNTER);
3689 if (ret)
3690 return ret;
3692 return size;
3695 static ssize_t
3696 qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
3697 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3700 struct device *dev = container_of(kobj, struct device, kobj);
3701 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3702 int ret;
3704 if (offset >= QLCNIC_MAX_PCI_FUNC)
3705 return QL_STATUS_INVALID_PARAM;
3707 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3708 QLCNIC_QUERY_RX_COUNTER);
3709 if (ret)
3710 return ret;
3712 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3713 QLCNIC_QUERY_TX_COUNTER);
3714 if (ret)
3715 return ret;
3717 return size;
3720 static ssize_t
3721 qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3722 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3724 struct device *dev = container_of(kobj, struct device, kobj);
3725 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3726 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
3727 struct qlcnic_pci_info *pci_info;
3728 int i, ret;
3730 if (size != sizeof(pci_cfg))
3731 return QL_STATUS_INVALID_PARAM;
3733 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
3734 if (!pci_info)
3735 return -ENOMEM;
3737 ret = qlcnic_get_pci_info(adapter, pci_info);
3738 if (ret) {
3739 kfree(pci_info);
3740 return ret;
3743 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3744 pci_cfg[i].pci_func = pci_info[i].id;
3745 pci_cfg[i].func_type = pci_info[i].type;
3746 pci_cfg[i].port_num = pci_info[i].default_port;
3747 pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
3748 pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
3749 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
3751 memcpy(buf, &pci_cfg, size);
3752 kfree(pci_info);
3753 return size;
3755 static struct bin_attribute bin_attr_npar_config = {
3756 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
3757 .size = 0,
3758 .read = qlcnic_sysfs_read_npar_config,
3759 .write = qlcnic_sysfs_write_npar_config,
3762 static struct bin_attribute bin_attr_pci_config = {
3763 .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
3764 .size = 0,
3765 .read = qlcnic_sysfs_read_pci_config,
3766 .write = NULL,
3769 static struct bin_attribute bin_attr_port_stats = {
3770 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
3771 .size = 0,
3772 .read = qlcnic_sysfs_get_port_stats,
3773 .write = qlcnic_sysfs_clear_port_stats,
3776 static struct bin_attribute bin_attr_esw_stats = {
3777 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
3778 .size = 0,
3779 .read = qlcnic_sysfs_get_esw_stats,
3780 .write = qlcnic_sysfs_clear_esw_stats,
3783 static struct bin_attribute bin_attr_esw_config = {
3784 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
3785 .size = 0,
3786 .read = qlcnic_sysfs_read_esw_config,
3787 .write = qlcnic_sysfs_write_esw_config,
3790 static struct bin_attribute bin_attr_pm_config = {
3791 .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
3792 .size = 0,
3793 .read = qlcnic_sysfs_read_pm_config,
3794 .write = qlcnic_sysfs_write_pm_config,
3797 static void
3798 qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
3800 struct device *dev = &adapter->pdev->dev;
3802 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3803 if (device_create_file(dev, &dev_attr_bridged_mode))
3804 dev_warn(dev,
3805 "failed to create bridged_mode sysfs entry\n");
3808 static void
3809 qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
3811 struct device *dev = &adapter->pdev->dev;
3813 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3814 device_remove_file(dev, &dev_attr_bridged_mode);
3817 static void
3818 qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
3820 struct device *dev = &adapter->pdev->dev;
3822 if (device_create_bin_file(dev, &bin_attr_port_stats))
3823 dev_info(dev, "failed to create port stats sysfs entry");
3825 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
3826 return;
3827 if (device_create_file(dev, &dev_attr_diag_mode))
3828 dev_info(dev, "failed to create diag_mode sysfs entry\n");
3829 if (device_create_bin_file(dev, &bin_attr_crb))
3830 dev_info(dev, "failed to create crb sysfs entry\n");
3831 if (device_create_bin_file(dev, &bin_attr_mem))
3832 dev_info(dev, "failed to create mem sysfs entry\n");
3833 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
3834 return;
3835 if (device_create_bin_file(dev, &bin_attr_esw_config))
3836 dev_info(dev, "failed to create esw config sysfs entry");
3837 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3838 return;
3839 if (device_create_bin_file(dev, &bin_attr_pci_config))
3840 dev_info(dev, "failed to create pci config sysfs entry");
3841 if (device_create_bin_file(dev, &bin_attr_npar_config))
3842 dev_info(dev, "failed to create npar config sysfs entry");
3843 if (device_create_bin_file(dev, &bin_attr_pm_config))
3844 dev_info(dev, "failed to create pm config sysfs entry");
3845 if (device_create_bin_file(dev, &bin_attr_esw_stats))
3846 dev_info(dev, "failed to create eswitch stats sysfs entry");
3849 static void
3850 qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
3852 struct device *dev = &adapter->pdev->dev;
3854 device_remove_bin_file(dev, &bin_attr_port_stats);
3856 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
3857 return;
3858 device_remove_file(dev, &dev_attr_diag_mode);
3859 device_remove_bin_file(dev, &bin_attr_crb);
3860 device_remove_bin_file(dev, &bin_attr_mem);
3861 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
3862 return;
3863 device_remove_bin_file(dev, &bin_attr_esw_config);
3864 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3865 return;
3866 device_remove_bin_file(dev, &bin_attr_pci_config);
3867 device_remove_bin_file(dev, &bin_attr_npar_config);
3868 device_remove_bin_file(dev, &bin_attr_pm_config);
3869 device_remove_bin_file(dev, &bin_attr_esw_stats);
3872 #ifdef CONFIG_INET
3874 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3876 static void
3877 qlcnic_config_indev_addr(struct net_device *dev, unsigned long event)
3879 struct in_device *indev;
3880 struct qlcnic_adapter *adapter = netdev_priv(dev);
3882 indev = in_dev_get(dev);
3883 if (!indev)
3884 return;
3886 for_ifa(indev) {
3887 switch (event) {
3888 case NETDEV_UP:
3889 qlcnic_config_ipaddr(adapter,
3890 ifa->ifa_address, QLCNIC_IP_UP);
3891 break;
3892 case NETDEV_DOWN:
3893 qlcnic_config_ipaddr(adapter,
3894 ifa->ifa_address, QLCNIC_IP_DOWN);
3895 break;
3896 default:
3897 break;
3899 } endfor_ifa(indev);
3901 in_dev_put(indev);
3904 static int qlcnic_netdev_event(struct notifier_block *this,
3905 unsigned long event, void *ptr)
3907 struct qlcnic_adapter *adapter;
3908 struct net_device *dev = (struct net_device *)ptr;
3910 recheck:
3911 if (dev == NULL)
3912 goto done;
3914 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3915 dev = vlan_dev_real_dev(dev);
3916 goto recheck;
3919 if (!is_qlcnic_netdev(dev))
3920 goto done;
3922 adapter = netdev_priv(dev);
3924 if (!adapter)
3925 goto done;
3927 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3928 goto done;
3930 qlcnic_config_indev_addr(dev, event);
3931 done:
3932 return NOTIFY_DONE;
3935 static int
3936 qlcnic_inetaddr_event(struct notifier_block *this,
3937 unsigned long event, void *ptr)
3939 struct qlcnic_adapter *adapter;
3940 struct net_device *dev;
3942 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
3944 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3946 recheck:
3947 if (dev == NULL || !netif_running(dev))
3948 goto done;
3950 if (dev->priv_flags & IFF_802_1Q_VLAN) {
3951 dev = vlan_dev_real_dev(dev);
3952 goto recheck;
3955 if (!is_qlcnic_netdev(dev))
3956 goto done;
3958 adapter = netdev_priv(dev);
3960 if (!adapter)
3961 goto done;
3963 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3964 goto done;
3966 switch (event) {
3967 case NETDEV_UP:
3968 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
3969 break;
3970 case NETDEV_DOWN:
3971 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
3972 break;
3973 default:
3974 break;
3977 done:
3978 return NOTIFY_DONE;
3981 static struct notifier_block qlcnic_netdev_cb = {
3982 .notifier_call = qlcnic_netdev_event,
3985 static struct notifier_block qlcnic_inetaddr_cb = {
3986 .notifier_call = qlcnic_inetaddr_event,
3988 #else
3989 static void
3990 qlcnic_config_indev_addr(struct net_device *dev, unsigned long event)
3992 #endif
3993 static struct pci_error_handlers qlcnic_err_handler = {
3994 .error_detected = qlcnic_io_error_detected,
3995 .slot_reset = qlcnic_io_slot_reset,
3996 .resume = qlcnic_io_resume,
3999 static struct pci_driver qlcnic_driver = {
4000 .name = qlcnic_driver_name,
4001 .id_table = qlcnic_pci_tbl,
4002 .probe = qlcnic_probe,
4003 .remove = __devexit_p(qlcnic_remove),
4004 #ifdef CONFIG_PM
4005 .suspend = qlcnic_suspend,
4006 .resume = qlcnic_resume,
4007 #endif
4008 .shutdown = qlcnic_shutdown,
4009 .err_handler = &qlcnic_err_handler
4013 static int __init qlcnic_init_module(void)
4015 int ret;
4017 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4019 #ifdef CONFIG_INET
4020 register_netdevice_notifier(&qlcnic_netdev_cb);
4021 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4022 #endif
4024 ret = pci_register_driver(&qlcnic_driver);
4025 if (ret) {
4026 #ifdef CONFIG_INET
4027 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4028 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4029 #endif
4032 return ret;
4035 module_init(qlcnic_init_module);
4037 static void __exit qlcnic_exit_module(void)
4040 pci_unregister_driver(&qlcnic_driver);
4042 #ifdef CONFIG_INET
4043 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4044 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4045 #endif
4048 module_exit(qlcnic_exit_module);