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