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