Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1 | /* |
Sritej Velaga | 40839129f | 2010-12-02 20:41:56 +0000 | [diff] [blame] | 2 | * QLogic qlcnic NIC Driver |
| 3 | * Copyright (c) 2009-2010 QLogic Corporation |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 4 | * |
Sritej Velaga | 40839129f | 2010-12-02 20:41:56 +0000 | [diff] [blame] | 5 | * See LICENSE.qlcnic for copyright and licensing details. |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 9 | #include <linux/vmalloc.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | |
| 12 | #include "qlcnic.h" |
| 13 | |
Sucheta Chakraborty | 7e56cac | 2010-10-04 04:20:13 +0000 | [diff] [blame] | 14 | #include <linux/swab.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 15 | #include <linux/dma-mapping.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 16 | #include <net/ip.h> |
| 17 | #include <linux/ipv6.h> |
| 18 | #include <linux/inetdevice.h> |
| 19 | #include <linux/sysfs.h> |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 20 | #include <linux/aer.h> |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 21 | #include <linux/log2.h> |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 22 | |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 23 | MODULE_DESCRIPTION("QLogic 1/10 GbE Converged/Intelligent Ethernet Driver"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 24 | MODULE_LICENSE("GPL"); |
| 25 | MODULE_VERSION(QLCNIC_LINUX_VERSIONID); |
| 26 | MODULE_FIRMWARE(QLCNIC_UNIFIED_ROMIMAGE_NAME); |
| 27 | |
| 28 | char qlcnic_driver_name[] = "qlcnic"; |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 29 | static const char qlcnic_driver_string[] = "QLogic 1/10 GbE " |
| 30 | "Converged/Intelligent Ethernet Driver v" QLCNIC_LINUX_VERSIONID; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 31 | |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 32 | static struct workqueue_struct *qlcnic_wq; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 33 | static int qlcnic_mac_learn; |
amit salecha | b11a25a | 2011-01-10 00:15:23 +0000 | [diff] [blame] | 34 | module_param(qlcnic_mac_learn, int, 0444); |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 35 | MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)"); |
| 36 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 37 | static int use_msi = 1; |
amit salecha | b11a25a | 2011-01-10 00:15:23 +0000 | [diff] [blame] | 38 | module_param(use_msi, int, 0444); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 39 | MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); |
| 40 | |
| 41 | static int use_msi_x = 1; |
amit salecha | b11a25a | 2011-01-10 00:15:23 +0000 | [diff] [blame] | 42 | module_param(use_msi_x, int, 0444); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 43 | MODULE_PARM_DESC(use_msi_x, "MSI-X interrupt (0=disabled, 1=enabled"); |
| 44 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 45 | static int auto_fw_reset = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 46 | module_param(auto_fw_reset, int, 0644); |
| 47 | MODULE_PARM_DESC(auto_fw_reset, "Auto firmware reset (0=disabled, 1=enabled"); |
| 48 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 49 | static int load_fw_file; |
amit salecha | b11a25a | 2011-01-10 00:15:23 +0000 | [diff] [blame] | 50 | module_param(load_fw_file, int, 0444); |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 51 | MODULE_PARM_DESC(load_fw_file, "Load firmware from (0=flash, 1=file"); |
| 52 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 53 | static int qlcnic_config_npars; |
amit salecha | b11a25a | 2011-01-10 00:15:23 +0000 | [diff] [blame] | 54 | module_param(qlcnic_config_npars, int, 0444); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 55 | MODULE_PARM_DESC(qlcnic_config_npars, "Configure NPARs (0=disabled, 1=enabled"); |
| 56 | |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame^] | 57 | static int qlcnic_probe(struct pci_dev *pdev, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 58 | const struct pci_device_id *ent); |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame^] | 59 | static void qlcnic_remove(struct pci_dev *pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 60 | static int qlcnic_open(struct net_device *netdev); |
| 61 | static int qlcnic_close(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 62 | static void qlcnic_tx_timeout(struct net_device *netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 63 | static void qlcnic_attach_work(struct work_struct *work); |
| 64 | static void qlcnic_fwinit_work(struct work_struct *work); |
| 65 | static void qlcnic_fw_poll_work(struct work_struct *work); |
| 66 | static void qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 67 | work_func_t func, int delay); |
| 68 | static void qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 70 | static void qlcnic_poll_controller(struct net_device *netdev); |
| 71 | #endif |
| 72 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 73 | static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 74 | static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 75 | static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); |
| 76 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 77 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 78 | static irqreturn_t qlcnic_intr(int irq, void *data); |
| 79 | static irqreturn_t qlcnic_msi_intr(int irq, void *data); |
| 80 | static irqreturn_t qlcnic_msix_intr(int irq, void *data); |
| 81 | |
| 82 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 83 | static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 84 | static int qlcnic_start_firmware(struct qlcnic_adapter *); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 85 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 86 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 87 | static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 88 | static int qlcnicvf_start_firmware(struct qlcnic_adapter *); |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 89 | static void qlcnic_set_netdev_features(struct qlcnic_adapter *, |
| 90 | struct qlcnic_esw_func_cfg *); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 91 | static int qlcnic_vlan_rx_add(struct net_device *, u16); |
| 92 | static int qlcnic_vlan_rx_del(struct net_device *, u16); |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 93 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 94 | /* PCI Device ID Table */ |
| 95 | #define ENTRY(device) \ |
| 96 | {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ |
| 97 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, .class_mask = ~0} |
| 98 | |
| 99 | #define PCI_DEVICE_ID_QLOGIC_QLE824X 0x8020 |
| 100 | |
Amit Kumar Salecha | 6a90288 | 2010-02-01 05:24:54 +0000 | [diff] [blame] | 101 | static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 102 | ENTRY(PCI_DEVICE_ID_QLOGIC_QLE824X), |
| 103 | {0,} |
| 104 | }; |
| 105 | |
| 106 | MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); |
| 107 | |
| 108 | |
Sony Chacko | 5ad6ff9 | 2012-11-17 21:04:38 +0000 | [diff] [blame] | 109 | inline void qlcnic_update_cmd_producer(struct qlcnic_host_tx_ring *tx_ring) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 110 | { |
| 111 | writel(tx_ring->producer, tx_ring->crb_cmd_producer); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static const u32 msi_tgt_status[8] = { |
| 115 | ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, |
| 116 | ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, |
| 117 | ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, |
| 118 | ISR_INT_TARGET_STATUS_F6, ISR_INT_TARGET_STATUS_F7 |
| 119 | }; |
| 120 | |
| 121 | static const |
| 122 | struct qlcnic_legacy_intr_set legacy_intr[] = QLCNIC_LEGACY_INTR_CONFIG; |
| 123 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 124 | int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 125 | { |
| 126 | int size = sizeof(struct qlcnic_host_sds_ring) * count; |
| 127 | |
| 128 | recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); |
| 129 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 130 | return recv_ctx->sds_rings == NULL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Sony Chacko | c70001a | 2012-11-28 04:34:26 +0000 | [diff] [blame] | 133 | void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 134 | { |
| 135 | if (recv_ctx->sds_rings != NULL) |
| 136 | kfree(recv_ctx->sds_rings); |
| 137 | |
| 138 | recv_ctx->sds_rings = NULL; |
| 139 | } |
| 140 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 141 | static void qlcnic_clear_stats(struct qlcnic_adapter *adapter) |
| 142 | { |
| 143 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 146 | static void qlcnic_set_msix_bit(struct pci_dev *pdev, int enable) |
| 147 | { |
| 148 | u32 control; |
| 149 | int pos; |
| 150 | |
| 151 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 152 | if (pos) { |
| 153 | pci_read_config_dword(pdev, pos, &control); |
| 154 | if (enable) |
| 155 | control |= PCI_MSIX_FLAGS_ENABLE; |
| 156 | else |
| 157 | control = 0; |
| 158 | pci_write_config_dword(pdev, pos, control); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static void qlcnic_init_msix_entries(struct qlcnic_adapter *adapter, int count) |
| 163 | { |
| 164 | int i; |
| 165 | |
| 166 | for (i = 0; i < count; i++) |
| 167 | adapter->msix_entries[i].entry = i; |
| 168 | } |
| 169 | |
| 170 | static int |
| 171 | qlcnic_read_mac_addr(struct qlcnic_adapter *adapter) |
| 172 | { |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 173 | u8 mac_addr[ETH_ALEN]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 174 | struct net_device *netdev = adapter->netdev; |
| 175 | struct pci_dev *pdev = adapter->pdev; |
| 176 | |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 177 | if (qlcnic_get_mac_address(adapter, mac_addr) != 0) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 178 | return -EIO; |
| 179 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 180 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 181 | memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len); |
| 182 | memcpy(adapter->mac_addr, netdev->dev_addr, netdev->addr_len); |
| 183 | |
| 184 | /* set station address */ |
| 185 | |
| 186 | if (!is_valid_ether_addr(netdev->perm_addr)) |
| 187 | dev_warn(&pdev->dev, "Bad MAC address %pM.\n", |
| 188 | netdev->dev_addr); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int qlcnic_set_mac(struct net_device *netdev, void *p) |
| 194 | { |
| 195 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 196 | struct sockaddr *addr = p; |
| 197 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 198 | if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED)) |
| 199 | return -EOPNOTSUPP; |
| 200 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 201 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 202 | return -EADDRNOTAVAIL; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 203 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 204 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 205 | netif_device_detach(netdev); |
| 206 | qlcnic_napi_disable(adapter); |
| 207 | } |
| 208 | |
| 209 | memcpy(adapter->mac_addr, addr->sa_data, netdev->addr_len); |
| 210 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 211 | qlcnic_set_multi(adapter->netdev); |
| 212 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 213 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 214 | netif_device_attach(netdev); |
| 215 | qlcnic_napi_enable(adapter); |
| 216 | } |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static const struct net_device_ops qlcnic_netdev_ops = { |
| 221 | .ndo_open = qlcnic_open, |
| 222 | .ndo_stop = qlcnic_close, |
| 223 | .ndo_start_xmit = qlcnic_xmit_frame, |
| 224 | .ndo_get_stats = qlcnic_get_stats, |
| 225 | .ndo_validate_addr = eth_validate_addr, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 226 | .ndo_set_rx_mode = qlcnic_set_multi, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 227 | .ndo_set_mac_address = qlcnic_set_mac, |
| 228 | .ndo_change_mtu = qlcnic_change_mtu, |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 229 | .ndo_fix_features = qlcnic_fix_features, |
| 230 | .ndo_set_features = qlcnic_set_features, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 231 | .ndo_tx_timeout = qlcnic_tx_timeout, |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 232 | .ndo_vlan_rx_add_vid = qlcnic_vlan_rx_add, |
| 233 | .ndo_vlan_rx_kill_vid = qlcnic_vlan_rx_del, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 234 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 235 | .ndo_poll_controller = qlcnic_poll_controller, |
| 236 | #endif |
| 237 | }; |
| 238 | |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 239 | static const struct net_device_ops qlcnic_netdev_failed_ops = { |
| 240 | .ndo_open = qlcnic_open, |
| 241 | }; |
| 242 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 243 | static struct qlcnic_nic_template qlcnic_ops = { |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 244 | .config_bridged_mode = qlcnic_config_bridged_mode, |
| 245 | .config_led = qlcnic_config_led, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 246 | .start_firmware = qlcnic_start_firmware |
| 247 | }; |
| 248 | |
| 249 | static struct qlcnic_nic_template qlcnic_vf_ops = { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 250 | .config_bridged_mode = qlcnicvf_config_bridged_mode, |
| 251 | .config_led = qlcnicvf_config_led, |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 252 | .start_firmware = qlcnicvf_start_firmware |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 255 | static int qlcnic_enable_msix(struct qlcnic_adapter *adapter, u32 num_msix) |
| 256 | { |
| 257 | struct pci_dev *pdev = adapter->pdev; |
| 258 | int err = -1; |
| 259 | |
| 260 | adapter->max_sds_rings = 1; |
| 261 | adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); |
| 262 | qlcnic_set_msix_bit(pdev, 0); |
| 263 | |
| 264 | if (adapter->msix_supported) { |
| 265 | enable_msix: |
| 266 | qlcnic_init_msix_entries(adapter, num_msix); |
| 267 | err = pci_enable_msix(pdev, adapter->msix_entries, num_msix); |
| 268 | if (err == 0) { |
| 269 | adapter->flags |= QLCNIC_MSIX_ENABLED; |
| 270 | qlcnic_set_msix_bit(pdev, 1); |
| 271 | |
| 272 | adapter->max_sds_rings = num_msix; |
| 273 | |
| 274 | dev_info(&pdev->dev, "using msi-x interrupts\n"); |
| 275 | return err; |
| 276 | } |
| 277 | if (err > 0) { |
| 278 | num_msix = rounddown_pow_of_two(err); |
| 279 | if (num_msix) |
| 280 | goto enable_msix; |
| 281 | } |
| 282 | } |
| 283 | return err; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | static void qlcnic_enable_msi_legacy(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 288 | { |
| 289 | const struct qlcnic_legacy_intr_set *legacy_intrp; |
| 290 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 291 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 292 | if (use_msi && !pci_enable_msi(pdev)) { |
| 293 | adapter->flags |= QLCNIC_MSI_ENABLED; |
| 294 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 295 | msi_tgt_status[adapter->ahw->pci_func]); |
| 296 | dev_info(&pdev->dev, "using msi interrupts\n"); |
| 297 | adapter->msix_entries[0].vector = pdev->irq; |
| 298 | return; |
| 299 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 300 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 301 | legacy_intrp = &legacy_intr[adapter->ahw->pci_func]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 302 | |
| 303 | adapter->int_vec_bit = legacy_intrp->int_vec_bit; |
| 304 | adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, |
| 305 | legacy_intrp->tgt_status_reg); |
| 306 | adapter->tgt_mask_reg = qlcnic_get_ioaddr(adapter, |
| 307 | legacy_intrp->tgt_mask_reg); |
| 308 | adapter->isr_int_vec = qlcnic_get_ioaddr(adapter, ISR_INT_VECTOR); |
| 309 | |
| 310 | adapter->crb_int_state_reg = qlcnic_get_ioaddr(adapter, |
| 311 | ISR_INT_STATE_REG); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 312 | dev_info(&pdev->dev, "using legacy interrupts\n"); |
| 313 | adapter->msix_entries[0].vector = pdev->irq; |
| 314 | } |
| 315 | |
| 316 | static void |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 317 | qlcnic_setup_intr(struct qlcnic_adapter *adapter) |
| 318 | { |
| 319 | int num_msix; |
| 320 | |
| 321 | if (adapter->msix_supported) { |
Sucheta Chakraborty | 5f6ec29 | 2011-06-22 02:52:20 +0000 | [diff] [blame] | 322 | num_msix = rounddown_pow_of_two(min_t(int, num_online_cpus(), |
| 323 | QLCNIC_DEF_NUM_STS_DESC_RINGS)); |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 324 | } else |
| 325 | num_msix = 1; |
| 326 | |
| 327 | if (!qlcnic_enable_msix(adapter, num_msix)) |
| 328 | return; |
| 329 | |
| 330 | qlcnic_enable_msi_legacy(adapter); |
| 331 | } |
| 332 | |
| 333 | static void |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 334 | qlcnic_teardown_intr(struct qlcnic_adapter *adapter) |
| 335 | { |
| 336 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 337 | pci_disable_msix(adapter->pdev); |
| 338 | if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 339 | pci_disable_msi(adapter->pdev); |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) |
| 344 | { |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 345 | if (adapter->ahw->pci_base0 != NULL) |
| 346 | iounmap(adapter->ahw->pci_base0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 349 | static int |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 350 | qlcnic_init_pci_info(struct qlcnic_adapter *adapter) |
| 351 | { |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 352 | struct qlcnic_pci_info *pci_info; |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 353 | int i, ret = 0; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 354 | u8 pfn; |
| 355 | |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 356 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
| 357 | if (!pci_info) |
| 358 | return -ENOMEM; |
| 359 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 360 | adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 361 | QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 362 | if (!adapter->npars) { |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 363 | ret = -ENOMEM; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 364 | goto err_pci_info; |
| 365 | } |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 366 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 367 | adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 368 | QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); |
| 369 | if (!adapter->eswitch) { |
Julia Lawall | 900853a | 2010-08-16 10:23:51 +0000 | [diff] [blame] | 370 | ret = -ENOMEM; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 371 | goto err_npars; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | ret = qlcnic_get_pci_info(adapter, pci_info); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 375 | if (ret) |
| 376 | goto err_eswitch; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 377 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 378 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 379 | pfn = pci_info[i].id; |
Dan Carpenter | 0f6efff9 | 2012-06-14 08:34:24 +0000 | [diff] [blame] | 380 | if (pfn >= QLCNIC_MAX_PCI_FUNC) { |
Sony Chacko | f848d6d | 2011-04-01 14:27:59 +0000 | [diff] [blame] | 381 | ret = QL_STATUS_INVALID_PARAM; |
| 382 | goto err_eswitch; |
| 383 | } |
Sucheta Chakraborty | a1c0c45 | 2010-10-04 04:20:14 +0000 | [diff] [blame] | 384 | adapter->npars[pfn].active = (u8)pci_info[i].active; |
| 385 | adapter->npars[pfn].type = (u8)pci_info[i].type; |
| 386 | adapter->npars[pfn].phy_port = (u8)pci_info[i].default_port; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 387 | adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; |
| 388 | adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 391 | for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++) |
| 392 | adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE; |
| 393 | |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 394 | kfree(pci_info); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 395 | return 0; |
| 396 | |
| 397 | err_eswitch: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 398 | kfree(adapter->eswitch); |
| 399 | adapter->eswitch = NULL; |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 400 | err_npars: |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 401 | kfree(adapter->npars); |
Dan Carpenter | ca315ac | 2010-08-09 21:47:56 +0000 | [diff] [blame] | 402 | adapter->npars = NULL; |
Dan Carpenter | e88db3b | 2010-08-09 21:49:36 +0000 | [diff] [blame] | 403 | err_pci_info: |
| 404 | kfree(pci_info); |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 405 | |
| 406 | return ret; |
| 407 | } |
| 408 | |
| 409 | static int |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 410 | qlcnic_set_function_modes(struct qlcnic_adapter *adapter) |
| 411 | { |
| 412 | u8 id; |
| 413 | u32 ref_count; |
| 414 | int i, ret = 1; |
| 415 | u32 data = QLCNIC_MGMT_FUNC; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 416 | void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 417 | |
| 418 | /* If other drivers are not in use set their privilege level */ |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 419 | ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 420 | ret = qlcnic_api_lock(adapter); |
| 421 | if (ret) |
| 422 | goto err_lock; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 423 | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 424 | if (qlcnic_config_npars) { |
| 425 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Rajesh K Borundia | 346fe76 | 2010-06-29 08:01:20 +0000 | [diff] [blame] | 426 | id = i; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 427 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC || |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 428 | id == adapter->ahw->pci_func) |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 429 | continue; |
| 430 | data |= (qlcnic_config_npars & |
| 431 | QLC_DEV_SET_DRV(0xf, id)); |
| 432 | } |
| 433 | } else { |
| 434 | data = readl(priv_op); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 435 | data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) | |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 436 | (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 437 | adapter->ahw->pci_func)); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 438 | } |
| 439 | writel(data, priv_op); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 440 | qlcnic_api_unlock(adapter); |
| 441 | err_lock: |
| 442 | return ret; |
| 443 | } |
| 444 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 445 | static void |
| 446 | qlcnic_check_vf(struct qlcnic_adapter *adapter) |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 447 | { |
| 448 | void __iomem *msix_base_addr; |
| 449 | void __iomem *priv_op; |
| 450 | u32 func; |
| 451 | u32 msix_base; |
| 452 | u32 op_mode, priv_level; |
| 453 | |
| 454 | /* Determine FW API version */ |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 455 | adapter->fw_hal_version = readl(adapter->ahw->pci_base0 + |
| 456 | QLCNIC_FW_API); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 457 | |
| 458 | /* Find PCI function number */ |
| 459 | pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 460 | msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 461 | msix_base = readl(msix_base_addr); |
| 462 | func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 463 | adapter->ahw->pci_func = func; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 464 | |
| 465 | /* Determine function privilege level */ |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 466 | priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 467 | op_mode = readl(priv_op); |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 468 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 469 | priv_level = QLCNIC_MGMT_FUNC; |
Anirban Chakraborty | 0e33c66 | 2010-06-16 09:07:27 +0000 | [diff] [blame] | 470 | else |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 471 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 472 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 473 | if (priv_level == QLCNIC_NON_PRIV_FUNC) { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 474 | adapter->op_mode = QLCNIC_NON_PRIV_FUNC; |
| 475 | dev_info(&adapter->pdev->dev, |
| 476 | "HAL Version: %d Non Privileged function\n", |
| 477 | adapter->fw_hal_version); |
| 478 | adapter->nic_ops = &qlcnic_vf_ops; |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 479 | } else |
| 480 | adapter->nic_ops = &qlcnic_ops; |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 483 | static int |
| 484 | qlcnic_setup_pci_map(struct qlcnic_adapter *adapter) |
| 485 | { |
| 486 | void __iomem *mem_ptr0 = NULL; |
| 487 | resource_size_t mem_base; |
| 488 | unsigned long mem_len, pci_len0 = 0; |
| 489 | |
| 490 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 491 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 492 | /* remap phys address */ |
| 493 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 494 | mem_len = pci_resource_len(pdev, 0); |
| 495 | |
| 496 | if (mem_len == QLCNIC_PCI_2MB_SIZE) { |
| 497 | |
| 498 | mem_ptr0 = pci_ioremap_bar(pdev, 0); |
| 499 | if (mem_ptr0 == NULL) { |
| 500 | dev_err(&pdev->dev, "failed to map PCI bar 0\n"); |
| 501 | return -EIO; |
| 502 | } |
| 503 | pci_len0 = mem_len; |
| 504 | } else { |
| 505 | return -EIO; |
| 506 | } |
| 507 | |
| 508 | dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); |
| 509 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 510 | adapter->ahw->pci_base0 = mem_ptr0; |
| 511 | adapter->ahw->pci_len0 = pci_len0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 512 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 513 | qlcnic_check_vf(adapter); |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 514 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 515 | adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter, |
| 516 | QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG( |
| 517 | adapter->ahw->pci_func))); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static void get_brd_name(struct qlcnic_adapter *adapter, char *name) |
| 523 | { |
| 524 | struct pci_dev *pdev = adapter->pdev; |
| 525 | int i, found = 0; |
| 526 | |
| 527 | for (i = 0; i < NUM_SUPPORTED_BOARDS; ++i) { |
| 528 | if (qlcnic_boards[i].vendor == pdev->vendor && |
| 529 | qlcnic_boards[i].device == pdev->device && |
| 530 | qlcnic_boards[i].sub_vendor == pdev->subsystem_vendor && |
| 531 | qlcnic_boards[i].sub_device == pdev->subsystem_device) { |
Sucheta Chakraborty | 02f6e46 | 2010-05-17 01:22:09 +0000 | [diff] [blame] | 532 | sprintf(name, "%pM: %s" , |
| 533 | adapter->mac_addr, |
| 534 | qlcnic_boards[i].short_name); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 535 | found = 1; |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | } |
| 540 | |
| 541 | if (!found) |
Sritej Velaga | 7f9a0c3 | 2010-06-17 02:56:39 +0000 | [diff] [blame] | 542 | sprintf(name, "%pM Gigabit Ethernet", adapter->mac_addr); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static void |
| 546 | qlcnic_check_options(struct qlcnic_adapter *adapter) |
| 547 | { |
Sritej Velaga | 031a4a2 | 2011-07-29 13:30:28 +0000 | [diff] [blame] | 548 | u32 fw_major, fw_minor, fw_build, prev_fw_version; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 549 | struct pci_dev *pdev = adapter->pdev; |
Sritej Velaga | 031a4a2 | 2011-07-29 13:30:28 +0000 | [diff] [blame] | 550 | struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump; |
| 551 | |
| 552 | prev_fw_version = adapter->fw_version; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 553 | |
| 554 | fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); |
| 555 | fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); |
| 556 | fw_build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB); |
| 557 | |
| 558 | adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); |
| 559 | |
Sritej Velaga | 031a4a2 | 2011-07-29 13:30:28 +0000 | [diff] [blame] | 560 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC) { |
| 561 | if (fw_dump->tmpl_hdr == NULL || |
| 562 | adapter->fw_version > prev_fw_version) { |
| 563 | if (fw_dump->tmpl_hdr) |
| 564 | vfree(fw_dump->tmpl_hdr); |
| 565 | if (!qlcnic_fw_cmd_get_minidump_temp(adapter)) |
| 566 | dev_info(&pdev->dev, |
| 567 | "Supports FW dump capability\n"); |
| 568 | } |
| 569 | } |
| 570 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 571 | dev_info(&pdev->dev, "firmware v%d.%d.%d\n", |
| 572 | fw_major, fw_minor, fw_build); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 573 | if (adapter->ahw->port_type == QLCNIC_XGBE) { |
Sony Chacko | 90d1900 | 2010-10-26 17:53:08 +0000 | [diff] [blame] | 574 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { |
| 575 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; |
| 576 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; |
| 577 | } else { |
| 578 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_10G; |
| 579 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_10G; |
| 580 | } |
| 581 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 582 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
Sony Chacko | 90d1900 | 2010-10-26 17:53:08 +0000 | [diff] [blame] | 583 | adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; |
| 584 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 585 | } else if (adapter->ahw->port_type == QLCNIC_GBE) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 586 | adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; |
| 587 | adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
Sony Chacko | 90d1900 | 2010-10-26 17:53:08 +0000 | [diff] [blame] | 588 | adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; |
| 589 | adapter->max_rxd = MAX_RCV_DESCRIPTORS_1G; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | adapter->msix_supported = !!use_msi_x; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 593 | |
| 594 | adapter->num_txd = MAX_CMD_DESCRIPTORS; |
| 595 | |
Sony Chacko | 251b036 | 2010-08-19 05:08:24 +0000 | [diff] [blame] | 596 | adapter->max_rds_rings = MAX_RDS_RINGS; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 599 | static int |
| 600 | qlcnic_initialize_nic(struct qlcnic_adapter *adapter) |
| 601 | { |
| 602 | int err; |
| 603 | struct qlcnic_info nic_info; |
| 604 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 605 | err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func); |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 606 | if (err) |
| 607 | return err; |
| 608 | |
Sucheta Chakraborty | a1c0c45 | 2010-10-04 04:20:14 +0000 | [diff] [blame] | 609 | adapter->physical_port = (u8)nic_info.phys_port; |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 610 | adapter->switch_mode = nic_info.switch_mode; |
| 611 | adapter->max_tx_ques = nic_info.max_tx_ques; |
| 612 | adapter->max_rx_ques = nic_info.max_rx_ques; |
| 613 | adapter->capabilities = nic_info.capabilities; |
| 614 | adapter->max_mac_filters = nic_info.max_mac_filters; |
| 615 | adapter->max_mtu = nic_info.max_mtu; |
| 616 | |
| 617 | if (adapter->capabilities & BIT_6) |
| 618 | adapter->flags |= QLCNIC_ESWITCH_ENABLED; |
| 619 | else |
| 620 | adapter->flags &= ~QLCNIC_ESWITCH_ENABLED; |
| 621 | |
| 622 | return err; |
| 623 | } |
| 624 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 625 | void qlcnic_set_vlan_config(struct qlcnic_adapter *adapter, |
| 626 | struct qlcnic_esw_func_cfg *esw_cfg) |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 627 | { |
| 628 | if (esw_cfg->discard_tagged) |
| 629 | adapter->flags &= ~QLCNIC_TAGGING_ENABLED; |
| 630 | else |
| 631 | adapter->flags |= QLCNIC_TAGGING_ENABLED; |
| 632 | |
| 633 | if (esw_cfg->vlan_id) |
| 634 | adapter->pvid = esw_cfg->vlan_id; |
| 635 | else |
| 636 | adapter->pvid = 0; |
| 637 | } |
| 638 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 639 | static int |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 640 | qlcnic_vlan_rx_add(struct net_device *netdev, u16 vid) |
| 641 | { |
| 642 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 643 | set_bit(vid, adapter->vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 644 | return 0; |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 647 | static int |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 648 | qlcnic_vlan_rx_del(struct net_device *netdev, u16 vid) |
| 649 | { |
| 650 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 651 | |
| 652 | qlcnic_restore_indev_addr(netdev, NETDEV_DOWN); |
| 653 | clear_bit(vid, adapter->vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 654 | return 0; |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 657 | void qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter, |
| 658 | struct qlcnic_esw_func_cfg *esw_cfg) |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 659 | { |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 660 | adapter->flags &= ~(QLCNIC_MACSPOOF | QLCNIC_MAC_OVERRIDE_DISABLED | |
| 661 | QLCNIC_PROMISC_DISABLED); |
Rajesh Borundia | 7613c87 | 2010-08-31 17:17:48 +0000 | [diff] [blame] | 662 | |
| 663 | if (esw_cfg->mac_anti_spoof) |
| 664 | adapter->flags |= QLCNIC_MACSPOOF; |
Sony Chacko | fe4d434 | 2010-08-19 05:08:27 +0000 | [diff] [blame] | 665 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 666 | if (!esw_cfg->mac_override) |
| 667 | adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED; |
| 668 | |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 669 | if (!esw_cfg->promisc_mode) |
| 670 | adapter->flags |= QLCNIC_PROMISC_DISABLED; |
| 671 | |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 672 | qlcnic_set_netdev_features(adapter, esw_cfg); |
| 673 | } |
| 674 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 675 | static int qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter) |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 676 | { |
| 677 | struct qlcnic_esw_func_cfg esw_cfg; |
| 678 | |
| 679 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 680 | return 0; |
| 681 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 682 | esw_cfg.pci_func = adapter->ahw->pci_func; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 683 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) |
| 684 | return -EIO; |
Amit Kumar Salecha | 8cf61f8 | 2010-08-25 04:03:03 +0000 | [diff] [blame] | 685 | qlcnic_set_vlan_config(adapter, &esw_cfg); |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 686 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg); |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static void |
| 692 | qlcnic_set_netdev_features(struct qlcnic_adapter *adapter, |
| 693 | struct qlcnic_esw_func_cfg *esw_cfg) |
| 694 | { |
| 695 | struct net_device *netdev = adapter->netdev; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 696 | netdev_features_t features, vlan_features; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 697 | |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 698 | features = (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM | |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 699 | NETIF_F_IPV6_CSUM | NETIF_F_GRO); |
| 700 | vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM | |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 701 | NETIF_F_IPV6_CSUM | NETIF_F_HW_VLAN_FILTER); |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 702 | |
| 703 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) { |
| 704 | features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 705 | vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6); |
| 706 | } |
Rajesh Borundia | b56421d | 2011-04-01 14:28:31 +0000 | [diff] [blame] | 707 | |
| 708 | if (netdev->features & NETIF_F_LRO) |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 709 | features |= NETIF_F_LRO; |
| 710 | |
| 711 | if (esw_cfg->offload_flags & BIT_0) { |
| 712 | netdev->features |= features; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 713 | if (!(esw_cfg->offload_flags & BIT_1)) |
| 714 | netdev->features &= ~NETIF_F_TSO; |
| 715 | if (!(esw_cfg->offload_flags & BIT_2)) |
| 716 | netdev->features &= ~NETIF_F_TSO6; |
| 717 | } else { |
| 718 | netdev->features &= ~features; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | netdev->vlan_features = (features & vlan_features); |
| 722 | } |
| 723 | |
| 724 | static int |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 725 | qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter) |
| 726 | { |
| 727 | void __iomem *priv_op; |
| 728 | u32 op_mode, priv_level; |
| 729 | int err = 0; |
| 730 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 731 | err = qlcnic_initialize_nic(adapter); |
| 732 | if (err) |
| 733 | return err; |
| 734 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 735 | if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) |
| 736 | return 0; |
| 737 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 738 | priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE; |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 739 | op_mode = readl(priv_op); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 740 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 741 | |
| 742 | if (op_mode == QLC_DEV_DRV_DEFAULT) |
| 743 | priv_level = QLCNIC_MGMT_FUNC; |
| 744 | else |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 745 | priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func); |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 746 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 747 | if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 748 | if (priv_level == QLCNIC_MGMT_FUNC) { |
| 749 | adapter->op_mode = QLCNIC_MGMT_FUNC; |
| 750 | err = qlcnic_init_pci_info(adapter); |
| 751 | if (err) |
| 752 | return err; |
| 753 | /* Set privilege level for other functions */ |
| 754 | qlcnic_set_function_modes(adapter); |
| 755 | dev_info(&adapter->pdev->dev, |
| 756 | "HAL Version: %d, Management function\n", |
| 757 | adapter->fw_hal_version); |
| 758 | } else if (priv_level == QLCNIC_PRIV_FUNC) { |
| 759 | adapter->op_mode = QLCNIC_PRIV_FUNC; |
| 760 | dev_info(&adapter->pdev->dev, |
| 761 | "HAL Version: %d, Privileged function\n", |
| 762 | adapter->fw_hal_version); |
| 763 | } |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 764 | } |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 765 | |
| 766 | adapter->flags |= QLCNIC_ADAPTER_INITIALIZED; |
| 767 | |
| 768 | return err; |
| 769 | } |
| 770 | |
| 771 | static int |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 772 | qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter) |
| 773 | { |
| 774 | struct qlcnic_esw_func_cfg esw_cfg; |
| 775 | struct qlcnic_npar_info *npar; |
| 776 | u8 i; |
| 777 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 778 | if (adapter->need_fw_reset) |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 779 | return 0; |
| 780 | |
| 781 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 782 | if (adapter->npars[i].type != QLCNIC_TYPE_NIC) |
| 783 | continue; |
| 784 | memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg)); |
| 785 | esw_cfg.pci_func = i; |
| 786 | esw_cfg.offload_flags = BIT_0; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 787 | esw_cfg.mac_override = BIT_0; |
Rajesh Borundia | ee07c1a | 2010-10-07 23:46:09 +0000 | [diff] [blame] | 788 | esw_cfg.promisc_mode = BIT_0; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 789 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) |
| 790 | esw_cfg.offload_flags |= (BIT_1 | BIT_2); |
| 791 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 792 | return -EIO; |
| 793 | npar = &adapter->npars[i]; |
| 794 | npar->pvid = esw_cfg.vlan_id; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 795 | npar->mac_override = esw_cfg.mac_override; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 796 | npar->mac_anti_spoof = esw_cfg.mac_anti_spoof; |
| 797 | npar->discard_tagged = esw_cfg.discard_tagged; |
| 798 | npar->promisc_mode = esw_cfg.promisc_mode; |
| 799 | npar->offload_flags = esw_cfg.offload_flags; |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 805 | static int |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 806 | qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter, |
| 807 | struct qlcnic_npar_info *npar, int pci_func) |
| 808 | { |
| 809 | struct qlcnic_esw_func_cfg esw_cfg; |
| 810 | esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS; |
| 811 | esw_cfg.pci_func = pci_func; |
| 812 | esw_cfg.vlan_id = npar->pvid; |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 813 | esw_cfg.mac_override = npar->mac_override; |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 814 | esw_cfg.discard_tagged = npar->discard_tagged; |
| 815 | esw_cfg.mac_anti_spoof = npar->mac_anti_spoof; |
| 816 | esw_cfg.offload_flags = npar->offload_flags; |
| 817 | esw_cfg.promisc_mode = npar->promisc_mode; |
| 818 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 819 | return -EIO; |
| 820 | |
| 821 | esw_cfg.op_mode = QLCNIC_ADD_VLAN; |
| 822 | if (qlcnic_config_switch_port(adapter, &esw_cfg)) |
| 823 | return -EIO; |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 829 | qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) |
| 830 | { |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 831 | int i, err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 832 | struct qlcnic_npar_info *npar; |
| 833 | struct qlcnic_info nic_info; |
| 834 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 835 | if (!adapter->need_fw_reset) |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 836 | return 0; |
| 837 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 838 | /* Set the NPAR config data after FW reset */ |
| 839 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
| 840 | npar = &adapter->npars[i]; |
| 841 | if (npar->type != QLCNIC_TYPE_NIC) |
| 842 | continue; |
| 843 | err = qlcnic_get_nic_info(adapter, &nic_info, i); |
| 844 | if (err) |
| 845 | return err; |
| 846 | nic_info.min_tx_bw = npar->min_bw; |
| 847 | nic_info.max_tx_bw = npar->max_bw; |
| 848 | err = qlcnic_set_nic_info(adapter, &nic_info); |
| 849 | if (err) |
| 850 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 851 | |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 852 | if (npar->enable_pm) { |
| 853 | err = qlcnic_config_port_mirroring(adapter, |
| 854 | npar->dest_npar, 1, i); |
| 855 | if (err) |
| 856 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 857 | } |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 858 | err = qlcnic_reset_eswitch_config(adapter, npar, i); |
| 859 | if (err) |
| 860 | return err; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 861 | } |
Rajesh Borundia | 4e8acb0 | 2010-08-19 05:08:25 +0000 | [diff] [blame] | 862 | return 0; |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Amit Kumar Salecha | 78f84e1 | 2010-08-19 05:08:28 +0000 | [diff] [blame] | 865 | static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter) |
| 866 | { |
| 867 | u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO; |
| 868 | u32 npar_state; |
| 869 | |
| 870 | if (adapter->op_mode == QLCNIC_MGMT_FUNC) |
| 871 | return 0; |
| 872 | |
| 873 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 874 | while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) { |
| 875 | msleep(1000); |
| 876 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 877 | } |
| 878 | if (!npar_opt_timeo) { |
| 879 | dev_err(&adapter->pdev->dev, |
| 880 | "Waiting for NPAR state to opertional timeout\n"); |
| 881 | return -EIO; |
| 882 | } |
| 883 | return 0; |
| 884 | } |
| 885 | |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 886 | static int |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 887 | qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter) |
| 888 | { |
| 889 | int err; |
| 890 | |
| 891 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || |
| 892 | adapter->op_mode != QLCNIC_MGMT_FUNC) |
| 893 | return 0; |
| 894 | |
| 895 | err = qlcnic_set_default_offload_settings(adapter); |
| 896 | if (err) |
| 897 | return err; |
| 898 | |
| 899 | err = qlcnic_reset_npar_config(adapter); |
| 900 | if (err) |
| 901 | return err; |
| 902 | |
| 903 | qlcnic_dev_set_npar_ready(adapter); |
| 904 | |
| 905 | return err; |
| 906 | } |
| 907 | |
| 908 | static int |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 909 | qlcnic_start_firmware(struct qlcnic_adapter *adapter) |
| 910 | { |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 911 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 912 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 913 | err = qlcnic_can_start_firmware(adapter); |
| 914 | if (err < 0) |
| 915 | return err; |
| 916 | else if (!err) |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 917 | goto check_fw_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 918 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 919 | if (load_fw_file) |
| 920 | qlcnic_request_firmware(adapter); |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 921 | else { |
Sony Chacko | 8cfdce0 | 2010-08-26 14:02:41 +0000 | [diff] [blame] | 922 | err = qlcnic_check_flash_fw_ver(adapter); |
| 923 | if (err) |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 924 | goto err_out; |
| 925 | |
Amit Kumar Salecha | 4d5bdb3 | 2010-05-17 01:22:11 +0000 | [diff] [blame] | 926 | adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; |
schacko | 8f89138 | 2010-06-17 02:56:40 +0000 | [diff] [blame] | 927 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 928 | |
| 929 | err = qlcnic_need_fw_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 930 | if (err == 0) |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 931 | goto check_fw_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 932 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 933 | err = qlcnic_pinit_from_rom(adapter); |
| 934 | if (err) |
| 935 | goto err_out; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 936 | |
| 937 | err = qlcnic_load_firmware(adapter); |
| 938 | if (err) |
| 939 | goto err_out; |
| 940 | |
| 941 | qlcnic_release_firmware(adapter); |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 942 | QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 943 | |
Sony Chacko | d406683 | 2010-08-19 05:08:31 +0000 | [diff] [blame] | 944 | check_fw_status: |
| 945 | err = qlcnic_check_fw_status(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 946 | if (err) |
| 947 | goto err_out; |
| 948 | |
| 949 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 950 | qlcnic_idc_debug_info(adapter, 1); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 951 | |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 952 | err = qlcnic_check_eswitch_mode(adapter); |
| 953 | if (err) { |
| 954 | dev_err(&adapter->pdev->dev, |
| 955 | "Memory allocation failed for eswitch\n"); |
| 956 | goto err_out; |
| 957 | } |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 958 | err = qlcnic_set_mgmt_operations(adapter); |
| 959 | if (err) |
| 960 | goto err_out; |
| 961 | |
| 962 | qlcnic_check_options(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 963 | adapter->need_fw_reset = 0; |
| 964 | |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 965 | qlcnic_release_firmware(adapter); |
| 966 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 967 | |
| 968 | err_out: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 969 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 970 | dev_err(&adapter->pdev->dev, "Device state set to failed\n"); |
Anirban Chakraborty | 0866d96 | 2010-08-26 14:02:52 +0000 | [diff] [blame] | 971 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 972 | qlcnic_release_firmware(adapter); |
| 973 | return err; |
| 974 | } |
| 975 | |
| 976 | static int |
| 977 | qlcnic_request_irq(struct qlcnic_adapter *adapter) |
| 978 | { |
| 979 | irq_handler_t handler; |
| 980 | struct qlcnic_host_sds_ring *sds_ring; |
| 981 | int err, ring; |
| 982 | |
| 983 | unsigned long flags = 0; |
| 984 | struct net_device *netdev = adapter->netdev; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 985 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 986 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 987 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 988 | handler = qlcnic_tmp_intr; |
| 989 | if (!QLCNIC_IS_MSI_FAMILY(adapter)) |
| 990 | flags |= IRQF_SHARED; |
| 991 | |
| 992 | } else { |
| 993 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 994 | handler = qlcnic_msix_intr; |
| 995 | else if (adapter->flags & QLCNIC_MSI_ENABLED) |
| 996 | handler = qlcnic_msi_intr; |
| 997 | else { |
| 998 | flags |= IRQF_SHARED; |
| 999 | handler = qlcnic_intr; |
| 1000 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1001 | } |
| 1002 | adapter->irq = netdev->irq; |
| 1003 | |
| 1004 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1005 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1006 | sprintf(sds_ring->name, "%s[%d]", netdev->name, ring); |
| 1007 | err = request_irq(sds_ring->irq, handler, |
| 1008 | flags, sds_ring->name, sds_ring); |
| 1009 | if (err) |
| 1010 | return err; |
| 1011 | } |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static void |
| 1017 | qlcnic_free_irq(struct qlcnic_adapter *adapter) |
| 1018 | { |
| 1019 | int ring; |
| 1020 | struct qlcnic_host_sds_ring *sds_ring; |
| 1021 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1022 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1023 | |
| 1024 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1025 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1026 | free_irq(sds_ring->irq, sds_ring); |
| 1027 | } |
| 1028 | } |
| 1029 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1030 | static int |
| 1031 | __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1032 | { |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1033 | int ring; |
Rajesh Borundia | cae82d4 | 2012-06-06 07:35:06 +0000 | [diff] [blame] | 1034 | u32 capab2; |
| 1035 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1036 | struct qlcnic_host_rds_ring *rds_ring; |
| 1037 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1038 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1039 | return -EIO; |
| 1040 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1041 | if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1042 | return 0; |
Rajesh Borundia | 0325d69 | 2010-08-19 05:08:26 +0000 | [diff] [blame] | 1043 | if (qlcnic_set_eswitch_port_config(adapter)) |
| 1044 | return -EIO; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1045 | |
Rajesh Borundia | cae82d4 | 2012-06-06 07:35:06 +0000 | [diff] [blame] | 1046 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) { |
| 1047 | capab2 = QLCRD32(adapter, CRB_FW_CAPABILITIES_2); |
| 1048 | if (capab2 & QLCNIC_FW_CAPABILITY_2_LRO_MAX_TCP_SEG) |
| 1049 | adapter->flags |= QLCNIC_FW_LRO_MSS_CAP; |
| 1050 | } |
| 1051 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1052 | if (qlcnic_fw_create_ctx(adapter)) |
| 1053 | return -EIO; |
| 1054 | |
| 1055 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1056 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
| 1057 | qlcnic_post_rx_buffers(adapter, rds_ring); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1060 | qlcnic_set_multi(netdev); |
| 1061 | qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); |
| 1062 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1063 | adapter->ahw->linkup = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1064 | |
| 1065 | if (adapter->max_sds_rings > 1) |
| 1066 | qlcnic_config_rss(adapter, 1); |
| 1067 | |
| 1068 | qlcnic_config_intr_coalesce(adapter); |
| 1069 | |
Sucheta Chakraborty | 24763d8 | 2010-08-17 00:34:25 +0000 | [diff] [blame] | 1070 | if (netdev->features & NETIF_F_LRO) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1071 | qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); |
| 1072 | |
| 1073 | qlcnic_napi_enable(adapter); |
| 1074 | |
| 1075 | qlcnic_linkevent_request(adapter, 1); |
| 1076 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1077 | adapter->reset_context = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1078 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | /* Usage: During resume and firmware recovery module.*/ |
| 1083 | |
| 1084 | static int |
| 1085 | qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1086 | { |
| 1087 | int err = 0; |
| 1088 | |
| 1089 | rtnl_lock(); |
| 1090 | if (netif_running(netdev)) |
| 1091 | err = __qlcnic_up(adapter, netdev); |
| 1092 | rtnl_unlock(); |
| 1093 | |
| 1094 | return err; |
| 1095 | } |
| 1096 | |
| 1097 | static void |
| 1098 | __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1099 | { |
| 1100 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1101 | return; |
| 1102 | |
| 1103 | if (!test_and_clear_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 1104 | return; |
| 1105 | |
| 1106 | smp_mb(); |
| 1107 | spin_lock(&adapter->tx_clean_lock); |
| 1108 | netif_carrier_off(netdev); |
| 1109 | netif_tx_disable(netdev); |
| 1110 | |
| 1111 | qlcnic_free_mac_list(adapter); |
| 1112 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1113 | if (adapter->fhash.fnum) |
| 1114 | qlcnic_delete_lb_filters(adapter); |
| 1115 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1116 | qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); |
| 1117 | |
| 1118 | qlcnic_napi_disable(adapter); |
| 1119 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1120 | qlcnic_fw_destroy_ctx(adapter); |
Rajesh Borundia | cae82d4 | 2012-06-06 07:35:06 +0000 | [diff] [blame] | 1121 | adapter->flags &= ~QLCNIC_FW_LRO_MSS_CAP; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1122 | |
| 1123 | qlcnic_reset_rx_buffers_list(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1124 | qlcnic_release_tx_buffers(adapter); |
| 1125 | spin_unlock(&adapter->tx_clean_lock); |
| 1126 | } |
| 1127 | |
| 1128 | /* Usage: During suspend and firmware recovery module */ |
| 1129 | |
| 1130 | static void |
| 1131 | qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev) |
| 1132 | { |
| 1133 | rtnl_lock(); |
| 1134 | if (netif_running(netdev)) |
| 1135 | __qlcnic_down(adapter, netdev); |
| 1136 | rtnl_unlock(); |
| 1137 | |
| 1138 | } |
| 1139 | |
| 1140 | static int |
| 1141 | qlcnic_attach(struct qlcnic_adapter *adapter) |
| 1142 | { |
| 1143 | struct net_device *netdev = adapter->netdev; |
| 1144 | struct pci_dev *pdev = adapter->pdev; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1145 | int err; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1146 | |
| 1147 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) |
| 1148 | return 0; |
| 1149 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1150 | err = qlcnic_napi_add(adapter, netdev); |
| 1151 | if (err) |
| 1152 | return err; |
| 1153 | |
| 1154 | err = qlcnic_alloc_sw_resources(adapter); |
| 1155 | if (err) { |
| 1156 | dev_err(&pdev->dev, "Error in setting sw resources\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1157 | goto err_out_napi_del; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | err = qlcnic_alloc_hw_resources(adapter); |
| 1161 | if (err) { |
| 1162 | dev_err(&pdev->dev, "Error in setting hw resources\n"); |
| 1163 | goto err_out_free_sw; |
| 1164 | } |
| 1165 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1166 | err = qlcnic_request_irq(adapter); |
| 1167 | if (err) { |
| 1168 | dev_err(&pdev->dev, "failed to setup interrupt\n"); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1169 | goto err_out_free_hw; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1172 | qlcnic_create_sysfs_entries(adapter); |
| 1173 | |
| 1174 | adapter->is_up = QLCNIC_ADAPTER_UP_MAGIC; |
| 1175 | return 0; |
| 1176 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1177 | err_out_free_hw: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1178 | qlcnic_free_hw_resources(adapter); |
| 1179 | err_out_free_sw: |
| 1180 | qlcnic_free_sw_resources(adapter); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1181 | err_out_napi_del: |
| 1182 | qlcnic_napi_del(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1183 | return err; |
| 1184 | } |
| 1185 | |
| 1186 | static void |
| 1187 | qlcnic_detach(struct qlcnic_adapter *adapter) |
| 1188 | { |
| 1189 | if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) |
| 1190 | return; |
| 1191 | |
| 1192 | qlcnic_remove_sysfs_entries(adapter); |
| 1193 | |
| 1194 | qlcnic_free_hw_resources(adapter); |
| 1195 | qlcnic_release_rx_buffers(adapter); |
| 1196 | qlcnic_free_irq(adapter); |
| 1197 | qlcnic_napi_del(adapter); |
| 1198 | qlcnic_free_sw_resources(adapter); |
| 1199 | |
| 1200 | adapter->is_up = 0; |
| 1201 | } |
| 1202 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1203 | void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings) |
| 1204 | { |
| 1205 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1206 | struct qlcnic_host_sds_ring *sds_ring; |
| 1207 | int ring; |
| 1208 | |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1209 | clear_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1210 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1211 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1212 | sds_ring = &adapter->recv_ctx->sds_rings[ring]; |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1213 | qlcnic_disable_int(sds_ring); |
| 1214 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1217 | qlcnic_fw_destroy_ctx(adapter); |
| 1218 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1219 | qlcnic_detach(adapter); |
| 1220 | |
| 1221 | adapter->diag_test = 0; |
| 1222 | adapter->max_sds_rings = max_sds_rings; |
| 1223 | |
| 1224 | if (qlcnic_attach(adapter)) |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1225 | goto out; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1226 | |
| 1227 | if (netif_running(netdev)) |
| 1228 | __qlcnic_up(adapter, netdev); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1229 | out: |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1230 | netif_device_attach(netdev); |
| 1231 | } |
| 1232 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1233 | static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter) |
| 1234 | { |
| 1235 | int err = 0; |
| 1236 | adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context), |
| 1237 | GFP_KERNEL); |
| 1238 | if (!adapter->ahw) { |
| 1239 | dev_err(&adapter->pdev->dev, |
| 1240 | "Failed to allocate recv ctx resources for adapter\n"); |
| 1241 | err = -ENOMEM; |
| 1242 | goto err_out; |
| 1243 | } |
| 1244 | adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context), |
| 1245 | GFP_KERNEL); |
| 1246 | if (!adapter->recv_ctx) { |
| 1247 | dev_err(&adapter->pdev->dev, |
| 1248 | "Failed to allocate recv ctx resources for adapter\n"); |
| 1249 | kfree(adapter->ahw); |
| 1250 | adapter->ahw = NULL; |
| 1251 | err = -ENOMEM; |
Anirban Chakraborty | 8816d00 | 2011-04-01 14:28:21 +0000 | [diff] [blame] | 1252 | goto err_out; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1253 | } |
Anirban Chakraborty | 8816d00 | 2011-04-01 14:28:21 +0000 | [diff] [blame] | 1254 | /* Initialize interrupt coalesce parameters */ |
| 1255 | adapter->ahw->coal.flag = QLCNIC_INTR_DEFAULT; |
| 1256 | adapter->ahw->coal.rx_time_us = QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US; |
| 1257 | adapter->ahw->coal.rx_packets = QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1258 | err_out: |
| 1259 | return err; |
| 1260 | } |
| 1261 | |
| 1262 | static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter) |
| 1263 | { |
| 1264 | kfree(adapter->recv_ctx); |
| 1265 | adapter->recv_ctx = NULL; |
| 1266 | |
Anirban Chakraborty | 18f2f61 | 2011-05-12 12:48:33 +0000 | [diff] [blame] | 1267 | if (adapter->ahw->fw_dump.tmpl_hdr) { |
| 1268 | vfree(adapter->ahw->fw_dump.tmpl_hdr); |
| 1269 | adapter->ahw->fw_dump.tmpl_hdr = NULL; |
| 1270 | } |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1271 | kfree(adapter->ahw); |
| 1272 | adapter->ahw = NULL; |
| 1273 | } |
| 1274 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1275 | int qlcnic_diag_alloc_res(struct net_device *netdev, int test) |
| 1276 | { |
| 1277 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1278 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1279 | struct qlcnic_host_rds_ring *rds_ring; |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1280 | int ring; |
| 1281 | int ret; |
| 1282 | |
| 1283 | netif_device_detach(netdev); |
| 1284 | |
| 1285 | if (netif_running(netdev)) |
| 1286 | __qlcnic_down(adapter, netdev); |
| 1287 | |
| 1288 | qlcnic_detach(adapter); |
| 1289 | |
| 1290 | adapter->max_sds_rings = 1; |
| 1291 | adapter->diag_test = test; |
| 1292 | |
| 1293 | ret = qlcnic_attach(adapter); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1294 | if (ret) { |
| 1295 | netif_device_attach(netdev); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1296 | return ret; |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1297 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1298 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1299 | ret = qlcnic_fw_create_ctx(adapter); |
| 1300 | if (ret) { |
| 1301 | qlcnic_detach(adapter); |
Sony Chacko | 57e4624 | 2010-07-24 18:32:18 +0000 | [diff] [blame] | 1302 | netif_device_attach(netdev); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1307 | rds_ring = &adapter->recv_ctx->rds_rings[ring]; |
| 1308 | qlcnic_post_rx_buffers(adapter, rds_ring); |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1311 | if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { |
| 1312 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1313 | sds_ring = &adapter->recv_ctx->sds_rings[ring]; |
Amit Kumar Salecha | cdaff18 | 2010-02-01 05:25:00 +0000 | [diff] [blame] | 1314 | qlcnic_enable_int(sds_ring); |
| 1315 | } |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1316 | } |
Sucheta Chakraborty | 22c8c93 | 2011-06-22 02:52:23 +0000 | [diff] [blame] | 1317 | |
| 1318 | if (adapter->diag_test == QLCNIC_LOOPBACK_TEST) { |
| 1319 | adapter->ahw->loopback_state = 0; |
| 1320 | qlcnic_linkevent_request(adapter, 1); |
| 1321 | } |
| 1322 | |
Sucheta Chakraborty | 78ad389 | 2010-05-17 01:22:12 +0000 | [diff] [blame] | 1323 | set_bit(__QLCNIC_DEV_UP, &adapter->state); |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1324 | |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1328 | /* Reset context in hardware only */ |
| 1329 | static int |
| 1330 | qlcnic_reset_hw_context(struct qlcnic_adapter *adapter) |
| 1331 | { |
| 1332 | struct net_device *netdev = adapter->netdev; |
| 1333 | |
| 1334 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1335 | return -EBUSY; |
| 1336 | |
| 1337 | netif_device_detach(netdev); |
| 1338 | |
| 1339 | qlcnic_down(adapter, netdev); |
| 1340 | |
| 1341 | qlcnic_up(adapter, netdev); |
| 1342 | |
| 1343 | netif_device_attach(netdev); |
| 1344 | |
| 1345 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1349 | int |
| 1350 | qlcnic_reset_context(struct qlcnic_adapter *adapter) |
| 1351 | { |
| 1352 | int err = 0; |
| 1353 | struct net_device *netdev = adapter->netdev; |
| 1354 | |
| 1355 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1356 | return -EBUSY; |
| 1357 | |
| 1358 | if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) { |
| 1359 | |
| 1360 | netif_device_detach(netdev); |
| 1361 | |
| 1362 | if (netif_running(netdev)) |
| 1363 | __qlcnic_down(adapter, netdev); |
| 1364 | |
| 1365 | qlcnic_detach(adapter); |
| 1366 | |
| 1367 | if (netif_running(netdev)) { |
| 1368 | err = qlcnic_attach(adapter); |
Anirban Chakraborty | 1d5c88e | 2012-03-23 06:32:34 +0000 | [diff] [blame] | 1369 | if (!err) { |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 1370 | __qlcnic_up(adapter, netdev); |
Anirban Chakraborty | 1d5c88e | 2012-03-23 06:32:34 +0000 | [diff] [blame] | 1371 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
| 1372 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | netif_device_attach(netdev); |
| 1376 | } |
| 1377 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1378 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1379 | return err; |
| 1380 | } |
| 1381 | |
| 1382 | static int |
Sony Chacko | 5ad6ff9 | 2012-11-17 21:04:38 +0000 | [diff] [blame] | 1383 | qlcnic_setup_netdev(struct qlcnic_adapter *adapter, struct net_device *netdev, |
| 1384 | int pci_using_dac) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1385 | { |
| 1386 | int err; |
| 1387 | struct pci_dev *pdev = adapter->pdev; |
| 1388 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1389 | adapter->mc_enabled = 0; |
| 1390 | adapter->max_mc_count = 38; |
| 1391 | |
| 1392 | netdev->netdev_ops = &qlcnic_netdev_ops; |
Rajesh K Borundia | ef71ff8 | 2010-06-17 02:56:41 +0000 | [diff] [blame] | 1393 | netdev->watchdog_timeo = 5*HZ; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1394 | |
| 1395 | qlcnic_change_mtu(netdev, netdev->mtu); |
| 1396 | |
| 1397 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); |
| 1398 | |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1399 | netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | |
| 1400 | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; |
Anirban Chakraborty | ac8d0c4 | 2010-07-09 13:14:58 +0000 | [diff] [blame] | 1401 | |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1402 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) |
| 1403 | netdev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6; |
Sony Chacko | 5ad6ff9 | 2012-11-17 21:04:38 +0000 | [diff] [blame] | 1404 | if (pci_using_dac == 1) |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1405 | netdev->hw_features |= NETIF_F_HIGHDMA; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1406 | |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1407 | netdev->vlan_features = netdev->hw_features; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1408 | |
| 1409 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_FVLANTX) |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1410 | netdev->hw_features |= NETIF_F_HW_VLAN_TX; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1411 | if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) |
Michał Mirosław | 135d84a | 2011-04-19 03:03:57 +0000 | [diff] [blame] | 1412 | netdev->hw_features |= NETIF_F_LRO; |
| 1413 | |
| 1414 | netdev->features |= netdev->hw_features | |
| 1415 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; |
| 1416 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1417 | netdev->irq = adapter->msix_entries[0].vector; |
| 1418 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1419 | err = register_netdev(netdev); |
| 1420 | if (err) { |
| 1421 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1422 | return err; |
| 1423 | } |
| 1424 | |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Sony Chacko | 5ad6ff9 | 2012-11-17 21:04:38 +0000 | [diff] [blame] | 1428 | static int qlcnic_set_dma_mask(struct pci_dev *pdev, int *pci_using_dac) |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1429 | { |
| 1430 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 1431 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) |
| 1432 | *pci_using_dac = 1; |
| 1433 | else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) && |
| 1434 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 1435 | *pci_using_dac = 0; |
| 1436 | else { |
| 1437 | dev_err(&pdev->dev, "Unable to set DMA mask, aborting\n"); |
| 1438 | return -EIO; |
| 1439 | } |
| 1440 | |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1444 | static int |
| 1445 | qlcnic_alloc_msix_entries(struct qlcnic_adapter *adapter, u16 count) |
| 1446 | { |
| 1447 | adapter->msix_entries = kcalloc(count, sizeof(struct msix_entry), |
| 1448 | GFP_KERNEL); |
| 1449 | |
| 1450 | if (adapter->msix_entries) |
| 1451 | return 0; |
| 1452 | |
| 1453 | dev_err(&adapter->pdev->dev, "failed allocating msix_entries\n"); |
| 1454 | return -ENOMEM; |
| 1455 | } |
| 1456 | |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame^] | 1457 | static int |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1458 | qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1459 | { |
| 1460 | struct net_device *netdev = NULL; |
| 1461 | struct qlcnic_adapter *adapter = NULL; |
Sony Chacko | 5ad6ff9 | 2012-11-17 21:04:38 +0000 | [diff] [blame] | 1462 | int err, pci_using_dac = -1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1463 | uint8_t revision_id; |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 1464 | char brd_name[QLCNIC_MAX_BOARD_NAME_LEN]; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1465 | |
| 1466 | err = pci_enable_device(pdev); |
| 1467 | if (err) |
| 1468 | return err; |
| 1469 | |
| 1470 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 1471 | err = -ENODEV; |
| 1472 | goto err_out_disable_pdev; |
| 1473 | } |
| 1474 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1475 | err = qlcnic_set_dma_mask(pdev, &pci_using_dac); |
| 1476 | if (err) |
| 1477 | goto err_out_disable_pdev; |
| 1478 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1479 | err = pci_request_regions(pdev, qlcnic_driver_name); |
| 1480 | if (err) |
| 1481 | goto err_out_disable_pdev; |
| 1482 | |
| 1483 | pci_set_master(pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 1484 | pci_enable_pcie_error_reporting(pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1485 | |
| 1486 | netdev = alloc_etherdev(sizeof(struct qlcnic_adapter)); |
| 1487 | if (!netdev) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1488 | err = -ENOMEM; |
| 1489 | goto err_out_free_res; |
| 1490 | } |
| 1491 | |
| 1492 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1493 | |
| 1494 | adapter = netdev_priv(netdev); |
| 1495 | adapter->netdev = netdev; |
| 1496 | adapter->pdev = pdev; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1497 | |
Peter Senna Tschudin | 2dfc967 | 2012-10-05 12:10:50 +0000 | [diff] [blame] | 1498 | err = qlcnic_alloc_adapter_resources(adapter); |
| 1499 | if (err) |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1500 | goto err_out_free_netdev; |
| 1501 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1502 | adapter->dev_rst_time = jiffies; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1503 | revision_id = pdev->revision; |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1504 | adapter->ahw->revision_id = revision_id; |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1505 | adapter->mac_learn = qlcnic_mac_learn; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1506 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1507 | rwlock_init(&adapter->ahw->crb_lock); |
| 1508 | mutex_init(&adapter->ahw->mem_lock); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1509 | |
| 1510 | spin_lock_init(&adapter->tx_clean_lock); |
| 1511 | INIT_LIST_HEAD(&adapter->mac_list); |
| 1512 | |
| 1513 | err = qlcnic_setup_pci_map(adapter); |
| 1514 | if (err) |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1515 | goto err_out_free_hw; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1516 | |
| 1517 | /* This will be reset for mezz cards */ |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1518 | adapter->portnum = adapter->ahw->pci_func; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1519 | |
| 1520 | err = qlcnic_get_board_info(adapter); |
| 1521 | if (err) { |
| 1522 | dev_err(&pdev->dev, "Error getting board config info.\n"); |
| 1523 | goto err_out_iounmap; |
| 1524 | } |
| 1525 | |
Sony Chacko | 8cfdce0 | 2010-08-26 14:02:41 +0000 | [diff] [blame] | 1526 | err = qlcnic_setup_idc_param(adapter); |
| 1527 | if (err) |
Sucheta Chakraborty | b3a2464 | 2010-05-13 03:07:48 +0000 | [diff] [blame] | 1528 | goto err_out_iounmap; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1529 | |
Rajesh Borundia | 1dc0f3c | 2010-12-16 22:59:02 +0000 | [diff] [blame] | 1530 | adapter->flags |= QLCNIC_NEED_FLR; |
Rajesh Borundia | b0044bc | 2010-11-23 01:25:21 +0000 | [diff] [blame] | 1531 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1532 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1533 | if (err) { |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1534 | dev_err(&pdev->dev, "Loading fw failed. Please Reboot\n" |
| 1535 | "\t\tIf reboot doesn't help, try flashing the card\n"); |
| 1536 | goto err_out_maintenance_mode; |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 1537 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1538 | |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 1539 | if (qlcnic_read_mac_addr(adapter)) |
| 1540 | dev_warn(&pdev->dev, "failed to read mac addr\n"); |
| 1541 | |
| 1542 | if (adapter->portnum == 0) { |
| 1543 | get_brd_name(adapter, brd_name); |
| 1544 | |
| 1545 | pr_info("%s: %s Board Chip rev 0x%x\n", |
| 1546 | module_name(THIS_MODULE), |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1547 | brd_name, adapter->ahw->revision_id); |
Rajesh Borundia | da48e6c | 2010-08-31 17:17:46 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1550 | qlcnic_clear_stats(adapter); |
| 1551 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1552 | err = qlcnic_alloc_msix_entries(adapter, adapter->max_rx_ques); |
| 1553 | if (err) |
| 1554 | goto err_out_decr_ref; |
| 1555 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1556 | qlcnic_setup_intr(adapter); |
| 1557 | |
Amit Kumar Salecha | 1bb09fb | 2010-05-14 03:07:46 -0700 | [diff] [blame] | 1558 | err = qlcnic_setup_netdev(adapter, netdev, pci_using_dac); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1559 | if (err) |
| 1560 | goto err_out_disable_msi; |
| 1561 | |
| 1562 | pci_set_drvdata(pdev, adapter); |
| 1563 | |
| 1564 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1565 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1566 | switch (adapter->ahw->port_type) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1567 | case QLCNIC_GBE: |
| 1568 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1569 | adapter->netdev->name); |
| 1570 | break; |
| 1571 | case QLCNIC_XGBE: |
| 1572 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1573 | adapter->netdev->name); |
| 1574 | break; |
| 1575 | } |
| 1576 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1577 | if (adapter->mac_learn) |
| 1578 | qlcnic_alloc_lb_filters_mem(adapter); |
| 1579 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1580 | qlcnic_create_diag_entries(adapter); |
| 1581 | |
| 1582 | return 0; |
| 1583 | |
| 1584 | err_out_disable_msi: |
| 1585 | qlcnic_teardown_intr(adapter); |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1586 | kfree(adapter->msix_entries); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1587 | |
| 1588 | err_out_decr_ref: |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1589 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1590 | |
| 1591 | err_out_iounmap: |
| 1592 | qlcnic_cleanup_pci_map(adapter); |
| 1593 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1594 | err_out_free_hw: |
| 1595 | qlcnic_free_adapter_resources(adapter); |
| 1596 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1597 | err_out_free_netdev: |
| 1598 | free_netdev(netdev); |
| 1599 | |
| 1600 | err_out_free_res: |
| 1601 | pci_release_regions(pdev); |
| 1602 | |
| 1603 | err_out_disable_pdev: |
| 1604 | pci_set_drvdata(pdev, NULL); |
| 1605 | pci_disable_device(pdev); |
| 1606 | return err; |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1607 | |
| 1608 | err_out_maintenance_mode: |
| 1609 | netdev->netdev_ops = &qlcnic_netdev_failed_ops; |
| 1610 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops); |
| 1611 | err = register_netdev(netdev); |
| 1612 | if (err) { |
| 1613 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1614 | goto err_out_decr_ref; |
| 1615 | } |
| 1616 | pci_set_drvdata(pdev, adapter); |
| 1617 | qlcnic_create_diag_entries(adapter); |
| 1618 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame^] | 1621 | static void qlcnic_remove(struct pci_dev *pdev) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1622 | { |
| 1623 | struct qlcnic_adapter *adapter; |
| 1624 | struct net_device *netdev; |
| 1625 | |
| 1626 | adapter = pci_get_drvdata(pdev); |
| 1627 | if (adapter == NULL) |
| 1628 | return; |
| 1629 | |
| 1630 | netdev = adapter->netdev; |
| 1631 | |
| 1632 | qlcnic_cancel_fw_work(adapter); |
| 1633 | |
| 1634 | unregister_netdev(netdev); |
| 1635 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1636 | qlcnic_detach(adapter); |
| 1637 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1638 | if (adapter->npars != NULL) |
| 1639 | kfree(adapter->npars); |
| 1640 | if (adapter->eswitch != NULL) |
| 1641 | kfree(adapter->eswitch); |
| 1642 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1643 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1644 | |
| 1645 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1646 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1647 | qlcnic_free_lb_filters_mem(adapter); |
| 1648 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1649 | qlcnic_teardown_intr(adapter); |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1650 | kfree(adapter->msix_entries); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1651 | |
| 1652 | qlcnic_remove_diag_entries(adapter); |
| 1653 | |
| 1654 | qlcnic_cleanup_pci_map(adapter); |
| 1655 | |
| 1656 | qlcnic_release_firmware(adapter); |
| 1657 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 1658 | pci_disable_pcie_error_reporting(pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1659 | pci_release_regions(pdev); |
| 1660 | pci_disable_device(pdev); |
| 1661 | pci_set_drvdata(pdev, NULL); |
| 1662 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1663 | qlcnic_free_adapter_resources(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1664 | free_netdev(netdev); |
| 1665 | } |
| 1666 | static int __qlcnic_shutdown(struct pci_dev *pdev) |
| 1667 | { |
| 1668 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1669 | struct net_device *netdev = adapter->netdev; |
| 1670 | int retval; |
| 1671 | |
| 1672 | netif_device_detach(netdev); |
| 1673 | |
| 1674 | qlcnic_cancel_fw_work(adapter); |
| 1675 | |
| 1676 | if (netif_running(netdev)) |
| 1677 | qlcnic_down(adapter, netdev); |
| 1678 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1679 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1680 | |
| 1681 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1682 | |
| 1683 | retval = pci_save_state(pdev); |
| 1684 | if (retval) |
| 1685 | return retval; |
| 1686 | |
| 1687 | if (qlcnic_wol_supported(adapter)) { |
| 1688 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1689 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1690 | } |
| 1691 | |
| 1692 | return 0; |
| 1693 | } |
| 1694 | |
| 1695 | static void qlcnic_shutdown(struct pci_dev *pdev) |
| 1696 | { |
| 1697 | if (__qlcnic_shutdown(pdev)) |
| 1698 | return; |
| 1699 | |
| 1700 | pci_disable_device(pdev); |
| 1701 | } |
| 1702 | |
| 1703 | #ifdef CONFIG_PM |
| 1704 | static int |
| 1705 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1706 | { |
| 1707 | int retval; |
| 1708 | |
| 1709 | retval = __qlcnic_shutdown(pdev); |
| 1710 | if (retval) |
| 1711 | return retval; |
| 1712 | |
| 1713 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | static int |
| 1718 | qlcnic_resume(struct pci_dev *pdev) |
| 1719 | { |
| 1720 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1721 | struct net_device *netdev = adapter->netdev; |
| 1722 | int err; |
| 1723 | |
| 1724 | err = pci_enable_device(pdev); |
| 1725 | if (err) |
| 1726 | return err; |
| 1727 | |
| 1728 | pci_set_power_state(pdev, PCI_D0); |
| 1729 | pci_set_master(pdev); |
| 1730 | pci_restore_state(pdev); |
| 1731 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1732 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1733 | if (err) { |
| 1734 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1735 | return err; |
| 1736 | } |
| 1737 | |
| 1738 | if (netif_running(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1739 | err = qlcnic_up(adapter, netdev); |
| 1740 | if (err) |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1741 | goto done; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1742 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 1743 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1744 | } |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1745 | done: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1746 | netif_device_attach(netdev); |
| 1747 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1748 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1749 | } |
| 1750 | #endif |
| 1751 | |
| 1752 | static int qlcnic_open(struct net_device *netdev) |
| 1753 | { |
| 1754 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1755 | u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1756 | int err; |
| 1757 | |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1758 | if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) { |
| 1759 | netdev_err(netdev, "Device in FAILED state\n"); |
| 1760 | return -EIO; |
| 1761 | } |
| 1762 | |
Amit Kumar Salecha | c55ad8e | 2011-06-22 02:52:21 +0000 | [diff] [blame] | 1763 | netif_carrier_off(netdev); |
| 1764 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1765 | err = qlcnic_attach(adapter); |
| 1766 | if (err) |
| 1767 | return err; |
| 1768 | |
| 1769 | err = __qlcnic_up(adapter, netdev); |
| 1770 | if (err) |
| 1771 | goto err_out; |
| 1772 | |
| 1773 | netif_start_queue(netdev); |
| 1774 | |
| 1775 | return 0; |
| 1776 | |
| 1777 | err_out: |
| 1778 | qlcnic_detach(adapter); |
| 1779 | return err; |
| 1780 | } |
| 1781 | |
| 1782 | /* |
| 1783 | * qlcnic_close - Disables a network interface entry point |
| 1784 | */ |
| 1785 | static int qlcnic_close(struct net_device *netdev) |
| 1786 | { |
| 1787 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1788 | |
| 1789 | __qlcnic_down(adapter, netdev); |
| 1790 | return 0; |
| 1791 | } |
| 1792 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1793 | void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1794 | { |
| 1795 | void *head; |
| 1796 | int i; |
| 1797 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1798 | if (adapter->fhash.fmax && adapter->fhash.fhead) |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1799 | return; |
| 1800 | |
| 1801 | spin_lock_init(&adapter->mac_learn_lock); |
| 1802 | |
| 1803 | head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), |
| 1804 | GFP_KERNEL); |
| 1805 | if (!head) |
| 1806 | return; |
| 1807 | |
| 1808 | adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 1809 | adapter->fhash.fhead = head; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1810 | |
| 1811 | for (i = 0; i < adapter->fhash.fmax; i++) |
| 1812 | INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); |
| 1813 | } |
| 1814 | |
| 1815 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) |
| 1816 | { |
| 1817 | if (adapter->fhash.fmax && adapter->fhash.fhead) |
| 1818 | kfree(adapter->fhash.fhead); |
| 1819 | |
| 1820 | adapter->fhash.fhead = NULL; |
| 1821 | adapter->fhash.fmax = 0; |
| 1822 | } |
| 1823 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1824 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) |
| 1825 | { |
| 1826 | struct net_device *netdev = adapter->netdev; |
| 1827 | u32 temp, temp_state, temp_val; |
| 1828 | int rv = 0; |
| 1829 | |
| 1830 | temp = QLCRD32(adapter, CRB_TEMP_STATE); |
| 1831 | |
| 1832 | temp_state = qlcnic_get_temp_state(temp); |
| 1833 | temp_val = qlcnic_get_temp_val(temp); |
| 1834 | |
| 1835 | if (temp_state == QLCNIC_TEMP_PANIC) { |
| 1836 | dev_err(&netdev->dev, |
| 1837 | "Device temperature %d degrees C exceeds" |
| 1838 | " maximum allowed. Hardware has been shut down.\n", |
| 1839 | temp_val); |
| 1840 | rv = 1; |
| 1841 | } else if (temp_state == QLCNIC_TEMP_WARN) { |
| 1842 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { |
| 1843 | dev_err(&netdev->dev, |
| 1844 | "Device temperature %d degrees C " |
| 1845 | "exceeds operating range." |
| 1846 | " Immediate action needed.\n", |
| 1847 | temp_val); |
| 1848 | } |
| 1849 | } else { |
| 1850 | if (adapter->temp == QLCNIC_TEMP_WARN) { |
| 1851 | dev_info(&netdev->dev, |
| 1852 | "Device temperature is now %d degrees C" |
| 1853 | " in normal range.\n", temp_val); |
| 1854 | } |
| 1855 | } |
| 1856 | adapter->temp = temp_state; |
| 1857 | return rv; |
| 1858 | } |
| 1859 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1860 | static void qlcnic_tx_timeout(struct net_device *netdev) |
| 1861 | { |
| 1862 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1863 | |
| 1864 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1865 | return; |
| 1866 | |
| 1867 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1868 | |
| 1869 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1870 | adapter->need_fw_reset = 1; |
| 1871 | else |
| 1872 | adapter->reset_context = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) |
| 1876 | { |
| 1877 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1878 | struct net_device_stats *stats = &netdev->stats; |
| 1879 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1880 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
| 1881 | stats->tx_packets = adapter->stats.xmitfinished; |
Sucheta Chakraborty | 7e38259 | 2010-05-17 01:22:10 +0000 | [diff] [blame] | 1882 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1883 | stats->tx_bytes = adapter->stats.txbytes; |
| 1884 | stats->rx_dropped = adapter->stats.rxdropped; |
| 1885 | stats->tx_dropped = adapter->stats.txdropped; |
| 1886 | |
| 1887 | return stats; |
| 1888 | } |
| 1889 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1890 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1891 | { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1892 | u32 status; |
| 1893 | |
| 1894 | status = readl(adapter->isr_int_vec); |
| 1895 | |
| 1896 | if (!(status & adapter->int_vec_bit)) |
| 1897 | return IRQ_NONE; |
| 1898 | |
| 1899 | /* check interrupt state machine, to be sure */ |
| 1900 | status = readl(adapter->crb_int_state_reg); |
| 1901 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 1902 | return IRQ_NONE; |
| 1903 | |
| 1904 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1905 | /* read twice to ensure write is flushed */ |
| 1906 | readl(adapter->isr_int_vec); |
| 1907 | readl(adapter->isr_int_vec); |
| 1908 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1909 | return IRQ_HANDLED; |
| 1910 | } |
| 1911 | |
| 1912 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) |
| 1913 | { |
| 1914 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1915 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1916 | |
| 1917 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 1918 | goto done; |
| 1919 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { |
| 1920 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1921 | goto done; |
| 1922 | } |
| 1923 | |
| 1924 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1925 | return IRQ_NONE; |
| 1926 | |
| 1927 | done: |
| 1928 | adapter->diag_cnt++; |
| 1929 | qlcnic_enable_int(sds_ring); |
| 1930 | return IRQ_HANDLED; |
| 1931 | } |
| 1932 | |
| 1933 | static irqreturn_t qlcnic_intr(int irq, void *data) |
| 1934 | { |
| 1935 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1936 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1937 | |
| 1938 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1939 | return IRQ_NONE; |
| 1940 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1941 | napi_schedule(&sds_ring->napi); |
| 1942 | |
| 1943 | return IRQ_HANDLED; |
| 1944 | } |
| 1945 | |
| 1946 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) |
| 1947 | { |
| 1948 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1949 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1950 | |
| 1951 | /* clear interrupt */ |
| 1952 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1953 | |
| 1954 | napi_schedule(&sds_ring->napi); |
| 1955 | return IRQ_HANDLED; |
| 1956 | } |
| 1957 | |
| 1958 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) |
| 1959 | { |
| 1960 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1961 | |
| 1962 | napi_schedule(&sds_ring->napi); |
| 1963 | return IRQ_HANDLED; |
| 1964 | } |
| 1965 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1966 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1967 | static void qlcnic_poll_controller(struct net_device *netdev) |
| 1968 | { |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1969 | int ring; |
| 1970 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1971 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1972 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1973 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1974 | disable_irq(adapter->irq); |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1975 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1976 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1977 | qlcnic_intr(adapter->irq, sds_ring); |
| 1978 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1979 | enable_irq(adapter->irq); |
| 1980 | } |
| 1981 | #endif |
| 1982 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1983 | static void |
| 1984 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) |
| 1985 | { |
| 1986 | u32 val; |
| 1987 | |
| 1988 | val = adapter->portnum & 0xf; |
| 1989 | val |= encoding << 7; |
| 1990 | val |= (jiffies - adapter->dev_rst_time) << 8; |
| 1991 | |
| 1992 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); |
| 1993 | adapter->dev_rst_time = jiffies; |
| 1994 | } |
| 1995 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 1996 | static int |
| 1997 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1998 | { |
| 1999 | u32 val; |
| 2000 | |
| 2001 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && |
| 2002 | state != QLCNIC_DEV_NEED_QUISCENT); |
| 2003 | |
| 2004 | if (qlcnic_api_lock(adapter)) |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2005 | return -EIO; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2006 | |
| 2007 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2008 | |
| 2009 | if (state == QLCNIC_DEV_NEED_RESET) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2010 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2011 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2012 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2013 | |
| 2014 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2015 | |
| 2016 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2017 | |
| 2018 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2021 | static int |
| 2022 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) |
| 2023 | { |
| 2024 | u32 val; |
| 2025 | |
| 2026 | if (qlcnic_api_lock(adapter)) |
| 2027 | return -EBUSY; |
| 2028 | |
| 2029 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2030 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2031 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2032 | |
| 2033 | qlcnic_api_unlock(adapter); |
| 2034 | |
| 2035 | return 0; |
| 2036 | } |
| 2037 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2038 | static void |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2039 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2040 | { |
| 2041 | u32 val; |
| 2042 | |
| 2043 | if (qlcnic_api_lock(adapter)) |
| 2044 | goto err; |
| 2045 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2046 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2047 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2048 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2049 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2050 | if (failed) { |
| 2051 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 2052 | dev_info(&adapter->pdev->dev, |
| 2053 | "Device state set to Failed. Please Reboot\n"); |
| 2054 | } else if (!(val & 0x11111111)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2055 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); |
| 2056 | |
| 2057 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2058 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2059 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2060 | |
| 2061 | qlcnic_api_unlock(adapter); |
| 2062 | err: |
| 2063 | adapter->fw_fail_cnt = 0; |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2064 | adapter->flags &= ~QLCNIC_FW_HANG; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2065 | clear_bit(__QLCNIC_START_FW, &adapter->state); |
| 2066 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2067 | } |
| 2068 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2069 | /* Grab api lock, before checking state */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2070 | static int |
| 2071 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) |
| 2072 | { |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2073 | int act, state, active_mask; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2074 | |
| 2075 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2076 | act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2077 | |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2078 | if (adapter->flags & QLCNIC_FW_RESET_OWNER) { |
| 2079 | active_mask = (~(1 << (adapter->ahw->pci_func * 4))); |
| 2080 | act = act & active_mask; |
| 2081 | } |
| 2082 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2083 | if (((state & 0x11111111) == (act & 0x11111111)) || |
| 2084 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) |
| 2085 | return 0; |
| 2086 | else |
| 2087 | return 1; |
| 2088 | } |
| 2089 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2090 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
| 2091 | { |
| 2092 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); |
| 2093 | |
| 2094 | if (val != QLCNIC_DRV_IDC_VER) { |
| 2095 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" |
| 2096 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); |
| 2097 | } |
| 2098 | |
| 2099 | return 0; |
| 2100 | } |
| 2101 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2102 | static int |
| 2103 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) |
| 2104 | { |
| 2105 | u32 val, prev_state; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2106 | u8 dev_init_timeo = adapter->dev_init_timeo; |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2107 | u8 portnum = adapter->portnum; |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2108 | u8 ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2109 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2110 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
| 2111 | return 1; |
| 2112 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2113 | if (qlcnic_api_lock(adapter)) |
| 2114 | return -1; |
| 2115 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2116 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2117 | if (!(val & (1 << (portnum * 4)))) { |
| 2118 | QLC_DEV_SET_REF_CNT(val, portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2119 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2123 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2124 | |
| 2125 | switch (prev_state) { |
| 2126 | case QLCNIC_DEV_COLD: |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2127 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2128 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2129 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2130 | qlcnic_api_unlock(adapter); |
| 2131 | return 1; |
| 2132 | |
| 2133 | case QLCNIC_DEV_READY: |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2134 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2135 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2136 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2137 | |
| 2138 | case QLCNIC_DEV_NEED_RESET: |
| 2139 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2140 | QLC_DEV_SET_RST_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2141 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2142 | break; |
| 2143 | |
| 2144 | case QLCNIC_DEV_NEED_QUISCENT: |
| 2145 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2146 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2147 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2148 | break; |
| 2149 | |
| 2150 | case QLCNIC_DEV_FAILED: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 2151 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2152 | qlcnic_api_unlock(adapter); |
| 2153 | return -1; |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2154 | |
| 2155 | case QLCNIC_DEV_INITIALIZING: |
| 2156 | case QLCNIC_DEV_QUISCENT: |
| 2157 | break; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2161 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2162 | do { |
| 2163 | msleep(1000); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2164 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2165 | |
| 2166 | if (prev_state == QLCNIC_DEV_QUISCENT) |
| 2167 | continue; |
| 2168 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2169 | |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2170 | if (!dev_init_timeo) { |
| 2171 | dev_err(&adapter->pdev->dev, |
| 2172 | "Waiting for device to initialize timeout\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2173 | return -1; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2174 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2175 | |
| 2176 | if (qlcnic_api_lock(adapter)) |
| 2177 | return -1; |
| 2178 | |
| 2179 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2180 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2181 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2182 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2183 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2184 | qlcnic_api_unlock(adapter); |
| 2185 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2186 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | static void |
| 2190 | qlcnic_fwinit_work(struct work_struct *work) |
| 2191 | { |
| 2192 | struct qlcnic_adapter *adapter = container_of(work, |
| 2193 | struct qlcnic_adapter, fw_work.work); |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2194 | u32 dev_state = 0xf; |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2195 | u32 val; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2196 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2197 | if (qlcnic_api_lock(adapter)) |
| 2198 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2199 | |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2200 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2201 | if (dev_state == QLCNIC_DEV_QUISCENT || |
| 2202 | dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2203 | qlcnic_api_unlock(adapter); |
| 2204 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2205 | FW_POLL_DELAY * 2); |
| 2206 | return; |
| 2207 | } |
| 2208 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2209 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2210 | qlcnic_api_unlock(adapter); |
| 2211 | goto wait_npar; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Sritej Velaga | 16e3cf7 | 2011-10-28 12:57:11 +0000 | [diff] [blame] | 2214 | if (dev_state == QLCNIC_DEV_INITIALIZING || |
| 2215 | dev_state == QLCNIC_DEV_READY) { |
| 2216 | dev_info(&adapter->pdev->dev, "Detected state change from " |
| 2217 | "DEV_NEED_RESET, skipping ack check\n"); |
| 2218 | goto skip_ack_check; |
| 2219 | } |
| 2220 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2221 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
Sritej Velaga | 16e3cf7 | 2011-10-28 12:57:11 +0000 | [diff] [blame] | 2222 | dev_info(&adapter->pdev->dev, "Reset:Failed to get ack %d sec\n", |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2223 | adapter->reset_ack_timeo); |
| 2224 | goto skip_ack_check; |
| 2225 | } |
| 2226 | |
| 2227 | if (!qlcnic_check_drv_state(adapter)) { |
| 2228 | skip_ack_check: |
| 2229 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2230 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2231 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
| 2232 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2233 | QLCNIC_DEV_INITIALIZING); |
| 2234 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2235 | QLCDB(adapter, DRV, "Restarting fw\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2236 | qlcnic_idc_debug_info(adapter, 0); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2237 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2238 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
| 2239 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2242 | qlcnic_api_unlock(adapter); |
| 2243 | |
Anirban Chakraborty | 287e38a | 2011-06-22 02:52:18 +0000 | [diff] [blame] | 2244 | rtnl_lock(); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2245 | if (adapter->ahw->fw_dump.enable && |
| 2246 | (adapter->flags & QLCNIC_FW_RESET_OWNER)) { |
Anirban Chakraborty | 9d6a644 | 2011-06-22 02:52:22 +0000 | [diff] [blame] | 2247 | QLCDB(adapter, DRV, "Take FW dump\n"); |
| 2248 | qlcnic_dump_fw(adapter); |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2249 | adapter->flags |= QLCNIC_FW_HANG; |
Anirban Chakraborty | 9d6a644 | 2011-06-22 02:52:22 +0000 | [diff] [blame] | 2250 | } |
Anirban Chakraborty | 287e38a | 2011-06-22 02:52:18 +0000 | [diff] [blame] | 2251 | rtnl_unlock(); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2252 | |
| 2253 | adapter->flags &= ~QLCNIC_FW_RESET_OWNER; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2254 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2255 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2256 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2257 | return; |
| 2258 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2259 | goto err_ret; |
| 2260 | } |
| 2261 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2262 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2263 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2264 | wait_npar: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2265 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2266 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2267 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2268 | switch (dev_state) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2269 | case QLCNIC_DEV_READY: |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2270 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2271 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2272 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2273 | return; |
| 2274 | } |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2275 | case QLCNIC_DEV_FAILED: |
| 2276 | break; |
| 2277 | default: |
| 2278 | qlcnic_schedule_work(adapter, |
| 2279 | qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2280 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | err_ret: |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2284 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
| 2285 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2286 | netif_device_attach(adapter->netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2287 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | static void |
| 2291 | qlcnic_detach_work(struct work_struct *work) |
| 2292 | { |
| 2293 | struct qlcnic_adapter *adapter = container_of(work, |
| 2294 | struct qlcnic_adapter, fw_work.work); |
| 2295 | struct net_device *netdev = adapter->netdev; |
| 2296 | u32 status; |
| 2297 | |
| 2298 | netif_device_detach(netdev); |
| 2299 | |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2300 | /* Dont grab rtnl lock during Quiscent mode */ |
| 2301 | if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
| 2302 | if (netif_running(netdev)) |
| 2303 | __qlcnic_down(adapter, netdev); |
| 2304 | } else |
| 2305 | qlcnic_down(adapter, netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2306 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2307 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
| 2308 | |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2309 | if (status & QLCNIC_RCODE_FATAL_ERROR) { |
| 2310 | dev_err(&adapter->pdev->dev, |
| 2311 | "Detaching the device: peg halt status1=0x%x\n", |
| 2312 | status); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2313 | |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2314 | if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { |
| 2315 | dev_err(&adapter->pdev->dev, |
| 2316 | "On board active cooling fan failed. " |
| 2317 | "Device has been halted.\n"); |
| 2318 | dev_err(&adapter->pdev->dev, |
| 2319 | "Replace the adapter.\n"); |
| 2320 | } |
| 2321 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2322 | goto err_ret; |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | if (adapter->temp == QLCNIC_TEMP_PANIC) { |
| 2326 | dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", |
| 2327 | adapter->temp); |
| 2328 | goto err_ret; |
| 2329 | } |
| 2330 | |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2331 | /* Dont ack if this instance is the reset owner */ |
| 2332 | if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2333 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { |
| 2334 | dev_err(&adapter->pdev->dev, |
| 2335 | "Failed to set driver state," |
| 2336 | "detaching the device.\n"); |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2337 | goto err_ret; |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2338 | } |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2339 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2340 | |
| 2341 | adapter->fw_wait_cnt = 0; |
| 2342 | |
| 2343 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2344 | |
| 2345 | return; |
| 2346 | |
| 2347 | err_ret: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2348 | netif_device_attach(netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2349 | qlcnic_clr_all_drv_state(adapter, 1); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2352 | /*Transit NPAR state to NON Operational */ |
| 2353 | static void |
| 2354 | qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) |
| 2355 | { |
| 2356 | u32 state; |
| 2357 | |
| 2358 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2359 | if (state == QLCNIC_DEV_NPAR_NON_OPER) |
| 2360 | return; |
| 2361 | |
| 2362 | if (qlcnic_api_lock(adapter)) |
| 2363 | return; |
| 2364 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
| 2365 | qlcnic_api_unlock(adapter); |
| 2366 | } |
| 2367 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2368 | /*Transit to RESET state from READY state only */ |
Anirban Chakraborty | 18f2f61 | 2011-05-12 12:48:33 +0000 | [diff] [blame] | 2369 | void |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2370 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) |
| 2371 | { |
Sritej Velaga | 646779f | 2012-02-03 13:45:41 +0000 | [diff] [blame] | 2372 | u32 state, xg_val = 0, gb_val = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2373 | |
Sritej Velaga | 646779f | 2012-02-03 13:45:41 +0000 | [diff] [blame] | 2374 | qlcnic_xg_set_xg0_mask(xg_val); |
| 2375 | qlcnic_xg_set_xg1_mask(xg_val); |
| 2376 | QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); |
| 2377 | qlcnic_gb_set_gb0_mask(gb_val); |
| 2378 | qlcnic_gb_set_gb1_mask(gb_val); |
| 2379 | qlcnic_gb_set_gb2_mask(gb_val); |
| 2380 | qlcnic_gb_set_gb3_mask(gb_val); |
| 2381 | QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); |
| 2382 | dev_info(&adapter->pdev->dev, "Pause control frames disabled" |
| 2383 | " on all ports\n"); |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 2384 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2385 | if (qlcnic_api_lock(adapter)) |
| 2386 | return; |
| 2387 | |
| 2388 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 2389 | if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) { |
| 2390 | netdev_err(adapter->netdev, |
| 2391 | "Device is in FAILED state, Please Reboot\n"); |
| 2392 | qlcnic_api_unlock(adapter); |
| 2393 | return; |
| 2394 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2395 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2396 | if (state == QLCNIC_DEV_READY) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2397 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2398 | adapter->flags |= QLCNIC_FW_RESET_OWNER; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2399 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2400 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2403 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2404 | qlcnic_api_unlock(adapter); |
| 2405 | } |
| 2406 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2407 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
| 2408 | static void |
| 2409 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) |
| 2410 | { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2411 | if (qlcnic_api_lock(adapter)) |
| 2412 | return; |
| 2413 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2414 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); |
| 2415 | QLCDB(adapter, DRV, "NPAR operational state set\n"); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2416 | |
| 2417 | qlcnic_api_unlock(adapter); |
| 2418 | } |
| 2419 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2420 | static void |
| 2421 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 2422 | work_func_t func, int delay) |
| 2423 | { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2424 | if (test_bit(__QLCNIC_AER, &adapter->state)) |
| 2425 | return; |
| 2426 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2427 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2428 | queue_delayed_work(qlcnic_wq, &adapter->fw_work, |
| 2429 | round_jiffies_relative(delay)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) |
| 2434 | { |
| 2435 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2436 | msleep(10); |
| 2437 | |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 2438 | if (!adapter->fw_work.work.func) |
| 2439 | return; |
| 2440 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2441 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2442 | } |
| 2443 | |
| 2444 | static void |
| 2445 | qlcnic_attach_work(struct work_struct *work) |
| 2446 | { |
| 2447 | struct qlcnic_adapter *adapter = container_of(work, |
| 2448 | struct qlcnic_adapter, fw_work.work); |
| 2449 | struct net_device *netdev = adapter->netdev; |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2450 | u32 npar_state; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2451 | |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2452 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) { |
| 2453 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2454 | if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) |
| 2455 | qlcnic_clr_all_drv_state(adapter, 0); |
| 2456 | else if (npar_state != QLCNIC_DEV_NPAR_OPER) |
| 2457 | qlcnic_schedule_work(adapter, qlcnic_attach_work, |
| 2458 | FW_POLL_DELAY); |
| 2459 | else |
| 2460 | goto attach; |
| 2461 | QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); |
| 2462 | return; |
| 2463 | } |
| 2464 | attach: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2465 | if (netif_running(netdev)) { |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 2466 | if (qlcnic_up(adapter, netdev)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2467 | goto done; |
| 2468 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2469 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2472 | done: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2473 | netif_device_attach(netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2474 | adapter->fw_fail_cnt = 0; |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2475 | adapter->flags &= ~QLCNIC_FW_HANG; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2476 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2477 | |
| 2478 | if (!qlcnic_clr_drv_state(adapter)) |
| 2479 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2480 | FW_POLL_DELAY); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | static int |
| 2484 | qlcnic_check_health(struct qlcnic_adapter *adapter) |
| 2485 | { |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 2486 | u32 state = 0, heartbeat; |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2487 | u32 peg_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2488 | |
| 2489 | if (qlcnic_check_temp(adapter)) |
| 2490 | goto detach; |
| 2491 | |
Amit Kumar Salecha | 2372a5f | 2010-05-13 03:07:42 +0000 | [diff] [blame] | 2492 | if (adapter->need_fw_reset) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2493 | qlcnic_dev_request_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2494 | |
| 2495 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2496 | if (state == QLCNIC_DEV_NEED_RESET) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2497 | qlcnic_set_npar_non_operational(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2498 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2499 | } else if (state == QLCNIC_DEV_NEED_QUISCENT) |
| 2500 | goto detach; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2501 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 2502 | heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 2503 | if (heartbeat != adapter->heartbeat) { |
| 2504 | adapter->heartbeat = heartbeat; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2505 | adapter->fw_fail_cnt = 0; |
| 2506 | if (adapter->need_fw_reset) |
| 2507 | goto detach; |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 2508 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2509 | if (adapter->reset_context && auto_fw_reset) { |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 2510 | qlcnic_reset_hw_context(adapter); |
| 2511 | adapter->netdev->trans_start = jiffies; |
| 2512 | } |
| 2513 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2514 | return 0; |
| 2515 | } |
| 2516 | |
| 2517 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) |
| 2518 | return 0; |
| 2519 | |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2520 | adapter->flags |= QLCNIC_FW_HANG; |
| 2521 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2522 | qlcnic_dev_request_reset(adapter); |
| 2523 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2524 | if (auto_fw_reset) |
Amit Kumar Salecha | 0df170b | 2010-07-13 20:33:32 +0000 | [diff] [blame] | 2525 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2526 | |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2527 | dev_err(&adapter->pdev->dev, "firmware hang detected\n"); |
| 2528 | dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" |
Sritej Velaga | c76ecb7 | 2011-07-29 13:30:29 +0000 | [diff] [blame] | 2529 | "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" |
| 2530 | "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" |
| 2531 | "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" |
| 2532 | "PEG_NET_4_PC: 0x%x\n", |
| 2533 | QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1), |
| 2534 | QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2), |
| 2535 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), |
| 2536 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), |
| 2537 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), |
| 2538 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), |
| 2539 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2540 | peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
Sritej Velaga | 97048a1 | 2012-02-03 13:45:43 +0000 | [diff] [blame] | 2541 | if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2542 | dev_err(&adapter->pdev->dev, |
| 2543 | "Firmware aborted with error code 0x00006700. " |
| 2544 | "Device is being reset.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2545 | detach: |
| 2546 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : |
| 2547 | QLCNIC_DEV_NEED_RESET; |
| 2548 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2549 | if (auto_fw_reset && |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2550 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
| 2551 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2552 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2553 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
| 2554 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2555 | |
| 2556 | return 1; |
| 2557 | } |
| 2558 | |
| 2559 | static void |
| 2560 | qlcnic_fw_poll_work(struct work_struct *work) |
| 2561 | { |
| 2562 | struct qlcnic_adapter *adapter = container_of(work, |
| 2563 | struct qlcnic_adapter, fw_work.work); |
| 2564 | |
| 2565 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2566 | goto reschedule; |
| 2567 | |
| 2568 | |
| 2569 | if (qlcnic_check_health(adapter)) |
| 2570 | return; |
| 2571 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 2572 | if (adapter->fhash.fnum) |
| 2573 | qlcnic_prune_lb_filters(adapter); |
| 2574 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2575 | reschedule: |
| 2576 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 2577 | } |
| 2578 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2579 | static int qlcnic_is_first_func(struct pci_dev *pdev) |
| 2580 | { |
| 2581 | struct pci_dev *oth_pdev; |
| 2582 | int val = pdev->devfn; |
| 2583 | |
| 2584 | while (val-- > 0) { |
| 2585 | oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr |
| 2586 | (pdev->bus), pdev->bus->number, |
| 2587 | PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2588 | if (!oth_pdev) |
| 2589 | continue; |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2590 | |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2591 | if (oth_pdev->current_state != PCI_D3cold) { |
| 2592 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2593 | return 0; |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2594 | } |
| 2595 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2596 | } |
| 2597 | return 1; |
| 2598 | } |
| 2599 | |
| 2600 | static int qlcnic_attach_func(struct pci_dev *pdev) |
| 2601 | { |
| 2602 | int err, first_func; |
| 2603 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2604 | struct net_device *netdev = adapter->netdev; |
| 2605 | |
| 2606 | pdev->error_state = pci_channel_io_normal; |
| 2607 | |
| 2608 | err = pci_enable_device(pdev); |
| 2609 | if (err) |
| 2610 | return err; |
| 2611 | |
| 2612 | pci_set_power_state(pdev, PCI_D0); |
| 2613 | pci_set_master(pdev); |
| 2614 | pci_restore_state(pdev); |
| 2615 | |
| 2616 | first_func = qlcnic_is_first_func(pdev); |
| 2617 | |
| 2618 | if (qlcnic_api_lock(adapter)) |
| 2619 | return -EINVAL; |
| 2620 | |
Amit Kumar Salecha | 933fce12 | 2010-08-17 00:34:19 +0000 | [diff] [blame] | 2621 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2622 | adapter->need_fw_reset = 1; |
| 2623 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2624 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
| 2625 | QLCDB(adapter, DRV, "Restarting fw\n"); |
| 2626 | } |
| 2627 | qlcnic_api_unlock(adapter); |
| 2628 | |
| 2629 | err = adapter->nic_ops->start_firmware(adapter); |
| 2630 | if (err) |
| 2631 | return err; |
| 2632 | |
| 2633 | qlcnic_clr_drv_state(adapter); |
| 2634 | qlcnic_setup_intr(adapter); |
| 2635 | |
| 2636 | if (netif_running(netdev)) { |
| 2637 | err = qlcnic_attach(adapter); |
| 2638 | if (err) { |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2639 | qlcnic_clr_all_drv_state(adapter, 1); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2640 | clear_bit(__QLCNIC_AER, &adapter->state); |
| 2641 | netif_device_attach(netdev); |
| 2642 | return err; |
| 2643 | } |
| 2644 | |
| 2645 | err = qlcnic_up(adapter, netdev); |
| 2646 | if (err) |
| 2647 | goto done; |
| 2648 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2649 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2650 | } |
| 2651 | done: |
| 2652 | netif_device_attach(netdev); |
| 2653 | return err; |
| 2654 | } |
| 2655 | |
| 2656 | static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, |
| 2657 | pci_channel_state_t state) |
| 2658 | { |
| 2659 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2660 | struct net_device *netdev = adapter->netdev; |
| 2661 | |
| 2662 | if (state == pci_channel_io_perm_failure) |
| 2663 | return PCI_ERS_RESULT_DISCONNECT; |
| 2664 | |
| 2665 | if (state == pci_channel_io_normal) |
| 2666 | return PCI_ERS_RESULT_RECOVERED; |
| 2667 | |
| 2668 | set_bit(__QLCNIC_AER, &adapter->state); |
| 2669 | netif_device_detach(netdev); |
| 2670 | |
| 2671 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2672 | |
| 2673 | if (netif_running(netdev)) |
| 2674 | qlcnic_down(adapter, netdev); |
| 2675 | |
| 2676 | qlcnic_detach(adapter); |
| 2677 | qlcnic_teardown_intr(adapter); |
| 2678 | |
| 2679 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2680 | |
| 2681 | pci_save_state(pdev); |
| 2682 | pci_disable_device(pdev); |
| 2683 | |
| 2684 | return PCI_ERS_RESULT_NEED_RESET; |
| 2685 | } |
| 2686 | |
| 2687 | static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) |
| 2688 | { |
| 2689 | return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : |
| 2690 | PCI_ERS_RESULT_RECOVERED; |
| 2691 | } |
| 2692 | |
| 2693 | static void qlcnic_io_resume(struct pci_dev *pdev) |
| 2694 | { |
| 2695 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2696 | |
| 2697 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 2698 | |
| 2699 | if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && |
| 2700 | test_and_clear_bit(__QLCNIC_AER, &adapter->state)) |
| 2701 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2702 | FW_POLL_DELAY); |
| 2703 | } |
| 2704 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2705 | static int |
| 2706 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) |
| 2707 | { |
| 2708 | int err; |
| 2709 | |
| 2710 | err = qlcnic_can_start_firmware(adapter); |
| 2711 | if (err) |
| 2712 | return err; |
| 2713 | |
Amit Kumar Salecha | 78f84e1 | 2010-08-19 05:08:28 +0000 | [diff] [blame] | 2714 | err = qlcnic_check_npar_opertional(adapter); |
| 2715 | if (err) |
| 2716 | return err; |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2717 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 2718 | err = qlcnic_initialize_nic(adapter); |
| 2719 | if (err) |
| 2720 | return err; |
| 2721 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2722 | qlcnic_check_options(adapter); |
| 2723 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 2724 | err = qlcnic_set_eswitch_port_config(adapter); |
| 2725 | if (err) |
| 2726 | return err; |
| 2727 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2728 | adapter->need_fw_reset = 0; |
| 2729 | |
| 2730 | return err; |
| 2731 | } |
| 2732 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 2733 | int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val) |
| 2734 | { |
| 2735 | if (!use_msi_x && !use_msi) { |
| 2736 | netdev_info(netdev, "no msix or msi support, hence no rss\n"); |
| 2737 | return -EINVAL; |
| 2738 | } |
| 2739 | |
| 2740 | if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) { |
| 2741 | netdev_info(netdev, "rss_ring valid range [2 - %x] in " |
| 2742 | " powers of 2\n", max_hw); |
| 2743 | return -EINVAL; |
| 2744 | } |
| 2745 | return 0; |
| 2746 | |
| 2747 | } |
| 2748 | |
| 2749 | int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data) |
| 2750 | { |
| 2751 | struct net_device *netdev = adapter->netdev; |
| 2752 | int err = 0; |
| 2753 | |
| 2754 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2755 | return -EBUSY; |
| 2756 | |
| 2757 | netif_device_detach(netdev); |
| 2758 | if (netif_running(netdev)) |
| 2759 | __qlcnic_down(adapter, netdev); |
| 2760 | qlcnic_detach(adapter); |
| 2761 | qlcnic_teardown_intr(adapter); |
| 2762 | |
| 2763 | if (qlcnic_enable_msix(adapter, data)) { |
| 2764 | netdev_info(netdev, "failed setting max_rss; rss disabled\n"); |
| 2765 | qlcnic_enable_msi_legacy(adapter); |
| 2766 | } |
| 2767 | |
| 2768 | if (netif_running(netdev)) { |
| 2769 | err = qlcnic_attach(adapter); |
| 2770 | if (err) |
| 2771 | goto done; |
| 2772 | err = __qlcnic_up(adapter, netdev); |
| 2773 | if (err) |
| 2774 | goto done; |
| 2775 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
| 2776 | } |
| 2777 | done: |
| 2778 | netif_device_attach(netdev); |
| 2779 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2780 | return err; |
| 2781 | } |
| 2782 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2783 | #ifdef CONFIG_INET |
| 2784 | |
| 2785 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) |
| 2786 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2787 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2788 | qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, |
| 2789 | struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2790 | { |
| 2791 | struct in_device *indev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2792 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2793 | indev = in_dev_get(dev); |
| 2794 | if (!indev) |
| 2795 | return; |
| 2796 | |
| 2797 | for_ifa(indev) { |
| 2798 | switch (event) { |
| 2799 | case NETDEV_UP: |
| 2800 | qlcnic_config_ipaddr(adapter, |
| 2801 | ifa->ifa_address, QLCNIC_IP_UP); |
| 2802 | break; |
| 2803 | case NETDEV_DOWN: |
| 2804 | qlcnic_config_ipaddr(adapter, |
| 2805 | ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2806 | break; |
| 2807 | default: |
| 2808 | break; |
| 2809 | } |
| 2810 | } endfor_ifa(indev); |
| 2811 | |
| 2812 | in_dev_put(indev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2815 | static void |
| 2816 | qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) |
| 2817 | { |
| 2818 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2819 | struct net_device *dev; |
| 2820 | u16 vid; |
| 2821 | |
| 2822 | qlcnic_config_indev_addr(adapter, netdev, event); |
| 2823 | |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 2824 | for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { |
Jiri Pirko | 223bb15 | 2011-07-20 04:54:44 +0000 | [diff] [blame] | 2825 | dev = __vlan_find_dev_deep(netdev, vid); |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2826 | if (!dev) |
| 2827 | continue; |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2828 | qlcnic_config_indev_addr(adapter, dev, event); |
| 2829 | } |
| 2830 | } |
| 2831 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2832 | static int qlcnic_netdev_event(struct notifier_block *this, |
| 2833 | unsigned long event, void *ptr) |
| 2834 | { |
| 2835 | struct qlcnic_adapter *adapter; |
| 2836 | struct net_device *dev = (struct net_device *)ptr; |
| 2837 | |
| 2838 | recheck: |
| 2839 | if (dev == NULL) |
| 2840 | goto done; |
| 2841 | |
| 2842 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2843 | dev = vlan_dev_real_dev(dev); |
| 2844 | goto recheck; |
| 2845 | } |
| 2846 | |
| 2847 | if (!is_qlcnic_netdev(dev)) |
| 2848 | goto done; |
| 2849 | |
| 2850 | adapter = netdev_priv(dev); |
| 2851 | |
| 2852 | if (!adapter) |
| 2853 | goto done; |
| 2854 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2855 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2856 | goto done; |
| 2857 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2858 | qlcnic_config_indev_addr(adapter, dev, event); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2859 | done: |
| 2860 | return NOTIFY_DONE; |
| 2861 | } |
| 2862 | |
| 2863 | static int |
| 2864 | qlcnic_inetaddr_event(struct notifier_block *this, |
| 2865 | unsigned long event, void *ptr) |
| 2866 | { |
| 2867 | struct qlcnic_adapter *adapter; |
| 2868 | struct net_device *dev; |
| 2869 | |
| 2870 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 2871 | |
| 2872 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 2873 | |
| 2874 | recheck: |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2875 | if (dev == NULL) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2876 | goto done; |
| 2877 | |
| 2878 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2879 | dev = vlan_dev_real_dev(dev); |
| 2880 | goto recheck; |
| 2881 | } |
| 2882 | |
| 2883 | if (!is_qlcnic_netdev(dev)) |
| 2884 | goto done; |
| 2885 | |
| 2886 | adapter = netdev_priv(dev); |
| 2887 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 2888 | if (!adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2889 | goto done; |
| 2890 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2891 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2892 | goto done; |
| 2893 | |
| 2894 | switch (event) { |
| 2895 | case NETDEV_UP: |
| 2896 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); |
| 2897 | break; |
| 2898 | case NETDEV_DOWN: |
| 2899 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2900 | break; |
| 2901 | default: |
| 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | done: |
| 2906 | return NOTIFY_DONE; |
| 2907 | } |
| 2908 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2909 | static struct notifier_block qlcnic_netdev_cb = { |
| 2910 | .notifier_call = qlcnic_netdev_event, |
| 2911 | }; |
| 2912 | |
| 2913 | static struct notifier_block qlcnic_inetaddr_cb = { |
| 2914 | .notifier_call = qlcnic_inetaddr_event, |
| 2915 | }; |
| 2916 | #else |
| 2917 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2918 | qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2919 | { } |
| 2920 | #endif |
Shahed Shaikh | 6350759 | 2012-11-23 23:56:52 +0000 | [diff] [blame] | 2921 | static struct pci_error_handlers qlcnic_err_handler = { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2922 | .error_detected = qlcnic_io_error_detected, |
| 2923 | .slot_reset = qlcnic_io_slot_reset, |
| 2924 | .resume = qlcnic_io_resume, |
| 2925 | }; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2926 | |
| 2927 | static struct pci_driver qlcnic_driver = { |
| 2928 | .name = qlcnic_driver_name, |
| 2929 | .id_table = qlcnic_pci_tbl, |
| 2930 | .probe = qlcnic_probe, |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame^] | 2931 | .remove = qlcnic_remove, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2932 | #ifdef CONFIG_PM |
| 2933 | .suspend = qlcnic_suspend, |
| 2934 | .resume = qlcnic_resume, |
| 2935 | #endif |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2936 | .shutdown = qlcnic_shutdown, |
| 2937 | .err_handler = &qlcnic_err_handler |
| 2938 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2939 | }; |
| 2940 | |
| 2941 | static int __init qlcnic_init_module(void) |
| 2942 | { |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2943 | int ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2944 | |
| 2945 | printk(KERN_INFO "%s\n", qlcnic_driver_string); |
| 2946 | |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2947 | qlcnic_wq = create_singlethread_workqueue("qlcnic"); |
| 2948 | if (qlcnic_wq == NULL) { |
| 2949 | printk(KERN_ERR "qlcnic: cannot create workqueue\n"); |
| 2950 | return -ENOMEM; |
| 2951 | } |
| 2952 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2953 | #ifdef CONFIG_INET |
| 2954 | register_netdevice_notifier(&qlcnic_netdev_cb); |
| 2955 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2956 | #endif |
| 2957 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2958 | ret = pci_register_driver(&qlcnic_driver); |
| 2959 | if (ret) { |
| 2960 | #ifdef CONFIG_INET |
| 2961 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2962 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 2963 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2964 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2965 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2966 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2967 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | module_init(qlcnic_init_module); |
| 2971 | |
| 2972 | static void __exit qlcnic_exit_module(void) |
| 2973 | { |
| 2974 | |
| 2975 | pci_unregister_driver(&qlcnic_driver); |
| 2976 | |
| 2977 | #ifdef CONFIG_INET |
| 2978 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2979 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 2980 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2981 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | module_exit(qlcnic_exit_module); |