Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver |
Catherine Sullivan | eaab59e | 2016-01-13 16:51:44 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Jesse Brandeburg | b831607 | 2014-04-05 07:46:11 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | #include "i40evf.h" |
| 28 | #include "i40e_prototype.h" |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 29 | #include "i40evf_client.h" |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 30 | /* All i40evf tracepoints are defined by the include below, which must |
| 31 | * be included exactly once across the whole kernel with |
| 32 | * CREATE_TRACE_POINTS defined |
| 33 | */ |
| 34 | #define CREATE_TRACE_POINTS |
| 35 | #include "i40e_trace.h" |
| 36 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 37 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter); |
| 38 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter); |
| 39 | static int i40evf_close(struct net_device *netdev); |
| 40 | |
| 41 | char i40evf_driver_name[] = "i40evf"; |
| 42 | static const char i40evf_driver_string[] = |
Catherine Sullivan | eaab59e | 2016-01-13 16:51:44 -0800 | [diff] [blame] | 43 | "Intel(R) 40-10 Gigabit Virtual Function Network Driver"; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 44 | |
Mitch Williams | 69ebe955 | 2015-11-19 11:34:24 -0800 | [diff] [blame] | 45 | #define DRV_KERN "-k" |
| 46 | |
Preethi Banala | abf709a | 2017-05-11 11:23:20 -0700 | [diff] [blame] | 47 | #define DRV_VERSION_MAJOR 3 |
Alice Michael | f2fc31e | 2017-10-27 11:06:56 -0400 | [diff] [blame] | 48 | #define DRV_VERSION_MINOR 2 |
| 49 | #define DRV_VERSION_BUILD 2 |
Mitch Williams | 69ebe955 | 2015-11-19 11:34:24 -0800 | [diff] [blame] | 50 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 51 | __stringify(DRV_VERSION_MINOR) "." \ |
| 52 | __stringify(DRV_VERSION_BUILD) \ |
| 53 | DRV_KERN |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 54 | const char i40evf_driver_version[] = DRV_VERSION; |
| 55 | static const char i40evf_copyright[] = |
Catherine Sullivan | bf41846 | 2015-07-10 19:36:10 -0400 | [diff] [blame] | 56 | "Copyright (c) 2013 - 2015 Intel Corporation."; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 57 | |
| 58 | /* i40evf_pci_tbl - PCI Device ID Table |
| 59 | * |
| 60 | * Wildcard entries (PCI_ANY_ID) should come last |
| 61 | * Last entry must be all 0s |
| 62 | * |
| 63 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 64 | * Class, Class Mask, private data (not used) } |
| 65 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 66 | static const struct pci_device_id i40evf_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 67 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0}, |
Joshua Hay | 9287141 | 2016-06-20 09:10:37 -0700 | [diff] [blame] | 68 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF_HV), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 69 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0}, |
Preethi Banala | abf709a | 2017-05-11 11:23:20 -0700 | [diff] [blame] | 70 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_ADAPTIVE_VF), 0}, |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 71 | /* required last entry */ |
| 72 | {0, } |
| 73 | }; |
| 74 | |
| 75 | MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl); |
| 76 | |
| 77 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 78 | MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver"); |
| 79 | MODULE_LICENSE("GPL"); |
| 80 | MODULE_VERSION(DRV_VERSION); |
| 81 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 82 | static struct workqueue_struct *i40evf_wq; |
| 83 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 84 | /** |
| 85 | * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 86 | * @hw: pointer to the HW structure |
| 87 | * @mem: ptr to mem struct to fill out |
| 88 | * @size: size of memory requested |
| 89 | * @alignment: what to align the allocation to |
| 90 | **/ |
| 91 | i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw, |
| 92 | struct i40e_dma_mem *mem, |
| 93 | u64 size, u32 alignment) |
| 94 | { |
| 95 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; |
| 96 | |
| 97 | if (!mem) |
| 98 | return I40E_ERR_PARAM; |
| 99 | |
| 100 | mem->size = ALIGN(size, alignment); |
| 101 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, |
| 102 | (dma_addr_t *)&mem->pa, GFP_KERNEL); |
| 103 | if (mem->va) |
| 104 | return 0; |
| 105 | else |
| 106 | return I40E_ERR_NO_MEMORY; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * i40evf_free_dma_mem_d - OS specific memory free for shared code |
| 111 | * @hw: pointer to the HW structure |
| 112 | * @mem: ptr to mem struct to free |
| 113 | **/ |
| 114 | i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 115 | { |
| 116 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; |
| 117 | |
| 118 | if (!mem || !mem->va) |
| 119 | return I40E_ERR_PARAM; |
| 120 | dma_free_coherent(&adapter->pdev->dev, mem->size, |
| 121 | mem->va, (dma_addr_t)mem->pa); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 127 | * @hw: pointer to the HW structure |
| 128 | * @mem: ptr to mem struct to fill out |
| 129 | * @size: size of memory requested |
| 130 | **/ |
| 131 | i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw, |
| 132 | struct i40e_virt_mem *mem, u32 size) |
| 133 | { |
| 134 | if (!mem) |
| 135 | return I40E_ERR_PARAM; |
| 136 | |
| 137 | mem->size = size; |
| 138 | mem->va = kzalloc(size, GFP_KERNEL); |
| 139 | |
| 140 | if (mem->va) |
| 141 | return 0; |
| 142 | else |
| 143 | return I40E_ERR_NO_MEMORY; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * i40evf_free_virt_mem_d - OS specific memory free for shared code |
| 148 | * @hw: pointer to the HW structure |
| 149 | * @mem: ptr to mem struct to free |
| 150 | **/ |
| 151 | i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw, |
| 152 | struct i40e_virt_mem *mem) |
| 153 | { |
| 154 | if (!mem) |
| 155 | return I40E_ERR_PARAM; |
| 156 | |
| 157 | /* it's ok to kfree a NULL pointer */ |
| 158 | kfree(mem->va); |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * i40evf_debug_d - OS dependent version of debug printing |
| 165 | * @hw: pointer to the HW structure |
| 166 | * @mask: debug level mask |
| 167 | * @fmt_str: printf-type format description |
| 168 | **/ |
| 169 | void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...) |
| 170 | { |
| 171 | char buf[512]; |
| 172 | va_list argptr; |
| 173 | |
| 174 | if (!(mask & ((struct i40e_hw *)hw)->debug_mask)) |
| 175 | return; |
| 176 | |
| 177 | va_start(argptr, fmt_str); |
| 178 | vsnprintf(buf, sizeof(buf), fmt_str, argptr); |
| 179 | va_end(argptr); |
| 180 | |
| 181 | /* the debug string is already formatted with a newline */ |
| 182 | pr_info("%s", buf); |
| 183 | } |
| 184 | |
| 185 | /** |
Mitch Williams | 00e5ec4 | 2016-01-15 14:33:10 -0800 | [diff] [blame] | 186 | * i40evf_schedule_reset - Set the flags and schedule a reset event |
| 187 | * @adapter: board private structure |
| 188 | **/ |
| 189 | void i40evf_schedule_reset(struct i40evf_adapter *adapter) |
| 190 | { |
| 191 | if (!(adapter->flags & |
| 192 | (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED))) { |
| 193 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
| 194 | schedule_work(&adapter->reset_task); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 199 | * i40evf_tx_timeout - Respond to a Tx Hang |
| 200 | * @netdev: network interface device structure |
| 201 | **/ |
| 202 | static void i40evf_tx_timeout(struct net_device *netdev) |
| 203 | { |
| 204 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 205 | |
| 206 | adapter->tx_timeout_count++; |
Mitch Williams | 00e5ec4 | 2016-01-15 14:33:10 -0800 | [diff] [blame] | 207 | i40evf_schedule_reset(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
| 211 | * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC |
| 212 | * @adapter: board private structure |
| 213 | **/ |
| 214 | static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter) |
| 215 | { |
| 216 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 217 | |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame] | 218 | if (!adapter->msix_entries) |
| 219 | return; |
| 220 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 221 | wr32(hw, I40E_VFINT_DYN_CTL01, 0); |
| 222 | |
| 223 | /* read flush */ |
| 224 | rd32(hw, I40E_VFGEN_RSTAT); |
| 225 | |
| 226 | synchronize_irq(adapter->msix_entries[0].vector); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * i40evf_misc_irq_enable - Enable default interrupt generation settings |
| 231 | * @adapter: board private structure |
| 232 | **/ |
| 233 | static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter) |
| 234 | { |
| 235 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 236 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 237 | wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK | |
| 238 | I40E_VFINT_DYN_CTL01_ITR_INDX_MASK); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 239 | wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 240 | |
| 241 | /* read flush */ |
| 242 | rd32(hw, I40E_VFGEN_RSTAT); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * i40evf_irq_disable - Mask off interrupt generation on the NIC |
| 247 | * @adapter: board private structure |
| 248 | **/ |
| 249 | static void i40evf_irq_disable(struct i40evf_adapter *adapter) |
| 250 | { |
| 251 | int i; |
| 252 | struct i40e_hw *hw = &adapter->hw; |
| 253 | |
Mitch Williams | dbb01c8 | 2014-02-20 19:29:07 -0800 | [diff] [blame] | 254 | if (!adapter->msix_entries) |
| 255 | return; |
| 256 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 257 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
| 258 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0); |
| 259 | synchronize_irq(adapter->msix_entries[i].vector); |
| 260 | } |
| 261 | /* read flush */ |
| 262 | rd32(hw, I40E_VFGEN_RSTAT); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * i40evf_irq_enable_queues - Enable interrupt for specified queues |
| 267 | * @adapter: board private structure |
| 268 | * @mask: bitmap of queues to enable |
| 269 | **/ |
| 270 | void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask) |
| 271 | { |
| 272 | struct i40e_hw *hw = &adapter->hw; |
| 273 | int i; |
| 274 | |
| 275 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 276 | if (mask & BIT(i - 1)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 277 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), |
| 278 | I40E_VFINT_DYN_CTLN1_INTENA_MASK | |
Alexander Duyck | 498860c | 2017-11-14 07:00:44 -0500 | [diff] [blame] | 279 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 285 | * i40evf_irq_enable - Enable default interrupt generation settings |
| 286 | * @adapter: board private structure |
Jean Sacren | 69c1d70 | 2015-10-13 01:06:27 -0600 | [diff] [blame] | 287 | * @flush: boolean value whether to run rd32() |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 288 | **/ |
| 289 | void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush) |
| 290 | { |
| 291 | struct i40e_hw *hw = &adapter->hw; |
| 292 | |
Mitch Williams | 164ec1b | 2014-06-04 08:45:19 +0000 | [diff] [blame] | 293 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 294 | i40evf_irq_enable_queues(adapter, ~0); |
| 295 | |
| 296 | if (flush) |
| 297 | rd32(hw, I40E_VFGEN_RSTAT); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * i40evf_msix_aq - Interrupt handler for vector 0 |
| 302 | * @irq: interrupt number |
| 303 | * @data: pointer to netdev |
| 304 | **/ |
| 305 | static irqreturn_t i40evf_msix_aq(int irq, void *data) |
| 306 | { |
| 307 | struct net_device *netdev = data; |
| 308 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 309 | struct i40e_hw *hw = &adapter->hw; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 310 | |
Jesse Brandeburg | cfbe4db | 2015-10-04 01:09:49 -0700 | [diff] [blame] | 311 | /* handle non-queue interrupts, these reads clear the registers */ |
Alexander Duyck | 498860c | 2017-11-14 07:00:44 -0500 | [diff] [blame] | 312 | rd32(hw, I40E_VFINT_ICR01); |
| 313 | rd32(hw, I40E_VFINT_ICR0_ENA1); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 314 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 315 | /* schedule work on the private workqueue */ |
| 316 | schedule_work(&adapter->adminq_task); |
| 317 | |
| 318 | return IRQ_HANDLED; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * i40evf_msix_clean_rings - MSIX mode Interrupt Handler |
| 323 | * @irq: interrupt number |
| 324 | * @data: pointer to a q_vector |
| 325 | **/ |
| 326 | static irqreturn_t i40evf_msix_clean_rings(int irq, void *data) |
| 327 | { |
| 328 | struct i40e_q_vector *q_vector = data; |
| 329 | |
| 330 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
| 331 | return IRQ_HANDLED; |
| 332 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 333 | napi_schedule_irqoff(&q_vector->napi); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 334 | |
| 335 | return IRQ_HANDLED; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * i40evf_map_vector_to_rxq - associate irqs with rx queues |
| 340 | * @adapter: board private structure |
| 341 | * @v_idx: interrupt number |
| 342 | * @r_idx: queue number |
| 343 | **/ |
| 344 | static void |
| 345 | i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx) |
| 346 | { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 347 | struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx]; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 348 | struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx]; |
Mitch Williams | f19a973 | 2016-09-12 14:18:38 -0700 | [diff] [blame] | 349 | struct i40e_hw *hw = &adapter->hw; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 350 | |
| 351 | rx_ring->q_vector = q_vector; |
| 352 | rx_ring->next = q_vector->rx.ring; |
| 353 | rx_ring->vsi = &adapter->vsi; |
| 354 | q_vector->rx.ring = rx_ring; |
| 355 | q_vector->rx.count++; |
| 356 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 357 | q_vector->rx.itr = ITR_TO_REG(rx_ring->rx_itr_setting); |
Mitch Williams | f19a973 | 2016-09-12 14:18:38 -0700 | [diff] [blame] | 358 | q_vector->ring_mask |= BIT(r_idx); |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 359 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Mitch Williams | f19a973 | 2016-09-12 14:18:38 -0700 | [diff] [blame] | 360 | wr32(hw, I40E_VFINT_ITRN1(I40E_RX_ITR, v_idx - 1), q_vector->rx.itr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
| 364 | * i40evf_map_vector_to_txq - associate irqs with tx queues |
| 365 | * @adapter: board private structure |
| 366 | * @v_idx: interrupt number |
| 367 | * @t_idx: queue number |
| 368 | **/ |
| 369 | static void |
| 370 | i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx) |
| 371 | { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 372 | struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx]; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 373 | struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx]; |
Mitch Williams | f19a973 | 2016-09-12 14:18:38 -0700 | [diff] [blame] | 374 | struct i40e_hw *hw = &adapter->hw; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 375 | |
| 376 | tx_ring->q_vector = q_vector; |
| 377 | tx_ring->next = q_vector->tx.ring; |
| 378 | tx_ring->vsi = &adapter->vsi; |
| 379 | q_vector->tx.ring = tx_ring; |
| 380 | q_vector->tx.count++; |
| 381 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 382 | q_vector->tx.itr = ITR_TO_REG(tx_ring->tx_itr_setting); |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 383 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 384 | q_vector->num_ringpairs++; |
Mitch Williams | f19a973 | 2016-09-12 14:18:38 -0700 | [diff] [blame] | 385 | wr32(hw, I40E_VFINT_ITRN1(I40E_TX_ITR, v_idx - 1), q_vector->tx.itr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /** |
| 389 | * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors |
| 390 | * @adapter: board private structure to initialize |
| 391 | * |
| 392 | * This function maps descriptor rings to the queue-specific vectors |
| 393 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 394 | * one vector per ring/queue, but on a constrained vector budget, we |
| 395 | * group the rings as "efficiently" as possible. You would add new |
| 396 | * mapping configurations in here. |
| 397 | **/ |
Mitch Williams | 1b7b759 | 2017-08-22 06:57:51 -0400 | [diff] [blame] | 398 | static void i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 399 | { |
Alan Brady | c97fc9b | 2017-07-14 09:27:07 -0400 | [diff] [blame] | 400 | int rings_remaining = adapter->num_active_queues; |
| 401 | int ridx = 0, vidx = 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 402 | int q_vectors; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 403 | |
| 404 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 405 | |
Alan Brady | c97fc9b | 2017-07-14 09:27:07 -0400 | [diff] [blame] | 406 | for (; ridx < rings_remaining; ridx++) { |
| 407 | i40evf_map_vector_to_rxq(adapter, vidx, ridx); |
| 408 | i40evf_map_vector_to_txq(adapter, vidx, ridx); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 409 | |
Alan Brady | c97fc9b | 2017-07-14 09:27:07 -0400 | [diff] [blame] | 410 | /* In the case where we have more queues than vectors, continue |
| 411 | * round-robin on vectors until all queues are mapped. |
| 412 | */ |
| 413 | if (++vidx >= q_vectors) |
| 414 | vidx = 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 417 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Alexander Duyck | 7709b4c | 2015-09-24 09:04:38 -0700 | [diff] [blame] | 420 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 421 | /** |
| 422 | * i40evf_netpoll - A Polling 'interrupt' handler |
| 423 | * @netdev: network interface device structure |
| 424 | * |
| 425 | * This is used by netconsole to send skbs without having to re-enable |
| 426 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 427 | **/ |
| 428 | static void i40evf_netpoll(struct net_device *netdev) |
| 429 | { |
| 430 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 431 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 432 | int i; |
| 433 | |
| 434 | /* if interface is down do nothing */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 435 | if (test_bit(__I40E_VSI_DOWN, adapter->vsi.state)) |
Alexander Duyck | 7709b4c | 2015-09-24 09:04:38 -0700 | [diff] [blame] | 436 | return; |
| 437 | |
| 438 | for (i = 0; i < q_vectors; i++) |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 439 | i40evf_msix_clean_rings(0, &adapter->q_vectors[i]); |
Alexander Duyck | 7709b4c | 2015-09-24 09:04:38 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | #endif |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 443 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 444 | * i40evf_irq_affinity_notify - Callback for affinity changes |
| 445 | * @notify: context as to what irq was changed |
| 446 | * @mask: the new affinity mask |
| 447 | * |
| 448 | * This is a callback function used by the irq_set_affinity_notifier function |
| 449 | * so that we may register to receive changes to the irq affinity masks. |
| 450 | **/ |
| 451 | static void i40evf_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 452 | const cpumask_t *mask) |
| 453 | { |
| 454 | struct i40e_q_vector *q_vector = |
| 455 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 456 | |
Jacob Keller | 7e4d01e | 2017-07-12 05:46:05 -0400 | [diff] [blame] | 457 | cpumask_copy(&q_vector->affinity_mask, mask); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
| 461 | * i40evf_irq_affinity_release - Callback for affinity notifier release |
| 462 | * @ref: internal core kernel usage |
| 463 | * |
| 464 | * This is a callback function used by the irq_set_affinity_notifier function |
| 465 | * to inform the current notification subscriber that they will no longer |
| 466 | * receive notifications. |
| 467 | **/ |
| 468 | static void i40evf_irq_affinity_release(struct kref *ref) {} |
| 469 | |
| 470 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 471 | * i40evf_request_traffic_irqs - Initialize MSI-X interrupts |
| 472 | * @adapter: board private structure |
| 473 | * |
| 474 | * Allocates MSI-X vectors for tx and rx handling, and requests |
| 475 | * interrupts from the kernel. |
| 476 | **/ |
| 477 | static int |
| 478 | i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename) |
| 479 | { |
Jacob Keller | 696ac80a | 2017-07-12 05:46:11 -0400 | [diff] [blame] | 480 | unsigned int vector, q_vectors; |
| 481 | unsigned int rx_int_idx = 0, tx_int_idx = 0; |
| 482 | int irq_num, err; |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 483 | int cpu; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 484 | |
| 485 | i40evf_irq_disable(adapter); |
| 486 | /* Decrement for Other and TCP Timer vectors */ |
| 487 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 488 | |
| 489 | for (vector = 0; vector < q_vectors; vector++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 490 | struct i40e_q_vector *q_vector = &adapter->q_vectors[vector]; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 491 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 492 | |
| 493 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jacob Keller | 696ac80a | 2017-07-12 05:46:11 -0400 | [diff] [blame] | 494 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 495 | "i40evf-%s-TxRx-%d", basename, rx_int_idx++); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 496 | tx_int_idx++; |
| 497 | } else if (q_vector->rx.ring) { |
Jacob Keller | 696ac80a | 2017-07-12 05:46:11 -0400 | [diff] [blame] | 498 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 499 | "i40evf-%s-rx-%d", basename, rx_int_idx++); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 500 | } else if (q_vector->tx.ring) { |
Jacob Keller | 696ac80a | 2017-07-12 05:46:11 -0400 | [diff] [blame] | 501 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 502 | "i40evf-%s-tx-%d", basename, tx_int_idx++); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 503 | } else { |
| 504 | /* skip this unused q_vector */ |
| 505 | continue; |
| 506 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 507 | err = request_irq(irq_num, |
| 508 | i40evf_msix_clean_rings, |
| 509 | 0, |
| 510 | q_vector->name, |
| 511 | q_vector); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 512 | if (err) { |
| 513 | dev_info(&adapter->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 514 | "Request_irq failed, error: %d\n", err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 515 | goto free_queue_irqs; |
| 516 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 517 | /* register for affinity change notifications */ |
| 518 | q_vector->affinity_notify.notify = i40evf_irq_affinity_notify; |
| 519 | q_vector->affinity_notify.release = |
| 520 | i40evf_irq_affinity_release; |
| 521 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 522 | /* Spread the IRQ affinity hints across online CPUs. Note that |
| 523 | * get_cpu_mask returns a mask with a permanent lifetime so |
| 524 | * it's safe to use as a hint for irq_set_affinity_hint. |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 525 | */ |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 526 | cpu = cpumask_local_spread(q_vector->v_idx, -1); |
| 527 | irq_set_affinity_hint(irq_num, get_cpu_mask(cpu)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | |
| 532 | free_queue_irqs: |
| 533 | while (vector) { |
| 534 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 535 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; |
| 536 | irq_set_affinity_notifier(irq_num, NULL); |
| 537 | irq_set_affinity_hint(irq_num, NULL); |
| 538 | free_irq(irq_num, &adapter->q_vectors[vector]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 539 | } |
| 540 | return err; |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * i40evf_request_misc_irq - Initialize MSI-X interrupts |
| 545 | * @adapter: board private structure |
| 546 | * |
| 547 | * Allocates MSI-X vector 0 and requests interrupts from the kernel. This |
| 548 | * vector is only for the admin queue, and stays active even when the netdev |
| 549 | * is closed. |
| 550 | **/ |
| 551 | static int i40evf_request_misc_irq(struct i40evf_adapter *adapter) |
| 552 | { |
| 553 | struct net_device *netdev = adapter->netdev; |
| 554 | int err; |
| 555 | |
Jesse Brandeburg | b39c1e2 | 2014-08-01 13:27:08 -0700 | [diff] [blame] | 556 | snprintf(adapter->misc_vector_name, |
Carolyn Wyborny | 9a21a00 | 2015-02-06 08:52:20 +0000 | [diff] [blame] | 557 | sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx", |
| 558 | dev_name(&adapter->pdev->dev)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 559 | err = request_irq(adapter->msix_entries[0].vector, |
Mitch Williams | e1dfee8 | 2014-02-13 03:48:51 -0800 | [diff] [blame] | 560 | &i40evf_msix_aq, 0, |
| 561 | adapter->misc_vector_name, netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 562 | if (err) { |
| 563 | dev_err(&adapter->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 564 | "request_irq for %s failed: %d\n", |
| 565 | adapter->misc_vector_name, err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 566 | free_irq(adapter->msix_entries[0].vector, netdev); |
| 567 | } |
| 568 | return err; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * i40evf_free_traffic_irqs - Free MSI-X interrupts |
| 573 | * @adapter: board private structure |
| 574 | * |
| 575 | * Frees all MSI-X vectors other than 0. |
| 576 | **/ |
| 577 | static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter) |
| 578 | { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 579 | int vector, irq_num, q_vectors; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 580 | |
Alan Brady | 47d2a5d | 2016-11-08 13:05:05 -0800 | [diff] [blame] | 581 | if (!adapter->msix_entries) |
| 582 | return; |
| 583 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 584 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 585 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 586 | for (vector = 0; vector < q_vectors; vector++) { |
| 587 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; |
| 588 | irq_set_affinity_notifier(irq_num, NULL); |
| 589 | irq_set_affinity_hint(irq_num, NULL); |
| 590 | free_irq(irq_num, &adapter->q_vectors[vector]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * i40evf_free_misc_irq - Free MSI-X miscellaneous vector |
| 596 | * @adapter: board private structure |
| 597 | * |
| 598 | * Frees MSI-X vector 0. |
| 599 | **/ |
| 600 | static void i40evf_free_misc_irq(struct i40evf_adapter *adapter) |
| 601 | { |
| 602 | struct net_device *netdev = adapter->netdev; |
| 603 | |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame] | 604 | if (!adapter->msix_entries) |
| 605 | return; |
| 606 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 607 | free_irq(adapter->msix_entries[0].vector, netdev); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * i40evf_configure_tx - Configure Transmit Unit after Reset |
| 612 | * @adapter: board private structure |
| 613 | * |
| 614 | * Configure the Tx unit of the MAC after a reset. |
| 615 | **/ |
| 616 | static void i40evf_configure_tx(struct i40evf_adapter *adapter) |
| 617 | { |
| 618 | struct i40e_hw *hw = &adapter->hw; |
| 619 | int i; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 620 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 621 | for (i = 0; i < adapter->num_active_queues; i++) |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 622 | adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /** |
| 626 | * i40evf_configure_rx - Configure Receive Unit after Reset |
| 627 | * @adapter: board private structure |
| 628 | * |
| 629 | * Configure the Rx unit of the MAC after a reset. |
| 630 | **/ |
| 631 | static void i40evf_configure_rx(struct i40evf_adapter *adapter) |
| 632 | { |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 633 | unsigned int rx_buf_len = I40E_RXBUFFER_2048; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 634 | struct i40e_hw *hw = &adapter->hw; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 635 | int i; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 636 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 637 | /* Legacy Rx will always default to a 2048 buffer size. */ |
| 638 | #if (PAGE_SIZE < 8192) |
| 639 | if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX)) { |
Arnd Bergmann | 3dfc3eb | 2017-04-19 19:29:48 +0200 | [diff] [blame] | 640 | struct net_device *netdev = adapter->netdev; |
| 641 | |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 642 | /* For jumbo frames on systems with 4K pages we have to use |
| 643 | * an order 1 page, so we might as well increase the size |
| 644 | * of our Rx buffer to make better use of the available space |
| 645 | */ |
| 646 | rx_buf_len = I40E_RXBUFFER_3072; |
| 647 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 648 | /* We use a 1536 buffer size for configurations with |
| 649 | * standard Ethernet mtu. On x86 this gives us enough room |
| 650 | * for shared info and 192 bytes of padding. |
| 651 | */ |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 652 | if (!I40E_2K_TOO_SMALL_WITH_PADDING && |
| 653 | (netdev->mtu <= ETH_DATA_LEN)) |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 654 | rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 655 | } |
| 656 | #endif |
| 657 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 658 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 659 | adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i); |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 660 | adapter->rx_rings[i].rx_buf_len = rx_buf_len; |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 661 | |
| 662 | if (adapter->flags & I40EVF_FLAG_LEGACY_RX) |
| 663 | clear_ring_build_skb_enabled(&adapter->rx_rings[i]); |
| 664 | else |
| 665 | set_ring_build_skb_enabled(&adapter->rx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * i40evf_find_vlan - Search filter list for specific vlan filter |
| 671 | * @adapter: board private structure |
| 672 | * @vlan: vlan tag |
| 673 | * |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 674 | * Returns ptr to the filter object or NULL. Must be called while holding the |
| 675 | * mac_vlan_list_lock. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 676 | **/ |
| 677 | static struct |
| 678 | i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 679 | { |
| 680 | struct i40evf_vlan_filter *f; |
| 681 | |
| 682 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 683 | if (vlan == f->vlan) |
| 684 | return f; |
| 685 | } |
| 686 | return NULL; |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * i40evf_add_vlan - Add a vlan filter to the list |
| 691 | * @adapter: board private structure |
| 692 | * @vlan: VLAN tag |
| 693 | * |
| 694 | * Returns ptr to the filter object or NULL when no memory available. |
| 695 | **/ |
| 696 | static struct |
| 697 | i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 698 | { |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 699 | struct i40evf_vlan_filter *f = NULL; |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 700 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 701 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 702 | |
| 703 | f = i40evf_find_vlan(adapter, vlan); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 704 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 705 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 706 | if (!f) |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 707 | goto clearout; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 708 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 709 | f->vlan = vlan; |
| 710 | |
| 711 | INIT_LIST_HEAD(&f->list); |
| 712 | list_add(&f->list, &adapter->vlan_filter_list); |
| 713 | f->add = true; |
| 714 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
| 715 | } |
| 716 | |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 717 | clearout: |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 718 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 719 | return f; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * i40evf_del_vlan - Remove a vlan filter from the list |
| 724 | * @adapter: board private structure |
| 725 | * @vlan: VLAN tag |
| 726 | **/ |
| 727 | static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 728 | { |
| 729 | struct i40evf_vlan_filter *f; |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 730 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 731 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 732 | |
| 733 | f = i40evf_find_vlan(adapter, vlan); |
| 734 | if (f) { |
| 735 | f->remove = true; |
| 736 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
| 737 | } |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 738 | |
| 739 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /** |
| 743 | * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device |
| 744 | * @netdev: network device struct |
| 745 | * @vid: VLAN tag |
| 746 | **/ |
| 747 | static int i40evf_vlan_rx_add_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 748 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 749 | { |
| 750 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 751 | |
Mitch Williams | 8ed995f | 2015-08-28 17:55:57 -0400 | [diff] [blame] | 752 | if (!VLAN_ALLOWED(adapter)) |
| 753 | return -EIO; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 754 | if (i40evf_add_vlan(adapter, vid) == NULL) |
| 755 | return -ENOMEM; |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device |
| 761 | * @netdev: network device struct |
| 762 | * @vid: VLAN tag |
| 763 | **/ |
| 764 | static int i40evf_vlan_rx_kill_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 765 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 766 | { |
| 767 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 768 | |
Mitch Williams | 8ed995f | 2015-08-28 17:55:57 -0400 | [diff] [blame] | 769 | if (VLAN_ALLOWED(adapter)) { |
| 770 | i40evf_del_vlan(adapter, vid); |
| 771 | return 0; |
| 772 | } |
| 773 | return -EIO; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
| 777 | * i40evf_find_filter - Search filter list for specific mac filter |
| 778 | * @adapter: board private structure |
| 779 | * @macaddr: the MAC address |
| 780 | * |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 781 | * Returns ptr to the filter object or NULL. Must be called while holding the |
| 782 | * mac_vlan_list_lock. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 783 | **/ |
| 784 | static struct |
| 785 | i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter, |
| 786 | u8 *macaddr) |
| 787 | { |
| 788 | struct i40evf_mac_filter *f; |
| 789 | |
| 790 | if (!macaddr) |
| 791 | return NULL; |
| 792 | |
| 793 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 794 | if (ether_addr_equal(macaddr, f->macaddr)) |
| 795 | return f; |
| 796 | } |
| 797 | return NULL; |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * i40e_add_filter - Add a mac filter to the filter list |
| 802 | * @adapter: board private structure |
| 803 | * @macaddr: the MAC address |
| 804 | * |
| 805 | * Returns ptr to the filter object or NULL when no memory available. |
| 806 | **/ |
| 807 | static struct |
| 808 | i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter, |
| 809 | u8 *macaddr) |
| 810 | { |
| 811 | struct i40evf_mac_filter *f; |
| 812 | |
| 813 | if (!macaddr) |
| 814 | return NULL; |
| 815 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 816 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 817 | |
| 818 | f = i40evf_find_filter(adapter, macaddr); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 819 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 820 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 821 | if (!f) |
| 822 | goto clearout; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 823 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 824 | ether_addr_copy(f->macaddr, macaddr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 825 | |
Mitch Williams | 63590b6 | 2016-05-16 10:26:42 -0700 | [diff] [blame] | 826 | list_add_tail(&f->list, &adapter->mac_filter_list); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 827 | f->add = true; |
| 828 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Alan Brady | c766b9a | 2017-09-07 08:05:47 -0400 | [diff] [blame] | 829 | } else { |
| 830 | f->remove = false; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 833 | clearout: |
| 834 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 835 | return f; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * i40evf_set_mac - NDO callback to set port mac address |
| 840 | * @netdev: network interface device structure |
| 841 | * @p: pointer to an address structure |
| 842 | * |
| 843 | * Returns 0 on success, negative on failure |
| 844 | **/ |
| 845 | static int i40evf_set_mac(struct net_device *netdev, void *p) |
| 846 | { |
| 847 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 848 | struct i40e_hw *hw = &adapter->hw; |
| 849 | struct i40evf_mac_filter *f; |
| 850 | struct sockaddr *addr = p; |
| 851 | |
| 852 | if (!is_valid_ether_addr(addr->sa_data)) |
| 853 | return -EADDRNOTAVAIL; |
| 854 | |
| 855 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) |
| 856 | return 0; |
| 857 | |
Mitch Williams | 14e52ee | 2015-08-31 19:54:44 -0400 | [diff] [blame] | 858 | if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF) |
| 859 | return -EPERM; |
| 860 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 861 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
| 862 | |
Mitch Williams | 14e52ee | 2015-08-31 19:54:44 -0400 | [diff] [blame] | 863 | f = i40evf_find_filter(adapter, hw->mac.addr); |
| 864 | if (f) { |
| 865 | f->remove = true; |
| 866 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 867 | } |
| 868 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 869 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
| 870 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 871 | f = i40evf_add_filter(adapter, addr->sa_data); |
| 872 | if (f) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 873 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
| 874 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | return (f == NULL) ? -ENOMEM : 0; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * i40evf_set_rx_mode - NDO callback to set the netdev filters |
| 882 | * @netdev: network interface device structure |
| 883 | **/ |
| 884 | static void i40evf_set_rx_mode(struct net_device *netdev) |
| 885 | { |
| 886 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 887 | struct i40evf_mac_filter *f, *ftmp; |
| 888 | struct netdev_hw_addr *uca; |
| 889 | struct netdev_hw_addr *mca; |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 890 | struct netdev_hw_addr *ha; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 891 | |
| 892 | /* add addr if not already in the filter list */ |
| 893 | netdev_for_each_uc_addr(uca, netdev) { |
| 894 | i40evf_add_filter(adapter, uca->addr); |
| 895 | } |
| 896 | netdev_for_each_mc_addr(mca, netdev) { |
| 897 | i40evf_add_filter(adapter, mca->addr); |
| 898 | } |
| 899 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 900 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
| 901 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 902 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 903 | netdev_for_each_mc_addr(mca, netdev) |
| 904 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 905 | goto bottom_of_search_loop; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 906 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 907 | netdev_for_each_uc_addr(uca, netdev) |
| 908 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 909 | goto bottom_of_search_loop; |
| 910 | |
| 911 | for_each_dev_addr(netdev, ha) |
| 912 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 913 | goto bottom_of_search_loop; |
| 914 | |
| 915 | if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) |
| 916 | goto bottom_of_search_loop; |
| 917 | |
| 918 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 919 | f->remove = true; |
| 920 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 921 | |
| 922 | bottom_of_search_loop: |
| 923 | continue; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 924 | } |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 925 | |
| 926 | if (netdev->flags & IFF_PROMISC && |
| 927 | !(adapter->flags & I40EVF_FLAG_PROMISC_ON)) |
| 928 | adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_PROMISC; |
| 929 | else if (!(netdev->flags & IFF_PROMISC) && |
| 930 | adapter->flags & I40EVF_FLAG_PROMISC_ON) |
| 931 | adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_PROMISC; |
| 932 | |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 933 | if (netdev->flags & IFF_ALLMULTI && |
| 934 | !(adapter->flags & I40EVF_FLAG_ALLMULTI_ON)) |
| 935 | adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_ALLMULTI; |
| 936 | else if (!(netdev->flags & IFF_ALLMULTI) && |
| 937 | adapter->flags & I40EVF_FLAG_ALLMULTI_ON) |
| 938 | adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_ALLMULTI; |
| 939 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 940 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /** |
| 944 | * i40evf_napi_enable_all - enable NAPI on all queue vectors |
| 945 | * @adapter: board private structure |
| 946 | **/ |
| 947 | static void i40evf_napi_enable_all(struct i40evf_adapter *adapter) |
| 948 | { |
| 949 | int q_idx; |
| 950 | struct i40e_q_vector *q_vector; |
| 951 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 952 | |
| 953 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 954 | struct napi_struct *napi; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 955 | |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 956 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 957 | napi = &q_vector->napi; |
| 958 | napi_enable(napi); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * i40evf_napi_disable_all - disable NAPI on all queue vectors |
| 964 | * @adapter: board private structure |
| 965 | **/ |
| 966 | static void i40evf_napi_disable_all(struct i40evf_adapter *adapter) |
| 967 | { |
| 968 | int q_idx; |
| 969 | struct i40e_q_vector *q_vector; |
| 970 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 971 | |
| 972 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 973 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 974 | napi_disable(&q_vector->napi); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * i40evf_configure - set up transmit and receive data structures |
| 980 | * @adapter: board private structure |
| 981 | **/ |
| 982 | static void i40evf_configure(struct i40evf_adapter *adapter) |
| 983 | { |
| 984 | struct net_device *netdev = adapter->netdev; |
| 985 | int i; |
| 986 | |
| 987 | i40evf_set_rx_mode(netdev); |
| 988 | |
| 989 | i40evf_configure_tx(adapter); |
| 990 | i40evf_configure_rx(adapter); |
| 991 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES; |
| 992 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 993 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 994 | struct i40e_ring *ring = &adapter->rx_rings[i]; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 995 | |
Mitch Williams | b163098 | 2016-04-18 11:33:48 -0700 | [diff] [blame] | 996 | i40evf_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * i40evf_up_complete - Finish the last steps of bringing up a connection |
| 1002 | * @adapter: board private structure |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 1003 | * |
| 1004 | * Expects to be called while holding the __I40EVF_IN_CRITICAL_TASK bit lock. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1005 | **/ |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 1006 | static void i40evf_up_complete(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1007 | { |
| 1008 | adapter->state = __I40EVF_RUNNING; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1009 | clear_bit(__I40E_VSI_DOWN, adapter->vsi.state); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1010 | |
| 1011 | i40evf_napi_enable_all(adapter); |
| 1012 | |
| 1013 | adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES; |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 1014 | if (CLIENT_ENABLED(adapter)) |
| 1015 | adapter->flags |= I40EVF_FLAG_CLIENT_NEEDS_OPEN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1016 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1020 | * i40e_down - Shutdown the connection processing |
| 1021 | * @adapter: board private structure |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 1022 | * |
| 1023 | * Expects to be called while holding the __I40EVF_IN_CRITICAL_TASK bit lock. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1024 | **/ |
| 1025 | void i40evf_down(struct i40evf_adapter *adapter) |
| 1026 | { |
| 1027 | struct net_device *netdev = adapter->netdev; |
| 1028 | struct i40evf_mac_filter *f; |
| 1029 | |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 1030 | if (adapter->state <= __I40EVF_DOWN_PENDING) |
Mitch Williams | ddf0b3a | 2014-05-22 06:31:46 +0000 | [diff] [blame] | 1031 | return; |
| 1032 | |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 1033 | netif_carrier_off(netdev); |
| 1034 | netif_tx_disable(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 1035 | adapter->link_up = false; |
Mitch Williams | 748c434 | 2015-01-29 07:17:18 +0000 | [diff] [blame] | 1036 | i40evf_napi_disable_all(adapter); |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 1037 | i40evf_irq_disable(adapter); |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1038 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1039 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
| 1040 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1041 | /* remove all MAC filters */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1042 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1043 | f->remove = true; |
| 1044 | } |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1045 | /* remove all VLAN filters */ |
| 1046 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 1047 | f->remove = true; |
| 1048 | } |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1049 | |
| 1050 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
| 1051 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1052 | if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) && |
| 1053 | adapter->state != __I40EVF_RESETTING) { |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1054 | /* cancel any current operation */ |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1055 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1056 | /* Schedule operations to close down the HW. Don't wait |
| 1057 | * here for this to complete. The watchdog is still running |
| 1058 | * and it will take care of this. |
| 1059 | */ |
| 1060 | adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1061 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1062 | adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1063 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1064 | |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 1065 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * i40evf_acquire_msix_vectors - Setup the MSIX capability |
| 1070 | * @adapter: board private structure |
| 1071 | * @vectors: number of vectors to request |
| 1072 | * |
| 1073 | * Work with the OS to set up the MSIX vectors needed. |
| 1074 | * |
| 1075 | * Returns 0 on success, negative on failure |
| 1076 | **/ |
| 1077 | static int |
| 1078 | i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors) |
| 1079 | { |
| 1080 | int err, vector_threshold; |
| 1081 | |
| 1082 | /* We'll want at least 3 (vector_threshold): |
| 1083 | * 0) Other (Admin Queue and link, mostly) |
| 1084 | * 1) TxQ[0] Cleanup |
| 1085 | * 2) RxQ[0] Cleanup |
| 1086 | */ |
| 1087 | vector_threshold = MIN_MSIX_COUNT; |
| 1088 | |
| 1089 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 1090 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 1091 | * Right now, we simply care about how many we'll get; we'll |
| 1092 | * set them up later while requesting irq's. |
| 1093 | */ |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1094 | err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 1095 | vector_threshold, vectors); |
| 1096 | if (err < 0) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1097 | dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1098 | kfree(adapter->msix_entries); |
| 1099 | adapter->msix_entries = NULL; |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1100 | return err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1101 | } |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1102 | |
| 1103 | /* Adjust for only the vectors we'll use, which is minimum |
| 1104 | * of max_msix_q_vectors + NONQ_VECS, or the number of |
| 1105 | * vectors we were allocated. |
| 1106 | */ |
| 1107 | adapter->num_msix_vectors = err; |
| 1108 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * i40evf_free_queues - Free memory for all rings |
| 1113 | * @adapter: board private structure to initialize |
| 1114 | * |
| 1115 | * Free all of the memory associated with queue pairs. |
| 1116 | **/ |
| 1117 | static void i40evf_free_queues(struct i40evf_adapter *adapter) |
| 1118 | { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1119 | if (!adapter->vsi_res) |
| 1120 | return; |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1121 | adapter->num_active_queues = 0; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1122 | kfree(adapter->tx_rings); |
Mitch Williams | 1031154 | 2015-12-09 15:50:30 -0800 | [diff] [blame] | 1123 | adapter->tx_rings = NULL; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1124 | kfree(adapter->rx_rings); |
Mitch Williams | 1031154 | 2015-12-09 15:50:30 -0800 | [diff] [blame] | 1125 | adapter->rx_rings = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * i40evf_alloc_queues - Allocate memory for all rings |
| 1130 | * @adapter: board private structure to initialize |
| 1131 | * |
| 1132 | * We allocate one ring per queue at run-time since we don't know the |
| 1133 | * number of queues at compile-time. The polling_netdev array is |
| 1134 | * intended for Multiqueue, but should work fine with a single queue. |
| 1135 | **/ |
| 1136 | static int i40evf_alloc_queues(struct i40evf_adapter *adapter) |
| 1137 | { |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1138 | int i, num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1139 | |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1140 | /* If we're in reset reallocating queues we don't actually know yet for |
| 1141 | * certain the PF gave us the number of queues we asked for but we'll |
| 1142 | * assume it did. Once basic reset is finished we'll confirm once we |
| 1143 | * start negotiating config with PF. |
| 1144 | */ |
| 1145 | if (adapter->num_req_queues) |
| 1146 | num_active_queues = adapter->num_req_queues; |
| 1147 | else |
| 1148 | num_active_queues = min_t(int, |
| 1149 | adapter->vsi_res->num_queue_pairs, |
| 1150 | (int)(num_online_cpus())); |
| 1151 | |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1152 | |
| 1153 | adapter->tx_rings = kcalloc(num_active_queues, |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1154 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1155 | if (!adapter->tx_rings) |
| 1156 | goto err_out; |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1157 | adapter->rx_rings = kcalloc(num_active_queues, |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1158 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1159 | if (!adapter->rx_rings) |
| 1160 | goto err_out; |
| 1161 | |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1162 | for (i = 0; i < num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1163 | struct i40e_ring *tx_ring; |
| 1164 | struct i40e_ring *rx_ring; |
| 1165 | |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1166 | tx_ring = &adapter->tx_rings[i]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1167 | |
| 1168 | tx_ring->queue_index = i; |
| 1169 | tx_ring->netdev = adapter->netdev; |
| 1170 | tx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1171 | tx_ring->count = adapter->tx_desc_count; |
Jacob Keller | 4270255 | 2017-09-07 08:05:48 -0400 | [diff] [blame] | 1172 | tx_ring->tx_itr_setting = I40E_ITR_TX_DEF; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 1173 | if (adapter->flags & I40EVF_FLAG_WB_ON_ITR_CAPABLE) |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 1174 | tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1175 | |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1176 | rx_ring = &adapter->rx_rings[i]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1177 | rx_ring->queue_index = i; |
| 1178 | rx_ring->netdev = adapter->netdev; |
| 1179 | rx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1180 | rx_ring->count = adapter->rx_desc_count; |
Jacob Keller | 4270255 | 2017-09-07 08:05:48 -0400 | [diff] [blame] | 1181 | rx_ring->rx_itr_setting = I40E_ITR_RX_DEF; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Jacob Keller | 65c7006 | 2017-06-07 05:43:01 -0400 | [diff] [blame] | 1184 | adapter->num_active_queues = num_active_queues; |
| 1185 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1186 | return 0; |
| 1187 | |
| 1188 | err_out: |
| 1189 | i40evf_free_queues(adapter); |
| 1190 | return -ENOMEM; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported |
| 1195 | * @adapter: board private structure to initialize |
| 1196 | * |
| 1197 | * Attempt to configure the interrupts using the best available |
| 1198 | * capabilities of the hardware and the kernel. |
| 1199 | **/ |
| 1200 | static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter) |
| 1201 | { |
| 1202 | int vector, v_budget; |
| 1203 | int pairs = 0; |
| 1204 | int err = 0; |
| 1205 | |
| 1206 | if (!adapter->vsi_res) { |
| 1207 | err = -EIO; |
| 1208 | goto out; |
| 1209 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1210 | pairs = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1211 | |
Jacob Keller | 789f38c | 2017-04-19 09:25:56 -0400 | [diff] [blame] | 1212 | /* It's easy to be greedy for MSI-X vectors, but it really doesn't do |
| 1213 | * us much good if we have more vectors than CPUs. However, we already |
| 1214 | * limit the total number of queues by the number of CPUs so we do not |
| 1215 | * need any further limiting here. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1216 | */ |
Jacob Keller | 789f38c | 2017-04-19 09:25:56 -0400 | [diff] [blame] | 1217 | v_budget = min_t(int, pairs + NONQ_VECS, |
| 1218 | (int)adapter->vf_res->max_vectors); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1219 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1220 | adapter->msix_entries = kcalloc(v_budget, |
| 1221 | sizeof(struct msix_entry), GFP_KERNEL); |
| 1222 | if (!adapter->msix_entries) { |
| 1223 | err = -ENOMEM; |
| 1224 | goto out; |
| 1225 | } |
| 1226 | |
| 1227 | for (vector = 0; vector < v_budget; vector++) |
| 1228 | adapter->msix_entries[vector].entry = vector; |
| 1229 | |
Mitch Williams | 313ed2d | 2015-08-27 11:42:31 -0400 | [diff] [blame] | 1230 | err = i40evf_acquire_msix_vectors(adapter, v_budget); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1231 | |
| 1232 | out: |
Mitch Williams | e6c4cf6 | 2015-11-06 15:26:00 -0800 | [diff] [blame] | 1233 | netif_set_real_num_rx_queues(adapter->netdev, pairs); |
| 1234 | netif_set_real_num_tx_queues(adapter->netdev, pairs); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1235 | return err; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1239 | * i40e_config_rss_aq - Configure RSS keys and lut by using AQ commands |
| 1240 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1241 | * |
| 1242 | * Return 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1243 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1244 | static int i40evf_config_rss_aq(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1245 | { |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1246 | struct i40e_aqc_get_set_rss_key_data *rss_key = |
| 1247 | (struct i40e_aqc_get_set_rss_key_data *)adapter->rss_key; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1248 | struct i40e_hw *hw = &adapter->hw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1249 | int ret = 0; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1250 | |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1251 | if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1252 | /* bail because we already have a command pending */ |
Masanari Iida | e3d132d | 2015-10-16 21:14:29 +0900 | [diff] [blame] | 1253 | dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n", |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1254 | adapter->current_op); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1255 | return -EBUSY; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1258 | ret = i40evf_aq_set_rss_key(hw, adapter->vsi.id, rss_key); |
| 1259 | if (ret) { |
| 1260 | dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n", |
| 1261 | i40evf_stat_str(hw, ret), |
| 1262 | i40evf_aq_str(hw, hw->aq.asq_last_status)); |
| 1263 | return ret; |
| 1264 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1267 | ret = i40evf_aq_set_rss_lut(hw, adapter->vsi.id, false, |
| 1268 | adapter->rss_lut, adapter->rss_lut_size); |
| 1269 | if (ret) { |
| 1270 | dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n", |
| 1271 | i40evf_stat_str(hw, ret), |
| 1272 | i40evf_aq_str(hw, hw->aq.asq_last_status)); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | return ret; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1276 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | /** |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1280 | * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1281 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1282 | * |
| 1283 | * Returns 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1284 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1285 | static int i40evf_config_rss_reg(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1286 | { |
| 1287 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1288 | u32 *dw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1289 | u16 i; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1290 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1291 | dw = (u32 *)adapter->rss_key; |
| 1292 | for (i = 0; i <= adapter->rss_key_size / 4; i++) |
| 1293 | wr32(hw, I40E_VFQF_HKEY(i), dw[i]); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1294 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1295 | dw = (u32 *)adapter->rss_lut; |
| 1296 | for (i = 0; i <= adapter->rss_lut_size / 4; i++) |
| 1297 | wr32(hw, I40E_VFQF_HLUT(i), dw[i]); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1298 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1299 | i40e_flush(hw); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * i40evf_config_rss - Configure RSS keys and lut |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1306 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1307 | * |
| 1308 | * Returns 0 on success, negative on failure |
| 1309 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1310 | int i40evf_config_rss(struct i40evf_adapter *adapter) |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1311 | { |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1312 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1313 | if (RSS_PF(adapter)) { |
| 1314 | adapter->aq_required |= I40EVF_FLAG_AQ_SET_RSS_LUT | |
| 1315 | I40EVF_FLAG_AQ_SET_RSS_KEY; |
| 1316 | return 0; |
| 1317 | } else if (RSS_AQ(adapter)) { |
| 1318 | return i40evf_config_rss_aq(adapter); |
| 1319 | } else { |
| 1320 | return i40evf_config_rss_reg(adapter); |
| 1321 | } |
Helin Zhang | 90b02b4 | 2015-10-26 19:44:33 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1325 | * i40evf_fill_rss_lut - Fill the lut with default values |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1326 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1327 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1328 | static void i40evf_fill_rss_lut(struct i40evf_adapter *adapter) |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1329 | { |
| 1330 | u16 i; |
| 1331 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1332 | for (i = 0; i < adapter->rss_lut_size; i++) |
| 1333 | adapter->rss_lut[i] = i % adapter->num_active_queues; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /** |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 1337 | * i40evf_init_rss - Prepare for RSS |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1338 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1339 | * |
| 1340 | * Return 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1341 | **/ |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1342 | static int i40evf_init_rss(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1343 | { |
| 1344 | struct i40e_hw *hw = &adapter->hw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1345 | int ret; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1346 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1347 | if (!RSS_PF(adapter)) { |
| 1348 | /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */ |
Stefan Assmann | fbb113f | 2017-06-29 15:12:24 +0200 | [diff] [blame] | 1349 | if (adapter->vf_res->vf_cap_flags & |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1350 | VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2) |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1351 | adapter->hena = I40E_DEFAULT_RSS_HENA_EXPANDED; |
| 1352 | else |
| 1353 | adapter->hena = I40E_DEFAULT_RSS_HENA; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1354 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1355 | wr32(hw, I40E_VFQF_HENA(0), (u32)adapter->hena); |
| 1356 | wr32(hw, I40E_VFQF_HENA(1), (u32)(adapter->hena >> 32)); |
| 1357 | } |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1358 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1359 | i40evf_fill_rss_lut(adapter); |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1360 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1361 | netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size); |
| 1362 | ret = i40evf_config_rss(adapter); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1363 | |
| 1364 | return ret; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1368 | * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1369 | * @adapter: board private structure to initialize |
| 1370 | * |
| 1371 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1372 | * return -ENOMEM. |
| 1373 | **/ |
| 1374 | static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter) |
| 1375 | { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1376 | int q_idx = 0, num_q_vectors; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1377 | struct i40e_q_vector *q_vector; |
| 1378 | |
| 1379 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1380 | adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector), |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1381 | GFP_KERNEL); |
| 1382 | if (!adapter->q_vectors) |
Alan Cox | 311f23e | 2016-03-01 16:02:15 -0800 | [diff] [blame] | 1383 | return -ENOMEM; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1384 | |
| 1385 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1386 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1387 | q_vector->adapter = adapter; |
| 1388 | q_vector->vsi = &adapter->vsi; |
| 1389 | q_vector->v_idx = q_idx; |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 1390 | cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1391 | netif_napi_add(adapter->netdev, &q_vector->napi, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1392 | i40evf_napi_poll, NAPI_POLL_WEIGHT); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * i40evf_free_q_vectors - Free memory allocated for interrupt vectors |
| 1400 | * @adapter: board private structure to initialize |
| 1401 | * |
| 1402 | * This function frees the memory allocated to the q_vectors. In addition if |
| 1403 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 1404 | * to freeing the q_vector. |
| 1405 | **/ |
| 1406 | static void i40evf_free_q_vectors(struct i40evf_adapter *adapter) |
| 1407 | { |
| 1408 | int q_idx, num_q_vectors; |
| 1409 | int napi_vectors; |
| 1410 | |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame] | 1411 | if (!adapter->q_vectors) |
| 1412 | return; |
| 1413 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1414 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1415 | napi_vectors = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1416 | |
| 1417 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1418 | struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1419 | if (q_idx < napi_vectors) |
| 1420 | netif_napi_del(&q_vector->napi); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1421 | } |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1422 | kfree(adapter->q_vectors); |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame] | 1423 | adapter->q_vectors = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * i40evf_reset_interrupt_capability - Reset MSIX setup |
| 1428 | * @adapter: board private structure |
| 1429 | * |
| 1430 | **/ |
| 1431 | void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter) |
| 1432 | { |
Alan Brady | 47d2a5d | 2016-11-08 13:05:05 -0800 | [diff] [blame] | 1433 | if (!adapter->msix_entries) |
| 1434 | return; |
| 1435 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1436 | pci_disable_msix(adapter->pdev); |
| 1437 | kfree(adapter->msix_entries); |
| 1438 | adapter->msix_entries = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /** |
| 1442 | * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init |
| 1443 | * @adapter: board private structure to initialize |
| 1444 | * |
| 1445 | **/ |
| 1446 | int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter) |
| 1447 | { |
| 1448 | int err; |
| 1449 | |
Jacob Keller | 283aeaf | 2017-04-19 09:25:59 -0400 | [diff] [blame] | 1450 | err = i40evf_alloc_queues(adapter); |
| 1451 | if (err) { |
| 1452 | dev_err(&adapter->pdev->dev, |
| 1453 | "Unable to allocate memory for queues\n"); |
| 1454 | goto err_alloc_queues; |
| 1455 | } |
| 1456 | |
Jacob Keller | 62fe2a8 | 2016-07-27 12:02:33 -0700 | [diff] [blame] | 1457 | rtnl_lock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1458 | err = i40evf_set_interrupt_capability(adapter); |
Jacob Keller | 62fe2a8 | 2016-07-27 12:02:33 -0700 | [diff] [blame] | 1459 | rtnl_unlock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1460 | if (err) { |
| 1461 | dev_err(&adapter->pdev->dev, |
| 1462 | "Unable to setup interrupt capabilities\n"); |
| 1463 | goto err_set_interrupt; |
| 1464 | } |
| 1465 | |
| 1466 | err = i40evf_alloc_q_vectors(adapter); |
| 1467 | if (err) { |
| 1468 | dev_err(&adapter->pdev->dev, |
| 1469 | "Unable to allocate memory for queue vectors\n"); |
| 1470 | goto err_alloc_q_vectors; |
| 1471 | } |
| 1472 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1473 | dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1474 | (adapter->num_active_queues > 1) ? "Enabled" : "Disabled", |
| 1475 | adapter->num_active_queues); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1476 | |
| 1477 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1478 | err_alloc_q_vectors: |
| 1479 | i40evf_reset_interrupt_capability(adapter); |
| 1480 | err_set_interrupt: |
Jacob Keller | 283aeaf | 2017-04-19 09:25:59 -0400 | [diff] [blame] | 1481 | i40evf_free_queues(adapter); |
| 1482 | err_alloc_queues: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1483 | return err; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1487 | * i40evf_free_rss - Free memory used by RSS structs |
| 1488 | * @adapter: board private structure |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1489 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1490 | static void i40evf_free_rss(struct i40evf_adapter *adapter) |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1491 | { |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1492 | kfree(adapter->rss_key); |
| 1493 | adapter->rss_key = NULL; |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1494 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1495 | kfree(adapter->rss_lut); |
| 1496 | adapter->rss_lut = NULL; |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1500 | * i40evf_reinit_interrupt_scheme - Reallocate queues and vectors |
| 1501 | * @adapter: board private structure |
| 1502 | * |
| 1503 | * Returns 0 on success, negative on failure |
| 1504 | **/ |
| 1505 | static int i40evf_reinit_interrupt_scheme(struct i40evf_adapter *adapter) |
| 1506 | { |
| 1507 | struct net_device *netdev = adapter->netdev; |
| 1508 | int err; |
| 1509 | |
| 1510 | if (netif_running(netdev)) |
| 1511 | i40evf_free_traffic_irqs(adapter); |
| 1512 | i40evf_free_misc_irq(adapter); |
| 1513 | i40evf_reset_interrupt_capability(adapter); |
| 1514 | i40evf_free_q_vectors(adapter); |
| 1515 | i40evf_free_queues(adapter); |
| 1516 | |
| 1517 | err = i40evf_init_interrupt_scheme(adapter); |
| 1518 | if (err) |
| 1519 | goto err; |
| 1520 | |
| 1521 | netif_tx_stop_all_queues(netdev); |
| 1522 | |
| 1523 | err = i40evf_request_misc_irq(adapter); |
| 1524 | if (err) |
| 1525 | goto err; |
| 1526 | |
| 1527 | set_bit(__I40E_VSI_DOWN, adapter->vsi.state); |
| 1528 | |
Mitch Williams | 1b7b759 | 2017-08-22 06:57:51 -0400 | [diff] [blame] | 1529 | i40evf_map_rings_to_vectors(adapter); |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1530 | |
| 1531 | if (RSS_AQ(adapter)) |
| 1532 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS; |
| 1533 | else |
| 1534 | err = i40evf_init_rss(adapter); |
| 1535 | err: |
| 1536 | return err; |
| 1537 | } |
| 1538 | |
| 1539 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1540 | * i40evf_watchdog_timer - Periodic call-back timer |
| 1541 | * @data: pointer to adapter disguised as unsigned long |
| 1542 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 1543 | static void i40evf_watchdog_timer(struct timer_list *t) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1544 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 1545 | struct i40evf_adapter *adapter = from_timer(adapter, t, |
| 1546 | watchdog_timer); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1547 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1548 | schedule_work(&adapter->watchdog_task); |
| 1549 | /* timer will be rescheduled in watchdog task */ |
| 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * i40evf_watchdog_task - Periodic call-back task |
| 1554 | * @work: pointer to work_struct |
| 1555 | **/ |
| 1556 | static void i40evf_watchdog_task(struct work_struct *work) |
| 1557 | { |
| 1558 | struct i40evf_adapter *adapter = container_of(work, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1559 | struct i40evf_adapter, |
| 1560 | watchdog_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1561 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1562 | u32 reg_val; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1563 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1564 | if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section)) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1565 | goto restart_watchdog; |
| 1566 | |
| 1567 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1568 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1569 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1570 | if ((reg_val == VIRTCHNL_VFR_VFACTIVE) || |
| 1571 | (reg_val == VIRTCHNL_VFR_COMPLETED)) { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1572 | /* A chance for redemption! */ |
| 1573 | dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n"); |
| 1574 | adapter->state = __I40EVF_STARTUP; |
| 1575 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 1576 | schedule_delayed_work(&adapter->init_task, 10); |
| 1577 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1578 | &adapter->crit_section); |
| 1579 | /* Don't reschedule the watchdog, since we've restarted |
| 1580 | * the init task. When init_task contacts the PF and |
| 1581 | * gets everything set up again, it'll restart the |
| 1582 | * watchdog for us. Down, boy. Sit. Stay. Woof. |
| 1583 | */ |
| 1584 | return; |
| 1585 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1586 | adapter->aq_required = 0; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1587 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1588 | goto watchdog_done; |
| 1589 | } |
| 1590 | |
| 1591 | if ((adapter->state < __I40EVF_DOWN) || |
| 1592 | (adapter->flags & I40EVF_FLAG_RESET_PENDING)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1593 | goto watchdog_done; |
| 1594 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1595 | /* check for reset */ |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1596 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK; |
| 1597 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1598 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1599 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1600 | dev_err(&adapter->pdev->dev, "Hardware reset detected\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1601 | schedule_work(&adapter->reset_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1602 | adapter->aq_required = 0; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1603 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1604 | goto watchdog_done; |
| 1605 | } |
| 1606 | |
| 1607 | /* Process admin queue tasks. After init, everything gets done |
| 1608 | * here so we don't race on the admin queue. |
| 1609 | */ |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 1610 | if (adapter->current_op) { |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1611 | if (!i40evf_asq_done(hw)) { |
| 1612 | dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n"); |
| 1613 | i40evf_send_api_ver(adapter); |
| 1614 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1615 | goto watchdog_done; |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1616 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1617 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) { |
| 1618 | i40evf_send_vf_config_msg(adapter); |
| 1619 | goto watchdog_done; |
| 1620 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1621 | |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1622 | if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) { |
| 1623 | i40evf_disable_queues(adapter); |
| 1624 | goto watchdog_done; |
| 1625 | } |
| 1626 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1627 | if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) { |
| 1628 | i40evf_map_queues(adapter); |
| 1629 | goto watchdog_done; |
| 1630 | } |
| 1631 | |
| 1632 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) { |
| 1633 | i40evf_add_ether_addrs(adapter); |
| 1634 | goto watchdog_done; |
| 1635 | } |
| 1636 | |
| 1637 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) { |
| 1638 | i40evf_add_vlans(adapter); |
| 1639 | goto watchdog_done; |
| 1640 | } |
| 1641 | |
| 1642 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) { |
| 1643 | i40evf_del_ether_addrs(adapter); |
| 1644 | goto watchdog_done; |
| 1645 | } |
| 1646 | |
| 1647 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) { |
| 1648 | i40evf_del_vlans(adapter); |
| 1649 | goto watchdog_done; |
| 1650 | } |
| 1651 | |
Mariusz Stachura | 8774370 | 2017-07-17 22:09:45 -0700 | [diff] [blame] | 1652 | if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING) { |
| 1653 | i40evf_enable_vlan_stripping(adapter); |
| 1654 | goto watchdog_done; |
| 1655 | } |
| 1656 | |
| 1657 | if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING) { |
| 1658 | i40evf_disable_vlan_stripping(adapter); |
| 1659 | goto watchdog_done; |
| 1660 | } |
| 1661 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1662 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) { |
| 1663 | i40evf_configure_queues(adapter); |
| 1664 | goto watchdog_done; |
| 1665 | } |
| 1666 | |
| 1667 | if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) { |
| 1668 | i40evf_enable_queues(adapter); |
| 1669 | goto watchdog_done; |
| 1670 | } |
| 1671 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1672 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) { |
| 1673 | /* This message goes straight to the firmware, not the |
| 1674 | * PF, so we don't have to set current_op as we will |
| 1675 | * not get a response through the ARQ. |
| 1676 | */ |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 1677 | i40evf_init_rss(adapter); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1678 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS; |
| 1679 | goto watchdog_done; |
| 1680 | } |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1681 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_HENA) { |
| 1682 | i40evf_get_hena(adapter); |
| 1683 | goto watchdog_done; |
| 1684 | } |
| 1685 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_HENA) { |
| 1686 | i40evf_set_hena(adapter); |
| 1687 | goto watchdog_done; |
| 1688 | } |
| 1689 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_KEY) { |
| 1690 | i40evf_set_rss_key(adapter); |
| 1691 | goto watchdog_done; |
| 1692 | } |
| 1693 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_LUT) { |
| 1694 | i40evf_set_rss_lut(adapter); |
| 1695 | goto watchdog_done; |
| 1696 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1697 | |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1698 | if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_PROMISC) { |
Jesse Brandeburg | ff3f4cc | 2017-05-11 11:23:16 -0700 | [diff] [blame] | 1699 | i40evf_set_promiscuous(adapter, FLAG_VF_UNICAST_PROMISC | |
| 1700 | FLAG_VF_MULTICAST_PROMISC); |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1701 | goto watchdog_done; |
| 1702 | } |
| 1703 | |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 1704 | if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_ALLMULTI) { |
Jesse Brandeburg | ff3f4cc | 2017-05-11 11:23:16 -0700 | [diff] [blame] | 1705 | i40evf_set_promiscuous(adapter, FLAG_VF_MULTICAST_PROMISC); |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 1706 | goto watchdog_done; |
| 1707 | } |
| 1708 | |
| 1709 | if ((adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_PROMISC) && |
| 1710 | (adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_ALLMULTI)) { |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1711 | i40evf_set_promiscuous(adapter, 0); |
| 1712 | goto watchdog_done; |
| 1713 | } |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 1714 | schedule_delayed_work(&adapter->client_task, msecs_to_jiffies(5)); |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1715 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1716 | if (adapter->state == __I40EVF_RUNNING) |
| 1717 | i40evf_request_stats(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1718 | watchdog_done: |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1719 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 1720 | restart_watchdog: |
Ashish Shah | d3e2edb | 2014-08-01 13:27:12 -0700 | [diff] [blame] | 1721 | if (adapter->state == __I40EVF_REMOVE) |
| 1722 | return; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1723 | if (adapter->aq_required) |
| 1724 | mod_timer(&adapter->watchdog_timer, |
| 1725 | jiffies + msecs_to_jiffies(20)); |
| 1726 | else |
| 1727 | mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1728 | schedule_work(&adapter->adminq_task); |
| 1729 | } |
| 1730 | |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1731 | static void i40evf_disable_vf(struct i40evf_adapter *adapter) |
| 1732 | { |
| 1733 | struct i40evf_mac_filter *f, *ftmp; |
| 1734 | struct i40evf_vlan_filter *fv, *fvtmp; |
| 1735 | |
| 1736 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
| 1737 | |
Jacob Keller | 44b034b | 2017-10-27 11:06:49 -0400 | [diff] [blame] | 1738 | /* We don't use netif_running() because it may be true prior to |
| 1739 | * ndo_open() returning, so we can't assume it means all our open |
| 1740 | * tasks have finished, since we're not holding the rtnl_lock here. |
| 1741 | */ |
| 1742 | if (adapter->state == __I40EVF_RUNNING) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1743 | set_bit(__I40E_VSI_DOWN, adapter->vsi.state); |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1744 | netif_carrier_off(adapter->netdev); |
| 1745 | netif_tx_disable(adapter->netdev); |
| 1746 | adapter->link_up = false; |
| 1747 | i40evf_napi_disable_all(adapter); |
| 1748 | i40evf_irq_disable(adapter); |
| 1749 | i40evf_free_traffic_irqs(adapter); |
| 1750 | i40evf_free_all_tx_resources(adapter); |
| 1751 | i40evf_free_all_rx_resources(adapter); |
| 1752 | } |
| 1753 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1754 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
| 1755 | |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1756 | /* Delete all of the filters, both MAC and VLAN. */ |
| 1757 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 1758 | list_del(&f->list); |
| 1759 | kfree(f); |
| 1760 | } |
| 1761 | |
| 1762 | list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, list) { |
| 1763 | list_del(&fv->list); |
| 1764 | kfree(fv); |
| 1765 | } |
| 1766 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1767 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
| 1768 | |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1769 | i40evf_free_misc_irq(adapter); |
| 1770 | i40evf_reset_interrupt_capability(adapter); |
| 1771 | i40evf_free_queues(adapter); |
| 1772 | i40evf_free_q_vectors(adapter); |
| 1773 | kfree(adapter->vf_res); |
| 1774 | i40evf_shutdown_adminq(&adapter->hw); |
| 1775 | adapter->netdev->flags &= ~IFF_UP; |
| 1776 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 1777 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1778 | adapter->state = __I40EVF_DOWN; |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 1779 | wake_up(&adapter->down_waitqueue); |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1780 | dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n"); |
| 1781 | } |
| 1782 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1783 | #define I40EVF_RESET_WAIT_MS 10 |
| 1784 | #define I40EVF_RESET_WAIT_COUNT 500 |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1785 | /** |
| 1786 | * i40evf_reset_task - Call-back task to handle hardware reset |
| 1787 | * @work: pointer to work_struct |
| 1788 | * |
| 1789 | * During reset we need to shut down and reinitialize the admin queue |
| 1790 | * before we can use it to communicate with the PF again. We also clear |
| 1791 | * and reinit the rings because that context is lost as well. |
| 1792 | **/ |
| 1793 | static void i40evf_reset_task(struct work_struct *work) |
| 1794 | { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1795 | struct i40evf_adapter *adapter = container_of(work, |
| 1796 | struct i40evf_adapter, |
| 1797 | reset_task); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1798 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1799 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 40d0136 | 2015-10-01 14:37:37 -0400 | [diff] [blame] | 1800 | struct i40evf_vlan_filter *vlf; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1801 | struct i40evf_mac_filter *f; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1802 | u32 reg_val; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1803 | int i = 0, err; |
Jacob Keller | 44b034b | 2017-10-27 11:06:49 -0400 | [diff] [blame] | 1804 | bool running; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1805 | |
Avinash Dayanand | 06aa040 | 2017-12-18 05:16:43 -0500 | [diff] [blame] | 1806 | /* When device is being removed it doesn't make sense to run the reset |
| 1807 | * task, just return in such a case. |
| 1808 | */ |
| 1809 | if (test_bit(__I40EVF_IN_REMOVE_TASK, &adapter->crit_section)) |
| 1810 | return; |
| 1811 | |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 1812 | while (test_and_set_bit(__I40EVF_IN_CLIENT_TASK, |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1813 | &adapter->crit_section)) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 1814 | usleep_range(500, 1000); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 1815 | if (CLIENT_ENABLED(adapter)) { |
| 1816 | adapter->flags &= ~(I40EVF_FLAG_CLIENT_NEEDS_OPEN | |
| 1817 | I40EVF_FLAG_CLIENT_NEEDS_CLOSE | |
| 1818 | I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS | |
| 1819 | I40EVF_FLAG_SERVICE_CLIENT_REQUESTED); |
| 1820 | cancel_delayed_work_sync(&adapter->client_task); |
| 1821 | i40evf_notify_client_close(&adapter->vsi, true); |
| 1822 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1823 | i40evf_misc_irq_disable(adapter); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1824 | if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1825 | adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED; |
| 1826 | /* Restart the AQ here. If we have been reset but didn't |
| 1827 | * detect it, or if the PF had to reinit, our AQ will be hosed. |
| 1828 | */ |
| 1829 | i40evf_shutdown_adminq(hw); |
| 1830 | i40evf_init_adminq(hw); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1831 | i40evf_request_reset(adapter); |
| 1832 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1833 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1834 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1835 | /* poll until we see the reset actually happen */ |
| 1836 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1837 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & |
| 1838 | I40E_VF_ARQLEN1_ARQENABLE_MASK; |
| 1839 | if (!reg_val) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1840 | break; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1841 | usleep_range(5000, 10000); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1842 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1843 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1844 | dev_info(&adapter->pdev->dev, "Never saw reset\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1845 | goto continue_reset; /* act like the reset happened */ |
| 1846 | } |
| 1847 | |
| 1848 | /* wait until the reset is complete and the PF is responding to us */ |
| 1849 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1850 | /* sleep first to make sure a minimum wait time is met */ |
| 1851 | msleep(I40EVF_RESET_WAIT_MS); |
| 1852 | |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1853 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1854 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1855 | if (reg_val == VIRTCHNL_VFR_VFACTIVE) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1856 | break; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1857 | } |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1858 | |
Mitch Williams | 509a447 | 2015-12-23 12:05:52 -0800 | [diff] [blame] | 1859 | pci_set_master(adapter->pdev); |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1860 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1861 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1862 | dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1863 | reg_val); |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1864 | i40evf_disable_vf(adapter); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 1865 | clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1866 | return; /* Do not attempt to reinit. It's dead, Jim. */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1867 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1868 | |
| 1869 | continue_reset: |
Jacob Keller | 44b034b | 2017-10-27 11:06:49 -0400 | [diff] [blame] | 1870 | /* We don't use netif_running() because it may be true prior to |
| 1871 | * ndo_open() returning, so we can't assume it means all our open |
| 1872 | * tasks have finished, since we're not holding the rtnl_lock here. |
| 1873 | */ |
| 1874 | running = (adapter->state == __I40EVF_RUNNING); |
| 1875 | |
| 1876 | if (running) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1877 | netif_carrier_off(netdev); |
| 1878 | netif_tx_stop_all_queues(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 1879 | adapter->link_up = false; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1880 | i40evf_napi_disable_all(adapter); |
| 1881 | } |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1882 | i40evf_irq_disable(adapter); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1883 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1884 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1885 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1886 | |
| 1887 | /* free the Tx/Rx rings and descriptors, might be better to just |
| 1888 | * re-use them sometime in the future |
| 1889 | */ |
| 1890 | i40evf_free_all_rx_resources(adapter); |
| 1891 | i40evf_free_all_tx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1892 | |
| 1893 | /* kill and reinit the admin queue */ |
Lihong Yang | 903e683 | 2016-09-06 18:05:05 -0700 | [diff] [blame] | 1894 | i40evf_shutdown_adminq(hw); |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 1895 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1896 | err = i40evf_init_adminq(hw); |
| 1897 | if (err) |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1898 | dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n", |
| 1899 | err); |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1900 | adapter->aq_required = 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1901 | |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1902 | if (adapter->flags & I40EVF_FLAG_REINIT_ITR_NEEDED) { |
| 1903 | err = i40evf_reinit_interrupt_scheme(adapter); |
| 1904 | if (err) |
| 1905 | goto reset_err; |
| 1906 | } |
| 1907 | |
| 1908 | adapter->aq_required |= I40EVF_FLAG_AQ_GET_CONFIG; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1909 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1910 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1911 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
| 1912 | |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1913 | /* re-add all MAC filters */ |
| 1914 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1915 | f->add = true; |
| 1916 | } |
| 1917 | /* re-add all VLAN filters */ |
Mitch Williams | 40d0136 | 2015-10-01 14:37:37 -0400 | [diff] [blame] | 1918 | list_for_each_entry(vlf, &adapter->vlan_filter_list, list) { |
| 1919 | vlf->add = true; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1920 | } |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 1921 | |
| 1922 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
| 1923 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1924 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1925 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1926 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1927 | |
| 1928 | mod_timer(&adapter->watchdog_timer, jiffies + 2); |
| 1929 | |
Jacob Keller | 44b034b | 2017-10-27 11:06:49 -0400 | [diff] [blame] | 1930 | /* We were running when the reset started, so we need to restore some |
| 1931 | * state here. |
| 1932 | */ |
| 1933 | if (running) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1934 | /* allocate transmit descriptors */ |
| 1935 | err = i40evf_setup_all_tx_resources(adapter); |
| 1936 | if (err) |
| 1937 | goto reset_err; |
| 1938 | |
| 1939 | /* allocate receive descriptors */ |
| 1940 | err = i40evf_setup_all_rx_resources(adapter); |
| 1941 | if (err) |
| 1942 | goto reset_err; |
| 1943 | |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 1944 | if (adapter->flags & I40EVF_FLAG_REINIT_ITR_NEEDED) { |
| 1945 | err = i40evf_request_traffic_irqs(adapter, |
| 1946 | netdev->name); |
| 1947 | if (err) |
| 1948 | goto reset_err; |
| 1949 | |
| 1950 | adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED; |
| 1951 | } |
| 1952 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1953 | i40evf_configure(adapter); |
| 1954 | |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 1955 | i40evf_up_complete(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1956 | |
| 1957 | i40evf_irq_enable(adapter, true); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1958 | } else { |
| 1959 | adapter->state = __I40EVF_DOWN; |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 1960 | wake_up(&adapter->down_waitqueue); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1961 | } |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 1962 | clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section); |
| 1963 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1964 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1965 | return; |
| 1966 | reset_err: |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 1967 | clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section); |
| 1968 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1969 | dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); |
Alan Brady | f0db789 | 2017-07-12 05:46:04 -0400 | [diff] [blame] | 1970 | i40evf_close(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * i40evf_adminq_task - worker thread to clean the admin queue |
| 1975 | * @work: pointer to work_struct containing our data |
| 1976 | **/ |
| 1977 | static void i40evf_adminq_task(struct work_struct *work) |
| 1978 | { |
| 1979 | struct i40evf_adapter *adapter = |
| 1980 | container_of(work, struct i40evf_adapter, adminq_task); |
| 1981 | struct i40e_hw *hw = &adapter->hw; |
| 1982 | struct i40e_arq_event_info event; |
Tushar Dave | c969ef4 | 2017-06-22 09:44:32 -0700 | [diff] [blame] | 1983 | enum virtchnl_ops v_op; |
| 1984 | i40e_status ret, v_ret; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1985 | u32 val, oldval; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1986 | u16 pending; |
| 1987 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1988 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1989 | goto out; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1990 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 1991 | event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; |
| 1992 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1993 | if (!event.msg_buf) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1994 | goto out; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1995 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1996 | do { |
| 1997 | ret = i40evf_clean_arq_element(hw, &event, &pending); |
Tushar Dave | c969ef4 | 2017-06-22 09:44:32 -0700 | [diff] [blame] | 1998 | v_op = (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); |
| 1999 | v_ret = (i40e_status)le32_to_cpu(event.desc.cookie_low); |
| 2000 | |
| 2001 | if (ret || !v_op) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2002 | break; /* No event to process or error cleaning ARQ */ |
| 2003 | |
Tushar Dave | c969ef4 | 2017-06-22 09:44:32 -0700 | [diff] [blame] | 2004 | i40evf_virtchnl_completion(adapter, v_op, v_ret, event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 2005 | event.msg_len); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2006 | if (pending != 0) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2007 | memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2008 | } while (pending); |
| 2009 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 2010 | if ((adapter->flags & |
| 2011 | (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) || |
| 2012 | adapter->state == __I40EVF_RESETTING) |
| 2013 | goto freedom; |
| 2014 | |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2015 | /* check for error indications */ |
| 2016 | val = rd32(hw, hw->aq.arq.len); |
Mitch Williams | 19b73d8 | 2016-03-10 14:59:49 -0800 | [diff] [blame] | 2017 | if (val == 0xdeadbeef) /* indicates device in reset */ |
| 2018 | goto freedom; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2019 | oldval = val; |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2020 | if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2021 | dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2022 | val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2023 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2024 | if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2025 | dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2026 | val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2027 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2028 | if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2029 | dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2030 | val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2031 | } |
| 2032 | if (oldval != val) |
| 2033 | wr32(hw, hw->aq.arq.len, val); |
| 2034 | |
| 2035 | val = rd32(hw, hw->aq.asq.len); |
| 2036 | oldval = val; |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2037 | if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2038 | dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2039 | val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2040 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2041 | if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2042 | dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2043 | val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2044 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2045 | if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2046 | dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 2047 | val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 2048 | } |
| 2049 | if (oldval != val) |
| 2050 | wr32(hw, hw->aq.asq.len, val); |
| 2051 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 2052 | freedom: |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 2053 | kfree(event.msg_buf); |
| 2054 | out: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2055 | /* re-enable Admin queue interrupt cause */ |
| 2056 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | /** |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2060 | * i40evf_client_task - worker thread to perform client work |
| 2061 | * @work: pointer to work_struct containing our data |
| 2062 | * |
| 2063 | * This task handles client interactions. Because client calls can be |
| 2064 | * reentrant, we can't handle them in the watchdog. |
| 2065 | **/ |
| 2066 | static void i40evf_client_task(struct work_struct *work) |
| 2067 | { |
| 2068 | struct i40evf_adapter *adapter = |
| 2069 | container_of(work, struct i40evf_adapter, client_task.work); |
| 2070 | |
| 2071 | /* If we can't get the client bit, just give up. We'll be rescheduled |
| 2072 | * later. |
| 2073 | */ |
| 2074 | |
| 2075 | if (test_and_set_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section)) |
| 2076 | return; |
| 2077 | |
| 2078 | if (adapter->flags & I40EVF_FLAG_SERVICE_CLIENT_REQUESTED) { |
| 2079 | i40evf_client_subtask(adapter); |
| 2080 | adapter->flags &= ~I40EVF_FLAG_SERVICE_CLIENT_REQUESTED; |
| 2081 | goto out; |
| 2082 | } |
Alan Brady | 01acc73 | 2017-11-14 07:00:51 -0500 | [diff] [blame] | 2083 | if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS) { |
| 2084 | i40evf_notify_client_l2_params(&adapter->vsi); |
| 2085 | adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS; |
| 2086 | goto out; |
| 2087 | } |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2088 | if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_CLOSE) { |
| 2089 | i40evf_notify_client_close(&adapter->vsi, false); |
| 2090 | adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_CLOSE; |
| 2091 | goto out; |
| 2092 | } |
| 2093 | if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_OPEN) { |
| 2094 | i40evf_notify_client_open(&adapter->vsi); |
| 2095 | adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_OPEN; |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2096 | } |
| 2097 | out: |
| 2098 | clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section); |
| 2099 | } |
| 2100 | |
| 2101 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2102 | * i40evf_free_all_tx_resources - Free Tx Resources for All Queues |
| 2103 | * @adapter: board private structure |
| 2104 | * |
| 2105 | * Free all transmit software resources |
| 2106 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 2107 | void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2108 | { |
| 2109 | int i; |
| 2110 | |
Mitch Williams | fdb47ae | 2015-11-19 11:34:18 -0800 | [diff] [blame] | 2111 | if (!adapter->tx_rings) |
| 2112 | return; |
| 2113 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2114 | for (i = 0; i < adapter->num_active_queues; i++) |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2115 | if (adapter->tx_rings[i].desc) |
| 2116 | i40evf_free_tx_resources(&adapter->tx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /** |
| 2120 | * i40evf_setup_all_tx_resources - allocate all queues Tx resources |
| 2121 | * @adapter: board private structure |
| 2122 | * |
| 2123 | * If this function returns with an error, then it's possible one or |
| 2124 | * more of the rings is populated (while the rest are not). It is the |
| 2125 | * callers duty to clean those orphaned rings. |
| 2126 | * |
| 2127 | * Return 0 on success, negative on failure |
| 2128 | **/ |
| 2129 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter) |
| 2130 | { |
| 2131 | int i, err = 0; |
| 2132 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2133 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2134 | adapter->tx_rings[i].count = adapter->tx_desc_count; |
| 2135 | err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2136 | if (!err) |
| 2137 | continue; |
| 2138 | dev_err(&adapter->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 2139 | "Allocation for Tx Queue %u failed\n", i); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2140 | break; |
| 2141 | } |
| 2142 | |
| 2143 | return err; |
| 2144 | } |
| 2145 | |
| 2146 | /** |
| 2147 | * i40evf_setup_all_rx_resources - allocate all queues Rx resources |
| 2148 | * @adapter: board private structure |
| 2149 | * |
| 2150 | * If this function returns with an error, then it's possible one or |
| 2151 | * more of the rings is populated (while the rest are not). It is the |
| 2152 | * callers duty to clean those orphaned rings. |
| 2153 | * |
| 2154 | * Return 0 on success, negative on failure |
| 2155 | **/ |
| 2156 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter) |
| 2157 | { |
| 2158 | int i, err = 0; |
| 2159 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2160 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2161 | adapter->rx_rings[i].count = adapter->rx_desc_count; |
| 2162 | err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2163 | if (!err) |
| 2164 | continue; |
| 2165 | dev_err(&adapter->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 2166 | "Allocation for Rx Queue %u failed\n", i); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | } |
| 2169 | return err; |
| 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * i40evf_free_all_rx_resources - Free Rx Resources for All Queues |
| 2174 | * @adapter: board private structure |
| 2175 | * |
| 2176 | * Free all receive software resources |
| 2177 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 2178 | void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2179 | { |
| 2180 | int i; |
| 2181 | |
Mitch Williams | fdb47ae | 2015-11-19 11:34:18 -0800 | [diff] [blame] | 2182 | if (!adapter->rx_rings) |
| 2183 | return; |
| 2184 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2185 | for (i = 0; i < adapter->num_active_queues; i++) |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2186 | if (adapter->rx_rings[i].desc) |
| 2187 | i40evf_free_rx_resources(&adapter->rx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | /** |
| 2191 | * i40evf_open - Called when a network interface is made active |
| 2192 | * @netdev: network interface device structure |
| 2193 | * |
| 2194 | * Returns 0 on success, negative value on failure |
| 2195 | * |
| 2196 | * The open entry point is called when a network interface is made |
| 2197 | * active by the system (IFF_UP). At this point all resources needed |
| 2198 | * for transmit and receive operations are allocated, the interrupt |
| 2199 | * handler is registered with the OS, the watchdog timer is started, |
| 2200 | * and the stack is notified that the interface is ready. |
| 2201 | **/ |
| 2202 | static int i40evf_open(struct net_device *netdev) |
| 2203 | { |
| 2204 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2205 | int err; |
| 2206 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2207 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
| 2208 | dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); |
| 2209 | return -EIO; |
| 2210 | } |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2211 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2212 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 2213 | &adapter->crit_section)) |
| 2214 | usleep_range(500, 1000); |
| 2215 | |
| 2216 | if (adapter->state != __I40EVF_DOWN) { |
| 2217 | err = -EBUSY; |
| 2218 | goto err_unlock; |
| 2219 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2220 | |
| 2221 | /* allocate transmit descriptors */ |
| 2222 | err = i40evf_setup_all_tx_resources(adapter); |
| 2223 | if (err) |
| 2224 | goto err_setup_tx; |
| 2225 | |
| 2226 | /* allocate receive descriptors */ |
| 2227 | err = i40evf_setup_all_rx_resources(adapter); |
| 2228 | if (err) |
| 2229 | goto err_setup_rx; |
| 2230 | |
| 2231 | /* clear any pending interrupts, may auto mask */ |
| 2232 | err = i40evf_request_traffic_irqs(adapter, netdev->name); |
| 2233 | if (err) |
| 2234 | goto err_req_irq; |
| 2235 | |
Mitch Williams | 44151cd | 2015-04-27 14:57:17 -0400 | [diff] [blame] | 2236 | i40evf_add_filter(adapter, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2237 | i40evf_configure(adapter); |
| 2238 | |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 2239 | i40evf_up_complete(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2240 | |
| 2241 | i40evf_irq_enable(adapter, true); |
| 2242 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2243 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 2244 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2245 | return 0; |
| 2246 | |
| 2247 | err_req_irq: |
| 2248 | i40evf_down(adapter); |
| 2249 | i40evf_free_traffic_irqs(adapter); |
| 2250 | err_setup_rx: |
| 2251 | i40evf_free_all_rx_resources(adapter); |
| 2252 | err_setup_tx: |
| 2253 | i40evf_free_all_tx_resources(adapter); |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2254 | err_unlock: |
| 2255 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2256 | |
| 2257 | return err; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
| 2261 | * i40evf_close - Disables a network interface |
| 2262 | * @netdev: network interface device structure |
| 2263 | * |
| 2264 | * Returns 0, this is not allowed to fail |
| 2265 | * |
| 2266 | * The close entry point is called when an interface is de-activated |
| 2267 | * by the OS. The hardware is still under the drivers control, but |
| 2268 | * needs to be disabled. All IRQs except vector 0 (reserved for admin queue) |
| 2269 | * are freed, along with all transmit and receive resources. |
| 2270 | **/ |
| 2271 | static int i40evf_close(struct net_device *netdev) |
| 2272 | { |
| 2273 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 2274 | int status; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2275 | |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2276 | if (adapter->state <= __I40EVF_DOWN_PENDING) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2277 | return 0; |
| 2278 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2279 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 2280 | &adapter->crit_section)) |
| 2281 | usleep_range(500, 1000); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2282 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2283 | set_bit(__I40E_VSI_DOWN, adapter->vsi.state); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2284 | if (CLIENT_ENABLED(adapter)) |
| 2285 | adapter->flags |= I40EVF_FLAG_CLIENT_NEEDS_CLOSE; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2286 | |
| 2287 | i40evf_down(adapter); |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2288 | adapter->state = __I40EVF_DOWN_PENDING; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2289 | i40evf_free_traffic_irqs(adapter); |
| 2290 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2291 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 2292 | |
Mitch Williams | 51f3826 | 2016-12-12 15:44:11 -0800 | [diff] [blame] | 2293 | /* We explicitly don't free resources here because the hardware is |
| 2294 | * still active and can DMA into memory. Resources are cleared in |
| 2295 | * i40evf_virtchnl_completion() after we get confirmation from the PF |
| 2296 | * driver that the rings have been stopped. |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 2297 | * |
| 2298 | * Also, we wait for state to transition to __I40EVF_DOWN before |
| 2299 | * returning. State change occurs in i40evf_virtchnl_completion() after |
| 2300 | * VF resources are released (which occurs after PF driver processes and |
| 2301 | * responds to admin queue commands). |
Mitch Williams | 51f3826 | 2016-12-12 15:44:11 -0800 | [diff] [blame] | 2302 | */ |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 2303 | |
| 2304 | status = wait_event_timeout(adapter->down_waitqueue, |
| 2305 | adapter->state == __I40EVF_DOWN, |
| 2306 | msecs_to_jiffies(200)); |
| 2307 | if (!status) |
| 2308 | netdev_warn(netdev, "Device resources not yet released\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2313 | * i40evf_change_mtu - Change the Maximum Transfer Unit |
| 2314 | * @netdev: network interface device structure |
| 2315 | * @new_mtu: new value for maximum frame size |
| 2316 | * |
| 2317 | * Returns 0 on success, negative on failure |
| 2318 | **/ |
| 2319 | static int i40evf_change_mtu(struct net_device *netdev, int new_mtu) |
| 2320 | { |
| 2321 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2322 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2323 | netdev->mtu = new_mtu; |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2324 | if (CLIENT_ENABLED(adapter)) { |
| 2325 | i40evf_notify_client_l2_params(&adapter->vsi); |
| 2326 | adapter->flags |= I40EVF_FLAG_SERVICE_CLIENT_REQUESTED; |
| 2327 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 2328 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
| 2329 | schedule_work(&adapter->reset_task); |
| 2330 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2331 | return 0; |
| 2332 | } |
| 2333 | |
Alexander Duyck | 06fc016 | 2016-10-25 16:08:47 -0700 | [diff] [blame] | 2334 | /** |
Mariusz Stachura | 8774370 | 2017-07-17 22:09:45 -0700 | [diff] [blame] | 2335 | * i40e_set_features - set the netdev feature flags |
| 2336 | * @netdev: ptr to the netdev being adjusted |
| 2337 | * @features: the feature set that the stack is suggesting |
| 2338 | * Note: expects to be called while under rtnl_lock() |
| 2339 | **/ |
| 2340 | static int i40evf_set_features(struct net_device *netdev, |
| 2341 | netdev_features_t features) |
| 2342 | { |
| 2343 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2344 | |
| 2345 | if (!VLAN_ALLOWED(adapter)) |
| 2346 | return -EINVAL; |
| 2347 | |
| 2348 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2349 | adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; |
| 2350 | else |
| 2351 | adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; |
| 2352 | |
| 2353 | return 0; |
| 2354 | } |
| 2355 | |
| 2356 | /** |
Alexander Duyck | 06fc016 | 2016-10-25 16:08:47 -0700 | [diff] [blame] | 2357 | * i40evf_features_check - Validate encapsulated packet conforms to limits |
| 2358 | * @skb: skb buff |
| 2359 | * @netdev: This physical port's netdev |
| 2360 | * @features: Offload features that the stack believes apply |
| 2361 | **/ |
| 2362 | static netdev_features_t i40evf_features_check(struct sk_buff *skb, |
| 2363 | struct net_device *dev, |
| 2364 | netdev_features_t features) |
| 2365 | { |
| 2366 | size_t len; |
| 2367 | |
| 2368 | /* No point in doing any of this if neither checksum nor GSO are |
| 2369 | * being requested for this frame. We can rule out both by just |
| 2370 | * checking for CHECKSUM_PARTIAL |
| 2371 | */ |
| 2372 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 2373 | return features; |
| 2374 | |
| 2375 | /* We cannot support GSO if the MSS is going to be less than |
| 2376 | * 64 bytes. If it is then we need to drop support for GSO. |
| 2377 | */ |
| 2378 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 2379 | features &= ~NETIF_F_GSO_MASK; |
| 2380 | |
| 2381 | /* MACLEN can support at most 63 words */ |
| 2382 | len = skb_network_header(skb) - skb->data; |
| 2383 | if (len & ~(63 * 2)) |
| 2384 | goto out_err; |
| 2385 | |
| 2386 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 2387 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 2388 | if (len & ~(127 * 4)) |
| 2389 | goto out_err; |
| 2390 | |
| 2391 | if (skb->encapsulation) { |
| 2392 | /* L4TUNLEN can support 127 words */ |
| 2393 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 2394 | if (len & ~(127 * 2)) |
| 2395 | goto out_err; |
| 2396 | |
| 2397 | /* IPLEN can support at most 127 dwords */ |
| 2398 | len = skb_inner_transport_header(skb) - |
| 2399 | skb_inner_network_header(skb); |
| 2400 | if (len & ~(127 * 4)) |
| 2401 | goto out_err; |
| 2402 | } |
| 2403 | |
| 2404 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 2405 | * a flexible value and we support all possible values supported |
| 2406 | * by TCP, which is at most 15 dwords |
| 2407 | */ |
| 2408 | |
| 2409 | return features; |
| 2410 | out_err: |
| 2411 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
| 2412 | } |
| 2413 | |
Mitch Williams | c4445ae | 2016-03-18 12:18:07 -0700 | [diff] [blame] | 2414 | /** |
| 2415 | * i40evf_fix_features - fix up the netdev feature bits |
| 2416 | * @netdev: our net device |
| 2417 | * @features: desired feature bits |
| 2418 | * |
| 2419 | * Returns fixed-up features bits |
| 2420 | **/ |
| 2421 | static netdev_features_t i40evf_fix_features(struct net_device *netdev, |
| 2422 | netdev_features_t features) |
| 2423 | { |
| 2424 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2425 | |
Jacob Keller | 0a3b4f7 | 2017-08-29 05:32:41 -0400 | [diff] [blame] | 2426 | if (!(adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN)) |
| 2427 | features &= ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 2428 | NETIF_F_HW_VLAN_CTAG_RX | |
| 2429 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 2430 | |
Mitch Williams | c4445ae | 2016-03-18 12:18:07 -0700 | [diff] [blame] | 2431 | return features; |
| 2432 | } |
| 2433 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2434 | static const struct net_device_ops i40evf_netdev_ops = { |
| 2435 | .ndo_open = i40evf_open, |
| 2436 | .ndo_stop = i40evf_close, |
| 2437 | .ndo_start_xmit = i40evf_xmit_frame, |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2438 | .ndo_set_rx_mode = i40evf_set_rx_mode, |
| 2439 | .ndo_validate_addr = eth_validate_addr, |
| 2440 | .ndo_set_mac_address = i40evf_set_mac, |
| 2441 | .ndo_change_mtu = i40evf_change_mtu, |
| 2442 | .ndo_tx_timeout = i40evf_tx_timeout, |
| 2443 | .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid, |
| 2444 | .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid, |
Alexander Duyck | 06fc016 | 2016-10-25 16:08:47 -0700 | [diff] [blame] | 2445 | .ndo_features_check = i40evf_features_check, |
Mitch Williams | c4445ae | 2016-03-18 12:18:07 -0700 | [diff] [blame] | 2446 | .ndo_fix_features = i40evf_fix_features, |
Mariusz Stachura | 8774370 | 2017-07-17 22:09:45 -0700 | [diff] [blame] | 2447 | .ndo_set_features = i40evf_set_features, |
Alexander Duyck | 7709b4c | 2015-09-24 09:04:38 -0700 | [diff] [blame] | 2448 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2449 | .ndo_poll_controller = i40evf_netpoll, |
| 2450 | #endif |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2451 | }; |
| 2452 | |
| 2453 | /** |
| 2454 | * i40evf_check_reset_complete - check that VF reset is complete |
| 2455 | * @hw: pointer to hw struct |
| 2456 | * |
| 2457 | * Returns 0 if device is ready to use, or -EBUSY if it's in reset. |
| 2458 | **/ |
| 2459 | static int i40evf_check_reset_complete(struct i40e_hw *hw) |
| 2460 | { |
| 2461 | u32 rstat; |
| 2462 | int i; |
| 2463 | |
| 2464 | for (i = 0; i < 100; i++) { |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 2465 | rstat = rd32(hw, I40E_VFGEN_RSTAT) & |
| 2466 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2467 | if ((rstat == VIRTCHNL_VFR_VFACTIVE) || |
| 2468 | (rstat == VIRTCHNL_VFR_COMPLETED)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2469 | return 0; |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 2470 | usleep_range(10, 20); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2471 | } |
| 2472 | return -EBUSY; |
| 2473 | } |
| 2474 | |
| 2475 | /** |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2476 | * i40evf_process_config - Process the config information we got from the PF |
| 2477 | * @adapter: board private structure |
| 2478 | * |
| 2479 | * Verify that we have a valid config struct, and set up our netdev features |
| 2480 | * and our VSI struct. |
| 2481 | **/ |
| 2482 | int i40evf_process_config(struct i40evf_adapter *adapter) |
| 2483 | { |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2484 | struct virtchnl_vf_resource *vfres = adapter->vf_res; |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 2485 | int i, num_req_queues = adapter->num_req_queues; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2486 | struct net_device *netdev = adapter->netdev; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2487 | struct i40e_vsi *vsi = &adapter->vsi; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2488 | netdev_features_t hw_enc_features; |
| 2489 | netdev_features_t hw_features; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2490 | |
| 2491 | /* got VF config message back from PF, now we can parse it */ |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2492 | for (i = 0; i < vfres->num_vsis; i++) { |
Jesse Brandeburg | ff3f4cc | 2017-05-11 11:23:16 -0700 | [diff] [blame] | 2493 | if (vfres->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV) |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2494 | adapter->vsi_res = &vfres->vsi_res[i]; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2495 | } |
| 2496 | if (!adapter->vsi_res) { |
| 2497 | dev_err(&adapter->pdev->dev, "No LAN VSI found\n"); |
| 2498 | return -ENODEV; |
| 2499 | } |
| 2500 | |
Alan Brady | 5b36e8d | 2017-08-22 06:57:50 -0400 | [diff] [blame] | 2501 | if (num_req_queues && |
| 2502 | num_req_queues != adapter->vsi_res->num_queue_pairs) { |
| 2503 | /* Problem. The PF gave us fewer queues than what we had |
| 2504 | * negotiated in our request. Need a reset to see if we can't |
| 2505 | * get back to a working state. |
| 2506 | */ |
| 2507 | dev_err(&adapter->pdev->dev, |
| 2508 | "Requested %d queues, but PF only gave us %d.\n", |
| 2509 | num_req_queues, |
| 2510 | adapter->vsi_res->num_queue_pairs); |
| 2511 | adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED; |
| 2512 | adapter->num_req_queues = adapter->vsi_res->num_queue_pairs; |
| 2513 | i40evf_schedule_reset(adapter); |
| 2514 | return -ENODEV; |
| 2515 | } |
| 2516 | adapter->num_req_queues = 0; |
| 2517 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2518 | hw_enc_features = NETIF_F_SG | |
| 2519 | NETIF_F_IP_CSUM | |
| 2520 | NETIF_F_IPV6_CSUM | |
| 2521 | NETIF_F_HIGHDMA | |
| 2522 | NETIF_F_SOFT_FEATURES | |
| 2523 | NETIF_F_TSO | |
| 2524 | NETIF_F_TSO_ECN | |
| 2525 | NETIF_F_TSO6 | |
| 2526 | NETIF_F_SCTP_CRC | |
| 2527 | NETIF_F_RXHASH | |
| 2528 | NETIF_F_RXCSUM | |
| 2529 | 0; |
| 2530 | |
| 2531 | /* advertise to stack only if offloads for encapsulated packets is |
| 2532 | * supported |
| 2533 | */ |
Stefan Assmann | fbb113f | 2017-06-29 15:12:24 +0200 | [diff] [blame] | 2534 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ENCAP) { |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2535 | hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2536 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2537 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 2538 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 2539 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2540 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2541 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2542 | 0; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2543 | |
Stefan Assmann | fbb113f | 2017-06-29 15:12:24 +0200 | [diff] [blame] | 2544 | if (!(vfres->vf_cap_flags & |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2545 | VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)) |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2546 | netdev->gso_partial_features |= |
| 2547 | NETIF_F_GSO_UDP_TUNNEL_CSUM; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2548 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2549 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
| 2550 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
| 2551 | netdev->hw_enc_features |= hw_enc_features; |
| 2552 | } |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2553 | /* record features VLANs can make use of */ |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2554 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
Alexander Duyck | f608e6a | 2016-01-24 21:17:57 -0800 | [diff] [blame] | 2555 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2556 | /* Write features and hw_features separately to avoid polluting |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2557 | * with, or dropping, features that are set when we registered. |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2558 | */ |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2559 | hw_features = hw_enc_features; |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2560 | |
Jacob Keller | 0a3b4f7 | 2017-08-29 05:32:41 -0400 | [diff] [blame] | 2561 | /* Enable VLAN features if supported */ |
| 2562 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) |
| 2563 | hw_features |= (NETIF_F_HW_VLAN_CTAG_TX | |
| 2564 | NETIF_F_HW_VLAN_CTAG_RX); |
| 2565 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 2566 | netdev->hw_features |= hw_features; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2567 | |
Jacob Keller | 0a3b4f7 | 2017-08-29 05:32:41 -0400 | [diff] [blame] | 2568 | netdev->features |= hw_features; |
| 2569 | |
| 2570 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) |
| 2571 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2572 | |
| 2573 | adapter->vsi.id = adapter->vsi_res->vsi_id; |
| 2574 | |
| 2575 | adapter->vsi.back = adapter; |
| 2576 | adapter->vsi.base_vector = 1; |
| 2577 | adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2578 | vsi->netdev = adapter->netdev; |
| 2579 | vsi->qs_handle = adapter->vsi_res->qset_handle; |
Stefan Assmann | fbb113f | 2017-06-29 15:12:24 +0200 | [diff] [blame] | 2580 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) { |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2581 | adapter->rss_key_size = vfres->rss_key_size; |
| 2582 | adapter->rss_lut_size = vfres->rss_lut_size; |
| 2583 | } else { |
| 2584 | adapter->rss_key_size = I40EVF_HKEY_ARRAY_SIZE; |
| 2585 | adapter->rss_lut_size = I40EVF_HLUT_ARRAY_SIZE; |
| 2586 | } |
| 2587 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2592 | * i40evf_init_task - worker thread to perform delayed initialization |
| 2593 | * @work: pointer to work_struct containing our data |
| 2594 | * |
| 2595 | * This task completes the work that was begun in probe. Due to the nature |
| 2596 | * of VF-PF communications, we may need to wait tens of milliseconds to get |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2597 | * responses back from the PF. Rather than busy-wait in probe and bog down the |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2598 | * whole system, we'll do it in a task so we can sleep. |
| 2599 | * This task only runs during driver init. Once we've established |
| 2600 | * communications with the PF driver and set up our netdev, the watchdog |
| 2601 | * takes over. |
| 2602 | **/ |
| 2603 | static void i40evf_init_task(struct work_struct *work) |
| 2604 | { |
| 2605 | struct i40evf_adapter *adapter = container_of(work, |
| 2606 | struct i40evf_adapter, |
| 2607 | init_task.work); |
| 2608 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2609 | struct i40e_hw *hw = &adapter->hw; |
| 2610 | struct pci_dev *pdev = adapter->pdev; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2611 | int err, bufsz; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2612 | |
| 2613 | switch (adapter->state) { |
| 2614 | case __I40EVF_STARTUP: |
| 2615 | /* driver loaded, probe complete */ |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2616 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 2617 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2618 | err = i40e_set_mac_type(hw); |
| 2619 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2620 | dev_err(&pdev->dev, "Failed to set MAC type (%d)\n", |
| 2621 | err); |
Mitch Williams | 2619ef4 | 2015-04-07 19:45:30 -0400 | [diff] [blame] | 2622 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2623 | } |
| 2624 | err = i40evf_check_reset_complete(hw); |
| 2625 | if (err) { |
Mitch Williams | 0d9c7ea | 2014-04-23 04:50:00 +0000 | [diff] [blame] | 2626 | dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2627 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2628 | goto err; |
| 2629 | } |
| 2630 | hw->aq.num_arq_entries = I40EVF_AQ_LEN; |
| 2631 | hw->aq.num_asq_entries = I40EVF_AQ_LEN; |
| 2632 | hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2633 | hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2634 | |
| 2635 | err = i40evf_init_adminq(hw); |
| 2636 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2637 | dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n", |
| 2638 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2639 | goto err; |
| 2640 | } |
| 2641 | err = i40evf_send_api_ver(adapter); |
| 2642 | if (err) { |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2643 | dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2644 | i40evf_shutdown_adminq(hw); |
| 2645 | goto err; |
| 2646 | } |
| 2647 | adapter->state = __I40EVF_INIT_VERSION_CHECK; |
| 2648 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2649 | case __I40EVF_INIT_VERSION_CHECK: |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2650 | if (!i40evf_asq_done(hw)) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 2651 | dev_err(&pdev->dev, "Admin queue command never completed\n"); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2652 | i40evf_shutdown_adminq(hw); |
| 2653 | adapter->state = __I40EVF_STARTUP; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2654 | goto err; |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2655 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2656 | |
| 2657 | /* aq msg sent, awaiting reply */ |
| 2658 | err = i40evf_verify_api_ver(adapter); |
| 2659 | if (err) { |
Mitch A Williams | d4f82fd | 2014-12-09 08:53:03 +0000 | [diff] [blame] | 2660 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Mitch Williams | 56f9920 | 2014-06-04 04:22:41 +0000 | [diff] [blame] | 2661 | err = i40evf_send_api_ver(adapter); |
Mitch Williams | ee1693e | 2015-06-04 16:23:59 -0400 | [diff] [blame] | 2662 | else |
| 2663 | dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n", |
| 2664 | adapter->pf_version.major, |
| 2665 | adapter->pf_version.minor, |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2666 | VIRTCHNL_VERSION_MAJOR, |
| 2667 | VIRTCHNL_VERSION_MINOR); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2668 | goto err; |
| 2669 | } |
| 2670 | err = i40evf_send_vf_config_msg(adapter); |
| 2671 | if (err) { |
Mitch Williams | 3f2ab17 | 2014-06-04 04:22:40 +0000 | [diff] [blame] | 2672 | dev_err(&pdev->dev, "Unable to send config request (%d)\n", |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2673 | err); |
| 2674 | goto err; |
| 2675 | } |
| 2676 | adapter->state = __I40EVF_INIT_GET_RESOURCES; |
| 2677 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2678 | case __I40EVF_INIT_GET_RESOURCES: |
| 2679 | /* aq msg sent, awaiting reply */ |
| 2680 | if (!adapter->vf_res) { |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2681 | bufsz = sizeof(struct virtchnl_vf_resource) + |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2682 | (I40E_MAX_VF_VSI * |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2683 | sizeof(struct virtchnl_vsi_resource)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2684 | adapter->vf_res = kzalloc(bufsz, GFP_KERNEL); |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2685 | if (!adapter->vf_res) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2686 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2687 | } |
| 2688 | err = i40evf_get_vf_config(adapter); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2689 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2690 | err = i40evf_send_vf_config_msg(adapter); |
| 2691 | goto err; |
Mitch Williams | e743072 | 2015-10-26 19:44:38 -0400 | [diff] [blame] | 2692 | } else if (err == I40E_ERR_PARAM) { |
| 2693 | /* We only get ERR_PARAM if the device is in a very bad |
| 2694 | * state or if we've been disabled for previous bad |
| 2695 | * behavior. Either way, we're done now. |
| 2696 | */ |
| 2697 | i40evf_shutdown_adminq(hw); |
| 2698 | dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n"); |
| 2699 | return; |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2700 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2701 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2702 | dev_err(&pdev->dev, "Unable to get VF config (%d)\n", |
| 2703 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2704 | goto err_alloc; |
| 2705 | } |
| 2706 | adapter->state = __I40EVF_INIT_SW; |
| 2707 | break; |
| 2708 | default: |
| 2709 | goto err_alloc; |
| 2710 | } |
Alexander Duyck | f608e6a | 2016-01-24 21:17:57 -0800 | [diff] [blame] | 2711 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2712 | if (i40evf_process_config(adapter)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2713 | goto err_alloc; |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2714 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2715 | |
| 2716 | adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED; |
| 2717 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2718 | netdev->netdev_ops = &i40evf_netdev_ops; |
| 2719 | i40evf_set_ethtool_ops(netdev); |
| 2720 | netdev->watchdog_timeo = 5 * HZ; |
Greg Rose | 3415e8c | 2014-01-30 12:40:27 +0000 | [diff] [blame] | 2721 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 2722 | /* MTU range: 68 - 9710 */ |
| 2723 | netdev->min_mtu = ETH_MIN_MTU; |
Mitch Williams | 1e3a5fd | 2017-06-23 04:24:43 -0400 | [diff] [blame] | 2724 | netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD; |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 2725 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2726 | if (!is_valid_ether_addr(adapter->hw.mac.addr)) { |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2727 | dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n", |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2728 | adapter->hw.mac.addr); |
Mitch Williams | 14e52ee | 2015-08-31 19:54:44 -0400 | [diff] [blame] | 2729 | eth_hw_addr_random(netdev); |
| 2730 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); |
| 2731 | } else { |
| 2732 | adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF; |
| 2733 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
| 2734 | ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2735 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2736 | |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 2737 | timer_setup(&adapter->watchdog_timer, i40evf_watchdog_timer, 0); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2738 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 2739 | |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 2740 | adapter->tx_desc_count = I40EVF_DEFAULT_TXD; |
| 2741 | adapter->rx_desc_count = I40EVF_DEFAULT_RXD; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2742 | err = i40evf_init_interrupt_scheme(adapter); |
| 2743 | if (err) |
| 2744 | goto err_sw_init; |
| 2745 | i40evf_map_rings_to_vectors(adapter); |
Stefan Assmann | fbb113f | 2017-06-29 15:12:24 +0200 | [diff] [blame] | 2746 | if (adapter->vf_res->vf_cap_flags & |
Jesse Brandeburg | 310a2ad | 2017-05-11 11:23:11 -0700 | [diff] [blame] | 2747 | VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 2748 | adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE; |
| 2749 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2750 | err = i40evf_request_misc_irq(adapter); |
| 2751 | if (err) |
| 2752 | goto err_sw_init; |
| 2753 | |
| 2754 | netif_carrier_off(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 2755 | adapter->link_up = false; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2756 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2757 | if (!adapter->netdev_registered) { |
| 2758 | err = register_netdev(netdev); |
| 2759 | if (err) |
| 2760 | goto err_register; |
| 2761 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2762 | |
| 2763 | adapter->netdev_registered = true; |
| 2764 | |
| 2765 | netif_tx_stop_all_queues(netdev); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2766 | if (CLIENT_ALLOWED(adapter)) { |
| 2767 | err = i40evf_lan_add_device(adapter); |
| 2768 | if (err) |
| 2769 | dev_info(&pdev->dev, "Failed to add VF to client API service list: %d\n", |
| 2770 | err); |
| 2771 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2772 | |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2773 | dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2774 | if (netdev->features & NETIF_F_GRO) |
| 2775 | dev_info(&pdev->dev, "GRO is enabled\n"); |
| 2776 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2777 | adapter->state = __I40EVF_DOWN; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2778 | set_bit(__I40E_VSI_DOWN, adapter->vsi.state); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2779 | i40evf_misc_irq_enable(adapter); |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 2780 | wake_up(&adapter->down_waitqueue); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2781 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2782 | adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL); |
| 2783 | adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL); |
| 2784 | if (!adapter->rss_key || !adapter->rss_lut) |
| 2785 | goto err_mem; |
| 2786 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2787 | if (RSS_AQ(adapter)) { |
| 2788 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS; |
| 2789 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
| 2790 | } else { |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 2791 | i40evf_init_rss(adapter); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2792 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2793 | return; |
| 2794 | restart: |
Mitch Williams | 3f7e5c3 | 2015-09-28 14:12:42 -0400 | [diff] [blame] | 2795 | schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2796 | return; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2797 | err_mem: |
| 2798 | i40evf_free_rss(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2799 | err_register: |
| 2800 | i40evf_free_misc_irq(adapter); |
| 2801 | err_sw_init: |
| 2802 | i40evf_reset_interrupt_capability(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2803 | err_alloc: |
| 2804 | kfree(adapter->vf_res); |
| 2805 | adapter->vf_res = NULL; |
| 2806 | err: |
| 2807 | /* Things went into the weeds, so try again later */ |
| 2808 | if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) { |
Mitch Williams | b9029e9 | 2015-09-28 14:16:50 -0400 | [diff] [blame] | 2809 | dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2810 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
Mitch Williams | b9029e9 | 2015-09-28 14:16:50 -0400 | [diff] [blame] | 2811 | i40evf_shutdown_adminq(hw); |
| 2812 | adapter->state = __I40EVF_STARTUP; |
| 2813 | schedule_delayed_work(&adapter->init_task, HZ * 5); |
| 2814 | return; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2815 | } |
Mitch Williams | 3f7e5c3 | 2015-09-28 14:12:42 -0400 | [diff] [blame] | 2816 | schedule_delayed_work(&adapter->init_task, HZ); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | /** |
| 2820 | * i40evf_shutdown - Shutdown the device in preparation for a reboot |
| 2821 | * @pdev: pci device structure |
| 2822 | **/ |
| 2823 | static void i40evf_shutdown(struct pci_dev *pdev) |
| 2824 | { |
| 2825 | struct net_device *netdev = pci_get_drvdata(pdev); |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2826 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2827 | |
| 2828 | netif_device_detach(netdev); |
| 2829 | |
| 2830 | if (netif_running(netdev)) |
| 2831 | i40evf_close(netdev); |
| 2832 | |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2833 | /* Prevent the watchdog from running. */ |
| 2834 | adapter->state = __I40EVF_REMOVE; |
| 2835 | adapter->aq_required = 0; |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2836 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2837 | #ifdef CONFIG_PM |
| 2838 | pci_save_state(pdev); |
| 2839 | |
| 2840 | #endif |
| 2841 | pci_disable_device(pdev); |
| 2842 | } |
| 2843 | |
| 2844 | /** |
| 2845 | * i40evf_probe - Device Initialization Routine |
| 2846 | * @pdev: PCI device information struct |
| 2847 | * @ent: entry in i40evf_pci_tbl |
| 2848 | * |
| 2849 | * Returns 0 on success, negative on failure |
| 2850 | * |
| 2851 | * i40evf_probe initializes an adapter identified by a pci_dev structure. |
| 2852 | * The OS initialization, configuring of the adapter private structure, |
| 2853 | * and a hardware reset occur. |
| 2854 | **/ |
| 2855 | static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2856 | { |
| 2857 | struct net_device *netdev; |
| 2858 | struct i40evf_adapter *adapter = NULL; |
| 2859 | struct i40e_hw *hw = NULL; |
Mitch Williams | dbbd811 | 2014-02-20 19:29:08 -0800 | [diff] [blame] | 2860 | int err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2861 | |
| 2862 | err = pci_enable_device(pdev); |
| 2863 | if (err) |
| 2864 | return err; |
| 2865 | |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2866 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2867 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 2868 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 2869 | if (err) { |
| 2870 | dev_err(&pdev->dev, |
| 2871 | "DMA configuration failed: 0x%x\n", err); |
| 2872 | goto err_dma; |
| 2873 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | err = pci_request_regions(pdev, i40evf_driver_name); |
| 2877 | if (err) { |
| 2878 | dev_err(&pdev->dev, |
| 2879 | "pci_request_regions failed 0x%x\n", err); |
| 2880 | goto err_pci_reg; |
| 2881 | } |
| 2882 | |
| 2883 | pci_enable_pcie_error_reporting(pdev); |
| 2884 | |
| 2885 | pci_set_master(pdev); |
| 2886 | |
Mitch Williams | 1255b7a | 2015-11-06 15:25:59 -0800 | [diff] [blame] | 2887 | netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2888 | if (!netdev) { |
| 2889 | err = -ENOMEM; |
| 2890 | goto err_alloc_etherdev; |
| 2891 | } |
| 2892 | |
| 2893 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2894 | |
| 2895 | pci_set_drvdata(pdev, netdev); |
| 2896 | adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2897 | |
| 2898 | adapter->netdev = netdev; |
| 2899 | adapter->pdev = pdev; |
| 2900 | |
| 2901 | hw = &adapter->hw; |
| 2902 | hw->back = adapter; |
| 2903 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2904 | adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2905 | adapter->state = __I40EVF_STARTUP; |
| 2906 | |
| 2907 | /* Call save state here because it relies on the adapter struct. */ |
| 2908 | pci_save_state(pdev); |
| 2909 | |
| 2910 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 2911 | pci_resource_len(pdev, 0)); |
| 2912 | if (!hw->hw_addr) { |
| 2913 | err = -EIO; |
| 2914 | goto err_ioremap; |
| 2915 | } |
| 2916 | hw->vendor_id = pdev->vendor; |
| 2917 | hw->device_id = pdev->device; |
| 2918 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 2919 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 2920 | hw->subsystem_device_id = pdev->subsystem_device; |
| 2921 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 2922 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 2923 | hw->bus.bus_id = pdev->bus->number; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2924 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 2925 | /* set up the locks for the AQ, do this only once in probe |
| 2926 | * and destroy them only once in remove |
| 2927 | */ |
| 2928 | mutex_init(&hw->aq.asq_mutex); |
| 2929 | mutex_init(&hw->aq.arq_mutex); |
| 2930 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 2931 | spin_lock_init(&adapter->mac_vlan_list_lock); |
| 2932 | |
Serey Kong | 8bb1a54 | 2014-08-01 13:27:15 -0700 | [diff] [blame] | 2933 | INIT_LIST_HEAD(&adapter->mac_filter_list); |
| 2934 | INIT_LIST_HEAD(&adapter->vlan_filter_list); |
| 2935 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2936 | INIT_WORK(&adapter->reset_task, i40evf_reset_task); |
| 2937 | INIT_WORK(&adapter->adminq_task, i40evf_adminq_task); |
| 2938 | INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 2939 | INIT_DELAYED_WORK(&adapter->client_task, i40evf_client_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2940 | INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task); |
Mitch Williams | 9b32b0b | 2015-08-13 15:11:32 -0700 | [diff] [blame] | 2941 | schedule_delayed_work(&adapter->init_task, |
| 2942 | msecs_to_jiffies(5 * (pdev->devfn & 0x07))); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2943 | |
Sudheer Mogilappagari | fe2647a | 2017-06-23 04:24:44 -0400 | [diff] [blame] | 2944 | /* Setup the wait queue for indicating transition to down status */ |
| 2945 | init_waitqueue_head(&adapter->down_waitqueue); |
| 2946 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2947 | return 0; |
| 2948 | |
| 2949 | err_ioremap: |
| 2950 | free_netdev(netdev); |
| 2951 | err_alloc_etherdev: |
| 2952 | pci_release_regions(pdev); |
| 2953 | err_pci_reg: |
| 2954 | err_dma: |
| 2955 | pci_disable_device(pdev); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | #ifdef CONFIG_PM |
| 2960 | /** |
| 2961 | * i40evf_suspend - Power management suspend routine |
| 2962 | * @pdev: PCI device information struct |
| 2963 | * @state: unused |
| 2964 | * |
| 2965 | * Called when the system (VM) is entering sleep/suspend. |
| 2966 | **/ |
| 2967 | static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2968 | { |
| 2969 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2970 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2971 | int retval = 0; |
| 2972 | |
| 2973 | netif_device_detach(netdev); |
| 2974 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2975 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 2976 | &adapter->crit_section)) |
| 2977 | usleep_range(500, 1000); |
| 2978 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2979 | if (netif_running(netdev)) { |
| 2980 | rtnl_lock(); |
| 2981 | i40evf_down(adapter); |
| 2982 | rtnl_unlock(); |
| 2983 | } |
| 2984 | i40evf_free_misc_irq(adapter); |
| 2985 | i40evf_reset_interrupt_capability(adapter); |
| 2986 | |
Jacob Keller | 9b2aef1 | 2017-10-27 11:06:52 -0400 | [diff] [blame] | 2987 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 2988 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2989 | retval = pci_save_state(pdev); |
| 2990 | if (retval) |
| 2991 | return retval; |
| 2992 | |
| 2993 | pci_disable_device(pdev); |
| 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | /** |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2999 | * i40evf_resume - Power management resume routine |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3000 | * @pdev: PCI device information struct |
| 3001 | * |
| 3002 | * Called when the system (VM) is resumed from sleep/suspend. |
| 3003 | **/ |
| 3004 | static int i40evf_resume(struct pci_dev *pdev) |
| 3005 | { |
| 3006 | struct i40evf_adapter *adapter = pci_get_drvdata(pdev); |
| 3007 | struct net_device *netdev = adapter->netdev; |
| 3008 | u32 err; |
| 3009 | |
| 3010 | pci_set_power_state(pdev, PCI_D0); |
| 3011 | pci_restore_state(pdev); |
| 3012 | /* pci_restore_state clears dev->state_saved so call |
| 3013 | * pci_save_state to restore it. |
| 3014 | */ |
| 3015 | pci_save_state(pdev); |
| 3016 | |
| 3017 | err = pci_enable_device_mem(pdev); |
| 3018 | if (err) { |
| 3019 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n"); |
| 3020 | return err; |
| 3021 | } |
| 3022 | pci_set_master(pdev); |
| 3023 | |
| 3024 | rtnl_lock(); |
| 3025 | err = i40evf_set_interrupt_capability(adapter); |
| 3026 | if (err) { |
Vasily Averin | f2a1c36 | 2015-07-07 18:53:38 +0300 | [diff] [blame] | 3027 | rtnl_unlock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3028 | dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); |
| 3029 | return err; |
| 3030 | } |
| 3031 | err = i40evf_request_misc_irq(adapter); |
| 3032 | rtnl_unlock(); |
| 3033 | if (err) { |
| 3034 | dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); |
| 3035 | return err; |
| 3036 | } |
| 3037 | |
| 3038 | schedule_work(&adapter->reset_task); |
| 3039 | |
| 3040 | netif_device_attach(netdev); |
| 3041 | |
| 3042 | return err; |
| 3043 | } |
| 3044 | |
| 3045 | #endif /* CONFIG_PM */ |
| 3046 | /** |
| 3047 | * i40evf_remove - Device Removal Routine |
| 3048 | * @pdev: PCI device information struct |
| 3049 | * |
| 3050 | * i40evf_remove is called by the PCI subsystem to alert the driver |
| 3051 | * that it should release a PCI device. The could be caused by a |
| 3052 | * Hot-Plug event, or because the driver is going to be removed from |
| 3053 | * memory. |
| 3054 | **/ |
| 3055 | static void i40evf_remove(struct pci_dev *pdev) |
| 3056 | { |
| 3057 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3058 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 3059 | struct i40evf_mac_filter *f, *ftmp; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3060 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 3061 | int err; |
Avinash Dayanand | 06aa040 | 2017-12-18 05:16:43 -0500 | [diff] [blame] | 3062 | /* Indicate we are in remove and not to run reset_task */ |
| 3063 | set_bit(__I40EVF_IN_REMOVE_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3064 | cancel_delayed_work_sync(&adapter->init_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 3065 | cancel_work_sync(&adapter->reset_task); |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 3066 | cancel_delayed_work_sync(&adapter->client_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3067 | if (adapter->netdev_registered) { |
| 3068 | unregister_netdev(netdev); |
| 3069 | adapter->netdev_registered = false; |
| 3070 | } |
Mitch Williams | ed0e894 | 2017-01-24 10:23:59 -0800 | [diff] [blame] | 3071 | if (CLIENT_ALLOWED(adapter)) { |
| 3072 | err = i40evf_lan_del_device(adapter); |
| 3073 | if (err) |
| 3074 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 3075 | err); |
| 3076 | } |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 3077 | |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 3078 | /* Shut down all the garbage mashers on the detention level */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3079 | adapter->state = __I40EVF_REMOVE; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 3080 | adapter->aq_required = 0; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 3081 | i40evf_request_reset(adapter); |
Mitch Williams | 22ead37 | 2016-03-18 12:18:10 -0700 | [diff] [blame] | 3082 | msleep(50); |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 3083 | /* If the FW isn't responding, kick it once, but only once. */ |
| 3084 | if (!i40evf_asq_done(hw)) { |
| 3085 | i40evf_request_reset(adapter); |
Mitch Williams | 22ead37 | 2016-03-18 12:18:10 -0700 | [diff] [blame] | 3086 | msleep(50); |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 3087 | } |
Mitch Williams | 8a68bad | 2016-12-12 15:44:10 -0800 | [diff] [blame] | 3088 | i40evf_free_all_tx_resources(adapter); |
| 3089 | i40evf_free_all_rx_resources(adapter); |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame] | 3090 | i40evf_misc_irq_disable(adapter); |
| 3091 | i40evf_free_misc_irq(adapter); |
| 3092 | i40evf_reset_interrupt_capability(adapter); |
| 3093 | i40evf_free_q_vectors(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3094 | |
Mitch Williams | e5d17c3 | 2014-06-04 04:22:38 +0000 | [diff] [blame] | 3095 | if (adapter->watchdog_timer.function) |
| 3096 | del_timer_sync(&adapter->watchdog_timer); |
| 3097 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 3098 | i40evf_free_rss(adapter); |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 3099 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3100 | if (hw->aq.asq.count) |
| 3101 | i40evf_shutdown_adminq(hw); |
| 3102 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 3103 | /* destroy the locks only once, here */ |
| 3104 | mutex_destroy(&hw->aq.arq_mutex); |
| 3105 | mutex_destroy(&hw->aq.asq_mutex); |
| 3106 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3107 | iounmap(hw->hw_addr); |
| 3108 | pci_release_regions(pdev); |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 3109 | i40evf_free_all_tx_resources(adapter); |
| 3110 | i40evf_free_all_rx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3111 | i40evf_free_queues(adapter); |
| 3112 | kfree(adapter->vf_res); |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 3113 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 3114 | /* If we got removed before an up/down sequence, we've got a filter |
| 3115 | * hanging out there that we need to get rid of. |
| 3116 | */ |
| 3117 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 3118 | list_del(&f->list); |
| 3119 | kfree(f); |
| 3120 | } |
Mitch A Williams | 37dfdf3 | 2014-12-09 08:53:05 +0000 | [diff] [blame] | 3121 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
| 3122 | list_del(&f->list); |
| 3123 | kfree(f); |
| 3124 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3125 | |
Jacob Keller | 504398f | 2017-10-27 11:06:50 -0400 | [diff] [blame] | 3126 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
| 3127 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3128 | free_netdev(netdev); |
| 3129 | |
| 3130 | pci_disable_pcie_error_reporting(pdev); |
| 3131 | |
| 3132 | pci_disable_device(pdev); |
| 3133 | } |
| 3134 | |
| 3135 | static struct pci_driver i40evf_driver = { |
| 3136 | .name = i40evf_driver_name, |
| 3137 | .id_table = i40evf_pci_tbl, |
| 3138 | .probe = i40evf_probe, |
| 3139 | .remove = i40evf_remove, |
| 3140 | #ifdef CONFIG_PM |
| 3141 | .suspend = i40evf_suspend, |
| 3142 | .resume = i40evf_resume, |
| 3143 | #endif |
| 3144 | .shutdown = i40evf_shutdown, |
| 3145 | }; |
| 3146 | |
| 3147 | /** |
| 3148 | * i40e_init_module - Driver Registration Routine |
| 3149 | * |
| 3150 | * i40e_init_module is the first routine called when the driver is |
| 3151 | * loaded. All it does is register with the PCI subsystem. |
| 3152 | **/ |
| 3153 | static int __init i40evf_init_module(void) |
| 3154 | { |
| 3155 | int ret; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 3156 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3157 | pr_info("i40evf: %s - version %s\n", i40evf_driver_string, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 3158 | i40evf_driver_version); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3159 | |
| 3160 | pr_info("%s\n", i40evf_copyright); |
| 3161 | |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 3162 | i40evf_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 3163 | i40evf_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 3164 | if (!i40evf_wq) { |
| 3165 | pr_err("%s: Failed to create workqueue\n", i40evf_driver_name); |
| 3166 | return -ENOMEM; |
| 3167 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3168 | ret = pci_register_driver(&i40evf_driver); |
| 3169 | return ret; |
| 3170 | } |
| 3171 | |
| 3172 | module_init(i40evf_init_module); |
| 3173 | |
| 3174 | /** |
| 3175 | * i40e_exit_module - Driver Exit Cleanup Routine |
| 3176 | * |
| 3177 | * i40e_exit_module is called just before the driver is removed |
| 3178 | * from memory. |
| 3179 | **/ |
| 3180 | static void __exit i40evf_exit_module(void) |
| 3181 | { |
| 3182 | pci_unregister_driver(&i40evf_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 3183 | destroy_workqueue(i40evf_wq); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | module_exit(i40evf_exit_module); |
| 3187 | |
| 3188 | /* i40evf_main.c */ |