Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver |
Sravanthi Tangeda | 5b8eb17 | 2015-02-06 08:52:21 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 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" |
| 29 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter); |
| 30 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter); |
| 31 | static int i40evf_close(struct net_device *netdev); |
| 32 | |
| 33 | char i40evf_driver_name[] = "i40evf"; |
| 34 | static const char i40evf_driver_string[] = |
Mitch Williams | 0af56f4 | 2014-06-04 20:42:10 +0000 | [diff] [blame] | 35 | "Intel(R) XL710/X710 Virtual Function Network Driver"; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 36 | |
Catherine Sullivan | 76945bf | 2015-04-27 14:57:22 -0400 | [diff] [blame] | 37 | #define DRV_VERSION "1.3.2" |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 38 | const char i40evf_driver_version[] = DRV_VERSION; |
| 39 | static const char i40evf_copyright[] = |
Mitch Williams | 673f2eb | 2014-02-20 19:29:13 -0800 | [diff] [blame] | 40 | "Copyright (c) 2013 - 2014 Intel Corporation."; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 41 | |
| 42 | /* i40evf_pci_tbl - PCI Device ID Table |
| 43 | * |
| 44 | * Wildcard entries (PCI_ANY_ID) should come last |
| 45 | * Last entry must be all 0s |
| 46 | * |
| 47 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 48 | * Class, Class Mask, private data (not used) } |
| 49 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 50 | static const struct pci_device_id i40evf_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 51 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame^] | 52 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0}, |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 53 | /* required last entry */ |
| 54 | {0, } |
| 55 | }; |
| 56 | |
| 57 | MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl); |
| 58 | |
| 59 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 60 | MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver"); |
| 61 | MODULE_LICENSE("GPL"); |
| 62 | MODULE_VERSION(DRV_VERSION); |
| 63 | |
| 64 | /** |
| 65 | * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 66 | * @hw: pointer to the HW structure |
| 67 | * @mem: ptr to mem struct to fill out |
| 68 | * @size: size of memory requested |
| 69 | * @alignment: what to align the allocation to |
| 70 | **/ |
| 71 | i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw, |
| 72 | struct i40e_dma_mem *mem, |
| 73 | u64 size, u32 alignment) |
| 74 | { |
| 75 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; |
| 76 | |
| 77 | if (!mem) |
| 78 | return I40E_ERR_PARAM; |
| 79 | |
| 80 | mem->size = ALIGN(size, alignment); |
| 81 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, |
| 82 | (dma_addr_t *)&mem->pa, GFP_KERNEL); |
| 83 | if (mem->va) |
| 84 | return 0; |
| 85 | else |
| 86 | return I40E_ERR_NO_MEMORY; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * i40evf_free_dma_mem_d - OS specific memory free for shared code |
| 91 | * @hw: pointer to the HW structure |
| 92 | * @mem: ptr to mem struct to free |
| 93 | **/ |
| 94 | i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 95 | { |
| 96 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; |
| 97 | |
| 98 | if (!mem || !mem->va) |
| 99 | return I40E_ERR_PARAM; |
| 100 | dma_free_coherent(&adapter->pdev->dev, mem->size, |
| 101 | mem->va, (dma_addr_t)mem->pa); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 107 | * @hw: pointer to the HW structure |
| 108 | * @mem: ptr to mem struct to fill out |
| 109 | * @size: size of memory requested |
| 110 | **/ |
| 111 | i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw, |
| 112 | struct i40e_virt_mem *mem, u32 size) |
| 113 | { |
| 114 | if (!mem) |
| 115 | return I40E_ERR_PARAM; |
| 116 | |
| 117 | mem->size = size; |
| 118 | mem->va = kzalloc(size, GFP_KERNEL); |
| 119 | |
| 120 | if (mem->va) |
| 121 | return 0; |
| 122 | else |
| 123 | return I40E_ERR_NO_MEMORY; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * i40evf_free_virt_mem_d - OS specific memory free for shared code |
| 128 | * @hw: pointer to the HW structure |
| 129 | * @mem: ptr to mem struct to free |
| 130 | **/ |
| 131 | i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw, |
| 132 | struct i40e_virt_mem *mem) |
| 133 | { |
| 134 | if (!mem) |
| 135 | return I40E_ERR_PARAM; |
| 136 | |
| 137 | /* it's ok to kfree a NULL pointer */ |
| 138 | kfree(mem->va); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * i40evf_debug_d - OS dependent version of debug printing |
| 145 | * @hw: pointer to the HW structure |
| 146 | * @mask: debug level mask |
| 147 | * @fmt_str: printf-type format description |
| 148 | **/ |
| 149 | void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...) |
| 150 | { |
| 151 | char buf[512]; |
| 152 | va_list argptr; |
| 153 | |
| 154 | if (!(mask & ((struct i40e_hw *)hw)->debug_mask)) |
| 155 | return; |
| 156 | |
| 157 | va_start(argptr, fmt_str); |
| 158 | vsnprintf(buf, sizeof(buf), fmt_str, argptr); |
| 159 | va_end(argptr); |
| 160 | |
| 161 | /* the debug string is already formatted with a newline */ |
| 162 | pr_info("%s", buf); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * i40evf_tx_timeout - Respond to a Tx Hang |
| 167 | * @netdev: network interface device structure |
| 168 | **/ |
| 169 | static void i40evf_tx_timeout(struct net_device *netdev) |
| 170 | { |
| 171 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 172 | |
| 173 | adapter->tx_timeout_count++; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 174 | if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING | |
| 175 | I40EVF_FLAG_RESET_NEEDED))) { |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 176 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
Mitch Williams | 625777e | 2014-02-20 19:29:05 -0800 | [diff] [blame] | 177 | schedule_work(&adapter->reset_task); |
| 178 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
| 182 | * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC |
| 183 | * @adapter: board private structure |
| 184 | **/ |
| 185 | static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter) |
| 186 | { |
| 187 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 188 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 189 | wr32(hw, I40E_VFINT_DYN_CTL01, 0); |
| 190 | |
| 191 | /* read flush */ |
| 192 | rd32(hw, I40E_VFGEN_RSTAT); |
| 193 | |
| 194 | synchronize_irq(adapter->msix_entries[0].vector); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * i40evf_misc_irq_enable - Enable default interrupt generation settings |
| 199 | * @adapter: board private structure |
| 200 | **/ |
| 201 | static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter) |
| 202 | { |
| 203 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 204 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 205 | wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK | |
| 206 | I40E_VFINT_DYN_CTL01_ITR_INDX_MASK); |
| 207 | wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK); |
| 208 | |
| 209 | /* read flush */ |
| 210 | rd32(hw, I40E_VFGEN_RSTAT); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * i40evf_irq_disable - Mask off interrupt generation on the NIC |
| 215 | * @adapter: board private structure |
| 216 | **/ |
| 217 | static void i40evf_irq_disable(struct i40evf_adapter *adapter) |
| 218 | { |
| 219 | int i; |
| 220 | struct i40e_hw *hw = &adapter->hw; |
| 221 | |
Mitch Williams | dbb01c8 | 2014-02-20 19:29:07 -0800 | [diff] [blame] | 222 | if (!adapter->msix_entries) |
| 223 | return; |
| 224 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 225 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
| 226 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0); |
| 227 | synchronize_irq(adapter->msix_entries[i].vector); |
| 228 | } |
| 229 | /* read flush */ |
| 230 | rd32(hw, I40E_VFGEN_RSTAT); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
| 234 | * i40evf_irq_enable_queues - Enable interrupt for specified queues |
| 235 | * @adapter: board private structure |
| 236 | * @mask: bitmap of queues to enable |
| 237 | **/ |
| 238 | void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask) |
| 239 | { |
| 240 | struct i40e_hw *hw = &adapter->hw; |
| 241 | int i; |
| 242 | |
| 243 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 244 | if (mask & BIT(i - 1)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 245 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), |
| 246 | I40E_VFINT_DYN_CTLN1_INTENA_MASK | |
Jesse Brandeburg | 97bf75f | 2015-02-27 09:18:32 +0000 | [diff] [blame] | 247 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 248 | I40E_VFINT_DYN_CTLN_CLEARPBA_MASK); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * i40evf_fire_sw_int - Generate SW interrupt for specified vectors |
| 255 | * @adapter: board private structure |
| 256 | * @mask: bitmap of vectors to trigger |
| 257 | **/ |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 258 | static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 259 | { |
| 260 | struct i40e_hw *hw = &adapter->hw; |
| 261 | int i; |
| 262 | uint32_t dyn_ctl; |
| 263 | |
Mitch Williams | 164ec1b | 2014-06-04 08:45:19 +0000 | [diff] [blame] | 264 | if (mask & 1) { |
| 265 | dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01); |
| 266 | dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK | |
Jesse Brandeburg | 97bf75f | 2015-02-27 09:18:32 +0000 | [diff] [blame] | 267 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
Mitch Williams | 164ec1b | 2014-06-04 08:45:19 +0000 | [diff] [blame] | 268 | I40E_VFINT_DYN_CTLN_CLEARPBA_MASK; |
| 269 | wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl); |
| 270 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 271 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 272 | if (mask & BIT(i)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 273 | dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1)); |
| 274 | dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK | |
Jesse Brandeburg | 97bf75f | 2015-02-27 09:18:32 +0000 | [diff] [blame] | 275 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 276 | I40E_VFINT_DYN_CTLN_CLEARPBA_MASK; |
| 277 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * i40evf_irq_enable - Enable default interrupt generation settings |
| 284 | * @adapter: board private structure |
| 285 | **/ |
| 286 | void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush) |
| 287 | { |
| 288 | struct i40e_hw *hw = &adapter->hw; |
| 289 | |
Mitch Williams | 164ec1b | 2014-06-04 08:45:19 +0000 | [diff] [blame] | 290 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 291 | i40evf_irq_enable_queues(adapter, ~0); |
| 292 | |
| 293 | if (flush) |
| 294 | rd32(hw, I40E_VFGEN_RSTAT); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * i40evf_msix_aq - Interrupt handler for vector 0 |
| 299 | * @irq: interrupt number |
| 300 | * @data: pointer to netdev |
| 301 | **/ |
| 302 | static irqreturn_t i40evf_msix_aq(int irq, void *data) |
| 303 | { |
| 304 | struct net_device *netdev = data; |
| 305 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 306 | struct i40e_hw *hw = &adapter->hw; |
| 307 | u32 val; |
| 308 | u32 ena_mask; |
| 309 | |
| 310 | /* handle non-queue interrupts */ |
| 311 | val = rd32(hw, I40E_VFINT_ICR01); |
| 312 | ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1); |
| 313 | |
| 314 | |
| 315 | val = rd32(hw, I40E_VFINT_DYN_CTL01); |
| 316 | val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; |
| 317 | wr32(hw, I40E_VFINT_DYN_CTL01, val); |
| 318 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 319 | /* schedule work on the private workqueue */ |
| 320 | schedule_work(&adapter->adminq_task); |
| 321 | |
| 322 | return IRQ_HANDLED; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * i40evf_msix_clean_rings - MSIX mode Interrupt Handler |
| 327 | * @irq: interrupt number |
| 328 | * @data: pointer to a q_vector |
| 329 | **/ |
| 330 | static irqreturn_t i40evf_msix_clean_rings(int irq, void *data) |
| 331 | { |
| 332 | struct i40e_q_vector *q_vector = data; |
| 333 | |
| 334 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
| 335 | return IRQ_HANDLED; |
| 336 | |
| 337 | napi_schedule(&q_vector->napi); |
| 338 | |
| 339 | return IRQ_HANDLED; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * i40evf_map_vector_to_rxq - associate irqs with rx queues |
| 344 | * @adapter: board private structure |
| 345 | * @v_idx: interrupt number |
| 346 | * @r_idx: queue number |
| 347 | **/ |
| 348 | static void |
| 349 | i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx) |
| 350 | { |
| 351 | struct i40e_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 352 | struct i40e_ring *rx_ring = adapter->rx_rings[r_idx]; |
| 353 | |
| 354 | rx_ring->q_vector = q_vector; |
| 355 | rx_ring->next = q_vector->rx.ring; |
| 356 | rx_ring->vsi = &adapter->vsi; |
| 357 | q_vector->rx.ring = rx_ring; |
| 358 | q_vector->rx.count++; |
| 359 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * i40evf_map_vector_to_txq - associate irqs with tx queues |
| 364 | * @adapter: board private structure |
| 365 | * @v_idx: interrupt number |
| 366 | * @t_idx: queue number |
| 367 | **/ |
| 368 | static void |
| 369 | i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx) |
| 370 | { |
| 371 | struct i40e_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 372 | struct i40e_ring *tx_ring = adapter->tx_rings[t_idx]; |
| 373 | |
| 374 | tx_ring->q_vector = q_vector; |
| 375 | tx_ring->next = q_vector->tx.ring; |
| 376 | tx_ring->vsi = &adapter->vsi; |
| 377 | q_vector->tx.ring = tx_ring; |
| 378 | q_vector->tx.count++; |
| 379 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 380 | q_vector->num_ringpairs++; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 381 | q_vector->ring_mask |= BIT(t_idx); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /** |
| 385 | * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors |
| 386 | * @adapter: board private structure to initialize |
| 387 | * |
| 388 | * This function maps descriptor rings to the queue-specific vectors |
| 389 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 390 | * one vector per ring/queue, but on a constrained vector budget, we |
| 391 | * group the rings as "efficiently" as possible. You would add new |
| 392 | * mapping configurations in here. |
| 393 | **/ |
| 394 | static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter) |
| 395 | { |
| 396 | int q_vectors; |
| 397 | int v_start = 0; |
| 398 | int rxr_idx = 0, txr_idx = 0; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 399 | int rxr_remaining = adapter->num_active_queues; |
| 400 | int txr_remaining = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 401 | int i, j; |
| 402 | int rqpv, tqpv; |
| 403 | int err = 0; |
| 404 | |
| 405 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 406 | |
| 407 | /* The ideal configuration... |
| 408 | * We have enough vectors to map one per queue. |
| 409 | */ |
Mitch Williams | 973371d | 2015-04-27 14:57:09 -0400 | [diff] [blame] | 410 | if (q_vectors >= (rxr_remaining * 2)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 411 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 412 | i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 413 | |
| 414 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 415 | i40evf_map_vector_to_txq(adapter, v_start, txr_idx); |
| 416 | goto out; |
| 417 | } |
| 418 | |
| 419 | /* If we don't have enough vectors for a 1-to-1 |
| 420 | * mapping, we'll have to group them so there are |
| 421 | * multiple queues per vector. |
| 422 | * Re-adjusting *qpv takes care of the remainder. |
| 423 | */ |
| 424 | for (i = v_start; i < q_vectors; i++) { |
| 425 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
| 426 | for (j = 0; j < rqpv; j++) { |
| 427 | i40evf_map_vector_to_rxq(adapter, i, rxr_idx); |
| 428 | rxr_idx++; |
| 429 | rxr_remaining--; |
| 430 | } |
| 431 | } |
| 432 | for (i = v_start; i < q_vectors; i++) { |
| 433 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
| 434 | for (j = 0; j < tqpv; j++) { |
| 435 | i40evf_map_vector_to_txq(adapter, i, txr_idx); |
| 436 | txr_idx++; |
| 437 | txr_remaining--; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | out: |
| 442 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; |
| 443 | |
| 444 | return err; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * i40evf_request_traffic_irqs - Initialize MSI-X interrupts |
| 449 | * @adapter: board private structure |
| 450 | * |
| 451 | * Allocates MSI-X vectors for tx and rx handling, and requests |
| 452 | * interrupts from the kernel. |
| 453 | **/ |
| 454 | static int |
| 455 | i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename) |
| 456 | { |
| 457 | int vector, err, q_vectors; |
| 458 | int rx_int_idx = 0, tx_int_idx = 0; |
| 459 | |
| 460 | i40evf_irq_disable(adapter); |
| 461 | /* Decrement for Other and TCP Timer vectors */ |
| 462 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 463 | |
| 464 | for (vector = 0; vector < q_vectors; vector++) { |
| 465 | struct i40e_q_vector *q_vector = adapter->q_vector[vector]; |
| 466 | |
| 467 | if (q_vector->tx.ring && q_vector->rx.ring) { |
| 468 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 469 | "i40evf-%s-%s-%d", basename, |
| 470 | "TxRx", rx_int_idx++); |
| 471 | tx_int_idx++; |
| 472 | } else if (q_vector->rx.ring) { |
| 473 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 474 | "i40evf-%s-%s-%d", basename, |
| 475 | "rx", rx_int_idx++); |
| 476 | } else if (q_vector->tx.ring) { |
| 477 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 478 | "i40evf-%s-%s-%d", basename, |
| 479 | "tx", tx_int_idx++); |
| 480 | } else { |
| 481 | /* skip this unused q_vector */ |
| 482 | continue; |
| 483 | } |
| 484 | err = request_irq( |
| 485 | adapter->msix_entries[vector + NONQ_VECS].vector, |
| 486 | i40evf_msix_clean_rings, |
| 487 | 0, |
| 488 | q_vector->name, |
| 489 | q_vector); |
| 490 | if (err) { |
| 491 | dev_info(&adapter->pdev->dev, |
| 492 | "%s: request_irq failed, error: %d\n", |
| 493 | __func__, err); |
| 494 | goto free_queue_irqs; |
| 495 | } |
| 496 | /* assign the mask for this irq */ |
| 497 | irq_set_affinity_hint( |
| 498 | adapter->msix_entries[vector + NONQ_VECS].vector, |
| 499 | q_vector->affinity_mask); |
| 500 | } |
| 501 | |
| 502 | return 0; |
| 503 | |
| 504 | free_queue_irqs: |
| 505 | while (vector) { |
| 506 | vector--; |
| 507 | irq_set_affinity_hint( |
| 508 | adapter->msix_entries[vector + NONQ_VECS].vector, |
| 509 | NULL); |
| 510 | free_irq(adapter->msix_entries[vector + NONQ_VECS].vector, |
| 511 | adapter->q_vector[vector]); |
| 512 | } |
| 513 | return err; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * i40evf_request_misc_irq - Initialize MSI-X interrupts |
| 518 | * @adapter: board private structure |
| 519 | * |
| 520 | * Allocates MSI-X vector 0 and requests interrupts from the kernel. This |
| 521 | * vector is only for the admin queue, and stays active even when the netdev |
| 522 | * is closed. |
| 523 | **/ |
| 524 | static int i40evf_request_misc_irq(struct i40evf_adapter *adapter) |
| 525 | { |
| 526 | struct net_device *netdev = adapter->netdev; |
| 527 | int err; |
| 528 | |
Jesse Brandeburg | b39c1e2 | 2014-08-01 13:27:08 -0700 | [diff] [blame] | 529 | snprintf(adapter->misc_vector_name, |
Carolyn Wyborny | 9a21a00 | 2015-02-06 08:52:20 +0000 | [diff] [blame] | 530 | sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx", |
| 531 | dev_name(&adapter->pdev->dev)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 532 | err = request_irq(adapter->msix_entries[0].vector, |
Mitch Williams | e1dfee8 | 2014-02-13 03:48:51 -0800 | [diff] [blame] | 533 | &i40evf_msix_aq, 0, |
| 534 | adapter->misc_vector_name, netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 535 | if (err) { |
| 536 | dev_err(&adapter->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 537 | "request_irq for %s failed: %d\n", |
| 538 | adapter->misc_vector_name, err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 539 | free_irq(adapter->msix_entries[0].vector, netdev); |
| 540 | } |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * i40evf_free_traffic_irqs - Free MSI-X interrupts |
| 546 | * @adapter: board private structure |
| 547 | * |
| 548 | * Frees all MSI-X vectors other than 0. |
| 549 | **/ |
| 550 | static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter) |
| 551 | { |
| 552 | int i; |
| 553 | int q_vectors; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 554 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 555 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 556 | |
| 557 | for (i = 0; i < q_vectors; i++) { |
| 558 | irq_set_affinity_hint(adapter->msix_entries[i+1].vector, |
| 559 | NULL); |
| 560 | free_irq(adapter->msix_entries[i+1].vector, |
| 561 | adapter->q_vector[i]); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * i40evf_free_misc_irq - Free MSI-X miscellaneous vector |
| 567 | * @adapter: board private structure |
| 568 | * |
| 569 | * Frees MSI-X vector 0. |
| 570 | **/ |
| 571 | static void i40evf_free_misc_irq(struct i40evf_adapter *adapter) |
| 572 | { |
| 573 | struct net_device *netdev = adapter->netdev; |
| 574 | |
| 575 | free_irq(adapter->msix_entries[0].vector, netdev); |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * i40evf_configure_tx - Configure Transmit Unit after Reset |
| 580 | * @adapter: board private structure |
| 581 | * |
| 582 | * Configure the Tx unit of the MAC after a reset. |
| 583 | **/ |
| 584 | static void i40evf_configure_tx(struct i40evf_adapter *adapter) |
| 585 | { |
| 586 | struct i40e_hw *hw = &adapter->hw; |
| 587 | int i; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 588 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 589 | for (i = 0; i < adapter->num_active_queues; i++) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 590 | adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i); |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * i40evf_configure_rx - Configure Receive Unit after Reset |
| 595 | * @adapter: board private structure |
| 596 | * |
| 597 | * Configure the Rx unit of the MAC after a reset. |
| 598 | **/ |
| 599 | static void i40evf_configure_rx(struct i40evf_adapter *adapter) |
| 600 | { |
| 601 | struct i40e_hw *hw = &adapter->hw; |
| 602 | struct net_device *netdev = adapter->netdev; |
| 603 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 604 | int i; |
| 605 | int rx_buf_len; |
| 606 | |
| 607 | |
| 608 | adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE; |
| 609 | adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE; |
| 610 | |
| 611 | /* Decide whether to use packet split mode or not */ |
| 612 | if (netdev->mtu > ETH_DATA_LEN) { |
| 613 | if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE) |
| 614 | adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED; |
| 615 | else |
| 616 | adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED; |
| 617 | } else { |
| 618 | if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE) |
| 619 | adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED; |
| 620 | else |
| 621 | adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED; |
| 622 | } |
| 623 | |
| 624 | /* Set the RX buffer length according to the mode */ |
| 625 | if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) { |
| 626 | rx_buf_len = I40E_RX_HDR_SIZE; |
| 627 | } else { |
| 628 | if (netdev->mtu <= ETH_DATA_LEN) |
| 629 | rx_buf_len = I40EVF_RXBUFFER_2048; |
| 630 | else |
| 631 | rx_buf_len = ALIGN(max_frame, 1024); |
| 632 | } |
| 633 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 634 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 635 | adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i); |
| 636 | adapter->rx_rings[i]->rx_buf_len = rx_buf_len; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * i40evf_find_vlan - Search filter list for specific vlan filter |
| 642 | * @adapter: board private structure |
| 643 | * @vlan: vlan tag |
| 644 | * |
| 645 | * Returns ptr to the filter object or NULL |
| 646 | **/ |
| 647 | static struct |
| 648 | i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 649 | { |
| 650 | struct i40evf_vlan_filter *f; |
| 651 | |
| 652 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 653 | if (vlan == f->vlan) |
| 654 | return f; |
| 655 | } |
| 656 | return NULL; |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * i40evf_add_vlan - Add a vlan filter to the list |
| 661 | * @adapter: board private structure |
| 662 | * @vlan: VLAN tag |
| 663 | * |
| 664 | * Returns ptr to the filter object or NULL when no memory available. |
| 665 | **/ |
| 666 | static struct |
| 667 | i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 668 | { |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 669 | struct i40evf_vlan_filter *f = NULL; |
| 670 | int count = 50; |
| 671 | |
| 672 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 673 | &adapter->crit_section)) { |
| 674 | udelay(1); |
| 675 | if (--count == 0) |
| 676 | goto out; |
| 677 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 678 | |
| 679 | f = i40evf_find_vlan(adapter, vlan); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 680 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 681 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 682 | if (!f) |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 683 | goto clearout; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 684 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 685 | f->vlan = vlan; |
| 686 | |
| 687 | INIT_LIST_HEAD(&f->list); |
| 688 | list_add(&f->list, &adapter->vlan_filter_list); |
| 689 | f->add = true; |
| 690 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
| 691 | } |
| 692 | |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 693 | clearout: |
| 694 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 695 | out: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 696 | return f; |
| 697 | } |
| 698 | |
| 699 | /** |
| 700 | * i40evf_del_vlan - Remove a vlan filter from the list |
| 701 | * @adapter: board private structure |
| 702 | * @vlan: VLAN tag |
| 703 | **/ |
| 704 | static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 705 | { |
| 706 | struct i40evf_vlan_filter *f; |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 707 | int count = 50; |
| 708 | |
| 709 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 710 | &adapter->crit_section)) { |
| 711 | udelay(1); |
| 712 | if (--count == 0) |
| 713 | return; |
| 714 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 715 | |
| 716 | f = i40evf_find_vlan(adapter, vlan); |
| 717 | if (f) { |
| 718 | f->remove = true; |
| 719 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
| 720 | } |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 721 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /** |
| 725 | * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device |
| 726 | * @netdev: network device struct |
| 727 | * @vid: VLAN tag |
| 728 | **/ |
| 729 | static int i40evf_vlan_rx_add_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 730 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 731 | { |
| 732 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 733 | |
| 734 | if (i40evf_add_vlan(adapter, vid) == NULL) |
| 735 | return -ENOMEM; |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device |
| 741 | * @netdev: network device struct |
| 742 | * @vid: VLAN tag |
| 743 | **/ |
| 744 | static int i40evf_vlan_rx_kill_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 745 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 746 | { |
| 747 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 748 | |
| 749 | i40evf_del_vlan(adapter, vid); |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * i40evf_find_filter - Search filter list for specific mac filter |
| 755 | * @adapter: board private structure |
| 756 | * @macaddr: the MAC address |
| 757 | * |
| 758 | * Returns ptr to the filter object or NULL |
| 759 | **/ |
| 760 | static struct |
| 761 | i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter, |
| 762 | u8 *macaddr) |
| 763 | { |
| 764 | struct i40evf_mac_filter *f; |
| 765 | |
| 766 | if (!macaddr) |
| 767 | return NULL; |
| 768 | |
| 769 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 770 | if (ether_addr_equal(macaddr, f->macaddr)) |
| 771 | return f; |
| 772 | } |
| 773 | return NULL; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * i40e_add_filter - Add a mac filter to the filter list |
| 778 | * @adapter: board private structure |
| 779 | * @macaddr: the MAC address |
| 780 | * |
| 781 | * Returns ptr to the filter object or NULL when no memory available. |
| 782 | **/ |
| 783 | static struct |
| 784 | i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter, |
| 785 | u8 *macaddr) |
| 786 | { |
| 787 | struct i40evf_mac_filter *f; |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 788 | int count = 50; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 789 | |
| 790 | if (!macaddr) |
| 791 | return NULL; |
| 792 | |
| 793 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 794 | &adapter->crit_section)) { |
Mitch Williams | b65476c | 2014-07-09 07:46:14 +0000 | [diff] [blame] | 795 | udelay(1); |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 796 | if (--count == 0) |
| 797 | return NULL; |
| 798 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 799 | |
| 800 | f = i40evf_find_filter(adapter, macaddr); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 801 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 802 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 803 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 804 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
| 805 | &adapter->crit_section); |
| 806 | return NULL; |
| 807 | } |
| 808 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 809 | ether_addr_copy(f->macaddr, macaddr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 810 | |
| 811 | list_add(&f->list, &adapter->mac_filter_list); |
| 812 | f->add = true; |
| 813 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
| 814 | } |
| 815 | |
| 816 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 817 | return f; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * i40evf_set_mac - NDO callback to set port mac address |
| 822 | * @netdev: network interface device structure |
| 823 | * @p: pointer to an address structure |
| 824 | * |
| 825 | * Returns 0 on success, negative on failure |
| 826 | **/ |
| 827 | static int i40evf_set_mac(struct net_device *netdev, void *p) |
| 828 | { |
| 829 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 830 | struct i40e_hw *hw = &adapter->hw; |
| 831 | struct i40evf_mac_filter *f; |
| 832 | struct sockaddr *addr = p; |
| 833 | |
| 834 | if (!is_valid_ether_addr(addr->sa_data)) |
| 835 | return -EADDRNOTAVAIL; |
| 836 | |
| 837 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) |
| 838 | return 0; |
| 839 | |
| 840 | f = i40evf_add_filter(adapter, addr->sa_data); |
| 841 | if (f) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 842 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
| 843 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | return (f == NULL) ? -ENOMEM : 0; |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * i40evf_set_rx_mode - NDO callback to set the netdev filters |
| 851 | * @netdev: network interface device structure |
| 852 | **/ |
| 853 | static void i40evf_set_rx_mode(struct net_device *netdev) |
| 854 | { |
| 855 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 856 | struct i40evf_mac_filter *f, *ftmp; |
| 857 | struct netdev_hw_addr *uca; |
| 858 | struct netdev_hw_addr *mca; |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 859 | int count = 50; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 860 | |
| 861 | /* add addr if not already in the filter list */ |
| 862 | netdev_for_each_uc_addr(uca, netdev) { |
| 863 | i40evf_add_filter(adapter, uca->addr); |
| 864 | } |
| 865 | netdev_for_each_mc_addr(mca, netdev) { |
| 866 | i40evf_add_filter(adapter, mca->addr); |
| 867 | } |
| 868 | |
| 869 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 870 | &adapter->crit_section)) { |
Mitch Williams | b65476c | 2014-07-09 07:46:14 +0000 | [diff] [blame] | 871 | udelay(1); |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 872 | if (--count == 0) { |
| 873 | dev_err(&adapter->pdev->dev, |
| 874 | "Failed to get lock in %s\n", __func__); |
| 875 | return; |
| 876 | } |
| 877 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 878 | /* remove filter if not in netdev list */ |
| 879 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 880 | bool found = false; |
| 881 | |
Tobias Klauser | dc5f2de | 2014-05-20 08:23:06 +0000 | [diff] [blame] | 882 | if (is_multicast_ether_addr(f->macaddr)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 883 | netdev_for_each_mc_addr(mca, netdev) { |
| 884 | if (ether_addr_equal(mca->addr, f->macaddr)) { |
| 885 | found = true; |
| 886 | break; |
| 887 | } |
| 888 | } |
| 889 | } else { |
| 890 | netdev_for_each_uc_addr(uca, netdev) { |
| 891 | if (ether_addr_equal(uca->addr, f->macaddr)) { |
| 892 | found = true; |
| 893 | break; |
| 894 | } |
| 895 | } |
Mitch Williams | 68ef169 | 2015-04-27 14:57:16 -0400 | [diff] [blame] | 896 | if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) |
| 897 | found = true; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 898 | } |
Mitch Williams | 68ef169 | 2015-04-27 14:57:16 -0400 | [diff] [blame] | 899 | if (!found) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 900 | f->remove = true; |
| 901 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 902 | } |
| 903 | } |
| 904 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * i40evf_napi_enable_all - enable NAPI on all queue vectors |
| 909 | * @adapter: board private structure |
| 910 | **/ |
| 911 | static void i40evf_napi_enable_all(struct i40evf_adapter *adapter) |
| 912 | { |
| 913 | int q_idx; |
| 914 | struct i40e_q_vector *q_vector; |
| 915 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 916 | |
| 917 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 918 | struct napi_struct *napi; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 919 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 920 | q_vector = adapter->q_vector[q_idx]; |
| 921 | napi = &q_vector->napi; |
| 922 | napi_enable(napi); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /** |
| 927 | * i40evf_napi_disable_all - disable NAPI on all queue vectors |
| 928 | * @adapter: board private structure |
| 929 | **/ |
| 930 | static void i40evf_napi_disable_all(struct i40evf_adapter *adapter) |
| 931 | { |
| 932 | int q_idx; |
| 933 | struct i40e_q_vector *q_vector; |
| 934 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 935 | |
| 936 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 937 | q_vector = adapter->q_vector[q_idx]; |
| 938 | napi_disable(&q_vector->napi); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * i40evf_configure - set up transmit and receive data structures |
| 944 | * @adapter: board private structure |
| 945 | **/ |
| 946 | static void i40evf_configure(struct i40evf_adapter *adapter) |
| 947 | { |
| 948 | struct net_device *netdev = adapter->netdev; |
| 949 | int i; |
| 950 | |
| 951 | i40evf_set_rx_mode(netdev); |
| 952 | |
| 953 | i40evf_configure_tx(adapter); |
| 954 | i40evf_configure_rx(adapter); |
| 955 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES; |
| 956 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 957 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 958 | struct i40e_ring *ring = adapter->rx_rings[i]; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 959 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 960 | i40evf_alloc_rx_buffers_1buf(ring, ring->count); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 961 | ring->next_to_use = ring->count - 1; |
| 962 | writel(ring->next_to_use, ring->tail); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * i40evf_up_complete - Finish the last steps of bringing up a connection |
| 968 | * @adapter: board private structure |
| 969 | **/ |
| 970 | static int i40evf_up_complete(struct i40evf_adapter *adapter) |
| 971 | { |
| 972 | adapter->state = __I40EVF_RUNNING; |
| 973 | clear_bit(__I40E_DOWN, &adapter->vsi.state); |
| 974 | |
| 975 | i40evf_napi_enable_all(adapter); |
| 976 | |
| 977 | adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES; |
| 978 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 983 | * i40e_down - Shutdown the connection processing |
| 984 | * @adapter: board private structure |
| 985 | **/ |
| 986 | void i40evf_down(struct i40evf_adapter *adapter) |
| 987 | { |
| 988 | struct net_device *netdev = adapter->netdev; |
| 989 | struct i40evf_mac_filter *f; |
| 990 | |
Mitch Williams | ddf0b3a | 2014-05-22 06:31:46 +0000 | [diff] [blame] | 991 | if (adapter->state == __I40EVF_DOWN) |
| 992 | return; |
| 993 | |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 994 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 995 | &adapter->crit_section)) |
| 996 | usleep_range(500, 1000); |
| 997 | |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 998 | netif_carrier_off(netdev); |
| 999 | netif_tx_disable(netdev); |
Mitch Williams | 748c434 | 2015-01-29 07:17:18 +0000 | [diff] [blame] | 1000 | i40evf_napi_disable_all(adapter); |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 1001 | i40evf_irq_disable(adapter); |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1002 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1003 | /* remove all MAC filters */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1004 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1005 | f->remove = true; |
| 1006 | } |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1007 | /* remove all VLAN filters */ |
| 1008 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 1009 | f->remove = true; |
| 1010 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1011 | if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) && |
| 1012 | adapter->state != __I40EVF_RESETTING) { |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1013 | /* cancel any current operation */ |
| 1014 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1015 | /* Schedule operations to close down the HW. Don't wait |
| 1016 | * here for this to complete. The watchdog is still running |
| 1017 | * and it will take care of this. |
| 1018 | */ |
| 1019 | adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1020 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1021 | adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1022 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1023 | |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1024 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * i40evf_acquire_msix_vectors - Setup the MSIX capability |
| 1029 | * @adapter: board private structure |
| 1030 | * @vectors: number of vectors to request |
| 1031 | * |
| 1032 | * Work with the OS to set up the MSIX vectors needed. |
| 1033 | * |
| 1034 | * Returns 0 on success, negative on failure |
| 1035 | **/ |
| 1036 | static int |
| 1037 | i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors) |
| 1038 | { |
| 1039 | int err, vector_threshold; |
| 1040 | |
| 1041 | /* We'll want at least 3 (vector_threshold): |
| 1042 | * 0) Other (Admin Queue and link, mostly) |
| 1043 | * 1) TxQ[0] Cleanup |
| 1044 | * 2) RxQ[0] Cleanup |
| 1045 | */ |
| 1046 | vector_threshold = MIN_MSIX_COUNT; |
| 1047 | |
| 1048 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 1049 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 1050 | * Right now, we simply care about how many we'll get; we'll |
| 1051 | * set them up later while requesting irq's. |
| 1052 | */ |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1053 | err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 1054 | vector_threshold, vectors); |
| 1055 | if (err < 0) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1056 | dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1057 | kfree(adapter->msix_entries); |
| 1058 | adapter->msix_entries = NULL; |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1059 | return err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1060 | } |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1061 | |
| 1062 | /* Adjust for only the vectors we'll use, which is minimum |
| 1063 | * of max_msix_q_vectors + NONQ_VECS, or the number of |
| 1064 | * vectors we were allocated. |
| 1065 | */ |
| 1066 | adapter->num_msix_vectors = err; |
| 1067 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * i40evf_free_queues - Free memory for all rings |
| 1072 | * @adapter: board private structure to initialize |
| 1073 | * |
| 1074 | * Free all of the memory associated with queue pairs. |
| 1075 | **/ |
| 1076 | static void i40evf_free_queues(struct i40evf_adapter *adapter) |
| 1077 | { |
| 1078 | int i; |
| 1079 | |
| 1080 | if (!adapter->vsi_res) |
| 1081 | return; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1082 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1083 | if (adapter->tx_rings[i]) |
| 1084 | kfree_rcu(adapter->tx_rings[i], rcu); |
| 1085 | adapter->tx_rings[i] = NULL; |
| 1086 | adapter->rx_rings[i] = NULL; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * i40evf_alloc_queues - Allocate memory for all rings |
| 1092 | * @adapter: board private structure to initialize |
| 1093 | * |
| 1094 | * We allocate one ring per queue at run-time since we don't know the |
| 1095 | * number of queues at compile-time. The polling_netdev array is |
| 1096 | * intended for Multiqueue, but should work fine with a single queue. |
| 1097 | **/ |
| 1098 | static int i40evf_alloc_queues(struct i40evf_adapter *adapter) |
| 1099 | { |
| 1100 | int i; |
| 1101 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1102 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1103 | struct i40e_ring *tx_ring; |
| 1104 | struct i40e_ring *rx_ring; |
| 1105 | |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1106 | tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1107 | if (!tx_ring) |
| 1108 | goto err_out; |
| 1109 | |
| 1110 | tx_ring->queue_index = i; |
| 1111 | tx_ring->netdev = adapter->netdev; |
| 1112 | tx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1113 | tx_ring->count = adapter->tx_desc_count; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1114 | adapter->tx_rings[i] = tx_ring; |
| 1115 | |
| 1116 | rx_ring = &tx_ring[1]; |
| 1117 | rx_ring->queue_index = i; |
| 1118 | rx_ring->netdev = adapter->netdev; |
| 1119 | rx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1120 | rx_ring->count = adapter->rx_desc_count; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1121 | adapter->rx_rings[i] = rx_ring; |
| 1122 | } |
| 1123 | |
| 1124 | return 0; |
| 1125 | |
| 1126 | err_out: |
| 1127 | i40evf_free_queues(adapter); |
| 1128 | return -ENOMEM; |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported |
| 1133 | * @adapter: board private structure to initialize |
| 1134 | * |
| 1135 | * Attempt to configure the interrupts using the best available |
| 1136 | * capabilities of the hardware and the kernel. |
| 1137 | **/ |
| 1138 | static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter) |
| 1139 | { |
| 1140 | int vector, v_budget; |
| 1141 | int pairs = 0; |
| 1142 | int err = 0; |
| 1143 | |
| 1144 | if (!adapter->vsi_res) { |
| 1145 | err = -EIO; |
| 1146 | goto out; |
| 1147 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1148 | pairs = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1149 | |
| 1150 | /* It's easy to be greedy for MSI-X vectors, but it really |
| 1151 | * doesn't do us much good if we have a lot more vectors |
| 1152 | * than CPU's. So let's be conservative and only ask for |
| 1153 | * (roughly) twice the number of vectors as there are CPU's. |
| 1154 | */ |
Mitch Williams | 30a500e | 2014-02-11 08:27:52 +0000 | [diff] [blame] | 1155 | v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS; |
| 1156 | v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1157 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1158 | adapter->msix_entries = kcalloc(v_budget, |
| 1159 | sizeof(struct msix_entry), GFP_KERNEL); |
| 1160 | if (!adapter->msix_entries) { |
| 1161 | err = -ENOMEM; |
| 1162 | goto out; |
| 1163 | } |
| 1164 | |
| 1165 | for (vector = 0; vector < v_budget; vector++) |
| 1166 | adapter->msix_entries[vector].entry = vector; |
| 1167 | |
| 1168 | i40evf_acquire_msix_vectors(adapter, v_budget); |
| 1169 | |
| 1170 | out: |
| 1171 | adapter->netdev->real_num_tx_queues = pairs; |
| 1172 | return err; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1177 | * @adapter: board private structure to initialize |
| 1178 | * |
| 1179 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1180 | * return -ENOMEM. |
| 1181 | **/ |
| 1182 | static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter) |
| 1183 | { |
| 1184 | int q_idx, num_q_vectors; |
| 1185 | struct i40e_q_vector *q_vector; |
| 1186 | |
| 1187 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 1188 | |
| 1189 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1190 | q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1191 | if (!q_vector) |
| 1192 | goto err_out; |
| 1193 | q_vector->adapter = adapter; |
| 1194 | q_vector->vsi = &adapter->vsi; |
| 1195 | q_vector->v_idx = q_idx; |
| 1196 | netif_napi_add(adapter->netdev, &q_vector->napi, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1197 | i40evf_napi_poll, NAPI_POLL_WEIGHT); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1198 | adapter->q_vector[q_idx] = q_vector; |
| 1199 | } |
| 1200 | |
| 1201 | return 0; |
| 1202 | |
| 1203 | err_out: |
| 1204 | while (q_idx) { |
| 1205 | q_idx--; |
| 1206 | q_vector = adapter->q_vector[q_idx]; |
| 1207 | netif_napi_del(&q_vector->napi); |
| 1208 | kfree(q_vector); |
| 1209 | adapter->q_vector[q_idx] = NULL; |
| 1210 | } |
| 1211 | return -ENOMEM; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * i40evf_free_q_vectors - Free memory allocated for interrupt vectors |
| 1216 | * @adapter: board private structure to initialize |
| 1217 | * |
| 1218 | * This function frees the memory allocated to the q_vectors. In addition if |
| 1219 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 1220 | * to freeing the q_vector. |
| 1221 | **/ |
| 1222 | static void i40evf_free_q_vectors(struct i40evf_adapter *adapter) |
| 1223 | { |
| 1224 | int q_idx, num_q_vectors; |
| 1225 | int napi_vectors; |
| 1226 | |
| 1227 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1228 | napi_vectors = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1229 | |
| 1230 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 1231 | struct i40e_q_vector *q_vector = adapter->q_vector[q_idx]; |
| 1232 | |
| 1233 | adapter->q_vector[q_idx] = NULL; |
| 1234 | if (q_idx < napi_vectors) |
| 1235 | netif_napi_del(&q_vector->napi); |
| 1236 | kfree(q_vector); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | /** |
| 1241 | * i40evf_reset_interrupt_capability - Reset MSIX setup |
| 1242 | * @adapter: board private structure |
| 1243 | * |
| 1244 | **/ |
| 1245 | void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter) |
| 1246 | { |
| 1247 | pci_disable_msix(adapter->pdev); |
| 1248 | kfree(adapter->msix_entries); |
| 1249 | adapter->msix_entries = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init |
| 1254 | * @adapter: board private structure to initialize |
| 1255 | * |
| 1256 | **/ |
| 1257 | int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter) |
| 1258 | { |
| 1259 | int err; |
| 1260 | |
| 1261 | err = i40evf_set_interrupt_capability(adapter); |
| 1262 | if (err) { |
| 1263 | dev_err(&adapter->pdev->dev, |
| 1264 | "Unable to setup interrupt capabilities\n"); |
| 1265 | goto err_set_interrupt; |
| 1266 | } |
| 1267 | |
| 1268 | err = i40evf_alloc_q_vectors(adapter); |
| 1269 | if (err) { |
| 1270 | dev_err(&adapter->pdev->dev, |
| 1271 | "Unable to allocate memory for queue vectors\n"); |
| 1272 | goto err_alloc_q_vectors; |
| 1273 | } |
| 1274 | |
| 1275 | err = i40evf_alloc_queues(adapter); |
| 1276 | if (err) { |
| 1277 | dev_err(&adapter->pdev->dev, |
| 1278 | "Unable to allocate memory for queues\n"); |
| 1279 | goto err_alloc_queues; |
| 1280 | } |
| 1281 | |
| 1282 | dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1283 | (adapter->num_active_queues > 1) ? "Enabled" : "Disabled", |
| 1284 | adapter->num_active_queues); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1285 | |
| 1286 | return 0; |
| 1287 | err_alloc_queues: |
| 1288 | i40evf_free_q_vectors(adapter); |
| 1289 | err_alloc_q_vectors: |
| 1290 | i40evf_reset_interrupt_capability(adapter); |
| 1291 | err_set_interrupt: |
| 1292 | return err; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * i40evf_watchdog_timer - Periodic call-back timer |
| 1297 | * @data: pointer to adapter disguised as unsigned long |
| 1298 | **/ |
| 1299 | static void i40evf_watchdog_timer(unsigned long data) |
| 1300 | { |
| 1301 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)data; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1302 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1303 | schedule_work(&adapter->watchdog_task); |
| 1304 | /* timer will be rescheduled in watchdog task */ |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * i40evf_watchdog_task - Periodic call-back task |
| 1309 | * @work: pointer to work_struct |
| 1310 | **/ |
| 1311 | static void i40evf_watchdog_task(struct work_struct *work) |
| 1312 | { |
| 1313 | struct i40evf_adapter *adapter = container_of(work, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1314 | struct i40evf_adapter, |
| 1315 | watchdog_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1316 | struct i40e_hw *hw = &adapter->hw; |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1317 | uint32_t rstat_val; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1318 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1319 | if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section)) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1320 | goto restart_watchdog; |
| 1321 | |
| 1322 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1323 | rstat_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1324 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
| 1325 | if ((rstat_val == I40E_VFR_VFACTIVE) || |
| 1326 | (rstat_val == I40E_VFR_COMPLETED)) { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1327 | /* A chance for redemption! */ |
| 1328 | dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n"); |
| 1329 | adapter->state = __I40EVF_STARTUP; |
| 1330 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 1331 | schedule_delayed_work(&adapter->init_task, 10); |
| 1332 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1333 | &adapter->crit_section); |
| 1334 | /* Don't reschedule the watchdog, since we've restarted |
| 1335 | * the init task. When init_task contacts the PF and |
| 1336 | * gets everything set up again, it'll restart the |
| 1337 | * watchdog for us. Down, boy. Sit. Stay. Woof. |
| 1338 | */ |
| 1339 | return; |
| 1340 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1341 | adapter->aq_required = 0; |
| 1342 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 1343 | goto watchdog_done; |
| 1344 | } |
| 1345 | |
| 1346 | if ((adapter->state < __I40EVF_DOWN) || |
| 1347 | (adapter->flags & I40EVF_FLAG_RESET_PENDING)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1348 | goto watchdog_done; |
| 1349 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1350 | /* check for reset */ |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1351 | rstat_val = rd32(hw, I40E_VFGEN_RSTAT) & |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1352 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1353 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1354 | (rstat_val != I40E_VFR_VFACTIVE) && |
| 1355 | (rstat_val != I40E_VFR_COMPLETED)) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1356 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1357 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1358 | dev_err(&adapter->pdev->dev, "Hardware reset detected\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1359 | schedule_work(&adapter->reset_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1360 | adapter->aq_required = 0; |
| 1361 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1362 | goto watchdog_done; |
| 1363 | } |
| 1364 | |
| 1365 | /* Process admin queue tasks. After init, everything gets done |
| 1366 | * here so we don't race on the admin queue. |
| 1367 | */ |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 1368 | if (adapter->current_op) { |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1369 | if (!i40evf_asq_done(hw)) { |
| 1370 | dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n"); |
| 1371 | i40evf_send_api_ver(adapter); |
| 1372 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1373 | goto watchdog_done; |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1374 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1375 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) { |
| 1376 | i40evf_send_vf_config_msg(adapter); |
| 1377 | goto watchdog_done; |
| 1378 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1379 | |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1380 | if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) { |
| 1381 | i40evf_disable_queues(adapter); |
| 1382 | goto watchdog_done; |
| 1383 | } |
| 1384 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1385 | if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) { |
| 1386 | i40evf_map_queues(adapter); |
| 1387 | goto watchdog_done; |
| 1388 | } |
| 1389 | |
| 1390 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) { |
| 1391 | i40evf_add_ether_addrs(adapter); |
| 1392 | goto watchdog_done; |
| 1393 | } |
| 1394 | |
| 1395 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) { |
| 1396 | i40evf_add_vlans(adapter); |
| 1397 | goto watchdog_done; |
| 1398 | } |
| 1399 | |
| 1400 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) { |
| 1401 | i40evf_del_ether_addrs(adapter); |
| 1402 | goto watchdog_done; |
| 1403 | } |
| 1404 | |
| 1405 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) { |
| 1406 | i40evf_del_vlans(adapter); |
| 1407 | goto watchdog_done; |
| 1408 | } |
| 1409 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1410 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) { |
| 1411 | i40evf_configure_queues(adapter); |
| 1412 | goto watchdog_done; |
| 1413 | } |
| 1414 | |
| 1415 | if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) { |
| 1416 | i40evf_enable_queues(adapter); |
| 1417 | goto watchdog_done; |
| 1418 | } |
| 1419 | |
| 1420 | if (adapter->state == __I40EVF_RUNNING) |
| 1421 | i40evf_request_stats(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1422 | watchdog_done: |
Mitch A Williams | 4870e17 | 2014-12-09 08:53:06 +0000 | [diff] [blame] | 1423 | if (adapter->state == __I40EVF_RUNNING) { |
| 1424 | i40evf_irq_enable_queues(adapter, ~0); |
| 1425 | i40evf_fire_sw_int(adapter, 0xFF); |
| 1426 | } else { |
| 1427 | i40evf_fire_sw_int(adapter, 0x1); |
| 1428 | } |
| 1429 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1430 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 1431 | restart_watchdog: |
Ashish Shah | d3e2edb | 2014-08-01 13:27:12 -0700 | [diff] [blame] | 1432 | if (adapter->state == __I40EVF_REMOVE) |
| 1433 | return; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1434 | if (adapter->aq_required) |
| 1435 | mod_timer(&adapter->watchdog_timer, |
| 1436 | jiffies + msecs_to_jiffies(20)); |
| 1437 | else |
| 1438 | mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1439 | schedule_work(&adapter->adminq_task); |
| 1440 | } |
| 1441 | |
Mitch A Williams | 5b7af02 | 2014-03-28 06:49:02 +0000 | [diff] [blame] | 1442 | /** |
Anjali Singhai Jain | 9a9c8ae | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 1443 | * i40evf_configure_rss - Prepare for RSS |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1444 | * @adapter: board private structure |
| 1445 | **/ |
| 1446 | static void i40evf_configure_rss(struct i40evf_adapter *adapter) |
| 1447 | { |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 1448 | u32 rss_key[I40E_VFQF_HKEY_MAX_INDEX + 1]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1449 | struct i40e_hw *hw = &adapter->hw; |
Anjali Singhai Jain | 9a9c8ae | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 1450 | u32 cqueue = 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1451 | u32 lut = 0; |
| 1452 | int i, j; |
| 1453 | u64 hena; |
| 1454 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1455 | /* Hash type is configured by the PF - we just supply the key */ |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 1456 | netdev_rss_key_fill(rss_key, sizeof(rss_key)); |
Anjali Singhai Jain | 9a9c8ae | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 1457 | |
| 1458 | /* Fill out hash function seed */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1459 | for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 1460 | wr32(hw, I40E_VFQF_HKEY(i), rss_key[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1461 | |
| 1462 | /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */ |
| 1463 | hena = I40E_DEFAULT_RSS_HENA; |
| 1464 | wr32(hw, I40E_VFQF_HENA(0), (u32)hena); |
| 1465 | wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32)); |
| 1466 | |
| 1467 | /* Populate the LUT with max no. of queues in round robin fashion */ |
Mitch Williams | 96d4770 | 2014-02-11 08:27:50 +0000 | [diff] [blame] | 1468 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) { |
Anjali Singhai Jain | 9a9c8ae | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 1469 | lut = 0; |
| 1470 | for (j = 0; j < 4; j++) { |
Mitch Williams | 40746eb | 2015-06-22 17:26:38 -0700 | [diff] [blame] | 1471 | if (cqueue == adapter->num_active_queues) |
Anjali Singhai Jain | 9a9c8ae | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 1472 | cqueue = 0; |
| 1473 | lut |= ((cqueue) << (8 * j)); |
| 1474 | cqueue++; |
| 1475 | } |
Mitch Williams | 96d4770 | 2014-02-11 08:27:50 +0000 | [diff] [blame] | 1476 | wr32(hw, I40E_VFQF_HLUT(i), lut); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1477 | } |
| 1478 | i40e_flush(hw); |
| 1479 | } |
| 1480 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1481 | #define I40EVF_RESET_WAIT_MS 10 |
| 1482 | #define I40EVF_RESET_WAIT_COUNT 500 |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1483 | /** |
| 1484 | * i40evf_reset_task - Call-back task to handle hardware reset |
| 1485 | * @work: pointer to work_struct |
| 1486 | * |
| 1487 | * During reset we need to shut down and reinitialize the admin queue |
| 1488 | * before we can use it to communicate with the PF again. We also clear |
| 1489 | * and reinit the rings because that context is lost as well. |
| 1490 | **/ |
| 1491 | static void i40evf_reset_task(struct work_struct *work) |
| 1492 | { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1493 | struct i40evf_adapter *adapter = container_of(work, |
| 1494 | struct i40evf_adapter, |
| 1495 | reset_task); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1496 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1497 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1498 | struct i40evf_mac_filter *f; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1499 | uint32_t rstat_val; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1500 | int i = 0, err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1501 | |
| 1502 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1503 | &adapter->crit_section)) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 1504 | usleep_range(500, 1000); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1505 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1506 | i40evf_misc_irq_disable(adapter); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1507 | if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1508 | adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED; |
| 1509 | /* Restart the AQ here. If we have been reset but didn't |
| 1510 | * detect it, or if the PF had to reinit, our AQ will be hosed. |
| 1511 | */ |
| 1512 | i40evf_shutdown_adminq(hw); |
| 1513 | i40evf_init_adminq(hw); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1514 | i40evf_request_reset(adapter); |
| 1515 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1516 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1517 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1518 | /* poll until we see the reset actually happen */ |
| 1519 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1520 | rstat_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1521 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1522 | if ((rstat_val != I40E_VFR_VFACTIVE) && |
| 1523 | (rstat_val != I40E_VFR_COMPLETED)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1524 | break; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1525 | usleep_range(500, 1000); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1526 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1527 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1528 | dev_info(&adapter->pdev->dev, "Never saw reset\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1529 | goto continue_reset; /* act like the reset happened */ |
| 1530 | } |
| 1531 | |
| 1532 | /* wait until the reset is complete and the PF is responding to us */ |
| 1533 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
| 1534 | rstat_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1535 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1536 | if (rstat_val == I40E_VFR_VFACTIVE) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1537 | break; |
Mitch Williams | c88e38c | 2014-11-11 20:03:13 +0000 | [diff] [blame] | 1538 | msleep(I40EVF_RESET_WAIT_MS); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1539 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1540 | /* extra wait to make sure minimum wait is met */ |
| 1541 | msleep(I40EVF_RESET_WAIT_MS); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1542 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 1543 | struct i40evf_mac_filter *f, *ftmp; |
| 1544 | struct i40evf_vlan_filter *fv, *fvtmp; |
| 1545 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1546 | /* reset never finished */ |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1547 | dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1548 | rstat_val); |
| 1549 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
| 1550 | |
Mitch Williams | 169f407 | 2014-04-01 07:11:50 +0000 | [diff] [blame] | 1551 | if (netif_running(adapter->netdev)) { |
| 1552 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1553 | netif_carrier_off(netdev); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1554 | netif_tx_disable(netdev); |
| 1555 | i40evf_napi_disable_all(adapter); |
| 1556 | i40evf_irq_disable(adapter); |
Mitch Williams | 169f407 | 2014-04-01 07:11:50 +0000 | [diff] [blame] | 1557 | i40evf_free_traffic_irqs(adapter); |
| 1558 | i40evf_free_all_tx_resources(adapter); |
| 1559 | i40evf_free_all_rx_resources(adapter); |
| 1560 | } |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 1561 | |
| 1562 | /* Delete all of the filters, both MAC and VLAN. */ |
| 1563 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, |
| 1564 | list) { |
| 1565 | list_del(&f->list); |
| 1566 | kfree(f); |
| 1567 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1568 | |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 1569 | list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, |
| 1570 | list) { |
| 1571 | list_del(&fv->list); |
| 1572 | kfree(fv); |
| 1573 | } |
| 1574 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1575 | i40evf_free_misc_irq(adapter); |
| 1576 | i40evf_reset_interrupt_capability(adapter); |
| 1577 | i40evf_free_queues(adapter); |
Mitch Williams | d31944d | 2014-08-01 13:27:13 -0700 | [diff] [blame] | 1578 | i40evf_free_q_vectors(adapter); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1579 | kfree(adapter->vf_res); |
| 1580 | i40evf_shutdown_adminq(hw); |
| 1581 | adapter->netdev->flags &= ~IFF_UP; |
| 1582 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1583 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1584 | dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1585 | return; /* Do not attempt to reinit. It's dead, Jim. */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1586 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1587 | |
| 1588 | continue_reset: |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1589 | if (netif_running(adapter->netdev)) { |
| 1590 | netif_carrier_off(netdev); |
| 1591 | netif_tx_stop_all_queues(netdev); |
| 1592 | i40evf_napi_disable_all(adapter); |
| 1593 | } |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1594 | i40evf_irq_disable(adapter); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1595 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1596 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1597 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1598 | |
| 1599 | /* free the Tx/Rx rings and descriptors, might be better to just |
| 1600 | * re-use them sometime in the future |
| 1601 | */ |
| 1602 | i40evf_free_all_rx_resources(adapter); |
| 1603 | i40evf_free_all_tx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1604 | |
| 1605 | /* kill and reinit the admin queue */ |
| 1606 | if (i40evf_shutdown_adminq(hw)) |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1607 | dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n"); |
| 1608 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1609 | err = i40evf_init_adminq(hw); |
| 1610 | if (err) |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1611 | dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n", |
| 1612 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1613 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1614 | adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG; |
| 1615 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1616 | |
| 1617 | /* re-add all MAC filters */ |
| 1618 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1619 | f->add = true; |
| 1620 | } |
| 1621 | /* re-add all VLAN filters */ |
| 1622 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 1623 | f->add = true; |
| 1624 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1625 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1626 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1627 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1628 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1629 | |
| 1630 | mod_timer(&adapter->watchdog_timer, jiffies + 2); |
| 1631 | |
| 1632 | if (netif_running(adapter->netdev)) { |
| 1633 | /* allocate transmit descriptors */ |
| 1634 | err = i40evf_setup_all_tx_resources(adapter); |
| 1635 | if (err) |
| 1636 | goto reset_err; |
| 1637 | |
| 1638 | /* allocate receive descriptors */ |
| 1639 | err = i40evf_setup_all_rx_resources(adapter); |
| 1640 | if (err) |
| 1641 | goto reset_err; |
| 1642 | |
| 1643 | i40evf_configure(adapter); |
| 1644 | |
| 1645 | err = i40evf_up_complete(adapter); |
| 1646 | if (err) |
| 1647 | goto reset_err; |
| 1648 | |
| 1649 | i40evf_irq_enable(adapter, true); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1650 | } else { |
| 1651 | adapter->state = __I40EVF_DOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1652 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1653 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1654 | return; |
| 1655 | reset_err: |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1656 | dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1657 | i40evf_close(adapter->netdev); |
| 1658 | } |
| 1659 | |
| 1660 | /** |
| 1661 | * i40evf_adminq_task - worker thread to clean the admin queue |
| 1662 | * @work: pointer to work_struct containing our data |
| 1663 | **/ |
| 1664 | static void i40evf_adminq_task(struct work_struct *work) |
| 1665 | { |
| 1666 | struct i40evf_adapter *adapter = |
| 1667 | container_of(work, struct i40evf_adapter, adminq_task); |
| 1668 | struct i40e_hw *hw = &adapter->hw; |
| 1669 | struct i40e_arq_event_info event; |
| 1670 | struct i40e_virtchnl_msg *v_msg; |
| 1671 | i40e_status ret; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1672 | u32 val, oldval; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1673 | u16 pending; |
| 1674 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1675 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1676 | goto out; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1677 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 1678 | event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; |
| 1679 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1680 | if (!event.msg_buf) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1681 | goto out; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1682 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1683 | v_msg = (struct i40e_virtchnl_msg *)&event.desc; |
| 1684 | do { |
| 1685 | ret = i40evf_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 8b011eb | 2015-01-09 11:18:17 +0000 | [diff] [blame] | 1686 | if (ret || !v_msg->v_opcode) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1687 | break; /* No event to process or error cleaning ARQ */ |
| 1688 | |
| 1689 | i40evf_virtchnl_completion(adapter, v_msg->v_opcode, |
| 1690 | v_msg->v_retval, event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 1691 | event.msg_len); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1692 | if (pending != 0) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1693 | memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1694 | } while (pending); |
| 1695 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1696 | if ((adapter->flags & |
| 1697 | (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) || |
| 1698 | adapter->state == __I40EVF_RESETTING) |
| 1699 | goto freedom; |
| 1700 | |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1701 | /* check for error indications */ |
| 1702 | val = rd32(hw, hw->aq.arq.len); |
| 1703 | oldval = val; |
| 1704 | if (val & I40E_VF_ARQLEN_ARQVFE_MASK) { |
| 1705 | dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n"); |
| 1706 | val &= ~I40E_VF_ARQLEN_ARQVFE_MASK; |
| 1707 | } |
| 1708 | if (val & I40E_VF_ARQLEN_ARQOVFL_MASK) { |
| 1709 | dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n"); |
| 1710 | val &= ~I40E_VF_ARQLEN_ARQOVFL_MASK; |
| 1711 | } |
| 1712 | if (val & I40E_VF_ARQLEN_ARQCRIT_MASK) { |
| 1713 | dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n"); |
| 1714 | val &= ~I40E_VF_ARQLEN_ARQCRIT_MASK; |
| 1715 | } |
| 1716 | if (oldval != val) |
| 1717 | wr32(hw, hw->aq.arq.len, val); |
| 1718 | |
| 1719 | val = rd32(hw, hw->aq.asq.len); |
| 1720 | oldval = val; |
| 1721 | if (val & I40E_VF_ATQLEN_ATQVFE_MASK) { |
| 1722 | dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n"); |
| 1723 | val &= ~I40E_VF_ATQLEN_ATQVFE_MASK; |
| 1724 | } |
| 1725 | if (val & I40E_VF_ATQLEN_ATQOVFL_MASK) { |
| 1726 | dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n"); |
| 1727 | val &= ~I40E_VF_ATQLEN_ATQOVFL_MASK; |
| 1728 | } |
| 1729 | if (val & I40E_VF_ATQLEN_ATQCRIT_MASK) { |
| 1730 | dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n"); |
| 1731 | val &= ~I40E_VF_ATQLEN_ATQCRIT_MASK; |
| 1732 | } |
| 1733 | if (oldval != val) |
| 1734 | wr32(hw, hw->aq.asq.len, val); |
| 1735 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1736 | freedom: |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1737 | kfree(event.msg_buf); |
| 1738 | out: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1739 | /* re-enable Admin queue interrupt cause */ |
| 1740 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /** |
| 1744 | * i40evf_free_all_tx_resources - Free Tx Resources for All Queues |
| 1745 | * @adapter: board private structure |
| 1746 | * |
| 1747 | * Free all transmit software resources |
| 1748 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1749 | void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1750 | { |
| 1751 | int i; |
| 1752 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1753 | for (i = 0; i < adapter->num_active_queues; i++) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1754 | if (adapter->tx_rings[i]->desc) |
| 1755 | i40evf_free_tx_resources(adapter->tx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * i40evf_setup_all_tx_resources - allocate all queues Tx resources |
| 1760 | * @adapter: board private structure |
| 1761 | * |
| 1762 | * If this function returns with an error, then it's possible one or |
| 1763 | * more of the rings is populated (while the rest are not). It is the |
| 1764 | * callers duty to clean those orphaned rings. |
| 1765 | * |
| 1766 | * Return 0 on success, negative on failure |
| 1767 | **/ |
| 1768 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter) |
| 1769 | { |
| 1770 | int i, err = 0; |
| 1771 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1772 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1773 | adapter->tx_rings[i]->count = adapter->tx_desc_count; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1774 | err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]); |
| 1775 | if (!err) |
| 1776 | continue; |
| 1777 | dev_err(&adapter->pdev->dev, |
| 1778 | "%s: Allocation for Tx Queue %u failed\n", |
| 1779 | __func__, i); |
| 1780 | break; |
| 1781 | } |
| 1782 | |
| 1783 | return err; |
| 1784 | } |
| 1785 | |
| 1786 | /** |
| 1787 | * i40evf_setup_all_rx_resources - allocate all queues Rx resources |
| 1788 | * @adapter: board private structure |
| 1789 | * |
| 1790 | * If this function returns with an error, then it's possible one or |
| 1791 | * more of the rings is populated (while the rest are not). It is the |
| 1792 | * callers duty to clean those orphaned rings. |
| 1793 | * |
| 1794 | * Return 0 on success, negative on failure |
| 1795 | **/ |
| 1796 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter) |
| 1797 | { |
| 1798 | int i, err = 0; |
| 1799 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1800 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1801 | adapter->rx_rings[i]->count = adapter->rx_desc_count; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1802 | err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]); |
| 1803 | if (!err) |
| 1804 | continue; |
| 1805 | dev_err(&adapter->pdev->dev, |
| 1806 | "%s: Allocation for Rx Queue %u failed\n", |
| 1807 | __func__, i); |
| 1808 | break; |
| 1809 | } |
| 1810 | return err; |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * i40evf_free_all_rx_resources - Free Rx Resources for All Queues |
| 1815 | * @adapter: board private structure |
| 1816 | * |
| 1817 | * Free all receive software resources |
| 1818 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1819 | void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1820 | { |
| 1821 | int i; |
| 1822 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1823 | for (i = 0; i < adapter->num_active_queues; i++) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1824 | if (adapter->rx_rings[i]->desc) |
| 1825 | i40evf_free_rx_resources(adapter->rx_rings[i]); |
| 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * i40evf_open - Called when a network interface is made active |
| 1830 | * @netdev: network interface device structure |
| 1831 | * |
| 1832 | * Returns 0 on success, negative value on failure |
| 1833 | * |
| 1834 | * The open entry point is called when a network interface is made |
| 1835 | * active by the system (IFF_UP). At this point all resources needed |
| 1836 | * for transmit and receive operations are allocated, the interrupt |
| 1837 | * handler is registered with the OS, the watchdog timer is started, |
| 1838 | * and the stack is notified that the interface is ready. |
| 1839 | **/ |
| 1840 | static int i40evf_open(struct net_device *netdev) |
| 1841 | { |
| 1842 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 1843 | int err; |
| 1844 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1845 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
| 1846 | dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); |
| 1847 | return -EIO; |
| 1848 | } |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1849 | if (adapter->state != __I40EVF_DOWN || adapter->aq_required) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1850 | return -EBUSY; |
| 1851 | |
| 1852 | /* allocate transmit descriptors */ |
| 1853 | err = i40evf_setup_all_tx_resources(adapter); |
| 1854 | if (err) |
| 1855 | goto err_setup_tx; |
| 1856 | |
| 1857 | /* allocate receive descriptors */ |
| 1858 | err = i40evf_setup_all_rx_resources(adapter); |
| 1859 | if (err) |
| 1860 | goto err_setup_rx; |
| 1861 | |
| 1862 | /* clear any pending interrupts, may auto mask */ |
| 1863 | err = i40evf_request_traffic_irqs(adapter, netdev->name); |
| 1864 | if (err) |
| 1865 | goto err_req_irq; |
| 1866 | |
Mitch Williams | 44151cd | 2015-04-27 14:57:17 -0400 | [diff] [blame] | 1867 | i40evf_add_filter(adapter, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1868 | i40evf_configure(adapter); |
| 1869 | |
| 1870 | err = i40evf_up_complete(adapter); |
| 1871 | if (err) |
| 1872 | goto err_req_irq; |
| 1873 | |
| 1874 | i40evf_irq_enable(adapter, true); |
| 1875 | |
| 1876 | return 0; |
| 1877 | |
| 1878 | err_req_irq: |
| 1879 | i40evf_down(adapter); |
| 1880 | i40evf_free_traffic_irqs(adapter); |
| 1881 | err_setup_rx: |
| 1882 | i40evf_free_all_rx_resources(adapter); |
| 1883 | err_setup_tx: |
| 1884 | i40evf_free_all_tx_resources(adapter); |
| 1885 | |
| 1886 | return err; |
| 1887 | } |
| 1888 | |
| 1889 | /** |
| 1890 | * i40evf_close - Disables a network interface |
| 1891 | * @netdev: network interface device structure |
| 1892 | * |
| 1893 | * Returns 0, this is not allowed to fail |
| 1894 | * |
| 1895 | * The close entry point is called when an interface is de-activated |
| 1896 | * by the OS. The hardware is still under the drivers control, but |
| 1897 | * needs to be disabled. All IRQs except vector 0 (reserved for admin queue) |
| 1898 | * are freed, along with all transmit and receive resources. |
| 1899 | **/ |
| 1900 | static int i40evf_close(struct net_device *netdev) |
| 1901 | { |
| 1902 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 1903 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1904 | if (adapter->state <= __I40EVF_DOWN) |
| 1905 | return 0; |
| 1906 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1907 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1908 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
| 1909 | |
| 1910 | i40evf_down(adapter); |
Mitch Williams | ddf0b3a | 2014-05-22 06:31:46 +0000 | [diff] [blame] | 1911 | adapter->state = __I40EVF_DOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1912 | i40evf_free_traffic_irqs(adapter); |
| 1913 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1914 | return 0; |
| 1915 | } |
| 1916 | |
| 1917 | /** |
| 1918 | * i40evf_get_stats - Get System Network Statistics |
| 1919 | * @netdev: network interface device structure |
| 1920 | * |
| 1921 | * Returns the address of the device statistics structure. |
| 1922 | * The statistics are actually updated from the timer callback. |
| 1923 | **/ |
| 1924 | static struct net_device_stats *i40evf_get_stats(struct net_device *netdev) |
| 1925 | { |
| 1926 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 1927 | |
| 1928 | /* only return the current stats */ |
| 1929 | return &adapter->net_stats; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1933 | * i40evf_change_mtu - Change the Maximum Transfer Unit |
| 1934 | * @netdev: network interface device structure |
| 1935 | * @new_mtu: new value for maximum frame size |
| 1936 | * |
| 1937 | * Returns 0 on success, negative on failure |
| 1938 | **/ |
| 1939 | static int i40evf_change_mtu(struct net_device *netdev, int new_mtu) |
| 1940 | { |
| 1941 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 1942 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 1943 | |
| 1944 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 1945 | return -EINVAL; |
| 1946 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1947 | netdev->mtu = new_mtu; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1948 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
| 1949 | schedule_work(&adapter->reset_task); |
| 1950 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1951 | return 0; |
| 1952 | } |
| 1953 | |
| 1954 | static const struct net_device_ops i40evf_netdev_ops = { |
| 1955 | .ndo_open = i40evf_open, |
| 1956 | .ndo_stop = i40evf_close, |
| 1957 | .ndo_start_xmit = i40evf_xmit_frame, |
| 1958 | .ndo_get_stats = i40evf_get_stats, |
| 1959 | .ndo_set_rx_mode = i40evf_set_rx_mode, |
| 1960 | .ndo_validate_addr = eth_validate_addr, |
| 1961 | .ndo_set_mac_address = i40evf_set_mac, |
| 1962 | .ndo_change_mtu = i40evf_change_mtu, |
| 1963 | .ndo_tx_timeout = i40evf_tx_timeout, |
| 1964 | .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid, |
| 1965 | .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid, |
| 1966 | }; |
| 1967 | |
| 1968 | /** |
| 1969 | * i40evf_check_reset_complete - check that VF reset is complete |
| 1970 | * @hw: pointer to hw struct |
| 1971 | * |
| 1972 | * Returns 0 if device is ready to use, or -EBUSY if it's in reset. |
| 1973 | **/ |
| 1974 | static int i40evf_check_reset_complete(struct i40e_hw *hw) |
| 1975 | { |
| 1976 | u32 rstat; |
| 1977 | int i; |
| 1978 | |
| 1979 | for (i = 0; i < 100; i++) { |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 1980 | rstat = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1981 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
| 1982 | if ((rstat == I40E_VFR_VFACTIVE) || |
| 1983 | (rstat == I40E_VFR_COMPLETED)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1984 | return 0; |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 1985 | usleep_range(10, 20); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1986 | } |
| 1987 | return -EBUSY; |
| 1988 | } |
| 1989 | |
| 1990 | /** |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1991 | * i40evf_process_config - Process the config information we got from the PF |
| 1992 | * @adapter: board private structure |
| 1993 | * |
| 1994 | * Verify that we have a valid config struct, and set up our netdev features |
| 1995 | * and our VSI struct. |
| 1996 | **/ |
| 1997 | int i40evf_process_config(struct i40evf_adapter *adapter) |
| 1998 | { |
| 1999 | struct net_device *netdev = adapter->netdev; |
| 2000 | int i; |
| 2001 | |
| 2002 | /* got VF config message back from PF, now we can parse it */ |
| 2003 | for (i = 0; i < adapter->vf_res->num_vsis; i++) { |
| 2004 | if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV) |
| 2005 | adapter->vsi_res = &adapter->vf_res->vsi_res[i]; |
| 2006 | } |
| 2007 | if (!adapter->vsi_res) { |
| 2008 | dev_err(&adapter->pdev->dev, "No LAN VSI found\n"); |
| 2009 | return -ENODEV; |
| 2010 | } |
| 2011 | |
| 2012 | if (adapter->vf_res->vf_offload_flags |
| 2013 | & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) { |
| 2014 | netdev->vlan_features = netdev->features; |
| 2015 | netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 2016 | NETIF_F_HW_VLAN_CTAG_RX | |
| 2017 | NETIF_F_HW_VLAN_CTAG_FILTER; |
| 2018 | } |
| 2019 | netdev->features |= NETIF_F_HIGHDMA | |
| 2020 | NETIF_F_SG | |
| 2021 | NETIF_F_IP_CSUM | |
| 2022 | NETIF_F_SCTP_CSUM | |
| 2023 | NETIF_F_IPV6_CSUM | |
| 2024 | NETIF_F_TSO | |
| 2025 | NETIF_F_TSO6 | |
| 2026 | NETIF_F_RXCSUM | |
| 2027 | NETIF_F_GRO; |
| 2028 | |
| 2029 | /* copy netdev features into list of user selectable features */ |
| 2030 | netdev->hw_features |= netdev->features; |
| 2031 | netdev->hw_features &= ~NETIF_F_RXCSUM; |
| 2032 | |
| 2033 | adapter->vsi.id = adapter->vsi_res->vsi_id; |
| 2034 | |
| 2035 | adapter->vsi.back = adapter; |
| 2036 | adapter->vsi.base_vector = 1; |
| 2037 | adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK; |
| 2038 | adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC | |
| 2039 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF)); |
| 2040 | adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC | |
| 2041 | ITR_REG_TO_USEC(I40E_ITR_TX_DEF)); |
| 2042 | adapter->vsi.netdev = adapter->netdev; |
| 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2047 | * i40evf_init_task - worker thread to perform delayed initialization |
| 2048 | * @work: pointer to work_struct containing our data |
| 2049 | * |
| 2050 | * This task completes the work that was begun in probe. Due to the nature |
| 2051 | * 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] | 2052 | * 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] | 2053 | * whole system, we'll do it in a task so we can sleep. |
| 2054 | * This task only runs during driver init. Once we've established |
| 2055 | * communications with the PF driver and set up our netdev, the watchdog |
| 2056 | * takes over. |
| 2057 | **/ |
| 2058 | static void i40evf_init_task(struct work_struct *work) |
| 2059 | { |
| 2060 | struct i40evf_adapter *adapter = container_of(work, |
| 2061 | struct i40evf_adapter, |
| 2062 | init_task.work); |
| 2063 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2064 | struct i40e_hw *hw = &adapter->hw; |
| 2065 | struct pci_dev *pdev = adapter->pdev; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2066 | int err, bufsz; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2067 | |
| 2068 | switch (adapter->state) { |
| 2069 | case __I40EVF_STARTUP: |
| 2070 | /* driver loaded, probe complete */ |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2071 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 2072 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2073 | err = i40e_set_mac_type(hw); |
| 2074 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2075 | dev_err(&pdev->dev, "Failed to set MAC type (%d)\n", |
| 2076 | err); |
Mitch Williams | 2619ef4 | 2015-04-07 19:45:30 -0400 | [diff] [blame] | 2077 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2078 | } |
| 2079 | err = i40evf_check_reset_complete(hw); |
| 2080 | if (err) { |
Mitch Williams | 0d9c7ea | 2014-04-23 04:50:00 +0000 | [diff] [blame] | 2081 | dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2082 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2083 | goto err; |
| 2084 | } |
| 2085 | hw->aq.num_arq_entries = I40EVF_AQ_LEN; |
| 2086 | hw->aq.num_asq_entries = I40EVF_AQ_LEN; |
| 2087 | hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2088 | hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2089 | |
| 2090 | err = i40evf_init_adminq(hw); |
| 2091 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2092 | dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n", |
| 2093 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2094 | goto err; |
| 2095 | } |
| 2096 | err = i40evf_send_api_ver(adapter); |
| 2097 | if (err) { |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2098 | dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2099 | i40evf_shutdown_adminq(hw); |
| 2100 | goto err; |
| 2101 | } |
| 2102 | adapter->state = __I40EVF_INIT_VERSION_CHECK; |
| 2103 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2104 | case __I40EVF_INIT_VERSION_CHECK: |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2105 | if (!i40evf_asq_done(hw)) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 2106 | dev_err(&pdev->dev, "Admin queue command never completed\n"); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2107 | i40evf_shutdown_adminq(hw); |
| 2108 | adapter->state = __I40EVF_STARTUP; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2109 | goto err; |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2110 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2111 | |
| 2112 | /* aq msg sent, awaiting reply */ |
| 2113 | err = i40evf_verify_api_ver(adapter); |
| 2114 | if (err) { |
Mitch A Williams | d4f82fd | 2014-12-09 08:53:03 +0000 | [diff] [blame] | 2115 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Mitch Williams | 56f9920 | 2014-06-04 04:22:41 +0000 | [diff] [blame] | 2116 | err = i40evf_send_api_ver(adapter); |
Mitch Williams | ee1693e | 2015-06-04 16:23:59 -0400 | [diff] [blame] | 2117 | else |
| 2118 | dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n", |
| 2119 | adapter->pf_version.major, |
| 2120 | adapter->pf_version.minor, |
| 2121 | I40E_VIRTCHNL_VERSION_MAJOR, |
| 2122 | I40E_VIRTCHNL_VERSION_MINOR); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2123 | goto err; |
| 2124 | } |
| 2125 | err = i40evf_send_vf_config_msg(adapter); |
| 2126 | if (err) { |
Mitch Williams | 3f2ab17 | 2014-06-04 04:22:40 +0000 | [diff] [blame] | 2127 | dev_err(&pdev->dev, "Unable to send config request (%d)\n", |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2128 | err); |
| 2129 | goto err; |
| 2130 | } |
| 2131 | adapter->state = __I40EVF_INIT_GET_RESOURCES; |
| 2132 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2133 | case __I40EVF_INIT_GET_RESOURCES: |
| 2134 | /* aq msg sent, awaiting reply */ |
| 2135 | if (!adapter->vf_res) { |
| 2136 | bufsz = sizeof(struct i40e_virtchnl_vf_resource) + |
| 2137 | (I40E_MAX_VF_VSI * |
| 2138 | sizeof(struct i40e_virtchnl_vsi_resource)); |
| 2139 | adapter->vf_res = kzalloc(bufsz, GFP_KERNEL); |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2140 | if (!adapter->vf_res) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2141 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2142 | } |
| 2143 | err = i40evf_get_vf_config(adapter); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2144 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2145 | err = i40evf_send_vf_config_msg(adapter); |
| 2146 | goto err; |
| 2147 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2148 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2149 | dev_err(&pdev->dev, "Unable to get VF config (%d)\n", |
| 2150 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2151 | goto err_alloc; |
| 2152 | } |
| 2153 | adapter->state = __I40EVF_INIT_SW; |
| 2154 | break; |
| 2155 | default: |
| 2156 | goto err_alloc; |
| 2157 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2158 | if (i40evf_process_config(adapter)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2159 | goto err_alloc; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2160 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2161 | |
| 2162 | adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED; |
| 2163 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2164 | netdev->netdev_ops = &i40evf_netdev_ops; |
| 2165 | i40evf_set_ethtool_ops(netdev); |
| 2166 | netdev->watchdog_timeo = 5 * HZ; |
Greg Rose | 3415e8c | 2014-01-30 12:40:27 +0000 | [diff] [blame] | 2167 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2168 | if (!is_valid_ether_addr(adapter->hw.mac.addr)) { |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2169 | dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n", |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2170 | adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2171 | random_ether_addr(adapter->hw.mac.addr); |
| 2172 | } |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2173 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
| 2174 | ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2175 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2176 | init_timer(&adapter->watchdog_timer); |
| 2177 | adapter->watchdog_timer.function = &i40evf_watchdog_timer; |
| 2178 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 2179 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 2180 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2181 | adapter->num_active_queues = min_t(int, |
| 2182 | adapter->vsi_res->num_queue_pairs, |
| 2183 | (int)(num_online_cpus())); |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 2184 | adapter->tx_desc_count = I40EVF_DEFAULT_TXD; |
| 2185 | adapter->rx_desc_count = I40EVF_DEFAULT_RXD; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2186 | err = i40evf_init_interrupt_scheme(adapter); |
| 2187 | if (err) |
| 2188 | goto err_sw_init; |
| 2189 | i40evf_map_rings_to_vectors(adapter); |
| 2190 | i40evf_configure_rss(adapter); |
| 2191 | err = i40evf_request_misc_irq(adapter); |
| 2192 | if (err) |
| 2193 | goto err_sw_init; |
| 2194 | |
| 2195 | netif_carrier_off(netdev); |
| 2196 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2197 | if (!adapter->netdev_registered) { |
| 2198 | err = register_netdev(netdev); |
| 2199 | if (err) |
| 2200 | goto err_register; |
| 2201 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2202 | |
| 2203 | adapter->netdev_registered = true; |
| 2204 | |
| 2205 | netif_tx_stop_all_queues(netdev); |
| 2206 | |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2207 | dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2208 | if (netdev->features & NETIF_F_GRO) |
| 2209 | dev_info(&pdev->dev, "GRO is enabled\n"); |
| 2210 | |
| 2211 | dev_info(&pdev->dev, "%s\n", i40evf_driver_string); |
| 2212 | adapter->state = __I40EVF_DOWN; |
| 2213 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
| 2214 | i40evf_misc_irq_enable(adapter); |
| 2215 | return; |
| 2216 | restart: |
| 2217 | schedule_delayed_work(&adapter->init_task, |
| 2218 | msecs_to_jiffies(50)); |
| 2219 | return; |
| 2220 | |
| 2221 | err_register: |
| 2222 | i40evf_free_misc_irq(adapter); |
| 2223 | err_sw_init: |
| 2224 | i40evf_reset_interrupt_capability(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2225 | err_alloc: |
| 2226 | kfree(adapter->vf_res); |
| 2227 | adapter->vf_res = NULL; |
| 2228 | err: |
| 2229 | /* Things went into the weeds, so try again later */ |
| 2230 | if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 2231 | dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2232 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2233 | return; /* do not reschedule */ |
| 2234 | } |
| 2235 | schedule_delayed_work(&adapter->init_task, HZ * 3); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * i40evf_shutdown - Shutdown the device in preparation for a reboot |
| 2240 | * @pdev: pci device structure |
| 2241 | **/ |
| 2242 | static void i40evf_shutdown(struct pci_dev *pdev) |
| 2243 | { |
| 2244 | struct net_device *netdev = pci_get_drvdata(pdev); |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2245 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2246 | |
| 2247 | netif_device_detach(netdev); |
| 2248 | |
| 2249 | if (netif_running(netdev)) |
| 2250 | i40evf_close(netdev); |
| 2251 | |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2252 | /* Prevent the watchdog from running. */ |
| 2253 | adapter->state = __I40EVF_REMOVE; |
| 2254 | adapter->aq_required = 0; |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2255 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2256 | #ifdef CONFIG_PM |
| 2257 | pci_save_state(pdev); |
| 2258 | |
| 2259 | #endif |
| 2260 | pci_disable_device(pdev); |
| 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * i40evf_probe - Device Initialization Routine |
| 2265 | * @pdev: PCI device information struct |
| 2266 | * @ent: entry in i40evf_pci_tbl |
| 2267 | * |
| 2268 | * Returns 0 on success, negative on failure |
| 2269 | * |
| 2270 | * i40evf_probe initializes an adapter identified by a pci_dev structure. |
| 2271 | * The OS initialization, configuring of the adapter private structure, |
| 2272 | * and a hardware reset occur. |
| 2273 | **/ |
| 2274 | static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2275 | { |
| 2276 | struct net_device *netdev; |
| 2277 | struct i40evf_adapter *adapter = NULL; |
| 2278 | struct i40e_hw *hw = NULL; |
Mitch Williams | dbbd811 | 2014-02-20 19:29:08 -0800 | [diff] [blame] | 2279 | int err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2280 | |
| 2281 | err = pci_enable_device(pdev); |
| 2282 | if (err) |
| 2283 | return err; |
| 2284 | |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2285 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2286 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 2287 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 2288 | if (err) { |
| 2289 | dev_err(&pdev->dev, |
| 2290 | "DMA configuration failed: 0x%x\n", err); |
| 2291 | goto err_dma; |
| 2292 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | err = pci_request_regions(pdev, i40evf_driver_name); |
| 2296 | if (err) { |
| 2297 | dev_err(&pdev->dev, |
| 2298 | "pci_request_regions failed 0x%x\n", err); |
| 2299 | goto err_pci_reg; |
| 2300 | } |
| 2301 | |
| 2302 | pci_enable_pcie_error_reporting(pdev); |
| 2303 | |
| 2304 | pci_set_master(pdev); |
| 2305 | |
| 2306 | netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), |
| 2307 | MAX_TX_QUEUES); |
| 2308 | if (!netdev) { |
| 2309 | err = -ENOMEM; |
| 2310 | goto err_alloc_etherdev; |
| 2311 | } |
| 2312 | |
| 2313 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2314 | |
| 2315 | pci_set_drvdata(pdev, netdev); |
| 2316 | adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2317 | |
| 2318 | adapter->netdev = netdev; |
| 2319 | adapter->pdev = pdev; |
| 2320 | |
| 2321 | hw = &adapter->hw; |
| 2322 | hw->back = adapter; |
| 2323 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2324 | adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2325 | adapter->state = __I40EVF_STARTUP; |
| 2326 | |
| 2327 | /* Call save state here because it relies on the adapter struct. */ |
| 2328 | pci_save_state(pdev); |
| 2329 | |
| 2330 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 2331 | pci_resource_len(pdev, 0)); |
| 2332 | if (!hw->hw_addr) { |
| 2333 | err = -EIO; |
| 2334 | goto err_ioremap; |
| 2335 | } |
| 2336 | hw->vendor_id = pdev->vendor; |
| 2337 | hw->device_id = pdev->device; |
| 2338 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 2339 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 2340 | hw->subsystem_device_id = pdev->subsystem_device; |
| 2341 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 2342 | hw->bus.func = PCI_FUNC(pdev->devfn); |
| 2343 | |
Serey Kong | 8bb1a54 | 2014-08-01 13:27:15 -0700 | [diff] [blame] | 2344 | INIT_LIST_HEAD(&adapter->mac_filter_list); |
| 2345 | INIT_LIST_HEAD(&adapter->vlan_filter_list); |
| 2346 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2347 | INIT_WORK(&adapter->reset_task, i40evf_reset_task); |
| 2348 | INIT_WORK(&adapter->adminq_task, i40evf_adminq_task); |
| 2349 | INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task); |
| 2350 | INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task); |
| 2351 | schedule_delayed_work(&adapter->init_task, 10); |
| 2352 | |
| 2353 | return 0; |
| 2354 | |
| 2355 | err_ioremap: |
| 2356 | free_netdev(netdev); |
| 2357 | err_alloc_etherdev: |
| 2358 | pci_release_regions(pdev); |
| 2359 | err_pci_reg: |
| 2360 | err_dma: |
| 2361 | pci_disable_device(pdev); |
| 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | #ifdef CONFIG_PM |
| 2366 | /** |
| 2367 | * i40evf_suspend - Power management suspend routine |
| 2368 | * @pdev: PCI device information struct |
| 2369 | * @state: unused |
| 2370 | * |
| 2371 | * Called when the system (VM) is entering sleep/suspend. |
| 2372 | **/ |
| 2373 | static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2374 | { |
| 2375 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2376 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2377 | int retval = 0; |
| 2378 | |
| 2379 | netif_device_detach(netdev); |
| 2380 | |
| 2381 | if (netif_running(netdev)) { |
| 2382 | rtnl_lock(); |
| 2383 | i40evf_down(adapter); |
| 2384 | rtnl_unlock(); |
| 2385 | } |
| 2386 | i40evf_free_misc_irq(adapter); |
| 2387 | i40evf_reset_interrupt_capability(adapter); |
| 2388 | |
| 2389 | retval = pci_save_state(pdev); |
| 2390 | if (retval) |
| 2391 | return retval; |
| 2392 | |
| 2393 | pci_disable_device(pdev); |
| 2394 | |
| 2395 | return 0; |
| 2396 | } |
| 2397 | |
| 2398 | /** |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2399 | * i40evf_resume - Power management resume routine |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2400 | * @pdev: PCI device information struct |
| 2401 | * |
| 2402 | * Called when the system (VM) is resumed from sleep/suspend. |
| 2403 | **/ |
| 2404 | static int i40evf_resume(struct pci_dev *pdev) |
| 2405 | { |
| 2406 | struct i40evf_adapter *adapter = pci_get_drvdata(pdev); |
| 2407 | struct net_device *netdev = adapter->netdev; |
| 2408 | u32 err; |
| 2409 | |
| 2410 | pci_set_power_state(pdev, PCI_D0); |
| 2411 | pci_restore_state(pdev); |
| 2412 | /* pci_restore_state clears dev->state_saved so call |
| 2413 | * pci_save_state to restore it. |
| 2414 | */ |
| 2415 | pci_save_state(pdev); |
| 2416 | |
| 2417 | err = pci_enable_device_mem(pdev); |
| 2418 | if (err) { |
| 2419 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n"); |
| 2420 | return err; |
| 2421 | } |
| 2422 | pci_set_master(pdev); |
| 2423 | |
| 2424 | rtnl_lock(); |
| 2425 | err = i40evf_set_interrupt_capability(adapter); |
| 2426 | if (err) { |
| 2427 | dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); |
| 2428 | return err; |
| 2429 | } |
| 2430 | err = i40evf_request_misc_irq(adapter); |
| 2431 | rtnl_unlock(); |
| 2432 | if (err) { |
| 2433 | dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); |
| 2434 | return err; |
| 2435 | } |
| 2436 | |
| 2437 | schedule_work(&adapter->reset_task); |
| 2438 | |
| 2439 | netif_device_attach(netdev); |
| 2440 | |
| 2441 | return err; |
| 2442 | } |
| 2443 | |
| 2444 | #endif /* CONFIG_PM */ |
| 2445 | /** |
| 2446 | * i40evf_remove - Device Removal Routine |
| 2447 | * @pdev: PCI device information struct |
| 2448 | * |
| 2449 | * i40evf_remove is called by the PCI subsystem to alert the driver |
| 2450 | * that it should release a PCI device. The could be caused by a |
| 2451 | * Hot-Plug event, or because the driver is going to be removed from |
| 2452 | * memory. |
| 2453 | **/ |
| 2454 | static void i40evf_remove(struct pci_dev *pdev) |
| 2455 | { |
| 2456 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2457 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 2458 | struct i40evf_mac_filter *f, *ftmp; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2459 | struct i40e_hw *hw = &adapter->hw; |
| 2460 | |
| 2461 | cancel_delayed_work_sync(&adapter->init_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2462 | cancel_work_sync(&adapter->reset_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2463 | |
| 2464 | if (adapter->netdev_registered) { |
| 2465 | unregister_netdev(netdev); |
| 2466 | adapter->netdev_registered = false; |
| 2467 | } |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 2468 | |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2469 | /* Shut down all the garbage mashers on the detention level */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2470 | adapter->state = __I40EVF_REMOVE; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2471 | adapter->aq_required = 0; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2472 | i40evf_request_reset(adapter); |
| 2473 | msleep(20); |
| 2474 | /* If the FW isn't responding, kick it once, but only once. */ |
| 2475 | if (!i40evf_asq_done(hw)) { |
| 2476 | i40evf_request_reset(adapter); |
| 2477 | msleep(20); |
| 2478 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2479 | |
Mitch Williams | dbb01c8 | 2014-02-20 19:29:07 -0800 | [diff] [blame] | 2480 | if (adapter->msix_entries) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2481 | i40evf_misc_irq_disable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2482 | i40evf_free_misc_irq(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2483 | i40evf_reset_interrupt_capability(adapter); |
Mitch Williams | d31944d | 2014-08-01 13:27:13 -0700 | [diff] [blame] | 2484 | i40evf_free_q_vectors(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
Mitch Williams | e5d17c3 | 2014-06-04 04:22:38 +0000 | [diff] [blame] | 2487 | if (adapter->watchdog_timer.function) |
| 2488 | del_timer_sync(&adapter->watchdog_timer); |
| 2489 | |
Mitch Williams | dbb01c8 | 2014-02-20 19:29:07 -0800 | [diff] [blame] | 2490 | flush_scheduled_work(); |
| 2491 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2492 | if (hw->aq.asq.count) |
| 2493 | i40evf_shutdown_adminq(hw); |
| 2494 | |
| 2495 | iounmap(hw->hw_addr); |
| 2496 | pci_release_regions(pdev); |
| 2497 | |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 2498 | i40evf_free_all_tx_resources(adapter); |
| 2499 | i40evf_free_all_rx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2500 | i40evf_free_queues(adapter); |
| 2501 | kfree(adapter->vf_res); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 2502 | /* If we got removed before an up/down sequence, we've got a filter |
| 2503 | * hanging out there that we need to get rid of. |
| 2504 | */ |
| 2505 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 2506 | list_del(&f->list); |
| 2507 | kfree(f); |
| 2508 | } |
Mitch A Williams | 37dfdf3 | 2014-12-09 08:53:05 +0000 | [diff] [blame] | 2509 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
| 2510 | list_del(&f->list); |
| 2511 | kfree(f); |
| 2512 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2513 | |
| 2514 | free_netdev(netdev); |
| 2515 | |
| 2516 | pci_disable_pcie_error_reporting(pdev); |
| 2517 | |
| 2518 | pci_disable_device(pdev); |
| 2519 | } |
| 2520 | |
| 2521 | static struct pci_driver i40evf_driver = { |
| 2522 | .name = i40evf_driver_name, |
| 2523 | .id_table = i40evf_pci_tbl, |
| 2524 | .probe = i40evf_probe, |
| 2525 | .remove = i40evf_remove, |
| 2526 | #ifdef CONFIG_PM |
| 2527 | .suspend = i40evf_suspend, |
| 2528 | .resume = i40evf_resume, |
| 2529 | #endif |
| 2530 | .shutdown = i40evf_shutdown, |
| 2531 | }; |
| 2532 | |
| 2533 | /** |
| 2534 | * i40e_init_module - Driver Registration Routine |
| 2535 | * |
| 2536 | * i40e_init_module is the first routine called when the driver is |
| 2537 | * loaded. All it does is register with the PCI subsystem. |
| 2538 | **/ |
| 2539 | static int __init i40evf_init_module(void) |
| 2540 | { |
| 2541 | int ret; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2542 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2543 | pr_info("i40evf: %s - version %s\n", i40evf_driver_string, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2544 | i40evf_driver_version); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2545 | |
| 2546 | pr_info("%s\n", i40evf_copyright); |
| 2547 | |
| 2548 | ret = pci_register_driver(&i40evf_driver); |
| 2549 | return ret; |
| 2550 | } |
| 2551 | |
| 2552 | module_init(i40evf_init_module); |
| 2553 | |
| 2554 | /** |
| 2555 | * i40e_exit_module - Driver Exit Cleanup Routine |
| 2556 | * |
| 2557 | * i40e_exit_module is called just before the driver is removed |
| 2558 | * from memory. |
| 2559 | **/ |
| 2560 | static void __exit i40evf_exit_module(void) |
| 2561 | { |
| 2562 | pci_unregister_driver(&i40evf_driver); |
| 2563 | } |
| 2564 | |
| 2565 | module_exit(i40evf_exit_module); |
| 2566 | |
| 2567 | /* i40evf_main.c */ |