2 * Copyright (C) 2009 - QLogic Corporation.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/slab.h>
26 #include <linux/vmalloc.h>
27 #include <linux/interrupt.h>
31 #include <linux/swab.h>
32 #include <linux/dma-mapping.h>
33 #include <linux/if_vlan.h>
35 #include <linux/ipv6.h>
36 #include <linux/inetdevice.h>
37 #include <linux/sysfs.h>
38 #include <linux/aer.h>
40 MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver");
41 MODULE_LICENSE("GPL");
42 MODULE_VERSION(QLCNIC_LINUX_VERSIONID);
43 MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME);
45 char qlcnic_driver_name[] = "qlcnic";
46 static const char qlcnic_driver_string[] = "QLogic 1/10 GbE "
47 "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID;
49 static struct workqueue_struct *qlcnic_wq;
50 static int qlcnic_mac_learn;
51 module_param(qlcnic_mac_learn, int, 0644);
52 MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
54 static int use_msi = 1;
55 module_param(use_msi, int, 0644);
56 MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
58 static int use_msi_x = 1;
59 module_param(use_msi_x, int, 0644);
60 MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled");
62 static int auto_fw_reset = AUTO_FW_RESET_ENABLED;
63 module_param(auto_fw_reset, int, 0644);
64 MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled");
66 static int load_fw_file;
67 module_param(load_fw_file, int, 0644);
68 MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file");
70 static int qlcnic_config_npars;
71 module_param(qlcnic_config_npars, int, 0644);
72 MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled");
74 static int __devinit qlcnic_probe(struct pci_dev *pdev,
75 const struct pci_device_id *ent);
76 static void __devexit qlcnic_remove(struct pci_dev *pdev);
77 static int qlcnic_open(struct net_device *netdev);
78 static int qlcnic_close(struct net_device *netdev);
79 static void qlcnic_tx_timeout(struct net_device *netdev);
80 static void qlcnic_attach_work(struct work_struct *work);
81 static void qlcnic_fwinit_work(struct work_struct *work);
82 static void qlcnic_fw_poll_work(struct work_struct *work);
83 static void qlcnic_schedule_work(struct qlcnic_adapter *adapter,
84 work_func_t func, int delay);
85 static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter);
86 static int qlcnic_poll(struct napi_struct *napi, int budget);
87 static int qlcnic_rx_poll(struct napi_struct *napi, int budget);
88 #ifdef CONFIG_NET_POLL_CONTROLLER
89 static void qlcnic_poll_controller(struct net_device *netdev);
92 static void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter);
93 static void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter);
94 static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter);
95 static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter);
97 static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
98 static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
99 static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
101 static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
102 static irqreturn_t qlcnic_intr(int irq, void *data);
103 static irqreturn_t qlcnic_msi_intr(int irq, void *data);
104 static irqreturn_t qlcnic_msix_intr(int irq, void *data);
106 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
107 static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long);
108 static int qlcnic_start_firmware(struct qlcnic_adapter *);
110 static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter);
111 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
112 static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
113 static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
114 static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
115 static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
116 static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
117 struct qlcnic_esw_func_cfg *);
118 /* PCI Device ID Table */
119 #define ENTRY(device) \
120 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
121 .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0}
123 #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020
125 static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
126 ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X),
130 MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
134 qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
135 struct qlcnic_host_tx_ring *tx_ring)
137 writel(tx_ring->producer, tx_ring->crb_cmd_producer);
140 static const u32 msi_tgt_status[8] = {
141 ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1,
142 ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3,
143 ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5,
144 ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7
148 struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG;
150 static inline void qlcnic_disable_int(struct qlcnic_host_sds_ring *sds_ring)
152 writel(0, sds_ring->crb_intr_mask);
155 static inline void qlcnic_enable_int(struct qlcnic_host_sds_ring *sds_ring)
157 struct qlcnic_adapter *adapter = sds_ring->adapter;
159 writel(0x1, sds_ring->crb_intr_mask);
161 if (!QLCNIC_IS_MSI_FAMILY(adapter))
162 writel(0xfbff, adapter->tgt_mask_reg);
166 qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
168 int size = sizeof(struct qlcnic_host_sds_ring) * count;
170 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
172 return recv_ctx->sds_rings == NULL;
176 qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
178 if (recv_ctx->sds_rings != NULL)
179 kfree(recv_ctx->sds_rings);
181 recv_ctx->sds_rings = NULL;
185 qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev)
188 struct qlcnic_host_sds_ring *sds_ring;
189 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
191 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
194 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
195 sds_ring = &recv_ctx->sds_rings[ring];
197 if (ring == adapter->max_sds_rings - 1)
198 netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll,
199 QLCNIC_NETDEV_WEIGHT/adapter->max_sds_rings);
201 netif_napi_add(netdev, &sds_ring->napi,
202 qlcnic_rx_poll, QLCNIC_NETDEV_WEIGHT*2);
209 qlcnic_napi_del(struct qlcnic_adapter *adapter)
212 struct qlcnic_host_sds_ring *sds_ring;
213 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
215 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
216 sds_ring = &recv_ctx->sds_rings[ring];
217 netif_napi_del(&sds_ring->napi);
220 qlcnic_free_sds_rings(&adapter->recv_ctx);
224 qlcnic_napi_enable(struct qlcnic_adapter *adapter)
227 struct qlcnic_host_sds_ring *sds_ring;
228 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
230 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
233 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
234 sds_ring = &recv_ctx->sds_rings[ring];
235 napi_enable(&sds_ring->napi);
236 qlcnic_enable_int(sds_ring);
241 qlcnic_napi_disable(struct qlcnic_adapter *adapter)
244 struct qlcnic_host_sds_ring *sds_ring;
245 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
247 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
250 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
251 sds_ring = &recv_ctx->sds_rings[ring];
252 qlcnic_disable_int(sds_ring);
253 napi_synchronize(&sds_ring->napi);
254 napi_disable(&sds_ring->napi);
258 static void qlcnic_clear_stats(struct qlcnic_adapter *adapter)
260 memset(&adapter->stats, 0, sizeof(adapter->stats));
263 static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable)
268 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
270 pci_read_config_dword(pdev, pos, &control);
272 control |= PCI_MSIX_FLAGS_ENABLE;
275 pci_write_config_dword(pdev, pos, control);
279 static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count)
283 for (i = 0; i < count; i++)
284 adapter->msix_entries[i].entry = i;
288 qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
290 u8 mac_addr[ETH_ALEN];
291 struct net_device *netdev = adapter->netdev;
292 struct pci_dev *pdev = adapter->pdev;
294 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
297 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
298 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
299 memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len);
301 /* set station address */
303 if (!is_valid_ether_addr(netdev->perm_addr))
304 dev_warn(&pdev->dev, "Bad MAC address %pM.\n",
310 static int qlcnic_set_mac(struct net_device *netdev, void *p)
312 struct qlcnic_adapter *adapter = netdev_priv(netdev);
313 struct sockaddr *addr = p;
315 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
318 if (!is_valid_ether_addr(addr->sa_data))
321 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
322 netif_device_detach(netdev);
323 qlcnic_napi_disable(adapter);
326 memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len);
327 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
328 qlcnic_set_multi(adapter->netdev);
330 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
331 netif_device_attach(netdev);
332 qlcnic_napi_enable(adapter);
337 static void qlcnic_vlan_rx_register(struct net_device *netdev,
338 struct vlan_group *grp)
340 struct qlcnic_adapter *adapter = netdev_priv(netdev);
341 adapter->vlgrp = grp;
344 static const struct net_device_ops qlcnic_netdev_ops = {
345 .ndo_open = qlcnic_open,
346 .ndo_stop = qlcnic_close,
347 .ndo_start_xmit = qlcnic_xmit_frame,
348 .ndo_get_stats = qlcnic_get_stats,
349 .ndo_validate_addr = eth_validate_addr,
350 .ndo_set_multicast_list = qlcnic_set_multi,
351 .ndo_set_mac_address = qlcnic_set_mac,
352 .ndo_change_mtu = qlcnic_change_mtu,
353 .ndo_tx_timeout = qlcnic_tx_timeout,
354 .ndo_vlan_rx_register = qlcnic_vlan_rx_register,
355 #ifdef CONFIG_NET_POLL_CONTROLLER
356 .ndo_poll_controller = qlcnic_poll_controller,
360 static struct qlcnic_nic_template qlcnic_ops = {
361 .config_bridged_mode = qlcnic_config_bridged_mode,
362 .config_led = qlcnic_config_led,
363 .start_firmware = qlcnic_start_firmware
366 static struct qlcnic_nic_template qlcnic_vf_ops = {
367 .config_bridged_mode = qlcnicvf_config_bridged_mode,
368 .config_led = qlcnicvf_config_led,
369 .start_firmware = qlcnicvf_start_firmware
373 qlcnic_setup_intr(struct qlcnic_adapter *adapter)
375 const struct qlcnic_legacy_intr_set *legacy_intrp;
376 struct pci_dev *pdev = adapter->pdev;
379 if (adapter->rss_supported) {
380 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
381 MSIX_ENTRIES_PER_ADAPTER : 2;
385 adapter->max_sds_rings = 1;
387 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
389 legacy_intrp = &legacy_intr[adapter->ahw.pci_func];
391 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
392 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
393 legacy_intrp->tgt_status_reg);
394 adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter,
395 legacy_intrp->tgt_mask_reg);
396 adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR);
398 adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter,
401 qlcnic_set_msix_bit(pdev, 0);
403 if (adapter->msix_supported) {
405 qlcnic_init_msix_entries(adapter, num_msix);
406 err = pci_enable_msix(pdev, adapter->msix_entries, num_msix);
408 adapter->flags |= QLCNIC_MSIX_ENABLED;
409 qlcnic_set_msix_bit(pdev, 1);
411 if (adapter->rss_supported)
412 adapter->max_sds_rings = num_msix;
414 dev_info(&pdev->dev, "using msi-x interrupts\n");
419 pci_disable_msix(pdev);
421 /* fall through for msi */
424 if (use_msi && !pci_enable_msi(pdev)) {
425 adapter->flags |= QLCNIC_MSI_ENABLED;
426 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
427 msi_tgt_status[adapter->ahw.pci_func]);
428 dev_info(&pdev->dev, "using msi interrupts\n");
429 adapter->msix_entries[0].vector = pdev->irq;
433 dev_info(&pdev->dev, "using legacy interrupts\n");
434 adapter->msix_entries[0].vector = pdev->irq;
438 qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
440 if (adapter->flags & QLCNIC_MSIX_ENABLED)
441 pci_disable_msix(adapter->pdev);
442 if (adapter->flags & QLCNIC_MSI_ENABLED)
443 pci_disable_msi(adapter->pdev);
447 qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
449 if (adapter->ahw.pci_base0 != NULL)
450 iounmap(adapter->ahw.pci_base0);
454 qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
456 struct qlcnic_pci_info *pci_info;
460 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
464 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
465 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
466 if (!adapter->npars) {
471 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
472 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
473 if (!adapter->eswitch) {
478 ret = qlcnic_get_pci_info(adapter, pci_info);
482 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
483 pfn = pci_info[i].id;
484 if (pfn > QLCNIC_MAX_PCI_FUNC)
485 return QL_STATUS_INVALID_PARAM;
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 + QLCNIC_FW_API);
559 /* Find PCI function number */
560 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
561 msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE;
562 msix_base = readl(msix_base_addr);
563 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
564 adapter->ahw.pci_func = func;
566 /* Determine function privilege level */
567 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
568 op_mode = readl(priv_op);
569 if (op_mode == QLC_DEV_DRV_DEFAULT)
570 priv_level = QLCNIC_MGMT_FUNC;
572 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
574 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
575 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
576 dev_info(&adapter->pdev->dev,
577 "HAL Version: %d Non Privileged function\n",
578 adapter->fw_hal_version);
579 adapter->nic_ops = &qlcnic_vf_ops;
581 adapter->nic_ops = &qlcnic_ops;
585 qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
587 void __iomem *mem_ptr0 = NULL;
588 resource_size_t mem_base;
589 unsigned long mem_len, pci_len0 = 0;
591 struct pci_dev *pdev = adapter->pdev;
593 /* remap phys address */
594 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
595 mem_len = pci_resource_len(pdev, 0);
597 if (mem_len == QLCNIC_PCI_2MB_SIZE) {
599 mem_ptr0 = pci_ioremap_bar(pdev, 0);
600 if (mem_ptr0 == NULL) {
601 dev_err(&pdev->dev, "failed to map PCI bar 0\n");
609 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
611 adapter->ahw.pci_base0 = mem_ptr0;
612 adapter->ahw.pci_len0 = pci_len0;
614 qlcnic_check_vf(adapter);
616 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter,
617 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func)));
622 static void get_brd_name(struct qlcnic_adapter *adapter, char *name)
624 struct pci_dev *pdev = adapter->pdev;
627 for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) {
628 if (qlcnic_boards[i].vendor == pdev->vendor &&
629 qlcnic_boards[i].device == pdev->device &&
630 qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor &&
631 qlcnic_boards[i].sub_device == pdev->subsystem_device) {
632 sprintf(name, "%pM: %s" ,
634 qlcnic_boards[i].short_name);
642 sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr);
646 qlcnic_check_options(struct qlcnic_adapter *adapter)
648 u32 fw_major, fw_minor, fw_build;
649 struct pci_dev *pdev = adapter->pdev;
651 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
652 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
653 fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
655 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
657 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
658 fw_major, fw_minor, fw_build);
659 if (adapter->ahw.port_type == QLCNIC_XGBE) {
660 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
661 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
662 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
664 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G;
665 adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G;
668 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
669 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
671 } else if (adapter->ahw.port_type == QLCNIC_GBE) {
672 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
673 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
674 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
675 adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G;
678 adapter->msix_supported = !!use_msi_x;
679 adapter->rss_supported = !!use_msi_x;
681 adapter->num_txd = MAX_CMD_DESCRIPTORS;
683 adapter->max_rds_rings = MAX_RDS_RINGS;
687 qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
690 struct qlcnic_info nic_info;
692 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func);
696 adapter->physical_port = (u8)nic_info.phys_port;
697 adapter->switch_mode = nic_info.switch_mode;
698 adapter->max_tx_ques = nic_info.max_tx_ques;
699 adapter->max_rx_ques = nic_info.max_rx_ques;
700 adapter->capabilities = nic_info.capabilities;
701 adapter->max_mac_filters = nic_info.max_mac_filters;
702 adapter->max_mtu = nic_info.max_mtu;
704 if (adapter->capabilities & BIT_6)
705 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
707 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
713 qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
714 struct qlcnic_esw_func_cfg *esw_cfg)
716 if (esw_cfg->discard_tagged)
717 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
719 adapter->flags |= QLCNIC_TAGGING_ENABLED;
721 if (esw_cfg->vlan_id)
722 adapter->pvid = esw_cfg->vlan_id;
728 qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
729 struct qlcnic_esw_func_cfg *esw_cfg)
731 adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED |
732 QLCNIC_PROMISC_DISABLED);
734 if (esw_cfg->mac_anti_spoof)
735 adapter->flags |= QLCNIC_MACSPOOF;
737 if (!esw_cfg->mac_override)
738 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
740 if (!esw_cfg->promisc_mode)
741 adapter->flags |= QLCNIC_PROMISC_DISABLED;
743 qlcnic_set_netdev_features(adapter, esw_cfg);
747 qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
749 struct qlcnic_esw_func_cfg esw_cfg;
751 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
754 esw_cfg.pci_func = adapter->ahw.pci_func;
755 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
757 qlcnic_set_vlan_config(adapter, &esw_cfg);
758 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
764 qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
765 struct qlcnic_esw_func_cfg *esw_cfg)
767 struct net_device *netdev = adapter->netdev;
768 unsigned long features, vlan_features;
770 features = (NETIF_F_SG | NETIF_F_IP_CSUM |
771 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
772 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
775 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
776 features |= (NETIF_F_TSO | NETIF_F_TSO6);
777 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
779 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
780 features |= NETIF_F_LRO;
782 if (esw_cfg->offload_flags & BIT_0) {
783 netdev->features |= features;
784 adapter->rx_csum = 1;
785 if (!(esw_cfg->offload_flags & BIT_1))
786 netdev->features &= ~NETIF_F_TSO;
787 if (!(esw_cfg->offload_flags & BIT_2))
788 netdev->features &= ~NETIF_F_TSO6;
790 netdev->features &= ~features;
791 adapter->rx_csum = 0;
794 netdev->vlan_features = (features & vlan_features);
798 qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
800 void __iomem *priv_op;
801 u32 op_mode, priv_level;
804 err = qlcnic_initialize_nic(adapter);
808 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
811 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
812 op_mode = readl(priv_op);
813 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
815 if (op_mode == QLC_DEV_DRV_DEFAULT)
816 priv_level = QLCNIC_MGMT_FUNC;
818 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
820 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
821 if (priv_level == QLCNIC_MGMT_FUNC) {
822 adapter->op_mode = QLCNIC_MGMT_FUNC;
823 err = qlcnic_init_pci_info(adapter);
826 /* Set privilege level for other functions */
827 qlcnic_set_function_modes(adapter);
828 dev_info(&adapter->pdev->dev,
829 "HAL Version: %d, Management function\n",
830 adapter->fw_hal_version);
831 } else if (priv_level == QLCNIC_PRIV_FUNC) {
832 adapter->op_mode = QLCNIC_PRIV_FUNC;
833 dev_info(&adapter->pdev->dev,
834 "HAL Version: %d, Privileged function\n",
835 adapter->fw_hal_version);
839 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
845 qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
847 struct qlcnic_esw_func_cfg esw_cfg;
848 struct qlcnic_npar_info *npar;
851 if (adapter->need_fw_reset)
854 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
855 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
857 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
858 esw_cfg.pci_func = i;
859 esw_cfg.offload_flags = BIT_0;
860 esw_cfg.mac_override = BIT_0;
861 esw_cfg.promisc_mode = BIT_0;
862 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
863 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
864 if (qlcnic_config_switch_port(adapter, &esw_cfg))
866 npar = &adapter->npars[i];
867 npar->pvid = esw_cfg.vlan_id;
868 npar->mac_override = esw_cfg.mac_override;
869 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
870 npar->discard_tagged = esw_cfg.discard_tagged;
871 npar->promisc_mode = esw_cfg.promisc_mode;
872 npar->offload_flags = esw_cfg.offload_flags;
879 qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
880 struct qlcnic_npar_info *npar, int pci_func)
882 struct qlcnic_esw_func_cfg esw_cfg;
883 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
884 esw_cfg.pci_func = pci_func;
885 esw_cfg.vlan_id = npar->pvid;
886 esw_cfg.mac_override = npar->mac_override;
887 esw_cfg.discard_tagged = npar->discard_tagged;
888 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
889 esw_cfg.offload_flags = npar->offload_flags;
890 esw_cfg.promisc_mode = npar->promisc_mode;
891 if (qlcnic_config_switch_port(adapter, &esw_cfg))
894 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
895 if (qlcnic_config_switch_port(adapter, &esw_cfg))
902 qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
905 struct qlcnic_npar_info *npar;
906 struct qlcnic_info nic_info;
908 if (!adapter->need_fw_reset)
911 /* Set the NPAR config data after FW reset */
912 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
913 npar = &adapter->npars[i];
914 if (npar->type != QLCNIC_TYPE_NIC)
916 err = qlcnic_get_nic_info(adapter, &nic_info, i);
919 nic_info.min_tx_bw = npar->min_bw;
920 nic_info.max_tx_bw = npar->max_bw;
921 err = qlcnic_set_nic_info(adapter, &nic_info);
925 if (npar->enable_pm) {
926 err = qlcnic_config_port_mirroring(adapter,
927 npar->dest_npar, 1, i);
931 err = qlcnic_reset_eswitch_config(adapter, npar, i);
938 static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
940 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
943 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
946 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
947 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
949 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
951 if (!npar_opt_timeo) {
952 dev_err(&adapter->pdev->dev,
953 "Waiting for NPAR state to opertional timeout\n");
960 qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
964 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
965 adapter->op_mode != QLCNIC_MGMT_FUNC)
968 err = qlcnic_set_default_offload_settings(adapter);
972 err = qlcnic_reset_npar_config(adapter);
976 qlcnic_dev_set_npar_ready(adapter);
982 qlcnic_start_firmware(struct qlcnic_adapter *adapter)
986 err = qlcnic_can_start_firmware(adapter);
990 goto check_fw_status;
993 qlcnic_request_firmware(adapter);
995 err = qlcnic_check_flash_fw_ver(adapter);
999 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
1002 err = qlcnic_need_fw_reset(adapter);
1004 goto check_fw_status;
1006 err = qlcnic_pinit_from_rom(adapter);
1010 err = qlcnic_load_firmware(adapter);
1014 qlcnic_release_firmware(adapter);
1015 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
1018 err = qlcnic_check_fw_status(adapter);
1022 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
1023 qlcnic_idc_debug_info(adapter, 1);
1025 err = qlcnic_check_eswitch_mode(adapter);
1027 dev_err(&adapter->pdev->dev,
1028 "Memory allocation failed for eswitch\n");
1031 err = qlcnic_set_mgmt_operations(adapter);
1035 qlcnic_check_options(adapter);
1036 adapter->need_fw_reset = 0;
1038 qlcnic_release_firmware(adapter);
1042 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
1043 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
1045 qlcnic_release_firmware(adapter);
1050 qlcnic_request_irq(struct qlcnic_adapter *adapter)
1052 irq_handler_t handler;
1053 struct qlcnic_host_sds_ring *sds_ring;
1056 unsigned long flags = 0;
1057 struct net_device *netdev = adapter->netdev;
1058 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1060 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1061 handler = qlcnic_tmp_intr;
1062 if (!QLCNIC_IS_MSI_FAMILY(adapter))
1063 flags |= IRQF_SHARED;
1066 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1067 handler = qlcnic_msix_intr;
1068 else if (adapter->flags & QLCNIC_MSI_ENABLED)
1069 handler = qlcnic_msi_intr;
1071 flags |= IRQF_SHARED;
1072 handler = qlcnic_intr;
1075 adapter->irq = netdev->irq;
1077 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1078 sds_ring = &recv_ctx->sds_rings[ring];
1079 sprintf(sds_ring->name, "%s[%d]", netdev->name, ring);
1080 err = request_irq(sds_ring->irq, handler,
1081 flags, sds_ring->name, sds_ring);
1090 qlcnic_free_irq(struct qlcnic_adapter *adapter)
1093 struct qlcnic_host_sds_ring *sds_ring;
1095 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
1097 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1098 sds_ring = &recv_ctx->sds_rings[ring];
1099 free_irq(sds_ring->irq, sds_ring);
1104 qlcnic_init_coalesce_defaults(struct qlcnic_adapter *adapter)
1106 adapter->coal.flags = QLCNIC_INTR_DEFAULT;
1107 adapter->coal.normal.data.rx_time_us =
1108 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US;
1109 adapter->coal.normal.data.rx_packets =
1110 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS;
1111 adapter->coal.normal.data.tx_time_us =
1112 QLCNIC_DEFAULT_INTR_COALESCE_TX_TIME_US;
1113 adapter->coal.normal.data.tx_packets =
1114 QLCNIC_DEFAULT_INTR_COALESCE_TX_PACKETS;
1118 __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1121 struct qlcnic_host_rds_ring *rds_ring;
1123 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1126 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1128 if (qlcnic_set_eswitch_port_config(adapter))
1131 if (qlcnic_fw_create_ctx(adapter))
1134 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1135 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1136 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1139 qlcnic_set_multi(netdev);
1140 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1142 adapter->ahw.linkup = 0;
1144 if (adapter->max_sds_rings > 1)
1145 qlcnic_config_rss(adapter, 1);
1147 qlcnic_config_intr_coalesce(adapter);
1149 if (netdev->features & NETIF_F_LRO)
1150 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1152 qlcnic_napi_enable(adapter);
1154 qlcnic_linkevent_request(adapter, 1);
1156 adapter->reset_context = 0;
1157 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1161 /* Usage: During resume and firmware recovery module.*/
1164 qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1169 if (netif_running(netdev))
1170 err = __qlcnic_up(adapter, netdev);
1177 __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1179 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1182 if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state))
1186 spin_lock(&adapter->tx_clean_lock);
1187 netif_carrier_off(netdev);
1188 netif_tx_disable(netdev);
1190 qlcnic_free_mac_list(adapter);
1192 if (adapter->fhash.fnum)
1193 qlcnic_delete_lb_filters(adapter);
1195 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1197 qlcnic_napi_disable(adapter);
1199 qlcnic_fw_destroy_ctx(adapter);
1201 qlcnic_reset_rx_buffers_list(adapter);
1202 qlcnic_release_tx_buffers(adapter);
1203 spin_unlock(&adapter->tx_clean_lock);
1206 /* Usage: During suspend and firmware recovery module */
1209 qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1212 if (netif_running(netdev))
1213 __qlcnic_down(adapter, netdev);
1219 qlcnic_attach(struct qlcnic_adapter *adapter)
1221 struct net_device *netdev = adapter->netdev;
1222 struct pci_dev *pdev = adapter->pdev;
1225 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC)
1228 err = qlcnic_napi_add(adapter, netdev);
1232 err = qlcnic_alloc_sw_resources(adapter);
1234 dev_err(&pdev->dev, "Error in setting sw resources\n");
1235 goto err_out_napi_del;
1238 err = qlcnic_alloc_hw_resources(adapter);
1240 dev_err(&pdev->dev, "Error in setting hw resources\n");
1241 goto err_out_free_sw;
1244 err = qlcnic_request_irq(adapter);
1246 dev_err(&pdev->dev, "failed to setup interrupt\n");
1247 goto err_out_free_hw;
1250 qlcnic_init_coalesce_defaults(adapter);
1252 qlcnic_create_sysfs_entries(adapter);
1254 adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC;
1258 qlcnic_free_hw_resources(adapter);
1260 qlcnic_free_sw_resources(adapter);
1262 qlcnic_napi_del(adapter);
1267 qlcnic_detach(struct qlcnic_adapter *adapter)
1269 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1272 qlcnic_remove_sysfs_entries(adapter);
1274 qlcnic_free_hw_resources(adapter);
1275 qlcnic_release_rx_buffers(adapter);
1276 qlcnic_free_irq(adapter);
1277 qlcnic_napi_del(adapter);
1278 qlcnic_free_sw_resources(adapter);
1283 void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1285 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1286 struct qlcnic_host_sds_ring *sds_ring;
1289 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
1290 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1291 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1292 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1293 qlcnic_disable_int(sds_ring);
1297 qlcnic_fw_destroy_ctx(adapter);
1299 qlcnic_detach(adapter);
1301 adapter->diag_test = 0;
1302 adapter->max_sds_rings = max_sds_rings;
1304 if (qlcnic_attach(adapter))
1307 if (netif_running(netdev))
1308 __qlcnic_up(adapter, netdev);
1310 netif_device_attach(netdev);
1313 int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1315 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1316 struct qlcnic_host_sds_ring *sds_ring;
1317 struct qlcnic_host_rds_ring *rds_ring;
1321 netif_device_detach(netdev);
1323 if (netif_running(netdev))
1324 __qlcnic_down(adapter, netdev);
1326 qlcnic_detach(adapter);
1328 adapter->max_sds_rings = 1;
1329 adapter->diag_test = test;
1331 ret = qlcnic_attach(adapter);
1333 netif_device_attach(netdev);
1337 ret = qlcnic_fw_create_ctx(adapter);
1339 qlcnic_detach(adapter);
1340 netif_device_attach(netdev);
1344 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1345 rds_ring = &adapter->recv_ctx.rds_rings[ring];
1346 qlcnic_post_rx_buffers(adapter, ring, rds_ring);
1349 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1350 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1351 sds_ring = &adapter->recv_ctx.sds_rings[ring];
1352 qlcnic_enable_int(sds_ring);
1355 set_bit(__QLCNIC_DEV_UP, &adapter->state);
1360 /* Reset context in hardware only */
1362 qlcnic_reset_hw_context(struct qlcnic_adapter *adapter)
1364 struct net_device *netdev = adapter->netdev;
1366 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1369 netif_device_detach(netdev);
1371 qlcnic_down(adapter, netdev);
1373 qlcnic_up(adapter, netdev);
1375 netif_device_attach(netdev);
1377 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1382 qlcnic_reset_context(struct qlcnic_adapter *adapter)
1385 struct net_device *netdev = adapter->netdev;
1387 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1390 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1392 netif_device_detach(netdev);
1394 if (netif_running(netdev))
1395 __qlcnic_down(adapter, netdev);
1397 qlcnic_detach(adapter);
1399 if (netif_running(netdev)) {
1400 err = qlcnic_attach(adapter);
1402 __qlcnic_up(adapter, netdev);
1405 netif_device_attach(netdev);
1408 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1413 qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1414 struct net_device *netdev, u8 pci_using_dac)
1417 struct pci_dev *pdev = adapter->pdev;
1419 adapter->rx_csum = 1;
1420 adapter->mc_enabled = 0;
1421 adapter->max_mc_count = 38;
1423 netdev->netdev_ops = &qlcnic_netdev_ops;
1424 netdev->watchdog_timeo = 5*HZ;
1426 qlcnic_change_mtu(netdev, netdev->mtu);
1428 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1430 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1431 NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_HW_VLAN_RX);
1432 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1435 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
1436 netdev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
1437 netdev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
1440 if (pci_using_dac) {
1441 netdev->features |= NETIF_F_HIGHDMA;
1442 netdev->vlan_features |= NETIF_F_HIGHDMA;
1445 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX)
1446 netdev->features |= (NETIF_F_HW_VLAN_TX);
1448 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1449 netdev->features |= NETIF_F_LRO;
1450 netdev->irq = adapter->msix_entries[0].vector;
1452 netif_carrier_off(netdev);
1454 err = register_netdev(netdev);
1456 dev_err(&pdev->dev, "failed to register net device\n");
1463 static int qlcnic_set_dma_mask(struct pci_dev *pdev, u8 *pci_using_dac)
1465 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
1466 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
1468 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) &&
1469 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
1472 dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n");
1479 static int __devinit
1480 qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1482 struct net_device *netdev = NULL;
1483 struct qlcnic_adapter *adapter = NULL;
1485 uint8_t revision_id;
1486 uint8_t pci_using_dac;
1487 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
1490 err = pci_enable_device(pdev);
1494 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
1496 goto err_out_disable_pdev;
1499 err = qlcnic_set_dma_mask(pdev, &pci_using_dac);
1501 goto err_out_disable_pdev;
1503 err = pci_request_regions(pdev, qlcnic_driver_name);
1505 goto err_out_disable_pdev;
1507 pci_set_master(pdev);
1508 pci_enable_pcie_error_reporting(pdev);
1510 netdev = alloc_etherdev(sizeof(struct qlcnic_adapter));
1512 dev_err(&pdev->dev, "failed to allocate net_device\n");
1514 goto err_out_free_res;
1517 SET_NETDEV_DEV(netdev, &pdev->dev);
1519 adapter = netdev_priv(netdev);
1520 adapter->netdev = netdev;
1521 adapter->pdev = pdev;
1522 adapter->dev_rst_time = jiffies;
1524 revision_id = pdev->revision;
1525 adapter->ahw.revision_id = revision_id;
1527 rwlock_init(&adapter->ahw.crb_lock);
1528 mutex_init(&adapter->ahw.mem_lock);
1530 spin_lock_init(&adapter->tx_clean_lock);
1531 INIT_LIST_HEAD(&adapter->mac_list);
1533 err = qlcnic_setup_pci_map(adapter);
1535 goto err_out_free_netdev;
1537 /* This will be reset for mezz cards */
1538 adapter->portnum = adapter->ahw.pci_func;
1540 err = qlcnic_get_board_info(adapter);
1542 dev_err(&pdev->dev, "Error getting board config info.\n");
1543 goto err_out_iounmap;
1546 err = qlcnic_setup_idc_param(adapter);
1548 goto err_out_iounmap;
1550 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
1551 if (QLC_DEV_CHECK_ACTIVE(val, adapter->portnum))
1552 adapter->flags |= QLCNIC_NEED_FLR;
1554 err = adapter->nic_ops->start_firmware(adapter);
1556 dev_err(&pdev->dev, "Loading fw failed.Please Reboot\n");
1557 goto err_out_decr_ref;
1560 if (qlcnic_read_mac_addr(adapter))
1561 dev_warn(&pdev->dev, "failed to read mac addr\n");
1563 if (adapter->portnum == 0) {
1564 get_brd_name(adapter, brd_name);
1566 pr_info("%s: %s Board Chip rev 0x%x\n",
1567 module_name(THIS_MODULE),
1568 brd_name, adapter->ahw.revision_id);
1571 qlcnic_clear_stats(adapter);
1573 qlcnic_setup_intr(adapter);
1575 err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac);
1577 goto err_out_disable_msi;
1579 pci_set_drvdata(pdev, adapter);
1581 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1583 switch (adapter->ahw.port_type) {
1585 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1586 adapter->netdev->name);
1589 dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n",
1590 adapter->netdev->name);
1594 qlcnic_alloc_lb_filters_mem(adapter);
1595 qlcnic_create_diag_entries(adapter);
1599 err_out_disable_msi:
1600 qlcnic_teardown_intr(adapter);
1603 qlcnic_clr_all_drv_state(adapter, 0);
1606 qlcnic_cleanup_pci_map(adapter);
1608 err_out_free_netdev:
1609 free_netdev(netdev);
1612 pci_release_regions(pdev);
1614 err_out_disable_pdev:
1615 pci_set_drvdata(pdev, NULL);
1616 pci_disable_device(pdev);
1620 static void __devexit qlcnic_remove(struct pci_dev *pdev)
1622 struct qlcnic_adapter *adapter;
1623 struct net_device *netdev;
1625 adapter = pci_get_drvdata(pdev);
1626 if (adapter == NULL)
1629 netdev = adapter->netdev;
1631 qlcnic_cancel_fw_work(adapter);
1633 unregister_netdev(netdev);
1635 qlcnic_detach(adapter);
1637 if (adapter->npars != NULL)
1638 kfree(adapter->npars);
1639 if (adapter->eswitch != NULL)
1640 kfree(adapter->eswitch);
1642 qlcnic_clr_all_drv_state(adapter, 0);
1644 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1646 qlcnic_free_lb_filters_mem(adapter);
1648 qlcnic_teardown_intr(adapter);
1650 qlcnic_remove_diag_entries(adapter);
1652 qlcnic_cleanup_pci_map(adapter);
1654 qlcnic_release_firmware(adapter);
1656 pci_disable_pcie_error_reporting(pdev);
1657 pci_release_regions(pdev);
1658 pci_disable_device(pdev);
1659 pci_set_drvdata(pdev, NULL);
1661 free_netdev(netdev);
1663 static int __qlcnic_shutdown(struct pci_dev *pdev)
1665 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1666 struct net_device *netdev = adapter->netdev;
1669 netif_device_detach(netdev);
1671 qlcnic_cancel_fw_work(adapter);
1673 if (netif_running(netdev))
1674 qlcnic_down(adapter, netdev);
1676 qlcnic_clr_all_drv_state(adapter, 0);
1678 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1680 retval = pci_save_state(pdev);
1684 if (qlcnic_wol_supported(adapter)) {
1685 pci_enable_wake(pdev, PCI_D3cold, 1);
1686 pci_enable_wake(pdev, PCI_D3hot, 1);
1692 static void qlcnic_shutdown(struct pci_dev *pdev)
1694 if (__qlcnic_shutdown(pdev))
1697 pci_disable_device(pdev);
1702 qlcnic_suspend(struct pci_dev *pdev, pm_message_t state)
1706 retval = __qlcnic_shutdown(pdev);
1710 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1715 qlcnic_resume(struct pci_dev *pdev)
1717 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
1718 struct net_device *netdev = adapter->netdev;
1721 err = pci_enable_device(pdev);
1725 pci_set_power_state(pdev, PCI_D0);
1726 pci_set_master(pdev);
1727 pci_restore_state(pdev);
1729 err = adapter->nic_ops->start_firmware(adapter);
1731 dev_err(&pdev->dev, "failed to start firmware\n");
1735 if (netif_running(netdev)) {
1736 err = qlcnic_up(adapter, netdev);
1740 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1743 netif_device_attach(netdev);
1744 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1749 static int qlcnic_open(struct net_device *netdev)
1751 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1754 err = qlcnic_attach(adapter);
1758 err = __qlcnic_up(adapter, netdev);
1762 netif_start_queue(netdev);
1767 qlcnic_detach(adapter);
1772 * qlcnic_close - Disables a network interface entry point
1774 static int qlcnic_close(struct net_device *netdev)
1776 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1778 __qlcnic_down(adapter, netdev);
1783 qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
1788 if (!qlcnic_mac_learn)
1791 spin_lock_init(&adapter->mac_learn_lock);
1793 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1798 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
1799 adapter->fhash.fhead = (struct hlist_head *)head;
1801 for (i = 0; i < adapter->fhash.fmax; i++)
1802 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1805 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1807 if (adapter->fhash.fmax && adapter->fhash.fhead)
1808 kfree(adapter->fhash.fhead);
1810 adapter->fhash.fhead = NULL;
1811 adapter->fhash.fmax = 0;
1814 static void qlcnic_change_filter(struct qlcnic_adapter *adapter,
1815 u64 uaddr, __le16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
1817 struct cmd_desc_type0 *hwdesc;
1818 struct qlcnic_nic_req *req;
1819 struct qlcnic_mac_req *mac_req;
1820 struct qlcnic_vlan_req *vlan_req;
1824 producer = tx_ring->producer;
1825 hwdesc = &tx_ring->desc_head[tx_ring->producer];
1827 req = (struct qlcnic_nic_req *)hwdesc;
1828 memset(req, 0, sizeof(struct qlcnic_nic_req));
1829 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
1831 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
1832 req->req_hdr = cpu_to_le64(word);
1834 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
1835 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
1836 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
1838 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
1839 vlan_req->vlan_id = vlan_id;
1841 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
1844 #define QLCNIC_MAC_HASH(MAC)\
1845 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1848 qlcnic_send_filter(struct qlcnic_adapter *adapter,
1849 struct qlcnic_host_tx_ring *tx_ring,
1850 struct cmd_desc_type0 *first_desc,
1851 struct sk_buff *skb)
1853 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
1854 struct qlcnic_filter *fil, *tmp_fil;
1855 struct hlist_node *tmp_hnode, *n;
1856 struct hlist_head *head;
1861 if (!compare_ether_addr(phdr->h_source, adapter->mac_addr))
1864 if (adapter->fhash.fnum >= adapter->fhash.fmax)
1867 /* Only NPAR capable devices support vlan based learning*/
1868 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
1869 vlan_id = first_desc->vlan_TCI;
1870 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
1871 hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1);
1872 head = &(adapter->fhash.fhead[hindex]);
1874 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
1875 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1876 tmp_fil->vlan_id == vlan_id) {
1879 (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
1880 qlcnic_change_filter(adapter, src_addr, vlan_id,
1882 tmp_fil->ftime = jiffies;
1887 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
1891 qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring);
1893 fil->ftime = jiffies;
1894 fil->vlan_id = vlan_id;
1895 memcpy(fil->faddr, &src_addr, ETH_ALEN);
1896 spin_lock(&adapter->mac_learn_lock);
1897 hlist_add_head(&(fil->fnode), head);
1898 adapter->fhash.fnum++;
1899 spin_unlock(&adapter->mac_learn_lock);
1903 qlcnic_tso_check(struct net_device *netdev,
1904 struct qlcnic_host_tx_ring *tx_ring,
1905 struct cmd_desc_type0 *first_desc,
1906 struct sk_buff *skb)
1908 u8 opcode = TX_ETHER_PKT;
1909 __be16 protocol = skb->protocol;
1911 int copied, offset, copy_len, hdr_len = 0, tso = 0;
1912 struct cmd_desc_type0 *hwdesc;
1913 struct vlan_ethhdr *vh;
1914 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1915 u32 producer = tx_ring->producer;
1916 __le16 vlan_oob = first_desc->flags_opcode &
1917 cpu_to_le16(FLAGS_VLAN_OOB);
1919 if (*(skb->data) & BIT_0) {
1921 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
1924 if ((netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
1925 skb_shinfo(skb)->gso_size > 0) {
1927 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
1929 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
1930 first_desc->total_hdr_length = hdr_len;
1932 first_desc->total_hdr_length += VLAN_HLEN;
1933 first_desc->tcp_hdr_offset = VLAN_HLEN;
1934 first_desc->ip_hdr_offset = VLAN_HLEN;
1935 /* Only in case of TSO on vlan device */
1936 flags |= FLAGS_VLAN_TAGGED;
1939 opcode = (protocol == cpu_to_be16(ETH_P_IPV6)) ?
1940 TX_TCP_LSO6 : TX_TCP_LSO;
1943 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1946 if (protocol == cpu_to_be16(ETH_P_IP)) {
1947 l4proto = ip_hdr(skb)->protocol;
1949 if (l4proto == IPPROTO_TCP)
1950 opcode = TX_TCP_PKT;
1951 else if (l4proto == IPPROTO_UDP)
1952 opcode = TX_UDP_PKT;
1953 } else if (protocol == cpu_to_be16(ETH_P_IPV6)) {
1954 l4proto = ipv6_hdr(skb)->nexthdr;
1956 if (l4proto == IPPROTO_TCP)
1957 opcode = TX_TCPV6_PKT;
1958 else if (l4proto == IPPROTO_UDP)
1959 opcode = TX_UDPV6_PKT;
1963 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
1964 first_desc->ip_hdr_offset += skb_network_offset(skb);
1965 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
1970 /* For LSO, we need to copy the MAC/IP/TCP headers into
1971 * the descriptor ring
1977 /* Create a TSO vlan header template for firmware */
1979 hwdesc = &tx_ring->desc_head[producer];
1980 tx_ring->cmd_buf_arr[producer].skb = NULL;
1982 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
1983 hdr_len + VLAN_HLEN);
1985 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1986 skb_copy_from_linear_data(skb, vh, 12);
1987 vh->h_vlan_proto = htons(ETH_P_8021Q);
1988 vh->h_vlan_TCI = (__be16)swab16((u16)first_desc->vlan_TCI);
1990 skb_copy_from_linear_data_offset(skb, 12,
1991 (char *)vh + 16, copy_len - 16);
1993 copied = copy_len - VLAN_HLEN;
1996 producer = get_next_index(producer, tx_ring->num_desc);
1999 while (copied < hdr_len) {
2001 copy_len = min((int)sizeof(struct cmd_desc_type0) - offset,
2002 (hdr_len - copied));
2004 hwdesc = &tx_ring->desc_head[producer];
2005 tx_ring->cmd_buf_arr[producer].skb = NULL;
2007 skb_copy_from_linear_data_offset(skb, copied,
2008 (char *)hwdesc + offset, copy_len);
2013 producer = get_next_index(producer, tx_ring->num_desc);
2016 tx_ring->producer = producer;
2018 adapter->stats.lso_frames++;
2022 qlcnic_map_tx_skb(struct pci_dev *pdev,
2023 struct sk_buff *skb, struct qlcnic_cmd_buffer *pbuf)
2025 struct qlcnic_skb_frag *nf;
2026 struct skb_frag_struct *frag;
2030 nr_frags = skb_shinfo(skb)->nr_frags;
2031 nf = &pbuf->frag_array[0];
2033 map = pci_map_single(pdev, skb->data,
2034 skb_headlen(skb), PCI_DMA_TODEVICE);
2035 if (pci_dma_mapping_error(pdev, map))
2039 nf->length = skb_headlen(skb);
2041 for (i = 0; i < nr_frags; i++) {
2042 frag = &skb_shinfo(skb)->frags[i];
2043 nf = &pbuf->frag_array[i+1];
2045 map = pci_map_page(pdev, frag->page, frag->page_offset,
2046 frag->size, PCI_DMA_TODEVICE);
2047 if (pci_dma_mapping_error(pdev, map))
2051 nf->length = frag->size;
2058 nf = &pbuf->frag_array[i+1];
2059 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
2062 nf = &pbuf->frag_array[0];
2063 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
2070 qlcnic_check_tx_tagging(struct qlcnic_adapter *adapter,
2071 struct sk_buff *skb,
2072 struct cmd_desc_type0 *first_desc)
2076 __be16 protocol = skb->protocol;
2077 struct vlan_ethhdr *vh;
2079 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
2080 vh = (struct vlan_ethhdr *)skb->data;
2081 protocol = vh->h_vlan_encapsulated_proto;
2082 flags = FLAGS_VLAN_TAGGED;
2083 qlcnic_set_tx_vlan_tci(first_desc, ntohs(vh->h_vlan_TCI));
2084 } else if (vlan_tx_tag_present(skb)) {
2085 flags = FLAGS_VLAN_OOB;
2086 qlcnic_set_tx_vlan_tci(first_desc, vlan_tx_tag_get(skb));
2088 if (unlikely(adapter->pvid)) {
2089 if (first_desc->vlan_TCI &&
2090 !(adapter->flags & QLCNIC_TAGGING_ENABLED))
2092 if (first_desc->vlan_TCI &&
2093 (adapter->flags & QLCNIC_TAGGING_ENABLED))
2096 flags = FLAGS_VLAN_OOB;
2097 qlcnic_set_tx_vlan_tci(first_desc, adapter->pvid);
2100 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2105 qlcnic_clear_cmddesc(u64 *desc)
2113 qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2115 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2116 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2117 struct qlcnic_cmd_buffer *pbuf;
2118 struct qlcnic_skb_frag *buffrag;
2119 struct cmd_desc_type0 *hwdesc, *first_desc;
2120 struct pci_dev *pdev;
2121 struct ethhdr *phdr;
2125 int frag_count, no_of_desc;
2126 u32 num_txd = tx_ring->num_desc;
2128 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
2129 netif_stop_queue(netdev);
2130 return NETDEV_TX_BUSY;
2133 if (adapter->flags & QLCNIC_MACSPOOF) {
2134 phdr = (struct ethhdr *)skb->data;
2135 if (compare_ether_addr(phdr->h_source,
2140 frag_count = skb_shinfo(skb)->nr_frags + 1;
2142 /* 4 fragments per cmd des */
2143 no_of_desc = (frag_count + 3) >> 2;
2145 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
2146 netif_stop_queue(netdev);
2148 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
2149 netif_start_queue(netdev);
2151 adapter->stats.xmit_off++;
2152 return NETDEV_TX_BUSY;
2156 producer = tx_ring->producer;
2157 pbuf = &tx_ring->cmd_buf_arr[producer];
2159 pdev = adapter->pdev;
2161 first_desc = hwdesc = &tx_ring->desc_head[producer];
2162 qlcnic_clear_cmddesc((u64 *)hwdesc);
2164 if (qlcnic_check_tx_tagging(adapter, skb, first_desc))
2167 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
2168 adapter->stats.tx_dma_map_error++;
2173 pbuf->frag_count = frag_count;
2175 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
2176 qlcnic_set_tx_port(first_desc, adapter->portnum);
2178 for (i = 0; i < frag_count; i++) {
2182 if ((k == 0) && (i > 0)) {
2183 /* move to next desc.*/
2184 producer = get_next_index(producer, num_txd);
2185 hwdesc = &tx_ring->desc_head[producer];
2186 qlcnic_clear_cmddesc((u64 *)hwdesc);
2187 tx_ring->cmd_buf_arr[producer].skb = NULL;
2190 buffrag = &pbuf->frag_array[i];
2192 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
2195 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
2198 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
2201 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
2204 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
2209 tx_ring->producer = get_next_index(producer, num_txd);
2211 qlcnic_tso_check(netdev, tx_ring, first_desc, skb);
2213 if (qlcnic_mac_learn)
2214 qlcnic_send_filter(adapter, tx_ring, first_desc, skb);
2216 qlcnic_update_cmd_producer(adapter, tx_ring);
2218 adapter->stats.txbytes += skb->len;
2219 adapter->stats.xmitcalled++;
2221 return NETDEV_TX_OK;
2224 adapter->stats.txdropped++;
2225 dev_kfree_skb_any(skb);
2226 return NETDEV_TX_OK;
2229 static int qlcnic_check_temp(struct qlcnic_adapter *adapter)
2231 struct net_device *netdev = adapter->netdev;
2232 u32 temp, temp_state, temp_val;
2235 temp = QLCRD32(adapter, CRB_TEMP_STATE);
2237 temp_state = qlcnic_get_temp_state(temp);
2238 temp_val = qlcnic_get_temp_val(temp);
2240 if (temp_state == QLCNIC_TEMP_PANIC) {
2241 dev_err(&netdev->dev,
2242 "Device temperature %d degrees C exceeds"
2243 " maximum allowed. Hardware has been shut down.\n",
2246 } else if (temp_state == QLCNIC_TEMP_WARN) {
2247 if (adapter->temp == QLCNIC_TEMP_NORMAL) {
2248 dev_err(&netdev->dev,
2249 "Device temperature %d degrees C "
2250 "exceeds operating range."
2251 " Immediate action needed.\n",
2255 if (adapter->temp == QLCNIC_TEMP_WARN) {
2256 dev_info(&netdev->dev,
2257 "Device temperature is now %d degrees C"
2258 " in normal range.\n", temp_val);
2261 adapter->temp = temp_state;
2265 void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2267 struct net_device *netdev = adapter->netdev;
2269 if (adapter->ahw.linkup && !linkup) {
2270 netdev_info(netdev, "NIC Link is down\n");
2271 adapter->ahw.linkup = 0;
2272 if (netif_running(netdev)) {
2273 netif_carrier_off(netdev);
2274 netif_stop_queue(netdev);
2276 } else if (!adapter->ahw.linkup && linkup) {
2277 netdev_info(netdev, "NIC Link is up\n");
2278 adapter->ahw.linkup = 1;
2279 if (netif_running(netdev)) {
2280 netif_carrier_on(netdev);
2281 netif_wake_queue(netdev);
2286 static void qlcnic_tx_timeout(struct net_device *netdev)
2288 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2290 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
2293 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
2295 if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS)
2296 adapter->need_fw_reset = 1;
2298 adapter->reset_context = 1;
2301 static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev)
2303 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2304 struct net_device_stats *stats = &netdev->stats;
2306 stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts;
2307 stats->tx_packets = adapter->stats.xmitfinished;
2308 stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes;
2309 stats->tx_bytes = adapter->stats.txbytes;
2310 stats->rx_dropped = adapter->stats.rxdropped;
2311 stats->tx_dropped = adapter->stats.txdropped;
2316 static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter)
2320 status = readl(adapter->isr_int_vec);
2322 if (!(status & adapter->int_vec_bit))
2325 /* check interrupt state machine, to be sure */
2326 status = readl(adapter->crb_int_state_reg);
2327 if (!ISR_LEGACY_INT_TRIGGERED(status))
2330 writel(0xffffffff, adapter->tgt_status_reg);
2331 /* read twice to ensure write is flushed */
2332 readl(adapter->isr_int_vec);
2333 readl(adapter->isr_int_vec);
2338 static irqreturn_t qlcnic_tmp_intr(int irq, void *data)
2340 struct qlcnic_host_sds_ring *sds_ring = data;
2341 struct qlcnic_adapter *adapter = sds_ring->adapter;
2343 if (adapter->flags & QLCNIC_MSIX_ENABLED)
2345 else if (adapter->flags & QLCNIC_MSI_ENABLED) {
2346 writel(0xffffffff, adapter->tgt_status_reg);
2350 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2354 adapter->diag_cnt++;
2355 qlcnic_enable_int(sds_ring);
2359 static irqreturn_t qlcnic_intr(int irq, void *data)
2361 struct qlcnic_host_sds_ring *sds_ring = data;
2362 struct qlcnic_adapter *adapter = sds_ring->adapter;
2364 if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE)
2367 napi_schedule(&sds_ring->napi);
2372 static irqreturn_t qlcnic_msi_intr(int irq, void *data)
2374 struct qlcnic_host_sds_ring *sds_ring = data;
2375 struct qlcnic_adapter *adapter = sds_ring->adapter;
2377 /* clear interrupt */
2378 writel(0xffffffff, adapter->tgt_status_reg);
2380 napi_schedule(&sds_ring->napi);
2384 static irqreturn_t qlcnic_msix_intr(int irq, void *data)
2386 struct qlcnic_host_sds_ring *sds_ring = data;
2388 napi_schedule(&sds_ring->napi);
2392 static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter)
2394 u32 sw_consumer, hw_consumer;
2396 struct qlcnic_cmd_buffer *buffer;
2397 struct pci_dev *pdev = adapter->pdev;
2398 struct net_device *netdev = adapter->netdev;
2399 struct qlcnic_skb_frag *frag;
2401 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
2403 if (!spin_trylock(&adapter->tx_clean_lock))
2406 sw_consumer = tx_ring->sw_consumer;
2407 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2409 while (sw_consumer != hw_consumer) {
2410 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
2412 frag = &buffer->frag_array[0];
2413 pci_unmap_single(pdev, frag->dma, frag->length,
2416 for (i = 1; i < buffer->frag_count; i++) {
2418 pci_unmap_page(pdev, frag->dma, frag->length,
2423 adapter->stats.xmitfinished++;
2424 dev_kfree_skb_any(buffer->skb);
2428 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
2429 if (++count >= MAX_STATUS_HANDLE)
2433 if (count && netif_running(netdev)) {
2434 tx_ring->sw_consumer = sw_consumer;
2438 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
2439 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
2440 netif_wake_queue(netdev);
2441 adapter->stats.xmit_on++;
2444 adapter->tx_timeo_cnt = 0;
2447 * If everything is freed up to consumer then check if the ring is full
2448 * If the ring is full then check if more needs to be freed and
2449 * schedule the call back again.
2451 * This happens when there are 2 CPUs. One could be freeing and the
2452 * other filling it. If the ring is full when we get out of here and
2453 * the card has already interrupted the host then the host can miss the
2456 * There is still a possible race condition and the host could miss an
2457 * interrupt. The card has to take care of this.
2459 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
2460 done = (sw_consumer == hw_consumer);
2461 spin_unlock(&adapter->tx_clean_lock);
2466 static int qlcnic_poll(struct napi_struct *napi, int budget)
2468 struct qlcnic_host_sds_ring *sds_ring =
2469 container_of(napi, struct qlcnic_host_sds_ring, napi);
2471 struct qlcnic_adapter *adapter = sds_ring->adapter;
2476 tx_complete = qlcnic_process_cmd_ring(adapter);
2478 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2480 if ((work_done < budget) && tx_complete) {
2481 napi_complete(&sds_ring->napi);
2482 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2483 qlcnic_enable_int(sds_ring);
2489 static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
2491 struct qlcnic_host_sds_ring *sds_ring =
2492 container_of(napi, struct qlcnic_host_sds_ring, napi);
2494 struct qlcnic_adapter *adapter = sds_ring->adapter;
2497 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
2499 if (work_done < budget) {
2500 napi_complete(&sds_ring->napi);
2501 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2502 qlcnic_enable_int(sds_ring);
2508 #ifdef CONFIG_NET_POLL_CONTROLLER
2509 static void qlcnic_poll_controller(struct net_device *netdev)
2512 struct qlcnic_host_sds_ring *sds_ring;
2513 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2514 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx;
2516 disable_irq(adapter->irq);
2517 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2518 sds_ring = &recv_ctx->sds_rings[ring];
2519 qlcnic_intr(adapter->irq, sds_ring);
2521 enable_irq(adapter->irq);
2526 qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding)
2530 val = adapter->portnum & 0xf;
2531 val |= encoding << 7;
2532 val |= (jiffies - adapter->dev_rst_time) << 8;
2534 QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val);
2535 adapter->dev_rst_time = jiffies;
2539 qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state)
2543 WARN_ON(state != QLCNIC_DEV_NEED_RESET &&
2544 state != QLCNIC_DEV_NEED_QUISCENT);
2546 if (qlcnic_api_lock(adapter))
2549 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2551 if (state == QLCNIC_DEV_NEED_RESET)
2552 QLC_DEV_SET_RST_RDY(val, adapter->portnum);
2553 else if (state == QLCNIC_DEV_NEED_QUISCENT)
2554 QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum);
2556 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2558 qlcnic_api_unlock(adapter);
2564 qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2568 if (qlcnic_api_lock(adapter))
2571 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2572 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2573 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2575 qlcnic_api_unlock(adapter);
2581 qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
2585 if (qlcnic_api_lock(adapter))
2588 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2589 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
2590 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2593 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2594 dev_info(&adapter->pdev->dev,
2595 "Device state set to Failed. Please Reboot\n");
2596 } else if (!(val & 0x11111111))
2597 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2599 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2600 QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum);
2601 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2603 qlcnic_api_unlock(adapter);
2605 adapter->fw_fail_cnt = 0;
2606 clear_bit(__QLCNIC_START_FW, &adapter->state);
2607 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2610 /* Grab api lock, before checking state */
2612 qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2616 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2617 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2619 if (((state & 0x11111111) == (act & 0x11111111)) ||
2620 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
2626 static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter)
2628 u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER);
2630 if (val != QLCNIC_DRV_IDC_VER) {
2631 dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's"
2632 " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val);
2639 qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2641 u32 val, prev_state;
2642 u8 dev_init_timeo = adapter->dev_init_timeo;
2643 u8 portnum = adapter->portnum;
2646 if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state))
2649 if (qlcnic_api_lock(adapter))
2652 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2653 if (!(val & (1 << (portnum * 4)))) {
2654 QLC_DEV_SET_REF_CNT(val, portnum);
2655 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2658 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2659 QLCDB(adapter, HW, "Device state = %u\n", prev_state);
2661 switch (prev_state) {
2662 case QLCNIC_DEV_COLD:
2663 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
2664 QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER);
2665 qlcnic_idc_debug_info(adapter, 0);
2666 qlcnic_api_unlock(adapter);
2669 case QLCNIC_DEV_READY:
2670 ret = qlcnic_check_idc_ver(adapter);
2671 qlcnic_api_unlock(adapter);
2674 case QLCNIC_DEV_NEED_RESET:
2675 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2676 QLC_DEV_SET_RST_RDY(val, portnum);
2677 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2680 case QLCNIC_DEV_NEED_QUISCENT:
2681 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2682 QLC_DEV_SET_QSCNT_RDY(val, portnum);
2683 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2686 case QLCNIC_DEV_FAILED:
2687 dev_err(&adapter->pdev->dev, "Device in failed state.\n");
2688 qlcnic_api_unlock(adapter);
2691 case QLCNIC_DEV_INITIALIZING:
2692 case QLCNIC_DEV_QUISCENT:
2696 qlcnic_api_unlock(adapter);
2700 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2702 if (prev_state == QLCNIC_DEV_QUISCENT)
2704 } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo);
2706 if (!dev_init_timeo) {
2707 dev_err(&adapter->pdev->dev,
2708 "Waiting for device to initialize timeout\n");
2712 if (qlcnic_api_lock(adapter))
2715 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2716 QLC_DEV_CLR_RST_QSCNT(val, portnum);
2717 QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val);
2719 ret = qlcnic_check_idc_ver(adapter);
2720 qlcnic_api_unlock(adapter);
2726 qlcnic_fwinit_work(struct work_struct *work)
2728 struct qlcnic_adapter *adapter = container_of(work,
2729 struct qlcnic_adapter, fw_work.work);
2730 u32 dev_state = 0xf;
2732 if (qlcnic_api_lock(adapter))
2735 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2736 if (dev_state == QLCNIC_DEV_QUISCENT ||
2737 dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2738 qlcnic_api_unlock(adapter);
2739 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2744 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
2745 qlcnic_api_unlock(adapter);
2749 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
2750 dev_err(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n",
2751 adapter->reset_ack_timeo);
2752 goto skip_ack_check;
2755 if (!qlcnic_check_drv_state(adapter)) {
2757 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2759 if (dev_state == QLCNIC_DEV_NEED_RESET) {
2760 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE,
2761 QLCNIC_DEV_INITIALIZING);
2762 set_bit(__QLCNIC_START_FW, &adapter->state);
2763 QLCDB(adapter, DRV, "Restarting fw\n");
2764 qlcnic_idc_debug_info(adapter, 0);
2767 qlcnic_api_unlock(adapter);
2769 if (!adapter->nic_ops->start_firmware(adapter)) {
2770 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2771 adapter->fw_wait_cnt = 0;
2777 qlcnic_api_unlock(adapter);
2780 dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2781 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
2783 switch (dev_state) {
2784 case QLCNIC_DEV_READY:
2785 if (!adapter->nic_ops->start_firmware(adapter)) {
2786 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2787 adapter->fw_wait_cnt = 0;
2790 case QLCNIC_DEV_FAILED:
2793 qlcnic_schedule_work(adapter,
2794 qlcnic_fwinit_work, FW_POLL_DELAY);
2799 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2800 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
2801 netif_device_attach(adapter->netdev);
2802 qlcnic_clr_all_drv_state(adapter, 0);
2806 qlcnic_detach_work(struct work_struct *work)
2808 struct qlcnic_adapter *adapter = container_of(work,
2809 struct qlcnic_adapter, fw_work.work);
2810 struct net_device *netdev = adapter->netdev;
2813 netif_device_detach(netdev);
2815 /* Dont grab rtnl lock during Quiscent mode */
2816 if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) {
2817 if (netif_running(netdev))
2818 __qlcnic_down(adapter, netdev);
2820 qlcnic_down(adapter, netdev);
2822 status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1);
2824 if (status & QLCNIC_RCODE_FATAL_ERROR)
2827 if (adapter->temp == QLCNIC_TEMP_PANIC)
2830 if (qlcnic_set_drv_state(adapter, adapter->dev_state))
2833 adapter->fw_wait_cnt = 0;
2835 qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY);
2840 dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n",
2841 status, adapter->temp);
2842 netif_device_attach(netdev);
2843 qlcnic_clr_all_drv_state(adapter, 1);
2846 /*Transit NPAR state to NON Operational */
2848 qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2852 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2853 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2856 if (qlcnic_api_lock(adapter))
2858 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2859 qlcnic_api_unlock(adapter);
2862 /*Transit to RESET state from READY state only */
2864 qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2868 adapter->need_fw_reset = 1;
2869 if (qlcnic_api_lock(adapter))
2872 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2874 if (state == QLCNIC_DEV_READY) {
2875 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET);
2876 QLCDB(adapter, DRV, "NEED_RESET state set\n");
2877 qlcnic_idc_debug_info(adapter, 0);
2880 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2881 qlcnic_api_unlock(adapter);
2884 /* Transit to NPAR READY state from NPAR NOT READY state */
2886 qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2888 if (qlcnic_api_lock(adapter))
2891 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2892 QLCDB(adapter, DRV, "NPAR operational state set\n");
2894 qlcnic_api_unlock(adapter);
2898 qlcnic_schedule_work(struct qlcnic_adapter *adapter,
2899 work_func_t func, int delay)
2901 if (test_bit(__QLCNIC_AER, &adapter->state))
2904 INIT_DELAYED_WORK(&adapter->fw_work, func);
2905 queue_delayed_work(qlcnic_wq, &adapter->fw_work,
2906 round_jiffies_relative(delay));
2910 qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter)
2912 while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
2915 cancel_delayed_work_sync(&adapter->fw_work);
2919 qlcnic_attach_work(struct work_struct *work)
2921 struct qlcnic_adapter *adapter = container_of(work,
2922 struct qlcnic_adapter, fw_work.work);
2923 struct net_device *netdev = adapter->netdev;
2926 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2927 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2928 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2929 qlcnic_clr_all_drv_state(adapter, 0);
2930 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2931 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2935 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2939 if (netif_running(netdev)) {
2940 if (qlcnic_up(adapter, netdev))
2943 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2947 netif_device_attach(netdev);
2948 adapter->fw_fail_cnt = 0;
2949 clear_bit(__QLCNIC_RESETTING, &adapter->state);
2951 if (!qlcnic_clr_drv_state(adapter))
2952 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
2957 qlcnic_check_health(struct qlcnic_adapter *adapter)
2959 u32 state = 0, heartbeat;
2960 struct net_device *netdev = adapter->netdev;
2962 if (qlcnic_check_temp(adapter))
2965 if (adapter->need_fw_reset)
2966 qlcnic_dev_request_reset(adapter);
2968 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2969 if (state == QLCNIC_DEV_NEED_RESET) {
2970 qlcnic_set_npar_non_operational(adapter);
2971 adapter->need_fw_reset = 1;
2972 } else if (state == QLCNIC_DEV_NEED_QUISCENT)
2975 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
2976 if (heartbeat != adapter->heartbeat) {
2977 adapter->heartbeat = heartbeat;
2978 adapter->fw_fail_cnt = 0;
2979 if (adapter->need_fw_reset)
2982 if (adapter->reset_context &&
2983 auto_fw_reset == AUTO_FW_RESET_ENABLED) {
2984 qlcnic_reset_hw_context(adapter);
2985 adapter->netdev->trans_start = jiffies;
2991 if (++adapter->fw_fail_cnt < FW_FAIL_THRESH)
2994 qlcnic_dev_request_reset(adapter);
2996 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED))
2997 clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state);
2999 dev_info(&netdev->dev, "firmware hang detected\n");
3002 adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state :
3003 QLCNIC_DEV_NEED_RESET;
3005 if ((auto_fw_reset == AUTO_FW_RESET_ENABLED) &&
3006 !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) {
3008 qlcnic_schedule_work(adapter, qlcnic_detach_work, 0);
3009 QLCDB(adapter, DRV, "fw recovery scheduled.\n");
3016 qlcnic_fw_poll_work(struct work_struct *work)
3018 struct qlcnic_adapter *adapter = container_of(work,
3019 struct qlcnic_adapter, fw_work.work);
3021 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
3025 if (qlcnic_check_health(adapter))
3028 if (adapter->fhash.fnum)
3029 qlcnic_prune_lb_filters(adapter);
3032 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
3035 static int qlcnic_is_first_func(struct pci_dev *pdev)
3037 struct pci_dev *oth_pdev;
3038 int val = pdev->devfn;
3041 oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr
3042 (pdev->bus), pdev->bus->number,
3043 PCI_DEVFN(PCI_SLOT(pdev->devfn), val));
3047 if (oth_pdev->current_state != PCI_D3cold) {
3048 pci_dev_put(oth_pdev);
3051 pci_dev_put(oth_pdev);
3056 static int qlcnic_attach_func(struct pci_dev *pdev)
3058 int err, first_func;
3059 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3060 struct net_device *netdev = adapter->netdev;
3062 pdev->error_state = pci_channel_io_normal;
3064 err = pci_enable_device(pdev);
3068 pci_set_power_state(pdev, PCI_D0);
3069 pci_set_master(pdev);
3070 pci_restore_state(pdev);
3072 first_func = qlcnic_is_first_func(pdev);
3074 if (qlcnic_api_lock(adapter))
3077 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
3078 adapter->need_fw_reset = 1;
3079 set_bit(__QLCNIC_START_FW, &adapter->state);
3080 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
3081 QLCDB(adapter, DRV, "Restarting fw\n");
3083 qlcnic_api_unlock(adapter);
3085 err = adapter->nic_ops->start_firmware(adapter);
3089 qlcnic_clr_drv_state(adapter);
3090 qlcnic_setup_intr(adapter);
3092 if (netif_running(netdev)) {
3093 err = qlcnic_attach(adapter);
3095 qlcnic_clr_all_drv_state(adapter, 1);
3096 clear_bit(__QLCNIC_AER, &adapter->state);
3097 netif_device_attach(netdev);
3101 err = qlcnic_up(adapter, netdev);
3105 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
3108 netif_device_attach(netdev);
3112 static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev,
3113 pci_channel_state_t state)
3115 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3116 struct net_device *netdev = adapter->netdev;
3118 if (state == pci_channel_io_perm_failure)
3119 return PCI_ERS_RESULT_DISCONNECT;
3121 if (state == pci_channel_io_normal)
3122 return PCI_ERS_RESULT_RECOVERED;
3124 set_bit(__QLCNIC_AER, &adapter->state);
3125 netif_device_detach(netdev);
3127 cancel_delayed_work_sync(&adapter->fw_work);
3129 if (netif_running(netdev))
3130 qlcnic_down(adapter, netdev);
3132 qlcnic_detach(adapter);
3133 qlcnic_teardown_intr(adapter);
3135 clear_bit(__QLCNIC_RESETTING, &adapter->state);
3137 pci_save_state(pdev);
3138 pci_disable_device(pdev);
3140 return PCI_ERS_RESULT_NEED_RESET;
3143 static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev)
3145 return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT :
3146 PCI_ERS_RESULT_RECOVERED;
3149 static void qlcnic_io_resume(struct pci_dev *pdev)
3151 struct qlcnic_adapter *adapter = pci_get_drvdata(pdev);
3153 pci_cleanup_aer_uncorrect_error_status(pdev);
3155 if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY &&
3156 test_and_clear_bit(__QLCNIC_AER, &adapter->state))
3157 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work,
3162 qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
3166 err = qlcnic_can_start_firmware(adapter);
3170 err = qlcnic_check_npar_opertional(adapter);
3174 err = qlcnic_initialize_nic(adapter);
3178 qlcnic_check_options(adapter);
3180 err = qlcnic_set_eswitch_port_config(adapter);
3184 adapter->need_fw_reset = 0;
3190 qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
3196 qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
3202 qlcnic_store_bridged_mode(struct device *dev,
3203 struct device_attribute *attr, const char *buf, size_t len)
3205 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3209 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG))
3212 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3215 if (strict_strtoul(buf, 2, &new))
3218 if (!adapter->nic_ops->config_bridged_mode(adapter, !!new))
3226 qlcnic_show_bridged_mode(struct device *dev,
3227 struct device_attribute *attr, char *buf)
3229 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3230 int bridged_mode = 0;
3232 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3233 bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED);
3235 return sprintf(buf, "%d\n", bridged_mode);
3238 static struct device_attribute dev_attr_bridged_mode = {
3239 .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)},
3240 .show = qlcnic_show_bridged_mode,
3241 .store = qlcnic_store_bridged_mode,
3245 qlcnic_store_diag_mode(struct device *dev,
3246 struct device_attribute *attr, const char *buf, size_t len)
3248 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3251 if (strict_strtoul(buf, 2, &new))
3254 if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED))
3255 adapter->flags ^= QLCNIC_DIAG_ENABLED;
3261 qlcnic_show_diag_mode(struct device *dev,
3262 struct device_attribute *attr, char *buf)
3264 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3266 return sprintf(buf, "%d\n",
3267 !!(adapter->flags & QLCNIC_DIAG_ENABLED));
3270 static struct device_attribute dev_attr_diag_mode = {
3271 .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)},
3272 .show = qlcnic_show_diag_mode,
3273 .store = qlcnic_store_diag_mode,
3277 qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter,
3278 loff_t offset, size_t size)
3280 size_t crb_size = 4;
3282 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3285 if (offset < QLCNIC_PCI_CRBSPACE) {
3286 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM,
3287 QLCNIC_PCI_CAMQM_END))
3293 if ((size != crb_size) || (offset & (crb_size-1)))
3300 qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj,
3301 struct bin_attribute *attr,
3302 char *buf, loff_t offset, size_t size)
3304 struct device *dev = container_of(kobj, struct device, kobj);
3305 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3310 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3314 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3315 qlcnic_pci_camqm_read_2M(adapter, offset, &qmdata);
3316 memcpy(buf, &qmdata, size);
3318 data = QLCRD32(adapter, offset);
3319 memcpy(buf, &data, size);
3325 qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj,
3326 struct bin_attribute *attr,
3327 char *buf, loff_t offset, size_t size)
3329 struct device *dev = container_of(kobj, struct device, kobj);
3330 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3335 ret = qlcnic_sysfs_validate_crb(adapter, offset, size);
3339 if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, QLCNIC_PCI_CAMQM_END)) {
3340 memcpy(&qmdata, buf, size);
3341 qlcnic_pci_camqm_write_2M(adapter, offset, qmdata);
3343 memcpy(&data, buf, size);
3344 QLCWR32(adapter, offset, data);
3350 qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter,
3351 loff_t offset, size_t size)
3353 if (!(adapter->flags & QLCNIC_DIAG_ENABLED))
3356 if ((size != 8) || (offset & 0x7))
3363 qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj,
3364 struct bin_attribute *attr,
3365 char *buf, loff_t offset, size_t size)
3367 struct device *dev = container_of(kobj, struct device, kobj);
3368 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3372 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3376 if (qlcnic_pci_mem_read_2M(adapter, offset, &data))
3379 memcpy(buf, &data, size);
3385 qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj,
3386 struct bin_attribute *attr,
3387 char *buf, loff_t offset, size_t size)
3389 struct device *dev = container_of(kobj, struct device, kobj);
3390 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3394 ret = qlcnic_sysfs_validate_mem(adapter, offset, size);
3398 memcpy(&data, buf, size);
3400 if (qlcnic_pci_mem_write_2M(adapter, offset, data))
3407 static struct bin_attribute bin_attr_crb = {
3408 .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)},
3410 .read = qlcnic_sysfs_read_crb,
3411 .write = qlcnic_sysfs_write_crb,
3414 static struct bin_attribute bin_attr_mem = {
3415 .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)},
3417 .read = qlcnic_sysfs_read_mem,
3418 .write = qlcnic_sysfs_write_mem,
3422 validate_pm_config(struct qlcnic_adapter *adapter,
3423 struct qlcnic_pm_func_cfg *pm_cfg, int count)
3426 u8 src_pci_func, s_esw_id, d_esw_id;
3430 for (i = 0; i < count; i++) {
3431 src_pci_func = pm_cfg[i].pci_func;
3432 dest_pci_func = pm_cfg[i].dest_npar;
3433 if (src_pci_func >= QLCNIC_MAX_PCI_FUNC
3434 || dest_pci_func >= QLCNIC_MAX_PCI_FUNC)
3435 return QL_STATUS_INVALID_PARAM;
3437 if (adapter->npars[src_pci_func].type != QLCNIC_TYPE_NIC)
3438 return QL_STATUS_INVALID_PARAM;
3440 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3441 return QL_STATUS_INVALID_PARAM;
3443 s_esw_id = adapter->npars[src_pci_func].phy_port;
3444 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3446 if (s_esw_id != d_esw_id)
3447 return QL_STATUS_INVALID_PARAM;
3455 qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3456 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3458 struct device *dev = container_of(kobj, struct device, kobj);
3459 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3460 struct qlcnic_pm_func_cfg *pm_cfg;
3461 u32 id, action, pci_func;
3462 int count, rem, i, ret;
3464 count = size / sizeof(struct qlcnic_pm_func_cfg);
3465 rem = size % sizeof(struct qlcnic_pm_func_cfg);
3467 return QL_STATUS_INVALID_PARAM;
3469 pm_cfg = (struct qlcnic_pm_func_cfg *) buf;
3471 ret = validate_pm_config(adapter, pm_cfg, count);
3474 for (i = 0; i < count; i++) {
3475 pci_func = pm_cfg[i].pci_func;
3476 action = !!pm_cfg[i].action;
3477 id = adapter->npars[pci_func].phy_port;
3478 ret = qlcnic_config_port_mirroring(adapter, id,
3484 for (i = 0; i < count; i++) {
3485 pci_func = pm_cfg[i].pci_func;
3486 id = adapter->npars[pci_func].phy_port;
3487 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
3488 adapter->npars[pci_func].dest_npar = id;
3494 qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3495 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3497 struct device *dev = container_of(kobj, struct device, kobj);
3498 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3499 struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC];
3502 if (size != sizeof(pm_cfg))
3503 return QL_STATUS_INVALID_PARAM;
3505 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3506 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3508 pm_cfg[i].action = adapter->npars[i].enable_pm;
3509 pm_cfg[i].dest_npar = 0;
3510 pm_cfg[i].pci_func = i;
3512 memcpy(buf, &pm_cfg, size);
3518 validate_esw_config(struct qlcnic_adapter *adapter,
3519 struct qlcnic_esw_func_cfg *esw_cfg, int count)
3525 op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE);
3527 for (i = 0; i < count; i++) {
3528 pci_func = esw_cfg[i].pci_func;
3529 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3530 return QL_STATUS_INVALID_PARAM;
3532 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3533 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3534 return QL_STATUS_INVALID_PARAM;
3536 switch (esw_cfg[i].op_mode) {
3537 case QLCNIC_PORT_DEFAULTS:
3538 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
3539 QLCNIC_NON_PRIV_FUNC) {
3540 esw_cfg[i].mac_anti_spoof = 0;
3541 esw_cfg[i].mac_override = 1;
3542 esw_cfg[i].promisc_mode = 1;
3545 case QLCNIC_ADD_VLAN:
3546 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3547 return QL_STATUS_INVALID_PARAM;
3548 if (!esw_cfg[i].op_type)
3549 return QL_STATUS_INVALID_PARAM;
3551 case QLCNIC_DEL_VLAN:
3552 if (!esw_cfg[i].op_type)
3553 return QL_STATUS_INVALID_PARAM;
3556 return QL_STATUS_INVALID_PARAM;
3563 qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3564 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3566 struct device *dev = container_of(kobj, struct device, kobj);
3567 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3568 struct qlcnic_esw_func_cfg *esw_cfg;
3569 struct qlcnic_npar_info *npar;
3570 int count, rem, i, ret;
3571 u8 pci_func, op_mode = 0;
3573 count = size / sizeof(struct qlcnic_esw_func_cfg);
3574 rem = size % sizeof(struct qlcnic_esw_func_cfg);
3576 return QL_STATUS_INVALID_PARAM;
3578 esw_cfg = (struct qlcnic_esw_func_cfg *) buf;
3579 ret = validate_esw_config(adapter, esw_cfg, count);
3583 for (i = 0; i < count; i++) {
3584 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3585 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3586 return QL_STATUS_INVALID_PARAM;
3588 if (adapter->ahw.pci_func != esw_cfg[i].pci_func)
3591 op_mode = esw_cfg[i].op_mode;
3592 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3593 esw_cfg[i].op_mode = op_mode;
3594 esw_cfg[i].pci_func = adapter->ahw.pci_func;
3596 switch (esw_cfg[i].op_mode) {
3597 case QLCNIC_PORT_DEFAULTS:
3598 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3600 case QLCNIC_ADD_VLAN:
3601 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3603 case QLCNIC_DEL_VLAN:
3604 esw_cfg[i].vlan_id = 0;
3605 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3610 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3613 for (i = 0; i < count; i++) {
3614 pci_func = esw_cfg[i].pci_func;
3615 npar = &adapter->npars[pci_func];
3616 switch (esw_cfg[i].op_mode) {
3617 case QLCNIC_PORT_DEFAULTS:
3618 npar->promisc_mode = esw_cfg[i].promisc_mode;
3619 npar->mac_override = esw_cfg[i].mac_override;
3620 npar->offload_flags = esw_cfg[i].offload_flags;
3621 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3622 npar->discard_tagged = esw_cfg[i].discard_tagged;
3624 case QLCNIC_ADD_VLAN:
3625 npar->pvid = esw_cfg[i].vlan_id;
3627 case QLCNIC_DEL_VLAN:
3637 qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3638 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3640 struct device *dev = container_of(kobj, struct device, kobj);
3641 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3642 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
3645 if (size != sizeof(esw_cfg))
3646 return QL_STATUS_INVALID_PARAM;
3648 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3649 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3651 esw_cfg[i].pci_func = i;
3652 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
3653 return QL_STATUS_INVALID_PARAM;
3655 memcpy(buf, &esw_cfg, size);
3661 validate_npar_config(struct qlcnic_adapter *adapter,
3662 struct qlcnic_npar_func_cfg *np_cfg, int count)
3666 for (i = 0; i < count; i++) {
3667 pci_func = np_cfg[i].pci_func;
3668 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3669 return QL_STATUS_INVALID_PARAM;
3671 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3672 return QL_STATUS_INVALID_PARAM;
3674 if (!IS_VALID_BW(np_cfg[i].min_bw)
3675 || !IS_VALID_BW(np_cfg[i].max_bw)
3676 || !IS_VALID_RX_QUEUES(np_cfg[i].max_rx_queues)
3677 || !IS_VALID_TX_QUEUES(np_cfg[i].max_tx_queues))
3678 return QL_STATUS_INVALID_PARAM;
3684 qlcnic_sysfs_write_npar_config(struct file *file, struct kobject *kobj,
3685 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3687 struct device *dev = container_of(kobj, struct device, kobj);
3688 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3689 struct qlcnic_info nic_info;
3690 struct qlcnic_npar_func_cfg *np_cfg;
3691 int i, count, rem, ret;
3694 count = size / sizeof(struct qlcnic_npar_func_cfg);
3695 rem = size % sizeof(struct qlcnic_npar_func_cfg);
3697 return QL_STATUS_INVALID_PARAM;
3699 np_cfg = (struct qlcnic_npar_func_cfg *) buf;
3700 ret = validate_npar_config(adapter, np_cfg, count);
3704 for (i = 0; i < count ; i++) {
3705 pci_func = np_cfg[i].pci_func;
3706 ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func);
3709 nic_info.pci_func = pci_func;
3710 nic_info.min_tx_bw = np_cfg[i].min_bw;
3711 nic_info.max_tx_bw = np_cfg[i].max_bw;
3712 ret = qlcnic_set_nic_info(adapter, &nic_info);
3715 adapter->npars[i].min_bw = nic_info.min_tx_bw;
3716 adapter->npars[i].max_bw = nic_info.max_tx_bw;
3723 qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
3724 struct bin_attribute *attr, 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);
3728 struct qlcnic_info nic_info;
3729 struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC];
3732 if (size != sizeof(np_cfg))
3733 return QL_STATUS_INVALID_PARAM;
3735 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3736 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3738 ret = qlcnic_get_nic_info(adapter, &nic_info, i);
3742 np_cfg[i].pci_func = i;
3743 np_cfg[i].op_mode = (u8)nic_info.op_mode;
3744 np_cfg[i].port_num = nic_info.phys_port;
3745 np_cfg[i].fw_capab = nic_info.capabilities;
3746 np_cfg[i].min_bw = nic_info.min_tx_bw ;
3747 np_cfg[i].max_bw = nic_info.max_tx_bw;
3748 np_cfg[i].max_tx_queues = nic_info.max_tx_ques;
3749 np_cfg[i].max_rx_queues = nic_info.max_rx_ques;
3751 memcpy(buf, &np_cfg, size);
3756 qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
3757 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3759 struct device *dev = container_of(kobj, struct device, kobj);
3760 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3761 struct qlcnic_esw_statistics port_stats;
3764 if (size != sizeof(struct qlcnic_esw_statistics))
3765 return QL_STATUS_INVALID_PARAM;
3767 if (offset >= QLCNIC_MAX_PCI_FUNC)
3768 return QL_STATUS_INVALID_PARAM;
3770 memset(&port_stats, 0, size);
3771 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3776 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3781 memcpy(buf, &port_stats, size);
3786 qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
3787 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3789 struct device *dev = container_of(kobj, struct device, kobj);
3790 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3791 struct qlcnic_esw_statistics esw_stats;
3794 if (size != sizeof(struct qlcnic_esw_statistics))
3795 return QL_STATUS_INVALID_PARAM;
3797 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3798 return QL_STATUS_INVALID_PARAM;
3800 memset(&esw_stats, 0, size);
3801 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3806 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3811 memcpy(buf, &esw_stats, size);
3816 qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
3817 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3819 struct device *dev = container_of(kobj, struct device, kobj);
3820 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3823 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3824 return QL_STATUS_INVALID_PARAM;
3826 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3827 QLCNIC_QUERY_RX_COUNTER);
3831 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3832 QLCNIC_QUERY_TX_COUNTER);
3840 qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
3841 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3844 struct device *dev = container_of(kobj, struct device, kobj);
3845 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3848 if (offset >= QLCNIC_MAX_PCI_FUNC)
3849 return QL_STATUS_INVALID_PARAM;
3851 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3852 QLCNIC_QUERY_RX_COUNTER);
3856 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3857 QLCNIC_QUERY_TX_COUNTER);
3865 qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3866 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3868 struct device *dev = container_of(kobj, struct device, kobj);
3869 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3870 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
3871 struct qlcnic_pci_info *pci_info;
3874 if (size != sizeof(pci_cfg))
3875 return QL_STATUS_INVALID_PARAM;
3877 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
3881 ret = qlcnic_get_pci_info(adapter, pci_info);
3887 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3888 pci_cfg[i].pci_func = pci_info[i].id;
3889 pci_cfg[i].func_type = pci_info[i].type;
3890 pci_cfg[i].port_num = pci_info[i].default_port;
3891 pci_cfg[i].min_bw = pci_info[i].tx_min_bw;
3892 pci_cfg[i].max_bw = pci_info[i].tx_max_bw;
3893 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
3895 memcpy(buf, &pci_cfg, size);
3899 static struct bin_attribute bin_attr_npar_config = {
3900 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
3902 .read = qlcnic_sysfs_read_npar_config,
3903 .write = qlcnic_sysfs_write_npar_config,
3906 static struct bin_attribute bin_attr_pci_config = {
3907 .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)},
3909 .read = qlcnic_sysfs_read_pci_config,
3913 static struct bin_attribute bin_attr_port_stats = {
3914 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
3916 .read = qlcnic_sysfs_get_port_stats,
3917 .write = qlcnic_sysfs_clear_port_stats,
3920 static struct bin_attribute bin_attr_esw_stats = {
3921 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
3923 .read = qlcnic_sysfs_get_esw_stats,
3924 .write = qlcnic_sysfs_clear_esw_stats,
3927 static struct bin_attribute bin_attr_esw_config = {
3928 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
3930 .read = qlcnic_sysfs_read_esw_config,
3931 .write = qlcnic_sysfs_write_esw_config,
3934 static struct bin_attribute bin_attr_pm_config = {
3935 .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)},
3937 .read = qlcnic_sysfs_read_pm_config,
3938 .write = qlcnic_sysfs_write_pm_config,
3942 qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter)
3944 struct device *dev = &adapter->pdev->dev;
3946 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3947 if (device_create_file(dev, &dev_attr_bridged_mode))
3949 "failed to create bridged_mode sysfs entry\n");
3953 qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter)
3955 struct device *dev = &adapter->pdev->dev;
3957 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_BDG)
3958 device_remove_file(dev, &dev_attr_bridged_mode);
3962 qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
3964 struct device *dev = &adapter->pdev->dev;
3966 if (device_create_bin_file(dev, &bin_attr_port_stats))
3967 dev_info(dev, "failed to create port stats sysfs entry");
3969 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
3971 if (device_create_file(dev, &dev_attr_diag_mode))
3972 dev_info(dev, "failed to create diag_mode sysfs entry\n");
3973 if (device_create_bin_file(dev, &bin_attr_crb))
3974 dev_info(dev, "failed to create crb sysfs entry\n");
3975 if (device_create_bin_file(dev, &bin_attr_mem))
3976 dev_info(dev, "failed to create mem sysfs entry\n");
3977 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
3979 if (device_create_bin_file(dev, &bin_attr_esw_config))
3980 dev_info(dev, "failed to create esw config sysfs entry");
3981 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3983 if (device_create_bin_file(dev, &bin_attr_pci_config))
3984 dev_info(dev, "failed to create pci config sysfs entry");
3985 if (device_create_bin_file(dev, &bin_attr_npar_config))
3986 dev_info(dev, "failed to create npar config sysfs entry");
3987 if (device_create_bin_file(dev, &bin_attr_pm_config))
3988 dev_info(dev, "failed to create pm config sysfs entry");
3989 if (device_create_bin_file(dev, &bin_attr_esw_stats))
3990 dev_info(dev, "failed to create eswitch stats sysfs entry");
3994 qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
3996 struct device *dev = &adapter->pdev->dev;
3998 device_remove_bin_file(dev, &bin_attr_port_stats);
4000 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
4002 device_remove_file(dev, &dev_attr_diag_mode);
4003 device_remove_bin_file(dev, &bin_attr_crb);
4004 device_remove_bin_file(dev, &bin_attr_mem);
4005 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
4007 device_remove_bin_file(dev, &bin_attr_esw_config);
4008 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
4010 device_remove_bin_file(dev, &bin_attr_pci_config);
4011 device_remove_bin_file(dev, &bin_attr_npar_config);
4012 device_remove_bin_file(dev, &bin_attr_pm_config);
4013 device_remove_bin_file(dev, &bin_attr_esw_stats);
4018 #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
4021 qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4022 struct net_device *dev, unsigned long event)
4024 struct in_device *indev;
4026 indev = in_dev_get(dev);
4033 qlcnic_config_ipaddr(adapter,
4034 ifa->ifa_address, QLCNIC_IP_UP);
4037 qlcnic_config_ipaddr(adapter,
4038 ifa->ifa_address, QLCNIC_IP_DOWN);
4043 } endfor_ifa(indev);
4049 qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
4051 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4052 struct net_device *dev;
4055 qlcnic_config_indev_addr(adapter, netdev, event);
4057 if (!adapter->vlgrp)
4060 for (vid = 0; vid < VLAN_N_VID; vid++) {
4061 dev = vlan_group_get_device(adapter->vlgrp, vid);
4065 qlcnic_config_indev_addr(adapter, dev, event);
4069 static int qlcnic_netdev_event(struct notifier_block *this,
4070 unsigned long event, void *ptr)
4072 struct qlcnic_adapter *adapter;
4073 struct net_device *dev = (struct net_device *)ptr;
4079 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4080 dev = vlan_dev_real_dev(dev);
4084 if (!is_qlcnic_netdev(dev))
4087 adapter = netdev_priv(dev);
4092 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4095 qlcnic_config_indev_addr(adapter, dev, event);
4101 qlcnic_inetaddr_event(struct notifier_block *this,
4102 unsigned long event, void *ptr)
4104 struct qlcnic_adapter *adapter;
4105 struct net_device *dev;
4107 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4109 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
4115 if (dev->priv_flags & IFF_802_1Q_VLAN) {
4116 dev = vlan_dev_real_dev(dev);
4120 if (!is_qlcnic_netdev(dev))
4123 adapter = netdev_priv(dev);
4128 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
4133 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP);
4136 qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN);
4146 static struct notifier_block qlcnic_netdev_cb = {
4147 .notifier_call = qlcnic_netdev_event,
4150 static struct notifier_block qlcnic_inetaddr_cb = {
4151 .notifier_call = qlcnic_inetaddr_event,
4155 qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
4158 static struct pci_error_handlers qlcnic_err_handler = {
4159 .error_detected = qlcnic_io_error_detected,
4160 .slot_reset = qlcnic_io_slot_reset,
4161 .resume = qlcnic_io_resume,
4164 static struct pci_driver qlcnic_driver = {
4165 .name = qlcnic_driver_name,
4166 .id_table = qlcnic_pci_tbl,
4167 .probe = qlcnic_probe,
4168 .remove = __devexit_p(qlcnic_remove),
4170 .suspend = qlcnic_suspend,
4171 .resume = qlcnic_resume,
4173 .shutdown = qlcnic_shutdown,
4174 .err_handler = &qlcnic_err_handler
4178 static int __init qlcnic_init_module(void)
4182 printk(KERN_INFO "%s\n", qlcnic_driver_string);
4184 qlcnic_wq = create_singlethread_workqueue("qlcnic");
4185 if (qlcnic_wq == NULL) {
4186 printk(KERN_ERR "qlcnic: cannot create workqueue\n");
4191 register_netdevice_notifier(&qlcnic_netdev_cb);
4192 register_inetaddr_notifier(&qlcnic_inetaddr_cb);
4195 ret = pci_register_driver(&qlcnic_driver);
4198 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4199 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4201 destroy_workqueue(qlcnic_wq);
4207 module_init(qlcnic_init_module);
4209 static void __exit qlcnic_exit_module(void)
4212 pci_unregister_driver(&qlcnic_driver);
4215 unregister_inetaddr_notifier(&qlcnic_inetaddr_cb);
4216 unregister_netdevice_notifier(&qlcnic_netdev_cb);
4218 destroy_workqueue(qlcnic_wq);
4221 module_exit(qlcnic_exit_module);