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