From: Chad Dupuis <cdupuis@redhat.com> Date: Wed, 11 Aug 2010 17:33:04 -0400 Subject: [net] qlcnic: add AER support and miscellaneous fixes Message-id: <20100811172918.3299.82344.sendpatchset@localhost.localdomain> Patchwork-id: 27511 O-Subject: [RHEL 5.6 PATCH 3/3] qlcnic: Sync. with upstream part 3: add AER support and miscellaneous fixes. Bugzilla: 614281 Bugzilla ======== 614281 Description =========== This patch is part 3 of sync'ing the RHEL 5.6 qlcnic driver with the lateset upstream qlcnic driver. This patch has some minor fixes from upstream but the major feature being added here is PCIe AER support. This patch consists of the following fixes: qlcnic: driver private workqueue qlcnic: aer support qlcnic: restore NPAR config data after recovery qlcnic: fix tx csum setting qlcnic: fix pci resource leak Upstream Status =============== Commit ids from net-2.6. commit bfc978fa5f3005e5dfb39c52393c3339f4f00233 qlcnic: fix pci resource leak commit cea8975e84409f01fc4cf92775d2d0028ccc1665 qlcnic: restore NPAR config data after recovery commit 451724c821c1fe5af076a0def72362f947e1b6a0 qlcnic: aer support Signed-off-by: Jarod Wilson <jarod@redhat.com> diff --git a/drivers/net/qlcnic/qlcnic.h b/drivers/net/qlcnic/qlcnic.h index 6615785..d93b119 100644 --- a/drivers/net/qlcnic/qlcnic.h +++ b/drivers/net/qlcnic/qlcnic.h @@ -52,8 +52,8 @@ #define _QLCNIC_LINUX_MAJOR 5 #define _QLCNIC_LINUX_MINOR 0 -#define _QLCNIC_LINUX_SUBVERSION 6 -#define QLCNIC_LINUX_VERSIONID "5.0.6" +#define _QLCNIC_LINUX_SUBVERSION 7 +#define QLCNIC_LINUX_VERSIONID "5.0.7" #define QLCNIC_DRV_IDC_VER 0x01 #define QLCNIC_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c)) @@ -914,6 +914,7 @@ struct qlcnic_mac_req { #define __QLCNIC_DEV_UP 1 #define __QLCNIC_RESETTING 2 #define __QLCNIC_START_FW 4 +#define __QLCNIC_AER 5 #define QLCNIC_INTERRUPT_TEST 1 #define QLCNIC_LOOPBACK_TEST 2 @@ -951,7 +952,6 @@ struct qlcnic_adapter { u8 has_link_events; u8 fw_type; u16 tx_context_id; - u16 mtu; u16 is_up; u16 link_speed; @@ -1048,6 +1048,8 @@ struct qlcnic_pci_info { struct qlcnic_npar_info { u16 vlan_id; + u16 min_bw; + u16 max_bw; u8 phy_port; u8 type; u8 active; diff --git a/drivers/net/qlcnic/qlcnic_ctx.c b/drivers/net/qlcnic/qlcnic_ctx.c index cdd44b4..cc5d861 100644 --- a/drivers/net/qlcnic/qlcnic_ctx.c +++ b/drivers/net/qlcnic/qlcnic_ctx.c @@ -636,6 +636,8 @@ int qlcnic_get_nic_info(struct qlcnic_adapter *adapter, QLCNIC_CDRP_CMD_GET_NIC_INFO); if (err == QLCNIC_RCODE_SUCCESS) { + npar_info->pci_func = le16_to_cpu(nic_info->pci_func); + npar_info->op_mode = le16_to_cpu(nic_info->op_mode); npar_info->phys_port = le16_to_cpu(nic_info->phys_port); npar_info->switch_mode = le16_to_cpu(nic_info->switch_mode); npar_info->max_tx_ques = le16_to_cpu(nic_info->max_tx_ques); diff --git a/drivers/net/qlcnic/qlcnic_ethtool.c b/drivers/net/qlcnic/qlcnic_ethtool.c index f44889f..d0826dd 100644 --- a/drivers/net/qlcnic/qlcnic_ethtool.c +++ b/drivers/net/qlcnic/qlcnic_ethtool.c @@ -797,6 +797,15 @@ qlcnic_get_ethtool_stats(struct net_device *dev, } } +static int qlcnic_set_tx_csum(struct net_device *dev, u32 data) +{ + if (data) + dev->features |= (NETIF_F_IP_CSUM | NETIF_F_HW_CSUM); + else + dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_HW_CSUM); + return 0; +} + static u32 qlcnic_get_tx_csum(struct net_device *dev) { return dev->features & NETIF_F_IP_CSUM; @@ -1011,7 +1020,7 @@ struct ethtool_ops qlcnic_ethtool_ops = { .get_pauseparam = qlcnic_get_pauseparam, .set_pauseparam = qlcnic_set_pauseparam, .get_tx_csum = qlcnic_get_tx_csum, - .set_tx_csum = ethtool_op_set_tx_csum, + .set_tx_csum = qlcnic_set_tx_csum, .get_sg = ethtool_op_get_sg, .set_sg = ethtool_op_set_sg, .get_tso = qlcnic_get_tso, diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c index 98e7ffe..238c1fe 100644 --- a/drivers/net/qlcnic/qlcnic_main.c +++ b/drivers/net/qlcnic/qlcnic_main.c @@ -33,6 +33,7 @@ #include <linux/ipv6.h> #include <linux/inetdevice.h> #include <linux/sysfs.h> +#include <linux/aer.h> MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); MODULE_LICENSE("GPL"); @@ -43,6 +44,7 @@ char qlcnic_driver_name[] = "qlcnic"; static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; +static struct workqueue_struct *qlcnic_wq; static int port_mode = QLCNIC_PORT_MODE_AUTO_NEG; /* Default to restricted 1G auto-neg mode */ @@ -505,6 +507,8 @@ qlcnic_init_pci_info(struct qlcnic_adapter *adapter) adapter->npars[pfn].type = pci_info[i].type; adapter->npars[pfn].phy_port = pci_info[i].default_port; adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN; + adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; + adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; } for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) @@ -769,6 +773,50 @@ qlcnic_check_options(struct qlcnic_adapter *adapter) } static int +qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) +{ + int i, err = 0; + struct qlcnic_npar_info *npar; + struct qlcnic_info nic_info; + + if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || + !adapter->need_fw_reset) + return 0; + + if (adapter->op_mode == QLCNIC_MGMT_FUNC) { + /* Set the NPAR config data after FW reset */ + for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { + npar = &adapter->npars[i]; + if (npar->type != QLCNIC_TYPE_NIC) + continue; + err = qlcnic_get_nic_info(adapter, &nic_info, i); + if (err) + goto err_out; + nic_info.min_tx_bw = npar->min_bw; + nic_info.max_tx_bw = npar->max_bw; + err = qlcnic_set_nic_info(adapter, &nic_info); + if (err) + goto err_out; + + if (npar->enable_pm) { + err = qlcnic_config_port_mirroring(adapter, + npar->dest_npar, 1, i); + if (err) + goto err_out; + + } + npar->mac_learning = DEFAULT_MAC_LEARN; + npar->host_vlan_tag = 0; + npar->promisc_mode = 0; + npar->discard_tagged = 0; + npar->vlan_id = 0; + } + } +err_out: + return err; +} + +static int qlcnic_start_firmware(struct qlcnic_adapter *adapter) { int val, err, first_boot; @@ -832,10 +880,9 @@ wait_init: qlcnic_idc_debug_info(adapter, 1); qlcnic_check_options(adapter); - - if (adapter->flags & QLCNIC_ESWITCH_ENABLED && - adapter->op_mode != QLCNIC_NON_PRIV_FUNC) - qlcnic_dev_set_npar_ready(adapter); + if (qlcnic_reset_npar_config(adapter)) + goto err_out; + qlcnic_dev_set_npar_ready(adapter); adapter->need_fw_reset = 0; @@ -1311,6 +1358,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_out_disable_pdev; pci_set_master(pdev); + pci_enable_pcie_error_reporting(pdev); netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); if (!netdev) { @@ -1442,6 +1490,7 @@ static void __devexit qlcnic_remove(struct pci_dev *pdev) qlcnic_release_firmware(adapter); + pci_disable_pcie_error_reporting(pdev); pci_release_regions(pdev); pci_disable_device(pdev); pci_set_drvdata(pdev, NULL); @@ -2504,6 +2553,7 @@ qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) { u32 state; + adapter->need_fw_reset = 1; if (qlcnic_api_lock(adapter)) return; @@ -2524,6 +2574,9 @@ qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) { u32 state; + if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || + adapter->op_mode == QLCNIC_NON_PRIV_FUNC) + return; if (qlcnic_api_lock(adapter)) return; @@ -2542,8 +2595,12 @@ static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, work_func_t func, int delay) { + if (test_bit(__QLCNIC_AER, &adapter->state)) + return; + INIT_WORK(&adapter->fw_work, func, (void *)adapter); - schedule_delayed_work(&adapter->fw_work, round_jiffies_relative(delay)); + queue_delayed_work(qlcnic_wq, &adapter->fw_work, + round_jiffies_relative(delay)); } static void @@ -2552,7 +2609,7 @@ qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) msleep(10); - flush_scheduled_work(); + flush_workqueue(qlcnic_wq); cancel_delayed_work(&adapter->fw_work); } @@ -2650,6 +2707,135 @@ reschedule: qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); } +static int qlcnic_is_first_func(struct pci_dev *pdev) +{ + struct pci_dev *oth_pdev; + int val = pdev->devfn; + + while (val-- > 0) { + oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr + (pdev->bus), pdev->bus->number, + PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); + + if (!oth_pdev) + continue; + + if (oth_pdev->is_enabled) { + pci_dev_put(oth_pdev); + return 0; + } + pci_dev_put(oth_pdev); + } + return 1; +} + +static int qlcnic_attach_func(struct pci_dev *pdev) +{ + int err, first_func; + struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); + struct net_device *netdev = adapter->netdev; + + pdev->error_state = pci_channel_io_normal; + + err = pci_enable_device(pdev); + if (err) + return err; + + pci_set_power_state(pdev, PCI_D0); + pci_set_master(pdev); + pci_restore_state(pdev); + + first_func = qlcnic_is_first_func(pdev); + + if (qlcnic_api_lock(adapter)) + return -EINVAL; + + if (first_func) { + adapter->need_fw_reset = 1; + set_bit(__QLCNIC_START_FW, &adapter->state); + QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); + QLCDB(adapter, DRV, "Restarting fw\n"); + } + qlcnic_api_unlock(adapter); + + err = adapter->nic_ops->start_firmware(adapter); + if (err) + return err; + + qlcnic_clr_drv_state(adapter); + qlcnic_setup_intr(adapter); + + if (netif_running(netdev)) { + err = qlcnic_attach(adapter); + if (err) { + qlcnic_clr_all_drv_state(adapter); + clear_bit(__QLCNIC_AER, &adapter->state); + netif_device_attach(netdev); + return err; + } + + err = qlcnic_up(adapter, netdev); + if (err) + goto done; + + qlcnic_config_indev_addr(netdev, NETDEV_UP); + } + done: + netif_device_attach(netdev); + return err; +} + +static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, + pci_channel_state_t state) +{ + struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); + struct net_device *netdev = adapter->netdev; + + if (state == pci_channel_io_perm_failure) + return PCI_ERS_RESULT_DISCONNECT; + + if (state == pci_channel_io_normal) + return PCI_ERS_RESULT_RECOVERED; + + set_bit(__QLCNIC_AER, &adapter->state); + netif_device_detach(netdev); + + flush_workqueue(qlcnic_wq); + cancel_delayed_work(&adapter->fw_work); + + if (netif_running(netdev)) + qlcnic_down(adapter, netdev); + + qlcnic_detach(adapter); + qlcnic_teardown_intr(adapter); + + clear_bit(__QLCNIC_RESETTING, &adapter->state); + + pci_save_state(pdev); + pci_disable_device(pdev); + + return PCI_ERS_RESULT_NEED_RESET; +} + +static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) +{ + return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : + PCI_ERS_RESULT_RECOVERED; +} + +static void qlcnic_io_resume(struct pci_dev *pdev) +{ + struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); + + pci_cleanup_aer_uncorrect_error_status(pdev); + + if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && + test_and_clear_bit(__QLCNIC_AER, &adapter->state)) + qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, + FW_POLL_DELAY); +} + + int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) { char *tail; @@ -2930,7 +3116,7 @@ static struct bin_attribute bin_attr_mem = { .write = qlcnic_sysfs_write_mem, }; -int +static int validate_pm_config(struct qlcnic_adapter *adapter, struct qlcnic_pm_func_cfg *pm_cfg, int count) { @@ -3029,7 +3215,7 @@ qlcnic_sysfs_read_pm_config(struct kobject *kobj, return size; } -int +static int validate_esw_config(struct qlcnic_adapter *adapter, struct qlcnic_esw_func_cfg *esw_cfg, int count) { @@ -3065,9 +3251,8 @@ qlcnic_sysfs_write_esw_config(struct kobject *kobj, struct device *dev = container_of(kobj, struct device, kobj); struct qlcnic_adapter *adapter = dev_get_drvdata(dev); struct qlcnic_esw_func_cfg *esw_cfg; - u8 id, discard_tagged, promsc_mode, mac_learn; - u8 vlan_tagging, pci_func, vlan_id; int count, rem, i, ret; + u8 id, pci_func; count = size / sizeof(struct qlcnic_esw_func_cfg); rem = size % sizeof(struct qlcnic_esw_func_cfg); @@ -3082,17 +3267,13 @@ qlcnic_sysfs_write_esw_config(struct kobject *kobj, for (i = 0; i < count; i++) { pci_func = esw_cfg[i].pci_func; id = adapter->npars[pci_func].phy_port; - vlan_tagging = esw_cfg[i].host_vlan_tag; - promsc_mode = esw_cfg[i].promisc_mode; - mac_learn = esw_cfg[i].mac_learning; - vlan_id = esw_cfg[i].vlan_id; - discard_tagged = esw_cfg[i].discard_tagged; - ret = qlcnic_config_switch_port(adapter, id, vlan_tagging, - discard_tagged, - promsc_mode, - mac_learn, - pci_func, - vlan_id); + ret = qlcnic_config_switch_port(adapter, id, + esw_cfg[i].host_vlan_tag, + esw_cfg[i].discard_tagged, + esw_cfg[i].promisc_mode, + esw_cfg[i].mac_learning, + esw_cfg[i].pci_func, + esw_cfg[i].vlan_id); if (ret) return ret; } @@ -3138,7 +3319,7 @@ qlcnic_sysfs_read_esw_config(struct kobject *kobj, return size; } -int +static int validate_npar_config(struct qlcnic_adapter *adapter, struct qlcnic_npar_func_cfg *np_cfg, int count) { @@ -3193,6 +3374,8 @@ qlcnic_sysfs_write_npar_config(struct kobject *kobj, ret = qlcnic_set_nic_info(adapter, &nic_info); if (ret) return ret; + adapter->npars[i].min_bw = nic_info.min_tx_bw; + adapter->npars[i].max_bw = nic_info.max_tx_bw; } return size; @@ -3480,6 +3663,11 @@ static void qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) { } #endif +static struct pci_error_handlers qlcnic_err_handler = { + .error_detected = qlcnic_io_error_detected, + .slot_reset = qlcnic_io_slot_reset, + .resume = qlcnic_io_resume, +}; static struct pci_driver qlcnic_driver = { .name = qlcnic_driver_name, @@ -3490,7 +3678,9 @@ static struct pci_driver qlcnic_driver = { .suspend = qlcnic_suspend, .resume = qlcnic_resume, #endif - .shutdown = qlcnic_shutdown + .shutdown = qlcnic_shutdown, + .err_handler = &qlcnic_err_handler + }; static int __init qlcnic_init_module(void) @@ -3499,6 +3689,12 @@ static int __init qlcnic_init_module(void) printk(KERN_INFO "%s\n", qlcnic_driver_string); + qlcnic_wq = create_singlethread_workqueue("qlcnic"); + if (qlcnic_wq == NULL) { + printk(KERN_ERR "Cannot create workqueue\n"); + return -ENOMEM; + } + #ifdef CONFIG_INET register_netdevice_notifier(&qlcnic_netdev_cb); register_inetaddr_notifier(&qlcnic_inetaddr_cb); @@ -3510,6 +3706,7 @@ static int __init qlcnic_init_module(void) unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); unregister_netdevice_notifier(&qlcnic_netdev_cb); #endif + destroy_workqueue(qlcnic_wq); } return ret; @@ -3526,6 +3723,7 @@ static void __exit qlcnic_exit_module(void) unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); unregister_netdevice_notifier(&qlcnic_netdev_cb); #endif + destroy_workqueue(qlcnic_wq); } module_exit(qlcnic_exit_module);