Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver |
Catherine Sullivan | eaab59e | 2016-01-13 16:51:44 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Jesse Brandeburg | b831607 | 2014-04-05 07:46:11 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | #include "i40evf.h" |
| 28 | #include "i40e_prototype.h" |
| 29 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter); |
| 30 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter); |
| 31 | static int i40evf_close(struct net_device *netdev); |
| 32 | |
| 33 | char i40evf_driver_name[] = "i40evf"; |
| 34 | static const char i40evf_driver_string[] = |
Catherine Sullivan | eaab59e | 2016-01-13 16:51:44 -0800 | [diff] [blame] | 35 | "Intel(R) 40-10 Gigabit Virtual Function Network Driver"; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 36 | |
Mitch Williams | 69ebe955 | 2015-11-19 11:34:24 -0800 | [diff] [blame] | 37 | #define DRV_KERN "-k" |
| 38 | |
| 39 | #define DRV_VERSION_MAJOR 1 |
Bimmy Pujari | 0706195 | 2016-05-16 10:26:45 -0700 | [diff] [blame] | 40 | #define DRV_VERSION_MINOR 6 |
Bimmy Pujari | cf465fe | 2016-09-27 11:28:54 -0700 | [diff] [blame] | 41 | #define DRV_VERSION_BUILD 21 |
Mitch Williams | 69ebe955 | 2015-11-19 11:34:24 -0800 | [diff] [blame] | 42 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 43 | __stringify(DRV_VERSION_MINOR) "." \ |
| 44 | __stringify(DRV_VERSION_BUILD) \ |
| 45 | DRV_KERN |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 46 | const char i40evf_driver_version[] = DRV_VERSION; |
| 47 | static const char i40evf_copyright[] = |
Catherine Sullivan | bf41846 | 2015-07-10 19:36:10 -0400 | [diff] [blame] | 48 | "Copyright (c) 2013 - 2015 Intel Corporation."; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 49 | |
| 50 | /* i40evf_pci_tbl - PCI Device ID Table |
| 51 | * |
| 52 | * Wildcard entries (PCI_ANY_ID) should come last |
| 53 | * Last entry must be all 0s |
| 54 | * |
| 55 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 56 | * Class, Class Mask, private data (not used) } |
| 57 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 58 | static const struct pci_device_id i40evf_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 59 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0}, |
Joshua Hay | 9287141 | 2016-06-20 09:10:37 -0700 | [diff] [blame] | 60 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF_HV), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 61 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0}, |
Joshua Hay | 9287141 | 2016-06-20 09:10:37 -0700 | [diff] [blame] | 62 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF_HV), 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 | { |
| 689 | struct i40e_hw *hw = &adapter->hw; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 690 | int i; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 691 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 692 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 693 | adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i); |
Jesse Brandeburg | 19b85e6 | 2016-04-18 11:33:45 -0700 | [diff] [blame] | 694 | adapter->rx_rings[i].rx_buf_len = I40EVF_RXBUFFER_2048; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * i40evf_find_vlan - Search filter list for specific vlan filter |
| 700 | * @adapter: board private structure |
| 701 | * @vlan: vlan tag |
| 702 | * |
| 703 | * Returns ptr to the filter object or NULL |
| 704 | **/ |
| 705 | static struct |
| 706 | i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 707 | { |
| 708 | struct i40evf_vlan_filter *f; |
| 709 | |
| 710 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 711 | if (vlan == f->vlan) |
| 712 | return f; |
| 713 | } |
| 714 | return NULL; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * i40evf_add_vlan - Add a vlan filter to the list |
| 719 | * @adapter: board private structure |
| 720 | * @vlan: VLAN tag |
| 721 | * |
| 722 | * Returns ptr to the filter object or NULL when no memory available. |
| 723 | **/ |
| 724 | static struct |
| 725 | i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 726 | { |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 727 | struct i40evf_vlan_filter *f = NULL; |
| 728 | int count = 50; |
| 729 | |
| 730 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 731 | &adapter->crit_section)) { |
| 732 | udelay(1); |
| 733 | if (--count == 0) |
| 734 | goto out; |
| 735 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 736 | |
| 737 | f = i40evf_find_vlan(adapter, vlan); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 738 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 739 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 740 | if (!f) |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 741 | goto clearout; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 742 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 743 | f->vlan = vlan; |
| 744 | |
| 745 | INIT_LIST_HEAD(&f->list); |
| 746 | list_add(&f->list, &adapter->vlan_filter_list); |
| 747 | f->add = true; |
| 748 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
| 749 | } |
| 750 | |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 751 | clearout: |
| 752 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 753 | out: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 754 | return f; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * i40evf_del_vlan - Remove a vlan filter from the list |
| 759 | * @adapter: board private structure |
| 760 | * @vlan: VLAN tag |
| 761 | **/ |
| 762 | static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan) |
| 763 | { |
| 764 | struct i40evf_vlan_filter *f; |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 765 | int count = 50; |
| 766 | |
| 767 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 768 | &adapter->crit_section)) { |
| 769 | udelay(1); |
| 770 | if (--count == 0) |
| 771 | return; |
| 772 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 773 | |
| 774 | f = i40evf_find_vlan(adapter, vlan); |
| 775 | if (f) { |
| 776 | f->remove = true; |
| 777 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
| 778 | } |
Mitch Williams | 13acb54 | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 779 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /** |
| 783 | * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device |
| 784 | * @netdev: network device struct |
| 785 | * @vid: VLAN tag |
| 786 | **/ |
| 787 | static int i40evf_vlan_rx_add_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 788 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 789 | { |
| 790 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 791 | |
Mitch Williams | 8ed995f | 2015-08-28 17:55:57 -0400 | [diff] [blame] | 792 | if (!VLAN_ALLOWED(adapter)) |
| 793 | return -EIO; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 794 | if (i40evf_add_vlan(adapter, vid) == NULL) |
| 795 | return -ENOMEM; |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device |
| 801 | * @netdev: network device struct |
| 802 | * @vid: VLAN tag |
| 803 | **/ |
| 804 | static int i40evf_vlan_rx_kill_vid(struct net_device *netdev, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 805 | __always_unused __be16 proto, u16 vid) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 806 | { |
| 807 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 808 | |
Mitch Williams | 8ed995f | 2015-08-28 17:55:57 -0400 | [diff] [blame] | 809 | if (VLAN_ALLOWED(adapter)) { |
| 810 | i40evf_del_vlan(adapter, vid); |
| 811 | return 0; |
| 812 | } |
| 813 | return -EIO; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
| 817 | * i40evf_find_filter - Search filter list for specific mac filter |
| 818 | * @adapter: board private structure |
| 819 | * @macaddr: the MAC address |
| 820 | * |
| 821 | * Returns ptr to the filter object or NULL |
| 822 | **/ |
| 823 | static struct |
| 824 | i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter, |
| 825 | u8 *macaddr) |
| 826 | { |
| 827 | struct i40evf_mac_filter *f; |
| 828 | |
| 829 | if (!macaddr) |
| 830 | return NULL; |
| 831 | |
| 832 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 833 | if (ether_addr_equal(macaddr, f->macaddr)) |
| 834 | return f; |
| 835 | } |
| 836 | return NULL; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * i40e_add_filter - Add a mac filter to the filter list |
| 841 | * @adapter: board private structure |
| 842 | * @macaddr: the MAC address |
| 843 | * |
| 844 | * Returns ptr to the filter object or NULL when no memory available. |
| 845 | **/ |
| 846 | static struct |
| 847 | i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter, |
| 848 | u8 *macaddr) |
| 849 | { |
| 850 | struct i40evf_mac_filter *f; |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 851 | int count = 50; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 852 | |
| 853 | if (!macaddr) |
| 854 | return NULL; |
| 855 | |
| 856 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 857 | &adapter->crit_section)) { |
Mitch Williams | b65476c | 2014-07-09 07:46:14 +0000 | [diff] [blame] | 858 | udelay(1); |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 859 | if (--count == 0) |
| 860 | return NULL; |
| 861 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 862 | |
| 863 | f = i40evf_find_filter(adapter, macaddr); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 864 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 865 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
Mitch Williams | 348d499 | 2014-11-11 20:02:52 +0000 | [diff] [blame] | 866 | if (!f) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 867 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
| 868 | &adapter->crit_section); |
| 869 | return NULL; |
| 870 | } |
| 871 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 872 | ether_addr_copy(f->macaddr, macaddr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 873 | |
Mitch Williams | 63590b6 | 2016-05-16 10:26:42 -0700 | [diff] [blame] | 874 | list_add_tail(&f->list, &adapter->mac_filter_list); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 875 | f->add = true; |
| 876 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
| 877 | } |
| 878 | |
| 879 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 880 | return f; |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * i40evf_set_mac - NDO callback to set port mac address |
| 885 | * @netdev: network interface device structure |
| 886 | * @p: pointer to an address structure |
| 887 | * |
| 888 | * Returns 0 on success, negative on failure |
| 889 | **/ |
| 890 | static int i40evf_set_mac(struct net_device *netdev, void *p) |
| 891 | { |
| 892 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 893 | struct i40e_hw *hw = &adapter->hw; |
| 894 | struct i40evf_mac_filter *f; |
| 895 | struct sockaddr *addr = p; |
| 896 | |
| 897 | if (!is_valid_ether_addr(addr->sa_data)) |
| 898 | return -EADDRNOTAVAIL; |
| 899 | |
| 900 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) |
| 901 | return 0; |
| 902 | |
Mitch Williams | 14e52ee | 2015-08-31 19:54:44 -0400 | [diff] [blame] | 903 | if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF) |
| 904 | return -EPERM; |
| 905 | |
| 906 | f = i40evf_find_filter(adapter, hw->mac.addr); |
| 907 | if (f) { |
| 908 | f->remove = true; |
| 909 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 910 | } |
| 911 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 912 | f = i40evf_add_filter(adapter, addr->sa_data); |
| 913 | if (f) { |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 914 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
| 915 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | return (f == NULL) ? -ENOMEM : 0; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * i40evf_set_rx_mode - NDO callback to set the netdev filters |
| 923 | * @netdev: network interface device structure |
| 924 | **/ |
| 925 | static void i40evf_set_rx_mode(struct net_device *netdev) |
| 926 | { |
| 927 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 928 | struct i40evf_mac_filter *f, *ftmp; |
| 929 | struct netdev_hw_addr *uca; |
| 930 | struct netdev_hw_addr *mca; |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 931 | struct netdev_hw_addr *ha; |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 932 | int count = 50; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 933 | |
| 934 | /* add addr if not already in the filter list */ |
| 935 | netdev_for_each_uc_addr(uca, netdev) { |
| 936 | i40evf_add_filter(adapter, uca->addr); |
| 937 | } |
| 938 | netdev_for_each_mc_addr(mca, netdev) { |
| 939 | i40evf_add_filter(adapter, mca->addr); |
| 940 | } |
| 941 | |
| 942 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 943 | &adapter->crit_section)) { |
Mitch Williams | b65476c | 2014-07-09 07:46:14 +0000 | [diff] [blame] | 944 | udelay(1); |
Mitch Williams | 54e16f6 | 2015-01-29 07:17:20 +0000 | [diff] [blame] | 945 | if (--count == 0) { |
| 946 | dev_err(&adapter->pdev->dev, |
| 947 | "Failed to get lock in %s\n", __func__); |
| 948 | return; |
| 949 | } |
| 950 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 951 | /* remove filter if not in netdev list */ |
| 952 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 953 | netdev_for_each_mc_addr(mca, netdev) |
| 954 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 955 | goto bottom_of_search_loop; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 956 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 957 | netdev_for_each_uc_addr(uca, netdev) |
| 958 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 959 | goto bottom_of_search_loop; |
| 960 | |
| 961 | for_each_dev_addr(netdev, ha) |
| 962 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 963 | goto bottom_of_search_loop; |
| 964 | |
| 965 | if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) |
| 966 | goto bottom_of_search_loop; |
| 967 | |
| 968 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 969 | f->remove = true; |
| 970 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
| 971 | |
| 972 | bottom_of_search_loop: |
| 973 | continue; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 974 | } |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 975 | |
| 976 | if (netdev->flags & IFF_PROMISC && |
| 977 | !(adapter->flags & I40EVF_FLAG_PROMISC_ON)) |
| 978 | adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_PROMISC; |
| 979 | else if (!(netdev->flags & IFF_PROMISC) && |
| 980 | adapter->flags & I40EVF_FLAG_PROMISC_ON) |
| 981 | adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_PROMISC; |
| 982 | |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 983 | if (netdev->flags & IFF_ALLMULTI && |
| 984 | !(adapter->flags & I40EVF_FLAG_ALLMULTI_ON)) |
| 985 | adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_ALLMULTI; |
| 986 | else if (!(netdev->flags & IFF_ALLMULTI) && |
| 987 | adapter->flags & I40EVF_FLAG_ALLMULTI_ON) |
| 988 | adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_ALLMULTI; |
| 989 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 990 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * i40evf_napi_enable_all - enable NAPI on all queue vectors |
| 995 | * @adapter: board private structure |
| 996 | **/ |
| 997 | static void i40evf_napi_enable_all(struct i40evf_adapter *adapter) |
| 998 | { |
| 999 | int q_idx; |
| 1000 | struct i40e_q_vector *q_vector; |
| 1001 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 1002 | |
| 1003 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 1004 | struct napi_struct *napi; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1005 | |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1006 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1007 | napi = &q_vector->napi; |
| 1008 | napi_enable(napi); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * i40evf_napi_disable_all - disable NAPI on all queue vectors |
| 1014 | * @adapter: board private structure |
| 1015 | **/ |
| 1016 | static void i40evf_napi_disable_all(struct i40evf_adapter *adapter) |
| 1017 | { |
| 1018 | int q_idx; |
| 1019 | struct i40e_q_vector *q_vector; |
| 1020 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
| 1021 | |
| 1022 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1023 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1024 | napi_disable(&q_vector->napi); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * i40evf_configure - set up transmit and receive data structures |
| 1030 | * @adapter: board private structure |
| 1031 | **/ |
| 1032 | static void i40evf_configure(struct i40evf_adapter *adapter) |
| 1033 | { |
| 1034 | struct net_device *netdev = adapter->netdev; |
| 1035 | int i; |
| 1036 | |
| 1037 | i40evf_set_rx_mode(netdev); |
| 1038 | |
| 1039 | i40evf_configure_tx(adapter); |
| 1040 | i40evf_configure_rx(adapter); |
| 1041 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES; |
| 1042 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1043 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1044 | struct i40e_ring *ring = &adapter->rx_rings[i]; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1045 | |
Mitch Williams | b163098 | 2016-04-18 11:33:48 -0700 | [diff] [blame] | 1046 | i40evf_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * i40evf_up_complete - Finish the last steps of bringing up a connection |
| 1052 | * @adapter: board private structure |
| 1053 | **/ |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 1054 | static void i40evf_up_complete(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1055 | { |
| 1056 | adapter->state = __I40EVF_RUNNING; |
| 1057 | clear_bit(__I40E_DOWN, &adapter->vsi.state); |
| 1058 | |
| 1059 | i40evf_napi_enable_all(adapter); |
| 1060 | |
| 1061 | adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES; |
| 1062 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1066 | * i40e_down - Shutdown the connection processing |
| 1067 | * @adapter: board private structure |
| 1068 | **/ |
| 1069 | void i40evf_down(struct i40evf_adapter *adapter) |
| 1070 | { |
| 1071 | struct net_device *netdev = adapter->netdev; |
| 1072 | struct i40evf_mac_filter *f; |
| 1073 | |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 1074 | if (adapter->state <= __I40EVF_DOWN_PENDING) |
Mitch Williams | ddf0b3a | 2014-05-22 06:31:46 +0000 | [diff] [blame] | 1075 | return; |
| 1076 | |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1077 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1078 | &adapter->crit_section)) |
| 1079 | usleep_range(500, 1000); |
| 1080 | |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 1081 | netif_carrier_off(netdev); |
| 1082 | netif_tx_disable(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 1083 | adapter->link_up = false; |
Mitch Williams | 748c434 | 2015-01-29 07:17:18 +0000 | [diff] [blame] | 1084 | i40evf_napi_disable_all(adapter); |
Mitch Williams | 63e18c2 | 2015-03-27 00:12:10 -0700 | [diff] [blame] | 1085 | i40evf_irq_disable(adapter); |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1086 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1087 | /* remove all MAC filters */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1088 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1089 | f->remove = true; |
| 1090 | } |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1091 | /* remove all VLAN filters */ |
| 1092 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { |
| 1093 | f->remove = true; |
| 1094 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1095 | if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) && |
| 1096 | adapter->state != __I40EVF_RESETTING) { |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1097 | /* cancel any current operation */ |
| 1098 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1099 | /* Schedule operations to close down the HW. Don't wait |
| 1100 | * here for this to complete. The watchdog is still running |
| 1101 | * and it will take care of this. |
| 1102 | */ |
| 1103 | adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER; |
Mitch Williams | ed1f5b5 | 2014-02-20 19:29:06 -0800 | [diff] [blame] | 1104 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1105 | adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1106 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1107 | |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 1108 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * i40evf_acquire_msix_vectors - Setup the MSIX capability |
| 1113 | * @adapter: board private structure |
| 1114 | * @vectors: number of vectors to request |
| 1115 | * |
| 1116 | * Work with the OS to set up the MSIX vectors needed. |
| 1117 | * |
| 1118 | * Returns 0 on success, negative on failure |
| 1119 | **/ |
| 1120 | static int |
| 1121 | i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors) |
| 1122 | { |
| 1123 | int err, vector_threshold; |
| 1124 | |
| 1125 | /* We'll want at least 3 (vector_threshold): |
| 1126 | * 0) Other (Admin Queue and link, mostly) |
| 1127 | * 1) TxQ[0] Cleanup |
| 1128 | * 2) RxQ[0] Cleanup |
| 1129 | */ |
| 1130 | vector_threshold = MIN_MSIX_COUNT; |
| 1131 | |
| 1132 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 1133 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 1134 | * Right now, we simply care about how many we'll get; we'll |
| 1135 | * set them up later while requesting irq's. |
| 1136 | */ |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1137 | err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 1138 | vector_threshold, vectors); |
| 1139 | if (err < 0) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1140 | dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1141 | kfree(adapter->msix_entries); |
| 1142 | adapter->msix_entries = NULL; |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1143 | return err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1144 | } |
Alexander Gordeev | fc2f2f5 | 2014-04-28 17:53:16 +0000 | [diff] [blame] | 1145 | |
| 1146 | /* Adjust for only the vectors we'll use, which is minimum |
| 1147 | * of max_msix_q_vectors + NONQ_VECS, or the number of |
| 1148 | * vectors we were allocated. |
| 1149 | */ |
| 1150 | adapter->num_msix_vectors = err; |
| 1151 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * i40evf_free_queues - Free memory for all rings |
| 1156 | * @adapter: board private structure to initialize |
| 1157 | * |
| 1158 | * Free all of the memory associated with queue pairs. |
| 1159 | **/ |
| 1160 | static void i40evf_free_queues(struct i40evf_adapter *adapter) |
| 1161 | { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1162 | if (!adapter->vsi_res) |
| 1163 | return; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1164 | kfree(adapter->tx_rings); |
Mitch Williams | 1031154 | 2015-12-09 15:50:30 -0800 | [diff] [blame] | 1165 | adapter->tx_rings = NULL; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1166 | kfree(adapter->rx_rings); |
Mitch Williams | 1031154 | 2015-12-09 15:50:30 -0800 | [diff] [blame] | 1167 | adapter->rx_rings = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * i40evf_alloc_queues - Allocate memory for all rings |
| 1172 | * @adapter: board private structure to initialize |
| 1173 | * |
| 1174 | * We allocate one ring per queue at run-time since we don't know the |
| 1175 | * number of queues at compile-time. The polling_netdev array is |
| 1176 | * intended for Multiqueue, but should work fine with a single queue. |
| 1177 | **/ |
| 1178 | static int i40evf_alloc_queues(struct i40evf_adapter *adapter) |
| 1179 | { |
| 1180 | int i; |
| 1181 | |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1182 | adapter->tx_rings = kcalloc(adapter->num_active_queues, |
| 1183 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1184 | if (!adapter->tx_rings) |
| 1185 | goto err_out; |
| 1186 | adapter->rx_rings = kcalloc(adapter->num_active_queues, |
| 1187 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1188 | if (!adapter->rx_rings) |
| 1189 | goto err_out; |
| 1190 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1191 | for (i = 0; i < adapter->num_active_queues; i++) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1192 | struct i40e_ring *tx_ring; |
| 1193 | struct i40e_ring *rx_ring; |
| 1194 | |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1195 | tx_ring = &adapter->tx_rings[i]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1196 | |
| 1197 | tx_ring->queue_index = i; |
| 1198 | tx_ring->netdev = adapter->netdev; |
| 1199 | tx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1200 | tx_ring->count = adapter->tx_desc_count; |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 1201 | 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] | 1202 | if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 1203 | tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1204 | |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1205 | rx_ring = &adapter->rx_rings[i]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1206 | rx_ring->queue_index = i; |
| 1207 | rx_ring->netdev = adapter->netdev; |
| 1208 | rx_ring->dev = &adapter->pdev->dev; |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 1209 | rx_ring->count = adapter->rx_desc_count; |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 1210 | rx_ring->rx_itr_setting = (I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | return 0; |
| 1214 | |
| 1215 | err_out: |
| 1216 | i40evf_free_queues(adapter); |
| 1217 | return -ENOMEM; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
| 1221 | * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported |
| 1222 | * @adapter: board private structure to initialize |
| 1223 | * |
| 1224 | * Attempt to configure the interrupts using the best available |
| 1225 | * capabilities of the hardware and the kernel. |
| 1226 | **/ |
| 1227 | static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter) |
| 1228 | { |
| 1229 | int vector, v_budget; |
| 1230 | int pairs = 0; |
| 1231 | int err = 0; |
| 1232 | |
| 1233 | if (!adapter->vsi_res) { |
| 1234 | err = -EIO; |
| 1235 | goto out; |
| 1236 | } |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1237 | pairs = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1238 | |
| 1239 | /* It's easy to be greedy for MSI-X vectors, but it really |
| 1240 | * doesn't do us much good if we have a lot more vectors |
| 1241 | * than CPU's. So let's be conservative and only ask for |
| 1242 | * (roughly) twice the number of vectors as there are CPU's. |
| 1243 | */ |
Mitch Williams | 30a500e | 2014-02-11 08:27:52 +0000 | [diff] [blame] | 1244 | v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS; |
| 1245 | 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] | 1246 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1247 | adapter->msix_entries = kcalloc(v_budget, |
| 1248 | sizeof(struct msix_entry), GFP_KERNEL); |
| 1249 | if (!adapter->msix_entries) { |
| 1250 | err = -ENOMEM; |
| 1251 | goto out; |
| 1252 | } |
| 1253 | |
| 1254 | for (vector = 0; vector < v_budget; vector++) |
| 1255 | adapter->msix_entries[vector].entry = vector; |
| 1256 | |
Mitch Williams | 313ed2d | 2015-08-27 11:42:31 -0400 | [diff] [blame] | 1257 | err = i40evf_acquire_msix_vectors(adapter, v_budget); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1258 | |
| 1259 | out: |
Mitch Williams | e6c4cf6 | 2015-11-06 15:26:00 -0800 | [diff] [blame] | 1260 | netif_set_real_num_rx_queues(adapter->netdev, pairs); |
| 1261 | netif_set_real_num_tx_queues(adapter->netdev, pairs); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1262 | return err; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1266 | * i40e_config_rss_aq - Configure RSS keys and lut by using AQ commands |
| 1267 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1268 | * |
| 1269 | * Return 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1270 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1271 | static int i40evf_config_rss_aq(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1272 | { |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1273 | struct i40e_aqc_get_set_rss_key_data *rss_key = |
| 1274 | (struct i40e_aqc_get_set_rss_key_data *)adapter->rss_key; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1275 | struct i40e_hw *hw = &adapter->hw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1276 | int ret = 0; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1277 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1278 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { |
| 1279 | /* bail because we already have a command pending */ |
Masanari Iida | e3d132d | 2015-10-16 21:14:29 +0900 | [diff] [blame] | 1280 | 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] | 1281 | adapter->current_op); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1282 | return -EBUSY; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1285 | ret = i40evf_aq_set_rss_key(hw, adapter->vsi.id, rss_key); |
| 1286 | if (ret) { |
| 1287 | dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n", |
| 1288 | i40evf_stat_str(hw, ret), |
| 1289 | i40evf_aq_str(hw, hw->aq.asq_last_status)); |
| 1290 | return ret; |
| 1291 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1292 | } |
| 1293 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1294 | ret = i40evf_aq_set_rss_lut(hw, adapter->vsi.id, false, |
| 1295 | adapter->rss_lut, adapter->rss_lut_size); |
| 1296 | if (ret) { |
| 1297 | dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n", |
| 1298 | i40evf_stat_str(hw, ret), |
| 1299 | i40evf_aq_str(hw, hw->aq.asq_last_status)); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | return ret; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1303 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /** |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1307 | * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1308 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1309 | * |
| 1310 | * Returns 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1311 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1312 | static int i40evf_config_rss_reg(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1313 | { |
| 1314 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1315 | u32 *dw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1316 | u16 i; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1317 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1318 | dw = (u32 *)adapter->rss_key; |
| 1319 | for (i = 0; i <= adapter->rss_key_size / 4; i++) |
| 1320 | wr32(hw, I40E_VFQF_HKEY(i), dw[i]); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1321 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1322 | dw = (u32 *)adapter->rss_lut; |
| 1323 | for (i = 0; i <= adapter->rss_lut_size / 4; i++) |
| 1324 | wr32(hw, I40E_VFQF_HLUT(i), dw[i]); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1325 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1326 | i40e_flush(hw); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * i40evf_config_rss - Configure RSS keys and lut |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1333 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1334 | * |
| 1335 | * Returns 0 on success, negative on failure |
| 1336 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1337 | int i40evf_config_rss(struct i40evf_adapter *adapter) |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1338 | { |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1339 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1340 | if (RSS_PF(adapter)) { |
| 1341 | adapter->aq_required |= I40EVF_FLAG_AQ_SET_RSS_LUT | |
| 1342 | I40EVF_FLAG_AQ_SET_RSS_KEY; |
| 1343 | return 0; |
| 1344 | } else if (RSS_AQ(adapter)) { |
| 1345 | return i40evf_config_rss_aq(adapter); |
| 1346 | } else { |
| 1347 | return i40evf_config_rss_reg(adapter); |
| 1348 | } |
Helin Zhang | 90b02b4 | 2015-10-26 19:44:33 -0400 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /** |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1352 | * i40evf_fill_rss_lut - Fill the lut with default values |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1353 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1354 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1355 | static void i40evf_fill_rss_lut(struct i40evf_adapter *adapter) |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1356 | { |
| 1357 | u16 i; |
| 1358 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1359 | for (i = 0; i < adapter->rss_lut_size; i++) |
| 1360 | adapter->rss_lut[i] = i % adapter->num_active_queues; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /** |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 1364 | * i40evf_init_rss - Prepare for RSS |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1365 | * @adapter: board private structure |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1366 | * |
| 1367 | * Return 0 on success, negative on failure |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1368 | **/ |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1369 | static int i40evf_init_rss(struct i40evf_adapter *adapter) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1370 | { |
| 1371 | struct i40e_hw *hw = &adapter->hw; |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1372 | int ret; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1373 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1374 | if (!RSS_PF(adapter)) { |
| 1375 | /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */ |
| 1376 | if (adapter->vf_res->vf_offload_flags & |
| 1377 | I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2) |
| 1378 | adapter->hena = I40E_DEFAULT_RSS_HENA_EXPANDED; |
| 1379 | else |
| 1380 | adapter->hena = I40E_DEFAULT_RSS_HENA; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1381 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1382 | wr32(hw, I40E_VFQF_HENA(0), (u32)adapter->hena); |
| 1383 | wr32(hw, I40E_VFQF_HENA(1), (u32)(adapter->hena >> 32)); |
| 1384 | } |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1385 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1386 | i40evf_fill_rss_lut(adapter); |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1387 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1388 | netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size); |
| 1389 | ret = i40evf_config_rss(adapter); |
Helin Zhang | 2c86ac3 | 2015-10-27 16:15:06 -0400 | [diff] [blame] | 1390 | |
| 1391 | return ret; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1395 | * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1396 | * @adapter: board private structure to initialize |
| 1397 | * |
| 1398 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1399 | * return -ENOMEM. |
| 1400 | **/ |
| 1401 | static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter) |
| 1402 | { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1403 | int q_idx = 0, num_q_vectors; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1404 | struct i40e_q_vector *q_vector; |
| 1405 | |
| 1406 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1407 | adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector), |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1408 | GFP_KERNEL); |
| 1409 | if (!adapter->q_vectors) |
Alan Cox | 311f23e | 2016-03-01 16:02:15 -0800 | [diff] [blame] | 1410 | return -ENOMEM; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1411 | |
| 1412 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1413 | q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1414 | q_vector->adapter = adapter; |
| 1415 | q_vector->vsi = &adapter->vsi; |
| 1416 | q_vector->v_idx = q_idx; |
| 1417 | netif_napi_add(adapter->netdev, &q_vector->napi, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1418 | i40evf_napi_poll, NAPI_POLL_WEIGHT); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | return 0; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * i40evf_free_q_vectors - Free memory allocated for interrupt vectors |
| 1426 | * @adapter: board private structure to initialize |
| 1427 | * |
| 1428 | * This function frees the memory allocated to the q_vectors. In addition if |
| 1429 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 1430 | * to freeing the q_vector. |
| 1431 | **/ |
| 1432 | static void i40evf_free_q_vectors(struct i40evf_adapter *adapter) |
| 1433 | { |
| 1434 | int q_idx, num_q_vectors; |
| 1435 | int napi_vectors; |
| 1436 | |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame^] | 1437 | if (!adapter->q_vectors) |
| 1438 | return; |
| 1439 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1440 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1441 | napi_vectors = adapter->num_active_queues; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1442 | |
| 1443 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1444 | struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx]; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1445 | if (q_idx < napi_vectors) |
| 1446 | netif_napi_del(&q_vector->napi); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1447 | } |
Mitch Williams | 7d96ba1 | 2015-10-26 19:44:39 -0400 | [diff] [blame] | 1448 | kfree(adapter->q_vectors); |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame^] | 1449 | adapter->q_vectors = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * i40evf_reset_interrupt_capability - Reset MSIX setup |
| 1454 | * @adapter: board private structure |
| 1455 | * |
| 1456 | **/ |
| 1457 | void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter) |
| 1458 | { |
Alan Brady | 47d2a5d | 2016-11-08 13:05:05 -0800 | [diff] [blame] | 1459 | if (!adapter->msix_entries) |
| 1460 | return; |
| 1461 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1462 | pci_disable_msix(adapter->pdev); |
| 1463 | kfree(adapter->msix_entries); |
| 1464 | adapter->msix_entries = NULL; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /** |
| 1468 | * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init |
| 1469 | * @adapter: board private structure to initialize |
| 1470 | * |
| 1471 | **/ |
| 1472 | int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter) |
| 1473 | { |
| 1474 | int err; |
| 1475 | |
Jacob Keller | 62fe2a8 | 2016-07-27 12:02:33 -0700 | [diff] [blame] | 1476 | rtnl_lock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1477 | err = i40evf_set_interrupt_capability(adapter); |
Jacob Keller | 62fe2a8 | 2016-07-27 12:02:33 -0700 | [diff] [blame] | 1478 | rtnl_unlock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1479 | if (err) { |
| 1480 | dev_err(&adapter->pdev->dev, |
| 1481 | "Unable to setup interrupt capabilities\n"); |
| 1482 | goto err_set_interrupt; |
| 1483 | } |
| 1484 | |
| 1485 | err = i40evf_alloc_q_vectors(adapter); |
| 1486 | if (err) { |
| 1487 | dev_err(&adapter->pdev->dev, |
| 1488 | "Unable to allocate memory for queue vectors\n"); |
| 1489 | goto err_alloc_q_vectors; |
| 1490 | } |
| 1491 | |
| 1492 | err = i40evf_alloc_queues(adapter); |
| 1493 | if (err) { |
| 1494 | dev_err(&adapter->pdev->dev, |
| 1495 | "Unable to allocate memory for queues\n"); |
| 1496 | goto err_alloc_queues; |
| 1497 | } |
| 1498 | |
| 1499 | dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1500 | (adapter->num_active_queues > 1) ? "Enabled" : "Disabled", |
| 1501 | adapter->num_active_queues); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1502 | |
| 1503 | return 0; |
| 1504 | err_alloc_queues: |
| 1505 | i40evf_free_q_vectors(adapter); |
| 1506 | err_alloc_q_vectors: |
| 1507 | i40evf_reset_interrupt_capability(adapter); |
| 1508 | err_set_interrupt: |
| 1509 | return err; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1513 | * i40evf_free_rss - Free memory used by RSS structs |
| 1514 | * @adapter: board private structure |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1515 | **/ |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1516 | static void i40evf_free_rss(struct i40evf_adapter *adapter) |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1517 | { |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1518 | kfree(adapter->rss_key); |
| 1519 | adapter->rss_key = NULL; |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1520 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1521 | kfree(adapter->rss_lut); |
| 1522 | adapter->rss_lut = NULL; |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1526 | * i40evf_watchdog_timer - Periodic call-back timer |
| 1527 | * @data: pointer to adapter disguised as unsigned long |
| 1528 | **/ |
| 1529 | static void i40evf_watchdog_timer(unsigned long data) |
| 1530 | { |
| 1531 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)data; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1532 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1533 | schedule_work(&adapter->watchdog_task); |
| 1534 | /* timer will be rescheduled in watchdog task */ |
| 1535 | } |
| 1536 | |
| 1537 | /** |
| 1538 | * i40evf_watchdog_task - Periodic call-back task |
| 1539 | * @work: pointer to work_struct |
| 1540 | **/ |
| 1541 | static void i40evf_watchdog_task(struct work_struct *work) |
| 1542 | { |
| 1543 | struct i40evf_adapter *adapter = container_of(work, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1544 | struct i40evf_adapter, |
| 1545 | watchdog_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1546 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1547 | u32 reg_val; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1548 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1549 | if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section)) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1550 | goto restart_watchdog; |
| 1551 | |
| 1552 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1553 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1554 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
| 1555 | if ((reg_val == I40E_VFR_VFACTIVE) || |
| 1556 | (reg_val == I40E_VFR_COMPLETED)) { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1557 | /* A chance for redemption! */ |
| 1558 | dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n"); |
| 1559 | adapter->state = __I40EVF_STARTUP; |
| 1560 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 1561 | schedule_delayed_work(&adapter->init_task, 10); |
| 1562 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1563 | &adapter->crit_section); |
| 1564 | /* Don't reschedule the watchdog, since we've restarted |
| 1565 | * the init task. When init_task contacts the PF and |
| 1566 | * gets everything set up again, it'll restart the |
| 1567 | * watchdog for us. Down, boy. Sit. Stay. Woof. |
| 1568 | */ |
| 1569 | return; |
| 1570 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1571 | adapter->aq_required = 0; |
| 1572 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
| 1573 | goto watchdog_done; |
| 1574 | } |
| 1575 | |
| 1576 | if ((adapter->state < __I40EVF_DOWN) || |
| 1577 | (adapter->flags & I40EVF_FLAG_RESET_PENDING)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1578 | goto watchdog_done; |
| 1579 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1580 | /* check for reset */ |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1581 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK; |
| 1582 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) { |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1583 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1584 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1585 | dev_err(&adapter->pdev->dev, "Hardware reset detected\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1586 | schedule_work(&adapter->reset_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1587 | adapter->aq_required = 0; |
| 1588 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1589 | goto watchdog_done; |
| 1590 | } |
| 1591 | |
| 1592 | /* Process admin queue tasks. After init, everything gets done |
| 1593 | * here so we don't race on the admin queue. |
| 1594 | */ |
Mitch Williams | ed63696 | 2015-04-07 19:45:32 -0400 | [diff] [blame] | 1595 | if (adapter->current_op) { |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1596 | if (!i40evf_asq_done(hw)) { |
| 1597 | dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n"); |
| 1598 | i40evf_send_api_ver(adapter); |
| 1599 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1600 | goto watchdog_done; |
Mitch A Williams | 0758e7cb | 2014-12-09 08:53:08 +0000 | [diff] [blame] | 1601 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1602 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) { |
| 1603 | i40evf_send_vf_config_msg(adapter); |
| 1604 | goto watchdog_done; |
| 1605 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1606 | |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1607 | if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) { |
| 1608 | i40evf_disable_queues(adapter); |
| 1609 | goto watchdog_done; |
| 1610 | } |
| 1611 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1612 | if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) { |
| 1613 | i40evf_map_queues(adapter); |
| 1614 | goto watchdog_done; |
| 1615 | } |
| 1616 | |
| 1617 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) { |
| 1618 | i40evf_add_ether_addrs(adapter); |
| 1619 | goto watchdog_done; |
| 1620 | } |
| 1621 | |
| 1622 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) { |
| 1623 | i40evf_add_vlans(adapter); |
| 1624 | goto watchdog_done; |
| 1625 | } |
| 1626 | |
| 1627 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) { |
| 1628 | i40evf_del_ether_addrs(adapter); |
| 1629 | goto watchdog_done; |
| 1630 | } |
| 1631 | |
| 1632 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) { |
| 1633 | i40evf_del_vlans(adapter); |
| 1634 | goto watchdog_done; |
| 1635 | } |
| 1636 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1637 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) { |
| 1638 | i40evf_configure_queues(adapter); |
| 1639 | goto watchdog_done; |
| 1640 | } |
| 1641 | |
| 1642 | if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) { |
| 1643 | i40evf_enable_queues(adapter); |
| 1644 | goto watchdog_done; |
| 1645 | } |
| 1646 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1647 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) { |
| 1648 | /* This message goes straight to the firmware, not the |
| 1649 | * PF, so we don't have to set current_op as we will |
| 1650 | * not get a response through the ARQ. |
| 1651 | */ |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 1652 | i40evf_init_rss(adapter); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1653 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS; |
| 1654 | goto watchdog_done; |
| 1655 | } |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 1656 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_HENA) { |
| 1657 | i40evf_get_hena(adapter); |
| 1658 | goto watchdog_done; |
| 1659 | } |
| 1660 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_HENA) { |
| 1661 | i40evf_set_hena(adapter); |
| 1662 | goto watchdog_done; |
| 1663 | } |
| 1664 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_KEY) { |
| 1665 | i40evf_set_rss_key(adapter); |
| 1666 | goto watchdog_done; |
| 1667 | } |
| 1668 | if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_LUT) { |
| 1669 | i40evf_set_rss_lut(adapter); |
| 1670 | goto watchdog_done; |
| 1671 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1672 | |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1673 | if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_PROMISC) { |
| 1674 | i40evf_set_promiscuous(adapter, I40E_FLAG_VF_UNICAST_PROMISC | |
| 1675 | I40E_FLAG_VF_MULTICAST_PROMISC); |
| 1676 | goto watchdog_done; |
| 1677 | } |
| 1678 | |
Anjali Singhai Jain | f42a5c7 | 2016-05-03 15:13:10 -0700 | [diff] [blame] | 1679 | if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_ALLMULTI) { |
| 1680 | i40evf_set_promiscuous(adapter, I40E_FLAG_VF_MULTICAST_PROMISC); |
| 1681 | goto watchdog_done; |
| 1682 | } |
| 1683 | |
| 1684 | if ((adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_PROMISC) && |
| 1685 | (adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_ALLMULTI)) { |
Anjali Singhai Jain | 47d3483 | 2016-04-12 08:30:52 -0700 | [diff] [blame] | 1686 | i40evf_set_promiscuous(adapter, 0); |
| 1687 | goto watchdog_done; |
| 1688 | } |
| 1689 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1690 | if (adapter->state == __I40EVF_RUNNING) |
| 1691 | i40evf_request_stats(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1692 | watchdog_done: |
Mitch A Williams | 4870e17 | 2014-12-09 08:53:06 +0000 | [diff] [blame] | 1693 | if (adapter->state == __I40EVF_RUNNING) { |
| 1694 | i40evf_irq_enable_queues(adapter, ~0); |
| 1695 | i40evf_fire_sw_int(adapter, 0xFF); |
| 1696 | } else { |
| 1697 | i40evf_fire_sw_int(adapter, 0x1); |
| 1698 | } |
| 1699 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1700 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 1701 | restart_watchdog: |
Ashish Shah | d3e2edb | 2014-08-01 13:27:12 -0700 | [diff] [blame] | 1702 | if (adapter->state == __I40EVF_REMOVE) |
| 1703 | return; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1704 | if (adapter->aq_required) |
| 1705 | mod_timer(&adapter->watchdog_timer, |
| 1706 | jiffies + msecs_to_jiffies(20)); |
| 1707 | else |
| 1708 | mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1709 | schedule_work(&adapter->adminq_task); |
| 1710 | } |
| 1711 | |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1712 | static void i40evf_disable_vf(struct i40evf_adapter *adapter) |
| 1713 | { |
| 1714 | struct i40evf_mac_filter *f, *ftmp; |
| 1715 | struct i40evf_vlan_filter *fv, *fvtmp; |
| 1716 | |
| 1717 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
| 1718 | |
| 1719 | if (netif_running(adapter->netdev)) { |
| 1720 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
| 1721 | netif_carrier_off(adapter->netdev); |
| 1722 | netif_tx_disable(adapter->netdev); |
| 1723 | adapter->link_up = false; |
| 1724 | i40evf_napi_disable_all(adapter); |
| 1725 | i40evf_irq_disable(adapter); |
| 1726 | i40evf_free_traffic_irqs(adapter); |
| 1727 | i40evf_free_all_tx_resources(adapter); |
| 1728 | i40evf_free_all_rx_resources(adapter); |
| 1729 | } |
| 1730 | |
| 1731 | /* Delete all of the filters, both MAC and VLAN. */ |
| 1732 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 1733 | list_del(&f->list); |
| 1734 | kfree(f); |
| 1735 | } |
| 1736 | |
| 1737 | list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, list) { |
| 1738 | list_del(&fv->list); |
| 1739 | kfree(fv); |
| 1740 | } |
| 1741 | |
| 1742 | i40evf_free_misc_irq(adapter); |
| 1743 | i40evf_reset_interrupt_capability(adapter); |
| 1744 | i40evf_free_queues(adapter); |
| 1745 | i40evf_free_q_vectors(adapter); |
| 1746 | kfree(adapter->vf_res); |
| 1747 | i40evf_shutdown_adminq(&adapter->hw); |
| 1748 | adapter->netdev->flags &= ~IFF_UP; |
| 1749 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
| 1750 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1751 | adapter->state = __I40EVF_DOWN; |
| 1752 | dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n"); |
| 1753 | } |
| 1754 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1755 | #define I40EVF_RESET_WAIT_MS 10 |
| 1756 | #define I40EVF_RESET_WAIT_COUNT 500 |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1757 | /** |
| 1758 | * i40evf_reset_task - Call-back task to handle hardware reset |
| 1759 | * @work: pointer to work_struct |
| 1760 | * |
| 1761 | * During reset we need to shut down and reinitialize the admin queue |
| 1762 | * before we can use it to communicate with the PF again. We also clear |
| 1763 | * and reinit the rings because that context is lost as well. |
| 1764 | **/ |
| 1765 | static void i40evf_reset_task(struct work_struct *work) |
| 1766 | { |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1767 | struct i40evf_adapter *adapter = container_of(work, |
| 1768 | struct i40evf_adapter, |
| 1769 | reset_task); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1770 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1771 | struct i40e_hw *hw = &adapter->hw; |
Mitch Williams | 40d0136 | 2015-10-01 14:37:37 -0400 | [diff] [blame] | 1772 | struct i40evf_vlan_filter *vlf; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1773 | struct i40evf_mac_filter *f; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1774 | u32 reg_val; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1775 | int i = 0, err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1776 | |
| 1777 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
| 1778 | &adapter->crit_section)) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 1779 | usleep_range(500, 1000); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1780 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1781 | i40evf_misc_irq_disable(adapter); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1782 | if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1783 | adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED; |
| 1784 | /* Restart the AQ here. If we have been reset but didn't |
| 1785 | * detect it, or if the PF had to reinit, our AQ will be hosed. |
| 1786 | */ |
| 1787 | i40evf_shutdown_adminq(hw); |
| 1788 | i40evf_init_adminq(hw); |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1789 | i40evf_request_reset(adapter); |
| 1790 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1791 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
Mitch Williams | 3526d80 | 2014-03-06 08:59:56 +0000 | [diff] [blame] | 1792 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1793 | /* poll until we see the reset actually happen */ |
| 1794 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1795 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & |
| 1796 | I40E_VF_ARQLEN1_ARQENABLE_MASK; |
| 1797 | if (!reg_val) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1798 | break; |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1799 | usleep_range(5000, 10000); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1800 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1801 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1802 | dev_info(&adapter->pdev->dev, "Never saw reset\n"); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1803 | goto continue_reset; /* act like the reset happened */ |
| 1804 | } |
| 1805 | |
| 1806 | /* wait until the reset is complete and the PF is responding to us */ |
| 1807 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1808 | /* sleep first to make sure a minimum wait time is met */ |
| 1809 | msleep(I40EVF_RESET_WAIT_MS); |
| 1810 | |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1811 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
| 1812 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
| 1813 | if (reg_val == I40E_VFR_VFACTIVE) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1814 | break; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1815 | } |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1816 | |
Mitch Williams | 509a447 | 2015-12-23 12:05:52 -0800 | [diff] [blame] | 1817 | pci_set_master(adapter->pdev); |
Jacob Keller | 7d3f04a | 2016-10-05 09:30:45 -0700 | [diff] [blame] | 1818 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1819 | if (i == I40EVF_RESET_WAIT_COUNT) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1820 | dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", |
Mitch Williams | ee5c1e9 | 2015-08-28 17:55:53 -0400 | [diff] [blame] | 1821 | reg_val); |
Joe Perches | dedecb6 | 2016-11-01 15:35:14 -0700 | [diff] [blame] | 1822 | i40evf_disable_vf(adapter); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1823 | return; /* Do not attempt to reinit. It's dead, Jim. */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1824 | } |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1825 | |
| 1826 | continue_reset: |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1827 | if (netif_running(adapter->netdev)) { |
| 1828 | netif_carrier_off(netdev); |
| 1829 | netif_tx_stop_all_queues(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 1830 | adapter->link_up = false; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1831 | i40evf_napi_disable_all(adapter); |
| 1832 | } |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1833 | i40evf_irq_disable(adapter); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1834 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1835 | adapter->state = __I40EVF_RESETTING; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1836 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
| 1837 | |
| 1838 | /* free the Tx/Rx rings and descriptors, might be better to just |
| 1839 | * re-use them sometime in the future |
| 1840 | */ |
| 1841 | i40evf_free_all_rx_resources(adapter); |
| 1842 | i40evf_free_all_tx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1843 | |
| 1844 | /* kill and reinit the admin queue */ |
Lihong Yang | 903e683 | 2016-09-06 18:05:05 -0700 | [diff] [blame] | 1845 | i40evf_shutdown_adminq(hw); |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1846 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1847 | err = i40evf_init_adminq(hw); |
| 1848 | if (err) |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1849 | dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n", |
| 1850 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1851 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1852 | adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG; |
| 1853 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1854 | |
| 1855 | /* re-add all MAC filters */ |
| 1856 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
| 1857 | f->add = true; |
| 1858 | } |
| 1859 | /* re-add all VLAN filters */ |
Mitch Williams | 40d0136 | 2015-10-01 14:37:37 -0400 | [diff] [blame] | 1860 | list_for_each_entry(vlf, &adapter->vlan_filter_list, list) { |
| 1861 | vlf->add = true; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1862 | } |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 1863 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
Mitch Williams | ac833bb | 2015-01-29 07:17:19 +0000 | [diff] [blame] | 1864 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
Avinash Dayanand | bf3a178 | 2016-08-17 16:04:08 -0700 | [diff] [blame] | 1865 | /* Open RDMA Client again */ |
| 1866 | adapter->aq_required |= I40EVF_FLAG_SERVICE_CLIENT_REQUESTED; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1867 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1868 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1869 | |
| 1870 | mod_timer(&adapter->watchdog_timer, jiffies + 2); |
| 1871 | |
| 1872 | if (netif_running(adapter->netdev)) { |
| 1873 | /* allocate transmit descriptors */ |
| 1874 | err = i40evf_setup_all_tx_resources(adapter); |
| 1875 | if (err) |
| 1876 | goto reset_err; |
| 1877 | |
| 1878 | /* allocate receive descriptors */ |
| 1879 | err = i40evf_setup_all_rx_resources(adapter); |
| 1880 | if (err) |
| 1881 | goto reset_err; |
| 1882 | |
| 1883 | i40evf_configure(adapter); |
| 1884 | |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 1885 | i40evf_up_complete(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1886 | |
| 1887 | i40evf_irq_enable(adapter, true); |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1888 | } else { |
| 1889 | adapter->state = __I40EVF_DOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1890 | } |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1891 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1892 | return; |
| 1893 | reset_err: |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 1894 | dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1895 | i40evf_close(adapter->netdev); |
| 1896 | } |
| 1897 | |
| 1898 | /** |
| 1899 | * i40evf_adminq_task - worker thread to clean the admin queue |
| 1900 | * @work: pointer to work_struct containing our data |
| 1901 | **/ |
| 1902 | static void i40evf_adminq_task(struct work_struct *work) |
| 1903 | { |
| 1904 | struct i40evf_adapter *adapter = |
| 1905 | container_of(work, struct i40evf_adapter, adminq_task); |
| 1906 | struct i40e_hw *hw = &adapter->hw; |
| 1907 | struct i40e_arq_event_info event; |
| 1908 | struct i40e_virtchnl_msg *v_msg; |
| 1909 | i40e_status ret; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1910 | u32 val, oldval; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1911 | u16 pending; |
| 1912 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1913 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1914 | goto out; |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 1915 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 1916 | event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; |
| 1917 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1918 | if (!event.msg_buf) |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1919 | goto out; |
Mitch Williams | 249c8b8 | 2014-05-10 04:49:04 +0000 | [diff] [blame] | 1920 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1921 | v_msg = (struct i40e_virtchnl_msg *)&event.desc; |
| 1922 | do { |
| 1923 | ret = i40evf_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 8b011eb | 2015-01-09 11:18:17 +0000 | [diff] [blame] | 1924 | if (ret || !v_msg->v_opcode) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1925 | break; /* No event to process or error cleaning ARQ */ |
| 1926 | |
| 1927 | i40evf_virtchnl_completion(adapter, v_msg->v_opcode, |
| 1928 | v_msg->v_retval, event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 1929 | event.msg_len); |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 1930 | if (pending != 0) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1931 | memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1932 | } while (pending); |
| 1933 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1934 | if ((adapter->flags & |
| 1935 | (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) || |
| 1936 | adapter->state == __I40EVF_RESETTING) |
| 1937 | goto freedom; |
| 1938 | |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1939 | /* check for error indications */ |
| 1940 | val = rd32(hw, hw->aq.arq.len); |
Mitch Williams | 19b73d8 | 2016-03-10 14:59:49 -0800 | [diff] [blame] | 1941 | if (val == 0xdeadbeef) /* indicates device in reset */ |
| 1942 | goto freedom; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1943 | oldval = val; |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1944 | if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1945 | dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1946 | val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1947 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1948 | if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1949 | dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1950 | val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1951 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1952 | if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1953 | dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1954 | val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1955 | } |
| 1956 | if (oldval != val) |
| 1957 | wr32(hw, hw->aq.arq.len, val); |
| 1958 | |
| 1959 | val = rd32(hw, hw->aq.asq.len); |
| 1960 | oldval = val; |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1961 | if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1962 | dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1963 | val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1964 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1965 | if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1966 | dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1967 | val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1968 | } |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1969 | if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) { |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1970 | dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n"); |
Anjali Singhai Jain | b1f3366 | 2015-07-10 19:36:05 -0400 | [diff] [blame] | 1971 | val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK; |
Mitch Williams | 912257e | 2014-05-22 06:32:07 +0000 | [diff] [blame] | 1972 | } |
| 1973 | if (oldval != val) |
| 1974 | wr32(hw, hw->aq.asq.len, val); |
| 1975 | |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 1976 | freedom: |
Mitch A Williams | 7235448 | 2014-12-09 08:53:07 +0000 | [diff] [blame] | 1977 | kfree(event.msg_buf); |
| 1978 | out: |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1979 | /* re-enable Admin queue interrupt cause */ |
| 1980 | i40evf_misc_irq_enable(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * i40evf_free_all_tx_resources - Free Tx Resources for All Queues |
| 1985 | * @adapter: board private structure |
| 1986 | * |
| 1987 | * Free all transmit software resources |
| 1988 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 1989 | void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1990 | { |
| 1991 | int i; |
| 1992 | |
Mitch Williams | fdb47ae | 2015-11-19 11:34:18 -0800 | [diff] [blame] | 1993 | if (!adapter->tx_rings) |
| 1994 | return; |
| 1995 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 1996 | for (i = 0; i < adapter->num_active_queues; i++) |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 1997 | if (adapter->tx_rings[i].desc) |
| 1998 | i40evf_free_tx_resources(&adapter->tx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
| 2002 | * i40evf_setup_all_tx_resources - allocate all queues Tx resources |
| 2003 | * @adapter: board private structure |
| 2004 | * |
| 2005 | * If this function returns with an error, then it's possible one or |
| 2006 | * more of the rings is populated (while the rest are not). It is the |
| 2007 | * callers duty to clean those orphaned rings. |
| 2008 | * |
| 2009 | * Return 0 on success, negative on failure |
| 2010 | **/ |
| 2011 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter) |
| 2012 | { |
| 2013 | int i, err = 0; |
| 2014 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2015 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2016 | adapter->tx_rings[i].count = adapter->tx_desc_count; |
| 2017 | err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2018 | if (!err) |
| 2019 | continue; |
| 2020 | dev_err(&adapter->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 2021 | "Allocation for Tx Queue %u failed\n", i); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2022 | break; |
| 2023 | } |
| 2024 | |
| 2025 | return err; |
| 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * i40evf_setup_all_rx_resources - allocate all queues Rx resources |
| 2030 | * @adapter: board private structure |
| 2031 | * |
| 2032 | * If this function returns with an error, then it's possible one or |
| 2033 | * more of the rings is populated (while the rest are not). It is the |
| 2034 | * callers duty to clean those orphaned rings. |
| 2035 | * |
| 2036 | * Return 0 on success, negative on failure |
| 2037 | **/ |
| 2038 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter) |
| 2039 | { |
| 2040 | int i, err = 0; |
| 2041 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2042 | for (i = 0; i < adapter->num_active_queues; i++) { |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2043 | adapter->rx_rings[i].count = adapter->rx_desc_count; |
| 2044 | err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2045 | if (!err) |
| 2046 | continue; |
| 2047 | dev_err(&adapter->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 2048 | "Allocation for Rx Queue %u failed\n", i); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | return err; |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * i40evf_free_all_rx_resources - Free Rx Resources for All Queues |
| 2056 | * @adapter: board private structure |
| 2057 | * |
| 2058 | * Free all receive software resources |
| 2059 | **/ |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 2060 | void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2061 | { |
| 2062 | int i; |
| 2063 | |
Mitch Williams | fdb47ae | 2015-11-19 11:34:18 -0800 | [diff] [blame] | 2064 | if (!adapter->rx_rings) |
| 2065 | return; |
| 2066 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2067 | for (i = 0; i < adapter->num_active_queues; i++) |
Mitch Williams | 0dd438d | 2015-10-26 19:44:40 -0400 | [diff] [blame] | 2068 | if (adapter->rx_rings[i].desc) |
| 2069 | i40evf_free_rx_resources(&adapter->rx_rings[i]); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * i40evf_open - Called when a network interface is made active |
| 2074 | * @netdev: network interface device structure |
| 2075 | * |
| 2076 | * Returns 0 on success, negative value on failure |
| 2077 | * |
| 2078 | * The open entry point is called when a network interface is made |
| 2079 | * active by the system (IFF_UP). At this point all resources needed |
| 2080 | * for transmit and receive operations are allocated, the interrupt |
| 2081 | * handler is registered with the OS, the watchdog timer is started, |
| 2082 | * and the stack is notified that the interface is ready. |
| 2083 | **/ |
| 2084 | static int i40evf_open(struct net_device *netdev) |
| 2085 | { |
| 2086 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2087 | int err; |
| 2088 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2089 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
| 2090 | dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); |
| 2091 | return -EIO; |
| 2092 | } |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2093 | |
| 2094 | if (adapter->state != __I40EVF_DOWN) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2095 | return -EBUSY; |
| 2096 | |
| 2097 | /* allocate transmit descriptors */ |
| 2098 | err = i40evf_setup_all_tx_resources(adapter); |
| 2099 | if (err) |
| 2100 | goto err_setup_tx; |
| 2101 | |
| 2102 | /* allocate receive descriptors */ |
| 2103 | err = i40evf_setup_all_rx_resources(adapter); |
| 2104 | if (err) |
| 2105 | goto err_setup_rx; |
| 2106 | |
| 2107 | /* clear any pending interrupts, may auto mask */ |
| 2108 | err = i40evf_request_traffic_irqs(adapter, netdev->name); |
| 2109 | if (err) |
| 2110 | goto err_req_irq; |
| 2111 | |
Mitch Williams | 44151cd | 2015-04-27 14:57:17 -0400 | [diff] [blame] | 2112 | i40evf_add_filter(adapter, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2113 | i40evf_configure(adapter); |
| 2114 | |
Bimmy Pujari | cb130a0 | 2016-09-06 18:05:03 -0700 | [diff] [blame] | 2115 | i40evf_up_complete(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2116 | |
| 2117 | i40evf_irq_enable(adapter, true); |
| 2118 | |
| 2119 | return 0; |
| 2120 | |
| 2121 | err_req_irq: |
| 2122 | i40evf_down(adapter); |
| 2123 | i40evf_free_traffic_irqs(adapter); |
| 2124 | err_setup_rx: |
| 2125 | i40evf_free_all_rx_resources(adapter); |
| 2126 | err_setup_tx: |
| 2127 | i40evf_free_all_tx_resources(adapter); |
| 2128 | |
| 2129 | return err; |
| 2130 | } |
| 2131 | |
| 2132 | /** |
| 2133 | * i40evf_close - Disables a network interface |
| 2134 | * @netdev: network interface device structure |
| 2135 | * |
| 2136 | * Returns 0, this is not allowed to fail |
| 2137 | * |
| 2138 | * The close entry point is called when an interface is de-activated |
| 2139 | * by the OS. The hardware is still under the drivers control, but |
| 2140 | * needs to be disabled. All IRQs except vector 0 (reserved for admin queue) |
| 2141 | * are freed, along with all transmit and receive resources. |
| 2142 | **/ |
| 2143 | static int i40evf_close(struct net_device *netdev) |
| 2144 | { |
| 2145 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2146 | |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2147 | if (adapter->state <= __I40EVF_DOWN_PENDING) |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2148 | return 0; |
| 2149 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2150 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2151 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
| 2152 | |
| 2153 | i40evf_down(adapter); |
Mitch Williams | 209dc4d | 2015-12-09 15:50:27 -0800 | [diff] [blame] | 2154 | adapter->state = __I40EVF_DOWN_PENDING; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2155 | i40evf_free_traffic_irqs(adapter); |
| 2156 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2157 | return 0; |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * i40evf_get_stats - Get System Network Statistics |
| 2162 | * @netdev: network interface device structure |
| 2163 | * |
| 2164 | * Returns the address of the device statistics structure. |
| 2165 | * The statistics are actually updated from the timer callback. |
| 2166 | **/ |
| 2167 | static struct net_device_stats *i40evf_get_stats(struct net_device *netdev) |
| 2168 | { |
| 2169 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2170 | |
| 2171 | /* only return the current stats */ |
| 2172 | return &adapter->net_stats; |
| 2173 | } |
| 2174 | |
| 2175 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2176 | * i40evf_change_mtu - Change the Maximum Transfer Unit |
| 2177 | * @netdev: network interface device structure |
| 2178 | * @new_mtu: new value for maximum frame size |
| 2179 | * |
| 2180 | * Returns 0 on success, negative on failure |
| 2181 | **/ |
| 2182 | static int i40evf_change_mtu(struct net_device *netdev, int new_mtu) |
| 2183 | { |
| 2184 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2185 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2186 | netdev->mtu = new_mtu; |
Mitch Williams | 67c818a | 2015-06-19 08:56:30 -0700 | [diff] [blame] | 2187 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
| 2188 | schedule_work(&adapter->reset_task); |
| 2189 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2190 | return 0; |
| 2191 | } |
| 2192 | |
Alexander Duyck | 06fc016 | 2016-10-25 16:08:47 -0700 | [diff] [blame] | 2193 | /** |
| 2194 | * i40evf_features_check - Validate encapsulated packet conforms to limits |
| 2195 | * @skb: skb buff |
| 2196 | * @netdev: This physical port's netdev |
| 2197 | * @features: Offload features that the stack believes apply |
| 2198 | **/ |
| 2199 | static netdev_features_t i40evf_features_check(struct sk_buff *skb, |
| 2200 | struct net_device *dev, |
| 2201 | netdev_features_t features) |
| 2202 | { |
| 2203 | size_t len; |
| 2204 | |
| 2205 | /* No point in doing any of this if neither checksum nor GSO are |
| 2206 | * being requested for this frame. We can rule out both by just |
| 2207 | * checking for CHECKSUM_PARTIAL |
| 2208 | */ |
| 2209 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 2210 | return features; |
| 2211 | |
| 2212 | /* We cannot support GSO if the MSS is going to be less than |
| 2213 | * 64 bytes. If it is then we need to drop support for GSO. |
| 2214 | */ |
| 2215 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 2216 | features &= ~NETIF_F_GSO_MASK; |
| 2217 | |
| 2218 | /* MACLEN can support at most 63 words */ |
| 2219 | len = skb_network_header(skb) - skb->data; |
| 2220 | if (len & ~(63 * 2)) |
| 2221 | goto out_err; |
| 2222 | |
| 2223 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 2224 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 2225 | if (len & ~(127 * 4)) |
| 2226 | goto out_err; |
| 2227 | |
| 2228 | if (skb->encapsulation) { |
| 2229 | /* L4TUNLEN can support 127 words */ |
| 2230 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 2231 | if (len & ~(127 * 2)) |
| 2232 | goto out_err; |
| 2233 | |
| 2234 | /* IPLEN can support at most 127 dwords */ |
| 2235 | len = skb_inner_transport_header(skb) - |
| 2236 | skb_inner_network_header(skb); |
| 2237 | if (len & ~(127 * 4)) |
| 2238 | goto out_err; |
| 2239 | } |
| 2240 | |
| 2241 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 2242 | * a flexible value and we support all possible values supported |
| 2243 | * by TCP, which is at most 15 dwords |
| 2244 | */ |
| 2245 | |
| 2246 | return features; |
| 2247 | out_err: |
| 2248 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
| 2249 | } |
| 2250 | |
Mitch Williams | c4445ae | 2016-03-18 12:18:07 -0700 | [diff] [blame] | 2251 | #define I40EVF_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_TX |\ |
| 2252 | NETIF_F_HW_VLAN_CTAG_RX |\ |
| 2253 | NETIF_F_HW_VLAN_CTAG_FILTER) |
| 2254 | |
| 2255 | /** |
| 2256 | * i40evf_fix_features - fix up the netdev feature bits |
| 2257 | * @netdev: our net device |
| 2258 | * @features: desired feature bits |
| 2259 | * |
| 2260 | * Returns fixed-up features bits |
| 2261 | **/ |
| 2262 | static netdev_features_t i40evf_fix_features(struct net_device *netdev, |
| 2263 | netdev_features_t features) |
| 2264 | { |
| 2265 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2266 | |
| 2267 | features &= ~I40EVF_VLAN_FEATURES; |
| 2268 | if (adapter->vf_res->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) |
| 2269 | features |= I40EVF_VLAN_FEATURES; |
| 2270 | return features; |
| 2271 | } |
| 2272 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2273 | static const struct net_device_ops i40evf_netdev_ops = { |
| 2274 | .ndo_open = i40evf_open, |
| 2275 | .ndo_stop = i40evf_close, |
| 2276 | .ndo_start_xmit = i40evf_xmit_frame, |
| 2277 | .ndo_get_stats = i40evf_get_stats, |
| 2278 | .ndo_set_rx_mode = i40evf_set_rx_mode, |
| 2279 | .ndo_validate_addr = eth_validate_addr, |
| 2280 | .ndo_set_mac_address = i40evf_set_mac, |
| 2281 | .ndo_change_mtu = i40evf_change_mtu, |
| 2282 | .ndo_tx_timeout = i40evf_tx_timeout, |
| 2283 | .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid, |
| 2284 | .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid, |
Alexander Duyck | 06fc016 | 2016-10-25 16:08:47 -0700 | [diff] [blame] | 2285 | .ndo_features_check = i40evf_features_check, |
Mitch Williams | c4445ae | 2016-03-18 12:18:07 -0700 | [diff] [blame] | 2286 | .ndo_fix_features = i40evf_fix_features, |
Alexander Duyck | 7709b4c | 2015-09-24 09:04:38 -0700 | [diff] [blame] | 2287 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2288 | .ndo_poll_controller = i40evf_netpoll, |
| 2289 | #endif |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2290 | }; |
| 2291 | |
| 2292 | /** |
| 2293 | * i40evf_check_reset_complete - check that VF reset is complete |
| 2294 | * @hw: pointer to hw struct |
| 2295 | * |
| 2296 | * Returns 0 if device is ready to use, or -EBUSY if it's in reset. |
| 2297 | **/ |
| 2298 | static int i40evf_check_reset_complete(struct i40e_hw *hw) |
| 2299 | { |
| 2300 | u32 rstat; |
| 2301 | int i; |
| 2302 | |
| 2303 | for (i = 0; i < 100; i++) { |
Ashish Shah | fd35886 | 2014-08-01 13:27:11 -0700 | [diff] [blame] | 2304 | rstat = rd32(hw, I40E_VFGEN_RSTAT) & |
| 2305 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; |
| 2306 | if ((rstat == I40E_VFR_VFACTIVE) || |
| 2307 | (rstat == I40E_VFR_COMPLETED)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2308 | return 0; |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 2309 | usleep_range(10, 20); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2310 | } |
| 2311 | return -EBUSY; |
| 2312 | } |
| 2313 | |
| 2314 | /** |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2315 | * i40evf_process_config - Process the config information we got from the PF |
| 2316 | * @adapter: board private structure |
| 2317 | * |
| 2318 | * Verify that we have a valid config struct, and set up our netdev features |
| 2319 | * and our VSI struct. |
| 2320 | **/ |
| 2321 | int i40evf_process_config(struct i40evf_adapter *adapter) |
| 2322 | { |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2323 | struct i40e_virtchnl_vf_resource *vfres = adapter->vf_res; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2324 | struct net_device *netdev = adapter->netdev; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2325 | struct i40e_vsi *vsi = &adapter->vsi; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2326 | int i; |
| 2327 | |
| 2328 | /* got VF config message back from PF, now we can parse it */ |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2329 | for (i = 0; i < vfres->num_vsis; i++) { |
| 2330 | if (vfres->vsi_res[i].vsi_type == I40E_VSI_SRIOV) |
| 2331 | adapter->vsi_res = &vfres->vsi_res[i]; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2332 | } |
| 2333 | if (!adapter->vsi_res) { |
| 2334 | dev_err(&adapter->pdev->dev, "No LAN VSI found\n"); |
| 2335 | return -ENODEV; |
| 2336 | } |
| 2337 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2338 | netdev->hw_enc_features |= NETIF_F_SG | |
| 2339 | NETIF_F_IP_CSUM | |
| 2340 | NETIF_F_IPV6_CSUM | |
| 2341 | NETIF_F_HIGHDMA | |
| 2342 | NETIF_F_SOFT_FEATURES | |
| 2343 | NETIF_F_TSO | |
| 2344 | NETIF_F_TSO_ECN | |
| 2345 | NETIF_F_TSO6 | |
| 2346 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2347 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 2348 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 2349 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2350 | NETIF_F_GSO_UDP_TUNNEL | |
| 2351 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2352 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2353 | NETIF_F_SCTP_CRC | |
| 2354 | NETIF_F_RXHASH | |
| 2355 | NETIF_F_RXCSUM | |
| 2356 | 0; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2357 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2358 | if (!(adapter->flags & I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2359 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 2360 | |
| 2361 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | f608e6a | 2016-01-24 21:17:57 -0800 | [diff] [blame] | 2362 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2363 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2364 | netdev->vlan_features |= netdev->hw_enc_features | |
| 2365 | NETIF_F_TSO_MANGLEID; |
Alexander Duyck | f608e6a | 2016-01-24 21:17:57 -0800 | [diff] [blame] | 2366 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2367 | /* Write features and hw_features separately to avoid polluting |
| 2368 | * with, or dropping, features that are set when we registgered. |
| 2369 | */ |
| 2370 | netdev->hw_features |= netdev->hw_enc_features; |
Mitch Williams | ba6cc7f | 2016-04-01 13:34:31 -0700 | [diff] [blame] | 2371 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2372 | netdev->features |= netdev->hw_enc_features | I40EVF_VLAN_FEATURES; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 2373 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 2374 | |
| 2375 | /* disable VLAN features if not supported */ |
| 2376 | if (!(vfres->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_VLAN)) |
| 2377 | netdev->features ^= I40EVF_VLAN_FEATURES; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2378 | |
| 2379 | adapter->vsi.id = adapter->vsi_res->vsi_id; |
| 2380 | |
| 2381 | adapter->vsi.back = adapter; |
| 2382 | adapter->vsi.base_vector = 1; |
| 2383 | adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2384 | vsi->netdev = adapter->netdev; |
| 2385 | vsi->qs_handle = adapter->vsi_res->qset_handle; |
| 2386 | if (vfres->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF) { |
| 2387 | adapter->rss_key_size = vfres->rss_key_size; |
| 2388 | adapter->rss_lut_size = vfres->rss_lut_size; |
| 2389 | } else { |
| 2390 | adapter->rss_key_size = I40EVF_HKEY_ARRAY_SIZE; |
| 2391 | adapter->rss_lut_size = I40EVF_HLUT_ARRAY_SIZE; |
| 2392 | } |
| 2393 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2394 | return 0; |
| 2395 | } |
| 2396 | |
| 2397 | /** |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2398 | * i40evf_init_task - worker thread to perform delayed initialization |
| 2399 | * @work: pointer to work_struct containing our data |
| 2400 | * |
| 2401 | * This task completes the work that was begun in probe. Due to the nature |
| 2402 | * 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] | 2403 | * 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] | 2404 | * whole system, we'll do it in a task so we can sleep. |
| 2405 | * This task only runs during driver init. Once we've established |
| 2406 | * communications with the PF driver and set up our netdev, the watchdog |
| 2407 | * takes over. |
| 2408 | **/ |
| 2409 | static void i40evf_init_task(struct work_struct *work) |
| 2410 | { |
| 2411 | struct i40evf_adapter *adapter = container_of(work, |
| 2412 | struct i40evf_adapter, |
| 2413 | init_task.work); |
| 2414 | struct net_device *netdev = adapter->netdev; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2415 | struct i40e_hw *hw = &adapter->hw; |
| 2416 | struct pci_dev *pdev = adapter->pdev; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2417 | int err, bufsz; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2418 | |
| 2419 | switch (adapter->state) { |
| 2420 | case __I40EVF_STARTUP: |
| 2421 | /* driver loaded, probe complete */ |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2422 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
| 2423 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2424 | err = i40e_set_mac_type(hw); |
| 2425 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2426 | dev_err(&pdev->dev, "Failed to set MAC type (%d)\n", |
| 2427 | err); |
Mitch Williams | 2619ef4 | 2015-04-07 19:45:30 -0400 | [diff] [blame] | 2428 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2429 | } |
| 2430 | err = i40evf_check_reset_complete(hw); |
| 2431 | if (err) { |
Mitch Williams | 0d9c7ea | 2014-04-23 04:50:00 +0000 | [diff] [blame] | 2432 | dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n", |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2433 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2434 | goto err; |
| 2435 | } |
| 2436 | hw->aq.num_arq_entries = I40EVF_AQ_LEN; |
| 2437 | hw->aq.num_asq_entries = I40EVF_AQ_LEN; |
| 2438 | hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2439 | hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; |
| 2440 | |
| 2441 | err = i40evf_init_adminq(hw); |
| 2442 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2443 | dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n", |
| 2444 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2445 | goto err; |
| 2446 | } |
| 2447 | err = i40evf_send_api_ver(adapter); |
| 2448 | if (err) { |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2449 | dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2450 | i40evf_shutdown_adminq(hw); |
| 2451 | goto err; |
| 2452 | } |
| 2453 | adapter->state = __I40EVF_INIT_VERSION_CHECK; |
| 2454 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2455 | case __I40EVF_INIT_VERSION_CHECK: |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2456 | if (!i40evf_asq_done(hw)) { |
Mitch Williams | 80e7289 | 2014-05-10 04:49:06 +0000 | [diff] [blame] | 2457 | dev_err(&pdev->dev, "Admin queue command never completed\n"); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2458 | i40evf_shutdown_adminq(hw); |
| 2459 | adapter->state = __I40EVF_STARTUP; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2460 | goto err; |
Mitch Williams | 10bdd67 | 2014-03-06 08:59:53 +0000 | [diff] [blame] | 2461 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2462 | |
| 2463 | /* aq msg sent, awaiting reply */ |
| 2464 | err = i40evf_verify_api_ver(adapter); |
| 2465 | if (err) { |
Mitch A Williams | d4f82fd | 2014-12-09 08:53:03 +0000 | [diff] [blame] | 2466 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Mitch Williams | 56f9920 | 2014-06-04 04:22:41 +0000 | [diff] [blame] | 2467 | err = i40evf_send_api_ver(adapter); |
Mitch Williams | ee1693e | 2015-06-04 16:23:59 -0400 | [diff] [blame] | 2468 | else |
| 2469 | dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n", |
| 2470 | adapter->pf_version.major, |
| 2471 | adapter->pf_version.minor, |
| 2472 | I40E_VIRTCHNL_VERSION_MAJOR, |
| 2473 | I40E_VIRTCHNL_VERSION_MINOR); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2474 | goto err; |
| 2475 | } |
| 2476 | err = i40evf_send_vf_config_msg(adapter); |
| 2477 | if (err) { |
Mitch Williams | 3f2ab17 | 2014-06-04 04:22:40 +0000 | [diff] [blame] | 2478 | dev_err(&pdev->dev, "Unable to send config request (%d)\n", |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2479 | err); |
| 2480 | goto err; |
| 2481 | } |
| 2482 | adapter->state = __I40EVF_INIT_GET_RESOURCES; |
| 2483 | goto restart; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2484 | case __I40EVF_INIT_GET_RESOURCES: |
| 2485 | /* aq msg sent, awaiting reply */ |
| 2486 | if (!adapter->vf_res) { |
| 2487 | bufsz = sizeof(struct i40e_virtchnl_vf_resource) + |
| 2488 | (I40E_MAX_VF_VSI * |
| 2489 | sizeof(struct i40e_virtchnl_vsi_resource)); |
| 2490 | adapter->vf_res = kzalloc(bufsz, GFP_KERNEL); |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2491 | if (!adapter->vf_res) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2492 | goto err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2493 | } |
| 2494 | err = i40evf_get_vf_config(adapter); |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2495 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2496 | err = i40evf_send_vf_config_msg(adapter); |
| 2497 | goto err; |
Mitch Williams | e743072 | 2015-10-26 19:44:38 -0400 | [diff] [blame] | 2498 | } else if (err == I40E_ERR_PARAM) { |
| 2499 | /* We only get ERR_PARAM if the device is in a very bad |
| 2500 | * state or if we've been disabled for previous bad |
| 2501 | * behavior. Either way, we're done now. |
| 2502 | */ |
| 2503 | i40evf_shutdown_adminq(hw); |
| 2504 | dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n"); |
| 2505 | return; |
Mitch Williams | 906a693 | 2014-11-13 03:06:12 +0000 | [diff] [blame] | 2506 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2507 | if (err) { |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2508 | dev_err(&pdev->dev, "Unable to get VF config (%d)\n", |
| 2509 | err); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2510 | goto err_alloc; |
| 2511 | } |
| 2512 | adapter->state = __I40EVF_INIT_SW; |
| 2513 | break; |
| 2514 | default: |
| 2515 | goto err_alloc; |
| 2516 | } |
Alexander Duyck | f608e6a | 2016-01-24 21:17:57 -0800 | [diff] [blame] | 2517 | |
| 2518 | if (hw->mac.type == I40E_MAC_X722_VF) |
| 2519 | adapter->flags |= I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE; |
| 2520 | |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2521 | if (i40evf_process_config(adapter)) |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2522 | goto err_alloc; |
Mitch Williams | e6d038d | 2015-06-04 16:23:58 -0400 | [diff] [blame] | 2523 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2524 | |
| 2525 | adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED; |
| 2526 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2527 | netdev->netdev_ops = &i40evf_netdev_ops; |
| 2528 | i40evf_set_ethtool_ops(netdev); |
| 2529 | netdev->watchdog_timeo = 5 * HZ; |
Greg Rose | 3415e8c | 2014-01-30 12:40:27 +0000 | [diff] [blame] | 2530 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 2531 | /* MTU range: 68 - 9710 */ |
| 2532 | netdev->min_mtu = ETH_MIN_MTU; |
| 2533 | netdev->max_mtu = I40E_MAX_RXBUFFER - (ETH_HLEN + ETH_FCS_LEN); |
| 2534 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2535 | if (!is_valid_ether_addr(adapter->hw.mac.addr)) { |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2536 | dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n", |
Mitch Williams | c2a137c | 2014-02-20 19:29:09 -0800 | [diff] [blame] | 2537 | adapter->hw.mac.addr); |
Mitch Williams | 14e52ee | 2015-08-31 19:54:44 -0400 | [diff] [blame] | 2538 | eth_hw_addr_random(netdev); |
| 2539 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); |
| 2540 | } else { |
| 2541 | adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF; |
| 2542 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
| 2543 | ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2544 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2545 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2546 | init_timer(&adapter->watchdog_timer); |
| 2547 | adapter->watchdog_timer.function = &i40evf_watchdog_timer; |
| 2548 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 2549 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 2550 | |
Mitch Williams | cc05292 | 2014-10-25 03:24:34 +0000 | [diff] [blame] | 2551 | adapter->num_active_queues = min_t(int, |
| 2552 | adapter->vsi_res->num_queue_pairs, |
| 2553 | (int)(num_online_cpus())); |
Mitch Williams | d732a18 | 2014-04-24 06:41:37 +0000 | [diff] [blame] | 2554 | adapter->tx_desc_count = I40EVF_DEFAULT_TXD; |
| 2555 | adapter->rx_desc_count = I40EVF_DEFAULT_RXD; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2556 | err = i40evf_init_interrupt_scheme(adapter); |
| 2557 | if (err) |
| 2558 | goto err_sw_init; |
| 2559 | i40evf_map_rings_to_vectors(adapter); |
Anjali Singhai Jain | 1f01227 | 2015-09-03 17:18:53 -0400 | [diff] [blame] | 2560 | if (adapter->vf_res->vf_offload_flags & |
Anjali Singhai Jain | f6d83d1 | 2015-12-22 14:25:07 -0800 | [diff] [blame] | 2561 | I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) |
| 2562 | adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE; |
| 2563 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2564 | err = i40evf_request_misc_irq(adapter); |
| 2565 | if (err) |
| 2566 | goto err_sw_init; |
| 2567 | |
| 2568 | netif_carrier_off(netdev); |
Sridhar Samudrala | 3f341ac | 2016-09-01 22:27:27 +0200 | [diff] [blame] | 2569 | adapter->link_up = false; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2570 | |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2571 | if (!adapter->netdev_registered) { |
| 2572 | err = register_netdev(netdev); |
| 2573 | if (err) |
| 2574 | goto err_register; |
| 2575 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2576 | |
| 2577 | adapter->netdev_registered = true; |
| 2578 | |
| 2579 | netif_tx_stop_all_queues(netdev); |
| 2580 | |
Mitch Williams | b34f90e | 2014-05-10 04:49:07 +0000 | [diff] [blame] | 2581 | dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2582 | if (netdev->features & NETIF_F_GRO) |
| 2583 | dev_info(&pdev->dev, "GRO is enabled\n"); |
| 2584 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2585 | adapter->state = __I40EVF_DOWN; |
| 2586 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
| 2587 | i40evf_misc_irq_enable(adapter); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2588 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2589 | adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL); |
| 2590 | adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL); |
| 2591 | if (!adapter->rss_key || !adapter->rss_lut) |
| 2592 | goto err_mem; |
| 2593 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2594 | if (RSS_AQ(adapter)) { |
| 2595 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS; |
| 2596 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); |
| 2597 | } else { |
Helin Zhang | 96a8198 | 2015-10-26 19:44:31 -0400 | [diff] [blame] | 2598 | i40evf_init_rss(adapter); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 2599 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2600 | return; |
| 2601 | restart: |
Mitch Williams | 3f7e5c3 | 2015-09-28 14:12:42 -0400 | [diff] [blame] | 2602 | schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30)); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2603 | return; |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2604 | err_mem: |
| 2605 | i40evf_free_rss(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2606 | err_register: |
| 2607 | i40evf_free_misc_irq(adapter); |
| 2608 | err_sw_init: |
| 2609 | i40evf_reset_interrupt_capability(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2610 | err_alloc: |
| 2611 | kfree(adapter->vf_res); |
| 2612 | adapter->vf_res = NULL; |
| 2613 | err: |
| 2614 | /* Things went into the weeds, so try again later */ |
| 2615 | if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) { |
Mitch Williams | b9029e9 | 2015-09-28 14:16:50 -0400 | [diff] [blame] | 2616 | 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] | 2617 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
Mitch Williams | b9029e9 | 2015-09-28 14:16:50 -0400 | [diff] [blame] | 2618 | i40evf_shutdown_adminq(hw); |
| 2619 | adapter->state = __I40EVF_STARTUP; |
| 2620 | schedule_delayed_work(&adapter->init_task, HZ * 5); |
| 2621 | return; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2622 | } |
Mitch Williams | 3f7e5c3 | 2015-09-28 14:12:42 -0400 | [diff] [blame] | 2623 | schedule_delayed_work(&adapter->init_task, HZ); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /** |
| 2627 | * i40evf_shutdown - Shutdown the device in preparation for a reboot |
| 2628 | * @pdev: pci device structure |
| 2629 | **/ |
| 2630 | static void i40evf_shutdown(struct pci_dev *pdev) |
| 2631 | { |
| 2632 | struct net_device *netdev = pci_get_drvdata(pdev); |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2633 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2634 | |
| 2635 | netif_device_detach(netdev); |
| 2636 | |
| 2637 | if (netif_running(netdev)) |
| 2638 | i40evf_close(netdev); |
| 2639 | |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2640 | /* Prevent the watchdog from running. */ |
| 2641 | adapter->state = __I40EVF_REMOVE; |
| 2642 | adapter->aq_required = 0; |
Mitch Williams | 00293fd | 2015-01-09 11:18:18 +0000 | [diff] [blame] | 2643 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2644 | #ifdef CONFIG_PM |
| 2645 | pci_save_state(pdev); |
| 2646 | |
| 2647 | #endif |
| 2648 | pci_disable_device(pdev); |
| 2649 | } |
| 2650 | |
| 2651 | /** |
| 2652 | * i40evf_probe - Device Initialization Routine |
| 2653 | * @pdev: PCI device information struct |
| 2654 | * @ent: entry in i40evf_pci_tbl |
| 2655 | * |
| 2656 | * Returns 0 on success, negative on failure |
| 2657 | * |
| 2658 | * i40evf_probe initializes an adapter identified by a pci_dev structure. |
| 2659 | * The OS initialization, configuring of the adapter private structure, |
| 2660 | * and a hardware reset occur. |
| 2661 | **/ |
| 2662 | static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 2663 | { |
| 2664 | struct net_device *netdev; |
| 2665 | struct i40evf_adapter *adapter = NULL; |
| 2666 | struct i40e_hw *hw = NULL; |
Mitch Williams | dbbd811 | 2014-02-20 19:29:08 -0800 | [diff] [blame] | 2667 | int err; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2668 | |
| 2669 | err = pci_enable_device(pdev); |
| 2670 | if (err) |
| 2671 | return err; |
| 2672 | |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2673 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 2674 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 2675 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 2676 | if (err) { |
| 2677 | dev_err(&pdev->dev, |
| 2678 | "DMA configuration failed: 0x%x\n", err); |
| 2679 | goto err_dma; |
| 2680 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | err = pci_request_regions(pdev, i40evf_driver_name); |
| 2684 | if (err) { |
| 2685 | dev_err(&pdev->dev, |
| 2686 | "pci_request_regions failed 0x%x\n", err); |
| 2687 | goto err_pci_reg; |
| 2688 | } |
| 2689 | |
| 2690 | pci_enable_pcie_error_reporting(pdev); |
| 2691 | |
| 2692 | pci_set_master(pdev); |
| 2693 | |
Mitch Williams | 1255b7a | 2015-11-06 15:25:59 -0800 | [diff] [blame] | 2694 | netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2695 | if (!netdev) { |
| 2696 | err = -ENOMEM; |
| 2697 | goto err_alloc_etherdev; |
| 2698 | } |
| 2699 | |
| 2700 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2701 | |
| 2702 | pci_set_drvdata(pdev, netdev); |
| 2703 | adapter = netdev_priv(netdev); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2704 | |
| 2705 | adapter->netdev = netdev; |
| 2706 | adapter->pdev = pdev; |
| 2707 | |
| 2708 | hw = &adapter->hw; |
| 2709 | hw->back = adapter; |
| 2710 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2711 | adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2712 | adapter->state = __I40EVF_STARTUP; |
| 2713 | |
| 2714 | /* Call save state here because it relies on the adapter struct. */ |
| 2715 | pci_save_state(pdev); |
| 2716 | |
| 2717 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 2718 | pci_resource_len(pdev, 0)); |
| 2719 | if (!hw->hw_addr) { |
| 2720 | err = -EIO; |
| 2721 | goto err_ioremap; |
| 2722 | } |
| 2723 | hw->vendor_id = pdev->vendor; |
| 2724 | hw->device_id = pdev->device; |
| 2725 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 2726 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 2727 | hw->subsystem_device_id = pdev->subsystem_device; |
| 2728 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 2729 | hw->bus.func = PCI_FUNC(pdev->devfn); |
| 2730 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 2731 | /* set up the locks for the AQ, do this only once in probe |
| 2732 | * and destroy them only once in remove |
| 2733 | */ |
| 2734 | mutex_init(&hw->aq.asq_mutex); |
| 2735 | mutex_init(&hw->aq.arq_mutex); |
| 2736 | |
Serey Kong | 8bb1a54 | 2014-08-01 13:27:15 -0700 | [diff] [blame] | 2737 | INIT_LIST_HEAD(&adapter->mac_filter_list); |
| 2738 | INIT_LIST_HEAD(&adapter->vlan_filter_list); |
| 2739 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2740 | INIT_WORK(&adapter->reset_task, i40evf_reset_task); |
| 2741 | INIT_WORK(&adapter->adminq_task, i40evf_adminq_task); |
| 2742 | INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task); |
| 2743 | INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task); |
Mitch Williams | 9b32b0b | 2015-08-13 15:11:32 -0700 | [diff] [blame] | 2744 | schedule_delayed_work(&adapter->init_task, |
| 2745 | msecs_to_jiffies(5 * (pdev->devfn & 0x07))); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2746 | |
| 2747 | return 0; |
| 2748 | |
| 2749 | err_ioremap: |
| 2750 | free_netdev(netdev); |
| 2751 | err_alloc_etherdev: |
| 2752 | pci_release_regions(pdev); |
| 2753 | err_pci_reg: |
| 2754 | err_dma: |
| 2755 | pci_disable_device(pdev); |
| 2756 | return err; |
| 2757 | } |
| 2758 | |
| 2759 | #ifdef CONFIG_PM |
| 2760 | /** |
| 2761 | * i40evf_suspend - Power management suspend routine |
| 2762 | * @pdev: PCI device information struct |
| 2763 | * @state: unused |
| 2764 | * |
| 2765 | * Called when the system (VM) is entering sleep/suspend. |
| 2766 | **/ |
| 2767 | static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2768 | { |
| 2769 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2770 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
| 2771 | int retval = 0; |
| 2772 | |
| 2773 | netif_device_detach(netdev); |
| 2774 | |
| 2775 | if (netif_running(netdev)) { |
| 2776 | rtnl_lock(); |
| 2777 | i40evf_down(adapter); |
| 2778 | rtnl_unlock(); |
| 2779 | } |
| 2780 | i40evf_free_misc_irq(adapter); |
| 2781 | i40evf_reset_interrupt_capability(adapter); |
| 2782 | |
| 2783 | retval = pci_save_state(pdev); |
| 2784 | if (retval) |
| 2785 | return retval; |
| 2786 | |
| 2787 | pci_disable_device(pdev); |
| 2788 | |
| 2789 | return 0; |
| 2790 | } |
| 2791 | |
| 2792 | /** |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 2793 | * i40evf_resume - Power management resume routine |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2794 | * @pdev: PCI device information struct |
| 2795 | * |
| 2796 | * Called when the system (VM) is resumed from sleep/suspend. |
| 2797 | **/ |
| 2798 | static int i40evf_resume(struct pci_dev *pdev) |
| 2799 | { |
| 2800 | struct i40evf_adapter *adapter = pci_get_drvdata(pdev); |
| 2801 | struct net_device *netdev = adapter->netdev; |
| 2802 | u32 err; |
| 2803 | |
| 2804 | pci_set_power_state(pdev, PCI_D0); |
| 2805 | pci_restore_state(pdev); |
| 2806 | /* pci_restore_state clears dev->state_saved so call |
| 2807 | * pci_save_state to restore it. |
| 2808 | */ |
| 2809 | pci_save_state(pdev); |
| 2810 | |
| 2811 | err = pci_enable_device_mem(pdev); |
| 2812 | if (err) { |
| 2813 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n"); |
| 2814 | return err; |
| 2815 | } |
| 2816 | pci_set_master(pdev); |
| 2817 | |
| 2818 | rtnl_lock(); |
| 2819 | err = i40evf_set_interrupt_capability(adapter); |
| 2820 | if (err) { |
Vasily Averin | f2a1c36 | 2015-07-07 18:53:38 +0300 | [diff] [blame] | 2821 | rtnl_unlock(); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2822 | dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); |
| 2823 | return err; |
| 2824 | } |
| 2825 | err = i40evf_request_misc_irq(adapter); |
| 2826 | rtnl_unlock(); |
| 2827 | if (err) { |
| 2828 | dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); |
| 2829 | return err; |
| 2830 | } |
| 2831 | |
| 2832 | schedule_work(&adapter->reset_task); |
| 2833 | |
| 2834 | netif_device_attach(netdev); |
| 2835 | |
| 2836 | return err; |
| 2837 | } |
| 2838 | |
| 2839 | #endif /* CONFIG_PM */ |
| 2840 | /** |
| 2841 | * i40evf_remove - Device Removal Routine |
| 2842 | * @pdev: PCI device information struct |
| 2843 | * |
| 2844 | * i40evf_remove is called by the PCI subsystem to alert the driver |
| 2845 | * that it should release a PCI device. The could be caused by a |
| 2846 | * Hot-Plug event, or because the driver is going to be removed from |
| 2847 | * memory. |
| 2848 | **/ |
| 2849 | static void i40evf_remove(struct pci_dev *pdev) |
| 2850 | { |
| 2851 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2852 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 2853 | struct i40evf_mac_filter *f, *ftmp; |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2854 | struct i40e_hw *hw = &adapter->hw; |
| 2855 | |
| 2856 | cancel_delayed_work_sync(&adapter->init_task); |
Mitch Williams | ef8693e | 2014-02-13 03:48:53 -0800 | [diff] [blame] | 2857 | cancel_work_sync(&adapter->reset_task); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2858 | |
| 2859 | if (adapter->netdev_registered) { |
| 2860 | unregister_netdev(netdev); |
| 2861 | adapter->netdev_registered = false; |
| 2862 | } |
Mitch A Williams | 53d0b3a | 2014-12-09 08:53:04 +0000 | [diff] [blame] | 2863 | |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2864 | /* Shut down all the garbage mashers on the detention level */ |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2865 | adapter->state = __I40EVF_REMOVE; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2866 | adapter->aq_required = 0; |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2867 | i40evf_request_reset(adapter); |
Mitch Williams | 22ead37 | 2016-03-18 12:18:10 -0700 | [diff] [blame] | 2868 | msleep(50); |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2869 | /* If the FW isn't responding, kick it once, but only once. */ |
| 2870 | if (!i40evf_asq_done(hw)) { |
| 2871 | i40evf_request_reset(adapter); |
Mitch Williams | 22ead37 | 2016-03-18 12:18:10 -0700 | [diff] [blame] | 2872 | msleep(50); |
Mitch Williams | f4a7188 | 2015-01-09 11:18:16 +0000 | [diff] [blame] | 2873 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2874 | |
Jacob Keller | ef4603e | 2016-11-08 13:05:08 -0800 | [diff] [blame^] | 2875 | i40evf_misc_irq_disable(adapter); |
| 2876 | i40evf_free_misc_irq(adapter); |
| 2877 | i40evf_reset_interrupt_capability(adapter); |
| 2878 | i40evf_free_q_vectors(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2879 | |
Mitch Williams | e5d17c3 | 2014-06-04 04:22:38 +0000 | [diff] [blame] | 2880 | if (adapter->watchdog_timer.function) |
| 2881 | del_timer_sync(&adapter->watchdog_timer); |
| 2882 | |
Mitch Williams | dbb01c8 | 2014-02-20 19:29:07 -0800 | [diff] [blame] | 2883 | flush_scheduled_work(); |
| 2884 | |
Mitch Williams | 43a3d9b | 2016-04-12 08:30:44 -0700 | [diff] [blame] | 2885 | i40evf_free_rss(adapter); |
Helin Zhang | 66f9af85 | 2015-10-26 19:44:34 -0400 | [diff] [blame] | 2886 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2887 | if (hw->aq.asq.count) |
| 2888 | i40evf_shutdown_adminq(hw); |
| 2889 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 2890 | /* destroy the locks only once, here */ |
| 2891 | mutex_destroy(&hw->aq.arq_mutex); |
| 2892 | mutex_destroy(&hw->aq.asq_mutex); |
| 2893 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2894 | iounmap(hw->hw_addr); |
| 2895 | pci_release_regions(pdev); |
Mitch Williams | e284fc8 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 2896 | i40evf_free_all_tx_resources(adapter); |
| 2897 | i40evf_free_all_rx_resources(adapter); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2898 | i40evf_free_queues(adapter); |
| 2899 | kfree(adapter->vf_res); |
Mitch Williams | 6ba36a2 | 2014-08-01 13:27:14 -0700 | [diff] [blame] | 2900 | /* If we got removed before an up/down sequence, we've got a filter |
| 2901 | * hanging out there that we need to get rid of. |
| 2902 | */ |
| 2903 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
| 2904 | list_del(&f->list); |
| 2905 | kfree(f); |
| 2906 | } |
Mitch A Williams | 37dfdf3 | 2014-12-09 08:53:05 +0000 | [diff] [blame] | 2907 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
| 2908 | list_del(&f->list); |
| 2909 | kfree(f); |
| 2910 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2911 | |
| 2912 | free_netdev(netdev); |
| 2913 | |
| 2914 | pci_disable_pcie_error_reporting(pdev); |
| 2915 | |
| 2916 | pci_disable_device(pdev); |
| 2917 | } |
| 2918 | |
| 2919 | static struct pci_driver i40evf_driver = { |
| 2920 | .name = i40evf_driver_name, |
| 2921 | .id_table = i40evf_pci_tbl, |
| 2922 | .probe = i40evf_probe, |
| 2923 | .remove = i40evf_remove, |
| 2924 | #ifdef CONFIG_PM |
| 2925 | .suspend = i40evf_suspend, |
| 2926 | .resume = i40evf_resume, |
| 2927 | #endif |
| 2928 | .shutdown = i40evf_shutdown, |
| 2929 | }; |
| 2930 | |
| 2931 | /** |
| 2932 | * i40e_init_module - Driver Registration Routine |
| 2933 | * |
| 2934 | * i40e_init_module is the first routine called when the driver is |
| 2935 | * loaded. All it does is register with the PCI subsystem. |
| 2936 | **/ |
| 2937 | static int __init i40evf_init_module(void) |
| 2938 | { |
| 2939 | int ret; |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2940 | |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2941 | pr_info("i40evf: %s - version %s\n", i40evf_driver_string, |
Mitch Williams | 75a6443 | 2014-11-11 20:02:42 +0000 | [diff] [blame] | 2942 | i40evf_driver_version); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2943 | |
| 2944 | pr_info("%s\n", i40evf_copyright); |
| 2945 | |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 2946 | i40evf_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 2947 | i40evf_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 2948 | if (!i40evf_wq) { |
| 2949 | pr_err("%s: Failed to create workqueue\n", i40evf_driver_name); |
| 2950 | return -ENOMEM; |
| 2951 | } |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2952 | ret = pci_register_driver(&i40evf_driver); |
| 2953 | return ret; |
| 2954 | } |
| 2955 | |
| 2956 | module_init(i40evf_init_module); |
| 2957 | |
| 2958 | /** |
| 2959 | * i40e_exit_module - Driver Exit Cleanup Routine |
| 2960 | * |
| 2961 | * i40e_exit_module is called just before the driver is removed |
| 2962 | * from memory. |
| 2963 | **/ |
| 2964 | static void __exit i40evf_exit_module(void) |
| 2965 | { |
| 2966 | pci_unregister_driver(&i40evf_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 2967 | destroy_workqueue(i40evf_wq); |
Greg Rose | 5eae00c | 2013-12-21 06:12:45 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | module_exit(i40evf_exit_module); |
| 2971 | |
| 2972 | /* i40evf_main.c */ |