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