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