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