2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include <linux/slab.h>
9 #include <linux/vmalloc.h>
10 #include <linux/interrupt.h>
14 #include <linux/swab.h>
15 #include <linux/dma-mapping.h>
17 #include <linux/ipv6.h>
18 #include <linux/inetdevice.h>
19 #include <linux/sysfs.h>
20 #include <linux/aer.h>
21 #include <linux/log2.h>
23 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
24 MODULE_LICENSE("GPL");
25 MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
26 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
28 char qlcnic_driver_name[] = "qlcnic";
29 static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
30 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
32 static struct workqueue_struct *qlcnic_wq;
33 static int qlcnic_mac_learn;
34 module_param(qlcnic_mac_learn, int, 0444);
35 MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
37 static int use_msi = 1;
38 module_param(use_msi, int, 0444);
39 MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
41 static int use_msi_x = 1;
42 module_param(use_msi_x, int, 0444);
43 MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
45 static int auto_fw_reset = 1;
46 module_param(auto_fw_reset, int, 0644);
47 MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
49 static int load_fw_file;
50 module_param(load_fw_file, int, 0444);
51 MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
53 static int qlcnic_config_npars;
54 module_param(qlcnic_config_npars, int, 0444);
55 MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
57 static int __devinit qlcnic_probe(struct pci_dev *pdev,
58 const struct pci_device_id *ent);
59 static void __devexit qlcnic_remove(struct pci_dev *pdev);
60 static int qlcnic_open(struct net_device *netdev);
61 static int qlcnic_close(struct net_device *netdev);
62 static void qlcnic_tx_timeout(struct net_device *netdev);
63 static void qlcnic_attach_work(struct work_struct *work);
64 static void qlcnic_fwinit_work(struct work_struct *work);
65 static void qlcnic_fw_poll_work(struct work_struct *work);
66 static void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
67 work_func_t func, int delay);
68 static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter);
69 static int qlcnic_poll(struct napi_struct *napi, int budget);
70 static int qlcnic_rx_poll(struct napi_struct *napi, int budget);
71 #ifdef CONFIG_NET_POLL_CONTROLLER
72 static void qlcnic_poll_controller(struct net_device *netdev);
75 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter);
76 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter);
77 static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter);
78 static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter);
80 static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
81 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
82 static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
84 static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
85 static irqreturn_t qlcnic_intr(int irq, void *data);
86 static irqreturn_t qlcnic_msi_intr(int irq, void *data);
87 static irqreturn_t qlcnic_msix_intr(int irq, void *data);
89 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
90 static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long);
91 static int qlcnic_start_firmware(struct qlcnic_adapter *);
93 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
94 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
95 static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
96 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
97 static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
98 static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
99 struct qlcnic_esw_func_cfg *);
100 static int qlcnic_vlan_rx_add(struct net_device *, u16);
101 static int qlcnic_vlan_rx_del(struct net_device *, u16);
103 /* PCI Device ID Table */
104 #define ENTRY(device) \
105 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
106 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
108 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
110 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
111 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
115 MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
119 qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
120 struct qlcnic_host_tx_ring *tx_ring)
122 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
125 static const u32 msi_tgt_status[8] = {
126 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
127 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
128 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
129 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
133 struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
135 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring)
137 writel(0, sds_ring->crb_intr_mask);
140 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring)
142 struct qlcnic_adapter *adapter = sds_ring->adapter;
144 writel(0x1, sds_ring->crb_intr_mask);
146 if (!QLCNIC_IS_MSI_FAMILY(adapter))
147 writel(0xfbff, adapter->tgt_mask_reg);
151 qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
153 int size = sizeof(struct qlcnic_host_sds_ring) * count;
155 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
157 return recv_ctx->sds_rings == NULL;
161 qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
163 if (recv_ctx->sds_rings != NULL)
164 kfree(recv_ctx->sds_rings);
166 recv_ctx->sds_rings = NULL;
170 qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev)
173 struct qlcnic_host_sds_ring *sds_ring;
174 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
176 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
179 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
180 sds_ring = &recv_ctx->sds_rings[ring];
182 if (ring == adapter->max_sds_rings - 1)
183 netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll,
184 QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings);
186 netif_napi_add(netdev, &sds_ring->napi,
187 qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2);
194 qlcnic_napi_del(struct qlcnic_adapter *adapter)
197 struct qlcnic_host_sds_ring *sds_ring;
198 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
200 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
201 sds_ring = &recv_ctx->sds_rings[ring];
202 netif_napi_del(&sds_ring->napi);
205 qlcnic_free_sds_rings(adapter->recv_ctx);
209 qlcnic_napi_enable(struct qlcnic_adapter *adapter)
212 struct qlcnic_host_sds_ring *sds_ring;
213 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
215 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
218 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
219 sds_ring = &recv_ctx->sds_rings[ring];
220 napi_enable(&sds_ring->napi);
221 qlcnic_enable_int(sds_ring);
226 qlcnic_napi_disable(struct qlcnic_adapter *adapter)
229 struct qlcnic_host_sds_ring *sds_ring;
230 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
232 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
235 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
236 sds_ring = &recv_ctx->sds_rings[ring];
237 qlcnic_disable_int(sds_ring);
238 napi_synchronize(&sds_ring->napi);
239 napi_disable(&sds_ring->napi);
243 static void qlcnic_clear_stats(struct qlcnic_adapter *adapter)
245 memset(&adapter->stats, 0, sizeof(adapter->stats));
248 static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable)
253 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
255 pci_read_config_dword(pdev, pos, &control);
257 control |= PCI_MSIX_FLAGS_ENABLE;
260 pci_write_config_dword(pdev, pos, control);
264 static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count)
268 for (i = 0; i < count; i++)
269 adapter->msix_entries[i].entry = i;
273 qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
275 u8 mac_addr[ETH_ALEN];
276 struct net_device *netdev = adapter->netdev;
277 struct pci_dev *pdev = adapter->pdev;
279 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
282 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
283 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
284 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
286 /* set station address */
288 if (!is_valid_ether_addr(netdev->perm_addr))
289 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
295 static int qlcnic_set_mac(struct net_device *netdev, void *p)
297 struct qlcnic_adapter *adapter = netdev_priv(netdev);
298 struct sockaddr *addr = p;
300 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
303 if (!is_valid_ether_addr(addr->sa_data))
304 return -EADDRNOTAVAIL;
306 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
307 netif_device_detach(netdev);
308 qlcnic_napi_disable(adapter);
311 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
312 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
313 qlcnic_set_multi(adapter->netdev);
315 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
316 netif_device_attach(netdev);
317 qlcnic_napi_enable(adapter);
322 static const struct net_device_ops qlcnic_netdev_ops = {
323 .ndo_open = qlcnic_open,
324 .ndo_stop = qlcnic_close,
325 .ndo_start_xmit = qlcnic_xmit_frame,
326 .ndo_get_stats = qlcnic_get_stats,
327 .ndo_validate_addr = eth_validate_addr,
328 .ndo_set_rx_mode = qlcnic_set_multi,
329 .ndo_set_mac_address = qlcnic_set_mac,
330 .ndo_change_mtu = qlcnic_change_mtu,
331 .ndo_fix_features = qlcnic_fix_features,
332 .ndo_set_features = qlcnic_set_features,
333 .ndo_tx_timeout = qlcnic_tx_timeout,
334 .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add,
335 .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del,
336 #ifdef CONFIG_NET_POLL_CONTROLLER
337 .ndo_poll_controller = qlcnic_poll_controller,
341 static const struct net_device_ops qlcnic_netdev_failed_ops = {
342 .ndo_open = qlcnic_open,
345 static struct qlcnic_nic_template qlcnic_ops = {
346 .config_bridged_mode = qlcnic_config_bridged_mode,
347 .config_led = qlcnic_config_led,
348 .start_firmware = qlcnic_start_firmware
351 static struct qlcnic_nic_template qlcnic_vf_ops = {
352 .config_bridged_mode = qlcnicvf_config_bridged_mode,
353 .config_led = qlcnicvf_config_led,
354 .start_firmware = qlcnicvf_start_firmware
357 static int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix)
359 struct pci_dev *pdev = adapter->pdev;
362 adapter->max_sds_rings = 1;
363 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
364 qlcnic_set_msix_bit(pdev, 0);
366 if (adapter->msix_supported) {
368 qlcnic_init_msix_entries(adapter, num_msix);
369 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
371 adapter->flags |= QLCNIC_MSIX_ENABLED;
372 qlcnic_set_msix_bit(pdev, 1);
374 adapter->max_sds_rings = num_msix;
376 dev_info(&pdev->dev, "using msi-x interrupts\n");
380 num_msix = rounddown_pow_of_two(err);
389 static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter)
391 const struct qlcnic_legacy_intr_set *legacy_intrp;
392 struct pci_dev *pdev = adapter->pdev;
394 if (use_msi && !pci_enable_msi(pdev)) {
395 adapter->flags |= QLCNIC_MSI_ENABLED;
396 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
397 msi_tgt_status[adapter->ahw->pci_func]);
398 dev_info(&pdev->dev, "using msi interrupts\n");
399 adapter->msix_entries[0].vector = pdev->irq;
403 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
405 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
406 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
407 legacy_intrp->tgt_status_reg);
408 adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter,
409 legacy_intrp->tgt_mask_reg);
410 adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR);
412 adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter,
414 dev_info(&pdev->dev, "using legacy interrupts\n");
415 adapter->msix_entries[0].vector = pdev->irq;
419 qlcnic_setup_intr(struct qlcnic_adapter *adapter)
423 if (adapter->msix_supported) {
424 num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(),
425 QLCNIC_DEF_NUM_STS_DESC_RINGS));
429 if (!qlcnic_enable_msix(adapter, num_msix))
432 qlcnic_enable_msi_legacy(adapter);
436 qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
438 if (adapter->flags & QLCNIC_MSIX_ENABLED)
439 pci_disable_msix(adapter->pdev);
440 if (adapter->flags & QLCNIC_MSI_ENABLED)
441 pci_disable_msi(adapter->pdev);
445 qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
447 if (adapter->ahw->pci_base0 != NULL)
448 iounmap(adapter->ahw->pci_base0);
452 qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
454 struct qlcnic_pci_info *pci_info;
458 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
462 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
463 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
464 if (!adapter->npars) {
469 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
470 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
471 if (!adapter->eswitch) {
476 ret = qlcnic_get_pci_info(adapter, pci_info);
480 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
481 pfn = pci_info[i].id;
482 if (pfn >= QLCNIC_MAX_PCI_FUNC) {
483 ret = QL_STATUS_INVALID_PARAM;
486 adapter->npars[pfn].active = (u8)pci_info[i].active;
487 adapter->npars[pfn].type = (u8)pci_info[i].type;
488 adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port;
489 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
490 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
493 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
494 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
500 kfree(adapter->eswitch);
501 adapter->eswitch = NULL;
503 kfree(adapter->npars);
504 adapter->npars = NULL;
512 qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
517 u32 data = QLCNIC_MGMT_FUNC;
518 void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
520 /* If other drivers are not in use set their privilege level */
521 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
522 ret = qlcnic_api_lock(adapter);
526 if (qlcnic_config_npars) {
527 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
529 if (adapter->npars[i].type != QLCNIC_TYPE_NIC ||
530 id == adapter->ahw->pci_func)
532 data |= (qlcnic_config_npars &
533 QLC_DEV_SET_DRV(0xf, id));
536 data = readl(priv_op);
537 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) |
538 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
539 adapter->ahw->pci_func));
541 writel(data, priv_op);
542 qlcnic_api_unlock(adapter);
548 qlcnic_check_vf(struct qlcnic_adapter *adapter)
550 void __iomem *msix_base_addr;
551 void __iomem *priv_op;
554 u32 op_mode, priv_level;
556 /* Determine FW API version */
557 adapter->fw_hal_version = readl(adapter->ahw->pci_base0 +
560 /* Find PCI function number */
561 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
562 msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE;
563 msix_base = readl(msix_base_addr);
564 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
565 adapter->ahw->pci_func = func;
567 /* Determine function privilege level */
568 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
569 op_mode = readl(priv_op);
570 if (op_mode == QLC_DEV_DRV_DEFAULT)
571 priv_level = QLCNIC_MGMT_FUNC;
573 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
575 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
576 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
577 dev_info(&adapter->pdev->dev,
578 "HAL Version: %d Non Privileged function\n",
579 adapter->fw_hal_version);
580 adapter->nic_ops = &qlcnic_vf_ops;
582 adapter->nic_ops = &qlcnic_ops;
586 qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
588 void __iomem *mem_ptr0 = NULL;
589 resource_size_t mem_base;
590 unsigned long mem_len, pci_len0 = 0;
592 struct pci_dev *pdev = adapter->pdev;
594 /* remap phys address */
595 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
596 mem_len = pci_resource_len(pdev, 0);
598 if (mem_len == QLCNIC_PCI_2MB_SIZE) {
600 mem_ptr0 = pci_ioremap_bar(pdev, 0);
601 if (mem_ptr0 == NULL) {
602 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
610 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
612 adapter->ahw->pci_base0 = mem_ptr0;
613 adapter->ahw->pci_len0 = pci_len0;
615 qlcnic_check_vf(adapter);
617 adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter,
618 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(
619 adapter->ahw->pci_func)));
624 static void get_brd_name(struct qlcnic_adapter *adapter, char *name)
626 struct pci_dev *pdev = adapter->pdev;
629 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
630 if (qlcnic_boards[i].vendor == pdev->vendor &&
631 qlcnic_boards[i].device == pdev->device &&
632 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
633 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
634 sprintf(name, "%pM: %s" ,
636 qlcnic_boards[i].short_name);
644 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
648 qlcnic_check_options(struct qlcnic_adapter *adapter)
650 u32 fw_major, fw_minor, fw_build, prev_fw_version;
651 struct pci_dev *pdev = adapter->pdev;
652 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
654 prev_fw_version = adapter->fw_version;
656 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
657 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
658 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
660 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
662 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC) {
663 if (fw_dump->tmpl_hdr == NULL ||
664 adapter->fw_version > prev_fw_version) {
665 if (fw_dump->tmpl_hdr)
666 vfree(fw_dump->tmpl_hdr);
667 if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
669 "Supports FW dump capability\n");
673 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
674 fw_major, fw_minor, fw_build);
675 if (adapter->ahw->port_type == QLCNIC_XGBE) {
676 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
677 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
678 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
680 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
681 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
684 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
685 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
687 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
688 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
689 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
690 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
691 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
694 adapter->msix_supported = !!use_msi_x;
696 adapter->num_txd = MAX_CMD_DESCRIPTORS;
698 adapter->max_rds_rings = MAX_RDS_RINGS;
702 qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
705 struct qlcnic_info nic_info;
707 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
711 adapter->physical_port = (u8)nic_info.phys_port;
712 adapter->switch_mode = nic_info.switch_mode;
713 adapter->max_tx_ques = nic_info.max_tx_ques;
714 adapter->max_rx_ques = nic_info.max_rx_ques;
715 adapter->capabilities = nic_info.capabilities;
716 adapter->max_mac_filters = nic_info.max_mac_filters;
717 adapter->max_mtu = nic_info.max_mtu;
719 if (adapter->capabilities & BIT_6)
720 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
722 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
728 qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
729 struct qlcnic_esw_func_cfg *esw_cfg)
731 if (esw_cfg->discard_tagged)
732 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
734 adapter->flags |= QLCNIC_TAGGING_ENABLED;
736 if (esw_cfg->vlan_id)
737 adapter->pvid = esw_cfg->vlan_id;
743 qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid)
745 struct qlcnic_adapter *adapter = netdev_priv(netdev);
746 set_bit(vid, adapter->vlans);
751 qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid)
753 struct qlcnic_adapter *adapter = netdev_priv(netdev);
755 qlcnic_restore_indev_addr(netdev, NETDEV_DOWN);
756 clear_bit(vid, adapter->vlans);
761 qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
762 struct qlcnic_esw_func_cfg *esw_cfg)
764 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
765 QLCNIC_PROMISC_DISABLED);
767 if (esw_cfg->mac_anti_spoof)
768 adapter->flags |= QLCNIC_MACSPOOF;
770 if (!esw_cfg->mac_override)
771 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
773 if (!esw_cfg->promisc_mode)
774 adapter->flags |= QLCNIC_PROMISC_DISABLED;
776 qlcnic_set_netdev_features(adapter, esw_cfg);
780 qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
782 struct qlcnic_esw_func_cfg esw_cfg;
784 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
787 esw_cfg.pci_func = adapter->ahw->pci_func;
788 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
790 qlcnic_set_vlan_config(adapter, &esw_cfg);
791 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
797 qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
798 struct qlcnic_esw_func_cfg *esw_cfg)
800 struct net_device *netdev = adapter->netdev;
801 netdev_features_t features, vlan_features;
803 features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
804 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
805 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
806 NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER);
808 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
809 features |= (NETIF_F_TSO | NETIF_F_TSO6);
810 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
813 if (netdev->features & NETIF_F_LRO)
814 features |= NETIF_F_LRO;
816 if (esw_cfg->offload_flags & BIT_0) {
817 netdev->features |= features;
818 if (!(esw_cfg->offload_flags & BIT_1))
819 netdev->features &= ~NETIF_F_TSO;
820 if (!(esw_cfg->offload_flags & BIT_2))
821 netdev->features &= ~NETIF_F_TSO6;
823 netdev->features &= ~features;
826 netdev->vlan_features = (features & vlan_features);
830 qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
832 void __iomem *priv_op;
833 u32 op_mode, priv_level;
836 err = qlcnic_initialize_nic(adapter);
840 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
843 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
844 op_mode = readl(priv_op);
845 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
847 if (op_mode == QLC_DEV_DRV_DEFAULT)
848 priv_level = QLCNIC_MGMT_FUNC;
850 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
852 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
853 if (priv_level == QLCNIC_MGMT_FUNC) {
854 adapter->op_mode = QLCNIC_MGMT_FUNC;
855 err = qlcnic_init_pci_info(adapter);
858 /* Set privilege level for other functions */
859 qlcnic_set_function_modes(adapter);
860 dev_info(&adapter->pdev->dev,
861 "HAL Version: %d, Management function\n",
862 adapter->fw_hal_version);
863 } else if (priv_level == QLCNIC_PRIV_FUNC) {
864 adapter->op_mode = QLCNIC_PRIV_FUNC;
865 dev_info(&adapter->pdev->dev,
866 "HAL Version: %d, Privileged function\n",
867 adapter->fw_hal_version);
871 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
877 qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
879 struct qlcnic_esw_func_cfg esw_cfg;
880 struct qlcnic_npar_info *npar;
883 if (adapter->need_fw_reset)
886 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
887 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
889 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
890 esw_cfg.pci_func = i;
891 esw_cfg.offload_flags = BIT_0;
892 esw_cfg.mac_override = BIT_0;
893 esw_cfg.promisc_mode = BIT_0;
894 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
895 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
896 if (qlcnic_config_switch_port(adapter, &esw_cfg))
898 npar = &adapter->npars[i];
899 npar->pvid = esw_cfg.vlan_id;
900 npar->mac_override = esw_cfg.mac_override;
901 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
902 npar->discard_tagged = esw_cfg.discard_tagged;
903 npar->promisc_mode = esw_cfg.promisc_mode;
904 npar->offload_flags = esw_cfg.offload_flags;
911 qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
912 struct qlcnic_npar_info *npar, int pci_func)
914 struct qlcnic_esw_func_cfg esw_cfg;
915 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
916 esw_cfg.pci_func = pci_func;
917 esw_cfg.vlan_id = npar->pvid;
918 esw_cfg.mac_override = npar->mac_override;
919 esw_cfg.discard_tagged = npar->discard_tagged;
920 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
921 esw_cfg.offload_flags = npar->offload_flags;
922 esw_cfg.promisc_mode = npar->promisc_mode;
923 if (qlcnic_config_switch_port(adapter, &esw_cfg))
926 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
927 if (qlcnic_config_switch_port(adapter, &esw_cfg))
934 qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
937 struct qlcnic_npar_info *npar;
938 struct qlcnic_info nic_info;
940 if (!adapter->need_fw_reset)
943 /* Set the NPAR config data after FW reset */
944 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
945 npar = &adapter->npars[i];
946 if (npar->type != QLCNIC_TYPE_NIC)
948 err = qlcnic_get_nic_info(adapter, &nic_info, i);
951 nic_info.min_tx_bw = npar->min_bw;
952 nic_info.max_tx_bw = npar->max_bw;
953 err = qlcnic_set_nic_info(adapter, &nic_info);
957 if (npar->enable_pm) {
958 err = qlcnic_config_port_mirroring(adapter,
959 npar->dest_npar, 1, i);
963 err = qlcnic_reset_eswitch_config(adapter, npar, i);
970 static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
972 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
975 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
978 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
979 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
981 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
983 if (!npar_opt_timeo) {
984 dev_err(&adapter->pdev->dev,
985 "Waiting for NPAR state to opertional timeout\n");
992 qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
996 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
997 adapter->op_mode != QLCNIC_MGMT_FUNC)
1000 err = qlcnic_set_default_offload_settings(adapter);
1004 err = qlcnic_reset_npar_config(adapter);
1008 qlcnic_dev_set_npar_ready(adapter);
1014 qlcnic_start_firmware(struct qlcnic_adapter *adapter)
1018 err = qlcnic_can_start_firmware(adapter);
1022 goto check_fw_status;
1025 qlcnic_request_firmware(adapter);
1027 err = qlcnic_check_flash_fw_ver(adapter);
1031 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
1034 err = qlcnic_need_fw_reset(adapter);
1036 goto check_fw_status;
1038 err = qlcnic_pinit_from_rom(adapter);
1042 err = qlcnic_load_firmware(adapter);
1046 qlcnic_release_firmware(adapter);
1047 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
1050 err = qlcnic_check_fw_status(adapter);
1054 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
1055 qlcnic_idc_debug_info(adapter, 1);
1057 err = qlcnic_check_eswitch_mode(adapter);
1059 dev_err(&adapter->pdev->dev,
1060 "Memory allocation failed for eswitch\n");
1063 err = qlcnic_set_mgmt_operations(adapter);
1067 qlcnic_check_options(adapter);
1068 adapter->need_fw_reset = 0;
1070 qlcnic_release_firmware(adapter);
1074 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
1075 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
1077 qlcnic_release_firmware(adapter);
1082 qlcnic_request_irq(struct qlcnic_adapter *adapter)
1084 irq_handler_t handler;
1085 struct qlcnic_host_sds_ring *sds_ring;
1088 unsigned long flags = 0;
1089 struct net_device *netdev = adapter->netdev;
1090 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1092 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1093 handler = qlcnic_tmp_intr;
1094 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1095 flags |= IRQF_SHARED;
1098 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1099 handler = qlcnic_msix_intr;
1100 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1101 handler = qlcnic_msi_intr;
1103 flags |= IRQF_SHARED;
1104 handler = qlcnic_intr;
1107 adapter->irq = netdev->irq;
1109 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1110 sds_ring = &recv_ctx->sds_rings[ring];
1111 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1112 err = request_irq(sds_ring->irq, handler,
1113 flags, sds_ring->name, sds_ring);
1122 qlcnic_free_irq(struct qlcnic_adapter *adapter)
1125 struct qlcnic_host_sds_ring *sds_ring;
1127 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1129 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1130 sds_ring = &recv_ctx->sds_rings[ring];
1131 free_irq(sds_ring->irq, sds_ring);
1136 __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1139 struct qlcnic_host_rds_ring *rds_ring;
1141 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1144 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1146 if (qlcnic_set_eswitch_port_config(adapter))
1149 if (qlcnic_fw_create_ctx(adapter))
1152 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1153 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1154 qlcnic_post_rx_buffers(adapter, rds_ring);
1157 qlcnic_set_multi(netdev);
1158 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1160 adapter->ahw->linkup = 0;
1162 if (adapter->max_sds_rings > 1)
1163 qlcnic_config_rss(adapter, 1);
1165 qlcnic_config_intr_coalesce(adapter);
1167 if (netdev->features & NETIF_F_LRO)
1168 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1170 qlcnic_napi_enable(adapter);
1172 qlcnic_linkevent_request(adapter, 1);
1174 adapter->reset_context = 0;
1175 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1179 /* Usage: During resume and firmware recovery module.*/
1182 qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1187 if (netif_running(netdev))
1188 err = __qlcnic_up(adapter, netdev);
1195 __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1197 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1200 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1204 spin_lock(&adapter->tx_clean_lock);
1205 netif_carrier_off(netdev);
1206 netif_tx_disable(netdev);
1208 qlcnic_free_mac_list(adapter);
1210 if (adapter->fhash.fnum)
1211 qlcnic_delete_lb_filters(adapter);
1213 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1215 qlcnic_napi_disable(adapter);
1217 qlcnic_fw_destroy_ctx(adapter);
1219 qlcnic_reset_rx_buffers_list(adapter);
1220 qlcnic_release_tx_buffers(adapter);
1221 spin_unlock(&adapter->tx_clean_lock);
1224 /* Usage: During suspend and firmware recovery module */
1227 qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1230 if (netif_running(netdev))
1231 __qlcnic_down(adapter, netdev);
1237 qlcnic_attach(struct qlcnic_adapter *adapter)
1239 struct net_device *netdev = adapter->netdev;
1240 struct pci_dev *pdev = adapter->pdev;
1243 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1246 err = qlcnic_napi_add(adapter, netdev);
1250 err = qlcnic_alloc_sw_resources(adapter);
1252 dev_err(&pdev->dev, "Error in setting sw resources\n");
1253 goto err_out_napi_del;
1256 err = qlcnic_alloc_hw_resources(adapter);
1258 dev_err(&pdev->dev, "Error in setting hw resources\n");
1259 goto err_out_free_sw;
1262 err = qlcnic_request_irq(adapter);
1264 dev_err(&pdev->dev, "failed to setup interrupt\n");
1265 goto err_out_free_hw;
1268 qlcnic_create_sysfs_entries(adapter);
1270 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1274 qlcnic_free_hw_resources(adapter);
1276 qlcnic_free_sw_resources(adapter);
1278 qlcnic_napi_del(adapter);
1283 qlcnic_detach(struct qlcnic_adapter *adapter)
1285 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1288 qlcnic_remove_sysfs_entries(adapter);
1290 qlcnic_free_hw_resources(adapter);
1291 qlcnic_release_rx_buffers(adapter);
1292 qlcnic_free_irq(adapter);
1293 qlcnic_napi_del(adapter);
1294 qlcnic_free_sw_resources(adapter);
1299 void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1301 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1302 struct qlcnic_host_sds_ring *sds_ring;
1305 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
1306 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1307 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1308 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1309 qlcnic_disable_int(sds_ring);
1313 qlcnic_fw_destroy_ctx(adapter);
1315 qlcnic_detach(adapter);
1317 adapter->diag_test = 0;
1318 adapter->max_sds_rings = max_sds_rings;
1320 if (qlcnic_attach(adapter))
1323 if (netif_running(netdev))
1324 __qlcnic_up(adapter, netdev);
1326 netif_device_attach(netdev);
1329 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1332 adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context),
1334 if (!adapter->ahw) {
1335 dev_err(&adapter->pdev->dev,
1336 "Failed to allocate recv ctx resources for adapter\n");
1340 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1342 if (!adapter->recv_ctx) {
1343 dev_err(&adapter->pdev->dev,
1344 "Failed to allocate recv ctx resources for adapter\n");
1345 kfree(adapter->ahw);
1346 adapter->ahw = NULL;
1350 /* Initialize interrupt coalesce parameters */
1351 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1352 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1353 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
1358 static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1360 kfree(adapter->recv_ctx);
1361 adapter->recv_ctx = NULL;
1363 if (adapter->ahw->fw_dump.tmpl_hdr) {
1364 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1365 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1367 kfree(adapter->ahw);
1368 adapter->ahw = NULL;
1371 int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1373 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1374 struct qlcnic_host_sds_ring *sds_ring;
1375 struct qlcnic_host_rds_ring *rds_ring;
1379 netif_device_detach(netdev);
1381 if (netif_running(netdev))
1382 __qlcnic_down(adapter, netdev);
1384 qlcnic_detach(adapter);
1386 adapter->max_sds_rings = 1;
1387 adapter->diag_test = test;
1389 ret = qlcnic_attach(adapter);
1391 netif_device_attach(netdev);
1395 ret = qlcnic_fw_create_ctx(adapter);
1397 qlcnic_detach(adapter);
1398 netif_device_attach(netdev);
1402 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1403 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1404 qlcnic_post_rx_buffers(adapter, rds_ring);
1407 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1408 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1409 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1410 qlcnic_enable_int(sds_ring);
1414 if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) {
1415 adapter->ahw->loopback_state = 0;
1416 qlcnic_linkevent_request(adapter, 1);
1419 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1424 /* Reset context in hardware only */
1426 qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1428 struct net_device *netdev = adapter->netdev;
1430 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1433 netif_device_detach(netdev);
1435 qlcnic_down(adapter, netdev);
1437 qlcnic_up(adapter, netdev);
1439 netif_device_attach(netdev);
1441 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1446 qlcnic_reset_context(struct qlcnic_adapter *adapter)
1449 struct net_device *netdev = adapter->netdev;
1451 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1454 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1456 netif_device_detach(netdev);
1458 if (netif_running(netdev))
1459 __qlcnic_down(adapter, netdev);
1461 qlcnic_detach(adapter);
1463 if (netif_running(netdev)) {
1464 err = qlcnic_attach(adapter);
1466 __qlcnic_up(adapter, netdev);
1467 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1471 netif_device_attach(netdev);
1474 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1479 qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1480 struct net_device *netdev, u8 pci_using_dac)
1483 struct pci_dev *pdev = adapter->pdev;
1485 adapter->mc_enabled = 0;
1486 adapter->max_mc_count = 38;
1488 netdev->netdev_ops = &qlcnic_netdev_ops;
1489 netdev->watchdog_timeo = 5*HZ;
1491 qlcnic_change_mtu(netdev, netdev->mtu);
1493 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1495 netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
1496 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM;
1498 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
1499 netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
1501 netdev->hw_features |= NETIF_F_HIGHDMA;
1503 netdev->vlan_features = netdev->hw_features;
1505 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
1506 netdev->hw_features |= NETIF_F_HW_VLAN_TX;
1507 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1508 netdev->hw_features |= NETIF_F_LRO;
1510 netdev->features |= netdev->hw_features |
1511 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
1513 netdev->irq = adapter->msix_entries[0].vector;
1515 err = register_netdev(netdev);
1517 dev_err(&pdev->dev, "failed to register net device\n");
1524 static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac)
1526 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1527 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1529 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1530 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1533 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1541 qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count)
1543 adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry),
1546 if (adapter->msix_entries)
1549 dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n");
1553 static int __devinit
1554 qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1556 struct net_device *netdev = NULL;
1557 struct qlcnic_adapter *adapter = NULL;
1559 uint8_t revision_id;
1560 uint8_t pci_using_dac;
1561 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
1563 err = pci_enable_device(pdev);
1567 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1569 goto err_out_disable_pdev;
1572 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1574 goto err_out_disable_pdev;
1576 err = pci_request_regions(pdev, qlcnic_driver_name);
1578 goto err_out_disable_pdev;
1580 pci_set_master(pdev);
1581 pci_enable_pcie_error_reporting(pdev);
1583 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1586 goto err_out_free_res;
1589 SET_NETDEV_DEV(netdev, &pdev->dev);
1591 adapter = netdev_priv(netdev);
1592 adapter->netdev = netdev;
1593 adapter->pdev = pdev;
1595 if (qlcnic_alloc_adapter_resources(adapter))
1596 goto err_out_free_netdev;
1598 adapter->dev_rst_time = jiffies;
1599 revision_id = pdev->revision;
1600 adapter->ahw->revision_id = revision_id;
1601 adapter->mac_learn = qlcnic_mac_learn;
1603 rwlock_init(&adapter->ahw->crb_lock);
1604 mutex_init(&adapter->ahw->mem_lock);
1606 spin_lock_init(&adapter->tx_clean_lock);
1607 INIT_LIST_HEAD(&adapter->mac_list);
1609 err = qlcnic_setup_pci_map(adapter);
1611 goto err_out_free_hw;
1613 /* This will be reset for mezz cards */
1614 adapter->portnum = adapter->ahw->pci_func;
1616 err = qlcnic_get_board_info(adapter);
1618 dev_err(&pdev->dev, "Error getting board config info.\n");
1619 goto err_out_iounmap;
1622 err = qlcnic_setup_idc_param(adapter);
1624 goto err_out_iounmap;
1626 adapter->flags |= QLCNIC_NEED_FLR;
1628 err = adapter->nic_ops->start_firmware(adapter);
1630 dev_err(&pdev->dev, "Loading fw failed. Please Reboot\n"
1631 "\t\tIf reboot doesn't help, try flashing the card\n");
1632 goto err_out_maintenance_mode;
1635 if (qlcnic_read_mac_addr(adapter))
1636 dev_warn(&pdev->dev, "failed to read mac addr\n");
1638 if (adapter->portnum == 0) {
1639 get_brd_name(adapter, brd_name);
1641 pr_info("%s: %s Board Chip rev 0x%x\n",
1642 module_name(THIS_MODULE),
1643 brd_name, adapter->ahw->revision_id);
1646 qlcnic_clear_stats(adapter);
1648 err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques);
1650 goto err_out_decr_ref;
1652 qlcnic_setup_intr(adapter);
1654 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
1656 goto err_out_disable_msi;
1658 pci_set_drvdata(pdev, adapter);
1660 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1662 switch (adapter->ahw->port_type) {
1664 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1665 adapter->netdev->name);
1668 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1669 adapter->netdev->name);
1673 if (adapter->mac_learn)
1674 qlcnic_alloc_lb_filters_mem(adapter);
1676 qlcnic_create_diag_entries(adapter);
1680 err_out_disable_msi:
1681 qlcnic_teardown_intr(adapter);
1682 kfree(adapter->msix_entries);
1685 qlcnic_clr_all_drv_state(adapter, 0);
1688 qlcnic_cleanup_pci_map(adapter);
1691 qlcnic_free_adapter_resources(adapter);
1693 err_out_free_netdev:
1694 free_netdev(netdev);
1697 pci_release_regions(pdev);
1699 err_out_disable_pdev:
1700 pci_set_drvdata(pdev, NULL);
1701 pci_disable_device(pdev);
1704 err_out_maintenance_mode:
1705 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
1706 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
1707 err = register_netdev(netdev);
1709 dev_err(&pdev->dev, "failed to register net device\n");
1710 goto err_out_decr_ref;
1712 pci_set_drvdata(pdev, adapter);
1713 qlcnic_create_diag_entries(adapter);
1717 static void __devexit qlcnic_remove(struct pci_dev *pdev)
1719 struct qlcnic_adapter *adapter;
1720 struct net_device *netdev;
1722 adapter = pci_get_drvdata(pdev);
1723 if (adapter == NULL)
1726 netdev = adapter->netdev;
1728 qlcnic_cancel_fw_work(adapter);
1730 unregister_netdev(netdev);
1732 qlcnic_detach(adapter);
1734 if (adapter->npars != NULL)
1735 kfree(adapter->npars);
1736 if (adapter->eswitch != NULL)
1737 kfree(adapter->eswitch);
1739 qlcnic_clr_all_drv_state(adapter, 0);
1741 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1743 qlcnic_free_lb_filters_mem(adapter);
1745 qlcnic_teardown_intr(adapter);
1746 kfree(adapter->msix_entries);
1748 qlcnic_remove_diag_entries(adapter);
1750 qlcnic_cleanup_pci_map(adapter);
1752 qlcnic_release_firmware(adapter);
1754 pci_disable_pcie_error_reporting(pdev);
1755 pci_release_regions(pdev);
1756 pci_disable_device(pdev);
1757 pci_set_drvdata(pdev, NULL);
1759 qlcnic_free_adapter_resources(adapter);
1760 free_netdev(netdev);
1762 static int __qlcnic_shutdown(struct pci_dev *pdev)
1764 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1765 struct net_device *netdev = adapter->netdev;
1768 netif_device_detach(netdev);
1770 qlcnic_cancel_fw_work(adapter);
1772 if (netif_running(netdev))
1773 qlcnic_down(adapter, netdev);
1775 qlcnic_clr_all_drv_state(adapter, 0);
1777 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1779 retval = pci_save_state(pdev);
1783 if (qlcnic_wol_supported(adapter)) {
1784 pci_enable_wake(pdev, PCI_D3cold, 1);
1785 pci_enable_wake(pdev, PCI_D3hot, 1);
1791 static void qlcnic_shutdown(struct pci_dev *pdev)
1793 if (__qlcnic_shutdown(pdev))
1796 pci_disable_device(pdev);
1801 qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1805 retval = __qlcnic_shutdown(pdev);
1809 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1814 qlcnic_resume(struct pci_dev *pdev)
1816 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1817 struct net_device *netdev = adapter->netdev;
1820 err = pci_enable_device(pdev);
1824 pci_set_power_state(pdev, PCI_D0);
1825 pci_set_master(pdev);
1826 pci_restore_state(pdev);
1828 err = adapter->nic_ops->start_firmware(adapter);
1830 dev_err(&pdev->dev, "failed to start firmware\n");
1834 if (netif_running(netdev)) {
1835 err = qlcnic_up(adapter, netdev);
1839 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1842 netif_device_attach(netdev);
1843 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1848 static int qlcnic_open(struct net_device *netdev)
1850 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1851 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
1854 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
1855 netdev_err(netdev, "Device in FAILED state\n");
1859 netif_carrier_off(netdev);
1861 err = qlcnic_attach(adapter);
1865 err = __qlcnic_up(adapter, netdev);
1869 netif_start_queue(netdev);
1874 qlcnic_detach(adapter);
1879 * qlcnic_close - Disables a network interface entry point
1881 static int qlcnic_close(struct net_device *netdev)
1883 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1885 __qlcnic_down(adapter, netdev);
1889 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
1894 if (adapter->fhash.fmax && adapter->fhash.fhead)
1897 spin_lock_init(&adapter->mac_learn_lock);
1899 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1904 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
1905 adapter->fhash.fhead = head;
1907 for (i = 0; i < adapter->fhash.fmax; i++)
1908 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1911 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1913 if (adapter->fhash.fmax && adapter->fhash.fhead)
1914 kfree(adapter->fhash.fhead);
1916 adapter->fhash.fhead = NULL;
1917 adapter->fhash.fmax = 0;
1920 static void qlcnic_change_filter(struct qlcnic_adapter *adapter,
1921 u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
1923 struct cmd_desc_type0 *hwdesc;
1924 struct qlcnic_nic_req *req;
1925 struct qlcnic_mac_req *mac_req;
1926 struct qlcnic_vlan_req *vlan_req;
1930 producer = tx_ring->producer;
1931 hwdesc = &tx_ring->desc_head[tx_ring->producer];
1933 req = (struct qlcnic_nic_req *)hwdesc;
1934 memset(req, 0, sizeof(struct qlcnic_nic_req));
1935 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
1937 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
1938 req->req_hdr = cpu_to_le64(word);
1940 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
1941 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
1942 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
1944 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
1945 vlan_req->vlan_id = vlan_id;
1947 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
1951 #define QLCNIC_MAC_HASH(MAC)\
1952 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1955 qlcnic_send_filter(struct qlcnic_adapter *adapter,
1956 struct qlcnic_host_tx_ring *tx_ring,
1957 struct cmd_desc_type0 *first_desc,
1958 struct sk_buff *skb)
1960 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
1961 struct qlcnic_filter *fil, *tmp_fil;
1962 struct hlist_node *tmp_hnode, *n;
1963 struct hlist_head *head;
1968 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
1971 if (adapter->fhash.fnum >= adapter->fhash.fmax)
1974 /* Only NPAR capable devices support vlan based learning*/
1975 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
1976 vlan_id = first_desc->vlan_TCI;
1977 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
1978 hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1);
1979 head = &(adapter->fhash.fhead[hindex]);
1981 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
1982 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1983 tmp_fil->vlan_id == vlan_id) {
1986 (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
1987 qlcnic_change_filter(adapter, src_addr, vlan_id,
1989 tmp_fil->ftime = jiffies;
1994 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
1998 qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring);
2000 fil->ftime = jiffies;
2001 fil->vlan_id = vlan_id;
2002 memcpy(fil->faddr, &src_addr, ETH_ALEN);
2003 spin_lock(&adapter->mac_learn_lock);
2004 hlist_add_head(&(fil->fnode), head);
2005 adapter->fhash.fnum++;
2006 spin_unlock(&adapter->mac_learn_lock);
2010 qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
2011 struct cmd_desc_type0 *first_desc,
2012 struct sk_buff *skb)
2014 u8 opcode = 0, hdr_len = 0;
2015 u16 flags = 0, vlan_tci = 0;
2016 int copied, offset, copy_len;
2017 struct cmd_desc_type0 *hwdesc;
2018 struct vlan_ethhdr *vh;
2019 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2020 u16 protocol = ntohs(skb->protocol);
2021 u32 producer = tx_ring->producer;
2023 if (protocol == ETH_P_8021Q) {
2024 vh = (struct vlan_ethhdr *)skb->data;
2025 flags = FLAGS_VLAN_TAGGED;
2026 vlan_tci = vh->h_vlan_TCI;
2027 } else if (vlan_tx_tag_present(skb)) {
2028 flags = FLAGS_VLAN_OOB;
2029 vlan_tci = vlan_tx_tag_get(skb);
2031 if (unlikely(adapter->pvid)) {
2032 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
2034 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
2037 flags = FLAGS_VLAN_OOB;
2038 vlan_tci = adapter->pvid;
2041 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
2042 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2044 if (*(skb->data) & BIT_0) {
2046 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
2048 opcode = TX_ETHER_PKT;
2049 if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
2050 skb_shinfo(skb)->gso_size > 0) {
2052 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2054 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
2055 first_desc->total_hdr_length = hdr_len;
2057 opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO;
2059 /* For LSO, we need to copy the MAC/IP/TCP headers into
2060 * the descriptor ring */
2064 if (flags & FLAGS_VLAN_OOB) {
2065 first_desc->total_hdr_length += VLAN_HLEN;
2066 first_desc->tcp_hdr_offset = VLAN_HLEN;
2067 first_desc->ip_hdr_offset = VLAN_HLEN;
2068 /* Only in case of TSO on vlan device */
2069 flags |= FLAGS_VLAN_TAGGED;
2071 /* Create a TSO vlan header template for firmware */
2073 hwdesc = &tx_ring->desc_head[producer];
2074 tx_ring->cmd_buf_arr[producer].skb = NULL;
2076 copy_len = min((int)sizeof(struct cmd_desc_type0) -
2077 offset, hdr_len + VLAN_HLEN);
2079 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
2080 skb_copy_from_linear_data(skb, vh, 12);
2081 vh->h_vlan_proto = htons(ETH_P_8021Q);
2082 vh->h_vlan_TCI = htons(vlan_tci);
2084 skb_copy_from_linear_data_offset(skb, 12,
2085 (char *)vh + 16, copy_len - 16);
2087 copied = copy_len - VLAN_HLEN;
2090 producer = get_next_index(producer, tx_ring->num_desc);
2093 while (copied < hdr_len) {
2095 copy_len = min((int)sizeof(struct cmd_desc_type0) -
2096 offset, (hdr_len - copied));
2098 hwdesc = &tx_ring->desc_head[producer];
2099 tx_ring->cmd_buf_arr[producer].skb = NULL;
2101 skb_copy_from_linear_data_offset(skb, copied,
2102 (char *) hwdesc + offset, copy_len);
2107 producer = get_next_index(producer, tx_ring->num_desc);
2110 tx_ring->producer = producer;
2112 adapter->stats.lso_frames++;
2114 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
2117 if (protocol == ETH_P_IP) {
2118 l4proto = ip_hdr(skb)->protocol;
2120 if (l4proto == IPPROTO_TCP)
2121 opcode = TX_TCP_PKT;
2122 else if (l4proto == IPPROTO_UDP)
2123 opcode = TX_UDP_PKT;
2124 } else if (protocol == ETH_P_IPV6) {
2125 l4proto = ipv6_hdr(skb)->nexthdr;
2127 if (l4proto == IPPROTO_TCP)
2128 opcode = TX_TCPV6_PKT;
2129 else if (l4proto == IPPROTO_UDP)
2130 opcode = TX_UDPV6_PKT;
2133 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
2134 first_desc->ip_hdr_offset += skb_network_offset(skb);
2135 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2141 qlcnic_map_tx_skb(struct pci_dev *pdev,
2142 struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf)
2144 struct qlcnic_skb_frag *nf;
2145 struct skb_frag_struct *frag;
2149 nr_frags = skb_shinfo(skb)->nr_frags;
2150 nf = &pbuf->frag_array[0];
2152 map = pci_map_single(pdev, skb->data,
2153 skb_headlen(skb), PCI_DMA_TODEVICE);
2154 if (pci_dma_mapping_error(pdev, map))
2158 nf->length = skb_headlen(skb);
2160 for (i = 0; i < nr_frags; i++) {
2161 frag = &skb_shinfo(skb)->frags[i];
2162 nf = &pbuf->frag_array[i+1];
2164 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
2166 if (dma_mapping_error(&pdev->dev, map))
2170 nf->length = skb_frag_size(frag);
2177 nf = &pbuf->frag_array[i+1];
2178 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2181 nf = &pbuf->frag_array[0];
2182 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2189 qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
2190 struct qlcnic_cmd_buffer *pbuf)
2192 struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
2193 int nr_frags = skb_shinfo(skb)->nr_frags;
2196 for (i = 0; i < nr_frags; i++) {
2197 nf = &pbuf->frag_array[i+1];
2198 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2201 nf = &pbuf->frag_array[0];
2202 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2207 qlcnic_clear_cmddesc(u64 *desc)
2215 qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2217 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2218 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2219 struct qlcnic_cmd_buffer *pbuf;
2220 struct qlcnic_skb_frag *buffrag;
2221 struct cmd_desc_type0 *hwdesc, *first_desc;
2222 struct pci_dev *pdev;
2223 struct ethhdr *phdr;
2229 u32 num_txd = tx_ring->num_desc;
2231 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
2232 netif_stop_queue(netdev);
2233 return NETDEV_TX_BUSY;
2236 if (adapter->flags & QLCNIC_MACSPOOF) {
2237 phdr = (struct ethhdr *)skb->data;
2238 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
2242 frag_count = skb_shinfo(skb)->nr_frags + 1;
2243 /* 14 frags supported for normal packet and
2244 * 32 frags supported for TSO packet
2246 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
2248 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
2249 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
2251 if (!__pskb_pull_tail(skb, delta))
2254 frag_count = 1 + skb_shinfo(skb)->nr_frags;
2257 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
2258 netif_stop_queue(netdev);
2259 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
2260 netif_start_queue(netdev);
2262 adapter->stats.xmit_off++;
2263 return NETDEV_TX_BUSY;
2267 producer = tx_ring->producer;
2268 pbuf = &tx_ring->cmd_buf_arr[producer];
2270 pdev = adapter->pdev;
2272 first_desc = hwdesc = &tx_ring->desc_head[producer];
2273 qlcnic_clear_cmddesc((u64 *)hwdesc);
2275 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
2276 adapter->stats.tx_dma_map_error++;
2281 pbuf->frag_count = frag_count;
2283 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
2284 qlcnic_set_tx_port(first_desc, adapter->portnum);
2286 for (i = 0; i < frag_count; i++) {
2290 if ((k == 0) && (i > 0)) {
2291 /* move to next desc.*/
2292 producer = get_next_index(producer, num_txd);
2293 hwdesc = &tx_ring->desc_head[producer];
2294 qlcnic_clear_cmddesc((u64 *)hwdesc);
2295 tx_ring->cmd_buf_arr[producer].skb = NULL;
2298 buffrag = &pbuf->frag_array[i];
2300 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2303 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2306 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2309 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2312 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2317 tx_ring->producer = get_next_index(producer, num_txd);
2320 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb)))
2323 if (adapter->mac_learn)
2324 qlcnic_send_filter(adapter, tx_ring, first_desc, skb);
2326 adapter->stats.txbytes += skb->len;
2327 adapter->stats.xmitcalled++;
2329 qlcnic_update_cmd_producer(adapter, tx_ring);
2331 return NETDEV_TX_OK;
2334 qlcnic_unmap_buffers(pdev, skb, pbuf);
2336 adapter->stats.txdropped++;
2337 dev_kfree_skb_any(skb);
2338 return NETDEV_TX_OK;
2341 static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
2343 struct net_device *netdev = adapter->netdev;
2344 u32 temp, temp_state, temp_val;
2347 temp = QLCRD32(adapter, CRB_TEMP_STATE);
2349 temp_state = qlcnic_get_temp_state(temp);
2350 temp_val = qlcnic_get_temp_val(temp);
2352 if (temp_state == QLCNIC_TEMP_PANIC) {
2353 dev_err(&netdev->dev,
2354 "Device temperature %d degrees C exceeds"
2355 " maximum allowed. Hardware has been shut down.\n",
2358 } else if (temp_state == QLCNIC_TEMP_WARN) {
2359 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
2360 dev_err(&netdev->dev,
2361 "Device temperature %d degrees C "
2362 "exceeds operating range."
2363 " Immediate action needed.\n",
2367 if (adapter->temp == QLCNIC_TEMP_WARN) {
2368 dev_info(&netdev->dev,
2369 "Device temperature is now %d degrees C"
2370 " in normal range.\n", temp_val);
2373 adapter->temp = temp_state;
2377 void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2379 struct net_device *netdev = adapter->netdev;
2381 if (adapter->ahw->linkup && !linkup) {
2382 netdev_info(netdev, "NIC Link is down\n");
2383 adapter->ahw->linkup = 0;
2384 if (netif_running(netdev)) {
2385 netif_carrier_off(netdev);
2386 netif_stop_queue(netdev);
2388 } else if (!adapter->ahw->linkup && linkup) {
2389 netdev_info(netdev, "NIC Link is up\n");
2390 adapter->ahw->linkup = 1;
2391 if (netif_running(netdev)) {
2392 netif_carrier_on(netdev);
2393 netif_wake_queue(netdev);
2398 static void qlcnic_tx_timeout(struct net_device *netdev)
2400 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2402 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2405 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
2407 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
2408 adapter->need_fw_reset = 1;
2410 adapter->reset_context = 1;
2413 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2415 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2416 struct net_device_stats *stats = &netdev->stats;
2418 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2419 stats->tx_packets = adapter->stats.xmitfinished;
2420 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
2421 stats->tx_bytes = adapter->stats.txbytes;
2422 stats->rx_dropped = adapter->stats.rxdropped;
2423 stats->tx_dropped = adapter->stats.txdropped;
2428 static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
2432 status = readl(adapter->isr_int_vec);
2434 if (!(status & adapter->int_vec_bit))
2437 /* check interrupt state machine, to be sure */
2438 status = readl(adapter->crb_int_state_reg);
2439 if (!ISR_LEGACY_INT_TRIGGERED(status))
2442 writel(0xffffffff, adapter->tgt_status_reg);
2443 /* read twice to ensure write is flushed */
2444 readl(adapter->isr_int_vec);
2445 readl(adapter->isr_int_vec);
2450 static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2452 struct qlcnic_host_sds_ring *sds_ring = data;
2453 struct qlcnic_adapter *adapter = sds_ring->adapter;
2455 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2457 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2458 writel(0xffffffff, adapter->tgt_status_reg);
2462 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2466 adapter->diag_cnt++;
2467 qlcnic_enable_int(sds_ring);
2471 static irqreturn_t qlcnic_intr(int irq, void *data)
2473 struct qlcnic_host_sds_ring *sds_ring = data;
2474 struct qlcnic_adapter *adapter = sds_ring->adapter;
2476 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2479 napi_schedule(&sds_ring->napi);
2484 static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2486 struct qlcnic_host_sds_ring *sds_ring = data;
2487 struct qlcnic_adapter *adapter = sds_ring->adapter;
2489 /* clear interrupt */
2490 writel(0xffffffff, adapter->tgt_status_reg);
2492 napi_schedule(&sds_ring->napi);
2496 static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2498 struct qlcnic_host_sds_ring *sds_ring = data;
2500 napi_schedule(&sds_ring->napi);
2504 static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter)
2506 u32 sw_consumer, hw_consumer;
2508 struct qlcnic_cmd_buffer *buffer;
2509 struct pci_dev *pdev = adapter->pdev;
2510 struct net_device *netdev = adapter->netdev;
2511 struct qlcnic_skb_frag *frag;
2513 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2515 if (!spin_trylock(&adapter->tx_clean_lock))
2518 sw_consumer = tx_ring->sw_consumer;
2519 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2521 while (sw_consumer != hw_consumer) {
2522 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
2524 frag = &buffer->frag_array[0];
2525 pci_unmap_single(pdev, frag->dma, frag->length,
2528 for (i = 1; i < buffer->frag_count; i++) {
2530 pci_unmap_page(pdev, frag->dma, frag->length,
2535 adapter->stats.xmitfinished++;
2536 dev_kfree_skb_any(buffer->skb);
2540 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
2541 if (++count >= MAX_STATUS_HANDLE)
2545 if (count && netif_running(netdev)) {
2546 tx_ring->sw_consumer = sw_consumer;
2550 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
2551 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
2552 netif_wake_queue(netdev);
2553 adapter->stats.xmit_on++;
2556 adapter->tx_timeo_cnt = 0;
2559 * If everything is freed up to consumer then check if the ring is full
2560 * If the ring is full then check if more needs to be freed and
2561 * schedule the call back again.
2563 * This happens when there are 2 CPUs. One could be freeing and the
2564 * other filling it. If the ring is full when we get out of here and
2565 * the card has already interrupted the host then the host can miss the
2568 * There is still a possible race condition and the host could miss an
2569 * interrupt. The card has to take care of this.
2571 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2572 done = (sw_consumer == hw_consumer);
2573 spin_unlock(&adapter->tx_clean_lock);
2578 static int qlcnic_poll(struct napi_struct *napi, int budget)
2580 struct qlcnic_host_sds_ring *sds_ring =
2581 container_of(napi, struct qlcnic_host_sds_ring, napi);
2583 struct qlcnic_adapter *adapter = sds_ring->adapter;
2588 tx_complete = qlcnic_process_cmd_ring(adapter);
2590 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2592 if ((work_done < budget) && tx_complete) {
2593 napi_complete(&sds_ring->napi);
2594 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2595 qlcnic_enable_int(sds_ring);
2601 static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
2603 struct qlcnic_host_sds_ring *sds_ring =
2604 container_of(napi, struct qlcnic_host_sds_ring, napi);
2606 struct qlcnic_adapter *adapter = sds_ring->adapter;
2609 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2611 if (work_done < budget) {
2612 napi_complete(&sds_ring->napi);
2613 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2614 qlcnic_enable_int(sds_ring);
2620 #ifdef CONFIG_NET_POLL_CONTROLLER
2621 static void qlcnic_poll_controller(struct net_device *netdev)
2624 struct qlcnic_host_sds_ring *sds_ring;
2625 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2626 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2628 disable_irq(adapter->irq);
2629 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2630 sds_ring = &recv_ctx->sds_rings[ring];
2631 qlcnic_intr(adapter->irq, sds_ring);
2633 enable_irq(adapter->irq);
2638 qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2642 val = adapter->portnum & 0xf;
2643 val |= encoding << 7;
2644 val |= (jiffies - adapter->dev_rst_time) << 8;
2646 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2647 adapter->dev_rst_time = jiffies;
2651 qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
2655 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2656 state != QLCNIC_DEV_NEED_QUISCENT);
2658 if (qlcnic_api_lock(adapter))
2661 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2663 if (state == QLCNIC_DEV_NEED_RESET)
2664 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2665 else if (state == QLCNIC_DEV_NEED_QUISCENT)
2666 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
2668 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2670 qlcnic_api_unlock(adapter);
2676 qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2680 if (qlcnic_api_lock(adapter))
2683 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2684 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2685 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2687 qlcnic_api_unlock(adapter);
2693 qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
2697 if (qlcnic_api_lock(adapter))
2700 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2701 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
2702 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2705 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2706 dev_info(&adapter->pdev->dev,
2707 "Device state set to Failed. Please Reboot\n");
2708 } else if (!(val & 0x11111111))
2709 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2711 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2712 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2713 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2715 qlcnic_api_unlock(adapter);
2717 adapter->fw_fail_cnt = 0;
2718 adapter->flags &= ~QLCNIC_FW_HANG;
2719 clear_bit(__QLCNIC_START_FW, &adapter->state);
2720 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2723 /* Grab api lock, before checking state */
2725 qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2727 int act, state, active_mask;
2729 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2730 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2732 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
2733 active_mask = (~(1 << (adapter->ahw->pci_func * 4)));
2734 act = act & active_mask;
2737 if (((state & 0x11111111) == (act & 0x11111111)) ||
2738 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2744 static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2746 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2748 if (val != QLCNIC_DRV_IDC_VER) {
2749 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2750 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2757 qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2759 u32 val, prev_state;
2760 u8 dev_init_timeo = adapter->dev_init_timeo;
2761 u8 portnum = adapter->portnum;
2764 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2767 if (qlcnic_api_lock(adapter))
2770 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2771 if (!(val & (1 << (portnum * 4)))) {
2772 QLC_DEV_SET_REF_CNT(val, portnum);
2773 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2776 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2777 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
2779 switch (prev_state) {
2780 case QLCNIC_DEV_COLD:
2781 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2782 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
2783 qlcnic_idc_debug_info(adapter, 0);
2784 qlcnic_api_unlock(adapter);
2787 case QLCNIC_DEV_READY:
2788 ret = qlcnic_check_idc_ver(adapter);
2789 qlcnic_api_unlock(adapter);
2792 case QLCNIC_DEV_NEED_RESET:
2793 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2794 QLC_DEV_SET_RST_RDY(val, portnum);
2795 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2798 case QLCNIC_DEV_NEED_QUISCENT:
2799 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2800 QLC_DEV_SET_QSCNT_RDY(val, portnum);
2801 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2804 case QLCNIC_DEV_FAILED:
2805 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
2806 qlcnic_api_unlock(adapter);
2809 case QLCNIC_DEV_INITIALIZING:
2810 case QLCNIC_DEV_QUISCENT:
2814 qlcnic_api_unlock(adapter);
2818 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2820 if (prev_state == QLCNIC_DEV_QUISCENT)
2822 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
2824 if (!dev_init_timeo) {
2825 dev_err(&adapter->pdev->dev,
2826 "Waiting for device to initialize timeout\n");
2830 if (qlcnic_api_lock(adapter))
2833 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2834 QLC_DEV_CLR_RST_QSCNT(val, portnum);
2835 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2837 ret = qlcnic_check_idc_ver(adapter);
2838 qlcnic_api_unlock(adapter);
2844 qlcnic_fwinit_work(struct work_struct *work)
2846 struct qlcnic_adapter *adapter = container_of(work,
2847 struct qlcnic_adapter, fw_work.work);
2848 u32 dev_state = 0xf;
2851 if (qlcnic_api_lock(adapter))
2854 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2855 if (dev_state == QLCNIC_DEV_QUISCENT ||
2856 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2857 qlcnic_api_unlock(adapter);
2858 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2863 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
2864 qlcnic_api_unlock(adapter);
2868 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2869 dev_state == QLCNIC_DEV_READY) {
2870 dev_info(&adapter->pdev->dev, "Detected state change from "
2871 "DEV_NEED_RESET, skipping ack check\n");
2872 goto skip_ack_check;
2875 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
2876 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
2877 adapter->reset_ack_timeo);
2878 goto skip_ack_check;
2881 if (!qlcnic_check_drv_state(adapter)) {
2883 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2885 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2886 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2887 QLCNIC_DEV_INITIALIZING);
2888 set_bit(__QLCNIC_START_FW, &adapter->state);
2889 QLCDB(adapter, DRV, "Restarting fw\n");
2890 qlcnic_idc_debug_info(adapter, 0);
2891 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2892 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2893 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2896 qlcnic_api_unlock(adapter);
2899 if (adapter->ahw->fw_dump.enable &&
2900 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
2901 QLCDB(adapter, DRV, "Take FW dump\n");
2902 qlcnic_dump_fw(adapter);
2903 adapter->flags |= QLCNIC_FW_HANG;
2907 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
2908 if (!adapter->nic_ops->start_firmware(adapter)) {
2909 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2910 adapter->fw_wait_cnt = 0;
2916 qlcnic_api_unlock(adapter);
2919 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2920 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
2922 switch (dev_state) {
2923 case QLCNIC_DEV_READY:
2924 if (!adapter->nic_ops->start_firmware(adapter)) {
2925 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2926 adapter->fw_wait_cnt = 0;
2929 case QLCNIC_DEV_FAILED:
2932 qlcnic_schedule_work(adapter,
2933 qlcnic_fwinit_work, FW_POLL_DELAY);
2938 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2939 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
2940 netif_device_attach(adapter->netdev);
2941 qlcnic_clr_all_drv_state(adapter, 0);
2945 qlcnic_detach_work(struct work_struct *work)
2947 struct qlcnic_adapter *adapter = container_of(work,
2948 struct qlcnic_adapter, fw_work.work);
2949 struct net_device *netdev = adapter->netdev;
2952 netif_device_detach(netdev);
2954 /* Dont grab rtnl lock during Quiscent mode */
2955 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2956 if (netif_running(netdev))
2957 __qlcnic_down(adapter, netdev);
2959 qlcnic_down(adapter, netdev);
2961 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2963 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2964 dev_err(&adapter->pdev->dev,
2965 "Detaching the device: peg halt status1=0x%x\n",
2968 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2969 dev_err(&adapter->pdev->dev,
2970 "On board active cooling fan failed. "
2971 "Device has been halted.\n");
2972 dev_err(&adapter->pdev->dev,
2973 "Replace the adapter.\n");
2979 if (adapter->temp == QLCNIC_TEMP_PANIC) {
2980 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
2985 /* Dont ack if this instance is the reset owner */
2986 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
2987 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2988 dev_err(&adapter->pdev->dev,
2989 "Failed to set driver state,"
2990 "detaching the device.\n");
2995 adapter->fw_wait_cnt = 0;
2997 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3002 netif_device_attach(netdev);
3003 qlcnic_clr_all_drv_state(adapter, 1);
3006 /*Transit NPAR state to NON Operational */
3008 qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3012 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
3013 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3016 if (qlcnic_api_lock(adapter))
3018 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
3019 qlcnic_api_unlock(adapter);
3022 /*Transit to RESET state from READY state only */
3024 qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
3026 u32 state, xg_val = 0, gb_val = 0;
3028 qlcnic_xg_set_xg0_mask(xg_val);
3029 qlcnic_xg_set_xg1_mask(xg_val);
3030 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3031 qlcnic_gb_set_gb0_mask(gb_val);
3032 qlcnic_gb_set_gb1_mask(gb_val);
3033 qlcnic_gb_set_gb2_mask(gb_val);
3034 qlcnic_gb_set_gb3_mask(gb_val);
3035 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3036 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3038 adapter->need_fw_reset = 1;
3039 if (qlcnic_api_lock(adapter))
3042 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
3043 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
3044 netdev_err(adapter->netdev,
3045 "Device is in FAILED state, Please Reboot\n");
3046 qlcnic_api_unlock(adapter);
3050 if (state == QLCNIC_DEV_READY) {
3051 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
3052 adapter->flags |= QLCNIC_FW_RESET_OWNER;
3053 QLCDB(adapter, DRV, "NEED_RESET state set\n");
3054 qlcnic_idc_debug_info(adapter, 0);
3057 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
3058 qlcnic_api_unlock(adapter);
3061 /* Transit to NPAR READY state from NPAR NOT READY state */
3063 qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3065 if (qlcnic_api_lock(adapter))
3068 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
3069 QLCDB(adapter, DRV, "NPAR operational state set\n");
3071 qlcnic_api_unlock(adapter);
3075 qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3076 work_func_t func, int delay)
3078 if (test_bit(__QLCNIC_AER, &adapter->state))
3081 INIT_DELAYED_WORK(&adapter->fw_work, func);
3082 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
3083 round_jiffies_relative(delay));
3087 qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
3089 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
3092 if (!adapter->fw_work.work.func)
3095 cancel_delayed_work_sync(&adapter->fw_work);
3099 qlcnic_attach_work(struct work_struct *work)
3101 struct qlcnic_adapter *adapter = container_of(work,
3102 struct qlcnic_adapter, fw_work.work);
3103 struct net_device *netdev = adapter->netdev;
3106 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
3107 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
3108 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3109 qlcnic_clr_all_drv_state(adapter, 0);
3110 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3111 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3115 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3119 if (netif_running(netdev)) {
3120 if (qlcnic_up(adapter, netdev))
3123 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3127 netif_device_attach(netdev);
3128 adapter->fw_fail_cnt = 0;
3129 adapter->flags &= ~QLCNIC_FW_HANG;
3130 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3132 if (!qlcnic_clr_drv_state(adapter))
3133 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3138 qlcnic_check_health(struct qlcnic_adapter *adapter)
3140 u32 state = 0, heartbeat;
3143 if (qlcnic_check_temp(adapter))
3146 if (adapter->need_fw_reset)
3147 qlcnic_dev_request_reset(adapter);
3149 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
3150 if (state == QLCNIC_DEV_NEED_RESET) {
3151 qlcnic_set_npar_non_operational(adapter);
3152 adapter->need_fw_reset = 1;
3153 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3156 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
3157 if (heartbeat != adapter->heartbeat) {
3158 adapter->heartbeat = heartbeat;
3159 adapter->fw_fail_cnt = 0;
3160 if (adapter->need_fw_reset)
3163 if (adapter->reset_context && auto_fw_reset) {
3164 qlcnic_reset_hw_context(adapter);
3165 adapter->netdev->trans_start = jiffies;
3171 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3174 adapter->flags |= QLCNIC_FW_HANG;
3176 qlcnic_dev_request_reset(adapter);
3179 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
3181 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
3182 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
3183 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3184 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3185 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3186 "PEG_NET_4_PC: 0x%x\n",
3187 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1),
3188 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2),
3189 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3190 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3191 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3192 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3193 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
3194 peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
3195 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
3196 dev_err(&adapter->pdev->dev,
3197 "Firmware aborted with error code 0x00006700. "
3198 "Device is being reset.\n");
3200 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3201 QLCNIC_DEV_NEED_RESET;
3203 if (auto_fw_reset &&
3204 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
3206 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
3207 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3214 qlcnic_fw_poll_work(struct work_struct *work)
3216 struct qlcnic_adapter *adapter = container_of(work,
3217 struct qlcnic_adapter, fw_work.work);
3219 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3223 if (qlcnic_check_health(adapter))
3226 if (adapter->fhash.fnum)
3227 qlcnic_prune_lb_filters(adapter);
3230 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3233 static int qlcnic_is_first_func(struct pci_dev *pdev)
3235 struct pci_dev *oth_pdev;
3236 int val = pdev->devfn;
3239 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3240 (pdev->bus), pdev->bus->number,
3241 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
3245 if (oth_pdev->current_state != PCI_D3cold) {
3246 pci_dev_put(oth_pdev);
3249 pci_dev_put(oth_pdev);
3254 static int qlcnic_attach_func(struct pci_dev *pdev)
3256 int err, first_func;
3257 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3258 struct net_device *netdev = adapter->netdev;
3260 pdev->error_state = pci_channel_io_normal;
3262 err = pci_enable_device(pdev);
3266 pci_set_power_state(pdev, PCI_D0);
3267 pci_set_master(pdev);
3268 pci_restore_state(pdev);
3270 first_func = qlcnic_is_first_func(pdev);
3272 if (qlcnic_api_lock(adapter))
3275 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
3276 adapter->need_fw_reset = 1;
3277 set_bit(__QLCNIC_START_FW, &adapter->state);
3278 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
3279 QLCDB(adapter, DRV, "Restarting fw\n");
3281 qlcnic_api_unlock(adapter);
3283 err = adapter->nic_ops->start_firmware(adapter);
3287 qlcnic_clr_drv_state(adapter);
3288 qlcnic_setup_intr(adapter);
3290 if (netif_running(netdev)) {
3291 err = qlcnic_attach(adapter);
3293 qlcnic_clr_all_drv_state(adapter, 1);
3294 clear_bit(__QLCNIC_AER, &adapter->state);
3295 netif_device_attach(netdev);
3299 err = qlcnic_up(adapter, netdev);
3303 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3306 netif_device_attach(netdev);
3310 static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3311 pci_channel_state_t state)
3313 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3314 struct net_device *netdev = adapter->netdev;
3316 if (state == pci_channel_io_perm_failure)
3317 return PCI_ERS_RESULT_DISCONNECT;
3319 if (state == pci_channel_io_normal)
3320 return PCI_ERS_RESULT_RECOVERED;
3322 set_bit(__QLCNIC_AER, &adapter->state);
3323 netif_device_detach(netdev);
3325 cancel_delayed_work_sync(&adapter->fw_work);
3327 if (netif_running(netdev))
3328 qlcnic_down(adapter, netdev);
3330 qlcnic_detach(adapter);
3331 qlcnic_teardown_intr(adapter);
3333 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3335 pci_save_state(pdev);
3336 pci_disable_device(pdev);
3338 return PCI_ERS_RESULT_NEED_RESET;
3341 static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3343 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3344 PCI_ERS_RESULT_RECOVERED;
3347 static void qlcnic_io_resume(struct pci_dev *pdev)
3349 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3351 pci_cleanup_aer_uncorrect_error_status(pdev);
3353 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
3354 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
3355 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3360 qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3364 err = qlcnic_can_start_firmware(adapter);
3368 err = qlcnic_check_npar_opertional(adapter);
3372 err = qlcnic_initialize_nic(adapter);
3376 qlcnic_check_options(adapter);
3378 err = qlcnic_set_eswitch_port_config(adapter);
3382 adapter->need_fw_reset = 0;
3388 qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
3394 qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
3400 qlcnic_store_bridged_mode(struct device *dev,
3401 struct device_attribute *attr, const char *buf, size_t len)
3403 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3407 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG))
3410 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3413 if (strict_strtoul(buf, 2, &new))
3416 if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
3424 qlcnic_show_bridged_mode(struct device *dev,
3425 struct device_attribute *attr, char *buf)
3427 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3428 int bridged_mode = 0;
3430 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3431 bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
3433 return sprintf(buf, "%d\n", bridged_mode);
3436 static struct device_attribute dev_attr_bridged_mode = {
3437 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
3438 .show = qlcnic_show_bridged_mode,
3439 .store = qlcnic_store_bridged_mode,
3443 qlcnic_store_diag_mode(struct device *dev,
3444 struct device_attribute *attr, const char *buf, size_t len)
3446 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3449 if (strict_strtoul(buf, 2, &new))
3452 if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
3453 adapter->flags ^= QLCNIC_DIAG_ENABLED;
3459 qlcnic_show_diag_mode(struct device *dev,
3460 struct device_attribute *attr, char *buf)
3462 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3464 return sprintf(buf, "%d\n",
3465 !!(adapter->flags & QLCNIC_DIAG_ENABLED));
3468 static struct device_attribute dev_attr_diag_mode = {
3469 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
3470 .show = qlcnic_show_diag_mode,
3471 .store = qlcnic_store_diag_mode,
3474 int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val)
3476 if (!use_msi_x && !use_msi) {
3477 netdev_info(netdev, "no msix or msi support, hence no rss\n");
3481 if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) {
3482 netdev_info(netdev, "rss_ring valid range [2 - %x] in "
3483 " powers of 2\n", max_hw);
3490 int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data)
3492 struct net_device *netdev = adapter->netdev;
3495 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
3498 netif_device_detach(netdev);
3499 if (netif_running(netdev))
3500 __qlcnic_down(adapter, netdev);
3501 qlcnic_detach(adapter);
3502 qlcnic_teardown_intr(adapter);
3504 if (qlcnic_enable_msix(adapter, data)) {
3505 netdev_info(netdev, "failed setting max_rss; rss disabled\n");
3506 qlcnic_enable_msi_legacy(adapter);
3509 if (netif_running(netdev)) {
3510 err = qlcnic_attach(adapter);
3513 err = __qlcnic_up(adapter, netdev);
3516 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3519 netif_device_attach(netdev);
3520 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3525 qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon, u8 *state,
3528 *rate = LSB(beacon);
3529 *state = MSB(beacon);
3531 QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state);
3534 *rate = __QLCNIC_MAX_LED_RATE;
3536 } else if (*state > __QLCNIC_MAX_LED_STATE)
3539 if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE))
3546 qlcnic_store_beacon(struct device *dev,
3547 struct device_attribute *attr, const char *buf, size_t len)
3549 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3550 int max_sds_rings = adapter->max_sds_rings;
3555 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
3556 dev_warn(dev, "LED test not supported for non "
3557 "privilege function\n");
3561 if (len != sizeof(u16))
3562 return QL_STATUS_INVALID_PARAM;
3564 memcpy(&beacon, buf, sizeof(u16));
3565 err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate);
3569 if (adapter->ahw->beacon_state == b_state)
3574 if (!adapter->ahw->beacon_state)
3575 if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) {
3580 if (test_bit(__QLCNIC_RESETTING, &adapter->state)) {
3585 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
3586 err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST);
3589 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
3592 err = qlcnic_config_led(adapter, b_state, b_rate);
3596 adapter->ahw->beacon_state = b_state;
3599 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
3600 qlcnic_diag_free_res(adapter->netdev, max_sds_rings);
3603 if (!adapter->ahw->beacon_state)
3604 clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
3611 qlcnic_show_beacon(struct device *dev,
3612 struct device_attribute *attr, char *buf)
3614 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3616 return sprintf(buf, "%d\n", adapter->ahw->beacon_state);
3619 static struct device_attribute dev_attr_beacon = {
3620 .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)},
3621 .show = qlcnic_show_beacon,
3622 .store = qlcnic_store_beacon,
3626 qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
3627 loff_t offset, size_t size)
3629 size_t crb_size = 4;
3631 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3634 if (offset < QLCNIC_PCI_CRBSPACE) {
3635 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
3636 QLCNIC_PCI_CAMQM_END))
3642 if ((size != crb_size) || (offset & (crb_size-1)))
3649 qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
3650 struct bin_attribute *attr,
3651 char *buf, loff_t offset, size_t size)
3653 struct device *dev = container_of(kobj, struct device, kobj);
3654 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3659 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3663 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3664 qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata);
3665 memcpy(buf, &qmdata, size);
3667 data = QLCRD32(adapter, offset);
3668 memcpy(buf, &data, size);
3674 qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
3675 struct bin_attribute *attr,
3676 char *buf, loff_t offset, size_t size)
3678 struct device *dev = container_of(kobj, struct device, kobj);
3679 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3684 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3688 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3689 memcpy(&qmdata, buf, size);
3690 qlcnic_pci_camqm_write_2M(adapter, offset, qmdata);
3692 memcpy(&data, buf, size);
3693 QLCWR32(adapter, offset, data);
3699 qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
3700 loff_t offset, size_t size)
3702 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3705 if ((size != 8) || (offset & 0x7))
3712 qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
3713 struct bin_attribute *attr,
3714 char *buf, loff_t offset, size_t size)
3716 struct device *dev = container_of(kobj, struct device, kobj);
3717 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3721 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3725 if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
3728 memcpy(buf, &data, size);
3734 qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
3735 struct bin_attribute *attr,
3736 char *buf, loff_t offset, size_t size)
3738 struct device *dev = container_of(kobj, struct device, kobj);
3739 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3743 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3747 memcpy(&data, buf, size);
3749 if (qlcnic_pci_mem_write_2M(adapter, offset, data))
3755 static struct bin_attribute bin_attr_crb = {
3756 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
3758 .read = qlcnic_sysfs_read_crb,
3759 .write = qlcnic_sysfs_write_crb,
3762 static struct bin_attribute bin_attr_mem = {
3763 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
3765 .read = qlcnic_sysfs_read_mem,
3766 .write = qlcnic_sysfs_write_mem,
3770 validate_pm_config(struct qlcnic_adapter *adapter,
3771 struct qlcnic_pm_func_cfg *pm_cfg, int count)
3774 u8 src_pci_func, s_esw_id, d_esw_id;
3778 for (i = 0; i < count; i++) {
3779 src_pci_func = pm_cfg[i].pci_func;
3780 dest_pci_func = pm_cfg[i].dest_npar;
3781 if (src_pci_func >= QLCNIC_MAX_PCI_FUNC
3782 || dest_pci_func >= QLCNIC_MAX_PCI_FUNC)
3783 return QL_STATUS_INVALID_PARAM;
3785 if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC)
3786 return QL_STATUS_INVALID_PARAM;
3788 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3789 return QL_STATUS_INVALID_PARAM;
3791 s_esw_id = adapter->npars[src_pci_func].phy_port;
3792 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3794 if (s_esw_id != d_esw_id)
3795 return QL_STATUS_INVALID_PARAM;
3803 qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3804 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3806 struct device *dev = container_of(kobj, struct device, kobj);
3807 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3808 struct qlcnic_pm_func_cfg *pm_cfg;
3809 u32 id, action, pci_func;
3810 int count, rem, i, ret;
3812 count = size / sizeof(struct qlcnic_pm_func_cfg);
3813 rem = size % sizeof(struct qlcnic_pm_func_cfg);
3815 return QL_STATUS_INVALID_PARAM;
3817 pm_cfg = (struct qlcnic_pm_func_cfg *) buf;
3819 ret = validate_pm_config(adapter, pm_cfg, count);
3822 for (i = 0; i < count; i++) {
3823 pci_func = pm_cfg[i].pci_func;
3824 action = !!pm_cfg[i].action;
3825 id = adapter->npars[pci_func].phy_port;
3826 ret = qlcnic_config_port_mirroring(adapter, id,
3832 for (i = 0; i < count; i++) {
3833 pci_func = pm_cfg[i].pci_func;
3834 id = adapter->npars[pci_func].phy_port;
3835 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
3836 adapter->npars[pci_func].dest_npar = id;
3842 qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3843 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3845 struct device *dev = container_of(kobj, struct device, kobj);
3846 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3847 struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC];
3850 if (size != sizeof(pm_cfg))
3851 return QL_STATUS_INVALID_PARAM;
3853 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3854 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3856 pm_cfg[i].action = adapter->npars[i].enable_pm;
3857 pm_cfg[i].dest_npar = 0;
3858 pm_cfg[i].pci_func = i;
3860 memcpy(buf, &pm_cfg, size);
3866 validate_esw_config(struct qlcnic_adapter *adapter,
3867 struct qlcnic_esw_func_cfg *esw_cfg, int count)
3873 op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE);
3875 for (i = 0; i < count; i++) {
3876 pci_func = esw_cfg[i].pci_func;
3877 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3878 return QL_STATUS_INVALID_PARAM;
3880 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3881 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3882 return QL_STATUS_INVALID_PARAM;
3884 switch (esw_cfg[i].op_mode) {
3885 case QLCNIC_PORT_DEFAULTS:
3886 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
3887 QLCNIC_NON_PRIV_FUNC) {
3888 if (esw_cfg[i].mac_anti_spoof != 0)
3889 return QL_STATUS_INVALID_PARAM;
3890 if (esw_cfg[i].mac_override != 1)
3891 return QL_STATUS_INVALID_PARAM;
3892 if (esw_cfg[i].promisc_mode != 1)
3893 return QL_STATUS_INVALID_PARAM;
3896 case QLCNIC_ADD_VLAN:
3897 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3898 return QL_STATUS_INVALID_PARAM;
3899 if (!esw_cfg[i].op_type)
3900 return QL_STATUS_INVALID_PARAM;
3902 case QLCNIC_DEL_VLAN:
3903 if (!esw_cfg[i].op_type)
3904 return QL_STATUS_INVALID_PARAM;
3907 return QL_STATUS_INVALID_PARAM;
3914 qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3915 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3917 struct device *dev = container_of(kobj, struct device, kobj);
3918 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3919 struct qlcnic_esw_func_cfg *esw_cfg;
3920 struct qlcnic_npar_info *npar;
3921 int count, rem, i, ret;
3922 u8 pci_func, op_mode = 0;
3924 count = size / sizeof(struct qlcnic_esw_func_cfg);
3925 rem = size % sizeof(struct qlcnic_esw_func_cfg);
3927 return QL_STATUS_INVALID_PARAM;
3929 esw_cfg = (struct qlcnic_esw_func_cfg *) buf;
3930 ret = validate_esw_config(adapter, esw_cfg, count);
3934 for (i = 0; i < count; i++) {
3935 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3936 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3937 return QL_STATUS_INVALID_PARAM;
3939 if (adapter->ahw->pci_func != esw_cfg[i].pci_func)
3942 op_mode = esw_cfg[i].op_mode;
3943 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3944 esw_cfg[i].op_mode = op_mode;
3945 esw_cfg[i].pci_func = adapter->ahw->pci_func;
3947 switch (esw_cfg[i].op_mode) {
3948 case QLCNIC_PORT_DEFAULTS:
3949 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3951 case QLCNIC_ADD_VLAN:
3952 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3954 case QLCNIC_DEL_VLAN:
3955 esw_cfg[i].vlan_id = 0;
3956 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3961 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3964 for (i = 0; i < count; i++) {
3965 pci_func = esw_cfg[i].pci_func;
3966 npar = &adapter->npars[pci_func];
3967 switch (esw_cfg[i].op_mode) {
3968 case QLCNIC_PORT_DEFAULTS:
3969 npar->promisc_mode = esw_cfg[i].promisc_mode;
3970 npar->mac_override = esw_cfg[i].mac_override;
3971 npar->offload_flags = esw_cfg[i].offload_flags;
3972 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3973 npar->discard_tagged = esw_cfg[i].discard_tagged;
3975 case QLCNIC_ADD_VLAN:
3976 npar->pvid = esw_cfg[i].vlan_id;
3978 case QLCNIC_DEL_VLAN:
3988 qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3989 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3991 struct device *dev = container_of(kobj, struct device, kobj);
3992 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3993 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
3996 if (size != sizeof(esw_cfg))
3997 return QL_STATUS_INVALID_PARAM;
3999 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
4000 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
4002 esw_cfg[i].pci_func = i;
4003 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
4004 return QL_STATUS_INVALID_PARAM;
4006 memcpy(buf, &esw_cfg, size);
4012 validate_npar_config(struct qlcnic_adapter *adapter,
4013 struct qlcnic_npar_func_cfg *np_cfg, int count)
4017 for (i = 0; i < count; i++) {
4018 pci_func = np_cfg[i].pci_func;
4019 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
4020 return QL_STATUS_INVALID_PARAM;
4022 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
4023 return QL_STATUS_INVALID_PARAM;
4025 if (!IS_VALID_BW(np_cfg[i].min_bw) ||
4026 !IS_VALID_BW(np_cfg[i].max_bw))
4027 return QL_STATUS_INVALID_PARAM;
4033 qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj,
4034 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4036 struct device *dev = container_of(kobj, struct device, kobj);
4037 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4038 struct qlcnic_info nic_info;
4039 struct qlcnic_npar_func_cfg *np_cfg;
4040 int i, count, rem, ret;
4043 count = size / sizeof(struct qlcnic_npar_func_cfg);
4044 rem = size % sizeof(struct qlcnic_npar_func_cfg);
4046 return QL_STATUS_INVALID_PARAM;
4048 np_cfg = (struct qlcnic_npar_func_cfg *) buf;
4049 ret = validate_npar_config(adapter, np_cfg, count);
4053 for (i = 0; i < count ; i++) {
4054 pci_func = np_cfg[i].pci_func;
4055 ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
4058 nic_info.pci_func = pci_func;
4059 nic_info.min_tx_bw = np_cfg[i].min_bw;
4060 nic_info.max_tx_bw = np_cfg[i].max_bw;
4061 ret = qlcnic_set_nic_info(adapter, &nic_info);
4064 adapter->npars[i].min_bw = nic_info.min_tx_bw;
4065 adapter->npars[i].max_bw = nic_info.max_tx_bw;
4072 qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
4073 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4075 struct device *dev = container_of(kobj, struct device, kobj);
4076 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4077 struct qlcnic_info nic_info;
4078 struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
4081 if (size != sizeof(np_cfg))
4082 return QL_STATUS_INVALID_PARAM;
4084 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
4085 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
4087 ret = qlcnic_get_nic_info(adapter, &nic_info, i);
4091 np_cfg[i].pci_func = i;
4092 np_cfg[i].op_mode = (u8)nic_info.op_mode;
4093 np_cfg[i].port_num = nic_info.phys_port;
4094 np_cfg[i].fw_capab = nic_info.capabilities;
4095 np_cfg[i].min_bw = nic_info.min_tx_bw ;
4096 np_cfg[i].max_bw = nic_info.max_tx_bw;
4097 np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
4098 np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
4100 memcpy(buf, &np_cfg, size);
4105 qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
4106 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4108 struct device *dev = container_of(kobj, struct device, kobj);
4109 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4110 struct qlcnic_esw_statistics port_stats;
4113 if (size != sizeof(struct qlcnic_esw_statistics))
4114 return QL_STATUS_INVALID_PARAM;
4116 if (offset >= QLCNIC_MAX_PCI_FUNC)
4117 return QL_STATUS_INVALID_PARAM;
4119 memset(&port_stats, 0, size);
4120 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
4125 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
4130 memcpy(buf, &port_stats, size);
4135 qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
4136 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4138 struct device *dev = container_of(kobj, struct device, kobj);
4139 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4140 struct qlcnic_esw_statistics esw_stats;
4143 if (size != sizeof(struct qlcnic_esw_statistics))
4144 return QL_STATUS_INVALID_PARAM;
4146 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
4147 return QL_STATUS_INVALID_PARAM;
4149 memset(&esw_stats, 0, size);
4150 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
4155 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
4160 memcpy(buf, &esw_stats, size);
4165 qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
4166 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4168 struct device *dev = container_of(kobj, struct device, kobj);
4169 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4172 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
4173 return QL_STATUS_INVALID_PARAM;
4175 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
4176 QLCNIC_QUERY_RX_COUNTER);
4180 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
4181 QLCNIC_QUERY_TX_COUNTER);
4189 qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
4190 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4193 struct device *dev = container_of(kobj, struct device, kobj);
4194 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4197 if (offset >= QLCNIC_MAX_PCI_FUNC)
4198 return QL_STATUS_INVALID_PARAM;
4200 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
4201 QLCNIC_QUERY_RX_COUNTER);
4205 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
4206 QLCNIC_QUERY_TX_COUNTER);
4214 qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
4215 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4217 struct device *dev = container_of(kobj, struct device, kobj);
4218 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4219 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
4220 struct qlcnic_pci_info *pci_info;
4223 if (size != sizeof(pci_cfg))
4224 return QL_STATUS_INVALID_PARAM;
4226 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
4230 ret = qlcnic_get_pci_info(adapter, pci_info);
4236 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
4237 pci_cfg[i].pci_func = pci_info[i].id;
4238 pci_cfg[i].func_type = pci_info[i].type;
4239 pci_cfg[i].port_num = pci_info[i].default_port;
4240 pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
4241 pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
4242 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
4244 memcpy(buf, &pci_cfg, size);
4248 static struct bin_attribute bin_attr_npar_config = {
4249 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
4251 .read = qlcnic_sysfs_read_npar_config,
4252 .write = qlcnic_sysfs_write_npar_config,
4255 static struct bin_attribute bin_attr_pci_config = {
4256 .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
4258 .read = qlcnic_sysfs_read_pci_config,
4262 static struct bin_attribute bin_attr_port_stats = {
4263 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
4265 .read = qlcnic_sysfs_get_port_stats,
4266 .write = qlcnic_sysfs_clear_port_stats,
4269 static struct bin_attribute bin_attr_esw_stats = {
4270 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
4272 .read = qlcnic_sysfs_get_esw_stats,
4273 .write = qlcnic_sysfs_clear_esw_stats,
4276 static struct bin_attribute bin_attr_esw_config = {
4277 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
4279 .read = qlcnic_sysfs_read_esw_config,
4280 .write = qlcnic_sysfs_write_esw_config,
4283 static struct bin_attribute bin_attr_pm_config = {
4284 .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
4286 .read = qlcnic_sysfs_read_pm_config,
4287 .write = qlcnic_sysfs_write_pm_config,
4291 qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
4293 struct device *dev = &adapter->pdev->dev;
4295 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
4296 if (device_create_file(dev, &dev_attr_bridged_mode))
4298 "failed to create bridged_mode sysfs entry\n");
4302 qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
4304 struct device *dev = &adapter->pdev->dev;
4306 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
4307 device_remove_file(dev, &dev_attr_bridged_mode);
4311 qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
4313 struct device *dev = &adapter->pdev->dev;
4314 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
4316 if (device_create_bin_file(dev, &bin_attr_port_stats))
4317 dev_info(dev, "failed to create port stats sysfs entry");
4319 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4321 if (device_create_file(dev, &dev_attr_diag_mode))
4322 dev_info(dev, "failed to create diag_mode sysfs entry\n");
4323 if (device_create_bin_file(dev, &bin_attr_crb))
4324 dev_info(dev, "failed to create crb sysfs entry\n");
4325 if (device_create_bin_file(dev, &bin_attr_mem))
4326 dev_info(dev, "failed to create mem sysfs entry\n");
4328 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD))
4331 if (device_create_bin_file(dev, &bin_attr_pci_config))
4332 dev_info(dev, "failed to create pci config sysfs entry");
4333 if (device_create_file(dev, &dev_attr_beacon))
4334 dev_info(dev, "failed to create beacon sysfs entry");
4336 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4338 if (device_create_bin_file(dev, &bin_attr_esw_config))
4339 dev_info(dev, "failed to create esw config sysfs entry");
4340 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
4342 if (device_create_bin_file(dev, &bin_attr_npar_config))
4343 dev_info(dev, "failed to create npar config sysfs entry");
4344 if (device_create_bin_file(dev, &bin_attr_pm_config))
4345 dev_info(dev, "failed to create pm config sysfs entry");
4346 if (device_create_bin_file(dev, &bin_attr_esw_stats))
4347 dev_info(dev, "failed to create eswitch stats sysfs entry");
4351 qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
4353 struct device *dev = &adapter->pdev->dev;
4354 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
4356 device_remove_bin_file(dev, &bin_attr_port_stats);
4358 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4360 device_remove_file(dev, &dev_attr_diag_mode);
4361 device_remove_bin_file(dev, &bin_attr_crb);
4362 device_remove_bin_file(dev, &bin_attr_mem);
4363 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD))
4365 device_remove_bin_file(dev, &bin_attr_pci_config);
4366 device_remove_file(dev, &dev_attr_beacon);
4367 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4369 device_remove_bin_file(dev, &bin_attr_esw_config);
4370 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
4372 device_remove_bin_file(dev, &bin_attr_npar_config);
4373 device_remove_bin_file(dev, &bin_attr_pm_config);
4374 device_remove_bin_file(dev, &bin_attr_esw_stats);
4379 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4382 qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4383 struct net_device *dev, unsigned long event)
4385 struct in_device *indev;
4387 indev = in_dev_get(dev);
4394 qlcnic_config_ipaddr(adapter,
4395 ifa->ifa_address, QLCNIC_IP_UP);
4398 qlcnic_config_ipaddr(adapter,
4399 ifa->ifa_address, QLCNIC_IP_DOWN);
4404 } endfor_ifa(indev);
4410 qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
4412 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4413 struct net_device *dev;
4416 qlcnic_config_indev_addr(adapter, netdev, event);
4418 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
4419 dev = __vlan_find_dev_deep(netdev, vid);
4422 qlcnic_config_indev_addr(adapter, dev, event);
4426 static int qlcnic_netdev_event(struct notifier_block *this,
4427 unsigned long event, void *ptr)
4429 struct qlcnic_adapter *adapter;
4430 struct net_device *dev = (struct net_device *)ptr;
4436 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4437 dev = vlan_dev_real_dev(dev);
4441 if (!is_qlcnic_netdev(dev))
4444 adapter = netdev_priv(dev);
4449 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4452 qlcnic_config_indev_addr(adapter, dev, event);
4458 qlcnic_inetaddr_event(struct notifier_block *this,
4459 unsigned long event, void *ptr)
4461 struct qlcnic_adapter *adapter;
4462 struct net_device *dev;
4464 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4466 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4472 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4473 dev = vlan_dev_real_dev(dev);
4477 if (!is_qlcnic_netdev(dev))
4480 adapter = netdev_priv(dev);
4485 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4490 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
4493 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
4503 static struct notifier_block qlcnic_netdev_cb = {
4504 .notifier_call = qlcnic_netdev_event,
4507 static struct notifier_block qlcnic_inetaddr_cb = {
4508 .notifier_call = qlcnic_inetaddr_event,
4512 qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
4515 static struct pci_error_handlers qlcnic_err_handler = {
4516 .error_detected = qlcnic_io_error_detected,
4517 .slot_reset = qlcnic_io_slot_reset,
4518 .resume = qlcnic_io_resume,
4521 static struct pci_driver qlcnic_driver = {
4522 .name = qlcnic_driver_name,
4523 .id_table = qlcnic_pci_tbl,
4524 .probe = qlcnic_probe,
4525 .remove = __devexit_p(qlcnic_remove),
4527 .suspend = qlcnic_suspend,
4528 .resume = qlcnic_resume,
4530 .shutdown = qlcnic_shutdown,
4531 .err_handler = &qlcnic_err_handler
4535 static int __init qlcnic_init_module(void)
4539 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4541 qlcnic_wq = create_singlethread_workqueue("qlcnic");
4542 if (qlcnic_wq == NULL) {
4543 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
4548 register_netdevice_notifier(&qlcnic_netdev_cb);
4549 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4552 ret = pci_register_driver(&qlcnic_driver);
4555 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4556 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4558 destroy_workqueue(qlcnic_wq);
4564 module_init(qlcnic_init_module);
4566 static void __exit qlcnic_exit_module(void)
4569 pci_unregister_driver(&qlcnic_driver);
4572 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4573 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4575 destroy_workqueue(qlcnic_wq);
4578 module_exit(qlcnic_exit_module);