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 | /** |
Mariusz Stachura | 0dc8692 | 2017-07-14 09:27:00 -0400 | [diff] [blame] | 603 | * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat |
| 604 | * @hw: ptr to the hardware info |
| 605 | * @reg: the hw reg to read and clear |
| 606 | * @stat: ptr to the stat |
| 607 | **/ |
| 608 | static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat) |
| 609 | { |
| 610 | u32 new_data = rd32(hw, reg); |
| 611 | |
| 612 | wr32(hw, reg, 1); /* must write a nonzero value to clear register */ |
| 613 | *stat += new_data; |
| 614 | } |
| 615 | |
| 616 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 617 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 618 | * @vsi: the VSI to be updated |
| 619 | **/ |
| 620 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 621 | { |
| 622 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 623 | struct i40e_pf *pf = vsi->back; |
| 624 | struct i40e_hw *hw = &pf->hw; |
| 625 | struct i40e_eth_stats *oes; |
| 626 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 627 | |
| 628 | es = &vsi->eth_stats; |
| 629 | oes = &vsi->eth_stats_offsets; |
| 630 | |
| 631 | /* Gather up the stats that the hw collects */ |
| 632 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 633 | vsi->stat_offsets_loaded, |
| 634 | &oes->tx_errors, &es->tx_errors); |
| 635 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 636 | vsi->stat_offsets_loaded, |
| 637 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 638 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 639 | vsi->stat_offsets_loaded, |
| 640 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 641 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 642 | vsi->stat_offsets_loaded, |
| 643 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 644 | |
| 645 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 646 | I40E_GLV_GORCL(stat_idx), |
| 647 | vsi->stat_offsets_loaded, |
| 648 | &oes->rx_bytes, &es->rx_bytes); |
| 649 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 650 | I40E_GLV_UPRCL(stat_idx), |
| 651 | vsi->stat_offsets_loaded, |
| 652 | &oes->rx_unicast, &es->rx_unicast); |
| 653 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 654 | I40E_GLV_MPRCL(stat_idx), |
| 655 | vsi->stat_offsets_loaded, |
| 656 | &oes->rx_multicast, &es->rx_multicast); |
| 657 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 658 | I40E_GLV_BPRCL(stat_idx), |
| 659 | vsi->stat_offsets_loaded, |
| 660 | &oes->rx_broadcast, &es->rx_broadcast); |
| 661 | |
| 662 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 663 | I40E_GLV_GOTCL(stat_idx), |
| 664 | vsi->stat_offsets_loaded, |
| 665 | &oes->tx_bytes, &es->tx_bytes); |
| 666 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 667 | I40E_GLV_UPTCL(stat_idx), |
| 668 | vsi->stat_offsets_loaded, |
| 669 | &oes->tx_unicast, &es->tx_unicast); |
| 670 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 671 | I40E_GLV_MPTCL(stat_idx), |
| 672 | vsi->stat_offsets_loaded, |
| 673 | &oes->tx_multicast, &es->tx_multicast); |
| 674 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 675 | I40E_GLV_BPTCL(stat_idx), |
| 676 | vsi->stat_offsets_loaded, |
| 677 | &oes->tx_broadcast, &es->tx_broadcast); |
| 678 | vsi->stat_offsets_loaded = true; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * i40e_update_veb_stats - Update Switch component statistics |
| 683 | * @veb: the VEB being updated |
| 684 | **/ |
| 685 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 686 | { |
| 687 | struct i40e_pf *pf = veb->pf; |
| 688 | struct i40e_hw *hw = &pf->hw; |
| 689 | struct i40e_eth_stats *oes; |
| 690 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 691 | struct i40e_veb_tc_stats *veb_oes; |
| 692 | struct i40e_veb_tc_stats *veb_es; |
| 693 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 694 | |
| 695 | idx = veb->stats_idx; |
| 696 | es = &veb->stats; |
| 697 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 698 | veb_es = &veb->tc_stats; |
| 699 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 700 | |
| 701 | /* Gather up the stats that the hw collects */ |
| 702 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 703 | veb->stat_offsets_loaded, |
| 704 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 705 | if (hw->revision_id > 0) |
| 706 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &oes->rx_unknown_protocol, |
| 709 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 710 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 711 | veb->stat_offsets_loaded, |
| 712 | &oes->rx_bytes, &es->rx_bytes); |
| 713 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 714 | veb->stat_offsets_loaded, |
| 715 | &oes->rx_unicast, &es->rx_unicast); |
| 716 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 717 | veb->stat_offsets_loaded, |
| 718 | &oes->rx_multicast, &es->rx_multicast); |
| 719 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &oes->rx_broadcast, &es->rx_broadcast); |
| 722 | |
| 723 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 724 | veb->stat_offsets_loaded, |
| 725 | &oes->tx_bytes, &es->tx_bytes); |
| 726 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 727 | veb->stat_offsets_loaded, |
| 728 | &oes->tx_unicast, &es->tx_unicast); |
| 729 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 730 | veb->stat_offsets_loaded, |
| 731 | &oes->tx_multicast, &es->tx_multicast); |
| 732 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 733 | veb->stat_offsets_loaded, |
| 734 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 735 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 736 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 737 | I40E_GLVEBTC_RPCL(i, idx), |
| 738 | veb->stat_offsets_loaded, |
| 739 | &veb_oes->tc_rx_packets[i], |
| 740 | &veb_es->tc_rx_packets[i]); |
| 741 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 742 | I40E_GLVEBTC_RBCL(i, idx), |
| 743 | veb->stat_offsets_loaded, |
| 744 | &veb_oes->tc_rx_bytes[i], |
| 745 | &veb_es->tc_rx_bytes[i]); |
| 746 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 747 | I40E_GLVEBTC_TPCL(i, idx), |
| 748 | veb->stat_offsets_loaded, |
| 749 | &veb_oes->tc_tx_packets[i], |
| 750 | &veb_es->tc_tx_packets[i]); |
| 751 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 752 | I40E_GLVEBTC_TBCL(i, idx), |
| 753 | veb->stat_offsets_loaded, |
| 754 | &veb_oes->tc_tx_bytes[i], |
| 755 | &veb_es->tc_tx_bytes[i]); |
| 756 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 757 | veb->stat_offsets_loaded = true; |
| 758 | } |
| 759 | |
| 760 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 761 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 762 | * @vsi: the VSI to be updated |
| 763 | * |
| 764 | * There are a few instances where we store the same stat in a |
| 765 | * couple of different structs. This is partly because we have |
| 766 | * the netdev stats that need to be filled out, which is slightly |
| 767 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 768 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 769 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 770 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 771 | { |
| 772 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 773 | struct rtnl_link_stats64 *ons; |
| 774 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 775 | struct i40e_eth_stats *oes; |
| 776 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 777 | u32 tx_restart, tx_busy; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 778 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 779 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 780 | u64 bytes, packets; |
| 781 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 782 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 783 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 784 | u64 rx_p, rx_b; |
| 785 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 786 | u16 q; |
| 787 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 788 | if (test_bit(__I40E_VSI_DOWN, vsi->state) || |
| 789 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 790 | return; |
| 791 | |
| 792 | ns = i40e_get_vsi_stats_struct(vsi); |
| 793 | ons = &vsi->net_stats_offsets; |
| 794 | es = &vsi->eth_stats; |
| 795 | oes = &vsi->eth_stats_offsets; |
| 796 | |
| 797 | /* Gather up the netdev and vsi stats that the driver collects |
| 798 | * on the fly during packet processing |
| 799 | */ |
| 800 | rx_b = rx_p = 0; |
| 801 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 802 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 803 | rx_page = 0; |
| 804 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 805 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 806 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 807 | /* locate Tx ring */ |
| 808 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 809 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 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 | tx_b += bytes; |
| 816 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 817 | tx_restart += p->tx_stats.restart_queue; |
| 818 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 819 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 820 | tx_force_wb += p->tx_stats.tx_force_wb; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 821 | |
| 822 | /* Rx queue is part of the same block as Tx queue */ |
| 823 | p = &p[1]; |
| 824 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 825 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 826 | packets = p->stats.packets; |
| 827 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 828 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 829 | rx_b += bytes; |
| 830 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 831 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 832 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 834 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 835 | vsi->tx_restart = tx_restart; |
| 836 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 837 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 838 | vsi->tx_force_wb = tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 839 | vsi->rx_page_failed = rx_page; |
| 840 | vsi->rx_buf_failed = rx_buf; |
| 841 | |
| 842 | ns->rx_packets = rx_p; |
| 843 | ns->rx_bytes = rx_b; |
| 844 | ns->tx_packets = tx_p; |
| 845 | ns->tx_bytes = tx_b; |
| 846 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 847 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 848 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 849 | ons->tx_errors = oes->tx_errors; |
| 850 | ns->tx_errors = es->tx_errors; |
| 851 | ons->multicast = oes->rx_multicast; |
| 852 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 853 | ons->rx_dropped = oes->rx_discards; |
| 854 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 855 | ons->tx_dropped = oes->tx_discards; |
| 856 | ns->tx_dropped = es->tx_discards; |
| 857 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 858 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 860 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 861 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 862 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 863 | } |
| 864 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 865 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 866 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 867 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 868 | * @pf: the PF to be updated |
| 869 | **/ |
| 870 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 871 | { |
| 872 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 873 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 874 | struct i40e_hw *hw = &pf->hw; |
| 875 | u32 val; |
| 876 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 877 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 878 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 879 | I40E_GLPRT_GORCL(hw->port), |
| 880 | pf->stat_offsets_loaded, |
| 881 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 882 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 883 | I40E_GLPRT_GOTCL(hw->port), |
| 884 | pf->stat_offsets_loaded, |
| 885 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 886 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 887 | pf->stat_offsets_loaded, |
| 888 | &osd->eth.rx_discards, |
| 889 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 890 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 891 | I40E_GLPRT_UPRCL(hw->port), |
| 892 | pf->stat_offsets_loaded, |
| 893 | &osd->eth.rx_unicast, |
| 894 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 895 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 896 | I40E_GLPRT_MPRCL(hw->port), |
| 897 | pf->stat_offsets_loaded, |
| 898 | &osd->eth.rx_multicast, |
| 899 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 900 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 901 | I40E_GLPRT_BPRCL(hw->port), |
| 902 | pf->stat_offsets_loaded, |
| 903 | &osd->eth.rx_broadcast, |
| 904 | &nsd->eth.rx_broadcast); |
| 905 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 906 | I40E_GLPRT_UPTCL(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->eth.tx_unicast, |
| 909 | &nsd->eth.tx_unicast); |
| 910 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 911 | I40E_GLPRT_MPTCL(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->eth.tx_multicast, |
| 914 | &nsd->eth.tx_multicast); |
| 915 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 916 | I40E_GLPRT_BPTCL(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->eth.tx_broadcast, |
| 919 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 920 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 921 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 922 | pf->stat_offsets_loaded, |
| 923 | &osd->tx_dropped_link_down, |
| 924 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 925 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 926 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 929 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 930 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 931 | pf->stat_offsets_loaded, |
| 932 | &osd->illegal_bytes, &nsd->illegal_bytes); |
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_MLFC(hw->port), |
| 935 | pf->stat_offsets_loaded, |
| 936 | &osd->mac_local_faults, |
| 937 | &nsd->mac_local_faults); |
| 938 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->mac_remote_faults, |
| 941 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 942 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 943 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->rx_length_errors, |
| 946 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 947 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 948 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 951 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 952 | pf->stat_offsets_loaded, |
| 953 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 954 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 955 | pf->stat_offsets_loaded, |
| 956 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 957 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 958 | pf->stat_offsets_loaded, |
| 959 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 960 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 961 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 962 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 963 | pf->stat_offsets_loaded, |
| 964 | &osd->priority_xoff_rx[i], |
| 965 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 966 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 967 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 968 | &osd->priority_xon_rx[i], |
| 969 | &nsd->priority_xon_rx[i]); |
| 970 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 971 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 972 | &osd->priority_xon_tx[i], |
| 973 | &nsd->priority_xon_tx[i]); |
| 974 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 975 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 976 | &osd->priority_xoff_tx[i], |
| 977 | &nsd->priority_xoff_tx[i]); |
| 978 | i40e_stat_update32(hw, |
| 979 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 980 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 981 | &osd->priority_xon_2_xoff[i], |
| 982 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 985 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 986 | I40E_GLPRT_PRC64L(hw->port), |
| 987 | pf->stat_offsets_loaded, |
| 988 | &osd->rx_size_64, &nsd->rx_size_64); |
| 989 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 990 | I40E_GLPRT_PRC127L(hw->port), |
| 991 | pf->stat_offsets_loaded, |
| 992 | &osd->rx_size_127, &nsd->rx_size_127); |
| 993 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 994 | I40E_GLPRT_PRC255L(hw->port), |
| 995 | pf->stat_offsets_loaded, |
| 996 | &osd->rx_size_255, &nsd->rx_size_255); |
| 997 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 998 | I40E_GLPRT_PRC511L(hw->port), |
| 999 | pf->stat_offsets_loaded, |
| 1000 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1001 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1002 | I40E_GLPRT_PRC1023L(hw->port), |
| 1003 | pf->stat_offsets_loaded, |
| 1004 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1005 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1006 | I40E_GLPRT_PRC1522L(hw->port), |
| 1007 | pf->stat_offsets_loaded, |
| 1008 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1009 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1010 | I40E_GLPRT_PRC9522L(hw->port), |
| 1011 | pf->stat_offsets_loaded, |
| 1012 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1013 | |
| 1014 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1015 | I40E_GLPRT_PTC64L(hw->port), |
| 1016 | pf->stat_offsets_loaded, |
| 1017 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1018 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1019 | I40E_GLPRT_PTC127L(hw->port), |
| 1020 | pf->stat_offsets_loaded, |
| 1021 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1022 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1023 | I40E_GLPRT_PTC255L(hw->port), |
| 1024 | pf->stat_offsets_loaded, |
| 1025 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1026 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1027 | I40E_GLPRT_PTC511L(hw->port), |
| 1028 | pf->stat_offsets_loaded, |
| 1029 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1030 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1031 | I40E_GLPRT_PTC1023L(hw->port), |
| 1032 | pf->stat_offsets_loaded, |
| 1033 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1034 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1035 | I40E_GLPRT_PTC1522L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1038 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1039 | I40E_GLPRT_PTC9522L(hw->port), |
| 1040 | pf->stat_offsets_loaded, |
| 1041 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1042 | |
| 1043 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1044 | pf->stat_offsets_loaded, |
| 1045 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1046 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1047 | pf->stat_offsets_loaded, |
| 1048 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1049 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1050 | pf->stat_offsets_loaded, |
| 1051 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1052 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1053 | pf->stat_offsets_loaded, |
| 1054 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1055 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1056 | /* FDIR stats */ |
Mariusz Stachura | 0dc8692 | 2017-07-14 09:27:00 -0400 | [diff] [blame] | 1057 | i40e_stat_update_and_clear32(hw, |
| 1058 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)), |
| 1059 | &nsd->fd_atr_match); |
| 1060 | i40e_stat_update_and_clear32(hw, |
| 1061 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)), |
| 1062 | &nsd->fd_sb_match); |
| 1063 | i40e_stat_update_and_clear32(hw, |
| 1064 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)), |
| 1065 | &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1066 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1067 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1068 | nsd->tx_lpi_status = |
| 1069 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1070 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1071 | nsd->rx_lpi_status = |
| 1072 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1073 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1074 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1075 | pf->stat_offsets_loaded, |
| 1076 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1077 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1078 | pf->stat_offsets_loaded, |
| 1079 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1080 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1081 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 1082 | !(pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1083 | nsd->fd_sb_status = true; |
| 1084 | else |
| 1085 | nsd->fd_sb_status = false; |
| 1086 | |
| 1087 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 1088 | !(pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1089 | nsd->fd_atr_status = true; |
| 1090 | else |
| 1091 | nsd->fd_atr_status = false; |
| 1092 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1093 | pf->stat_offsets_loaded = true; |
| 1094 | } |
| 1095 | |
| 1096 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1097 | * i40e_update_stats - Update the various statistics counters. |
| 1098 | * @vsi: the VSI to be updated |
| 1099 | * |
| 1100 | * Update the various stats for this VSI and its related entities. |
| 1101 | **/ |
| 1102 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1103 | { |
| 1104 | struct i40e_pf *pf = vsi->back; |
| 1105 | |
| 1106 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1107 | i40e_update_pf_stats(pf); |
| 1108 | |
| 1109 | i40e_update_vsi_stats(vsi); |
| 1110 | } |
| 1111 | |
| 1112 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1113 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1114 | * @vsi: the VSI to be searched |
| 1115 | * @macaddr: the MAC address |
| 1116 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1117 | * |
| 1118 | * Returns ptr to the filter object or NULL |
| 1119 | **/ |
| 1120 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1121 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1122 | { |
| 1123 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1124 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1125 | |
| 1126 | if (!vsi || !macaddr) |
| 1127 | return NULL; |
| 1128 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1129 | key = i40e_addr_to_hkey(macaddr); |
| 1130 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1131 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1132 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1133 | return f; |
| 1134 | } |
| 1135 | return NULL; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1140 | * @vsi: the VSI to be searched |
| 1141 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1142 | * |
| 1143 | * Returns the first filter with the provided MAC address or NULL if |
| 1144 | * MAC address was not found |
| 1145 | **/ |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1146 | 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] | 1147 | { |
| 1148 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1149 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1150 | |
| 1151 | if (!vsi || !macaddr) |
| 1152 | return NULL; |
| 1153 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1154 | key = i40e_addr_to_hkey(macaddr); |
| 1155 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1156 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1157 | return f; |
| 1158 | } |
| 1159 | return NULL; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1164 | * @vsi: the VSI to be searched |
| 1165 | * |
| 1166 | * Returns true if VSI is in vlan mode or false otherwise |
| 1167 | **/ |
| 1168 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1169 | { |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1170 | /* If we have a PVID, always operate in VLAN mode */ |
| 1171 | if (vsi->info.pvid) |
| 1172 | return true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1173 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1174 | /* We need to operate in VLAN mode whenever we have any filters with |
| 1175 | * a VLAN other than I40E_VLAN_ALL. We could check the table each |
| 1176 | * time, incurring search cost repeatedly. However, we can notice two |
| 1177 | * things: |
| 1178 | * |
| 1179 | * 1) the only place where we can gain a VLAN filter is in |
| 1180 | * i40e_add_filter. |
| 1181 | * |
| 1182 | * 2) the only place where filters are actually removed is in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1183 | * i40e_sync_filters_subtask. |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1184 | * |
| 1185 | * Thus, we can simply use a boolean value, has_vlan_filters which we |
| 1186 | * will set to true when we add a VLAN filter in i40e_add_filter. Then |
| 1187 | * we have to perform the full search after deleting filters in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1188 | * i40e_sync_filters_subtask, but we already have to search |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1189 | * filters here and can perform the check at the same time. This |
| 1190 | * results in avoiding embedding a loop for VLAN mode inside another |
| 1191 | * loop over all the filters, and should maintain correctness as noted |
| 1192 | * above. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1193 | */ |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1194 | return vsi->has_vlan_filter; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /** |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1198 | * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary |
| 1199 | * @vsi: the VSI to configure |
| 1200 | * @tmp_add_list: list of filters ready to be added |
| 1201 | * @tmp_del_list: list of filters ready to be deleted |
| 1202 | * @vlan_filters: the number of active VLAN filters |
| 1203 | * |
| 1204 | * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they |
| 1205 | * behave as expected. If we have any active VLAN filters remaining or about |
| 1206 | * to be added then we need to update non-VLAN filters to be marked as VLAN=0 |
| 1207 | * so that they only match against untagged traffic. If we no longer have any |
| 1208 | * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1 |
| 1209 | * so that they match against both tagged and untagged traffic. In this way, |
| 1210 | * we ensure that we correctly receive the desired traffic. This ensures that |
| 1211 | * when we have an active VLAN we will receive only untagged traffic and |
| 1212 | * traffic matching active VLANs. If we have no active VLANs then we will |
| 1213 | * operate in non-VLAN mode and receive all traffic, tagged or untagged. |
| 1214 | * |
| 1215 | * Finally, in a similar fashion, this function also corrects filters when |
| 1216 | * there is an active PVID assigned to this VSI. |
| 1217 | * |
| 1218 | * In case of memory allocation failure return -ENOMEM. Otherwise, return 0. |
| 1219 | * |
| 1220 | * This function is only expected to be called from within |
| 1221 | * i40e_sync_vsi_filters. |
| 1222 | * |
| 1223 | * NOTE: This function expects to be called while under the |
| 1224 | * mac_filter_hash_lock |
| 1225 | */ |
| 1226 | static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi, |
| 1227 | struct hlist_head *tmp_add_list, |
| 1228 | struct hlist_head *tmp_del_list, |
| 1229 | int vlan_filters) |
| 1230 | { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1231 | s16 pvid = le16_to_cpu(vsi->info.pvid); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1232 | struct i40e_mac_filter *f, *add_head; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1233 | struct i40e_new_mac_filter *new; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1234 | struct hlist_node *h; |
| 1235 | int bkt, new_vlan; |
| 1236 | |
| 1237 | /* To determine if a particular filter needs to be replaced we |
| 1238 | * have the three following conditions: |
| 1239 | * |
| 1240 | * a) if we have a PVID assigned, then all filters which are |
| 1241 | * not marked as VLAN=PVID must be replaced with filters that |
| 1242 | * are. |
| 1243 | * b) otherwise, if we have any active VLANS, all filters |
| 1244 | * which are marked as VLAN=-1 must be replaced with |
| 1245 | * filters marked as VLAN=0 |
| 1246 | * c) finally, if we do not have any active VLANS, all filters |
| 1247 | * which are marked as VLAN=0 must be replaced with filters |
| 1248 | * marked as VLAN=-1 |
| 1249 | */ |
| 1250 | |
| 1251 | /* Update the filters about to be added in place */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1252 | hlist_for_each_entry(new, tmp_add_list, hlist) { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1253 | if (pvid && new->f->vlan != pvid) |
| 1254 | new->f->vlan = pvid; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1255 | else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY) |
| 1256 | new->f->vlan = 0; |
| 1257 | else if (!vlan_filters && new->f->vlan == 0) |
| 1258 | new->f->vlan = I40E_VLAN_ANY; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /* Update the remaining active filters */ |
| 1262 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
| 1263 | /* Combine the checks for whether a filter needs to be changed |
| 1264 | * and then determine the new VLAN inside the if block, in |
| 1265 | * order to avoid duplicating code for adding the new filter |
| 1266 | * then deleting the old filter. |
| 1267 | */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1268 | if ((pvid && f->vlan != pvid) || |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1269 | (vlan_filters && f->vlan == I40E_VLAN_ANY) || |
| 1270 | (!vlan_filters && f->vlan == 0)) { |
| 1271 | /* Determine the new vlan we will be adding */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1272 | if (pvid) |
| 1273 | new_vlan = pvid; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1274 | else if (vlan_filters) |
| 1275 | new_vlan = 0; |
| 1276 | else |
| 1277 | new_vlan = I40E_VLAN_ANY; |
| 1278 | |
| 1279 | /* Create the new filter */ |
| 1280 | add_head = i40e_add_filter(vsi, f->macaddr, new_vlan); |
| 1281 | if (!add_head) |
| 1282 | return -ENOMEM; |
| 1283 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1284 | /* Create a temporary i40e_new_mac_filter */ |
| 1285 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 1286 | if (!new) |
| 1287 | return -ENOMEM; |
| 1288 | |
| 1289 | new->f = add_head; |
| 1290 | new->state = add_head->state; |
| 1291 | |
| 1292 | /* Add the new filter to the tmp list */ |
| 1293 | hlist_add_head(&new->hlist, tmp_add_list); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1294 | |
| 1295 | /* Put the original filter into the delete list */ |
| 1296 | f->state = I40E_FILTER_REMOVE; |
| 1297 | hash_del(&f->hlist); |
| 1298 | hlist_add_head(&f->hlist, tmp_del_list); |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | vsi->has_vlan_filter = !!vlan_filters; |
| 1303 | |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 1308 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1309 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1310 | * @macaddr: the MAC address |
| 1311 | * |
| 1312 | * Remove whatever filter the firmware set up so the driver can manage |
| 1313 | * its own filtering intelligently. |
| 1314 | **/ |
| 1315 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
| 1316 | { |
| 1317 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1318 | struct i40e_pf *pf = vsi->back; |
| 1319 | |
| 1320 | /* Only appropriate for the PF main VSI */ |
| 1321 | if (vsi->type != I40E_VSI_MAIN) |
| 1322 | return; |
| 1323 | |
| 1324 | memset(&element, 0, sizeof(element)); |
| 1325 | ether_addr_copy(element.mac_addr, macaddr); |
| 1326 | element.vlan_tag = 0; |
| 1327 | /* Ignore error returns, some firmware does it this way... */ |
| 1328 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1329 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1330 | |
| 1331 | memset(&element, 0, sizeof(element)); |
| 1332 | ether_addr_copy(element.mac_addr, macaddr); |
| 1333 | element.vlan_tag = 0; |
| 1334 | /* ...and some firmware does it this way. */ |
| 1335 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1336 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1337 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1341 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1342 | * @vsi: the VSI to be searched |
| 1343 | * @macaddr: the MAC address |
| 1344 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1345 | * |
| 1346 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1347 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1348 | * 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] | 1349 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1350 | **/ |
| 1351 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1352 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1353 | { |
| 1354 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1355 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1356 | |
| 1357 | if (!vsi || !macaddr) |
| 1358 | return NULL; |
| 1359 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1360 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1361 | if (!f) { |
| 1362 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1363 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1364 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1365 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1366 | /* Update the boolean indicating if we need to function in |
| 1367 | * VLAN mode. |
| 1368 | */ |
| 1369 | if (vlan >= 0) |
| 1370 | vsi->has_vlan_filter = true; |
| 1371 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1372 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1373 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1374 | /* If we're in overflow promisc mode, set the state directly |
| 1375 | * to failed, so we don't bother to try sending the filter |
| 1376 | * to the hardware. |
| 1377 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1378 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state)) |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1379 | f->state = I40E_FILTER_FAILED; |
| 1380 | else |
| 1381 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1382 | INIT_HLIST_NODE(&f->hlist); |
| 1383 | |
| 1384 | key = i40e_addr_to_hkey(macaddr); |
| 1385 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1386 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1387 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1388 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1389 | } |
| 1390 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1391 | /* If we're asked to add a filter that has been marked for removal, it |
| 1392 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1393 | * will have simply deleted any filters which were previously marked |
| 1394 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1395 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1396 | * task, just restore this filter to the ACTIVE state so that the |
| 1397 | * sync task leaves it in place |
| 1398 | */ |
| 1399 | if (f->state == I40E_FILTER_REMOVE) |
| 1400 | f->state = I40E_FILTER_ACTIVE; |
| 1401 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1402 | return f; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1406 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1407 | * @vsi: VSI to remove from |
| 1408 | * @f: the filter to remove from the list |
| 1409 | * |
| 1410 | * This function should be called instead of i40e_del_filter only if you know |
| 1411 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1412 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1413 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1414 | * 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] | 1415 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1416 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1417 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1418 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1419 | **/ |
Jacob Keller | 148141b | 2016-11-11 12:39:36 -0800 | [diff] [blame] | 1420 | 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] | 1421 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1422 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1423 | return; |
| 1424 | |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1425 | /* If the filter was never added to firmware then we can just delete it |
| 1426 | * directly and we don't want to set the status to remove or else an |
| 1427 | * admin queue command will unnecessarily fire. |
| 1428 | */ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1429 | if ((f->state == I40E_FILTER_FAILED) || |
| 1430 | (f->state == I40E_FILTER_NEW)) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1431 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1432 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1433 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1434 | f->state = I40E_FILTER_REMOVE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1435 | } |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1436 | |
| 1437 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1438 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1442 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1443 | * @vsi: the VSI to be searched |
| 1444 | * @macaddr: the MAC address |
| 1445 | * @vlan: the VLAN |
| 1446 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1447 | * 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] | 1448 | * being held. |
| 1449 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1450 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1451 | * instead of list_for_each_entry(). |
| 1452 | **/ |
| 1453 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1454 | { |
| 1455 | struct i40e_mac_filter *f; |
| 1456 | |
| 1457 | if (!vsi || !macaddr) |
| 1458 | return; |
| 1459 | |
| 1460 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1461 | __i40e_del_filter(vsi, f); |
| 1462 | } |
| 1463 | |
| 1464 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1465 | * i40e_add_mac_filter - Add a MAC filter for all active VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1466 | * @vsi: the VSI to be searched |
| 1467 | * @macaddr: the mac address to be filtered |
| 1468 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1469 | * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise, |
| 1470 | * 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] | 1471 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1472 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1473 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1474 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1475 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1476 | struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, |
| 1477 | const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1478 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1479 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1480 | struct hlist_node *h; |
| 1481 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1482 | |
| 1483 | if (vsi->info.pvid) |
| 1484 | return i40e_add_filter(vsi, macaddr, |
| 1485 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1486 | |
Jacob Keller | 7aaf9536 | 2016-11-11 12:39:33 -0800 | [diff] [blame] | 1487 | if (!i40e_is_vsi_in_vlan(vsi)) |
| 1488 | return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY); |
| 1489 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1490 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1491 | if (f->state == I40E_FILTER_REMOVE) |
| 1492 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1493 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1494 | if (!add) |
| 1495 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1498 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1502 | * i40e_del_mac_filter - Remove a MAC filter from all VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1503 | * @vsi: the VSI to be searched |
| 1504 | * @macaddr: the mac address to be removed |
| 1505 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1506 | * Removes a given MAC address from a VSI regardless of what VLAN it has been |
| 1507 | * associated with. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1508 | * |
| 1509 | * Returns 0 for success, or error |
| 1510 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1511 | int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1512 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1513 | struct i40e_mac_filter *f; |
| 1514 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1515 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1516 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1517 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1518 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1519 | "Missing mac_filter_hash_lock\n"); |
| 1520 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1521 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1522 | __i40e_del_filter(vsi, f); |
| 1523 | found = true; |
| 1524 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1525 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1526 | |
| 1527 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1528 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1529 | else |
| 1530 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1534 | * i40e_set_mac - NDO callback to set mac address |
| 1535 | * @netdev: network interface device structure |
| 1536 | * @p: pointer to an address structure |
| 1537 | * |
| 1538 | * Returns 0 on success, negative on failure |
| 1539 | **/ |
| 1540 | static int i40e_set_mac(struct net_device *netdev, void *p) |
| 1541 | { |
| 1542 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1543 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1544 | struct i40e_pf *pf = vsi->back; |
| 1545 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1546 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1547 | |
| 1548 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1549 | return -EADDRNOTAVAIL; |
| 1550 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1551 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1552 | netdev_info(netdev, "already using mac address %pM\n", |
| 1553 | addr->sa_data); |
| 1554 | return 0; |
| 1555 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1556 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1557 | if (test_bit(__I40E_VSI_DOWN, vsi->back->state) || |
| 1558 | test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state)) |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1559 | return -EADDRNOTAVAIL; |
| 1560 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1561 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1562 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1563 | hw->mac.addr); |
| 1564 | else |
| 1565 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1566 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1567 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1568 | i40e_del_mac_filter(vsi, netdev->dev_addr); |
| 1569 | i40e_add_mac_filter(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1570 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1571 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1572 | if (vsi->type == I40E_VSI_MAIN) { |
| 1573 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1574 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1575 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1576 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1577 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1578 | if (ret) |
| 1579 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1580 | i40e_stat_str(hw, ret), |
| 1581 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1584 | /* schedule our worker thread which will take care of |
| 1585 | * applying the new filter changes |
| 1586 | */ |
| 1587 | i40e_service_event_schedule(vsi->back); |
| 1588 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /** |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 1592 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 1593 | * @vsi: vsi structure |
| 1594 | * @seed: RSS hash seed |
| 1595 | **/ |
| 1596 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 1597 | u8 *lut, u16 lut_size) |
| 1598 | { |
| 1599 | struct i40e_pf *pf = vsi->back; |
| 1600 | struct i40e_hw *hw = &pf->hw; |
| 1601 | int ret = 0; |
| 1602 | |
| 1603 | if (seed) { |
| 1604 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 1605 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 1606 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 1607 | if (ret) { |
| 1608 | dev_info(&pf->pdev->dev, |
| 1609 | "Cannot set RSS key, err %s aq_err %s\n", |
| 1610 | i40e_stat_str(hw, ret), |
| 1611 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 1612 | return ret; |
| 1613 | } |
| 1614 | } |
| 1615 | if (lut) { |
| 1616 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 1617 | |
| 1618 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 1619 | if (ret) { |
| 1620 | dev_info(&pf->pdev->dev, |
| 1621 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 1622 | i40e_stat_str(hw, ret), |
| 1623 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 1624 | return ret; |
| 1625 | } |
| 1626 | } |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 1632 | * @vsi: VSI structure |
| 1633 | **/ |
| 1634 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 1635 | { |
| 1636 | struct i40e_pf *pf = vsi->back; |
| 1637 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 1638 | u8 *lut; |
| 1639 | int ret; |
| 1640 | |
| 1641 | if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)) |
| 1642 | return 0; |
| 1643 | if (!vsi->rss_size) |
| 1644 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 1645 | vsi->num_queue_pairs); |
| 1646 | if (!vsi->rss_size) |
| 1647 | return -EINVAL; |
| 1648 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 1649 | if (!lut) |
| 1650 | return -ENOMEM; |
| 1651 | |
| 1652 | /* Use the user configured hash keys and lookup table if there is one, |
| 1653 | * otherwise use default |
| 1654 | */ |
| 1655 | if (vsi->rss_lut_user) |
| 1656 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 1657 | else |
| 1658 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 1659 | if (vsi->rss_hkey_user) |
| 1660 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 1661 | else |
| 1662 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
| 1663 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 1664 | kfree(lut); |
| 1665 | return ret; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config |
| 1670 | * @vsi: the VSI being configured, |
| 1671 | * @ctxt: VSI context structure |
| 1672 | * @enabled_tc: number of traffic classes to enable |
| 1673 | * |
| 1674 | * Prepares VSI tc_config to have queue configurations based on MQPRIO options. |
| 1675 | **/ |
| 1676 | static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi, |
| 1677 | struct i40e_vsi_context *ctxt, |
| 1678 | u8 enabled_tc) |
| 1679 | { |
| 1680 | u16 qcount = 0, max_qcount, qmap, sections = 0; |
| 1681 | int i, override_q, pow, num_qps, ret; |
| 1682 | u8 netdev_tc = 0, offset = 0; |
| 1683 | |
| 1684 | if (vsi->type != I40E_VSI_MAIN) |
| 1685 | return -EINVAL; |
| 1686 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1687 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1688 | vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc; |
| 1689 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
| 1690 | num_qps = vsi->mqprio_qopt.qopt.count[0]; |
| 1691 | |
| 1692 | /* find the next higher power-of-2 of num queue pairs */ |
| 1693 | pow = ilog2(num_qps); |
| 1694 | if (!is_power_of_2(num_qps)) |
| 1695 | pow++; |
| 1696 | qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1697 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1698 | |
| 1699 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1700 | max_qcount = vsi->mqprio_qopt.qopt.count[0]; |
| 1701 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1702 | /* See if the given TC is enabled for the given VSI */ |
| 1703 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
| 1704 | offset = vsi->mqprio_qopt.qopt.offset[i]; |
| 1705 | qcount = vsi->mqprio_qopt.qopt.count[i]; |
| 1706 | if (qcount > max_qcount) |
| 1707 | max_qcount = qcount; |
| 1708 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1709 | vsi->tc_config.tc_info[i].qcount = qcount; |
| 1710 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1711 | } else { |
| 1712 | /* TC is not enabled so set the offset to |
| 1713 | * default queue and allocate one queue |
| 1714 | * for the given TC. |
| 1715 | */ |
| 1716 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1717 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1718 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | /* Set actual Tx/Rx queue pairs */ |
| 1723 | vsi->num_queue_pairs = offset + qcount; |
| 1724 | |
| 1725 | /* Setup queue TC[0].qmap for given VSI context */ |
| 1726 | ctxt->info.tc_mapping[0] = cpu_to_le16(qmap); |
| 1727 | ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1728 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1729 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1730 | |
| 1731 | /* Reconfigure RSS for main VSI with max queue count */ |
| 1732 | vsi->rss_size = max_qcount; |
| 1733 | ret = i40e_vsi_config_rss(vsi); |
| 1734 | if (ret) { |
| 1735 | dev_info(&vsi->back->pdev->dev, |
| 1736 | "Failed to reconfig rss for num_queues (%u)\n", |
| 1737 | max_qcount); |
| 1738 | return ret; |
| 1739 | } |
| 1740 | vsi->reconfig_rss = true; |
| 1741 | dev_dbg(&vsi->back->pdev->dev, |
| 1742 | "Reconfigured rss with num_queues (%u)\n", max_qcount); |
| 1743 | |
| 1744 | /* Find queue count available for channel VSIs and starting offset |
| 1745 | * for channel VSIs |
| 1746 | */ |
| 1747 | override_q = vsi->mqprio_qopt.qopt.count[0]; |
| 1748 | if (override_q && override_q < vsi->num_queue_pairs) { |
| 1749 | vsi->cnt_q_avail = vsi->num_queue_pairs - override_q; |
| 1750 | vsi->next_base_queue = override_q; |
| 1751 | } |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1756 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1757 | * @vsi: the VSI being setup |
| 1758 | * @ctxt: VSI context structure |
| 1759 | * @enabled_tc: Enabled TCs bitmap |
| 1760 | * @is_add: True if called before Add VSI |
| 1761 | * |
| 1762 | * Setup VSI queue mapping for enabled traffic classes. |
| 1763 | **/ |
| 1764 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1765 | struct i40e_vsi_context *ctxt, |
| 1766 | u8 enabled_tc, |
| 1767 | bool is_add) |
| 1768 | { |
| 1769 | struct i40e_pf *pf = vsi->back; |
| 1770 | u16 sections = 0; |
| 1771 | u8 netdev_tc = 0; |
| 1772 | u16 numtc = 0; |
| 1773 | u16 qcount; |
| 1774 | u8 offset; |
| 1775 | u16 qmap; |
| 1776 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1777 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1778 | |
| 1779 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1780 | offset = 0; |
| 1781 | |
| 1782 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1783 | /* Find numtc from enabled TC bitmap */ |
| 1784 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1785 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1786 | numtc++; |
| 1787 | } |
| 1788 | if (!numtc) { |
| 1789 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1790 | numtc = 1; |
| 1791 | } |
| 1792 | } else { |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 1793 | /* At least TC0 is enabled in non-DCB, non-MQPRIO case */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1794 | numtc = 1; |
| 1795 | } |
| 1796 | |
| 1797 | vsi->tc_config.numtc = numtc; |
| 1798 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1799 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1800 | qcount = vsi->alloc_queue_pairs; |
| 1801 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1802 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1803 | 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] | 1804 | |
| 1805 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1806 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1807 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1808 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1809 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1810 | int pow, num_qps; |
| 1811 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1812 | switch (vsi->type) { |
| 1813 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1814 | qcount = min_t(int, pf->alloc_rss_size, |
| 1815 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1816 | break; |
| 1817 | case I40E_VSI_FDIR: |
| 1818 | case I40E_VSI_SRIOV: |
| 1819 | case I40E_VSI_VMDQ2: |
| 1820 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1821 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1822 | WARN_ON(i != 0); |
| 1823 | break; |
| 1824 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1825 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1826 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1827 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1828 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1829 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1830 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1831 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1832 | pow++; |
| 1833 | num_qps >>= 1; |
| 1834 | } |
| 1835 | |
| 1836 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1837 | qmap = |
| 1838 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1839 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1840 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1841 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1842 | } else { |
| 1843 | /* TC is not enabled so set the offset to |
| 1844 | * default queue and allocate one queue |
| 1845 | * for the given TC. |
| 1846 | */ |
| 1847 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1848 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1849 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1850 | |
| 1851 | qmap = 0; |
| 1852 | } |
| 1853 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1854 | } |
| 1855 | |
| 1856 | /* Set actual Tx/Rx queue pairs */ |
| 1857 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1858 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1859 | if (vsi->req_queue_pairs > 0) |
| 1860 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1861 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1862 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1863 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1864 | |
| 1865 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1866 | if (is_add) { |
| 1867 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1868 | |
| 1869 | ctxt->info.up_enable_bits = enabled_tc; |
| 1870 | } |
| 1871 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1872 | ctxt->info.mapping_flags |= |
| 1873 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1874 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1875 | ctxt->info.queue_mapping[i] = |
| 1876 | cpu_to_le16(vsi->base_queue + i); |
| 1877 | } else { |
| 1878 | ctxt->info.mapping_flags |= |
| 1879 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1880 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1881 | } |
| 1882 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1883 | } |
| 1884 | |
| 1885 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1886 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1887 | * @netdev: the netdevice |
| 1888 | * @addr: address to add |
| 1889 | * |
| 1890 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1891 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1892 | */ |
| 1893 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1894 | { |
| 1895 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1896 | struct i40e_vsi *vsi = np->vsi; |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1897 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1898 | if (i40e_add_mac_filter(vsi, addr)) |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1899 | return 0; |
| 1900 | else |
| 1901 | return -ENOMEM; |
| 1902 | } |
| 1903 | |
| 1904 | /** |
| 1905 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1906 | * @netdev: the netdevice |
| 1907 | * @addr: address to add |
| 1908 | * |
| 1909 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1910 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1911 | */ |
| 1912 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1913 | { |
| 1914 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1915 | struct i40e_vsi *vsi = np->vsi; |
| 1916 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1917 | i40e_del_mac_filter(vsi, addr); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1923 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1924 | * @netdev: network interface device structure |
| 1925 | **/ |
| 1926 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1927 | { |
| 1928 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1929 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1930 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1931 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1932 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1933 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1934 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1935 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1936 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1937 | |
| 1938 | /* check for other flag changes */ |
| 1939 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1940 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1941 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1946 | * 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] | 1947 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1948 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1949 | * those entries needs to be undone. |
| 1950 | * |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1951 | * MAC filter entries from this list were slated for deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1952 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1953 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1954 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1955 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1956 | struct i40e_mac_filter *f; |
| 1957 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1958 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1959 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1960 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1961 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1962 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1963 | hlist_del(&f->hlist); |
| 1964 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1969 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1970 | * @vsi: Pointer to vsi struct |
| 1971 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1972 | * those entries needs to be undone. |
| 1973 | * |
| 1974 | * MAC filter entries from this list were slated for addition. |
| 1975 | **/ |
| 1976 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, |
| 1977 | struct hlist_head *from) |
| 1978 | { |
| 1979 | struct i40e_new_mac_filter *new; |
| 1980 | struct hlist_node *h; |
| 1981 | |
| 1982 | hlist_for_each_entry_safe(new, h, from, hlist) { |
| 1983 | /* We can simply free the wrapper structure */ |
| 1984 | hlist_del(&new->hlist); |
| 1985 | kfree(new); |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | /** |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1990 | * i40e_next_entry - Get the next non-broadcast filter from a list |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1991 | * @next: pointer to filter in list |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1992 | * |
| 1993 | * Returns the next non-broadcast filter in the list. Required so that we |
| 1994 | * ignore broadcast filters within the list, since these are not handled via |
| 1995 | * the normal firmware update path. |
| 1996 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1997 | static |
| 1998 | 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] | 1999 | { |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 2000 | hlist_for_each_entry_continue(next, hlist) { |
| 2001 | if (!is_broadcast_ether_addr(next->f->macaddr)) |
| 2002 | return next; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 2005 | return NULL; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2009 | * i40e_update_filter_state - Update filter state based on return data |
| 2010 | * from firmware |
| 2011 | * @count: Number of filters added |
| 2012 | * @add_list: return data from fw |
| 2013 | * @head: pointer to first filter in current batch |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2014 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2015 | * MAC filter entries from list were slated to be added to device. Returns |
| 2016 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2017 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2018 | static int |
| 2019 | i40e_update_filter_state(int count, |
| 2020 | struct i40e_aqc_add_macvlan_element_data *add_list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2021 | struct i40e_new_mac_filter *add_head) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2022 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2023 | int retval = 0; |
| 2024 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2025 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2026 | for (i = 0; i < count; i++) { |
| 2027 | /* Always check status of each filter. We don't need to check |
| 2028 | * the firmware return status because we pre-set the filter |
| 2029 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter |
| 2030 | * request to the adminq. Thus, if it no longer matches then |
| 2031 | * we know the filter is active. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2032 | */ |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2033 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2034 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2035 | } else { |
| 2036 | add_head->state = I40E_FILTER_ACTIVE; |
| 2037 | retval++; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2038 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2039 | |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2040 | add_head = i40e_next_filter(add_head); |
| 2041 | if (!add_head) |
| 2042 | break; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2043 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2044 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2045 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2049 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 2050 | * @vsi: ptr to the VSI |
| 2051 | * @vsi_name: name to display in messages |
| 2052 | * @list: the list of filters to send to firmware |
| 2053 | * @num_del: the number of filters to delete |
| 2054 | * @retval: Set to -EIO on failure to delete |
| 2055 | * |
| 2056 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 2057 | * *retval instead of a return value so that success does not force ret_val to |
| 2058 | * be set to 0. This ensures that a sequence of calls to this function |
| 2059 | * preserve the previous value of *retval on successful delete. |
| 2060 | */ |
| 2061 | static |
| 2062 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 2063 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 2064 | int num_del, int *retval) |
| 2065 | { |
| 2066 | struct i40e_hw *hw = &vsi->back->hw; |
| 2067 | i40e_status aq_ret; |
| 2068 | int aq_err; |
| 2069 | |
| 2070 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 2071 | aq_err = hw->aq.asq_last_status; |
| 2072 | |
| 2073 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 2074 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 2075 | *retval = -EIO; |
| 2076 | dev_info(&vsi->back->pdev->dev, |
| 2077 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 2078 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 2079 | i40e_aq_str(hw, aq_err)); |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 2085 | * @vsi: ptr to the VSI |
| 2086 | * @vsi_name: name to display in messages |
| 2087 | * @list: the list of filters to send to firmware |
| 2088 | * @add_head: Position in the add hlist |
| 2089 | * @num_add: the number of filters to add |
| 2090 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 2091 | * |
| 2092 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 2093 | * promisc_changed to true if the firmware has run out of space for more |
| 2094 | * filters. |
| 2095 | */ |
| 2096 | static |
| 2097 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 2098 | struct i40e_aqc_add_macvlan_element_data *list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2099 | struct i40e_new_mac_filter *add_head, |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2100 | int num_add, bool *promisc_changed) |
| 2101 | { |
| 2102 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2103 | int aq_err, fcnt; |
| 2104 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2105 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2106 | aq_err = hw->aq.asq_last_status; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2107 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2108 | |
| 2109 | if (fcnt != num_add) { |
| 2110 | *promisc_changed = true; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2111 | set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2112 | dev_warn(&vsi->back->pdev->dev, |
| 2113 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2114 | i40e_aq_str(hw, aq_err), |
| 2115 | vsi_name); |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2120 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 2121 | * @vsi: pointer to the VSI |
| 2122 | * @f: filter data |
| 2123 | * |
| 2124 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 2125 | * filters in order to properly receive broadcast frames. Assumes that only |
| 2126 | * broadcast filters are passed. |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2127 | * |
| 2128 | * Returns status indicating success or failure; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2129 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2130 | static i40e_status |
| 2131 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 2132 | struct i40e_mac_filter *f) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2133 | { |
| 2134 | bool enable = f->state == I40E_FILTER_NEW; |
| 2135 | struct i40e_hw *hw = &vsi->back->hw; |
| 2136 | i40e_status aq_ret; |
| 2137 | |
| 2138 | if (f->vlan == I40E_VLAN_ANY) { |
| 2139 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 2140 | vsi->seid, |
| 2141 | enable, |
| 2142 | NULL); |
| 2143 | } else { |
| 2144 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 2145 | vsi->seid, |
| 2146 | enable, |
| 2147 | f->vlan, |
| 2148 | NULL); |
| 2149 | } |
| 2150 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2151 | if (aq_ret) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2152 | dev_warn(&vsi->back->pdev->dev, |
| 2153 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 2154 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 2155 | vsi_name); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2156 | |
| 2157 | return aq_ret; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2161 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 2162 | * @vsi: ptr to the VSI |
| 2163 | * |
| 2164 | * Push any outstanding VSI filter changes through the AdminQ. |
| 2165 | * |
| 2166 | * Returns 0 or error value |
| 2167 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2168 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2169 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2170 | struct hlist_head tmp_add_list, tmp_del_list; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2171 | struct i40e_mac_filter *f; |
| 2172 | struct i40e_new_mac_filter *new, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2173 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2174 | unsigned int failed_filters = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2175 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2176 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2177 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2178 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2179 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2180 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2181 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2182 | struct i40e_pf *pf; |
| 2183 | int num_add = 0; |
| 2184 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2185 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2186 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2187 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2188 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2189 | |
| 2190 | /* empty array typed pointers, kcalloc later */ |
| 2191 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 2192 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 2193 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2194 | while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2195 | usleep_range(1000, 2000); |
| 2196 | pf = vsi->back; |
| 2197 | |
| 2198 | if (vsi->netdev) { |
| 2199 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 2200 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 2201 | } |
| 2202 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2203 | INIT_HLIST_HEAD(&tmp_add_list); |
| 2204 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2205 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2206 | if (vsi->type == I40E_VSI_SRIOV) |
| 2207 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 2208 | else if (vsi->type != I40E_VSI_MAIN) |
| 2209 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 2210 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2211 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 2212 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 2213 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2214 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2215 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2216 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2217 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2218 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2219 | hash_del(&f->hlist); |
| 2220 | hlist_add_head(&f->hlist, &tmp_del_list); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2221 | |
| 2222 | /* Avoid counting removed filters */ |
| 2223 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2224 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2225 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2226 | /* Create a temporary i40e_new_mac_filter */ |
| 2227 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 2228 | if (!new) |
| 2229 | goto err_no_memory_locked; |
| 2230 | |
| 2231 | /* Store pointer to the real filter */ |
| 2232 | new->f = f; |
| 2233 | new->state = f->state; |
| 2234 | |
| 2235 | /* Add it to the hash list */ |
| 2236 | hlist_add_head(&new->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2237 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2238 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2239 | /* Count the number of active (current and new) VLAN |
| 2240 | * filters we have now. Does not count filters which |
| 2241 | * are marked for deletion. |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2242 | */ |
| 2243 | if (f->vlan > 0) |
| 2244 | vlan_filters++; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2247 | retval = i40e_correct_mac_vlan_filters(vsi, |
| 2248 | &tmp_add_list, |
| 2249 | &tmp_del_list, |
| 2250 | vlan_filters); |
| 2251 | if (retval) |
| 2252 | goto err_no_memory_locked; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2253 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2254 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2258 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2259 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2260 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2261 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2262 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2263 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2264 | if (!del_list) |
| 2265 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2266 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2267 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2268 | cmd_flags = 0; |
| 2269 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2270 | /* handle broadcast filters by updating the broadcast |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2271 | * promiscuous flag and release filter list. |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2272 | */ |
| 2273 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2274 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2275 | |
| 2276 | hlist_del(&f->hlist); |
| 2277 | kfree(f); |
| 2278 | continue; |
| 2279 | } |
| 2280 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2281 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2282 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2283 | if (f->vlan == I40E_VLAN_ANY) { |
| 2284 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2285 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2286 | } else { |
| 2287 | del_list[num_del].vlan_tag = |
| 2288 | cpu_to_le16((u16)(f->vlan)); |
| 2289 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2290 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2291 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2292 | del_list[num_del].flags = cmd_flags; |
| 2293 | num_del++; |
| 2294 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2295 | /* flush a full buffer */ |
| 2296 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2297 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2298 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2299 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2300 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2301 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2302 | /* Release memory for MAC filter entries which were |
| 2303 | * synced up with HW. |
| 2304 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2305 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2306 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2307 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2308 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2309 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2310 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2311 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | kfree(del_list); |
| 2315 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2316 | } |
| 2317 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2318 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2319 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2320 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2321 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2322 | list_size = filter_list_len * |
| 2323 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2324 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2325 | if (!add_list) |
| 2326 | goto err_no_memory; |
| 2327 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2328 | num_add = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2329 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2330 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2331 | vsi->state)) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2332 | new->state = I40E_FILTER_FAILED; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2333 | continue; |
| 2334 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2335 | |
| 2336 | /* handle broadcast filters by updating the broadcast |
| 2337 | * promiscuous flag instead of adding a MAC filter. |
| 2338 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2339 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
| 2340 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, |
| 2341 | new->f)) |
| 2342 | new->state = I40E_FILTER_FAILED; |
| 2343 | else |
| 2344 | new->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2345 | continue; |
| 2346 | } |
| 2347 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2348 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2349 | if (num_add == 0) |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2350 | add_head = new; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2351 | cmd_flags = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2352 | ether_addr_copy(add_list[num_add].mac_addr, |
| 2353 | new->f->macaddr); |
| 2354 | if (new->f->vlan == I40E_VLAN_ANY) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2355 | add_list[num_add].vlan_tag = 0; |
| 2356 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2357 | } else { |
| 2358 | add_list[num_add].vlan_tag = |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2359 | cpu_to_le16((u16)(new->f->vlan)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2360 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2361 | add_list[num_add].queue_number = 0; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2362 | /* set invalid match method for later detection */ |
Keller, Jacob E | 0266ac4 | 2016-12-09 13:39:21 -0800 | [diff] [blame] | 2363 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2364 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2365 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2366 | num_add++; |
| 2367 | |
| 2368 | /* flush a full buffer */ |
| 2369 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2370 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2371 | add_head, num_add, |
| 2372 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2373 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2374 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2378 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2379 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2380 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2381 | /* Now move all of the filters from the temp add list back to |
| 2382 | * the VSI's list. |
| 2383 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2384 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2385 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
| 2386 | /* Only update the state if we're still NEW */ |
| 2387 | if (new->f->state == I40E_FILTER_NEW) |
| 2388 | new->f->state = new->state; |
| 2389 | hlist_del(&new->hlist); |
| 2390 | kfree(new); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2391 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2392 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2393 | kfree(add_list); |
| 2394 | add_list = NULL; |
| 2395 | } |
| 2396 | |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2397 | /* Determine the number of active and failed filters. */ |
| 2398 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2399 | vsi->active_filters = 0; |
| 2400 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
| 2401 | if (f->state == I40E_FILTER_ACTIVE) |
| 2402 | vsi->active_filters++; |
| 2403 | else if (f->state == I40E_FILTER_FAILED) |
| 2404 | failed_filters++; |
| 2405 | } |
| 2406 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2407 | |
| 2408 | /* If promiscuous mode has changed, we need to calculate a new |
| 2409 | * threshold for when we are safe to exit |
| 2410 | */ |
| 2411 | if (promisc_changed) |
| 2412 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 2413 | |
| 2414 | /* Check if we are able to exit overflow promiscuous mode. We can |
| 2415 | * safely exit if we didn't just enter, we no longer have any failed |
| 2416 | * filters, and we have reduced filters below the threshold value. |
| 2417 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2418 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) && |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2419 | !promisc_changed && !failed_filters && |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2420 | (vsi->active_filters < vsi->promisc_threshold)) { |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2421 | dev_info(&pf->pdev->dev, |
| 2422 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2423 | vsi_name); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2424 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2425 | promisc_changed = true; |
| 2426 | vsi->promisc_threshold = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2429 | /* if the VF is not trusted do not do promisc */ |
| 2430 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2431 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2432 | goto out; |
| 2433 | } |
| 2434 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2435 | /* check for changes in promiscuous modes */ |
| 2436 | if (changed_flags & IFF_ALLMULTI) { |
| 2437 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2438 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2439 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2440 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2441 | vsi->seid, |
| 2442 | cur_multipromisc, |
| 2443 | NULL); |
| 2444 | if (aq_ret) { |
| 2445 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2446 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2447 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2448 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2449 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2450 | i40e_stat_str(hw, aq_ret), |
| 2451 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2452 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2453 | } |
Alan Brady | e588723 | 2017-06-07 05:43:10 -0400 | [diff] [blame] | 2454 | |
| 2455 | if ((changed_flags & IFF_PROMISC) || promisc_changed) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2456 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2457 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2458 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2459 | test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2460 | vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2461 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2462 | (pf->lan_veb != I40E_NO_VEB) && |
| 2463 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2464 | /* set defport ON for Main VSI instead of true promisc |
| 2465 | * this way we will get all unicast/multicast and VLAN |
| 2466 | * promisc behavior but will not get VF or VMDq traffic |
| 2467 | * replicated on the Main VSI. |
| 2468 | */ |
| 2469 | if (pf->cur_promisc != cur_promisc) { |
| 2470 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2471 | if (cur_promisc) |
| 2472 | aq_ret = |
| 2473 | i40e_aq_set_default_vsi(hw, |
| 2474 | vsi->seid, |
| 2475 | NULL); |
| 2476 | else |
| 2477 | aq_ret = |
| 2478 | i40e_aq_clear_default_vsi(hw, |
| 2479 | vsi->seid, |
| 2480 | NULL); |
| 2481 | if (aq_ret) { |
| 2482 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2483 | hw->aq.asq_last_status); |
| 2484 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2485 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2486 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2487 | i40e_stat_str(hw, aq_ret), |
| 2488 | i40e_aq_str(hw, |
| 2489 | hw->aq.asq_last_status)); |
| 2490 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2491 | } |
| 2492 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2493 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2494 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2495 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2496 | cur_promisc, NULL, |
| 2497 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2498 | if (aq_ret) { |
| 2499 | retval = |
| 2500 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2501 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2502 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2503 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2504 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2505 | i40e_stat_str(hw, aq_ret), |
| 2506 | i40e_aq_str(hw, |
| 2507 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2508 | } |
| 2509 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2510 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2511 | vsi->seid, |
| 2512 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2513 | if (aq_ret) { |
| 2514 | retval = |
| 2515 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2516 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2517 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2518 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2519 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2520 | i40e_stat_str(hw, aq_ret), |
| 2521 | i40e_aq_str(hw, |
| 2522 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2523 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2524 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2525 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2526 | vsi->seid, |
| 2527 | cur_promisc, NULL); |
| 2528 | if (aq_ret) { |
| 2529 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2530 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2531 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2532 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2533 | i40e_stat_str(hw, aq_ret), |
| 2534 | i40e_aq_str(hw, |
| 2535 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2536 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2537 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2538 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2539 | /* if something went wrong then set the changed flag so we try again */ |
| 2540 | if (retval) |
| 2541 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2542 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2543 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2544 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2545 | |
| 2546 | err_no_memory: |
| 2547 | /* Restore elements on the temporary add and delete lists */ |
| 2548 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2549 | err_no_memory_locked: |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2550 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 2551 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2552 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2553 | |
| 2554 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2555 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2556 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | /** |
| 2560 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2561 | * @pf: board private structure |
| 2562 | **/ |
| 2563 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2564 | { |
| 2565 | int v; |
| 2566 | |
| 2567 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2568 | return; |
| 2569 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2570 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2571 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2572 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2573 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2574 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2575 | |
| 2576 | if (ret) { |
| 2577 | /* come back and try again later */ |
| 2578 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2579 | break; |
| 2580 | } |
| 2581 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | /** |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2586 | * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP |
| 2587 | * @vsi: the vsi |
| 2588 | **/ |
| 2589 | static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi) |
| 2590 | { |
| 2591 | if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 2592 | return I40E_RXBUFFER_2048; |
| 2593 | else |
| 2594 | return I40E_RXBUFFER_3072; |
| 2595 | } |
| 2596 | |
| 2597 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2598 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2599 | * @netdev: network interface device structure |
| 2600 | * @new_mtu: new value for maximum frame size |
| 2601 | * |
| 2602 | * Returns 0 on success, negative on failure |
| 2603 | **/ |
| 2604 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2605 | { |
| 2606 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2607 | struct i40e_vsi *vsi = np->vsi; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2608 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2609 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2610 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 2611 | int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 2612 | |
| 2613 | if (frame_size > i40e_max_xdp_frame_size(vsi)) |
| 2614 | return -EINVAL; |
| 2615 | } |
| 2616 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2617 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2618 | netdev->mtu, new_mtu); |
| 2619 | netdev->mtu = new_mtu; |
| 2620 | if (netif_running(netdev)) |
| 2621 | i40e_vsi_reinit_locked(vsi); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2622 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 2623 | I40E_FLAG_CLIENT_L2_CHANGE); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2624 | return 0; |
| 2625 | } |
| 2626 | |
| 2627 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2628 | * i40e_ioctl - Access the hwtstamp interface |
| 2629 | * @netdev: network interface device structure |
| 2630 | * @ifr: interface request data |
| 2631 | * @cmd: ioctl command |
| 2632 | **/ |
| 2633 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2634 | { |
| 2635 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2636 | struct i40e_pf *pf = np->vsi->back; |
| 2637 | |
| 2638 | switch (cmd) { |
| 2639 | case SIOCGHWTSTAMP: |
| 2640 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2641 | case SIOCSHWTSTAMP: |
| 2642 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2643 | default: |
| 2644 | return -EOPNOTSUPP; |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2649 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2650 | * @vsi: the vsi being adjusted |
| 2651 | **/ |
| 2652 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2653 | { |
| 2654 | struct i40e_vsi_context ctxt; |
| 2655 | i40e_status ret; |
| 2656 | |
| 2657 | if ((vsi->info.valid_sections & |
| 2658 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2659 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2660 | return; /* already enabled */ |
| 2661 | |
| 2662 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2663 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2664 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2665 | |
| 2666 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2667 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2668 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2669 | if (ret) { |
| 2670 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2671 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2672 | i40e_stat_str(&vsi->back->hw, ret), |
| 2673 | i40e_aq_str(&vsi->back->hw, |
| 2674 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2680 | * @vsi: the vsi being adjusted |
| 2681 | **/ |
| 2682 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2683 | { |
| 2684 | struct i40e_vsi_context ctxt; |
| 2685 | i40e_status ret; |
| 2686 | |
| 2687 | if ((vsi->info.valid_sections & |
| 2688 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2689 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2690 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2691 | return; /* already disabled */ |
| 2692 | |
| 2693 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2694 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2695 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2696 | |
| 2697 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2698 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2699 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2700 | if (ret) { |
| 2701 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2702 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2703 | i40e_stat_str(&vsi->back->hw, ret), |
| 2704 | i40e_aq_str(&vsi->back->hw, |
| 2705 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2711 | * @netdev: network interface to be adjusted |
| 2712 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2713 | **/ |
| 2714 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2715 | { |
| 2716 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2717 | struct i40e_vsi *vsi = np->vsi; |
| 2718 | |
| 2719 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2720 | i40e_vlan_stripping_enable(vsi); |
| 2721 | else |
| 2722 | i40e_vlan_stripping_disable(vsi); |
| 2723 | } |
| 2724 | |
| 2725 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2726 | * 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] | 2727 | * @vsi: the vsi being configured |
| 2728 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2729 | * |
| 2730 | * This is a helper function for adding a new MAC/VLAN filter with the |
| 2731 | * specified VLAN for each existing MAC address already in the hash table. |
| 2732 | * This function does *not* perform any accounting to update filters based on |
| 2733 | * VLAN mode. |
| 2734 | * |
| 2735 | * NOTE: this function expects to be called while under the |
| 2736 | * mac_filter_hash_lock |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2737 | **/ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2738 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2739 | { |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2740 | struct i40e_mac_filter *f, *add_f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2741 | struct hlist_node *h; |
| 2742 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2743 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2744 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2745 | if (f->state == I40E_FILTER_REMOVE) |
| 2746 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2747 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2748 | if (!add_f) { |
| 2749 | dev_info(&vsi->back->pdev->dev, |
| 2750 | "Could not add vlan filter %d for %pM\n", |
| 2751 | vid, f->macaddr); |
| 2752 | return -ENOMEM; |
| 2753 | } |
| 2754 | } |
| 2755 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2756 | return 0; |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN |
| 2761 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2762 | * @vid: VLAN id to be added |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2763 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2764 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2765 | { |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2766 | int err; |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2767 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2768 | if (vsi->info.pvid) |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2769 | return -EINVAL; |
| 2770 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2771 | /* The network stack will attempt to add VID=0, with the intention to |
| 2772 | * receive priority tagged packets with a VLAN of 0. Our HW receives |
| 2773 | * these packets by default when configured to receive untagged |
| 2774 | * packets, so we don't need to add a filter for this case. |
| 2775 | * Additionally, HW interprets adding a VID=0 filter as meaning to |
| 2776 | * receive *only* tagged traffic and stops receiving untagged traffic. |
| 2777 | * Thus, we do not want to actually add a filter for VID=0 |
| 2778 | */ |
| 2779 | if (!vid) |
| 2780 | return 0; |
| 2781 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2782 | /* Locked once because all functions invoked below iterates list*/ |
| 2783 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2784 | err = i40e_add_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2785 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2786 | if (err) |
| 2787 | return err; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2788 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2789 | /* schedule our worker thread which will take care of |
| 2790 | * applying the new filter changes |
| 2791 | */ |
| 2792 | i40e_service_event_schedule(vsi->back); |
| 2793 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2797 | * 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] | 2798 | * @vsi: the vsi being configured |
| 2799 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2800 | * |
| 2801 | * This function should be used to remove all VLAN filters which match the |
| 2802 | * given VID. It does not schedule the service event and does not take the |
| 2803 | * mac_filter_hash_lock so it may be combined with other operations under |
| 2804 | * a single invocation of the mac_filter_hash_lock. |
| 2805 | * |
| 2806 | * NOTE: this function expects to be called while under the |
| 2807 | * mac_filter_hash_lock |
| 2808 | */ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2809 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2810 | { |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2811 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2812 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2813 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2814 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2815 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2816 | if (f->vlan == vid) |
| 2817 | __i40e_del_filter(vsi, f); |
| 2818 | } |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2819 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2820 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2821 | /** |
| 2822 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN |
| 2823 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2824 | * @vid: VLAN id to be removed |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2825 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2826 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2827 | { |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2828 | if (!vid || vsi->info.pvid) |
| 2829 | return; |
| 2830 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2831 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2832 | i40e_rm_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2833 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2834 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2835 | /* schedule our worker thread which will take care of |
| 2836 | * applying the new filter changes |
| 2837 | */ |
| 2838 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | /** |
| 2842 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2843 | * @netdev: network interface to be adjusted |
| 2844 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2845 | * |
| 2846 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2847 | **/ |
| 2848 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2849 | __always_unused __be16 proto, u16 vid) |
| 2850 | { |
| 2851 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2852 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2853 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2854 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2855 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2856 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2857 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2858 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2859 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2860 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2861 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2862 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2867 | * @netdev: network interface to be adjusted |
| 2868 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2869 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2870 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2871 | **/ |
| 2872 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2873 | __always_unused __be16 proto, u16 vid) |
| 2874 | { |
| 2875 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2876 | struct i40e_vsi *vsi = np->vsi; |
| 2877 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2878 | /* return code is ignored as there is nothing a user |
| 2879 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2880 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2881 | */ |
| 2882 | i40e_vsi_kill_vlan(vsi, vid); |
| 2883 | |
| 2884 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2885 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2886 | return 0; |
| 2887 | } |
| 2888 | |
| 2889 | /** |
| 2890 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2891 | * @vsi: the vsi being brought back up |
| 2892 | **/ |
| 2893 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2894 | { |
| 2895 | u16 vid; |
| 2896 | |
| 2897 | if (!vsi->netdev) |
| 2898 | return; |
| 2899 | |
| 2900 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2901 | |
| 2902 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2903 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2904 | vid); |
| 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2909 | * @vsi: the vsi being adjusted |
| 2910 | * @vid: the vlan id to set as a PVID |
| 2911 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2912 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2913 | { |
| 2914 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2915 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2916 | |
| 2917 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2918 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2919 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2920 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2921 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2922 | |
| 2923 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2924 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2925 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2926 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2927 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2928 | "add pvid failed, err %s aq_err %s\n", |
| 2929 | i40e_stat_str(&vsi->back->hw, ret), |
| 2930 | i40e_aq_str(&vsi->back->hw, |
| 2931 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2932 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2935 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | /** |
| 2939 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2940 | * @vsi: the vsi being adjusted |
| 2941 | * |
| 2942 | * Just use the vlan_rx_register() service to put it back to normal |
| 2943 | **/ |
| 2944 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2945 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2946 | i40e_vlan_stripping_disable(vsi); |
| 2947 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2948 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | /** |
| 2952 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2953 | * @vsi: ptr to the VSI |
| 2954 | * |
| 2955 | * If this function returns with an error, then it's possible one or |
| 2956 | * more of the rings is populated (while the rest are not). It is the |
| 2957 | * callers duty to clean those orphaned rings. |
| 2958 | * |
| 2959 | * Return 0 on success, negative on failure |
| 2960 | **/ |
| 2961 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2962 | { |
| 2963 | int i, err = 0; |
| 2964 | |
| 2965 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2966 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2967 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2968 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 2969 | return err; |
| 2970 | |
| 2971 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
| 2972 | err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]); |
| 2973 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2974 | return err; |
| 2975 | } |
| 2976 | |
| 2977 | /** |
| 2978 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2979 | * @vsi: ptr to the VSI |
| 2980 | * |
| 2981 | * Free VSI's transmit software resources |
| 2982 | **/ |
| 2983 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2984 | { |
| 2985 | int i; |
| 2986 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2987 | if (vsi->tx_rings) { |
| 2988 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2989 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
| 2990 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 2991 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2992 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2993 | if (vsi->xdp_rings) { |
| 2994 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2995 | if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) |
| 2996 | i40e_free_tx_resources(vsi->xdp_rings[i]); |
| 2997 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | /** |
| 3001 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 3002 | * @vsi: ptr to the VSI |
| 3003 | * |
| 3004 | * If this function returns with an error, then it's possible one or |
| 3005 | * more of the rings is populated (while the rest are not). It is the |
| 3006 | * callers duty to clean those orphaned rings. |
| 3007 | * |
| 3008 | * Return 0 on success, negative on failure |
| 3009 | **/ |
| 3010 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 3011 | { |
| 3012 | int i, err = 0; |
| 3013 | |
| 3014 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3015 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | return err; |
| 3017 | } |
| 3018 | |
| 3019 | /** |
| 3020 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 3021 | * @vsi: ptr to the VSI |
| 3022 | * |
| 3023 | * Free all receive software resources |
| 3024 | **/ |
| 3025 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 3026 | { |
| 3027 | int i; |
| 3028 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 3029 | if (!vsi->rx_rings) |
| 3030 | return; |
| 3031 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3032 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 3033 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3034 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 3038 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 3039 | * @ring: The Tx ring to configure |
| 3040 | * |
| 3041 | * This enables/disables XPS for a given Tx descriptor ring |
| 3042 | * based on the TCs enabled for the VSI that ring belongs to. |
| 3043 | **/ |
| 3044 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 3045 | { |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3046 | int cpu; |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 3047 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 3048 | if (!ring->q_vector || !ring->netdev || ring->ch) |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 3049 | return; |
| 3050 | |
Jacob Keller | 6f853d4 | 2017-09-07 08:05:53 -0400 | [diff] [blame] | 3051 | /* We only initialize XPS once, so as not to overwrite user settings */ |
| 3052 | if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state)) |
| 3053 | return; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 3054 | |
Jacob Keller | 6f853d4 | 2017-09-07 08:05:53 -0400 | [diff] [blame] | 3055 | cpu = cpumask_local_spread(ring->q_vector->v_idx, -1); |
| 3056 | netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu), |
| 3057 | ring->queue_index); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3061 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 3062 | * @ring: The Tx ring to configure |
| 3063 | * |
| 3064 | * Configure the Tx descriptor ring in the HMC context. |
| 3065 | **/ |
| 3066 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 3067 | { |
| 3068 | struct i40e_vsi *vsi = ring->vsi; |
| 3069 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 3070 | struct i40e_hw *hw = &vsi->back->hw; |
| 3071 | struct i40e_hmc_obj_txq tx_ctx; |
| 3072 | i40e_status err = 0; |
| 3073 | u32 qtx_ctl = 0; |
| 3074 | |
| 3075 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3076 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3077 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 3078 | ring->atr_count = 0; |
| 3079 | } else { |
| 3080 | ring->atr_sample_rate = 0; |
| 3081 | } |
| 3082 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 3083 | /* configure XPS */ |
| 3084 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3085 | |
| 3086 | /* clear the context structure first */ |
| 3087 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 3088 | |
| 3089 | tx_ctx.new_context = 1; |
| 3090 | tx_ctx.base = (ring->dma / 128); |
| 3091 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3092 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 3093 | I40E_FLAG_FD_ATR_ENABLED)); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3094 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 3095 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 3096 | if (vsi->type != I40E_VSI_FDIR) |
| 3097 | tx_ctx.head_wb_ena = 1; |
| 3098 | tx_ctx.head_wb_addr = ring->dma + |
| 3099 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3100 | |
| 3101 | /* As part of VSI creation/update, FW allocates certain |
| 3102 | * Tx arbitration queue sets for each TC enabled for |
| 3103 | * the VSI. The FW returns the handles to these queue |
| 3104 | * sets as part of the response buffer to Add VSI, |
| 3105 | * Update VSI, etc. AQ commands. It is expected that |
| 3106 | * these queue set handles be associated with the Tx |
| 3107 | * queues by the driver as part of the TX queue context |
| 3108 | * initialization. This has to be done regardless of |
| 3109 | * DCB as by default everything is mapped to TC0. |
| 3110 | */ |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 3111 | |
| 3112 | if (ring->ch) |
| 3113 | tx_ctx.rdylist = |
| 3114 | le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]); |
| 3115 | |
| 3116 | else |
| 3117 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 3118 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3119 | tx_ctx.rdylist_act = 0; |
| 3120 | |
| 3121 | /* clear the context in the HMC */ |
| 3122 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 3123 | if (err) { |
| 3124 | dev_info(&vsi->back->pdev->dev, |
| 3125 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 3126 | ring->queue_index, pf_q, err); |
| 3127 | return -ENOMEM; |
| 3128 | } |
| 3129 | |
| 3130 | /* set the context in the HMC */ |
| 3131 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 3132 | if (err) { |
| 3133 | dev_info(&vsi->back->pdev->dev, |
| 3134 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 3135 | ring->queue_index, pf_q, err); |
| 3136 | return -ENOMEM; |
| 3137 | } |
| 3138 | |
| 3139 | /* Now associate this queue with this PCI function */ |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 3140 | if (ring->ch) { |
| 3141 | if (ring->ch->type == I40E_VSI_VMDQ2) |
| 3142 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
| 3143 | else |
| 3144 | return -EINVAL; |
| 3145 | |
| 3146 | qtx_ctl |= (ring->ch->vsi_number << |
| 3147 | I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 3148 | I40E_QTX_CTL_VFVM_INDX_MASK; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 3149 | } else { |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 3150 | if (vsi->type == I40E_VSI_VMDQ2) { |
| 3151 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
| 3152 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 3153 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 3154 | } else { |
| 3155 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
| 3156 | } |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 3159 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 3160 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3161 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 3162 | i40e_flush(hw); |
| 3163 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3164 | /* cache tail off for easier writes later */ |
| 3165 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 3166 | |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
| 3170 | /** |
| 3171 | * i40e_configure_rx_ring - Configure a receive ring context |
| 3172 | * @ring: The Rx ring to configure |
| 3173 | * |
| 3174 | * Configure the Rx descriptor ring in the HMC context. |
| 3175 | **/ |
| 3176 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 3177 | { |
| 3178 | struct i40e_vsi *vsi = ring->vsi; |
| 3179 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 3180 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 3181 | struct i40e_hw *hw = &vsi->back->hw; |
| 3182 | struct i40e_hmc_obj_rxq rx_ctx; |
| 3183 | i40e_status err = 0; |
| 3184 | |
Jesse Brandeburg | bd6cd4e | 2017-08-29 05:32:35 -0400 | [diff] [blame] | 3185 | bitmap_zero(ring->state, __I40E_RING_STATE_NBITS); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3186 | |
| 3187 | /* clear the context structure first */ |
| 3188 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 3189 | |
| 3190 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3191 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3192 | rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len, |
| 3193 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3194 | |
| 3195 | rx_ctx.base = (ring->dma / 128); |
| 3196 | rx_ctx.qlen = ring->count; |
| 3197 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3198 | /* use 32 byte descriptors */ |
| 3199 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3200 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3201 | /* descriptor type is always zero |
| 3202 | * rx_ctx.dtype = 0; |
| 3203 | */ |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3204 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3205 | |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3206 | 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] | 3207 | if (hw->revision_id == 0) |
| 3208 | rx_ctx.lrxqthresh = 0; |
| 3209 | else |
Jacob Keller | 7362be9 | 2017-09-07 08:05:50 -0400 | [diff] [blame] | 3210 | rx_ctx.lrxqthresh = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3211 | rx_ctx.crcstrip = 1; |
| 3212 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3213 | /* this controls whether VLAN is stripped from inner headers */ |
| 3214 | rx_ctx.showiv = 0; |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3215 | /* set the prefena field to 1 because the manual says to */ |
| 3216 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3217 | |
| 3218 | /* clear the context in the HMC */ |
| 3219 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3220 | if (err) { |
| 3221 | dev_info(&vsi->back->pdev->dev, |
| 3222 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3223 | ring->queue_index, pf_q, err); |
| 3224 | return -ENOMEM; |
| 3225 | } |
| 3226 | |
| 3227 | /* set the context in the HMC */ |
| 3228 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3229 | if (err) { |
| 3230 | dev_info(&vsi->back->pdev->dev, |
| 3231 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3232 | ring->queue_index, pf_q, err); |
| 3233 | return -ENOMEM; |
| 3234 | } |
| 3235 | |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3236 | /* configure Rx buffer alignment */ |
| 3237 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 3238 | clear_ring_build_skb_enabled(ring); |
| 3239 | else |
| 3240 | set_ring_build_skb_enabled(ring); |
| 3241 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3242 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3243 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3244 | writel(0, ring->tail); |
| 3245 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3246 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3247 | |
| 3248 | return 0; |
| 3249 | } |
| 3250 | |
| 3251 | /** |
| 3252 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3253 | * @vsi: VSI structure describing this set of rings and resources |
| 3254 | * |
| 3255 | * Configure the Tx VSI for operation. |
| 3256 | **/ |
| 3257 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3258 | { |
| 3259 | int err = 0; |
| 3260 | u16 i; |
| 3261 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3262 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3263 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3264 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3265 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3266 | return err; |
| 3267 | |
| 3268 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3269 | err = i40e_configure_tx_ring(vsi->xdp_rings[i]); |
| 3270 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3271 | return err; |
| 3272 | } |
| 3273 | |
| 3274 | /** |
| 3275 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3276 | * @vsi: the VSI being configured |
| 3277 | * |
| 3278 | * Configure the Rx VSI for operation. |
| 3279 | **/ |
| 3280 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3281 | { |
| 3282 | int err = 0; |
| 3283 | u16 i; |
| 3284 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3285 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) { |
| 3286 | vsi->max_frame = I40E_MAX_RXBUFFER; |
| 3287 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 3288 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3289 | } else if (!I40E_2K_TOO_SMALL_WITH_PADDING && |
| 3290 | (vsi->netdev->mtu <= ETH_DATA_LEN)) { |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3291 | vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3292 | vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3293 | #endif |
| 3294 | } else { |
| 3295 | vsi->max_frame = I40E_MAX_RXBUFFER; |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 3296 | vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 : |
| 3297 | I40E_RXBUFFER_2048; |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3298 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3299 | |
| 3300 | /* set up individual rings */ |
| 3301 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3302 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3303 | |
| 3304 | return err; |
| 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3309 | * @vsi: ptr to the VSI |
| 3310 | **/ |
| 3311 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3312 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3313 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3314 | u16 qoffset, qcount; |
| 3315 | int i, n; |
| 3316 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3317 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3318 | /* Reset the TC information */ |
| 3319 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3320 | rx_ring = vsi->rx_rings[i]; |
| 3321 | tx_ring = vsi->tx_rings[i]; |
| 3322 | rx_ring->dcb_tc = 0; |
| 3323 | tx_ring->dcb_tc = 0; |
| 3324 | } |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 3325 | return; |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3326 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3327 | |
| 3328 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3329 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3330 | continue; |
| 3331 | |
| 3332 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3333 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3334 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3335 | rx_ring = vsi->rx_rings[i]; |
| 3336 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3337 | rx_ring->dcb_tc = n; |
| 3338 | tx_ring->dcb_tc = n; |
| 3339 | } |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | /** |
| 3344 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3345 | * @vsi: ptr to the VSI |
| 3346 | **/ |
| 3347 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3348 | { |
| 3349 | if (vsi->netdev) |
| 3350 | i40e_set_rx_mode(vsi->netdev); |
| 3351 | } |
| 3352 | |
| 3353 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3354 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3355 | * @vsi: Pointer to the targeted VSI |
| 3356 | * |
| 3357 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3358 | * filters were saved. |
| 3359 | **/ |
| 3360 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3361 | { |
| 3362 | struct i40e_fdir_filter *filter; |
| 3363 | struct i40e_pf *pf = vsi->back; |
| 3364 | struct hlist_node *node; |
| 3365 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3366 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3367 | return; |
| 3368 | |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3369 | /* Reset FDir counters as we're replaying all existing filters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3370 | pf->fd_tcp4_filter_cnt = 0; |
| 3371 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 3372 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3373 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3374 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3375 | hlist_for_each_entry_safe(filter, node, |
| 3376 | &pf->fdir_filter_list, fdir_node) { |
| 3377 | i40e_add_del_fdir(vsi, filter, true); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3382 | * i40e_vsi_configure - Set up the VSI for action |
| 3383 | * @vsi: the VSI being configured |
| 3384 | **/ |
| 3385 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3386 | { |
| 3387 | int err; |
| 3388 | |
| 3389 | i40e_set_vsi_rx_mode(vsi); |
| 3390 | i40e_restore_vlan(vsi); |
| 3391 | i40e_vsi_config_dcb_rings(vsi); |
| 3392 | err = i40e_vsi_configure_tx(vsi); |
| 3393 | if (!err) |
| 3394 | err = i40e_vsi_configure_rx(vsi); |
| 3395 | |
| 3396 | return err; |
| 3397 | } |
| 3398 | |
| 3399 | /** |
| 3400 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3401 | * @vsi: the VSI being configured |
| 3402 | **/ |
| 3403 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3404 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3405 | bool has_xdp = i40e_enabled_xdp_vsi(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3406 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3407 | struct i40e_hw *hw = &pf->hw; |
| 3408 | u16 vector; |
| 3409 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3410 | u32 qp; |
| 3411 | |
| 3412 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3413 | * and PFINT_LNKLSTn registers, e.g.: |
| 3414 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3415 | */ |
| 3416 | qp = vsi->base_queue; |
| 3417 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3418 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3419 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3420 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3421 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3422 | 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] | 3423 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3424 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3425 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3426 | 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] | 3427 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3428 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3429 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3430 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 3431 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3432 | |
| 3433 | /* Linked list for the queuepairs assigned to this vector */ |
| 3434 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3435 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3436 | u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3437 | u32 val; |
| 3438 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3439 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3440 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3441 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3442 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | |
| 3443 | (I40E_QUEUE_TYPE_TX << |
| 3444 | I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3445 | |
| 3446 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3447 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3448 | if (has_xdp) { |
| 3449 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3450 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3451 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3452 | (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3453 | (I40E_QUEUE_TYPE_TX << |
| 3454 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3455 | |
| 3456 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3457 | } |
| 3458 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3459 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3460 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3461 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3462 | ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3463 | (I40E_QUEUE_TYPE_RX << |
| 3464 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3465 | |
| 3466 | /* Terminate the linked list */ |
| 3467 | if (q == (q_vector->num_ringpairs - 1)) |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3468 | val |= (I40E_QUEUE_END_OF_LIST << |
| 3469 | I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3470 | |
| 3471 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3472 | qp++; |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | i40e_flush(hw); |
| 3477 | } |
| 3478 | |
| 3479 | /** |
| 3480 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3481 | * @hw: ptr to the hardware info |
| 3482 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3483 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3484 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3485 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3486 | u32 val; |
| 3487 | |
| 3488 | /* clear things first */ |
| 3489 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3490 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3491 | |
| 3492 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3493 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3494 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3495 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3496 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3497 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3498 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3499 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3500 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3501 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3502 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3503 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3504 | if (pf->flags & I40E_FLAG_PTP) |
| 3505 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3506 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3507 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3508 | |
| 3509 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3510 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3511 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3512 | |
| 3513 | /* OTHER_ITR_IDX = 0 */ |
| 3514 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3519 | * @vsi: the VSI being configured |
| 3520 | **/ |
| 3521 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3522 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3523 | u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3524 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3525 | struct i40e_pf *pf = vsi->back; |
| 3526 | struct i40e_hw *hw = &pf->hw; |
| 3527 | u32 val; |
| 3528 | |
| 3529 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3530 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3531 | 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] | 3532 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3533 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3534 | 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] | 3535 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3536 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3537 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3538 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3539 | |
| 3540 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3541 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3542 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3543 | /* 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] | 3544 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3545 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3546 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3548 | |
| 3549 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3550 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3551 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 3552 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3553 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)| |
| 3554 | (I40E_QUEUE_TYPE_TX |
| 3555 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3556 | |
| 3557 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3558 | } |
| 3559 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3560 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3561 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3562 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3563 | |
| 3564 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3565 | i40e_flush(hw); |
| 3566 | } |
| 3567 | |
| 3568 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3569 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3570 | * @pf: board private structure |
| 3571 | **/ |
| 3572 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3573 | { |
| 3574 | struct i40e_hw *hw = &pf->hw; |
| 3575 | |
| 3576 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3577 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3578 | i40e_flush(hw); |
| 3579 | } |
| 3580 | |
| 3581 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3582 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3583 | * @pf: board private structure |
| 3584 | **/ |
Jacob Keller | dbadbbe | 2017-09-07 08:05:49 -0400 | [diff] [blame] | 3585 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3586 | { |
| 3587 | struct i40e_hw *hw = &pf->hw; |
| 3588 | u32 val; |
| 3589 | |
| 3590 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jacob Keller | dbadbbe | 2017-09-07 08:05:49 -0400 | [diff] [blame] | 3591 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3592 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3593 | |
| 3594 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3595 | i40e_flush(hw); |
| 3596 | } |
| 3597 | |
| 3598 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3599 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3600 | * @irq: interrupt number |
| 3601 | * @data: pointer to a q_vector |
| 3602 | **/ |
| 3603 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3604 | { |
| 3605 | struct i40e_q_vector *q_vector = data; |
| 3606 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3607 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3608 | return IRQ_HANDLED; |
| 3609 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3610 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3611 | |
| 3612 | return IRQ_HANDLED; |
| 3613 | } |
| 3614 | |
| 3615 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3616 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3617 | * @notify: context as to what irq was changed |
| 3618 | * @mask: the new affinity mask |
| 3619 | * |
| 3620 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3621 | * so that we may register to receive changes to the irq affinity masks. |
| 3622 | **/ |
| 3623 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3624 | const cpumask_t *mask) |
| 3625 | { |
| 3626 | struct i40e_q_vector *q_vector = |
| 3627 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3628 | |
Jacob Keller | 7e4d01e | 2017-07-12 05:46:05 -0400 | [diff] [blame] | 3629 | cpumask_copy(&q_vector->affinity_mask, mask); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | /** |
| 3633 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3634 | * @ref: internal core kernel usage |
| 3635 | * |
| 3636 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3637 | * to inform the current notification subscriber that they will no longer |
| 3638 | * receive notifications. |
| 3639 | **/ |
| 3640 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3641 | |
| 3642 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3643 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3644 | * @vsi: the VSI being configured |
| 3645 | * @basename: name for the vector |
| 3646 | * |
| 3647 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3648 | **/ |
| 3649 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3650 | { |
| 3651 | int q_vectors = vsi->num_q_vectors; |
| 3652 | struct i40e_pf *pf = vsi->back; |
| 3653 | int base = vsi->base_vector; |
| 3654 | int rx_int_idx = 0; |
| 3655 | int tx_int_idx = 0; |
| 3656 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3657 | int irq_num; |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3658 | int cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3659 | |
| 3660 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3661 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3662 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3663 | irq_num = pf->msix_entries[base + vector].vector; |
| 3664 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3665 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3666 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3667 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3668 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3669 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3670 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3671 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3672 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3673 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3674 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3675 | } else { |
| 3676 | /* skip this unused q_vector */ |
| 3677 | continue; |
| 3678 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3679 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3680 | vsi->irq_handler, |
| 3681 | 0, |
| 3682 | q_vector->name, |
| 3683 | q_vector); |
| 3684 | if (err) { |
| 3685 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3686 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3687 | goto free_queue_irqs; |
| 3688 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3689 | |
| 3690 | /* register for affinity change notifications */ |
| 3691 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3692 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3693 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3694 | /* Spread affinity hints out across online CPUs. |
| 3695 | * |
| 3696 | * get_cpu_mask returns a static constant mask with |
| 3697 | * a permanent lifetime so it's ok to pass to |
| 3698 | * irq_set_affinity_hint without making a copy. |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 3699 | */ |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3700 | cpu = cpumask_local_spread(q_vector->v_idx, -1); |
| 3701 | irq_set_affinity_hint(irq_num, get_cpu_mask(cpu)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3704 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3705 | return 0; |
| 3706 | |
| 3707 | free_queue_irqs: |
| 3708 | while (vector) { |
| 3709 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3710 | irq_num = pf->msix_entries[base + vector].vector; |
| 3711 | irq_set_affinity_notifier(irq_num, NULL); |
| 3712 | irq_set_affinity_hint(irq_num, NULL); |
| 3713 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3714 | } |
| 3715 | return err; |
| 3716 | } |
| 3717 | |
| 3718 | /** |
| 3719 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3720 | * @vsi: the VSI being un-configured |
| 3721 | **/ |
| 3722 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3723 | { |
| 3724 | struct i40e_pf *pf = vsi->back; |
| 3725 | struct i40e_hw *hw = &pf->hw; |
| 3726 | int base = vsi->base_vector; |
| 3727 | int i; |
| 3728 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3729 | /* disable interrupt causation from each queue */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3730 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3731 | u32 val; |
| 3732 | |
| 3733 | val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx)); |
| 3734 | val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3735 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val); |
| 3736 | |
| 3737 | val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx)); |
| 3738 | val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3739 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val); |
| 3740 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3741 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3742 | continue; |
| 3743 | wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3746 | /* disable each interrupt */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3747 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3748 | for (i = vsi->base_vector; |
| 3749 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3750 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3751 | |
| 3752 | i40e_flush(hw); |
| 3753 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3754 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3755 | } else { |
| 3756 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3757 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3758 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3759 | i40e_flush(hw); |
| 3760 | synchronize_irq(pf->pdev->irq); |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | /** |
| 3765 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3766 | * @vsi: the VSI being configured |
| 3767 | **/ |
| 3768 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3769 | { |
| 3770 | struct i40e_pf *pf = vsi->back; |
| 3771 | int i; |
| 3772 | |
| 3773 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3774 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3775 | i40e_irq_dynamic_enable(vsi, i); |
| 3776 | } else { |
Jacob Keller | dbadbbe | 2017-09-07 08:05:49 -0400 | [diff] [blame] | 3777 | i40e_irq_dynamic_enable_icr0(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3780 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3781 | return 0; |
| 3782 | } |
| 3783 | |
| 3784 | /** |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3785 | * i40e_free_misc_vector - Free the vector that handles non-queue events |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3786 | * @pf: board private structure |
| 3787 | **/ |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3788 | static void i40e_free_misc_vector(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3789 | { |
| 3790 | /* Disable ICR 0 */ |
| 3791 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3792 | i40e_flush(&pf->hw); |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3793 | |
| 3794 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
| 3795 | synchronize_irq(pf->msix_entries[0].vector); |
| 3796 | free_irq(pf->msix_entries[0].vector, pf); |
| 3797 | clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state); |
| 3798 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3803 | * @irq: interrupt number |
| 3804 | * @data: pointer to a q_vector |
| 3805 | * |
| 3806 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3807 | * with both queue and non-queue interrupts. This is also used in |
| 3808 | * MSIX mode to handle the non-queue interrupts. |
| 3809 | **/ |
| 3810 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3811 | { |
| 3812 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3813 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3814 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3815 | u32 icr0, icr0_remaining; |
| 3816 | u32 val, ena_mask; |
| 3817 | |
| 3818 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3819 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3820 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3821 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3822 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3823 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3824 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3825 | /* if interrupt but no bits showing, must be SWINT */ |
| 3826 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3827 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3828 | pf->sw_int_count++; |
| 3829 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3830 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3831 | (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3832 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
Carolyn Wyborny | 23bb6dc | 2016-11-08 13:05:12 -0800 | [diff] [blame] | 3833 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3834 | set_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3835 | } |
| 3836 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3837 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3838 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3839 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3840 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3841 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3842 | /* We do not have a way to disarm Queue causes while leaving |
| 3843 | * interrupt enabled for all other causes, ideally |
| 3844 | * interrupt should be disabled while we are in NAPI but |
| 3845 | * this is not a performance path and napi_schedule() |
| 3846 | * can deal with rescheduling. |
| 3847 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3848 | if (!test_bit(__I40E_DOWN, pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3849 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3853 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3854 | set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3855 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3859 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3860 | set_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3864 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3865 | set_bit(__I40E_VFLR_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3869 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
| 3870 | set_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3871 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3872 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3873 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3874 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3875 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3876 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3877 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3878 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3879 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3880 | pf->empr_count++; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3881 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3882 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3885 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3886 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3887 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3888 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3889 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3890 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3893 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3894 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3895 | |
| 3896 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3897 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3898 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3899 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3902 | /* If a critical error is pending we have no choice but to reset the |
| 3903 | * device. |
| 3904 | * Report and mask out any remaining unexpected interrupts. |
| 3905 | */ |
| 3906 | icr0_remaining = icr0 & ena_mask; |
| 3907 | if (icr0_remaining) { |
| 3908 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3909 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3910 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3911 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3912 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3913 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3914 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3915 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3916 | } |
| 3917 | ena_mask &= ~icr0_remaining; |
| 3918 | } |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3919 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3920 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3921 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3922 | /* re-enable interrupt causes */ |
| 3923 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3924 | if (!test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | i40e_service_event_schedule(pf); |
Jacob Keller | dbadbbe | 2017-09-07 08:05:49 -0400 | [diff] [blame] | 3926 | i40e_irq_dynamic_enable_icr0(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3927 | } |
| 3928 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3929 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3933 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3934 | * @tx_ring: tx ring to clean |
| 3935 | * @budget: how many cleans we're allowed |
| 3936 | * |
| 3937 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3938 | **/ |
| 3939 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3940 | { |
| 3941 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3942 | u16 i = tx_ring->next_to_clean; |
| 3943 | struct i40e_tx_buffer *tx_buf; |
| 3944 | struct i40e_tx_desc *tx_desc; |
| 3945 | |
| 3946 | tx_buf = &tx_ring->tx_bi[i]; |
| 3947 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3948 | i -= tx_ring->count; |
| 3949 | |
| 3950 | do { |
| 3951 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3952 | |
| 3953 | /* if next_to_watch is not set then there is no work pending */ |
| 3954 | if (!eop_desc) |
| 3955 | break; |
| 3956 | |
| 3957 | /* prevent any other reads prior to eop_desc */ |
| 3958 | read_barrier_depends(); |
| 3959 | |
| 3960 | /* if the descriptor isn't done, no work yet to do */ |
| 3961 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3962 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3963 | break; |
| 3964 | |
| 3965 | /* clear next_to_watch to prevent false hangs */ |
| 3966 | tx_buf->next_to_watch = NULL; |
| 3967 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3968 | tx_desc->buffer_addr = 0; |
| 3969 | tx_desc->cmd_type_offset_bsz = 0; |
| 3970 | /* move past filter desc */ |
| 3971 | tx_buf++; |
| 3972 | tx_desc++; |
| 3973 | i++; |
| 3974 | if (unlikely(!i)) { |
| 3975 | i -= tx_ring->count; |
| 3976 | tx_buf = tx_ring->tx_bi; |
| 3977 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3978 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3979 | /* unmap skb header data */ |
| 3980 | dma_unmap_single(tx_ring->dev, |
| 3981 | dma_unmap_addr(tx_buf, dma), |
| 3982 | dma_unmap_len(tx_buf, len), |
| 3983 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3984 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3985 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3986 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3987 | tx_buf->raw_buf = NULL; |
| 3988 | tx_buf->tx_flags = 0; |
| 3989 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3990 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3991 | tx_desc->buffer_addr = 0; |
| 3992 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3993 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3994 | /* 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] | 3995 | tx_buf++; |
| 3996 | tx_desc++; |
| 3997 | i++; |
| 3998 | if (unlikely(!i)) { |
| 3999 | i -= tx_ring->count; |
| 4000 | tx_buf = tx_ring->tx_bi; |
| 4001 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 4002 | } |
| 4003 | |
| 4004 | /* update budget accounting */ |
| 4005 | budget--; |
| 4006 | } while (likely(budget)); |
| 4007 | |
| 4008 | i += tx_ring->count; |
| 4009 | tx_ring->next_to_clean = i; |
| 4010 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4011 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 4012 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4013 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 4014 | return budget > 0; |
| 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 4019 | * @irq: interrupt number |
| 4020 | * @data: pointer to a q_vector |
| 4021 | **/ |
| 4022 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 4023 | { |
| 4024 | struct i40e_q_vector *q_vector = data; |
| 4025 | struct i40e_vsi *vsi; |
| 4026 | |
| 4027 | if (!q_vector->tx.ring) |
| 4028 | return IRQ_HANDLED; |
| 4029 | |
| 4030 | vsi = q_vector->tx.ring->vsi; |
| 4031 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 4032 | |
| 4033 | return IRQ_HANDLED; |
| 4034 | } |
| 4035 | |
| 4036 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4037 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4038 | * @vsi: the VSI being configured |
| 4039 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4040 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4041 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 4042 | 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] | 4043 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4044 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4045 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 4046 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4047 | |
| 4048 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4049 | tx_ring->next = q_vector->tx.ring; |
| 4050 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4051 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4052 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4053 | /* Place XDP Tx ring in the same q_vector ring list as regular Tx */ |
| 4054 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 4055 | struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx]; |
| 4056 | |
| 4057 | xdp_ring->q_vector = q_vector; |
| 4058 | xdp_ring->next = q_vector->tx.ring; |
| 4059 | q_vector->tx.ring = xdp_ring; |
| 4060 | q_vector->tx.count++; |
| 4061 | } |
| 4062 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4063 | rx_ring->q_vector = q_vector; |
| 4064 | rx_ring->next = q_vector->rx.ring; |
| 4065 | q_vector->rx.ring = rx_ring; |
| 4066 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | /** |
| 4070 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 4071 | * @vsi: the VSI being configured |
| 4072 | * |
| 4073 | * This function maps descriptor rings to the queue-specific vectors |
| 4074 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 4075 | * one vector per queue pair, but on a constrained vector budget, we |
| 4076 | * group the queue pairs as "efficiently" as possible. |
| 4077 | **/ |
| 4078 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 4079 | { |
| 4080 | int qp_remaining = vsi->num_queue_pairs; |
| 4081 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4082 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4083 | int v_start = 0; |
| 4084 | int qp_idx = 0; |
| 4085 | |
| 4086 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 4087 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 4088 | * It is also important to go through all the vectors available to be |
| 4089 | * sure that if we don't use all the vectors, that the remaining vectors |
| 4090 | * are cleared. This is especially important when decreasing the |
| 4091 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4092 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 4093 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4094 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 4095 | |
| 4096 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 4097 | |
| 4098 | q_vector->num_ringpairs = num_ringpairs; |
| 4099 | |
| 4100 | q_vector->rx.count = 0; |
| 4101 | q_vector->tx.count = 0; |
| 4102 | q_vector->rx.ring = NULL; |
| 4103 | q_vector->tx.ring = NULL; |
| 4104 | |
| 4105 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 4106 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4107 | qp_idx++; |
| 4108 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4109 | } |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | /** |
| 4114 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 4115 | * @vsi: the VSI being configured |
| 4116 | * @basename: name for the vector |
| 4117 | **/ |
| 4118 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 4119 | { |
| 4120 | struct i40e_pf *pf = vsi->back; |
| 4121 | int err; |
| 4122 | |
| 4123 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4124 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 4125 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 4126 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 4127 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4128 | else |
| 4129 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 4130 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4131 | |
| 4132 | if (err) |
| 4133 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 4134 | |
| 4135 | return err; |
| 4136 | } |
| 4137 | |
| 4138 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4139 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 4140 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4141 | * @netdev: network interface device structure |
| 4142 | * |
| 4143 | * This is used by netconsole to send skbs without having to re-enable |
| 4144 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 4145 | **/ |
| 4146 | static void i40e_netpoll(struct net_device *netdev) |
| 4147 | { |
| 4148 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4149 | struct i40e_vsi *vsi = np->vsi; |
| 4150 | struct i40e_pf *pf = vsi->back; |
| 4151 | int i; |
| 4152 | |
| 4153 | /* if interface is down do nothing */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4154 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4155 | return; |
| 4156 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4157 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4158 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4159 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4160 | } else { |
| 4161 | i40e_intr(pf->pdev->irq, netdev); |
| 4162 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4163 | } |
| 4164 | #endif |
| 4165 | |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4166 | #define I40E_QTX_ENA_WAIT_COUNT 50 |
| 4167 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4168 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4169 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 4170 | * @pf: the PF being configured |
| 4171 | * @pf_q: the PF queue |
| 4172 | * @enable: enable or disable state of the queue |
| 4173 | * |
| 4174 | * This routine will wait for the given Tx queue of the PF to reach the |
| 4175 | * enabled or disabled state. |
| 4176 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4177 | * multiple retries; else will return 0 in case of success. |
| 4178 | **/ |
| 4179 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4180 | { |
| 4181 | int i; |
| 4182 | u32 tx_reg; |
| 4183 | |
| 4184 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4185 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 4186 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4187 | break; |
| 4188 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4189 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4190 | } |
| 4191 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4192 | return -ETIMEDOUT; |
| 4193 | |
| 4194 | return 0; |
| 4195 | } |
| 4196 | |
| 4197 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4198 | * i40e_control_tx_q - Start or stop a particular Tx queue |
| 4199 | * @pf: the PF structure |
| 4200 | * @pf_q: the PF queue to configure |
| 4201 | * @enable: start or stop the queue |
| 4202 | * |
| 4203 | * This function enables or disables a single queue. Note that any delay |
| 4204 | * required after the operation is expected to be handled by the caller of |
| 4205 | * this function. |
| 4206 | **/ |
| 4207 | static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4208 | { |
| 4209 | struct i40e_hw *hw = &pf->hw; |
| 4210 | u32 tx_reg; |
| 4211 | int i; |
| 4212 | |
| 4213 | /* warn the TX unit of coming changes */ |
| 4214 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 4215 | if (!enable) |
| 4216 | usleep_range(10, 20); |
| 4217 | |
| 4218 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4219 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
| 4220 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4221 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4222 | break; |
| 4223 | usleep_range(1000, 2000); |
| 4224 | } |
| 4225 | |
| 4226 | /* Skip if the queue is already in the requested state */ |
| 4227 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4228 | return; |
| 4229 | |
| 4230 | /* turn on/off the queue */ |
| 4231 | if (enable) { |
| 4232 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
| 4233 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
| 4234 | } else { |
| 4235 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
| 4236 | } |
| 4237 | |
| 4238 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
| 4239 | } |
| 4240 | |
| 4241 | /** |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4242 | * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion |
| 4243 | * @seid: VSI SEID |
| 4244 | * @pf: the PF structure |
| 4245 | * @pf_q: the PF queue to configure |
| 4246 | * @is_xdp: true if the queue is used for XDP |
| 4247 | * @enable: start or stop the queue |
| 4248 | **/ |
| 4249 | static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q, |
| 4250 | bool is_xdp, bool enable) |
| 4251 | { |
| 4252 | int ret; |
| 4253 | |
| 4254 | i40e_control_tx_q(pf, pf_q, enable); |
| 4255 | |
| 4256 | /* wait for the change to finish */ |
| 4257 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 4258 | if (ret) { |
| 4259 | dev_info(&pf->pdev->dev, |
| 4260 | "VSI seid %d %sTx ring %d %sable timeout\n", |
| 4261 | seid, (is_xdp ? "XDP " : ""), pf_q, |
| 4262 | (enable ? "en" : "dis")); |
| 4263 | } |
| 4264 | |
| 4265 | return ret; |
| 4266 | } |
| 4267 | |
| 4268 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4269 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 4270 | * @vsi: the VSI being configured |
| 4271 | * @enable: start or stop the rings |
| 4272 | **/ |
| 4273 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 4274 | { |
| 4275 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4276 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4277 | |
| 4278 | pf_q = vsi->base_queue; |
| 4279 | 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] | 4280 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4281 | pf_q, |
| 4282 | false /*is xdp*/, enable); |
| 4283 | if (ret) |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4284 | break; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4285 | |
| 4286 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4287 | continue; |
| 4288 | |
| 4289 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4290 | pf_q + vsi->alloc_queue_pairs, |
| 4291 | true /*is xdp*/, enable); |
| 4292 | if (ret) |
| 4293 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4294 | } |
| 4295 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4296 | return ret; |
| 4297 | } |
| 4298 | |
| 4299 | /** |
| 4300 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 4301 | * @pf: the PF being configured |
| 4302 | * @pf_q: the PF queue |
| 4303 | * @enable: enable or disable state of the queue |
| 4304 | * |
| 4305 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4306 | * enabled or disabled state. |
| 4307 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4308 | * multiple retries; else will return 0 in case of success. |
| 4309 | **/ |
| 4310 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4311 | { |
| 4312 | int i; |
| 4313 | u32 rx_reg; |
| 4314 | |
| 4315 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4316 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4317 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4318 | break; |
| 4319 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4320 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4321 | } |
| 4322 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4323 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4324 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4325 | return 0; |
| 4326 | } |
| 4327 | |
| 4328 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4329 | * i40e_control_rx_q - Start or stop a particular Rx queue |
| 4330 | * @pf: the PF structure |
| 4331 | * @pf_q: the PF queue to configure |
| 4332 | * @enable: start or stop the queue |
| 4333 | * |
| 4334 | * This function enables or disables a single queue. Note that any delay |
| 4335 | * required after the operation is expected to be handled by the caller of |
| 4336 | * this function. |
| 4337 | **/ |
| 4338 | static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4339 | { |
| 4340 | struct i40e_hw *hw = &pf->hw; |
| 4341 | u32 rx_reg; |
| 4342 | int i; |
| 4343 | |
| 4344 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4345 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 4346 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4347 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4348 | break; |
| 4349 | usleep_range(1000, 2000); |
| 4350 | } |
| 4351 | |
| 4352 | /* Skip if the queue is already in the requested state */ |
| 4353 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4354 | return; |
| 4355 | |
| 4356 | /* turn on/off the queue */ |
| 4357 | if (enable) |
| 4358 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
| 4359 | else |
| 4360 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
| 4361 | |
| 4362 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 4363 | } |
| 4364 | |
| 4365 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4366 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4367 | * @vsi: the VSI being configured |
| 4368 | * @enable: start or stop the rings |
| 4369 | **/ |
| 4370 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4371 | { |
| 4372 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4373 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4374 | |
| 4375 | pf_q = vsi->base_queue; |
| 4376 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4377 | i40e_control_rx_q(pf, pf_q, enable); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4378 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4379 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4380 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4381 | if (ret) { |
| 4382 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4383 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4384 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4385 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | |
Wyborny, Carolyn | d08a9f6 | 2017-03-28 08:00:48 -0700 | [diff] [blame] | 4389 | /* Due to HW errata, on Rx disable only, the register can indicate done |
| 4390 | * before it really is. Needs 50ms to be sure |
| 4391 | */ |
| 4392 | if (!enable) |
| 4393 | mdelay(50); |
| 4394 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4395 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4399 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4400 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4401 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4402 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4403 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4404 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4405 | |
| 4406 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4407 | ret = i40e_vsi_control_rx(vsi, true); |
| 4408 | if (ret) |
| 4409 | return ret; |
| 4410 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4411 | |
| 4412 | return ret; |
| 4413 | } |
| 4414 | |
| 4415 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4416 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4417 | * @vsi: the VSI being configured |
| 4418 | **/ |
| 4419 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4420 | { |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4421 | /* When port TX is suspended, don't wait */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4422 | if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state)) |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4423 | return i40e_vsi_stop_rings_no_wait(vsi); |
| 4424 | |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4425 | /* do rx first for enable and last for disable |
| 4426 | * Ignore return value, we need to shutdown whatever we can |
| 4427 | */ |
| 4428 | i40e_vsi_control_tx(vsi, false); |
| 4429 | i40e_vsi_control_rx(vsi, false); |
| 4430 | } |
| 4431 | |
| 4432 | /** |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4433 | * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay |
| 4434 | * @vsi: the VSI being shutdown |
| 4435 | * |
| 4436 | * This function stops all the rings for a VSI but does not delay to verify |
| 4437 | * that rings have been disabled. It is expected that the caller is shutting |
| 4438 | * down multiple VSIs at once and will delay together for all the VSIs after |
| 4439 | * initiating the shutdown. This is particularly useful for shutting down lots |
| 4440 | * of VFs together. Otherwise, a large delay can be incurred while configuring |
| 4441 | * each VSI in serial. |
| 4442 | **/ |
| 4443 | void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi) |
| 4444 | { |
| 4445 | struct i40e_pf *pf = vsi->back; |
| 4446 | int i, pf_q; |
| 4447 | |
| 4448 | pf_q = vsi->base_queue; |
| 4449 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4450 | i40e_control_tx_q(pf, pf_q, false); |
| 4451 | i40e_control_rx_q(pf, pf_q, false); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4456 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4457 | * @vsi: the VSI being configured |
| 4458 | **/ |
| 4459 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4460 | { |
| 4461 | struct i40e_pf *pf = vsi->back; |
| 4462 | struct i40e_hw *hw = &pf->hw; |
| 4463 | int base = vsi->base_vector; |
| 4464 | u32 val, qp; |
| 4465 | int i; |
| 4466 | |
| 4467 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4468 | if (!vsi->q_vectors) |
| 4469 | return; |
| 4470 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4471 | if (!vsi->irqs_ready) |
| 4472 | return; |
| 4473 | |
| 4474 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4475 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4476 | int irq_num; |
| 4477 | u16 vector; |
| 4478 | |
| 4479 | vector = i + base; |
| 4480 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4481 | |
| 4482 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4483 | if (!vsi->q_vectors[i] || |
| 4484 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4485 | continue; |
| 4486 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4487 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4488 | irq_set_affinity_notifier(irq_num, NULL); |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 4489 | /* remove our suggested affinity mask for this IRQ */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4490 | irq_set_affinity_hint(irq_num, NULL); |
| 4491 | synchronize_irq(irq_num); |
| 4492 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4493 | |
| 4494 | /* Tear down the interrupt queue link list |
| 4495 | * |
| 4496 | * We know that they come in pairs and always |
| 4497 | * the Rx first, then the Tx. To clear the |
| 4498 | * link list, stick the EOL value into the |
| 4499 | * next_q field of the registers. |
| 4500 | */ |
| 4501 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4502 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4503 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4504 | val |= I40E_QUEUE_END_OF_LIST |
| 4505 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4506 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4507 | |
| 4508 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4509 | u32 next; |
| 4510 | |
| 4511 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4512 | |
| 4513 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4514 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4515 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4516 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4517 | |
| 4518 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4519 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4520 | |
| 4521 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4522 | |
| 4523 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4524 | |
| 4525 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4526 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4527 | |
| 4528 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4529 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4530 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4531 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4532 | |
| 4533 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4534 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4535 | |
| 4536 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4537 | qp = next; |
| 4538 | } |
| 4539 | } |
| 4540 | } else { |
| 4541 | free_irq(pf->pdev->irq, pf); |
| 4542 | |
| 4543 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4544 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4545 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4546 | val |= I40E_QUEUE_END_OF_LIST |
| 4547 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4548 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4549 | |
| 4550 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4551 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4552 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4553 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4554 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4555 | |
| 4556 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4557 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4558 | |
| 4559 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4560 | |
| 4561 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4562 | |
| 4563 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4564 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4565 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4566 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4567 | |
| 4568 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4569 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4570 | |
| 4571 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4576 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4577 | * @vsi: the VSI being configured |
| 4578 | * @v_idx: Index of vector to be freed |
| 4579 | * |
| 4580 | * This function frees the memory allocated to the q_vector. In addition if |
| 4581 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4582 | * to freeing the q_vector. |
| 4583 | **/ |
| 4584 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4585 | { |
| 4586 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4587 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4588 | |
| 4589 | if (!q_vector) |
| 4590 | return; |
| 4591 | |
| 4592 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4593 | i40e_for_each_ring(ring, q_vector->tx) |
| 4594 | ring->q_vector = NULL; |
| 4595 | |
| 4596 | i40e_for_each_ring(ring, q_vector->rx) |
| 4597 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4598 | |
| 4599 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4600 | if (vsi->netdev) |
| 4601 | netif_napi_del(&q_vector->napi); |
| 4602 | |
| 4603 | vsi->q_vectors[v_idx] = NULL; |
| 4604 | |
| 4605 | kfree_rcu(q_vector, rcu); |
| 4606 | } |
| 4607 | |
| 4608 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4609 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4610 | * @vsi: the VSI being un-configured |
| 4611 | * |
| 4612 | * This frees the memory allocated to the q_vectors and |
| 4613 | * deletes references to the NAPI struct. |
| 4614 | **/ |
| 4615 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4616 | { |
| 4617 | int v_idx; |
| 4618 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4619 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4620 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4625 | * @pf: board private structure |
| 4626 | **/ |
| 4627 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4628 | { |
| 4629 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4630 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4631 | pci_disable_msix(pf->pdev); |
| 4632 | kfree(pf->msix_entries); |
| 4633 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4634 | kfree(pf->irq_pile); |
| 4635 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4636 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4637 | pci_disable_msi(pf->pdev); |
| 4638 | } |
| 4639 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4644 | * @pf: board private structure |
| 4645 | * |
| 4646 | * We go through and clear interrupt specific resources and reset the structure |
| 4647 | * to pre-load conditions |
| 4648 | **/ |
| 4649 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4650 | { |
| 4651 | int i; |
| 4652 | |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 4653 | i40e_free_misc_vector(pf); |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4654 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4655 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4656 | I40E_IWARP_IRQ_PILE_ID); |
| 4657 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4658 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4659 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4660 | if (pf->vsi[i]) |
| 4661 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4662 | i40e_reset_interrupt_capability(pf); |
| 4663 | } |
| 4664 | |
| 4665 | /** |
| 4666 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4667 | * @vsi: the VSI being configured |
| 4668 | **/ |
| 4669 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4670 | { |
| 4671 | int q_idx; |
| 4672 | |
| 4673 | if (!vsi->netdev) |
| 4674 | return; |
| 4675 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4676 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4677 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4678 | |
| 4679 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4680 | napi_enable(&q_vector->napi); |
| 4681 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | /** |
| 4685 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4686 | * @vsi: the VSI being configured |
| 4687 | **/ |
| 4688 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4689 | { |
| 4690 | int q_idx; |
| 4691 | |
| 4692 | if (!vsi->netdev) |
| 4693 | return; |
| 4694 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4695 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4696 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4697 | |
| 4698 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4699 | napi_disable(&q_vector->napi); |
| 4700 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4704 | * i40e_vsi_close - Shut down a VSI |
| 4705 | * @vsi: the vsi to be quelled |
| 4706 | **/ |
| 4707 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4708 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4709 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4710 | if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state)) |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4711 | i40e_down(vsi); |
| 4712 | i40e_vsi_free_irq(vsi); |
| 4713 | i40e_vsi_free_tx_resources(vsi); |
| 4714 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4715 | vsi->current_netdev_flags = 0; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4716 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4717 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4718 | pf->flags |= I40E_FLAG_CLIENT_RESET; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4722 | * i40e_quiesce_vsi - Pause a given VSI |
| 4723 | * @vsi: the VSI being paused |
| 4724 | **/ |
| 4725 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4726 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4727 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4728 | return; |
| 4729 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4730 | set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4731 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4732 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4733 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4734 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | /** |
| 4738 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4739 | * @vsi: the VSI being resumed |
| 4740 | **/ |
| 4741 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4742 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4743 | if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4744 | return; |
| 4745 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4746 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4747 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4748 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4749 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | /** |
| 4753 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4754 | * @pf: the PF |
| 4755 | **/ |
| 4756 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4757 | { |
| 4758 | int v; |
| 4759 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4760 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4761 | if (pf->vsi[v]) |
| 4762 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4768 | * @pf: the PF |
| 4769 | **/ |
| 4770 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4771 | { |
| 4772 | int v; |
| 4773 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4774 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4775 | if (pf->vsi[v]) |
| 4776 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4777 | } |
| 4778 | } |
| 4779 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4780 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4781 | * 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] | 4782 | * @vsi: the VSI being configured |
| 4783 | * |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4784 | * Wait until all queues on a given VSI have been disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4785 | **/ |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4786 | int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4787 | { |
| 4788 | struct i40e_pf *pf = vsi->back; |
| 4789 | int i, pf_q, ret; |
| 4790 | |
| 4791 | pf_q = vsi->base_queue; |
| 4792 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4793 | /* Check and wait for the Tx queue */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4794 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4795 | if (ret) { |
| 4796 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4797 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4798 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4799 | return ret; |
| 4800 | } |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4801 | |
| 4802 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4803 | goto wait_rx; |
| 4804 | |
| 4805 | /* Check and wait for the XDP Tx queue */ |
| 4806 | ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs, |
| 4807 | false); |
| 4808 | if (ret) { |
| 4809 | dev_info(&pf->pdev->dev, |
| 4810 | "VSI seid %d XDP Tx ring %d disable timeout\n", |
| 4811 | vsi->seid, pf_q); |
| 4812 | return ret; |
| 4813 | } |
| 4814 | wait_rx: |
| 4815 | /* Check and wait for the Rx queue */ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4816 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4817 | if (ret) { |
| 4818 | dev_info(&pf->pdev->dev, |
| 4819 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4820 | vsi->seid, pf_q); |
| 4821 | return ret; |
| 4822 | } |
| 4823 | } |
| 4824 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4825 | return 0; |
| 4826 | } |
| 4827 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4828 | #ifdef CONFIG_I40E_DCB |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4829 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4830 | * 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] | 4831 | * @pf: the PF |
| 4832 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4833 | * 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] | 4834 | * VSIs that are managed by this PF. |
| 4835 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4836 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4837 | { |
| 4838 | int v, ret = 0; |
| 4839 | |
| 4840 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 4841 | if (pf->vsi[v]) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4842 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4843 | if (ret) |
| 4844 | break; |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | return ret; |
| 4849 | } |
| 4850 | |
| 4851 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4852 | |
| 4853 | /** |
| 4854 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4855 | * @q_idx: TX queue number |
| 4856 | * @vsi: Pointer to VSI struct |
| 4857 | * |
| 4858 | * This function checks specified queue for given VSI. Detects hung condition. |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4859 | * We proactively detect hung TX queues by checking if interrupts are disabled |
| 4860 | * but there are pending descriptors. If it appears hung, attempt to recover |
| 4861 | * by triggering a SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4862 | **/ |
| 4863 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4864 | { |
| 4865 | struct i40e_ring *tx_ring = NULL; |
| 4866 | struct i40e_pf *pf; |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4867 | u32 val, tx_pending; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4868 | int i; |
| 4869 | |
| 4870 | pf = vsi->back; |
| 4871 | |
| 4872 | /* now that we have an index, find the tx_ring struct */ |
| 4873 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4874 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4875 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4876 | tx_ring = vsi->tx_rings[i]; |
| 4877 | break; |
| 4878 | } |
| 4879 | } |
| 4880 | } |
| 4881 | |
| 4882 | if (!tx_ring) |
| 4883 | return; |
| 4884 | |
| 4885 | /* Read interrupt register */ |
| 4886 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4887 | val = rd32(&pf->hw, |
| 4888 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4889 | tx_ring->vsi->base_vector - 1)); |
| 4890 | else |
| 4891 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4892 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4893 | tx_pending = i40e_get_tx_pending(tx_ring); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4894 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4895 | /* Interrupts are disabled and TX pending is non-zero, |
| 4896 | * trigger the SW interrupt (don't wait). Worst case |
| 4897 | * there will be one extra interrupt which may result |
| 4898 | * into not cleaning any queues because queues are cleaned. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4899 | */ |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4900 | if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) |
| 4901 | i40e_force_wb(vsi, tx_ring->q_vector); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | /** |
| 4905 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4906 | * @pf: pointer to PF struct |
| 4907 | * |
| 4908 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4909 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4910 | * SW interrupt. |
| 4911 | **/ |
| 4912 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4913 | { |
| 4914 | struct net_device *netdev; |
| 4915 | struct i40e_vsi *vsi; |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 4916 | unsigned int i; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4917 | |
| 4918 | /* Only for LAN VSI */ |
| 4919 | vsi = pf->vsi[pf->lan_vsi]; |
| 4920 | |
| 4921 | if (!vsi) |
| 4922 | return; |
| 4923 | |
| 4924 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4925 | if (test_bit(__I40E_VSI_DOWN, vsi->back->state) || |
| 4926 | test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state)) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4927 | return; |
| 4928 | |
| 4929 | /* Make sure type is MAIN VSI */ |
| 4930 | if (vsi->type != I40E_VSI_MAIN) |
| 4931 | return; |
| 4932 | |
| 4933 | netdev = vsi->netdev; |
| 4934 | if (!netdev) |
| 4935 | return; |
| 4936 | |
| 4937 | /* Bail out if netif_carrier is not OK */ |
| 4938 | if (!netif_carrier_ok(netdev)) |
| 4939 | return; |
| 4940 | |
| 4941 | /* Go thru' TX queues for netdev */ |
| 4942 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4943 | struct netdev_queue *q; |
| 4944 | |
| 4945 | q = netdev_get_tx_queue(netdev, i); |
| 4946 | if (q) |
| 4947 | i40e_detect_recover_hung_queue(i, vsi); |
| 4948 | } |
| 4949 | } |
| 4950 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4951 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4952 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4953 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4954 | * |
| 4955 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4956 | * and LAN TC. |
| 4957 | **/ |
| 4958 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4959 | { |
| 4960 | struct i40e_dcb_app_priority_table app; |
| 4961 | struct i40e_hw *hw = &pf->hw; |
| 4962 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4963 | u8 tc, i; |
| 4964 | /* Get the iSCSI APP TLV */ |
| 4965 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4966 | |
| 4967 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4968 | app = dcbcfg->app[i]; |
| 4969 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4970 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4971 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4972 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4973 | break; |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | return enabled_tc; |
| 4978 | } |
| 4979 | |
| 4980 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4981 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4982 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4983 | * |
| 4984 | * Return the number of TCs from given DCBx configuration |
| 4985 | **/ |
| 4986 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4987 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4988 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4989 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4990 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4991 | |
| 4992 | /* Scan the ETS Config Priority Table to find |
| 4993 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4994 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4995 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4996 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4997 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4998 | |
| 4999 | /* Now scan the bitmask to check for |
| 5000 | * contiguous TCs starting with TC0 |
| 5001 | */ |
| 5002 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5003 | if (num_tc & BIT(i)) { |
| 5004 | if (!tc_unused) { |
| 5005 | ret++; |
| 5006 | } else { |
| 5007 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 5008 | return 1; |
| 5009 | } |
| 5010 | } else { |
| 5011 | tc_unused = 1; |
| 5012 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5013 | } |
| 5014 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 5015 | /* There is always at least TC0 */ |
| 5016 | if (!ret) |
| 5017 | ret = 1; |
| 5018 | |
| 5019 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | /** |
| 5023 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 5024 | * @dcbcfg: the corresponding DCBx configuration structure |
| 5025 | * |
| 5026 | * Query the current DCB configuration and return the number of |
| 5027 | * traffic classes enabled from the given DCBX config |
| 5028 | **/ |
| 5029 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 5030 | { |
| 5031 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 5032 | u8 enabled_tc = 1; |
| 5033 | u8 i; |
| 5034 | |
| 5035 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5036 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5037 | |
| 5038 | return enabled_tc; |
| 5039 | } |
| 5040 | |
| 5041 | /** |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5042 | * i40e_mqprio_get_enabled_tc - Get enabled traffic classes |
| 5043 | * @pf: PF being queried |
| 5044 | * |
| 5045 | * Query the current MQPRIO configuration and return the number of |
| 5046 | * traffic classes enabled. |
| 5047 | **/ |
| 5048 | static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf) |
| 5049 | { |
| 5050 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 5051 | u8 num_tc = vsi->mqprio_qopt.qopt.num_tc; |
| 5052 | u8 enabled_tc = 1, i; |
| 5053 | |
| 5054 | for (i = 1; i < num_tc; i++) |
| 5055 | enabled_tc |= BIT(i); |
| 5056 | return enabled_tc; |
| 5057 | } |
| 5058 | |
| 5059 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5060 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 5061 | * @pf: PF being queried |
| 5062 | * |
| 5063 | * Return number of traffic classes enabled for the given PF |
| 5064 | **/ |
| 5065 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 5066 | { |
| 5067 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 5068 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5069 | u8 num_tc = 0; |
| 5070 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 5071 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5072 | if (pf->flags & I40E_FLAG_TC_MQPRIO) |
| 5073 | return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc; |
| 5074 | |
| 5075 | /* If neither MQPRIO nor DCB is enabled, then always use single TC */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5076 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 5077 | return 1; |
| 5078 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5079 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5080 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 5081 | return i40e_dcb_get_num_tc(dcbcfg); |
| 5082 | |
| 5083 | /* MFP mode return count of enabled TCs for this PF */ |
| 5084 | if (pf->hw.func_caps.iscsi) |
| 5085 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 5086 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 5087 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5088 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5089 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5090 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5091 | num_tc++; |
| 5092 | } |
| 5093 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5097 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 5098 | * @pf: PF being queried |
| 5099 | * |
| 5100 | * Return a bitmap for enabled traffic classes for this PF. |
| 5101 | **/ |
| 5102 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 5103 | { |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5104 | if (pf->flags & I40E_FLAG_TC_MQPRIO) |
| 5105 | return i40e_mqprio_get_enabled_tc(pf); |
| 5106 | |
| 5107 | /* If neither MQPRIO nor DCB is enabled for this PF then just return |
| 5108 | * default TC |
| 5109 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5110 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5111 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5112 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5113 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5114 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 5115 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 5116 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 5117 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 5118 | if (pf->hw.func_caps.iscsi) |
| 5119 | return i40e_get_iscsi_tc_map(pf); |
| 5120 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5121 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | /** |
| 5125 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 5126 | * @vsi: the VSI being queried |
| 5127 | * |
| 5128 | * Returns 0 on success, negative value on failure |
| 5129 | **/ |
| 5130 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 5131 | { |
| 5132 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 5133 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 5134 | struct i40e_pf *pf = vsi->back; |
| 5135 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5136 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5137 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5138 | int i; |
| 5139 | |
| 5140 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5141 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 5142 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5143 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5144 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 5145 | i40e_stat_str(&pf->hw, ret), |
| 5146 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5147 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5151 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 5152 | NULL); |
| 5153 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5154 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5155 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 5156 | i40e_stat_str(&pf->hw, ret), |
| 5157 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5158 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 5162 | dev_info(&pf->pdev->dev, |
| 5163 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 5164 | bw_config.tc_valid_bits, |
| 5165 | bw_ets_config.tc_valid_bits); |
| 5166 | /* Still continuing */ |
| 5167 | } |
| 5168 | |
| 5169 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 5170 | vsi->bw_max_quanta = bw_config.max_bw; |
| 5171 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 5172 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 5173 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5174 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 5175 | vsi->bw_ets_limit_credits[i] = |
| 5176 | le16_to_cpu(bw_ets_config.credits[i]); |
| 5177 | /* 3 bits out of 4 for each TC */ |
| 5178 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 5179 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 5180 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5181 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 5186 | * @vsi: the VSI being configured |
| 5187 | * @enabled_tc: TC bitmap |
| 5188 | * @bw_credits: BW shared credits per TC |
| 5189 | * |
| 5190 | * Returns 0 on success, negative value on failure |
| 5191 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5192 | 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] | 5193 | u8 *bw_share) |
| 5194 | { |
| 5195 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5196 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5197 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5198 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 5199 | if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5200 | return 0; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 5201 | if (!vsi->mqprio_qopt.qopt.hw) { |
| 5202 | ret = i40e_set_bw_limit(vsi, vsi->seid, 0); |
| 5203 | if (ret) |
| 5204 | dev_info(&vsi->back->pdev->dev, |
| 5205 | "Failed to reset tx rate for vsi->seid %u\n", |
| 5206 | vsi->seid); |
| 5207 | return ret; |
| 5208 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5209 | bw_data.tc_valid_bits = enabled_tc; |
| 5210 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 5211 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 5212 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5213 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 5214 | NULL); |
| 5215 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5216 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5217 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 5218 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5219 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 5223 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 5224 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5225 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | /** |
| 5229 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 5230 | * @vsi: the VSI being configured |
| 5231 | * @enabled_tc: TC map to be enabled |
| 5232 | * |
| 5233 | **/ |
| 5234 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5235 | { |
| 5236 | struct net_device *netdev = vsi->netdev; |
| 5237 | struct i40e_pf *pf = vsi->back; |
| 5238 | struct i40e_hw *hw = &pf->hw; |
| 5239 | u8 netdev_tc = 0; |
| 5240 | int i; |
| 5241 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 5242 | |
| 5243 | if (!netdev) |
| 5244 | return; |
| 5245 | |
| 5246 | if (!enabled_tc) { |
| 5247 | netdev_reset_tc(netdev); |
| 5248 | return; |
| 5249 | } |
| 5250 | |
| 5251 | /* Set up actual enabled TCs on the VSI */ |
| 5252 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 5253 | return; |
| 5254 | |
| 5255 | /* set per TC queues for the VSI */ |
| 5256 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5257 | /* Only set TC queues for enabled tcs |
| 5258 | * |
| 5259 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 5260 | * enabled_tc bitmap would be 0x00001001; the driver |
| 5261 | * will set the numtc for netdev as 2 that will be |
| 5262 | * referenced by the netdev layer as TC 0 and 1. |
| 5263 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5264 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5265 | netdev_set_tc_queue(netdev, |
| 5266 | vsi->tc_config.tc_info[i].netdev_tc, |
| 5267 | vsi->tc_config.tc_info[i].qcount, |
| 5268 | vsi->tc_config.tc_info[i].qoffset); |
| 5269 | } |
| 5270 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5271 | if (pf->flags & I40E_FLAG_TC_MQPRIO) |
| 5272 | return; |
| 5273 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5274 | /* Assign UP2TC map for the VSI */ |
| 5275 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 5276 | /* Get the actual TC# for the UP */ |
| 5277 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 5278 | /* Get the mapped netdev TC# for the UP */ |
| 5279 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 5280 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 5281 | } |
| 5282 | } |
| 5283 | |
| 5284 | /** |
| 5285 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 5286 | * @vsi: the VSI being configured |
| 5287 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 5288 | **/ |
| 5289 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 5290 | struct i40e_vsi_context *ctxt) |
| 5291 | { |
| 5292 | /* copy just the sections touched not the entire info |
| 5293 | * since not all sections are valid as returned by |
| 5294 | * update vsi params |
| 5295 | */ |
| 5296 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 5297 | memcpy(&vsi->info.queue_mapping, |
| 5298 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 5299 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 5300 | sizeof(vsi->info.tc_mapping)); |
| 5301 | } |
| 5302 | |
| 5303 | /** |
| 5304 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 5305 | * @vsi: VSI to be configured |
| 5306 | * @enabled_tc: TC bitmap |
| 5307 | * |
| 5308 | * This configures a particular VSI for TCs that are mapped to the |
| 5309 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 5310 | * VSIs to configure TC for a particular VSI. |
| 5311 | * |
| 5312 | * NOTE: |
| 5313 | * It is expected that the VSI queues have been quisced before calling |
| 5314 | * this function. |
| 5315 | **/ |
| 5316 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5317 | { |
| 5318 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 5319 | struct i40e_vsi_context ctxt; |
| 5320 | int ret = 0; |
| 5321 | int i; |
| 5322 | |
| 5323 | /* Check if enabled_tc is same as existing or new TCs */ |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5324 | if (vsi->tc_config.enabled_tc == enabled_tc && |
| 5325 | vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5326 | return ret; |
| 5327 | |
| 5328 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 5329 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5330 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5331 | bw_share[i] = 1; |
| 5332 | } |
| 5333 | |
| 5334 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 5335 | if (ret) { |
| 5336 | dev_info(&vsi->back->pdev->dev, |
| 5337 | "Failed configuring TC map %d for VSI %d\n", |
| 5338 | enabled_tc, vsi->seid); |
| 5339 | goto out; |
| 5340 | } |
| 5341 | |
| 5342 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 5343 | ctxt.seid = vsi->seid; |
| 5344 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 5345 | ctxt.vf_num = 0; |
| 5346 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5347 | ctxt.info = vsi->info; |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5348 | if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) { |
| 5349 | ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc); |
| 5350 | if (ret) |
| 5351 | goto out; |
| 5352 | } else { |
| 5353 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 5354 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5355 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5356 | /* On destroying the qdisc, reset vsi->rss_size, as number of enabled |
| 5357 | * queues changed. |
| 5358 | */ |
| 5359 | if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) { |
| 5360 | vsi->rss_size = min_t(int, vsi->back->alloc_rss_size, |
| 5361 | vsi->num_queue_pairs); |
| 5362 | ret = i40e_vsi_config_rss(vsi); |
| 5363 | if (ret) { |
| 5364 | dev_info(&vsi->back->pdev->dev, |
| 5365 | "Failed to reconfig rss for num_queues\n"); |
| 5366 | return ret; |
| 5367 | } |
| 5368 | vsi->reconfig_rss = false; |
| 5369 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5370 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 5371 | ctxt.info.valid_sections |= |
| 5372 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 5373 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 5374 | } |
| 5375 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 5376 | /* Update the VSI after updating the VSI queue-mapping |
| 5377 | * information |
| 5378 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5379 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 5380 | if (ret) { |
| 5381 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5382 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 5383 | i40e_stat_str(&vsi->back->hw, ret), |
| 5384 | i40e_aq_str(&vsi->back->hw, |
| 5385 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5386 | goto out; |
| 5387 | } |
| 5388 | /* update the local VSI info with updated queue map */ |
| 5389 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 5390 | vsi->info.valid_sections = 0; |
| 5391 | |
| 5392 | /* Update current VSI BW information */ |
| 5393 | ret = i40e_vsi_get_bw_info(vsi); |
| 5394 | if (ret) { |
| 5395 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5396 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5397 | i40e_stat_str(&vsi->back->hw, ret), |
| 5398 | i40e_aq_str(&vsi->back->hw, |
| 5399 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5400 | goto out; |
| 5401 | } |
| 5402 | |
| 5403 | /* Update the netdev TC setup */ |
| 5404 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5405 | out: |
| 5406 | return ret; |
| 5407 | } |
| 5408 | |
| 5409 | /** |
Amritha Nambiar | 5ecae41 | 2017-09-07 04:00:27 -0700 | [diff] [blame] | 5410 | * i40e_get_link_speed - Returns link speed for the interface |
| 5411 | * @vsi: VSI to be configured |
| 5412 | * |
| 5413 | **/ |
| 5414 | int i40e_get_link_speed(struct i40e_vsi *vsi) |
| 5415 | { |
| 5416 | struct i40e_pf *pf = vsi->back; |
| 5417 | |
| 5418 | switch (pf->hw.phy.link_info.link_speed) { |
| 5419 | case I40E_LINK_SPEED_40GB: |
| 5420 | return 40000; |
| 5421 | case I40E_LINK_SPEED_25GB: |
| 5422 | return 25000; |
| 5423 | case I40E_LINK_SPEED_20GB: |
| 5424 | return 20000; |
| 5425 | case I40E_LINK_SPEED_10GB: |
| 5426 | return 10000; |
| 5427 | case I40E_LINK_SPEED_1GB: |
| 5428 | return 1000; |
| 5429 | default: |
| 5430 | return -EINVAL; |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | /** |
| 5435 | * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate |
| 5436 | * @vsi: VSI to be configured |
| 5437 | * @seid: seid of the channel/VSI |
| 5438 | * @max_tx_rate: max TX rate to be configured as BW limit |
| 5439 | * |
| 5440 | * Helper function to set BW limit for a given VSI |
| 5441 | **/ |
| 5442 | int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate) |
| 5443 | { |
| 5444 | struct i40e_pf *pf = vsi->back; |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 5445 | u64 credits = 0; |
Amritha Nambiar | 5ecae41 | 2017-09-07 04:00:27 -0700 | [diff] [blame] | 5446 | int speed = 0; |
| 5447 | int ret = 0; |
| 5448 | |
| 5449 | speed = i40e_get_link_speed(vsi); |
| 5450 | if (max_tx_rate > speed) { |
| 5451 | dev_err(&pf->pdev->dev, |
| 5452 | "Invalid max tx rate %llu specified for VSI seid %d.", |
| 5453 | max_tx_rate, seid); |
| 5454 | return -EINVAL; |
| 5455 | } |
| 5456 | if (max_tx_rate && max_tx_rate < 50) { |
| 5457 | dev_warn(&pf->pdev->dev, |
| 5458 | "Setting max tx rate to minimum usable value of 50Mbps.\n"); |
| 5459 | max_tx_rate = 50; |
| 5460 | } |
| 5461 | |
| 5462 | /* Tx rate credits are in values of 50Mbps, 0 is disabled */ |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 5463 | credits = max_tx_rate; |
| 5464 | do_div(credits, I40E_BW_CREDIT_DIVISOR); |
| 5465 | ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits, |
Amritha Nambiar | 5ecae41 | 2017-09-07 04:00:27 -0700 | [diff] [blame] | 5466 | I40E_MAX_BW_INACTIVE_ACCUM, NULL); |
| 5467 | if (ret) |
| 5468 | dev_err(&pf->pdev->dev, |
| 5469 | "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n", |
| 5470 | max_tx_rate, seid, i40e_stat_str(&pf->hw, ret), |
| 5471 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 5472 | return ret; |
| 5473 | } |
| 5474 | |
| 5475 | /** |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 5476 | * i40e_remove_queue_channels - Remove queue channels for the TCs |
| 5477 | * @vsi: VSI to be configured |
| 5478 | * |
| 5479 | * Remove queue channels for the TCs |
| 5480 | **/ |
| 5481 | static void i40e_remove_queue_channels(struct i40e_vsi *vsi) |
| 5482 | { |
| 5483 | struct i40e_channel *ch, *ch_tmp; |
| 5484 | int ret, i; |
| 5485 | |
| 5486 | /* Reset rss size that was stored when reconfiguring rss for |
| 5487 | * channel VSIs with non-power-of-2 queue count. |
| 5488 | */ |
| 5489 | vsi->current_rss_size = 0; |
| 5490 | |
| 5491 | /* perform cleanup for channels if they exist */ |
| 5492 | if (list_empty(&vsi->ch_list)) |
| 5493 | return; |
| 5494 | |
| 5495 | list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) { |
| 5496 | struct i40e_vsi *p_vsi; |
| 5497 | |
| 5498 | list_del(&ch->list); |
| 5499 | p_vsi = ch->parent_vsi; |
| 5500 | if (!p_vsi || !ch->initialized) { |
| 5501 | kfree(ch); |
| 5502 | continue; |
| 5503 | } |
| 5504 | /* Reset queue contexts */ |
| 5505 | for (i = 0; i < ch->num_queue_pairs; i++) { |
| 5506 | struct i40e_ring *tx_ring, *rx_ring; |
| 5507 | u16 pf_q; |
| 5508 | |
| 5509 | pf_q = ch->base_queue + i; |
| 5510 | tx_ring = vsi->tx_rings[pf_q]; |
| 5511 | tx_ring->ch = NULL; |
| 5512 | |
| 5513 | rx_ring = vsi->rx_rings[pf_q]; |
| 5514 | rx_ring->ch = NULL; |
| 5515 | } |
| 5516 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 5517 | /* Reset BW configured for this VSI via mqprio */ |
| 5518 | ret = i40e_set_bw_limit(vsi, ch->seid, 0); |
| 5519 | if (ret) |
| 5520 | dev_info(&vsi->back->pdev->dev, |
| 5521 | "Failed to reset tx rate for ch->seid %u\n", |
| 5522 | ch->seid); |
| 5523 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 5524 | /* delete VSI from FW */ |
| 5525 | ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid, |
| 5526 | NULL); |
| 5527 | if (ret) |
| 5528 | dev_err(&vsi->back->pdev->dev, |
| 5529 | "unable to remove channel (%d) for parent VSI(%d)\n", |
| 5530 | ch->seid, p_vsi->seid); |
| 5531 | kfree(ch); |
| 5532 | } |
| 5533 | INIT_LIST_HEAD(&vsi->ch_list); |
| 5534 | } |
| 5535 | |
| 5536 | /** |
| 5537 | * i40e_is_any_channel - channel exist or not |
| 5538 | * @vsi: ptr to VSI to which channels are associated with |
| 5539 | * |
| 5540 | * Returns true or false if channel(s) exist for associated VSI or not |
| 5541 | **/ |
| 5542 | static bool i40e_is_any_channel(struct i40e_vsi *vsi) |
| 5543 | { |
| 5544 | struct i40e_channel *ch, *ch_tmp; |
| 5545 | |
| 5546 | list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) { |
| 5547 | if (ch->initialized) |
| 5548 | return true; |
| 5549 | } |
| 5550 | |
| 5551 | return false; |
| 5552 | } |
| 5553 | |
| 5554 | /** |
| 5555 | * i40e_get_max_queues_for_channel |
| 5556 | * @vsi: ptr to VSI to which channels are associated with |
| 5557 | * |
| 5558 | * Helper function which returns max value among the queue counts set on the |
| 5559 | * channels/TCs created. |
| 5560 | **/ |
| 5561 | static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi) |
| 5562 | { |
| 5563 | struct i40e_channel *ch, *ch_tmp; |
| 5564 | int max = 0; |
| 5565 | |
| 5566 | list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) { |
| 5567 | if (!ch->initialized) |
| 5568 | continue; |
| 5569 | if (ch->num_queue_pairs > max) |
| 5570 | max = ch->num_queue_pairs; |
| 5571 | } |
| 5572 | |
| 5573 | return max; |
| 5574 | } |
| 5575 | |
| 5576 | /** |
| 5577 | * i40e_validate_num_queues - validate num_queues w.r.t channel |
| 5578 | * @pf: ptr to PF device |
| 5579 | * @num_queues: number of queues |
| 5580 | * @vsi: the parent VSI |
| 5581 | * @reconfig_rss: indicates should the RSS be reconfigured or not |
| 5582 | * |
| 5583 | * This function validates number of queues in the context of new channel |
| 5584 | * which is being established and determines if RSS should be reconfigured |
| 5585 | * or not for parent VSI. |
| 5586 | **/ |
| 5587 | static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues, |
| 5588 | struct i40e_vsi *vsi, bool *reconfig_rss) |
| 5589 | { |
| 5590 | int max_ch_queues; |
| 5591 | |
| 5592 | if (!reconfig_rss) |
| 5593 | return -EINVAL; |
| 5594 | |
| 5595 | *reconfig_rss = false; |
| 5596 | |
| 5597 | if (num_queues > I40E_MAX_QUEUES_PER_CH) { |
| 5598 | dev_err(&pf->pdev->dev, |
| 5599 | "Failed to create VMDq VSI. User requested num_queues (%d) > I40E_MAX_QUEUES_PER_VSI (%u)\n", |
| 5600 | num_queues, I40E_MAX_QUEUES_PER_CH); |
| 5601 | return -EINVAL; |
| 5602 | } |
| 5603 | |
| 5604 | if (vsi->current_rss_size) { |
| 5605 | if (num_queues > vsi->current_rss_size) { |
| 5606 | dev_dbg(&pf->pdev->dev, |
| 5607 | "Error: num_queues (%d) > vsi's current_size(%d)\n", |
| 5608 | num_queues, vsi->current_rss_size); |
| 5609 | return -EINVAL; |
| 5610 | } else if ((num_queues < vsi->current_rss_size) && |
| 5611 | (!is_power_of_2(num_queues))) { |
| 5612 | dev_dbg(&pf->pdev->dev, |
| 5613 | "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n", |
| 5614 | num_queues, vsi->current_rss_size); |
| 5615 | return -EINVAL; |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | if (!is_power_of_2(num_queues)) { |
| 5620 | /* Find the max num_queues configured for channel if channel |
| 5621 | * exist. |
| 5622 | * if channel exist, then enforce 'num_queues' to be more than |
| 5623 | * max ever queues configured for channel. |
| 5624 | */ |
| 5625 | max_ch_queues = i40e_get_max_queues_for_channel(vsi); |
| 5626 | if (num_queues < max_ch_queues) { |
| 5627 | dev_dbg(&pf->pdev->dev, |
| 5628 | "Error: num_queues (%d) < max queues configured for channel(%d)\n", |
| 5629 | num_queues, max_ch_queues); |
| 5630 | return -EINVAL; |
| 5631 | } |
| 5632 | *reconfig_rss = true; |
| 5633 | } |
| 5634 | |
| 5635 | return 0; |
| 5636 | } |
| 5637 | |
| 5638 | /** |
| 5639 | * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size |
| 5640 | * @vsi: the VSI being setup |
| 5641 | * @rss_size: size of RSS, accordingly LUT gets reprogrammed |
| 5642 | * |
| 5643 | * This function reconfigures RSS by reprogramming LUTs using 'rss_size' |
| 5644 | **/ |
| 5645 | static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size) |
| 5646 | { |
| 5647 | struct i40e_pf *pf = vsi->back; |
| 5648 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 5649 | struct i40e_hw *hw = &pf->hw; |
| 5650 | int local_rss_size; |
| 5651 | u8 *lut; |
| 5652 | int ret; |
| 5653 | |
| 5654 | if (!vsi->rss_size) |
| 5655 | return -EINVAL; |
| 5656 | |
| 5657 | if (rss_size > vsi->rss_size) |
| 5658 | return -EINVAL; |
| 5659 | |
| 5660 | local_rss_size = min_t(int, vsi->rss_size, rss_size); |
| 5661 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 5662 | if (!lut) |
| 5663 | return -ENOMEM; |
| 5664 | |
| 5665 | /* Ignoring user configured lut if there is one */ |
| 5666 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size); |
| 5667 | |
| 5668 | /* Use user configured hash key if there is one, otherwise |
| 5669 | * use default. |
| 5670 | */ |
| 5671 | if (vsi->rss_hkey_user) |
| 5672 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 5673 | else |
| 5674 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
| 5675 | |
| 5676 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
| 5677 | if (ret) { |
| 5678 | dev_info(&pf->pdev->dev, |
| 5679 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 5680 | i40e_stat_str(hw, ret), |
| 5681 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 5682 | kfree(lut); |
| 5683 | return ret; |
| 5684 | } |
| 5685 | kfree(lut); |
| 5686 | |
| 5687 | /* Do the update w.r.t. storing rss_size */ |
| 5688 | if (!vsi->orig_rss_size) |
| 5689 | vsi->orig_rss_size = vsi->rss_size; |
| 5690 | vsi->current_rss_size = local_rss_size; |
| 5691 | |
| 5692 | return ret; |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * i40e_channel_setup_queue_map - Setup a channel queue map |
| 5697 | * @pf: ptr to PF device |
| 5698 | * @vsi: the VSI being setup |
| 5699 | * @ctxt: VSI context structure |
| 5700 | * @ch: ptr to channel structure |
| 5701 | * |
| 5702 | * Setup queue map for a specific channel |
| 5703 | **/ |
| 5704 | static void i40e_channel_setup_queue_map(struct i40e_pf *pf, |
| 5705 | struct i40e_vsi_context *ctxt, |
| 5706 | struct i40e_channel *ch) |
| 5707 | { |
| 5708 | u16 qcount, qmap, sections = 0; |
| 5709 | u8 offset = 0; |
| 5710 | int pow; |
| 5711 | |
| 5712 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 5713 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 5714 | |
| 5715 | qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix); |
| 5716 | ch->num_queue_pairs = qcount; |
| 5717 | |
| 5718 | /* find the next higher power-of-2 of num queue pairs */ |
| 5719 | pow = ilog2(qcount); |
| 5720 | if (!is_power_of_2(qcount)) |
| 5721 | pow++; |
| 5722 | |
| 5723 | qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 5724 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 5725 | |
| 5726 | /* Setup queue TC[0].qmap for given VSI context */ |
| 5727 | ctxt->info.tc_mapping[0] = cpu_to_le16(qmap); |
| 5728 | |
| 5729 | ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */ |
| 5730 | ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 5731 | ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue); |
| 5732 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 5733 | } |
| 5734 | |
| 5735 | /** |
| 5736 | * i40e_add_channel - add a channel by adding VSI |
| 5737 | * @pf: ptr to PF device |
| 5738 | * @uplink_seid: underlying HW switching element (VEB) ID |
| 5739 | * @ch: ptr to channel structure |
| 5740 | * |
| 5741 | * Add a channel (VSI) using add_vsi and queue_map |
| 5742 | **/ |
| 5743 | static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid, |
| 5744 | struct i40e_channel *ch) |
| 5745 | { |
| 5746 | struct i40e_hw *hw = &pf->hw; |
| 5747 | struct i40e_vsi_context ctxt; |
| 5748 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 5749 | int ret; |
| 5750 | |
| 5751 | if (ch->type != I40E_VSI_VMDQ2) { |
| 5752 | dev_info(&pf->pdev->dev, |
| 5753 | "add new vsi failed, ch->type %d\n", ch->type); |
| 5754 | return -EINVAL; |
| 5755 | } |
| 5756 | |
| 5757 | memset(&ctxt, 0, sizeof(ctxt)); |
| 5758 | ctxt.pf_num = hw->pf_id; |
| 5759 | ctxt.vf_num = 0; |
| 5760 | ctxt.uplink_seid = uplink_seid; |
| 5761 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
| 5762 | if (ch->type == I40E_VSI_VMDQ2) |
| 5763 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 5764 | |
| 5765 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) { |
| 5766 | ctxt.info.valid_sections |= |
| 5767 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 5768 | ctxt.info.switch_id = |
| 5769 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 5770 | } |
| 5771 | |
| 5772 | /* Set queue map for a given VSI context */ |
| 5773 | i40e_channel_setup_queue_map(pf, &ctxt, ch); |
| 5774 | |
| 5775 | /* Now time to create VSI */ |
| 5776 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 5777 | if (ret) { |
| 5778 | dev_info(&pf->pdev->dev, |
| 5779 | "add new vsi failed, err %s aq_err %s\n", |
| 5780 | i40e_stat_str(&pf->hw, ret), |
| 5781 | i40e_aq_str(&pf->hw, |
| 5782 | pf->hw.aq.asq_last_status)); |
| 5783 | return -ENOENT; |
| 5784 | } |
| 5785 | |
| 5786 | /* Success, update channel */ |
| 5787 | ch->enabled_tc = enabled_tc; |
| 5788 | ch->seid = ctxt.seid; |
| 5789 | ch->vsi_number = ctxt.vsi_number; |
| 5790 | ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx); |
| 5791 | |
| 5792 | /* copy just the sections touched not the entire info |
| 5793 | * since not all sections are valid as returned by |
| 5794 | * update vsi params |
| 5795 | */ |
| 5796 | ch->info.mapping_flags = ctxt.info.mapping_flags; |
| 5797 | memcpy(&ch->info.queue_mapping, |
| 5798 | &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping)); |
| 5799 | memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping, |
| 5800 | sizeof(ctxt.info.tc_mapping)); |
| 5801 | |
| 5802 | return 0; |
| 5803 | } |
| 5804 | |
| 5805 | static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch, |
| 5806 | u8 *bw_share) |
| 5807 | { |
| 5808 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
| 5809 | i40e_status ret; |
| 5810 | int i; |
| 5811 | |
| 5812 | bw_data.tc_valid_bits = ch->enabled_tc; |
| 5813 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 5814 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 5815 | |
| 5816 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid, |
| 5817 | &bw_data, NULL); |
| 5818 | if (ret) { |
| 5819 | dev_info(&vsi->back->pdev->dev, |
| 5820 | "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n", |
| 5821 | vsi->back->hw.aq.asq_last_status, ch->seid); |
| 5822 | return -EINVAL; |
| 5823 | } |
| 5824 | |
| 5825 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 5826 | ch->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 5827 | |
| 5828 | return 0; |
| 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * i40e_channel_config_tx_ring - config TX ring associated with new channel |
| 5833 | * @pf: ptr to PF device |
| 5834 | * @vsi: the VSI being setup |
| 5835 | * @ch: ptr to channel structure |
| 5836 | * |
| 5837 | * Configure TX rings associated with channel (VSI) since queues are being |
| 5838 | * from parent VSI. |
| 5839 | **/ |
| 5840 | static int i40e_channel_config_tx_ring(struct i40e_pf *pf, |
| 5841 | struct i40e_vsi *vsi, |
| 5842 | struct i40e_channel *ch) |
| 5843 | { |
| 5844 | i40e_status ret; |
| 5845 | int i; |
| 5846 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 5847 | |
| 5848 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 5849 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5850 | if (ch->enabled_tc & BIT(i)) |
| 5851 | bw_share[i] = 1; |
| 5852 | } |
| 5853 | |
| 5854 | /* configure BW for new VSI */ |
| 5855 | ret = i40e_channel_config_bw(vsi, ch, bw_share); |
| 5856 | if (ret) { |
| 5857 | dev_info(&vsi->back->pdev->dev, |
| 5858 | "Failed configuring TC map %d for channel (seid %u)\n", |
| 5859 | ch->enabled_tc, ch->seid); |
| 5860 | return ret; |
| 5861 | } |
| 5862 | |
| 5863 | for (i = 0; i < ch->num_queue_pairs; i++) { |
| 5864 | struct i40e_ring *tx_ring, *rx_ring; |
| 5865 | u16 pf_q; |
| 5866 | |
| 5867 | pf_q = ch->base_queue + i; |
| 5868 | |
| 5869 | /* Get to TX ring ptr of main VSI, for re-setup TX queue |
| 5870 | * context |
| 5871 | */ |
| 5872 | tx_ring = vsi->tx_rings[pf_q]; |
| 5873 | tx_ring->ch = ch; |
| 5874 | |
| 5875 | /* Get the RX ring ptr */ |
| 5876 | rx_ring = vsi->rx_rings[pf_q]; |
| 5877 | rx_ring->ch = ch; |
| 5878 | } |
| 5879 | |
| 5880 | return 0; |
| 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * i40e_setup_hw_channel - setup new channel |
| 5885 | * @pf: ptr to PF device |
| 5886 | * @vsi: the VSI being setup |
| 5887 | * @ch: ptr to channel structure |
| 5888 | * @uplink_seid: underlying HW switching element (VEB) ID |
| 5889 | * @type: type of channel to be created (VMDq2/VF) |
| 5890 | * |
| 5891 | * Setup new channel (VSI) based on specified type (VMDq2/VF) |
| 5892 | * and configures TX rings accordingly |
| 5893 | **/ |
| 5894 | static inline int i40e_setup_hw_channel(struct i40e_pf *pf, |
| 5895 | struct i40e_vsi *vsi, |
| 5896 | struct i40e_channel *ch, |
| 5897 | u16 uplink_seid, u8 type) |
| 5898 | { |
| 5899 | int ret; |
| 5900 | |
| 5901 | ch->initialized = false; |
| 5902 | ch->base_queue = vsi->next_base_queue; |
| 5903 | ch->type = type; |
| 5904 | |
| 5905 | /* Proceed with creation of channel (VMDq2) VSI */ |
| 5906 | ret = i40e_add_channel(pf, uplink_seid, ch); |
| 5907 | if (ret) { |
| 5908 | dev_info(&pf->pdev->dev, |
| 5909 | "failed to add_channel using uplink_seid %u\n", |
| 5910 | uplink_seid); |
| 5911 | return ret; |
| 5912 | } |
| 5913 | |
| 5914 | /* Mark the successful creation of channel */ |
| 5915 | ch->initialized = true; |
| 5916 | |
| 5917 | /* Reconfigure TX queues using QTX_CTL register */ |
| 5918 | ret = i40e_channel_config_tx_ring(pf, vsi, ch); |
| 5919 | if (ret) { |
| 5920 | dev_info(&pf->pdev->dev, |
| 5921 | "failed to configure TX rings for channel %u\n", |
| 5922 | ch->seid); |
| 5923 | return ret; |
| 5924 | } |
| 5925 | |
| 5926 | /* update 'next_base_queue' */ |
| 5927 | vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs; |
| 5928 | dev_dbg(&pf->pdev->dev, |
| 5929 | "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n", |
| 5930 | ch->seid, ch->vsi_number, ch->stat_counter_idx, |
| 5931 | ch->num_queue_pairs, |
| 5932 | vsi->next_base_queue); |
| 5933 | return ret; |
| 5934 | } |
| 5935 | |
| 5936 | /** |
| 5937 | * i40e_setup_channel - setup new channel using uplink element |
| 5938 | * @pf: ptr to PF device |
| 5939 | * @type: type of channel to be created (VMDq2/VF) |
| 5940 | * @uplink_seid: underlying HW switching element (VEB) ID |
| 5941 | * @ch: ptr to channel structure |
| 5942 | * |
| 5943 | * Setup new channel (VSI) based on specified type (VMDq2/VF) |
| 5944 | * and uplink switching element (uplink_seid) |
| 5945 | **/ |
| 5946 | static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi, |
| 5947 | struct i40e_channel *ch) |
| 5948 | { |
| 5949 | u8 vsi_type; |
| 5950 | u16 seid; |
| 5951 | int ret; |
| 5952 | |
| 5953 | if (vsi->type == I40E_VSI_MAIN) { |
| 5954 | vsi_type = I40E_VSI_VMDQ2; |
| 5955 | } else { |
| 5956 | dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n", |
| 5957 | vsi->type); |
| 5958 | return false; |
| 5959 | } |
| 5960 | |
| 5961 | /* underlying switching element */ |
| 5962 | seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 5963 | |
| 5964 | /* create channel (VSI), configure TX rings */ |
| 5965 | ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type); |
| 5966 | if (ret) { |
| 5967 | dev_err(&pf->pdev->dev, "failed to setup hw_channel\n"); |
| 5968 | return false; |
| 5969 | } |
| 5970 | |
| 5971 | return ch->initialized ? true : false; |
| 5972 | } |
| 5973 | |
| 5974 | /** |
| 5975 | * i40e_create_queue_channel - function to create channel |
| 5976 | * @vsi: VSI to be configured |
| 5977 | * @ch: ptr to channel (it contains channel specific params) |
| 5978 | * |
| 5979 | * This function creates channel (VSI) using num_queues specified by user, |
| 5980 | * reconfigs RSS if needed. |
| 5981 | **/ |
| 5982 | int i40e_create_queue_channel(struct i40e_vsi *vsi, |
| 5983 | struct i40e_channel *ch) |
| 5984 | { |
| 5985 | struct i40e_pf *pf = vsi->back; |
| 5986 | bool reconfig_rss; |
| 5987 | int err; |
| 5988 | |
| 5989 | if (!ch) |
| 5990 | return -EINVAL; |
| 5991 | |
| 5992 | if (!ch->num_queue_pairs) { |
| 5993 | dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n", |
| 5994 | ch->num_queue_pairs); |
| 5995 | return -EINVAL; |
| 5996 | } |
| 5997 | |
| 5998 | /* validate user requested num_queues for channel */ |
| 5999 | err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi, |
| 6000 | &reconfig_rss); |
| 6001 | if (err) { |
| 6002 | dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n", |
| 6003 | ch->num_queue_pairs); |
| 6004 | return -EINVAL; |
| 6005 | } |
| 6006 | |
| 6007 | /* By default we are in VEPA mode, if this is the first VF/VMDq |
| 6008 | * VSI to be added switch to VEB mode. |
| 6009 | */ |
| 6010 | if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) || |
| 6011 | (!i40e_is_any_channel(vsi))) { |
| 6012 | if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) { |
| 6013 | dev_dbg(&pf->pdev->dev, |
| 6014 | "Failed to create channel. Override queues (%u) not power of 2\n", |
| 6015 | vsi->tc_config.tc_info[0].qcount); |
| 6016 | return -EINVAL; |
| 6017 | } |
| 6018 | |
| 6019 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 6020 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 6021 | |
| 6022 | if (vsi->type == I40E_VSI_MAIN) { |
| 6023 | if (pf->flags & I40E_FLAG_TC_MQPRIO) |
| 6024 | i40e_do_reset(pf, I40E_PF_RESET_FLAG, |
| 6025 | true); |
| 6026 | else |
| 6027 | i40e_do_reset_safe(pf, |
| 6028 | I40E_PF_RESET_FLAG); |
| 6029 | } |
| 6030 | } |
| 6031 | /* now onwards for main VSI, number of queues will be value |
| 6032 | * of TC0's queue count |
| 6033 | */ |
| 6034 | } |
| 6035 | |
| 6036 | /* By this time, vsi->cnt_q_avail shall be set to non-zero and |
| 6037 | * it should be more than num_queues |
| 6038 | */ |
| 6039 | if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) { |
| 6040 | dev_dbg(&pf->pdev->dev, |
| 6041 | "Error: cnt_q_avail (%u) less than num_queues %d\n", |
| 6042 | vsi->cnt_q_avail, ch->num_queue_pairs); |
| 6043 | return -EINVAL; |
| 6044 | } |
| 6045 | |
| 6046 | /* reconfig_rss only if vsi type is MAIN_VSI */ |
| 6047 | if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) { |
| 6048 | err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs); |
| 6049 | if (err) { |
| 6050 | dev_info(&pf->pdev->dev, |
| 6051 | "Error: unable to reconfig rss for num_queues (%u)\n", |
| 6052 | ch->num_queue_pairs); |
| 6053 | return -EINVAL; |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | if (!i40e_setup_channel(pf, vsi, ch)) { |
| 6058 | dev_info(&pf->pdev->dev, "Failed to setup channel\n"); |
| 6059 | return -EINVAL; |
| 6060 | } |
| 6061 | |
| 6062 | dev_info(&pf->pdev->dev, |
| 6063 | "Setup channel (id:%u) utilizing num_queues %d\n", |
| 6064 | ch->seid, ch->num_queue_pairs); |
| 6065 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6066 | /* configure VSI for BW limit */ |
| 6067 | if (ch->max_tx_rate) { |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6068 | u64 credits = ch->max_tx_rate; |
| 6069 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6070 | if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate)) |
| 6071 | return -EINVAL; |
| 6072 | |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6073 | do_div(credits, I40E_BW_CREDIT_DIVISOR); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6074 | dev_dbg(&pf->pdev->dev, |
| 6075 | "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", |
| 6076 | ch->max_tx_rate, |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6077 | credits, |
| 6078 | ch->seid); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6079 | } |
| 6080 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6081 | /* in case of VF, this will be main SRIOV VSI */ |
| 6082 | ch->parent_vsi = vsi; |
| 6083 | |
| 6084 | /* and update main_vsi's count for queue_available to use */ |
| 6085 | vsi->cnt_q_avail -= ch->num_queue_pairs; |
| 6086 | |
| 6087 | return 0; |
| 6088 | } |
| 6089 | |
| 6090 | /** |
| 6091 | * i40e_configure_queue_channels - Add queue channel for the given TCs |
| 6092 | * @vsi: VSI to be configured |
| 6093 | * |
| 6094 | * Configures queue channel mapping to the given TCs |
| 6095 | **/ |
| 6096 | static int i40e_configure_queue_channels(struct i40e_vsi *vsi) |
| 6097 | { |
| 6098 | struct i40e_channel *ch; |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6099 | u64 max_rate = 0; |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6100 | int ret = 0, i; |
| 6101 | |
| 6102 | /* Create app vsi with the TCs. Main VSI with TC0 is already set up */ |
| 6103 | for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 6104 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
| 6105 | ch = kzalloc(sizeof(*ch), GFP_KERNEL); |
| 6106 | if (!ch) { |
| 6107 | ret = -ENOMEM; |
| 6108 | goto err_free; |
| 6109 | } |
| 6110 | |
| 6111 | INIT_LIST_HEAD(&ch->list); |
| 6112 | ch->num_queue_pairs = |
| 6113 | vsi->tc_config.tc_info[i].qcount; |
| 6114 | ch->base_queue = |
| 6115 | vsi->tc_config.tc_info[i].qoffset; |
| 6116 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6117 | /* Bandwidth limit through tc interface is in bytes/s, |
| 6118 | * change to Mbit/s |
| 6119 | */ |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6120 | max_rate = vsi->mqprio_qopt.max_rate[i]; |
| 6121 | do_div(max_rate, I40E_BW_MBPS_DIVISOR); |
| 6122 | ch->max_tx_rate = max_rate; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6123 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6124 | list_add_tail(&ch->list, &vsi->ch_list); |
| 6125 | |
| 6126 | ret = i40e_create_queue_channel(vsi, ch); |
| 6127 | if (ret) { |
| 6128 | dev_err(&vsi->back->pdev->dev, |
| 6129 | "Failed creating queue channel with TC%d: queues %d\n", |
| 6130 | i, ch->num_queue_pairs); |
| 6131 | goto err_free; |
| 6132 | } |
| 6133 | } |
| 6134 | } |
| 6135 | return ret; |
| 6136 | |
| 6137 | err_free: |
| 6138 | i40e_remove_queue_channels(vsi); |
| 6139 | return ret; |
| 6140 | } |
| 6141 | |
| 6142 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6143 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 6144 | * @veb: given VEB |
| 6145 | * @enabled_tc: TC bitmap |
| 6146 | * |
| 6147 | * Configures given TC bitmap for VEB (switching) element |
| 6148 | **/ |
| 6149 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 6150 | { |
| 6151 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 6152 | struct i40e_pf *pf = veb->pf; |
| 6153 | int ret = 0; |
| 6154 | int i; |
| 6155 | |
| 6156 | /* No TCs or already enabled TCs just return */ |
| 6157 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 6158 | return ret; |
| 6159 | |
| 6160 | bw_data.tc_valid_bits = enabled_tc; |
| 6161 | /* bw_data.absolute_credits is not set (relative) */ |
| 6162 | |
| 6163 | /* Enable ETS TCs with equal BW Share for now */ |
| 6164 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6165 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6166 | bw_data.tc_bw_share_credits[i] = 1; |
| 6167 | } |
| 6168 | |
| 6169 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 6170 | &bw_data, NULL); |
| 6171 | if (ret) { |
| 6172 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6173 | "VEB bw config failed, err %s aq_err %s\n", |
| 6174 | i40e_stat_str(&pf->hw, ret), |
| 6175 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6176 | goto out; |
| 6177 | } |
| 6178 | |
| 6179 | /* Update the BW information */ |
| 6180 | ret = i40e_veb_get_bw_info(veb); |
| 6181 | if (ret) { |
| 6182 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6183 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 6184 | i40e_stat_str(&pf->hw, ret), |
| 6185 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | out: |
| 6189 | return ret; |
| 6190 | } |
| 6191 | |
| 6192 | #ifdef CONFIG_I40E_DCB |
| 6193 | /** |
| 6194 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 6195 | * @pf: PF struct |
| 6196 | * |
| 6197 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 6198 | * the caller would've quiesce all the VSIs before calling |
| 6199 | * this function |
| 6200 | **/ |
| 6201 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 6202 | { |
| 6203 | u8 tc_map = 0; |
| 6204 | int ret; |
| 6205 | u8 v; |
| 6206 | |
| 6207 | /* Enable the TCs available on PF to all VEBs */ |
| 6208 | tc_map = i40e_pf_get_tc_map(pf); |
| 6209 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6210 | if (!pf->veb[v]) |
| 6211 | continue; |
| 6212 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 6213 | if (ret) { |
| 6214 | dev_info(&pf->pdev->dev, |
| 6215 | "Failed configuring TC for VEB seid=%d\n", |
| 6216 | pf->veb[v]->seid); |
| 6217 | /* Will try to configure as many components */ |
| 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6222 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6223 | if (!pf->vsi[v]) |
| 6224 | continue; |
| 6225 | |
| 6226 | /* - Enable all TCs for the LAN VSI |
| 6227 | * - For all others keep them at TC0 for now |
| 6228 | */ |
| 6229 | if (v == pf->lan_vsi) |
| 6230 | tc_map = i40e_pf_get_tc_map(pf); |
| 6231 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 6232 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6233 | |
| 6234 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 6235 | if (ret) { |
| 6236 | dev_info(&pf->pdev->dev, |
| 6237 | "Failed configuring TC for VSI seid=%d\n", |
| 6238 | pf->vsi[v]->seid); |
| 6239 | /* Will try to configure as many components */ |
| 6240 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 6241 | /* Re-configure VSI vectors based on updated TC map */ |
| 6242 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6243 | if (pf->vsi[v]->netdev) |
| 6244 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 6245 | } |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6250 | * i40e_resume_port_tx - Resume port Tx |
| 6251 | * @pf: PF struct |
| 6252 | * |
| 6253 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 6254 | * resume. |
| 6255 | **/ |
| 6256 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 6257 | { |
| 6258 | struct i40e_hw *hw = &pf->hw; |
| 6259 | int ret; |
| 6260 | |
| 6261 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 6262 | if (ret) { |
| 6263 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6264 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 6265 | i40e_stat_str(&pf->hw, ret), |
| 6266 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6267 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6268 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6269 | i40e_service_event_schedule(pf); |
| 6270 | } |
| 6271 | |
| 6272 | return ret; |
| 6273 | } |
| 6274 | |
| 6275 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6276 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 6277 | * @pf: PF being configured |
| 6278 | * |
| 6279 | * Query the current DCB configuration and cache it |
| 6280 | * in the hardware structure |
| 6281 | **/ |
| 6282 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 6283 | { |
| 6284 | struct i40e_hw *hw = &pf->hw; |
| 6285 | int err = 0; |
| 6286 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6287 | /* 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] | 6288 | if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6289 | goto out; |
| 6290 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6291 | /* Get the initial DCB configuration */ |
| 6292 | err = i40e_init_dcb(hw); |
| 6293 | if (!err) { |
| 6294 | /* Device/Function is not DCBX capable */ |
| 6295 | if ((!hw->func_caps.dcb) || |
| 6296 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 6297 | dev_info(&pf->pdev->dev, |
| 6298 | "DCBX offload is not supported or is disabled for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6299 | } else { |
| 6300 | /* When status is not DISABLED then DCBX in FW */ |
| 6301 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 6302 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6303 | |
| 6304 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 6305 | /* Enable DCB tagging only when more than one TC |
| 6306 | * or explicitly disable if only one TC |
| 6307 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6308 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 6309 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 6310 | else |
| 6311 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6312 | dev_dbg(&pf->pdev->dev, |
| 6313 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6314 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 6315 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6316 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6317 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 6318 | i40e_stat_str(&pf->hw, err), |
| 6319 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | out: |
| 6323 | return err; |
| 6324 | } |
| 6325 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6326 | #define SPEED_SIZE 14 |
| 6327 | #define FC_SIZE 8 |
| 6328 | /** |
| 6329 | * i40e_print_link_message - print link up or down |
| 6330 | * @vsi: the VSI for which link needs a message |
| 6331 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 6332 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6333 | { |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 6334 | enum i40e_aq_link_speed new_speed; |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6335 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6336 | char *speed = "Unknown"; |
| 6337 | char *fc = "Unknown"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6338 | char *fec = ""; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 6339 | char *req_fec = ""; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6340 | char *an = ""; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6341 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6342 | new_speed = pf->hw.phy.link_info.link_speed; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 6343 | |
| 6344 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 6345 | return; |
| 6346 | vsi->current_isup = isup; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 6347 | vsi->current_speed = new_speed; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6348 | if (!isup) { |
| 6349 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 6350 | return; |
| 6351 | } |
| 6352 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 6353 | /* Warn user if link speed on NPAR enabled partition is not at |
| 6354 | * least 10GB |
| 6355 | */ |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6356 | if (pf->hw.func_caps.npar_enable && |
| 6357 | (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 6358 | pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 6359 | netdev_warn(vsi->netdev, |
| 6360 | "The partition detected link speed that is less than 10Gbps\n"); |
| 6361 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6362 | switch (pf->hw.phy.link_info.link_speed) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6363 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6364 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6365 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 6366 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6367 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 6368 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 6369 | case I40E_LINK_SPEED_25GB: |
| 6370 | speed = "25 G"; |
| 6371 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6372 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6373 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6374 | break; |
| 6375 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6376 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6377 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 6378 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6379 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 6380 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6381 | default: |
| 6382 | break; |
| 6383 | } |
| 6384 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6385 | switch (pf->hw.fc.current_mode) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6386 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6387 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6388 | break; |
| 6389 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6390 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6391 | break; |
| 6392 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6393 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6394 | break; |
| 6395 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 6396 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6397 | break; |
| 6398 | } |
| 6399 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6400 | if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 6401 | req_fec = ", Requested FEC: None"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6402 | fec = ", FEC: None"; |
| 6403 | an = ", Autoneg: False"; |
| 6404 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6405 | if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6406 | an = ", Autoneg: True"; |
| 6407 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6408 | if (pf->hw.phy.link_info.fec_info & |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6409 | I40E_AQ_CONFIG_FEC_KR_ENA) |
| 6410 | fec = ", FEC: CL74 FC-FEC/BASE-R"; |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 6411 | else if (pf->hw.phy.link_info.fec_info & |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6412 | I40E_AQ_CONFIG_FEC_RS_ENA) |
| 6413 | fec = ", FEC: CL108 RS-FEC"; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 6414 | |
| 6415 | /* 'CL108 RS-FEC' should be displayed when RS is requested, or |
| 6416 | * both RS and FC are requested |
| 6417 | */ |
| 6418 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 6419 | (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) { |
| 6420 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 6421 | I40E_AQ_REQUEST_FEC_RS) |
| 6422 | req_fec = ", Requested FEC: CL108 RS-FEC"; |
| 6423 | else |
| 6424 | req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R"; |
| 6425 | } |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 6426 | } |
| 6427 | |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 6428 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n", |
| 6429 | speed, req_fec, fec, an, fc); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6430 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6431 | |
| 6432 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6433 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 6434 | * @vsi: the VSI being configured |
| 6435 | **/ |
| 6436 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 6437 | { |
| 6438 | struct i40e_pf *pf = vsi->back; |
| 6439 | int err; |
| 6440 | |
| 6441 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6442 | i40e_vsi_configure_msix(vsi); |
| 6443 | else |
| 6444 | i40e_configure_msi_and_legacy(vsi); |
| 6445 | |
| 6446 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 6447 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6448 | if (err) |
| 6449 | return err; |
| 6450 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6451 | clear_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6452 | i40e_napi_enable_all(vsi); |
| 6453 | i40e_vsi_enable_irq(vsi); |
| 6454 | |
| 6455 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 6456 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 6457 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6458 | netif_tx_start_all_queues(vsi->netdev); |
| 6459 | netif_carrier_on(vsi->netdev); |
| 6460 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 6461 | |
| 6462 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6463 | if (vsi->type == I40E_VSI_FDIR) { |
| 6464 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6465 | pf->fd_add_err = 0; |
| 6466 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 6467 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6468 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6469 | |
| 6470 | /* On the next run of the service_task, notify any clients of the new |
| 6471 | * opened netdev |
| 6472 | */ |
| 6473 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6474 | i40e_service_event_schedule(pf); |
| 6475 | |
| 6476 | return 0; |
| 6477 | } |
| 6478 | |
| 6479 | /** |
| 6480 | * i40e_vsi_reinit_locked - Reset the VSI |
| 6481 | * @vsi: the VSI being configured |
| 6482 | * |
| 6483 | * Rebuild the ring structs after some configuration |
| 6484 | * has changed, e.g. MTU size. |
| 6485 | **/ |
| 6486 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 6487 | { |
| 6488 | struct i40e_pf *pf = vsi->back; |
| 6489 | |
| 6490 | WARN_ON(in_interrupt()); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6491 | while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6492 | usleep_range(1000, 2000); |
| 6493 | i40e_down(vsi); |
| 6494 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6495 | i40e_up(vsi); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6496 | clear_bit(__I40E_CONFIG_BUSY, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6497 | } |
| 6498 | |
| 6499 | /** |
| 6500 | * i40e_up - Bring the connection back up after being down |
| 6501 | * @vsi: the VSI being configured |
| 6502 | **/ |
| 6503 | int i40e_up(struct i40e_vsi *vsi) |
| 6504 | { |
| 6505 | int err; |
| 6506 | |
| 6507 | err = i40e_vsi_configure(vsi); |
| 6508 | if (!err) |
| 6509 | err = i40e_up_complete(vsi); |
| 6510 | |
| 6511 | return err; |
| 6512 | } |
| 6513 | |
| 6514 | /** |
| 6515 | * i40e_down - Shutdown the connection processing |
| 6516 | * @vsi: the VSI being stopped |
| 6517 | **/ |
| 6518 | void i40e_down(struct i40e_vsi *vsi) |
| 6519 | { |
| 6520 | int i; |
| 6521 | |
| 6522 | /* It is assumed that the caller of this function |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 6523 | * sets the vsi->state __I40E_VSI_DOWN bit. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6524 | */ |
| 6525 | if (vsi->netdev) { |
| 6526 | netif_carrier_off(vsi->netdev); |
| 6527 | netif_tx_disable(vsi->netdev); |
| 6528 | } |
| 6529 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 6530 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6531 | i40e_napi_disable_all(vsi); |
| 6532 | |
| 6533 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6534 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 6535 | if (i40e_enabled_xdp_vsi(vsi)) |
| 6536 | i40e_clean_tx_ring(vsi->xdp_rings[i]); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6537 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6538 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 6539 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6540 | } |
| 6541 | |
| 6542 | /** |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6543 | * i40e_validate_mqprio_qopt- validate queue mapping info |
| 6544 | * @vsi: the VSI being configured |
| 6545 | * @mqprio_qopt: queue parametrs |
| 6546 | **/ |
| 6547 | static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi, |
| 6548 | struct tc_mqprio_qopt_offload *mqprio_qopt) |
| 6549 | { |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6550 | u64 sum_max_rate = 0; |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6551 | u64 max_rate = 0; |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6552 | int i; |
| 6553 | |
| 6554 | if (mqprio_qopt->qopt.offset[0] != 0 || |
| 6555 | mqprio_qopt->qopt.num_tc < 1 || |
| 6556 | mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS) |
| 6557 | return -EINVAL; |
| 6558 | for (i = 0; ; i++) { |
| 6559 | if (!mqprio_qopt->qopt.count[i]) |
| 6560 | return -EINVAL; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6561 | if (mqprio_qopt->min_rate[i]) { |
| 6562 | dev_err(&vsi->back->pdev->dev, |
| 6563 | "Invalid min tx rate (greater than 0) specified\n"); |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6564 | return -EINVAL; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6565 | } |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6566 | max_rate = mqprio_qopt->max_rate[i]; |
| 6567 | do_div(max_rate, I40E_BW_MBPS_DIVISOR); |
| 6568 | sum_max_rate += max_rate; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6569 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6570 | if (i >= mqprio_qopt->qopt.num_tc - 1) |
| 6571 | break; |
| 6572 | if (mqprio_qopt->qopt.offset[i + 1] != |
| 6573 | (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) |
| 6574 | return -EINVAL; |
| 6575 | } |
| 6576 | if (vsi->num_queue_pairs < |
| 6577 | (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) { |
| 6578 | return -EINVAL; |
| 6579 | } |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6580 | if (sum_max_rate > i40e_get_link_speed(vsi)) { |
| 6581 | dev_err(&vsi->back->pdev->dev, |
| 6582 | "Invalid max tx rate specified\n"); |
| 6583 | return -EINVAL; |
| 6584 | } |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6585 | return 0; |
| 6586 | } |
| 6587 | |
| 6588 | /** |
| 6589 | * i40e_vsi_set_default_tc_config - set default values for tc configuration |
| 6590 | * @vsi: the VSI being configured |
| 6591 | **/ |
| 6592 | static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi) |
| 6593 | { |
| 6594 | u16 qcount; |
| 6595 | int i; |
| 6596 | |
| 6597 | /* Only TC0 is enabled */ |
| 6598 | vsi->tc_config.numtc = 1; |
| 6599 | vsi->tc_config.enabled_tc = 1; |
| 6600 | qcount = min_t(int, vsi->alloc_queue_pairs, |
| 6601 | i40e_pf_get_max_q_per_tc(vsi->back)); |
| 6602 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 6603 | /* For the TC that is not enabled set the offset to to default |
| 6604 | * queue and allocate one queue for the given TC. |
| 6605 | */ |
| 6606 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 6607 | if (i == 0) |
| 6608 | vsi->tc_config.tc_info[i].qcount = qcount; |
| 6609 | else |
| 6610 | vsi->tc_config.tc_info[i].qcount = 1; |
| 6611 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 6612 | } |
| 6613 | } |
| 6614 | |
| 6615 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6616 | * i40e_setup_tc - configure multiple traffic classes |
| 6617 | * @netdev: net device to configure |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6618 | * @type_data: tc offload data |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6619 | **/ |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6620 | static int i40e_setup_tc(struct net_device *netdev, void *type_data) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6621 | { |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6622 | struct tc_mqprio_qopt_offload *mqprio_qopt = type_data; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6623 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6624 | struct i40e_vsi *vsi = np->vsi; |
| 6625 | struct i40e_pf *pf = vsi->back; |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6626 | u8 enabled_tc = 0, num_tc, hw; |
| 6627 | bool need_reset = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6628 | int ret = -EINVAL; |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6629 | u16 mode; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6630 | int i; |
| 6631 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6632 | num_tc = mqprio_qopt->qopt.num_tc; |
| 6633 | hw = mqprio_qopt->qopt.hw; |
| 6634 | mode = mqprio_qopt->mode; |
| 6635 | if (!hw) { |
| 6636 | pf->flags &= ~I40E_FLAG_TC_MQPRIO; |
| 6637 | memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt)); |
| 6638 | goto config_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | /* Check if MFP enabled */ |
| 6642 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6643 | netdev_info(netdev, |
| 6644 | "Configuring TC not supported in MFP mode\n"); |
| 6645 | return ret; |
| 6646 | } |
| 6647 | switch (mode) { |
| 6648 | case TC_MQPRIO_MODE_DCB: |
| 6649 | pf->flags &= ~I40E_FLAG_TC_MQPRIO; |
| 6650 | |
| 6651 | /* Check if DCB enabled to continue */ |
| 6652 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 6653 | netdev_info(netdev, |
| 6654 | "DCB is not enabled for adapter\n"); |
| 6655 | return ret; |
| 6656 | } |
| 6657 | |
| 6658 | /* Check whether tc count is within enabled limit */ |
| 6659 | if (num_tc > i40e_pf_get_num_tc(pf)) { |
| 6660 | netdev_info(netdev, |
| 6661 | "TC count greater than enabled on link for adapter\n"); |
| 6662 | return ret; |
| 6663 | } |
| 6664 | break; |
| 6665 | case TC_MQPRIO_MODE_CHANNEL: |
| 6666 | if (pf->flags & I40E_FLAG_DCB_ENABLED) { |
| 6667 | netdev_info(netdev, |
| 6668 | "Full offload of TC Mqprio options is not supported when DCB is enabled\n"); |
| 6669 | return ret; |
| 6670 | } |
| 6671 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 6672 | return ret; |
| 6673 | ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt); |
| 6674 | if (ret) |
| 6675 | return ret; |
| 6676 | memcpy(&vsi->mqprio_qopt, mqprio_qopt, |
| 6677 | sizeof(*mqprio_qopt)); |
| 6678 | pf->flags |= I40E_FLAG_TC_MQPRIO; |
| 6679 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 6680 | break; |
| 6681 | default: |
| 6682 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6685 | config_tc: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6686 | /* Generate TC map for number of tc requested */ |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6687 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6688 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6689 | |
| 6690 | /* Requesting same TC configuration as already enabled */ |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6691 | if (enabled_tc == vsi->tc_config.enabled_tc && |
| 6692 | mode != TC_MQPRIO_MODE_CHANNEL) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6693 | return 0; |
| 6694 | |
| 6695 | /* Quiesce VSI queues */ |
| 6696 | i40e_quiesce_vsi(vsi); |
| 6697 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6698 | if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO)) |
| 6699 | i40e_remove_queue_channels(vsi); |
| 6700 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6701 | /* Configure VSI for enabled TCs */ |
| 6702 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 6703 | if (ret) { |
| 6704 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 6705 | vsi->seid); |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6706 | need_reset = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6707 | goto exit; |
| 6708 | } |
| 6709 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6710 | if (pf->flags & I40E_FLAG_TC_MQPRIO) { |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6711 | if (vsi->mqprio_qopt.max_rate[0]) { |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6712 | u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; |
| 6713 | |
| 6714 | do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6715 | ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); |
| 6716 | if (!ret) { |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6717 | u64 credits = max_tx_rate; |
| 6718 | |
| 6719 | do_div(credits, I40E_BW_CREDIT_DIVISOR); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6720 | dev_dbg(&vsi->back->pdev->dev, |
| 6721 | "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", |
| 6722 | max_tx_rate, |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 6723 | credits, |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 6724 | vsi->seid); |
| 6725 | } else { |
| 6726 | need_reset = true; |
| 6727 | goto exit; |
| 6728 | } |
| 6729 | } |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6730 | ret = i40e_configure_queue_channels(vsi); |
| 6731 | if (ret) { |
| 6732 | netdev_info(netdev, |
| 6733 | "Failed configuring queue channels\n"); |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6734 | need_reset = true; |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6735 | goto exit; |
| 6736 | } |
| 6737 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6738 | |
| 6739 | exit: |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6740 | /* Reset the configuration data to defaults, only TC0 is enabled */ |
| 6741 | if (need_reset) { |
| 6742 | i40e_vsi_set_default_tc_config(vsi); |
| 6743 | need_reset = false; |
| 6744 | } |
| 6745 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 6746 | /* Unquiesce VSI */ |
| 6747 | i40e_unquiesce_vsi(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6748 | return ret; |
| 6749 | } |
| 6750 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 6751 | 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] | 6752 | void *type_data) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 6753 | { |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 6754 | if (type != TC_SETUP_MQPRIO) |
Jiri Pirko | 38cf042 | 2017-08-07 10:15:31 +0200 | [diff] [blame] | 6755 | return -EOPNOTSUPP; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 6756 | |
Amritha Nambiar | a9ce82f | 2017-09-07 04:00:22 -0700 | [diff] [blame] | 6757 | return i40e_setup_tc(netdev, type_data); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 6758 | } |
| 6759 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6760 | /** |
| 6761 | * i40e_open - Called when a network interface is made active |
| 6762 | * @netdev: network interface device structure |
| 6763 | * |
| 6764 | * The open entry point is called when a network interface is made |
| 6765 | * active by the system (IFF_UP). At this point all resources needed |
| 6766 | * for transmit and receive operations are allocated, the interrupt |
| 6767 | * handler is registered with the OS, the netdev watchdog subtask is |
| 6768 | * enabled, and the stack is notified that the interface is ready. |
| 6769 | * |
| 6770 | * Returns 0 on success, negative value on failure |
| 6771 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6772 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6773 | { |
| 6774 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6775 | struct i40e_vsi *vsi = np->vsi; |
| 6776 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6777 | int err; |
| 6778 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6779 | /* disallow open during test or if eeprom is broken */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6780 | if (test_bit(__I40E_TESTING, pf->state) || |
| 6781 | test_bit(__I40E_BAD_EEPROM, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6782 | return -EBUSY; |
| 6783 | |
| 6784 | netif_carrier_off(netdev); |
| 6785 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 6786 | err = i40e_vsi_open(vsi); |
| 6787 | if (err) |
| 6788 | return err; |
| 6789 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 6790 | /* configure global TSO hardware offload settings */ |
| 6791 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 6792 | TCP_FLAG_FIN) >> 16); |
| 6793 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 6794 | TCP_FLAG_FIN | |
| 6795 | TCP_FLAG_CWR) >> 16); |
| 6796 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 6797 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 6798 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6799 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 6800 | return 0; |
| 6801 | } |
| 6802 | |
| 6803 | /** |
| 6804 | * i40e_vsi_open - |
| 6805 | * @vsi: the VSI to open |
| 6806 | * |
| 6807 | * Finish initialization of the VSI. |
| 6808 | * |
| 6809 | * Returns 0 on success, negative value on failure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6810 | * |
| 6811 | * Note: expects to be called while under rtnl_lock() |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 6812 | **/ |
| 6813 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 6814 | { |
| 6815 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 6816 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 6817 | int err; |
| 6818 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6819 | /* allocate descriptors */ |
| 6820 | err = i40e_vsi_setup_tx_resources(vsi); |
| 6821 | if (err) |
| 6822 | goto err_setup_tx; |
| 6823 | err = i40e_vsi_setup_rx_resources(vsi); |
| 6824 | if (err) |
| 6825 | goto err_setup_rx; |
| 6826 | |
| 6827 | err = i40e_vsi_configure(vsi); |
| 6828 | if (err) |
| 6829 | goto err_setup_rx; |
| 6830 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 6831 | if (vsi->netdev) { |
| 6832 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 6833 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 6834 | err = i40e_vsi_request_irq(vsi, int_name); |
| 6835 | if (err) |
| 6836 | goto err_setup_rx; |
| 6837 | |
| 6838 | /* Notify the stack of the actual queue counts. */ |
| 6839 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 6840 | vsi->num_queue_pairs); |
| 6841 | if (err) |
| 6842 | goto err_set_queues; |
| 6843 | |
| 6844 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 6845 | vsi->num_queue_pairs); |
| 6846 | if (err) |
| 6847 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6848 | |
| 6849 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 6850 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 6851 | dev_driver_string(&pf->pdev->dev), |
| 6852 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6853 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 6854 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 6855 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 6856 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 6857 | goto err_setup_rx; |
| 6858 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 6859 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6860 | err = i40e_up_complete(vsi); |
| 6861 | if (err) |
| 6862 | goto err_up_complete; |
| 6863 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6864 | return 0; |
| 6865 | |
| 6866 | err_up_complete: |
| 6867 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 6868 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6869 | i40e_vsi_free_irq(vsi); |
| 6870 | err_setup_rx: |
| 6871 | i40e_vsi_free_rx_resources(vsi); |
| 6872 | err_setup_tx: |
| 6873 | i40e_vsi_free_tx_resources(vsi); |
| 6874 | if (vsi == pf->vsi[pf->lan_vsi]) |
Amritha Nambiar | ff42418 | 2017-09-07 04:00:11 -0700 | [diff] [blame] | 6875 | i40e_do_reset(pf, I40E_PF_RESET_FLAG, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6876 | |
| 6877 | return err; |
| 6878 | } |
| 6879 | |
| 6880 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6881 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6882 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6883 | * |
| 6884 | * This function destroys the hlist where all the Flow Director |
| 6885 | * filters were saved. |
| 6886 | **/ |
| 6887 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 6888 | { |
| 6889 | struct i40e_fdir_filter *filter; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 6890 | struct i40e_flex_pit *pit_entry, *tmp; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6891 | struct hlist_node *node2; |
| 6892 | |
| 6893 | hlist_for_each_entry_safe(filter, node2, |
| 6894 | &pf->fdir_filter_list, fdir_node) { |
| 6895 | hlist_del(&filter->fdir_node); |
| 6896 | kfree(filter); |
| 6897 | } |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6898 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 6899 | list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) { |
| 6900 | list_del(&pit_entry->list); |
| 6901 | kfree(pit_entry); |
| 6902 | } |
| 6903 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 6904 | |
| 6905 | list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) { |
| 6906 | list_del(&pit_entry->list); |
| 6907 | kfree(pit_entry); |
| 6908 | } |
| 6909 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 6910 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6911 | pf->fdir_pf_active_filters = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6912 | pf->fd_tcp4_filter_cnt = 0; |
| 6913 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 6914 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6915 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 3bcee1e | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6916 | |
| 6917 | /* Reprogram the default input set for TCP/IPv4 */ |
| 6918 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP, |
| 6919 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 6920 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 6921 | |
| 6922 | /* Reprogram the default input set for UDP/IPv4 */ |
| 6923 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP, |
| 6924 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 6925 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 6926 | |
| 6927 | /* Reprogram the default input set for SCTP/IPv4 */ |
| 6928 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP, |
| 6929 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 6930 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 6931 | |
| 6932 | /* Reprogram the default input set for Other/IPv4 */ |
| 6933 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER, |
| 6934 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6935 | } |
| 6936 | |
| 6937 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6938 | * i40e_close - Disables a network interface |
| 6939 | * @netdev: network interface device structure |
| 6940 | * |
| 6941 | * The close entry point is called when an interface is de-activated |
| 6942 | * by the OS. The hardware is still under the driver's control, but |
| 6943 | * this netdev interface is disabled. |
| 6944 | * |
| 6945 | * Returns 0, this is not allowed to fail |
| 6946 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6947 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6948 | { |
| 6949 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6950 | struct i40e_vsi *vsi = np->vsi; |
| 6951 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 6952 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6953 | |
| 6954 | return 0; |
| 6955 | } |
| 6956 | |
| 6957 | /** |
| 6958 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 6959 | * @pf: board private structure |
| 6960 | * @reset_flags: which reset is requested |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6961 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 6962 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6963 | * |
| 6964 | * The essential difference in resets is that the PF Reset |
| 6965 | * doesn't clear the packet buffers, doesn't reset the PE |
| 6966 | * firmware, and doesn't bother the other PFs on the chip. |
| 6967 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6968 | 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] | 6969 | { |
| 6970 | u32 val; |
| 6971 | |
| 6972 | WARN_ON(in_interrupt()); |
| 6973 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 6974 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6975 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 6976 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6977 | |
| 6978 | /* Request a Global Reset |
| 6979 | * |
| 6980 | * This will start the chip's countdown to the actual full |
| 6981 | * chip reset event, and a warning interrupt to be sent |
| 6982 | * to all PFs, including the requestor. Our handler |
| 6983 | * for the warning interrupt will deal with the shutdown |
| 6984 | * and recovery of the switch setup. |
| 6985 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6986 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6987 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 6988 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 6989 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 6990 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 6991 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6992 | |
| 6993 | /* Request a Core Reset |
| 6994 | * |
| 6995 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 6996 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6997 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6998 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 6999 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 7000 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 7001 | i40e_flush(&pf->hw); |
| 7002 | |
Amritha Nambiar | ff42418 | 2017-09-07 04:00:11 -0700 | [diff] [blame] | 7003 | } else if (reset_flags & I40E_PF_RESET_FLAG) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7004 | |
| 7005 | /* Request a PF Reset |
| 7006 | * |
| 7007 | * Resets only the PF-specific registers |
| 7008 | * |
| 7009 | * This goes directly to the tear-down and rebuild of |
| 7010 | * the switch, since we need to do all the recovery as |
| 7011 | * for the Core Reset. |
| 7012 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7013 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7014 | i40e_handle_reset_warning(pf, lock_acquired); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7015 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 7016 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7017 | int v; |
| 7018 | |
| 7019 | /* Find the VSI(s) that requested a re-init */ |
| 7020 | dev_info(&pf->pdev->dev, |
| 7021 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7022 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7023 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 7024 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7025 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 7026 | test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7027 | vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7028 | i40e_vsi_reinit_locked(pf->vsi[v]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 7030 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 7031 | int v; |
| 7032 | |
| 7033 | /* Find the VSI(s) that needs to be brought down */ |
| 7034 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 7035 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 7036 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 7037 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 7038 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 7039 | test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7040 | vsi->state)) { |
| 7041 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 7042 | i40e_down(vsi); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 7043 | } |
| 7044 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7045 | } else { |
| 7046 | dev_info(&pf->pdev->dev, |
| 7047 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7048 | } |
| 7049 | } |
| 7050 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7051 | #ifdef CONFIG_I40E_DCB |
| 7052 | /** |
| 7053 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 7054 | * @pf: board private structure |
| 7055 | * @old_cfg: current DCB config |
| 7056 | * @new_cfg: new DCB config |
| 7057 | **/ |
| 7058 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 7059 | struct i40e_dcbx_config *old_cfg, |
| 7060 | struct i40e_dcbx_config *new_cfg) |
| 7061 | { |
| 7062 | bool need_reconfig = false; |
| 7063 | |
| 7064 | /* Check if ETS configuration has changed */ |
| 7065 | if (memcmp(&new_cfg->etscfg, |
| 7066 | &old_cfg->etscfg, |
| 7067 | sizeof(new_cfg->etscfg))) { |
| 7068 | /* If Priority Table has changed reconfig is needed */ |
| 7069 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 7070 | &old_cfg->etscfg.prioritytable, |
| 7071 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 7072 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7073 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 7077 | &old_cfg->etscfg.tcbwtable, |
| 7078 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7079 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7080 | |
| 7081 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 7082 | &old_cfg->etscfg.tsatable, |
| 7083 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7084 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | /* Check if PFC configuration has changed */ |
| 7088 | if (memcmp(&new_cfg->pfc, |
| 7089 | &old_cfg->pfc, |
| 7090 | sizeof(new_cfg->pfc))) { |
| 7091 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7092 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | /* Check if APP Table has changed */ |
| 7096 | if (memcmp(&new_cfg->app, |
| 7097 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 7098 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7099 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7100 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 7101 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7102 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 7103 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7104 | return need_reconfig; |
| 7105 | } |
| 7106 | |
| 7107 | /** |
| 7108 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 7109 | * @pf: board private structure |
| 7110 | * @e: event info posted on ARQ |
| 7111 | **/ |
| 7112 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 7113 | struct i40e_arq_event_info *e) |
| 7114 | { |
| 7115 | struct i40e_aqc_lldp_get_mib *mib = |
| 7116 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 7117 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7118 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 7119 | bool need_reconfig = false; |
| 7120 | int ret = 0; |
| 7121 | u8 type; |
| 7122 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7123 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 7124 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7125 | return ret; |
| 7126 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7127 | /* Ignore if event is not for Nearest Bridge */ |
| 7128 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 7129 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 7130 | 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] | 7131 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 7132 | return ret; |
| 7133 | |
| 7134 | /* Check MIB Type and return if event for Remote MIB update */ |
| 7135 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 7136 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 7137 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7138 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 7139 | /* Update the remote cached instance and return */ |
| 7140 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 7141 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 7142 | &hw->remote_dcbx_config); |
| 7143 | goto exit; |
| 7144 | } |
| 7145 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 7146 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 7147 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 7148 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 7149 | /* Reset the old DCBx configuration data */ |
| 7150 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 7151 | /* Get updated DCBX data from firmware */ |
| 7152 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7153 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7154 | dev_info(&pf->pdev->dev, |
| 7155 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 7156 | i40e_stat_str(&pf->hw, ret), |
| 7157 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7158 | goto exit; |
| 7159 | } |
| 7160 | |
| 7161 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 7162 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 7163 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7164 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7165 | goto exit; |
| 7166 | } |
| 7167 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 7168 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 7169 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7170 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 7171 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7172 | |
| 7173 | if (!need_reconfig) |
| 7174 | goto exit; |
| 7175 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7176 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 7177 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7178 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 7179 | else |
| 7180 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 7181 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7182 | set_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7183 | /* Reconfiguration needed quiesce all VSIs */ |
| 7184 | i40e_pf_quiesce_all_vsi(pf); |
| 7185 | |
| 7186 | /* Changes in configuration update VEB/VSI */ |
| 7187 | i40e_dcb_reconfigure(pf); |
| 7188 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 7189 | ret = i40e_resume_port_tx(pf); |
| 7190 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7191 | clear_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 7192 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 7193 | if (ret) |
| 7194 | goto exit; |
| 7195 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 7196 | /* Wait for the PF's queues to be disabled */ |
| 7197 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 7198 | if (ret) { |
| 7199 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7200 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 7201 | i40e_service_event_schedule(pf); |
| 7202 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 7203 | i40e_pf_unquiesce_all_vsi(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 7204 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 7205 | I40E_FLAG_CLIENT_L2_CHANGE); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 7206 | } |
| 7207 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7208 | exit: |
| 7209 | return ret; |
| 7210 | } |
| 7211 | #endif /* CONFIG_I40E_DCB */ |
| 7212 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7213 | /** |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 7214 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 7215 | * @pf: board private structure |
| 7216 | * @reset_flags: which reset is requested |
| 7217 | * |
| 7218 | **/ |
| 7219 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 7220 | { |
| 7221 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7222 | i40e_do_reset(pf, reset_flags, true); |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 7223 | rtnl_unlock(); |
| 7224 | } |
| 7225 | |
| 7226 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7227 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 7228 | * @pf: board private structure |
| 7229 | * @e: event info posted on ARQ |
| 7230 | * |
| 7231 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 7232 | * and VF queues |
| 7233 | **/ |
| 7234 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 7235 | struct i40e_arq_event_info *e) |
| 7236 | { |
| 7237 | struct i40e_aqc_lan_overflow *data = |
| 7238 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 7239 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 7240 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 7241 | struct i40e_hw *hw = &pf->hw; |
| 7242 | struct i40e_vf *vf; |
| 7243 | u16 vf_id; |
| 7244 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7245 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 7246 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7247 | |
| 7248 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 7249 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 7250 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 7251 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 7252 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 7253 | vf_id -= hw->func_caps.vf_base_id; |
| 7254 | vf = &pf->vf[vf_id]; |
| 7255 | i40e_vc_notify_vf_reset(vf); |
| 7256 | /* Allow VF to process pending reset notification */ |
| 7257 | msleep(20); |
| 7258 | i40e_reset_vf(vf, false); |
| 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 7263 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 7264 | * @pf: board private structure |
| 7265 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7266 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 7267 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7268 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 7269 | |
| 7270 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 7271 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 7272 | return fcnt_prog; |
| 7273 | } |
| 7274 | |
| 7275 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7276 | * 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] | 7277 | * @pf: board private structure |
| 7278 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7279 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7280 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7281 | u32 val, fcnt_prog; |
| 7282 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7283 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 7284 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 7285 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 7286 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 7287 | return fcnt_prog; |
| 7288 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7289 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7290 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7291 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 7292 | * @pf: board private structure |
| 7293 | **/ |
| 7294 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 7295 | { |
| 7296 | u32 val, fcnt_prog; |
| 7297 | |
| 7298 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 7299 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 7300 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 7301 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 7302 | return fcnt_prog; |
| 7303 | } |
| 7304 | |
| 7305 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7306 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 7307 | * @pf: board private structure |
| 7308 | **/ |
| 7309 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 7310 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 7311 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7312 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 7313 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7314 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7315 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7316 | return; |
| 7317 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7318 | /* 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] | 7319 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 7320 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7321 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 7322 | (pf->fd_add_err == 0) || |
| 7323 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7324 | if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) { |
| 7325 | pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED; |
| 7326 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7327 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 7328 | 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] | 7329 | } |
| 7330 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 7331 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7332 | /* We should wait for even more space before re-enabling ATR. |
| 7333 | * Additionally, we cannot enable ATR as long as we still have TCP SB |
| 7334 | * rules active. |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 7335 | */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7336 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) && |
| 7337 | (pf->fd_tcp4_filter_cnt == 0)) { |
| 7338 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 7339 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 7340 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 7341 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 7342 | 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] | 7343 | } |
| 7344 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 7345 | |
| 7346 | /* if hw had a problem adding a filter, delete it */ |
| 7347 | if (pf->fd_inv > 0) { |
| 7348 | hlist_for_each_entry_safe(filter, node, |
| 7349 | &pf->fdir_filter_list, fdir_node) { |
| 7350 | if (filter->fd_id == pf->fd_inv) { |
| 7351 | hlist_del(&filter->fdir_node); |
| 7352 | kfree(filter); |
| 7353 | pf->fdir_pf_active_filters--; |
Filip Sadowski | 013df59 | 2017-08-29 05:32:38 -0400 | [diff] [blame] | 7354 | pf->fd_inv = 0; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 7355 | } |
| 7356 | } |
| 7357 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7358 | } |
| 7359 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7360 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7361 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7362 | /** |
| 7363 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 7364 | * @pf: board private structure |
| 7365 | **/ |
| 7366 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 7367 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7368 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7369 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7370 | bool disable_atr = false; |
| 7371 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7372 | int reg; |
| 7373 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7374 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 7375 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 7376 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7377 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7378 | /* If the flush is happening too quick and we have mostly SB rules we |
| 7379 | * should not re-enable ATR for some time. |
| 7380 | */ |
| 7381 | min_flush_time = pf->fd_flush_timestamp + |
| 7382 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 7383 | 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] | 7384 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7385 | if (!(time_after(jiffies, min_flush_time)) && |
| 7386 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 7387 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 7388 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 7389 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7390 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7391 | |
| 7392 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7393 | pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7394 | /* flush all filters */ |
| 7395 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 7396 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 7397 | i40e_flush(&pf->hw); |
| 7398 | pf->fd_flush_cnt++; |
| 7399 | pf->fd_add_err = 0; |
| 7400 | do { |
| 7401 | /* Check FD flush status every 5-6msec */ |
| 7402 | usleep_range(5000, 6000); |
| 7403 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 7404 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 7405 | break; |
| 7406 | } while (flush_wait_retry--); |
| 7407 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 7408 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 7409 | } else { |
| 7410 | /* replay sideband filters */ |
| 7411 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 7412 | if (!disable_atr && !pf->fd_tcp4_filter_cnt) |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 7413 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7414 | clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state); |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 7415 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 7416 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 7417 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7418 | } |
| 7419 | |
| 7420 | /** |
| 7421 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 7422 | * @pf: board private structure |
| 7423 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 7424 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7425 | { |
| 7426 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 7427 | } |
| 7428 | |
| 7429 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 7430 | * being applied really fast; before we see the first |
| 7431 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 7432 | * reacting will make sure we don't cause flush too often. |
| 7433 | */ |
| 7434 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 7435 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7436 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7437 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 7438 | * @pf: board private structure |
| 7439 | **/ |
| 7440 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 7441 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7442 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7443 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7444 | if (test_bit(__I40E_DOWN, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7445 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7446 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7447 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7448 | i40e_fdir_flush_and_replay(pf); |
| 7449 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 7450 | i40e_fdir_check_and_reenable(pf); |
| 7451 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7452 | } |
| 7453 | |
| 7454 | /** |
| 7455 | * i40e_vsi_link_event - notify VSI of a link event |
| 7456 | * @vsi: vsi to be notified |
| 7457 | * @link_up: link up or down |
| 7458 | **/ |
| 7459 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 7460 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7461 | if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7462 | return; |
| 7463 | |
| 7464 | switch (vsi->type) { |
| 7465 | case I40E_VSI_MAIN: |
| 7466 | if (!vsi->netdev || !vsi->netdev_registered) |
| 7467 | break; |
| 7468 | |
| 7469 | if (link_up) { |
| 7470 | netif_carrier_on(vsi->netdev); |
| 7471 | netif_tx_wake_all_queues(vsi->netdev); |
| 7472 | } else { |
| 7473 | netif_carrier_off(vsi->netdev); |
| 7474 | netif_tx_stop_all_queues(vsi->netdev); |
| 7475 | } |
| 7476 | break; |
| 7477 | |
| 7478 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | case I40E_VSI_VMDQ2: |
| 7480 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7481 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7482 | case I40E_VSI_MIRROR: |
| 7483 | default: |
| 7484 | /* there is no notification for other VSIs */ |
| 7485 | break; |
| 7486 | } |
| 7487 | } |
| 7488 | |
| 7489 | /** |
| 7490 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 7491 | * @veb: veb to be notified |
| 7492 | * @link_up: link up or down |
| 7493 | **/ |
| 7494 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 7495 | { |
| 7496 | struct i40e_pf *pf; |
| 7497 | int i; |
| 7498 | |
| 7499 | if (!veb || !veb->pf) |
| 7500 | return; |
| 7501 | pf = veb->pf; |
| 7502 | |
| 7503 | /* depth first... */ |
| 7504 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 7505 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 7506 | i40e_veb_link_event(pf->veb[i], link_up); |
| 7507 | |
| 7508 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7509 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7510 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 7511 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 7512 | } |
| 7513 | |
| 7514 | /** |
| 7515 | * i40e_link_event - Update netif_carrier status |
| 7516 | * @pf: board private structure |
| 7517 | **/ |
| 7518 | static void i40e_link_event(struct i40e_pf *pf) |
| 7519 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 7520 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 7521 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 7522 | i40e_status status; |
| 7523 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7524 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 7525 | /* save off old link status information */ |
| 7526 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 7527 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 7528 | /* set this to force the get_link_status call to refresh state */ |
| 7529 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7530 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 7531 | 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] | 7532 | |
| 7533 | status = i40e_get_link_status(&pf->hw, &new_link); |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 7534 | |
| 7535 | /* On success, disable temp link polling */ |
| 7536 | if (status == I40E_SUCCESS) { |
| 7537 | if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING) |
| 7538 | pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING; |
| 7539 | } else { |
| 7540 | /* Enable link polling temporarily until i40e_get_link_status |
| 7541 | * returns I40E_SUCCESS |
| 7542 | */ |
| 7543 | pf->flags |= I40E_FLAG_TEMP_LINK_POLLING; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 7544 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 7545 | status); |
| 7546 | return; |
| 7547 | } |
| 7548 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 7549 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 7550 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 7551 | |
| 7552 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 7553 | new_link_speed == old_link_speed && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7554 | (test_bit(__I40E_VSI_DOWN, vsi->state) || |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 7555 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7556 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 7557 | |
Sudheer Mogilappagari | 9a03449 | 2017-07-14 09:10:16 -0400 | [diff] [blame] | 7558 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7559 | |
| 7560 | /* Notify the base of the switch tree connected to |
| 7561 | * the link. Floating VEBs are not notified. |
| 7562 | */ |
| 7563 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 7564 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 7565 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 7566 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7567 | |
| 7568 | if (pf->vf) |
| 7569 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 7570 | |
| 7571 | if (pf->flags & I40E_FLAG_PTP) |
| 7572 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7573 | } |
| 7574 | |
| 7575 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 7576 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7577 | * @pf: board private structure |
| 7578 | **/ |
| 7579 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 7580 | { |
| 7581 | int i; |
| 7582 | |
| 7583 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7584 | if (test_bit(__I40E_DOWN, pf->state) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7585 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7586 | return; |
| 7587 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 7588 | /* make sure we don't do these things too often */ |
| 7589 | if (time_before(jiffies, (pf->service_timer_previous + |
| 7590 | pf->service_timer_period))) |
| 7591 | return; |
| 7592 | pf->service_timer_previous = jiffies; |
| 7593 | |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 7594 | if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) || |
| 7595 | (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)) |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 7596 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 7597 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | /* Update the stats for active netdevs so the network stack |
| 7599 | * can look at updated numbers whenever it cares to |
| 7600 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7601 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7602 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 7603 | i40e_update_stats(pf->vsi[i]); |
| 7604 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 7605 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 7606 | /* Update the stats for the active switching components */ |
| 7607 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 7608 | if (pf->veb[i]) |
| 7609 | i40e_update_veb_stats(pf->veb[i]); |
| 7610 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 7611 | |
Jacob Keller | 6118955 | 2017-05-03 10:29:01 -0700 | [diff] [blame] | 7612 | i40e_ptp_rx_hang(pf); |
Jacob Keller | 0bc0706 | 2017-05-03 10:29:02 -0700 | [diff] [blame] | 7613 | i40e_ptp_tx_hang(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | /** |
| 7617 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 7618 | * @pf: board private structure |
| 7619 | **/ |
| 7620 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 7621 | { |
| 7622 | u32 reset_flags = 0; |
| 7623 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7624 | if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 7625 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7626 | clear_bit(__I40E_REINIT_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7627 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7628 | if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 7629 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7630 | clear_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7631 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7632 | if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 7633 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7634 | clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7635 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7636 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 7637 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7638 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7639 | } |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7640 | if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) { |
| 7641 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
| 7642 | clear_bit(__I40E_DOWN_REQUESTED, pf->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 7643 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7644 | |
| 7645 | /* If there's a recovery already waiting, it takes |
| 7646 | * precedence before starting a new reset sequence. |
| 7647 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7648 | if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7649 | i40e_prep_for_reset(pf, false); |
| 7650 | i40e_reset(pf); |
| 7651 | i40e_rebuild(pf, false, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7652 | } |
| 7653 | |
| 7654 | /* If we're already down or resetting, just bail */ |
| 7655 | if (reset_flags && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7656 | !test_bit(__I40E_DOWN, pf->state) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7657 | !test_bit(__I40E_CONFIG_BUSY, pf->state)) { |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 7658 | i40e_do_reset(pf, reset_flags, false); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7659 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | /** |
| 7663 | * i40e_handle_link_event - Handle link event |
| 7664 | * @pf: board private structure |
| 7665 | * @e: event info posted on ARQ |
| 7666 | **/ |
| 7667 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 7668 | struct i40e_arq_event_info *e) |
| 7669 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7670 | struct i40e_aqc_get_link_status *status = |
| 7671 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7672 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 7673 | /* Do a new status request to re-enable LSE reporting |
| 7674 | * and load new status information into the hw struct |
| 7675 | * This completely ignores any state information |
| 7676 | * in the ARQ event info, instead choosing to always |
| 7677 | * issue the AQ update link status command. |
| 7678 | */ |
| 7679 | i40e_link_event(pf); |
| 7680 | |
Filip Sadowski | 9a85817 | 2017-08-29 05:32:37 -0400 | [diff] [blame] | 7681 | /* Check if module meets thermal requirements */ |
| 7682 | if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) { |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 7683 | dev_err(&pf->pdev->dev, |
Filip Sadowski | 9a85817 | 2017-08-29 05:32:37 -0400 | [diff] [blame] | 7684 | "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n"); |
| 7685 | dev_err(&pf->pdev->dev, |
| 7686 | "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); |
| 7687 | } else { |
| 7688 | /* check for unqualified module, if link is down, suppress |
| 7689 | * the message if link was forced to be down. |
| 7690 | */ |
| 7691 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 7692 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 7693 | (!(status->link_info & I40E_AQ_LINK_UP)) && |
| 7694 | (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) { |
| 7695 | dev_err(&pf->pdev->dev, |
| 7696 | "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n"); |
| 7697 | dev_err(&pf->pdev->dev, |
| 7698 | "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); |
| 7699 | } |
| 7700 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | /** |
| 7704 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 7705 | * @pf: board private structure |
| 7706 | **/ |
| 7707 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 7708 | { |
| 7709 | struct i40e_arq_event_info event; |
| 7710 | struct i40e_hw *hw = &pf->hw; |
| 7711 | u16 pending, i = 0; |
| 7712 | i40e_status ret; |
| 7713 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7714 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7715 | u32 val; |
| 7716 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7717 | /* Do not run clean AQ when PF reset fails */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7718 | if (test_bit(__I40E_RESET_FAILED, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7719 | return; |
| 7720 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7721 | /* check for error indications */ |
| 7722 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 7723 | oldval = val; |
| 7724 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7725 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 7726 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7727 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 7728 | } |
| 7729 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7730 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 7731 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7732 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 7733 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7734 | } |
| 7735 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7736 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 7737 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7738 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 7739 | } |
| 7740 | if (oldval != val) |
| 7741 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 7742 | |
| 7743 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 7744 | oldval = val; |
| 7745 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7746 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 7747 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7748 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 7749 | } |
| 7750 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7751 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 7752 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7753 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 7754 | } |
| 7755 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 7756 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 7757 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 7758 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 7759 | } |
| 7760 | if (oldval != val) |
| 7761 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 7762 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 7763 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 7764 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7765 | if (!event.msg_buf) |
| 7766 | return; |
| 7767 | |
| 7768 | do { |
| 7769 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 7770 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7771 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 7772 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7773 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 7774 | break; |
| 7775 | } |
| 7776 | |
| 7777 | opcode = le16_to_cpu(event.desc.opcode); |
| 7778 | switch (opcode) { |
| 7779 | |
| 7780 | case i40e_aqc_opc_get_link_status: |
| 7781 | i40e_handle_link_event(pf, &event); |
| 7782 | break; |
| 7783 | case i40e_aqc_opc_send_msg_to_pf: |
| 7784 | ret = i40e_vc_process_vf_msg(pf, |
| 7785 | le16_to_cpu(event.desc.retval), |
| 7786 | le32_to_cpu(event.desc.cookie_high), |
| 7787 | le32_to_cpu(event.desc.cookie_low), |
| 7788 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 7789 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7790 | break; |
| 7791 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7792 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7793 | #ifdef CONFIG_I40E_DCB |
| 7794 | rtnl_lock(); |
| 7795 | ret = i40e_handle_lldp_event(pf, &event); |
| 7796 | rtnl_unlock(); |
| 7797 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7798 | break; |
| 7799 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7800 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7801 | i40e_handle_lan_overflow_event(pf, &event); |
| 7802 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 7803 | case i40e_aqc_opc_send_msg_to_peer: |
| 7804 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 7805 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 7806 | case i40e_aqc_opc_nvm_erase: |
| 7807 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 7808 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 7809 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 7810 | "ARQ NVM operation 0x%04x completed\n", |
| 7811 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 7812 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7813 | default: |
| 7814 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 7815 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 7816 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7817 | break; |
| 7818 | } |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 7819 | } while (i++ < pf->adminq_work_limit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7820 | |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 7821 | if (i < pf->adminq_work_limit) |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7822 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 7823 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7824 | /* re-enable Admin queue interrupt cause */ |
| 7825 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7826 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 7827 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 7828 | i40e_flush(hw); |
| 7829 | |
| 7830 | kfree(event.msg_buf); |
| 7831 | } |
| 7832 | |
| 7833 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7834 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 7835 | * @pf: board private structure |
| 7836 | **/ |
| 7837 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 7838 | { |
| 7839 | int err; |
| 7840 | |
| 7841 | err = i40e_diag_eeprom_test(&pf->hw); |
| 7842 | if (err) { |
| 7843 | /* retry in case of garbage read */ |
| 7844 | err = i40e_diag_eeprom_test(&pf->hw); |
| 7845 | if (err) { |
| 7846 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 7847 | err); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7848 | set_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7849 | } |
| 7850 | } |
| 7851 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7852 | if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7853 | 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] | 7854 | clear_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7855 | } |
| 7856 | } |
| 7857 | |
| 7858 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7859 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7860 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7861 | * |
| 7862 | * enable switch loop back or die - no point in a return value |
| 7863 | **/ |
| 7864 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 7865 | { |
| 7866 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 7867 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7868 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7869 | |
| 7870 | ctxt.seid = pf->main_vsi_seid; |
| 7871 | ctxt.pf_num = pf->hw.pf_id; |
| 7872 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7873 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 7874 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7875 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7876 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 7877 | i40e_stat_str(&pf->hw, ret), |
| 7878 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7879 | return; |
| 7880 | } |
| 7881 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 7882 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 7883 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 7884 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7885 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 7886 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7887 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7888 | "update vsi switch failed, err %s aq_err %s\n", |
| 7889 | i40e_stat_str(&pf->hw, ret), |
| 7890 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7891 | } |
| 7892 | } |
| 7893 | |
| 7894 | /** |
| 7895 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7896 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7897 | * |
| 7898 | * disable switch loop back or die - no point in a return value |
| 7899 | **/ |
| 7900 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 7901 | { |
| 7902 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 7903 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7904 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7905 | |
| 7906 | ctxt.seid = pf->main_vsi_seid; |
| 7907 | ctxt.pf_num = pf->hw.pf_id; |
| 7908 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7909 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 7910 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7911 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7912 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 7913 | i40e_stat_str(&pf->hw, ret), |
| 7914 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7915 | return; |
| 7916 | } |
| 7917 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 7918 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 7919 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 7920 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7921 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 7922 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7923 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7924 | "update vsi switch failed, err %s aq_err %s\n", |
| 7925 | i40e_stat_str(&pf->hw, ret), |
| 7926 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 7927 | } |
| 7928 | } |
| 7929 | |
| 7930 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 7931 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 7932 | * @veb: pointer to the bridge instance |
| 7933 | * |
| 7934 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 7935 | * specified HW bridge instance. It is expected this function is called |
| 7936 | * when a new HW bridge is instantiated. |
| 7937 | **/ |
| 7938 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 7939 | { |
| 7940 | struct i40e_pf *pf = veb->pf; |
| 7941 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 7942 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 7943 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 7944 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 7945 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 7946 | i40e_disable_pf_switch_lb(pf); |
| 7947 | else |
| 7948 | i40e_enable_pf_switch_lb(pf); |
| 7949 | } |
| 7950 | |
| 7951 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7952 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 7953 | * @veb: pointer to the VEB instance |
| 7954 | * |
| 7955 | * This is a recursive function that first builds the attached VSIs then |
| 7956 | * recurses in to build the next layer of VEB. We track the connections |
| 7957 | * through our own index numbers because the seid's from the HW could |
| 7958 | * change across the reset. |
| 7959 | **/ |
| 7960 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 7961 | { |
| 7962 | struct i40e_vsi *ctl_vsi = NULL; |
| 7963 | struct i40e_pf *pf = veb->pf; |
| 7964 | int v, veb_idx; |
| 7965 | int ret; |
| 7966 | |
| 7967 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7968 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7969 | if (pf->vsi[v] && |
| 7970 | pf->vsi[v]->veb_idx == veb->idx && |
| 7971 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 7972 | ctl_vsi = pf->vsi[v]; |
| 7973 | break; |
| 7974 | } |
| 7975 | } |
| 7976 | if (!ctl_vsi) { |
| 7977 | dev_info(&pf->pdev->dev, |
| 7978 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 7979 | ret = -ENOENT; |
| 7980 | goto end_reconstitute; |
| 7981 | } |
| 7982 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 7983 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 7984 | ret = i40e_add_vsi(ctl_vsi); |
| 7985 | if (ret) { |
| 7986 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7987 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 7988 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7989 | goto end_reconstitute; |
| 7990 | } |
| 7991 | i40e_vsi_reset_stats(ctl_vsi); |
| 7992 | |
| 7993 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 7994 | ret = i40e_add_veb(veb, ctl_vsi); |
| 7995 | if (ret) |
| 7996 | goto end_reconstitute; |
| 7997 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 7998 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 7999 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 8000 | else |
| 8001 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8002 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 8003 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8004 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8005 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8006 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 8007 | continue; |
| 8008 | |
| 8009 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 8010 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 8011 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8012 | vsi->uplink_seid = veb->seid; |
| 8013 | ret = i40e_add_vsi(vsi); |
| 8014 | if (ret) { |
| 8015 | dev_info(&pf->pdev->dev, |
| 8016 | "rebuild of vsi_idx %d failed: %d\n", |
| 8017 | v, ret); |
| 8018 | goto end_reconstitute; |
| 8019 | } |
| 8020 | i40e_vsi_reset_stats(vsi); |
| 8021 | } |
| 8022 | } |
| 8023 | |
| 8024 | /* create any VEBs attached to this VEB - RECURSION */ |
| 8025 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 8026 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 8027 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 8028 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 8029 | if (ret) |
| 8030 | break; |
| 8031 | } |
| 8032 | } |
| 8033 | |
| 8034 | end_reconstitute: |
| 8035 | return ret; |
| 8036 | } |
| 8037 | |
| 8038 | /** |
| 8039 | * i40e_get_capabilities - get info about the HW |
| 8040 | * @pf: the PF struct |
| 8041 | **/ |
| 8042 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 8043 | { |
| 8044 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 8045 | u16 data_size; |
| 8046 | int buf_len; |
| 8047 | int err; |
| 8048 | |
| 8049 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 8050 | do { |
| 8051 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 8052 | if (!cap_buf) |
| 8053 | return -ENOMEM; |
| 8054 | |
| 8055 | /* this loads the data into the hw struct for us */ |
| 8056 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 8057 | &data_size, |
| 8058 | i40e_aqc_opc_list_func_capabilities, |
| 8059 | NULL); |
| 8060 | /* data loaded, buffer no longer needed */ |
| 8061 | kfree(cap_buf); |
| 8062 | |
| 8063 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 8064 | /* retry with a larger buffer */ |
| 8065 | buf_len = data_size; |
| 8066 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 8067 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8068 | "capability discovery failed, err %s aq_err %s\n", |
| 8069 | i40e_stat_str(&pf->hw, err), |
| 8070 | i40e_aq_str(&pf->hw, |
| 8071 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8072 | return -ENODEV; |
| 8073 | } |
| 8074 | } while (err); |
| 8075 | |
| 8076 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 8077 | dev_info(&pf->pdev->dev, |
| 8078 | "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", |
| 8079 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 8080 | pf->hw.func_caps.num_msix_vectors, |
| 8081 | pf->hw.func_caps.num_msix_vectors_vf, |
| 8082 | pf->hw.func_caps.fd_filters_guaranteed, |
| 8083 | pf->hw.func_caps.fd_filters_best_effort, |
| 8084 | pf->hw.func_caps.num_tx_qp, |
| 8085 | pf->hw.func_caps.num_vsis); |
| 8086 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8087 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 8088 | + pf->hw.func_caps.num_vfs) |
| 8089 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 8090 | dev_info(&pf->pdev->dev, |
| 8091 | "got num_vsis %d, setting num_vsis to %d\n", |
| 8092 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 8093 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 8094 | } |
| 8095 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8096 | return 0; |
| 8097 | } |
| 8098 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8099 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 8100 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8101 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8102 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8103 | * @pf: board private structure |
| 8104 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8105 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8106 | { |
| 8107 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8108 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 8109 | /* quick workaround for an NVM issue that leaves a critical register |
| 8110 | * uninitialized |
| 8111 | */ |
| 8112 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 8113 | static const u32 hkey[] = { |
| 8114 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 8115 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 8116 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 8117 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 8118 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 8119 | |
| 8120 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 8121 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 8122 | } |
| 8123 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8124 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8125 | return; |
| 8126 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8127 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 8128 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8129 | |
| 8130 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8131 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8132 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 8133 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8134 | if (!vsi) { |
| 8135 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 8136 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 8137 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8138 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8139 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 8140 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8141 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8142 | } |
| 8143 | |
| 8144 | /** |
| 8145 | * i40e_fdir_teardown - release the Flow Director resources |
| 8146 | * @pf: board private structure |
| 8147 | **/ |
| 8148 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 8149 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 8150 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8151 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 8152 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 8153 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 8154 | if (vsi) |
| 8155 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8156 | } |
| 8157 | |
| 8158 | /** |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 8159 | * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset |
| 8160 | * @vsi: PF main vsi |
| 8161 | * |
| 8162 | * Rebuilds channel VSIs if they existed before reset |
| 8163 | **/ |
| 8164 | static int i40e_rebuild_channels(struct i40e_vsi *vsi) |
| 8165 | { |
| 8166 | struct i40e_channel *ch, *ch_tmp; |
| 8167 | i40e_status ret; |
| 8168 | |
| 8169 | if (list_empty(&vsi->ch_list)) |
| 8170 | return 0; |
| 8171 | |
| 8172 | list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) { |
| 8173 | if (!ch->initialized) |
| 8174 | break; |
| 8175 | /* Proceed with creation of channel (VMDq2) VSI */ |
| 8176 | ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch); |
| 8177 | if (ret) { |
| 8178 | dev_info(&vsi->back->pdev->dev, |
| 8179 | "failed to rebuild channels using uplink_seid %u\n", |
| 8180 | vsi->uplink_seid); |
| 8181 | return ret; |
| 8182 | } |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8183 | if (ch->max_tx_rate) { |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8184 | u64 credits = ch->max_tx_rate; |
| 8185 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8186 | if (i40e_set_bw_limit(vsi, ch->seid, |
| 8187 | ch->max_tx_rate)) |
| 8188 | return -EINVAL; |
| 8189 | |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8190 | do_div(credits, I40E_BW_CREDIT_DIVISOR); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8191 | dev_dbg(&vsi->back->pdev->dev, |
| 8192 | "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", |
| 8193 | ch->max_tx_rate, |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8194 | credits, |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8195 | ch->seid); |
| 8196 | } |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 8197 | } |
| 8198 | return 0; |
| 8199 | } |
| 8200 | |
| 8201 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8202 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8203 | * @pf: board private structure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8204 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 8205 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8206 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8207 | * 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] | 8208 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8209 | 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] | 8210 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8211 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 8212 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8213 | u32 v; |
| 8214 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8215 | clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
| 8216 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 8217 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 8218 | if (i40e_check_asq_alive(&pf->hw)) |
| 8219 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8220 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 8221 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8222 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8223 | /* quiesce the VSIs and their queues that are not already DOWN */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8224 | /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */ |
| 8225 | if (!lock_acquired) |
| 8226 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8227 | i40e_pf_quiesce_all_vsi(pf); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8228 | if (!lock_acquired) |
| 8229 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8230 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8231 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8232 | if (pf->vsi[v]) |
| 8233 | pf->vsi[v]->seid = 0; |
| 8234 | } |
| 8235 | |
| 8236 | i40e_shutdown_adminq(&pf->hw); |
| 8237 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8238 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 8239 | if (hw->hmc.hmc_obj) { |
| 8240 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 8241 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 8242 | dev_warn(&pf->pdev->dev, |
| 8243 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8244 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8245 | } |
| 8246 | |
| 8247 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 8248 | * i40e_send_version - update firmware with driver version |
| 8249 | * @pf: PF struct |
| 8250 | */ |
| 8251 | static void i40e_send_version(struct i40e_pf *pf) |
| 8252 | { |
| 8253 | struct i40e_driver_version dv; |
| 8254 | |
| 8255 | dv.major_version = DRV_VERSION_MAJOR; |
| 8256 | dv.minor_version = DRV_VERSION_MINOR; |
| 8257 | dv.build_version = DRV_VERSION_BUILD; |
| 8258 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 8259 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 8260 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 8261 | } |
| 8262 | |
| 8263 | /** |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 8264 | * i40e_get_oem_version - get OEM specific version information |
| 8265 | * @hw: pointer to the hardware structure |
| 8266 | **/ |
| 8267 | static void i40e_get_oem_version(struct i40e_hw *hw) |
| 8268 | { |
| 8269 | u16 block_offset = 0xffff; |
| 8270 | u16 block_length = 0; |
| 8271 | u16 capabilities = 0; |
| 8272 | u16 gen_snap = 0; |
| 8273 | u16 release = 0; |
| 8274 | |
| 8275 | #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B |
| 8276 | #define I40E_NVM_OEM_LENGTH_OFFSET 0x00 |
| 8277 | #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01 |
| 8278 | #define I40E_NVM_OEM_GEN_OFFSET 0x02 |
| 8279 | #define I40E_NVM_OEM_RELEASE_OFFSET 0x03 |
| 8280 | #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F |
| 8281 | #define I40E_NVM_OEM_LENGTH 3 |
| 8282 | |
| 8283 | /* Check if pointer to OEM version block is valid. */ |
| 8284 | i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset); |
| 8285 | if (block_offset == 0xffff) |
| 8286 | return; |
| 8287 | |
| 8288 | /* Check if OEM version block has correct length. */ |
| 8289 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET, |
| 8290 | &block_length); |
| 8291 | if (block_length < I40E_NVM_OEM_LENGTH) |
| 8292 | return; |
| 8293 | |
| 8294 | /* Check if OEM version format is as expected. */ |
| 8295 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET, |
| 8296 | &capabilities); |
| 8297 | if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0) |
| 8298 | return; |
| 8299 | |
| 8300 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET, |
| 8301 | &gen_snap); |
| 8302 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET, |
| 8303 | &release); |
| 8304 | hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release; |
| 8305 | hw->nvm.eetrack = I40E_OEM_EETRACK_ID; |
| 8306 | } |
| 8307 | |
| 8308 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8309 | * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen |
| 8310 | * @pf: board private structure |
| 8311 | **/ |
| 8312 | static int i40e_reset(struct i40e_pf *pf) |
| 8313 | { |
| 8314 | struct i40e_hw *hw = &pf->hw; |
| 8315 | i40e_status ret; |
| 8316 | |
| 8317 | ret = i40e_pf_reset(hw); |
| 8318 | if (ret) { |
| 8319 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8320 | set_bit(__I40E_RESET_FAILED, pf->state); |
| 8321 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8322 | } else { |
| 8323 | pf->pfr_count++; |
| 8324 | } |
| 8325 | return ret; |
| 8326 | } |
| 8327 | |
| 8328 | /** |
| 8329 | * i40e_rebuild - rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8330 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8331 | * @reinit: if the Main VSI needs to re-initialized. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8332 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 8333 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8334 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8335 | 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] | 8336 | { |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8337 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8338 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 8339 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8340 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 8341 | u32 val; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8342 | int v; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8343 | |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 8344 | if (test_bit(__I40E_DOWN, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 8345 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 8346 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8347 | |
| 8348 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 8349 | ret = i40e_init_adminq(&pf->hw); |
| 8350 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8351 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 8352 | i40e_stat_str(&pf->hw, ret), |
| 8353 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 8354 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8355 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 8356 | i40e_get_oem_version(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8357 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 8358 | /* re-verify the eeprom if we just had an EMP reset */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8359 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 8360 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 8361 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 8362 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8363 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8364 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8365 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8366 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8367 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 8368 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8369 | if (ret) { |
| 8370 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 8371 | goto end_core_reset; |
| 8372 | } |
| 8373 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 8374 | if (ret) { |
| 8375 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 8376 | goto end_core_reset; |
| 8377 | } |
| 8378 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 8379 | #ifdef CONFIG_I40E_DCB |
| 8380 | ret = i40e_init_pf_dcb(pf); |
| 8381 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 8382 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 8383 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 8384 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 8385 | } |
| 8386 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8387 | /* do basic switch setup */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8388 | if (!lock_acquired) |
| 8389 | rtnl_lock(); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8390 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8391 | if (ret) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8392 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8393 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 8394 | /* The driver only wants link up/down and module qualification |
| 8395 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 8396 | */ |
| 8397 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 8398 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 8399 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 8400 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 8401 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8402 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 8403 | i40e_stat_str(&pf->hw, ret), |
| 8404 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 8405 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 8406 | /* make sure our flow control settings are restored */ |
| 8407 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 8408 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 8409 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 8410 | i40e_stat_str(&pf->hw, ret), |
| 8411 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 8412 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8413 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 8414 | * They are still in our local switch element arrays, so only |
| 8415 | * need to rebuild the switch model in the HW. |
| 8416 | * |
| 8417 | * If there were VEBs but the reconstitution failed, we'll try |
| 8418 | * try to recover minimal use by getting the basic PF VSI working. |
| 8419 | */ |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8420 | if (vsi->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 8421 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8422 | /* find the one VEB connected to the MAC, and find orphans */ |
| 8423 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 8424 | if (!pf->veb[v]) |
| 8425 | continue; |
| 8426 | |
| 8427 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 8428 | pf->veb[v]->uplink_seid == 0) { |
| 8429 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 8430 | |
| 8431 | if (!ret) |
| 8432 | continue; |
| 8433 | |
| 8434 | /* If Main VEB failed, we're in deep doodoo, |
| 8435 | * so give up rebuilding the switch and set up |
| 8436 | * for minimal rebuild of PF VSI. |
| 8437 | * If orphan failed, we'll report the error |
| 8438 | * but try to keep going. |
| 8439 | */ |
| 8440 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 8441 | dev_info(&pf->pdev->dev, |
| 8442 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 8443 | ret); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8444 | vsi->uplink_seid = pf->mac_seid; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8445 | break; |
| 8446 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 8447 | dev_info(&pf->pdev->dev, |
| 8448 | "rebuild of orphan VEB failed: %d\n", |
| 8449 | ret); |
| 8450 | } |
| 8451 | } |
| 8452 | } |
| 8453 | } |
| 8454 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8455 | if (vsi->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 8456 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8457 | /* no VEB, so rebuild only the Main VSI */ |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8458 | ret = i40e_add_vsi(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8459 | if (ret) { |
| 8460 | dev_info(&pf->pdev->dev, |
| 8461 | "rebuild of Main VSI failed: %d\n", ret); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8462 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8463 | } |
| 8464 | } |
| 8465 | |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8466 | if (vsi->mqprio_qopt.max_rate[0]) { |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8467 | u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; |
| 8468 | u64 credits = 0; |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8469 | |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8470 | do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8471 | ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8472 | if (ret) |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8473 | goto end_unlock; |
Alan Brady | 6c32e0d | 2017-10-09 15:48:45 -0700 | [diff] [blame] | 8474 | |
| 8475 | credits = max_tx_rate; |
| 8476 | do_div(credits, I40E_BW_CREDIT_DIVISOR); |
| 8477 | dev_dbg(&vsi->back->pdev->dev, |
| 8478 | "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n", |
| 8479 | max_tx_rate, |
| 8480 | credits, |
| 8481 | vsi->seid); |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8482 | } |
| 8483 | |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 8484 | /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs |
| 8485 | * for this main VSI if they exist |
| 8486 | */ |
Amritha Nambiar | 2027d4d | 2017-09-07 04:00:32 -0700 | [diff] [blame] | 8487 | ret = i40e_rebuild_channels(vsi); |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 8488 | if (ret) |
| 8489 | goto end_unlock; |
| 8490 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 8491 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 8492 | * of TSO, so that we avoid the MDD being fired and causing |
| 8493 | * a reset in the case of small MSS+TSO. |
| 8494 | */ |
| 8495 | #define I40E_REG_MSS 0x000E64DC |
| 8496 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 8497 | #define I40E_64BYTE_MSS 0x400000 |
| 8498 | val = rd32(hw, I40E_REG_MSS); |
| 8499 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 8500 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 8501 | val |= I40E_64BYTE_MSS; |
| 8502 | wr32(hw, I40E_REG_MSS, val); |
| 8503 | } |
| 8504 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8505 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 8506 | msleep(75); |
| 8507 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 8508 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8509 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 8510 | i40e_stat_str(&pf->hw, ret), |
| 8511 | i40e_aq_str(&pf->hw, |
| 8512 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 8513 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8514 | /* reinit the misc interrupt */ |
| 8515 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 8516 | ret = i40e_setup_misc_vector(pf); |
| 8517 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 8518 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 8519 | * transmitted. By doing so we stop a malicious VF from sending out |
| 8520 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 8521 | * PF/VF VSIs. |
| 8522 | * The FW can still send Flow control frames if enabled. |
| 8523 | */ |
| 8524 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 8525 | pf->main_vsi_seid); |
| 8526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8527 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 8528 | i40e_pf_unquiesce_all_vsi(pf); |
| 8529 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 8530 | /* Release the RTNL lock before we start resetting VFs */ |
| 8531 | if (!lock_acquired) |
| 8532 | rtnl_unlock(); |
| 8533 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 8534 | i40e_reset_all_vfs(pf, true); |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 8535 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8536 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 8537 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8538 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 8539 | /* We've already released the lock, so don't do it again */ |
| 8540 | goto end_core_reset; |
| 8541 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8542 | end_unlock: |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 8543 | if (!lock_acquired) |
| 8544 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8545 | end_core_reset: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8546 | clear_bit(__I40E_RESET_FAILED, pf->state); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 8547 | clear_recovery: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8548 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8549 | } |
| 8550 | |
| 8551 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8552 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
| 8553 | * @pf: board private structure |
| 8554 | * @reinit: if the Main VSI needs to re-initialized. |
| 8555 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 8556 | * before this function was called. |
| 8557 | **/ |
| 8558 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit, |
| 8559 | bool lock_acquired) |
| 8560 | { |
| 8561 | int ret; |
| 8562 | /* Now we wait for GRST to settle out. |
| 8563 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 8564 | * because the reset will make them disappear. |
| 8565 | */ |
| 8566 | ret = i40e_reset(pf); |
| 8567 | if (!ret) |
| 8568 | i40e_rebuild(pf, reinit, lock_acquired); |
| 8569 | } |
| 8570 | |
| 8571 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8572 | * 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] | 8573 | * @pf: board private structure |
| 8574 | * |
| 8575 | * Close up the VFs and other things in prep for a Core Reset, |
| 8576 | * then get ready to rebuild the world. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8577 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 8578 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8579 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8580 | 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] | 8581 | { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8582 | i40e_prep_for_reset(pf, lock_acquired); |
| 8583 | i40e_reset_and_rebuild(pf, false, lock_acquired); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8587 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8588 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8589 | * |
| 8590 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 8591 | **/ |
| 8592 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 8593 | { |
| 8594 | struct i40e_hw *hw = &pf->hw; |
| 8595 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 8596 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8597 | struct i40e_vf *vf; |
| 8598 | u32 reg; |
| 8599 | int i; |
| 8600 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8601 | if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8602 | return; |
| 8603 | |
| 8604 | /* find what triggered the MDD event */ |
| 8605 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 8606 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 8607 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 8608 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 8609 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 8610 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 8611 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 8612 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 8613 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 8614 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 8615 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8616 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8617 | 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] | 8618 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8619 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 8620 | mdd_detected = true; |
| 8621 | } |
| 8622 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 8623 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 8624 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 8625 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 8626 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 8627 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 8628 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 8629 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 8630 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8631 | if (netif_msg_rx_err(pf)) |
| 8632 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 8633 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8634 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 8635 | mdd_detected = true; |
| 8636 | } |
| 8637 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 8638 | if (mdd_detected) { |
| 8639 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 8640 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 8641 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8642 | 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] | 8643 | pf_mdd_detected = true; |
| 8644 | } |
| 8645 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 8646 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 8647 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8648 | 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] | 8649 | pf_mdd_detected = true; |
| 8650 | } |
| 8651 | /* Queue belongs to the PF, initiate a reset */ |
| 8652 | if (pf_mdd_detected) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8653 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 8654 | i40e_service_event_schedule(pf); |
| 8655 | } |
| 8656 | } |
| 8657 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8658 | /* see if one of the VFs needs its hand slapped */ |
| 8659 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 8660 | vf = &(pf->vf[i]); |
| 8661 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 8662 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 8663 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 8664 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8665 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 8666 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8667 | } |
| 8668 | |
| 8669 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 8670 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 8671 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 8672 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 8673 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 8674 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8675 | } |
| 8676 | |
| 8677 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 8678 | dev_info(&pf->pdev->dev, |
| 8679 | "Too many MDD events on VF %d, disabled\n", i); |
| 8680 | dev_info(&pf->pdev->dev, |
| 8681 | "Use PF Control I/F to re-enable the VF\n"); |
Jacob Keller | 6322e63 | 2017-04-13 04:45:54 -0400 | [diff] [blame] | 8682 | set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8683 | } |
| 8684 | } |
| 8685 | |
| 8686 | /* re-enable mdd interrupt cause */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8687 | clear_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8688 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 8689 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 8690 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 8691 | i40e_flush(hw); |
| 8692 | } |
| 8693 | |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 8694 | static const char *i40e_tunnel_name(struct i40e_udp_port_config *port) |
| 8695 | { |
| 8696 | switch (port->type) { |
| 8697 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8698 | return "vxlan"; |
| 8699 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8700 | return "geneve"; |
| 8701 | default: |
| 8702 | return "unknown"; |
| 8703 | } |
| 8704 | } |
| 8705 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8706 | /** |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 8707 | * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters |
| 8708 | * @pf: board private structure |
| 8709 | **/ |
| 8710 | static void i40e_sync_udp_filters(struct i40e_pf *pf) |
| 8711 | { |
| 8712 | int i; |
| 8713 | |
| 8714 | /* loop through and set pending bit for all active UDP filters */ |
| 8715 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 8716 | if (pf->udp_ports[i].port) |
| 8717 | pf->pending_udp_bitmap |= BIT_ULL(i); |
| 8718 | } |
| 8719 | |
| 8720 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8721 | } |
| 8722 | |
| 8723 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8724 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8725 | * @pf: board private structure |
| 8726 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8727 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8728 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8729 | struct i40e_hw *hw = &pf->hw; |
| 8730 | i40e_status ret; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8731 | u16 port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8732 | int i; |
| 8733 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8734 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8735 | return; |
| 8736 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8737 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8738 | |
| 8739 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8740 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 8741 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 8742 | port = pf->udp_ports[i].port; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8743 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 8744 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 8745 | pf->udp_ports[i].type, |
| 8746 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8747 | else |
| 8748 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8749 | |
| 8750 | if (ret) { |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 8751 | dev_info(&pf->pdev->dev, |
| 8752 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 8753 | i40e_tunnel_name(&pf->udp_ports[i]), |
| 8754 | port ? "add" : "delete", |
| 8755 | port, i, |
| 8756 | i40e_stat_str(&pf->hw, ret), |
| 8757 | i40e_aq_str(&pf->hw, |
| 8758 | pf->hw.aq.asq_last_status)); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 8759 | pf->udp_ports[i].port = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8760 | } |
| 8761 | } |
| 8762 | } |
| 8763 | } |
| 8764 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8765 | /** |
| 8766 | * i40e_service_task - Run the driver's async subtasks |
| 8767 | * @work: pointer to work_struct containing our data |
| 8768 | **/ |
| 8769 | static void i40e_service_task(struct work_struct *work) |
| 8770 | { |
| 8771 | struct i40e_pf *pf = container_of(work, |
| 8772 | struct i40e_pf, |
| 8773 | service_task); |
| 8774 | unsigned long start_time = jiffies; |
| 8775 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 8776 | /* don't bother with service tasks if a reset is in progress */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8777 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 8778 | return; |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 8779 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8780 | if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state)) |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 8781 | return; |
| 8782 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 8783 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 8784 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8785 | i40e_reset_subtask(pf); |
| 8786 | i40e_handle_mdd_event(pf); |
| 8787 | i40e_vc_process_vflr_event(pf); |
| 8788 | i40e_watchdog_subtask(pf); |
| 8789 | i40e_fdir_reinit_subtask(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 8790 | if (pf->flags & I40E_FLAG_CLIENT_RESET) { |
| 8791 | /* Client subtask will reopen next time through. */ |
| 8792 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true); |
| 8793 | pf->flags &= ~I40E_FLAG_CLIENT_RESET; |
| 8794 | } else { |
| 8795 | i40e_client_subtask(pf); |
| 8796 | if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) { |
| 8797 | i40e_notify_client_of_l2_param_changes( |
| 8798 | pf->vsi[pf->lan_vsi]); |
| 8799 | pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE; |
| 8800 | } |
| 8801 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8802 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8803 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8804 | i40e_clean_adminq_subtask(pf); |
| 8805 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 8806 | /* flush memory to make sure state is correct before next watchdog */ |
| 8807 | smp_mb__before_atomic(); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8808 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8809 | |
| 8810 | /* If the tasks have taken longer than one timer cycle or there |
| 8811 | * is more work to be done, reschedule the service task now |
| 8812 | * rather than wait for the timer to tick again. |
| 8813 | */ |
| 8814 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8815 | test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) || |
| 8816 | test_bit(__I40E_MDD_EVENT_PENDING, pf->state) || |
| 8817 | test_bit(__I40E_VFLR_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8818 | i40e_service_event_schedule(pf); |
| 8819 | } |
| 8820 | |
| 8821 | /** |
| 8822 | * i40e_service_timer - timer callback |
| 8823 | * @data: pointer to PF struct |
| 8824 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 8825 | static void i40e_service_timer(struct timer_list *t) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8826 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 8827 | struct i40e_pf *pf = from_timer(pf, t, service_timer); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8828 | |
| 8829 | mod_timer(&pf->service_timer, |
| 8830 | round_jiffies(jiffies + pf->service_timer_period)); |
| 8831 | i40e_service_event_schedule(pf); |
| 8832 | } |
| 8833 | |
| 8834 | /** |
| 8835 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 8836 | * @vsi: the VSI being configured |
| 8837 | **/ |
| 8838 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 8839 | { |
| 8840 | struct i40e_pf *pf = vsi->back; |
| 8841 | |
| 8842 | switch (vsi->type) { |
| 8843 | case I40E_VSI_MAIN: |
| 8844 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 8845 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 8846 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 8847 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 8848 | vsi->num_q_vectors = pf->num_lan_msix; |
| 8849 | else |
| 8850 | vsi->num_q_vectors = 1; |
| 8851 | |
| 8852 | break; |
| 8853 | |
| 8854 | case I40E_VSI_FDIR: |
| 8855 | vsi->alloc_queue_pairs = 1; |
| 8856 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 8857 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8858 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8859 | break; |
| 8860 | |
| 8861 | case I40E_VSI_VMDQ2: |
| 8862 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 8863 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 8864 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 8865 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 8866 | break; |
| 8867 | |
| 8868 | case I40E_VSI_SRIOV: |
| 8869 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 8870 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 8871 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 8872 | break; |
| 8873 | |
| 8874 | default: |
| 8875 | WARN_ON(1); |
| 8876 | return -ENODATA; |
| 8877 | } |
| 8878 | |
| 8879 | return 0; |
| 8880 | } |
| 8881 | |
| 8882 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8883 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
Rami Rosen | 3d7d7a8 | 2017-09-16 05:49:48 +0300 | [diff] [blame] | 8884 | * @vsi: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8885 | * @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] | 8886 | * |
| 8887 | * On error: returns error code (negative) |
| 8888 | * On success: returns 0 |
| 8889 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8890 | 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] | 8891 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 8892 | struct i40e_ring **next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8893 | int size; |
| 8894 | int ret = 0; |
| 8895 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 8896 | /* allocate memory for both Tx, XDP Tx and Rx ring pointers */ |
| 8897 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * |
| 8898 | (i40e_enabled_xdp_vsi(vsi) ? 3 : 2); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8899 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 8900 | if (!vsi->tx_rings) |
| 8901 | return -ENOMEM; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 8902 | next_rings = vsi->tx_rings + vsi->alloc_queue_pairs; |
| 8903 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 8904 | vsi->xdp_rings = next_rings; |
| 8905 | next_rings += vsi->alloc_queue_pairs; |
| 8906 | } |
| 8907 | vsi->rx_rings = next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8908 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8909 | if (alloc_qvectors) { |
| 8910 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 8911 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8912 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 8913 | if (!vsi->q_vectors) { |
| 8914 | ret = -ENOMEM; |
| 8915 | goto err_vectors; |
| 8916 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8917 | } |
| 8918 | return ret; |
| 8919 | |
| 8920 | err_vectors: |
| 8921 | kfree(vsi->tx_rings); |
| 8922 | return ret; |
| 8923 | } |
| 8924 | |
| 8925 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8926 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 8927 | * @pf: board private structure |
| 8928 | * @type: type of VSI |
| 8929 | * |
| 8930 | * On error: returns error code (negative) |
| 8931 | * On success: returns vsi index in PF (positive) |
| 8932 | **/ |
| 8933 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 8934 | { |
| 8935 | int ret = -ENODEV; |
| 8936 | struct i40e_vsi *vsi; |
| 8937 | int vsi_idx; |
| 8938 | int i; |
| 8939 | |
| 8940 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 8941 | mutex_lock(&pf->switch_mutex); |
| 8942 | |
| 8943 | /* VSI list may be fragmented if VSI creation/destruction has |
| 8944 | * been happening. We can afford to do a quick scan to look |
| 8945 | * for any free VSIs in the list. |
| 8946 | * |
| 8947 | * find next empty vsi slot, looping back around if necessary |
| 8948 | */ |
| 8949 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8950 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8951 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8952 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8953 | i = 0; |
| 8954 | while (i < pf->next_vsi && pf->vsi[i]) |
| 8955 | i++; |
| 8956 | } |
| 8957 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8958 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8959 | vsi_idx = i; /* Found one! */ |
| 8960 | } else { |
| 8961 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8962 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8963 | } |
| 8964 | pf->next_vsi = ++i; |
| 8965 | |
| 8966 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 8967 | if (!vsi) { |
| 8968 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8969 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8970 | } |
| 8971 | vsi->type = type; |
| 8972 | vsi->back = pf; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 8973 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8974 | vsi->flags = 0; |
| 8975 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 8976 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8977 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 8978 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8979 | vsi->netdev_registered = false; |
| 8980 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 8981 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 8982 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8983 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 8984 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 8985 | if (ret) |
| 8986 | goto err_rings; |
| 8987 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8988 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 8989 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 8990 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8991 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8992 | /* Setup default MSIX irq handler for VSI */ |
| 8993 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 8994 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 8995 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 8996 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8997 | pf->vsi[vsi_idx] = vsi; |
| 8998 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8999 | goto unlock_pf; |
| 9000 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9001 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9002 | pf->next_vsi = i - 1; |
| 9003 | kfree(vsi); |
| 9004 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9005 | mutex_unlock(&pf->switch_mutex); |
| 9006 | return ret; |
| 9007 | } |
| 9008 | |
| 9009 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 9010 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 9011 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9012 | * @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] | 9013 | * |
| 9014 | * On error: returns error code (negative) |
| 9015 | * On success: returns 0 |
| 9016 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9017 | 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] | 9018 | { |
| 9019 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9020 | if (free_qvectors) { |
| 9021 | kfree(vsi->q_vectors); |
| 9022 | vsi->q_vectors = NULL; |
| 9023 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 9024 | kfree(vsi->tx_rings); |
| 9025 | vsi->tx_rings = NULL; |
| 9026 | vsi->rx_rings = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9027 | vsi->xdp_rings = NULL; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 9028 | } |
| 9029 | |
| 9030 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9031 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 9032 | * and lookup table |
| 9033 | * @vsi: Pointer to VSI structure |
| 9034 | */ |
| 9035 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 9036 | { |
| 9037 | if (!vsi) |
| 9038 | return; |
| 9039 | |
| 9040 | kfree(vsi->rss_hkey_user); |
| 9041 | vsi->rss_hkey_user = NULL; |
| 9042 | |
| 9043 | kfree(vsi->rss_lut_user); |
| 9044 | vsi->rss_lut_user = NULL; |
| 9045 | } |
| 9046 | |
| 9047 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9048 | * i40e_vsi_clear - Deallocate the VSI provided |
| 9049 | * @vsi: the VSI being un-configured |
| 9050 | **/ |
| 9051 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 9052 | { |
| 9053 | struct i40e_pf *pf; |
| 9054 | |
| 9055 | if (!vsi) |
| 9056 | return 0; |
| 9057 | |
| 9058 | if (!vsi->back) |
| 9059 | goto free_vsi; |
| 9060 | pf = vsi->back; |
| 9061 | |
| 9062 | mutex_lock(&pf->switch_mutex); |
| 9063 | if (!pf->vsi[vsi->idx]) { |
| 9064 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 9065 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 9066 | goto unlock_vsi; |
| 9067 | } |
| 9068 | |
| 9069 | if (pf->vsi[vsi->idx] != vsi) { |
| 9070 | dev_err(&pf->pdev->dev, |
| 9071 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 9072 | pf->vsi[vsi->idx]->idx, |
| 9073 | pf->vsi[vsi->idx], |
| 9074 | pf->vsi[vsi->idx]->type, |
| 9075 | vsi->idx, vsi, vsi->type); |
| 9076 | goto unlock_vsi; |
| 9077 | } |
| 9078 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 9079 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9080 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9081 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 9082 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9083 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9084 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9085 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9086 | pf->vsi[vsi->idx] = NULL; |
| 9087 | if (vsi->idx < pf->next_vsi) |
| 9088 | pf->next_vsi = vsi->idx; |
| 9089 | |
| 9090 | unlock_vsi: |
| 9091 | mutex_unlock(&pf->switch_mutex); |
| 9092 | free_vsi: |
| 9093 | kfree(vsi); |
| 9094 | |
| 9095 | return 0; |
| 9096 | } |
| 9097 | |
| 9098 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9099 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 9100 | * @vsi: the VSI being cleaned |
| 9101 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 9102 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9103 | { |
| 9104 | int i; |
| 9105 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 9106 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 9107 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 9108 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 9109 | vsi->tx_rings[i] = NULL; |
| 9110 | vsi->rx_rings[i] = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9111 | if (vsi->xdp_rings) |
| 9112 | vsi->xdp_rings[i] = NULL; |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 9113 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 9114 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9115 | } |
| 9116 | |
| 9117 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9118 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 9119 | * @vsi: the VSI being configured |
| 9120 | **/ |
| 9121 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 9122 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9123 | int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9124 | struct i40e_pf *pf = vsi->back; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9125 | struct i40e_ring *ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9126 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9127 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 9128 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 9129 | /* allocate space for both Tx and Rx in one shot */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9130 | ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL); |
| 9131 | if (!ring) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9132 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9133 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9134 | ring->queue_index = i; |
| 9135 | ring->reg_idx = vsi->base_queue + i; |
| 9136 | ring->ring_active = false; |
| 9137 | ring->vsi = vsi; |
| 9138 | ring->netdev = vsi->netdev; |
| 9139 | ring->dev = &pf->pdev->dev; |
| 9140 | ring->count = vsi->num_desc; |
| 9141 | ring->size = 0; |
| 9142 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9143 | 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] | 9144 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 9145 | ring->tx_itr_setting = pf->tx_itr_default; |
| 9146 | vsi->tx_rings[i] = ring++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9147 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 9148 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 9149 | goto setup_rx; |
| 9150 | |
| 9151 | ring->queue_index = vsi->alloc_queue_pairs + i; |
| 9152 | ring->reg_idx = vsi->base_queue + ring->queue_index; |
| 9153 | ring->ring_active = false; |
| 9154 | ring->vsi = vsi; |
| 9155 | ring->netdev = NULL; |
| 9156 | ring->dev = &pf->pdev->dev; |
| 9157 | ring->count = vsi->num_desc; |
| 9158 | ring->size = 0; |
| 9159 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9160 | 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] | 9161 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 9162 | set_ring_xdp(ring); |
| 9163 | ring->tx_itr_setting = pf->tx_itr_default; |
| 9164 | vsi->xdp_rings[i] = ring++; |
| 9165 | |
| 9166 | setup_rx: |
| 9167 | ring->queue_index = i; |
| 9168 | ring->reg_idx = vsi->base_queue + i; |
| 9169 | ring->ring_active = false; |
| 9170 | ring->vsi = vsi; |
| 9171 | ring->netdev = vsi->netdev; |
| 9172 | ring->dev = &pf->pdev->dev; |
| 9173 | ring->count = vsi->num_desc; |
| 9174 | ring->size = 0; |
| 9175 | ring->dcb_tc = 0; |
| 9176 | ring->rx_itr_setting = pf->rx_itr_default; |
| 9177 | vsi->rx_rings[i] = ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9178 | } |
| 9179 | |
| 9180 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 9181 | |
| 9182 | err_out: |
| 9183 | i40e_vsi_clear_rings(vsi); |
| 9184 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9185 | } |
| 9186 | |
| 9187 | /** |
| 9188 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 9189 | * @pf: board private structure |
| 9190 | * @vectors: the number of MSI-X vectors to request |
| 9191 | * |
| 9192 | * Returns the number of vectors reserved, or error |
| 9193 | **/ |
| 9194 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 9195 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 9196 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 9197 | I40E_MIN_MSIX, vectors); |
| 9198 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9199 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 9200 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9201 | vectors = 0; |
| 9202 | } |
| 9203 | |
| 9204 | return vectors; |
| 9205 | } |
| 9206 | |
| 9207 | /** |
| 9208 | * i40e_init_msix - Setup the MSIX capability |
| 9209 | * @pf: board private structure |
| 9210 | * |
| 9211 | * Work with the OS to set up the MSIX vectors needed. |
| 9212 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9213 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9214 | **/ |
| 9215 | static int i40e_init_msix(struct i40e_pf *pf) |
| 9216 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9217 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 9218 | int cpus, extra_vectors; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9219 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9220 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9221 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9222 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9223 | |
| 9224 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9225 | return -ENODEV; |
| 9226 | |
| 9227 | /* The number of vectors we'll request will be comprised of: |
| 9228 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 9229 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9230 | * - Queues being used for RSS. |
| 9231 | * We don't need as many as max_rss_size vectors. |
| 9232 | * use rss_size instead in the calculation since that |
| 9233 | * is governed by number of cpus in the system. |
| 9234 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9235 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9236 | * - The CPU count within the NUMA node if iWARP is enabled |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9237 | * Once we count this up, try the request. |
| 9238 | * |
| 9239 | * If we can't get what we want, we'll simplify to nearly nothing |
| 9240 | * and try again. If that still fails, we punt. |
| 9241 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9242 | vectors_left = hw->func_caps.num_msix_vectors; |
| 9243 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9244 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9245 | /* reserve one vector for miscellaneous handler */ |
| 9246 | if (vectors_left) { |
| 9247 | v_budget++; |
| 9248 | vectors_left--; |
| 9249 | } |
| 9250 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 9251 | /* reserve some vectors for the main PF traffic queues. Initially we |
| 9252 | * only reserve at most 50% of the available vectors, in the case that |
| 9253 | * the number of online CPUs is large. This ensures that we can enable |
| 9254 | * extra features as well. Once we've enabled the other features, we |
| 9255 | * will use any remaining vectors to reach as close as we can to the |
| 9256 | * number of online CPUs. |
| 9257 | */ |
| 9258 | cpus = num_online_cpus(); |
| 9259 | pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9260 | vectors_left -= pf->num_lan_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9261 | |
| 9262 | /* reserve one vector for sideband flow director */ |
| 9263 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9264 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 9265 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9266 | v_budget++; |
| 9267 | vectors_left--; |
| 9268 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 9269 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9270 | } |
| 9271 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 9272 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9273 | /* can we reserve enough for iWARP? */ |
| 9274 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 9275 | iwarp_requested = pf->num_iwarp_msix; |
| 9276 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9277 | if (!vectors_left) |
| 9278 | pf->num_iwarp_msix = 0; |
| 9279 | else if (vectors_left < pf->num_iwarp_msix) |
| 9280 | pf->num_iwarp_msix = 1; |
| 9281 | v_budget += pf->num_iwarp_msix; |
| 9282 | vectors_left -= pf->num_iwarp_msix; |
| 9283 | } |
| 9284 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9285 | /* any vectors left over go for VMDq support */ |
| 9286 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 9287 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 9288 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 9289 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 9290 | if (!vectors_left) { |
| 9291 | pf->num_vmdq_msix = 0; |
| 9292 | pf->num_vmdq_qps = 0; |
| 9293 | } else { |
| 9294 | /* if we're short on vectors for what's desired, we limit |
| 9295 | * the queues per vmdq. If this is still more than are |
| 9296 | * available, the user will need to change the number of |
| 9297 | * queues/vectors used by the PF later with the ethtool |
| 9298 | * channels command |
| 9299 | */ |
| 9300 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 9301 | pf->num_vmdq_qps = 1; |
| 9302 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9303 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 9304 | v_budget += vmdq_vecs; |
| 9305 | vectors_left -= vmdq_vecs; |
| 9306 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9307 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9308 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 9309 | /* On systems with a large number of SMP cores, we previously limited |
| 9310 | * the number of vectors for num_lan_msix to be at most 50% of the |
| 9311 | * available vectors, to allow for other features. Now, we add back |
| 9312 | * the remaining vectors. However, we ensure that the total |
| 9313 | * num_lan_msix will not exceed num_online_cpus(). To do this, we |
| 9314 | * calculate the number of vectors we can add without going over the |
| 9315 | * cap of CPUs. For systems with a small number of CPUs this will be |
| 9316 | * zero. |
| 9317 | */ |
| 9318 | extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left); |
| 9319 | pf->num_lan_msix += extra_vectors; |
| 9320 | vectors_left -= extra_vectors; |
| 9321 | |
| 9322 | WARN(vectors_left < 0, |
| 9323 | "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n"); |
| 9324 | |
| 9325 | v_budget += pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9326 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 9327 | GFP_KERNEL); |
| 9328 | if (!pf->msix_entries) |
| 9329 | return -ENOMEM; |
| 9330 | |
| 9331 | for (i = 0; i < v_budget; i++) |
| 9332 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9333 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 9334 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9335 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9336 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 9337 | kfree(pf->msix_entries); |
| 9338 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 9339 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9340 | return -ENODEV; |
| 9341 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9342 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9343 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9344 | pf->num_vmdq_vsis = 0; |
| 9345 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9346 | pf->num_lan_qps = 1; |
| 9347 | pf->num_lan_msix = 1; |
| 9348 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 9349 | } else if (!vectors_left) { |
| 9350 | /* If we have limited resources, we will start with no vectors |
| 9351 | * for the special features and then allocate vectors to some |
| 9352 | * of these features based on the policy and at the end disable |
| 9353 | * the features that did not get any vectors. |
| 9354 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9355 | int vec; |
| 9356 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 9357 | dev_info(&pf->pdev->dev, |
| 9358 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 9359 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9360 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 9361 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9362 | /* Scale vector usage down */ |
| 9363 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 9364 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 9365 | pf->num_vmdq_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9366 | |
| 9367 | /* partition out the remaining vectors */ |
| 9368 | switch (vec) { |
| 9369 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9370 | pf->num_lan_msix = 1; |
| 9371 | break; |
| 9372 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9373 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9374 | pf->num_lan_msix = 1; |
| 9375 | pf->num_iwarp_msix = 1; |
| 9376 | } else { |
| 9377 | pf->num_lan_msix = 2; |
| 9378 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9379 | break; |
| 9380 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9381 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9382 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 9383 | iwarp_requested); |
| 9384 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 9385 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 9386 | } else { |
| 9387 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 9388 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 9389 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 9390 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9391 | pf->num_fdsb_msix = 1; |
| 9392 | vec--; |
| 9393 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9394 | pf->num_lan_msix = min_t(int, |
| 9395 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 9396 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 9397 | pf->num_lan_qps = pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9398 | break; |
| 9399 | } |
| 9400 | } |
| 9401 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 9402 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 9403 | (pf->num_fdsb_msix == 0)) { |
| 9404 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 9405 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 9406 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 9407 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 9408 | (pf->num_vmdq_msix == 0)) { |
| 9409 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 9410 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 9411 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9412 | |
| 9413 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 9414 | (pf->num_iwarp_msix == 0)) { |
| 9415 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 9416 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 9417 | } |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 9418 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 9419 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 9420 | pf->num_lan_msix, |
| 9421 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 9422 | pf->num_fdsb_msix, |
| 9423 | pf->num_iwarp_msix); |
| 9424 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9425 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9426 | } |
| 9427 | |
| 9428 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9429 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9430 | * @vsi: the VSI being configured |
| 9431 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9432 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9433 | * |
| 9434 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 9435 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9436 | 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] | 9437 | { |
| 9438 | struct i40e_q_vector *q_vector; |
| 9439 | |
| 9440 | /* allocate q_vector */ |
| 9441 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 9442 | if (!q_vector) |
| 9443 | return -ENOMEM; |
| 9444 | |
| 9445 | q_vector->vsi = vsi; |
| 9446 | q_vector->v_idx = v_idx; |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 9447 | cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask); |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9448 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9449 | if (vsi->netdev) |
| 9450 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 9451 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9452 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 9453 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 9454 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 9455 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9456 | /* tie q_vector and vsi together */ |
| 9457 | vsi->q_vectors[v_idx] = q_vector; |
| 9458 | |
| 9459 | return 0; |
| 9460 | } |
| 9461 | |
| 9462 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9463 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | * @vsi: the VSI being configured |
| 9465 | * |
| 9466 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 9467 | * return -ENOMEM. |
| 9468 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9469 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9470 | { |
| 9471 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9472 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9473 | |
| 9474 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 9475 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 9476 | num_q_vectors = vsi->num_q_vectors; |
| 9477 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 9478 | num_q_vectors = 1; |
| 9479 | else |
| 9480 | return -EINVAL; |
| 9481 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9482 | current_cpu = cpumask_first(cpu_online_mask); |
| 9483 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9484 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9485 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9486 | if (err) |
| 9487 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 9488 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 9489 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 9490 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9491 | } |
| 9492 | |
| 9493 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9494 | |
| 9495 | err_out: |
| 9496 | while (v_idx--) |
| 9497 | i40e_free_q_vector(vsi, v_idx); |
| 9498 | |
| 9499 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9500 | } |
| 9501 | |
| 9502 | /** |
| 9503 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 9504 | * @pf: board private structure to initialize |
| 9505 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 9506 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9507 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9508 | int vectors = 0; |
| 9509 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9510 | |
| 9511 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9512 | vectors = i40e_init_msix(pf); |
| 9513 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9514 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9515 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9516 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9517 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 9518 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9519 | I40E_FLAG_SRIOV_ENABLED | |
| 9520 | I40E_FLAG_FD_SB_ENABLED | |
| 9521 | I40E_FLAG_FD_ATR_ENABLED | |
| 9522 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9523 | |
| 9524 | /* rework the queue expectations without MSIX */ |
| 9525 | i40e_determine_queue_usage(pf); |
| 9526 | } |
| 9527 | } |
| 9528 | |
| 9529 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 9530 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 9531 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9532 | vectors = pci_enable_msi(pf->pdev); |
| 9533 | if (vectors < 0) { |
| 9534 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 9535 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9536 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 9537 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9538 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9539 | } |
| 9540 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9541 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 9542 | 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] | 9543 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9544 | /* set up vector assignment tracking */ |
| 9545 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 9546 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 9547 | if (!pf->irq_pile) { |
| 9548 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 9549 | return -ENOMEM; |
| 9550 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9551 | pf->irq_pile->num_entries = vectors; |
| 9552 | pf->irq_pile->search_hint = 0; |
| 9553 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 9554 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 9555 | (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] | 9556 | |
| 9557 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9558 | } |
| 9559 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 9560 | /** |
| 9561 | * i40e_restore_interrupt_scheme - Restore the interrupt scheme |
| 9562 | * @pf: private board data structure |
| 9563 | * |
| 9564 | * Restore the interrupt scheme that was cleared when we suspended the |
| 9565 | * device. This should be called during resume to re-allocate the q_vectors |
| 9566 | * and reacquire IRQs. |
| 9567 | */ |
| 9568 | static int i40e_restore_interrupt_scheme(struct i40e_pf *pf) |
| 9569 | { |
| 9570 | int err, i; |
| 9571 | |
| 9572 | /* We cleared the MSI and MSI-X flags when disabling the old interrupt |
| 9573 | * scheme. We need to re-enabled them here in order to attempt to |
| 9574 | * re-acquire the MSI or MSI-X vectors |
| 9575 | */ |
| 9576 | pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 9577 | |
| 9578 | err = i40e_init_interrupt_scheme(pf); |
| 9579 | if (err) |
| 9580 | return err; |
| 9581 | |
| 9582 | /* Now that we've re-acquired IRQs, we need to remap the vectors and |
| 9583 | * rings together again. |
| 9584 | */ |
| 9585 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
| 9586 | if (pf->vsi[i]) { |
| 9587 | err = i40e_vsi_alloc_q_vectors(pf->vsi[i]); |
| 9588 | if (err) |
| 9589 | goto err_unwind; |
| 9590 | i40e_vsi_map_rings_to_vectors(pf->vsi[i]); |
| 9591 | } |
| 9592 | } |
| 9593 | |
| 9594 | err = i40e_setup_misc_vector(pf); |
| 9595 | if (err) |
| 9596 | goto err_unwind; |
| 9597 | |
| 9598 | return 0; |
| 9599 | |
| 9600 | err_unwind: |
| 9601 | while (i--) { |
| 9602 | if (pf->vsi[i]) |
| 9603 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 9604 | } |
| 9605 | |
| 9606 | return err; |
| 9607 | } |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 9608 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9609 | /** |
| 9610 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 9611 | * @pf: board private structure |
| 9612 | * |
| 9613 | * This sets up the handler for MSIX 0, which is used to manage the |
| 9614 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 9615 | * when in MSI or Legacy interrupt mode. |
| 9616 | **/ |
| 9617 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 9618 | { |
| 9619 | struct i40e_hw *hw = &pf->hw; |
| 9620 | int err = 0; |
| 9621 | |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 9622 | /* Only request the IRQ once, the first time through. */ |
| 9623 | if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9624 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 9625 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9626 | if (err) { |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 9627 | clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9628 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 9629 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 9630 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9631 | return -EFAULT; |
| 9632 | } |
| 9633 | } |
| 9634 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 9635 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9636 | |
| 9637 | /* associate no queues to the misc vector */ |
| 9638 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 9639 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 9640 | |
| 9641 | i40e_flush(hw); |
| 9642 | |
Jacob Keller | dbadbbe | 2017-09-07 08:05:49 -0400 | [diff] [blame] | 9643 | i40e_irq_dynamic_enable_icr0(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9644 | |
| 9645 | return err; |
| 9646 | } |
| 9647 | |
| 9648 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 9649 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 9650 | * @vsi: Pointer to vsi structure |
| 9651 | * @seed: Buffter to store the hash keys |
| 9652 | * @lut: Buffer to store the lookup table entries |
| 9653 | * @lut_size: Size of buffer to store the lookup table entries |
| 9654 | * |
| 9655 | * Return 0 on success, negative on failure |
| 9656 | */ |
| 9657 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 9658 | u8 *lut, u16 lut_size) |
| 9659 | { |
| 9660 | struct i40e_pf *pf = vsi->back; |
| 9661 | struct i40e_hw *hw = &pf->hw; |
| 9662 | int ret = 0; |
| 9663 | |
| 9664 | if (seed) { |
| 9665 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 9666 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 9667 | if (ret) { |
| 9668 | dev_info(&pf->pdev->dev, |
| 9669 | "Cannot get RSS key, err %s aq_err %s\n", |
| 9670 | i40e_stat_str(&pf->hw, ret), |
| 9671 | i40e_aq_str(&pf->hw, |
| 9672 | pf->hw.aq.asq_last_status)); |
| 9673 | return ret; |
| 9674 | } |
| 9675 | } |
| 9676 | |
| 9677 | if (lut) { |
| 9678 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 9679 | |
| 9680 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 9681 | if (ret) { |
| 9682 | dev_info(&pf->pdev->dev, |
| 9683 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 9684 | i40e_stat_str(&pf->hw, ret), |
| 9685 | i40e_aq_str(&pf->hw, |
| 9686 | pf->hw.aq.asq_last_status)); |
| 9687 | return ret; |
| 9688 | } |
| 9689 | } |
| 9690 | |
| 9691 | return ret; |
| 9692 | } |
| 9693 | |
| 9694 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9695 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9696 | * @vsi: Pointer to vsi structure |
| 9697 | * @seed: RSS hash seed |
| 9698 | * @lut: Lookup table |
| 9699 | * @lut_size: Lookup table size |
| 9700 | * |
| 9701 | * Returns 0 on success, negative on failure |
| 9702 | **/ |
| 9703 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 9704 | const u8 *lut, u16 lut_size) |
| 9705 | { |
| 9706 | struct i40e_pf *pf = vsi->back; |
| 9707 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9708 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9709 | u8 i; |
| 9710 | |
| 9711 | /* Fill out hash function seed */ |
| 9712 | if (seed) { |
| 9713 | u32 *seed_dw = (u32 *)seed; |
| 9714 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9715 | if (vsi->type == I40E_VSI_MAIN) { |
| 9716 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 9717 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9718 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 9719 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 9720 | wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9721 | } else { |
| 9722 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 9723 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9724 | } |
| 9725 | |
| 9726 | if (lut) { |
| 9727 | u32 *lut_dw = (u32 *)lut; |
| 9728 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9729 | if (vsi->type == I40E_VSI_MAIN) { |
| 9730 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 9731 | return -EINVAL; |
| 9732 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 9733 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 9734 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 9735 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 9736 | return -EINVAL; |
| 9737 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 9738 | wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 9739 | } else { |
| 9740 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 9741 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9742 | } |
| 9743 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9744 | |
| 9745 | return 0; |
| 9746 | } |
| 9747 | |
| 9748 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9749 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 9750 | * @vsi: Pointer to VSI structure |
| 9751 | * @seed: Buffer to store the keys |
| 9752 | * @lut: Buffer to store the lookup table entries |
| 9753 | * @lut_size: Size of buffer to store the lookup table entries |
| 9754 | * |
| 9755 | * Returns 0 on success, negative on failure |
| 9756 | */ |
| 9757 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 9758 | u8 *lut, u16 lut_size) |
| 9759 | { |
| 9760 | struct i40e_pf *pf = vsi->back; |
| 9761 | struct i40e_hw *hw = &pf->hw; |
| 9762 | u16 i; |
| 9763 | |
| 9764 | if (seed) { |
| 9765 | u32 *seed_dw = (u32 *)seed; |
| 9766 | |
| 9767 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 9768 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9769 | } |
| 9770 | if (lut) { |
| 9771 | u32 *lut_dw = (u32 *)lut; |
| 9772 | |
| 9773 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 9774 | return -EINVAL; |
| 9775 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 9776 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 9777 | } |
| 9778 | |
| 9779 | return 0; |
| 9780 | } |
| 9781 | |
| 9782 | /** |
| 9783 | * i40e_config_rss - Configure RSS keys and lut |
| 9784 | * @vsi: Pointer to VSI structure |
| 9785 | * @seed: RSS hash seed |
| 9786 | * @lut: Lookup table |
| 9787 | * @lut_size: Lookup table size |
| 9788 | * |
| 9789 | * Returns 0 on success, negative on failure |
| 9790 | */ |
| 9791 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 9792 | { |
| 9793 | struct i40e_pf *pf = vsi->back; |
| 9794 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9795 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9796 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 9797 | else |
| 9798 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 9799 | } |
| 9800 | |
| 9801 | /** |
| 9802 | * i40e_get_rss - Get RSS keys and lut |
| 9803 | * @vsi: Pointer to VSI structure |
| 9804 | * @seed: Buffer to store the keys |
| 9805 | * @lut: Buffer to store the lookup table entries |
| 9806 | * lut_size: Size of buffer to store the lookup table entries |
| 9807 | * |
| 9808 | * Returns 0 on success, negative on failure |
| 9809 | */ |
| 9810 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 9811 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 9812 | struct i40e_pf *pf = vsi->back; |
| 9813 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9814 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 9815 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 9816 | else |
| 9817 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9818 | } |
| 9819 | |
| 9820 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9821 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 9822 | * @pf: Pointer to board private structure |
| 9823 | * @lut: Lookup table |
| 9824 | * @rss_table_size: Lookup table size |
| 9825 | * @rss_size: Range of queue number for hashing |
| 9826 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 9827 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 9828 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9829 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9830 | u16 i; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9831 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9832 | for (i = 0; i < rss_table_size; i++) |
| 9833 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9837 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9838 | * @pf: board private structure |
| 9839 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9840 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9841 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 9842 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9843 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9844 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 9845 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 9846 | u32 reg_val; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9847 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9848 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9849 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9850 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 9851 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 9852 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9853 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 9854 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 9855 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 9856 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9857 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9858 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 9859 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9860 | reg_val = (pf->rss_table_size == 512) ? |
| 9861 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 9862 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 9863 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 9864 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9865 | /* Determine the RSS size of the VSI */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 9866 | if (!vsi->rss_size) { |
| 9867 | u16 qcount; |
| 9868 | |
| 9869 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 9870 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
| 9871 | } |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 9872 | if (!vsi->rss_size) |
| 9873 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9874 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9875 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 9876 | if (!lut) |
| 9877 | return -ENOMEM; |
| 9878 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9879 | /* Use user configured lut if there is one, otherwise use default */ |
| 9880 | if (vsi->rss_lut_user) |
| 9881 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 9882 | else |
| 9883 | 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] | 9884 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9885 | /* Use user configured hash key if there is one, otherwise |
| 9886 | * use default. |
| 9887 | */ |
| 9888 | if (vsi->rss_hkey_user) |
| 9889 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 9890 | else |
| 9891 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9892 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 9893 | kfree(lut); |
| 9894 | |
| 9895 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9896 | } |
| 9897 | |
| 9898 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9899 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 9900 | * @pf: board private structure |
| 9901 | * @queue_count: the requested queue count for rss. |
| 9902 | * |
| 9903 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 9904 | * count which may be different from the requested queue count. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9905 | * Note: expects to be called while under rtnl_lock() |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9906 | **/ |
| 9907 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 9908 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 9909 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 9910 | int new_rss_size; |
| 9911 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9912 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 9913 | return 0; |
| 9914 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 9915 | 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] | 9916 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 9917 | if (queue_count != vsi->num_queue_pairs) { |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 9918 | u16 qcount; |
| 9919 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 9920 | vsi->req_queue_pairs = queue_count; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9921 | i40e_prep_for_reset(pf, true); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9922 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 9923 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9924 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9925 | i40e_reset_and_rebuild(pf, true, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9926 | |
| 9927 | /* Discard the user configured hash keys and lut, if less |
| 9928 | * queues are enabled. |
| 9929 | */ |
| 9930 | if (queue_count < vsi->rss_size) { |
| 9931 | i40e_clear_rss_config_user(vsi); |
| 9932 | dev_dbg(&pf->pdev->dev, |
| 9933 | "discard user configured hash keys and lut\n"); |
| 9934 | } |
| 9935 | |
| 9936 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 9937 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 9938 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 9939 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 9940 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9941 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 9942 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 9943 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 9944 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9948 | * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9949 | * @pf: board private structure |
| 9950 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9951 | i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9952 | { |
| 9953 | i40e_status status; |
| 9954 | bool min_valid, max_valid; |
| 9955 | u32 max_bw, min_bw; |
| 9956 | |
| 9957 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 9958 | &min_valid, &max_valid); |
| 9959 | |
| 9960 | if (!status) { |
| 9961 | if (min_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9962 | pf->min_bw = min_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9963 | if (max_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9964 | pf->max_bw = max_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9965 | } |
| 9966 | |
| 9967 | return status; |
| 9968 | } |
| 9969 | |
| 9970 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9971 | * i40e_set_partition_bw_setting - Set BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9972 | * @pf: board private structure |
| 9973 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9974 | i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9975 | { |
| 9976 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 9977 | i40e_status status; |
| 9978 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 9979 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 9980 | 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] | 9981 | bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK; |
| 9982 | 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] | 9983 | |
| 9984 | /* Set the new bandwidths */ |
| 9985 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 9986 | |
| 9987 | return status; |
| 9988 | } |
| 9989 | |
| 9990 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9991 | * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9992 | * @pf: board private structure |
| 9993 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9994 | i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9995 | { |
| 9996 | /* Commit temporary BW setting to permanent NVM image */ |
| 9997 | enum i40e_admin_queue_err last_aq_status; |
| 9998 | i40e_status ret; |
| 9999 | u16 nvm_word; |
| 10000 | |
| 10001 | if (pf->hw.partition_id != 1) { |
| 10002 | dev_info(&pf->pdev->dev, |
| 10003 | "Commit BW only works on partition 1! This is partition %d", |
| 10004 | pf->hw.partition_id); |
| 10005 | ret = I40E_NOT_SUPPORTED; |
| 10006 | goto bw_commit_out; |
| 10007 | } |
| 10008 | |
| 10009 | /* Acquire NVM for read access */ |
| 10010 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 10011 | last_aq_status = pf->hw.aq.asq_last_status; |
| 10012 | if (ret) { |
| 10013 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10014 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 10015 | i40e_stat_str(&pf->hw, ret), |
| 10016 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10017 | goto bw_commit_out; |
| 10018 | } |
| 10019 | |
| 10020 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 10021 | ret = i40e_aq_read_nvm(&pf->hw, |
| 10022 | I40E_SR_NVM_CONTROL_WORD, |
| 10023 | 0x10, sizeof(nvm_word), &nvm_word, |
| 10024 | false, NULL); |
| 10025 | /* Save off last admin queue command status before releasing |
| 10026 | * the NVM |
| 10027 | */ |
| 10028 | last_aq_status = pf->hw.aq.asq_last_status; |
| 10029 | i40e_release_nvm(&pf->hw); |
| 10030 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10031 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 10032 | i40e_stat_str(&pf->hw, ret), |
| 10033 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10034 | goto bw_commit_out; |
| 10035 | } |
| 10036 | |
| 10037 | /* Wait a bit for NVM release to complete */ |
| 10038 | msleep(50); |
| 10039 | |
| 10040 | /* Acquire NVM for write access */ |
| 10041 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 10042 | last_aq_status = pf->hw.aq.asq_last_status; |
| 10043 | if (ret) { |
| 10044 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10045 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 10046 | i40e_stat_str(&pf->hw, ret), |
| 10047 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10048 | goto bw_commit_out; |
| 10049 | } |
| 10050 | /* Write it back out unchanged to initiate update NVM, |
| 10051 | * which will force a write of the shadow (alt) RAM to |
| 10052 | * the NVM - thus storing the bandwidth values permanently. |
| 10053 | */ |
| 10054 | ret = i40e_aq_update_nvm(&pf->hw, |
| 10055 | I40E_SR_NVM_CONTROL_WORD, |
| 10056 | 0x10, sizeof(nvm_word), |
| 10057 | &nvm_word, true, NULL); |
| 10058 | /* Save off last admin queue command status before releasing |
| 10059 | * the NVM |
| 10060 | */ |
| 10061 | last_aq_status = pf->hw.aq.asq_last_status; |
| 10062 | i40e_release_nvm(&pf->hw); |
| 10063 | if (ret) |
| 10064 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10065 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 10066 | i40e_stat_str(&pf->hw, ret), |
| 10067 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10068 | bw_commit_out: |
| 10069 | |
| 10070 | return ret; |
| 10071 | } |
| 10072 | |
| 10073 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10074 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 10075 | * @pf: board private structure to initialize |
| 10076 | * |
| 10077 | * i40e_sw_init initializes the Adapter private data structure. |
| 10078 | * Fields are initialized based on PCI device information and |
| 10079 | * OS network device settings (MTU size). |
| 10080 | **/ |
| 10081 | static int i40e_sw_init(struct i40e_pf *pf) |
| 10082 | { |
| 10083 | int err = 0; |
| 10084 | int size; |
| 10085 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10086 | /* Set default capability flags */ |
| 10087 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 10088 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 10089 | I40E_FLAG_MSIX_ENABLED; |
| 10090 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 10091 | /* Set default ITR */ |
Jacob Keller | 4270255 | 2017-09-07 08:05:48 -0400 | [diff] [blame] | 10092 | pf->rx_itr_default = I40E_ITR_RX_DEF; |
| 10093 | pf->tx_itr_default = I40E_ITR_TX_DEF; |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 10094 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10095 | /* Depending on PF configurations, it is possible that the RSS |
| 10096 | * maximum might end up larger than the available queues |
| 10097 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 10098 | 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] | 10099 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 10100 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10101 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 10102 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10103 | if (pf->hw.func_caps.rss) { |
| 10104 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10105 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 10106 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10107 | } |
| 10108 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 10109 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 10110 | 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] | 10111 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 10112 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 10113 | if (i40e_get_partition_bw_setting(pf)) { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10114 | dev_warn(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 10115 | "Could not get partition bw settings\n"); |
| 10116 | } else { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 10117 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 10118 | "Partition BW Min = %8.8x, Max = %8.8x\n", |
| 10119 | pf->min_bw, pf->max_bw); |
| 10120 | |
| 10121 | /* nudge the Tx scheduler */ |
| 10122 | i40e_set_partition_bw_setting(pf); |
| 10123 | } |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 10124 | } |
| 10125 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10126 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 10127 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 10128 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 10129 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 10130 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 10131 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10132 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 10133 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 10134 | else |
| 10135 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10136 | pf->fdir_pf_filter_count = |
| 10137 | pf->hw.func_caps.fd_filters_guaranteed; |
| 10138 | pf->hw.fdir_shared_filter_count = |
| 10139 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10140 | } |
| 10141 | |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 10142 | if (pf->hw.mac.type == I40E_MAC_X722) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10143 | pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE | |
| 10144 | I40E_HW_128_QP_RSS_CAPABLE | |
| 10145 | I40E_HW_ATR_EVICT_CAPABLE | |
| 10146 | I40E_HW_WB_ON_ITR_CAPABLE | |
| 10147 | I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
| 10148 | I40E_HW_NO_PCI_LINK_CHECK | |
| 10149 | I40E_HW_USE_SET_LLDP_MIB | |
| 10150 | I40E_HW_GENEVE_OFFLOAD_CAPABLE | |
| 10151 | I40E_HW_PTP_L4_CAPABLE | |
| 10152 | I40E_HW_WOL_MC_MAGIC_PKT_WAKE | |
| 10153 | I40E_HW_OUTER_UDP_CSUM_CAPABLE); |
Anjali Singhai Jain | 10a955f | 2017-06-23 04:24:48 -0400 | [diff] [blame] | 10154 | |
| 10155 | #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03 |
| 10156 | if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) != |
| 10157 | I40E_FDEVICT_PCTYPE_DEFAULT) { |
| 10158 | dev_warn(&pf->pdev->dev, |
| 10159 | "FD EVICT PCTYPES are not right, disable FD HW EVICT\n"); |
| 10160 | pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE; |
| 10161 | } |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 10162 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 10163 | ((pf->hw.aq.api_maj_ver == 1) && |
| 10164 | (pf->hw.aq.api_min_ver > 4))) { |
| 10165 | /* Supported in FW API version higher than 1.4 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10166 | pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 10167 | } |
| 10168 | |
| 10169 | /* Enable HW ATR eviction if possible */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10170 | if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE) |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 10171 | pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED; |
| 10172 | |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 10173 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10174 | (((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] | 10175 | (pf->hw.aq.fw_maj_ver < 4))) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10176 | pf->hw_features |= I40E_HW_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10177 | /* No DCB support for FW < v4.33 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10178 | pf->hw_features |= I40E_HW_NO_DCB_SUPPORT; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10179 | } |
| 10180 | |
| 10181 | /* Disable FW LLDP if FW < v4.3 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 10182 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10183 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 10184 | (pf->hw.aq.fw_maj_ver < 4))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10185 | pf->hw_features |= I40E_HW_STOP_FW_LLDP; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10186 | |
| 10187 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 10188 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10189 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 10190 | (pf->hw.aq.fw_maj_ver >= 5))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10191 | pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10192 | |
Alan Brady | c3d26b7 | 2017-08-29 05:32:32 -0400 | [diff] [blame] | 10193 | /* Enable PTP L4 if FW > v6.0 */ |
| 10194 | if (pf->hw.mac.type == I40E_MAC_XL710 && |
| 10195 | pf->hw.aq.fw_maj_ver >= 6) |
| 10196 | pf->hw_features |= I40E_HW_PTP_L4_CAPABLE; |
| 10197 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10198 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10199 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10200 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 10201 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10202 | } |
| 10203 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10204 | if (pf->hw.func_caps.iwarp) { |
| 10205 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 10206 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 10207 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 10208 | } |
| 10209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10210 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 10211 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10212 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 10213 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 10214 | pf->num_req_vfs = min_t(int, |
| 10215 | pf->hw.func_caps.num_vfs, |
| 10216 | I40E_MAX_VF_COUNT); |
| 10217 | } |
| 10218 | #endif /* CONFIG_PCI_IOV */ |
| 10219 | pf->eeprom_version = 0xDEAD; |
| 10220 | pf->lan_veb = I40E_NO_VEB; |
| 10221 | pf->lan_vsi = I40E_NO_VSI; |
| 10222 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 10223 | /* By default FW has this off for performance reasons */ |
| 10224 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 10225 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10226 | /* set up queue assignment tracking */ |
| 10227 | size = sizeof(struct i40e_lump_tracking) |
| 10228 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 10229 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 10230 | if (!pf->qp_pile) { |
| 10231 | err = -ENOMEM; |
| 10232 | goto sw_init_done; |
| 10233 | } |
| 10234 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 10235 | pf->qp_pile->search_hint = 0; |
| 10236 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 10237 | pf->tx_timeout_recovery_level = 1; |
| 10238 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10239 | mutex_init(&pf->switch_mutex); |
| 10240 | |
| 10241 | sw_init_done: |
| 10242 | return err; |
| 10243 | } |
| 10244 | |
| 10245 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10246 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 10247 | * @pf: board private structure to initialize |
| 10248 | * @features: the feature set that the stack is suggesting |
| 10249 | * |
| 10250 | * returns a bool to indicate if reset needs to happen |
| 10251 | **/ |
| 10252 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 10253 | { |
| 10254 | bool need_reset = false; |
| 10255 | |
| 10256 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 10257 | * the state changed, we need to reset. |
| 10258 | */ |
| 10259 | if (features & NETIF_F_NTUPLE) { |
| 10260 | /* Enable filters and mark for reset */ |
| 10261 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 10262 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 10263 | /* enable FD_SB only if there is MSI-X vector */ |
| 10264 | if (pf->num_fdsb_msix > 0) |
| 10265 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10266 | } else { |
| 10267 | /* turn off filters, mark for reset and clear SW filter list */ |
| 10268 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10269 | need_reset = true; |
| 10270 | i40e_fdir_filter_exit(pf); |
| 10271 | } |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 10272 | pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED | |
| 10273 | I40E_FLAG_FD_SB_AUTO_DISABLED); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 10274 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 10275 | pf->fd_add_err = 0; |
| 10276 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 10277 | /* if ATR was auto disabled it can be re-enabled. */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 10278 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 10279 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 10280 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 10281 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 10282 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 10283 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10284 | } |
| 10285 | return need_reset; |
| 10286 | } |
| 10287 | |
| 10288 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 10289 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 10290 | * @vsi: the VSI being configured |
| 10291 | **/ |
| 10292 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 10293 | { |
| 10294 | struct i40e_pf *pf = vsi->back; |
| 10295 | struct i40e_hw *hw = &pf->hw; |
| 10296 | u16 vf_id = vsi->vf_id; |
| 10297 | u8 i; |
| 10298 | |
| 10299 | if (vsi->type == I40E_VSI_MAIN) { |
| 10300 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 10301 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 10302 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 10303 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 10304 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 10305 | } else { |
| 10306 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 10307 | } |
| 10308 | } |
| 10309 | |
| 10310 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10311 | * i40e_set_features - set the netdev feature flags |
| 10312 | * @netdev: ptr to the netdev being adjusted |
| 10313 | * @features: the feature set that the stack is suggesting |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 10314 | * Note: expects to be called while under rtnl_lock() |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10315 | **/ |
| 10316 | static int i40e_set_features(struct net_device *netdev, |
| 10317 | netdev_features_t features) |
| 10318 | { |
| 10319 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 10320 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10321 | struct i40e_pf *pf = vsi->back; |
| 10322 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10323 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 10324 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 10325 | i40e_pf_config_rss(pf); |
| 10326 | else if (!(features & NETIF_F_RXHASH) && |
| 10327 | netdev->features & NETIF_F_RXHASH) |
| 10328 | i40e_clear_rss_lut(vsi); |
| 10329 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10330 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 10331 | i40e_vlan_stripping_enable(vsi); |
| 10332 | else |
| 10333 | i40e_vlan_stripping_disable(vsi); |
| 10334 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10335 | need_reset = i40e_set_ntuple(pf, features); |
| 10336 | |
| 10337 | if (need_reset) |
Amritha Nambiar | ff42418 | 2017-09-07 04:00:11 -0700 | [diff] [blame] | 10338 | i40e_do_reset(pf, I40E_PF_RESET_FLAG, true); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 10339 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10340 | return 0; |
| 10341 | } |
| 10342 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10343 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10344 | * 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] | 10345 | * @pf: board private structure |
| 10346 | * @port: The UDP port to look up |
| 10347 | * |
| 10348 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 10349 | **/ |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 10350 | 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] | 10351 | { |
| 10352 | u8 i; |
| 10353 | |
| 10354 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 10355 | if (pf->udp_ports[i].port == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10356 | return i; |
| 10357 | } |
| 10358 | |
| 10359 | return i; |
| 10360 | } |
| 10361 | |
| 10362 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10363 | * 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] | 10364 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10365 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10366 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10367 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 10368 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10369 | { |
| 10370 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 10371 | struct i40e_vsi *vsi = np->vsi; |
| 10372 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 10373 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10374 | u8 next_idx; |
| 10375 | u8 idx; |
| 10376 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10377 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10378 | |
| 10379 | /* Check if port already exists */ |
| 10380 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 10381 | netdev_info(netdev, "port %d already offloaded\n", port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10382 | return; |
| 10383 | } |
| 10384 | |
| 10385 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10386 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10387 | |
| 10388 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10389 | 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] | 10390 | port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10391 | return; |
| 10392 | } |
| 10393 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10394 | switch (ti->type) { |
| 10395 | case UDP_TUNNEL_TYPE_VXLAN: |
| 10396 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 10397 | break; |
| 10398 | case UDP_TUNNEL_TYPE_GENEVE: |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10399 | if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE)) |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10400 | return; |
| 10401 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 10402 | break; |
| 10403 | default: |
| 10404 | return; |
| 10405 | } |
| 10406 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10407 | /* New port: add it and mark its index in the bitmap */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 10408 | pf->udp_ports[next_idx].port = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10409 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 10410 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10411 | } |
| 10412 | |
| 10413 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10414 | * 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] | 10415 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10416 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10417 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10418 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 10419 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10420 | { |
| 10421 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 10422 | struct i40e_vsi *vsi = np->vsi; |
| 10423 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 10424 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10425 | u8 idx; |
| 10426 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10427 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10428 | |
| 10429 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10430 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 10431 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 10432 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10433 | switch (ti->type) { |
| 10434 | case UDP_TUNNEL_TYPE_VXLAN: |
| 10435 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 10436 | goto not_found; |
| 10437 | break; |
| 10438 | case UDP_TUNNEL_TYPE_GENEVE: |
| 10439 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 10440 | goto not_found; |
| 10441 | break; |
| 10442 | default: |
| 10443 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10444 | } |
| 10445 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10446 | /* if port exists, set it to 0 (mark for deletion) |
| 10447 | * and make it pending |
| 10448 | */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 10449 | pf->udp_ports[idx].port = 0; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10450 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10451 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 10452 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10453 | return; |
| 10454 | not_found: |
| 10455 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 10456 | port); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10457 | } |
| 10458 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10459 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 10460 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10461 | { |
| 10462 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 10463 | struct i40e_pf *pf = np->vsi->back; |
| 10464 | struct i40e_hw *hw = &pf->hw; |
| 10465 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10466 | if (!(pf->hw_features & I40E_HW_PORT_ID_VALID)) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10467 | return -EOPNOTSUPP; |
| 10468 | |
| 10469 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 10470 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 10471 | |
| 10472 | return 0; |
| 10473 | } |
| 10474 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 10475 | /** |
| 10476 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 10477 | * @ndm: the input from the stack |
| 10478 | * @tb: pointer to array of nladdr (unused) |
| 10479 | * @dev: the net device pointer |
| 10480 | * @addr: the MAC address entry being added |
| 10481 | * @flags: instructions from stack about fdb operation |
| 10482 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 10483 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 10484 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 10485 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 10486 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 10487 | { |
| 10488 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 10489 | struct i40e_pf *pf = np->vsi->back; |
| 10490 | int err = 0; |
| 10491 | |
| 10492 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 10493 | return -EOPNOTSUPP; |
| 10494 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 10495 | if (vid) { |
| 10496 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 10497 | return -EINVAL; |
| 10498 | } |
| 10499 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 10500 | /* Hardware does not support aging addresses so if a |
| 10501 | * ndm_state is given only allow permanent addresses |
| 10502 | */ |
| 10503 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 10504 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 10505 | return -EINVAL; |
| 10506 | } |
| 10507 | |
| 10508 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 10509 | err = dev_uc_add_excl(dev, addr); |
| 10510 | else if (is_multicast_ether_addr(addr)) |
| 10511 | err = dev_mc_add_excl(dev, addr); |
| 10512 | else |
| 10513 | err = -EINVAL; |
| 10514 | |
| 10515 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 10516 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 10517 | err = 0; |
| 10518 | |
| 10519 | return err; |
| 10520 | } |
| 10521 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10522 | /** |
| 10523 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 10524 | * @dev: the netdev being configured |
| 10525 | * @nlh: RTNL message |
| 10526 | * |
| 10527 | * Inserts a new hardware bridge if not already created and |
| 10528 | * enables the bridging mode requested (VEB or VEPA). If the |
| 10529 | * hardware bridge has already been inserted and the request |
| 10530 | * is to change the mode then that requires a PF reset to |
| 10531 | * allow rebuild of the components with required hardware |
| 10532 | * bridge mode enabled. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 10533 | * |
| 10534 | * Note: expects to be called while under rtnl_lock() |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10535 | **/ |
| 10536 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 10537 | struct nlmsghdr *nlh, |
| 10538 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10539 | { |
| 10540 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 10541 | struct i40e_vsi *vsi = np->vsi; |
| 10542 | struct i40e_pf *pf = vsi->back; |
| 10543 | struct i40e_veb *veb = NULL; |
| 10544 | struct nlattr *attr, *br_spec; |
| 10545 | int i, rem; |
| 10546 | |
| 10547 | /* Only for PF VSI for now */ |
| 10548 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 10549 | return -EOPNOTSUPP; |
| 10550 | |
| 10551 | /* Find the HW bridge for PF VSI */ |
| 10552 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 10553 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 10554 | veb = pf->veb[i]; |
| 10555 | } |
| 10556 | |
| 10557 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 10558 | |
| 10559 | nla_for_each_nested(attr, br_spec, rem) { |
| 10560 | __u16 mode; |
| 10561 | |
| 10562 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 10563 | continue; |
| 10564 | |
| 10565 | mode = nla_get_u16(attr); |
| 10566 | if ((mode != BRIDGE_MODE_VEPA) && |
| 10567 | (mode != BRIDGE_MODE_VEB)) |
| 10568 | return -EINVAL; |
| 10569 | |
| 10570 | /* Insert a new HW bridge */ |
| 10571 | if (!veb) { |
| 10572 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 10573 | vsi->tc_config.enabled_tc); |
| 10574 | if (veb) { |
| 10575 | veb->bridge_mode = mode; |
| 10576 | i40e_config_bridge_mode(veb); |
| 10577 | } else { |
| 10578 | /* No Bridge HW offload available */ |
| 10579 | return -ENOENT; |
| 10580 | } |
| 10581 | break; |
| 10582 | } else if (mode != veb->bridge_mode) { |
| 10583 | /* Existing HW bridge but different mode needs reset */ |
| 10584 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 10585 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 10586 | if (mode == BRIDGE_MODE_VEB) |
| 10587 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10588 | else |
| 10589 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
Amritha Nambiar | ff42418 | 2017-09-07 04:00:11 -0700 | [diff] [blame] | 10590 | i40e_do_reset(pf, I40E_PF_RESET_FLAG, true); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10591 | break; |
| 10592 | } |
| 10593 | } |
| 10594 | |
| 10595 | return 0; |
| 10596 | } |
| 10597 | |
| 10598 | /** |
| 10599 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 10600 | * @skb: skb buff |
| 10601 | * @pid: process id |
| 10602 | * @seq: RTNL message seq # |
| 10603 | * @dev: the netdev being configured |
| 10604 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 10605 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10606 | * |
| 10607 | * Return the mode in which the hardware bridge is operating in |
| 10608 | * i.e VEB or VEPA. |
| 10609 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10610 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 10611 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 10612 | u32 __always_unused filter_mask, |
| 10613 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10614 | { |
| 10615 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 10616 | struct i40e_vsi *vsi = np->vsi; |
| 10617 | struct i40e_pf *pf = vsi->back; |
| 10618 | struct i40e_veb *veb = NULL; |
| 10619 | int i; |
| 10620 | |
| 10621 | /* Only for PF VSI for now */ |
| 10622 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 10623 | return -EOPNOTSUPP; |
| 10624 | |
| 10625 | /* Find the HW bridge for the PF VSI */ |
| 10626 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 10627 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 10628 | veb = pf->veb[i]; |
| 10629 | } |
| 10630 | |
| 10631 | if (!veb) |
| 10632 | return 0; |
| 10633 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 10634 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 10635 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10636 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10637 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 10638 | /** |
| 10639 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 10640 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 10641 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 10642 | * @features: Offload features that the stack believes apply |
| 10643 | **/ |
| 10644 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 10645 | struct net_device *dev, |
| 10646 | netdev_features_t features) |
| 10647 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 10648 | size_t len; |
| 10649 | |
| 10650 | /* No point in doing any of this if neither checksum nor GSO are |
| 10651 | * being requested for this frame. We can rule out both by just |
| 10652 | * checking for CHECKSUM_PARTIAL |
| 10653 | */ |
| 10654 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 10655 | return features; |
| 10656 | |
| 10657 | /* We cannot support GSO if the MSS is going to be less than |
| 10658 | * 64 bytes. If it is then we need to drop support for GSO. |
| 10659 | */ |
| 10660 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 10661 | features &= ~NETIF_F_GSO_MASK; |
| 10662 | |
| 10663 | /* MACLEN can support at most 63 words */ |
| 10664 | len = skb_network_header(skb) - skb->data; |
| 10665 | if (len & ~(63 * 2)) |
| 10666 | goto out_err; |
| 10667 | |
| 10668 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 10669 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 10670 | if (len & ~(127 * 4)) |
| 10671 | goto out_err; |
| 10672 | |
| 10673 | if (skb->encapsulation) { |
| 10674 | /* L4TUNLEN can support 127 words */ |
| 10675 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 10676 | if (len & ~(127 * 2)) |
| 10677 | goto out_err; |
| 10678 | |
| 10679 | /* IPLEN can support at most 127 dwords */ |
| 10680 | len = skb_inner_transport_header(skb) - |
| 10681 | skb_inner_network_header(skb); |
| 10682 | if (len & ~(127 * 4)) |
| 10683 | goto out_err; |
| 10684 | } |
| 10685 | |
| 10686 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 10687 | * a flexible value and we support all possible values supported |
| 10688 | * by TCP, which is at most 15 dwords |
| 10689 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 10690 | |
| 10691 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 10692 | out_err: |
| 10693 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 10694 | } |
| 10695 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 10696 | /** |
| 10697 | * i40e_xdp_setup - add/remove an XDP program |
| 10698 | * @vsi: VSI to changed |
| 10699 | * @prog: XDP program |
| 10700 | **/ |
| 10701 | static int i40e_xdp_setup(struct i40e_vsi *vsi, |
| 10702 | struct bpf_prog *prog) |
| 10703 | { |
| 10704 | int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 10705 | struct i40e_pf *pf = vsi->back; |
| 10706 | struct bpf_prog *old_prog; |
| 10707 | bool need_reset; |
| 10708 | int i; |
| 10709 | |
| 10710 | /* Don't allow frames that span over multiple buffers */ |
| 10711 | if (frame_size > vsi->rx_buf_len) |
| 10712 | return -EINVAL; |
| 10713 | |
| 10714 | if (!i40e_enabled_xdp_vsi(vsi) && !prog) |
| 10715 | return 0; |
| 10716 | |
| 10717 | /* When turning XDP on->off/off->on we reset and rebuild the rings. */ |
| 10718 | need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog); |
| 10719 | |
| 10720 | if (need_reset) |
| 10721 | i40e_prep_for_reset(pf, true); |
| 10722 | |
| 10723 | old_prog = xchg(&vsi->xdp_prog, prog); |
| 10724 | |
| 10725 | if (need_reset) |
| 10726 | i40e_reset_and_rebuild(pf, true, true); |
| 10727 | |
| 10728 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 10729 | WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); |
| 10730 | |
| 10731 | if (old_prog) |
| 10732 | bpf_prog_put(old_prog); |
| 10733 | |
| 10734 | return 0; |
| 10735 | } |
| 10736 | |
| 10737 | /** |
| 10738 | * i40e_xdp - implements ndo_xdp for i40e |
| 10739 | * @dev: netdevice |
| 10740 | * @xdp: XDP command |
| 10741 | **/ |
| 10742 | static int i40e_xdp(struct net_device *dev, |
| 10743 | struct netdev_xdp *xdp) |
| 10744 | { |
| 10745 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 10746 | struct i40e_vsi *vsi = np->vsi; |
| 10747 | |
| 10748 | if (vsi->type != I40E_VSI_MAIN) |
| 10749 | return -EINVAL; |
| 10750 | |
| 10751 | switch (xdp->command) { |
| 10752 | case XDP_SETUP_PROG: |
| 10753 | return i40e_xdp_setup(vsi, xdp->prog); |
| 10754 | case XDP_QUERY_PROG: |
| 10755 | xdp->prog_attached = i40e_enabled_xdp_vsi(vsi); |
Daniel Borkmann | eb23039 | 2017-06-24 21:13:52 +0200 | [diff] [blame] | 10756 | 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] | 10757 | return 0; |
| 10758 | default: |
| 10759 | return -EINVAL; |
| 10760 | } |
| 10761 | } |
| 10762 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 10763 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10764 | .ndo_open = i40e_open, |
| 10765 | .ndo_stop = i40e_close, |
| 10766 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 10767 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 10768 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 10769 | .ndo_validate_addr = eth_validate_addr, |
| 10770 | .ndo_set_mac_address = i40e_set_mac, |
| 10771 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10772 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10773 | .ndo_tx_timeout = i40e_tx_timeout, |
| 10774 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 10775 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 10776 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 10777 | .ndo_poll_controller = i40e_netpoll, |
| 10778 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 10779 | .ndo_setup_tc = __i40e_setup_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10780 | .ndo_set_features = i40e_set_features, |
| 10781 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 10782 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 10783 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10784 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 10785 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 10786 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 10787 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 10788 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 10789 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10790 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 10791 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 10792 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10793 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 10794 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 10795 | .ndo_xdp = i40e_xdp, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10796 | }; |
| 10797 | |
| 10798 | /** |
| 10799 | * i40e_config_netdev - Setup the netdev flags |
| 10800 | * @vsi: the VSI being configured |
| 10801 | * |
| 10802 | * Returns 0 on success, negative value on failure |
| 10803 | **/ |
| 10804 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 10805 | { |
| 10806 | struct i40e_pf *pf = vsi->back; |
| 10807 | struct i40e_hw *hw = &pf->hw; |
| 10808 | struct i40e_netdev_priv *np; |
| 10809 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 10810 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10811 | u8 mac_addr[ETH_ALEN]; |
| 10812 | int etherdev_size; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10813 | netdev_features_t hw_enc_features; |
| 10814 | netdev_features_t hw_features; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10815 | |
| 10816 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10817 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10818 | if (!netdev) |
| 10819 | return -ENOMEM; |
| 10820 | |
| 10821 | vsi->netdev = netdev; |
| 10822 | np = netdev_priv(netdev); |
| 10823 | np->vsi = vsi; |
| 10824 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10825 | hw_enc_features = NETIF_F_SG | |
| 10826 | NETIF_F_IP_CSUM | |
| 10827 | NETIF_F_IPV6_CSUM | |
| 10828 | NETIF_F_HIGHDMA | |
| 10829 | NETIF_F_SOFT_FEATURES | |
| 10830 | NETIF_F_TSO | |
| 10831 | NETIF_F_TSO_ECN | |
| 10832 | NETIF_F_TSO6 | |
| 10833 | NETIF_F_GSO_GRE | |
| 10834 | NETIF_F_GSO_GRE_CSUM | |
| 10835 | NETIF_F_GSO_PARTIAL | |
| 10836 | NETIF_F_GSO_UDP_TUNNEL | |
| 10837 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 10838 | NETIF_F_SCTP_CRC | |
| 10839 | NETIF_F_RXHASH | |
| 10840 | NETIF_F_RXCSUM | |
| 10841 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10842 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10843 | if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 10844 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 10845 | |
| 10846 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 10847 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10848 | netdev->hw_enc_features |= hw_enc_features; |
| 10849 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 10850 | /* record features VLANs can make use of */ |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10851 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10852 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 10853 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 10854 | netdev->hw_features |= NETIF_F_NTUPLE; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10855 | hw_features = hw_enc_features | |
| 10856 | NETIF_F_HW_VLAN_CTAG_TX | |
| 10857 | NETIF_F_HW_VLAN_CTAG_RX; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 10858 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10859 | netdev->hw_features |= hw_features; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 10860 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 10861 | netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 10862 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10863 | |
| 10864 | if (vsi->type == I40E_VSI_MAIN) { |
| 10865 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10866 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 10867 | /* The following steps are necessary for two reasons. First, |
| 10868 | * some older NVM configurations load a default MAC-VLAN |
| 10869 | * filter that will accept any tagged packet, and we want to |
| 10870 | * replace this with a normal filter. Additionally, it is |
| 10871 | * possible our MAC address was provided by the platform using |
| 10872 | * Open Firmware or similar. |
| 10873 | * |
| 10874 | * Thus, we need to remove the default filter and install one |
| 10875 | * specific to the MAC address. |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 10876 | */ |
| 10877 | i40e_rm_default_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10878 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 10879 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10880 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10881 | } else { |
Jacob Keller | 8c9eb35 | 2017-07-12 05:46:12 -0400 | [diff] [blame] | 10882 | /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we |
| 10883 | * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to |
| 10884 | * the end, which is 4 bytes long, so force truncation of the |
| 10885 | * original name by IFNAMSIZ - 4 |
| 10886 | */ |
| 10887 | snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d", |
| 10888 | IFNAMSIZ - 4, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10889 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 10890 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10891 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10892 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 10893 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10894 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10895 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10896 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 10897 | /* Add the broadcast filter so that we initially will receive |
| 10898 | * broadcast packets. Note that when a new VLAN is first added the |
| 10899 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 10900 | * specific filters as part of transitioning into "vlan" operation. |
| 10901 | * When more VLANs are added, the driver will copy each existing MAC |
| 10902 | * filter and add it for the new VLAN. |
| 10903 | * |
| 10904 | * Broadcast filters are handled specially by |
| 10905 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 10906 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 10907 | * filter. The subtask will update the correct broadcast promiscuous |
| 10908 | * bits as VLANs become active or inactive. |
| 10909 | */ |
| 10910 | eth_broadcast_addr(broadcast); |
| 10911 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 10912 | i40e_add_mac_filter(vsi, broadcast); |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 10913 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 10914 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10915 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 10916 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 10917 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10918 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 10919 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 10920 | /* Setup netdev TC information */ |
| 10921 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 10922 | |
| 10923 | netdev->netdev_ops = &i40e_netdev_ops; |
| 10924 | netdev->watchdog_timeo = 5 * HZ; |
| 10925 | i40e_set_ethtool_ops(netdev); |
| 10926 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 10927 | /* MTU range: 68 - 9706 */ |
| 10928 | netdev->min_mtu = ETH_MIN_MTU; |
Mitch Williams | 1e3a5fd | 2017-06-23 04:24:43 -0400 | [diff] [blame] | 10929 | netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD; |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 10930 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10931 | return 0; |
| 10932 | } |
| 10933 | |
| 10934 | /** |
| 10935 | * i40e_vsi_delete - Delete a VSI from the switch |
| 10936 | * @vsi: the VSI being removed |
| 10937 | * |
| 10938 | * Returns 0 on success, negative value on failure |
| 10939 | **/ |
| 10940 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 10941 | { |
| 10942 | /* remove default VSI is not allowed */ |
| 10943 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 10944 | return; |
| 10945 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10946 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10947 | } |
| 10948 | |
| 10949 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10950 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 10951 | * @vsi: the VSI being queried |
| 10952 | * |
| 10953 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 10954 | **/ |
| 10955 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 10956 | { |
| 10957 | struct i40e_veb *veb; |
| 10958 | struct i40e_pf *pf = vsi->back; |
| 10959 | |
| 10960 | /* Uplink is not a bridge so default to VEB */ |
| 10961 | if (vsi->veb_idx == I40E_NO_VEB) |
| 10962 | return 1; |
| 10963 | |
| 10964 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 10965 | if (!veb) { |
| 10966 | dev_info(&pf->pdev->dev, |
| 10967 | "There is no veb associated with the bridge\n"); |
| 10968 | return -ENOENT; |
| 10969 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10970 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 10971 | /* Uplink is a bridge in VEPA mode */ |
| 10972 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 10973 | return 0; |
| 10974 | } else { |
| 10975 | /* Uplink is a bridge in VEB mode */ |
| 10976 | return 1; |
| 10977 | } |
| 10978 | |
| 10979 | /* VEPA is now default bridge, so return 0 */ |
| 10980 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10981 | } |
| 10982 | |
| 10983 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10984 | * i40e_add_vsi - Add a VSI to the switch |
| 10985 | * @vsi: the VSI being configured |
| 10986 | * |
| 10987 | * This initializes a VSI context depending on the VSI type to be added and |
| 10988 | * passes it down to the add_vsi aq command. |
| 10989 | **/ |
| 10990 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 10991 | { |
| 10992 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10993 | struct i40e_pf *pf = vsi->back; |
| 10994 | struct i40e_hw *hw = &pf->hw; |
| 10995 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10996 | struct i40e_mac_filter *f; |
| 10997 | struct hlist_node *h; |
| 10998 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10999 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11000 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 11001 | int f_count = 0; |
| 11002 | |
| 11003 | memset(&ctxt, 0, sizeof(ctxt)); |
| 11004 | switch (vsi->type) { |
| 11005 | case I40E_VSI_MAIN: |
| 11006 | /* The PF's main VSI is already setup as part of the |
| 11007 | * device initialization, so we'll not bother with |
| 11008 | * the add_vsi call, but we will retrieve the current |
| 11009 | * VSI context. |
| 11010 | */ |
| 11011 | ctxt.seid = pf->main_vsi_seid; |
| 11012 | ctxt.pf_num = pf->hw.pf_id; |
| 11013 | ctxt.vf_num = 0; |
| 11014 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 11015 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 11016 | if (ret) { |
| 11017 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11018 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 11019 | i40e_stat_str(&pf->hw, ret), |
| 11020 | i40e_aq_str(&pf->hw, |
| 11021 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11022 | return -ENOENT; |
| 11023 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 11024 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11025 | vsi->info.valid_sections = 0; |
| 11026 | |
| 11027 | vsi->seid = ctxt.seid; |
| 11028 | vsi->id = ctxt.vsi_number; |
| 11029 | |
| 11030 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 11031 | |
Mitch Williams | 64615b5 | 2017-08-29 05:32:30 -0400 | [diff] [blame] | 11032 | /* Source pruning is enabled by default, so the flag is |
| 11033 | * negative logic - if it's set, we need to fiddle with |
| 11034 | * the VSI to disable source pruning. |
| 11035 | */ |
| 11036 | if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) { |
| 11037 | memset(&ctxt, 0, sizeof(ctxt)); |
| 11038 | ctxt.seid = pf->main_vsi_seid; |
| 11039 | ctxt.pf_num = pf->hw.pf_id; |
| 11040 | ctxt.vf_num = 0; |
| 11041 | ctxt.info.valid_sections |= |
| 11042 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 11043 | ctxt.info.switch_id = |
| 11044 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); |
| 11045 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 11046 | if (ret) { |
| 11047 | dev_info(&pf->pdev->dev, |
| 11048 | "update vsi failed, err %s aq_err %s\n", |
| 11049 | i40e_stat_str(&pf->hw, ret), |
| 11050 | i40e_aq_str(&pf->hw, |
| 11051 | pf->hw.aq.asq_last_status)); |
| 11052 | ret = -ENOENT; |
| 11053 | goto err; |
| 11054 | } |
| 11055 | } |
| 11056 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11057 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 11058 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 11059 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11060 | memset(&ctxt, 0, sizeof(ctxt)); |
| 11061 | ctxt.seid = pf->main_vsi_seid; |
| 11062 | ctxt.pf_num = pf->hw.pf_id; |
| 11063 | ctxt.vf_num = 0; |
| 11064 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 11065 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 11066 | if (ret) { |
| 11067 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11068 | "update vsi failed, err %s aq_err %s\n", |
| 11069 | i40e_stat_str(&pf->hw, ret), |
| 11070 | i40e_aq_str(&pf->hw, |
| 11071 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11072 | ret = -ENOENT; |
| 11073 | goto err; |
| 11074 | } |
| 11075 | /* update the local VSI info queue map */ |
| 11076 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 11077 | vsi->info.valid_sections = 0; |
| 11078 | } else { |
| 11079 | /* Default/Main VSI is only enabled for TC0 |
| 11080 | * reconfigure it to enable all TCs that are |
| 11081 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 11082 | * For MFP case the iSCSI PF would use this |
| 11083 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11084 | */ |
| 11085 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 11086 | if (ret) { |
Carolyn Wyborny | 1927923 | 2017-07-14 09:10:07 -0400 | [diff] [blame] | 11087 | /* Single TC condition is not fatal, |
| 11088 | * message and continue |
| 11089 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11090 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11091 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 11092 | enabled_tc, |
| 11093 | i40e_stat_str(&pf->hw, ret), |
| 11094 | i40e_aq_str(&pf->hw, |
| 11095 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11096 | } |
| 11097 | } |
| 11098 | break; |
| 11099 | |
| 11100 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11101 | ctxt.pf_num = hw->pf_id; |
| 11102 | ctxt.vf_num = 0; |
| 11103 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 11104 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11105 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 11106 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 11107 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11108 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 11109 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11110 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 11111 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11112 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11113 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11114 | break; |
| 11115 | |
| 11116 | case I40E_VSI_VMDQ2: |
| 11117 | ctxt.pf_num = hw->pf_id; |
| 11118 | ctxt.vf_num = 0; |
| 11119 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 11120 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11121 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 11122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11123 | /* This VSI is connected to VEB so the switch_id |
| 11124 | * should be set to zero by default. |
| 11125 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11126 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 11127 | ctxt.info.valid_sections |= |
| 11128 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 11129 | ctxt.info.switch_id = |
| 11130 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 11131 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11132 | |
| 11133 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 11134 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 11135 | break; |
| 11136 | |
| 11137 | case I40E_VSI_SRIOV: |
| 11138 | ctxt.pf_num = hw->pf_id; |
| 11139 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 11140 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 11141 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11142 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 11143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11144 | /* This VSI is connected to VEB so the switch_id |
| 11145 | * should be set to zero by default. |
| 11146 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11147 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 11148 | ctxt.info.valid_sections |= |
| 11149 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 11150 | ctxt.info.switch_id = |
| 11151 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 11152 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11153 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11154 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11155 | ctxt.info.valid_sections |= |
| 11156 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 11157 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 11158 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 11159 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11160 | } |
| 11161 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11162 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 11163 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 11164 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 11165 | ctxt.info.valid_sections |= |
| 11166 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 11167 | ctxt.info.sec_flags |= |
| 11168 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 11169 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 11170 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11171 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 11172 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 11173 | break; |
| 11174 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11175 | case I40E_VSI_IWARP: |
| 11176 | /* send down message to iWARP */ |
| 11177 | break; |
| 11178 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11179 | default: |
| 11180 | return -ENODEV; |
| 11181 | } |
| 11182 | |
| 11183 | if (vsi->type != I40E_VSI_MAIN) { |
| 11184 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 11185 | if (ret) { |
| 11186 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11187 | "add vsi failed, err %s aq_err %s\n", |
| 11188 | i40e_stat_str(&pf->hw, ret), |
| 11189 | i40e_aq_str(&pf->hw, |
| 11190 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11191 | ret = -ENOENT; |
| 11192 | goto err; |
| 11193 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 11194 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11195 | vsi->info.valid_sections = 0; |
| 11196 | vsi->seid = ctxt.seid; |
| 11197 | vsi->id = ctxt.vsi_number; |
| 11198 | } |
| 11199 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 11200 | vsi->active_filters = 0; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11201 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11202 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11203 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11204 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 11205 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11206 | f_count++; |
| 11207 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11208 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 11209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11210 | if (f_count) { |
| 11211 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 11212 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 11213 | } |
| 11214 | |
| 11215 | /* Update VSI BW information */ |
| 11216 | ret = i40e_vsi_get_bw_info(vsi); |
| 11217 | if (ret) { |
| 11218 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11219 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 11220 | i40e_stat_str(&pf->hw, ret), |
| 11221 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11222 | /* VSI is already added so not tearing that up */ |
| 11223 | ret = 0; |
| 11224 | } |
| 11225 | |
| 11226 | err: |
| 11227 | return ret; |
| 11228 | } |
| 11229 | |
| 11230 | /** |
| 11231 | * i40e_vsi_release - Delete a VSI and free its resources |
| 11232 | * @vsi: the VSI being removed |
| 11233 | * |
| 11234 | * Returns 0 on success or < 0 on error |
| 11235 | **/ |
| 11236 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 11237 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11238 | struct i40e_mac_filter *f; |
| 11239 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11240 | struct i40e_veb *veb = NULL; |
| 11241 | struct i40e_pf *pf; |
| 11242 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11243 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11244 | |
| 11245 | pf = vsi->back; |
| 11246 | |
| 11247 | /* release of a VEB-owner or last VSI is not allowed */ |
| 11248 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 11249 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 11250 | vsi->seid, vsi->uplink_seid); |
| 11251 | return -ENODEV; |
| 11252 | } |
| 11253 | if (vsi == pf->vsi[pf->lan_vsi] && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11254 | !test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11255 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 11256 | return -ENODEV; |
| 11257 | } |
| 11258 | |
| 11259 | uplink_seid = vsi->uplink_seid; |
| 11260 | if (vsi->type != I40E_VSI_SRIOV) { |
| 11261 | if (vsi->netdev_registered) { |
| 11262 | vsi->netdev_registered = false; |
| 11263 | if (vsi->netdev) { |
| 11264 | /* results in a call to i40e_close() */ |
| 11265 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11266 | } |
| 11267 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 11268 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11269 | } |
| 11270 | i40e_vsi_disable_irq(vsi); |
| 11271 | } |
| 11272 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11273 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 11274 | |
| 11275 | /* clear the sync flag on all filters */ |
| 11276 | if (vsi->netdev) { |
| 11277 | __dev_uc_unsync(vsi->netdev, NULL); |
| 11278 | __dev_mc_unsync(vsi->netdev, NULL); |
| 11279 | } |
| 11280 | |
| 11281 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11282 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 11283 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 11284 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 11285 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 11286 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 11287 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11288 | |
| 11289 | i40e_vsi_delete(vsi); |
| 11290 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 11291 | if (vsi->netdev) { |
| 11292 | free_netdev(vsi->netdev); |
| 11293 | vsi->netdev = NULL; |
| 11294 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11295 | i40e_vsi_clear_rings(vsi); |
| 11296 | i40e_vsi_clear(vsi); |
| 11297 | |
| 11298 | /* If this was the last thing on the VEB, except for the |
| 11299 | * controlling VSI, remove the VEB, which puts the controlling |
| 11300 | * VSI onto the next level down in the switch. |
| 11301 | * |
| 11302 | * Well, okay, there's one more exception here: don't remove |
| 11303 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 11304 | * from up the network stack. |
| 11305 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11306 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11307 | if (pf->vsi[i] && |
| 11308 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 11309 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 11310 | n++; /* count the VSIs */ |
| 11311 | } |
| 11312 | } |
| 11313 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11314 | if (!pf->veb[i]) |
| 11315 | continue; |
| 11316 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 11317 | n++; /* count the VEBs */ |
| 11318 | if (pf->veb[i]->seid == uplink_seid) |
| 11319 | veb = pf->veb[i]; |
| 11320 | } |
| 11321 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 11322 | i40e_veb_release(veb); |
| 11323 | |
| 11324 | return 0; |
| 11325 | } |
| 11326 | |
| 11327 | /** |
| 11328 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 11329 | * @vsi: ptr to the VSI |
| 11330 | * |
| 11331 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 11332 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 11333 | * newly allocated VSI. |
| 11334 | * |
| 11335 | * Returns 0 on success or negative on failure |
| 11336 | **/ |
| 11337 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 11338 | { |
| 11339 | int ret = -ENOENT; |
| 11340 | struct i40e_pf *pf = vsi->back; |
| 11341 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 11342 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11343 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 11344 | vsi->seid); |
| 11345 | return -EEXIST; |
| 11346 | } |
| 11347 | |
| 11348 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 11349 | 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] | 11350 | vsi->seid, vsi->base_vector); |
| 11351 | return -EEXIST; |
| 11352 | } |
| 11353 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 11354 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11355 | if (ret) { |
| 11356 | dev_info(&pf->pdev->dev, |
| 11357 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 11358 | vsi->num_q_vectors, vsi->seid, ret); |
| 11359 | vsi->num_q_vectors = 0; |
| 11360 | goto vector_setup_out; |
| 11361 | } |
| 11362 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 11363 | /* In Legacy mode, we do not have to get any other vector since we |
| 11364 | * piggyback on the misc/ICR0 for queue interrupts. |
| 11365 | */ |
| 11366 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 11367 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 11368 | if (vsi->num_q_vectors) |
| 11369 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11370 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11371 | if (vsi->base_vector < 0) { |
| 11372 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 11373 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 11374 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11375 | i40e_vsi_free_q_vectors(vsi); |
| 11376 | ret = -ENOENT; |
| 11377 | goto vector_setup_out; |
| 11378 | } |
| 11379 | |
| 11380 | vector_setup_out: |
| 11381 | return ret; |
| 11382 | } |
| 11383 | |
| 11384 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11385 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 11386 | * @vsi: pointer to the vsi. |
| 11387 | * |
| 11388 | * This re-allocates a vsi's queue resources. |
| 11389 | * |
| 11390 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 11391 | * on success, otherwise returns NULL on failure. |
| 11392 | **/ |
| 11393 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 11394 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 11395 | u16 alloc_queue_pairs; |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 11396 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11397 | u8 enabled_tc; |
| 11398 | int ret; |
| 11399 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 11400 | if (!vsi) |
| 11401 | return NULL; |
| 11402 | |
| 11403 | pf = vsi->back; |
| 11404 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11405 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 11406 | i40e_vsi_clear_rings(vsi); |
| 11407 | |
| 11408 | i40e_vsi_free_arrays(vsi, false); |
| 11409 | i40e_set_num_rings_in_vsi(vsi); |
| 11410 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 11411 | if (ret) |
| 11412 | goto err_vsi; |
| 11413 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 11414 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 11415 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 11416 | |
| 11417 | 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] | 11418 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 11419 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11420 | "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] | 11421 | alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11422 | goto err_vsi; |
| 11423 | } |
| 11424 | vsi->base_queue = ret; |
| 11425 | |
| 11426 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 11427 | * layout configurations. |
| 11428 | */ |
| 11429 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 11430 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 11431 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 11432 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 11433 | if (vsi->type == I40E_VSI_MAIN) |
| 11434 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11435 | |
| 11436 | /* assign it some queues */ |
| 11437 | ret = i40e_alloc_rings(vsi); |
| 11438 | if (ret) |
| 11439 | goto err_rings; |
| 11440 | |
| 11441 | /* map all of the rings to the q_vectors */ |
| 11442 | i40e_vsi_map_rings_to_vectors(vsi); |
| 11443 | return vsi; |
| 11444 | |
| 11445 | err_rings: |
| 11446 | i40e_vsi_free_q_vectors(vsi); |
| 11447 | if (vsi->netdev_registered) { |
| 11448 | vsi->netdev_registered = false; |
| 11449 | unregister_netdev(vsi->netdev); |
| 11450 | free_netdev(vsi->netdev); |
| 11451 | vsi->netdev = NULL; |
| 11452 | } |
| 11453 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 11454 | err_vsi: |
| 11455 | i40e_vsi_clear(vsi); |
| 11456 | return NULL; |
| 11457 | } |
| 11458 | |
| 11459 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11460 | * i40e_vsi_setup - Set up a VSI by a given type |
| 11461 | * @pf: board private structure |
| 11462 | * @type: VSI type |
| 11463 | * @uplink_seid: the switch element to link to |
| 11464 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 11465 | * |
| 11466 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 11467 | * to the identified VEB. |
| 11468 | * |
| 11469 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 11470 | * success, otherwise returns NULL on failure. |
| 11471 | **/ |
| 11472 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 11473 | u16 uplink_seid, u32 param1) |
| 11474 | { |
| 11475 | struct i40e_vsi *vsi = NULL; |
| 11476 | struct i40e_veb *veb = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 11477 | u16 alloc_queue_pairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11478 | int ret, i; |
| 11479 | int v_idx; |
| 11480 | |
| 11481 | /* The requested uplink_seid must be either |
| 11482 | * - the PF's port seid |
| 11483 | * no VEB is needed because this is the PF |
| 11484 | * or this is a Flow Director special case VSI |
| 11485 | * - seid of an existing VEB |
| 11486 | * - seid of a VSI that owns an existing VEB |
| 11487 | * - seid of a VSI that doesn't own a VEB |
| 11488 | * a new VEB is created and the VSI becomes the owner |
| 11489 | * - seid of the PF VSI, which is what creates the first VEB |
| 11490 | * this is a special case of the previous |
| 11491 | * |
| 11492 | * Find which uplink_seid we were given and create a new VEB if needed |
| 11493 | */ |
| 11494 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11495 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 11496 | veb = pf->veb[i]; |
| 11497 | break; |
| 11498 | } |
| 11499 | } |
| 11500 | |
| 11501 | if (!veb && uplink_seid != pf->mac_seid) { |
| 11502 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11503 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11504 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 11505 | vsi = pf->vsi[i]; |
| 11506 | break; |
| 11507 | } |
| 11508 | } |
| 11509 | if (!vsi) { |
| 11510 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 11511 | uplink_seid); |
| 11512 | return NULL; |
| 11513 | } |
| 11514 | |
| 11515 | if (vsi->uplink_seid == pf->mac_seid) |
| 11516 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 11517 | vsi->tc_config.enabled_tc); |
| 11518 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 11519 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 11520 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 11521 | if (veb) { |
| 11522 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 11523 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11524 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 11525 | return NULL; |
| 11526 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11527 | /* We come up by default in VEPA mode if SRIOV is not |
| 11528 | * already enabled, in which case we can't force VEPA |
| 11529 | * mode. |
| 11530 | */ |
| 11531 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 11532 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 11533 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 11534 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 11535 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 11536 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11537 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 11538 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 11539 | veb = pf->veb[i]; |
| 11540 | } |
| 11541 | if (!veb) { |
| 11542 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 11543 | return NULL; |
| 11544 | } |
| 11545 | |
| 11546 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 11547 | uplink_seid = veb->seid; |
| 11548 | } |
| 11549 | |
| 11550 | /* get vsi sw struct */ |
| 11551 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 11552 | if (v_idx < 0) |
| 11553 | goto err_alloc; |
| 11554 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11555 | if (!vsi) |
| 11556 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11557 | vsi->type = type; |
| 11558 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 11559 | |
| 11560 | if (type == I40E_VSI_MAIN) |
| 11561 | pf->lan_vsi = v_idx; |
| 11562 | else if (type == I40E_VSI_SRIOV) |
| 11563 | vsi->vf_id = param1; |
| 11564 | /* assign it some queues */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 11565 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 11566 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 11567 | |
| 11568 | 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] | 11569 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 11570 | dev_info(&pf->pdev->dev, |
| 11571 | "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] | 11572 | alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11573 | goto err_vsi; |
| 11574 | } |
| 11575 | vsi->base_queue = ret; |
| 11576 | |
| 11577 | /* get a VSI from the hardware */ |
| 11578 | vsi->uplink_seid = uplink_seid; |
| 11579 | ret = i40e_add_vsi(vsi); |
| 11580 | if (ret) |
| 11581 | goto err_vsi; |
| 11582 | |
| 11583 | switch (vsi->type) { |
| 11584 | /* setup the netdev if needed */ |
| 11585 | case I40E_VSI_MAIN: |
| 11586 | case I40E_VSI_VMDQ2: |
| 11587 | ret = i40e_config_netdev(vsi); |
| 11588 | if (ret) |
| 11589 | goto err_netdev; |
| 11590 | ret = register_netdev(vsi->netdev); |
| 11591 | if (ret) |
| 11592 | goto err_netdev; |
| 11593 | vsi->netdev_registered = true; |
| 11594 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11595 | #ifdef CONFIG_I40E_DCB |
| 11596 | /* Setup DCB netlink interface */ |
| 11597 | i40e_dcbnl_setup(vsi); |
| 11598 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11599 | /* fall through */ |
| 11600 | |
| 11601 | case I40E_VSI_FDIR: |
| 11602 | /* set up vectors and rings if needed */ |
| 11603 | ret = i40e_vsi_setup_vectors(vsi); |
| 11604 | if (ret) |
| 11605 | goto err_msix; |
| 11606 | |
| 11607 | ret = i40e_alloc_rings(vsi); |
| 11608 | if (ret) |
| 11609 | goto err_rings; |
| 11610 | |
| 11611 | /* map all of the rings to the q_vectors */ |
| 11612 | i40e_vsi_map_rings_to_vectors(vsi); |
| 11613 | |
| 11614 | i40e_vsi_reset_stats(vsi); |
| 11615 | break; |
| 11616 | |
| 11617 | default: |
| 11618 | /* no netdev or rings for the other VSI types */ |
| 11619 | break; |
| 11620 | } |
| 11621 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11622 | if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) && |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 11623 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 11624 | ret = i40e_vsi_config_rss(vsi); |
| 11625 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11626 | return vsi; |
| 11627 | |
| 11628 | err_rings: |
| 11629 | i40e_vsi_free_q_vectors(vsi); |
| 11630 | err_msix: |
| 11631 | if (vsi->netdev_registered) { |
| 11632 | vsi->netdev_registered = false; |
| 11633 | unregister_netdev(vsi->netdev); |
| 11634 | free_netdev(vsi->netdev); |
| 11635 | vsi->netdev = NULL; |
| 11636 | } |
| 11637 | err_netdev: |
| 11638 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 11639 | err_vsi: |
| 11640 | i40e_vsi_clear(vsi); |
| 11641 | err_alloc: |
| 11642 | return NULL; |
| 11643 | } |
| 11644 | |
| 11645 | /** |
| 11646 | * i40e_veb_get_bw_info - Query VEB BW information |
| 11647 | * @veb: the veb to query |
| 11648 | * |
| 11649 | * Query the Tx scheduler BW configuration data for given VEB |
| 11650 | **/ |
| 11651 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 11652 | { |
| 11653 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 11654 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 11655 | struct i40e_pf *pf = veb->pf; |
| 11656 | struct i40e_hw *hw = &pf->hw; |
| 11657 | u32 tc_bw_max; |
| 11658 | int ret = 0; |
| 11659 | int i; |
| 11660 | |
| 11661 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 11662 | &bw_data, NULL); |
| 11663 | if (ret) { |
| 11664 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11665 | "query veb bw config failed, err %s aq_err %s\n", |
| 11666 | i40e_stat_str(&pf->hw, ret), |
| 11667 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11668 | goto out; |
| 11669 | } |
| 11670 | |
| 11671 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 11672 | &ets_data, NULL); |
| 11673 | if (ret) { |
| 11674 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11675 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 11676 | i40e_stat_str(&pf->hw, ret), |
| 11677 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11678 | goto out; |
| 11679 | } |
| 11680 | |
| 11681 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 11682 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 11683 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 11684 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11685 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 11686 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 11687 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 11688 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 11689 | veb->bw_tc_limit_credits[i] = |
| 11690 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 11691 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 11692 | } |
| 11693 | |
| 11694 | out: |
| 11695 | return ret; |
| 11696 | } |
| 11697 | |
| 11698 | /** |
| 11699 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 11700 | * @pf: board private structure |
| 11701 | * |
| 11702 | * On error: returns error code (negative) |
| 11703 | * On success: returns vsi index in PF (positive) |
| 11704 | **/ |
| 11705 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 11706 | { |
| 11707 | int ret = -ENOENT; |
| 11708 | struct i40e_veb *veb; |
| 11709 | int i; |
| 11710 | |
| 11711 | /* Need to protect the allocation of switch elements at the PF level */ |
| 11712 | mutex_lock(&pf->switch_mutex); |
| 11713 | |
| 11714 | /* VEB list may be fragmented if VEB creation/destruction has |
| 11715 | * been happening. We can afford to do a quick scan to look |
| 11716 | * for any free slots in the list. |
| 11717 | * |
| 11718 | * find next empty veb slot, looping back around if necessary |
| 11719 | */ |
| 11720 | i = 0; |
| 11721 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 11722 | i++; |
| 11723 | if (i >= I40E_MAX_VEB) { |
| 11724 | ret = -ENOMEM; |
| 11725 | goto err_alloc_veb; /* out of VEB slots! */ |
| 11726 | } |
| 11727 | |
| 11728 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 11729 | if (!veb) { |
| 11730 | ret = -ENOMEM; |
| 11731 | goto err_alloc_veb; |
| 11732 | } |
| 11733 | veb->pf = pf; |
| 11734 | veb->idx = i; |
| 11735 | veb->enabled_tc = 1; |
| 11736 | |
| 11737 | pf->veb[i] = veb; |
| 11738 | ret = i; |
| 11739 | err_alloc_veb: |
| 11740 | mutex_unlock(&pf->switch_mutex); |
| 11741 | return ret; |
| 11742 | } |
| 11743 | |
| 11744 | /** |
| 11745 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 11746 | * @branch: where to start deleting |
| 11747 | * |
| 11748 | * This uses recursion to find the tips of the branch to be |
| 11749 | * removed, deleting until we get back to and can delete this VEB. |
| 11750 | **/ |
| 11751 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 11752 | { |
| 11753 | struct i40e_pf *pf = branch->pf; |
| 11754 | u16 branch_seid = branch->seid; |
| 11755 | u16 veb_idx = branch->idx; |
| 11756 | int i; |
| 11757 | |
| 11758 | /* release any VEBs on this VEB - RECURSION */ |
| 11759 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11760 | if (!pf->veb[i]) |
| 11761 | continue; |
| 11762 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 11763 | i40e_switch_branch_release(pf->veb[i]); |
| 11764 | } |
| 11765 | |
| 11766 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 11767 | * |
| 11768 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 11769 | * the VEB itself, so don't use (*branch) after this loop. |
| 11770 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11771 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11772 | if (!pf->vsi[i]) |
| 11773 | continue; |
| 11774 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 11775 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 11776 | i40e_vsi_release(pf->vsi[i]); |
| 11777 | } |
| 11778 | } |
| 11779 | |
| 11780 | /* There's one corner case where the VEB might not have been |
| 11781 | * removed, so double check it here and remove it if needed. |
| 11782 | * This case happens if the veb was created from the debugfs |
| 11783 | * commands and no VSIs were added to it. |
| 11784 | */ |
| 11785 | if (pf->veb[veb_idx]) |
| 11786 | i40e_veb_release(pf->veb[veb_idx]); |
| 11787 | } |
| 11788 | |
| 11789 | /** |
| 11790 | * i40e_veb_clear - remove veb struct |
| 11791 | * @veb: the veb to remove |
| 11792 | **/ |
| 11793 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 11794 | { |
| 11795 | if (!veb) |
| 11796 | return; |
| 11797 | |
| 11798 | if (veb->pf) { |
| 11799 | struct i40e_pf *pf = veb->pf; |
| 11800 | |
| 11801 | mutex_lock(&pf->switch_mutex); |
| 11802 | if (pf->veb[veb->idx] == veb) |
| 11803 | pf->veb[veb->idx] = NULL; |
| 11804 | mutex_unlock(&pf->switch_mutex); |
| 11805 | } |
| 11806 | |
| 11807 | kfree(veb); |
| 11808 | } |
| 11809 | |
| 11810 | /** |
| 11811 | * i40e_veb_release - Delete a VEB and free its resources |
| 11812 | * @veb: the VEB being removed |
| 11813 | **/ |
| 11814 | void i40e_veb_release(struct i40e_veb *veb) |
| 11815 | { |
| 11816 | struct i40e_vsi *vsi = NULL; |
| 11817 | struct i40e_pf *pf; |
| 11818 | int i, n = 0; |
| 11819 | |
| 11820 | pf = veb->pf; |
| 11821 | |
| 11822 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11823 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11824 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 11825 | n++; |
| 11826 | vsi = pf->vsi[i]; |
| 11827 | } |
| 11828 | } |
| 11829 | if (n != 1) { |
| 11830 | dev_info(&pf->pdev->dev, |
| 11831 | "can't remove VEB %d with %d VSIs left\n", |
| 11832 | veb->seid, n); |
| 11833 | return; |
| 11834 | } |
| 11835 | |
| 11836 | /* move the remaining VSI to uplink veb */ |
| 11837 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 11838 | if (veb->uplink_seid) { |
| 11839 | vsi->uplink_seid = veb->uplink_seid; |
| 11840 | if (veb->uplink_seid == pf->mac_seid) |
| 11841 | vsi->veb_idx = I40E_NO_VEB; |
| 11842 | else |
| 11843 | vsi->veb_idx = veb->veb_idx; |
| 11844 | } else { |
| 11845 | /* floating VEB */ |
| 11846 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 11847 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 11848 | } |
| 11849 | |
| 11850 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 11851 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11852 | } |
| 11853 | |
| 11854 | /** |
| 11855 | * i40e_add_veb - create the VEB in the switch |
| 11856 | * @veb: the VEB to be instantiated |
| 11857 | * @vsi: the controlling VSI |
| 11858 | **/ |
| 11859 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 11860 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11861 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 11862 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11863 | int ret; |
| 11864 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11865 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 11866 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 11867 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 11868 | |
| 11869 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11870 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11871 | dev_info(&pf->pdev->dev, |
| 11872 | "couldn't add VEB, err %s aq_err %s\n", |
| 11873 | i40e_stat_str(&pf->hw, ret), |
| 11874 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11875 | return -EPERM; |
| 11876 | } |
| 11877 | |
| 11878 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11879 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11880 | &veb->stats_idx, NULL, NULL, NULL); |
| 11881 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11882 | dev_info(&pf->pdev->dev, |
| 11883 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 11884 | i40e_stat_str(&pf->hw, ret), |
| 11885 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11886 | return -EPERM; |
| 11887 | } |
| 11888 | ret = i40e_veb_get_bw_info(veb); |
| 11889 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11890 | dev_info(&pf->pdev->dev, |
| 11891 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 11892 | i40e_stat_str(&pf->hw, ret), |
| 11893 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11894 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11895 | return -ENOENT; |
| 11896 | } |
| 11897 | |
| 11898 | vsi->uplink_seid = veb->seid; |
| 11899 | vsi->veb_idx = veb->idx; |
| 11900 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 11901 | |
| 11902 | return 0; |
| 11903 | } |
| 11904 | |
| 11905 | /** |
| 11906 | * i40e_veb_setup - Set up a VEB |
| 11907 | * @pf: board private structure |
| 11908 | * @flags: VEB setup flags |
| 11909 | * @uplink_seid: the switch element to link to |
| 11910 | * @vsi_seid: the initial VSI seid |
| 11911 | * @enabled_tc: Enabled TC bit-map |
| 11912 | * |
| 11913 | * This allocates the sw VEB structure and links it into the switch |
| 11914 | * It is possible and legal for this to be a duplicate of an already |
| 11915 | * existing VEB. It is also possible for both uplink and vsi seids |
| 11916 | * to be zero, in order to create a floating VEB. |
| 11917 | * |
| 11918 | * Returns pointer to the successfully allocated VEB sw struct on |
| 11919 | * success, otherwise returns NULL on failure. |
| 11920 | **/ |
| 11921 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 11922 | u16 uplink_seid, u16 vsi_seid, |
| 11923 | u8 enabled_tc) |
| 11924 | { |
| 11925 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 11926 | int vsi_idx, veb_idx; |
| 11927 | int ret; |
| 11928 | |
| 11929 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 11930 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 11931 | (uplink_seid + vsi_seid != 0)) { |
| 11932 | dev_info(&pf->pdev->dev, |
| 11933 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 11934 | uplink_seid, vsi_seid); |
| 11935 | return NULL; |
| 11936 | } |
| 11937 | |
| 11938 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11939 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11940 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 11941 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11942 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11943 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 11944 | vsi_seid); |
| 11945 | return NULL; |
| 11946 | } |
| 11947 | |
| 11948 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 11949 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 11950 | if (pf->veb[veb_idx] && |
| 11951 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 11952 | uplink_veb = pf->veb[veb_idx]; |
| 11953 | break; |
| 11954 | } |
| 11955 | } |
| 11956 | if (!uplink_veb) { |
| 11957 | dev_info(&pf->pdev->dev, |
| 11958 | "uplink seid %d not found\n", uplink_seid); |
| 11959 | return NULL; |
| 11960 | } |
| 11961 | } |
| 11962 | |
| 11963 | /* get veb sw struct */ |
| 11964 | veb_idx = i40e_veb_mem_alloc(pf); |
| 11965 | if (veb_idx < 0) |
| 11966 | goto err_alloc; |
| 11967 | veb = pf->veb[veb_idx]; |
| 11968 | veb->flags = flags; |
| 11969 | veb->uplink_seid = uplink_seid; |
| 11970 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 11971 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 11972 | |
| 11973 | /* create the VEB in the switch */ |
| 11974 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 11975 | if (ret) |
| 11976 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 11977 | if (vsi_idx == pf->lan_vsi) |
| 11978 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11979 | |
| 11980 | return veb; |
| 11981 | |
| 11982 | err_veb: |
| 11983 | i40e_veb_clear(veb); |
| 11984 | err_alloc: |
| 11985 | return NULL; |
| 11986 | } |
| 11987 | |
| 11988 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 11989 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11990 | * @pf: board private structure |
| 11991 | * @ele: element we are building info from |
| 11992 | * @num_reported: total number of elements |
| 11993 | * @printconfig: should we print the contents |
| 11994 | * |
| 11995 | * helper function to assist in extracting a few useful SEID values. |
| 11996 | **/ |
| 11997 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 11998 | struct i40e_aqc_switch_config_element_resp *ele, |
| 11999 | u16 num_reported, bool printconfig) |
| 12000 | { |
| 12001 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 12002 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 12003 | u8 element_type = ele->element_type; |
| 12004 | u16 seid = le16_to_cpu(ele->seid); |
| 12005 | |
| 12006 | if (printconfig) |
| 12007 | dev_info(&pf->pdev->dev, |
| 12008 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 12009 | element_type, seid, uplink_seid, downlink_seid); |
| 12010 | |
| 12011 | switch (element_type) { |
| 12012 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 12013 | pf->mac_seid = seid; |
| 12014 | break; |
| 12015 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 12016 | /* Main VEB? */ |
| 12017 | if (uplink_seid != pf->mac_seid) |
| 12018 | break; |
| 12019 | if (pf->lan_veb == I40E_NO_VEB) { |
| 12020 | int v; |
| 12021 | |
| 12022 | /* find existing or else empty VEB */ |
| 12023 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 12024 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 12025 | pf->lan_veb = v; |
| 12026 | break; |
| 12027 | } |
| 12028 | } |
| 12029 | if (pf->lan_veb == I40E_NO_VEB) { |
| 12030 | v = i40e_veb_mem_alloc(pf); |
| 12031 | if (v < 0) |
| 12032 | break; |
| 12033 | pf->lan_veb = v; |
| 12034 | } |
| 12035 | } |
| 12036 | |
| 12037 | pf->veb[pf->lan_veb]->seid = seid; |
| 12038 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 12039 | pf->veb[pf->lan_veb]->pf = pf; |
| 12040 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 12041 | break; |
| 12042 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 12043 | if (num_reported != 1) |
| 12044 | break; |
| 12045 | /* This is immediately after a reset so we can assume this is |
| 12046 | * the PF's VSI |
| 12047 | */ |
| 12048 | pf->mac_seid = uplink_seid; |
| 12049 | pf->pf_seid = downlink_seid; |
| 12050 | pf->main_vsi_seid = seid; |
| 12051 | if (printconfig) |
| 12052 | dev_info(&pf->pdev->dev, |
| 12053 | "pf_seid=%d main_vsi_seid=%d\n", |
| 12054 | pf->pf_seid, pf->main_vsi_seid); |
| 12055 | break; |
| 12056 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 12057 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 12058 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 12059 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 12060 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 12061 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 12062 | /* ignore these for now */ |
| 12063 | break; |
| 12064 | default: |
| 12065 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 12066 | element_type, seid); |
| 12067 | break; |
| 12068 | } |
| 12069 | } |
| 12070 | |
| 12071 | /** |
| 12072 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 12073 | * @pf: board private structure |
| 12074 | * @printconfig: should we print the contents |
| 12075 | * |
| 12076 | * Get the current switch configuration from the device and |
| 12077 | * extract a few useful SEID values. |
| 12078 | **/ |
| 12079 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 12080 | { |
| 12081 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 12082 | u16 next_seid = 0; |
| 12083 | int ret = 0; |
| 12084 | u8 *aq_buf; |
| 12085 | int i; |
| 12086 | |
| 12087 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 12088 | if (!aq_buf) |
| 12089 | return -ENOMEM; |
| 12090 | |
| 12091 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 12092 | do { |
| 12093 | u16 num_reported, num_total; |
| 12094 | |
| 12095 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 12096 | I40E_AQ_LARGE_BUF, |
| 12097 | &next_seid, NULL); |
| 12098 | if (ret) { |
| 12099 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 12100 | "get switch config failed err %s aq_err %s\n", |
| 12101 | i40e_stat_str(&pf->hw, ret), |
| 12102 | i40e_aq_str(&pf->hw, |
| 12103 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12104 | kfree(aq_buf); |
| 12105 | return -ENOENT; |
| 12106 | } |
| 12107 | |
| 12108 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 12109 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 12110 | |
| 12111 | if (printconfig) |
| 12112 | dev_info(&pf->pdev->dev, |
| 12113 | "header: %d reported %d total\n", |
| 12114 | num_reported, num_total); |
| 12115 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12116 | for (i = 0; i < num_reported; i++) { |
| 12117 | struct i40e_aqc_switch_config_element_resp *ele = |
| 12118 | &sw_config->element[i]; |
| 12119 | |
| 12120 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 12121 | printconfig); |
| 12122 | } |
| 12123 | } while (next_seid != 0); |
| 12124 | |
| 12125 | kfree(aq_buf); |
| 12126 | return ret; |
| 12127 | } |
| 12128 | |
| 12129 | /** |
| 12130 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 12131 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 12132 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12133 | * |
| 12134 | * Returns 0 on success, negative value on failure |
| 12135 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 12136 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12137 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 12138 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12139 | int ret; |
| 12140 | |
| 12141 | /* find out what's out there already */ |
| 12142 | ret = i40e_fetch_switch_configuration(pf, false); |
| 12143 | if (ret) { |
| 12144 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 12145 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 12146 | i40e_stat_str(&pf->hw, ret), |
| 12147 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12148 | return ret; |
| 12149 | } |
| 12150 | i40e_pf_reset_stats(pf); |
| 12151 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 12152 | /* set the switch config bit for the whole device to |
| 12153 | * support limited promisc or true promisc |
| 12154 | * when user requests promisc. The default is limited |
| 12155 | * promisc. |
| 12156 | */ |
| 12157 | |
| 12158 | if ((pf->hw.pf_id == 0) && |
| 12159 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 12160 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 12161 | |
| 12162 | if (pf->hw.pf_id == 0) { |
| 12163 | u16 valid_flags; |
| 12164 | |
| 12165 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 12166 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 12167 | NULL); |
| 12168 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 12169 | dev_info(&pf->pdev->dev, |
| 12170 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 12171 | i40e_stat_str(&pf->hw, ret), |
| 12172 | i40e_aq_str(&pf->hw, |
| 12173 | pf->hw.aq.asq_last_status)); |
| 12174 | /* not a fatal problem, just keep going */ |
| 12175 | } |
| 12176 | } |
| 12177 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12178 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 12179 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12180 | struct i40e_vsi *vsi = NULL; |
| 12181 | u16 uplink_seid; |
| 12182 | |
| 12183 | /* Set up the PF VSI associated with the PF's main VSI |
| 12184 | * that is already in the HW switch |
| 12185 | */ |
| 12186 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 12187 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 12188 | else |
| 12189 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 12190 | if (pf->lan_vsi == I40E_NO_VSI) |
| 12191 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 12192 | else if (reinit) |
| 12193 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12194 | if (!vsi) { |
| 12195 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 12196 | i40e_fdir_teardown(pf); |
| 12197 | return -EAGAIN; |
| 12198 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12199 | } else { |
| 12200 | /* force a reset of TC and queue layout configurations */ |
| 12201 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 12202 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12203 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 12204 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 12205 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 12206 | } |
| 12207 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 12208 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12209 | i40e_fdir_sb_setup(pf); |
| 12210 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12211 | /* Setup static PF queue filter control settings */ |
| 12212 | ret = i40e_setup_pf_filter_control(pf); |
| 12213 | if (ret) { |
| 12214 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 12215 | ret); |
| 12216 | /* Failure here should not stop continuing other steps */ |
| 12217 | } |
| 12218 | |
| 12219 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 12220 | * the hash |
| 12221 | */ |
| 12222 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 12223 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12224 | |
| 12225 | /* fill in link information and enable LSE reporting */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12226 | i40e_link_event(pf); |
| 12227 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 12228 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12229 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 12230 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 12231 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 12232 | i40e_ptp_init(pf); |
| 12233 | |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 12234 | /* repopulate tunnel port filters */ |
| 12235 | i40e_sync_udp_filters(pf); |
| 12236 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12237 | return ret; |
| 12238 | } |
| 12239 | |
| 12240 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12241 | * i40e_determine_queue_usage - Work out queue distribution |
| 12242 | * @pf: board private structure |
| 12243 | **/ |
| 12244 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 12245 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12246 | int queues_left; |
Shannon Nelson | e50d575 | 2017-07-24 18:17:42 -0700 | [diff] [blame] | 12247 | int q_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12248 | |
| 12249 | pf->num_lan_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12250 | |
| 12251 | /* Find the max queues to be put into basic use. We'll always be |
| 12252 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 12253 | * big RSS set. |
| 12254 | */ |
| 12255 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 12256 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12257 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 12258 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12259 | /* one qp for PF, no queues for anything else */ |
| 12260 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 12261 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12262 | |
| 12263 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 12264 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 12265 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 12266 | I40E_FLAG_FD_SB_ENABLED | |
| 12267 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 12268 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 12269 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 12270 | I40E_FLAG_SRIOV_ENABLED | |
| 12271 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 12272 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 12273 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 12274 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 12275 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 12276 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 12277 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 12278 | queues_left -= pf->num_lan_qps; |
| 12279 | |
| 12280 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 12281 | I40E_FLAG_IWARP_ENABLED | |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 12282 | I40E_FLAG_FD_SB_ENABLED | |
| 12283 | I40E_FLAG_FD_ATR_ENABLED | |
| 12284 | I40E_FLAG_DCB_ENABLED | |
| 12285 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12286 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12287 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 12288 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12289 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 12290 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 12291 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12292 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 12293 | } |
Shannon Nelson | e50d575 | 2017-07-24 18:17:42 -0700 | [diff] [blame] | 12294 | |
| 12295 | /* limit lan qps to the smaller of qps, cpus or msix */ |
| 12296 | q_max = max_t(int, pf->rss_size_max, num_online_cpus()); |
| 12297 | q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp); |
| 12298 | q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors); |
| 12299 | pf->num_lan_qps = q_max; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 12300 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12301 | queues_left -= pf->num_lan_qps; |
| 12302 | } |
| 12303 | |
| 12304 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 12305 | if (queues_left > 1) { |
| 12306 | queues_left -= 1; /* save 1 queue for FD */ |
| 12307 | } else { |
| 12308 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 12309 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 12310 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12311 | } |
| 12312 | |
| 12313 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 12314 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 12315 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 12316 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12317 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 12318 | } |
| 12319 | |
| 12320 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 12321 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 12322 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 12323 | (queues_left / pf->num_vmdq_qps)); |
| 12324 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 12325 | } |
| 12326 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 12327 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 12328 | dev_dbg(&pf->pdev->dev, |
| 12329 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 12330 | pf->hw.func_caps.num_tx_qp, |
| 12331 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 12332 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 12333 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 12334 | queues_left); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12335 | } |
| 12336 | |
| 12337 | /** |
| 12338 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 12339 | * @pf: PF to be setup |
| 12340 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 12341 | * 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] | 12342 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 12343 | * based filter sizes required for them. It also enables Flow director, |
| 12344 | * ethertype and macvlan type filter settings for the pf. |
| 12345 | * |
| 12346 | * Returns 0 on success, negative on failure |
| 12347 | **/ |
| 12348 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 12349 | { |
| 12350 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 12351 | |
| 12352 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 12353 | |
| 12354 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 12355 | 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] | 12356 | settings->enable_fdir = true; |
| 12357 | |
| 12358 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 12359 | settings->enable_ethtype = true; |
| 12360 | settings->enable_macvlan = true; |
| 12361 | |
| 12362 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 12363 | return -ENOENT; |
| 12364 | |
| 12365 | return 0; |
| 12366 | } |
| 12367 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12368 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 12369 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12370 | static void i40e_print_features(struct i40e_pf *pf) |
| 12371 | { |
| 12372 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12373 | char *buf; |
| 12374 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12375 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12376 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 12377 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12378 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12379 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12380 | 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] | 12381 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12382 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12383 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 12384 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 12385 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 12386 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12387 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12388 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12389 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12390 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 12391 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12392 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 12393 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 12394 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 12395 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12396 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12397 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 12398 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12399 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12400 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 12401 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12402 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 12403 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12404 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12405 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 12406 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 12407 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 12408 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12409 | } |
| 12410 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12411 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 12412 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 12413 | * @pdev: PCI device information struct |
| 12414 | * @pf: board private structure |
| 12415 | * |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 12416 | * Look up the MAC address for the device. First we'll try |
| 12417 | * eth_platform_get_mac_address, which will check Open Firmware, or arch |
| 12418 | * specific fallback. Otherwise, we'll default to the stored value in |
| 12419 | * firmware. |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 12420 | **/ |
| 12421 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 12422 | { |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 12423 | if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
| 12424 | i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 12425 | } |
| 12426 | |
| 12427 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12428 | * i40e_probe - Device initialization routine |
| 12429 | * @pdev: PCI device information struct |
| 12430 | * @ent: entry in i40e_pci_tbl |
| 12431 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 12432 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 12433 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12434 | * and a hardware reset occur. |
| 12435 | * |
| 12436 | * Returns 0 on success, negative on failure |
| 12437 | **/ |
| 12438 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 12439 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 12440 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12441 | struct i40e_pf *pf; |
| 12442 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 12443 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 12444 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 12445 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 12446 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 12447 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 12448 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 12449 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12450 | |
| 12451 | err = pci_enable_device_mem(pdev); |
| 12452 | if (err) |
| 12453 | return err; |
| 12454 | |
| 12455 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 12456 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 12457 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 12458 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 12459 | if (err) { |
| 12460 | dev_err(&pdev->dev, |
| 12461 | "DMA configuration failed: 0x%x\n", err); |
| 12462 | goto err_dma; |
| 12463 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12464 | } |
| 12465 | |
| 12466 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 12467 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12468 | if (err) { |
| 12469 | dev_info(&pdev->dev, |
| 12470 | "pci_request_selected_regions failed %d\n", err); |
| 12471 | goto err_pci_reg; |
| 12472 | } |
| 12473 | |
| 12474 | pci_enable_pcie_error_reporting(pdev); |
| 12475 | pci_set_master(pdev); |
| 12476 | |
| 12477 | /* Now that we have a PCI connection, we need to do the |
| 12478 | * low level device setup. This is primarily setting up |
| 12479 | * the Admin Queue structures and then querying for the |
| 12480 | * device's current profile information. |
| 12481 | */ |
| 12482 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 12483 | if (!pf) { |
| 12484 | err = -ENOMEM; |
| 12485 | goto err_pf_alloc; |
| 12486 | } |
| 12487 | pf->next_vsi = 0; |
| 12488 | pf->pdev = pdev; |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12489 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12490 | |
| 12491 | hw = &pf->hw; |
| 12492 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 12493 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 12494 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 12495 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 12496 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 12497 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12498 | if (!hw->hw_addr) { |
| 12499 | err = -EIO; |
| 12500 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 12501 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 12502 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12503 | goto err_ioremap; |
| 12504 | } |
| 12505 | hw->vendor_id = pdev->vendor; |
| 12506 | hw->device_id = pdev->device; |
| 12507 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 12508 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 12509 | hw->subsystem_device_id = pdev->subsystem_device; |
| 12510 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 12511 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 12512 | hw->bus.bus_id = pdev->bus->number; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 12513 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12514 | |
Scott Peterson | ab243ec | 2017-08-22 06:57:54 -0400 | [diff] [blame] | 12515 | /* Select something other than the 802.1ad ethertype for the |
| 12516 | * switch to use internally and drop on ingress. |
| 12517 | */ |
| 12518 | hw->switch_tag = 0xffff; |
| 12519 | hw->first_tag = ETH_P_8021AD; |
| 12520 | hw->second_tag = ETH_P_8021Q; |
| 12521 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 12522 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 12523 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 12524 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 12525 | /* set up the locks for the AQ, do this only once in probe |
| 12526 | * and destroy them only once in remove |
| 12527 | */ |
| 12528 | mutex_init(&hw->aq.asq_mutex); |
| 12529 | mutex_init(&hw->aq.arq_mutex); |
| 12530 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 12531 | pf->msg_enable = netif_msg_init(debug, |
| 12532 | NETIF_MSG_DRV | |
| 12533 | NETIF_MSG_PROBE | |
| 12534 | NETIF_MSG_LINK); |
| 12535 | if (debug < -1) |
| 12536 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 12537 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 12538 | /* do a special CORER for clearing PXE mode once at init */ |
| 12539 | if (hw->revision_id == 0 && |
| 12540 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 12541 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 12542 | i40e_flush(hw); |
| 12543 | msleep(200); |
| 12544 | pf->corer_count++; |
| 12545 | |
| 12546 | i40e_clear_pxe_mode(hw); |
| 12547 | } |
| 12548 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12549 | /* 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] | 12550 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12551 | err = i40e_pf_reset(hw); |
| 12552 | if (err) { |
| 12553 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 12554 | goto err_pf_reset; |
| 12555 | } |
| 12556 | pf->pfr_count++; |
| 12557 | |
| 12558 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 12559 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 12560 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 12561 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 12562 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 12563 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 12564 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 12565 | "%s-%s:misc", |
| 12566 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12567 | |
| 12568 | err = i40e_init_shared_code(hw); |
| 12569 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 12570 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 12571 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12572 | goto err_pf_reset; |
| 12573 | } |
| 12574 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 12575 | /* set up a default setting for link flow control */ |
| 12576 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 12577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12578 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 12579 | if (err) { |
| 12580 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 12581 | dev_info(&pdev->dev, |
| 12582 | "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"); |
| 12583 | else |
| 12584 | dev_info(&pdev->dev, |
| 12585 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 12586 | |
| 12587 | goto err_pf_reset; |
| 12588 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 12589 | i40e_get_oem_version(hw); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 12590 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 12591 | /* provide nvm, fw, api versions */ |
| 12592 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 12593 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 12594 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 12595 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 12596 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 12597 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
Mitch Williams | 22b96551 | 2017-07-14 09:27:09 -0400 | [diff] [blame] | 12598 | hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 12599 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 12600 | "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"); |
Mariusz Stachura | e04ea00 | 2017-07-14 09:10:19 -0400 | [diff] [blame] | 12601 | else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 12602 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 12603 | "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] | 12604 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 12605 | i40e_verify_eeprom(pf); |
| 12606 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 12607 | /* Rev 0 hardware was never productized */ |
| 12608 | if (hw->revision_id < 1) |
| 12609 | 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"); |
| 12610 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 12611 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12612 | err = i40e_get_capabilities(pf); |
| 12613 | if (err) |
| 12614 | goto err_adminq_setup; |
| 12615 | |
| 12616 | err = i40e_sw_init(pf); |
| 12617 | if (err) { |
| 12618 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 12619 | goto err_sw_init; |
| 12620 | } |
| 12621 | |
| 12622 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 12623 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12624 | if (err) { |
| 12625 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 12626 | goto err_init_lan_hmc; |
| 12627 | } |
| 12628 | |
| 12629 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 12630 | if (err) { |
| 12631 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 12632 | err = -ENOENT; |
| 12633 | goto err_configure_lan_hmc; |
| 12634 | } |
| 12635 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 12636 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 12637 | * Ignore error return codes because if it was already disabled via |
| 12638 | * hardware settings this will fail |
| 12639 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12640 | if (pf->hw_features & I40E_HW_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 12641 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 12642 | i40e_aq_stop_lldp(hw, true, NULL); |
| 12643 | } |
| 12644 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 12645 | /* allow a platform config to override the HW addr */ |
| 12646 | i40e_get_platform_mac_addr(pdev, pf); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 12647 | |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 12648 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12649 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 12650 | err = -EIO; |
| 12651 | goto err_mac_addr; |
| 12652 | } |
| 12653 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 12654 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 12655 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 12656 | if (is_valid_ether_addr(hw->mac.port_addr)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12657 | pf->hw_features |= I40E_HW_PORT_ID_VALID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12658 | |
| 12659 | pci_set_drvdata(pdev, pf); |
| 12660 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 12661 | #ifdef CONFIG_I40E_DCB |
| 12662 | err = i40e_init_pf_dcb(pf); |
| 12663 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 12664 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 12665 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 12666 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 12667 | } |
| 12668 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12669 | |
| 12670 | /* set up periodic task facility */ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 12671 | timer_setup(&pf->service_timer, i40e_service_timer, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12672 | pf->service_timer_period = HZ; |
| 12673 | |
| 12674 | INIT_WORK(&pf->service_task, i40e_service_task); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12675 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12676 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 12677 | /* NVM bit on means WoL disabled for the port */ |
| 12678 | 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] | 12679 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 12680 | pf->wol_en = false; |
| 12681 | else |
| 12682 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12683 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 12684 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12685 | /* set up the main switch operations */ |
| 12686 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 12687 | err = i40e_init_interrupt_scheme(pf); |
| 12688 | if (err) |
| 12689 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12690 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 12691 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 12692 | * to us; HW supports far more and we share the remaining pool with |
| 12693 | * the other PFs. We allocate space for more than the guarantee with |
| 12694 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12695 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 12696 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 12697 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 12698 | else |
| 12699 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 12700 | |
| 12701 | /* 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] | 12702 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 12703 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 12704 | if (!pf->vsi) { |
| 12705 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12706 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 12707 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12708 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 12709 | #ifdef CONFIG_PCI_IOV |
| 12710 | /* prep for VF support */ |
| 12711 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 12712 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12713 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 12714 | if (pci_num_vf(pdev)) |
| 12715 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 12716 | } |
| 12717 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 12718 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12719 | if (err) { |
| 12720 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 12721 | goto err_vsis; |
| 12722 | } |
Amritha Nambiar | 8f88b30 | 2017-09-07 04:00:17 -0700 | [diff] [blame] | 12723 | INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list); |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 12724 | |
| 12725 | /* Make sure flow control is set according to current settings */ |
| 12726 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 12727 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 12728 | dev_dbg(&pf->pdev->dev, |
| 12729 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 12730 | i40e_stat_str(hw, err), |
| 12731 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 12732 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 12733 | dev_dbg(&pf->pdev->dev, |
| 12734 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 12735 | i40e_stat_str(hw, err), |
| 12736 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 12737 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 12738 | dev_dbg(&pf->pdev->dev, |
| 12739 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 12740 | i40e_stat_str(hw, err), |
| 12741 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 12742 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 12743 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 12744 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 12745 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 12746 | i40e_vsi_open(pf->vsi[i]); |
| 12747 | break; |
| 12748 | } |
| 12749 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12750 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 12751 | /* The driver only wants link up/down and module qualification |
| 12752 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 12753 | */ |
| 12754 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 12755 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 12756 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 12757 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 12758 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 12759 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 12760 | i40e_stat_str(&pf->hw, err), |
| 12761 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 12762 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 12763 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 12764 | * of TSO, so that we avoid the MDD being fired and causing |
| 12765 | * a reset in the case of small MSS+TSO. |
| 12766 | */ |
| 12767 | val = rd32(hw, I40E_REG_MSS); |
| 12768 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 12769 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 12770 | val |= I40E_64BYTE_MSS; |
| 12771 | wr32(hw, I40E_REG_MSS, val); |
| 12772 | } |
| 12773 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12774 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 12775 | msleep(75); |
| 12776 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 12777 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 12778 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 12779 | i40e_stat_str(&pf->hw, err), |
| 12780 | i40e_aq_str(&pf->hw, |
| 12781 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 12782 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12783 | /* The main driver is (mostly) up and happy. We need to set this state |
| 12784 | * before setting up the misc vector or we get a race and the vector |
| 12785 | * ends up disabled forever. |
| 12786 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12787 | clear_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12788 | |
| 12789 | /* In case of MSIX we are going to setup the misc vector right here |
| 12790 | * to handle admin queue events etc. In case of legacy and MSI |
| 12791 | * the misc functionality and queue processing is combined in |
| 12792 | * the same vector and that gets setup at open. |
| 12793 | */ |
| 12794 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 12795 | err = i40e_setup_misc_vector(pf); |
| 12796 | if (err) { |
| 12797 | dev_info(&pdev->dev, |
| 12798 | "setup of misc vector failed: %d\n", err); |
| 12799 | goto err_vsis; |
| 12800 | } |
| 12801 | } |
| 12802 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 12803 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12804 | /* prep for VF support */ |
| 12805 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 12806 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12807 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12808 | /* disable link interrupts for VFs */ |
| 12809 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 12810 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 12811 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 12812 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 12813 | |
| 12814 | if (pci_num_vf(pdev)) { |
| 12815 | dev_info(&pdev->dev, |
| 12816 | "Active VFs found, allocating resources.\n"); |
| 12817 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 12818 | if (err) |
| 12819 | dev_info(&pdev->dev, |
| 12820 | "Error %d allocating resources for existing VFs\n", |
| 12821 | err); |
| 12822 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12823 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 12824 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12825 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 12826 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 12827 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 12828 | pf->num_iwarp_msix, |
| 12829 | I40E_IWARP_IRQ_PILE_ID); |
| 12830 | if (pf->iwarp_base_vector < 0) { |
| 12831 | dev_info(&pdev->dev, |
| 12832 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 12833 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 12834 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 12835 | } |
| 12836 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 12837 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12838 | i40e_dbg_pf_init(pf); |
| 12839 | |
| 12840 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 12841 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12842 | |
| 12843 | /* since everything's happy, start the service_task timer */ |
| 12844 | mod_timer(&pf->service_timer, |
| 12845 | round_jiffies(jiffies + pf->service_timer_period)); |
| 12846 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 12847 | /* 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] | 12848 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 12849 | err = i40e_lan_add_device(pf); |
| 12850 | if (err) |
| 12851 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 12852 | err); |
| 12853 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 12854 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 12855 | #define PCI_SPEED_SIZE 8 |
| 12856 | #define PCI_WIDTH_SIZE 8 |
| 12857 | /* Devices on the IOSF bus do not have this information |
| 12858 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 12859 | * checking them. |
| 12860 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12861 | if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) { |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 12862 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 12863 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 12864 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 12865 | /* Get the negotiated link width and speed from PCI config |
| 12866 | * space |
| 12867 | */ |
| 12868 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 12869 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 12870 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 12871 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 12872 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 12873 | switch (hw->bus.speed) { |
| 12874 | case i40e_bus_speed_8000: |
| 12875 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 12876 | case i40e_bus_speed_5000: |
| 12877 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 12878 | case i40e_bus_speed_2500: |
| 12879 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 12880 | default: |
| 12881 | break; |
| 12882 | } |
| 12883 | switch (hw->bus.width) { |
| 12884 | case i40e_bus_width_pcie_x8: |
| 12885 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 12886 | case i40e_bus_width_pcie_x4: |
| 12887 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 12888 | case i40e_bus_width_pcie_x2: |
| 12889 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 12890 | case i40e_bus_width_pcie_x1: |
| 12891 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 12892 | default: |
| 12893 | break; |
| 12894 | } |
| 12895 | |
| 12896 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 12897 | speed, width); |
| 12898 | |
| 12899 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 12900 | hw->bus.speed < i40e_bus_speed_8000) { |
| 12901 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 12902 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 12903 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 12904 | } |
| 12905 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 12906 | /* get the requested speeds from the fw */ |
| 12907 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 12908 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 12909 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 12910 | i40e_stat_str(&pf->hw, err), |
| 12911 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 12912 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 12913 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 12914 | /* get the supported phy types from the fw */ |
| 12915 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 12916 | if (err) |
| 12917 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 12918 | i40e_stat_str(&pf->hw, err), |
| 12919 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 12920 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 12921 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 12922 | * transmitted. By doing so we stop a malicious VF from sending out |
| 12923 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 12924 | * PF/VF VSIs. |
| 12925 | * The FW can still send Flow control frames if enabled. |
| 12926 | */ |
| 12927 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 12928 | pf->main_vsi_seid); |
| 12929 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 12930 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 12931 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12932 | pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 12933 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12934 | pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 12935 | /* print a string summarizing features */ |
| 12936 | i40e_print_features(pf); |
| 12937 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12938 | return 0; |
| 12939 | |
| 12940 | /* Unwind what we've done if something failed in the setup */ |
| 12941 | err_vsis: |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12942 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12943 | i40e_clear_interrupt_scheme(pf); |
| 12944 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 12945 | err_switch_setup: |
| 12946 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12947 | del_timer_sync(&pf->service_timer); |
| 12948 | err_mac_addr: |
| 12949 | err_configure_lan_hmc: |
| 12950 | (void)i40e_shutdown_lan_hmc(hw); |
| 12951 | err_init_lan_hmc: |
| 12952 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12953 | err_sw_init: |
| 12954 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12955 | err_pf_reset: |
| 12956 | iounmap(hw->hw_addr); |
| 12957 | err_ioremap: |
| 12958 | kfree(pf); |
| 12959 | err_pf_alloc: |
| 12960 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 12961 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12962 | err_pci_reg: |
| 12963 | err_dma: |
| 12964 | pci_disable_device(pdev); |
| 12965 | return err; |
| 12966 | } |
| 12967 | |
| 12968 | /** |
| 12969 | * i40e_remove - Device removal routine |
| 12970 | * @pdev: PCI device information struct |
| 12971 | * |
| 12972 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 12973 | * that is should release a PCI device. This could be caused by a |
| 12974 | * Hot-Plug event, or because the driver is going to be removed from |
| 12975 | * memory. |
| 12976 | **/ |
| 12977 | static void i40e_remove(struct pci_dev *pdev) |
| 12978 | { |
| 12979 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 12980 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12981 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12982 | int i; |
| 12983 | |
| 12984 | i40e_dbg_pf_exit(pf); |
| 12985 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 12986 | i40e_ptp_stop(pf); |
| 12987 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 12988 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 12989 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 12990 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 12991 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12992 | /* no more scheduling of any task */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12993 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12994 | set_bit(__I40E_DOWN, pf->state); |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 12995 | if (pf->service_timer.function) |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 12996 | del_timer_sync(&pf->service_timer); |
| 12997 | if (pf->service_task.func) |
| 12998 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12999 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 13000 | /* Client close must be called explicitly here because the timer |
| 13001 | * has been stopped. |
| 13002 | */ |
| 13003 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 13004 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 13005 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 13006 | i40e_free_vfs(pf); |
| 13007 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 13008 | } |
| 13009 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13010 | i40e_fdir_teardown(pf); |
| 13011 | |
| 13012 | /* If there is a switch structure or any orphans, remove them. |
| 13013 | * This will leave only the PF's VSI remaining. |
| 13014 | */ |
| 13015 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 13016 | if (!pf->veb[i]) |
| 13017 | continue; |
| 13018 | |
| 13019 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 13020 | pf->veb[i]->uplink_seid == 0) |
| 13021 | i40e_switch_branch_release(pf->veb[i]); |
| 13022 | } |
| 13023 | |
| 13024 | /* Now we can shutdown the PF's VSI, just before we kill |
| 13025 | * adminq and hmc. |
| 13026 | */ |
| 13027 | if (pf->vsi[pf->lan_vsi]) |
| 13028 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 13029 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 13030 | /* remove attached clients */ |
Mitch Williams | 004eb61 | 2017-04-04 12:40:16 -0700 | [diff] [blame] | 13031 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 13032 | ret_code = i40e_lan_del_device(pf); |
| 13033 | if (ret_code) |
| 13034 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 13035 | ret_code); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 13036 | } |
| 13037 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13038 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 13039 | if (hw->hmc.hmc_obj) { |
| 13040 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 13041 | if (ret_code) |
| 13042 | dev_warn(&pdev->dev, |
| 13043 | "Failed to destroy the HMC resources: %d\n", |
| 13044 | ret_code); |
| 13045 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13046 | |
| 13047 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 13048 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13049 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 13050 | /* destroy the locks only once, here */ |
| 13051 | mutex_destroy(&hw->aq.arq_mutex); |
| 13052 | mutex_destroy(&hw->aq.asq_mutex); |
| 13053 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13054 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 13055 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 13056 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13057 | if (pf->vsi[i]) { |
| 13058 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 13059 | i40e_vsi_clear(pf->vsi[i]); |
| 13060 | pf->vsi[i] = NULL; |
| 13061 | } |
| 13062 | } |
| 13063 | |
| 13064 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 13065 | kfree(pf->veb[i]); |
| 13066 | pf->veb[i] = NULL; |
| 13067 | } |
| 13068 | |
| 13069 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13070 | kfree(pf->vsi); |
| 13071 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 13072 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13073 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 13074 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13075 | |
| 13076 | pci_disable_pcie_error_reporting(pdev); |
| 13077 | pci_disable_device(pdev); |
| 13078 | } |
| 13079 | |
| 13080 | /** |
| 13081 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 13082 | * @pdev: PCI device information struct |
| 13083 | * |
| 13084 | * Called to warn that something happened and the error handling steps |
| 13085 | * are in progress. Allows the driver to quiesce things, be ready for |
| 13086 | * remediation. |
| 13087 | **/ |
| 13088 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 13089 | enum pci_channel_state error) |
| 13090 | { |
| 13091 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 13092 | |
| 13093 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 13094 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 13095 | if (!pf) { |
| 13096 | dev_info(&pdev->dev, |
| 13097 | "Cannot recover - error happened during device probe\n"); |
| 13098 | return PCI_ERS_RESULT_DISCONNECT; |
| 13099 | } |
| 13100 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13101 | /* shutdown all operations */ |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 13102 | if (!test_bit(__I40E_SUSPENDED, pf->state)) |
| 13103 | i40e_prep_for_reset(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13104 | |
| 13105 | /* Request a slot reset */ |
| 13106 | return PCI_ERS_RESULT_NEED_RESET; |
| 13107 | } |
| 13108 | |
| 13109 | /** |
| 13110 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 13111 | * @pdev: PCI device information struct |
| 13112 | * |
| 13113 | * Called to find if the driver can work with the device now that |
| 13114 | * the pci slot has been reset. If a basic connection seems good |
| 13115 | * (registers are readable and have sane content) then return a |
| 13116 | * happy little PCI_ERS_RESULT_xxx. |
| 13117 | **/ |
| 13118 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 13119 | { |
| 13120 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 13121 | pci_ers_result_t result; |
| 13122 | int err; |
| 13123 | u32 reg; |
| 13124 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 13125 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13126 | if (pci_enable_device_mem(pdev)) { |
| 13127 | dev_info(&pdev->dev, |
| 13128 | "Cannot re-enable PCI device after reset.\n"); |
| 13129 | result = PCI_ERS_RESULT_DISCONNECT; |
| 13130 | } else { |
| 13131 | pci_set_master(pdev); |
| 13132 | pci_restore_state(pdev); |
| 13133 | pci_save_state(pdev); |
| 13134 | pci_wake_from_d3(pdev, false); |
| 13135 | |
| 13136 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 13137 | if (reg == 0) |
| 13138 | result = PCI_ERS_RESULT_RECOVERED; |
| 13139 | else |
| 13140 | result = PCI_ERS_RESULT_DISCONNECT; |
| 13141 | } |
| 13142 | |
| 13143 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 13144 | if (err) { |
| 13145 | dev_info(&pdev->dev, |
| 13146 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 13147 | err); |
| 13148 | /* non-fatal, continue */ |
| 13149 | } |
| 13150 | |
| 13151 | return result; |
| 13152 | } |
| 13153 | |
| 13154 | /** |
Alan Brady | 19b7960 | 2017-08-29 05:32:39 -0400 | [diff] [blame] | 13155 | * i40e_pci_error_reset_prepare - prepare device driver for pci reset |
| 13156 | * @pdev: PCI device information struct |
| 13157 | */ |
| 13158 | static void i40e_pci_error_reset_prepare(struct pci_dev *pdev) |
| 13159 | { |
| 13160 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 13161 | |
| 13162 | i40e_prep_for_reset(pf, false); |
| 13163 | } |
| 13164 | |
| 13165 | /** |
| 13166 | * i40e_pci_error_reset_done - pci reset done, device driver reset can begin |
| 13167 | * @pdev: PCI device information struct |
| 13168 | */ |
| 13169 | static void i40e_pci_error_reset_done(struct pci_dev *pdev) |
| 13170 | { |
| 13171 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 13172 | |
| 13173 | i40e_reset_and_rebuild(pf, false, false); |
| 13174 | } |
| 13175 | |
| 13176 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13177 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 13178 | * @pdev: PCI device information struct |
| 13179 | * |
| 13180 | * Called to allow the driver to bring things back up after PCI error |
| 13181 | * and/or reset recovery has finished. |
| 13182 | **/ |
| 13183 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 13184 | { |
| 13185 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 13186 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 13187 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 13188 | if (test_bit(__I40E_SUSPENDED, pf->state)) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13189 | return; |
| 13190 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 13191 | i40e_handle_reset_warning(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13192 | } |
| 13193 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13194 | /** |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 13195 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up |
| 13196 | * using the mac_address_write admin q function |
| 13197 | * @pf: pointer to i40e_pf struct |
| 13198 | **/ |
| 13199 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) |
| 13200 | { |
| 13201 | struct i40e_hw *hw = &pf->hw; |
| 13202 | i40e_status ret; |
| 13203 | u8 mac_addr[6]; |
| 13204 | u16 flags = 0; |
| 13205 | |
| 13206 | /* Get current MAC address in case it's an LAA */ |
| 13207 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { |
| 13208 | ether_addr_copy(mac_addr, |
| 13209 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); |
| 13210 | } else { |
| 13211 | dev_err(&pf->pdev->dev, |
| 13212 | "Failed to retrieve MAC address; using default\n"); |
| 13213 | ether_addr_copy(mac_addr, hw->mac.addr); |
| 13214 | } |
| 13215 | |
| 13216 | /* The FW expects the mac address write cmd to first be called with |
| 13217 | * one of these flags before calling it again with the multicast |
| 13218 | * enable flags. |
| 13219 | */ |
| 13220 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; |
| 13221 | |
| 13222 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) |
| 13223 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; |
| 13224 | |
| 13225 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 13226 | if (ret) { |
| 13227 | dev_err(&pf->pdev->dev, |
| 13228 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); |
| 13229 | return; |
| 13230 | } |
| 13231 | |
| 13232 | flags = I40E_AQC_MC_MAG_EN |
| 13233 | | I40E_AQC_WOL_PRESERVE_ON_PFR |
| 13234 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; |
| 13235 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 13236 | if (ret) |
| 13237 | dev_err(&pf->pdev->dev, |
| 13238 | "Failed to enable Multicast Magic Packet wake up\n"); |
| 13239 | } |
| 13240 | |
| 13241 | /** |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13242 | * i40e_shutdown - PCI callback for shutting down |
| 13243 | * @pdev: PCI device information struct |
| 13244 | **/ |
| 13245 | static void i40e_shutdown(struct pci_dev *pdev) |
| 13246 | { |
| 13247 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 13248 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13249 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 13250 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 13251 | set_bit(__I40E_DOWN, pf->state); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13252 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 13253 | i40e_prep_for_reset(pf, true); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13254 | rtnl_unlock(); |
| 13255 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 13256 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 13257 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 13258 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 13259 | del_timer_sync(&pf->service_timer); |
| 13260 | cancel_work_sync(&pf->service_task); |
| 13261 | i40e_fdir_teardown(pf); |
| 13262 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 13263 | /* Client close must be called explicitly here because the timer |
| 13264 | * has been stopped. |
| 13265 | */ |
| 13266 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 13267 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 13268 | 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] | 13269 | i40e_enable_mc_magic_wake(pf); |
| 13270 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 13271 | i40e_prep_for_reset(pf, false); |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 13272 | |
| 13273 | wr32(hw, I40E_PFPM_APM, |
| 13274 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 13275 | wr32(hw, I40E_PFPM_WUFC, |
| 13276 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 13277 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 13278 | i40e_clear_interrupt_scheme(pf); |
| 13279 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13280 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 13281 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13282 | pci_set_power_state(pdev, PCI_D3hot); |
| 13283 | } |
| 13284 | } |
| 13285 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13286 | /** |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13287 | * i40e_suspend - PM callback for moving to D3 |
| 13288 | * @dev: generic device information structure |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13289 | **/ |
Arnd Bergmann | 254d152 | 2017-10-10 10:17:38 +0200 | [diff] [blame^] | 13290 | static int __maybe_unused i40e_suspend(struct device *dev) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13291 | { |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13292 | struct pci_dev *pdev = to_pci_dev(dev); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13293 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 13294 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13295 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 13296 | /* If we're already suspended, then there is nothing to do */ |
| 13297 | if (test_and_set_bit(__I40E_SUSPENDED, pf->state)) |
| 13298 | return 0; |
| 13299 | |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 13300 | set_bit(__I40E_DOWN, pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 13301 | |
Jacob Keller | 5c49922 | 2017-07-14 09:27:05 -0400 | [diff] [blame] | 13302 | /* Ensure service task will not be running */ |
| 13303 | del_timer_sync(&pf->service_timer); |
| 13304 | cancel_work_sync(&pf->service_task); |
| 13305 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 13306 | 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] | 13307 | i40e_enable_mc_magic_wake(pf); |
| 13308 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 13309 | i40e_prep_for_reset(pf, false); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13310 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 13311 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 13312 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 13313 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 13314 | /* Clear the interrupt scheme and release our IRQs so that the system |
| 13315 | * can safely hibernate even when there are a large number of CPUs. |
| 13316 | * Otherwise hibernation might fail when mapping all the vectors back |
| 13317 | * to CPU0. |
| 13318 | */ |
| 13319 | i40e_clear_interrupt_scheme(pf); |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 13320 | |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13321 | return 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13322 | } |
| 13323 | |
| 13324 | /** |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13325 | * i40e_resume - PM callback for waking up from D3 |
| 13326 | * @dev: generic device information structure |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13327 | **/ |
Arnd Bergmann | 254d152 | 2017-10-10 10:17:38 +0200 | [diff] [blame^] | 13328 | static int __maybe_unused i40e_resume(struct device *dev) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13329 | { |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13330 | struct pci_dev *pdev = to_pci_dev(dev); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13331 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 13332 | int err; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13333 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 13334 | /* If we're not suspended, then there is nothing to do */ |
| 13335 | if (!test_bit(__I40E_SUSPENDED, pf->state)) |
| 13336 | return 0; |
| 13337 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 13338 | /* We cleared the interrupt scheme when we suspended, so we need to |
| 13339 | * restore it now to resume device functionality. |
| 13340 | */ |
| 13341 | err = i40e_restore_interrupt_scheme(pf); |
| 13342 | if (err) { |
| 13343 | dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n", |
| 13344 | err); |
| 13345 | } |
| 13346 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 13347 | clear_bit(__I40E_DOWN, pf->state); |
| 13348 | i40e_reset_and_rebuild(pf, false, false); |
| 13349 | |
| 13350 | /* Clear suspended state last after everything is recovered */ |
| 13351 | clear_bit(__I40E_SUSPENDED, pf->state); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13352 | |
Jacob Keller | 5c49922 | 2017-07-14 09:27:05 -0400 | [diff] [blame] | 13353 | /* Restart the service task */ |
| 13354 | mod_timer(&pf->service_timer, |
| 13355 | round_jiffies(jiffies + pf->service_timer_period)); |
| 13356 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13357 | return 0; |
| 13358 | } |
| 13359 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13360 | static const struct pci_error_handlers i40e_err_handler = { |
| 13361 | .error_detected = i40e_pci_error_detected, |
| 13362 | .slot_reset = i40e_pci_error_slot_reset, |
Alan Brady | 19b7960 | 2017-08-29 05:32:39 -0400 | [diff] [blame] | 13363 | .reset_prepare = i40e_pci_error_reset_prepare, |
| 13364 | .reset_done = i40e_pci_error_reset_done, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13365 | .resume = i40e_pci_error_resume, |
| 13366 | }; |
| 13367 | |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13368 | static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume); |
| 13369 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13370 | static struct pci_driver i40e_driver = { |
| 13371 | .name = i40e_driver_name, |
| 13372 | .id_table = i40e_pci_tbl, |
| 13373 | .probe = i40e_probe, |
| 13374 | .remove = i40e_remove, |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 13375 | .driver = { |
| 13376 | .pm = &i40e_pm_ops, |
| 13377 | }, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 13378 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13379 | .err_handler = &i40e_err_handler, |
| 13380 | .sriov_configure = i40e_pci_sriov_configure, |
| 13381 | }; |
| 13382 | |
| 13383 | /** |
| 13384 | * i40e_init_module - Driver registration routine |
| 13385 | * |
| 13386 | * i40e_init_module is the first routine called when the driver is |
| 13387 | * loaded. All it does is register with the PCI subsystem. |
| 13388 | **/ |
| 13389 | static int __init i40e_init_module(void) |
| 13390 | { |
| 13391 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 13392 | i40e_driver_string, i40e_driver_version_str); |
| 13393 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 13394 | |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 13395 | /* There is no need to throttle the number of active tasks because |
| 13396 | * each device limits its own task using a state bit for scheduling |
| 13397 | * the service task, and the device tasks do not interfere with each |
| 13398 | * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM |
| 13399 | * since we need to be able to guarantee forward progress even under |
| 13400 | * memory pressure. |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 13401 | */ |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 13402 | i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 13403 | if (!i40e_wq) { |
| 13404 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 13405 | return -ENOMEM; |
| 13406 | } |
| 13407 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13408 | i40e_dbg_init(); |
| 13409 | return pci_register_driver(&i40e_driver); |
| 13410 | } |
| 13411 | module_init(i40e_init_module); |
| 13412 | |
| 13413 | /** |
| 13414 | * i40e_exit_module - Driver exit cleanup routine |
| 13415 | * |
| 13416 | * i40e_exit_module is called just before the driver is removed |
| 13417 | * from memory. |
| 13418 | **/ |
| 13419 | static void __exit i40e_exit_module(void) |
| 13420 | { |
| 13421 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 13422 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13423 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 13424 | } |
| 13425 | module_exit(i40e_exit_module); |