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