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 | |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1564 | if (qlcnic_82xx_check(adapter)) |
| 1565 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 1566 | FW_POLL_DELAY); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1567 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1568 | switch (adapter->ahw->port_type) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1569 | case QLCNIC_GBE: |
| 1570 | dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", |
| 1571 | adapter->netdev->name); |
| 1572 | break; |
| 1573 | case QLCNIC_XGBE: |
| 1574 | dev_info(&adapter->pdev->dev, "%s: XGbE port initialized\n", |
| 1575 | adapter->netdev->name); |
| 1576 | break; |
| 1577 | } |
| 1578 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1579 | if (adapter->mac_learn) |
| 1580 | qlcnic_alloc_lb_filters_mem(adapter); |
| 1581 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1582 | qlcnic_create_diag_entries(adapter); |
| 1583 | |
| 1584 | return 0; |
| 1585 | |
| 1586 | err_out_disable_msi: |
| 1587 | qlcnic_teardown_intr(adapter); |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1588 | kfree(adapter->msix_entries); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1589 | |
| 1590 | err_out_decr_ref: |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 1591 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1592 | |
| 1593 | err_out_iounmap: |
| 1594 | qlcnic_cleanup_pci_map(adapter); |
| 1595 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1596 | err_out_free_hw: |
| 1597 | qlcnic_free_adapter_resources(adapter); |
| 1598 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1599 | err_out_free_netdev: |
| 1600 | free_netdev(netdev); |
| 1601 | |
| 1602 | err_out_free_res: |
| 1603 | pci_release_regions(pdev); |
| 1604 | |
| 1605 | err_out_disable_pdev: |
| 1606 | pci_set_drvdata(pdev, NULL); |
| 1607 | pci_disable_device(pdev); |
| 1608 | return err; |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1609 | |
| 1610 | err_out_maintenance_mode: |
| 1611 | netdev->netdev_ops = &qlcnic_netdev_failed_ops; |
| 1612 | SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_failed_ops); |
| 1613 | err = register_netdev(netdev); |
| 1614 | if (err) { |
| 1615 | dev_err(&pdev->dev, "failed to register net device\n"); |
| 1616 | goto err_out_decr_ref; |
| 1617 | } |
| 1618 | pci_set_drvdata(pdev, adapter); |
| 1619 | qlcnic_create_diag_entries(adapter); |
| 1620 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame] | 1623 | static void qlcnic_remove(struct pci_dev *pdev) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1624 | { |
| 1625 | struct qlcnic_adapter *adapter; |
| 1626 | struct net_device *netdev; |
| 1627 | |
| 1628 | adapter = pci_get_drvdata(pdev); |
| 1629 | if (adapter == NULL) |
| 1630 | return; |
| 1631 | |
| 1632 | netdev = adapter->netdev; |
| 1633 | |
| 1634 | qlcnic_cancel_fw_work(adapter); |
| 1635 | |
| 1636 | unregister_netdev(netdev); |
| 1637 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1638 | qlcnic_detach(adapter); |
| 1639 | |
Anirban Chakraborty | 2e9d722 | 2010-06-01 11:28:51 +0000 | [diff] [blame] | 1640 | if (adapter->npars != NULL) |
| 1641 | kfree(adapter->npars); |
| 1642 | if (adapter->eswitch != NULL) |
| 1643 | kfree(adapter->eswitch); |
| 1644 | |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1645 | if (qlcnic_82xx_check(adapter)) |
| 1646 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1647 | |
| 1648 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1649 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1650 | qlcnic_free_lb_filters_mem(adapter); |
| 1651 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1652 | qlcnic_teardown_intr(adapter); |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 1653 | kfree(adapter->msix_entries); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1654 | |
| 1655 | qlcnic_remove_diag_entries(adapter); |
| 1656 | |
| 1657 | qlcnic_cleanup_pci_map(adapter); |
| 1658 | |
| 1659 | qlcnic_release_firmware(adapter); |
| 1660 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 1661 | pci_disable_pcie_error_reporting(pdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1662 | pci_release_regions(pdev); |
| 1663 | pci_disable_device(pdev); |
| 1664 | pci_set_drvdata(pdev, NULL); |
| 1665 | |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1666 | qlcnic_free_adapter_resources(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1667 | free_netdev(netdev); |
| 1668 | } |
| 1669 | static int __qlcnic_shutdown(struct pci_dev *pdev) |
| 1670 | { |
| 1671 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1672 | struct net_device *netdev = adapter->netdev; |
| 1673 | int retval; |
| 1674 | |
| 1675 | netif_device_detach(netdev); |
| 1676 | |
| 1677 | qlcnic_cancel_fw_work(adapter); |
| 1678 | |
| 1679 | if (netif_running(netdev)) |
| 1680 | qlcnic_down(adapter, netdev); |
| 1681 | |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1682 | if (qlcnic_82xx_check(adapter)) |
| 1683 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1684 | |
| 1685 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 1686 | |
| 1687 | retval = pci_save_state(pdev); |
| 1688 | if (retval) |
| 1689 | return retval; |
| 1690 | |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1691 | if (qlcnic_82xx_check(adapter)) { |
| 1692 | if (qlcnic_wol_supported(adapter)) { |
| 1693 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 1694 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 1695 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
| 1701 | static void qlcnic_shutdown(struct pci_dev *pdev) |
| 1702 | { |
| 1703 | if (__qlcnic_shutdown(pdev)) |
| 1704 | return; |
| 1705 | |
| 1706 | pci_disable_device(pdev); |
| 1707 | } |
| 1708 | |
| 1709 | #ifdef CONFIG_PM |
| 1710 | static int |
| 1711 | qlcnic_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1712 | { |
| 1713 | int retval; |
| 1714 | |
| 1715 | retval = __qlcnic_shutdown(pdev); |
| 1716 | if (retval) |
| 1717 | return retval; |
| 1718 | |
| 1719 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | static int |
| 1724 | qlcnic_resume(struct pci_dev *pdev) |
| 1725 | { |
| 1726 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 1727 | struct net_device *netdev = adapter->netdev; |
| 1728 | int err; |
| 1729 | |
| 1730 | err = pci_enable_device(pdev); |
| 1731 | if (err) |
| 1732 | return err; |
| 1733 | |
| 1734 | pci_set_power_state(pdev, PCI_D0); |
| 1735 | pci_set_master(pdev); |
| 1736 | pci_restore_state(pdev); |
| 1737 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 1738 | err = adapter->nic_ops->start_firmware(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1739 | if (err) { |
| 1740 | dev_err(&pdev->dev, "failed to start firmware\n"); |
| 1741 | return err; |
| 1742 | } |
| 1743 | |
| 1744 | if (netif_running(netdev)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1745 | err = qlcnic_up(adapter, netdev); |
| 1746 | if (err) |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1747 | goto done; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1748 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 1749 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1750 | } |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 1751 | done: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1752 | netif_device_attach(netdev); |
| 1753 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 1754 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1755 | } |
| 1756 | #endif |
| 1757 | |
| 1758 | static int qlcnic_open(struct net_device *netdev) |
| 1759 | { |
| 1760 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1761 | u32 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1762 | int err; |
| 1763 | |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 1764 | if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) { |
| 1765 | netdev_err(netdev, "Device in FAILED state\n"); |
| 1766 | return -EIO; |
| 1767 | } |
| 1768 | |
Amit Kumar Salecha | c55ad8e | 2011-06-22 02:52:21 +0000 | [diff] [blame] | 1769 | netif_carrier_off(netdev); |
| 1770 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1771 | err = qlcnic_attach(adapter); |
| 1772 | if (err) |
| 1773 | return err; |
| 1774 | |
| 1775 | err = __qlcnic_up(adapter, netdev); |
| 1776 | if (err) |
| 1777 | goto err_out; |
| 1778 | |
| 1779 | netif_start_queue(netdev); |
| 1780 | |
| 1781 | return 0; |
| 1782 | |
| 1783 | err_out: |
| 1784 | qlcnic_detach(adapter); |
| 1785 | return err; |
| 1786 | } |
| 1787 | |
| 1788 | /* |
| 1789 | * qlcnic_close - Disables a network interface entry point |
| 1790 | */ |
| 1791 | static int qlcnic_close(struct net_device *netdev) |
| 1792 | { |
| 1793 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1794 | |
| 1795 | __qlcnic_down(adapter, netdev); |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1799 | void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1800 | { |
| 1801 | void *head; |
| 1802 | int i; |
| 1803 | |
Sucheta Chakraborty | e5dcf6d | 2011-07-14 03:16:52 +0000 | [diff] [blame] | 1804 | if (adapter->fhash.fmax && adapter->fhash.fhead) |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1805 | return; |
| 1806 | |
| 1807 | spin_lock_init(&adapter->mac_learn_lock); |
| 1808 | |
| 1809 | head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head), |
| 1810 | GFP_KERNEL); |
| 1811 | if (!head) |
| 1812 | return; |
| 1813 | |
| 1814 | adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS; |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 1815 | adapter->fhash.fhead = head; |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 1816 | |
| 1817 | for (i = 0; i < adapter->fhash.fmax; i++) |
| 1818 | INIT_HLIST_HEAD(&adapter->fhash.fhead[i]); |
| 1819 | } |
| 1820 | |
| 1821 | static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter) |
| 1822 | { |
| 1823 | if (adapter->fhash.fmax && adapter->fhash.fhead) |
| 1824 | kfree(adapter->fhash.fhead); |
| 1825 | |
| 1826 | adapter->fhash.fhead = NULL; |
| 1827 | adapter->fhash.fmax = 0; |
| 1828 | } |
| 1829 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1830 | static int qlcnic_check_temp(struct qlcnic_adapter *adapter) |
| 1831 | { |
| 1832 | struct net_device *netdev = adapter->netdev; |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1833 | u32 temp_state, temp_val, temp = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1834 | int rv = 0; |
| 1835 | |
Sony Chacko | 97ee45e | 2012-12-04 03:33:52 +0000 | [diff] [blame^] | 1836 | if (qlcnic_82xx_check(adapter)) |
| 1837 | temp = QLCRD32(adapter, CRB_TEMP_STATE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1838 | |
| 1839 | temp_state = qlcnic_get_temp_state(temp); |
| 1840 | temp_val = qlcnic_get_temp_val(temp); |
| 1841 | |
| 1842 | if (temp_state == QLCNIC_TEMP_PANIC) { |
| 1843 | dev_err(&netdev->dev, |
| 1844 | "Device temperature %d degrees C exceeds" |
| 1845 | " maximum allowed. Hardware has been shut down.\n", |
| 1846 | temp_val); |
| 1847 | rv = 1; |
| 1848 | } else if (temp_state == QLCNIC_TEMP_WARN) { |
| 1849 | if (adapter->temp == QLCNIC_TEMP_NORMAL) { |
| 1850 | dev_err(&netdev->dev, |
| 1851 | "Device temperature %d degrees C " |
| 1852 | "exceeds operating range." |
| 1853 | " Immediate action needed.\n", |
| 1854 | temp_val); |
| 1855 | } |
| 1856 | } else { |
| 1857 | if (adapter->temp == QLCNIC_TEMP_WARN) { |
| 1858 | dev_info(&netdev->dev, |
| 1859 | "Device temperature is now %d degrees C" |
| 1860 | " in normal range.\n", temp_val); |
| 1861 | } |
| 1862 | } |
| 1863 | adapter->temp = temp_state; |
| 1864 | return rv; |
| 1865 | } |
| 1866 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1867 | static void qlcnic_tx_timeout(struct net_device *netdev) |
| 1868 | { |
| 1869 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1870 | |
| 1871 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 1872 | return; |
| 1873 | |
| 1874 | dev_err(&netdev->dev, "transmit timeout, resetting.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1875 | |
| 1876 | if (++adapter->tx_timeo_cnt >= QLCNIC_MAX_TX_TIMEOUTS) |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 1877 | adapter->need_fw_reset = 1; |
| 1878 | else |
| 1879 | adapter->reset_context = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev) |
| 1883 | { |
| 1884 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 1885 | struct net_device_stats *stats = &netdev->stats; |
| 1886 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1887 | stats->rx_packets = adapter->stats.rx_pkts + adapter->stats.lro_pkts; |
| 1888 | stats->tx_packets = adapter->stats.xmitfinished; |
Sucheta Chakraborty | 7e38259 | 2010-05-17 01:22:10 +0000 | [diff] [blame] | 1889 | stats->rx_bytes = adapter->stats.rxbytes + adapter->stats.lrobytes; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1890 | stats->tx_bytes = adapter->stats.txbytes; |
| 1891 | stats->rx_dropped = adapter->stats.rxdropped; |
| 1892 | stats->tx_dropped = adapter->stats.txdropped; |
| 1893 | |
| 1894 | return stats; |
| 1895 | } |
| 1896 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1897 | static irqreturn_t qlcnic_clear_legacy_intr(struct qlcnic_adapter *adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1898 | { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1899 | u32 status; |
| 1900 | |
| 1901 | status = readl(adapter->isr_int_vec); |
| 1902 | |
| 1903 | if (!(status & adapter->int_vec_bit)) |
| 1904 | return IRQ_NONE; |
| 1905 | |
| 1906 | /* check interrupt state machine, to be sure */ |
| 1907 | status = readl(adapter->crb_int_state_reg); |
| 1908 | if (!ISR_LEGACY_INT_TRIGGERED(status)) |
| 1909 | return IRQ_NONE; |
| 1910 | |
| 1911 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1912 | /* read twice to ensure write is flushed */ |
| 1913 | readl(adapter->isr_int_vec); |
| 1914 | readl(adapter->isr_int_vec); |
| 1915 | |
Amit Kumar Salecha | 7eb9855 | 2010-02-01 05:24:59 +0000 | [diff] [blame] | 1916 | return IRQ_HANDLED; |
| 1917 | } |
| 1918 | |
| 1919 | static irqreturn_t qlcnic_tmp_intr(int irq, void *data) |
| 1920 | { |
| 1921 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1922 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1923 | |
| 1924 | if (adapter->flags & QLCNIC_MSIX_ENABLED) |
| 1925 | goto done; |
| 1926 | else if (adapter->flags & QLCNIC_MSI_ENABLED) { |
| 1927 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1928 | goto done; |
| 1929 | } |
| 1930 | |
| 1931 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1932 | return IRQ_NONE; |
| 1933 | |
| 1934 | done: |
| 1935 | adapter->diag_cnt++; |
| 1936 | qlcnic_enable_int(sds_ring); |
| 1937 | return IRQ_HANDLED; |
| 1938 | } |
| 1939 | |
| 1940 | static irqreturn_t qlcnic_intr(int irq, void *data) |
| 1941 | { |
| 1942 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1943 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1944 | |
| 1945 | if (qlcnic_clear_legacy_intr(adapter) == IRQ_NONE) |
| 1946 | return IRQ_NONE; |
| 1947 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1948 | napi_schedule(&sds_ring->napi); |
| 1949 | |
| 1950 | return IRQ_HANDLED; |
| 1951 | } |
| 1952 | |
| 1953 | static irqreturn_t qlcnic_msi_intr(int irq, void *data) |
| 1954 | { |
| 1955 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1956 | struct qlcnic_adapter *adapter = sds_ring->adapter; |
| 1957 | |
| 1958 | /* clear interrupt */ |
| 1959 | writel(0xffffffff, adapter->tgt_status_reg); |
| 1960 | |
| 1961 | napi_schedule(&sds_ring->napi); |
| 1962 | return IRQ_HANDLED; |
| 1963 | } |
| 1964 | |
| 1965 | static irqreturn_t qlcnic_msix_intr(int irq, void *data) |
| 1966 | { |
| 1967 | struct qlcnic_host_sds_ring *sds_ring = data; |
| 1968 | |
| 1969 | napi_schedule(&sds_ring->napi); |
| 1970 | return IRQ_HANDLED; |
| 1971 | } |
| 1972 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1973 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1974 | static void qlcnic_poll_controller(struct net_device *netdev) |
| 1975 | { |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1976 | int ring; |
| 1977 | struct qlcnic_host_sds_ring *sds_ring; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1978 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
Anirban Chakraborty | b1fc6d3 | 2011-04-01 14:28:05 +0000 | [diff] [blame] | 1979 | struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx; |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1980 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1981 | disable_irq(adapter->irq); |
Yinglin Luan | bf82791 | 2010-08-22 21:57:56 +0000 | [diff] [blame] | 1982 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 1983 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 1984 | qlcnic_intr(adapter->irq, sds_ring); |
| 1985 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 1986 | enable_irq(adapter->irq); |
| 1987 | } |
| 1988 | #endif |
| 1989 | |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 1990 | static void |
| 1991 | qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding) |
| 1992 | { |
| 1993 | u32 val; |
| 1994 | |
| 1995 | val = adapter->portnum & 0xf; |
| 1996 | val |= encoding << 7; |
| 1997 | val |= (jiffies - adapter->dev_rst_time) << 8; |
| 1998 | |
| 1999 | QLCWR32(adapter, QLCNIC_CRB_DRV_SCRATCH, val); |
| 2000 | adapter->dev_rst_time = jiffies; |
| 2001 | } |
| 2002 | |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2003 | static int |
| 2004 | qlcnic_set_drv_state(struct qlcnic_adapter *adapter, u8 state) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2005 | { |
| 2006 | u32 val; |
| 2007 | |
| 2008 | WARN_ON(state != QLCNIC_DEV_NEED_RESET && |
| 2009 | state != QLCNIC_DEV_NEED_QUISCENT); |
| 2010 | |
| 2011 | if (qlcnic_api_lock(adapter)) |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2012 | return -EIO; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2013 | |
| 2014 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2015 | |
| 2016 | if (state == QLCNIC_DEV_NEED_RESET) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2017 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2018 | else if (state == QLCNIC_DEV_NEED_QUISCENT) |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2019 | QLC_DEV_SET_QSCNT_RDY(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2020 | |
| 2021 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2022 | |
| 2023 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | ade91f8 | 2010-04-22 02:51:39 +0000 | [diff] [blame] | 2024 | |
| 2025 | return 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2028 | static int |
| 2029 | qlcnic_clr_drv_state(struct qlcnic_adapter *adapter) |
| 2030 | { |
| 2031 | u32 val; |
| 2032 | |
| 2033 | if (qlcnic_api_lock(adapter)) |
| 2034 | return -EBUSY; |
| 2035 | |
| 2036 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2037 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2038 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2039 | |
| 2040 | qlcnic_api_unlock(adapter); |
| 2041 | |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2045 | static void |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2046 | qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2047 | { |
| 2048 | u32 val; |
| 2049 | |
| 2050 | if (qlcnic_api_lock(adapter)) |
| 2051 | goto err; |
| 2052 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2053 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2054 | QLC_DEV_CLR_REF_CNT(val, adapter->portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2055 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2056 | |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2057 | if (failed) { |
| 2058 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); |
| 2059 | dev_info(&adapter->pdev->dev, |
| 2060 | "Device state set to Failed. Please Reboot\n"); |
| 2061 | } else if (!(val & 0x11111111)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2062 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); |
| 2063 | |
| 2064 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2065 | QLC_DEV_CLR_RST_QSCNT(val, adapter->portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2066 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2067 | |
| 2068 | qlcnic_api_unlock(adapter); |
| 2069 | err: |
| 2070 | adapter->fw_fail_cnt = 0; |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2071 | adapter->flags &= ~QLCNIC_FW_HANG; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2072 | clear_bit(__QLCNIC_START_FW, &adapter->state); |
| 2073 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2074 | } |
| 2075 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2076 | /* Grab api lock, before checking state */ |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2077 | static int |
| 2078 | qlcnic_check_drv_state(struct qlcnic_adapter *adapter) |
| 2079 | { |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2080 | int act, state, active_mask; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2081 | |
| 2082 | state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2083 | act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2084 | |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2085 | if (adapter->flags & QLCNIC_FW_RESET_OWNER) { |
| 2086 | active_mask = (~(1 << (adapter->ahw->pci_func * 4))); |
| 2087 | act = act & active_mask; |
| 2088 | } |
| 2089 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2090 | if (((state & 0x11111111) == (act & 0x11111111)) || |
| 2091 | ((act & 0x11111111) == ((state >> 1) & 0x11111111))) |
| 2092 | return 0; |
| 2093 | else |
| 2094 | return 1; |
| 2095 | } |
| 2096 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2097 | static int qlcnic_check_idc_ver(struct qlcnic_adapter *adapter) |
| 2098 | { |
| 2099 | u32 val = QLCRD32(adapter, QLCNIC_CRB_DRV_IDC_VER); |
| 2100 | |
| 2101 | if (val != QLCNIC_DRV_IDC_VER) { |
| 2102 | dev_warn(&adapter->pdev->dev, "IDC Version mismatch, driver's" |
| 2103 | " idc ver = %x; reqd = %x\n", QLCNIC_DRV_IDC_VER, val); |
| 2104 | } |
| 2105 | |
| 2106 | return 0; |
| 2107 | } |
| 2108 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2109 | static int |
| 2110 | qlcnic_can_start_firmware(struct qlcnic_adapter *adapter) |
| 2111 | { |
| 2112 | u32 val, prev_state; |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2113 | u8 dev_init_timeo = adapter->dev_init_timeo; |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2114 | u8 portnum = adapter->portnum; |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2115 | u8 ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2116 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2117 | if (test_and_clear_bit(__QLCNIC_START_FW, &adapter->state)) |
| 2118 | return 1; |
| 2119 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2120 | if (qlcnic_api_lock(adapter)) |
| 2121 | return -1; |
| 2122 | |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2123 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2124 | if (!(val & (1 << (portnum * 4)))) { |
| 2125 | QLC_DEV_SET_REF_CNT(val, portnum); |
Amit Kumar Salecha | 31018e0 | 2010-08-25 04:03:05 +0000 | [diff] [blame] | 2126 | QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2130 | QLCDB(adapter, HW, "Device state = %u\n", prev_state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2131 | |
| 2132 | switch (prev_state) { |
| 2133 | case QLCNIC_DEV_COLD: |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2134 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2135 | QLCWR32(adapter, QLCNIC_CRB_DRV_IDC_VER, QLCNIC_DRV_IDC_VER); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2136 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2137 | qlcnic_api_unlock(adapter); |
| 2138 | return 1; |
| 2139 | |
| 2140 | case QLCNIC_DEV_READY: |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2141 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2142 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2143 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2144 | |
| 2145 | case QLCNIC_DEV_NEED_RESET: |
| 2146 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2147 | QLC_DEV_SET_RST_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2148 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2149 | break; |
| 2150 | |
| 2151 | case QLCNIC_DEV_NEED_QUISCENT: |
| 2152 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2153 | QLC_DEV_SET_QSCNT_RDY(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2154 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2155 | break; |
| 2156 | |
| 2157 | case QLCNIC_DEV_FAILED: |
Amit Kumar Salecha | a7fc948 | 2010-05-17 01:22:14 +0000 | [diff] [blame] | 2158 | dev_err(&adapter->pdev->dev, "Device in failed state.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2159 | qlcnic_api_unlock(adapter); |
| 2160 | return -1; |
Amit Kumar Salecha | bbd8c6a | 2010-04-22 02:51:36 +0000 | [diff] [blame] | 2161 | |
| 2162 | case QLCNIC_DEV_INITIALIZING: |
| 2163 | case QLCNIC_DEV_QUISCENT: |
| 2164 | break; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | qlcnic_api_unlock(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2168 | |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2169 | do { |
| 2170 | msleep(1000); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2171 | prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
| 2172 | |
| 2173 | if (prev_state == QLCNIC_DEV_QUISCENT) |
| 2174 | continue; |
| 2175 | } while ((prev_state != QLCNIC_DEV_READY) && --dev_init_timeo); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2176 | |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2177 | if (!dev_init_timeo) { |
| 2178 | dev_err(&adapter->pdev->dev, |
| 2179 | "Waiting for device to initialize timeout\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2180 | return -1; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2181 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (qlcnic_api_lock(adapter)) |
| 2184 | return -1; |
| 2185 | |
| 2186 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
Amit Kumar Salecha | 6d2a472 | 2010-04-22 02:51:38 +0000 | [diff] [blame] | 2187 | QLC_DEV_CLR_RST_QSCNT(val, portnum); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2188 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
| 2189 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2190 | ret = qlcnic_check_idc_ver(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2191 | qlcnic_api_unlock(adapter); |
| 2192 | |
Sucheta Chakraborty | 96f8118 | 2010-05-13 03:07:47 +0000 | [diff] [blame] | 2193 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | static void |
| 2197 | qlcnic_fwinit_work(struct work_struct *work) |
| 2198 | { |
| 2199 | struct qlcnic_adapter *adapter = container_of(work, |
| 2200 | struct qlcnic_adapter, fw_work.work); |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2201 | u32 dev_state = 0xf; |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2202 | u32 val; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2203 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2204 | if (qlcnic_api_lock(adapter)) |
| 2205 | goto err_ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2206 | |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2207 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2208 | if (dev_state == QLCNIC_DEV_QUISCENT || |
| 2209 | dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2210 | qlcnic_api_unlock(adapter); |
| 2211 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, |
| 2212 | FW_POLL_DELAY * 2); |
| 2213 | return; |
| 2214 | } |
| 2215 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2216 | if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2217 | qlcnic_api_unlock(adapter); |
| 2218 | goto wait_npar; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Sritej Velaga | 16e3cf7 | 2011-10-28 12:57:11 +0000 | [diff] [blame] | 2221 | if (dev_state == QLCNIC_DEV_INITIALIZING || |
| 2222 | dev_state == QLCNIC_DEV_READY) { |
| 2223 | dev_info(&adapter->pdev->dev, "Detected state change from " |
| 2224 | "DEV_NEED_RESET, skipping ack check\n"); |
| 2225 | goto skip_ack_check; |
| 2226 | } |
| 2227 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2228 | if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { |
Sritej Velaga | 16e3cf7 | 2011-10-28 12:57:11 +0000 | [diff] [blame] | 2229 | 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] | 2230 | adapter->reset_ack_timeo); |
| 2231 | goto skip_ack_check; |
| 2232 | } |
| 2233 | |
| 2234 | if (!qlcnic_check_drv_state(adapter)) { |
| 2235 | skip_ack_check: |
| 2236 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | a5e463d | 2010-05-13 03:07:49 +0000 | [diff] [blame] | 2237 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2238 | if (dev_state == QLCNIC_DEV_NEED_RESET) { |
| 2239 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, |
| 2240 | QLCNIC_DEV_INITIALIZING); |
| 2241 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2242 | QLCDB(adapter, DRV, "Restarting fw\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2243 | qlcnic_idc_debug_info(adapter, 0); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2244 | val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); |
| 2245 | QLC_DEV_SET_RST_RDY(val, adapter->portnum); |
| 2246 | QLCWR32(adapter, QLCNIC_CRB_DRV_STATE, val); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2249 | qlcnic_api_unlock(adapter); |
| 2250 | |
Anirban Chakraborty | 287e38a | 2011-06-22 02:52:18 +0000 | [diff] [blame] | 2251 | rtnl_lock(); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2252 | if (adapter->ahw->fw_dump.enable && |
| 2253 | (adapter->flags & QLCNIC_FW_RESET_OWNER)) { |
Anirban Chakraborty | 9d6a644 | 2011-06-22 02:52:22 +0000 | [diff] [blame] | 2254 | QLCDB(adapter, DRV, "Take FW dump\n"); |
| 2255 | qlcnic_dump_fw(adapter); |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2256 | adapter->flags |= QLCNIC_FW_HANG; |
Anirban Chakraborty | 9d6a644 | 2011-06-22 02:52:22 +0000 | [diff] [blame] | 2257 | } |
Anirban Chakraborty | 287e38a | 2011-06-22 02:52:18 +0000 | [diff] [blame] | 2258 | rtnl_unlock(); |
Sritej Velaga | 7b749ff | 2011-07-14 03:16:50 +0000 | [diff] [blame] | 2259 | |
| 2260 | adapter->flags &= ~QLCNIC_FW_RESET_OWNER; |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2261 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2262 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2263 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2264 | return; |
| 2265 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2266 | goto err_ret; |
| 2267 | } |
| 2268 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2269 | qlcnic_api_unlock(adapter); |
Sucheta Chakraborty | aa5e18c | 2010-04-01 19:01:32 +0000 | [diff] [blame] | 2270 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2271 | wait_npar: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2272 | dev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2273 | QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2274 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2275 | switch (dev_state) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2276 | case QLCNIC_DEV_READY: |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2277 | if (!adapter->nic_ops->start_firmware(adapter)) { |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2278 | qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2279 | adapter->fw_wait_cnt = 0; |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2280 | return; |
| 2281 | } |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2282 | case QLCNIC_DEV_FAILED: |
| 2283 | break; |
| 2284 | default: |
| 2285 | qlcnic_schedule_work(adapter, |
| 2286 | qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2287 | return; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | err_ret: |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2291 | dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " |
| 2292 | "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2293 | netif_device_attach(adapter->netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2294 | qlcnic_clr_all_drv_state(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | static void |
| 2298 | qlcnic_detach_work(struct work_struct *work) |
| 2299 | { |
| 2300 | struct qlcnic_adapter *adapter = container_of(work, |
| 2301 | struct qlcnic_adapter, fw_work.work); |
| 2302 | struct net_device *netdev = adapter->netdev; |
| 2303 | u32 status; |
| 2304 | |
| 2305 | netif_device_detach(netdev); |
| 2306 | |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2307 | /* Dont grab rtnl lock during Quiscent mode */ |
| 2308 | if (adapter->dev_state == QLCNIC_DEV_NEED_QUISCENT) { |
| 2309 | if (netif_running(netdev)) |
| 2310 | __qlcnic_down(adapter, netdev); |
| 2311 | } else |
| 2312 | qlcnic_down(adapter, netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2313 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2314 | status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
| 2315 | |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2316 | if (status & QLCNIC_RCODE_FATAL_ERROR) { |
| 2317 | dev_err(&adapter->pdev->dev, |
| 2318 | "Detaching the device: peg halt status1=0x%x\n", |
| 2319 | status); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2320 | |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2321 | if (QLCNIC_FWERROR_CODE(status) == QLCNIC_FWERROR_FAN_FAILURE) { |
| 2322 | dev_err(&adapter->pdev->dev, |
| 2323 | "On board active cooling fan failed. " |
| 2324 | "Device has been halted.\n"); |
| 2325 | dev_err(&adapter->pdev->dev, |
| 2326 | "Replace the adapter.\n"); |
| 2327 | } |
| 2328 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2329 | goto err_ret; |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | if (adapter->temp == QLCNIC_TEMP_PANIC) { |
| 2333 | dev_err(&adapter->pdev->dev, "Detaching the device: temp=%d\n", |
| 2334 | adapter->temp); |
| 2335 | goto err_ret; |
| 2336 | } |
| 2337 | |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2338 | /* Dont ack if this instance is the reset owner */ |
| 2339 | if (!(adapter->flags & QLCNIC_FW_RESET_OWNER)) { |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2340 | if (qlcnic_set_drv_state(adapter, adapter->dev_state)) { |
| 2341 | dev_err(&adapter->pdev->dev, |
| 2342 | "Failed to set driver state," |
| 2343 | "detaching the device.\n"); |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2344 | goto err_ret; |
Sony Chacko | 44f65b2 | 2011-08-29 12:50:26 +0000 | [diff] [blame] | 2345 | } |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2346 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2347 | |
| 2348 | adapter->fw_wait_cnt = 0; |
| 2349 | |
| 2350 | qlcnic_schedule_work(adapter, qlcnic_fwinit_work, FW_POLL_DELAY); |
| 2351 | |
| 2352 | return; |
| 2353 | |
| 2354 | err_ret: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2355 | netif_device_attach(netdev); |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2356 | qlcnic_clr_all_drv_state(adapter, 1); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2359 | /*Transit NPAR state to NON Operational */ |
| 2360 | static void |
| 2361 | qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter) |
| 2362 | { |
| 2363 | u32 state; |
| 2364 | |
| 2365 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2366 | if (state == QLCNIC_DEV_NPAR_NON_OPER) |
| 2367 | return; |
| 2368 | |
| 2369 | if (qlcnic_api_lock(adapter)) |
| 2370 | return; |
| 2371 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER); |
| 2372 | qlcnic_api_unlock(adapter); |
| 2373 | } |
| 2374 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2375 | /*Transit to RESET state from READY state only */ |
Anirban Chakraborty | 18f2f61 | 2011-05-12 12:48:33 +0000 | [diff] [blame] | 2376 | void |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2377 | qlcnic_dev_request_reset(struct qlcnic_adapter *adapter) |
| 2378 | { |
Sritej Velaga | 646779f | 2012-02-03 13:45:41 +0000 | [diff] [blame] | 2379 | u32 state, xg_val = 0, gb_val = 0; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2380 | |
Sritej Velaga | 646779f | 2012-02-03 13:45:41 +0000 | [diff] [blame] | 2381 | qlcnic_xg_set_xg0_mask(xg_val); |
| 2382 | qlcnic_xg_set_xg1_mask(xg_val); |
| 2383 | QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, xg_val); |
| 2384 | qlcnic_gb_set_gb0_mask(gb_val); |
| 2385 | qlcnic_gb_set_gb1_mask(gb_val); |
| 2386 | qlcnic_gb_set_gb2_mask(gb_val); |
| 2387 | qlcnic_gb_set_gb3_mask(gb_val); |
| 2388 | QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, gb_val); |
| 2389 | dev_info(&adapter->pdev->dev, "Pause control frames disabled" |
| 2390 | " on all ports\n"); |
Anirban Chakraborty | cea8975 | 2010-07-13 20:33:35 +0000 | [diff] [blame] | 2391 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2392 | if (qlcnic_api_lock(adapter)) |
| 2393 | return; |
| 2394 | |
| 2395 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 2396 | if (state == QLCNIC_DEV_FAILED || (state == QLCNIC_DEV_BADBAD)) { |
| 2397 | netdev_err(adapter->netdev, |
| 2398 | "Device is in FAILED state, Please Reboot\n"); |
| 2399 | qlcnic_api_unlock(adapter); |
| 2400 | return; |
| 2401 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2402 | |
Amit Kumar Salecha | f73dfc5 | 2010-04-22 02:51:37 +0000 | [diff] [blame] | 2403 | if (state == QLCNIC_DEV_READY) { |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2404 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_NEED_RESET); |
Sritej Velaga | 602ca6f | 2011-06-22 02:52:17 +0000 | [diff] [blame] | 2405 | adapter->flags |= QLCNIC_FW_RESET_OWNER; |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2406 | QLCDB(adapter, DRV, "NEED_RESET state set\n"); |
Sucheta Chakraborty | 6df900e | 2010-05-13 03:07:50 +0000 | [diff] [blame] | 2407 | qlcnic_idc_debug_info(adapter, 0); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2410 | 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] | 2411 | qlcnic_api_unlock(adapter); |
| 2412 | } |
| 2413 | |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2414 | /* Transit to NPAR READY state from NPAR NOT READY state */ |
| 2415 | static void |
| 2416 | qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) |
| 2417 | { |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2418 | if (qlcnic_api_lock(adapter)) |
| 2419 | return; |
| 2420 | |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2421 | QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER); |
| 2422 | QLCDB(adapter, DRV, "NPAR operational state set\n"); |
Anirban Chakraborty | 9f26f54 | 2010-06-01 11:33:09 +0000 | [diff] [blame] | 2423 | |
| 2424 | qlcnic_api_unlock(adapter); |
| 2425 | } |
| 2426 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2427 | static void |
| 2428 | qlcnic_schedule_work(struct qlcnic_adapter *adapter, |
| 2429 | work_func_t func, int delay) |
| 2430 | { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2431 | if (test_bit(__QLCNIC_AER, &adapter->state)) |
| 2432 | return; |
| 2433 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2434 | INIT_DELAYED_WORK(&adapter->fw_work, func); |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2435 | queue_delayed_work(qlcnic_wq, &adapter->fw_work, |
| 2436 | round_jiffies_relative(delay)); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | static void |
| 2440 | qlcnic_cancel_fw_work(struct qlcnic_adapter *adapter) |
| 2441 | { |
| 2442 | while (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2443 | msleep(10); |
| 2444 | |
Sucheta Chakraborty | b43e5ee | 2012-04-26 10:31:29 +0000 | [diff] [blame] | 2445 | if (!adapter->fw_work.work.func) |
| 2446 | return; |
| 2447 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2448 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2449 | } |
| 2450 | |
| 2451 | static void |
| 2452 | qlcnic_attach_work(struct work_struct *work) |
| 2453 | { |
| 2454 | struct qlcnic_adapter *adapter = container_of(work, |
| 2455 | struct qlcnic_adapter, fw_work.work); |
| 2456 | struct net_device *netdev = adapter->netdev; |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2457 | u32 npar_state; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2458 | |
Amit Kumar Salecha | b18971d | 2010-08-25 04:03:04 +0000 | [diff] [blame] | 2459 | if (adapter->op_mode != QLCNIC_MGMT_FUNC) { |
| 2460 | npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); |
| 2461 | if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO) |
| 2462 | qlcnic_clr_all_drv_state(adapter, 0); |
| 2463 | else if (npar_state != QLCNIC_DEV_NPAR_OPER) |
| 2464 | qlcnic_schedule_work(adapter, qlcnic_attach_work, |
| 2465 | FW_POLL_DELAY); |
| 2466 | else |
| 2467 | goto attach; |
| 2468 | QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n"); |
| 2469 | return; |
| 2470 | } |
| 2471 | attach: |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2472 | if (netif_running(netdev)) { |
Amit Kumar Salecha | 52486a3 | 2010-06-22 03:19:02 +0000 | [diff] [blame] | 2473 | if (qlcnic_up(adapter, netdev)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2474 | goto done; |
| 2475 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2476 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2479 | done: |
Amit Kumar Salecha | 34ce362 | 2010-04-01 19:01:34 +0000 | [diff] [blame] | 2480 | netif_device_attach(netdev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2481 | adapter->fw_fail_cnt = 0; |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2482 | adapter->flags &= ~QLCNIC_FW_HANG; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2483 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
Amit Kumar Salecha | 1b95a83 | 2010-02-01 05:24:56 +0000 | [diff] [blame] | 2484 | |
| 2485 | if (!qlcnic_clr_drv_state(adapter)) |
| 2486 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2487 | FW_POLL_DELAY); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | static int |
| 2491 | qlcnic_check_health(struct qlcnic_adapter *adapter) |
| 2492 | { |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 2493 | u32 state = 0, heartbeat; |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2494 | u32 peg_status; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2495 | |
| 2496 | if (qlcnic_check_temp(adapter)) |
| 2497 | goto detach; |
| 2498 | |
Amit Kumar Salecha | 2372a5f | 2010-05-13 03:07:42 +0000 | [diff] [blame] | 2499 | if (adapter->need_fw_reset) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2500 | qlcnic_dev_request_reset(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2501 | |
| 2502 | state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2503 | if (state == QLCNIC_DEV_NEED_RESET) { |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2504 | qlcnic_set_npar_non_operational(adapter); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2505 | adapter->need_fw_reset = 1; |
Amit Kumar Salecha | b8c1762 | 2010-10-07 23:46:06 +0000 | [diff] [blame] | 2506 | } else if (state == QLCNIC_DEV_NEED_QUISCENT) |
| 2507 | goto detach; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2508 | |
Sony Chacko | 4e70812 | 2010-08-31 17:17:44 +0000 | [diff] [blame] | 2509 | heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); |
| 2510 | if (heartbeat != adapter->heartbeat) { |
| 2511 | adapter->heartbeat = heartbeat; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2512 | adapter->fw_fail_cnt = 0; |
| 2513 | if (adapter->need_fw_reset) |
| 2514 | goto detach; |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 2515 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2516 | if (adapter->reset_context && auto_fw_reset) { |
Amit Kumar Salecha | 68bf1c6 | 2010-06-22 03:19:03 +0000 | [diff] [blame] | 2517 | qlcnic_reset_hw_context(adapter); |
| 2518 | adapter->netdev->trans_start = jiffies; |
| 2519 | } |
| 2520 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2521 | return 0; |
| 2522 | } |
| 2523 | |
| 2524 | if (++adapter->fw_fail_cnt < FW_FAIL_THRESH) |
| 2525 | return 0; |
| 2526 | |
Sritej Velaga | 032a13c | 2011-07-29 13:30:27 +0000 | [diff] [blame] | 2527 | adapter->flags |= QLCNIC_FW_HANG; |
| 2528 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2529 | qlcnic_dev_request_reset(adapter); |
| 2530 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2531 | if (auto_fw_reset) |
Amit Kumar Salecha | 0df170b | 2010-07-13 20:33:32 +0000 | [diff] [blame] | 2532 | clear_bit(__QLCNIC_FW_ATTACHED, &adapter->state); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2533 | |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2534 | dev_err(&adapter->pdev->dev, "firmware hang detected\n"); |
| 2535 | dev_err(&adapter->pdev->dev, "Dumping hw/fw registers\n" |
Sritej Velaga | c76ecb7 | 2011-07-29 13:30:29 +0000 | [diff] [blame] | 2536 | "PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n" |
| 2537 | "PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n" |
| 2538 | "PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n" |
| 2539 | "PEG_NET_4_PC: 0x%x\n", |
| 2540 | QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1), |
| 2541 | QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS2), |
| 2542 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x3c), |
| 2543 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x3c), |
| 2544 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_2 + 0x3c), |
| 2545 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x3c), |
| 2546 | QLCRD32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x3c)); |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2547 | peg_status = QLCRD32(adapter, QLCNIC_PEG_HALT_STATUS1); |
Sritej Velaga | 97048a1 | 2012-02-03 13:45:43 +0000 | [diff] [blame] | 2548 | if (QLCNIC_FWERROR_CODE(peg_status) == 0x67) |
Ameen Rahman | 853d4bc | 2011-09-13 08:06:17 +0000 | [diff] [blame] | 2549 | dev_err(&adapter->pdev->dev, |
| 2550 | "Firmware aborted with error code 0x00006700. " |
| 2551 | "Device is being reset.\n"); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2552 | detach: |
| 2553 | adapter->dev_state = (state == QLCNIC_DEV_NEED_QUISCENT) ? state : |
| 2554 | QLCNIC_DEV_NEED_RESET; |
| 2555 | |
amit salecha | 9ce13ca | 2011-02-23 03:21:24 +0000 | [diff] [blame] | 2556 | if (auto_fw_reset && |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2557 | !test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) { |
| 2558 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2559 | qlcnic_schedule_work(adapter, qlcnic_detach_work, 0); |
Amit Kumar Salecha | 65b5b42 | 2010-04-01 19:01:33 +0000 | [diff] [blame] | 2560 | QLCDB(adapter, DRV, "fw recovery scheduled.\n"); |
| 2561 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2562 | |
| 2563 | return 1; |
| 2564 | } |
| 2565 | |
| 2566 | static void |
| 2567 | qlcnic_fw_poll_work(struct work_struct *work) |
| 2568 | { |
| 2569 | struct qlcnic_adapter *adapter = container_of(work, |
| 2570 | struct qlcnic_adapter, fw_work.work); |
| 2571 | |
| 2572 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2573 | goto reschedule; |
| 2574 | |
| 2575 | |
| 2576 | if (qlcnic_check_health(adapter)) |
| 2577 | return; |
| 2578 | |
Amit Kumar Salecha | b5e5492 | 2010-08-31 17:17:51 +0000 | [diff] [blame] | 2579 | if (adapter->fhash.fnum) |
| 2580 | qlcnic_prune_lb_filters(adapter); |
| 2581 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2582 | reschedule: |
| 2583 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); |
| 2584 | } |
| 2585 | |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2586 | static int qlcnic_is_first_func(struct pci_dev *pdev) |
| 2587 | { |
| 2588 | struct pci_dev *oth_pdev; |
| 2589 | int val = pdev->devfn; |
| 2590 | |
| 2591 | while (val-- > 0) { |
| 2592 | oth_pdev = pci_get_domain_bus_and_slot(pci_domain_nr |
| 2593 | (pdev->bus), pdev->bus->number, |
| 2594 | PCI_DEVFN(PCI_SLOT(pdev->devfn), val)); |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2595 | if (!oth_pdev) |
| 2596 | continue; |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2597 | |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2598 | if (oth_pdev->current_state != PCI_D3cold) { |
| 2599 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2600 | return 0; |
Amit Kumar Salecha | bfc978f | 2010-07-18 14:51:59 -0700 | [diff] [blame] | 2601 | } |
| 2602 | pci_dev_put(oth_pdev); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2603 | } |
| 2604 | return 1; |
| 2605 | } |
| 2606 | |
| 2607 | static int qlcnic_attach_func(struct pci_dev *pdev) |
| 2608 | { |
| 2609 | int err, first_func; |
| 2610 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2611 | struct net_device *netdev = adapter->netdev; |
| 2612 | |
| 2613 | pdev->error_state = pci_channel_io_normal; |
| 2614 | |
| 2615 | err = pci_enable_device(pdev); |
| 2616 | if (err) |
| 2617 | return err; |
| 2618 | |
| 2619 | pci_set_power_state(pdev, PCI_D0); |
| 2620 | pci_set_master(pdev); |
| 2621 | pci_restore_state(pdev); |
| 2622 | |
| 2623 | first_func = qlcnic_is_first_func(pdev); |
| 2624 | |
| 2625 | if (qlcnic_api_lock(adapter)) |
| 2626 | return -EINVAL; |
| 2627 | |
Amit Kumar Salecha | 933fce12 | 2010-08-17 00:34:19 +0000 | [diff] [blame] | 2628 | if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2629 | adapter->need_fw_reset = 1; |
| 2630 | set_bit(__QLCNIC_START_FW, &adapter->state); |
| 2631 | QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); |
| 2632 | QLCDB(adapter, DRV, "Restarting fw\n"); |
| 2633 | } |
| 2634 | qlcnic_api_unlock(adapter); |
| 2635 | |
| 2636 | err = adapter->nic_ops->start_firmware(adapter); |
| 2637 | if (err) |
| 2638 | return err; |
| 2639 | |
| 2640 | qlcnic_clr_drv_state(adapter); |
| 2641 | qlcnic_setup_intr(adapter); |
| 2642 | |
| 2643 | if (netif_running(netdev)) { |
| 2644 | err = qlcnic_attach(adapter); |
| 2645 | if (err) { |
Amit Kumar Salecha | 21854f0 | 2010-08-19 05:08:29 +0000 | [diff] [blame] | 2646 | qlcnic_clr_all_drv_state(adapter, 1); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2647 | clear_bit(__QLCNIC_AER, &adapter->state); |
| 2648 | netif_device_attach(netdev); |
| 2649 | return err; |
| 2650 | } |
| 2651 | |
| 2652 | err = qlcnic_up(adapter, netdev); |
| 2653 | if (err) |
| 2654 | goto done; |
| 2655 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2656 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2657 | } |
| 2658 | done: |
| 2659 | netif_device_attach(netdev); |
| 2660 | return err; |
| 2661 | } |
| 2662 | |
| 2663 | static pci_ers_result_t qlcnic_io_error_detected(struct pci_dev *pdev, |
| 2664 | pci_channel_state_t state) |
| 2665 | { |
| 2666 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2667 | struct net_device *netdev = adapter->netdev; |
| 2668 | |
| 2669 | if (state == pci_channel_io_perm_failure) |
| 2670 | return PCI_ERS_RESULT_DISCONNECT; |
| 2671 | |
| 2672 | if (state == pci_channel_io_normal) |
| 2673 | return PCI_ERS_RESULT_RECOVERED; |
| 2674 | |
| 2675 | set_bit(__QLCNIC_AER, &adapter->state); |
| 2676 | netif_device_detach(netdev); |
| 2677 | |
| 2678 | cancel_delayed_work_sync(&adapter->fw_work); |
| 2679 | |
| 2680 | if (netif_running(netdev)) |
| 2681 | qlcnic_down(adapter, netdev); |
| 2682 | |
| 2683 | qlcnic_detach(adapter); |
| 2684 | qlcnic_teardown_intr(adapter); |
| 2685 | |
| 2686 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2687 | |
| 2688 | pci_save_state(pdev); |
| 2689 | pci_disable_device(pdev); |
| 2690 | |
| 2691 | return PCI_ERS_RESULT_NEED_RESET; |
| 2692 | } |
| 2693 | |
| 2694 | static pci_ers_result_t qlcnic_io_slot_reset(struct pci_dev *pdev) |
| 2695 | { |
| 2696 | return qlcnic_attach_func(pdev) ? PCI_ERS_RESULT_DISCONNECT : |
| 2697 | PCI_ERS_RESULT_RECOVERED; |
| 2698 | } |
| 2699 | |
| 2700 | static void qlcnic_io_resume(struct pci_dev *pdev) |
| 2701 | { |
| 2702 | struct qlcnic_adapter *adapter = pci_get_drvdata(pdev); |
| 2703 | |
| 2704 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 2705 | |
| 2706 | if (QLCRD32(adapter, QLCNIC_CRB_DEV_STATE) == QLCNIC_DEV_READY && |
| 2707 | test_and_clear_bit(__QLCNIC_AER, &adapter->state)) |
| 2708 | qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, |
| 2709 | FW_POLL_DELAY); |
| 2710 | } |
| 2711 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2712 | static int |
| 2713 | qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) |
| 2714 | { |
| 2715 | int err; |
| 2716 | |
| 2717 | err = qlcnic_can_start_firmware(adapter); |
| 2718 | if (err) |
| 2719 | return err; |
| 2720 | |
Amit Kumar Salecha | 78f84e1 | 2010-08-19 05:08:28 +0000 | [diff] [blame] | 2721 | err = qlcnic_check_npar_opertional(adapter); |
| 2722 | if (err) |
| 2723 | return err; |
Amit Kumar Salecha | 3c4b23b | 2010-08-17 00:34:20 +0000 | [diff] [blame] | 2724 | |
Rajesh Borundia | 174240a | 2010-08-31 17:17:47 +0000 | [diff] [blame] | 2725 | err = qlcnic_initialize_nic(adapter); |
| 2726 | if (err) |
| 2727 | return err; |
| 2728 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2729 | qlcnic_check_options(adapter); |
| 2730 | |
Rajesh Borundia | 7373373 | 2010-08-31 17:17:50 +0000 | [diff] [blame] | 2731 | err = qlcnic_set_eswitch_port_config(adapter); |
| 2732 | if (err) |
| 2733 | return err; |
| 2734 | |
Anirban Chakraborty | 87eb743 | 2010-06-03 07:50:56 +0000 | [diff] [blame] | 2735 | adapter->need_fw_reset = 0; |
| 2736 | |
| 2737 | return err; |
| 2738 | } |
| 2739 | |
Sucheta Chakraborty | f94bc1e | 2011-04-28 11:48:18 +0000 | [diff] [blame] | 2740 | int qlcnic_validate_max_rss(struct net_device *netdev, u8 max_hw, u8 val) |
| 2741 | { |
| 2742 | if (!use_msi_x && !use_msi) { |
| 2743 | netdev_info(netdev, "no msix or msi support, hence no rss\n"); |
| 2744 | return -EINVAL; |
| 2745 | } |
| 2746 | |
| 2747 | if ((val > max_hw) || (val < 2) || !is_power_of_2(val)) { |
| 2748 | netdev_info(netdev, "rss_ring valid range [2 - %x] in " |
| 2749 | " powers of 2\n", max_hw); |
| 2750 | return -EINVAL; |
| 2751 | } |
| 2752 | return 0; |
| 2753 | |
| 2754 | } |
| 2755 | |
| 2756 | int qlcnic_set_max_rss(struct qlcnic_adapter *adapter, u8 data) |
| 2757 | { |
| 2758 | struct net_device *netdev = adapter->netdev; |
| 2759 | int err = 0; |
| 2760 | |
| 2761 | if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 2762 | return -EBUSY; |
| 2763 | |
| 2764 | netif_device_detach(netdev); |
| 2765 | if (netif_running(netdev)) |
| 2766 | __qlcnic_down(adapter, netdev); |
| 2767 | qlcnic_detach(adapter); |
| 2768 | qlcnic_teardown_intr(adapter); |
| 2769 | |
| 2770 | if (qlcnic_enable_msix(adapter, data)) { |
| 2771 | netdev_info(netdev, "failed setting max_rss; rss disabled\n"); |
| 2772 | qlcnic_enable_msi_legacy(adapter); |
| 2773 | } |
| 2774 | |
| 2775 | if (netif_running(netdev)) { |
| 2776 | err = qlcnic_attach(adapter); |
| 2777 | if (err) |
| 2778 | goto done; |
| 2779 | err = __qlcnic_up(adapter, netdev); |
| 2780 | if (err) |
| 2781 | goto done; |
| 2782 | qlcnic_restore_indev_addr(netdev, NETDEV_UP); |
| 2783 | } |
| 2784 | done: |
| 2785 | netif_device_attach(netdev); |
| 2786 | clear_bit(__QLCNIC_RESETTING, &adapter->state); |
| 2787 | return err; |
| 2788 | } |
| 2789 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2790 | #ifdef CONFIG_INET |
| 2791 | |
| 2792 | #define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) |
| 2793 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2794 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2795 | qlcnic_config_indev_addr(struct qlcnic_adapter *adapter, |
| 2796 | struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2797 | { |
| 2798 | struct in_device *indev; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2799 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2800 | indev = in_dev_get(dev); |
| 2801 | if (!indev) |
| 2802 | return; |
| 2803 | |
| 2804 | for_ifa(indev) { |
| 2805 | switch (event) { |
| 2806 | case NETDEV_UP: |
| 2807 | qlcnic_config_ipaddr(adapter, |
| 2808 | ifa->ifa_address, QLCNIC_IP_UP); |
| 2809 | break; |
| 2810 | case NETDEV_DOWN: |
| 2811 | qlcnic_config_ipaddr(adapter, |
| 2812 | ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2813 | break; |
| 2814 | default: |
| 2815 | break; |
| 2816 | } |
| 2817 | } endfor_ifa(indev); |
| 2818 | |
| 2819 | in_dev_put(indev); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2822 | static void |
| 2823 | qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event) |
| 2824 | { |
| 2825 | struct qlcnic_adapter *adapter = netdev_priv(netdev); |
| 2826 | struct net_device *dev; |
| 2827 | u16 vid; |
| 2828 | |
| 2829 | qlcnic_config_indev_addr(adapter, netdev, event); |
| 2830 | |
Anirban Chakraborty | b9796a1 | 2011-04-01 14:28:15 +0000 | [diff] [blame] | 2831 | for_each_set_bit(vid, adapter->vlans, VLAN_N_VID) { |
Jiri Pirko | 223bb15 | 2011-07-20 04:54:44 +0000 | [diff] [blame] | 2832 | dev = __vlan_find_dev_deep(netdev, vid); |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2833 | if (!dev) |
| 2834 | continue; |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2835 | qlcnic_config_indev_addr(adapter, dev, event); |
| 2836 | } |
| 2837 | } |
| 2838 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2839 | static int qlcnic_netdev_event(struct notifier_block *this, |
| 2840 | unsigned long event, void *ptr) |
| 2841 | { |
| 2842 | struct qlcnic_adapter *adapter; |
| 2843 | struct net_device *dev = (struct net_device *)ptr; |
| 2844 | |
| 2845 | recheck: |
| 2846 | if (dev == NULL) |
| 2847 | goto done; |
| 2848 | |
| 2849 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2850 | dev = vlan_dev_real_dev(dev); |
| 2851 | goto recheck; |
| 2852 | } |
| 2853 | |
| 2854 | if (!is_qlcnic_netdev(dev)) |
| 2855 | goto done; |
| 2856 | |
| 2857 | adapter = netdev_priv(dev); |
| 2858 | |
| 2859 | if (!adapter) |
| 2860 | goto done; |
| 2861 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2862 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2863 | goto done; |
| 2864 | |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2865 | qlcnic_config_indev_addr(adapter, dev, event); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2866 | done: |
| 2867 | return NOTIFY_DONE; |
| 2868 | } |
| 2869 | |
| 2870 | static int |
| 2871 | qlcnic_inetaddr_event(struct notifier_block *this, |
| 2872 | unsigned long event, void *ptr) |
| 2873 | { |
| 2874 | struct qlcnic_adapter *adapter; |
| 2875 | struct net_device *dev; |
| 2876 | |
| 2877 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 2878 | |
| 2879 | dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; |
| 2880 | |
| 2881 | recheck: |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2882 | if (dev == NULL) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2883 | goto done; |
| 2884 | |
| 2885 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2886 | dev = vlan_dev_real_dev(dev); |
| 2887 | goto recheck; |
| 2888 | } |
| 2889 | |
| 2890 | if (!is_qlcnic_netdev(dev)) |
| 2891 | goto done; |
| 2892 | |
| 2893 | adapter = netdev_priv(dev); |
| 2894 | |
Amit Kumar Salecha | 251a84c | 2010-05-13 03:07:46 +0000 | [diff] [blame] | 2895 | if (!adapter) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2896 | goto done; |
| 2897 | |
Amit Kumar Salecha | 8a15ad1 | 2010-06-22 03:19:01 +0000 | [diff] [blame] | 2898 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2899 | goto done; |
| 2900 | |
| 2901 | switch (event) { |
| 2902 | case NETDEV_UP: |
| 2903 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_UP); |
| 2904 | break; |
| 2905 | case NETDEV_DOWN: |
| 2906 | qlcnic_config_ipaddr(adapter, ifa->ifa_address, QLCNIC_IP_DOWN); |
| 2907 | break; |
| 2908 | default: |
| 2909 | break; |
| 2910 | } |
| 2911 | |
| 2912 | done: |
| 2913 | return NOTIFY_DONE; |
| 2914 | } |
| 2915 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2916 | static struct notifier_block qlcnic_netdev_cb = { |
| 2917 | .notifier_call = qlcnic_netdev_event, |
| 2918 | }; |
| 2919 | |
| 2920 | static struct notifier_block qlcnic_inetaddr_cb = { |
| 2921 | .notifier_call = qlcnic_inetaddr_event, |
| 2922 | }; |
| 2923 | #else |
| 2924 | static void |
Amit Kumar Salecha | aec1e84 | 2010-09-16 19:14:41 +0000 | [diff] [blame] | 2925 | qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event) |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2926 | { } |
| 2927 | #endif |
Shahed Shaikh | 6350759 | 2012-11-23 23:56:52 +0000 | [diff] [blame] | 2928 | static struct pci_error_handlers qlcnic_err_handler = { |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2929 | .error_detected = qlcnic_io_error_detected, |
| 2930 | .slot_reset = qlcnic_io_slot_reset, |
| 2931 | .resume = qlcnic_io_resume, |
| 2932 | }; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2933 | |
| 2934 | static struct pci_driver qlcnic_driver = { |
| 2935 | .name = qlcnic_driver_name, |
| 2936 | .id_table = qlcnic_pci_tbl, |
| 2937 | .probe = qlcnic_probe, |
Bill Pemberton | 6bb58bb | 2012-12-03 09:23:25 -0500 | [diff] [blame] | 2938 | .remove = qlcnic_remove, |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2939 | #ifdef CONFIG_PM |
| 2940 | .suspend = qlcnic_suspend, |
| 2941 | .resume = qlcnic_resume, |
| 2942 | #endif |
Sucheta Chakraborty | 451724c | 2010-07-13 20:33:34 +0000 | [diff] [blame] | 2943 | .shutdown = qlcnic_shutdown, |
| 2944 | .err_handler = &qlcnic_err_handler |
| 2945 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2946 | }; |
| 2947 | |
| 2948 | static int __init qlcnic_init_module(void) |
| 2949 | { |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2950 | int ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2951 | |
| 2952 | printk(KERN_INFO "%s\n", qlcnic_driver_string); |
| 2953 | |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2954 | qlcnic_wq = create_singlethread_workqueue("qlcnic"); |
| 2955 | if (qlcnic_wq == NULL) { |
| 2956 | printk(KERN_ERR "qlcnic: cannot create workqueue\n"); |
| 2957 | return -ENOMEM; |
| 2958 | } |
| 2959 | |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2960 | #ifdef CONFIG_INET |
| 2961 | register_netdevice_notifier(&qlcnic_netdev_cb); |
| 2962 | register_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2963 | #endif |
| 2964 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2965 | ret = pci_register_driver(&qlcnic_driver); |
| 2966 | if (ret) { |
| 2967 | #ifdef CONFIG_INET |
| 2968 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2969 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 2970 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2971 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2972 | } |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2973 | |
Amit Kumar Salecha | 0cf3a14 | 2010-07-13 20:33:33 +0000 | [diff] [blame] | 2974 | return ret; |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | module_init(qlcnic_init_module); |
| 2978 | |
| 2979 | static void __exit qlcnic_exit_module(void) |
| 2980 | { |
| 2981 | |
| 2982 | pci_unregister_driver(&qlcnic_driver); |
| 2983 | |
| 2984 | #ifdef CONFIG_INET |
| 2985 | unregister_inetaddr_notifier(&qlcnic_inetaddr_cb); |
| 2986 | unregister_netdevice_notifier(&qlcnic_netdev_cb); |
| 2987 | #endif |
Amit Kumar Salecha | f7ec804 | 2010-10-07 23:46:05 +0000 | [diff] [blame] | 2988 | destroy_workqueue(qlcnic_wq); |
Amit Kumar Salecha | af19b49 | 2010-01-13 00:37:25 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | module_exit(qlcnic_exit_module); |