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