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