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)
1141 struct qlcnic_host_rds_ring *rds_ring;
1143 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1146 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1148 if (qlcnic_set_eswitch_port_config(adapter))
1151 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) {
1152 capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2);
1153 if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG)
1154 adapter->flags |= QLCNIC_FW_LRO_MSS_CAP;
1157 if (qlcnic_fw_create_ctx(adapter))
1160 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1161 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1162 qlcnic_post_rx_buffers(adapter, rds_ring);
1165 qlcnic_set_multi(netdev);
1166 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1168 adapter->ahw->linkup = 0;
1170 if (adapter->max_sds_rings > 1)
1171 qlcnic_config_rss(adapter, 1);
1173 qlcnic_config_intr_coalesce(adapter);
1175 if (netdev->features & NETIF_F_LRO)
1176 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1178 qlcnic_napi_enable(adapter);
1180 qlcnic_linkevent_request(adapter, 1);
1182 adapter->reset_context = 0;
1183 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1187 /* Usage: During resume and firmware recovery module.*/
1190 qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1195 if (netif_running(netdev))
1196 err = __qlcnic_up(adapter, netdev);
1203 __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1205 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1208 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1212 spin_lock(&adapter->tx_clean_lock);
1213 netif_carrier_off(netdev);
1214 netif_tx_disable(netdev);
1216 qlcnic_free_mac_list(adapter);
1218 if (adapter->fhash.fnum)
1219 qlcnic_delete_lb_filters(adapter);
1221 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1223 qlcnic_napi_disable(adapter);
1225 qlcnic_fw_destroy_ctx(adapter);
1226 adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP;
1228 qlcnic_reset_rx_buffers_list(adapter);
1229 qlcnic_release_tx_buffers(adapter);
1230 spin_unlock(&adapter->tx_clean_lock);
1233 /* Usage: During suspend and firmware recovery module */
1236 qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1239 if (netif_running(netdev))
1240 __qlcnic_down(adapter, netdev);
1246 qlcnic_attach(struct qlcnic_adapter *adapter)
1248 struct net_device *netdev = adapter->netdev;
1249 struct pci_dev *pdev = adapter->pdev;
1252 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1255 err = qlcnic_napi_add(adapter, netdev);
1259 err = qlcnic_alloc_sw_resources(adapter);
1261 dev_err(&pdev->dev, "Error in setting sw resources\n");
1262 goto err_out_napi_del;
1265 err = qlcnic_alloc_hw_resources(adapter);
1267 dev_err(&pdev->dev, "Error in setting hw resources\n");
1268 goto err_out_free_sw;
1271 err = qlcnic_request_irq(adapter);
1273 dev_err(&pdev->dev, "failed to setup interrupt\n");
1274 goto err_out_free_hw;
1277 qlcnic_create_sysfs_entries(adapter);
1279 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1283 qlcnic_free_hw_resources(adapter);
1285 qlcnic_free_sw_resources(adapter);
1287 qlcnic_napi_del(adapter);
1292 qlcnic_detach(struct qlcnic_adapter *adapter)
1294 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1297 qlcnic_remove_sysfs_entries(adapter);
1299 qlcnic_free_hw_resources(adapter);
1300 qlcnic_release_rx_buffers(adapter);
1301 qlcnic_free_irq(adapter);
1302 qlcnic_napi_del(adapter);
1303 qlcnic_free_sw_resources(adapter);
1308 void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1310 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1311 struct qlcnic_host_sds_ring *sds_ring;
1314 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
1315 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1316 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1317 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1318 qlcnic_disable_int(sds_ring);
1322 qlcnic_fw_destroy_ctx(adapter);
1324 qlcnic_detach(adapter);
1326 adapter->diag_test = 0;
1327 adapter->max_sds_rings = max_sds_rings;
1329 if (qlcnic_attach(adapter))
1332 if (netif_running(netdev))
1333 __qlcnic_up(adapter, netdev);
1335 netif_device_attach(netdev);
1338 static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1341 adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context),
1343 if (!adapter->ahw) {
1344 dev_err(&adapter->pdev->dev,
1345 "Failed to allocate recv ctx resources for adapter\n");
1349 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1351 if (!adapter->recv_ctx) {
1352 dev_err(&adapter->pdev->dev,
1353 "Failed to allocate recv ctx resources for adapter\n");
1354 kfree(adapter->ahw);
1355 adapter->ahw = NULL;
1359 /* Initialize interrupt coalesce parameters */
1360 adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT;
1361 adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1362 adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
1367 static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1369 kfree(adapter->recv_ctx);
1370 adapter->recv_ctx = NULL;
1372 if (adapter->ahw->fw_dump.tmpl_hdr) {
1373 vfree(adapter->ahw->fw_dump.tmpl_hdr);
1374 adapter->ahw->fw_dump.tmpl_hdr = NULL;
1376 kfree(adapter->ahw);
1377 adapter->ahw = NULL;
1380 int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1382 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1383 struct qlcnic_host_sds_ring *sds_ring;
1384 struct qlcnic_host_rds_ring *rds_ring;
1388 netif_device_detach(netdev);
1390 if (netif_running(netdev))
1391 __qlcnic_down(adapter, netdev);
1393 qlcnic_detach(adapter);
1395 adapter->max_sds_rings = 1;
1396 adapter->diag_test = test;
1398 ret = qlcnic_attach(adapter);
1400 netif_device_attach(netdev);
1404 ret = qlcnic_fw_create_ctx(adapter);
1406 qlcnic_detach(adapter);
1407 netif_device_attach(netdev);
1411 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1412 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1413 qlcnic_post_rx_buffers(adapter, rds_ring);
1416 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1417 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1418 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1419 qlcnic_enable_int(sds_ring);
1423 if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) {
1424 adapter->ahw->loopback_state = 0;
1425 qlcnic_linkevent_request(adapter, 1);
1428 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1433 /* Reset context in hardware only */
1435 qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1437 struct net_device *netdev = adapter->netdev;
1439 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1442 netif_device_detach(netdev);
1444 qlcnic_down(adapter, netdev);
1446 qlcnic_up(adapter, netdev);
1448 netif_device_attach(netdev);
1450 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1455 qlcnic_reset_context(struct qlcnic_adapter *adapter)
1458 struct net_device *netdev = adapter->netdev;
1460 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1463 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1465 netif_device_detach(netdev);
1467 if (netif_running(netdev))
1468 __qlcnic_down(adapter, netdev);
1470 qlcnic_detach(adapter);
1472 if (netif_running(netdev)) {
1473 err = qlcnic_attach(adapter);
1475 __qlcnic_up(adapter, netdev);
1476 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1480 netif_device_attach(netdev);
1483 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1488 qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1489 struct net_device *netdev, u8 pci_using_dac)
1492 struct pci_dev *pdev = adapter->pdev;
1494 adapter->mc_enabled = 0;
1495 adapter->max_mc_count = 38;
1497 netdev->netdev_ops = &qlcnic_netdev_ops;
1498 netdev->watchdog_timeo = 5*HZ;
1500 qlcnic_change_mtu(netdev, netdev->mtu);
1502 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1504 netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
1505 NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM;
1507 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
1508 netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
1510 netdev->hw_features |= NETIF_F_HIGHDMA;
1512 netdev->vlan_features = netdev->hw_features;
1514 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
1515 netdev->hw_features |= NETIF_F_HW_VLAN_TX;
1516 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1517 netdev->hw_features |= NETIF_F_LRO;
1519 netdev->features |= netdev->hw_features |
1520 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
1522 netdev->irq = adapter->msix_entries[0].vector;
1524 err = register_netdev(netdev);
1526 dev_err(&pdev->dev, "failed to register net device\n");
1533 static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac)
1535 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1536 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1538 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1539 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1542 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1550 qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count)
1552 adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry),
1555 if (adapter->msix_entries)
1558 dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n");
1562 static int __devinit
1563 qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1565 struct net_device *netdev = NULL;
1566 struct qlcnic_adapter *adapter = NULL;
1568 uint8_t revision_id;
1569 uint8_t pci_using_dac;
1570 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
1572 err = pci_enable_device(pdev);
1576 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1578 goto err_out_disable_pdev;
1581 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1583 goto err_out_disable_pdev;
1585 err = pci_request_regions(pdev, qlcnic_driver_name);
1587 goto err_out_disable_pdev;
1589 pci_set_master(pdev);
1590 pci_enable_pcie_error_reporting(pdev);
1592 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1595 goto err_out_free_res;
1598 SET_NETDEV_DEV(netdev, &pdev->dev);
1600 adapter = netdev_priv(netdev);
1601 adapter->netdev = netdev;
1602 adapter->pdev = pdev;
1604 if (qlcnic_alloc_adapter_resources(adapter))
1605 goto err_out_free_netdev;
1607 adapter->dev_rst_time = jiffies;
1608 revision_id = pdev->revision;
1609 adapter->ahw->revision_id = revision_id;
1610 adapter->mac_learn = qlcnic_mac_learn;
1612 rwlock_init(&adapter->ahw->crb_lock);
1613 mutex_init(&adapter->ahw->mem_lock);
1615 spin_lock_init(&adapter->tx_clean_lock);
1616 INIT_LIST_HEAD(&adapter->mac_list);
1618 err = qlcnic_setup_pci_map(adapter);
1620 goto err_out_free_hw;
1622 /* This will be reset for mezz cards */
1623 adapter->portnum = adapter->ahw->pci_func;
1625 err = qlcnic_get_board_info(adapter);
1627 dev_err(&pdev->dev, "Error getting board config info.\n");
1628 goto err_out_iounmap;
1631 err = qlcnic_setup_idc_param(adapter);
1633 goto err_out_iounmap;
1635 adapter->flags |= QLCNIC_NEED_FLR;
1637 err = adapter->nic_ops->start_firmware(adapter);
1639 dev_err(&pdev->dev, "Loading fw failed. Please Reboot\n"
1640 "\t\tIf reboot doesn't help, try flashing the card\n");
1641 goto err_out_maintenance_mode;
1644 if (qlcnic_read_mac_addr(adapter))
1645 dev_warn(&pdev->dev, "failed to read mac addr\n");
1647 if (adapter->portnum == 0) {
1648 get_brd_name(adapter, brd_name);
1650 pr_info("%s: %s Board Chip rev 0x%x\n",
1651 module_name(THIS_MODULE),
1652 brd_name, adapter->ahw->revision_id);
1655 qlcnic_clear_stats(adapter);
1657 err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques);
1659 goto err_out_decr_ref;
1661 qlcnic_setup_intr(adapter);
1663 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
1665 goto err_out_disable_msi;
1667 pci_set_drvdata(pdev, adapter);
1669 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1671 switch (adapter->ahw->port_type) {
1673 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1674 adapter->netdev->name);
1677 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1678 adapter->netdev->name);
1682 if (adapter->mac_learn)
1683 qlcnic_alloc_lb_filters_mem(adapter);
1685 qlcnic_create_diag_entries(adapter);
1689 err_out_disable_msi:
1690 qlcnic_teardown_intr(adapter);
1691 kfree(adapter->msix_entries);
1694 qlcnic_clr_all_drv_state(adapter, 0);
1697 qlcnic_cleanup_pci_map(adapter);
1700 qlcnic_free_adapter_resources(adapter);
1702 err_out_free_netdev:
1703 free_netdev(netdev);
1706 pci_release_regions(pdev);
1708 err_out_disable_pdev:
1709 pci_set_drvdata(pdev, NULL);
1710 pci_disable_device(pdev);
1713 err_out_maintenance_mode:
1714 netdev->netdev_ops = &qlcnic_netdev_failed_ops;
1715 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops);
1716 err = register_netdev(netdev);
1718 dev_err(&pdev->dev, "failed to register net device\n");
1719 goto err_out_decr_ref;
1721 pci_set_drvdata(pdev, adapter);
1722 qlcnic_create_diag_entries(adapter);
1726 static void __devexit qlcnic_remove(struct pci_dev *pdev)
1728 struct qlcnic_adapter *adapter;
1729 struct net_device *netdev;
1731 adapter = pci_get_drvdata(pdev);
1732 if (adapter == NULL)
1735 netdev = adapter->netdev;
1737 qlcnic_cancel_fw_work(adapter);
1739 unregister_netdev(netdev);
1741 qlcnic_detach(adapter);
1743 if (adapter->npars != NULL)
1744 kfree(adapter->npars);
1745 if (adapter->eswitch != NULL)
1746 kfree(adapter->eswitch);
1748 qlcnic_clr_all_drv_state(adapter, 0);
1750 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1752 qlcnic_free_lb_filters_mem(adapter);
1754 qlcnic_teardown_intr(adapter);
1755 kfree(adapter->msix_entries);
1757 qlcnic_remove_diag_entries(adapter);
1759 qlcnic_cleanup_pci_map(adapter);
1761 qlcnic_release_firmware(adapter);
1763 pci_disable_pcie_error_reporting(pdev);
1764 pci_release_regions(pdev);
1765 pci_disable_device(pdev);
1766 pci_set_drvdata(pdev, NULL);
1768 qlcnic_free_adapter_resources(adapter);
1769 free_netdev(netdev);
1771 static int __qlcnic_shutdown(struct pci_dev *pdev)
1773 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1774 struct net_device *netdev = adapter->netdev;
1777 netif_device_detach(netdev);
1779 qlcnic_cancel_fw_work(adapter);
1781 if (netif_running(netdev))
1782 qlcnic_down(adapter, netdev);
1784 qlcnic_clr_all_drv_state(adapter, 0);
1786 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1788 retval = pci_save_state(pdev);
1792 if (qlcnic_wol_supported(adapter)) {
1793 pci_enable_wake(pdev, PCI_D3cold, 1);
1794 pci_enable_wake(pdev, PCI_D3hot, 1);
1800 static void qlcnic_shutdown(struct pci_dev *pdev)
1802 if (__qlcnic_shutdown(pdev))
1805 pci_disable_device(pdev);
1810 qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1814 retval = __qlcnic_shutdown(pdev);
1818 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1823 qlcnic_resume(struct pci_dev *pdev)
1825 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1826 struct net_device *netdev = adapter->netdev;
1829 err = pci_enable_device(pdev);
1833 pci_set_power_state(pdev, PCI_D0);
1834 pci_set_master(pdev);
1835 pci_restore_state(pdev);
1837 err = adapter->nic_ops->start_firmware(adapter);
1839 dev_err(&pdev->dev, "failed to start firmware\n");
1843 if (netif_running(netdev)) {
1844 err = qlcnic_up(adapter, netdev);
1848 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1851 netif_device_attach(netdev);
1852 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1857 static int qlcnic_open(struct net_device *netdev)
1859 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1860 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
1863 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
1864 netdev_err(netdev, "Device in FAILED state\n");
1868 netif_carrier_off(netdev);
1870 err = qlcnic_attach(adapter);
1874 err = __qlcnic_up(adapter, netdev);
1878 netif_start_queue(netdev);
1883 qlcnic_detach(adapter);
1888 * qlcnic_close - Disables a network interface entry point
1890 static int qlcnic_close(struct net_device *netdev)
1892 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1894 __qlcnic_down(adapter, netdev);
1898 void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
1903 if (adapter->fhash.fmax && adapter->fhash.fhead)
1906 spin_lock_init(&adapter->mac_learn_lock);
1908 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1913 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
1914 adapter->fhash.fhead = head;
1916 for (i = 0; i < adapter->fhash.fmax; i++)
1917 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1920 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1922 if (adapter->fhash.fmax && adapter->fhash.fhead)
1923 kfree(adapter->fhash.fhead);
1925 adapter->fhash.fhead = NULL;
1926 adapter->fhash.fmax = 0;
1929 static void qlcnic_change_filter(struct qlcnic_adapter *adapter,
1930 u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
1932 struct cmd_desc_type0 *hwdesc;
1933 struct qlcnic_nic_req *req;
1934 struct qlcnic_mac_req *mac_req;
1935 struct qlcnic_vlan_req *vlan_req;
1939 producer = tx_ring->producer;
1940 hwdesc = &tx_ring->desc_head[tx_ring->producer];
1942 req = (struct qlcnic_nic_req *)hwdesc;
1943 memset(req, 0, sizeof(struct qlcnic_nic_req));
1944 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
1946 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
1947 req->req_hdr = cpu_to_le64(word);
1949 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
1950 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
1951 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
1953 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
1954 vlan_req->vlan_id = vlan_id;
1956 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
1960 #define QLCNIC_MAC_HASH(MAC)\
1961 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1964 qlcnic_send_filter(struct qlcnic_adapter *adapter,
1965 struct qlcnic_host_tx_ring *tx_ring,
1966 struct cmd_desc_type0 *first_desc,
1967 struct sk_buff *skb)
1969 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
1970 struct qlcnic_filter *fil, *tmp_fil;
1971 struct hlist_node *tmp_hnode, *n;
1972 struct hlist_head *head;
1977 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
1980 if (adapter->fhash.fnum >= adapter->fhash.fmax)
1983 /* Only NPAR capable devices support vlan based learning*/
1984 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
1985 vlan_id = first_desc->vlan_TCI;
1986 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
1987 hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1);
1988 head = &(adapter->fhash.fhead[hindex]);
1990 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
1991 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1992 tmp_fil->vlan_id == vlan_id) {
1995 (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
1996 qlcnic_change_filter(adapter, src_addr, vlan_id,
1998 tmp_fil->ftime = jiffies;
2003 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
2007 qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring);
2009 fil->ftime = jiffies;
2010 fil->vlan_id = vlan_id;
2011 memcpy(fil->faddr, &src_addr, ETH_ALEN);
2012 spin_lock(&adapter->mac_learn_lock);
2013 hlist_add_head(&(fil->fnode), head);
2014 adapter->fhash.fnum++;
2015 spin_unlock(&adapter->mac_learn_lock);
2019 qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
2020 struct cmd_desc_type0 *first_desc,
2021 struct sk_buff *skb)
2023 u8 opcode = 0, hdr_len = 0;
2024 u16 flags = 0, vlan_tci = 0;
2025 int copied, offset, copy_len;
2026 struct cmd_desc_type0 *hwdesc;
2027 struct vlan_ethhdr *vh;
2028 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2029 u16 protocol = ntohs(skb->protocol);
2030 u32 producer = tx_ring->producer;
2032 if (protocol == ETH_P_8021Q) {
2033 vh = (struct vlan_ethhdr *)skb->data;
2034 flags = FLAGS_VLAN_TAGGED;
2035 vlan_tci = vh->h_vlan_TCI;
2036 protocol = ntohs(vh->h_vlan_encapsulated_proto);
2037 } else if (vlan_tx_tag_present(skb)) {
2038 flags = FLAGS_VLAN_OOB;
2039 vlan_tci = vlan_tx_tag_get(skb);
2041 if (unlikely(adapter->pvid)) {
2042 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
2044 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
2047 flags = FLAGS_VLAN_OOB;
2048 vlan_tci = adapter->pvid;
2051 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
2052 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2054 if (*(skb->data) & BIT_0) {
2056 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
2058 opcode = TX_ETHER_PKT;
2059 if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
2060 skb_shinfo(skb)->gso_size > 0) {
2062 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2064 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
2065 first_desc->total_hdr_length = hdr_len;
2067 opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO;
2069 /* For LSO, we need to copy the MAC/IP/TCP headers into
2070 * the descriptor ring */
2074 if (flags & FLAGS_VLAN_OOB) {
2075 first_desc->total_hdr_length += VLAN_HLEN;
2076 first_desc->tcp_hdr_offset = VLAN_HLEN;
2077 first_desc->ip_hdr_offset = VLAN_HLEN;
2078 /* Only in case of TSO on vlan device */
2079 flags |= FLAGS_VLAN_TAGGED;
2081 /* Create a TSO vlan header template for firmware */
2083 hwdesc = &tx_ring->desc_head[producer];
2084 tx_ring->cmd_buf_arr[producer].skb = NULL;
2086 copy_len = min((int)sizeof(struct cmd_desc_type0) -
2087 offset, hdr_len + VLAN_HLEN);
2089 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
2090 skb_copy_from_linear_data(skb, vh, 12);
2091 vh->h_vlan_proto = htons(ETH_P_8021Q);
2092 vh->h_vlan_TCI = htons(vlan_tci);
2094 skb_copy_from_linear_data_offset(skb, 12,
2095 (char *)vh + 16, copy_len - 16);
2097 copied = copy_len - VLAN_HLEN;
2100 producer = get_next_index(producer, tx_ring->num_desc);
2103 while (copied < hdr_len) {
2105 copy_len = min((int)sizeof(struct cmd_desc_type0) -
2106 offset, (hdr_len - copied));
2108 hwdesc = &tx_ring->desc_head[producer];
2109 tx_ring->cmd_buf_arr[producer].skb = NULL;
2111 skb_copy_from_linear_data_offset(skb, copied,
2112 (char *) hwdesc + offset, copy_len);
2117 producer = get_next_index(producer, tx_ring->num_desc);
2120 tx_ring->producer = producer;
2122 adapter->stats.lso_frames++;
2124 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
2127 if (protocol == ETH_P_IP) {
2128 l4proto = ip_hdr(skb)->protocol;
2130 if (l4proto == IPPROTO_TCP)
2131 opcode = TX_TCP_PKT;
2132 else if (l4proto == IPPROTO_UDP)
2133 opcode = TX_UDP_PKT;
2134 } else if (protocol == ETH_P_IPV6) {
2135 l4proto = ipv6_hdr(skb)->nexthdr;
2137 if (l4proto == IPPROTO_TCP)
2138 opcode = TX_TCPV6_PKT;
2139 else if (l4proto == IPPROTO_UDP)
2140 opcode = TX_UDPV6_PKT;
2143 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
2144 first_desc->ip_hdr_offset += skb_network_offset(skb);
2145 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2151 qlcnic_map_tx_skb(struct pci_dev *pdev,
2152 struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf)
2154 struct qlcnic_skb_frag *nf;
2155 struct skb_frag_struct *frag;
2159 nr_frags = skb_shinfo(skb)->nr_frags;
2160 nf = &pbuf->frag_array[0];
2162 map = pci_map_single(pdev, skb->data,
2163 skb_headlen(skb), PCI_DMA_TODEVICE);
2164 if (pci_dma_mapping_error(pdev, map))
2168 nf->length = skb_headlen(skb);
2170 for (i = 0; i < nr_frags; i++) {
2171 frag = &skb_shinfo(skb)->frags[i];
2172 nf = &pbuf->frag_array[i+1];
2174 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
2176 if (dma_mapping_error(&pdev->dev, map))
2180 nf->length = skb_frag_size(frag);
2187 nf = &pbuf->frag_array[i+1];
2188 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2191 nf = &pbuf->frag_array[0];
2192 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2199 qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
2200 struct qlcnic_cmd_buffer *pbuf)
2202 struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
2203 int nr_frags = skb_shinfo(skb)->nr_frags;
2206 for (i = 0; i < nr_frags; i++) {
2207 nf = &pbuf->frag_array[i+1];
2208 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2211 nf = &pbuf->frag_array[0];
2212 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2217 qlcnic_clear_cmddesc(u64 *desc)
2225 qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2227 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2228 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2229 struct qlcnic_cmd_buffer *pbuf;
2230 struct qlcnic_skb_frag *buffrag;
2231 struct cmd_desc_type0 *hwdesc, *first_desc;
2232 struct pci_dev *pdev;
2233 struct ethhdr *phdr;
2239 u32 num_txd = tx_ring->num_desc;
2241 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
2242 netif_stop_queue(netdev);
2243 return NETDEV_TX_BUSY;
2246 if (adapter->flags & QLCNIC_MACSPOOF) {
2247 phdr = (struct ethhdr *)skb->data;
2248 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
2252 frag_count = skb_shinfo(skb)->nr_frags + 1;
2253 /* 14 frags supported for normal packet and
2254 * 32 frags supported for TSO packet
2256 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
2258 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
2259 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
2261 if (!__pskb_pull_tail(skb, delta))
2264 frag_count = 1 + skb_shinfo(skb)->nr_frags;
2267 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
2268 netif_stop_queue(netdev);
2269 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
2270 netif_start_queue(netdev);
2272 adapter->stats.xmit_off++;
2273 return NETDEV_TX_BUSY;
2277 producer = tx_ring->producer;
2278 pbuf = &tx_ring->cmd_buf_arr[producer];
2280 pdev = adapter->pdev;
2282 first_desc = hwdesc = &tx_ring->desc_head[producer];
2283 qlcnic_clear_cmddesc((u64 *)hwdesc);
2285 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
2286 adapter->stats.tx_dma_map_error++;
2291 pbuf->frag_count = frag_count;
2293 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
2294 qlcnic_set_tx_port(first_desc, adapter->portnum);
2296 for (i = 0; i < frag_count; i++) {
2300 if ((k == 0) && (i > 0)) {
2301 /* move to next desc.*/
2302 producer = get_next_index(producer, num_txd);
2303 hwdesc = &tx_ring->desc_head[producer];
2304 qlcnic_clear_cmddesc((u64 *)hwdesc);
2305 tx_ring->cmd_buf_arr[producer].skb = NULL;
2308 buffrag = &pbuf->frag_array[i];
2310 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2313 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2316 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2319 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2322 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2327 tx_ring->producer = get_next_index(producer, num_txd);
2330 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb)))
2333 if (adapter->mac_learn)
2334 qlcnic_send_filter(adapter, tx_ring, first_desc, skb);
2336 adapter->stats.txbytes += skb->len;
2337 adapter->stats.xmitcalled++;
2339 qlcnic_update_cmd_producer(adapter, tx_ring);
2341 return NETDEV_TX_OK;
2344 qlcnic_unmap_buffers(pdev, skb, pbuf);
2346 adapter->stats.txdropped++;
2347 dev_kfree_skb_any(skb);
2348 return NETDEV_TX_OK;
2351 static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
2353 struct net_device *netdev = adapter->netdev;
2354 u32 temp, temp_state, temp_val;
2357 temp = QLCRD32(adapter, CRB_TEMP_STATE);
2359 temp_state = qlcnic_get_temp_state(temp);
2360 temp_val = qlcnic_get_temp_val(temp);
2362 if (temp_state == QLCNIC_TEMP_PANIC) {
2363 dev_err(&netdev->dev,
2364 "Device temperature %d degrees C exceeds"
2365 " maximum allowed. Hardware has been shut down.\n",
2368 } else if (temp_state == QLCNIC_TEMP_WARN) {
2369 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
2370 dev_err(&netdev->dev,
2371 "Device temperature %d degrees C "
2372 "exceeds operating range."
2373 " Immediate action needed.\n",
2377 if (adapter->temp == QLCNIC_TEMP_WARN) {
2378 dev_info(&netdev->dev,
2379 "Device temperature is now %d degrees C"
2380 " in normal range.\n", temp_val);
2383 adapter->temp = temp_state;
2387 void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2389 struct net_device *netdev = adapter->netdev;
2391 if (adapter->ahw->linkup && !linkup) {
2392 netdev_info(netdev, "NIC Link is down\n");
2393 adapter->ahw->linkup = 0;
2394 if (netif_running(netdev)) {
2395 netif_carrier_off(netdev);
2396 netif_stop_queue(netdev);
2398 } else if (!adapter->ahw->linkup && linkup) {
2399 netdev_info(netdev, "NIC Link is up\n");
2400 adapter->ahw->linkup = 1;
2401 if (netif_running(netdev)) {
2402 netif_carrier_on(netdev);
2403 netif_wake_queue(netdev);
2408 static void qlcnic_tx_timeout(struct net_device *netdev)
2410 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2412 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2415 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
2417 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
2418 adapter->need_fw_reset = 1;
2420 adapter->reset_context = 1;
2423 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2425 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2426 struct net_device_stats *stats = &netdev->stats;
2428 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2429 stats->tx_packets = adapter->stats.xmitfinished;
2430 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
2431 stats->tx_bytes = adapter->stats.txbytes;
2432 stats->rx_dropped = adapter->stats.rxdropped;
2433 stats->tx_dropped = adapter->stats.txdropped;
2438 static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
2442 status = readl(adapter->isr_int_vec);
2444 if (!(status & adapter->int_vec_bit))
2447 /* check interrupt state machine, to be sure */
2448 status = readl(adapter->crb_int_state_reg);
2449 if (!ISR_LEGACY_INT_TRIGGERED(status))
2452 writel(0xffffffff, adapter->tgt_status_reg);
2453 /* read twice to ensure write is flushed */
2454 readl(adapter->isr_int_vec);
2455 readl(adapter->isr_int_vec);
2460 static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2462 struct qlcnic_host_sds_ring *sds_ring = data;
2463 struct qlcnic_adapter *adapter = sds_ring->adapter;
2465 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2467 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2468 writel(0xffffffff, adapter->tgt_status_reg);
2472 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2476 adapter->diag_cnt++;
2477 qlcnic_enable_int(sds_ring);
2481 static irqreturn_t qlcnic_intr(int irq, void *data)
2483 struct qlcnic_host_sds_ring *sds_ring = data;
2484 struct qlcnic_adapter *adapter = sds_ring->adapter;
2486 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2489 napi_schedule(&sds_ring->napi);
2494 static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2496 struct qlcnic_host_sds_ring *sds_ring = data;
2497 struct qlcnic_adapter *adapter = sds_ring->adapter;
2499 /* clear interrupt */
2500 writel(0xffffffff, adapter->tgt_status_reg);
2502 napi_schedule(&sds_ring->napi);
2506 static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2508 struct qlcnic_host_sds_ring *sds_ring = data;
2510 napi_schedule(&sds_ring->napi);
2514 static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter)
2516 u32 sw_consumer, hw_consumer;
2518 struct qlcnic_cmd_buffer *buffer;
2519 struct pci_dev *pdev = adapter->pdev;
2520 struct net_device *netdev = adapter->netdev;
2521 struct qlcnic_skb_frag *frag;
2523 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2525 if (!spin_trylock(&adapter->tx_clean_lock))
2528 sw_consumer = tx_ring->sw_consumer;
2529 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2531 while (sw_consumer != hw_consumer) {
2532 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
2534 frag = &buffer->frag_array[0];
2535 pci_unmap_single(pdev, frag->dma, frag->length,
2538 for (i = 1; i < buffer->frag_count; i++) {
2540 pci_unmap_page(pdev, frag->dma, frag->length,
2545 adapter->stats.xmitfinished++;
2546 dev_kfree_skb_any(buffer->skb);
2550 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
2551 if (++count >= MAX_STATUS_HANDLE)
2555 if (count && netif_running(netdev)) {
2556 tx_ring->sw_consumer = sw_consumer;
2560 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
2561 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
2562 netif_wake_queue(netdev);
2563 adapter->stats.xmit_on++;
2566 adapter->tx_timeo_cnt = 0;
2569 * If everything is freed up to consumer then check if the ring is full
2570 * If the ring is full then check if more needs to be freed and
2571 * schedule the call back again.
2573 * This happens when there are 2 CPUs. One could be freeing and the
2574 * other filling it. If the ring is full when we get out of here and
2575 * the card has already interrupted the host then the host can miss the
2578 * There is still a possible race condition and the host could miss an
2579 * interrupt. The card has to take care of this.
2581 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2582 done = (sw_consumer == hw_consumer);
2583 spin_unlock(&adapter->tx_clean_lock);
2588 static int qlcnic_poll(struct napi_struct *napi, int budget)
2590 struct qlcnic_host_sds_ring *sds_ring =
2591 container_of(napi, struct qlcnic_host_sds_ring, napi);
2593 struct qlcnic_adapter *adapter = sds_ring->adapter;
2598 tx_complete = qlcnic_process_cmd_ring(adapter);
2600 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2602 if ((work_done < budget) && tx_complete) {
2603 napi_complete(&sds_ring->napi);
2604 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2605 qlcnic_enable_int(sds_ring);
2611 static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
2613 struct qlcnic_host_sds_ring *sds_ring =
2614 container_of(napi, struct qlcnic_host_sds_ring, napi);
2616 struct qlcnic_adapter *adapter = sds_ring->adapter;
2619 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2621 if (work_done < budget) {
2622 napi_complete(&sds_ring->napi);
2623 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2624 qlcnic_enable_int(sds_ring);
2630 #ifdef CONFIG_NET_POLL_CONTROLLER
2631 static void qlcnic_poll_controller(struct net_device *netdev)
2634 struct qlcnic_host_sds_ring *sds_ring;
2635 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2636 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2638 disable_irq(adapter->irq);
2639 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2640 sds_ring = &recv_ctx->sds_rings[ring];
2641 qlcnic_intr(adapter->irq, sds_ring);
2643 enable_irq(adapter->irq);
2648 qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2652 val = adapter->portnum & 0xf;
2653 val |= encoding << 7;
2654 val |= (jiffies - adapter->dev_rst_time) << 8;
2656 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2657 adapter->dev_rst_time = jiffies;
2661 qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
2665 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2666 state != QLCNIC_DEV_NEED_QUISCENT);
2668 if (qlcnic_api_lock(adapter))
2671 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2673 if (state == QLCNIC_DEV_NEED_RESET)
2674 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2675 else if (state == QLCNIC_DEV_NEED_QUISCENT)
2676 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
2678 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2680 qlcnic_api_unlock(adapter);
2686 qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2690 if (qlcnic_api_lock(adapter))
2693 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2694 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2695 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2697 qlcnic_api_unlock(adapter);
2703 qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
2707 if (qlcnic_api_lock(adapter))
2710 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2711 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
2712 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2715 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2716 dev_info(&adapter->pdev->dev,
2717 "Device state set to Failed. Please Reboot\n");
2718 } else if (!(val & 0x11111111))
2719 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2721 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2722 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2723 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2725 qlcnic_api_unlock(adapter);
2727 adapter->fw_fail_cnt = 0;
2728 adapter->flags &= ~QLCNIC_FW_HANG;
2729 clear_bit(__QLCNIC_START_FW, &adapter->state);
2730 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2733 /* Grab api lock, before checking state */
2735 qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2737 int act, state, active_mask;
2739 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2740 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2742 if (adapter->flags & QLCNIC_FW_RESET_OWNER) {
2743 active_mask = (~(1 << (adapter->ahw->pci_func * 4)));
2744 act = act & active_mask;
2747 if (((state & 0x11111111) == (act & 0x11111111)) ||
2748 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2754 static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2756 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2758 if (val != QLCNIC_DRV_IDC_VER) {
2759 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2760 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2767 qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2769 u32 val, prev_state;
2770 u8 dev_init_timeo = adapter->dev_init_timeo;
2771 u8 portnum = adapter->portnum;
2774 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2777 if (qlcnic_api_lock(adapter))
2780 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2781 if (!(val & (1 << (portnum * 4)))) {
2782 QLC_DEV_SET_REF_CNT(val, portnum);
2783 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2786 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2787 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
2789 switch (prev_state) {
2790 case QLCNIC_DEV_COLD:
2791 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2792 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
2793 qlcnic_idc_debug_info(adapter, 0);
2794 qlcnic_api_unlock(adapter);
2797 case QLCNIC_DEV_READY:
2798 ret = qlcnic_check_idc_ver(adapter);
2799 qlcnic_api_unlock(adapter);
2802 case QLCNIC_DEV_NEED_RESET:
2803 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2804 QLC_DEV_SET_RST_RDY(val, portnum);
2805 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2808 case QLCNIC_DEV_NEED_QUISCENT:
2809 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2810 QLC_DEV_SET_QSCNT_RDY(val, portnum);
2811 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2814 case QLCNIC_DEV_FAILED:
2815 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
2816 qlcnic_api_unlock(adapter);
2819 case QLCNIC_DEV_INITIALIZING:
2820 case QLCNIC_DEV_QUISCENT:
2824 qlcnic_api_unlock(adapter);
2828 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2830 if (prev_state == QLCNIC_DEV_QUISCENT)
2832 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
2834 if (!dev_init_timeo) {
2835 dev_err(&adapter->pdev->dev,
2836 "Waiting for device to initialize timeout\n");
2840 if (qlcnic_api_lock(adapter))
2843 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2844 QLC_DEV_CLR_RST_QSCNT(val, portnum);
2845 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2847 ret = qlcnic_check_idc_ver(adapter);
2848 qlcnic_api_unlock(adapter);
2854 qlcnic_fwinit_work(struct work_struct *work)
2856 struct qlcnic_adapter *adapter = container_of(work,
2857 struct qlcnic_adapter, fw_work.work);
2858 u32 dev_state = 0xf;
2861 if (qlcnic_api_lock(adapter))
2864 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2865 if (dev_state == QLCNIC_DEV_QUISCENT ||
2866 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2867 qlcnic_api_unlock(adapter);
2868 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2873 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
2874 qlcnic_api_unlock(adapter);
2878 if (dev_state == QLCNIC_DEV_INITIALIZING ||
2879 dev_state == QLCNIC_DEV_READY) {
2880 dev_info(&adapter->pdev->dev, "Detected state change from "
2881 "DEV_NEED_RESET, skipping ack check\n");
2882 goto skip_ack_check;
2885 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
2886 dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
2887 adapter->reset_ack_timeo);
2888 goto skip_ack_check;
2891 if (!qlcnic_check_drv_state(adapter)) {
2893 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2895 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2896 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2897 QLCNIC_DEV_INITIALIZING);
2898 set_bit(__QLCNIC_START_FW, &adapter->state);
2899 QLCDB(adapter, DRV, "Restarting fw\n");
2900 qlcnic_idc_debug_info(adapter, 0);
2901 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2902 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2903 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2906 qlcnic_api_unlock(adapter);
2909 if (adapter->ahw->fw_dump.enable &&
2910 (adapter->flags & QLCNIC_FW_RESET_OWNER)) {
2911 QLCDB(adapter, DRV, "Take FW dump\n");
2912 qlcnic_dump_fw(adapter);
2913 adapter->flags |= QLCNIC_FW_HANG;
2917 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
2918 if (!adapter->nic_ops->start_firmware(adapter)) {
2919 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2920 adapter->fw_wait_cnt = 0;
2926 qlcnic_api_unlock(adapter);
2929 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2930 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
2932 switch (dev_state) {
2933 case QLCNIC_DEV_READY:
2934 if (!adapter->nic_ops->start_firmware(adapter)) {
2935 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2936 adapter->fw_wait_cnt = 0;
2939 case QLCNIC_DEV_FAILED:
2942 qlcnic_schedule_work(adapter,
2943 qlcnic_fwinit_work, FW_POLL_DELAY);
2948 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2949 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
2950 netif_device_attach(adapter->netdev);
2951 qlcnic_clr_all_drv_state(adapter, 0);
2955 qlcnic_detach_work(struct work_struct *work)
2957 struct qlcnic_adapter *adapter = container_of(work,
2958 struct qlcnic_adapter, fw_work.work);
2959 struct net_device *netdev = adapter->netdev;
2962 netif_device_detach(netdev);
2964 /* Dont grab rtnl lock during Quiscent mode */
2965 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2966 if (netif_running(netdev))
2967 __qlcnic_down(adapter, netdev);
2969 qlcnic_down(adapter, netdev);
2971 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2973 if (status & QLCNIC_RCODE_FATAL_ERROR) {
2974 dev_err(&adapter->pdev->dev,
2975 "Detaching the device: peg halt status1=0x%x\n",
2978 if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) {
2979 dev_err(&adapter->pdev->dev,
2980 "On board active cooling fan failed. "
2981 "Device has been halted.\n");
2982 dev_err(&adapter->pdev->dev,
2983 "Replace the adapter.\n");
2989 if (adapter->temp == QLCNIC_TEMP_PANIC) {
2990 dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n",
2995 /* Dont ack if this instance is the reset owner */
2996 if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) {
2997 if (qlcnic_set_drv_state(adapter, adapter->dev_state)) {
2998 dev_err(&adapter->pdev->dev,
2999 "Failed to set driver state,"
3000 "detaching the device.\n");
3005 adapter->fw_wait_cnt = 0;
3007 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
3012 netif_device_attach(netdev);
3013 qlcnic_clr_all_drv_state(adapter, 1);
3016 /*Transit NPAR state to NON Operational */
3018 qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
3022 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
3023 if (state == QLCNIC_DEV_NPAR_NON_OPER)
3026 if (qlcnic_api_lock(adapter))
3028 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
3029 qlcnic_api_unlock(adapter);
3032 /*Transit to RESET state from READY state only */
3034 qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
3036 u32 state, xg_val = 0, gb_val = 0;
3038 qlcnic_xg_set_xg0_mask(xg_val);
3039 qlcnic_xg_set_xg1_mask(xg_val);
3040 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val);
3041 qlcnic_gb_set_gb0_mask(gb_val);
3042 qlcnic_gb_set_gb1_mask(gb_val);
3043 qlcnic_gb_set_gb2_mask(gb_val);
3044 qlcnic_gb_set_gb3_mask(gb_val);
3045 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val);
3046 dev_info(&adapter->pdev->dev, "Pause control frames disabled"
3048 adapter->need_fw_reset = 1;
3049 if (qlcnic_api_lock(adapter))
3052 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
3053 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) {
3054 netdev_err(adapter->netdev,
3055 "Device is in FAILED state, Please Reboot\n");
3056 qlcnic_api_unlock(adapter);
3060 if (state == QLCNIC_DEV_READY) {
3061 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
3062 adapter->flags |= QLCNIC_FW_RESET_OWNER;
3063 QLCDB(adapter, DRV, "NEED_RESET state set\n");
3064 qlcnic_idc_debug_info(adapter, 0);
3067 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
3068 qlcnic_api_unlock(adapter);
3071 /* Transit to NPAR READY state from NPAR NOT READY state */
3073 qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
3075 if (qlcnic_api_lock(adapter))
3078 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
3079 QLCDB(adapter, DRV, "NPAR operational state set\n");
3081 qlcnic_api_unlock(adapter);
3085 qlcnic_schedule_work(struct qlcnic_adapter *adapter,
3086 work_func_t func, int delay)
3088 if (test_bit(__QLCNIC_AER, &adapter->state))
3091 INIT_DELAYED_WORK(&adapter->fw_work, func);
3092 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
3093 round_jiffies_relative(delay));
3097 qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
3099 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
3102 if (!adapter->fw_work.work.func)
3105 cancel_delayed_work_sync(&adapter->fw_work);
3109 qlcnic_attach_work(struct work_struct *work)
3111 struct qlcnic_adapter *adapter = container_of(work,
3112 struct qlcnic_adapter, fw_work.work);
3113 struct net_device *netdev = adapter->netdev;
3116 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
3117 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
3118 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
3119 qlcnic_clr_all_drv_state(adapter, 0);
3120 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
3121 qlcnic_schedule_work(adapter, qlcnic_attach_work,
3125 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
3129 if (netif_running(netdev)) {
3130 if (qlcnic_up(adapter, netdev))
3133 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3137 netif_device_attach(netdev);
3138 adapter->fw_fail_cnt = 0;
3139 adapter->flags &= ~QLCNIC_FW_HANG;
3140 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3142 if (!qlcnic_clr_drv_state(adapter))
3143 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3148 qlcnic_check_health(struct qlcnic_adapter *adapter)
3150 u32 state = 0, heartbeat;
3153 if (qlcnic_check_temp(adapter))
3156 if (adapter->need_fw_reset)
3157 qlcnic_dev_request_reset(adapter);
3159 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
3160 if (state == QLCNIC_DEV_NEED_RESET) {
3161 qlcnic_set_npar_non_operational(adapter);
3162 adapter->need_fw_reset = 1;
3163 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
3166 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
3167 if (heartbeat != adapter->heartbeat) {
3168 adapter->heartbeat = heartbeat;
3169 adapter->fw_fail_cnt = 0;
3170 if (adapter->need_fw_reset)
3173 if (adapter->reset_context && auto_fw_reset) {
3174 qlcnic_reset_hw_context(adapter);
3175 adapter->netdev->trans_start = jiffies;
3181 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
3184 adapter->flags |= QLCNIC_FW_HANG;
3186 qlcnic_dev_request_reset(adapter);
3189 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
3191 dev_err(&adapter->pdev->dev, "firmware hang detected\n");
3192 dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n"
3193 "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
3194 "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
3195 "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
3196 "PEG_NET_4_PC: 0x%x\n",
3197 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1),
3198 QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2),
3199 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c),
3200 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c),
3201 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c),
3202 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c),
3203 QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c));
3204 peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
3205 if (QLCNIC_FWERROR_CODE(peg_status) == 0x67)
3206 dev_err(&adapter->pdev->dev,
3207 "Firmware aborted with error code 0x00006700. "
3208 "Device is being reset.\n");
3210 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3211 QLCNIC_DEV_NEED_RESET;
3213 if (auto_fw_reset &&
3214 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
3216 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
3217 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3224 qlcnic_fw_poll_work(struct work_struct *work)
3226 struct qlcnic_adapter *adapter = container_of(work,
3227 struct qlcnic_adapter, fw_work.work);
3229 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3233 if (qlcnic_check_health(adapter))
3236 if (adapter->fhash.fnum)
3237 qlcnic_prune_lb_filters(adapter);
3240 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3243 static int qlcnic_is_first_func(struct pci_dev *pdev)
3245 struct pci_dev *oth_pdev;
3246 int val = pdev->devfn;
3249 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3250 (pdev->bus), pdev->bus->number,
3251 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
3255 if (oth_pdev->current_state != PCI_D3cold) {
3256 pci_dev_put(oth_pdev);
3259 pci_dev_put(oth_pdev);
3264 static int qlcnic_attach_func(struct pci_dev *pdev)
3266 int err, first_func;
3267 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3268 struct net_device *netdev = adapter->netdev;
3270 pdev->error_state = pci_channel_io_normal;
3272 err = pci_enable_device(pdev);
3276 pci_set_power_state(pdev, PCI_D0);
3277 pci_set_master(pdev);
3278 pci_restore_state(pdev);
3280 first_func = qlcnic_is_first_func(pdev);
3282 if (qlcnic_api_lock(adapter))
3285 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
3286 adapter->need_fw_reset = 1;
3287 set_bit(__QLCNIC_START_FW, &adapter->state);
3288 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
3289 QLCDB(adapter, DRV, "Restarting fw\n");
3291 qlcnic_api_unlock(adapter);
3293 err = adapter->nic_ops->start_firmware(adapter);
3297 qlcnic_clr_drv_state(adapter);
3298 qlcnic_setup_intr(adapter);
3300 if (netif_running(netdev)) {
3301 err = qlcnic_attach(adapter);
3303 qlcnic_clr_all_drv_state(adapter, 1);
3304 clear_bit(__QLCNIC_AER, &adapter->state);
3305 netif_device_attach(netdev);
3309 err = qlcnic_up(adapter, netdev);
3313 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3316 netif_device_attach(netdev);
3320 static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3321 pci_channel_state_t state)
3323 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3324 struct net_device *netdev = adapter->netdev;
3326 if (state == pci_channel_io_perm_failure)
3327 return PCI_ERS_RESULT_DISCONNECT;
3329 if (state == pci_channel_io_normal)
3330 return PCI_ERS_RESULT_RECOVERED;
3332 set_bit(__QLCNIC_AER, &adapter->state);
3333 netif_device_detach(netdev);
3335 cancel_delayed_work_sync(&adapter->fw_work);
3337 if (netif_running(netdev))
3338 qlcnic_down(adapter, netdev);
3340 qlcnic_detach(adapter);
3341 qlcnic_teardown_intr(adapter);
3343 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3345 pci_save_state(pdev);
3346 pci_disable_device(pdev);
3348 return PCI_ERS_RESULT_NEED_RESET;
3351 static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3353 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3354 PCI_ERS_RESULT_RECOVERED;
3357 static void qlcnic_io_resume(struct pci_dev *pdev)
3359 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3361 pci_cleanup_aer_uncorrect_error_status(pdev);
3363 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
3364 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
3365 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3370 qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3374 err = qlcnic_can_start_firmware(adapter);
3378 err = qlcnic_check_npar_opertional(adapter);
3382 err = qlcnic_initialize_nic(adapter);
3386 qlcnic_check_options(adapter);
3388 err = qlcnic_set_eswitch_port_config(adapter);
3392 adapter->need_fw_reset = 0;
3398 qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
3404 qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
3410 qlcnic_store_bridged_mode(struct device *dev,
3411 struct device_attribute *attr, const char *buf, size_t len)
3413 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3417 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG))
3420 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3423 if (strict_strtoul(buf, 2, &new))
3426 if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
3434 qlcnic_show_bridged_mode(struct device *dev,
3435 struct device_attribute *attr, char *buf)
3437 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3438 int bridged_mode = 0;
3440 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3441 bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
3443 return sprintf(buf, "%d\n", bridged_mode);
3446 static struct device_attribute dev_attr_bridged_mode = {
3447 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
3448 .show = qlcnic_show_bridged_mode,
3449 .store = qlcnic_store_bridged_mode,
3453 qlcnic_store_diag_mode(struct device *dev,
3454 struct device_attribute *attr, const char *buf, size_t len)
3456 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3459 if (strict_strtoul(buf, 2, &new))
3462 if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
3463 adapter->flags ^= QLCNIC_DIAG_ENABLED;
3469 qlcnic_show_diag_mode(struct device *dev,
3470 struct device_attribute *attr, char *buf)
3472 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3474 return sprintf(buf, "%d\n",
3475 !!(adapter->flags & QLCNIC_DIAG_ENABLED));
3478 static struct device_attribute dev_attr_diag_mode = {
3479 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
3480 .show = qlcnic_show_diag_mode,
3481 .store = qlcnic_store_diag_mode,
3484 int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val)
3486 if (!use_msi_x && !use_msi) {
3487 netdev_info(netdev, "no msix or msi support, hence no rss\n");
3491 if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) {
3492 netdev_info(netdev, "rss_ring valid range [2 - %x] in "
3493 " powers of 2\n", max_hw);
3500 int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data)
3502 struct net_device *netdev = adapter->netdev;
3505 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
3508 netif_device_detach(netdev);
3509 if (netif_running(netdev))
3510 __qlcnic_down(adapter, netdev);
3511 qlcnic_detach(adapter);
3512 qlcnic_teardown_intr(adapter);
3514 if (qlcnic_enable_msix(adapter, data)) {
3515 netdev_info(netdev, "failed setting max_rss; rss disabled\n");
3516 qlcnic_enable_msi_legacy(adapter);
3519 if (netif_running(netdev)) {
3520 err = qlcnic_attach(adapter);
3523 err = __qlcnic_up(adapter, netdev);
3526 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3529 netif_device_attach(netdev);
3530 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3535 qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon, u8 *state,
3538 *rate = LSB(beacon);
3539 *state = MSB(beacon);
3541 QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state);
3544 *rate = __QLCNIC_MAX_LED_RATE;
3546 } else if (*state > __QLCNIC_MAX_LED_STATE)
3549 if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE))
3556 qlcnic_store_beacon(struct device *dev,
3557 struct device_attribute *attr, const char *buf, size_t len)
3559 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3560 int max_sds_rings = adapter->max_sds_rings;
3565 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
3566 dev_warn(dev, "LED test not supported for non "
3567 "privilege function\n");
3571 if (len != sizeof(u16))
3572 return QL_STATUS_INVALID_PARAM;
3574 memcpy(&beacon, buf, sizeof(u16));
3575 err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate);
3579 if (adapter->ahw->beacon_state == b_state)
3584 if (!adapter->ahw->beacon_state)
3585 if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) {
3590 if (test_bit(__QLCNIC_RESETTING, &adapter->state)) {
3595 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
3596 err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST);
3599 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
3602 err = qlcnic_config_led(adapter, b_state, b_rate);
3606 adapter->ahw->beacon_state = b_state;
3609 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
3610 qlcnic_diag_free_res(adapter->netdev, max_sds_rings);
3613 if (!adapter->ahw->beacon_state)
3614 clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
3621 qlcnic_show_beacon(struct device *dev,
3622 struct device_attribute *attr, char *buf)
3624 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3626 return sprintf(buf, "%d\n", adapter->ahw->beacon_state);
3629 static struct device_attribute dev_attr_beacon = {
3630 .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)},
3631 .show = qlcnic_show_beacon,
3632 .store = qlcnic_store_beacon,
3636 qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
3637 loff_t offset, size_t size)
3639 size_t crb_size = 4;
3641 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3644 if (offset < QLCNIC_PCI_CRBSPACE) {
3645 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
3646 QLCNIC_PCI_CAMQM_END))
3652 if ((size != crb_size) || (offset & (crb_size-1)))
3659 qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
3660 struct bin_attribute *attr,
3661 char *buf, loff_t offset, size_t size)
3663 struct device *dev = container_of(kobj, struct device, kobj);
3664 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3669 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3673 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3674 qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata);
3675 memcpy(buf, &qmdata, size);
3677 data = QLCRD32(adapter, offset);
3678 memcpy(buf, &data, size);
3684 qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
3685 struct bin_attribute *attr,
3686 char *buf, loff_t offset, size_t size)
3688 struct device *dev = container_of(kobj, struct device, kobj);
3689 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3694 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3698 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3699 memcpy(&qmdata, buf, size);
3700 qlcnic_pci_camqm_write_2M(adapter, offset, qmdata);
3702 memcpy(&data, buf, size);
3703 QLCWR32(adapter, offset, data);
3709 qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
3710 loff_t offset, size_t size)
3712 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3715 if ((size != 8) || (offset & 0x7))
3722 qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
3723 struct bin_attribute *attr,
3724 char *buf, loff_t offset, size_t size)
3726 struct device *dev = container_of(kobj, struct device, kobj);
3727 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3731 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3735 if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
3738 memcpy(buf, &data, size);
3744 qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
3745 struct bin_attribute *attr,
3746 char *buf, loff_t offset, size_t size)
3748 struct device *dev = container_of(kobj, struct device, kobj);
3749 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3753 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3757 memcpy(&data, buf, size);
3759 if (qlcnic_pci_mem_write_2M(adapter, offset, data))
3765 static struct bin_attribute bin_attr_crb = {
3766 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
3768 .read = qlcnic_sysfs_read_crb,
3769 .write = qlcnic_sysfs_write_crb,
3772 static struct bin_attribute bin_attr_mem = {
3773 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
3775 .read = qlcnic_sysfs_read_mem,
3776 .write = qlcnic_sysfs_write_mem,
3780 validate_pm_config(struct qlcnic_adapter *adapter,
3781 struct qlcnic_pm_func_cfg *pm_cfg, int count)
3784 u8 src_pci_func, s_esw_id, d_esw_id;
3788 for (i = 0; i < count; i++) {
3789 src_pci_func = pm_cfg[i].pci_func;
3790 dest_pci_func = pm_cfg[i].dest_npar;
3791 if (src_pci_func >= QLCNIC_MAX_PCI_FUNC
3792 || dest_pci_func >= QLCNIC_MAX_PCI_FUNC)
3793 return QL_STATUS_INVALID_PARAM;
3795 if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC)
3796 return QL_STATUS_INVALID_PARAM;
3798 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3799 return QL_STATUS_INVALID_PARAM;
3801 s_esw_id = adapter->npars[src_pci_func].phy_port;
3802 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3804 if (s_esw_id != d_esw_id)
3805 return QL_STATUS_INVALID_PARAM;
3813 qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3814 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3816 struct device *dev = container_of(kobj, struct device, kobj);
3817 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3818 struct qlcnic_pm_func_cfg *pm_cfg;
3819 u32 id, action, pci_func;
3820 int count, rem, i, ret;
3822 count = size / sizeof(struct qlcnic_pm_func_cfg);
3823 rem = size % sizeof(struct qlcnic_pm_func_cfg);
3825 return QL_STATUS_INVALID_PARAM;
3827 pm_cfg = (struct qlcnic_pm_func_cfg *) buf;
3829 ret = validate_pm_config(adapter, pm_cfg, count);
3832 for (i = 0; i < count; i++) {
3833 pci_func = pm_cfg[i].pci_func;
3834 action = !!pm_cfg[i].action;
3835 id = adapter->npars[pci_func].phy_port;
3836 ret = qlcnic_config_port_mirroring(adapter, id,
3842 for (i = 0; i < count; i++) {
3843 pci_func = pm_cfg[i].pci_func;
3844 id = adapter->npars[pci_func].phy_port;
3845 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
3846 adapter->npars[pci_func].dest_npar = id;
3852 qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3853 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3855 struct device *dev = container_of(kobj, struct device, kobj);
3856 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3857 struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC];
3860 if (size != sizeof(pm_cfg))
3861 return QL_STATUS_INVALID_PARAM;
3863 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3864 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3866 pm_cfg[i].action = adapter->npars[i].enable_pm;
3867 pm_cfg[i].dest_npar = 0;
3868 pm_cfg[i].pci_func = i;
3870 memcpy(buf, &pm_cfg, size);
3876 validate_esw_config(struct qlcnic_adapter *adapter,
3877 struct qlcnic_esw_func_cfg *esw_cfg, int count)
3883 op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE);
3885 for (i = 0; i < count; i++) {
3886 pci_func = esw_cfg[i].pci_func;
3887 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3888 return QL_STATUS_INVALID_PARAM;
3890 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3891 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3892 return QL_STATUS_INVALID_PARAM;
3894 switch (esw_cfg[i].op_mode) {
3895 case QLCNIC_PORT_DEFAULTS:
3896 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
3897 QLCNIC_NON_PRIV_FUNC) {
3898 if (esw_cfg[i].mac_anti_spoof != 0)
3899 return QL_STATUS_INVALID_PARAM;
3900 if (esw_cfg[i].mac_override != 1)
3901 return QL_STATUS_INVALID_PARAM;
3902 if (esw_cfg[i].promisc_mode != 1)
3903 return QL_STATUS_INVALID_PARAM;
3906 case QLCNIC_ADD_VLAN:
3907 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3908 return QL_STATUS_INVALID_PARAM;
3909 if (!esw_cfg[i].op_type)
3910 return QL_STATUS_INVALID_PARAM;
3912 case QLCNIC_DEL_VLAN:
3913 if (!esw_cfg[i].op_type)
3914 return QL_STATUS_INVALID_PARAM;
3917 return QL_STATUS_INVALID_PARAM;
3924 qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3925 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3927 struct device *dev = container_of(kobj, struct device, kobj);
3928 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3929 struct qlcnic_esw_func_cfg *esw_cfg;
3930 struct qlcnic_npar_info *npar;
3931 int count, rem, i, ret;
3932 u8 pci_func, op_mode = 0;
3934 count = size / sizeof(struct qlcnic_esw_func_cfg);
3935 rem = size % sizeof(struct qlcnic_esw_func_cfg);
3937 return QL_STATUS_INVALID_PARAM;
3939 esw_cfg = (struct qlcnic_esw_func_cfg *) buf;
3940 ret = validate_esw_config(adapter, esw_cfg, count);
3944 for (i = 0; i < count; i++) {
3945 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3946 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3947 return QL_STATUS_INVALID_PARAM;
3949 if (adapter->ahw->pci_func != esw_cfg[i].pci_func)
3952 op_mode = esw_cfg[i].op_mode;
3953 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3954 esw_cfg[i].op_mode = op_mode;
3955 esw_cfg[i].pci_func = adapter->ahw->pci_func;
3957 switch (esw_cfg[i].op_mode) {
3958 case QLCNIC_PORT_DEFAULTS:
3959 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3961 case QLCNIC_ADD_VLAN:
3962 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3964 case QLCNIC_DEL_VLAN:
3965 esw_cfg[i].vlan_id = 0;
3966 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3971 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3974 for (i = 0; i < count; i++) {
3975 pci_func = esw_cfg[i].pci_func;
3976 npar = &adapter->npars[pci_func];
3977 switch (esw_cfg[i].op_mode) {
3978 case QLCNIC_PORT_DEFAULTS:
3979 npar->promisc_mode = esw_cfg[i].promisc_mode;
3980 npar->mac_override = esw_cfg[i].mac_override;
3981 npar->offload_flags = esw_cfg[i].offload_flags;
3982 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3983 npar->discard_tagged = esw_cfg[i].discard_tagged;
3985 case QLCNIC_ADD_VLAN:
3986 npar->pvid = esw_cfg[i].vlan_id;
3988 case QLCNIC_DEL_VLAN:
3998 qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3999 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4001 struct device *dev = container_of(kobj, struct device, kobj);
4002 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4003 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
4006 if (size != sizeof(esw_cfg))
4007 return QL_STATUS_INVALID_PARAM;
4009 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
4010 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
4012 esw_cfg[i].pci_func = i;
4013 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
4014 return QL_STATUS_INVALID_PARAM;
4016 memcpy(buf, &esw_cfg, size);
4022 validate_npar_config(struct qlcnic_adapter *adapter,
4023 struct qlcnic_npar_func_cfg *np_cfg, int count)
4027 for (i = 0; i < count; i++) {
4028 pci_func = np_cfg[i].pci_func;
4029 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
4030 return QL_STATUS_INVALID_PARAM;
4032 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
4033 return QL_STATUS_INVALID_PARAM;
4035 if (!IS_VALID_BW(np_cfg[i].min_bw) ||
4036 !IS_VALID_BW(np_cfg[i].max_bw))
4037 return QL_STATUS_INVALID_PARAM;
4043 qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj,
4044 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4046 struct device *dev = container_of(kobj, struct device, kobj);
4047 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4048 struct qlcnic_info nic_info;
4049 struct qlcnic_npar_func_cfg *np_cfg;
4050 int i, count, rem, ret;
4053 count = size / sizeof(struct qlcnic_npar_func_cfg);
4054 rem = size % sizeof(struct qlcnic_npar_func_cfg);
4056 return QL_STATUS_INVALID_PARAM;
4058 np_cfg = (struct qlcnic_npar_func_cfg *) buf;
4059 ret = validate_npar_config(adapter, np_cfg, count);
4063 for (i = 0; i < count ; i++) {
4064 pci_func = np_cfg[i].pci_func;
4065 ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
4068 nic_info.pci_func = pci_func;
4069 nic_info.min_tx_bw = np_cfg[i].min_bw;
4070 nic_info.max_tx_bw = np_cfg[i].max_bw;
4071 ret = qlcnic_set_nic_info(adapter, &nic_info);
4074 adapter->npars[i].min_bw = nic_info.min_tx_bw;
4075 adapter->npars[i].max_bw = nic_info.max_tx_bw;
4082 qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
4083 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4085 struct device *dev = container_of(kobj, struct device, kobj);
4086 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4087 struct qlcnic_info nic_info;
4088 struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
4091 if (size != sizeof(np_cfg))
4092 return QL_STATUS_INVALID_PARAM;
4094 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
4095 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
4097 ret = qlcnic_get_nic_info(adapter, &nic_info, i);
4101 np_cfg[i].pci_func = i;
4102 np_cfg[i].op_mode = (u8)nic_info.op_mode;
4103 np_cfg[i].port_num = nic_info.phys_port;
4104 np_cfg[i].fw_capab = nic_info.capabilities;
4105 np_cfg[i].min_bw = nic_info.min_tx_bw ;
4106 np_cfg[i].max_bw = nic_info.max_tx_bw;
4107 np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
4108 np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
4110 memcpy(buf, &np_cfg, size);
4115 qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
4116 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4118 struct device *dev = container_of(kobj, struct device, kobj);
4119 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4120 struct qlcnic_esw_statistics port_stats;
4123 if (size != sizeof(struct qlcnic_esw_statistics))
4124 return QL_STATUS_INVALID_PARAM;
4126 if (offset >= QLCNIC_MAX_PCI_FUNC)
4127 return QL_STATUS_INVALID_PARAM;
4129 memset(&port_stats, 0, size);
4130 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
4135 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
4140 memcpy(buf, &port_stats, size);
4145 qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
4146 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4148 struct device *dev = container_of(kobj, struct device, kobj);
4149 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4150 struct qlcnic_esw_statistics esw_stats;
4153 if (size != sizeof(struct qlcnic_esw_statistics))
4154 return QL_STATUS_INVALID_PARAM;
4156 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
4157 return QL_STATUS_INVALID_PARAM;
4159 memset(&esw_stats, 0, size);
4160 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
4165 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
4170 memcpy(buf, &esw_stats, size);
4175 qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
4176 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4178 struct device *dev = container_of(kobj, struct device, kobj);
4179 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4182 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
4183 return QL_STATUS_INVALID_PARAM;
4185 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
4186 QLCNIC_QUERY_RX_COUNTER);
4190 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
4191 QLCNIC_QUERY_TX_COUNTER);
4199 qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
4200 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4203 struct device *dev = container_of(kobj, struct device, kobj);
4204 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4207 if (offset >= QLCNIC_MAX_PCI_FUNC)
4208 return QL_STATUS_INVALID_PARAM;
4210 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
4211 QLCNIC_QUERY_RX_COUNTER);
4215 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
4216 QLCNIC_QUERY_TX_COUNTER);
4224 qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
4225 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
4227 struct device *dev = container_of(kobj, struct device, kobj);
4228 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
4229 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
4230 struct qlcnic_pci_info *pci_info;
4233 if (size != sizeof(pci_cfg))
4234 return QL_STATUS_INVALID_PARAM;
4236 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
4240 ret = qlcnic_get_pci_info(adapter, pci_info);
4246 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
4247 pci_cfg[i].pci_func = pci_info[i].id;
4248 pci_cfg[i].func_type = pci_info[i].type;
4249 pci_cfg[i].port_num = pci_info[i].default_port;
4250 pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
4251 pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
4252 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
4254 memcpy(buf, &pci_cfg, size);
4258 static struct bin_attribute bin_attr_npar_config = {
4259 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
4261 .read = qlcnic_sysfs_read_npar_config,
4262 .write = qlcnic_sysfs_write_npar_config,
4265 static struct bin_attribute bin_attr_pci_config = {
4266 .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
4268 .read = qlcnic_sysfs_read_pci_config,
4272 static struct bin_attribute bin_attr_port_stats = {
4273 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
4275 .read = qlcnic_sysfs_get_port_stats,
4276 .write = qlcnic_sysfs_clear_port_stats,
4279 static struct bin_attribute bin_attr_esw_stats = {
4280 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
4282 .read = qlcnic_sysfs_get_esw_stats,
4283 .write = qlcnic_sysfs_clear_esw_stats,
4286 static struct bin_attribute bin_attr_esw_config = {
4287 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
4289 .read = qlcnic_sysfs_read_esw_config,
4290 .write = qlcnic_sysfs_write_esw_config,
4293 static struct bin_attribute bin_attr_pm_config = {
4294 .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
4296 .read = qlcnic_sysfs_read_pm_config,
4297 .write = qlcnic_sysfs_write_pm_config,
4301 qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
4303 struct device *dev = &adapter->pdev->dev;
4305 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
4306 if (device_create_file(dev, &dev_attr_bridged_mode))
4308 "failed to create bridged_mode sysfs entry\n");
4312 qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
4314 struct device *dev = &adapter->pdev->dev;
4316 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
4317 device_remove_file(dev, &dev_attr_bridged_mode);
4321 qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
4323 struct device *dev = &adapter->pdev->dev;
4324 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
4326 if (device_create_bin_file(dev, &bin_attr_port_stats))
4327 dev_info(dev, "failed to create port stats sysfs entry");
4329 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4331 if (device_create_file(dev, &dev_attr_diag_mode))
4332 dev_info(dev, "failed to create diag_mode sysfs entry\n");
4333 if (device_create_bin_file(dev, &bin_attr_crb))
4334 dev_info(dev, "failed to create crb sysfs entry\n");
4335 if (device_create_bin_file(dev, &bin_attr_mem))
4336 dev_info(dev, "failed to create mem sysfs entry\n");
4338 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD))
4341 if (device_create_bin_file(dev, &bin_attr_pci_config))
4342 dev_info(dev, "failed to create pci config sysfs entry");
4343 if (device_create_file(dev, &dev_attr_beacon))
4344 dev_info(dev, "failed to create beacon sysfs entry");
4346 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4348 if (device_create_bin_file(dev, &bin_attr_esw_config))
4349 dev_info(dev, "failed to create esw config sysfs entry");
4350 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
4352 if (device_create_bin_file(dev, &bin_attr_npar_config))
4353 dev_info(dev, "failed to create npar config sysfs entry");
4354 if (device_create_bin_file(dev, &bin_attr_pm_config))
4355 dev_info(dev, "failed to create pm config sysfs entry");
4356 if (device_create_bin_file(dev, &bin_attr_esw_stats))
4357 dev_info(dev, "failed to create eswitch stats sysfs entry");
4361 qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
4363 struct device *dev = &adapter->pdev->dev;
4364 u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
4366 device_remove_bin_file(dev, &bin_attr_port_stats);
4368 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4370 device_remove_file(dev, &dev_attr_diag_mode);
4371 device_remove_bin_file(dev, &bin_attr_crb);
4372 device_remove_bin_file(dev, &bin_attr_mem);
4373 if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD))
4375 device_remove_bin_file(dev, &bin_attr_pci_config);
4376 device_remove_file(dev, &dev_attr_beacon);
4377 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4379 device_remove_bin_file(dev, &bin_attr_esw_config);
4380 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
4382 device_remove_bin_file(dev, &bin_attr_npar_config);
4383 device_remove_bin_file(dev, &bin_attr_pm_config);
4384 device_remove_bin_file(dev, &bin_attr_esw_stats);
4389 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4392 qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4393 struct net_device *dev, unsigned long event)
4395 struct in_device *indev;
4397 indev = in_dev_get(dev);
4404 qlcnic_config_ipaddr(adapter,
4405 ifa->ifa_address, QLCNIC_IP_UP);
4408 qlcnic_config_ipaddr(adapter,
4409 ifa->ifa_address, QLCNIC_IP_DOWN);
4414 } endfor_ifa(indev);
4420 qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
4422 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4423 struct net_device *dev;
4426 qlcnic_config_indev_addr(adapter, netdev, event);
4428 for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) {
4429 dev = __vlan_find_dev_deep(netdev, vid);
4432 qlcnic_config_indev_addr(adapter, dev, event);
4436 static int qlcnic_netdev_event(struct notifier_block *this,
4437 unsigned long event, void *ptr)
4439 struct qlcnic_adapter *adapter;
4440 struct net_device *dev = (struct net_device *)ptr;
4446 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4447 dev = vlan_dev_real_dev(dev);
4451 if (!is_qlcnic_netdev(dev))
4454 adapter = netdev_priv(dev);
4459 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4462 qlcnic_config_indev_addr(adapter, dev, event);
4468 qlcnic_inetaddr_event(struct notifier_block *this,
4469 unsigned long event, void *ptr)
4471 struct qlcnic_adapter *adapter;
4472 struct net_device *dev;
4474 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4476 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4482 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4483 dev = vlan_dev_real_dev(dev);
4487 if (!is_qlcnic_netdev(dev))
4490 adapter = netdev_priv(dev);
4495 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4500 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
4503 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
4513 static struct notifier_block qlcnic_netdev_cb = {
4514 .notifier_call = qlcnic_netdev_event,
4517 static struct notifier_block qlcnic_inetaddr_cb = {
4518 .notifier_call = qlcnic_inetaddr_event,
4522 qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
4525 static struct pci_error_handlers qlcnic_err_handler = {
4526 .error_detected = qlcnic_io_error_detected,
4527 .slot_reset = qlcnic_io_slot_reset,
4528 .resume = qlcnic_io_resume,
4531 static struct pci_driver qlcnic_driver = {
4532 .name = qlcnic_driver_name,
4533 .id_table = qlcnic_pci_tbl,
4534 .probe = qlcnic_probe,
4535 .remove = __devexit_p(qlcnic_remove),
4537 .suspend = qlcnic_suspend,
4538 .resume = qlcnic_resume,
4540 .shutdown = qlcnic_shutdown,
4541 .err_handler = &qlcnic_err_handler
4545 static int __init qlcnic_init_module(void)
4549 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4551 qlcnic_wq = create_singlethread_workqueue("qlcnic");
4552 if (qlcnic_wq == NULL) {
4553 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
4558 register_netdevice_notifier(&qlcnic_netdev_cb);
4559 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4562 ret = pci_register_driver(&qlcnic_driver);
4565 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4566 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4568 destroy_workqueue(qlcnic_wq);
4574 module_init(qlcnic_init_module);
4576 static void __exit qlcnic_exit_module(void)
4579 pci_unregister_driver(&qlcnic_driver);
4582 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4583 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4585 destroy_workqueue(qlcnic_wq);
4588 module_exit(qlcnic_exit_module);