Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2017 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +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 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +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/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 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 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 30 | #include <linux/bpf.h> |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 31 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 32 | /* Local includes */ |
| 33 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 34 | #include "i40e_diag.h" |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 35 | #include <net/udp_tunnel.h> |
Scott Peterson | ed0980c | 2017-04-13 04:45:44 -0400 | [diff] [blame] | 36 | /* All i40e tracepoints are defined by the include below, which |
| 37 | * must be included exactly once across the whole kernel with |
| 38 | * CREATE_TRACE_POINTS defined |
| 39 | */ |
| 40 | #define CREATE_TRACE_POINTS |
| 41 | #include "i40e_trace.h" |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 42 | |
| 43 | const char i40e_driver_name[] = "i40e"; |
| 44 | static const char i40e_driver_string[] = |
| 45 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 46 | |
| 47 | #define DRV_KERN "-k" |
| 48 | |
Bimmy Pujari | 1599083 | 2017-01-30 12:29:37 -0800 | [diff] [blame] | 49 | #define DRV_VERSION_MAJOR 2 |
| 50 | #define DRV_VERSION_MINOR 1 |
Jacob Keller | 2318b40 | 2017-04-19 09:25:53 -0400 | [diff] [blame] | 51 | #define DRV_VERSION_BUILD 14 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 52 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 53 | __stringify(DRV_VERSION_MINOR) "." \ |
| 54 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 55 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 56 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 57 | |
| 58 | /* a bit of forward declarations */ |
| 59 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 60 | static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 61 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 62 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 63 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 64 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 65 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 66 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 67 | static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired); |
| 68 | static int i40e_reset(struct i40e_pf *pf); |
| 69 | static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 70 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 71 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 72 | |
| 73 | /* i40e_pci_tbl - PCI Device ID Table |
| 74 | * |
| 75 | * Last entry must be all 0s |
| 76 | * |
| 77 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 78 | * Class, Class Mask, private data (not used) } |
| 79 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 80 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 96 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 97 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0}, |
| 99 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 100 | /* required last entry */ |
| 101 | {0, } |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 104 | |
| 105 | #define I40E_MAX_VF_COUNT 128 |
| 106 | static int debug = -1; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 107 | module_param(debug, uint, 0); |
| 108 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 109 | |
| 110 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 111 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 112 | MODULE_LICENSE("GPL"); |
| 113 | MODULE_VERSION(DRV_VERSION); |
| 114 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 115 | static struct workqueue_struct *i40e_wq; |
| 116 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 117 | /** |
| 118 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 119 | * @hw: pointer to the HW structure |
| 120 | * @mem: ptr to mem struct to fill out |
| 121 | * @size: size of memory requested |
| 122 | * @alignment: what to align the allocation to |
| 123 | **/ |
| 124 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 125 | u64 size, u32 alignment) |
| 126 | { |
| 127 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 128 | |
| 129 | mem->size = ALIGN(size, alignment); |
| 130 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 131 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 132 | if (!mem->va) |
| 133 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 134 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 135 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 140 | * @hw: pointer to the HW structure |
| 141 | * @mem: ptr to mem struct to free |
| 142 | **/ |
| 143 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 144 | { |
| 145 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 146 | |
| 147 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 148 | mem->va = NULL; |
| 149 | mem->pa = 0; |
| 150 | mem->size = 0; |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 157 | * @hw: pointer to the HW structure |
| 158 | * @mem: ptr to mem struct to fill out |
| 159 | * @size: size of memory requested |
| 160 | **/ |
| 161 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 162 | u32 size) |
| 163 | { |
| 164 | mem->size = size; |
| 165 | mem->va = kzalloc(size, GFP_KERNEL); |
| 166 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 167 | if (!mem->va) |
| 168 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 169 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 170 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 175 | * @hw: pointer to the HW structure |
| 176 | * @mem: ptr to mem struct to free |
| 177 | **/ |
| 178 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 179 | { |
| 180 | /* it's ok to kfree a NULL pointer */ |
| 181 | kfree(mem->va); |
| 182 | mem->va = NULL; |
| 183 | mem->size = 0; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * i40e_get_lump - find a lump of free generic resource |
| 190 | * @pf: board private structure |
| 191 | * @pile: the pile of resource to search |
| 192 | * @needed: the number of items needed |
| 193 | * @id: an owner id to stick on the items assigned |
| 194 | * |
| 195 | * Returns the base item index of the lump, or negative for error |
| 196 | * |
| 197 | * The search_hint trick and lack of advanced fit-finding only work |
| 198 | * because we're highly likely to have all the same size lump requests. |
| 199 | * Linear search time and any fragmentation should be minimal. |
| 200 | **/ |
| 201 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 202 | u16 needed, u16 id) |
| 203 | { |
| 204 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 205 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 206 | |
| 207 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 208 | dev_info(&pf->pdev->dev, |
| 209 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 210 | pile, needed, id); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | |
| 214 | /* start the linear search with an imperfect hint */ |
| 215 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 216 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 217 | /* skip already allocated entries */ |
| 218 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 219 | i++; |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | /* do we have enough in this lump? */ |
| 224 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 225 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | if (j == needed) { |
| 230 | /* there was enough, so assign it to the requestor */ |
| 231 | for (j = 0; j < needed; j++) |
| 232 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 233 | ret = i; |
| 234 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 235 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 236 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 237 | |
| 238 | /* not enough, so skip over it and continue looking */ |
| 239 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * i40e_put_lump - return a lump of generic resource |
| 247 | * @pile: the pile of resource to search |
| 248 | * @index: the base item index |
| 249 | * @id: the owner id of the items assigned |
| 250 | * |
| 251 | * Returns the count of items in the lump |
| 252 | **/ |
| 253 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 254 | { |
| 255 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 256 | int count = 0; |
| 257 | int i; |
| 258 | |
| 259 | if (!pile || index >= pile->num_entries) |
| 260 | return -EINVAL; |
| 261 | |
| 262 | for (i = index; |
| 263 | i < pile->num_entries && pile->list[i] == valid_id; |
| 264 | i++) { |
| 265 | pile->list[i] = 0; |
| 266 | count++; |
| 267 | } |
| 268 | |
| 269 | if (count && index < pile->search_hint) |
| 270 | pile->search_hint = index; |
| 271 | |
| 272 | return count; |
| 273 | } |
| 274 | |
| 275 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 276 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 277 | * @pf - the pf structure to search for the vsi |
| 278 | * @id - id of the vsi it is searching for |
| 279 | **/ |
| 280 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 281 | { |
| 282 | int i; |
| 283 | |
| 284 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 285 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 286 | return pf->vsi[i]; |
| 287 | |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 292 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 293 | * @pf: board private structure |
| 294 | * |
| 295 | * If not already scheduled, this puts the task into the work queue |
| 296 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 297 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 298 | { |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 299 | if (!test_bit(__I40E_DOWN, pf->state) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 300 | !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 301 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * i40e_tx_timeout - Respond to a Tx Hang |
| 306 | * @netdev: network interface device structure |
| 307 | * |
| 308 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 309 | * device is munged, not just the one netdev port, so go for the full |
| 310 | * reset. |
| 311 | **/ |
| 312 | static void i40e_tx_timeout(struct net_device *netdev) |
| 313 | { |
| 314 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 315 | struct i40e_vsi *vsi = np->vsi; |
| 316 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 317 | struct i40e_ring *tx_ring = NULL; |
| 318 | unsigned int i, hung_queue = 0; |
| 319 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 320 | |
| 321 | pf->tx_timeout_count++; |
| 322 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 323 | /* find the stopped queue the same way the stack does */ |
| 324 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 325 | struct netdev_queue *q; |
| 326 | unsigned long trans_start; |
| 327 | |
| 328 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 329 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 330 | if (netif_xmit_stopped(q) && |
| 331 | time_after(jiffies, |
| 332 | (trans_start + netdev->watchdog_timeo))) { |
| 333 | hung_queue = i; |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (i == netdev->num_tx_queues) { |
| 339 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 340 | } else { |
| 341 | /* now that we have an index, find the tx_ring struct */ |
| 342 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 343 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 344 | if (hung_queue == |
| 345 | vsi->tx_rings[i]->queue_index) { |
| 346 | tx_ring = vsi->tx_rings[i]; |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 353 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 354 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 355 | else if (time_before(jiffies, |
| 356 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 357 | return; /* don't do any new action before the next timeout */ |
| 358 | |
| 359 | if (tx_ring) { |
| 360 | head = i40e_get_head(tx_ring); |
| 361 | /* Read interrupt register */ |
| 362 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 363 | val = rd32(&pf->hw, |
| 364 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 365 | tx_ring->vsi->base_vector - 1)); |
| 366 | else |
| 367 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 368 | |
| 369 | netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n", |
| 370 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 371 | head, tx_ring->next_to_use, |
| 372 | readl(tx_ring->tail), val); |
| 373 | } |
| 374 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 375 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 376 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 377 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 378 | |
| 379 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 380 | case 1: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 381 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 382 | break; |
| 383 | case 2: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 384 | set_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 385 | break; |
| 386 | case 3: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 387 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 388 | break; |
| 389 | default: |
| 390 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 391 | break; |
| 392 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 394 | i40e_service_event_schedule(pf); |
| 395 | pf->tx_timeout_recovery_level++; |
| 396 | } |
| 397 | |
| 398 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 399 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 400 | * @vsi: the VSI we care about |
| 401 | * |
| 402 | * Returns the address of the device statistics structure. |
| 403 | * The statistics are actually updated from the service task. |
| 404 | **/ |
| 405 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 406 | { |
| 407 | return &vsi->net_stats; |
| 408 | } |
| 409 | |
| 410 | /** |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 411 | * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring |
| 412 | * @ring: Tx ring to get statistics from |
| 413 | * @stats: statistics entry to be updated |
| 414 | **/ |
| 415 | static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring, |
| 416 | struct rtnl_link_stats64 *stats) |
| 417 | { |
| 418 | u64 bytes, packets; |
| 419 | unsigned int start; |
| 420 | |
| 421 | do { |
| 422 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
| 423 | packets = ring->stats.packets; |
| 424 | bytes = ring->stats.bytes; |
| 425 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
| 426 | |
| 427 | stats->tx_packets += packets; |
| 428 | stats->tx_bytes += bytes; |
| 429 | } |
| 430 | |
| 431 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 432 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 433 | * @netdev: network interface device structure |
| 434 | * |
| 435 | * Returns the address of the device statistics structure. |
| 436 | * The statistics are actually updated from the service task. |
| 437 | **/ |
Alexander Duyck | 9eed69a | 2017-02-21 15:55:47 -0800 | [diff] [blame] | 438 | static void i40e_get_netdev_stats_struct(struct net_device *netdev, |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 439 | struct rtnl_link_stats64 *stats) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 440 | { |
| 441 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 442 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 443 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 444 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 445 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 446 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 447 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 448 | return; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 449 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 450 | if (!vsi->tx_rings) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 451 | return; |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 452 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 453 | rcu_read_lock(); |
| 454 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 455 | u64 bytes, packets; |
| 456 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 457 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 458 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 459 | if (!tx_ring) |
| 460 | continue; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 461 | i40e_get_netdev_stats_struct_tx(tx_ring, stats); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 462 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 463 | rx_ring = &tx_ring[1]; |
| 464 | |
| 465 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 466 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 467 | packets = rx_ring->stats.packets; |
| 468 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 469 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 470 | |
| 471 | stats->rx_packets += packets; |
| 472 | stats->rx_bytes += bytes; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 473 | |
| 474 | if (i40e_enabled_xdp_vsi(vsi)) |
| 475 | i40e_get_netdev_stats_struct_tx(&rx_ring[1], stats); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 476 | } |
| 477 | rcu_read_unlock(); |
| 478 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 479 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 480 | stats->multicast = vsi_stats->multicast; |
| 481 | stats->tx_errors = vsi_stats->tx_errors; |
| 482 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 483 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 484 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 485 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 486 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
| 490 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 491 | * @vsi: the VSI to have its stats reset |
| 492 | **/ |
| 493 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 494 | { |
| 495 | struct rtnl_link_stats64 *ns; |
| 496 | int i; |
| 497 | |
| 498 | if (!vsi) |
| 499 | return; |
| 500 | |
| 501 | ns = i40e_get_vsi_stats_struct(vsi); |
| 502 | memset(ns, 0, sizeof(*ns)); |
| 503 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 504 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 505 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 506 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 507 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 508 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 509 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 510 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 511 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 512 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 513 | sizeof(vsi->tx_rings[i]->stats)); |
| 514 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 515 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 516 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 517 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 518 | vsi->stat_offsets_loaded = false; |
| 519 | } |
| 520 | |
| 521 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 522 | * i40e_pf_reset_stats - Reset all of the stats for the given PF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 523 | * @pf: the PF to be reset |
| 524 | **/ |
| 525 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 526 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 527 | int i; |
| 528 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 529 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 530 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 531 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 532 | |
| 533 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 534 | if (pf->veb[i]) { |
| 535 | memset(&pf->veb[i]->stats, 0, |
| 536 | sizeof(pf->veb[i]->stats)); |
| 537 | memset(&pf->veb[i]->stats_offsets, 0, |
| 538 | sizeof(pf->veb[i]->stats_offsets)); |
| 539 | pf->veb[i]->stat_offsets_loaded = false; |
| 540 | } |
| 541 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 542 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
| 546 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 547 | * @hw: ptr to the hardware info |
| 548 | * @hireg: the high 32 bit reg to read |
| 549 | * @loreg: the low 32 bit reg to read |
| 550 | * @offset_loaded: has the initial offset been loaded yet |
| 551 | * @offset: ptr to current offset value |
| 552 | * @stat: ptr to the stat |
| 553 | * |
| 554 | * Since the device stats are not reset at PFReset, they likely will not |
| 555 | * be zeroed when the driver starts. We'll save the first values read |
| 556 | * and use them as offsets to be subtracted from the raw values in order |
| 557 | * to report stats that count from zero. In the process, we also manage |
| 558 | * the potential roll-over. |
| 559 | **/ |
| 560 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 561 | bool offset_loaded, u64 *offset, u64 *stat) |
| 562 | { |
| 563 | u64 new_data; |
| 564 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 565 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 566 | new_data = rd32(hw, loreg); |
| 567 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 568 | } else { |
| 569 | new_data = rd64(hw, loreg); |
| 570 | } |
| 571 | if (!offset_loaded) |
| 572 | *offset = new_data; |
| 573 | if (likely(new_data >= *offset)) |
| 574 | *stat = new_data - *offset; |
| 575 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 576 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 577 | *stat &= 0xFFFFFFFFFFFFULL; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 582 | * @hw: ptr to the hardware info |
| 583 | * @reg: the hw reg to read |
| 584 | * @offset_loaded: has the initial offset been loaded yet |
| 585 | * @offset: ptr to current offset value |
| 586 | * @stat: ptr to the stat |
| 587 | **/ |
| 588 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 589 | bool offset_loaded, u64 *offset, u64 *stat) |
| 590 | { |
| 591 | u32 new_data; |
| 592 | |
| 593 | new_data = rd32(hw, reg); |
| 594 | if (!offset_loaded) |
| 595 | *offset = new_data; |
| 596 | if (likely(new_data >= *offset)) |
| 597 | *stat = (u32)(new_data - *offset); |
| 598 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 599 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /** |
| 603 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 604 | * @vsi: the VSI to be updated |
| 605 | **/ |
| 606 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 607 | { |
| 608 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 609 | struct i40e_pf *pf = vsi->back; |
| 610 | struct i40e_hw *hw = &pf->hw; |
| 611 | struct i40e_eth_stats *oes; |
| 612 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 613 | |
| 614 | es = &vsi->eth_stats; |
| 615 | oes = &vsi->eth_stats_offsets; |
| 616 | |
| 617 | /* Gather up the stats that the hw collects */ |
| 618 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 619 | vsi->stat_offsets_loaded, |
| 620 | &oes->tx_errors, &es->tx_errors); |
| 621 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 622 | vsi->stat_offsets_loaded, |
| 623 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 624 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 625 | vsi->stat_offsets_loaded, |
| 626 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 627 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 628 | vsi->stat_offsets_loaded, |
| 629 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 630 | |
| 631 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 632 | I40E_GLV_GORCL(stat_idx), |
| 633 | vsi->stat_offsets_loaded, |
| 634 | &oes->rx_bytes, &es->rx_bytes); |
| 635 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 636 | I40E_GLV_UPRCL(stat_idx), |
| 637 | vsi->stat_offsets_loaded, |
| 638 | &oes->rx_unicast, &es->rx_unicast); |
| 639 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 640 | I40E_GLV_MPRCL(stat_idx), |
| 641 | vsi->stat_offsets_loaded, |
| 642 | &oes->rx_multicast, &es->rx_multicast); |
| 643 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 644 | I40E_GLV_BPRCL(stat_idx), |
| 645 | vsi->stat_offsets_loaded, |
| 646 | &oes->rx_broadcast, &es->rx_broadcast); |
| 647 | |
| 648 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 649 | I40E_GLV_GOTCL(stat_idx), |
| 650 | vsi->stat_offsets_loaded, |
| 651 | &oes->tx_bytes, &es->tx_bytes); |
| 652 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 653 | I40E_GLV_UPTCL(stat_idx), |
| 654 | vsi->stat_offsets_loaded, |
| 655 | &oes->tx_unicast, &es->tx_unicast); |
| 656 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 657 | I40E_GLV_MPTCL(stat_idx), |
| 658 | vsi->stat_offsets_loaded, |
| 659 | &oes->tx_multicast, &es->tx_multicast); |
| 660 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 661 | I40E_GLV_BPTCL(stat_idx), |
| 662 | vsi->stat_offsets_loaded, |
| 663 | &oes->tx_broadcast, &es->tx_broadcast); |
| 664 | vsi->stat_offsets_loaded = true; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * i40e_update_veb_stats - Update Switch component statistics |
| 669 | * @veb: the VEB being updated |
| 670 | **/ |
| 671 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 672 | { |
| 673 | struct i40e_pf *pf = veb->pf; |
| 674 | struct i40e_hw *hw = &pf->hw; |
| 675 | struct i40e_eth_stats *oes; |
| 676 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 677 | struct i40e_veb_tc_stats *veb_oes; |
| 678 | struct i40e_veb_tc_stats *veb_es; |
| 679 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 680 | |
| 681 | idx = veb->stats_idx; |
| 682 | es = &veb->stats; |
| 683 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 684 | veb_es = &veb->tc_stats; |
| 685 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 686 | |
| 687 | /* Gather up the stats that the hw collects */ |
| 688 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 689 | veb->stat_offsets_loaded, |
| 690 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 691 | if (hw->revision_id > 0) |
| 692 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 693 | veb->stat_offsets_loaded, |
| 694 | &oes->rx_unknown_protocol, |
| 695 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 696 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 697 | veb->stat_offsets_loaded, |
| 698 | &oes->rx_bytes, &es->rx_bytes); |
| 699 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 700 | veb->stat_offsets_loaded, |
| 701 | &oes->rx_unicast, &es->rx_unicast); |
| 702 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 703 | veb->stat_offsets_loaded, |
| 704 | &oes->rx_multicast, &es->rx_multicast); |
| 705 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 706 | veb->stat_offsets_loaded, |
| 707 | &oes->rx_broadcast, &es->rx_broadcast); |
| 708 | |
| 709 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 710 | veb->stat_offsets_loaded, |
| 711 | &oes->tx_bytes, &es->tx_bytes); |
| 712 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 713 | veb->stat_offsets_loaded, |
| 714 | &oes->tx_unicast, &es->tx_unicast); |
| 715 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 716 | veb->stat_offsets_loaded, |
| 717 | &oes->tx_multicast, &es->tx_multicast); |
| 718 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 719 | veb->stat_offsets_loaded, |
| 720 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 721 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 722 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 723 | I40E_GLVEBTC_RPCL(i, idx), |
| 724 | veb->stat_offsets_loaded, |
| 725 | &veb_oes->tc_rx_packets[i], |
| 726 | &veb_es->tc_rx_packets[i]); |
| 727 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 728 | I40E_GLVEBTC_RBCL(i, idx), |
| 729 | veb->stat_offsets_loaded, |
| 730 | &veb_oes->tc_rx_bytes[i], |
| 731 | &veb_es->tc_rx_bytes[i]); |
| 732 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 733 | I40E_GLVEBTC_TPCL(i, idx), |
| 734 | veb->stat_offsets_loaded, |
| 735 | &veb_oes->tc_tx_packets[i], |
| 736 | &veb_es->tc_tx_packets[i]); |
| 737 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 738 | I40E_GLVEBTC_TBCL(i, idx), |
| 739 | veb->stat_offsets_loaded, |
| 740 | &veb_oes->tc_tx_bytes[i], |
| 741 | &veb_es->tc_tx_bytes[i]); |
| 742 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 743 | veb->stat_offsets_loaded = true; |
| 744 | } |
| 745 | |
| 746 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 747 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 748 | * @vsi: the VSI to be updated |
| 749 | * |
| 750 | * There are a few instances where we store the same stat in a |
| 751 | * couple of different structs. This is partly because we have |
| 752 | * the netdev stats that need to be filled out, which is slightly |
| 753 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 754 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 755 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 756 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 757 | { |
| 758 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 759 | struct rtnl_link_stats64 *ons; |
| 760 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 761 | struct i40e_eth_stats *oes; |
| 762 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 763 | u32 tx_restart, tx_busy; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 764 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 765 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 766 | u64 bytes, packets; |
| 767 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 768 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 769 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 770 | u64 rx_p, rx_b; |
| 771 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 772 | u16 q; |
| 773 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 774 | if (test_bit(__I40E_VSI_DOWN, vsi->state) || |
| 775 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 776 | return; |
| 777 | |
| 778 | ns = i40e_get_vsi_stats_struct(vsi); |
| 779 | ons = &vsi->net_stats_offsets; |
| 780 | es = &vsi->eth_stats; |
| 781 | oes = &vsi->eth_stats_offsets; |
| 782 | |
| 783 | /* Gather up the netdev and vsi stats that the driver collects |
| 784 | * on the fly during packet processing |
| 785 | */ |
| 786 | rx_b = rx_p = 0; |
| 787 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 788 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 789 | rx_page = 0; |
| 790 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 791 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 792 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 793 | /* locate Tx ring */ |
| 794 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 795 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 796 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 797 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 798 | packets = p->stats.packets; |
| 799 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 800 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 801 | tx_b += bytes; |
| 802 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 803 | tx_restart += p->tx_stats.restart_queue; |
| 804 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 805 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 806 | tx_force_wb += p->tx_stats.tx_force_wb; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 807 | |
| 808 | /* Rx queue is part of the same block as Tx queue */ |
| 809 | p = &p[1]; |
| 810 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 811 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 812 | packets = p->stats.packets; |
| 813 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 814 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 815 | rx_b += bytes; |
| 816 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 817 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 818 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 819 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 820 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 821 | vsi->tx_restart = tx_restart; |
| 822 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 823 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 824 | vsi->tx_force_wb = tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 825 | vsi->rx_page_failed = rx_page; |
| 826 | vsi->rx_buf_failed = rx_buf; |
| 827 | |
| 828 | ns->rx_packets = rx_p; |
| 829 | ns->rx_bytes = rx_b; |
| 830 | ns->tx_packets = tx_p; |
| 831 | ns->tx_bytes = tx_b; |
| 832 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 834 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 835 | ons->tx_errors = oes->tx_errors; |
| 836 | ns->tx_errors = es->tx_errors; |
| 837 | ons->multicast = oes->rx_multicast; |
| 838 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 839 | ons->rx_dropped = oes->rx_discards; |
| 840 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 841 | ons->tx_dropped = oes->tx_discards; |
| 842 | ns->tx_dropped = es->tx_discards; |
| 843 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 844 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 845 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 846 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 847 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 848 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 849 | } |
| 850 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 851 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 852 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 853 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 854 | * @pf: the PF to be updated |
| 855 | **/ |
| 856 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 857 | { |
| 858 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 859 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 860 | struct i40e_hw *hw = &pf->hw; |
| 861 | u32 val; |
| 862 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 863 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 864 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 865 | I40E_GLPRT_GORCL(hw->port), |
| 866 | pf->stat_offsets_loaded, |
| 867 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 868 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 869 | I40E_GLPRT_GOTCL(hw->port), |
| 870 | pf->stat_offsets_loaded, |
| 871 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 872 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 873 | pf->stat_offsets_loaded, |
| 874 | &osd->eth.rx_discards, |
| 875 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 876 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 877 | I40E_GLPRT_UPRCL(hw->port), |
| 878 | pf->stat_offsets_loaded, |
| 879 | &osd->eth.rx_unicast, |
| 880 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 881 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 882 | I40E_GLPRT_MPRCL(hw->port), |
| 883 | pf->stat_offsets_loaded, |
| 884 | &osd->eth.rx_multicast, |
| 885 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 886 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 887 | I40E_GLPRT_BPRCL(hw->port), |
| 888 | pf->stat_offsets_loaded, |
| 889 | &osd->eth.rx_broadcast, |
| 890 | &nsd->eth.rx_broadcast); |
| 891 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 892 | I40E_GLPRT_UPTCL(hw->port), |
| 893 | pf->stat_offsets_loaded, |
| 894 | &osd->eth.tx_unicast, |
| 895 | &nsd->eth.tx_unicast); |
| 896 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 897 | I40E_GLPRT_MPTCL(hw->port), |
| 898 | pf->stat_offsets_loaded, |
| 899 | &osd->eth.tx_multicast, |
| 900 | &nsd->eth.tx_multicast); |
| 901 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 902 | I40E_GLPRT_BPTCL(hw->port), |
| 903 | pf->stat_offsets_loaded, |
| 904 | &osd->eth.tx_broadcast, |
| 905 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 906 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 907 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 908 | pf->stat_offsets_loaded, |
| 909 | &osd->tx_dropped_link_down, |
| 910 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 911 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 912 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 913 | pf->stat_offsets_loaded, |
| 914 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 915 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 916 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 919 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 920 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 921 | pf->stat_offsets_loaded, |
| 922 | &osd->mac_local_faults, |
| 923 | &nsd->mac_local_faults); |
| 924 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 925 | pf->stat_offsets_loaded, |
| 926 | &osd->mac_remote_faults, |
| 927 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 928 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 929 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 930 | pf->stat_offsets_loaded, |
| 931 | &osd->rx_length_errors, |
| 932 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 933 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 934 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 935 | pf->stat_offsets_loaded, |
| 936 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 937 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 938 | pf->stat_offsets_loaded, |
| 939 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 940 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 941 | pf->stat_offsets_loaded, |
| 942 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 943 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 946 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 947 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 948 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->priority_xoff_rx[i], |
| 951 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 952 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 953 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 954 | &osd->priority_xon_rx[i], |
| 955 | &nsd->priority_xon_rx[i]); |
| 956 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 957 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 958 | &osd->priority_xon_tx[i], |
| 959 | &nsd->priority_xon_tx[i]); |
| 960 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 961 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 962 | &osd->priority_xoff_tx[i], |
| 963 | &nsd->priority_xoff_tx[i]); |
| 964 | i40e_stat_update32(hw, |
| 965 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 966 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 967 | &osd->priority_xon_2_xoff[i], |
| 968 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 971 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 972 | I40E_GLPRT_PRC64L(hw->port), |
| 973 | pf->stat_offsets_loaded, |
| 974 | &osd->rx_size_64, &nsd->rx_size_64); |
| 975 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 976 | I40E_GLPRT_PRC127L(hw->port), |
| 977 | pf->stat_offsets_loaded, |
| 978 | &osd->rx_size_127, &nsd->rx_size_127); |
| 979 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 980 | I40E_GLPRT_PRC255L(hw->port), |
| 981 | pf->stat_offsets_loaded, |
| 982 | &osd->rx_size_255, &nsd->rx_size_255); |
| 983 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 984 | I40E_GLPRT_PRC511L(hw->port), |
| 985 | pf->stat_offsets_loaded, |
| 986 | &osd->rx_size_511, &nsd->rx_size_511); |
| 987 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 988 | I40E_GLPRT_PRC1023L(hw->port), |
| 989 | pf->stat_offsets_loaded, |
| 990 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 991 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 992 | I40E_GLPRT_PRC1522L(hw->port), |
| 993 | pf->stat_offsets_loaded, |
| 994 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 995 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 996 | I40E_GLPRT_PRC9522L(hw->port), |
| 997 | pf->stat_offsets_loaded, |
| 998 | &osd->rx_size_big, &nsd->rx_size_big); |
| 999 | |
| 1000 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1001 | I40E_GLPRT_PTC64L(hw->port), |
| 1002 | pf->stat_offsets_loaded, |
| 1003 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1004 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1005 | I40E_GLPRT_PTC127L(hw->port), |
| 1006 | pf->stat_offsets_loaded, |
| 1007 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1008 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1009 | I40E_GLPRT_PTC255L(hw->port), |
| 1010 | pf->stat_offsets_loaded, |
| 1011 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1012 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1013 | I40E_GLPRT_PTC511L(hw->port), |
| 1014 | pf->stat_offsets_loaded, |
| 1015 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1016 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1017 | I40E_GLPRT_PTC1023L(hw->port), |
| 1018 | pf->stat_offsets_loaded, |
| 1019 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1020 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1021 | I40E_GLPRT_PTC1522L(hw->port), |
| 1022 | pf->stat_offsets_loaded, |
| 1023 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1024 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1025 | I40E_GLPRT_PTC9522L(hw->port), |
| 1026 | pf->stat_offsets_loaded, |
| 1027 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1028 | |
| 1029 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1030 | pf->stat_offsets_loaded, |
| 1031 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1032 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1033 | pf->stat_offsets_loaded, |
| 1034 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1035 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1038 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1039 | pf->stat_offsets_loaded, |
| 1040 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1041 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1042 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1043 | i40e_stat_update32(hw, |
| 1044 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1045 | pf->stat_offsets_loaded, |
| 1046 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1047 | i40e_stat_update32(hw, |
| 1048 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1049 | pf->stat_offsets_loaded, |
| 1050 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1051 | i40e_stat_update32(hw, |
| 1052 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1053 | pf->stat_offsets_loaded, |
| 1054 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1055 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1056 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1057 | nsd->tx_lpi_status = |
| 1058 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1059 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1060 | nsd->rx_lpi_status = |
| 1061 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1062 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1063 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1064 | pf->stat_offsets_loaded, |
| 1065 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1066 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1067 | pf->stat_offsets_loaded, |
| 1068 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1069 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1070 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 1071 | !(pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1072 | nsd->fd_sb_status = true; |
| 1073 | else |
| 1074 | nsd->fd_sb_status = false; |
| 1075 | |
| 1076 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 1077 | !(pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1078 | nsd->fd_atr_status = true; |
| 1079 | else |
| 1080 | nsd->fd_atr_status = false; |
| 1081 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1082 | pf->stat_offsets_loaded = true; |
| 1083 | } |
| 1084 | |
| 1085 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1086 | * i40e_update_stats - Update the various statistics counters. |
| 1087 | * @vsi: the VSI to be updated |
| 1088 | * |
| 1089 | * Update the various stats for this VSI and its related entities. |
| 1090 | **/ |
| 1091 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1092 | { |
| 1093 | struct i40e_pf *pf = vsi->back; |
| 1094 | |
| 1095 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1096 | i40e_update_pf_stats(pf); |
| 1097 | |
| 1098 | i40e_update_vsi_stats(vsi); |
| 1099 | } |
| 1100 | |
| 1101 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1102 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1103 | * @vsi: the VSI to be searched |
| 1104 | * @macaddr: the MAC address |
| 1105 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1106 | * |
| 1107 | * Returns ptr to the filter object or NULL |
| 1108 | **/ |
| 1109 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1110 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1111 | { |
| 1112 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1113 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1114 | |
| 1115 | if (!vsi || !macaddr) |
| 1116 | return NULL; |
| 1117 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1118 | key = i40e_addr_to_hkey(macaddr); |
| 1119 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1120 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1121 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1122 | return f; |
| 1123 | } |
| 1124 | return NULL; |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1129 | * @vsi: the VSI to be searched |
| 1130 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1131 | * |
| 1132 | * Returns the first filter with the provided MAC address or NULL if |
| 1133 | * MAC address was not found |
| 1134 | **/ |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1135 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1136 | { |
| 1137 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1138 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1139 | |
| 1140 | if (!vsi || !macaddr) |
| 1141 | return NULL; |
| 1142 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1143 | key = i40e_addr_to_hkey(macaddr); |
| 1144 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1145 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1146 | return f; |
| 1147 | } |
| 1148 | return NULL; |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1153 | * @vsi: the VSI to be searched |
| 1154 | * |
| 1155 | * Returns true if VSI is in vlan mode or false otherwise |
| 1156 | **/ |
| 1157 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1158 | { |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1159 | /* If we have a PVID, always operate in VLAN mode */ |
| 1160 | if (vsi->info.pvid) |
| 1161 | return true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1162 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1163 | /* We need to operate in VLAN mode whenever we have any filters with |
| 1164 | * a VLAN other than I40E_VLAN_ALL. We could check the table each |
| 1165 | * time, incurring search cost repeatedly. However, we can notice two |
| 1166 | * things: |
| 1167 | * |
| 1168 | * 1) the only place where we can gain a VLAN filter is in |
| 1169 | * i40e_add_filter. |
| 1170 | * |
| 1171 | * 2) the only place where filters are actually removed is in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1172 | * i40e_sync_filters_subtask. |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1173 | * |
| 1174 | * Thus, we can simply use a boolean value, has_vlan_filters which we |
| 1175 | * will set to true when we add a VLAN filter in i40e_add_filter. Then |
| 1176 | * we have to perform the full search after deleting filters in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1177 | * i40e_sync_filters_subtask, but we already have to search |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1178 | * filters here and can perform the check at the same time. This |
| 1179 | * results in avoiding embedding a loop for VLAN mode inside another |
| 1180 | * loop over all the filters, and should maintain correctness as noted |
| 1181 | * above. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1182 | */ |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1183 | return vsi->has_vlan_filter; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /** |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1187 | * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary |
| 1188 | * @vsi: the VSI to configure |
| 1189 | * @tmp_add_list: list of filters ready to be added |
| 1190 | * @tmp_del_list: list of filters ready to be deleted |
| 1191 | * @vlan_filters: the number of active VLAN filters |
| 1192 | * |
| 1193 | * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they |
| 1194 | * behave as expected. If we have any active VLAN filters remaining or about |
| 1195 | * to be added then we need to update non-VLAN filters to be marked as VLAN=0 |
| 1196 | * so that they only match against untagged traffic. If we no longer have any |
| 1197 | * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1 |
| 1198 | * so that they match against both tagged and untagged traffic. In this way, |
| 1199 | * we ensure that we correctly receive the desired traffic. This ensures that |
| 1200 | * when we have an active VLAN we will receive only untagged traffic and |
| 1201 | * traffic matching active VLANs. If we have no active VLANs then we will |
| 1202 | * operate in non-VLAN mode and receive all traffic, tagged or untagged. |
| 1203 | * |
| 1204 | * Finally, in a similar fashion, this function also corrects filters when |
| 1205 | * there is an active PVID assigned to this VSI. |
| 1206 | * |
| 1207 | * In case of memory allocation failure return -ENOMEM. Otherwise, return 0. |
| 1208 | * |
| 1209 | * This function is only expected to be called from within |
| 1210 | * i40e_sync_vsi_filters. |
| 1211 | * |
| 1212 | * NOTE: This function expects to be called while under the |
| 1213 | * mac_filter_hash_lock |
| 1214 | */ |
| 1215 | static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi, |
| 1216 | struct hlist_head *tmp_add_list, |
| 1217 | struct hlist_head *tmp_del_list, |
| 1218 | int vlan_filters) |
| 1219 | { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1220 | s16 pvid = le16_to_cpu(vsi->info.pvid); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1221 | struct i40e_mac_filter *f, *add_head; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1222 | struct i40e_new_mac_filter *new; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1223 | struct hlist_node *h; |
| 1224 | int bkt, new_vlan; |
| 1225 | |
| 1226 | /* To determine if a particular filter needs to be replaced we |
| 1227 | * have the three following conditions: |
| 1228 | * |
| 1229 | * a) if we have a PVID assigned, then all filters which are |
| 1230 | * not marked as VLAN=PVID must be replaced with filters that |
| 1231 | * are. |
| 1232 | * b) otherwise, if we have any active VLANS, all filters |
| 1233 | * which are marked as VLAN=-1 must be replaced with |
| 1234 | * filters marked as VLAN=0 |
| 1235 | * c) finally, if we do not have any active VLANS, all filters |
| 1236 | * which are marked as VLAN=0 must be replaced with filters |
| 1237 | * marked as VLAN=-1 |
| 1238 | */ |
| 1239 | |
| 1240 | /* Update the filters about to be added in place */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1241 | hlist_for_each_entry(new, tmp_add_list, hlist) { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1242 | if (pvid && new->f->vlan != pvid) |
| 1243 | new->f->vlan = pvid; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1244 | else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY) |
| 1245 | new->f->vlan = 0; |
| 1246 | else if (!vlan_filters && new->f->vlan == 0) |
| 1247 | new->f->vlan = I40E_VLAN_ANY; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | /* Update the remaining active filters */ |
| 1251 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
| 1252 | /* Combine the checks for whether a filter needs to be changed |
| 1253 | * and then determine the new VLAN inside the if block, in |
| 1254 | * order to avoid duplicating code for adding the new filter |
| 1255 | * then deleting the old filter. |
| 1256 | */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1257 | if ((pvid && f->vlan != pvid) || |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1258 | (vlan_filters && f->vlan == I40E_VLAN_ANY) || |
| 1259 | (!vlan_filters && f->vlan == 0)) { |
| 1260 | /* Determine the new vlan we will be adding */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1261 | if (pvid) |
| 1262 | new_vlan = pvid; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1263 | else if (vlan_filters) |
| 1264 | new_vlan = 0; |
| 1265 | else |
| 1266 | new_vlan = I40E_VLAN_ANY; |
| 1267 | |
| 1268 | /* Create the new filter */ |
| 1269 | add_head = i40e_add_filter(vsi, f->macaddr, new_vlan); |
| 1270 | if (!add_head) |
| 1271 | return -ENOMEM; |
| 1272 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1273 | /* Create a temporary i40e_new_mac_filter */ |
| 1274 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 1275 | if (!new) |
| 1276 | return -ENOMEM; |
| 1277 | |
| 1278 | new->f = add_head; |
| 1279 | new->state = add_head->state; |
| 1280 | |
| 1281 | /* Add the new filter to the tmp list */ |
| 1282 | hlist_add_head(&new->hlist, tmp_add_list); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1283 | |
| 1284 | /* Put the original filter into the delete list */ |
| 1285 | f->state = I40E_FILTER_REMOVE; |
| 1286 | hash_del(&f->hlist); |
| 1287 | hlist_add_head(&f->hlist, tmp_del_list); |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | vsi->has_vlan_filter = !!vlan_filters; |
| 1292 | |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | /** |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 1297 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1298 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1299 | * @macaddr: the MAC address |
| 1300 | * |
| 1301 | * Remove whatever filter the firmware set up so the driver can manage |
| 1302 | * its own filtering intelligently. |
| 1303 | **/ |
| 1304 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
| 1305 | { |
| 1306 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1307 | struct i40e_pf *pf = vsi->back; |
| 1308 | |
| 1309 | /* Only appropriate for the PF main VSI */ |
| 1310 | if (vsi->type != I40E_VSI_MAIN) |
| 1311 | return; |
| 1312 | |
| 1313 | memset(&element, 0, sizeof(element)); |
| 1314 | ether_addr_copy(element.mac_addr, macaddr); |
| 1315 | element.vlan_tag = 0; |
| 1316 | /* Ignore error returns, some firmware does it this way... */ |
| 1317 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1318 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1319 | |
| 1320 | memset(&element, 0, sizeof(element)); |
| 1321 | ether_addr_copy(element.mac_addr, macaddr); |
| 1322 | element.vlan_tag = 0; |
| 1323 | /* ...and some firmware does it this way. */ |
| 1324 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1325 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1326 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1327 | } |
| 1328 | |
| 1329 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1330 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1331 | * @vsi: the VSI to be searched |
| 1332 | * @macaddr: the MAC address |
| 1333 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1334 | * |
| 1335 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1336 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1337 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1338 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1339 | **/ |
| 1340 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1341 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1342 | { |
| 1343 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1344 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1345 | |
| 1346 | if (!vsi || !macaddr) |
| 1347 | return NULL; |
| 1348 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1349 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1350 | if (!f) { |
| 1351 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1352 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1353 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1355 | /* Update the boolean indicating if we need to function in |
| 1356 | * VLAN mode. |
| 1357 | */ |
| 1358 | if (vlan >= 0) |
| 1359 | vsi->has_vlan_filter = true; |
| 1360 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1361 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1362 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1363 | /* If we're in overflow promisc mode, set the state directly |
| 1364 | * to failed, so we don't bother to try sending the filter |
| 1365 | * to the hardware. |
| 1366 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1367 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state)) |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1368 | f->state = I40E_FILTER_FAILED; |
| 1369 | else |
| 1370 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1371 | INIT_HLIST_NODE(&f->hlist); |
| 1372 | |
| 1373 | key = i40e_addr_to_hkey(macaddr); |
| 1374 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1376 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1377 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1378 | } |
| 1379 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1380 | /* If we're asked to add a filter that has been marked for removal, it |
| 1381 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1382 | * will have simply deleted any filters which were previously marked |
| 1383 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1384 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1385 | * task, just restore this filter to the ACTIVE state so that the |
| 1386 | * sync task leaves it in place |
| 1387 | */ |
| 1388 | if (f->state == I40E_FILTER_REMOVE) |
| 1389 | f->state = I40E_FILTER_ACTIVE; |
| 1390 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1391 | return f; |
| 1392 | } |
| 1393 | |
| 1394 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1395 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1396 | * @vsi: VSI to remove from |
| 1397 | * @f: the filter to remove from the list |
| 1398 | * |
| 1399 | * This function should be called instead of i40e_del_filter only if you know |
| 1400 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1401 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1402 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1403 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1404 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1405 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1406 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1407 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1408 | **/ |
Jacob Keller | 148141b | 2016-11-11 12:39:36 -0800 | [diff] [blame] | 1409 | void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1410 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1411 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1412 | return; |
| 1413 | |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1414 | /* If the filter was never added to firmware then we can just delete it |
| 1415 | * directly and we don't want to set the status to remove or else an |
| 1416 | * admin queue command will unnecessarily fire. |
| 1417 | */ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1418 | if ((f->state == I40E_FILTER_FAILED) || |
| 1419 | (f->state == I40E_FILTER_NEW)) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1420 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1421 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1422 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1423 | f->state = I40E_FILTER_REMOVE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1424 | } |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1425 | |
| 1426 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1427 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1431 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1432 | * @vsi: the VSI to be searched |
| 1433 | * @macaddr: the MAC address |
| 1434 | * @vlan: the VLAN |
| 1435 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1436 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1437 | * being held. |
| 1438 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1439 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1440 | * instead of list_for_each_entry(). |
| 1441 | **/ |
| 1442 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1443 | { |
| 1444 | struct i40e_mac_filter *f; |
| 1445 | |
| 1446 | if (!vsi || !macaddr) |
| 1447 | return; |
| 1448 | |
| 1449 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1450 | __i40e_del_filter(vsi, f); |
| 1451 | } |
| 1452 | |
| 1453 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1454 | * i40e_add_mac_filter - Add a MAC filter for all active VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1455 | * @vsi: the VSI to be searched |
| 1456 | * @macaddr: the mac address to be filtered |
| 1457 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1458 | * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise, |
| 1459 | * go through all the macvlan filters and add a macvlan filter for each |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1460 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1461 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1462 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1463 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1464 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1465 | struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, |
| 1466 | const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1467 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1468 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1469 | struct hlist_node *h; |
| 1470 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1471 | |
| 1472 | if (vsi->info.pvid) |
| 1473 | return i40e_add_filter(vsi, macaddr, |
| 1474 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1475 | |
Jacob Keller | 7aaf9536 | 2016-11-11 12:39:33 -0800 | [diff] [blame] | 1476 | if (!i40e_is_vsi_in_vlan(vsi)) |
| 1477 | return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY); |
| 1478 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1479 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1480 | if (f->state == I40E_FILTER_REMOVE) |
| 1481 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1482 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1483 | if (!add) |
| 1484 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1487 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1491 | * i40e_del_mac_filter - Remove a MAC filter from all VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1492 | * @vsi: the VSI to be searched |
| 1493 | * @macaddr: the mac address to be removed |
| 1494 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1495 | * Removes a given MAC address from a VSI regardless of what VLAN it has been |
| 1496 | * associated with. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1497 | * |
| 1498 | * Returns 0 for success, or error |
| 1499 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1500 | int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1501 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1502 | struct i40e_mac_filter *f; |
| 1503 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1504 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1505 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1506 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1507 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1508 | "Missing mac_filter_hash_lock\n"); |
| 1509 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1510 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1511 | __i40e_del_filter(vsi, f); |
| 1512 | found = true; |
| 1513 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1514 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1515 | |
| 1516 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1517 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1518 | else |
| 1519 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1523 | * i40e_set_mac - NDO callback to set mac address |
| 1524 | * @netdev: network interface device structure |
| 1525 | * @p: pointer to an address structure |
| 1526 | * |
| 1527 | * Returns 0 on success, negative on failure |
| 1528 | **/ |
| 1529 | static int i40e_set_mac(struct net_device *netdev, void *p) |
| 1530 | { |
| 1531 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1532 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1533 | struct i40e_pf *pf = vsi->back; |
| 1534 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1535 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1536 | |
| 1537 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1538 | return -EADDRNOTAVAIL; |
| 1539 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1540 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1541 | netdev_info(netdev, "already using mac address %pM\n", |
| 1542 | addr->sa_data); |
| 1543 | return 0; |
| 1544 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1545 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1546 | if (test_bit(__I40E_VSI_DOWN, vsi->back->state) || |
| 1547 | test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state)) |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1548 | return -EADDRNOTAVAIL; |
| 1549 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1550 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1551 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1552 | hw->mac.addr); |
| 1553 | else |
| 1554 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1555 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1556 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1557 | i40e_del_mac_filter(vsi, netdev->dev_addr); |
| 1558 | i40e_add_mac_filter(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1559 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1560 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1561 | if (vsi->type == I40E_VSI_MAIN) { |
| 1562 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1563 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1564 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1565 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1566 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1567 | if (ret) |
| 1568 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1569 | i40e_stat_str(hw, ret), |
| 1570 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1573 | /* schedule our worker thread which will take care of |
| 1574 | * applying the new filter changes |
| 1575 | */ |
| 1576 | i40e_service_event_schedule(vsi->back); |
| 1577 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1582 | * @vsi: the VSI being setup |
| 1583 | * @ctxt: VSI context structure |
| 1584 | * @enabled_tc: Enabled TCs bitmap |
| 1585 | * @is_add: True if called before Add VSI |
| 1586 | * |
| 1587 | * Setup VSI queue mapping for enabled traffic classes. |
| 1588 | **/ |
| 1589 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1590 | struct i40e_vsi_context *ctxt, |
| 1591 | u8 enabled_tc, |
| 1592 | bool is_add) |
| 1593 | { |
| 1594 | struct i40e_pf *pf = vsi->back; |
| 1595 | u16 sections = 0; |
| 1596 | u8 netdev_tc = 0; |
| 1597 | u16 numtc = 0; |
| 1598 | u16 qcount; |
| 1599 | u8 offset; |
| 1600 | u16 qmap; |
| 1601 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1602 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1603 | |
| 1604 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1605 | offset = 0; |
| 1606 | |
| 1607 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1608 | /* Find numtc from enabled TC bitmap */ |
| 1609 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1610 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1611 | numtc++; |
| 1612 | } |
| 1613 | if (!numtc) { |
| 1614 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1615 | numtc = 1; |
| 1616 | } |
| 1617 | } else { |
| 1618 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1619 | numtc = 1; |
| 1620 | } |
| 1621 | |
| 1622 | vsi->tc_config.numtc = numtc; |
| 1623 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1624 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1625 | qcount = vsi->alloc_queue_pairs; |
| 1626 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1627 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1628 | num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1629 | |
| 1630 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1631 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1632 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1633 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1634 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1635 | int pow, num_qps; |
| 1636 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1637 | switch (vsi->type) { |
| 1638 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1639 | qcount = min_t(int, pf->alloc_rss_size, |
| 1640 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | case I40E_VSI_FDIR: |
| 1643 | case I40E_VSI_SRIOV: |
| 1644 | case I40E_VSI_VMDQ2: |
| 1645 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1646 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1647 | WARN_ON(i != 0); |
| 1648 | break; |
| 1649 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1650 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1651 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1652 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1653 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1654 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1655 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1656 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1657 | pow++; |
| 1658 | num_qps >>= 1; |
| 1659 | } |
| 1660 | |
| 1661 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1662 | qmap = |
| 1663 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1664 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1665 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1666 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1667 | } else { |
| 1668 | /* TC is not enabled so set the offset to |
| 1669 | * default queue and allocate one queue |
| 1670 | * for the given TC. |
| 1671 | */ |
| 1672 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1673 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1674 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1675 | |
| 1676 | qmap = 0; |
| 1677 | } |
| 1678 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1679 | } |
| 1680 | |
| 1681 | /* Set actual Tx/Rx queue pairs */ |
| 1682 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1683 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1684 | if (vsi->req_queue_pairs > 0) |
| 1685 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1686 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1687 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1688 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1689 | |
| 1690 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1691 | if (is_add) { |
| 1692 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1693 | |
| 1694 | ctxt->info.up_enable_bits = enabled_tc; |
| 1695 | } |
| 1696 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1697 | ctxt->info.mapping_flags |= |
| 1698 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1699 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1700 | ctxt->info.queue_mapping[i] = |
| 1701 | cpu_to_le16(vsi->base_queue + i); |
| 1702 | } else { |
| 1703 | ctxt->info.mapping_flags |= |
| 1704 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1705 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1706 | } |
| 1707 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1708 | } |
| 1709 | |
| 1710 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1711 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1712 | * @netdev: the netdevice |
| 1713 | * @addr: address to add |
| 1714 | * |
| 1715 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1716 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1717 | */ |
| 1718 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1719 | { |
| 1720 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1721 | struct i40e_vsi *vsi = np->vsi; |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1722 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1723 | if (i40e_add_mac_filter(vsi, addr)) |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1724 | return 0; |
| 1725 | else |
| 1726 | return -ENOMEM; |
| 1727 | } |
| 1728 | |
| 1729 | /** |
| 1730 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1731 | * @netdev: the netdevice |
| 1732 | * @addr: address to add |
| 1733 | * |
| 1734 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1735 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1736 | */ |
| 1737 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1738 | { |
| 1739 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1740 | struct i40e_vsi *vsi = np->vsi; |
| 1741 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1742 | i40e_del_mac_filter(vsi, addr); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1743 | |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
| 1747 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1748 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1749 | * @netdev: network interface device structure |
| 1750 | **/ |
| 1751 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1752 | { |
| 1753 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1754 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1755 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1756 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1757 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1758 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1759 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1760 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1761 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1762 | |
| 1763 | /* check for other flag changes */ |
| 1764 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1765 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1766 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1767 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1768 | |
| 1769 | /* schedule our worker thread which will take care of |
| 1770 | * applying the new filter changes |
| 1771 | */ |
| 1772 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1776 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1777 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1778 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1779 | * those entries needs to be undone. |
| 1780 | * |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1781 | * MAC filter entries from this list were slated for deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1782 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1783 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1784 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1785 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1786 | struct i40e_mac_filter *f; |
| 1787 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1788 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1789 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1790 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1791 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1792 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1793 | hlist_del(&f->hlist); |
| 1794 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1799 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1800 | * @vsi: Pointer to vsi struct |
| 1801 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1802 | * those entries needs to be undone. |
| 1803 | * |
| 1804 | * MAC filter entries from this list were slated for addition. |
| 1805 | **/ |
| 1806 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, |
| 1807 | struct hlist_head *from) |
| 1808 | { |
| 1809 | struct i40e_new_mac_filter *new; |
| 1810 | struct hlist_node *h; |
| 1811 | |
| 1812 | hlist_for_each_entry_safe(new, h, from, hlist) { |
| 1813 | /* We can simply free the wrapper structure */ |
| 1814 | hlist_del(&new->hlist); |
| 1815 | kfree(new); |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | /** |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1820 | * i40e_next_entry - Get the next non-broadcast filter from a list |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1821 | * @next: pointer to filter in list |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1822 | * |
| 1823 | * Returns the next non-broadcast filter in the list. Required so that we |
| 1824 | * ignore broadcast filters within the list, since these are not handled via |
| 1825 | * the normal firmware update path. |
| 1826 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1827 | static |
| 1828 | struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next) |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1829 | { |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1830 | hlist_for_each_entry_continue(next, hlist) { |
| 1831 | if (!is_broadcast_ether_addr(next->f->macaddr)) |
| 1832 | return next; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1835 | return NULL; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1839 | * i40e_update_filter_state - Update filter state based on return data |
| 1840 | * from firmware |
| 1841 | * @count: Number of filters added |
| 1842 | * @add_list: return data from fw |
| 1843 | * @head: pointer to first filter in current batch |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1844 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1845 | * MAC filter entries from list were slated to be added to device. Returns |
| 1846 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1847 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1848 | static int |
| 1849 | i40e_update_filter_state(int count, |
| 1850 | struct i40e_aqc_add_macvlan_element_data *add_list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1851 | struct i40e_new_mac_filter *add_head) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1852 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1853 | int retval = 0; |
| 1854 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1855 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1856 | for (i = 0; i < count; i++) { |
| 1857 | /* Always check status of each filter. We don't need to check |
| 1858 | * the firmware return status because we pre-set the filter |
| 1859 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter |
| 1860 | * request to the adminq. Thus, if it no longer matches then |
| 1861 | * we know the filter is active. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1862 | */ |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1863 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1864 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1865 | } else { |
| 1866 | add_head->state = I40E_FILTER_ACTIVE; |
| 1867 | retval++; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1868 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1869 | |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1870 | add_head = i40e_next_filter(add_head); |
| 1871 | if (!add_head) |
| 1872 | break; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1873 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1874 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1875 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1879 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1880 | * @vsi: ptr to the VSI |
| 1881 | * @vsi_name: name to display in messages |
| 1882 | * @list: the list of filters to send to firmware |
| 1883 | * @num_del: the number of filters to delete |
| 1884 | * @retval: Set to -EIO on failure to delete |
| 1885 | * |
| 1886 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1887 | * *retval instead of a return value so that success does not force ret_val to |
| 1888 | * be set to 0. This ensures that a sequence of calls to this function |
| 1889 | * preserve the previous value of *retval on successful delete. |
| 1890 | */ |
| 1891 | static |
| 1892 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1893 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1894 | int num_del, int *retval) |
| 1895 | { |
| 1896 | struct i40e_hw *hw = &vsi->back->hw; |
| 1897 | i40e_status aq_ret; |
| 1898 | int aq_err; |
| 1899 | |
| 1900 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1901 | aq_err = hw->aq.asq_last_status; |
| 1902 | |
| 1903 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1904 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1905 | *retval = -EIO; |
| 1906 | dev_info(&vsi->back->pdev->dev, |
| 1907 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1908 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1909 | i40e_aq_str(hw, aq_err)); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1915 | * @vsi: ptr to the VSI |
| 1916 | * @vsi_name: name to display in messages |
| 1917 | * @list: the list of filters to send to firmware |
| 1918 | * @add_head: Position in the add hlist |
| 1919 | * @num_add: the number of filters to add |
| 1920 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1921 | * |
| 1922 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1923 | * promisc_changed to true if the firmware has run out of space for more |
| 1924 | * filters. |
| 1925 | */ |
| 1926 | static |
| 1927 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1928 | struct i40e_aqc_add_macvlan_element_data *list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1929 | struct i40e_new_mac_filter *add_head, |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1930 | int num_add, bool *promisc_changed) |
| 1931 | { |
| 1932 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1933 | int aq_err, fcnt; |
| 1934 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1935 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1936 | aq_err = hw->aq.asq_last_status; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1937 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1938 | |
| 1939 | if (fcnt != num_add) { |
| 1940 | *promisc_changed = true; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1941 | set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1942 | dev_warn(&vsi->back->pdev->dev, |
| 1943 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1944 | i40e_aq_str(hw, aq_err), |
| 1945 | vsi_name); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1950 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 1951 | * @vsi: pointer to the VSI |
| 1952 | * @f: filter data |
| 1953 | * |
| 1954 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 1955 | * filters in order to properly receive broadcast frames. Assumes that only |
| 1956 | * broadcast filters are passed. |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1957 | * |
| 1958 | * Returns status indicating success or failure; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1959 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1960 | static i40e_status |
| 1961 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 1962 | struct i40e_mac_filter *f) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1963 | { |
| 1964 | bool enable = f->state == I40E_FILTER_NEW; |
| 1965 | struct i40e_hw *hw = &vsi->back->hw; |
| 1966 | i40e_status aq_ret; |
| 1967 | |
| 1968 | if (f->vlan == I40E_VLAN_ANY) { |
| 1969 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 1970 | vsi->seid, |
| 1971 | enable, |
| 1972 | NULL); |
| 1973 | } else { |
| 1974 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 1975 | vsi->seid, |
| 1976 | enable, |
| 1977 | f->vlan, |
| 1978 | NULL); |
| 1979 | } |
| 1980 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1981 | if (aq_ret) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1982 | dev_warn(&vsi->back->pdev->dev, |
| 1983 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 1984 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 1985 | vsi_name); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1986 | |
| 1987 | return aq_ret; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1991 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1992 | * @vsi: ptr to the VSI |
| 1993 | * |
| 1994 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1995 | * |
| 1996 | * Returns 0 or error value |
| 1997 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1998 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1999 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2000 | struct hlist_head tmp_add_list, tmp_del_list; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2001 | struct i40e_mac_filter *f; |
| 2002 | struct i40e_new_mac_filter *new, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2003 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2004 | unsigned int failed_filters = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2005 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2006 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2007 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2008 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2009 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2010 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2011 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2012 | struct i40e_pf *pf; |
| 2013 | int num_add = 0; |
| 2014 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2015 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2016 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2017 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2018 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2019 | |
| 2020 | /* empty array typed pointers, kcalloc later */ |
| 2021 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 2022 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 2023 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2024 | while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2025 | usleep_range(1000, 2000); |
| 2026 | pf = vsi->back; |
| 2027 | |
| 2028 | if (vsi->netdev) { |
| 2029 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 2030 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 2031 | } |
| 2032 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2033 | INIT_HLIST_HEAD(&tmp_add_list); |
| 2034 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2035 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2036 | if (vsi->type == I40E_VSI_SRIOV) |
| 2037 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 2038 | else if (vsi->type != I40E_VSI_MAIN) |
| 2039 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 2040 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2041 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 2042 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 2043 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2044 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2045 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2046 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2047 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2048 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2049 | hash_del(&f->hlist); |
| 2050 | hlist_add_head(&f->hlist, &tmp_del_list); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2051 | |
| 2052 | /* Avoid counting removed filters */ |
| 2053 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2054 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2055 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2056 | /* Create a temporary i40e_new_mac_filter */ |
| 2057 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 2058 | if (!new) |
| 2059 | goto err_no_memory_locked; |
| 2060 | |
| 2061 | /* Store pointer to the real filter */ |
| 2062 | new->f = f; |
| 2063 | new->state = f->state; |
| 2064 | |
| 2065 | /* Add it to the hash list */ |
| 2066 | hlist_add_head(&new->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2067 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2068 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2069 | /* Count the number of active (current and new) VLAN |
| 2070 | * filters we have now. Does not count filters which |
| 2071 | * are marked for deletion. |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2072 | */ |
| 2073 | if (f->vlan > 0) |
| 2074 | vlan_filters++; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2077 | retval = i40e_correct_mac_vlan_filters(vsi, |
| 2078 | &tmp_add_list, |
| 2079 | &tmp_del_list, |
| 2080 | vlan_filters); |
| 2081 | if (retval) |
| 2082 | goto err_no_memory_locked; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2083 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2084 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2088 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2089 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2090 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2091 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2092 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2093 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2094 | if (!del_list) |
| 2095 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2096 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2097 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2098 | cmd_flags = 0; |
| 2099 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2100 | /* handle broadcast filters by updating the broadcast |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2101 | * promiscuous flag and release filter list. |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2102 | */ |
| 2103 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2104 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2105 | |
| 2106 | hlist_del(&f->hlist); |
| 2107 | kfree(f); |
| 2108 | continue; |
| 2109 | } |
| 2110 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2111 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2112 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2113 | if (f->vlan == I40E_VLAN_ANY) { |
| 2114 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2115 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2116 | } else { |
| 2117 | del_list[num_del].vlan_tag = |
| 2118 | cpu_to_le16((u16)(f->vlan)); |
| 2119 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2120 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2121 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2122 | del_list[num_del].flags = cmd_flags; |
| 2123 | num_del++; |
| 2124 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2125 | /* flush a full buffer */ |
| 2126 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2127 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2128 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2129 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2130 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2131 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2132 | /* Release memory for MAC filter entries which were |
| 2133 | * synced up with HW. |
| 2134 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2135 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2136 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2137 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2138 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2139 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2140 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2141 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | kfree(del_list); |
| 2145 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2146 | } |
| 2147 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2148 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2149 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2150 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2151 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2152 | list_size = filter_list_len * |
| 2153 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2154 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2155 | if (!add_list) |
| 2156 | goto err_no_memory; |
| 2157 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2158 | num_add = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2159 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2160 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2161 | vsi->state)) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2162 | new->state = I40E_FILTER_FAILED; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2163 | continue; |
| 2164 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2165 | |
| 2166 | /* handle broadcast filters by updating the broadcast |
| 2167 | * promiscuous flag instead of adding a MAC filter. |
| 2168 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2169 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
| 2170 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, |
| 2171 | new->f)) |
| 2172 | new->state = I40E_FILTER_FAILED; |
| 2173 | else |
| 2174 | new->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2175 | continue; |
| 2176 | } |
| 2177 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2178 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2179 | if (num_add == 0) |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2180 | add_head = new; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2181 | cmd_flags = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2182 | ether_addr_copy(add_list[num_add].mac_addr, |
| 2183 | new->f->macaddr); |
| 2184 | if (new->f->vlan == I40E_VLAN_ANY) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2185 | add_list[num_add].vlan_tag = 0; |
| 2186 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2187 | } else { |
| 2188 | add_list[num_add].vlan_tag = |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2189 | cpu_to_le16((u16)(new->f->vlan)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2190 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2191 | add_list[num_add].queue_number = 0; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2192 | /* set invalid match method for later detection */ |
Keller, Jacob E | 0266ac4 | 2016-12-09 13:39:21 -0800 | [diff] [blame] | 2193 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2194 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2195 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2196 | num_add++; |
| 2197 | |
| 2198 | /* flush a full buffer */ |
| 2199 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2200 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2201 | add_head, num_add, |
| 2202 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2203 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2204 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2208 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2209 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2210 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2211 | /* Now move all of the filters from the temp add list back to |
| 2212 | * the VSI's list. |
| 2213 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2214 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2215 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
| 2216 | /* Only update the state if we're still NEW */ |
| 2217 | if (new->f->state == I40E_FILTER_NEW) |
| 2218 | new->f->state = new->state; |
| 2219 | hlist_del(&new->hlist); |
| 2220 | kfree(new); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2221 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2222 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2223 | kfree(add_list); |
| 2224 | add_list = NULL; |
| 2225 | } |
| 2226 | |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2227 | /* Determine the number of active and failed filters. */ |
| 2228 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2229 | vsi->active_filters = 0; |
| 2230 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
| 2231 | if (f->state == I40E_FILTER_ACTIVE) |
| 2232 | vsi->active_filters++; |
| 2233 | else if (f->state == I40E_FILTER_FAILED) |
| 2234 | failed_filters++; |
| 2235 | } |
| 2236 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2237 | |
| 2238 | /* If promiscuous mode has changed, we need to calculate a new |
| 2239 | * threshold for when we are safe to exit |
| 2240 | */ |
| 2241 | if (promisc_changed) |
| 2242 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 2243 | |
| 2244 | /* Check if we are able to exit overflow promiscuous mode. We can |
| 2245 | * safely exit if we didn't just enter, we no longer have any failed |
| 2246 | * filters, and we have reduced filters below the threshold value. |
| 2247 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2248 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) && |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2249 | !promisc_changed && !failed_filters && |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2250 | (vsi->active_filters < vsi->promisc_threshold)) { |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2251 | dev_info(&pf->pdev->dev, |
| 2252 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2253 | vsi_name); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2254 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2255 | promisc_changed = true; |
| 2256 | vsi->promisc_threshold = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2259 | /* if the VF is not trusted do not do promisc */ |
| 2260 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2261 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2262 | goto out; |
| 2263 | } |
| 2264 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2265 | /* check for changes in promiscuous modes */ |
| 2266 | if (changed_flags & IFF_ALLMULTI) { |
| 2267 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2268 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2269 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2270 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2271 | vsi->seid, |
| 2272 | cur_multipromisc, |
| 2273 | NULL); |
| 2274 | if (aq_ret) { |
| 2275 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2276 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2277 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2278 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2279 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2280 | i40e_stat_str(hw, aq_ret), |
| 2281 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2282 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2283 | } |
Alan Brady | e588723 | 2017-06-07 05:43:10 -0400 | [diff] [blame] | 2284 | |
| 2285 | if ((changed_flags & IFF_PROMISC) || promisc_changed) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2286 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2287 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2288 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2289 | test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2290 | vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2291 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2292 | (pf->lan_veb != I40E_NO_VEB) && |
| 2293 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2294 | /* set defport ON for Main VSI instead of true promisc |
| 2295 | * this way we will get all unicast/multicast and VLAN |
| 2296 | * promisc behavior but will not get VF or VMDq traffic |
| 2297 | * replicated on the Main VSI. |
| 2298 | */ |
| 2299 | if (pf->cur_promisc != cur_promisc) { |
| 2300 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2301 | if (cur_promisc) |
| 2302 | aq_ret = |
| 2303 | i40e_aq_set_default_vsi(hw, |
| 2304 | vsi->seid, |
| 2305 | NULL); |
| 2306 | else |
| 2307 | aq_ret = |
| 2308 | i40e_aq_clear_default_vsi(hw, |
| 2309 | vsi->seid, |
| 2310 | NULL); |
| 2311 | if (aq_ret) { |
| 2312 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2313 | hw->aq.asq_last_status); |
| 2314 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2315 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2316 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2317 | i40e_stat_str(hw, aq_ret), |
| 2318 | i40e_aq_str(hw, |
| 2319 | hw->aq.asq_last_status)); |
| 2320 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2321 | } |
| 2322 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2323 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2324 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2325 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2326 | cur_promisc, NULL, |
| 2327 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2328 | if (aq_ret) { |
| 2329 | retval = |
| 2330 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2331 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2332 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2333 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2334 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2335 | i40e_stat_str(hw, aq_ret), |
| 2336 | i40e_aq_str(hw, |
| 2337 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2338 | } |
| 2339 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2340 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2341 | vsi->seid, |
| 2342 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2343 | if (aq_ret) { |
| 2344 | retval = |
| 2345 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2346 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2347 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2348 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2349 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2350 | i40e_stat_str(hw, aq_ret), |
| 2351 | i40e_aq_str(hw, |
| 2352 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2353 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2354 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2355 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2356 | vsi->seid, |
| 2357 | cur_promisc, NULL); |
| 2358 | if (aq_ret) { |
| 2359 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2360 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2361 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2362 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2363 | i40e_stat_str(hw, aq_ret), |
| 2364 | i40e_aq_str(hw, |
| 2365 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2366 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2367 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2368 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2369 | /* if something went wrong then set the changed flag so we try again */ |
| 2370 | if (retval) |
| 2371 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2372 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2373 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2374 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2375 | |
| 2376 | err_no_memory: |
| 2377 | /* Restore elements on the temporary add and delete lists */ |
| 2378 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2379 | err_no_memory_locked: |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2380 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 2381 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2382 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2383 | |
| 2384 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2385 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2386 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | /** |
| 2390 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2391 | * @pf: board private structure |
| 2392 | **/ |
| 2393 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2394 | { |
| 2395 | int v; |
| 2396 | |
| 2397 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2398 | return; |
| 2399 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2400 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2401 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2402 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2403 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2404 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2405 | |
| 2406 | if (ret) { |
| 2407 | /* come back and try again later */ |
| 2408 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2409 | break; |
| 2410 | } |
| 2411 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | /** |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2416 | * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP |
| 2417 | * @vsi: the vsi |
| 2418 | **/ |
| 2419 | static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi) |
| 2420 | { |
| 2421 | if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 2422 | return I40E_RXBUFFER_2048; |
| 2423 | else |
| 2424 | return I40E_RXBUFFER_3072; |
| 2425 | } |
| 2426 | |
| 2427 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2428 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2429 | * @netdev: network interface device structure |
| 2430 | * @new_mtu: new value for maximum frame size |
| 2431 | * |
| 2432 | * Returns 0 on success, negative on failure |
| 2433 | **/ |
| 2434 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2435 | { |
| 2436 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2437 | struct i40e_vsi *vsi = np->vsi; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2438 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2439 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2440 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 2441 | int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 2442 | |
| 2443 | if (frame_size > i40e_max_xdp_frame_size(vsi)) |
| 2444 | return -EINVAL; |
| 2445 | } |
| 2446 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2447 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2448 | netdev->mtu, new_mtu); |
| 2449 | netdev->mtu = new_mtu; |
| 2450 | if (netif_running(netdev)) |
| 2451 | i40e_vsi_reinit_locked(vsi); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2452 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 2453 | I40E_FLAG_CLIENT_L2_CHANGE); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2458 | * i40e_ioctl - Access the hwtstamp interface |
| 2459 | * @netdev: network interface device structure |
| 2460 | * @ifr: interface request data |
| 2461 | * @cmd: ioctl command |
| 2462 | **/ |
| 2463 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2464 | { |
| 2465 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2466 | struct i40e_pf *pf = np->vsi->back; |
| 2467 | |
| 2468 | switch (cmd) { |
| 2469 | case SIOCGHWTSTAMP: |
| 2470 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2471 | case SIOCSHWTSTAMP: |
| 2472 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2473 | default: |
| 2474 | return -EOPNOTSUPP; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2479 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2480 | * @vsi: the vsi being adjusted |
| 2481 | **/ |
| 2482 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2483 | { |
| 2484 | struct i40e_vsi_context ctxt; |
| 2485 | i40e_status ret; |
| 2486 | |
| 2487 | if ((vsi->info.valid_sections & |
| 2488 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2489 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2490 | return; /* already enabled */ |
| 2491 | |
| 2492 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2493 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2494 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2495 | |
| 2496 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2497 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2498 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2499 | if (ret) { |
| 2500 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2501 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2502 | i40e_stat_str(&vsi->back->hw, ret), |
| 2503 | i40e_aq_str(&vsi->back->hw, |
| 2504 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | |
| 2508 | /** |
| 2509 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2510 | * @vsi: the vsi being adjusted |
| 2511 | **/ |
| 2512 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2513 | { |
| 2514 | struct i40e_vsi_context ctxt; |
| 2515 | i40e_status ret; |
| 2516 | |
| 2517 | if ((vsi->info.valid_sections & |
| 2518 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2519 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2520 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2521 | return; /* already disabled */ |
| 2522 | |
| 2523 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2524 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2525 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2526 | |
| 2527 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2528 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2529 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2530 | if (ret) { |
| 2531 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2532 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2533 | i40e_stat_str(&vsi->back->hw, ret), |
| 2534 | i40e_aq_str(&vsi->back->hw, |
| 2535 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2541 | * @netdev: network interface to be adjusted |
| 2542 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2543 | **/ |
| 2544 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2545 | { |
| 2546 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2547 | struct i40e_vsi *vsi = np->vsi; |
| 2548 | |
| 2549 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2550 | i40e_vlan_stripping_enable(vsi); |
| 2551 | else |
| 2552 | i40e_vlan_stripping_disable(vsi); |
| 2553 | } |
| 2554 | |
| 2555 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2556 | * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2557 | * @vsi: the vsi being configured |
| 2558 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2559 | * |
| 2560 | * This is a helper function for adding a new MAC/VLAN filter with the |
| 2561 | * specified VLAN for each existing MAC address already in the hash table. |
| 2562 | * This function does *not* perform any accounting to update filters based on |
| 2563 | * VLAN mode. |
| 2564 | * |
| 2565 | * NOTE: this function expects to be called while under the |
| 2566 | * mac_filter_hash_lock |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2567 | **/ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2568 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2569 | { |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2570 | struct i40e_mac_filter *f, *add_f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2571 | struct hlist_node *h; |
| 2572 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2573 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2574 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2575 | if (f->state == I40E_FILTER_REMOVE) |
| 2576 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2577 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2578 | if (!add_f) { |
| 2579 | dev_info(&vsi->back->pdev->dev, |
| 2580 | "Could not add vlan filter %d for %pM\n", |
| 2581 | vid, f->macaddr); |
| 2582 | return -ENOMEM; |
| 2583 | } |
| 2584 | } |
| 2585 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2586 | return 0; |
| 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN |
| 2591 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2592 | * @vid: VLAN id to be added |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2593 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2594 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2595 | { |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2596 | int err; |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2597 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2598 | if (vsi->info.pvid) |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2599 | return -EINVAL; |
| 2600 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2601 | /* The network stack will attempt to add VID=0, with the intention to |
| 2602 | * receive priority tagged packets with a VLAN of 0. Our HW receives |
| 2603 | * these packets by default when configured to receive untagged |
| 2604 | * packets, so we don't need to add a filter for this case. |
| 2605 | * Additionally, HW interprets adding a VID=0 filter as meaning to |
| 2606 | * receive *only* tagged traffic and stops receiving untagged traffic. |
| 2607 | * Thus, we do not want to actually add a filter for VID=0 |
| 2608 | */ |
| 2609 | if (!vid) |
| 2610 | return 0; |
| 2611 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2612 | /* Locked once because all functions invoked below iterates list*/ |
| 2613 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2614 | err = i40e_add_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2615 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2616 | if (err) |
| 2617 | return err; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2618 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2619 | /* schedule our worker thread which will take care of |
| 2620 | * applying the new filter changes |
| 2621 | */ |
| 2622 | i40e_service_event_schedule(vsi->back); |
| 2623 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2627 | * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2628 | * @vsi: the vsi being configured |
| 2629 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2630 | * |
| 2631 | * This function should be used to remove all VLAN filters which match the |
| 2632 | * given VID. It does not schedule the service event and does not take the |
| 2633 | * mac_filter_hash_lock so it may be combined with other operations under |
| 2634 | * a single invocation of the mac_filter_hash_lock. |
| 2635 | * |
| 2636 | * NOTE: this function expects to be called while under the |
| 2637 | * mac_filter_hash_lock |
| 2638 | */ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2639 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2640 | { |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2641 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2642 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2643 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2644 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2645 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2646 | if (f->vlan == vid) |
| 2647 | __i40e_del_filter(vsi, f); |
| 2648 | } |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2649 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2650 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2651 | /** |
| 2652 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN |
| 2653 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2654 | * @vid: VLAN id to be removed |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2655 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2656 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2657 | { |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2658 | if (!vid || vsi->info.pvid) |
| 2659 | return; |
| 2660 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2661 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2662 | i40e_rm_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2663 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2664 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2665 | /* schedule our worker thread which will take care of |
| 2666 | * applying the new filter changes |
| 2667 | */ |
| 2668 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2673 | * @netdev: network interface to be adjusted |
| 2674 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2675 | * |
| 2676 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2677 | **/ |
| 2678 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2679 | __always_unused __be16 proto, u16 vid) |
| 2680 | { |
| 2681 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2682 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2683 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2684 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2685 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2686 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2687 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2688 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2689 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2690 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2691 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2692 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | /** |
| 2696 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2697 | * @netdev: network interface to be adjusted |
| 2698 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2699 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2700 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2701 | **/ |
| 2702 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2703 | __always_unused __be16 proto, u16 vid) |
| 2704 | { |
| 2705 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2706 | struct i40e_vsi *vsi = np->vsi; |
| 2707 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2708 | /* return code is ignored as there is nothing a user |
| 2709 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2710 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2711 | */ |
| 2712 | i40e_vsi_kill_vlan(vsi, vid); |
| 2713 | |
| 2714 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2715 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2716 | return 0; |
| 2717 | } |
| 2718 | |
| 2719 | /** |
| 2720 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2721 | * @vsi: the vsi being brought back up |
| 2722 | **/ |
| 2723 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2724 | { |
| 2725 | u16 vid; |
| 2726 | |
| 2727 | if (!vsi->netdev) |
| 2728 | return; |
| 2729 | |
| 2730 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2731 | |
| 2732 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2733 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2734 | vid); |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2739 | * @vsi: the vsi being adjusted |
| 2740 | * @vid: the vlan id to set as a PVID |
| 2741 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2742 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2743 | { |
| 2744 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2745 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2746 | |
| 2747 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2748 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2749 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2750 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2751 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2752 | |
| 2753 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2754 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2755 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2756 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2757 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2758 | "add pvid failed, err %s aq_err %s\n", |
| 2759 | i40e_stat_str(&vsi->back->hw, ret), |
| 2760 | i40e_aq_str(&vsi->back->hw, |
| 2761 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2762 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2765 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | /** |
| 2769 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2770 | * @vsi: the vsi being adjusted |
| 2771 | * |
| 2772 | * Just use the vlan_rx_register() service to put it back to normal |
| 2773 | **/ |
| 2774 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2775 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2776 | i40e_vlan_stripping_disable(vsi); |
| 2777 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2778 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2783 | * @vsi: ptr to the VSI |
| 2784 | * |
| 2785 | * If this function returns with an error, then it's possible one or |
| 2786 | * more of the rings is populated (while the rest are not). It is the |
| 2787 | * callers duty to clean those orphaned rings. |
| 2788 | * |
| 2789 | * Return 0 on success, negative on failure |
| 2790 | **/ |
| 2791 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2792 | { |
| 2793 | int i, err = 0; |
| 2794 | |
| 2795 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2796 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2797 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2798 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 2799 | return err; |
| 2800 | |
| 2801 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
| 2802 | err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]); |
| 2803 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2804 | return err; |
| 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2809 | * @vsi: ptr to the VSI |
| 2810 | * |
| 2811 | * Free VSI's transmit software resources |
| 2812 | **/ |
| 2813 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2814 | { |
| 2815 | int i; |
| 2816 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2817 | if (vsi->tx_rings) { |
| 2818 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2819 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
| 2820 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 2821 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2822 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2823 | if (vsi->xdp_rings) { |
| 2824 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2825 | if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) |
| 2826 | i40e_free_tx_resources(vsi->xdp_rings[i]); |
| 2827 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2832 | * @vsi: ptr to the VSI |
| 2833 | * |
| 2834 | * If this function returns with an error, then it's possible one or |
| 2835 | * more of the rings is populated (while the rest are not). It is the |
| 2836 | * callers duty to clean those orphaned rings. |
| 2837 | * |
| 2838 | * Return 0 on success, negative on failure |
| 2839 | **/ |
| 2840 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2841 | { |
| 2842 | int i, err = 0; |
| 2843 | |
| 2844 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2845 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2846 | return err; |
| 2847 | } |
| 2848 | |
| 2849 | /** |
| 2850 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2851 | * @vsi: ptr to the VSI |
| 2852 | * |
| 2853 | * Free all receive software resources |
| 2854 | **/ |
| 2855 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2856 | { |
| 2857 | int i; |
| 2858 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2859 | if (!vsi->rx_rings) |
| 2860 | return; |
| 2861 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2862 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2863 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2864 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2868 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2869 | * @ring: The Tx ring to configure |
| 2870 | * |
| 2871 | * This enables/disables XPS for a given Tx descriptor ring |
| 2872 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2873 | **/ |
| 2874 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2875 | { |
| 2876 | struct i40e_vsi *vsi = ring->vsi; |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2877 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2878 | if (!ring->q_vector || !ring->netdev) |
| 2879 | return; |
| 2880 | |
Jacob Keller | ba4460d | 2017-07-14 09:10:08 -0400 | [diff] [blame] | 2881 | if ((vsi->tc_config.numtc <= 1) && |
| 2882 | !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) { |
| 2883 | netif_set_xps_queue(ring->netdev, |
| 2884 | &ring->q_vector->affinity_mask, |
| 2885 | ring->queue_index); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2886 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2887 | |
| 2888 | /* schedule our worker thread which will take care of |
| 2889 | * applying the new filter changes |
| 2890 | */ |
| 2891 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2895 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2896 | * @ring: The Tx ring to configure |
| 2897 | * |
| 2898 | * Configure the Tx descriptor ring in the HMC context. |
| 2899 | **/ |
| 2900 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2901 | { |
| 2902 | struct i40e_vsi *vsi = ring->vsi; |
| 2903 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2904 | struct i40e_hw *hw = &vsi->back->hw; |
| 2905 | struct i40e_hmc_obj_txq tx_ctx; |
| 2906 | i40e_status err = 0; |
| 2907 | u32 qtx_ctl = 0; |
| 2908 | |
| 2909 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2910 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2911 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2912 | ring->atr_count = 0; |
| 2913 | } else { |
| 2914 | ring->atr_sample_rate = 0; |
| 2915 | } |
| 2916 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2917 | /* configure XPS */ |
| 2918 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2919 | |
| 2920 | /* clear the context structure first */ |
| 2921 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2922 | |
| 2923 | tx_ctx.new_context = 1; |
| 2924 | tx_ctx.base = (ring->dma / 128); |
| 2925 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2926 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2927 | I40E_FLAG_FD_ATR_ENABLED)); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2928 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2929 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2930 | if (vsi->type != I40E_VSI_FDIR) |
| 2931 | tx_ctx.head_wb_ena = 1; |
| 2932 | tx_ctx.head_wb_addr = ring->dma + |
| 2933 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2934 | |
| 2935 | /* As part of VSI creation/update, FW allocates certain |
| 2936 | * Tx arbitration queue sets for each TC enabled for |
| 2937 | * the VSI. The FW returns the handles to these queue |
| 2938 | * sets as part of the response buffer to Add VSI, |
| 2939 | * Update VSI, etc. AQ commands. It is expected that |
| 2940 | * these queue set handles be associated with the Tx |
| 2941 | * queues by the driver as part of the TX queue context |
| 2942 | * initialization. This has to be done regardless of |
| 2943 | * DCB as by default everything is mapped to TC0. |
| 2944 | */ |
| 2945 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2946 | tx_ctx.rdylist_act = 0; |
| 2947 | |
| 2948 | /* clear the context in the HMC */ |
| 2949 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2950 | if (err) { |
| 2951 | dev_info(&vsi->back->pdev->dev, |
| 2952 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2953 | ring->queue_index, pf_q, err); |
| 2954 | return -ENOMEM; |
| 2955 | } |
| 2956 | |
| 2957 | /* set the context in the HMC */ |
| 2958 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2959 | if (err) { |
| 2960 | dev_info(&vsi->back->pdev->dev, |
| 2961 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2962 | ring->queue_index, pf_q, err); |
| 2963 | return -ENOMEM; |
| 2964 | } |
| 2965 | |
| 2966 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2967 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2968 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2969 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2970 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2971 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2972 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2973 | } |
| 2974 | |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2975 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2976 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2977 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2978 | i40e_flush(hw); |
| 2979 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2980 | /* cache tail off for easier writes later */ |
| 2981 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2982 | |
| 2983 | return 0; |
| 2984 | } |
| 2985 | |
| 2986 | /** |
| 2987 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2988 | * @ring: The Rx ring to configure |
| 2989 | * |
| 2990 | * Configure the Rx descriptor ring in the HMC context. |
| 2991 | **/ |
| 2992 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2993 | { |
| 2994 | struct i40e_vsi *vsi = ring->vsi; |
| 2995 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2996 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2997 | struct i40e_hw *hw = &vsi->back->hw; |
| 2998 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2999 | i40e_status err = 0; |
| 3000 | |
| 3001 | ring->state = 0; |
| 3002 | |
| 3003 | /* clear the context structure first */ |
| 3004 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 3005 | |
| 3006 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3007 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3008 | rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len, |
| 3009 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3010 | |
| 3011 | rx_ctx.base = (ring->dma / 128); |
| 3012 | rx_ctx.qlen = ring->count; |
| 3013 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3014 | /* use 32 byte descriptors */ |
| 3015 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3017 | /* descriptor type is always zero |
| 3018 | * rx_ctx.dtype = 0; |
| 3019 | */ |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3020 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3021 | |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3022 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3023 | if (hw->revision_id == 0) |
| 3024 | rx_ctx.lrxqthresh = 0; |
| 3025 | else |
| 3026 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3027 | rx_ctx.crcstrip = 1; |
| 3028 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3029 | /* this controls whether VLAN is stripped from inner headers */ |
| 3030 | rx_ctx.showiv = 0; |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3031 | /* set the prefena field to 1 because the manual says to */ |
| 3032 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3033 | |
| 3034 | /* clear the context in the HMC */ |
| 3035 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3036 | if (err) { |
| 3037 | dev_info(&vsi->back->pdev->dev, |
| 3038 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3039 | ring->queue_index, pf_q, err); |
| 3040 | return -ENOMEM; |
| 3041 | } |
| 3042 | |
| 3043 | /* set the context in the HMC */ |
| 3044 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3045 | if (err) { |
| 3046 | dev_info(&vsi->back->pdev->dev, |
| 3047 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3048 | ring->queue_index, pf_q, err); |
| 3049 | return -ENOMEM; |
| 3050 | } |
| 3051 | |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3052 | /* configure Rx buffer alignment */ |
| 3053 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 3054 | clear_ring_build_skb_enabled(ring); |
| 3055 | else |
| 3056 | set_ring_build_skb_enabled(ring); |
| 3057 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3058 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3059 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3060 | writel(0, ring->tail); |
| 3061 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3062 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3063 | |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
| 3067 | /** |
| 3068 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3069 | * @vsi: VSI structure describing this set of rings and resources |
| 3070 | * |
| 3071 | * Configure the Tx VSI for operation. |
| 3072 | **/ |
| 3073 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3074 | { |
| 3075 | int err = 0; |
| 3076 | u16 i; |
| 3077 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3078 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3079 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3080 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3081 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3082 | return err; |
| 3083 | |
| 3084 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3085 | err = i40e_configure_tx_ring(vsi->xdp_rings[i]); |
| 3086 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3087 | return err; |
| 3088 | } |
| 3089 | |
| 3090 | /** |
| 3091 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3092 | * @vsi: the VSI being configured |
| 3093 | * |
| 3094 | * Configure the Rx VSI for operation. |
| 3095 | **/ |
| 3096 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3097 | { |
| 3098 | int err = 0; |
| 3099 | u16 i; |
| 3100 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3101 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) { |
| 3102 | vsi->max_frame = I40E_MAX_RXBUFFER; |
| 3103 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 3104 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3105 | } else if (!I40E_2K_TOO_SMALL_WITH_PADDING && |
| 3106 | (vsi->netdev->mtu <= ETH_DATA_LEN)) { |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3107 | vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3108 | vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3109 | #endif |
| 3110 | } else { |
| 3111 | vsi->max_frame = I40E_MAX_RXBUFFER; |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 3112 | vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 : |
| 3113 | I40E_RXBUFFER_2048; |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3114 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3115 | |
| 3116 | /* set up individual rings */ |
| 3117 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3118 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3119 | |
| 3120 | return err; |
| 3121 | } |
| 3122 | |
| 3123 | /** |
| 3124 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3125 | * @vsi: ptr to the VSI |
| 3126 | **/ |
| 3127 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3128 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3129 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3130 | u16 qoffset, qcount; |
| 3131 | int i, n; |
| 3132 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3133 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3134 | /* Reset the TC information */ |
| 3135 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3136 | rx_ring = vsi->rx_rings[i]; |
| 3137 | tx_ring = vsi->tx_rings[i]; |
| 3138 | rx_ring->dcb_tc = 0; |
| 3139 | tx_ring->dcb_tc = 0; |
| 3140 | } |
| 3141 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3142 | |
| 3143 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3144 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3145 | continue; |
| 3146 | |
| 3147 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3148 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3149 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3150 | rx_ring = vsi->rx_rings[i]; |
| 3151 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3152 | rx_ring->dcb_tc = n; |
| 3153 | tx_ring->dcb_tc = n; |
| 3154 | } |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3160 | * @vsi: ptr to the VSI |
| 3161 | **/ |
| 3162 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3163 | { |
| 3164 | if (vsi->netdev) |
| 3165 | i40e_set_rx_mode(vsi->netdev); |
| 3166 | } |
| 3167 | |
| 3168 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3169 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3170 | * @vsi: Pointer to the targeted VSI |
| 3171 | * |
| 3172 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3173 | * filters were saved. |
| 3174 | **/ |
| 3175 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3176 | { |
| 3177 | struct i40e_fdir_filter *filter; |
| 3178 | struct i40e_pf *pf = vsi->back; |
| 3179 | struct hlist_node *node; |
| 3180 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3181 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3182 | return; |
| 3183 | |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3184 | /* Reset FDir counters as we're replaying all existing filters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3185 | pf->fd_tcp4_filter_cnt = 0; |
| 3186 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 3187 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3188 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3189 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3190 | hlist_for_each_entry_safe(filter, node, |
| 3191 | &pf->fdir_filter_list, fdir_node) { |
| 3192 | i40e_add_del_fdir(vsi, filter, true); |
| 3193 | } |
| 3194 | } |
| 3195 | |
| 3196 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3197 | * i40e_vsi_configure - Set up the VSI for action |
| 3198 | * @vsi: the VSI being configured |
| 3199 | **/ |
| 3200 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3201 | { |
| 3202 | int err; |
| 3203 | |
| 3204 | i40e_set_vsi_rx_mode(vsi); |
| 3205 | i40e_restore_vlan(vsi); |
| 3206 | i40e_vsi_config_dcb_rings(vsi); |
| 3207 | err = i40e_vsi_configure_tx(vsi); |
| 3208 | if (!err) |
| 3209 | err = i40e_vsi_configure_rx(vsi); |
| 3210 | |
| 3211 | return err; |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3216 | * @vsi: the VSI being configured |
| 3217 | **/ |
| 3218 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3219 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3220 | bool has_xdp = i40e_enabled_xdp_vsi(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3221 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3222 | struct i40e_hw *hw = &pf->hw; |
| 3223 | u16 vector; |
| 3224 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3225 | u32 qp; |
| 3226 | |
| 3227 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3228 | * and PFINT_LNKLSTn registers, e.g.: |
| 3229 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3230 | */ |
| 3231 | qp = vsi->base_queue; |
| 3232 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3233 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3234 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3235 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3236 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3237 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3238 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3239 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3240 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3241 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3242 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3243 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3244 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3245 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 3246 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3247 | |
| 3248 | /* Linked list for the queuepairs assigned to this vector */ |
| 3249 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3250 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3251 | u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3252 | u32 val; |
| 3253 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3254 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3255 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3256 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3257 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | |
| 3258 | (I40E_QUEUE_TYPE_TX << |
| 3259 | I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3260 | |
| 3261 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3262 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3263 | if (has_xdp) { |
| 3264 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3265 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3266 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3267 | (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3268 | (I40E_QUEUE_TYPE_TX << |
| 3269 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3270 | |
| 3271 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3272 | } |
| 3273 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3274 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3275 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3276 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3277 | ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3278 | (I40E_QUEUE_TYPE_RX << |
| 3279 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3280 | |
| 3281 | /* Terminate the linked list */ |
| 3282 | if (q == (q_vector->num_ringpairs - 1)) |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3283 | val |= (I40E_QUEUE_END_OF_LIST << |
| 3284 | I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3285 | |
| 3286 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3287 | qp++; |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | i40e_flush(hw); |
| 3292 | } |
| 3293 | |
| 3294 | /** |
| 3295 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3296 | * @hw: ptr to the hardware info |
| 3297 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3298 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3299 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3300 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3301 | u32 val; |
| 3302 | |
| 3303 | /* clear things first */ |
| 3304 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3305 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3306 | |
| 3307 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3308 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3309 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3310 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3311 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3312 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3313 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3314 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3315 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3316 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3317 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3318 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3319 | if (pf->flags & I40E_FLAG_PTP) |
| 3320 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3321 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3322 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3323 | |
| 3324 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3325 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3326 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3327 | |
| 3328 | /* OTHER_ITR_IDX = 0 */ |
| 3329 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3330 | } |
| 3331 | |
| 3332 | /** |
| 3333 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3334 | * @vsi: the VSI being configured |
| 3335 | **/ |
| 3336 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3337 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3338 | u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3339 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3340 | struct i40e_pf *pf = vsi->back; |
| 3341 | struct i40e_hw *hw = &pf->hw; |
| 3342 | u32 val; |
| 3343 | |
| 3344 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3345 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3346 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3347 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3348 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3349 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3350 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3351 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3352 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3353 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3354 | |
| 3355 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3356 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3357 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3358 | /* Associate the queue pair to the vector and enable the queue int */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3359 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3360 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3361 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3362 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3363 | |
| 3364 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3365 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3366 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 3367 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3368 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)| |
| 3369 | (I40E_QUEUE_TYPE_TX |
| 3370 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3371 | |
| 3372 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3373 | } |
| 3374 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3375 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3376 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3377 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3378 | |
| 3379 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3380 | i40e_flush(hw); |
| 3381 | } |
| 3382 | |
| 3383 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3384 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3385 | * @pf: board private structure |
| 3386 | **/ |
| 3387 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3388 | { |
| 3389 | struct i40e_hw *hw = &pf->hw; |
| 3390 | |
| 3391 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3392 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3393 | i40e_flush(hw); |
| 3394 | } |
| 3395 | |
| 3396 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3397 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3398 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3399 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3400 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3401 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3402 | { |
| 3403 | struct i40e_hw *hw = &pf->hw; |
| 3404 | u32 val; |
| 3405 | |
| 3406 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3407 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3408 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3409 | |
| 3410 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3411 | i40e_flush(hw); |
| 3412 | } |
| 3413 | |
| 3414 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3415 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3416 | * @irq: interrupt number |
| 3417 | * @data: pointer to a q_vector |
| 3418 | **/ |
| 3419 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3420 | { |
| 3421 | struct i40e_q_vector *q_vector = data; |
| 3422 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3423 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3424 | return IRQ_HANDLED; |
| 3425 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3426 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3427 | |
| 3428 | return IRQ_HANDLED; |
| 3429 | } |
| 3430 | |
| 3431 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3432 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3433 | * @notify: context as to what irq was changed |
| 3434 | * @mask: the new affinity mask |
| 3435 | * |
| 3436 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3437 | * so that we may register to receive changes to the irq affinity masks. |
| 3438 | **/ |
| 3439 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3440 | const cpumask_t *mask) |
| 3441 | { |
| 3442 | struct i40e_q_vector *q_vector = |
| 3443 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3444 | |
Jacob Keller | 7e4d01e | 2017-07-12 05:46:05 -0400 | [diff] [blame] | 3445 | cpumask_copy(&q_vector->affinity_mask, mask); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | /** |
| 3449 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3450 | * @ref: internal core kernel usage |
| 3451 | * |
| 3452 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3453 | * to inform the current notification subscriber that they will no longer |
| 3454 | * receive notifications. |
| 3455 | **/ |
| 3456 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3457 | |
| 3458 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3459 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3460 | * @vsi: the VSI being configured |
| 3461 | * @basename: name for the vector |
| 3462 | * |
| 3463 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3464 | **/ |
| 3465 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3466 | { |
| 3467 | int q_vectors = vsi->num_q_vectors; |
| 3468 | struct i40e_pf *pf = vsi->back; |
| 3469 | int base = vsi->base_vector; |
| 3470 | int rx_int_idx = 0; |
| 3471 | int tx_int_idx = 0; |
| 3472 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3473 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3474 | |
| 3475 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3476 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3477 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3478 | irq_num = pf->msix_entries[base + vector].vector; |
| 3479 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3480 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3481 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3482 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3483 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3484 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3485 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3486 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3487 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3488 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3489 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3490 | } else { |
| 3491 | /* skip this unused q_vector */ |
| 3492 | continue; |
| 3493 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3494 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3495 | vsi->irq_handler, |
| 3496 | 0, |
| 3497 | q_vector->name, |
| 3498 | q_vector); |
| 3499 | if (err) { |
| 3500 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3501 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3502 | goto free_queue_irqs; |
| 3503 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3504 | |
| 3505 | /* register for affinity change notifications */ |
| 3506 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3507 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3508 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3509 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3510 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3513 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3514 | return 0; |
| 3515 | |
| 3516 | free_queue_irqs: |
| 3517 | while (vector) { |
| 3518 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3519 | irq_num = pf->msix_entries[base + vector].vector; |
| 3520 | irq_set_affinity_notifier(irq_num, NULL); |
| 3521 | irq_set_affinity_hint(irq_num, NULL); |
| 3522 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3523 | } |
| 3524 | return err; |
| 3525 | } |
| 3526 | |
| 3527 | /** |
| 3528 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3529 | * @vsi: the VSI being un-configured |
| 3530 | **/ |
| 3531 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3532 | { |
| 3533 | struct i40e_pf *pf = vsi->back; |
| 3534 | struct i40e_hw *hw = &pf->hw; |
| 3535 | int base = vsi->base_vector; |
| 3536 | int i; |
| 3537 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3538 | /* disable interrupt causation from each queue */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3539 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3540 | u32 val; |
| 3541 | |
| 3542 | val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx)); |
| 3543 | val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3544 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val); |
| 3545 | |
| 3546 | val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx)); |
| 3547 | val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3548 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val); |
| 3549 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3550 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3551 | continue; |
| 3552 | wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3555 | /* disable each interrupt */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3556 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3557 | for (i = vsi->base_vector; |
| 3558 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3559 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3560 | |
| 3561 | i40e_flush(hw); |
| 3562 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3563 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3564 | } else { |
| 3565 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3566 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3567 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3568 | i40e_flush(hw); |
| 3569 | synchronize_irq(pf->pdev->irq); |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | /** |
| 3574 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3575 | * @vsi: the VSI being configured |
| 3576 | **/ |
| 3577 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3578 | { |
| 3579 | struct i40e_pf *pf = vsi->back; |
| 3580 | int i; |
| 3581 | |
| 3582 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3583 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3584 | i40e_irq_dynamic_enable(vsi, i); |
| 3585 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3586 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3587 | } |
| 3588 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3589 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3590 | return 0; |
| 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3595 | * @pf: board private structure |
| 3596 | **/ |
| 3597 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3598 | { |
| 3599 | /* Disable ICR 0 */ |
| 3600 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3601 | i40e_flush(&pf->hw); |
| 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3606 | * @irq: interrupt number |
| 3607 | * @data: pointer to a q_vector |
| 3608 | * |
| 3609 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3610 | * with both queue and non-queue interrupts. This is also used in |
| 3611 | * MSIX mode to handle the non-queue interrupts. |
| 3612 | **/ |
| 3613 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3614 | { |
| 3615 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3616 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3617 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3618 | u32 icr0, icr0_remaining; |
| 3619 | u32 val, ena_mask; |
| 3620 | |
| 3621 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3622 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3623 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3624 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3625 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3626 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3627 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3628 | /* if interrupt but no bits showing, must be SWINT */ |
| 3629 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3630 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3631 | pf->sw_int_count++; |
| 3632 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3633 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3634 | (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3635 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
Carolyn Wyborny | 23bb6dc | 2016-11-08 13:05:12 -0800 | [diff] [blame] | 3636 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3637 | set_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3638 | } |
| 3639 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3640 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3641 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3642 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3643 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3644 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3645 | /* We do not have a way to disarm Queue causes while leaving |
| 3646 | * interrupt enabled for all other causes, ideally |
| 3647 | * interrupt should be disabled while we are in NAPI but |
| 3648 | * this is not a performance path and napi_schedule() |
| 3649 | * can deal with rescheduling. |
| 3650 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3651 | if (!test_bit(__I40E_DOWN, pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3652 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3656 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3657 | set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3658 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3662 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3663 | set_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3667 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3668 | set_bit(__I40E_VFLR_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3672 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
| 3673 | set_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3674 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3675 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3676 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3677 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3678 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3679 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3680 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3681 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3682 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3683 | pf->empr_count++; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3684 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3685 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3688 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3689 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3690 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3691 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3692 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3693 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3696 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3697 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3698 | |
| 3699 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3700 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3701 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3702 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3705 | /* If a critical error is pending we have no choice but to reset the |
| 3706 | * device. |
| 3707 | * Report and mask out any remaining unexpected interrupts. |
| 3708 | */ |
| 3709 | icr0_remaining = icr0 & ena_mask; |
| 3710 | if (icr0_remaining) { |
| 3711 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3712 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3713 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3714 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3715 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3716 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3717 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3718 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3719 | } |
| 3720 | ena_mask &= ~icr0_remaining; |
| 3721 | } |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3722 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3723 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3724 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3725 | /* re-enable interrupt causes */ |
| 3726 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3727 | if (!test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3728 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3729 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3732 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3736 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3737 | * @tx_ring: tx ring to clean |
| 3738 | * @budget: how many cleans we're allowed |
| 3739 | * |
| 3740 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3741 | **/ |
| 3742 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3743 | { |
| 3744 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3745 | u16 i = tx_ring->next_to_clean; |
| 3746 | struct i40e_tx_buffer *tx_buf; |
| 3747 | struct i40e_tx_desc *tx_desc; |
| 3748 | |
| 3749 | tx_buf = &tx_ring->tx_bi[i]; |
| 3750 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3751 | i -= tx_ring->count; |
| 3752 | |
| 3753 | do { |
| 3754 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3755 | |
| 3756 | /* if next_to_watch is not set then there is no work pending */ |
| 3757 | if (!eop_desc) |
| 3758 | break; |
| 3759 | |
| 3760 | /* prevent any other reads prior to eop_desc */ |
| 3761 | read_barrier_depends(); |
| 3762 | |
| 3763 | /* if the descriptor isn't done, no work yet to do */ |
| 3764 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3765 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3766 | break; |
| 3767 | |
| 3768 | /* clear next_to_watch to prevent false hangs */ |
| 3769 | tx_buf->next_to_watch = NULL; |
| 3770 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3771 | tx_desc->buffer_addr = 0; |
| 3772 | tx_desc->cmd_type_offset_bsz = 0; |
| 3773 | /* move past filter desc */ |
| 3774 | tx_buf++; |
| 3775 | tx_desc++; |
| 3776 | i++; |
| 3777 | if (unlikely(!i)) { |
| 3778 | i -= tx_ring->count; |
| 3779 | tx_buf = tx_ring->tx_bi; |
| 3780 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3781 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3782 | /* unmap skb header data */ |
| 3783 | dma_unmap_single(tx_ring->dev, |
| 3784 | dma_unmap_addr(tx_buf, dma), |
| 3785 | dma_unmap_len(tx_buf, len), |
| 3786 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3787 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3788 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3789 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3790 | tx_buf->raw_buf = NULL; |
| 3791 | tx_buf->tx_flags = 0; |
| 3792 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3793 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3794 | tx_desc->buffer_addr = 0; |
| 3795 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3796 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3797 | /* move us past the eop_desc for start of next FD desc */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3798 | tx_buf++; |
| 3799 | tx_desc++; |
| 3800 | i++; |
| 3801 | if (unlikely(!i)) { |
| 3802 | i -= tx_ring->count; |
| 3803 | tx_buf = tx_ring->tx_bi; |
| 3804 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3805 | } |
| 3806 | |
| 3807 | /* update budget accounting */ |
| 3808 | budget--; |
| 3809 | } while (likely(budget)); |
| 3810 | |
| 3811 | i += tx_ring->count; |
| 3812 | tx_ring->next_to_clean = i; |
| 3813 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3814 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3815 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3816 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3817 | return budget > 0; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3822 | * @irq: interrupt number |
| 3823 | * @data: pointer to a q_vector |
| 3824 | **/ |
| 3825 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3826 | { |
| 3827 | struct i40e_q_vector *q_vector = data; |
| 3828 | struct i40e_vsi *vsi; |
| 3829 | |
| 3830 | if (!q_vector->tx.ring) |
| 3831 | return IRQ_HANDLED; |
| 3832 | |
| 3833 | vsi = q_vector->tx.ring->vsi; |
| 3834 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3835 | |
| 3836 | return IRQ_HANDLED; |
| 3837 | } |
| 3838 | |
| 3839 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3840 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3841 | * @vsi: the VSI being configured |
| 3842 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3843 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3844 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3845 | static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3846 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3847 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3848 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3849 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | |
| 3851 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3852 | tx_ring->next = q_vector->tx.ring; |
| 3853 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3854 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3855 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3856 | /* Place XDP Tx ring in the same q_vector ring list as regular Tx */ |
| 3857 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 3858 | struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx]; |
| 3859 | |
| 3860 | xdp_ring->q_vector = q_vector; |
| 3861 | xdp_ring->next = q_vector->tx.ring; |
| 3862 | q_vector->tx.ring = xdp_ring; |
| 3863 | q_vector->tx.count++; |
| 3864 | } |
| 3865 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3866 | rx_ring->q_vector = q_vector; |
| 3867 | rx_ring->next = q_vector->rx.ring; |
| 3868 | q_vector->rx.ring = rx_ring; |
| 3869 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | /** |
| 3873 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3874 | * @vsi: the VSI being configured |
| 3875 | * |
| 3876 | * This function maps descriptor rings to the queue-specific vectors |
| 3877 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3878 | * one vector per queue pair, but on a constrained vector budget, we |
| 3879 | * group the queue pairs as "efficiently" as possible. |
| 3880 | **/ |
| 3881 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3882 | { |
| 3883 | int qp_remaining = vsi->num_queue_pairs; |
| 3884 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3885 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3886 | int v_start = 0; |
| 3887 | int qp_idx = 0; |
| 3888 | |
| 3889 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3890 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3891 | * It is also important to go through all the vectors available to be |
| 3892 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3893 | * are cleared. This is especially important when decreasing the |
| 3894 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3895 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3896 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3897 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3898 | |
| 3899 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3900 | |
| 3901 | q_vector->num_ringpairs = num_ringpairs; |
| 3902 | |
| 3903 | q_vector->rx.count = 0; |
| 3904 | q_vector->tx.count = 0; |
| 3905 | q_vector->rx.ring = NULL; |
| 3906 | q_vector->tx.ring = NULL; |
| 3907 | |
| 3908 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3909 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3910 | qp_idx++; |
| 3911 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3912 | } |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | /** |
| 3917 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3918 | * @vsi: the VSI being configured |
| 3919 | * @basename: name for the vector |
| 3920 | **/ |
| 3921 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3922 | { |
| 3923 | struct i40e_pf *pf = vsi->back; |
| 3924 | int err; |
| 3925 | |
| 3926 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3927 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3928 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3929 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3930 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3931 | else |
| 3932 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3933 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3934 | |
| 3935 | if (err) |
| 3936 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3937 | |
| 3938 | return err; |
| 3939 | } |
| 3940 | |
| 3941 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3942 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3943 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3944 | * @netdev: network interface device structure |
| 3945 | * |
| 3946 | * This is used by netconsole to send skbs without having to re-enable |
| 3947 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3948 | **/ |
| 3949 | static void i40e_netpoll(struct net_device *netdev) |
| 3950 | { |
| 3951 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3952 | struct i40e_vsi *vsi = np->vsi; |
| 3953 | struct i40e_pf *pf = vsi->back; |
| 3954 | int i; |
| 3955 | |
| 3956 | /* if interface is down do nothing */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3957 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3958 | return; |
| 3959 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3960 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3961 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3962 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3963 | } else { |
| 3964 | i40e_intr(pf->pdev->irq, netdev); |
| 3965 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3966 | } |
| 3967 | #endif |
| 3968 | |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 3969 | #define I40E_QTX_ENA_WAIT_COUNT 50 |
| 3970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3971 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3972 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3973 | * @pf: the PF being configured |
| 3974 | * @pf_q: the PF queue |
| 3975 | * @enable: enable or disable state of the queue |
| 3976 | * |
| 3977 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3978 | * enabled or disabled state. |
| 3979 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3980 | * multiple retries; else will return 0 in case of success. |
| 3981 | **/ |
| 3982 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3983 | { |
| 3984 | int i; |
| 3985 | u32 tx_reg; |
| 3986 | |
| 3987 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3988 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3989 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3990 | break; |
| 3991 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3992 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3993 | } |
| 3994 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3995 | return -ETIMEDOUT; |
| 3996 | |
| 3997 | return 0; |
| 3998 | } |
| 3999 | |
| 4000 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4001 | * i40e_control_tx_q - Start or stop a particular Tx queue |
| 4002 | * @pf: the PF structure |
| 4003 | * @pf_q: the PF queue to configure |
| 4004 | * @enable: start or stop the queue |
| 4005 | * |
| 4006 | * This function enables or disables a single queue. Note that any delay |
| 4007 | * required after the operation is expected to be handled by the caller of |
| 4008 | * this function. |
| 4009 | **/ |
| 4010 | static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4011 | { |
| 4012 | struct i40e_hw *hw = &pf->hw; |
| 4013 | u32 tx_reg; |
| 4014 | int i; |
| 4015 | |
| 4016 | /* warn the TX unit of coming changes */ |
| 4017 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 4018 | if (!enable) |
| 4019 | usleep_range(10, 20); |
| 4020 | |
| 4021 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4022 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
| 4023 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4024 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4025 | break; |
| 4026 | usleep_range(1000, 2000); |
| 4027 | } |
| 4028 | |
| 4029 | /* Skip if the queue is already in the requested state */ |
| 4030 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4031 | return; |
| 4032 | |
| 4033 | /* turn on/off the queue */ |
| 4034 | if (enable) { |
| 4035 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
| 4036 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
| 4037 | } else { |
| 4038 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
| 4039 | } |
| 4040 | |
| 4041 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
| 4042 | } |
| 4043 | |
| 4044 | /** |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4045 | * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion |
| 4046 | * @seid: VSI SEID |
| 4047 | * @pf: the PF structure |
| 4048 | * @pf_q: the PF queue to configure |
| 4049 | * @is_xdp: true if the queue is used for XDP |
| 4050 | * @enable: start or stop the queue |
| 4051 | **/ |
| 4052 | static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q, |
| 4053 | bool is_xdp, bool enable) |
| 4054 | { |
| 4055 | int ret; |
| 4056 | |
| 4057 | i40e_control_tx_q(pf, pf_q, enable); |
| 4058 | |
| 4059 | /* wait for the change to finish */ |
| 4060 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 4061 | if (ret) { |
| 4062 | dev_info(&pf->pdev->dev, |
| 4063 | "VSI seid %d %sTx ring %d %sable timeout\n", |
| 4064 | seid, (is_xdp ? "XDP " : ""), pf_q, |
| 4065 | (enable ? "en" : "dis")); |
| 4066 | } |
| 4067 | |
| 4068 | return ret; |
| 4069 | } |
| 4070 | |
| 4071 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4072 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 4073 | * @vsi: the VSI being configured |
| 4074 | * @enable: start or stop the rings |
| 4075 | **/ |
| 4076 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 4077 | { |
| 4078 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4079 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4080 | |
| 4081 | pf_q = vsi->base_queue; |
| 4082 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4083 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4084 | pf_q, |
| 4085 | false /*is xdp*/, enable); |
| 4086 | if (ret) |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4087 | break; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4088 | |
| 4089 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4090 | continue; |
| 4091 | |
| 4092 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4093 | pf_q + vsi->alloc_queue_pairs, |
| 4094 | true /*is xdp*/, enable); |
| 4095 | if (ret) |
| 4096 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4099 | return ret; |
| 4100 | } |
| 4101 | |
| 4102 | /** |
| 4103 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 4104 | * @pf: the PF being configured |
| 4105 | * @pf_q: the PF queue |
| 4106 | * @enable: enable or disable state of the queue |
| 4107 | * |
| 4108 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4109 | * enabled or disabled state. |
| 4110 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4111 | * multiple retries; else will return 0 in case of success. |
| 4112 | **/ |
| 4113 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4114 | { |
| 4115 | int i; |
| 4116 | u32 rx_reg; |
| 4117 | |
| 4118 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4119 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4120 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4121 | break; |
| 4122 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4123 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4124 | } |
| 4125 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4126 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4127 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4128 | return 0; |
| 4129 | } |
| 4130 | |
| 4131 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4132 | * i40e_control_rx_q - Start or stop a particular Rx queue |
| 4133 | * @pf: the PF structure |
| 4134 | * @pf_q: the PF queue to configure |
| 4135 | * @enable: start or stop the queue |
| 4136 | * |
| 4137 | * This function enables or disables a single queue. Note that any delay |
| 4138 | * required after the operation is expected to be handled by the caller of |
| 4139 | * this function. |
| 4140 | **/ |
| 4141 | static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4142 | { |
| 4143 | struct i40e_hw *hw = &pf->hw; |
| 4144 | u32 rx_reg; |
| 4145 | int i; |
| 4146 | |
| 4147 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4148 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 4149 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4150 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4151 | break; |
| 4152 | usleep_range(1000, 2000); |
| 4153 | } |
| 4154 | |
| 4155 | /* Skip if the queue is already in the requested state */ |
| 4156 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4157 | return; |
| 4158 | |
| 4159 | /* turn on/off the queue */ |
| 4160 | if (enable) |
| 4161 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
| 4162 | else |
| 4163 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
| 4164 | |
| 4165 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 4166 | } |
| 4167 | |
| 4168 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4169 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4170 | * @vsi: the VSI being configured |
| 4171 | * @enable: start or stop the rings |
| 4172 | **/ |
| 4173 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4174 | { |
| 4175 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4176 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4177 | |
| 4178 | pf_q = vsi->base_queue; |
| 4179 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4180 | i40e_control_rx_q(pf, pf_q, enable); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4181 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4182 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4183 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4184 | if (ret) { |
| 4185 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4186 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4187 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4188 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | |
Wyborny, Carolyn | d08a9f6 | 2017-03-28 08:00:48 -0700 | [diff] [blame] | 4192 | /* Due to HW errata, on Rx disable only, the register can indicate done |
| 4193 | * before it really is. Needs 50ms to be sure |
| 4194 | */ |
| 4195 | if (!enable) |
| 4196 | mdelay(50); |
| 4197 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4198 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4202 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4203 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4204 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4205 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4206 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4207 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4208 | |
| 4209 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4210 | ret = i40e_vsi_control_rx(vsi, true); |
| 4211 | if (ret) |
| 4212 | return ret; |
| 4213 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4214 | |
| 4215 | return ret; |
| 4216 | } |
| 4217 | |
| 4218 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4219 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4220 | * @vsi: the VSI being configured |
| 4221 | **/ |
| 4222 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4223 | { |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4224 | /* When port TX is suspended, don't wait */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4225 | if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state)) |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4226 | return i40e_vsi_stop_rings_no_wait(vsi); |
| 4227 | |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4228 | /* do rx first for enable and last for disable |
| 4229 | * Ignore return value, we need to shutdown whatever we can |
| 4230 | */ |
| 4231 | i40e_vsi_control_tx(vsi, false); |
| 4232 | i40e_vsi_control_rx(vsi, false); |
| 4233 | } |
| 4234 | |
| 4235 | /** |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4236 | * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay |
| 4237 | * @vsi: the VSI being shutdown |
| 4238 | * |
| 4239 | * This function stops all the rings for a VSI but does not delay to verify |
| 4240 | * that rings have been disabled. It is expected that the caller is shutting |
| 4241 | * down multiple VSIs at once and will delay together for all the VSIs after |
| 4242 | * initiating the shutdown. This is particularly useful for shutting down lots |
| 4243 | * of VFs together. Otherwise, a large delay can be incurred while configuring |
| 4244 | * each VSI in serial. |
| 4245 | **/ |
| 4246 | void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi) |
| 4247 | { |
| 4248 | struct i40e_pf *pf = vsi->back; |
| 4249 | int i, pf_q; |
| 4250 | |
| 4251 | pf_q = vsi->base_queue; |
| 4252 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4253 | i40e_control_tx_q(pf, pf_q, false); |
| 4254 | i40e_control_rx_q(pf, pf_q, false); |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4259 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4260 | * @vsi: the VSI being configured |
| 4261 | **/ |
| 4262 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4263 | { |
| 4264 | struct i40e_pf *pf = vsi->back; |
| 4265 | struct i40e_hw *hw = &pf->hw; |
| 4266 | int base = vsi->base_vector; |
| 4267 | u32 val, qp; |
| 4268 | int i; |
| 4269 | |
| 4270 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4271 | if (!vsi->q_vectors) |
| 4272 | return; |
| 4273 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4274 | if (!vsi->irqs_ready) |
| 4275 | return; |
| 4276 | |
| 4277 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4278 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4279 | int irq_num; |
| 4280 | u16 vector; |
| 4281 | |
| 4282 | vector = i + base; |
| 4283 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4284 | |
| 4285 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4286 | if (!vsi->q_vectors[i] || |
| 4287 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4288 | continue; |
| 4289 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4290 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4291 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4292 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4293 | irq_set_affinity_hint(irq_num, NULL); |
| 4294 | synchronize_irq(irq_num); |
| 4295 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4296 | |
| 4297 | /* Tear down the interrupt queue link list |
| 4298 | * |
| 4299 | * We know that they come in pairs and always |
| 4300 | * the Rx first, then the Tx. To clear the |
| 4301 | * link list, stick the EOL value into the |
| 4302 | * next_q field of the registers. |
| 4303 | */ |
| 4304 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4305 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4306 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4307 | val |= I40E_QUEUE_END_OF_LIST |
| 4308 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4309 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4310 | |
| 4311 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4312 | u32 next; |
| 4313 | |
| 4314 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4315 | |
| 4316 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4317 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4318 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4319 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4320 | |
| 4321 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4322 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4323 | |
| 4324 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4325 | |
| 4326 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4327 | |
| 4328 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4329 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4330 | |
| 4331 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4332 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4333 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4334 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4335 | |
| 4336 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4337 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4338 | |
| 4339 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4340 | qp = next; |
| 4341 | } |
| 4342 | } |
| 4343 | } else { |
| 4344 | free_irq(pf->pdev->irq, pf); |
| 4345 | |
| 4346 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4347 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4348 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4349 | val |= I40E_QUEUE_END_OF_LIST |
| 4350 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4351 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4352 | |
| 4353 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4354 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4355 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4356 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4357 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4358 | |
| 4359 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4360 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4361 | |
| 4362 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4363 | |
| 4364 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4365 | |
| 4366 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4367 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4368 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4369 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4370 | |
| 4371 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4372 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4373 | |
| 4374 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4375 | } |
| 4376 | } |
| 4377 | |
| 4378 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4379 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4380 | * @vsi: the VSI being configured |
| 4381 | * @v_idx: Index of vector to be freed |
| 4382 | * |
| 4383 | * This function frees the memory allocated to the q_vector. In addition if |
| 4384 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4385 | * to freeing the q_vector. |
| 4386 | **/ |
| 4387 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4388 | { |
| 4389 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4390 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4391 | |
| 4392 | if (!q_vector) |
| 4393 | return; |
| 4394 | |
| 4395 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4396 | i40e_for_each_ring(ring, q_vector->tx) |
| 4397 | ring->q_vector = NULL; |
| 4398 | |
| 4399 | i40e_for_each_ring(ring, q_vector->rx) |
| 4400 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4401 | |
| 4402 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4403 | if (vsi->netdev) |
| 4404 | netif_napi_del(&q_vector->napi); |
| 4405 | |
| 4406 | vsi->q_vectors[v_idx] = NULL; |
| 4407 | |
| 4408 | kfree_rcu(q_vector, rcu); |
| 4409 | } |
| 4410 | |
| 4411 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4412 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4413 | * @vsi: the VSI being un-configured |
| 4414 | * |
| 4415 | * This frees the memory allocated to the q_vectors and |
| 4416 | * deletes references to the NAPI struct. |
| 4417 | **/ |
| 4418 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4419 | { |
| 4420 | int v_idx; |
| 4421 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4422 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4423 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4428 | * @pf: board private structure |
| 4429 | **/ |
| 4430 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4431 | { |
| 4432 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4433 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4434 | pci_disable_msix(pf->pdev); |
| 4435 | kfree(pf->msix_entries); |
| 4436 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4437 | kfree(pf->irq_pile); |
| 4438 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4439 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4440 | pci_disable_msi(pf->pdev); |
| 4441 | } |
| 4442 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4443 | } |
| 4444 | |
| 4445 | /** |
| 4446 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4447 | * @pf: board private structure |
| 4448 | * |
| 4449 | * We go through and clear interrupt specific resources and reset the structure |
| 4450 | * to pre-load conditions |
| 4451 | **/ |
| 4452 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4453 | { |
| 4454 | int i; |
| 4455 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4456 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4457 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4458 | synchronize_irq(pf->msix_entries[0].vector); |
| 4459 | free_irq(pf->msix_entries[0].vector, pf); |
| 4460 | } |
| 4461 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4462 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4463 | I40E_IWARP_IRQ_PILE_ID); |
| 4464 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4465 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4466 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4467 | if (pf->vsi[i]) |
| 4468 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4469 | i40e_reset_interrupt_capability(pf); |
| 4470 | } |
| 4471 | |
| 4472 | /** |
| 4473 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4474 | * @vsi: the VSI being configured |
| 4475 | **/ |
| 4476 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4477 | { |
| 4478 | int q_idx; |
| 4479 | |
| 4480 | if (!vsi->netdev) |
| 4481 | return; |
| 4482 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4483 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4484 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4485 | |
| 4486 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4487 | napi_enable(&q_vector->napi); |
| 4488 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
| 4492 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4493 | * @vsi: the VSI being configured |
| 4494 | **/ |
| 4495 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4496 | { |
| 4497 | int q_idx; |
| 4498 | |
| 4499 | if (!vsi->netdev) |
| 4500 | return; |
| 4501 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4502 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4503 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4504 | |
| 4505 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4506 | napi_disable(&q_vector->napi); |
| 4507 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4511 | * i40e_vsi_close - Shut down a VSI |
| 4512 | * @vsi: the vsi to be quelled |
| 4513 | **/ |
| 4514 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4515 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4516 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4517 | if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state)) |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4518 | i40e_down(vsi); |
| 4519 | i40e_vsi_free_irq(vsi); |
| 4520 | i40e_vsi_free_tx_resources(vsi); |
| 4521 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4522 | vsi->current_netdev_flags = 0; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4523 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4524 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4525 | pf->flags |= I40E_FLAG_CLIENT_RESET; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4529 | * i40e_quiesce_vsi - Pause a given VSI |
| 4530 | * @vsi: the VSI being paused |
| 4531 | **/ |
| 4532 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4533 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4534 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4535 | return; |
| 4536 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4537 | set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4538 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4539 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4540 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4541 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | /** |
| 4545 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4546 | * @vsi: the VSI being resumed |
| 4547 | **/ |
| 4548 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4549 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4550 | if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4551 | return; |
| 4552 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4553 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4554 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4555 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4556 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | /** |
| 4560 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4561 | * @pf: the PF |
| 4562 | **/ |
| 4563 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4564 | { |
| 4565 | int v; |
| 4566 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4567 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4568 | if (pf->vsi[v]) |
| 4569 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | /** |
| 4574 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4575 | * @pf: the PF |
| 4576 | **/ |
| 4577 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4578 | { |
| 4579 | int v; |
| 4580 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4581 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4582 | if (pf->vsi[v]) |
| 4583 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4584 | } |
| 4585 | } |
| 4586 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4587 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4588 | * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4589 | * @vsi: the VSI being configured |
| 4590 | * |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4591 | * Wait until all queues on a given VSI have been disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4592 | **/ |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4593 | int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4594 | { |
| 4595 | struct i40e_pf *pf = vsi->back; |
| 4596 | int i, pf_q, ret; |
| 4597 | |
| 4598 | pf_q = vsi->base_queue; |
| 4599 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4600 | /* Check and wait for the Tx queue */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4601 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4602 | if (ret) { |
| 4603 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4604 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4605 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4606 | return ret; |
| 4607 | } |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4608 | |
| 4609 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4610 | goto wait_rx; |
| 4611 | |
| 4612 | /* Check and wait for the XDP Tx queue */ |
| 4613 | ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs, |
| 4614 | false); |
| 4615 | if (ret) { |
| 4616 | dev_info(&pf->pdev->dev, |
| 4617 | "VSI seid %d XDP Tx ring %d disable timeout\n", |
| 4618 | vsi->seid, pf_q); |
| 4619 | return ret; |
| 4620 | } |
| 4621 | wait_rx: |
| 4622 | /* Check and wait for the Rx queue */ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4623 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4624 | if (ret) { |
| 4625 | dev_info(&pf->pdev->dev, |
| 4626 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4627 | vsi->seid, pf_q); |
| 4628 | return ret; |
| 4629 | } |
| 4630 | } |
| 4631 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4632 | return 0; |
| 4633 | } |
| 4634 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4635 | #ifdef CONFIG_I40E_DCB |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4636 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4637 | * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4638 | * @pf: the PF |
| 4639 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4640 | * This function waits for the queues to be in disabled state for all the |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4641 | * VSIs that are managed by this PF. |
| 4642 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4643 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4644 | { |
| 4645 | int v, ret = 0; |
| 4646 | |
| 4647 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 4648 | if (pf->vsi[v]) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4649 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4650 | if (ret) |
| 4651 | break; |
| 4652 | } |
| 4653 | } |
| 4654 | |
| 4655 | return ret; |
| 4656 | } |
| 4657 | |
| 4658 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4659 | |
| 4660 | /** |
| 4661 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4662 | * @q_idx: TX queue number |
| 4663 | * @vsi: Pointer to VSI struct |
| 4664 | * |
| 4665 | * This function checks specified queue for given VSI. Detects hung condition. |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4666 | * We proactively detect hung TX queues by checking if interrupts are disabled |
| 4667 | * but there are pending descriptors. If it appears hung, attempt to recover |
| 4668 | * by triggering a SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4669 | **/ |
| 4670 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4671 | { |
| 4672 | struct i40e_ring *tx_ring = NULL; |
| 4673 | struct i40e_pf *pf; |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4674 | u32 val, tx_pending; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4675 | int i; |
| 4676 | |
| 4677 | pf = vsi->back; |
| 4678 | |
| 4679 | /* now that we have an index, find the tx_ring struct */ |
| 4680 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4681 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4682 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4683 | tx_ring = vsi->tx_rings[i]; |
| 4684 | break; |
| 4685 | } |
| 4686 | } |
| 4687 | } |
| 4688 | |
| 4689 | if (!tx_ring) |
| 4690 | return; |
| 4691 | |
| 4692 | /* Read interrupt register */ |
| 4693 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4694 | val = rd32(&pf->hw, |
| 4695 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4696 | tx_ring->vsi->base_vector - 1)); |
| 4697 | else |
| 4698 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4699 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4700 | tx_pending = i40e_get_tx_pending(tx_ring); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4701 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4702 | /* Interrupts are disabled and TX pending is non-zero, |
| 4703 | * trigger the SW interrupt (don't wait). Worst case |
| 4704 | * there will be one extra interrupt which may result |
| 4705 | * into not cleaning any queues because queues are cleaned. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4706 | */ |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4707 | if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) |
| 4708 | i40e_force_wb(vsi, tx_ring->q_vector); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4713 | * @pf: pointer to PF struct |
| 4714 | * |
| 4715 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4716 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4717 | * SW interrupt. |
| 4718 | **/ |
| 4719 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4720 | { |
| 4721 | struct net_device *netdev; |
| 4722 | struct i40e_vsi *vsi; |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 4723 | unsigned int i; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4724 | |
| 4725 | /* Only for LAN VSI */ |
| 4726 | vsi = pf->vsi[pf->lan_vsi]; |
| 4727 | |
| 4728 | if (!vsi) |
| 4729 | return; |
| 4730 | |
| 4731 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4732 | if (test_bit(__I40E_VSI_DOWN, vsi->back->state) || |
| 4733 | test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state)) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4734 | return; |
| 4735 | |
| 4736 | /* Make sure type is MAIN VSI */ |
| 4737 | if (vsi->type != I40E_VSI_MAIN) |
| 4738 | return; |
| 4739 | |
| 4740 | netdev = vsi->netdev; |
| 4741 | if (!netdev) |
| 4742 | return; |
| 4743 | |
| 4744 | /* Bail out if netif_carrier is not OK */ |
| 4745 | if (!netif_carrier_ok(netdev)) |
| 4746 | return; |
| 4747 | |
| 4748 | /* Go thru' TX queues for netdev */ |
| 4749 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4750 | struct netdev_queue *q; |
| 4751 | |
| 4752 | q = netdev_get_tx_queue(netdev, i); |
| 4753 | if (q) |
| 4754 | i40e_detect_recover_hung_queue(i, vsi); |
| 4755 | } |
| 4756 | } |
| 4757 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4758 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4759 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4760 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4761 | * |
| 4762 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4763 | * and LAN TC. |
| 4764 | **/ |
| 4765 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4766 | { |
| 4767 | struct i40e_dcb_app_priority_table app; |
| 4768 | struct i40e_hw *hw = &pf->hw; |
| 4769 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4770 | u8 tc, i; |
| 4771 | /* Get the iSCSI APP TLV */ |
| 4772 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4773 | |
| 4774 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4775 | app = dcbcfg->app[i]; |
| 4776 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4777 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4778 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4779 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4780 | break; |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | return enabled_tc; |
| 4785 | } |
| 4786 | |
| 4787 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4788 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4789 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4790 | * |
| 4791 | * Return the number of TCs from given DCBx configuration |
| 4792 | **/ |
| 4793 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4794 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4795 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4796 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4797 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4798 | |
| 4799 | /* Scan the ETS Config Priority Table to find |
| 4800 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4801 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4802 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4803 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4804 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4805 | |
| 4806 | /* Now scan the bitmask to check for |
| 4807 | * contiguous TCs starting with TC0 |
| 4808 | */ |
| 4809 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4810 | if (num_tc & BIT(i)) { |
| 4811 | if (!tc_unused) { |
| 4812 | ret++; |
| 4813 | } else { |
| 4814 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4815 | return 1; |
| 4816 | } |
| 4817 | } else { |
| 4818 | tc_unused = 1; |
| 4819 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4820 | } |
| 4821 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4822 | /* There is always at least TC0 */ |
| 4823 | if (!ret) |
| 4824 | ret = 1; |
| 4825 | |
| 4826 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | /** |
| 4830 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4831 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4832 | * |
| 4833 | * Query the current DCB configuration and return the number of |
| 4834 | * traffic classes enabled from the given DCBX config |
| 4835 | **/ |
| 4836 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4837 | { |
| 4838 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4839 | u8 enabled_tc = 1; |
| 4840 | u8 i; |
| 4841 | |
| 4842 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4843 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4844 | |
| 4845 | return enabled_tc; |
| 4846 | } |
| 4847 | |
| 4848 | /** |
| 4849 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4850 | * @pf: PF being queried |
| 4851 | * |
| 4852 | * Return number of traffic classes enabled for the given PF |
| 4853 | **/ |
| 4854 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4855 | { |
| 4856 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4857 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4858 | u8 num_tc = 0; |
| 4859 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4860 | |
| 4861 | /* If DCB is not enabled then always in single TC */ |
| 4862 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4863 | return 1; |
| 4864 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4865 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4866 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4867 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4868 | |
| 4869 | /* MFP mode return count of enabled TCs for this PF */ |
| 4870 | if (pf->hw.func_caps.iscsi) |
| 4871 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4872 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4873 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4874 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4875 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4876 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4877 | num_tc++; |
| 4878 | } |
| 4879 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4883 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4884 | * @pf: PF being queried |
| 4885 | * |
| 4886 | * Return a bitmap for enabled traffic classes for this PF. |
| 4887 | **/ |
| 4888 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4889 | { |
| 4890 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4891 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4892 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4893 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4894 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4895 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4896 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4897 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4898 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4899 | if (pf->hw.func_caps.iscsi) |
| 4900 | return i40e_get_iscsi_tc_map(pf); |
| 4901 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4902 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | /** |
| 4906 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4907 | * @vsi: the VSI being queried |
| 4908 | * |
| 4909 | * Returns 0 on success, negative value on failure |
| 4910 | **/ |
| 4911 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4912 | { |
| 4913 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4914 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4915 | struct i40e_pf *pf = vsi->back; |
| 4916 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4917 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4918 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4919 | int i; |
| 4920 | |
| 4921 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4922 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4923 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4924 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4925 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4926 | i40e_stat_str(&pf->hw, ret), |
| 4927 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4928 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4932 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4933 | NULL); |
| 4934 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4935 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4936 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4937 | i40e_stat_str(&pf->hw, ret), |
| 4938 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4939 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4943 | dev_info(&pf->pdev->dev, |
| 4944 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4945 | bw_config.tc_valid_bits, |
| 4946 | bw_ets_config.tc_valid_bits); |
| 4947 | /* Still continuing */ |
| 4948 | } |
| 4949 | |
| 4950 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4951 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4952 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4953 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4954 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4955 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4956 | vsi->bw_ets_limit_credits[i] = |
| 4957 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4958 | /* 3 bits out of 4 for each TC */ |
| 4959 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4960 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4961 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4962 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | /** |
| 4966 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4967 | * @vsi: the VSI being configured |
| 4968 | * @enabled_tc: TC bitmap |
| 4969 | * @bw_credits: BW shared credits per TC |
| 4970 | * |
| 4971 | * Returns 0 on success, negative value on failure |
| 4972 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4973 | static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4974 | u8 *bw_share) |
| 4975 | { |
| 4976 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4977 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4978 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4979 | |
| 4980 | bw_data.tc_valid_bits = enabled_tc; |
| 4981 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4982 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4983 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4984 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4985 | NULL); |
| 4986 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4987 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4988 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4989 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4990 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4994 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4995 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4996 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | /** |
| 5000 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 5001 | * @vsi: the VSI being configured |
| 5002 | * @enabled_tc: TC map to be enabled |
| 5003 | * |
| 5004 | **/ |
| 5005 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5006 | { |
| 5007 | struct net_device *netdev = vsi->netdev; |
| 5008 | struct i40e_pf *pf = vsi->back; |
| 5009 | struct i40e_hw *hw = &pf->hw; |
| 5010 | u8 netdev_tc = 0; |
| 5011 | int i; |
| 5012 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 5013 | |
| 5014 | if (!netdev) |
| 5015 | return; |
| 5016 | |
| 5017 | if (!enabled_tc) { |
| 5018 | netdev_reset_tc(netdev); |
| 5019 | return; |
| 5020 | } |
| 5021 | |
| 5022 | /* Set up actual enabled TCs on the VSI */ |
| 5023 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 5024 | return; |
| 5025 | |
| 5026 | /* set per TC queues for the VSI */ |
| 5027 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5028 | /* Only set TC queues for enabled tcs |
| 5029 | * |
| 5030 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 5031 | * enabled_tc bitmap would be 0x00001001; the driver |
| 5032 | * will set the numtc for netdev as 2 that will be |
| 5033 | * referenced by the netdev layer as TC 0 and 1. |
| 5034 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5035 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5036 | netdev_set_tc_queue(netdev, |
| 5037 | vsi->tc_config.tc_info[i].netdev_tc, |
| 5038 | vsi->tc_config.tc_info[i].qcount, |
| 5039 | vsi->tc_config.tc_info[i].qoffset); |
| 5040 | } |
| 5041 | |
| 5042 | /* Assign UP2TC map for the VSI */ |
| 5043 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 5044 | /* Get the actual TC# for the UP */ |
| 5045 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 5046 | /* Get the mapped netdev TC# for the UP */ |
| 5047 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 5048 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | /** |
| 5053 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 5054 | * @vsi: the VSI being configured |
| 5055 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 5056 | **/ |
| 5057 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 5058 | struct i40e_vsi_context *ctxt) |
| 5059 | { |
| 5060 | /* copy just the sections touched not the entire info |
| 5061 | * since not all sections are valid as returned by |
| 5062 | * update vsi params |
| 5063 | */ |
| 5064 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 5065 | memcpy(&vsi->info.queue_mapping, |
| 5066 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 5067 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 5068 | sizeof(vsi->info.tc_mapping)); |
| 5069 | } |
| 5070 | |
| 5071 | /** |
| 5072 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 5073 | * @vsi: VSI to be configured |
| 5074 | * @enabled_tc: TC bitmap |
| 5075 | * |
| 5076 | * This configures a particular VSI for TCs that are mapped to the |
| 5077 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 5078 | * VSIs to configure TC for a particular VSI. |
| 5079 | * |
| 5080 | * NOTE: |
| 5081 | * It is expected that the VSI queues have been quisced before calling |
| 5082 | * this function. |
| 5083 | **/ |
| 5084 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5085 | { |
| 5086 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 5087 | struct i40e_vsi_context ctxt; |
| 5088 | int ret = 0; |
| 5089 | int i; |
| 5090 | |
| 5091 | /* Check if enabled_tc is same as existing or new TCs */ |
| 5092 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 5093 | return ret; |
| 5094 | |
| 5095 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 5096 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5097 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5098 | bw_share[i] = 1; |
| 5099 | } |
| 5100 | |
| 5101 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 5102 | if (ret) { |
| 5103 | dev_info(&vsi->back->pdev->dev, |
| 5104 | "Failed configuring TC map %d for VSI %d\n", |
| 5105 | enabled_tc, vsi->seid); |
| 5106 | goto out; |
| 5107 | } |
| 5108 | |
| 5109 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 5110 | ctxt.seid = vsi->seid; |
| 5111 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 5112 | ctxt.vf_num = 0; |
| 5113 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5114 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5115 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 5116 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5117 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 5118 | ctxt.info.valid_sections |= |
| 5119 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 5120 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 5121 | } |
| 5122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5123 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 5124 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 5125 | if (ret) { |
| 5126 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5127 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 5128 | i40e_stat_str(&vsi->back->hw, ret), |
| 5129 | i40e_aq_str(&vsi->back->hw, |
| 5130 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5131 | goto out; |
| 5132 | } |
| 5133 | /* update the local VSI info with updated queue map */ |
| 5134 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 5135 | vsi->info.valid_sections = 0; |
| 5136 | |
| 5137 | /* Update current VSI BW information */ |
| 5138 | ret = i40e_vsi_get_bw_info(vsi); |
| 5139 | if (ret) { |
| 5140 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5141 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5142 | i40e_stat_str(&vsi->back->hw, ret), |
| 5143 | i40e_aq_str(&vsi->back->hw, |
| 5144 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5145 | goto out; |
| 5146 | } |
| 5147 | |
| 5148 | /* Update the netdev TC setup */ |
| 5149 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5150 | out: |
| 5151 | return ret; |
| 5152 | } |
| 5153 | |
| 5154 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5155 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 5156 | * @veb: given VEB |
| 5157 | * @enabled_tc: TC bitmap |
| 5158 | * |
| 5159 | * Configures given TC bitmap for VEB (switching) element |
| 5160 | **/ |
| 5161 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 5162 | { |
| 5163 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 5164 | struct i40e_pf *pf = veb->pf; |
| 5165 | int ret = 0; |
| 5166 | int i; |
| 5167 | |
| 5168 | /* No TCs or already enabled TCs just return */ |
| 5169 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 5170 | return ret; |
| 5171 | |
| 5172 | bw_data.tc_valid_bits = enabled_tc; |
| 5173 | /* bw_data.absolute_credits is not set (relative) */ |
| 5174 | |
| 5175 | /* Enable ETS TCs with equal BW Share for now */ |
| 5176 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5177 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5178 | bw_data.tc_bw_share_credits[i] = 1; |
| 5179 | } |
| 5180 | |
| 5181 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 5182 | &bw_data, NULL); |
| 5183 | if (ret) { |
| 5184 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5185 | "VEB bw config failed, err %s aq_err %s\n", |
| 5186 | i40e_stat_str(&pf->hw, ret), |
| 5187 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5188 | goto out; |
| 5189 | } |
| 5190 | |
| 5191 | /* Update the BW information */ |
| 5192 | ret = i40e_veb_get_bw_info(veb); |
| 5193 | if (ret) { |
| 5194 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5195 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5196 | i40e_stat_str(&pf->hw, ret), |
| 5197 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | out: |
| 5201 | return ret; |
| 5202 | } |
| 5203 | |
| 5204 | #ifdef CONFIG_I40E_DCB |
| 5205 | /** |
| 5206 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5207 | * @pf: PF struct |
| 5208 | * |
| 5209 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5210 | * the caller would've quiesce all the VSIs before calling |
| 5211 | * this function |
| 5212 | **/ |
| 5213 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5214 | { |
| 5215 | u8 tc_map = 0; |
| 5216 | int ret; |
| 5217 | u8 v; |
| 5218 | |
| 5219 | /* Enable the TCs available on PF to all VEBs */ |
| 5220 | tc_map = i40e_pf_get_tc_map(pf); |
| 5221 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5222 | if (!pf->veb[v]) |
| 5223 | continue; |
| 5224 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5225 | if (ret) { |
| 5226 | dev_info(&pf->pdev->dev, |
| 5227 | "Failed configuring TC for VEB seid=%d\n", |
| 5228 | pf->veb[v]->seid); |
| 5229 | /* Will try to configure as many components */ |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5234 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5235 | if (!pf->vsi[v]) |
| 5236 | continue; |
| 5237 | |
| 5238 | /* - Enable all TCs for the LAN VSI |
| 5239 | * - For all others keep them at TC0 for now |
| 5240 | */ |
| 5241 | if (v == pf->lan_vsi) |
| 5242 | tc_map = i40e_pf_get_tc_map(pf); |
| 5243 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5244 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5245 | |
| 5246 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5247 | if (ret) { |
| 5248 | dev_info(&pf->pdev->dev, |
| 5249 | "Failed configuring TC for VSI seid=%d\n", |
| 5250 | pf->vsi[v]->seid); |
| 5251 | /* Will try to configure as many components */ |
| 5252 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5253 | /* Re-configure VSI vectors based on updated TC map */ |
| 5254 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5255 | if (pf->vsi[v]->netdev) |
| 5256 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5257 | } |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5262 | * i40e_resume_port_tx - Resume port Tx |
| 5263 | * @pf: PF struct |
| 5264 | * |
| 5265 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5266 | * resume. |
| 5267 | **/ |
| 5268 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5269 | { |
| 5270 | struct i40e_hw *hw = &pf->hw; |
| 5271 | int ret; |
| 5272 | |
| 5273 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5274 | if (ret) { |
| 5275 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5276 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5277 | i40e_stat_str(&pf->hw, ret), |
| 5278 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5279 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5280 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5281 | i40e_service_event_schedule(pf); |
| 5282 | } |
| 5283 | |
| 5284 | return ret; |
| 5285 | } |
| 5286 | |
| 5287 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5288 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5289 | * @pf: PF being configured |
| 5290 | * |
| 5291 | * Query the current DCB configuration and cache it |
| 5292 | * in the hardware structure |
| 5293 | **/ |
| 5294 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5295 | { |
| 5296 | struct i40e_hw *hw = &pf->hw; |
| 5297 | int err = 0; |
| 5298 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5299 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 5300 | if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5301 | goto out; |
| 5302 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5303 | /* Get the initial DCB configuration */ |
| 5304 | err = i40e_init_dcb(hw); |
| 5305 | if (!err) { |
| 5306 | /* Device/Function is not DCBX capable */ |
| 5307 | if ((!hw->func_caps.dcb) || |
| 5308 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5309 | dev_info(&pf->pdev->dev, |
| 5310 | "DCBX offload is not supported or is disabled for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5311 | } else { |
| 5312 | /* When status is not DISABLED then DCBX in FW */ |
| 5313 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5314 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5315 | |
| 5316 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5317 | /* Enable DCB tagging only when more than one TC |
| 5318 | * or explicitly disable if only one TC |
| 5319 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5320 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5321 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5322 | else |
| 5323 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5324 | dev_dbg(&pf->pdev->dev, |
| 5325 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5326 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5327 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5328 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5329 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5330 | i40e_stat_str(&pf->hw, err), |
| 5331 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | out: |
| 5335 | return err; |
| 5336 | } |
| 5337 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5338 | #define SPEED_SIZE 14 |
| 5339 | #define FC_SIZE 8 |
| 5340 | /** |
| 5341 | * i40e_print_link_message - print link up or down |
| 5342 | * @vsi: the VSI for which link needs a message |
| 5343 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5344 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5345 | { |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5346 | enum i40e_aq_link_speed new_speed; |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5347 | char *speed = "Unknown"; |
| 5348 | char *fc = "Unknown"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5349 | char *fec = ""; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5350 | char *req_fec = ""; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5351 | char *an = ""; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5352 | |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5353 | new_speed = vsi->back->hw.phy.link_info.link_speed; |
| 5354 | |
| 5355 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5356 | return; |
| 5357 | vsi->current_isup = isup; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5358 | vsi->current_speed = new_speed; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5359 | if (!isup) { |
| 5360 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5361 | return; |
| 5362 | } |
| 5363 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5364 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5365 | * least 10GB |
| 5366 | */ |
| 5367 | if (vsi->back->hw.func_caps.npar_enable && |
| 5368 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5369 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5370 | netdev_warn(vsi->netdev, |
| 5371 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5372 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5373 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5374 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5375 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5376 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5377 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5378 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5379 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 5380 | case I40E_LINK_SPEED_25GB: |
| 5381 | speed = "25 G"; |
| 5382 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5383 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5384 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5385 | break; |
| 5386 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5387 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5388 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5389 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5390 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5391 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5392 | default: |
| 5393 | break; |
| 5394 | } |
| 5395 | |
| 5396 | switch (vsi->back->hw.fc.current_mode) { |
| 5397 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5398 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5399 | break; |
| 5400 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5401 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5404 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5405 | break; |
| 5406 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5407 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5408 | break; |
| 5409 | } |
| 5410 | |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5411 | if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5412 | req_fec = ", Requested FEC: None"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5413 | fec = ", FEC: None"; |
| 5414 | an = ", Autoneg: False"; |
| 5415 | |
| 5416 | if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) |
| 5417 | an = ", Autoneg: True"; |
| 5418 | |
| 5419 | if (vsi->back->hw.phy.link_info.fec_info & |
| 5420 | I40E_AQ_CONFIG_FEC_KR_ENA) |
| 5421 | fec = ", FEC: CL74 FC-FEC/BASE-R"; |
| 5422 | else if (vsi->back->hw.phy.link_info.fec_info & |
| 5423 | I40E_AQ_CONFIG_FEC_RS_ENA) |
| 5424 | fec = ", FEC: CL108 RS-FEC"; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5425 | |
| 5426 | /* 'CL108 RS-FEC' should be displayed when RS is requested, or |
| 5427 | * both RS and FC are requested |
| 5428 | */ |
| 5429 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 5430 | (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) { |
| 5431 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 5432 | I40E_AQ_REQUEST_FEC_RS) |
| 5433 | req_fec = ", Requested FEC: CL108 RS-FEC"; |
| 5434 | else |
| 5435 | req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R"; |
| 5436 | } |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5437 | } |
| 5438 | |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5439 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n", |
| 5440 | speed, req_fec, fec, an, fc); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5441 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5442 | |
| 5443 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5444 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5445 | * @vsi: the VSI being configured |
| 5446 | **/ |
| 5447 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5448 | { |
| 5449 | struct i40e_pf *pf = vsi->back; |
| 5450 | int err; |
| 5451 | |
| 5452 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5453 | i40e_vsi_configure_msix(vsi); |
| 5454 | else |
| 5455 | i40e_configure_msi_and_legacy(vsi); |
| 5456 | |
| 5457 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5458 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5459 | if (err) |
| 5460 | return err; |
| 5461 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5462 | clear_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5463 | i40e_napi_enable_all(vsi); |
| 5464 | i40e_vsi_enable_irq(vsi); |
| 5465 | |
| 5466 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5467 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5468 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5469 | netif_tx_start_all_queues(vsi->netdev); |
| 5470 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5471 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5472 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5473 | /* need to check for qualified module here*/ |
| 5474 | if ((pf->hw.phy.link_info.link_info & |
| 5475 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5476 | (!(pf->hw.phy.link_info.an_info & |
| 5477 | I40E_AQ_QUALIFIED_MODULE))) |
| 5478 | netdev_err(vsi->netdev, |
| 5479 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5480 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5481 | |
| 5482 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5483 | if (vsi->type == I40E_VSI_FDIR) { |
| 5484 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5485 | pf->fd_add_err = 0; |
| 5486 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5487 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5488 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5489 | |
| 5490 | /* On the next run of the service_task, notify any clients of the new |
| 5491 | * opened netdev |
| 5492 | */ |
| 5493 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5494 | i40e_service_event_schedule(pf); |
| 5495 | |
| 5496 | return 0; |
| 5497 | } |
| 5498 | |
| 5499 | /** |
| 5500 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5501 | * @vsi: the VSI being configured |
| 5502 | * |
| 5503 | * Rebuild the ring structs after some configuration |
| 5504 | * has changed, e.g. MTU size. |
| 5505 | **/ |
| 5506 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5507 | { |
| 5508 | struct i40e_pf *pf = vsi->back; |
| 5509 | |
| 5510 | WARN_ON(in_interrupt()); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5511 | while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5512 | usleep_range(1000, 2000); |
| 5513 | i40e_down(vsi); |
| 5514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5515 | i40e_up(vsi); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5516 | clear_bit(__I40E_CONFIG_BUSY, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * i40e_up - Bring the connection back up after being down |
| 5521 | * @vsi: the VSI being configured |
| 5522 | **/ |
| 5523 | int i40e_up(struct i40e_vsi *vsi) |
| 5524 | { |
| 5525 | int err; |
| 5526 | |
| 5527 | err = i40e_vsi_configure(vsi); |
| 5528 | if (!err) |
| 5529 | err = i40e_up_complete(vsi); |
| 5530 | |
| 5531 | return err; |
| 5532 | } |
| 5533 | |
| 5534 | /** |
| 5535 | * i40e_down - Shutdown the connection processing |
| 5536 | * @vsi: the VSI being stopped |
| 5537 | **/ |
| 5538 | void i40e_down(struct i40e_vsi *vsi) |
| 5539 | { |
| 5540 | int i; |
| 5541 | |
| 5542 | /* It is assumed that the caller of this function |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5543 | * sets the vsi->state __I40E_VSI_DOWN bit. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5544 | */ |
| 5545 | if (vsi->netdev) { |
| 5546 | netif_carrier_off(vsi->netdev); |
| 5547 | netif_tx_disable(vsi->netdev); |
| 5548 | } |
| 5549 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5550 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5551 | i40e_napi_disable_all(vsi); |
| 5552 | |
| 5553 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5554 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 5555 | if (i40e_enabled_xdp_vsi(vsi)) |
| 5556 | i40e_clean_tx_ring(vsi->xdp_rings[i]); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5557 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5558 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5559 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | /** |
| 5563 | * i40e_setup_tc - configure multiple traffic classes |
| 5564 | * @netdev: net device to configure |
| 5565 | * @tc: number of traffic classes to enable |
| 5566 | **/ |
| 5567 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5568 | { |
| 5569 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5570 | struct i40e_vsi *vsi = np->vsi; |
| 5571 | struct i40e_pf *pf = vsi->back; |
| 5572 | u8 enabled_tc = 0; |
| 5573 | int ret = -EINVAL; |
| 5574 | int i; |
| 5575 | |
| 5576 | /* Check if DCB enabled to continue */ |
| 5577 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5578 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5579 | goto exit; |
| 5580 | } |
| 5581 | |
| 5582 | /* Check if MFP enabled */ |
| 5583 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5584 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5585 | goto exit; |
| 5586 | } |
| 5587 | |
| 5588 | /* Check whether tc count is within enabled limit */ |
| 5589 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5590 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5591 | goto exit; |
| 5592 | } |
| 5593 | |
| 5594 | /* Generate TC map for number of tc requested */ |
| 5595 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5596 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5597 | |
| 5598 | /* Requesting same TC configuration as already enabled */ |
| 5599 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5600 | return 0; |
| 5601 | |
| 5602 | /* Quiesce VSI queues */ |
| 5603 | i40e_quiesce_vsi(vsi); |
| 5604 | |
| 5605 | /* Configure VSI for enabled TCs */ |
| 5606 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5607 | if (ret) { |
| 5608 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5609 | vsi->seid); |
| 5610 | goto exit; |
| 5611 | } |
| 5612 | |
| 5613 | /* Unquiesce VSI */ |
| 5614 | i40e_unquiesce_vsi(vsi); |
| 5615 | |
| 5616 | exit: |
| 5617 | return ret; |
| 5618 | } |
| 5619 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 5620 | static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type, |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5621 | void *type_data) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5622 | { |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5623 | struct tc_mqprio_qopt *mqprio = type_data; |
| 5624 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 5625 | if (type != TC_SETUP_MQPRIO) |
Jiri Pirko | 38cf042 | 2017-08-07 10:15:31 +0200 | [diff] [blame] | 5626 | return -EOPNOTSUPP; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5627 | |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5628 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5629 | |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5630 | return i40e_setup_tc(netdev, mqprio->num_tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5631 | } |
| 5632 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5633 | /** |
| 5634 | * i40e_open - Called when a network interface is made active |
| 5635 | * @netdev: network interface device structure |
| 5636 | * |
| 5637 | * The open entry point is called when a network interface is made |
| 5638 | * active by the system (IFF_UP). At this point all resources needed |
| 5639 | * for transmit and receive operations are allocated, the interrupt |
| 5640 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5641 | * enabled, and the stack is notified that the interface is ready. |
| 5642 | * |
| 5643 | * Returns 0 on success, negative value on failure |
| 5644 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5645 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5646 | { |
| 5647 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5648 | struct i40e_vsi *vsi = np->vsi; |
| 5649 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5650 | int err; |
| 5651 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5652 | /* disallow open during test or if eeprom is broken */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5653 | if (test_bit(__I40E_TESTING, pf->state) || |
| 5654 | test_bit(__I40E_BAD_EEPROM, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5655 | return -EBUSY; |
| 5656 | |
| 5657 | netif_carrier_off(netdev); |
| 5658 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5659 | err = i40e_vsi_open(vsi); |
| 5660 | if (err) |
| 5661 | return err; |
| 5662 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5663 | /* configure global TSO hardware offload settings */ |
| 5664 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5665 | TCP_FLAG_FIN) >> 16); |
| 5666 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5667 | TCP_FLAG_FIN | |
| 5668 | TCP_FLAG_CWR) >> 16); |
| 5669 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5670 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5671 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5672 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5673 | return 0; |
| 5674 | } |
| 5675 | |
| 5676 | /** |
| 5677 | * i40e_vsi_open - |
| 5678 | * @vsi: the VSI to open |
| 5679 | * |
| 5680 | * Finish initialization of the VSI. |
| 5681 | * |
| 5682 | * Returns 0 on success, negative value on failure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5683 | * |
| 5684 | * Note: expects to be called while under rtnl_lock() |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5685 | **/ |
| 5686 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5687 | { |
| 5688 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5689 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5690 | int err; |
| 5691 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5692 | /* allocate descriptors */ |
| 5693 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5694 | if (err) |
| 5695 | goto err_setup_tx; |
| 5696 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5697 | if (err) |
| 5698 | goto err_setup_rx; |
| 5699 | |
| 5700 | err = i40e_vsi_configure(vsi); |
| 5701 | if (err) |
| 5702 | goto err_setup_rx; |
| 5703 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5704 | if (vsi->netdev) { |
| 5705 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5706 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5707 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5708 | if (err) |
| 5709 | goto err_setup_rx; |
| 5710 | |
| 5711 | /* Notify the stack of the actual queue counts. */ |
| 5712 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5713 | vsi->num_queue_pairs); |
| 5714 | if (err) |
| 5715 | goto err_set_queues; |
| 5716 | |
| 5717 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5718 | vsi->num_queue_pairs); |
| 5719 | if (err) |
| 5720 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5721 | |
| 5722 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5723 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5724 | dev_driver_string(&pf->pdev->dev), |
| 5725 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5726 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5727 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5728 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5729 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5730 | goto err_setup_rx; |
| 5731 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5732 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5733 | err = i40e_up_complete(vsi); |
| 5734 | if (err) |
| 5735 | goto err_up_complete; |
| 5736 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5737 | return 0; |
| 5738 | |
| 5739 | err_up_complete: |
| 5740 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5741 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5742 | i40e_vsi_free_irq(vsi); |
| 5743 | err_setup_rx: |
| 5744 | i40e_vsi_free_rx_resources(vsi); |
| 5745 | err_setup_tx: |
| 5746 | i40e_vsi_free_tx_resources(vsi); |
| 5747 | if (vsi == pf->vsi[pf->lan_vsi]) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5748 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5749 | |
| 5750 | return err; |
| 5751 | } |
| 5752 | |
| 5753 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5754 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5755 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5756 | * |
| 5757 | * This function destroys the hlist where all the Flow Director |
| 5758 | * filters were saved. |
| 5759 | **/ |
| 5760 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5761 | { |
| 5762 | struct i40e_fdir_filter *filter; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5763 | struct i40e_flex_pit *pit_entry, *tmp; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5764 | struct hlist_node *node2; |
| 5765 | |
| 5766 | hlist_for_each_entry_safe(filter, node2, |
| 5767 | &pf->fdir_filter_list, fdir_node) { |
| 5768 | hlist_del(&filter->fdir_node); |
| 5769 | kfree(filter); |
| 5770 | } |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5771 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5772 | list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) { |
| 5773 | list_del(&pit_entry->list); |
| 5774 | kfree(pit_entry); |
| 5775 | } |
| 5776 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 5777 | |
| 5778 | list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) { |
| 5779 | list_del(&pit_entry->list); |
| 5780 | kfree(pit_entry); |
| 5781 | } |
| 5782 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 5783 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5784 | pf->fdir_pf_active_filters = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5785 | pf->fd_tcp4_filter_cnt = 0; |
| 5786 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 5787 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5788 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 3bcee1e | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5789 | |
| 5790 | /* Reprogram the default input set for TCP/IPv4 */ |
| 5791 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP, |
| 5792 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5793 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5794 | |
| 5795 | /* Reprogram the default input set for UDP/IPv4 */ |
| 5796 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP, |
| 5797 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5798 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5799 | |
| 5800 | /* Reprogram the default input set for SCTP/IPv4 */ |
| 5801 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP, |
| 5802 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5803 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5804 | |
| 5805 | /* Reprogram the default input set for Other/IPv4 */ |
| 5806 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER, |
| 5807 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5811 | * i40e_close - Disables a network interface |
| 5812 | * @netdev: network interface device structure |
| 5813 | * |
| 5814 | * The close entry point is called when an interface is de-activated |
| 5815 | * by the OS. The hardware is still under the driver's control, but |
| 5816 | * this netdev interface is disabled. |
| 5817 | * |
| 5818 | * Returns 0, this is not allowed to fail |
| 5819 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5820 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5821 | { |
| 5822 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5823 | struct i40e_vsi *vsi = np->vsi; |
| 5824 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5825 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5826 | |
| 5827 | return 0; |
| 5828 | } |
| 5829 | |
| 5830 | /** |
| 5831 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5832 | * @pf: board private structure |
| 5833 | * @reset_flags: which reset is requested |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5834 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 5835 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5836 | * |
| 5837 | * The essential difference in resets is that the PF Reset |
| 5838 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5839 | * firmware, and doesn't bother the other PFs on the chip. |
| 5840 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5841 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5842 | { |
| 5843 | u32 val; |
| 5844 | |
| 5845 | WARN_ON(in_interrupt()); |
| 5846 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5847 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5848 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5849 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5850 | |
| 5851 | /* Request a Global Reset |
| 5852 | * |
| 5853 | * This will start the chip's countdown to the actual full |
| 5854 | * chip reset event, and a warning interrupt to be sent |
| 5855 | * to all PFs, including the requestor. Our handler |
| 5856 | * for the warning interrupt will deal with the shutdown |
| 5857 | * and recovery of the switch setup. |
| 5858 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5859 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5860 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5861 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5862 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5863 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5864 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5865 | |
| 5866 | /* Request a Core Reset |
| 5867 | * |
| 5868 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5869 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5870 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5871 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5872 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5873 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5874 | i40e_flush(&pf->hw); |
| 5875 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5876 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5877 | |
| 5878 | /* Request a PF Reset |
| 5879 | * |
| 5880 | * Resets only the PF-specific registers |
| 5881 | * |
| 5882 | * This goes directly to the tear-down and rebuild of |
| 5883 | * the switch, since we need to do all the recovery as |
| 5884 | * for the Core Reset. |
| 5885 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5886 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5887 | i40e_handle_reset_warning(pf, lock_acquired); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5888 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5889 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5890 | int v; |
| 5891 | |
| 5892 | /* Find the VSI(s) that requested a re-init */ |
| 5893 | dev_info(&pf->pdev->dev, |
| 5894 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5895 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5896 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5897 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5898 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5899 | test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5900 | vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5901 | i40e_vsi_reinit_locked(pf->vsi[v]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5902 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5903 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5904 | int v; |
| 5905 | |
| 5906 | /* Find the VSI(s) that needs to be brought down */ |
| 5907 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5908 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5909 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5910 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5911 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5912 | test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5913 | vsi->state)) { |
| 5914 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5915 | i40e_down(vsi); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5916 | } |
| 5917 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5918 | } else { |
| 5919 | dev_info(&pf->pdev->dev, |
| 5920 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5921 | } |
| 5922 | } |
| 5923 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5924 | #ifdef CONFIG_I40E_DCB |
| 5925 | /** |
| 5926 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5927 | * @pf: board private structure |
| 5928 | * @old_cfg: current DCB config |
| 5929 | * @new_cfg: new DCB config |
| 5930 | **/ |
| 5931 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5932 | struct i40e_dcbx_config *old_cfg, |
| 5933 | struct i40e_dcbx_config *new_cfg) |
| 5934 | { |
| 5935 | bool need_reconfig = false; |
| 5936 | |
| 5937 | /* Check if ETS configuration has changed */ |
| 5938 | if (memcmp(&new_cfg->etscfg, |
| 5939 | &old_cfg->etscfg, |
| 5940 | sizeof(new_cfg->etscfg))) { |
| 5941 | /* If Priority Table has changed reconfig is needed */ |
| 5942 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5943 | &old_cfg->etscfg.prioritytable, |
| 5944 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5945 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5946 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5950 | &old_cfg->etscfg.tcbwtable, |
| 5951 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5952 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5953 | |
| 5954 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5955 | &old_cfg->etscfg.tsatable, |
| 5956 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5957 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | /* Check if PFC configuration has changed */ |
| 5961 | if (memcmp(&new_cfg->pfc, |
| 5962 | &old_cfg->pfc, |
| 5963 | sizeof(new_cfg->pfc))) { |
| 5964 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5965 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | /* Check if APP Table has changed */ |
| 5969 | if (memcmp(&new_cfg->app, |
| 5970 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5971 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5972 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5973 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5974 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5975 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5976 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5977 | return need_reconfig; |
| 5978 | } |
| 5979 | |
| 5980 | /** |
| 5981 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5982 | * @pf: board private structure |
| 5983 | * @e: event info posted on ARQ |
| 5984 | **/ |
| 5985 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5986 | struct i40e_arq_event_info *e) |
| 5987 | { |
| 5988 | struct i40e_aqc_lldp_get_mib *mib = |
| 5989 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5990 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5991 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5992 | bool need_reconfig = false; |
| 5993 | int ret = 0; |
| 5994 | u8 type; |
| 5995 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5996 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5997 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5998 | return ret; |
| 5999 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6000 | /* Ignore if event is not for Nearest Bridge */ |
| 6001 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 6002 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 6003 | dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6004 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 6005 | return ret; |
| 6006 | |
| 6007 | /* Check MIB Type and return if event for Remote MIB update */ |
| 6008 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6009 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 6010 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6011 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 6012 | /* Update the remote cached instance and return */ |
| 6013 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 6014 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 6015 | &hw->remote_dcbx_config); |
| 6016 | goto exit; |
| 6017 | } |
| 6018 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6019 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 6020 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6021 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6022 | /* Reset the old DCBx configuration data */ |
| 6023 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6024 | /* Get updated DCBX data from firmware */ |
| 6025 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6026 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6027 | dev_info(&pf->pdev->dev, |
| 6028 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 6029 | i40e_stat_str(&pf->hw, ret), |
| 6030 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6031 | goto exit; |
| 6032 | } |
| 6033 | |
| 6034 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6035 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 6036 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6037 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6038 | goto exit; |
| 6039 | } |
| 6040 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6041 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 6042 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6043 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6044 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6045 | |
| 6046 | if (!need_reconfig) |
| 6047 | goto exit; |
| 6048 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6049 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6050 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6051 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 6052 | else |
| 6053 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 6054 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6055 | set_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6056 | /* Reconfiguration needed quiesce all VSIs */ |
| 6057 | i40e_pf_quiesce_all_vsi(pf); |
| 6058 | |
| 6059 | /* Changes in configuration update VEB/VSI */ |
| 6060 | i40e_dcb_reconfigure(pf); |
| 6061 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6062 | ret = i40e_resume_port_tx(pf); |
| 6063 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6064 | clear_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6065 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 6066 | if (ret) |
| 6067 | goto exit; |
| 6068 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 6069 | /* Wait for the PF's queues to be disabled */ |
| 6070 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6071 | if (ret) { |
| 6072 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6073 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6074 | i40e_service_event_schedule(pf); |
| 6075 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6076 | i40e_pf_unquiesce_all_vsi(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 6077 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 6078 | I40E_FLAG_CLIENT_L2_CHANGE); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6081 | exit: |
| 6082 | return ret; |
| 6083 | } |
| 6084 | #endif /* CONFIG_I40E_DCB */ |
| 6085 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6086 | /** |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6087 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 6088 | * @pf: board private structure |
| 6089 | * @reset_flags: which reset is requested |
| 6090 | * |
| 6091 | **/ |
| 6092 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 6093 | { |
| 6094 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6095 | i40e_do_reset(pf, reset_flags, true); |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6096 | rtnl_unlock(); |
| 6097 | } |
| 6098 | |
| 6099 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6100 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 6101 | * @pf: board private structure |
| 6102 | * @e: event info posted on ARQ |
| 6103 | * |
| 6104 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 6105 | * and VF queues |
| 6106 | **/ |
| 6107 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 6108 | struct i40e_arq_event_info *e) |
| 6109 | { |
| 6110 | struct i40e_aqc_lan_overflow *data = |
| 6111 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 6112 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 6113 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 6114 | struct i40e_hw *hw = &pf->hw; |
| 6115 | struct i40e_vf *vf; |
| 6116 | u16 vf_id; |
| 6117 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6118 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 6119 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6120 | |
| 6121 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 6122 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 6123 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 6124 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 6125 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 6126 | vf_id -= hw->func_caps.vf_base_id; |
| 6127 | vf = &pf->vf[vf_id]; |
| 6128 | i40e_vc_notify_vf_reset(vf); |
| 6129 | /* Allow VF to process pending reset notification */ |
| 6130 | msleep(20); |
| 6131 | i40e_reset_vf(vf, false); |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6136 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 6137 | * @pf: board private structure |
| 6138 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6139 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6140 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6141 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6142 | |
| 6143 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6144 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 6145 | return fcnt_prog; |
| 6146 | } |
| 6147 | |
| 6148 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6149 | * i40e_get_current_fd_count - Get total FD filters programmed for this PF |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6150 | * @pf: board private structure |
| 6151 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6152 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6153 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6154 | u32 val, fcnt_prog; |
| 6155 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6156 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6157 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 6158 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 6159 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 6160 | return fcnt_prog; |
| 6161 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6162 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6163 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6164 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 6165 | * @pf: board private structure |
| 6166 | **/ |
| 6167 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 6168 | { |
| 6169 | u32 val, fcnt_prog; |
| 6170 | |
| 6171 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 6172 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 6173 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 6174 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 6175 | return fcnt_prog; |
| 6176 | } |
| 6177 | |
| 6178 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6179 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 6180 | * @pf: board private structure |
| 6181 | **/ |
| 6182 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 6183 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6184 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6185 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6186 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6187 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6188 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6189 | return; |
| 6190 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6191 | /* Check if we have enough room to re-enable FDir SB capability. */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6192 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6193 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6194 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 6195 | (pf->fd_add_err == 0) || |
| 6196 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6197 | if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) { |
| 6198 | pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED; |
| 6199 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 6200 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6201 | dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6202 | } |
| 6203 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6204 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6205 | /* We should wait for even more space before re-enabling ATR. |
| 6206 | * Additionally, we cannot enable ATR as long as we still have TCP SB |
| 6207 | * rules active. |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6208 | */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6209 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) && |
| 6210 | (pf->fd_tcp4_filter_cnt == 0)) { |
| 6211 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 6212 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 6213 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 6214 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6215 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6216 | } |
| 6217 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6218 | |
| 6219 | /* if hw had a problem adding a filter, delete it */ |
| 6220 | if (pf->fd_inv > 0) { |
| 6221 | hlist_for_each_entry_safe(filter, node, |
| 6222 | &pf->fdir_filter_list, fdir_node) { |
| 6223 | if (filter->fd_id == pf->fd_inv) { |
| 6224 | hlist_del(&filter->fdir_node); |
| 6225 | kfree(filter); |
| 6226 | pf->fdir_pf_active_filters--; |
| 6227 | } |
| 6228 | } |
| 6229 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6230 | } |
| 6231 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6232 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6233 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6234 | /** |
| 6235 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6236 | * @pf: board private structure |
| 6237 | **/ |
| 6238 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6239 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6240 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6241 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6242 | bool disable_atr = false; |
| 6243 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6244 | int reg; |
| 6245 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6246 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6247 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6248 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6249 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6250 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6251 | * should not re-enable ATR for some time. |
| 6252 | */ |
| 6253 | min_flush_time = pf->fd_flush_timestamp + |
| 6254 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6255 | fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6256 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6257 | if (!(time_after(jiffies, min_flush_time)) && |
| 6258 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6259 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6260 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6261 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6262 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6263 | |
| 6264 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6265 | pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6266 | /* flush all filters */ |
| 6267 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6268 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6269 | i40e_flush(&pf->hw); |
| 6270 | pf->fd_flush_cnt++; |
| 6271 | pf->fd_add_err = 0; |
| 6272 | do { |
| 6273 | /* Check FD flush status every 5-6msec */ |
| 6274 | usleep_range(5000, 6000); |
| 6275 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6276 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6277 | break; |
| 6278 | } while (flush_wait_retry--); |
| 6279 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6280 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6281 | } else { |
| 6282 | /* replay sideband filters */ |
| 6283 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6284 | if (!disable_atr && !pf->fd_tcp4_filter_cnt) |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6285 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6286 | clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state); |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6287 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6288 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6289 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | /** |
| 6293 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6294 | * @pf: board private structure |
| 6295 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6296 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6297 | { |
| 6298 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6299 | } |
| 6300 | |
| 6301 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6302 | * being applied really fast; before we see the first |
| 6303 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6304 | * reacting will make sure we don't cause flush too often. |
| 6305 | */ |
| 6306 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6307 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6308 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6309 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6310 | * @pf: board private structure |
| 6311 | **/ |
| 6312 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6313 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6314 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6315 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6316 | if (test_bit(__I40E_DOWN, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6317 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6318 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6319 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6320 | i40e_fdir_flush_and_replay(pf); |
| 6321 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6322 | i40e_fdir_check_and_reenable(pf); |
| 6323 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * i40e_vsi_link_event - notify VSI of a link event |
| 6328 | * @vsi: vsi to be notified |
| 6329 | * @link_up: link up or down |
| 6330 | **/ |
| 6331 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6332 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6333 | if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6334 | return; |
| 6335 | |
| 6336 | switch (vsi->type) { |
| 6337 | case I40E_VSI_MAIN: |
| 6338 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6339 | break; |
| 6340 | |
| 6341 | if (link_up) { |
| 6342 | netif_carrier_on(vsi->netdev); |
| 6343 | netif_tx_wake_all_queues(vsi->netdev); |
| 6344 | } else { |
| 6345 | netif_carrier_off(vsi->netdev); |
| 6346 | netif_tx_stop_all_queues(vsi->netdev); |
| 6347 | } |
| 6348 | break; |
| 6349 | |
| 6350 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6351 | case I40E_VSI_VMDQ2: |
| 6352 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6353 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6354 | case I40E_VSI_MIRROR: |
| 6355 | default: |
| 6356 | /* there is no notification for other VSIs */ |
| 6357 | break; |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | /** |
| 6362 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6363 | * @veb: veb to be notified |
| 6364 | * @link_up: link up or down |
| 6365 | **/ |
| 6366 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6367 | { |
| 6368 | struct i40e_pf *pf; |
| 6369 | int i; |
| 6370 | |
| 6371 | if (!veb || !veb->pf) |
| 6372 | return; |
| 6373 | pf = veb->pf; |
| 6374 | |
| 6375 | /* depth first... */ |
| 6376 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6377 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6378 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6379 | |
| 6380 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6381 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6382 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6383 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6384 | } |
| 6385 | |
| 6386 | /** |
| 6387 | * i40e_link_event - Update netif_carrier status |
| 6388 | * @pf: board private structure |
| 6389 | **/ |
| 6390 | static void i40e_link_event(struct i40e_pf *pf) |
| 6391 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6392 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6393 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6394 | i40e_status status; |
| 6395 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6396 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6397 | /* save off old link status information */ |
| 6398 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6399 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6400 | /* set this to force the get_link_status call to refresh state */ |
| 6401 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6402 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6403 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6404 | |
| 6405 | status = i40e_get_link_status(&pf->hw, &new_link); |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6406 | |
| 6407 | /* On success, disable temp link polling */ |
| 6408 | if (status == I40E_SUCCESS) { |
| 6409 | if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING) |
| 6410 | pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING; |
| 6411 | } else { |
| 6412 | /* Enable link polling temporarily until i40e_get_link_status |
| 6413 | * returns I40E_SUCCESS |
| 6414 | */ |
| 6415 | pf->flags |= I40E_FLAG_TEMP_LINK_POLLING; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6416 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6417 | status); |
| 6418 | return; |
| 6419 | } |
| 6420 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6421 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6422 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6423 | |
| 6424 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6425 | new_link_speed == old_link_speed && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6426 | (test_bit(__I40E_VSI_DOWN, vsi->state) || |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6427 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6428 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6429 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6430 | if (!test_bit(__I40E_VSI_DOWN, vsi->state)) |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6431 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6432 | |
| 6433 | /* Notify the base of the switch tree connected to |
| 6434 | * the link. Floating VEBs are not notified. |
| 6435 | */ |
| 6436 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6437 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6438 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6439 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6440 | |
| 6441 | if (pf->vf) |
| 6442 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6443 | |
| 6444 | if (pf->flags & I40E_FLAG_PTP) |
| 6445 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6449 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6450 | * @pf: board private structure |
| 6451 | **/ |
| 6452 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6453 | { |
| 6454 | int i; |
| 6455 | |
| 6456 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6457 | if (test_bit(__I40E_DOWN, pf->state) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6458 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6459 | return; |
| 6460 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6461 | /* make sure we don't do these things too often */ |
| 6462 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6463 | pf->service_timer_period))) |
| 6464 | return; |
| 6465 | pf->service_timer_previous = jiffies; |
| 6466 | |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6467 | if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) || |
| 6468 | (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)) |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6469 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6470 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6471 | /* Update the stats for active netdevs so the network stack |
| 6472 | * can look at updated numbers whenever it cares to |
| 6473 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6474 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6475 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6476 | i40e_update_stats(pf->vsi[i]); |
| 6477 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6478 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6479 | /* Update the stats for the active switching components */ |
| 6480 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6481 | if (pf->veb[i]) |
| 6482 | i40e_update_veb_stats(pf->veb[i]); |
| 6483 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6484 | |
Jacob Keller | 6118955 | 2017-05-03 10:29:01 -0700 | [diff] [blame] | 6485 | i40e_ptp_rx_hang(pf); |
Jacob Keller | 0bc0706 | 2017-05-03 10:29:02 -0700 | [diff] [blame] | 6486 | i40e_ptp_tx_hang(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | /** |
| 6490 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6491 | * @pf: board private structure |
| 6492 | **/ |
| 6493 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6494 | { |
| 6495 | u32 reset_flags = 0; |
| 6496 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6497 | if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6498 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6499 | clear_bit(__I40E_REINIT_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6500 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6501 | if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6502 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6503 | clear_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6504 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6505 | if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6506 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6507 | clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6508 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6509 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6510 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6511 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6512 | } |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6513 | if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) { |
| 6514 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
| 6515 | clear_bit(__I40E_DOWN_REQUESTED, pf->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6516 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6517 | |
| 6518 | /* If there's a recovery already waiting, it takes |
| 6519 | * precedence before starting a new reset sequence. |
| 6520 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6521 | if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6522 | i40e_prep_for_reset(pf, false); |
| 6523 | i40e_reset(pf); |
| 6524 | i40e_rebuild(pf, false, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6525 | } |
| 6526 | |
| 6527 | /* If we're already down or resetting, just bail */ |
| 6528 | if (reset_flags && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6529 | !test_bit(__I40E_DOWN, pf->state) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6530 | !test_bit(__I40E_CONFIG_BUSY, pf->state)) { |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 6531 | i40e_do_reset(pf, reset_flags, false); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6532 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | /** |
| 6536 | * i40e_handle_link_event - Handle link event |
| 6537 | * @pf: board private structure |
| 6538 | * @e: event info posted on ARQ |
| 6539 | **/ |
| 6540 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6541 | struct i40e_arq_event_info *e) |
| 6542 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6543 | struct i40e_aqc_get_link_status *status = |
| 6544 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6545 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6546 | /* Do a new status request to re-enable LSE reporting |
| 6547 | * and load new status information into the hw struct |
| 6548 | * This completely ignores any state information |
| 6549 | * in the ARQ event info, instead choosing to always |
| 6550 | * issue the AQ update link status command. |
| 6551 | */ |
| 6552 | i40e_link_event(pf); |
| 6553 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6554 | /* check for unqualified module, if link is down */ |
| 6555 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6556 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6557 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6558 | dev_err(&pf->pdev->dev, |
| 6559 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
| 6562 | /** |
| 6563 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6564 | * @pf: board private structure |
| 6565 | **/ |
| 6566 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6567 | { |
| 6568 | struct i40e_arq_event_info event; |
| 6569 | struct i40e_hw *hw = &pf->hw; |
| 6570 | u16 pending, i = 0; |
| 6571 | i40e_status ret; |
| 6572 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6573 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6574 | u32 val; |
| 6575 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6576 | /* Do not run clean AQ when PF reset fails */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6577 | if (test_bit(__I40E_RESET_FAILED, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6578 | return; |
| 6579 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6580 | /* check for error indications */ |
| 6581 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6582 | oldval = val; |
| 6583 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6584 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6585 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6586 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6587 | } |
| 6588 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6589 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6590 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6591 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6592 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6593 | } |
| 6594 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6595 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6596 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6597 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6598 | } |
| 6599 | if (oldval != val) |
| 6600 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6601 | |
| 6602 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6603 | oldval = val; |
| 6604 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6605 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6606 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6607 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6608 | } |
| 6609 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6610 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6611 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6612 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6613 | } |
| 6614 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6615 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6616 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6617 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6618 | } |
| 6619 | if (oldval != val) |
| 6620 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6621 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6622 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6623 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6624 | if (!event.msg_buf) |
| 6625 | return; |
| 6626 | |
| 6627 | do { |
| 6628 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6629 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6630 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6631 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6632 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6633 | break; |
| 6634 | } |
| 6635 | |
| 6636 | opcode = le16_to_cpu(event.desc.opcode); |
| 6637 | switch (opcode) { |
| 6638 | |
| 6639 | case i40e_aqc_opc_get_link_status: |
| 6640 | i40e_handle_link_event(pf, &event); |
| 6641 | break; |
| 6642 | case i40e_aqc_opc_send_msg_to_pf: |
| 6643 | ret = i40e_vc_process_vf_msg(pf, |
| 6644 | le16_to_cpu(event.desc.retval), |
| 6645 | le32_to_cpu(event.desc.cookie_high), |
| 6646 | le32_to_cpu(event.desc.cookie_low), |
| 6647 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6648 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6649 | break; |
| 6650 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6651 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6652 | #ifdef CONFIG_I40E_DCB |
| 6653 | rtnl_lock(); |
| 6654 | ret = i40e_handle_lldp_event(pf, &event); |
| 6655 | rtnl_unlock(); |
| 6656 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6657 | break; |
| 6658 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6659 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6660 | i40e_handle_lan_overflow_event(pf, &event); |
| 6661 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6662 | case i40e_aqc_opc_send_msg_to_peer: |
| 6663 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6664 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6665 | case i40e_aqc_opc_nvm_erase: |
| 6666 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6667 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6668 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6669 | "ARQ NVM operation 0x%04x completed\n", |
| 6670 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6671 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6672 | default: |
| 6673 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6674 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6675 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6676 | break; |
| 6677 | } |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6678 | } while (i++ < pf->adminq_work_limit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6679 | |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6680 | if (i < pf->adminq_work_limit) |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6681 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6682 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6683 | /* re-enable Admin queue interrupt cause */ |
| 6684 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6685 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6686 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6687 | i40e_flush(hw); |
| 6688 | |
| 6689 | kfree(event.msg_buf); |
| 6690 | } |
| 6691 | |
| 6692 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6693 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6694 | * @pf: board private structure |
| 6695 | **/ |
| 6696 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6697 | { |
| 6698 | int err; |
| 6699 | |
| 6700 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6701 | if (err) { |
| 6702 | /* retry in case of garbage read */ |
| 6703 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6704 | if (err) { |
| 6705 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6706 | err); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6707 | set_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6708 | } |
| 6709 | } |
| 6710 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6711 | if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6712 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6713 | clear_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6714 | } |
| 6715 | } |
| 6716 | |
| 6717 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6718 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6719 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6720 | * |
| 6721 | * enable switch loop back or die - no point in a return value |
| 6722 | **/ |
| 6723 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6724 | { |
| 6725 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6726 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6727 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6728 | |
| 6729 | ctxt.seid = pf->main_vsi_seid; |
| 6730 | ctxt.pf_num = pf->hw.pf_id; |
| 6731 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6732 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6733 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6734 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6735 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6736 | i40e_stat_str(&pf->hw, ret), |
| 6737 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6738 | return; |
| 6739 | } |
| 6740 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6741 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6742 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6743 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6744 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6745 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6746 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6747 | "update vsi switch failed, err %s aq_err %s\n", |
| 6748 | i40e_stat_str(&pf->hw, ret), |
| 6749 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | /** |
| 6754 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6755 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6756 | * |
| 6757 | * disable switch loop back or die - no point in a return value |
| 6758 | **/ |
| 6759 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6760 | { |
| 6761 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6762 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6763 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6764 | |
| 6765 | ctxt.seid = pf->main_vsi_seid; |
| 6766 | ctxt.pf_num = pf->hw.pf_id; |
| 6767 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6768 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6769 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6770 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6771 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6772 | i40e_stat_str(&pf->hw, ret), |
| 6773 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6774 | return; |
| 6775 | } |
| 6776 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6777 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6778 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6779 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6780 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6781 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6782 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6783 | "update vsi switch failed, err %s aq_err %s\n", |
| 6784 | i40e_stat_str(&pf->hw, ret), |
| 6785 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6786 | } |
| 6787 | } |
| 6788 | |
| 6789 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6790 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6791 | * @veb: pointer to the bridge instance |
| 6792 | * |
| 6793 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6794 | * specified HW bridge instance. It is expected this function is called |
| 6795 | * when a new HW bridge is instantiated. |
| 6796 | **/ |
| 6797 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6798 | { |
| 6799 | struct i40e_pf *pf = veb->pf; |
| 6800 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6801 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6802 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6803 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6804 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6805 | i40e_disable_pf_switch_lb(pf); |
| 6806 | else |
| 6807 | i40e_enable_pf_switch_lb(pf); |
| 6808 | } |
| 6809 | |
| 6810 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6811 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6812 | * @veb: pointer to the VEB instance |
| 6813 | * |
| 6814 | * This is a recursive function that first builds the attached VSIs then |
| 6815 | * recurses in to build the next layer of VEB. We track the connections |
| 6816 | * through our own index numbers because the seid's from the HW could |
| 6817 | * change across the reset. |
| 6818 | **/ |
| 6819 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6820 | { |
| 6821 | struct i40e_vsi *ctl_vsi = NULL; |
| 6822 | struct i40e_pf *pf = veb->pf; |
| 6823 | int v, veb_idx; |
| 6824 | int ret; |
| 6825 | |
| 6826 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6827 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6828 | if (pf->vsi[v] && |
| 6829 | pf->vsi[v]->veb_idx == veb->idx && |
| 6830 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6831 | ctl_vsi = pf->vsi[v]; |
| 6832 | break; |
| 6833 | } |
| 6834 | } |
| 6835 | if (!ctl_vsi) { |
| 6836 | dev_info(&pf->pdev->dev, |
| 6837 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6838 | ret = -ENOENT; |
| 6839 | goto end_reconstitute; |
| 6840 | } |
| 6841 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6842 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6843 | ret = i40e_add_vsi(ctl_vsi); |
| 6844 | if (ret) { |
| 6845 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6846 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6847 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6848 | goto end_reconstitute; |
| 6849 | } |
| 6850 | i40e_vsi_reset_stats(ctl_vsi); |
| 6851 | |
| 6852 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6853 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6854 | if (ret) |
| 6855 | goto end_reconstitute; |
| 6856 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6857 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6858 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6859 | else |
| 6860 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6861 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6862 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6863 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6864 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6865 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6866 | continue; |
| 6867 | |
| 6868 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6869 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6870 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6871 | vsi->uplink_seid = veb->seid; |
| 6872 | ret = i40e_add_vsi(vsi); |
| 6873 | if (ret) { |
| 6874 | dev_info(&pf->pdev->dev, |
| 6875 | "rebuild of vsi_idx %d failed: %d\n", |
| 6876 | v, ret); |
| 6877 | goto end_reconstitute; |
| 6878 | } |
| 6879 | i40e_vsi_reset_stats(vsi); |
| 6880 | } |
| 6881 | } |
| 6882 | |
| 6883 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6884 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6885 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6886 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6887 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6888 | if (ret) |
| 6889 | break; |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | end_reconstitute: |
| 6894 | return ret; |
| 6895 | } |
| 6896 | |
| 6897 | /** |
| 6898 | * i40e_get_capabilities - get info about the HW |
| 6899 | * @pf: the PF struct |
| 6900 | **/ |
| 6901 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6902 | { |
| 6903 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6904 | u16 data_size; |
| 6905 | int buf_len; |
| 6906 | int err; |
| 6907 | |
| 6908 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6909 | do { |
| 6910 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6911 | if (!cap_buf) |
| 6912 | return -ENOMEM; |
| 6913 | |
| 6914 | /* this loads the data into the hw struct for us */ |
| 6915 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6916 | &data_size, |
| 6917 | i40e_aqc_opc_list_func_capabilities, |
| 6918 | NULL); |
| 6919 | /* data loaded, buffer no longer needed */ |
| 6920 | kfree(cap_buf); |
| 6921 | |
| 6922 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6923 | /* retry with a larger buffer */ |
| 6924 | buf_len = data_size; |
| 6925 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6926 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6927 | "capability discovery failed, err %s aq_err %s\n", |
| 6928 | i40e_stat_str(&pf->hw, err), |
| 6929 | i40e_aq_str(&pf->hw, |
| 6930 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6931 | return -ENODEV; |
| 6932 | } |
| 6933 | } while (err); |
| 6934 | |
| 6935 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6936 | dev_info(&pf->pdev->dev, |
| 6937 | "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n", |
| 6938 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6939 | pf->hw.func_caps.num_msix_vectors, |
| 6940 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6941 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6942 | pf->hw.func_caps.fd_filters_best_effort, |
| 6943 | pf->hw.func_caps.num_tx_qp, |
| 6944 | pf->hw.func_caps.num_vsis); |
| 6945 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6946 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6947 | + pf->hw.func_caps.num_vfs) |
| 6948 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6949 | dev_info(&pf->pdev->dev, |
| 6950 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6951 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6952 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6953 | } |
| 6954 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6955 | return 0; |
| 6956 | } |
| 6957 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6958 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6959 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6960 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6961 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6962 | * @pf: board private structure |
| 6963 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6964 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6965 | { |
| 6966 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6967 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6968 | /* quick workaround for an NVM issue that leaves a critical register |
| 6969 | * uninitialized |
| 6970 | */ |
| 6971 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6972 | static const u32 hkey[] = { |
| 6973 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6974 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6975 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6976 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6977 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6978 | |
| 6979 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6980 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6981 | } |
| 6982 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6983 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6984 | return; |
| 6985 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6986 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6987 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6988 | |
| 6989 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6990 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6991 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6992 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6993 | if (!vsi) { |
| 6994 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6995 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6996 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6997 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6998 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6999 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7000 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7001 | } |
| 7002 | |
| 7003 | /** |
| 7004 | * i40e_fdir_teardown - release the Flow Director resources |
| 7005 | * @pf: board private structure |
| 7006 | **/ |
| 7007 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 7008 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 7009 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7010 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 7011 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 7012 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 7013 | if (vsi) |
| 7014 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7015 | } |
| 7016 | |
| 7017 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7018 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7019 | * @pf: board private structure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7020 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7021 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7022 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7023 | * Close up the VFs and other things in prep for PF Reset. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7024 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7025 | static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7026 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7027 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7028 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | u32 v; |
| 7030 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7031 | clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
| 7032 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7033 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 7034 | if (i40e_check_asq_alive(&pf->hw)) |
| 7035 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7036 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7037 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7038 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7039 | /* quiesce the VSIs and their queues that are not already DOWN */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7040 | /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */ |
| 7041 | if (!lock_acquired) |
| 7042 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7043 | i40e_pf_quiesce_all_vsi(pf); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7044 | if (!lock_acquired) |
| 7045 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7046 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7047 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7048 | if (pf->vsi[v]) |
| 7049 | pf->vsi[v]->seid = 0; |
| 7050 | } |
| 7051 | |
| 7052 | i40e_shutdown_adminq(&pf->hw); |
| 7053 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7054 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7055 | if (hw->hmc.hmc_obj) { |
| 7056 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7057 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7058 | dev_warn(&pf->pdev->dev, |
| 7059 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7060 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7064 | * i40e_send_version - update firmware with driver version |
| 7065 | * @pf: PF struct |
| 7066 | */ |
| 7067 | static void i40e_send_version(struct i40e_pf *pf) |
| 7068 | { |
| 7069 | struct i40e_driver_version dv; |
| 7070 | |
| 7071 | dv.major_version = DRV_VERSION_MAJOR; |
| 7072 | dv.minor_version = DRV_VERSION_MINOR; |
| 7073 | dv.build_version = DRV_VERSION_BUILD; |
| 7074 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 7075 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7076 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 7077 | } |
| 7078 | |
| 7079 | /** |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 7080 | * i40e_get_oem_version - get OEM specific version information |
| 7081 | * @hw: pointer to the hardware structure |
| 7082 | **/ |
| 7083 | static void i40e_get_oem_version(struct i40e_hw *hw) |
| 7084 | { |
| 7085 | u16 block_offset = 0xffff; |
| 7086 | u16 block_length = 0; |
| 7087 | u16 capabilities = 0; |
| 7088 | u16 gen_snap = 0; |
| 7089 | u16 release = 0; |
| 7090 | |
| 7091 | #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B |
| 7092 | #define I40E_NVM_OEM_LENGTH_OFFSET 0x00 |
| 7093 | #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01 |
| 7094 | #define I40E_NVM_OEM_GEN_OFFSET 0x02 |
| 7095 | #define I40E_NVM_OEM_RELEASE_OFFSET 0x03 |
| 7096 | #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F |
| 7097 | #define I40E_NVM_OEM_LENGTH 3 |
| 7098 | |
| 7099 | /* Check if pointer to OEM version block is valid. */ |
| 7100 | i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset); |
| 7101 | if (block_offset == 0xffff) |
| 7102 | return; |
| 7103 | |
| 7104 | /* Check if OEM version block has correct length. */ |
| 7105 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET, |
| 7106 | &block_length); |
| 7107 | if (block_length < I40E_NVM_OEM_LENGTH) |
| 7108 | return; |
| 7109 | |
| 7110 | /* Check if OEM version format is as expected. */ |
| 7111 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET, |
| 7112 | &capabilities); |
| 7113 | if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0) |
| 7114 | return; |
| 7115 | |
| 7116 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET, |
| 7117 | &gen_snap); |
| 7118 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET, |
| 7119 | &release); |
| 7120 | hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release; |
| 7121 | hw->nvm.eetrack = I40E_OEM_EETRACK_ID; |
| 7122 | } |
| 7123 | |
| 7124 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7125 | * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen |
| 7126 | * @pf: board private structure |
| 7127 | **/ |
| 7128 | static int i40e_reset(struct i40e_pf *pf) |
| 7129 | { |
| 7130 | struct i40e_hw *hw = &pf->hw; |
| 7131 | i40e_status ret; |
| 7132 | |
| 7133 | ret = i40e_pf_reset(hw); |
| 7134 | if (ret) { |
| 7135 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7136 | set_bit(__I40E_RESET_FAILED, pf->state); |
| 7137 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7138 | } else { |
| 7139 | pf->pfr_count++; |
| 7140 | } |
| 7141 | return ret; |
| 7142 | } |
| 7143 | |
| 7144 | /** |
| 7145 | * i40e_rebuild - rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7146 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7147 | * @reinit: if the Main VSI needs to re-initialized. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7148 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7149 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7150 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7151 | static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7152 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7153 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7154 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7155 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7156 | u32 val; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7157 | int v; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7158 | |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7159 | if (test_bit(__I40E_DOWN, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7160 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7161 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7162 | |
| 7163 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 7164 | ret = i40e_init_adminq(&pf->hw); |
| 7165 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7166 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 7167 | i40e_stat_str(&pf->hw, ret), |
| 7168 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7169 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7170 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 7171 | i40e_get_oem_version(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7172 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7173 | /* re-verify the eeprom if we just had an EMP reset */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7174 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7175 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7176 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 7177 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7178 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7179 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7180 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7181 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7182 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 7183 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7184 | if (ret) { |
| 7185 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 7186 | goto end_core_reset; |
| 7187 | } |
| 7188 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 7189 | if (ret) { |
| 7190 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 7191 | goto end_core_reset; |
| 7192 | } |
| 7193 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7194 | #ifdef CONFIG_I40E_DCB |
| 7195 | ret = i40e_init_pf_dcb(pf); |
| 7196 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 7197 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 7198 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 7199 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7200 | } |
| 7201 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7202 | /* do basic switch setup */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7203 | if (!lock_acquired) |
| 7204 | rtnl_lock(); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7205 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7206 | if (ret) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7207 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7208 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7209 | /* The driver only wants link up/down and module qualification |
| 7210 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7211 | */ |
| 7212 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7213 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 7214 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7215 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7216 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7217 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 7218 | i40e_stat_str(&pf->hw, ret), |
| 7219 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7220 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7221 | /* make sure our flow control settings are restored */ |
| 7222 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 7223 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 7224 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 7225 | i40e_stat_str(&pf->hw, ret), |
| 7226 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7227 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7228 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 7229 | * They are still in our local switch element arrays, so only |
| 7230 | * need to rebuild the switch model in the HW. |
| 7231 | * |
| 7232 | * If there were VEBs but the reconstitution failed, we'll try |
| 7233 | * try to recover minimal use by getting the basic PF VSI working. |
| 7234 | */ |
| 7235 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7236 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7237 | /* find the one VEB connected to the MAC, and find orphans */ |
| 7238 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 7239 | if (!pf->veb[v]) |
| 7240 | continue; |
| 7241 | |
| 7242 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 7243 | pf->veb[v]->uplink_seid == 0) { |
| 7244 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 7245 | |
| 7246 | if (!ret) |
| 7247 | continue; |
| 7248 | |
| 7249 | /* If Main VEB failed, we're in deep doodoo, |
| 7250 | * so give up rebuilding the switch and set up |
| 7251 | * for minimal rebuild of PF VSI. |
| 7252 | * If orphan failed, we'll report the error |
| 7253 | * but try to keep going. |
| 7254 | */ |
| 7255 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 7256 | dev_info(&pf->pdev->dev, |
| 7257 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 7258 | ret); |
| 7259 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 7260 | = pf->mac_seid; |
| 7261 | break; |
| 7262 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 7263 | dev_info(&pf->pdev->dev, |
| 7264 | "rebuild of orphan VEB failed: %d\n", |
| 7265 | ret); |
| 7266 | } |
| 7267 | } |
| 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 7272 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7273 | /* no VEB, so rebuild only the Main VSI */ |
| 7274 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 7275 | if (ret) { |
| 7276 | dev_info(&pf->pdev->dev, |
| 7277 | "rebuild of Main VSI failed: %d\n", ret); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7278 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7279 | } |
| 7280 | } |
| 7281 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7282 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 7283 | * of TSO, so that we avoid the MDD being fired and causing |
| 7284 | * a reset in the case of small MSS+TSO. |
| 7285 | */ |
| 7286 | #define I40E_REG_MSS 0x000E64DC |
| 7287 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 7288 | #define I40E_64BYTE_MSS 0x400000 |
| 7289 | val = rd32(hw, I40E_REG_MSS); |
| 7290 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7291 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7292 | val |= I40E_64BYTE_MSS; |
| 7293 | wr32(hw, I40E_REG_MSS, val); |
| 7294 | } |
| 7295 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7296 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7297 | msleep(75); |
| 7298 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7299 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7300 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7301 | i40e_stat_str(&pf->hw, ret), |
| 7302 | i40e_aq_str(&pf->hw, |
| 7303 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7304 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7305 | /* reinit the misc interrupt */ |
| 7306 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7307 | ret = i40e_setup_misc_vector(pf); |
| 7308 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7309 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7310 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7311 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7312 | * PF/VF VSIs. |
| 7313 | * The FW can still send Flow control frames if enabled. |
| 7314 | */ |
| 7315 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7316 | pf->main_vsi_seid); |
| 7317 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7318 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7319 | i40e_pf_unquiesce_all_vsi(pf); |
| 7320 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7321 | /* Release the RTNL lock before we start resetting VFs */ |
| 7322 | if (!lock_acquired) |
| 7323 | rtnl_unlock(); |
| 7324 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 7325 | i40e_reset_all_vfs(pf, true); |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7326 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7327 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7328 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7329 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7330 | /* We've already released the lock, so don't do it again */ |
| 7331 | goto end_core_reset; |
| 7332 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7333 | end_unlock: |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7334 | if (!lock_acquired) |
| 7335 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7336 | end_core_reset: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7337 | clear_bit(__I40E_RESET_FAILED, pf->state); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7338 | clear_recovery: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7339 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7343 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
| 7344 | * @pf: board private structure |
| 7345 | * @reinit: if the Main VSI needs to re-initialized. |
| 7346 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7347 | * before this function was called. |
| 7348 | **/ |
| 7349 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit, |
| 7350 | bool lock_acquired) |
| 7351 | { |
| 7352 | int ret; |
| 7353 | /* Now we wait for GRST to settle out. |
| 7354 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 7355 | * because the reset will make them disappear. |
| 7356 | */ |
| 7357 | ret = i40e_reset(pf); |
| 7358 | if (!ret) |
| 7359 | i40e_rebuild(pf, reinit, lock_acquired); |
| 7360 | } |
| 7361 | |
| 7362 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7363 | * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7364 | * @pf: board private structure |
| 7365 | * |
| 7366 | * Close up the VFs and other things in prep for a Core Reset, |
| 7367 | * then get ready to rebuild the world. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7368 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7369 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7370 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7371 | static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7372 | { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7373 | i40e_prep_for_reset(pf, lock_acquired); |
| 7374 | i40e_reset_and_rebuild(pf, false, lock_acquired); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7375 | } |
| 7376 | |
| 7377 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7378 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7379 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7380 | * |
| 7381 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7382 | **/ |
| 7383 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7384 | { |
| 7385 | struct i40e_hw *hw = &pf->hw; |
| 7386 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7387 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7388 | struct i40e_vf *vf; |
| 7389 | u32 reg; |
| 7390 | int i; |
| 7391 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7392 | if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7393 | return; |
| 7394 | |
| 7395 | /* find what triggered the MDD event */ |
| 7396 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7397 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7398 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7399 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7400 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7401 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7402 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7403 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7404 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7405 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7406 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7407 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7408 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n", |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7409 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7410 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7411 | mdd_detected = true; |
| 7412 | } |
| 7413 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7414 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7415 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7416 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7417 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7418 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7419 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7420 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7421 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7422 | if (netif_msg_rx_err(pf)) |
| 7423 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7424 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7425 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7426 | mdd_detected = true; |
| 7427 | } |
| 7428 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7429 | if (mdd_detected) { |
| 7430 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7431 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7432 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7433 | dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n"); |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7434 | pf_mdd_detected = true; |
| 7435 | } |
| 7436 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7437 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7438 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7439 | dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n"); |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7440 | pf_mdd_detected = true; |
| 7441 | } |
| 7442 | /* Queue belongs to the PF, initiate a reset */ |
| 7443 | if (pf_mdd_detected) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7444 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7445 | i40e_service_event_schedule(pf); |
| 7446 | } |
| 7447 | } |
| 7448 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7449 | /* see if one of the VFs needs its hand slapped */ |
| 7450 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7451 | vf = &(pf->vf[i]); |
| 7452 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7453 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7454 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7455 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7456 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7457 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7458 | } |
| 7459 | |
| 7460 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7461 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7462 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7463 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7464 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7465 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7466 | } |
| 7467 | |
| 7468 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7469 | dev_info(&pf->pdev->dev, |
| 7470 | "Too many MDD events on VF %d, disabled\n", i); |
| 7471 | dev_info(&pf->pdev->dev, |
| 7472 | "Use PF Control I/F to re-enable the VF\n"); |
Jacob Keller | 6322e63 | 2017-04-13 04:45:54 -0400 | [diff] [blame] | 7473 | set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7474 | } |
| 7475 | } |
| 7476 | |
| 7477 | /* re-enable mdd interrupt cause */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7478 | clear_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7480 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7481 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7482 | i40e_flush(hw); |
| 7483 | } |
| 7484 | |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 7485 | static const char *i40e_tunnel_name(struct i40e_udp_port_config *port) |
| 7486 | { |
| 7487 | switch (port->type) { |
| 7488 | case UDP_TUNNEL_TYPE_VXLAN: |
| 7489 | return "vxlan"; |
| 7490 | case UDP_TUNNEL_TYPE_GENEVE: |
| 7491 | return "geneve"; |
| 7492 | default: |
| 7493 | return "unknown"; |
| 7494 | } |
| 7495 | } |
| 7496 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7497 | /** |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 7498 | * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters |
| 7499 | * @pf: board private structure |
| 7500 | **/ |
| 7501 | static void i40e_sync_udp_filters(struct i40e_pf *pf) |
| 7502 | { |
| 7503 | int i; |
| 7504 | |
| 7505 | /* loop through and set pending bit for all active UDP filters */ |
| 7506 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 7507 | if (pf->udp_ports[i].port) |
| 7508 | pf->pending_udp_bitmap |= BIT_ULL(i); |
| 7509 | } |
| 7510 | |
| 7511 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 7512 | } |
| 7513 | |
| 7514 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7515 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7516 | * @pf: board private structure |
| 7517 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7518 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7519 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7520 | struct i40e_hw *hw = &pf->hw; |
| 7521 | i40e_status ret; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 7522 | u16 port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7523 | int i; |
| 7524 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7525 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7526 | return; |
| 7527 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7528 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7529 | |
| 7530 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7531 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7532 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 7533 | port = pf->udp_ports[i].port; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7534 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7535 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7536 | pf->udp_ports[i].type, |
| 7537 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7538 | else |
| 7539 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7540 | |
| 7541 | if (ret) { |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 7542 | dev_info(&pf->pdev->dev, |
| 7543 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7544 | i40e_tunnel_name(&pf->udp_ports[i]), |
| 7545 | port ? "add" : "delete", |
| 7546 | port, i, |
| 7547 | i40e_stat_str(&pf->hw, ret), |
| 7548 | i40e_aq_str(&pf->hw, |
| 7549 | pf->hw.aq.asq_last_status)); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 7550 | pf->udp_ports[i].port = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7551 | } |
| 7552 | } |
| 7553 | } |
| 7554 | } |
| 7555 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7556 | /** |
| 7557 | * i40e_service_task - Run the driver's async subtasks |
| 7558 | * @work: pointer to work_struct containing our data |
| 7559 | **/ |
| 7560 | static void i40e_service_task(struct work_struct *work) |
| 7561 | { |
| 7562 | struct i40e_pf *pf = container_of(work, |
| 7563 | struct i40e_pf, |
| 7564 | service_task); |
| 7565 | unsigned long start_time = jiffies; |
| 7566 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7567 | /* don't bother with service tasks if a reset is in progress */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7568 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7569 | return; |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7570 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7571 | if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state)) |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7572 | return; |
| 7573 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7574 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7575 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7576 | i40e_reset_subtask(pf); |
| 7577 | i40e_handle_mdd_event(pf); |
| 7578 | i40e_vc_process_vflr_event(pf); |
| 7579 | i40e_watchdog_subtask(pf); |
| 7580 | i40e_fdir_reinit_subtask(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 7581 | if (pf->flags & I40E_FLAG_CLIENT_RESET) { |
| 7582 | /* Client subtask will reopen next time through. */ |
| 7583 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true); |
| 7584 | pf->flags &= ~I40E_FLAG_CLIENT_RESET; |
| 7585 | } else { |
| 7586 | i40e_client_subtask(pf); |
| 7587 | if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) { |
| 7588 | i40e_notify_client_of_l2_param_changes( |
| 7589 | pf->vsi[pf->lan_vsi]); |
| 7590 | pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE; |
| 7591 | } |
| 7592 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7593 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7594 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7595 | i40e_clean_adminq_subtask(pf); |
| 7596 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7597 | /* flush memory to make sure state is correct before next watchdog */ |
| 7598 | smp_mb__before_atomic(); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7599 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7600 | |
| 7601 | /* If the tasks have taken longer than one timer cycle or there |
| 7602 | * is more work to be done, reschedule the service task now |
| 7603 | * rather than wait for the timer to tick again. |
| 7604 | */ |
| 7605 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7606 | test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) || |
| 7607 | test_bit(__I40E_MDD_EVENT_PENDING, pf->state) || |
| 7608 | test_bit(__I40E_VFLR_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7609 | i40e_service_event_schedule(pf); |
| 7610 | } |
| 7611 | |
| 7612 | /** |
| 7613 | * i40e_service_timer - timer callback |
| 7614 | * @data: pointer to PF struct |
| 7615 | **/ |
| 7616 | static void i40e_service_timer(unsigned long data) |
| 7617 | { |
| 7618 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7619 | |
| 7620 | mod_timer(&pf->service_timer, |
| 7621 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7622 | i40e_service_event_schedule(pf); |
| 7623 | } |
| 7624 | |
| 7625 | /** |
| 7626 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7627 | * @vsi: the VSI being configured |
| 7628 | **/ |
| 7629 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7630 | { |
| 7631 | struct i40e_pf *pf = vsi->back; |
| 7632 | |
| 7633 | switch (vsi->type) { |
| 7634 | case I40E_VSI_MAIN: |
| 7635 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7636 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7637 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7638 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7639 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7640 | else |
| 7641 | vsi->num_q_vectors = 1; |
| 7642 | |
| 7643 | break; |
| 7644 | |
| 7645 | case I40E_VSI_FDIR: |
| 7646 | vsi->alloc_queue_pairs = 1; |
| 7647 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7648 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7649 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7650 | break; |
| 7651 | |
| 7652 | case I40E_VSI_VMDQ2: |
| 7653 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7654 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7655 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7656 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7657 | break; |
| 7658 | |
| 7659 | case I40E_VSI_SRIOV: |
| 7660 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7661 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7662 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7663 | break; |
| 7664 | |
| 7665 | default: |
| 7666 | WARN_ON(1); |
| 7667 | return -ENODATA; |
| 7668 | } |
| 7669 | |
| 7670 | return 0; |
| 7671 | } |
| 7672 | |
| 7673 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7674 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7675 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7676 | * @alloc_qvectors: a bool to specify if q_vectors need to be allocated. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7677 | * |
| 7678 | * On error: returns error code (negative) |
| 7679 | * On success: returns 0 |
| 7680 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7681 | static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7682 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7683 | struct i40e_ring **next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7684 | int size; |
| 7685 | int ret = 0; |
| 7686 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7687 | /* allocate memory for both Tx, XDP Tx and Rx ring pointers */ |
| 7688 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * |
| 7689 | (i40e_enabled_xdp_vsi(vsi) ? 3 : 2); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7690 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7691 | if (!vsi->tx_rings) |
| 7692 | return -ENOMEM; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7693 | next_rings = vsi->tx_rings + vsi->alloc_queue_pairs; |
| 7694 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 7695 | vsi->xdp_rings = next_rings; |
| 7696 | next_rings += vsi->alloc_queue_pairs; |
| 7697 | } |
| 7698 | vsi->rx_rings = next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7699 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7700 | if (alloc_qvectors) { |
| 7701 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7702 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7703 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7704 | if (!vsi->q_vectors) { |
| 7705 | ret = -ENOMEM; |
| 7706 | goto err_vectors; |
| 7707 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7708 | } |
| 7709 | return ret; |
| 7710 | |
| 7711 | err_vectors: |
| 7712 | kfree(vsi->tx_rings); |
| 7713 | return ret; |
| 7714 | } |
| 7715 | |
| 7716 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7717 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7718 | * @pf: board private structure |
| 7719 | * @type: type of VSI |
| 7720 | * |
| 7721 | * On error: returns error code (negative) |
| 7722 | * On success: returns vsi index in PF (positive) |
| 7723 | **/ |
| 7724 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7725 | { |
| 7726 | int ret = -ENODEV; |
| 7727 | struct i40e_vsi *vsi; |
| 7728 | int vsi_idx; |
| 7729 | int i; |
| 7730 | |
| 7731 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7732 | mutex_lock(&pf->switch_mutex); |
| 7733 | |
| 7734 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7735 | * been happening. We can afford to do a quick scan to look |
| 7736 | * for any free VSIs in the list. |
| 7737 | * |
| 7738 | * find next empty vsi slot, looping back around if necessary |
| 7739 | */ |
| 7740 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7741 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7742 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7743 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7744 | i = 0; |
| 7745 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7746 | i++; |
| 7747 | } |
| 7748 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7749 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7750 | vsi_idx = i; /* Found one! */ |
| 7751 | } else { |
| 7752 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7753 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7754 | } |
| 7755 | pf->next_vsi = ++i; |
| 7756 | |
| 7757 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7758 | if (!vsi) { |
| 7759 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7760 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7761 | } |
| 7762 | vsi->type = type; |
| 7763 | vsi->back = pf; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7764 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7765 | vsi->flags = 0; |
| 7766 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7767 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7768 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7769 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7770 | vsi->netdev_registered = false; |
| 7771 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7772 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7773 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7774 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7775 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7776 | if (ret) |
| 7777 | goto err_rings; |
| 7778 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7779 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7780 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7781 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7782 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7783 | /* Setup default MSIX irq handler for VSI */ |
| 7784 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7785 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7786 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7787 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7788 | pf->vsi[vsi_idx] = vsi; |
| 7789 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7790 | goto unlock_pf; |
| 7791 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7792 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7793 | pf->next_vsi = i - 1; |
| 7794 | kfree(vsi); |
| 7795 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7796 | mutex_unlock(&pf->switch_mutex); |
| 7797 | return ret; |
| 7798 | } |
| 7799 | |
| 7800 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7801 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7802 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7803 | * @free_qvectors: a bool to specify if q_vectors need to be freed. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7804 | * |
| 7805 | * On error: returns error code (negative) |
| 7806 | * On success: returns 0 |
| 7807 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7808 | static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7809 | { |
| 7810 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7811 | if (free_qvectors) { |
| 7812 | kfree(vsi->q_vectors); |
| 7813 | vsi->q_vectors = NULL; |
| 7814 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7815 | kfree(vsi->tx_rings); |
| 7816 | vsi->tx_rings = NULL; |
| 7817 | vsi->rx_rings = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7818 | vsi->xdp_rings = NULL; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7819 | } |
| 7820 | |
| 7821 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7822 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7823 | * and lookup table |
| 7824 | * @vsi: Pointer to VSI structure |
| 7825 | */ |
| 7826 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7827 | { |
| 7828 | if (!vsi) |
| 7829 | return; |
| 7830 | |
| 7831 | kfree(vsi->rss_hkey_user); |
| 7832 | vsi->rss_hkey_user = NULL; |
| 7833 | |
| 7834 | kfree(vsi->rss_lut_user); |
| 7835 | vsi->rss_lut_user = NULL; |
| 7836 | } |
| 7837 | |
| 7838 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7839 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7840 | * @vsi: the VSI being un-configured |
| 7841 | **/ |
| 7842 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7843 | { |
| 7844 | struct i40e_pf *pf; |
| 7845 | |
| 7846 | if (!vsi) |
| 7847 | return 0; |
| 7848 | |
| 7849 | if (!vsi->back) |
| 7850 | goto free_vsi; |
| 7851 | pf = vsi->back; |
| 7852 | |
| 7853 | mutex_lock(&pf->switch_mutex); |
| 7854 | if (!pf->vsi[vsi->idx]) { |
| 7855 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7856 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7857 | goto unlock_vsi; |
| 7858 | } |
| 7859 | |
| 7860 | if (pf->vsi[vsi->idx] != vsi) { |
| 7861 | dev_err(&pf->pdev->dev, |
| 7862 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7863 | pf->vsi[vsi->idx]->idx, |
| 7864 | pf->vsi[vsi->idx], |
| 7865 | pf->vsi[vsi->idx]->type, |
| 7866 | vsi->idx, vsi, vsi->type); |
| 7867 | goto unlock_vsi; |
| 7868 | } |
| 7869 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7870 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7871 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7872 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7873 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7874 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7875 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7876 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7877 | pf->vsi[vsi->idx] = NULL; |
| 7878 | if (vsi->idx < pf->next_vsi) |
| 7879 | pf->next_vsi = vsi->idx; |
| 7880 | |
| 7881 | unlock_vsi: |
| 7882 | mutex_unlock(&pf->switch_mutex); |
| 7883 | free_vsi: |
| 7884 | kfree(vsi); |
| 7885 | |
| 7886 | return 0; |
| 7887 | } |
| 7888 | |
| 7889 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7890 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7891 | * @vsi: the VSI being cleaned |
| 7892 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7893 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7894 | { |
| 7895 | int i; |
| 7896 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7897 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7898 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7899 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7900 | vsi->tx_rings[i] = NULL; |
| 7901 | vsi->rx_rings[i] = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7902 | if (vsi->xdp_rings) |
| 7903 | vsi->xdp_rings[i] = NULL; |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7904 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7905 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7909 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7910 | * @vsi: the VSI being configured |
| 7911 | **/ |
| 7912 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7913 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7914 | int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7915 | struct i40e_pf *pf = vsi->back; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7916 | struct i40e_ring *ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7917 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7918 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7919 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7920 | /* allocate space for both Tx and Rx in one shot */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7921 | ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL); |
| 7922 | if (!ring) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7923 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7924 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7925 | ring->queue_index = i; |
| 7926 | ring->reg_idx = vsi->base_queue + i; |
| 7927 | ring->ring_active = false; |
| 7928 | ring->vsi = vsi; |
| 7929 | ring->netdev = vsi->netdev; |
| 7930 | ring->dev = &pf->pdev->dev; |
| 7931 | ring->count = vsi->num_desc; |
| 7932 | ring->size = 0; |
| 7933 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7934 | if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE) |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7935 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 7936 | ring->tx_itr_setting = pf->tx_itr_default; |
| 7937 | vsi->tx_rings[i] = ring++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7938 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7939 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 7940 | goto setup_rx; |
| 7941 | |
| 7942 | ring->queue_index = vsi->alloc_queue_pairs + i; |
| 7943 | ring->reg_idx = vsi->base_queue + ring->queue_index; |
| 7944 | ring->ring_active = false; |
| 7945 | ring->vsi = vsi; |
| 7946 | ring->netdev = NULL; |
| 7947 | ring->dev = &pf->pdev->dev; |
| 7948 | ring->count = vsi->num_desc; |
| 7949 | ring->size = 0; |
| 7950 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7951 | if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE) |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7952 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 7953 | set_ring_xdp(ring); |
| 7954 | ring->tx_itr_setting = pf->tx_itr_default; |
| 7955 | vsi->xdp_rings[i] = ring++; |
| 7956 | |
| 7957 | setup_rx: |
| 7958 | ring->queue_index = i; |
| 7959 | ring->reg_idx = vsi->base_queue + i; |
| 7960 | ring->ring_active = false; |
| 7961 | ring->vsi = vsi; |
| 7962 | ring->netdev = vsi->netdev; |
| 7963 | ring->dev = &pf->pdev->dev; |
| 7964 | ring->count = vsi->num_desc; |
| 7965 | ring->size = 0; |
| 7966 | ring->dcb_tc = 0; |
| 7967 | ring->rx_itr_setting = pf->rx_itr_default; |
| 7968 | vsi->rx_rings[i] = ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7969 | } |
| 7970 | |
| 7971 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7972 | |
| 7973 | err_out: |
| 7974 | i40e_vsi_clear_rings(vsi); |
| 7975 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7976 | } |
| 7977 | |
| 7978 | /** |
| 7979 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7980 | * @pf: board private structure |
| 7981 | * @vectors: the number of MSI-X vectors to request |
| 7982 | * |
| 7983 | * Returns the number of vectors reserved, or error |
| 7984 | **/ |
| 7985 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7986 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7987 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7988 | I40E_MIN_MSIX, vectors); |
| 7989 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7990 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7991 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7992 | vectors = 0; |
| 7993 | } |
| 7994 | |
| 7995 | return vectors; |
| 7996 | } |
| 7997 | |
| 7998 | /** |
| 7999 | * i40e_init_msix - Setup the MSIX capability |
| 8000 | * @pf: board private structure |
| 8001 | * |
| 8002 | * Work with the OS to set up the MSIX vectors needed. |
| 8003 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8004 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8005 | **/ |
| 8006 | static int i40e_init_msix(struct i40e_pf *pf) |
| 8007 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8008 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8009 | int cpus, extra_vectors; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8010 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8011 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8012 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8013 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8014 | |
| 8015 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 8016 | return -ENODEV; |
| 8017 | |
| 8018 | /* The number of vectors we'll request will be comprised of: |
| 8019 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 8020 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8021 | * - Queues being used for RSS. |
| 8022 | * We don't need as many as max_rss_size vectors. |
| 8023 | * use rss_size instead in the calculation since that |
| 8024 | * is governed by number of cpus in the system. |
| 8025 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8026 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8027 | * - The CPU count within the NUMA node if iWARP is enabled |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8028 | * Once we count this up, try the request. |
| 8029 | * |
| 8030 | * If we can't get what we want, we'll simplify to nearly nothing |
| 8031 | * and try again. If that still fails, we punt. |
| 8032 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8033 | vectors_left = hw->func_caps.num_msix_vectors; |
| 8034 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8035 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8036 | /* reserve one vector for miscellaneous handler */ |
| 8037 | if (vectors_left) { |
| 8038 | v_budget++; |
| 8039 | vectors_left--; |
| 8040 | } |
| 8041 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8042 | /* reserve some vectors for the main PF traffic queues. Initially we |
| 8043 | * only reserve at most 50% of the available vectors, in the case that |
| 8044 | * the number of online CPUs is large. This ensures that we can enable |
| 8045 | * extra features as well. Once we've enabled the other features, we |
| 8046 | * will use any remaining vectors to reach as close as we can to the |
| 8047 | * number of online CPUs. |
| 8048 | */ |
| 8049 | cpus = num_online_cpus(); |
| 8050 | pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8051 | vectors_left -= pf->num_lan_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8052 | |
| 8053 | /* reserve one vector for sideband flow director */ |
| 8054 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8055 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8056 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8057 | v_budget++; |
| 8058 | vectors_left--; |
| 8059 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8060 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8061 | } |
| 8062 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 8063 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8064 | /* can we reserve enough for iWARP? */ |
| 8065 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8066 | iwarp_requested = pf->num_iwarp_msix; |
| 8067 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8068 | if (!vectors_left) |
| 8069 | pf->num_iwarp_msix = 0; |
| 8070 | else if (vectors_left < pf->num_iwarp_msix) |
| 8071 | pf->num_iwarp_msix = 1; |
| 8072 | v_budget += pf->num_iwarp_msix; |
| 8073 | vectors_left -= pf->num_iwarp_msix; |
| 8074 | } |
| 8075 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8076 | /* any vectors left over go for VMDq support */ |
| 8077 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 8078 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 8079 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 8080 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 8081 | if (!vectors_left) { |
| 8082 | pf->num_vmdq_msix = 0; |
| 8083 | pf->num_vmdq_qps = 0; |
| 8084 | } else { |
| 8085 | /* if we're short on vectors for what's desired, we limit |
| 8086 | * the queues per vmdq. If this is still more than are |
| 8087 | * available, the user will need to change the number of |
| 8088 | * queues/vectors used by the PF later with the ethtool |
| 8089 | * channels command |
| 8090 | */ |
| 8091 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 8092 | pf->num_vmdq_qps = 1; |
| 8093 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8094 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 8095 | v_budget += vmdq_vecs; |
| 8096 | vectors_left -= vmdq_vecs; |
| 8097 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8098 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8099 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8100 | /* On systems with a large number of SMP cores, we previously limited |
| 8101 | * the number of vectors for num_lan_msix to be at most 50% of the |
| 8102 | * available vectors, to allow for other features. Now, we add back |
| 8103 | * the remaining vectors. However, we ensure that the total |
| 8104 | * num_lan_msix will not exceed num_online_cpus(). To do this, we |
| 8105 | * calculate the number of vectors we can add without going over the |
| 8106 | * cap of CPUs. For systems with a small number of CPUs this will be |
| 8107 | * zero. |
| 8108 | */ |
| 8109 | extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left); |
| 8110 | pf->num_lan_msix += extra_vectors; |
| 8111 | vectors_left -= extra_vectors; |
| 8112 | |
| 8113 | WARN(vectors_left < 0, |
| 8114 | "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n"); |
| 8115 | |
| 8116 | v_budget += pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8117 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 8118 | GFP_KERNEL); |
| 8119 | if (!pf->msix_entries) |
| 8120 | return -ENOMEM; |
| 8121 | |
| 8122 | for (i = 0; i < v_budget; i++) |
| 8123 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8124 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8125 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8126 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8127 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 8128 | kfree(pf->msix_entries); |
| 8129 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 8130 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8131 | return -ENODEV; |
| 8132 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8133 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8134 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8135 | pf->num_vmdq_vsis = 0; |
| 8136 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8137 | pf->num_lan_qps = 1; |
| 8138 | pf->num_lan_msix = 1; |
| 8139 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8140 | } else if (!vectors_left) { |
| 8141 | /* If we have limited resources, we will start with no vectors |
| 8142 | * for the special features and then allocate vectors to some |
| 8143 | * of these features based on the policy and at the end disable |
| 8144 | * the features that did not get any vectors. |
| 8145 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8146 | int vec; |
| 8147 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8148 | dev_info(&pf->pdev->dev, |
| 8149 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8150 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8151 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8152 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8153 | /* Scale vector usage down */ |
| 8154 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8155 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8156 | pf->num_vmdq_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8157 | |
| 8158 | /* partition out the remaining vectors */ |
| 8159 | switch (vec) { |
| 8160 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8161 | pf->num_lan_msix = 1; |
| 8162 | break; |
| 8163 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8164 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 8165 | pf->num_lan_msix = 1; |
| 8166 | pf->num_iwarp_msix = 1; |
| 8167 | } else { |
| 8168 | pf->num_lan_msix = 2; |
| 8169 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8170 | break; |
| 8171 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8172 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 8173 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 8174 | iwarp_requested); |
| 8175 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 8176 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 8177 | } else { |
| 8178 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 8179 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 8180 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 8181 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8182 | pf->num_fdsb_msix = 1; |
| 8183 | vec--; |
| 8184 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8185 | pf->num_lan_msix = min_t(int, |
| 8186 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 8187 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8188 | pf->num_lan_qps = pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8189 | break; |
| 8190 | } |
| 8191 | } |
| 8192 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 8193 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 8194 | (pf->num_fdsb_msix == 0)) { |
| 8195 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 8196 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 8197 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8198 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 8199 | (pf->num_vmdq_msix == 0)) { |
| 8200 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 8201 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 8202 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8203 | |
| 8204 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 8205 | (pf->num_iwarp_msix == 0)) { |
| 8206 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 8207 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 8208 | } |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8209 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 8210 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 8211 | pf->num_lan_msix, |
| 8212 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 8213 | pf->num_fdsb_msix, |
| 8214 | pf->num_iwarp_msix); |
| 8215 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8216 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8217 | } |
| 8218 | |
| 8219 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8220 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8221 | * @vsi: the VSI being configured |
| 8222 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8223 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8224 | * |
| 8225 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 8226 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8227 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8228 | { |
| 8229 | struct i40e_q_vector *q_vector; |
| 8230 | |
| 8231 | /* allocate q_vector */ |
| 8232 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 8233 | if (!q_vector) |
| 8234 | return -ENOMEM; |
| 8235 | |
| 8236 | q_vector->vsi = vsi; |
| 8237 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8238 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 8239 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8240 | if (vsi->netdev) |
| 8241 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 8242 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8243 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 8244 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 8245 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 8246 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8247 | /* tie q_vector and vsi together */ |
| 8248 | vsi->q_vectors[v_idx] = q_vector; |
| 8249 | |
| 8250 | return 0; |
| 8251 | } |
| 8252 | |
| 8253 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8254 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8255 | * @vsi: the VSI being configured |
| 8256 | * |
| 8257 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 8258 | * return -ENOMEM. |
| 8259 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8260 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8261 | { |
| 8262 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8263 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8264 | |
| 8265 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 8266 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 8267 | num_q_vectors = vsi->num_q_vectors; |
| 8268 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 8269 | num_q_vectors = 1; |
| 8270 | else |
| 8271 | return -EINVAL; |
| 8272 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8273 | current_cpu = cpumask_first(cpu_online_mask); |
| 8274 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8275 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8276 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8277 | if (err) |
| 8278 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8279 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 8280 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 8281 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8285 | |
| 8286 | err_out: |
| 8287 | while (v_idx--) |
| 8288 | i40e_free_q_vector(vsi, v_idx); |
| 8289 | |
| 8290 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8291 | } |
| 8292 | |
| 8293 | /** |
| 8294 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 8295 | * @pf: board private structure to initialize |
| 8296 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8297 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8298 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8299 | int vectors = 0; |
| 8300 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8301 | |
| 8302 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8303 | vectors = i40e_init_msix(pf); |
| 8304 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8305 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8306 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8307 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 8308 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 8309 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8310 | I40E_FLAG_SRIOV_ENABLED | |
| 8311 | I40E_FLAG_FD_SB_ENABLED | |
| 8312 | I40E_FLAG_FD_ATR_ENABLED | |
| 8313 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8314 | |
| 8315 | /* rework the queue expectations without MSIX */ |
| 8316 | i40e_determine_queue_usage(pf); |
| 8317 | } |
| 8318 | } |
| 8319 | |
| 8320 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8321 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8322 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8323 | vectors = pci_enable_msi(pf->pdev); |
| 8324 | if (vectors < 0) { |
| 8325 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 8326 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8327 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 8328 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8329 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8330 | } |
| 8331 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8332 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8333 | dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n"); |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8334 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8335 | /* set up vector assignment tracking */ |
| 8336 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 8337 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8338 | if (!pf->irq_pile) { |
| 8339 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 8340 | return -ENOMEM; |
| 8341 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8342 | pf->irq_pile->num_entries = vectors; |
| 8343 | pf->irq_pile->search_hint = 0; |
| 8344 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8345 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8346 | (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8347 | |
| 8348 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | /** |
| 8352 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 8353 | * @pf: board private structure |
| 8354 | * |
| 8355 | * This sets up the handler for MSIX 0, which is used to manage the |
| 8356 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 8357 | * when in MSI or Legacy interrupt mode. |
| 8358 | **/ |
| 8359 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8360 | { |
| 8361 | struct i40e_hw *hw = &pf->hw; |
| 8362 | int err = 0; |
| 8363 | |
| 8364 | /* Only request the irq if this is the first time through, and |
| 8365 | * not when we're rebuilding after a Reset |
| 8366 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8367 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8368 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8369 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8370 | if (err) { |
| 8371 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8372 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8373 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8374 | return -EFAULT; |
| 8375 | } |
| 8376 | } |
| 8377 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8378 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8379 | |
| 8380 | /* associate no queues to the misc vector */ |
| 8381 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8382 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8383 | |
| 8384 | i40e_flush(hw); |
| 8385 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8386 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8387 | |
| 8388 | return err; |
| 8389 | } |
| 8390 | |
| 8391 | /** |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8392 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8393 | * @vsi: vsi structure |
| 8394 | * @seed: RSS hash seed |
| 8395 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8396 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8397 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8398 | { |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8399 | struct i40e_pf *pf = vsi->back; |
| 8400 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8401 | int ret = 0; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8402 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8403 | if (seed) { |
| 8404 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8405 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8406 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8407 | if (ret) { |
| 8408 | dev_info(&pf->pdev->dev, |
| 8409 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8410 | i40e_stat_str(hw, ret), |
| 8411 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8412 | return ret; |
| 8413 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8414 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8415 | if (lut) { |
| 8416 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8417 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8418 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8419 | if (ret) { |
| 8420 | dev_info(&pf->pdev->dev, |
| 8421 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8422 | i40e_stat_str(hw, ret), |
| 8423 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8424 | return ret; |
| 8425 | } |
| 8426 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8427 | return ret; |
| 8428 | } |
| 8429 | |
| 8430 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8431 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8432 | * @vsi: Pointer to vsi structure |
| 8433 | * @seed: Buffter to store the hash keys |
| 8434 | * @lut: Buffer to store the lookup table entries |
| 8435 | * @lut_size: Size of buffer to store the lookup table entries |
| 8436 | * |
| 8437 | * Return 0 on success, negative on failure |
| 8438 | */ |
| 8439 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8440 | u8 *lut, u16 lut_size) |
| 8441 | { |
| 8442 | struct i40e_pf *pf = vsi->back; |
| 8443 | struct i40e_hw *hw = &pf->hw; |
| 8444 | int ret = 0; |
| 8445 | |
| 8446 | if (seed) { |
| 8447 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8448 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8449 | if (ret) { |
| 8450 | dev_info(&pf->pdev->dev, |
| 8451 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8452 | i40e_stat_str(&pf->hw, ret), |
| 8453 | i40e_aq_str(&pf->hw, |
| 8454 | pf->hw.aq.asq_last_status)); |
| 8455 | return ret; |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | if (lut) { |
| 8460 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8461 | |
| 8462 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8463 | if (ret) { |
| 8464 | dev_info(&pf->pdev->dev, |
| 8465 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8466 | i40e_stat_str(&pf->hw, ret), |
| 8467 | i40e_aq_str(&pf->hw, |
| 8468 | pf->hw.aq.asq_last_status)); |
| 8469 | return ret; |
| 8470 | } |
| 8471 | } |
| 8472 | |
| 8473 | return ret; |
| 8474 | } |
| 8475 | |
| 8476 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8477 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8478 | * @vsi: VSI structure |
| 8479 | **/ |
| 8480 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8481 | { |
| 8482 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8483 | struct i40e_pf *pf = vsi->back; |
| 8484 | u8 *lut; |
| 8485 | int ret; |
| 8486 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8487 | if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)) |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8488 | return 0; |
| 8489 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8490 | if (!vsi->rss_size) |
| 8491 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8492 | vsi->num_queue_pairs); |
| 8493 | if (!vsi->rss_size) |
| 8494 | return -EINVAL; |
| 8495 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8496 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8497 | if (!lut) |
| 8498 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8499 | /* Use the user configured hash keys and lookup table if there is one, |
| 8500 | * otherwise use default |
| 8501 | */ |
| 8502 | if (vsi->rss_lut_user) |
| 8503 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8504 | else |
| 8505 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8506 | if (vsi->rss_hkey_user) |
| 8507 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8508 | else |
| 8509 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8510 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8511 | kfree(lut); |
| 8512 | |
| 8513 | return ret; |
| 8514 | } |
| 8515 | |
| 8516 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8517 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8518 | * @vsi: Pointer to vsi structure |
| 8519 | * @seed: RSS hash seed |
| 8520 | * @lut: Lookup table |
| 8521 | * @lut_size: Lookup table size |
| 8522 | * |
| 8523 | * Returns 0 on success, negative on failure |
| 8524 | **/ |
| 8525 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8526 | const u8 *lut, u16 lut_size) |
| 8527 | { |
| 8528 | struct i40e_pf *pf = vsi->back; |
| 8529 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8530 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8531 | u8 i; |
| 8532 | |
| 8533 | /* Fill out hash function seed */ |
| 8534 | if (seed) { |
| 8535 | u32 *seed_dw = (u32 *)seed; |
| 8536 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8537 | if (vsi->type == I40E_VSI_MAIN) { |
| 8538 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8539 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8540 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8541 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8542 | wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8543 | } else { |
| 8544 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8545 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8546 | } |
| 8547 | |
| 8548 | if (lut) { |
| 8549 | u32 *lut_dw = (u32 *)lut; |
| 8550 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8551 | if (vsi->type == I40E_VSI_MAIN) { |
| 8552 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8553 | return -EINVAL; |
| 8554 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8555 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8556 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8557 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8558 | return -EINVAL; |
| 8559 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8560 | wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8561 | } else { |
| 8562 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8563 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8564 | } |
| 8565 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8566 | |
| 8567 | return 0; |
| 8568 | } |
| 8569 | |
| 8570 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8571 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8572 | * @vsi: Pointer to VSI structure |
| 8573 | * @seed: Buffer to store the keys |
| 8574 | * @lut: Buffer to store the lookup table entries |
| 8575 | * @lut_size: Size of buffer to store the lookup table entries |
| 8576 | * |
| 8577 | * Returns 0 on success, negative on failure |
| 8578 | */ |
| 8579 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8580 | u8 *lut, u16 lut_size) |
| 8581 | { |
| 8582 | struct i40e_pf *pf = vsi->back; |
| 8583 | struct i40e_hw *hw = &pf->hw; |
| 8584 | u16 i; |
| 8585 | |
| 8586 | if (seed) { |
| 8587 | u32 *seed_dw = (u32 *)seed; |
| 8588 | |
| 8589 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8590 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8591 | } |
| 8592 | if (lut) { |
| 8593 | u32 *lut_dw = (u32 *)lut; |
| 8594 | |
| 8595 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8596 | return -EINVAL; |
| 8597 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8598 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8599 | } |
| 8600 | |
| 8601 | return 0; |
| 8602 | } |
| 8603 | |
| 8604 | /** |
| 8605 | * i40e_config_rss - Configure RSS keys and lut |
| 8606 | * @vsi: Pointer to VSI structure |
| 8607 | * @seed: RSS hash seed |
| 8608 | * @lut: Lookup table |
| 8609 | * @lut_size: Lookup table size |
| 8610 | * |
| 8611 | * Returns 0 on success, negative on failure |
| 8612 | */ |
| 8613 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8614 | { |
| 8615 | struct i40e_pf *pf = vsi->back; |
| 8616 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8617 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8618 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8619 | else |
| 8620 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8621 | } |
| 8622 | |
| 8623 | /** |
| 8624 | * i40e_get_rss - Get RSS keys and lut |
| 8625 | * @vsi: Pointer to VSI structure |
| 8626 | * @seed: Buffer to store the keys |
| 8627 | * @lut: Buffer to store the lookup table entries |
| 8628 | * lut_size: Size of buffer to store the lookup table entries |
| 8629 | * |
| 8630 | * Returns 0 on success, negative on failure |
| 8631 | */ |
| 8632 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8633 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8634 | struct i40e_pf *pf = vsi->back; |
| 8635 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8636 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8637 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8638 | else |
| 8639 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8640 | } |
| 8641 | |
| 8642 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8643 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8644 | * @pf: Pointer to board private structure |
| 8645 | * @lut: Lookup table |
| 8646 | * @rss_table_size: Lookup table size |
| 8647 | * @rss_size: Range of queue number for hashing |
| 8648 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8649 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8650 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8651 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8652 | u16 i; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8653 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8654 | for (i = 0; i < rss_table_size; i++) |
| 8655 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8656 | } |
| 8657 | |
| 8658 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8659 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8660 | * @pf: board private structure |
| 8661 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8662 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8663 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8664 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8665 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8666 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8667 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8668 | u32 reg_val; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8669 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8670 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8671 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8672 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8673 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8674 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8675 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8676 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8677 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8678 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8679 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8680 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8681 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8682 | reg_val = (pf->rss_table_size == 512) ? |
| 8683 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8684 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8685 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8686 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8687 | /* Determine the RSS size of the VSI */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8688 | if (!vsi->rss_size) { |
| 8689 | u16 qcount; |
| 8690 | |
| 8691 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8692 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
| 8693 | } |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8694 | if (!vsi->rss_size) |
| 8695 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8696 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8697 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8698 | if (!lut) |
| 8699 | return -ENOMEM; |
| 8700 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8701 | /* Use user configured lut if there is one, otherwise use default */ |
| 8702 | if (vsi->rss_lut_user) |
| 8703 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8704 | else |
| 8705 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8706 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8707 | /* Use user configured hash key if there is one, otherwise |
| 8708 | * use default. |
| 8709 | */ |
| 8710 | if (vsi->rss_hkey_user) |
| 8711 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8712 | else |
| 8713 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8714 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8715 | kfree(lut); |
| 8716 | |
| 8717 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8718 | } |
| 8719 | |
| 8720 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8721 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8722 | * @pf: board private structure |
| 8723 | * @queue_count: the requested queue count for rss. |
| 8724 | * |
| 8725 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8726 | * count which may be different from the requested queue count. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8727 | * Note: expects to be called while under rtnl_lock() |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8728 | **/ |
| 8729 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8730 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8731 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8732 | int new_rss_size; |
| 8733 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8734 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8735 | return 0; |
| 8736 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8737 | new_rss_size = min_t(int, queue_count, pf->rss_size_max); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8738 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8739 | if (queue_count != vsi->num_queue_pairs) { |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8740 | u16 qcount; |
| 8741 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8742 | vsi->req_queue_pairs = queue_count; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8743 | i40e_prep_for_reset(pf, true); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8744 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8745 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8746 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8747 | i40e_reset_and_rebuild(pf, true, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8748 | |
| 8749 | /* Discard the user configured hash keys and lut, if less |
| 8750 | * queues are enabled. |
| 8751 | */ |
| 8752 | if (queue_count < vsi->rss_size) { |
| 8753 | i40e_clear_rss_config_user(vsi); |
| 8754 | dev_dbg(&pf->pdev->dev, |
| 8755 | "discard user configured hash keys and lut\n"); |
| 8756 | } |
| 8757 | |
| 8758 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8759 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8760 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8761 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8762 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8763 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8764 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8765 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8766 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8767 | } |
| 8768 | |
| 8769 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8770 | * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8771 | * @pf: board private structure |
| 8772 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8773 | i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8774 | { |
| 8775 | i40e_status status; |
| 8776 | bool min_valid, max_valid; |
| 8777 | u32 max_bw, min_bw; |
| 8778 | |
| 8779 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8780 | &min_valid, &max_valid); |
| 8781 | |
| 8782 | if (!status) { |
| 8783 | if (min_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8784 | pf->min_bw = min_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8785 | if (max_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8786 | pf->max_bw = max_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8787 | } |
| 8788 | |
| 8789 | return status; |
| 8790 | } |
| 8791 | |
| 8792 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8793 | * i40e_set_partition_bw_setting - Set BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8794 | * @pf: board private structure |
| 8795 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8796 | i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8797 | { |
| 8798 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8799 | i40e_status status; |
| 8800 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8801 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8802 | bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id)); |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8803 | bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8804 | bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8805 | |
| 8806 | /* Set the new bandwidths */ |
| 8807 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8808 | |
| 8809 | return status; |
| 8810 | } |
| 8811 | |
| 8812 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8813 | * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8814 | * @pf: board private structure |
| 8815 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8816 | i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8817 | { |
| 8818 | /* Commit temporary BW setting to permanent NVM image */ |
| 8819 | enum i40e_admin_queue_err last_aq_status; |
| 8820 | i40e_status ret; |
| 8821 | u16 nvm_word; |
| 8822 | |
| 8823 | if (pf->hw.partition_id != 1) { |
| 8824 | dev_info(&pf->pdev->dev, |
| 8825 | "Commit BW only works on partition 1! This is partition %d", |
| 8826 | pf->hw.partition_id); |
| 8827 | ret = I40E_NOT_SUPPORTED; |
| 8828 | goto bw_commit_out; |
| 8829 | } |
| 8830 | |
| 8831 | /* Acquire NVM for read access */ |
| 8832 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8833 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8834 | if (ret) { |
| 8835 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8836 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8837 | i40e_stat_str(&pf->hw, ret), |
| 8838 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8839 | goto bw_commit_out; |
| 8840 | } |
| 8841 | |
| 8842 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8843 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8844 | I40E_SR_NVM_CONTROL_WORD, |
| 8845 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8846 | false, NULL); |
| 8847 | /* Save off last admin queue command status before releasing |
| 8848 | * the NVM |
| 8849 | */ |
| 8850 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8851 | i40e_release_nvm(&pf->hw); |
| 8852 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8853 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8854 | i40e_stat_str(&pf->hw, ret), |
| 8855 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8856 | goto bw_commit_out; |
| 8857 | } |
| 8858 | |
| 8859 | /* Wait a bit for NVM release to complete */ |
| 8860 | msleep(50); |
| 8861 | |
| 8862 | /* Acquire NVM for write access */ |
| 8863 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8864 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8865 | if (ret) { |
| 8866 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8867 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8868 | i40e_stat_str(&pf->hw, ret), |
| 8869 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8870 | goto bw_commit_out; |
| 8871 | } |
| 8872 | /* Write it back out unchanged to initiate update NVM, |
| 8873 | * which will force a write of the shadow (alt) RAM to |
| 8874 | * the NVM - thus storing the bandwidth values permanently. |
| 8875 | */ |
| 8876 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8877 | I40E_SR_NVM_CONTROL_WORD, |
| 8878 | 0x10, sizeof(nvm_word), |
| 8879 | &nvm_word, true, NULL); |
| 8880 | /* Save off last admin queue command status before releasing |
| 8881 | * the NVM |
| 8882 | */ |
| 8883 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8884 | i40e_release_nvm(&pf->hw); |
| 8885 | if (ret) |
| 8886 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8887 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8888 | i40e_stat_str(&pf->hw, ret), |
| 8889 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8890 | bw_commit_out: |
| 8891 | |
| 8892 | return ret; |
| 8893 | } |
| 8894 | |
| 8895 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8896 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8897 | * @pf: board private structure to initialize |
| 8898 | * |
| 8899 | * i40e_sw_init initializes the Adapter private data structure. |
| 8900 | * Fields are initialized based on PCI device information and |
| 8901 | * OS network device settings (MTU size). |
| 8902 | **/ |
| 8903 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8904 | { |
| 8905 | int err = 0; |
| 8906 | int size; |
| 8907 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8908 | /* Set default capability flags */ |
| 8909 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8910 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8911 | I40E_FLAG_MSIX_ENABLED; |
| 8912 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8913 | /* Set default ITR */ |
| 8914 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8915 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8916 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8917 | /* Depending on PF configurations, it is possible that the RSS |
| 8918 | * maximum might end up larger than the available queues |
| 8919 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8920 | pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8921 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8922 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8923 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8924 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8925 | if (pf->hw.func_caps.rss) { |
| 8926 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8927 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8928 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8929 | } |
| 8930 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8931 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8932 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) { |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8933 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8934 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8935 | if (i40e_get_partition_bw_setting(pf)) { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8936 | dev_warn(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8937 | "Could not get partition bw settings\n"); |
| 8938 | } else { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8939 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8940 | "Partition BW Min = %8.8x, Max = %8.8x\n", |
| 8941 | pf->min_bw, pf->max_bw); |
| 8942 | |
| 8943 | /* nudge the Tx scheduler */ |
| 8944 | i40e_set_partition_bw_setting(pf); |
| 8945 | } |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8946 | } |
| 8947 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8948 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8949 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8950 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8951 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8952 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8953 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8954 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8955 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8956 | else |
| 8957 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8958 | pf->fdir_pf_filter_count = |
| 8959 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8960 | pf->hw.fdir_shared_filter_count = |
| 8961 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8962 | } |
| 8963 | |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 8964 | if (pf->hw.mac.type == I40E_MAC_X722) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8965 | pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE | |
| 8966 | I40E_HW_128_QP_RSS_CAPABLE | |
| 8967 | I40E_HW_ATR_EVICT_CAPABLE | |
| 8968 | I40E_HW_WB_ON_ITR_CAPABLE | |
| 8969 | I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
| 8970 | I40E_HW_NO_PCI_LINK_CHECK | |
| 8971 | I40E_HW_USE_SET_LLDP_MIB | |
| 8972 | I40E_HW_GENEVE_OFFLOAD_CAPABLE | |
| 8973 | I40E_HW_PTP_L4_CAPABLE | |
| 8974 | I40E_HW_WOL_MC_MAGIC_PKT_WAKE | |
| 8975 | I40E_HW_OUTER_UDP_CSUM_CAPABLE); |
Anjali Singhai Jain | 10a955f | 2017-06-23 04:24:48 -0400 | [diff] [blame] | 8976 | |
| 8977 | #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03 |
| 8978 | if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) != |
| 8979 | I40E_FDEVICT_PCTYPE_DEFAULT) { |
| 8980 | dev_warn(&pf->pdev->dev, |
| 8981 | "FD EVICT PCTYPES are not right, disable FD HW EVICT\n"); |
| 8982 | pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE; |
| 8983 | } |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 8984 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8985 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8986 | (pf->hw.aq.api_min_ver > 4))) { |
| 8987 | /* Supported in FW API version higher than 1.4 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8988 | pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 8989 | } |
| 8990 | |
| 8991 | /* Enable HW ATR eviction if possible */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8992 | if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE) |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 8993 | pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED; |
| 8994 | |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8995 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8996 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8997 | (pf->hw.aq.fw_maj_ver < 4))) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8998 | pf->hw_features |= I40E_HW_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8999 | /* No DCB support for FW < v4.33 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9000 | pf->hw_features |= I40E_HW_NO_DCB_SUPPORT; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9001 | } |
| 9002 | |
| 9003 | /* Disable FW LLDP if FW < v4.3 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 9004 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9005 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 9006 | (pf->hw.aq.fw_maj_ver < 4))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9007 | pf->hw_features |= I40E_HW_STOP_FW_LLDP; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9008 | |
| 9009 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 9010 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9011 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 9012 | (pf->hw.aq.fw_maj_ver >= 5))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9013 | pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 9014 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9015 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9016 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9017 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 9018 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9019 | } |
| 9020 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9021 | if (pf->hw.func_caps.iwarp) { |
| 9022 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 9023 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 9024 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 9025 | } |
| 9026 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9027 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 9028 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9029 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 9030 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 9031 | pf->num_req_vfs = min_t(int, |
| 9032 | pf->hw.func_caps.num_vfs, |
| 9033 | I40E_MAX_VF_COUNT); |
| 9034 | } |
| 9035 | #endif /* CONFIG_PCI_IOV */ |
| 9036 | pf->eeprom_version = 0xDEAD; |
| 9037 | pf->lan_veb = I40E_NO_VEB; |
| 9038 | pf->lan_vsi = I40E_NO_VSI; |
| 9039 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 9040 | /* By default FW has this off for performance reasons */ |
| 9041 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 9042 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9043 | /* set up queue assignment tracking */ |
| 9044 | size = sizeof(struct i40e_lump_tracking) |
| 9045 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 9046 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 9047 | if (!pf->qp_pile) { |
| 9048 | err = -ENOMEM; |
| 9049 | goto sw_init_done; |
| 9050 | } |
| 9051 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 9052 | pf->qp_pile->search_hint = 0; |
| 9053 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 9054 | pf->tx_timeout_recovery_level = 1; |
| 9055 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9056 | mutex_init(&pf->switch_mutex); |
| 9057 | |
| 9058 | sw_init_done: |
| 9059 | return err; |
| 9060 | } |
| 9061 | |
| 9062 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9063 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 9064 | * @pf: board private structure to initialize |
| 9065 | * @features: the feature set that the stack is suggesting |
| 9066 | * |
| 9067 | * returns a bool to indicate if reset needs to happen |
| 9068 | **/ |
| 9069 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 9070 | { |
| 9071 | bool need_reset = false; |
| 9072 | |
| 9073 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 9074 | * the state changed, we need to reset. |
| 9075 | */ |
| 9076 | if (features & NETIF_F_NTUPLE) { |
| 9077 | /* Enable filters and mark for reset */ |
| 9078 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 9079 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 9080 | /* enable FD_SB only if there is MSI-X vector */ |
| 9081 | if (pf->num_fdsb_msix > 0) |
| 9082 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9083 | } else { |
| 9084 | /* turn off filters, mark for reset and clear SW filter list */ |
| 9085 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9086 | need_reset = true; |
| 9087 | i40e_fdir_filter_exit(pf); |
| 9088 | } |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 9089 | pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED | |
| 9090 | I40E_FLAG_FD_SB_AUTO_DISABLED); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 9091 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 9092 | pf->fd_add_err = 0; |
| 9093 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 9094 | /* if ATR was auto disabled it can be re-enabled. */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 9095 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 9096 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 9097 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 9098 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 9099 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 9100 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9101 | } |
| 9102 | return need_reset; |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 9106 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 9107 | * @vsi: the VSI being configured |
| 9108 | **/ |
| 9109 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 9110 | { |
| 9111 | struct i40e_pf *pf = vsi->back; |
| 9112 | struct i40e_hw *hw = &pf->hw; |
| 9113 | u16 vf_id = vsi->vf_id; |
| 9114 | u8 i; |
| 9115 | |
| 9116 | if (vsi->type == I40E_VSI_MAIN) { |
| 9117 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 9118 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 9119 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 9120 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 9121 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 9122 | } else { |
| 9123 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9128 | * i40e_set_features - set the netdev feature flags |
| 9129 | * @netdev: ptr to the netdev being adjusted |
| 9130 | * @features: the feature set that the stack is suggesting |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9131 | * Note: expects to be called while under rtnl_lock() |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9132 | **/ |
| 9133 | static int i40e_set_features(struct net_device *netdev, |
| 9134 | netdev_features_t features) |
| 9135 | { |
| 9136 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9137 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9138 | struct i40e_pf *pf = vsi->back; |
| 9139 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9140 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 9141 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 9142 | i40e_pf_config_rss(pf); |
| 9143 | else if (!(features & NETIF_F_RXHASH) && |
| 9144 | netdev->features & NETIF_F_RXHASH) |
| 9145 | i40e_clear_rss_lut(vsi); |
| 9146 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9147 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 9148 | i40e_vlan_stripping_enable(vsi); |
| 9149 | else |
| 9150 | i40e_vlan_stripping_disable(vsi); |
| 9151 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9152 | need_reset = i40e_set_ntuple(pf, features); |
| 9153 | |
| 9154 | if (need_reset) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9155 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9156 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9157 | return 0; |
| 9158 | } |
| 9159 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9160 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9161 | * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9162 | * @pf: board private structure |
| 9163 | * @port: The UDP port to look up |
| 9164 | * |
| 9165 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 9166 | **/ |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9167 | static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9168 | { |
| 9169 | u8 i; |
| 9170 | |
| 9171 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9172 | if (pf->udp_ports[i].port == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9173 | return i; |
| 9174 | } |
| 9175 | |
| 9176 | return i; |
| 9177 | } |
| 9178 | |
| 9179 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9180 | * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9181 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9182 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9183 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9184 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 9185 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9186 | { |
| 9187 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9188 | struct i40e_vsi *vsi = np->vsi; |
| 9189 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9190 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9191 | u8 next_idx; |
| 9192 | u8 idx; |
| 9193 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9194 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9195 | |
| 9196 | /* Check if port already exists */ |
| 9197 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9198 | netdev_info(netdev, "port %d already offloaded\n", port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9199 | return; |
| 9200 | } |
| 9201 | |
| 9202 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9203 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9204 | |
| 9205 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9206 | netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9207 | port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9208 | return; |
| 9209 | } |
| 9210 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9211 | switch (ti->type) { |
| 9212 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9213 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 9214 | break; |
| 9215 | case UDP_TUNNEL_TYPE_GENEVE: |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9216 | if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE)) |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9217 | return; |
| 9218 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 9219 | break; |
| 9220 | default: |
| 9221 | return; |
| 9222 | } |
| 9223 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9224 | /* New port: add it and mark its index in the bitmap */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9225 | pf->udp_ports[next_idx].port = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9226 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 9227 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9228 | } |
| 9229 | |
| 9230 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9231 | * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9232 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9233 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9234 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9235 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 9236 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9237 | { |
| 9238 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9239 | struct i40e_vsi *vsi = np->vsi; |
| 9240 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9241 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9242 | u8 idx; |
| 9243 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9244 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9245 | |
| 9246 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9247 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 9248 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9249 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9250 | switch (ti->type) { |
| 9251 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9252 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 9253 | goto not_found; |
| 9254 | break; |
| 9255 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9256 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 9257 | goto not_found; |
| 9258 | break; |
| 9259 | default: |
| 9260 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9261 | } |
| 9262 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9263 | /* if port exists, set it to 0 (mark for deletion) |
| 9264 | * and make it pending |
| 9265 | */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9266 | pf->udp_ports[idx].port = 0; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9267 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9268 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 9269 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9270 | return; |
| 9271 | not_found: |
| 9272 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9273 | port); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9274 | } |
| 9275 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9276 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 9277 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9278 | { |
| 9279 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9280 | struct i40e_pf *pf = np->vsi->back; |
| 9281 | struct i40e_hw *hw = &pf->hw; |
| 9282 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9283 | if (!(pf->hw_features & I40E_HW_PORT_ID_VALID)) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9284 | return -EOPNOTSUPP; |
| 9285 | |
| 9286 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 9287 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 9288 | |
| 9289 | return 0; |
| 9290 | } |
| 9291 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 9292 | /** |
| 9293 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 9294 | * @ndm: the input from the stack |
| 9295 | * @tb: pointer to array of nladdr (unused) |
| 9296 | * @dev: the net device pointer |
| 9297 | * @addr: the MAC address entry being added |
| 9298 | * @flags: instructions from stack about fdb operation |
| 9299 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9300 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 9301 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9302 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9303 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9304 | { |
| 9305 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9306 | struct i40e_pf *pf = np->vsi->back; |
| 9307 | int err = 0; |
| 9308 | |
| 9309 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 9310 | return -EOPNOTSUPP; |
| 9311 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 9312 | if (vid) { |
| 9313 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 9314 | return -EINVAL; |
| 9315 | } |
| 9316 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9317 | /* Hardware does not support aging addresses so if a |
| 9318 | * ndm_state is given only allow permanent addresses |
| 9319 | */ |
| 9320 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 9321 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 9322 | return -EINVAL; |
| 9323 | } |
| 9324 | |
| 9325 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 9326 | err = dev_uc_add_excl(dev, addr); |
| 9327 | else if (is_multicast_ether_addr(addr)) |
| 9328 | err = dev_mc_add_excl(dev, addr); |
| 9329 | else |
| 9330 | err = -EINVAL; |
| 9331 | |
| 9332 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 9333 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 9334 | err = 0; |
| 9335 | |
| 9336 | return err; |
| 9337 | } |
| 9338 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9339 | /** |
| 9340 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 9341 | * @dev: the netdev being configured |
| 9342 | * @nlh: RTNL message |
| 9343 | * |
| 9344 | * Inserts a new hardware bridge if not already created and |
| 9345 | * enables the bridging mode requested (VEB or VEPA). If the |
| 9346 | * hardware bridge has already been inserted and the request |
| 9347 | * is to change the mode then that requires a PF reset to |
| 9348 | * allow rebuild of the components with required hardware |
| 9349 | * bridge mode enabled. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9350 | * |
| 9351 | * Note: expects to be called while under rtnl_lock() |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9352 | **/ |
| 9353 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 9354 | struct nlmsghdr *nlh, |
| 9355 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9356 | { |
| 9357 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9358 | struct i40e_vsi *vsi = np->vsi; |
| 9359 | struct i40e_pf *pf = vsi->back; |
| 9360 | struct i40e_veb *veb = NULL; |
| 9361 | struct nlattr *attr, *br_spec; |
| 9362 | int i, rem; |
| 9363 | |
| 9364 | /* Only for PF VSI for now */ |
| 9365 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9366 | return -EOPNOTSUPP; |
| 9367 | |
| 9368 | /* Find the HW bridge for PF VSI */ |
| 9369 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9370 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9371 | veb = pf->veb[i]; |
| 9372 | } |
| 9373 | |
| 9374 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9375 | |
| 9376 | nla_for_each_nested(attr, br_spec, rem) { |
| 9377 | __u16 mode; |
| 9378 | |
| 9379 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9380 | continue; |
| 9381 | |
| 9382 | mode = nla_get_u16(attr); |
| 9383 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9384 | (mode != BRIDGE_MODE_VEB)) |
| 9385 | return -EINVAL; |
| 9386 | |
| 9387 | /* Insert a new HW bridge */ |
| 9388 | if (!veb) { |
| 9389 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9390 | vsi->tc_config.enabled_tc); |
| 9391 | if (veb) { |
| 9392 | veb->bridge_mode = mode; |
| 9393 | i40e_config_bridge_mode(veb); |
| 9394 | } else { |
| 9395 | /* No Bridge HW offload available */ |
| 9396 | return -ENOENT; |
| 9397 | } |
| 9398 | break; |
| 9399 | } else if (mode != veb->bridge_mode) { |
| 9400 | /* Existing HW bridge but different mode needs reset */ |
| 9401 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9402 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9403 | if (mode == BRIDGE_MODE_VEB) |
| 9404 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9405 | else |
| 9406 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9407 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), |
| 9408 | true); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9409 | break; |
| 9410 | } |
| 9411 | } |
| 9412 | |
| 9413 | return 0; |
| 9414 | } |
| 9415 | |
| 9416 | /** |
| 9417 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9418 | * @skb: skb buff |
| 9419 | * @pid: process id |
| 9420 | * @seq: RTNL message seq # |
| 9421 | * @dev: the netdev being configured |
| 9422 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9423 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9424 | * |
| 9425 | * Return the mode in which the hardware bridge is operating in |
| 9426 | * i.e VEB or VEPA. |
| 9427 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9428 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9429 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9430 | u32 __always_unused filter_mask, |
| 9431 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9432 | { |
| 9433 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9434 | struct i40e_vsi *vsi = np->vsi; |
| 9435 | struct i40e_pf *pf = vsi->back; |
| 9436 | struct i40e_veb *veb = NULL; |
| 9437 | int i; |
| 9438 | |
| 9439 | /* Only for PF VSI for now */ |
| 9440 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9441 | return -EOPNOTSUPP; |
| 9442 | |
| 9443 | /* Find the HW bridge for the PF VSI */ |
| 9444 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9445 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9446 | veb = pf->veb[i]; |
| 9447 | } |
| 9448 | |
| 9449 | if (!veb) |
| 9450 | return 0; |
| 9451 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9452 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9453 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9454 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9455 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9456 | /** |
| 9457 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9458 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9459 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9460 | * @features: Offload features that the stack believes apply |
| 9461 | **/ |
| 9462 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9463 | struct net_device *dev, |
| 9464 | netdev_features_t features) |
| 9465 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9466 | size_t len; |
| 9467 | |
| 9468 | /* No point in doing any of this if neither checksum nor GSO are |
| 9469 | * being requested for this frame. We can rule out both by just |
| 9470 | * checking for CHECKSUM_PARTIAL |
| 9471 | */ |
| 9472 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9473 | return features; |
| 9474 | |
| 9475 | /* We cannot support GSO if the MSS is going to be less than |
| 9476 | * 64 bytes. If it is then we need to drop support for GSO. |
| 9477 | */ |
| 9478 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 9479 | features &= ~NETIF_F_GSO_MASK; |
| 9480 | |
| 9481 | /* MACLEN can support at most 63 words */ |
| 9482 | len = skb_network_header(skb) - skb->data; |
| 9483 | if (len & ~(63 * 2)) |
| 9484 | goto out_err; |
| 9485 | |
| 9486 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 9487 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 9488 | if (len & ~(127 * 4)) |
| 9489 | goto out_err; |
| 9490 | |
| 9491 | if (skb->encapsulation) { |
| 9492 | /* L4TUNLEN can support 127 words */ |
| 9493 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 9494 | if (len & ~(127 * 2)) |
| 9495 | goto out_err; |
| 9496 | |
| 9497 | /* IPLEN can support at most 127 dwords */ |
| 9498 | len = skb_inner_transport_header(skb) - |
| 9499 | skb_inner_network_header(skb); |
| 9500 | if (len & ~(127 * 4)) |
| 9501 | goto out_err; |
| 9502 | } |
| 9503 | |
| 9504 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 9505 | * a flexible value and we support all possible values supported |
| 9506 | * by TCP, which is at most 15 dwords |
| 9507 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9508 | |
| 9509 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9510 | out_err: |
| 9511 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9512 | } |
| 9513 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 9514 | /** |
| 9515 | * i40e_xdp_setup - add/remove an XDP program |
| 9516 | * @vsi: VSI to changed |
| 9517 | * @prog: XDP program |
| 9518 | **/ |
| 9519 | static int i40e_xdp_setup(struct i40e_vsi *vsi, |
| 9520 | struct bpf_prog *prog) |
| 9521 | { |
| 9522 | int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 9523 | struct i40e_pf *pf = vsi->back; |
| 9524 | struct bpf_prog *old_prog; |
| 9525 | bool need_reset; |
| 9526 | int i; |
| 9527 | |
| 9528 | /* Don't allow frames that span over multiple buffers */ |
| 9529 | if (frame_size > vsi->rx_buf_len) |
| 9530 | return -EINVAL; |
| 9531 | |
| 9532 | if (!i40e_enabled_xdp_vsi(vsi) && !prog) |
| 9533 | return 0; |
| 9534 | |
| 9535 | /* When turning XDP on->off/off->on we reset and rebuild the rings. */ |
| 9536 | need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog); |
| 9537 | |
| 9538 | if (need_reset) |
| 9539 | i40e_prep_for_reset(pf, true); |
| 9540 | |
| 9541 | old_prog = xchg(&vsi->xdp_prog, prog); |
| 9542 | |
| 9543 | if (need_reset) |
| 9544 | i40e_reset_and_rebuild(pf, true, true); |
| 9545 | |
| 9546 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 9547 | WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); |
| 9548 | |
| 9549 | if (old_prog) |
| 9550 | bpf_prog_put(old_prog); |
| 9551 | |
| 9552 | return 0; |
| 9553 | } |
| 9554 | |
| 9555 | /** |
| 9556 | * i40e_xdp - implements ndo_xdp for i40e |
| 9557 | * @dev: netdevice |
| 9558 | * @xdp: XDP command |
| 9559 | **/ |
| 9560 | static int i40e_xdp(struct net_device *dev, |
| 9561 | struct netdev_xdp *xdp) |
| 9562 | { |
| 9563 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9564 | struct i40e_vsi *vsi = np->vsi; |
| 9565 | |
| 9566 | if (vsi->type != I40E_VSI_MAIN) |
| 9567 | return -EINVAL; |
| 9568 | |
| 9569 | switch (xdp->command) { |
| 9570 | case XDP_SETUP_PROG: |
| 9571 | return i40e_xdp_setup(vsi, xdp->prog); |
| 9572 | case XDP_QUERY_PROG: |
| 9573 | xdp->prog_attached = i40e_enabled_xdp_vsi(vsi); |
Daniel Borkmann | eb23039 | 2017-06-24 21:13:52 +0200 | [diff] [blame] | 9574 | xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0; |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 9575 | return 0; |
| 9576 | default: |
| 9577 | return -EINVAL; |
| 9578 | } |
| 9579 | } |
| 9580 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9581 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9582 | .ndo_open = i40e_open, |
| 9583 | .ndo_stop = i40e_close, |
| 9584 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9585 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9586 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9587 | .ndo_validate_addr = eth_validate_addr, |
| 9588 | .ndo_set_mac_address = i40e_set_mac, |
| 9589 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9590 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9591 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9592 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9593 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9594 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9595 | .ndo_poll_controller = i40e_netpoll, |
| 9596 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9597 | .ndo_setup_tc = __i40e_setup_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9598 | .ndo_set_features = i40e_set_features, |
| 9599 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9600 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9601 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9602 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9603 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9604 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9605 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9606 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9607 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9608 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9609 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9610 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9611 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9612 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 9613 | .ndo_xdp = i40e_xdp, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9614 | }; |
| 9615 | |
| 9616 | /** |
| 9617 | * i40e_config_netdev - Setup the netdev flags |
| 9618 | * @vsi: the VSI being configured |
| 9619 | * |
| 9620 | * Returns 0 on success, negative value on failure |
| 9621 | **/ |
| 9622 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9623 | { |
| 9624 | struct i40e_pf *pf = vsi->back; |
| 9625 | struct i40e_hw *hw = &pf->hw; |
| 9626 | struct i40e_netdev_priv *np; |
| 9627 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9628 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9629 | u8 mac_addr[ETH_ALEN]; |
| 9630 | int etherdev_size; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9631 | netdev_features_t hw_enc_features; |
| 9632 | netdev_features_t hw_features; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9633 | |
| 9634 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9635 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9636 | if (!netdev) |
| 9637 | return -ENOMEM; |
| 9638 | |
| 9639 | vsi->netdev = netdev; |
| 9640 | np = netdev_priv(netdev); |
| 9641 | np->vsi = vsi; |
| 9642 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9643 | hw_enc_features = NETIF_F_SG | |
| 9644 | NETIF_F_IP_CSUM | |
| 9645 | NETIF_F_IPV6_CSUM | |
| 9646 | NETIF_F_HIGHDMA | |
| 9647 | NETIF_F_SOFT_FEATURES | |
| 9648 | NETIF_F_TSO | |
| 9649 | NETIF_F_TSO_ECN | |
| 9650 | NETIF_F_TSO6 | |
| 9651 | NETIF_F_GSO_GRE | |
| 9652 | NETIF_F_GSO_GRE_CSUM | |
| 9653 | NETIF_F_GSO_PARTIAL | |
| 9654 | NETIF_F_GSO_UDP_TUNNEL | |
| 9655 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 9656 | NETIF_F_SCTP_CRC | |
| 9657 | NETIF_F_RXHASH | |
| 9658 | NETIF_F_RXCSUM | |
| 9659 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9660 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9661 | if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9662 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9663 | |
| 9664 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9665 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9666 | netdev->hw_enc_features |= hw_enc_features; |
| 9667 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9668 | /* record features VLANs can make use of */ |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9669 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9670 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9671 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9672 | netdev->hw_features |= NETIF_F_NTUPLE; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9673 | hw_features = hw_enc_features | |
| 9674 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9675 | NETIF_F_HW_VLAN_CTAG_RX; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9676 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9677 | netdev->hw_features |= hw_features; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9678 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9679 | netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9680 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9681 | |
| 9682 | if (vsi->type == I40E_VSI_MAIN) { |
| 9683 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9684 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 9685 | /* The following steps are necessary for two reasons. First, |
| 9686 | * some older NVM configurations load a default MAC-VLAN |
| 9687 | * filter that will accept any tagged packet, and we want to |
| 9688 | * replace this with a normal filter. Additionally, it is |
| 9689 | * possible our MAC address was provided by the platform using |
| 9690 | * Open Firmware or similar. |
| 9691 | * |
| 9692 | * Thus, we need to remove the default filter and install one |
| 9693 | * specific to the MAC address. |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9694 | */ |
| 9695 | i40e_rm_default_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9696 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9697 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9698 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9699 | } else { |
Jacob Keller | 8c9eb35 | 2017-07-12 05:46:12 -0400 | [diff] [blame] | 9700 | /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we |
| 9701 | * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to |
| 9702 | * the end, which is 4 bytes long, so force truncation of the |
| 9703 | * original name by IFNAMSIZ - 4 |
| 9704 | */ |
| 9705 | snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d", |
| 9706 | IFNAMSIZ - 4, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9707 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9708 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9709 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9710 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9711 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9712 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9713 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9714 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9715 | /* Add the broadcast filter so that we initially will receive |
| 9716 | * broadcast packets. Note that when a new VLAN is first added the |
| 9717 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 9718 | * specific filters as part of transitioning into "vlan" operation. |
| 9719 | * When more VLANs are added, the driver will copy each existing MAC |
| 9720 | * filter and add it for the new VLAN. |
| 9721 | * |
| 9722 | * Broadcast filters are handled specially by |
| 9723 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 9724 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 9725 | * filter. The subtask will update the correct broadcast promiscuous |
| 9726 | * bits as VLANs become active or inactive. |
| 9727 | */ |
| 9728 | eth_broadcast_addr(broadcast); |
| 9729 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9730 | i40e_add_mac_filter(vsi, broadcast); |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9731 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 9732 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9733 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9734 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9735 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9736 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9737 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9738 | /* Setup netdev TC information */ |
| 9739 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9740 | |
| 9741 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9742 | netdev->watchdog_timeo = 5 * HZ; |
| 9743 | i40e_set_ethtool_ops(netdev); |
| 9744 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9745 | /* MTU range: 68 - 9706 */ |
| 9746 | netdev->min_mtu = ETH_MIN_MTU; |
Mitch Williams | 1e3a5fd | 2017-06-23 04:24:43 -0400 | [diff] [blame] | 9747 | netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD; |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9748 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9749 | return 0; |
| 9750 | } |
| 9751 | |
| 9752 | /** |
| 9753 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9754 | * @vsi: the VSI being removed |
| 9755 | * |
| 9756 | * Returns 0 on success, negative value on failure |
| 9757 | **/ |
| 9758 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9759 | { |
| 9760 | /* remove default VSI is not allowed */ |
| 9761 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9762 | return; |
| 9763 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9764 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9765 | } |
| 9766 | |
| 9767 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9768 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9769 | * @vsi: the VSI being queried |
| 9770 | * |
| 9771 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9772 | **/ |
| 9773 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9774 | { |
| 9775 | struct i40e_veb *veb; |
| 9776 | struct i40e_pf *pf = vsi->back; |
| 9777 | |
| 9778 | /* Uplink is not a bridge so default to VEB */ |
| 9779 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9780 | return 1; |
| 9781 | |
| 9782 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9783 | if (!veb) { |
| 9784 | dev_info(&pf->pdev->dev, |
| 9785 | "There is no veb associated with the bridge\n"); |
| 9786 | return -ENOENT; |
| 9787 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9788 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9789 | /* Uplink is a bridge in VEPA mode */ |
| 9790 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9791 | return 0; |
| 9792 | } else { |
| 9793 | /* Uplink is a bridge in VEB mode */ |
| 9794 | return 1; |
| 9795 | } |
| 9796 | |
| 9797 | /* VEPA is now default bridge, so return 0 */ |
| 9798 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9799 | } |
| 9800 | |
| 9801 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9802 | * i40e_add_vsi - Add a VSI to the switch |
| 9803 | * @vsi: the VSI being configured |
| 9804 | * |
| 9805 | * This initializes a VSI context depending on the VSI type to be added and |
| 9806 | * passes it down to the add_vsi aq command. |
| 9807 | **/ |
| 9808 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9809 | { |
| 9810 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9811 | struct i40e_pf *pf = vsi->back; |
| 9812 | struct i40e_hw *hw = &pf->hw; |
| 9813 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9814 | struct i40e_mac_filter *f; |
| 9815 | struct hlist_node *h; |
| 9816 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9817 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9818 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9819 | int f_count = 0; |
| 9820 | |
| 9821 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9822 | switch (vsi->type) { |
| 9823 | case I40E_VSI_MAIN: |
| 9824 | /* The PF's main VSI is already setup as part of the |
| 9825 | * device initialization, so we'll not bother with |
| 9826 | * the add_vsi call, but we will retrieve the current |
| 9827 | * VSI context. |
| 9828 | */ |
| 9829 | ctxt.seid = pf->main_vsi_seid; |
| 9830 | ctxt.pf_num = pf->hw.pf_id; |
| 9831 | ctxt.vf_num = 0; |
| 9832 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9833 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9834 | if (ret) { |
| 9835 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9836 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9837 | i40e_stat_str(&pf->hw, ret), |
| 9838 | i40e_aq_str(&pf->hw, |
| 9839 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9840 | return -ENOENT; |
| 9841 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9842 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9843 | vsi->info.valid_sections = 0; |
| 9844 | |
| 9845 | vsi->seid = ctxt.seid; |
| 9846 | vsi->id = ctxt.vsi_number; |
| 9847 | |
| 9848 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9849 | |
| 9850 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9851 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9852 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9853 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9854 | ctxt.seid = pf->main_vsi_seid; |
| 9855 | ctxt.pf_num = pf->hw.pf_id; |
| 9856 | ctxt.vf_num = 0; |
| 9857 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9858 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9859 | if (ret) { |
| 9860 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9861 | "update vsi failed, err %s aq_err %s\n", |
| 9862 | i40e_stat_str(&pf->hw, ret), |
| 9863 | i40e_aq_str(&pf->hw, |
| 9864 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9865 | ret = -ENOENT; |
| 9866 | goto err; |
| 9867 | } |
| 9868 | /* update the local VSI info queue map */ |
| 9869 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9870 | vsi->info.valid_sections = 0; |
| 9871 | } else { |
| 9872 | /* Default/Main VSI is only enabled for TC0 |
| 9873 | * reconfigure it to enable all TCs that are |
| 9874 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9875 | * For MFP case the iSCSI PF would use this |
| 9876 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9877 | */ |
| 9878 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9879 | if (ret) { |
Carolyn Wyborny | 1927923 | 2017-07-14 09:10:07 -0400 | [diff] [blame] | 9880 | /* Single TC condition is not fatal, |
| 9881 | * message and continue |
| 9882 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9883 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9884 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9885 | enabled_tc, |
| 9886 | i40e_stat_str(&pf->hw, ret), |
| 9887 | i40e_aq_str(&pf->hw, |
| 9888 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9889 | } |
| 9890 | } |
| 9891 | break; |
| 9892 | |
| 9893 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9894 | ctxt.pf_num = hw->pf_id; |
| 9895 | ctxt.vf_num = 0; |
| 9896 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9897 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9898 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9899 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9900 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9901 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9902 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9903 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9904 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9905 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9906 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9907 | break; |
| 9908 | |
| 9909 | case I40E_VSI_VMDQ2: |
| 9910 | ctxt.pf_num = hw->pf_id; |
| 9911 | ctxt.vf_num = 0; |
| 9912 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9913 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9914 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9915 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9916 | /* This VSI is connected to VEB so the switch_id |
| 9917 | * should be set to zero by default. |
| 9918 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9919 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9920 | ctxt.info.valid_sections |= |
| 9921 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9922 | ctxt.info.switch_id = |
| 9923 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9924 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9925 | |
| 9926 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9927 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9928 | break; |
| 9929 | |
| 9930 | case I40E_VSI_SRIOV: |
| 9931 | ctxt.pf_num = hw->pf_id; |
| 9932 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9933 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9934 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9935 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9936 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9937 | /* This VSI is connected to VEB so the switch_id |
| 9938 | * should be set to zero by default. |
| 9939 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9940 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9941 | ctxt.info.valid_sections |= |
| 9942 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9943 | ctxt.info.switch_id = |
| 9944 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9945 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9946 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9947 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9948 | ctxt.info.valid_sections |= |
| 9949 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9950 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9951 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9952 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9953 | } |
| 9954 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9955 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9956 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9957 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9958 | ctxt.info.valid_sections |= |
| 9959 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9960 | ctxt.info.sec_flags |= |
| 9961 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9962 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9963 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9964 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9965 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9966 | break; |
| 9967 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9968 | case I40E_VSI_IWARP: |
| 9969 | /* send down message to iWARP */ |
| 9970 | break; |
| 9971 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9972 | default: |
| 9973 | return -ENODEV; |
| 9974 | } |
| 9975 | |
| 9976 | if (vsi->type != I40E_VSI_MAIN) { |
| 9977 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9978 | if (ret) { |
| 9979 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9980 | "add vsi failed, err %s aq_err %s\n", |
| 9981 | i40e_stat_str(&pf->hw, ret), |
| 9982 | i40e_aq_str(&pf->hw, |
| 9983 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9984 | ret = -ENOENT; |
| 9985 | goto err; |
| 9986 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9987 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9988 | vsi->info.valid_sections = 0; |
| 9989 | vsi->seid = ctxt.seid; |
| 9990 | vsi->id = ctxt.vsi_number; |
| 9991 | } |
| 9992 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9993 | vsi->active_filters = 0; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 9994 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9995 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9996 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9997 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9998 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9999 | f_count++; |
| 10000 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10001 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10002 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10003 | if (f_count) { |
| 10004 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 10005 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 10006 | } |
| 10007 | |
| 10008 | /* Update VSI BW information */ |
| 10009 | ret = i40e_vsi_get_bw_info(vsi); |
| 10010 | if (ret) { |
| 10011 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10012 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 10013 | i40e_stat_str(&pf->hw, ret), |
| 10014 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10015 | /* VSI is already added so not tearing that up */ |
| 10016 | ret = 0; |
| 10017 | } |
| 10018 | |
| 10019 | err: |
| 10020 | return ret; |
| 10021 | } |
| 10022 | |
| 10023 | /** |
| 10024 | * i40e_vsi_release - Delete a VSI and free its resources |
| 10025 | * @vsi: the VSI being removed |
| 10026 | * |
| 10027 | * Returns 0 on success or < 0 on error |
| 10028 | **/ |
| 10029 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 10030 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10031 | struct i40e_mac_filter *f; |
| 10032 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10033 | struct i40e_veb *veb = NULL; |
| 10034 | struct i40e_pf *pf; |
| 10035 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10036 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10037 | |
| 10038 | pf = vsi->back; |
| 10039 | |
| 10040 | /* release of a VEB-owner or last VSI is not allowed */ |
| 10041 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 10042 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 10043 | vsi->seid, vsi->uplink_seid); |
| 10044 | return -ENODEV; |
| 10045 | } |
| 10046 | if (vsi == pf->vsi[pf->lan_vsi] && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 10047 | !test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10048 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 10049 | return -ENODEV; |
| 10050 | } |
| 10051 | |
| 10052 | uplink_seid = vsi->uplink_seid; |
| 10053 | if (vsi->type != I40E_VSI_SRIOV) { |
| 10054 | if (vsi->netdev_registered) { |
| 10055 | vsi->netdev_registered = false; |
| 10056 | if (vsi->netdev) { |
| 10057 | /* results in a call to i40e_close() */ |
| 10058 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10059 | } |
| 10060 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 10061 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10062 | } |
| 10063 | i40e_vsi_disable_irq(vsi); |
| 10064 | } |
| 10065 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10066 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 10067 | |
| 10068 | /* clear the sync flag on all filters */ |
| 10069 | if (vsi->netdev) { |
| 10070 | __dev_uc_unsync(vsi->netdev, NULL); |
| 10071 | __dev_mc_unsync(vsi->netdev, NULL); |
| 10072 | } |
| 10073 | |
| 10074 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10075 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 10076 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 10077 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10078 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10079 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 10080 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10081 | |
| 10082 | i40e_vsi_delete(vsi); |
| 10083 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 10084 | if (vsi->netdev) { |
| 10085 | free_netdev(vsi->netdev); |
| 10086 | vsi->netdev = NULL; |
| 10087 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10088 | i40e_vsi_clear_rings(vsi); |
| 10089 | i40e_vsi_clear(vsi); |
| 10090 | |
| 10091 | /* If this was the last thing on the VEB, except for the |
| 10092 | * controlling VSI, remove the VEB, which puts the controlling |
| 10093 | * VSI onto the next level down in the switch. |
| 10094 | * |
| 10095 | * Well, okay, there's one more exception here: don't remove |
| 10096 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 10097 | * from up the network stack. |
| 10098 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10099 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10100 | if (pf->vsi[i] && |
| 10101 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 10102 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10103 | n++; /* count the VSIs */ |
| 10104 | } |
| 10105 | } |
| 10106 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10107 | if (!pf->veb[i]) |
| 10108 | continue; |
| 10109 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 10110 | n++; /* count the VEBs */ |
| 10111 | if (pf->veb[i]->seid == uplink_seid) |
| 10112 | veb = pf->veb[i]; |
| 10113 | } |
| 10114 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 10115 | i40e_veb_release(veb); |
| 10116 | |
| 10117 | return 0; |
| 10118 | } |
| 10119 | |
| 10120 | /** |
| 10121 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 10122 | * @vsi: ptr to the VSI |
| 10123 | * |
| 10124 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 10125 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 10126 | * newly allocated VSI. |
| 10127 | * |
| 10128 | * Returns 0 on success or negative on failure |
| 10129 | **/ |
| 10130 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 10131 | { |
| 10132 | int ret = -ENOENT; |
| 10133 | struct i40e_pf *pf = vsi->back; |
| 10134 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 10135 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10136 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 10137 | vsi->seid); |
| 10138 | return -EEXIST; |
| 10139 | } |
| 10140 | |
| 10141 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 10142 | dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10143 | vsi->seid, vsi->base_vector); |
| 10144 | return -EEXIST; |
| 10145 | } |
| 10146 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 10147 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10148 | if (ret) { |
| 10149 | dev_info(&pf->pdev->dev, |
| 10150 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 10151 | vsi->num_q_vectors, vsi->seid, ret); |
| 10152 | vsi->num_q_vectors = 0; |
| 10153 | goto vector_setup_out; |
| 10154 | } |
| 10155 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 10156 | /* In Legacy mode, we do not have to get any other vector since we |
| 10157 | * piggyback on the misc/ICR0 for queue interrupts. |
| 10158 | */ |
| 10159 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 10160 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 10161 | if (vsi->num_q_vectors) |
| 10162 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 10163 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10164 | if (vsi->base_vector < 0) { |
| 10165 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10166 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 10167 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10168 | i40e_vsi_free_q_vectors(vsi); |
| 10169 | ret = -ENOENT; |
| 10170 | goto vector_setup_out; |
| 10171 | } |
| 10172 | |
| 10173 | vector_setup_out: |
| 10174 | return ret; |
| 10175 | } |
| 10176 | |
| 10177 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10178 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 10179 | * @vsi: pointer to the vsi. |
| 10180 | * |
| 10181 | * This re-allocates a vsi's queue resources. |
| 10182 | * |
| 10183 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 10184 | * on success, otherwise returns NULL on failure. |
| 10185 | **/ |
| 10186 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 10187 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10188 | u16 alloc_queue_pairs; |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 10189 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10190 | u8 enabled_tc; |
| 10191 | int ret; |
| 10192 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 10193 | if (!vsi) |
| 10194 | return NULL; |
| 10195 | |
| 10196 | pf = vsi->back; |
| 10197 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10198 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 10199 | i40e_vsi_clear_rings(vsi); |
| 10200 | |
| 10201 | i40e_vsi_free_arrays(vsi, false); |
| 10202 | i40e_set_num_rings_in_vsi(vsi); |
| 10203 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 10204 | if (ret) |
| 10205 | goto err_vsi; |
| 10206 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10207 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 10208 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 10209 | |
| 10210 | ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10211 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10212 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10213 | "failed to get tracking for %d queues for VSI %d err %d\n", |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10214 | alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10215 | goto err_vsi; |
| 10216 | } |
| 10217 | vsi->base_queue = ret; |
| 10218 | |
| 10219 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 10220 | * layout configurations. |
| 10221 | */ |
| 10222 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 10223 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10224 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10225 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 10226 | if (vsi->type == I40E_VSI_MAIN) |
| 10227 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10228 | |
| 10229 | /* assign it some queues */ |
| 10230 | ret = i40e_alloc_rings(vsi); |
| 10231 | if (ret) |
| 10232 | goto err_rings; |
| 10233 | |
| 10234 | /* map all of the rings to the q_vectors */ |
| 10235 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10236 | return vsi; |
| 10237 | |
| 10238 | err_rings: |
| 10239 | i40e_vsi_free_q_vectors(vsi); |
| 10240 | if (vsi->netdev_registered) { |
| 10241 | vsi->netdev_registered = false; |
| 10242 | unregister_netdev(vsi->netdev); |
| 10243 | free_netdev(vsi->netdev); |
| 10244 | vsi->netdev = NULL; |
| 10245 | } |
| 10246 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10247 | err_vsi: |
| 10248 | i40e_vsi_clear(vsi); |
| 10249 | return NULL; |
| 10250 | } |
| 10251 | |
| 10252 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10253 | * i40e_vsi_setup - Set up a VSI by a given type |
| 10254 | * @pf: board private structure |
| 10255 | * @type: VSI type |
| 10256 | * @uplink_seid: the switch element to link to |
| 10257 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 10258 | * |
| 10259 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 10260 | * to the identified VEB. |
| 10261 | * |
| 10262 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 10263 | * success, otherwise returns NULL on failure. |
| 10264 | **/ |
| 10265 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 10266 | u16 uplink_seid, u32 param1) |
| 10267 | { |
| 10268 | struct i40e_vsi *vsi = NULL; |
| 10269 | struct i40e_veb *veb = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10270 | u16 alloc_queue_pairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10271 | int ret, i; |
| 10272 | int v_idx; |
| 10273 | |
| 10274 | /* The requested uplink_seid must be either |
| 10275 | * - the PF's port seid |
| 10276 | * no VEB is needed because this is the PF |
| 10277 | * or this is a Flow Director special case VSI |
| 10278 | * - seid of an existing VEB |
| 10279 | * - seid of a VSI that owns an existing VEB |
| 10280 | * - seid of a VSI that doesn't own a VEB |
| 10281 | * a new VEB is created and the VSI becomes the owner |
| 10282 | * - seid of the PF VSI, which is what creates the first VEB |
| 10283 | * this is a special case of the previous |
| 10284 | * |
| 10285 | * Find which uplink_seid we were given and create a new VEB if needed |
| 10286 | */ |
| 10287 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10288 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 10289 | veb = pf->veb[i]; |
| 10290 | break; |
| 10291 | } |
| 10292 | } |
| 10293 | |
| 10294 | if (!veb && uplink_seid != pf->mac_seid) { |
| 10295 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10296 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10297 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 10298 | vsi = pf->vsi[i]; |
| 10299 | break; |
| 10300 | } |
| 10301 | } |
| 10302 | if (!vsi) { |
| 10303 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 10304 | uplink_seid); |
| 10305 | return NULL; |
| 10306 | } |
| 10307 | |
| 10308 | if (vsi->uplink_seid == pf->mac_seid) |
| 10309 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 10310 | vsi->tc_config.enabled_tc); |
| 10311 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 10312 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 10313 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10314 | if (veb) { |
| 10315 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 10316 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 10317 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10318 | return NULL; |
| 10319 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10320 | /* We come up by default in VEPA mode if SRIOV is not |
| 10321 | * already enabled, in which case we can't force VEPA |
| 10322 | * mode. |
| 10323 | */ |
| 10324 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 10325 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 10326 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 10327 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10328 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10329 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10330 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 10331 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 10332 | veb = pf->veb[i]; |
| 10333 | } |
| 10334 | if (!veb) { |
| 10335 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 10336 | return NULL; |
| 10337 | } |
| 10338 | |
| 10339 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10340 | uplink_seid = veb->seid; |
| 10341 | } |
| 10342 | |
| 10343 | /* get vsi sw struct */ |
| 10344 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 10345 | if (v_idx < 0) |
| 10346 | goto err_alloc; |
| 10347 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10348 | if (!vsi) |
| 10349 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10350 | vsi->type = type; |
| 10351 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 10352 | |
| 10353 | if (type == I40E_VSI_MAIN) |
| 10354 | pf->lan_vsi = v_idx; |
| 10355 | else if (type == I40E_VSI_SRIOV) |
| 10356 | vsi->vf_id = param1; |
| 10357 | /* assign it some queues */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10358 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 10359 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 10360 | |
| 10361 | ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10362 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10363 | dev_info(&pf->pdev->dev, |
| 10364 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10365 | alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10366 | goto err_vsi; |
| 10367 | } |
| 10368 | vsi->base_queue = ret; |
| 10369 | |
| 10370 | /* get a VSI from the hardware */ |
| 10371 | vsi->uplink_seid = uplink_seid; |
| 10372 | ret = i40e_add_vsi(vsi); |
| 10373 | if (ret) |
| 10374 | goto err_vsi; |
| 10375 | |
| 10376 | switch (vsi->type) { |
| 10377 | /* setup the netdev if needed */ |
| 10378 | case I40E_VSI_MAIN: |
| 10379 | case I40E_VSI_VMDQ2: |
| 10380 | ret = i40e_config_netdev(vsi); |
| 10381 | if (ret) |
| 10382 | goto err_netdev; |
| 10383 | ret = register_netdev(vsi->netdev); |
| 10384 | if (ret) |
| 10385 | goto err_netdev; |
| 10386 | vsi->netdev_registered = true; |
| 10387 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10388 | #ifdef CONFIG_I40E_DCB |
| 10389 | /* Setup DCB netlink interface */ |
| 10390 | i40e_dcbnl_setup(vsi); |
| 10391 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10392 | /* fall through */ |
| 10393 | |
| 10394 | case I40E_VSI_FDIR: |
| 10395 | /* set up vectors and rings if needed */ |
| 10396 | ret = i40e_vsi_setup_vectors(vsi); |
| 10397 | if (ret) |
| 10398 | goto err_msix; |
| 10399 | |
| 10400 | ret = i40e_alloc_rings(vsi); |
| 10401 | if (ret) |
| 10402 | goto err_rings; |
| 10403 | |
| 10404 | /* map all of the rings to the q_vectors */ |
| 10405 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10406 | |
| 10407 | i40e_vsi_reset_stats(vsi); |
| 10408 | break; |
| 10409 | |
| 10410 | default: |
| 10411 | /* no netdev or rings for the other VSI types */ |
| 10412 | break; |
| 10413 | } |
| 10414 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10415 | if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) && |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10416 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 10417 | ret = i40e_vsi_config_rss(vsi); |
| 10418 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10419 | return vsi; |
| 10420 | |
| 10421 | err_rings: |
| 10422 | i40e_vsi_free_q_vectors(vsi); |
| 10423 | err_msix: |
| 10424 | if (vsi->netdev_registered) { |
| 10425 | vsi->netdev_registered = false; |
| 10426 | unregister_netdev(vsi->netdev); |
| 10427 | free_netdev(vsi->netdev); |
| 10428 | vsi->netdev = NULL; |
| 10429 | } |
| 10430 | err_netdev: |
| 10431 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10432 | err_vsi: |
| 10433 | i40e_vsi_clear(vsi); |
| 10434 | err_alloc: |
| 10435 | return NULL; |
| 10436 | } |
| 10437 | |
| 10438 | /** |
| 10439 | * i40e_veb_get_bw_info - Query VEB BW information |
| 10440 | * @veb: the veb to query |
| 10441 | * |
| 10442 | * Query the Tx scheduler BW configuration data for given VEB |
| 10443 | **/ |
| 10444 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 10445 | { |
| 10446 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 10447 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 10448 | struct i40e_pf *pf = veb->pf; |
| 10449 | struct i40e_hw *hw = &pf->hw; |
| 10450 | u32 tc_bw_max; |
| 10451 | int ret = 0; |
| 10452 | int i; |
| 10453 | |
| 10454 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 10455 | &bw_data, NULL); |
| 10456 | if (ret) { |
| 10457 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10458 | "query veb bw config failed, err %s aq_err %s\n", |
| 10459 | i40e_stat_str(&pf->hw, ret), |
| 10460 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10461 | goto out; |
| 10462 | } |
| 10463 | |
| 10464 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 10465 | &ets_data, NULL); |
| 10466 | if (ret) { |
| 10467 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10468 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 10469 | i40e_stat_str(&pf->hw, ret), |
| 10470 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10471 | goto out; |
| 10472 | } |
| 10473 | |
| 10474 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10475 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10476 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10477 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10478 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10479 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10480 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10481 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10482 | veb->bw_tc_limit_credits[i] = |
| 10483 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10484 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10485 | } |
| 10486 | |
| 10487 | out: |
| 10488 | return ret; |
| 10489 | } |
| 10490 | |
| 10491 | /** |
| 10492 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10493 | * @pf: board private structure |
| 10494 | * |
| 10495 | * On error: returns error code (negative) |
| 10496 | * On success: returns vsi index in PF (positive) |
| 10497 | **/ |
| 10498 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10499 | { |
| 10500 | int ret = -ENOENT; |
| 10501 | struct i40e_veb *veb; |
| 10502 | int i; |
| 10503 | |
| 10504 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10505 | mutex_lock(&pf->switch_mutex); |
| 10506 | |
| 10507 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10508 | * been happening. We can afford to do a quick scan to look |
| 10509 | * for any free slots in the list. |
| 10510 | * |
| 10511 | * find next empty veb slot, looping back around if necessary |
| 10512 | */ |
| 10513 | i = 0; |
| 10514 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10515 | i++; |
| 10516 | if (i >= I40E_MAX_VEB) { |
| 10517 | ret = -ENOMEM; |
| 10518 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10519 | } |
| 10520 | |
| 10521 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10522 | if (!veb) { |
| 10523 | ret = -ENOMEM; |
| 10524 | goto err_alloc_veb; |
| 10525 | } |
| 10526 | veb->pf = pf; |
| 10527 | veb->idx = i; |
| 10528 | veb->enabled_tc = 1; |
| 10529 | |
| 10530 | pf->veb[i] = veb; |
| 10531 | ret = i; |
| 10532 | err_alloc_veb: |
| 10533 | mutex_unlock(&pf->switch_mutex); |
| 10534 | return ret; |
| 10535 | } |
| 10536 | |
| 10537 | /** |
| 10538 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10539 | * @branch: where to start deleting |
| 10540 | * |
| 10541 | * This uses recursion to find the tips of the branch to be |
| 10542 | * removed, deleting until we get back to and can delete this VEB. |
| 10543 | **/ |
| 10544 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10545 | { |
| 10546 | struct i40e_pf *pf = branch->pf; |
| 10547 | u16 branch_seid = branch->seid; |
| 10548 | u16 veb_idx = branch->idx; |
| 10549 | int i; |
| 10550 | |
| 10551 | /* release any VEBs on this VEB - RECURSION */ |
| 10552 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10553 | if (!pf->veb[i]) |
| 10554 | continue; |
| 10555 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10556 | i40e_switch_branch_release(pf->veb[i]); |
| 10557 | } |
| 10558 | |
| 10559 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10560 | * |
| 10561 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10562 | * the VEB itself, so don't use (*branch) after this loop. |
| 10563 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10564 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10565 | if (!pf->vsi[i]) |
| 10566 | continue; |
| 10567 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10568 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10569 | i40e_vsi_release(pf->vsi[i]); |
| 10570 | } |
| 10571 | } |
| 10572 | |
| 10573 | /* There's one corner case where the VEB might not have been |
| 10574 | * removed, so double check it here and remove it if needed. |
| 10575 | * This case happens if the veb was created from the debugfs |
| 10576 | * commands and no VSIs were added to it. |
| 10577 | */ |
| 10578 | if (pf->veb[veb_idx]) |
| 10579 | i40e_veb_release(pf->veb[veb_idx]); |
| 10580 | } |
| 10581 | |
| 10582 | /** |
| 10583 | * i40e_veb_clear - remove veb struct |
| 10584 | * @veb: the veb to remove |
| 10585 | **/ |
| 10586 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10587 | { |
| 10588 | if (!veb) |
| 10589 | return; |
| 10590 | |
| 10591 | if (veb->pf) { |
| 10592 | struct i40e_pf *pf = veb->pf; |
| 10593 | |
| 10594 | mutex_lock(&pf->switch_mutex); |
| 10595 | if (pf->veb[veb->idx] == veb) |
| 10596 | pf->veb[veb->idx] = NULL; |
| 10597 | mutex_unlock(&pf->switch_mutex); |
| 10598 | } |
| 10599 | |
| 10600 | kfree(veb); |
| 10601 | } |
| 10602 | |
| 10603 | /** |
| 10604 | * i40e_veb_release - Delete a VEB and free its resources |
| 10605 | * @veb: the VEB being removed |
| 10606 | **/ |
| 10607 | void i40e_veb_release(struct i40e_veb *veb) |
| 10608 | { |
| 10609 | struct i40e_vsi *vsi = NULL; |
| 10610 | struct i40e_pf *pf; |
| 10611 | int i, n = 0; |
| 10612 | |
| 10613 | pf = veb->pf; |
| 10614 | |
| 10615 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10616 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10617 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10618 | n++; |
| 10619 | vsi = pf->vsi[i]; |
| 10620 | } |
| 10621 | } |
| 10622 | if (n != 1) { |
| 10623 | dev_info(&pf->pdev->dev, |
| 10624 | "can't remove VEB %d with %d VSIs left\n", |
| 10625 | veb->seid, n); |
| 10626 | return; |
| 10627 | } |
| 10628 | |
| 10629 | /* move the remaining VSI to uplink veb */ |
| 10630 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10631 | if (veb->uplink_seid) { |
| 10632 | vsi->uplink_seid = veb->uplink_seid; |
| 10633 | if (veb->uplink_seid == pf->mac_seid) |
| 10634 | vsi->veb_idx = I40E_NO_VEB; |
| 10635 | else |
| 10636 | vsi->veb_idx = veb->veb_idx; |
| 10637 | } else { |
| 10638 | /* floating VEB */ |
| 10639 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10640 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10641 | } |
| 10642 | |
| 10643 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10644 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10645 | } |
| 10646 | |
| 10647 | /** |
| 10648 | * i40e_add_veb - create the VEB in the switch |
| 10649 | * @veb: the VEB to be instantiated |
| 10650 | * @vsi: the controlling VSI |
| 10651 | **/ |
| 10652 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10653 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10654 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10655 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10656 | int ret; |
| 10657 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10658 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10659 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10660 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10661 | |
| 10662 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10663 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10664 | dev_info(&pf->pdev->dev, |
| 10665 | "couldn't add VEB, err %s aq_err %s\n", |
| 10666 | i40e_stat_str(&pf->hw, ret), |
| 10667 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10668 | return -EPERM; |
| 10669 | } |
| 10670 | |
| 10671 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10672 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10673 | &veb->stats_idx, NULL, NULL, NULL); |
| 10674 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10675 | dev_info(&pf->pdev->dev, |
| 10676 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10677 | i40e_stat_str(&pf->hw, ret), |
| 10678 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10679 | return -EPERM; |
| 10680 | } |
| 10681 | ret = i40e_veb_get_bw_info(veb); |
| 10682 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10683 | dev_info(&pf->pdev->dev, |
| 10684 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10685 | i40e_stat_str(&pf->hw, ret), |
| 10686 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10687 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10688 | return -ENOENT; |
| 10689 | } |
| 10690 | |
| 10691 | vsi->uplink_seid = veb->seid; |
| 10692 | vsi->veb_idx = veb->idx; |
| 10693 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10694 | |
| 10695 | return 0; |
| 10696 | } |
| 10697 | |
| 10698 | /** |
| 10699 | * i40e_veb_setup - Set up a VEB |
| 10700 | * @pf: board private structure |
| 10701 | * @flags: VEB setup flags |
| 10702 | * @uplink_seid: the switch element to link to |
| 10703 | * @vsi_seid: the initial VSI seid |
| 10704 | * @enabled_tc: Enabled TC bit-map |
| 10705 | * |
| 10706 | * This allocates the sw VEB structure and links it into the switch |
| 10707 | * It is possible and legal for this to be a duplicate of an already |
| 10708 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10709 | * to be zero, in order to create a floating VEB. |
| 10710 | * |
| 10711 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10712 | * success, otherwise returns NULL on failure. |
| 10713 | **/ |
| 10714 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10715 | u16 uplink_seid, u16 vsi_seid, |
| 10716 | u8 enabled_tc) |
| 10717 | { |
| 10718 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10719 | int vsi_idx, veb_idx; |
| 10720 | int ret; |
| 10721 | |
| 10722 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10723 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10724 | (uplink_seid + vsi_seid != 0)) { |
| 10725 | dev_info(&pf->pdev->dev, |
| 10726 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10727 | uplink_seid, vsi_seid); |
| 10728 | return NULL; |
| 10729 | } |
| 10730 | |
| 10731 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10732 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10733 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10734 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10735 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10736 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10737 | vsi_seid); |
| 10738 | return NULL; |
| 10739 | } |
| 10740 | |
| 10741 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10742 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10743 | if (pf->veb[veb_idx] && |
| 10744 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10745 | uplink_veb = pf->veb[veb_idx]; |
| 10746 | break; |
| 10747 | } |
| 10748 | } |
| 10749 | if (!uplink_veb) { |
| 10750 | dev_info(&pf->pdev->dev, |
| 10751 | "uplink seid %d not found\n", uplink_seid); |
| 10752 | return NULL; |
| 10753 | } |
| 10754 | } |
| 10755 | |
| 10756 | /* get veb sw struct */ |
| 10757 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10758 | if (veb_idx < 0) |
| 10759 | goto err_alloc; |
| 10760 | veb = pf->veb[veb_idx]; |
| 10761 | veb->flags = flags; |
| 10762 | veb->uplink_seid = uplink_seid; |
| 10763 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10764 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10765 | |
| 10766 | /* create the VEB in the switch */ |
| 10767 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10768 | if (ret) |
| 10769 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10770 | if (vsi_idx == pf->lan_vsi) |
| 10771 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10772 | |
| 10773 | return veb; |
| 10774 | |
| 10775 | err_veb: |
| 10776 | i40e_veb_clear(veb); |
| 10777 | err_alloc: |
| 10778 | return NULL; |
| 10779 | } |
| 10780 | |
| 10781 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10782 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10783 | * @pf: board private structure |
| 10784 | * @ele: element we are building info from |
| 10785 | * @num_reported: total number of elements |
| 10786 | * @printconfig: should we print the contents |
| 10787 | * |
| 10788 | * helper function to assist in extracting a few useful SEID values. |
| 10789 | **/ |
| 10790 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10791 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10792 | u16 num_reported, bool printconfig) |
| 10793 | { |
| 10794 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10795 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10796 | u8 element_type = ele->element_type; |
| 10797 | u16 seid = le16_to_cpu(ele->seid); |
| 10798 | |
| 10799 | if (printconfig) |
| 10800 | dev_info(&pf->pdev->dev, |
| 10801 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10802 | element_type, seid, uplink_seid, downlink_seid); |
| 10803 | |
| 10804 | switch (element_type) { |
| 10805 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10806 | pf->mac_seid = seid; |
| 10807 | break; |
| 10808 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10809 | /* Main VEB? */ |
| 10810 | if (uplink_seid != pf->mac_seid) |
| 10811 | break; |
| 10812 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10813 | int v; |
| 10814 | |
| 10815 | /* find existing or else empty VEB */ |
| 10816 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10817 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10818 | pf->lan_veb = v; |
| 10819 | break; |
| 10820 | } |
| 10821 | } |
| 10822 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10823 | v = i40e_veb_mem_alloc(pf); |
| 10824 | if (v < 0) |
| 10825 | break; |
| 10826 | pf->lan_veb = v; |
| 10827 | } |
| 10828 | } |
| 10829 | |
| 10830 | pf->veb[pf->lan_veb]->seid = seid; |
| 10831 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10832 | pf->veb[pf->lan_veb]->pf = pf; |
| 10833 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10834 | break; |
| 10835 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10836 | if (num_reported != 1) |
| 10837 | break; |
| 10838 | /* This is immediately after a reset so we can assume this is |
| 10839 | * the PF's VSI |
| 10840 | */ |
| 10841 | pf->mac_seid = uplink_seid; |
| 10842 | pf->pf_seid = downlink_seid; |
| 10843 | pf->main_vsi_seid = seid; |
| 10844 | if (printconfig) |
| 10845 | dev_info(&pf->pdev->dev, |
| 10846 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10847 | pf->pf_seid, pf->main_vsi_seid); |
| 10848 | break; |
| 10849 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10850 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10851 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10852 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10853 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10854 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10855 | /* ignore these for now */ |
| 10856 | break; |
| 10857 | default: |
| 10858 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10859 | element_type, seid); |
| 10860 | break; |
| 10861 | } |
| 10862 | } |
| 10863 | |
| 10864 | /** |
| 10865 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10866 | * @pf: board private structure |
| 10867 | * @printconfig: should we print the contents |
| 10868 | * |
| 10869 | * Get the current switch configuration from the device and |
| 10870 | * extract a few useful SEID values. |
| 10871 | **/ |
| 10872 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10873 | { |
| 10874 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10875 | u16 next_seid = 0; |
| 10876 | int ret = 0; |
| 10877 | u8 *aq_buf; |
| 10878 | int i; |
| 10879 | |
| 10880 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10881 | if (!aq_buf) |
| 10882 | return -ENOMEM; |
| 10883 | |
| 10884 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10885 | do { |
| 10886 | u16 num_reported, num_total; |
| 10887 | |
| 10888 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10889 | I40E_AQ_LARGE_BUF, |
| 10890 | &next_seid, NULL); |
| 10891 | if (ret) { |
| 10892 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10893 | "get switch config failed err %s aq_err %s\n", |
| 10894 | i40e_stat_str(&pf->hw, ret), |
| 10895 | i40e_aq_str(&pf->hw, |
| 10896 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10897 | kfree(aq_buf); |
| 10898 | return -ENOENT; |
| 10899 | } |
| 10900 | |
| 10901 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10902 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10903 | |
| 10904 | if (printconfig) |
| 10905 | dev_info(&pf->pdev->dev, |
| 10906 | "header: %d reported %d total\n", |
| 10907 | num_reported, num_total); |
| 10908 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10909 | for (i = 0; i < num_reported; i++) { |
| 10910 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10911 | &sw_config->element[i]; |
| 10912 | |
| 10913 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10914 | printconfig); |
| 10915 | } |
| 10916 | } while (next_seid != 0); |
| 10917 | |
| 10918 | kfree(aq_buf); |
| 10919 | return ret; |
| 10920 | } |
| 10921 | |
| 10922 | /** |
| 10923 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10924 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10925 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10926 | * |
| 10927 | * Returns 0 on success, negative value on failure |
| 10928 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10929 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10930 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10931 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10932 | int ret; |
| 10933 | |
| 10934 | /* find out what's out there already */ |
| 10935 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10936 | if (ret) { |
| 10937 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10938 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10939 | i40e_stat_str(&pf->hw, ret), |
| 10940 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10941 | return ret; |
| 10942 | } |
| 10943 | i40e_pf_reset_stats(pf); |
| 10944 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10945 | /* set the switch config bit for the whole device to |
| 10946 | * support limited promisc or true promisc |
| 10947 | * when user requests promisc. The default is limited |
| 10948 | * promisc. |
| 10949 | */ |
| 10950 | |
| 10951 | if ((pf->hw.pf_id == 0) && |
| 10952 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10953 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10954 | |
| 10955 | if (pf->hw.pf_id == 0) { |
| 10956 | u16 valid_flags; |
| 10957 | |
| 10958 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10959 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10960 | NULL); |
| 10961 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10962 | dev_info(&pf->pdev->dev, |
| 10963 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10964 | i40e_stat_str(&pf->hw, ret), |
| 10965 | i40e_aq_str(&pf->hw, |
| 10966 | pf->hw.aq.asq_last_status)); |
| 10967 | /* not a fatal problem, just keep going */ |
| 10968 | } |
| 10969 | } |
| 10970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10971 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10972 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10973 | struct i40e_vsi *vsi = NULL; |
| 10974 | u16 uplink_seid; |
| 10975 | |
| 10976 | /* Set up the PF VSI associated with the PF's main VSI |
| 10977 | * that is already in the HW switch |
| 10978 | */ |
| 10979 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10980 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10981 | else |
| 10982 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10983 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10984 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10985 | else if (reinit) |
| 10986 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10987 | if (!vsi) { |
| 10988 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10989 | i40e_fdir_teardown(pf); |
| 10990 | return -EAGAIN; |
| 10991 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10992 | } else { |
| 10993 | /* force a reset of TC and queue layout configurations */ |
| 10994 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10995 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10996 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10997 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10998 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10999 | } |
| 11000 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 11001 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11002 | i40e_fdir_sb_setup(pf); |
| 11003 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11004 | /* Setup static PF queue filter control settings */ |
| 11005 | ret = i40e_setup_pf_filter_control(pf); |
| 11006 | if (ret) { |
| 11007 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 11008 | ret); |
| 11009 | /* Failure here should not stop continuing other steps */ |
| 11010 | } |
| 11011 | |
| 11012 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 11013 | * the hash |
| 11014 | */ |
| 11015 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 11016 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11017 | |
| 11018 | /* fill in link information and enable LSE reporting */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11019 | i40e_link_event(pf); |
| 11020 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11021 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11022 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 11023 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11024 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11025 | i40e_ptp_init(pf); |
| 11026 | |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 11027 | /* repopulate tunnel port filters */ |
| 11028 | i40e_sync_udp_filters(pf); |
| 11029 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11030 | return ret; |
| 11031 | } |
| 11032 | |
| 11033 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11034 | * i40e_determine_queue_usage - Work out queue distribution |
| 11035 | * @pf: board private structure |
| 11036 | **/ |
| 11037 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 11038 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11039 | int queues_left; |
| 11040 | |
| 11041 | pf->num_lan_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11042 | |
| 11043 | /* Find the max queues to be put into basic use. We'll always be |
| 11044 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 11045 | * big RSS set. |
| 11046 | */ |
| 11047 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 11048 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11049 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11050 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11051 | /* one qp for PF, no queues for anything else */ |
| 11052 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11053 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11054 | |
| 11055 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11056 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11057 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11058 | I40E_FLAG_FD_SB_ENABLED | |
| 11059 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11060 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 11061 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11062 | I40E_FLAG_SRIOV_ENABLED | |
| 11063 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11064 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 11065 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 11066 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11067 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11068 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11069 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11070 | queues_left -= pf->num_lan_qps; |
| 11071 | |
| 11072 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11073 | I40E_FLAG_IWARP_ENABLED | |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11074 | I40E_FLAG_FD_SB_ENABLED | |
| 11075 | I40E_FLAG_FD_ATR_ENABLED | |
| 11076 | I40E_FLAG_DCB_ENABLED | |
| 11077 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11078 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11079 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11080 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11081 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 11082 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 11083 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11084 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 11085 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 11086 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 11087 | num_online_cpus()); |
| 11088 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 11089 | pf->hw.func_caps.num_tx_qp); |
| 11090 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11091 | queues_left -= pf->num_lan_qps; |
| 11092 | } |
| 11093 | |
| 11094 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 11095 | if (queues_left > 1) { |
| 11096 | queues_left -= 1; /* save 1 queue for FD */ |
| 11097 | } else { |
| 11098 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 11099 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 11100 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11101 | } |
| 11102 | |
| 11103 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11104 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11105 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 11106 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11107 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 11108 | } |
| 11109 | |
| 11110 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 11111 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 11112 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 11113 | (queues_left / pf->num_vmdq_qps)); |
| 11114 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 11115 | } |
| 11116 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 11117 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11118 | dev_dbg(&pf->pdev->dev, |
| 11119 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 11120 | pf->hw.func_caps.num_tx_qp, |
| 11121 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11122 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 11123 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 11124 | queues_left); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11125 | } |
| 11126 | |
| 11127 | /** |
| 11128 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 11129 | * @pf: PF to be setup |
| 11130 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 11131 | * i40e_setup_pf_filter_control sets up a PF's initial filter control |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11132 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 11133 | * based filter sizes required for them. It also enables Flow director, |
| 11134 | * ethertype and macvlan type filter settings for the pf. |
| 11135 | * |
| 11136 | * Returns 0 on success, negative on failure |
| 11137 | **/ |
| 11138 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 11139 | { |
| 11140 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 11141 | |
| 11142 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 11143 | |
| 11144 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11145 | if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11146 | settings->enable_fdir = true; |
| 11147 | |
| 11148 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 11149 | settings->enable_ethtype = true; |
| 11150 | settings->enable_macvlan = true; |
| 11151 | |
| 11152 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 11153 | return -ENOENT; |
| 11154 | |
| 11155 | return 0; |
| 11156 | } |
| 11157 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11158 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11159 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11160 | static void i40e_print_features(struct i40e_pf *pf) |
| 11161 | { |
| 11162 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11163 | char *buf; |
| 11164 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11165 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11166 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 11167 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11168 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11169 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11170 | i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11171 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11172 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11173 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 11174 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11175 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 11176 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11177 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11178 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11179 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11180 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 11181 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11182 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 11183 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 11184 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11185 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11186 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11187 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 11188 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11189 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11190 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11191 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11192 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11193 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11194 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11195 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11196 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 11197 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11198 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11199 | } |
| 11200 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11201 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11202 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11203 | * @pdev: PCI device information struct |
| 11204 | * @pf: board private structure |
| 11205 | * |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11206 | * Look up the MAC address for the device. First we'll try |
| 11207 | * eth_platform_get_mac_address, which will check Open Firmware, or arch |
| 11208 | * specific fallback. Otherwise, we'll default to the stored value in |
| 11209 | * firmware. |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11210 | **/ |
| 11211 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 11212 | { |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11213 | if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
| 11214 | i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11215 | } |
| 11216 | |
| 11217 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11218 | * i40e_probe - Device initialization routine |
| 11219 | * @pdev: PCI device information struct |
| 11220 | * @ent: entry in i40e_pci_tbl |
| 11221 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 11222 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 11223 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11224 | * and a hardware reset occur. |
| 11225 | * |
| 11226 | * Returns 0 on success, negative on failure |
| 11227 | **/ |
| 11228 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 11229 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11230 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11231 | struct i40e_pf *pf; |
| 11232 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11233 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11234 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11235 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 11236 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11237 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11238 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11239 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11240 | |
| 11241 | err = pci_enable_device_mem(pdev); |
| 11242 | if (err) |
| 11243 | return err; |
| 11244 | |
| 11245 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11246 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11247 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 11248 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 11249 | if (err) { |
| 11250 | dev_err(&pdev->dev, |
| 11251 | "DMA configuration failed: 0x%x\n", err); |
| 11252 | goto err_dma; |
| 11253 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11254 | } |
| 11255 | |
| 11256 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11257 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11258 | if (err) { |
| 11259 | dev_info(&pdev->dev, |
| 11260 | "pci_request_selected_regions failed %d\n", err); |
| 11261 | goto err_pci_reg; |
| 11262 | } |
| 11263 | |
| 11264 | pci_enable_pcie_error_reporting(pdev); |
| 11265 | pci_set_master(pdev); |
| 11266 | |
| 11267 | /* Now that we have a PCI connection, we need to do the |
| 11268 | * low level device setup. This is primarily setting up |
| 11269 | * the Admin Queue structures and then querying for the |
| 11270 | * device's current profile information. |
| 11271 | */ |
| 11272 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 11273 | if (!pf) { |
| 11274 | err = -ENOMEM; |
| 11275 | goto err_pf_alloc; |
| 11276 | } |
| 11277 | pf->next_vsi = 0; |
| 11278 | pf->pdev = pdev; |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11279 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11280 | |
| 11281 | hw = &pf->hw; |
| 11282 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11283 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11284 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 11285 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11286 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11287 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11288 | if (!hw->hw_addr) { |
| 11289 | err = -EIO; |
| 11290 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 11291 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11292 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11293 | goto err_ioremap; |
| 11294 | } |
| 11295 | hw->vendor_id = pdev->vendor; |
| 11296 | hw->device_id = pdev->device; |
| 11297 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 11298 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 11299 | hw->subsystem_device_id = pdev->subsystem_device; |
| 11300 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 11301 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 11302 | hw->bus.bus_id = pdev->bus->number; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11303 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11304 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 11305 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 11306 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 11307 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 11308 | /* set up the locks for the AQ, do this only once in probe |
| 11309 | * and destroy them only once in remove |
| 11310 | */ |
| 11311 | mutex_init(&hw->aq.asq_mutex); |
| 11312 | mutex_init(&hw->aq.arq_mutex); |
| 11313 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 11314 | pf->msg_enable = netif_msg_init(debug, |
| 11315 | NETIF_MSG_DRV | |
| 11316 | NETIF_MSG_PROBE | |
| 11317 | NETIF_MSG_LINK); |
| 11318 | if (debug < -1) |
| 11319 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 11320 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 11321 | /* do a special CORER for clearing PXE mode once at init */ |
| 11322 | if (hw->revision_id == 0 && |
| 11323 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 11324 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 11325 | i40e_flush(hw); |
| 11326 | msleep(200); |
| 11327 | pf->corer_count++; |
| 11328 | |
| 11329 | i40e_clear_pxe_mode(hw); |
| 11330 | } |
| 11331 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11332 | /* Reset here to make sure all is clean and to define PF 'n' */ |
Shannon Nelson | 838d41d | 2014-06-04 20:41:27 +0000 | [diff] [blame] | 11333 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11334 | err = i40e_pf_reset(hw); |
| 11335 | if (err) { |
| 11336 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 11337 | goto err_pf_reset; |
| 11338 | } |
| 11339 | pf->pfr_count++; |
| 11340 | |
| 11341 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 11342 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 11343 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11344 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11345 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11346 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 11347 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11348 | "%s-%s:misc", |
| 11349 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11350 | |
| 11351 | err = i40e_init_shared_code(hw); |
| 11352 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 11353 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 11354 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11355 | goto err_pf_reset; |
| 11356 | } |
| 11357 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11358 | /* set up a default setting for link flow control */ |
| 11359 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 11360 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11361 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 11362 | if (err) { |
| 11363 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 11364 | dev_info(&pdev->dev, |
| 11365 | "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n"); |
| 11366 | else |
| 11367 | dev_info(&pdev->dev, |
| 11368 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 11369 | |
| 11370 | goto err_pf_reset; |
| 11371 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 11372 | i40e_get_oem_version(hw); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11373 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11374 | /* provide nvm, fw, api versions */ |
| 11375 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 11376 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 11377 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 11378 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11379 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11380 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 11381 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11382 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11383 | "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n"); |
| 11384 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 11385 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11386 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11387 | "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n"); |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11388 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11389 | i40e_verify_eeprom(pf); |
| 11390 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 11391 | /* Rev 0 hardware was never productized */ |
| 11392 | if (hw->revision_id < 1) |
| 11393 | dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n"); |
| 11394 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 11395 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11396 | err = i40e_get_capabilities(pf); |
| 11397 | if (err) |
| 11398 | goto err_adminq_setup; |
| 11399 | |
| 11400 | err = i40e_sw_init(pf); |
| 11401 | if (err) { |
| 11402 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 11403 | goto err_sw_init; |
| 11404 | } |
| 11405 | |
| 11406 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 11407 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11408 | if (err) { |
| 11409 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 11410 | goto err_init_lan_hmc; |
| 11411 | } |
| 11412 | |
| 11413 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 11414 | if (err) { |
| 11415 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 11416 | err = -ENOENT; |
| 11417 | goto err_configure_lan_hmc; |
| 11418 | } |
| 11419 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11420 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 11421 | * Ignore error return codes because if it was already disabled via |
| 11422 | * hardware settings this will fail |
| 11423 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11424 | if (pf->hw_features & I40E_HW_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11425 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 11426 | i40e_aq_stop_lldp(hw, true, NULL); |
| 11427 | } |
| 11428 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11429 | /* allow a platform config to override the HW addr */ |
| 11430 | i40e_get_platform_mac_addr(pdev, pf); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11431 | |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 11432 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11433 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 11434 | err = -EIO; |
| 11435 | goto err_mac_addr; |
| 11436 | } |
| 11437 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 11438 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 11439 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 11440 | if (is_valid_ether_addr(hw->mac.port_addr)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11441 | pf->hw_features |= I40E_HW_PORT_ID_VALID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11442 | |
| 11443 | pci_set_drvdata(pdev, pf); |
| 11444 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11445 | #ifdef CONFIG_I40E_DCB |
| 11446 | err = i40e_init_pf_dcb(pf); |
| 11447 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11448 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11449 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11450 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11451 | } |
| 11452 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11453 | |
| 11454 | /* set up periodic task facility */ |
| 11455 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11456 | pf->service_timer_period = HZ; |
| 11457 | |
| 11458 | INIT_WORK(&pf->service_task, i40e_service_task); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11459 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11460 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11461 | /* NVM bit on means WoL disabled for the port */ |
| 11462 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 11463 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11464 | pf->wol_en = false; |
| 11465 | else |
| 11466 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11467 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11468 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11469 | /* set up the main switch operations */ |
| 11470 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11471 | err = i40e_init_interrupt_scheme(pf); |
| 11472 | if (err) |
| 11473 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11474 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11475 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11476 | * to us; HW supports far more and we share the remaining pool with |
| 11477 | * the other PFs. We allocate space for more than the guarantee with |
| 11478 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11479 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11480 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11481 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11482 | else |
| 11483 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11484 | |
| 11485 | /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */ |
Jesse Brandeburg | d17038d | 2015-12-23 12:05:55 -0800 | [diff] [blame] | 11486 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11487 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11488 | if (!pf->vsi) { |
| 11489 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11490 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11491 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11492 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11493 | #ifdef CONFIG_PCI_IOV |
| 11494 | /* prep for VF support */ |
| 11495 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11496 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11497 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11498 | if (pci_num_vf(pdev)) |
| 11499 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11500 | } |
| 11501 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11502 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11503 | if (err) { |
| 11504 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11505 | goto err_vsis; |
| 11506 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11507 | |
| 11508 | /* Make sure flow control is set according to current settings */ |
| 11509 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11510 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11511 | dev_dbg(&pf->pdev->dev, |
| 11512 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11513 | i40e_stat_str(hw, err), |
| 11514 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11515 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11516 | dev_dbg(&pf->pdev->dev, |
| 11517 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11518 | i40e_stat_str(hw, err), |
| 11519 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11520 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11521 | dev_dbg(&pf->pdev->dev, |
| 11522 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11523 | i40e_stat_str(hw, err), |
| 11524 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11525 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11526 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11527 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11528 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11529 | i40e_vsi_open(pf->vsi[i]); |
| 11530 | break; |
| 11531 | } |
| 11532 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11533 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11534 | /* The driver only wants link up/down and module qualification |
| 11535 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11536 | */ |
| 11537 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11538 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11539 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11540 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11541 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11542 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11543 | i40e_stat_str(&pf->hw, err), |
| 11544 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11545 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11546 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11547 | * of TSO, so that we avoid the MDD being fired and causing |
| 11548 | * a reset in the case of small MSS+TSO. |
| 11549 | */ |
| 11550 | val = rd32(hw, I40E_REG_MSS); |
| 11551 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11552 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11553 | val |= I40E_64BYTE_MSS; |
| 11554 | wr32(hw, I40E_REG_MSS, val); |
| 11555 | } |
| 11556 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11557 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11558 | msleep(75); |
| 11559 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11560 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11561 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11562 | i40e_stat_str(&pf->hw, err), |
| 11563 | i40e_aq_str(&pf->hw, |
| 11564 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11565 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11566 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11567 | * before setting up the misc vector or we get a race and the vector |
| 11568 | * ends up disabled forever. |
| 11569 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11570 | clear_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11571 | |
| 11572 | /* In case of MSIX we are going to setup the misc vector right here |
| 11573 | * to handle admin queue events etc. In case of legacy and MSI |
| 11574 | * the misc functionality and queue processing is combined in |
| 11575 | * the same vector and that gets setup at open. |
| 11576 | */ |
| 11577 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11578 | err = i40e_setup_misc_vector(pf); |
| 11579 | if (err) { |
| 11580 | dev_info(&pdev->dev, |
| 11581 | "setup of misc vector failed: %d\n", err); |
| 11582 | goto err_vsis; |
| 11583 | } |
| 11584 | } |
| 11585 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11586 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11587 | /* prep for VF support */ |
| 11588 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11589 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11590 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11591 | /* disable link interrupts for VFs */ |
| 11592 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11593 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11594 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11595 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11596 | |
| 11597 | if (pci_num_vf(pdev)) { |
| 11598 | dev_info(&pdev->dev, |
| 11599 | "Active VFs found, allocating resources.\n"); |
| 11600 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11601 | if (err) |
| 11602 | dev_info(&pdev->dev, |
| 11603 | "Error %d allocating resources for existing VFs\n", |
| 11604 | err); |
| 11605 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11606 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11607 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11608 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11609 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11610 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11611 | pf->num_iwarp_msix, |
| 11612 | I40E_IWARP_IRQ_PILE_ID); |
| 11613 | if (pf->iwarp_base_vector < 0) { |
| 11614 | dev_info(&pdev->dev, |
| 11615 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11616 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11617 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11618 | } |
| 11619 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11620 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11621 | i40e_dbg_pf_init(pf); |
| 11622 | |
| 11623 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11624 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11625 | |
| 11626 | /* since everything's happy, start the service_task timer */ |
| 11627 | mod_timer(&pf->service_timer, |
| 11628 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11629 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11630 | /* add this PF to client device list and launch a client service task */ |
Mitch Williams | 004eb61 | 2017-04-04 12:40:16 -0700 | [diff] [blame] | 11631 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11632 | err = i40e_lan_add_device(pf); |
| 11633 | if (err) |
| 11634 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11635 | err); |
| 11636 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11637 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11638 | #define PCI_SPEED_SIZE 8 |
| 11639 | #define PCI_WIDTH_SIZE 8 |
| 11640 | /* Devices on the IOSF bus do not have this information |
| 11641 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11642 | * checking them. |
| 11643 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11644 | if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) { |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11645 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11646 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11647 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11648 | /* Get the negotiated link width and speed from PCI config |
| 11649 | * space |
| 11650 | */ |
| 11651 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11652 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11653 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11654 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11655 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11656 | switch (hw->bus.speed) { |
| 11657 | case i40e_bus_speed_8000: |
| 11658 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11659 | case i40e_bus_speed_5000: |
| 11660 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11661 | case i40e_bus_speed_2500: |
| 11662 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11663 | default: |
| 11664 | break; |
| 11665 | } |
| 11666 | switch (hw->bus.width) { |
| 11667 | case i40e_bus_width_pcie_x8: |
| 11668 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11669 | case i40e_bus_width_pcie_x4: |
| 11670 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11671 | case i40e_bus_width_pcie_x2: |
| 11672 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11673 | case i40e_bus_width_pcie_x1: |
| 11674 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11675 | default: |
| 11676 | break; |
| 11677 | } |
| 11678 | |
| 11679 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11680 | speed, width); |
| 11681 | |
| 11682 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11683 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11684 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11685 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11686 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11687 | } |
| 11688 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11689 | /* get the requested speeds from the fw */ |
| 11690 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11691 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11692 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11693 | i40e_stat_str(&pf->hw, err), |
| 11694 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11695 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11696 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11697 | /* get the supported phy types from the fw */ |
| 11698 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11699 | if (err) |
| 11700 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11701 | i40e_stat_str(&pf->hw, err), |
| 11702 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11703 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11704 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11705 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11706 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11707 | * PF/VF VSIs. |
| 11708 | * The FW can still send Flow control frames if enabled. |
| 11709 | */ |
| 11710 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11711 | pf->main_vsi_seid); |
| 11712 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11713 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 11714 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11715 | pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 11716 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11717 | pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11718 | /* print a string summarizing features */ |
| 11719 | i40e_print_features(pf); |
| 11720 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11721 | return 0; |
| 11722 | |
| 11723 | /* Unwind what we've done if something failed in the setup */ |
| 11724 | err_vsis: |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11725 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11726 | i40e_clear_interrupt_scheme(pf); |
| 11727 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11728 | err_switch_setup: |
| 11729 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11730 | del_timer_sync(&pf->service_timer); |
| 11731 | err_mac_addr: |
| 11732 | err_configure_lan_hmc: |
| 11733 | (void)i40e_shutdown_lan_hmc(hw); |
| 11734 | err_init_lan_hmc: |
| 11735 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11736 | err_sw_init: |
| 11737 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11738 | err_pf_reset: |
| 11739 | iounmap(hw->hw_addr); |
| 11740 | err_ioremap: |
| 11741 | kfree(pf); |
| 11742 | err_pf_alloc: |
| 11743 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11744 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11745 | err_pci_reg: |
| 11746 | err_dma: |
| 11747 | pci_disable_device(pdev); |
| 11748 | return err; |
| 11749 | } |
| 11750 | |
| 11751 | /** |
| 11752 | * i40e_remove - Device removal routine |
| 11753 | * @pdev: PCI device information struct |
| 11754 | * |
| 11755 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11756 | * that is should release a PCI device. This could be caused by a |
| 11757 | * Hot-Plug event, or because the driver is going to be removed from |
| 11758 | * memory. |
| 11759 | **/ |
| 11760 | static void i40e_remove(struct pci_dev *pdev) |
| 11761 | { |
| 11762 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11763 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11764 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11765 | int i; |
| 11766 | |
| 11767 | i40e_dbg_pf_exit(pf); |
| 11768 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11769 | i40e_ptp_stop(pf); |
| 11770 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11771 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11772 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11773 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11774 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11775 | /* no more scheduling of any task */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11776 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11777 | set_bit(__I40E_DOWN, pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11778 | if (pf->service_timer.data) |
| 11779 | del_timer_sync(&pf->service_timer); |
| 11780 | if (pf->service_task.func) |
| 11781 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11782 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 11783 | /* Client close must be called explicitly here because the timer |
| 11784 | * has been stopped. |
| 11785 | */ |
| 11786 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 11787 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11788 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11789 | i40e_free_vfs(pf); |
| 11790 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11791 | } |
| 11792 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11793 | i40e_fdir_teardown(pf); |
| 11794 | |
| 11795 | /* If there is a switch structure or any orphans, remove them. |
| 11796 | * This will leave only the PF's VSI remaining. |
| 11797 | */ |
| 11798 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11799 | if (!pf->veb[i]) |
| 11800 | continue; |
| 11801 | |
| 11802 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11803 | pf->veb[i]->uplink_seid == 0) |
| 11804 | i40e_switch_branch_release(pf->veb[i]); |
| 11805 | } |
| 11806 | |
| 11807 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11808 | * adminq and hmc. |
| 11809 | */ |
| 11810 | if (pf->vsi[pf->lan_vsi]) |
| 11811 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11812 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11813 | /* remove attached clients */ |
Mitch Williams | 004eb61 | 2017-04-04 12:40:16 -0700 | [diff] [blame] | 11814 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11815 | ret_code = i40e_lan_del_device(pf); |
| 11816 | if (ret_code) |
| 11817 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11818 | ret_code); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11819 | } |
| 11820 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11821 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11822 | if (hw->hmc.hmc_obj) { |
| 11823 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11824 | if (ret_code) |
| 11825 | dev_warn(&pdev->dev, |
| 11826 | "Failed to destroy the HMC resources: %d\n", |
| 11827 | ret_code); |
| 11828 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11829 | |
| 11830 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11831 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11832 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11833 | /* destroy the locks only once, here */ |
| 11834 | mutex_destroy(&hw->aq.arq_mutex); |
| 11835 | mutex_destroy(&hw->aq.asq_mutex); |
| 11836 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11837 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11838 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11839 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11840 | if (pf->vsi[i]) { |
| 11841 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11842 | i40e_vsi_clear(pf->vsi[i]); |
| 11843 | pf->vsi[i] = NULL; |
| 11844 | } |
| 11845 | } |
| 11846 | |
| 11847 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11848 | kfree(pf->veb[i]); |
| 11849 | pf->veb[i] = NULL; |
| 11850 | } |
| 11851 | |
| 11852 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11853 | kfree(pf->vsi); |
| 11854 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11855 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11856 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11857 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11858 | |
| 11859 | pci_disable_pcie_error_reporting(pdev); |
| 11860 | pci_disable_device(pdev); |
| 11861 | } |
| 11862 | |
| 11863 | /** |
| 11864 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11865 | * @pdev: PCI device information struct |
| 11866 | * |
| 11867 | * Called to warn that something happened and the error handling steps |
| 11868 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11869 | * remediation. |
| 11870 | **/ |
| 11871 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11872 | enum pci_channel_state error) |
| 11873 | { |
| 11874 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11875 | |
| 11876 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11877 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11878 | if (!pf) { |
| 11879 | dev_info(&pdev->dev, |
| 11880 | "Cannot recover - error happened during device probe\n"); |
| 11881 | return PCI_ERS_RESULT_DISCONNECT; |
| 11882 | } |
| 11883 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11884 | /* shutdown all operations */ |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 11885 | if (!test_bit(__I40E_SUSPENDED, pf->state)) |
| 11886 | i40e_prep_for_reset(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11887 | |
| 11888 | /* Request a slot reset */ |
| 11889 | return PCI_ERS_RESULT_NEED_RESET; |
| 11890 | } |
| 11891 | |
| 11892 | /** |
| 11893 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11894 | * @pdev: PCI device information struct |
| 11895 | * |
| 11896 | * Called to find if the driver can work with the device now that |
| 11897 | * the pci slot has been reset. If a basic connection seems good |
| 11898 | * (registers are readable and have sane content) then return a |
| 11899 | * happy little PCI_ERS_RESULT_xxx. |
| 11900 | **/ |
| 11901 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11902 | { |
| 11903 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11904 | pci_ers_result_t result; |
| 11905 | int err; |
| 11906 | u32 reg; |
| 11907 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11908 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11909 | if (pci_enable_device_mem(pdev)) { |
| 11910 | dev_info(&pdev->dev, |
| 11911 | "Cannot re-enable PCI device after reset.\n"); |
| 11912 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11913 | } else { |
| 11914 | pci_set_master(pdev); |
| 11915 | pci_restore_state(pdev); |
| 11916 | pci_save_state(pdev); |
| 11917 | pci_wake_from_d3(pdev, false); |
| 11918 | |
| 11919 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11920 | if (reg == 0) |
| 11921 | result = PCI_ERS_RESULT_RECOVERED; |
| 11922 | else |
| 11923 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11924 | } |
| 11925 | |
| 11926 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11927 | if (err) { |
| 11928 | dev_info(&pdev->dev, |
| 11929 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11930 | err); |
| 11931 | /* non-fatal, continue */ |
| 11932 | } |
| 11933 | |
| 11934 | return result; |
| 11935 | } |
| 11936 | |
| 11937 | /** |
| 11938 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11939 | * @pdev: PCI device information struct |
| 11940 | * |
| 11941 | * Called to allow the driver to bring things back up after PCI error |
| 11942 | * and/or reset recovery has finished. |
| 11943 | **/ |
| 11944 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11945 | { |
| 11946 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11947 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11948 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11949 | if (test_bit(__I40E_SUSPENDED, pf->state)) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11950 | return; |
| 11951 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 11952 | i40e_handle_reset_warning(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11953 | } |
| 11954 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11955 | /** |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 11956 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up |
| 11957 | * using the mac_address_write admin q function |
| 11958 | * @pf: pointer to i40e_pf struct |
| 11959 | **/ |
| 11960 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) |
| 11961 | { |
| 11962 | struct i40e_hw *hw = &pf->hw; |
| 11963 | i40e_status ret; |
| 11964 | u8 mac_addr[6]; |
| 11965 | u16 flags = 0; |
| 11966 | |
| 11967 | /* Get current MAC address in case it's an LAA */ |
| 11968 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { |
| 11969 | ether_addr_copy(mac_addr, |
| 11970 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); |
| 11971 | } else { |
| 11972 | dev_err(&pf->pdev->dev, |
| 11973 | "Failed to retrieve MAC address; using default\n"); |
| 11974 | ether_addr_copy(mac_addr, hw->mac.addr); |
| 11975 | } |
| 11976 | |
| 11977 | /* The FW expects the mac address write cmd to first be called with |
| 11978 | * one of these flags before calling it again with the multicast |
| 11979 | * enable flags. |
| 11980 | */ |
| 11981 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; |
| 11982 | |
| 11983 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) |
| 11984 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; |
| 11985 | |
| 11986 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11987 | if (ret) { |
| 11988 | dev_err(&pf->pdev->dev, |
| 11989 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); |
| 11990 | return; |
| 11991 | } |
| 11992 | |
| 11993 | flags = I40E_AQC_MC_MAG_EN |
| 11994 | | I40E_AQC_WOL_PRESERVE_ON_PFR |
| 11995 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; |
| 11996 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11997 | if (ret) |
| 11998 | dev_err(&pf->pdev->dev, |
| 11999 | "Failed to enable Multicast Magic Packet wake up\n"); |
| 12000 | } |
| 12001 | |
| 12002 | /** |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12003 | * i40e_shutdown - PCI callback for shutting down |
| 12004 | * @pdev: PCI device information struct |
| 12005 | **/ |
| 12006 | static void i40e_shutdown(struct pci_dev *pdev) |
| 12007 | { |
| 12008 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12009 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12010 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12011 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12012 | set_bit(__I40E_DOWN, pf->state); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12013 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 12014 | i40e_prep_for_reset(pf, true); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12015 | rtnl_unlock(); |
| 12016 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12017 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12018 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12019 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 12020 | del_timer_sync(&pf->service_timer); |
| 12021 | cancel_work_sync(&pf->service_task); |
| 12022 | i40e_fdir_teardown(pf); |
| 12023 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 12024 | /* Client close must be called explicitly here because the timer |
| 12025 | * has been stopped. |
| 12026 | */ |
| 12027 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 12028 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12029 | if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE)) |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 12030 | i40e_enable_mc_magic_wake(pf); |
| 12031 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12032 | i40e_prep_for_reset(pf, false); |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 12033 | |
| 12034 | wr32(hw, I40E_PFPM_APM, |
| 12035 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12036 | wr32(hw, I40E_PFPM_WUFC, |
| 12037 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12038 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 12039 | i40e_clear_interrupt_scheme(pf); |
| 12040 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12041 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12042 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12043 | pci_set_power_state(pdev, PCI_D3hot); |
| 12044 | } |
| 12045 | } |
| 12046 | |
| 12047 | #ifdef CONFIG_PM |
| 12048 | /** |
| 12049 | * i40e_suspend - PCI callback for moving to D3 |
| 12050 | * @pdev: PCI device information struct |
| 12051 | **/ |
| 12052 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 12053 | { |
| 12054 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12055 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 12056 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12057 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12058 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12059 | set_bit(__I40E_DOWN, pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 12060 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12061 | if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE)) |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 12062 | i40e_enable_mc_magic_wake(pf); |
| 12063 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12064 | i40e_prep_for_reset(pf, false); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12065 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12066 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12067 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12068 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 12069 | i40e_stop_misc_vector(pf); |
Carolyn Wyborny | 7c9ae7f | 2017-06-20 15:16:53 -0700 | [diff] [blame] | 12070 | if (pf->msix_entries) { |
| 12071 | synchronize_irq(pf->msix_entries[0].vector); |
| 12072 | free_irq(pf->msix_entries[0].vector, pf); |
| 12073 | } |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 12074 | retval = pci_save_state(pdev); |
| 12075 | if (retval) |
| 12076 | return retval; |
| 12077 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12078 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12079 | pci_set_power_state(pdev, PCI_D3hot); |
| 12080 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 12081 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12082 | } |
| 12083 | |
| 12084 | /** |
| 12085 | * i40e_resume - PCI callback for waking up from D3 |
| 12086 | * @pdev: PCI device information struct |
| 12087 | **/ |
| 12088 | static int i40e_resume(struct pci_dev *pdev) |
| 12089 | { |
| 12090 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 12091 | u32 err; |
| 12092 | |
| 12093 | pci_set_power_state(pdev, PCI_D0); |
| 12094 | pci_restore_state(pdev); |
| 12095 | /* pci_restore_state() clears dev->state_saves, so |
| 12096 | * call pci_save_state() again to restore it. |
| 12097 | */ |
| 12098 | pci_save_state(pdev); |
| 12099 | |
| 12100 | err = pci_enable_device_mem(pdev); |
| 12101 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 12102 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12103 | return err; |
| 12104 | } |
| 12105 | pci_set_master(pdev); |
| 12106 | |
| 12107 | /* no wakeup events while running */ |
| 12108 | pci_wake_from_d3(pdev, false); |
| 12109 | |
| 12110 | /* handling the reset will rebuild the device state */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12111 | if (test_and_clear_bit(__I40E_SUSPENDED, pf->state)) { |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12112 | clear_bit(__I40E_DOWN, pf->state); |
Carolyn Wyborny | 7c9ae7f | 2017-06-20 15:16:53 -0700 | [diff] [blame] | 12113 | if (pf->msix_entries) { |
| 12114 | err = request_irq(pf->msix_entries[0].vector, |
| 12115 | i40e_intr, 0, pf->int_name, pf); |
| 12116 | if (err) { |
| 12117 | dev_err(&pf->pdev->dev, |
| 12118 | "request_irq for %s failed: %d\n", |
| 12119 | pf->int_name, err); |
| 12120 | } |
| 12121 | } |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12122 | i40e_reset_and_rebuild(pf, false, false); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12123 | } |
| 12124 | |
| 12125 | return 0; |
| 12126 | } |
| 12127 | |
| 12128 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12129 | static const struct pci_error_handlers i40e_err_handler = { |
| 12130 | .error_detected = i40e_pci_error_detected, |
| 12131 | .slot_reset = i40e_pci_error_slot_reset, |
| 12132 | .resume = i40e_pci_error_resume, |
| 12133 | }; |
| 12134 | |
| 12135 | static struct pci_driver i40e_driver = { |
| 12136 | .name = i40e_driver_name, |
| 12137 | .id_table = i40e_pci_tbl, |
| 12138 | .probe = i40e_probe, |
| 12139 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12140 | #ifdef CONFIG_PM |
| 12141 | .suspend = i40e_suspend, |
| 12142 | .resume = i40e_resume, |
| 12143 | #endif |
| 12144 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12145 | .err_handler = &i40e_err_handler, |
| 12146 | .sriov_configure = i40e_pci_sriov_configure, |
| 12147 | }; |
| 12148 | |
| 12149 | /** |
| 12150 | * i40e_init_module - Driver registration routine |
| 12151 | * |
| 12152 | * i40e_init_module is the first routine called when the driver is |
| 12153 | * loaded. All it does is register with the PCI subsystem. |
| 12154 | **/ |
| 12155 | static int __init i40e_init_module(void) |
| 12156 | { |
| 12157 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 12158 | i40e_driver_string, i40e_driver_version_str); |
| 12159 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 12160 | |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 12161 | /* There is no need to throttle the number of active tasks because |
| 12162 | * each device limits its own task using a state bit for scheduling |
| 12163 | * the service task, and the device tasks do not interfere with each |
| 12164 | * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM |
| 12165 | * since we need to be able to guarantee forward progress even under |
| 12166 | * memory pressure. |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12167 | */ |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 12168 | i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12169 | if (!i40e_wq) { |
| 12170 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 12171 | return -ENOMEM; |
| 12172 | } |
| 12173 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12174 | i40e_dbg_init(); |
| 12175 | return pci_register_driver(&i40e_driver); |
| 12176 | } |
| 12177 | module_init(i40e_init_module); |
| 12178 | |
| 12179 | /** |
| 12180 | * i40e_exit_module - Driver exit cleanup routine |
| 12181 | * |
| 12182 | * i40e_exit_module is called just before the driver is removed |
| 12183 | * from memory. |
| 12184 | **/ |
| 12185 | static void __exit i40e_exit_module(void) |
| 12186 | { |
| 12187 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12188 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12189 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12190 | } |
| 12191 | module_exit(i40e_exit_module); |