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